r14585: Tighten argument list of kerberos_kinit_password again,
[Samba/nascimento.git] / source3 / libads / kerberos.c
blob029e42c0c2fac5f94f466cc720ed3c48f68e4e0c
1 /*
2 Unix SMB/CIFS implementation.
3 kerberos utility library
4 Copyright (C) Andrew Tridgell 2001
5 Copyright (C) Remus Koos 2001
6 Copyright (C) Nalin Dahyabhai <nalin@redhat.com> 2004.
7 Copyright (C) Jeremy Allison 2004.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "includes.h"
26 #ifdef HAVE_KRB5
28 #define LIBADS_CCACHE_NAME "MEMORY:libads"
31 we use a prompter to avoid a crash bug in the kerberos libs when
32 dealing with empty passwords
33 this prompter is just a string copy ...
35 static krb5_error_code
36 kerb_prompter(krb5_context ctx, void *data,
37 const char *name,
38 const char *banner,
39 int num_prompts,
40 krb5_prompt prompts[])
42 if (num_prompts == 0) return 0;
44 memset(prompts[0].reply->data, '\0', prompts[0].reply->length);
45 if (prompts[0].reply->length > 0) {
46 if (data) {
47 strncpy(prompts[0].reply->data, data, prompts[0].reply->length-1);
48 prompts[0].reply->length = strlen(prompts[0].reply->data);
49 } else {
50 prompts[0].reply->length = 0;
53 return 0;
57 simulate a kinit, putting the tgt in the given cache location. If cache_name == NULL
58 place in default cache location.
59 remus@snapserver.com
61 int kerberos_kinit_password_ext(const char *principal,
62 const char *password,
63 int time_offset,
64 time_t *expire_time,
65 time_t *renew_till_time,
66 const char *cache_name,
67 BOOL request_pac,
68 time_t renewable_time)
70 krb5_context ctx = NULL;
71 krb5_error_code code = 0;
72 krb5_ccache cc = NULL;
73 krb5_principal me;
74 krb5_creds my_creds;
75 #if 0
76 krb5_get_init_creds_opt opt;
77 #endif
79 initialize_krb5_error_table();
80 if ((code = krb5_init_context(&ctx)))
81 return code;
83 if (time_offset != 0) {
84 krb5_set_real_time(ctx, time(NULL) + time_offset, 0);
87 DEBUG(10,("kerberos_kinit_password: using %s as ccache\n",
88 cache_name ? cache_name: krb5_cc_default_name(ctx)));
90 if ((code = krb5_cc_resolve(ctx, cache_name ? cache_name : krb5_cc_default_name(ctx), &cc))) {
91 krb5_free_context(ctx);
92 return code;
95 if ((code = krb5_parse_name(ctx, principal, &me))) {
96 krb5_free_context(ctx);
97 return code;
100 #if 0 /* This code causes problems with MIT krb5 1.3 when asking for a
101 TGT for the machine account */
102 krb5_get_init_creds_opt_init(&opt);
103 krb5_get_init_creds_opt_set_renew_life(&opt, renewable_time);
104 krb5_get_init_creds_opt_set_forwardable(&opt, 1);
105 #endif
107 if (request_pac) {
108 #ifdef HAVE_KRB5_GET_INIT_CREDS_OPT_SET_PAC_REQUEST
109 krb5_get_init_creds_opt_set_pac_request(ctx, &opt, True);
110 #endif
113 #if 0
114 if ((code = krb5_get_init_creds_password(ctx, &my_creds, me, CONST_DISCARD(char *,password),
115 kerb_prompter, NULL, 0, NULL, &opt)))
116 #else
117 if ((code = krb5_get_init_creds_password(ctx, &my_creds, me, CONST_DISCARD(char *,password),
118 kerb_prompter, NULL, 0, NULL, NULL)))
119 #endif
121 krb5_free_principal(ctx, me);
122 krb5_free_context(ctx);
123 return code;
126 if ((code = krb5_cc_initialize(ctx, cc, me))) {
127 krb5_free_cred_contents(ctx, &my_creds);
128 krb5_free_principal(ctx, me);
129 krb5_free_context(ctx);
130 return code;
133 if ((code = krb5_cc_store_cred(ctx, cc, &my_creds))) {
134 krb5_cc_close(ctx, cc);
135 krb5_free_cred_contents(ctx, &my_creds);
136 krb5_free_principal(ctx, me);
137 krb5_free_context(ctx);
138 return code;
141 if (expire_time) {
142 *expire_time = (time_t) my_creds.times.endtime;
145 if (renew_till_time) {
146 *renew_till_time = (time_t) my_creds.times.renew_till;
149 krb5_cc_close(ctx, cc);
150 krb5_free_cred_contents(ctx, &my_creds);
151 krb5_free_principal(ctx, me);
152 krb5_free_context(ctx);
154 return 0;
159 /* run kinit to setup our ccache */
160 int ads_kinit_password(ADS_STRUCT *ads)
162 char *s;
163 int ret;
164 const char *account_name;
165 fstring acct_name;
167 if ( IS_DC ) {
168 /* this will end up getting a ticket for DOMAIN@RUSTED.REA.LM */
169 account_name = lp_workgroup();
170 } else {
171 /* always use the sAMAccountName for security = domain */
172 /* global_myname()$@REA.LM */
173 if ( lp_security() == SEC_DOMAIN ) {
174 fstr_sprintf( acct_name, "%s$", global_myname() );
175 account_name = acct_name;
177 else
178 /* This looks like host/global_myname()@REA.LM */
179 account_name = ads->auth.user_name;
182 if (asprintf(&s, "%s@%s", account_name, ads->auth.realm) == -1) {
183 return KRB5_CC_NOMEM;
186 if (!ads->auth.password) {
187 return KRB5_LIBOS_CANTREADPWD;
190 ret = kerberos_kinit_password_ext(s, ads->auth.password, ads->auth.time_offset,
191 &ads->auth.expire, NULL, NULL, False, ads->auth.renewable);
193 if (ret) {
194 DEBUG(0,("kerberos_kinit_password %s failed: %s\n",
195 s, error_message(ret)));
197 free(s);
198 return ret;
201 int ads_kdestroy(const char *cc_name)
203 krb5_error_code code;
204 krb5_context ctx = NULL;
205 krb5_ccache cc = NULL;
207 initialize_krb5_error_table();
208 if ((code = krb5_init_context (&ctx))) {
209 DEBUG(3, ("ads_kdestroy: kdb5_init_context failed: %s\n",
210 error_message(code)));
211 return code;
214 if (!cc_name) {
215 if ((code = krb5_cc_default(ctx, &cc))) {
216 krb5_free_context(ctx);
217 return code;
219 } else {
220 if ((code = krb5_cc_resolve(ctx, cc_name, &cc))) {
221 DEBUG(3, ("ads_kdestroy: krb5_cc_resolve failed: %s\n",
222 error_message(code)));
223 krb5_free_context(ctx);
224 return code;
228 if ((code = krb5_cc_destroy (ctx, cc))) {
229 DEBUG(3, ("ads_kdestroy: krb5_cc_destroy failed: %s\n",
230 error_message(code)));
233 krb5_free_context (ctx);
234 return code;
237 /************************************************************************
238 Routine to fetch the salting principal for a service. Active
239 Directory may use a non-obvious principal name to generate the salt
240 when it determines the key to use for encrypting tickets for a service,
241 and hopefully we detected that when we joined the domain.
242 ************************************************************************/
244 static char *kerberos_secrets_fetch_salting_principal(const char *service, int enctype)
246 char *key = NULL;
247 char *ret = NULL;
249 asprintf(&key, "%s/%s/enctype=%d", SECRETS_SALTING_PRINCIPAL, service, enctype);
250 if (!key) {
251 return NULL;
253 ret = (char *)secrets_fetch(key, NULL);
254 SAFE_FREE(key);
255 return ret;
258 /************************************************************************
259 Routine to get the salting principal for this service. Active
260 Directory may use a non-obvious principal name to generate the salt
261 when it determines the key to use for encrypting tickets for a service,
262 and hopefully we detected that when we joined the domain.
263 Caller must free if return is not null.
264 ************************************************************************/
266 krb5_principal kerberos_fetch_salt_princ_for_host_princ(krb5_context context,
267 krb5_principal host_princ,
268 int enctype)
270 char *unparsed_name = NULL, *salt_princ_s = NULL;
271 krb5_principal ret_princ = NULL;
273 if (krb5_unparse_name(context, host_princ, &unparsed_name) != 0) {
274 return (krb5_principal)NULL;
277 if ((salt_princ_s = kerberos_secrets_fetch_salting_principal(unparsed_name, enctype)) == NULL) {
278 krb5_free_unparsed_name(context, unparsed_name);
279 return (krb5_principal)NULL;
282 if (krb5_parse_name(context, salt_princ_s, &ret_princ) != 0) {
283 krb5_free_unparsed_name(context, unparsed_name);
284 SAFE_FREE(salt_princ_s);
285 return (krb5_principal)NULL;
287 krb5_free_unparsed_name(context, unparsed_name);
288 SAFE_FREE(salt_princ_s);
289 return ret_princ;
292 /************************************************************************
293 Routine to set the salting principal for this service. Active
294 Directory may use a non-obvious principal name to generate the salt
295 when it determines the key to use for encrypting tickets for a service,
296 and hopefully we detected that when we joined the domain.
297 Setting principal to NULL deletes this entry.
298 ************************************************************************/
300 BOOL kerberos_secrets_store_salting_principal(const char *service,
301 int enctype,
302 const char *principal)
304 char *key = NULL;
305 BOOL ret = False;
306 krb5_context context = NULL;
307 krb5_principal princ = NULL;
308 char *princ_s = NULL;
309 char *unparsed_name = NULL;
311 krb5_init_context(&context);
312 if (!context) {
313 return False;
315 if (strchr_m(service, '@')) {
316 asprintf(&princ_s, "%s", service);
317 } else {
318 asprintf(&princ_s, "%s@%s", service, lp_realm());
321 if (krb5_parse_name(context, princ_s, &princ) != 0) {
322 goto out;
325 if (krb5_unparse_name(context, princ, &unparsed_name) != 0) {
326 goto out;
329 asprintf(&key, "%s/%s/enctype=%d", SECRETS_SALTING_PRINCIPAL, unparsed_name, enctype);
330 if (!key) {
331 goto out;
334 if ((principal != NULL) && (strlen(principal) > 0)) {
335 ret = secrets_store(key, principal, strlen(principal) + 1);
336 } else {
337 ret = secrets_delete(key);
340 out:
342 SAFE_FREE(key);
343 SAFE_FREE(princ_s);
345 if (unparsed_name) {
346 krb5_free_unparsed_name(context, unparsed_name);
348 if (context) {
349 krb5_free_context(context);
352 return ret;
355 /************************************************************************
356 Routine to get initial credentials as a service ticket for the local machine.
357 Returns a buffer initialized with krb5_mk_req_extended.
358 ************************************************************************/
360 static krb5_error_code get_service_ticket(krb5_context ctx,
361 krb5_ccache ccache,
362 const char *service_principal,
363 int enctype,
364 krb5_data *p_outbuf)
366 krb5_creds creds, *new_creds = NULL;
367 char *service_s = NULL;
368 char *machine_account = NULL, *password = NULL;
369 krb5_data in_data;
370 krb5_auth_context auth_context = NULL;
371 krb5_error_code err = 0;
373 ZERO_STRUCT(creds);
375 asprintf(&machine_account, "%s$@%s", global_myname(), lp_realm());
376 if (machine_account == NULL) {
377 goto out;
379 password = secrets_fetch_machine_password(lp_workgroup(), NULL, NULL);
380 if (password == NULL) {
381 goto out;
383 if ((err = kerberos_kinit_password(machine_account, password,
384 0, LIBADS_CCACHE_NAME)) != 0) {
385 DEBUG(0,("get_service_ticket: kerberos_kinit_password %s failed: %s\n",
386 machine_account,
387 error_message(err)));
388 goto out;
391 /* Ok - the above call has gotten a TGT. Now we need to get a service
392 ticket to ourselves. */
394 /* Set up the enctype and client and server principal fields for krb5_get_credentials. */
395 kerberos_set_creds_enctype(&creds, enctype);
397 if ((err = krb5_cc_get_principal(ctx, ccache, &creds.client))) {
398 DEBUG(3, ("get_service_ticket: krb5_cc_get_principal failed: %s\n",
399 error_message(err)));
400 goto out;
403 if (strchr_m(service_principal, '@')) {
404 asprintf(&service_s, "%s", service_principal);
405 } else {
406 asprintf(&service_s, "%s@%s", service_principal, lp_realm());
409 if ((err = krb5_parse_name(ctx, service_s, &creds.server))) {
410 DEBUG(0,("get_service_ticket: krb5_parse_name %s failed: %s\n",
411 service_s, error_message(err)));
412 goto out;
415 if ((err = krb5_get_credentials(ctx, 0, ccache, &creds, &new_creds))) {
416 DEBUG(5,("get_service_ticket: krb5_get_credentials for %s enctype %d failed: %s\n",
417 service_s, enctype, error_message(err)));
418 goto out;
421 memset(&in_data, '\0', sizeof(in_data));
422 if ((err = krb5_mk_req_extended(ctx, &auth_context, 0, &in_data,
423 new_creds, p_outbuf)) != 0) {
424 DEBUG(0,("get_service_ticket: krb5_mk_req_extended failed: %s\n",
425 error_message(err)));
426 goto out;
429 out:
431 if (auth_context) {
432 krb5_auth_con_free(ctx, auth_context);
434 if (new_creds) {
435 krb5_free_creds(ctx, new_creds);
437 if (creds.server) {
438 krb5_free_principal(ctx, creds.server);
440 if (creds.client) {
441 krb5_free_principal(ctx, creds.client);
444 SAFE_FREE(service_s);
445 SAFE_FREE(password);
446 SAFE_FREE(machine_account);
447 return err;
450 /************************************************************************
451 Check if the machine password can be used in conjunction with the salting_principal
452 to generate a key which will successfully decrypt the AP_REQ already
453 gotten as a message to the local machine.
454 ************************************************************************/
456 static BOOL verify_service_password(krb5_context ctx,
457 int enctype,
458 const char *salting_principal,
459 krb5_data *in_data)
461 BOOL ret = False;
462 krb5_principal salting_kprinc = NULL;
463 krb5_ticket *ticket = NULL;
464 krb5_keyblock key;
465 krb5_data passdata;
466 char *salting_s = NULL;
467 char *machine_account = NULL, *password = NULL;
468 krb5_auth_context auth_context = NULL;
469 krb5_error_code err;
471 memset(&passdata, '\0', sizeof(passdata));
472 memset(&key, '\0', sizeof(key));
474 asprintf(&machine_account, "%s$@%s", global_myname(), lp_realm());
475 if (machine_account == NULL) {
476 goto out;
478 password = secrets_fetch_machine_password(lp_workgroup(), NULL, NULL);
479 if (password == NULL) {
480 goto out;
483 if (strchr_m(salting_principal, '@')) {
484 asprintf(&salting_s, "%s", salting_principal);
485 } else {
486 asprintf(&salting_s, "%s@%s", salting_principal, lp_realm());
489 if ((err = krb5_parse_name(ctx, salting_s, &salting_kprinc))) {
490 DEBUG(0,("verify_service_password: krb5_parse_name %s failed: %s\n",
491 salting_s, error_message(err)));
492 goto out;
495 passdata.length = strlen(password);
496 passdata.data = (char*)password;
497 if ((err = create_kerberos_key_from_string_direct(ctx, salting_kprinc, &passdata, &key, enctype))) {
498 DEBUG(0,("verify_service_password: create_kerberos_key_from_string %d failed: %s\n",
499 enctype, error_message(err)));
500 goto out;
503 if ((err = krb5_auth_con_init(ctx, &auth_context)) != 0) {
504 DEBUG(0,("verify_service_password: krb5_auth_con_init failed %s\n", error_message(err)));
505 goto out;
508 if ((err = krb5_auth_con_setuseruserkey(ctx, auth_context, &key)) != 0) {
509 DEBUG(0,("verify_service_password: krb5_auth_con_setuseruserkey failed %s\n", error_message(err)));
510 goto out;
513 if (!(err = krb5_rd_req(ctx, &auth_context, in_data, NULL, NULL, NULL, &ticket))) {
514 DEBUG(10,("verify_service_password: decrypted message with enctype %u salt %s!\n",
515 (unsigned int)enctype, salting_s));
516 ret = True;
519 out:
521 memset(&passdata, 0, sizeof(passdata));
522 krb5_free_keyblock_contents(ctx, &key);
523 if (ticket != NULL) {
524 krb5_free_ticket(ctx, ticket);
526 if (salting_kprinc) {
527 krb5_free_principal(ctx, salting_kprinc);
529 SAFE_FREE(salting_s);
530 SAFE_FREE(password);
531 SAFE_FREE(machine_account);
532 return ret;
535 /************************************************************************
537 * From the current draft of kerberos-clarifications:
539 * It is not possible to reliably generate a user's key given a pass
540 * phrase without contacting the KDC, since it will not be known
541 * whether alternate salt or parameter values are required.
543 * And because our server has a password, we have this exact problem. We
544 * make multiple guesses as to which principal name provides the salt which
545 * the KDC is using.
547 ************************************************************************/
549 static void kerberos_derive_salting_principal_for_enctype(const char *service_principal,
550 krb5_context ctx,
551 krb5_ccache ccache,
552 krb5_enctype enctype,
553 krb5_enctype *enctypes)
555 char *salting_principals[3] = {NULL, NULL, NULL}, *second_principal = NULL;
556 krb5_error_code err = 0;
557 krb5_data outbuf;
558 int i, j;
560 memset(&outbuf, '\0', sizeof(outbuf));
562 /* Check that the service_principal is useful. */
563 if ((service_principal == NULL) || (strlen(service_principal) == 0)) {
564 return;
567 /* Generate our first guess -- the principal as-given. */
568 asprintf(&salting_principals[0], "%s", service_principal);
569 if ((salting_principals[0] == NULL) || (strlen(salting_principals[0]) == 0)) {
570 return;
573 /* Generate our second guess -- the computer's principal, as Win2k3. */
574 asprintf(&second_principal, "host/%s.%s", global_myname(), lp_realm());
575 if (second_principal != NULL) {
576 strlower_m(second_principal);
577 asprintf(&salting_principals[1], "%s@%s", second_principal, lp_realm());
578 SAFE_FREE(second_principal);
580 if ((salting_principals[1] == NULL) || (strlen(salting_principals[1]) == 0)) {
581 goto out;
584 /* Generate our third guess -- the computer's principal, as Win2k. */
585 asprintf(&second_principal, "HOST/%s", global_myname());
586 if (second_principal != NULL) {
587 strlower_m(second_principal + 5);
588 asprintf(&salting_principals[2], "%s@%s",
589 second_principal, lp_realm());
590 SAFE_FREE(second_principal);
592 if ((salting_principals[2] == NULL) || (strlen(salting_principals[2]) == 0)) {
593 goto out;
596 /* Get a service ticket for ourselves into our memory ccache. */
597 /* This will commonly fail if there is no principal by that name (and we're trying
598 many names). So don't print a debug 0 error. */
600 if ((err = get_service_ticket(ctx, ccache, service_principal, enctype, &outbuf)) != 0) {
601 DEBUG(3, ("verify_service_password: get_service_ticket failed: %s\n",
602 error_message(err)));
603 goto out;
606 /* At this point we have a message to ourselves, salted only the KDC knows how. We
607 have to work out what that salting is. */
609 /* Try and find the correct salting principal. */
610 for (i = 0; i < sizeof(salting_principals) / sizeof(salting_principals[i]); i++) {
611 if (verify_service_password(ctx, enctype, salting_principals[i], &outbuf)) {
612 break;
616 /* If we failed to get a match, return. */
617 if (i >= sizeof(salting_principals) / sizeof(salting_principals[i])) {
618 goto out;
621 /* If we succeeded, store the principal for use for all enctypes which
622 * share the same cipher and string-to-key function. Doing this here
623 * allows servers which just pass a keytab to krb5_rd_req() to work
624 * correctly. */
625 for (j = 0; enctypes[j] != 0; j++) {
626 if (enctype != enctypes[j]) {
627 /* If this enctype isn't compatible with the one which
628 * we used, skip it. */
630 if (!kerberos_compatible_enctypes(ctx, enctypes[j], enctype))
631 continue;
633 /* If the principal which gives us the proper salt is the one
634 * which we would normally guess, don't bother noting anything
635 * in the secrets tdb. */
636 if (strcmp(service_principal, salting_principals[i]) != 0) {
637 kerberos_secrets_store_salting_principal(service_principal,
638 enctypes[j],
639 salting_principals[i]);
643 out :
645 kerberos_free_data_contents(ctx, &outbuf);
646 SAFE_FREE(salting_principals[0]);
647 SAFE_FREE(salting_principals[1]);
648 SAFE_FREE(salting_principals[2]);
649 SAFE_FREE(second_principal);
652 /************************************************************************
653 Go through all the possible enctypes for this principal.
654 ************************************************************************/
656 static void kerberos_derive_salting_principal_direct(krb5_context context,
657 krb5_ccache ccache,
658 krb5_enctype *enctypes,
659 char *service_principal)
661 int i;
663 /* Try for each enctype separately, because the rules are
664 * different for different enctypes. */
665 for (i = 0; enctypes[i] != 0; i++) {
666 /* Delete secrets entry first. */
667 kerberos_secrets_store_salting_principal(service_principal, 0, NULL);
668 #ifdef ENCTYPE_ARCFOUR_HMAC
669 if (enctypes[i] == ENCTYPE_ARCFOUR_HMAC) {
670 /* Of course this'll always work, so just save
671 * ourselves the effort. */
672 continue;
674 #endif
675 /* Try to figure out what's going on with this
676 * principal. */
677 kerberos_derive_salting_principal_for_enctype(service_principal,
678 context,
679 ccache,
680 enctypes[i],
681 enctypes);
685 /************************************************************************
686 Wrapper function for the above.
687 ************************************************************************/
689 BOOL kerberos_derive_salting_principal(char *service_principal)
691 krb5_context context = NULL;
692 krb5_enctype *enctypes = NULL;
693 krb5_ccache ccache = NULL;
694 krb5_error_code ret = 0;
696 initialize_krb5_error_table();
697 if ((ret = krb5_init_context(&context)) != 0) {
698 DEBUG(1,("kerberos_derive_cifs_salting_principals: krb5_init_context failed. %s\n",
699 error_message(ret)));
700 return False;
702 if ((ret = get_kerberos_allowed_etypes(context, &enctypes)) != 0) {
703 DEBUG(1,("kerberos_derive_cifs_salting_principals: get_kerberos_allowed_etypes failed. %s\n",
704 error_message(ret)));
705 goto out;
708 if ((ret = krb5_cc_resolve(context, LIBADS_CCACHE_NAME, &ccache)) != 0) {
709 DEBUG(3, ("get_service_ticket: krb5_cc_resolve for %s failed: %s\n",
710 LIBADS_CCACHE_NAME, error_message(ret)));
711 goto out;
714 kerberos_derive_salting_principal_direct(context, ccache, enctypes, service_principal);
716 out:
717 if (enctypes) {
718 free_kerberos_etypes(context, enctypes);
720 if (ccache) {
721 krb5_cc_destroy(context, ccache);
723 if (context) {
724 krb5_free_context(context);
727 return ret ? False : True;
730 /************************************************************************
731 Core function to try and determine what salt is being used for any keytab
732 keys.
733 ************************************************************************/
735 BOOL kerberos_derive_cifs_salting_principals(void)
737 fstring my_fqdn;
738 char *service = NULL;
739 krb5_context context = NULL;
740 krb5_enctype *enctypes = NULL;
741 krb5_ccache ccache = NULL;
742 krb5_error_code ret = 0;
743 BOOL retval = False;
745 initialize_krb5_error_table();
746 if ((ret = krb5_init_context(&context)) != 0) {
747 DEBUG(1,("kerberos_derive_cifs_salting_principals: krb5_init_context failed. %s\n",
748 error_message(ret)));
749 return False;
751 if ((ret = get_kerberos_allowed_etypes(context, &enctypes)) != 0) {
752 DEBUG(1,("kerberos_derive_cifs_salting_principals: get_kerberos_allowed_etypes failed. %s\n",
753 error_message(ret)));
754 goto out;
757 if ((ret = krb5_cc_resolve(context, LIBADS_CCACHE_NAME, &ccache)) != 0) {
758 DEBUG(3, ("get_service_ticket: krb5_cc_resolve for %s failed: %s\n",
759 LIBADS_CCACHE_NAME, error_message(ret)));
760 goto out;
763 if (asprintf(&service, "%s$", global_myname()) != -1) {
764 strlower_m(service);
765 kerberos_derive_salting_principal_direct(context, ccache, enctypes, service);
766 SAFE_FREE(service);
768 if (asprintf(&service, "cifs/%s", global_myname()) != -1) {
769 strlower_m(service);
770 kerberos_derive_salting_principal_direct(context, ccache, enctypes, service);
771 SAFE_FREE(service);
773 if (asprintf(&service, "host/%s", global_myname()) != -1) {
774 strlower_m(service);
775 kerberos_derive_salting_principal_direct(context, ccache, enctypes, service);
776 SAFE_FREE(service);
778 if (asprintf(&service, "cifs/%s.%s", global_myname(), lp_realm()) != -1) {
779 strlower_m(service);
780 kerberos_derive_salting_principal_direct(context, ccache, enctypes, service);
781 SAFE_FREE(service);
783 if (asprintf(&service, "host/%s.%s", global_myname(), lp_realm()) != -1) {
784 strlower_m(service);
785 kerberos_derive_salting_principal_direct(context, ccache, enctypes, service);
786 SAFE_FREE(service);
788 name_to_fqdn(my_fqdn, global_myname());
789 if (asprintf(&service, "cifs/%s", my_fqdn) != -1) {
790 strlower_m(service);
791 kerberos_derive_salting_principal_direct(context, ccache, enctypes, service);
792 SAFE_FREE(service);
794 if (asprintf(&service, "host/%s", my_fqdn) != -1) {
795 strlower_m(service);
796 kerberos_derive_salting_principal_direct(context, ccache, enctypes, service);
797 SAFE_FREE(service);
800 retval = True;
802 out:
803 if (enctypes) {
804 free_kerberos_etypes(context, enctypes);
806 if (ccache) {
807 krb5_cc_destroy(context, ccache);
809 if (context) {
810 krb5_free_context(context);
812 return retval;
815 int kerberos_kinit_password(const char *principal,
816 const char *password,
817 int time_offset,
818 const char *cache_name)
820 return kerberos_kinit_password_ext(principal,
821 password,
822 time_offset,
825 cache_name,
826 False,
830 #endif