2 Unix SMB/CIFS implementation.
4 User credentials handling
6 Copyright (C) Jelmer Vernooij 2005
7 Copyright (C) Tim Potter 2001
8 Copyright (C) Andrew Bartlett <abartlet@samba.org> 2005
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #include "librpc/gen_ndr/samr.h" /* for struct samrPassword */
26 #include "auth/credentials/credentials.h"
27 #include "auth/credentials/credentials_krb5.h"
28 #include "auth/credentials/credentials_proto.h"
29 #include "libcli/auth/libcli_auth.h"
30 #include "lib/events/events.h"
31 #include "param/param.h"
34 * Create a new credentials structure
35 * @param mem_ctx TALLOC_CTX parent for credentials structure
37 _PUBLIC_
struct cli_credentials
*cli_credentials_init(TALLOC_CTX
*mem_ctx
)
39 struct cli_credentials
*cred
= talloc(mem_ctx
, struct cli_credentials
);
44 cred
->workstation_obtained
= CRED_UNINITIALISED
;
45 cred
->username_obtained
= CRED_UNINITIALISED
;
46 cred
->password_obtained
= CRED_UNINITIALISED
;
47 cred
->domain_obtained
= CRED_UNINITIALISED
;
48 cred
->realm_obtained
= CRED_UNINITIALISED
;
49 cred
->ccache_obtained
= CRED_UNINITIALISED
;
50 cred
->client_gss_creds_obtained
= CRED_UNINITIALISED
;
51 cred
->principal_obtained
= CRED_UNINITIALISED
;
52 cred
->keytab_obtained
= CRED_UNINITIALISED
;
53 cred
->server_gss_creds_obtained
= CRED_UNINITIALISED
;
55 cred
->ccache_threshold
= CRED_UNINITIALISED
;
56 cred
->client_gss_creds_threshold
= CRED_UNINITIALISED
;
58 cred
->workstation
= NULL
;
59 cred
->username
= NULL
;
60 cred
->password
= NULL
;
61 cred
->old_password
= NULL
;
64 cred
->principal
= NULL
;
65 cred
->salt_principal
= NULL
;
66 cred
->impersonate_principal
= NULL
;
67 cred
->target_service
= NULL
;
73 cred
->lm_response
.data
= NULL
;
74 cred
->lm_response
.length
= 0;
75 cred
->nt_response
.data
= NULL
;
76 cred
->nt_response
.length
= 0;
79 cred
->client_gss_creds
= NULL
;
81 cred
->server_gss_creds
= NULL
;
83 cred
->workstation_cb
= NULL
;
84 cred
->password_cb
= NULL
;
85 cred
->username_cb
= NULL
;
86 cred
->domain_cb
= NULL
;
87 cred
->realm_cb
= NULL
;
88 cred
->principal_cb
= NULL
;
90 cred
->priv_data
= NULL
;
92 cred
->netlogon_creds
= NULL
;
93 cred
->secure_channel_type
= SEC_CHAN_NULL
;
97 cred
->password_last_changed_time
= 0;
99 cred
->smb_krb5_context
= NULL
;
101 cred
->machine_account_pending
= false;
102 cred
->machine_account_pending_lp_ctx
= NULL
;
104 cred
->machine_account
= false;
108 cred
->callback_running
= false;
110 cli_credentials_set_kerberos_state(cred
, CRED_AUTO_USE_KERBEROS
);
111 cli_credentials_set_gensec_features(cred
, 0);
112 cli_credentials_set_krb_forwardable(cred
, CRED_AUTO_KRB_FORWARDABLE
);
118 * Create a new anonymous credential
119 * @param mem_ctx TALLOC_CTX parent for credentials structure
121 _PUBLIC_
struct cli_credentials
*cli_credentials_init_anon(TALLOC_CTX
*mem_ctx
)
123 struct cli_credentials
*anon_credentials
;
125 anon_credentials
= cli_credentials_init(mem_ctx
);
126 cli_credentials_set_anonymous(anon_credentials
);
128 return anon_credentials
;
131 _PUBLIC_
void cli_credentials_set_kerberos_state(struct cli_credentials
*creds
,
132 enum credentials_use_kerberos use_kerberos
)
134 creds
->use_kerberos
= use_kerberos
;
137 _PUBLIC_
void cli_credentials_set_krb_forwardable(struct cli_credentials
*creds
,
138 enum credentials_krb_forwardable krb_forwardable
)
140 creds
->krb_forwardable
= krb_forwardable
;
143 _PUBLIC_
enum credentials_use_kerberos
cli_credentials_get_kerberos_state(struct cli_credentials
*creds
)
145 return creds
->use_kerberos
;
148 _PUBLIC_
enum credentials_krb_forwardable
cli_credentials_get_krb_forwardable(struct cli_credentials
*creds
)
150 return creds
->krb_forwardable
;
153 _PUBLIC_
void cli_credentials_set_gensec_features(struct cli_credentials
*creds
, uint32_t gensec_features
)
155 creds
->gensec_features
= gensec_features
;
158 _PUBLIC_
uint32_t cli_credentials_get_gensec_features(struct cli_credentials
*creds
)
160 return creds
->gensec_features
;
165 * Obtain the username for this credentials context.
166 * @param cred credentials context
167 * @retval The username set on this context.
168 * @note Return value will never be NULL except by programmer error.
170 _PUBLIC_
const char *cli_credentials_get_username(struct cli_credentials
*cred
)
172 if (cred
->machine_account_pending
) {
173 cli_credentials_set_machine_account(cred
,
174 cred
->machine_account_pending_lp_ctx
);
177 if (cred
->username_obtained
== CRED_CALLBACK
&&
178 !cred
->callback_running
) {
179 cred
->callback_running
= true;
180 cred
->username
= cred
->username_cb(cred
);
181 cred
->callback_running
= false;
182 cred
->username_obtained
= CRED_SPECIFIED
;
183 cli_credentials_invalidate_ccache(cred
, cred
->username_obtained
);
186 return cred
->username
;
189 _PUBLIC_
bool cli_credentials_set_username(struct cli_credentials
*cred
,
190 const char *val
, enum credentials_obtained obtained
)
192 if (obtained
>= cred
->username_obtained
) {
193 cred
->username
= talloc_strdup(cred
, val
);
194 cred
->username_obtained
= obtained
;
195 cli_credentials_invalidate_ccache(cred
, cred
->username_obtained
);
202 bool cli_credentials_set_username_callback(struct cli_credentials
*cred
,
203 const char *(*username_cb
) (struct cli_credentials
*))
205 if (cred
->username_obtained
< CRED_CALLBACK
) {
206 cred
->username_cb
= username_cb
;
207 cred
->username_obtained
= CRED_CALLBACK
;
214 _PUBLIC_
bool cli_credentials_set_bind_dn(struct cli_credentials
*cred
,
217 cred
->bind_dn
= talloc_strdup(cred
, bind_dn
);
222 * Obtain the BIND DN for this credentials context.
223 * @param cred credentials context
224 * @retval The username set on this context.
225 * @note Return value will be NULL if not specified explictly
227 _PUBLIC_
const char *cli_credentials_get_bind_dn(struct cli_credentials
*cred
)
229 return cred
->bind_dn
;
234 * Obtain the client principal for this credentials context.
235 * @param cred credentials context
236 * @retval The username set on this context.
237 * @note Return value will never be NULL except by programmer error.
239 const char *cli_credentials_get_principal_and_obtained(struct cli_credentials
*cred
, TALLOC_CTX
*mem_ctx
, enum credentials_obtained
*obtained
)
241 if (cred
->machine_account_pending
) {
242 cli_credentials_set_machine_account(cred
,
243 cred
->machine_account_pending_lp_ctx
);
246 if (cred
->principal_obtained
== CRED_CALLBACK
&&
247 !cred
->callback_running
) {
248 cred
->callback_running
= true;
249 cred
->principal
= cred
->principal_cb(cred
);
250 cred
->callback_running
= false;
251 cred
->principal_obtained
= CRED_SPECIFIED
;
252 cli_credentials_invalidate_ccache(cred
, cred
->principal_obtained
);
255 if (cred
->principal_obtained
< cred
->username_obtained
256 || cred
->principal_obtained
< MAX(cred
->domain_obtained
, cred
->realm_obtained
)) {
257 if (cred
->domain_obtained
> cred
->realm_obtained
) {
258 *obtained
= MIN(cred
->domain_obtained
, cred
->username_obtained
);
259 return talloc_asprintf(mem_ctx
, "%s@%s",
260 cli_credentials_get_username(cred
),
261 cli_credentials_get_domain(cred
));
263 *obtained
= MIN(cred
->domain_obtained
, cred
->username_obtained
);
264 return talloc_asprintf(mem_ctx
, "%s@%s",
265 cli_credentials_get_username(cred
),
266 cli_credentials_get_realm(cred
));
269 *obtained
= cred
->principal_obtained
;
270 return talloc_reference(mem_ctx
, cred
->principal
);
274 * Obtain the client principal for this credentials context.
275 * @param cred credentials context
276 * @retval The username set on this context.
277 * @note Return value will never be NULL except by programmer error.
279 _PUBLIC_
const char *cli_credentials_get_principal(struct cli_credentials
*cred
, TALLOC_CTX
*mem_ctx
)
281 enum credentials_obtained obtained
;
282 return cli_credentials_get_principal_and_obtained(cred
, mem_ctx
, &obtained
);
285 bool cli_credentials_set_principal(struct cli_credentials
*cred
,
287 enum credentials_obtained obtained
)
289 if (obtained
>= cred
->principal_obtained
) {
290 cred
->principal
= talloc_strdup(cred
, val
);
291 cred
->principal_obtained
= obtained
;
292 cli_credentials_invalidate_ccache(cred
, cred
->principal_obtained
);
299 /* Set a callback to get the principal. This could be a popup dialog,
300 * a terminal prompt or similar. */
301 bool cli_credentials_set_principal_callback(struct cli_credentials
*cred
,
302 const char *(*principal_cb
) (struct cli_credentials
*))
304 if (cred
->principal_obtained
< CRED_CALLBACK
) {
305 cred
->principal_cb
= principal_cb
;
306 cred
->principal_obtained
= CRED_CALLBACK
;
313 /* Some of our tools are 'anonymous by default'. This is a single
314 * function to determine if authentication has been explicitly
317 _PUBLIC_
bool cli_credentials_authentication_requested(struct cli_credentials
*cred
)
323 if (cli_credentials_is_anonymous(cred
)){
327 if (cred
->principal_obtained
>= CRED_SPECIFIED
) {
330 if (cred
->username_obtained
>= CRED_SPECIFIED
) {
334 if (cli_credentials_get_kerberos_state(cred
) == CRED_MUST_USE_KERBEROS
) {
342 * Obtain the password for this credentials context.
343 * @param cred credentials context
344 * @retval If set, the cleartext password, otherwise NULL
346 _PUBLIC_
const char *cli_credentials_get_password(struct cli_credentials
*cred
)
348 if (cred
->machine_account_pending
) {
349 cli_credentials_set_machine_account(cred
,
350 cred
->machine_account_pending_lp_ctx
);
353 if (cred
->password_obtained
== CRED_CALLBACK
&&
354 !cred
->callback_running
) {
355 cred
->callback_running
= true;
356 cred
->password
= cred
->password_cb(cred
);
357 cred
->callback_running
= false;
358 cred
->password_obtained
= CRED_CALLBACK_RESULT
;
359 cli_credentials_invalidate_ccache(cred
, cred
->password_obtained
);
362 return cred
->password
;
365 /* Set a password on the credentials context, including an indication
366 * of 'how' the password was obtained */
368 _PUBLIC_
bool cli_credentials_set_password(struct cli_credentials
*cred
,
370 enum credentials_obtained obtained
)
372 if (obtained
>= cred
->password_obtained
) {
373 cred
->password
= talloc_strdup(cred
, val
);
374 cred
->password_obtained
= obtained
;
375 cli_credentials_invalidate_ccache(cred
, cred
->password_obtained
);
377 cred
->nt_hash
= NULL
;
378 cred
->lm_response
= data_blob(NULL
, 0);
379 cred
->nt_response
= data_blob(NULL
, 0);
386 _PUBLIC_
bool cli_credentials_set_password_callback(struct cli_credentials
*cred
,
387 const char *(*password_cb
) (struct cli_credentials
*))
389 if (cred
->password_obtained
< CRED_CALLBACK
) {
390 cred
->password_cb
= password_cb
;
391 cred
->password_obtained
= CRED_CALLBACK
;
392 cli_credentials_invalidate_ccache(cred
, cred
->password_obtained
);
400 * Obtain the 'old' password for this credentials context (used for join accounts).
401 * @param cred credentials context
402 * @retval If set, the cleartext password, otherwise NULL
404 const char *cli_credentials_get_old_password(struct cli_credentials
*cred
)
406 if (cred
->machine_account_pending
) {
407 cli_credentials_set_machine_account(cred
,
408 cred
->machine_account_pending_lp_ctx
);
411 return cred
->old_password
;
414 bool cli_credentials_set_old_password(struct cli_credentials
*cred
,
416 enum credentials_obtained obtained
)
418 cred
->old_password
= talloc_strdup(cred
, val
);
423 * Obtain the password, in the form MD4(unicode(password)) for this credentials context.
425 * Sometimes we only have this much of the password, while the rest of
426 * the time this call avoids calling E_md4hash themselves.
428 * @param cred credentials context
429 * @retval If set, the cleartext password, otherwise NULL
431 _PUBLIC_
const struct samr_Password
*cli_credentials_get_nt_hash(struct cli_credentials
*cred
,
434 const char *password
= cli_credentials_get_password(cred
);
437 struct samr_Password
*nt_hash
= talloc(mem_ctx
, struct samr_Password
);
442 E_md4hash(password
, nt_hash
->hash
);
446 return cred
->nt_hash
;
451 * Obtain the 'short' or 'NetBIOS' domain for this credentials context.
452 * @param cred credentials context
453 * @retval The domain set on this context.
454 * @note Return value will never be NULL except by programmer error.
456 _PUBLIC_
const char *cli_credentials_get_domain(struct cli_credentials
*cred
)
458 if (cred
->machine_account_pending
) {
459 cli_credentials_set_machine_account(cred
,
460 cred
->machine_account_pending_lp_ctx
);
463 if (cred
->domain_obtained
== CRED_CALLBACK
&&
464 !cred
->callback_running
) {
465 cred
->callback_running
= true;
466 cred
->domain
= cred
->domain_cb(cred
);
467 cred
->callback_running
= false;
468 cred
->domain_obtained
= CRED_SPECIFIED
;
469 cli_credentials_invalidate_ccache(cred
, cred
->domain_obtained
);
476 _PUBLIC_
bool cli_credentials_set_domain(struct cli_credentials
*cred
,
478 enum credentials_obtained obtained
)
480 if (obtained
>= cred
->domain_obtained
) {
481 /* it is important that the domain be in upper case,
482 * particularly for the sensitive NTLMv2
484 cred
->domain
= strupper_talloc(cred
, val
);
485 cred
->domain_obtained
= obtained
;
486 cli_credentials_invalidate_ccache(cred
, cred
->domain_obtained
);
493 bool cli_credentials_set_domain_callback(struct cli_credentials
*cred
,
494 const char *(*domain_cb
) (struct cli_credentials
*))
496 if (cred
->domain_obtained
< CRED_CALLBACK
) {
497 cred
->domain_cb
= domain_cb
;
498 cred
->domain_obtained
= CRED_CALLBACK
;
506 * Obtain the Kerberos realm for this credentials context.
507 * @param cred credentials context
508 * @retval The realm set on this context.
509 * @note Return value will never be NULL except by programmer error.
511 _PUBLIC_
const char *cli_credentials_get_realm(struct cli_credentials
*cred
)
513 if (cred
->machine_account_pending
) {
514 cli_credentials_set_machine_account(cred
,
515 cred
->machine_account_pending_lp_ctx
);
518 if (cred
->realm_obtained
== CRED_CALLBACK
&&
519 !cred
->callback_running
) {
520 cred
->callback_running
= true;
521 cred
->realm
= cred
->realm_cb(cred
);
522 cred
->callback_running
= false;
523 cred
->realm_obtained
= CRED_SPECIFIED
;
524 cli_credentials_invalidate_ccache(cred
, cred
->realm_obtained
);
531 * Set the realm for this credentials context, and force it to
532 * uppercase for the sainity of our local kerberos libraries
534 _PUBLIC_
bool cli_credentials_set_realm(struct cli_credentials
*cred
,
536 enum credentials_obtained obtained
)
538 if (obtained
>= cred
->realm_obtained
) {
539 cred
->realm
= strupper_talloc(cred
, val
);
540 cred
->realm_obtained
= obtained
;
541 cli_credentials_invalidate_ccache(cred
, cred
->realm_obtained
);
548 bool cli_credentials_set_realm_callback(struct cli_credentials
*cred
,
549 const char *(*realm_cb
) (struct cli_credentials
*))
551 if (cred
->realm_obtained
< CRED_CALLBACK
) {
552 cred
->realm_cb
= realm_cb
;
553 cred
->realm_obtained
= CRED_CALLBACK
;
561 * Obtain the 'short' or 'NetBIOS' workstation name for this credentials context.
563 * @param cred credentials context
564 * @retval The workstation name set on this context.
565 * @note Return value will never be NULL except by programmer error.
567 _PUBLIC_
const char *cli_credentials_get_workstation(struct cli_credentials
*cred
)
569 if (cred
->workstation_obtained
== CRED_CALLBACK
&&
570 !cred
->callback_running
) {
571 cred
->callback_running
= true;
572 cred
->workstation
= cred
->workstation_cb(cred
);
573 cred
->callback_running
= false;
574 cred
->workstation_obtained
= CRED_SPECIFIED
;
577 return cred
->workstation
;
580 _PUBLIC_
bool cli_credentials_set_workstation(struct cli_credentials
*cred
,
582 enum credentials_obtained obtained
)
584 if (obtained
>= cred
->workstation_obtained
) {
585 cred
->workstation
= talloc_strdup(cred
, val
);
586 cred
->workstation_obtained
= obtained
;
593 bool cli_credentials_set_workstation_callback(struct cli_credentials
*cred
,
594 const char *(*workstation_cb
) (struct cli_credentials
*))
596 if (cred
->workstation_obtained
< CRED_CALLBACK
) {
597 cred
->workstation_cb
= workstation_cb
;
598 cred
->workstation_obtained
= CRED_CALLBACK
;
606 * Given a string, typically obtained from a -U argument, parse it into domain, username, realm and password fields
608 * The format accepted is [domain\\]user[%password] or user[@realm][%password]
610 * @param credentials Credentials structure on which to set the password
611 * @param data the string containing the username, password etc
612 * @param obtained This enum describes how 'specified' this password is
615 _PUBLIC_
void cli_credentials_parse_string(struct cli_credentials
*credentials
, const char *data
, enum credentials_obtained obtained
)
619 if (strcmp("%",data
) == 0) {
620 cli_credentials_set_anonymous(credentials
);
624 uname
= talloc_strdup(credentials
, data
);
625 if ((p
= strchr_m(uname
,'%'))) {
627 cli_credentials_set_password(credentials
, p
+1, obtained
);
630 if ((p
= strchr_m(uname
,'@'))) {
631 cli_credentials_set_principal(credentials
, uname
, obtained
);
633 cli_credentials_set_realm(credentials
, p
+1, obtained
);
635 } else if ((p
= strchr_m(uname
,'\\')) || (p
= strchr_m(uname
, '/'))) {
637 cli_credentials_set_domain(credentials
, uname
, obtained
);
640 cli_credentials_set_username(credentials
, uname
, obtained
);
644 * Given a a credentials structure, print it as a string
646 * The format output is [domain\\]user[%password] or user[@realm][%password]
648 * @param credentials Credentials structure on which to set the password
649 * @param mem_ctx The memory context to place the result on
652 _PUBLIC_
const char *cli_credentials_get_unparsed_name(struct cli_credentials
*credentials
, TALLOC_CTX
*mem_ctx
)
654 const char *bind_dn
= cli_credentials_get_bind_dn(credentials
);
656 const char *username
;
660 name
= talloc_reference(mem_ctx
, bind_dn
);
662 cli_credentials_get_ntlm_username_domain(credentials
, mem_ctx
, &username
, &domain
);
663 if (domain
&& domain
[0]) {
664 name
= talloc_asprintf(mem_ctx
, "%s\\%s",
667 name
= talloc_asprintf(mem_ctx
, "%s",
675 * Specifies default values for domain, workstation and realm
676 * from the smb.conf configuration file
678 * @param cred Credentials structure to fill in
680 _PUBLIC_
void cli_credentials_set_conf(struct cli_credentials
*cred
,
681 struct loadparm_context
*lp_ctx
)
683 cli_credentials_set_username(cred
, "", CRED_UNINITIALISED
);
684 cli_credentials_set_domain(cred
, lpcfg_workgroup(lp_ctx
), CRED_UNINITIALISED
);
685 cli_credentials_set_workstation(cred
, lpcfg_netbios_name(lp_ctx
), CRED_UNINITIALISED
);
686 cli_credentials_set_realm(cred
, lpcfg_realm(lp_ctx
), CRED_UNINITIALISED
);
690 * Guess defaults for credentials from environment variables,
691 * and from the configuration file
693 * @param cred Credentials structure to fill in
695 _PUBLIC_
void cli_credentials_guess(struct cli_credentials
*cred
,
696 struct loadparm_context
*lp_ctx
)
699 const char *error_string
;
701 if (lp_ctx
!= NULL
) {
702 cli_credentials_set_conf(cred
, lp_ctx
);
705 if (getenv("LOGNAME")) {
706 cli_credentials_set_username(cred
, getenv("LOGNAME"), CRED_GUESS_ENV
);
709 if (getenv("USER")) {
710 cli_credentials_parse_string(cred
, getenv("USER"), CRED_GUESS_ENV
);
711 if ((p
= strchr_m(getenv("USER"),'%'))) {
712 memset(p
,0,strlen(cred
->password
));
716 if (getenv("PASSWD")) {
717 cli_credentials_set_password(cred
, getenv("PASSWD"), CRED_GUESS_ENV
);
720 if (getenv("PASSWD_FD")) {
721 cli_credentials_parse_password_fd(cred
, atoi(getenv("PASSWD_FD")),
725 p
= getenv("PASSWD_FILE");
727 cli_credentials_parse_password_file(cred
, p
, CRED_GUESS_FILE
);
730 if (cli_credentials_get_kerberos_state(cred
) != CRED_DONT_USE_KERBEROS
) {
731 cli_credentials_set_ccache(cred
, event_context_find(cred
), lp_ctx
, NULL
, CRED_GUESS_FILE
,
737 * Attach NETLOGON credentials for use with SCHANNEL
740 _PUBLIC_
void cli_credentials_set_netlogon_creds(struct cli_credentials
*cred
,
741 struct netlogon_creds_CredentialState
*netlogon_creds
)
743 cred
->netlogon_creds
= talloc_reference(cred
, netlogon_creds
);
747 * Return attached NETLOGON credentials
750 struct netlogon_creds_CredentialState
*cli_credentials_get_netlogon_creds(struct cli_credentials
*cred
)
752 return cred
->netlogon_creds
;
756 * Set NETLOGON secure channel type
759 _PUBLIC_
void cli_credentials_set_secure_channel_type(struct cli_credentials
*cred
,
760 enum netr_SchannelType secure_channel_type
)
762 cred
->secure_channel_type
= secure_channel_type
;
766 * Return NETLOGON secure chanel type
769 _PUBLIC_
time_t cli_credentials_get_password_last_changed_time(struct cli_credentials
*cred
)
771 return cred
->password_last_changed_time
;
775 * Set NETLOGON secure channel type
778 _PUBLIC_
void cli_credentials_set_password_last_changed_time(struct cli_credentials
*cred
,
779 time_t last_changed_time
)
781 cred
->password_last_changed_time
= last_changed_time
;
785 * Return NETLOGON secure chanel type
788 _PUBLIC_
enum netr_SchannelType
cli_credentials_get_secure_channel_type(struct cli_credentials
*cred
)
790 return cred
->secure_channel_type
;
794 * Fill in a credentials structure as the anonymous user
796 _PUBLIC_
void cli_credentials_set_anonymous(struct cli_credentials
*cred
)
798 cli_credentials_set_username(cred
, "", CRED_SPECIFIED
);
799 cli_credentials_set_domain(cred
, "", CRED_SPECIFIED
);
800 cli_credentials_set_password(cred
, NULL
, CRED_SPECIFIED
);
801 cli_credentials_set_realm(cred
, NULL
, CRED_SPECIFIED
);
802 cli_credentials_set_workstation(cred
, "", CRED_UNINITIALISED
);
806 * Describe a credentials context as anonymous or authenticated
807 * @retval true if anonymous, false if a username is specified
810 _PUBLIC_
bool cli_credentials_is_anonymous(struct cli_credentials
*cred
)
812 const char *username
;
814 /* if bind dn is set it's not anonymous */
819 if (cred
->machine_account_pending
) {
820 cli_credentials_set_machine_account(cred
,
821 cred
->machine_account_pending_lp_ctx
);
824 username
= cli_credentials_get_username(cred
);
826 /* Yes, it is deliberate that we die if we have a NULL pointer
827 * here - anonymous is "", not NULL, which is 'never specified,
828 * never guessed', ie programmer bug */
837 * Mark the current password for a credentials struct as wrong. This will
838 * cause the password to be prompted again (if a callback is set).
840 * This will decrement the number of times the password can be tried.
842 * @retval whether the credentials struct is finished
844 _PUBLIC_
bool cli_credentials_wrong_password(struct cli_credentials
*cred
)
846 if (cred
->password_obtained
!= CRED_CALLBACK_RESULT
) {
850 cred
->password_obtained
= CRED_CALLBACK
;
854 return (cred
->tries
> 0);