summaryrefslogtreecommitdiff
path: root/auth/credentials
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2016-12-14 16:47:57 +0100
committerAndrew Bartlett <abartlet@samba.org>2016-12-20 01:11:24 +0100
commiteaf3d44641370514169b74f7e564122354b6cfdf (patch)
tree169271fa1e71f8d248425337e455d085404a7cf7 /auth/credentials
parent6b18ac69156de588ec44d812e74ec8391c07d633 (diff)
downloadsamba-eaf3d44641370514169b74f7e564122354b6cfdf.tar.gz
auth/credentials: let cli_credentials_parse_string() always reset principal and realm
If we reset username we need to reset principal if it was set at the same level. If domain is reset we also need to use it as realm if realm was set at the same level. Otherwise we'd build a principal that belongs to a different user, which would not work and only increment the wrong lockout counter and result in wrong authorization tokens to be used. Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Diffstat (limited to 'auth/credentials')
-rw-r--r--auth/credentials/credentials.c33
1 files changed, 32 insertions, 1 deletions
diff --git a/auth/credentials/credentials.c b/auth/credentials/credentials.c
index cca772d9f41..14c84034ac6 100644
--- a/auth/credentials/credentials.c
+++ b/auth/credentials/credentials.c
@@ -797,9 +797,40 @@ _PUBLIC_ void cli_credentials_parse_string(struct cli_credentials *credentials,
|| (p = strchr_m(uname, '/'))
|| (p = strchr_m(uname, credentials->winbind_separator)))
{
+ const char *domain = NULL;
+
+ domain = uname;
*p = 0;
- cli_credentials_set_domain(credentials, uname, obtained);
uname = p+1;
+
+ if (obtained == credentials->realm_obtained &&
+ !strequal_m(credentials->domain, domain))
+ {
+ /*
+ * We need to undo a former set with the same level
+ * in order to get the expected result from
+ * cli_credentials_get_principal().
+ *
+ * But we only need to do that if the domain
+ * actually changes.
+ */
+ cli_credentials_set_realm(credentials, domain, obtained);
+ }
+ cli_credentials_set_domain(credentials, domain, obtained);
+ }
+ if (obtained == credentials->principal_obtained &&
+ !strequal_m(credentials->username, uname))
+ {
+ /*
+ * We need to undo a former set with the same level
+ * in order to get the expected result from
+ * cli_credentials_get_principal().
+ *
+ * But we only need to do that if the username
+ * actually changes.
+ */
+ credentials->principal_obtained = CRED_UNINITIALISED;
+ credentials->principal = NULL;
}
cli_credentials_set_username(credentials, uname, obtained);
}