summaryrefslogtreecommitdiff
path: root/auth
diff options
context:
space:
mode:
authorAlexander Bokovoy <ab@samba.org>2020-10-07 19:25:24 +0300
committerAlexander Bokovoy <ab@samba.org>2020-11-04 14:59:34 +0000
commiteb0474d27bae4592b25ac6bf600da29c6a1cb9f8 (patch)
tree539a40fe82c32b5f262b41149679ec7b2e349865 /auth
parenta1b021200e3d068631798942a1f219b26afadca7 (diff)
downloadsamba-eb0474d27bae4592b25ac6bf600da29c6a1cb9f8.tar.gz
cli_credentials_parse_string: fix parsing of principals
When parsing a principal-like name, user name was left with full principal instead of taking only the left part before '@' sign. >>> from samba import credentials >>> t = credentials.Credentials() >>> t.parse_string('admin@realm.test', credentials.SPECIFIED) >>> t.get_username() 'admin@realm.test' The issue is that cli_credentials_set_username() does a talloc_strdup() of the argument, so we need to change order of assignment to allow talloc_strdup() to copy the right part of the string. 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')
-rw-r--r--auth/credentials/credentials.c5
-rw-r--r--auth/credentials/tests/test_creds.c2
2 files changed, 3 insertions, 4 deletions
diff --git a/auth/credentials/credentials.c b/auth/credentials/credentials.c
index 1bdd6f15a09..a8d25278e9d 100644
--- a/auth/credentials/credentials.c
+++ b/auth/credentials/credentials.c
@@ -842,11 +842,10 @@ _PUBLIC_ void cli_credentials_parse_string(struct cli_credentials *credentials,
* in order to undo the effect of
* cli_credentials_guess().
*/
- cli_credentials_set_username(credentials, uname, obtained);
- cli_credentials_set_domain(credentials, "", obtained);
-
cli_credentials_set_principal(credentials, uname, obtained);
*p = 0;
+ cli_credentials_set_username(credentials, uname, obtained);
+ cli_credentials_set_domain(credentials, "", obtained);
cli_credentials_set_realm(credentials, p+1, obtained);
return;
} else if ((p = strchr_m(uname,'\\'))
diff --git a/auth/credentials/tests/test_creds.c b/auth/credentials/tests/test_creds.c
index d2d3d30d73d..541ecc7b264 100644
--- a/auth/credentials/tests/test_creds.c
+++ b/auth/credentials/tests/test_creds.c
@@ -187,7 +187,7 @@ static void torture_creds_parse_string(void **state)
assert_string_equal(creds->domain, "");
assert_int_equal(creds->domain_obtained, CRED_SPECIFIED);
- assert_string_equal(creds->username, "wurst@brot.realm");
+ assert_string_equal(creds->username, "wurst");
assert_int_equal(creds->username_obtained, CRED_SPECIFIED);
assert_string_equal(creds->principal, "wurst@brot.realm");