diff options
author | Andrew Bartlett <abartlet@samba.org> | 2005-08-30 01:19:41 +0000 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2005-08-30 01:19:41 +0000 |
commit | cf10def61d40d7ecf7c42d9509a8f659a73b81f3 (patch) | |
tree | 6aa1e3f30f417c0714372b0b373ee6b41aa77535 /source/lib | |
parent | 814ea5b90d445b2d59f17f85a53f33ceb39a50ea (diff) | |
download | samba-cf10def61d40d7ecf7c42d9509a8f659a73b81f3.tar.gz samba-cf10def61d40d7ecf7c42d9509a8f659a73b81f3.tar.xz samba-cf10def61d40d7ecf7c42d9509a8f659a73b81f3.zip |
r9772: Make credentials callbacks more consistant with the abstraction
function interface used in the credentials code.
Fix bug in ntlm_auth, where we would overwrite the PW specified as a
first input. (Reported and chased by Kai Blin <blin@gmx.net>, bug
#3040)
Andrew Bartlett
Diffstat (limited to 'source/lib')
-rw-r--r-- | source/lib/cmdline/credentials.c | 9 | ||||
-rw-r--r-- | source/lib/credentials.c | 99 |
2 files changed, 95 insertions, 13 deletions
diff --git a/source/lib/cmdline/credentials.c b/source/lib/cmdline/credentials.c index 7832e01e4bb..f46a03b2365 100644 --- a/source/lib/cmdline/credentials.c +++ b/source/lib/cmdline/credentials.c @@ -29,8 +29,8 @@ static const char *cmdline_get_userpassword(struct cli_credentials *credentials) { char *prompt; char *ret; - char *domain; - char *username; + const char *domain; + const char *username; TALLOC_CTX *mem_ctx = talloc_new(NULL); domain = cli_credentials_get_domain(credentials); @@ -51,8 +51,5 @@ static const char *cmdline_get_userpassword(struct cli_credentials *credentials) void cli_credentials_set_cmdline_callbacks(struct cli_credentials *cred) { - if (cred->password_obtained <= CRED_CALLBACK) { - cred->password_cb = cmdline_get_userpassword; - cred->password_obtained = CRED_CALLBACK; - } + cli_credentials_set_password_callback(cred, cmdline_get_userpassword); } diff --git a/source/lib/credentials.c b/source/lib/credentials.c index 579f199d2e3..162b52e5d05 100644 --- a/source/lib/credentials.c +++ b/source/lib/credentials.c @@ -77,7 +77,8 @@ const char *cli_credentials_get_username(struct cli_credentials *cred, TALLOC_CT return talloc_reference(mem_ctx, cred->username); } -BOOL cli_credentials_set_username(struct cli_credentials *cred, const char *val, enum credentials_obtained obtained) +BOOL cli_credentials_set_username(struct cli_credentials *cred, + const char *val, enum credentials_obtained obtained) { if (obtained >= cred->username_obtained) { cred->username = talloc_strdup(cred, val); @@ -88,6 +89,20 @@ BOOL cli_credentials_set_username(struct cli_credentials *cred, const char *val, return False; } +BOOL cli_credentials_set_username_callback(struct cli_credentials *cred, + const char *(*username_cb) (struct cli_credentials *)) +{ + if (cred->username_obtained < CRED_CALLBACK) { + cred->username_cb = username_cb; + cred->username_obtained = CRED_CALLBACK; + return True; + } + + return False; +} + + + /** * Obtain the client principal for this credentials context. * @param cred credentials context @@ -124,6 +139,18 @@ BOOL cli_credentials_set_principal(struct cli_credentials *cred, const char *val return False; } +BOOL cli_credentials_set_principal_callback(struct cli_credentials *cred, + const char *(*principal_cb) (struct cli_credentials *)) +{ + if (cred->principal_obtained < CRED_CALLBACK) { + cred->principal_cb = principal_cb; + cred->principal_obtained = CRED_CALLBACK; + return True; + } + + return False; +} + BOOL cli_credentials_authentication_requested(struct cli_credentials *cred) { if (cred->principal_obtained >= CRED_SPECIFIED) { @@ -154,7 +181,9 @@ const char *cli_credentials_get_password(struct cli_credentials *cred) return cred->password; } -BOOL cli_credentials_set_password(struct cli_credentials *cred, const char *val, enum credentials_obtained obtained) +BOOL cli_credentials_set_password(struct cli_credentials *cred, + const char *val, + enum credentials_obtained obtained) { if (obtained >= cred->password_obtained) { cred->password = talloc_strdup(cred, val); @@ -167,6 +196,18 @@ BOOL cli_credentials_set_password(struct cli_credentials *cred, const char *val, return False; } +BOOL cli_credentials_set_password_callback(struct cli_credentials *cred, + const char *(*password_cb) (struct cli_credentials *)) +{ + if (cred->password_obtained < CRED_CALLBACK) { + cred->password_cb = password_cb; + cred->password_obtained = CRED_CALLBACK; + return True; + } + + return False; +} + /** * Obtain the password for this credentials context. * @param cred credentials context @@ -375,7 +416,8 @@ int cli_credentials_new_ccache(struct cli_credentials *cred) return ret; } -int cli_credentials_get_ccache(struct cli_credentials *cred, struct ccache_container **ccc) +int cli_credentials_get_ccache(struct cli_credentials *cred, + struct ccache_container **ccc) { krb5_error_code ret; @@ -432,7 +474,9 @@ const char *cli_credentials_get_domain(struct cli_credentials *cred) } -BOOL cli_credentials_set_domain(struct cli_credentials *cred, const char *val, enum credentials_obtained obtained) +BOOL cli_credentials_set_domain(struct cli_credentials *cred, + const char *val, + enum credentials_obtained obtained) { if (obtained >= cred->domain_obtained) { cred->domain = talloc_strdup(cred, val); @@ -443,6 +487,18 @@ BOOL cli_credentials_set_domain(struct cli_credentials *cred, const char *val, e return False; } +BOOL cli_credentials_set_domain_callback(struct cli_credentials *cred, + const char *(*domain_cb) (struct cli_credentials *)) +{ + if (cred->domain_obtained < CRED_CALLBACK) { + cred->domain_cb = domain_cb; + cred->domain_obtained = CRED_CALLBACK; + return True; + } + + return False; +} + /** * Obtain the Kerberos realm for this credentials context. * @param cred credentials context @@ -467,7 +523,9 @@ const char *cli_credentials_get_realm(struct cli_credentials *cred) * Set the realm for this credentials context, and force it to * uppercase for the sainity of our local kerberos libraries */ -BOOL cli_credentials_set_realm(struct cli_credentials *cred, const char *val, enum credentials_obtained obtained) +BOOL cli_credentials_set_realm(struct cli_credentials *cred, + const char *val, + enum credentials_obtained obtained) { if (obtained >= cred->realm_obtained) { cred->realm = strupper_talloc(cred, val); @@ -478,6 +536,18 @@ BOOL cli_credentials_set_realm(struct cli_credentials *cred, const char *val, en return False; } +BOOL cli_credentials_set_realm_callback(struct cli_credentials *cred, + const char *(*realm_cb) (struct cli_credentials *)) +{ + if (cred->realm_obtained < CRED_CALLBACK) { + cred->realm_cb = realm_cb; + cred->realm_obtained = CRED_CALLBACK; + return True; + } + + return False; +} + /** * Obtain the 'short' or 'NetBIOS' workstation name for this credentials context. * @@ -495,7 +565,9 @@ const char *cli_credentials_get_workstation(struct cli_credentials *cred) return cred->workstation; } -BOOL cli_credentials_set_workstation(struct cli_credentials *cred, const char *val, enum credentials_obtained obtained) +BOOL cli_credentials_set_workstation(struct cli_credentials *cred, + const char *val, + enum credentials_obtained obtained) { if (obtained >= cred->workstation_obtained) { cred->workstation = talloc_strdup(cred, val); @@ -506,6 +578,18 @@ BOOL cli_credentials_set_workstation(struct cli_credentials *cred, const char *v return False; } +BOOL cli_credentials_set_workstation_callback(struct cli_credentials *cred, + const char *(*workstation_cb) (struct cli_credentials *)) +{ + if (cred->workstation_obtained < CRED_CALLBACK) { + cred->workstation_cb = workstation_cb; + cred->workstation_obtained = CRED_CALLBACK; + return True; + } + + return False; +} + /** * Read a file descriptor, and parse it for a password (eg from a file or stdin) * @@ -514,7 +598,8 @@ BOOL cli_credentials_set_workstation(struct cli_credentials *cred, const char *v * @param obtained This enum describes how 'specified' this password is */ -BOOL cli_credentials_parse_password_fd(struct cli_credentials *credentials, int fd, enum credentials_obtained obtained) +BOOL cli_credentials_parse_password_fd(struct cli_credentials *credentials, + int fd, enum credentials_obtained obtained) { char *p; char pass[128]; |