diff options
author | Andrew Bartlett <abartlet@samba.org> | 2005-03-22 08:00:45 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:11:11 -0500 |
commit | 645711c602313940dcf80ec786557920ecfbf884 (patch) | |
tree | 77c5f5c5f1285677eaaf7a3fa62bf0b2540e153f /source4/lib/credentials.c | |
parent | 376b03ebd895b221b70058ee18bea50587388182 (diff) | |
download | samba-645711c602313940dcf80ec786557920ecfbf884.tar.gz samba-645711c602313940dcf80ec786557920ecfbf884.tar.bz2 samba-645711c602313940dcf80ec786557920ecfbf884.zip |
r5941: Commit this patch much earlier than I would normally prefer, but metze needs a working tree...
The main volume of this patch was what I started working on today:
- Cleans up memory handling around DCE/RPC pipes, to have a parent talloc context.
- Uses sepereate inner loops for some of the DCE/RPC tests
The other and more important part of this patch fixes issues
surrounding the new credentials framwork:
This makes the struct cli_credentials always a talloc() structure,
rather than on the stack. Parts of the cli_credentials code already
assumed this.
There were other issues, particularly in the DCERPC over SMB handling,
as well as little things that had to be tidied up before test_w2k3.sh
would start to pass.
Andrew Bartlett
(This used to be commit 0453f9d05d2e336fba1f85dbf2718d01fa2bf778)
Diffstat (limited to 'source4/lib/credentials.c')
-rw-r--r-- | source4/lib/credentials.c | 43 |
1 files changed, 21 insertions, 22 deletions
diff --git a/source4/lib/credentials.c b/source4/lib/credentials.c index 2601028e7e..92f389e228 100644 --- a/source4/lib/credentials.c +++ b/source4/lib/credentials.c @@ -3,6 +3,7 @@ Copyright (C) Jelmer Vernooij 2005 Copyright (C) Tim Potter 2001 + Copyright (C) Andrew Bartlett <abartlet@samba.org> 2005 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -22,12 +23,14 @@ #include "includes.h" #include "system/filesys.h" -const char *cli_credentials_get_username(struct cli_credentials *cred) +/* Create a new credentials structure, on the specified TALLOC_CTX */ +struct cli_credentials *cli_credentials_init(TALLOC_CTX *mem_ctx) { - if (cred == NULL) { - return NULL; - } + return talloc_zero(mem_ctx, struct cli_credentials); +} +const char *cli_credentials_get_username(struct cli_credentials *cred) +{ if (cred->username_obtained == CRED_CALLBACK) { cred->username = cred->username_cb(cred); cred->username_obtained = CRED_SPECIFIED; @@ -49,10 +52,6 @@ BOOL cli_credentials_set_username(struct cli_credentials *cred, const char *val, const char *cli_credentials_get_password(struct cli_credentials *cred) { - if (cred == NULL) { - return NULL; - } - if (cred->password_obtained == CRED_CALLBACK) { cred->password = cred->password_cb(cred); cred->password_obtained = CRED_SPECIFIED; @@ -74,10 +73,6 @@ BOOL cli_credentials_set_password(struct cli_credentials *cred, const char *val, const char *cli_credentials_get_domain(struct cli_credentials *cred) { - if (cred == NULL) { - return NULL; - } - if (cred->domain_obtained == CRED_CALLBACK) { cred->domain = cred->domain_cb(cred); cred->domain_obtained = CRED_SPECIFIED; @@ -264,23 +259,20 @@ void cli_credentials_parse_string(struct cli_credentials *credentials, const cha char *uname, *p; uname = talloc_strdup(credentials, data); - cli_credentials_set_username(credentials, uname, obtained); - - if ((p = strchr_m(uname,'\\')) || (p = strchr_m(uname, '/'))) { + if ((p = strchr_m(uname,'%'))) { *p = 0; - cli_credentials_set_domain(credentials, uname, obtained); - credentials->username = uname = p+1; + cli_credentials_set_password(credentials, p+1, obtained); } if ((p = strchr_m(uname,'@'))) { *p = 0; cli_credentials_set_realm(credentials, p+1, obtained); - } - - if ((p = strchr_m(uname,'%'))) { + } else if ((p = strchr_m(uname,'\\')) || (p = strchr_m(uname, '/'))) { *p = 0; - cli_credentials_set_password(credentials, p+1, obtained); + cli_credentials_set_domain(credentials, uname, obtained); + uname = p+1; } + cli_credentials_set_username(credentials, uname, obtained); } void cli_credentials_guess(struct cli_credentials *cred) @@ -319,11 +311,18 @@ void cli_credentials_guess(struct cli_credentials *cred) } } +/* Fill in a credentails structure as anonymous */ +void cli_credentials_set_anonymous(struct cli_credentials *cred) +{ + cli_credentials_set_username(cred, "", CRED_SPECIFIED); + cli_credentials_set_domain(cred, "", CRED_SPECIFIED); +} + BOOL cli_credentials_is_anonymous(struct cli_credentials *credentials) { const char *username = cli_credentials_get_username(credentials); - if (!username || !username[0]) + if (!username[0]) return True; return False; |