diff options
author | Alexander Bokovoy <ab@samba.org> | 2020-11-04 14:00:58 +0200 |
---|---|---|
committer | Alexander Bokovoy <ab@samba.org> | 2020-11-04 14:59:34 +0000 |
commit | 00f4262ed0b22f6e333e5a29c5590b62c783905c (patch) | |
tree | b37e0a17d2d84f02fbc71b5399bdd0107552b0eb /auth/credentials/credentials.c | |
parent | eb0474d27bae4592b25ac6bf600da29c6a1cb9f8 (diff) | |
download | samba-00f4262ed0b22f6e333e5a29c5590b62c783905c.tar.gz |
cli_credentials: add a helper to parse user or group names
cli_credentials_parse_string() parses a string specified for -U option
in command line tools. It has a side-effect that '%' character is always
considered to be a separator after which a password is specified.
Active Directory does allow to create user or group objects with '%' in
the name. It means cli_credentials_parse_string() will not be able to
properly parse such name.
Introduce cli_credentials_parse_name() for the cases when a password is
not expected in the name and call to cli_credentials_parse_name() from
cli_credentials_parse_string().
Test cli_credentials_parse_name() with its intended use in lookup_name()
refactoring.
Signed-off-by: Alexander Bokovoy <ab@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
Diffstat (limited to 'auth/credentials/credentials.c')
-rw-r--r-- | auth/credentials/credentials.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/auth/credentials/credentials.c b/auth/credentials/credentials.c index a8d25278e9d..53bba78176b 100644 --- a/auth/credentials/credentials.c +++ b/auth/credentials/credentials.c @@ -836,6 +836,24 @@ _PUBLIC_ void cli_credentials_parse_string(struct cli_credentials *credentials, cli_credentials_set_password(credentials, p+1, obtained); } + cli_credentials_parse_name(credentials, uname, obtained); +} + +/** + * Given a string, parse it into a domain, username and realm fields + * + * The format accepted is [domain\\]user or user[@realm] + * + * @param credentials Credentials structure on which to set the components + * @param data the string containing the username, prefixed or suffixed with domain or realm + * @param obtained This enum describes how 'specified' this credential name is. + */ + +_PUBLIC_ void cli_credentials_parse_name(struct cli_credentials *credentials, const char *data, enum credentials_obtained obtained) +{ + char *uname, *p; + + uname = talloc_strdup(credentials, data); if ((p = strchr_m(uname,'@'))) { /* * We also need to set username and domain |