2 * Copyright (c) 1997-2007 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Portions Copyright (c) 2009 Apple Inc. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the Institute nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 #include "kuser_locl.h"
38 #ifdef HAVE_FRAMEWORK_SECURITY
39 #include <Security/Security.h>
47 #define SIGINFO SIGUSR1
50 int forwardable_flag
= -1;
51 int proxiable_flag
= -1;
52 int renewable_flag
= -1;
55 int validate_flag
= 0;
59 struct getarg_strings extra_addresses
;
60 int anonymous_flag
= 0;
61 char *lifetime
= NULL
;
62 char *renew_life
= NULL
;
63 char *server_str
= NULL
;
64 static krb5_principal tgs_service
;
65 char *cred_cache
= NULL
;
66 char *start_str
= NULL
;
67 static int default_for
= 0;
68 static int switch_cache_flags
= -1;
69 struct getarg_strings etype_str
;
71 char *keytab_str
= NULL
;
72 static krb5_keytab kt
= NULL
;
75 char *password_file
= NULL
;
76 char *pk_user_id
= NULL
;
77 int pk_enterprise_flag
= 0;
78 struct hx509_certs_data
*ent_user_id
= NULL
;
79 char *pk_x509_anchors
= NULL
;
80 int pk_use_enckey
= 0;
81 static int canonicalize_flag
= 0;
82 static int enterprise_flag
= 0;
83 static int ok_as_delegate_flag
= 0;
84 static char *fast_armor_cache_string
= NULL
;
85 static int use_referrals_flag
= 0;
86 static int windows_flag
= 0;
88 static char *ntlm_domain
;
92 static struct getargs args
[] = {
106 { "afslog", 0 , arg_flag
, &do_afslog
,
107 NP_("obtain afs tokens", ""), NULL
},
109 { "cache", 'c', arg_string
, &cred_cache
,
110 NP_("credentials cache", ""), "cachename" },
112 { "forwardable", 'F', arg_negative_flag
, &forwardable_flag
,
113 NP_("get tickets not forwardable", ""), NULL
},
115 { NULL
, 'f', arg_flag
, &forwardable_flag
,
116 NP_("get forwardable tickets", ""), NULL
},
118 { "keytab", 't', arg_string
, &keytab_str
,
119 NP_("keytab to use", ""), "keytabname" },
121 { "lifetime", 'l', arg_string
, &lifetime
,
122 NP_("lifetime of tickets", ""), "time" },
124 { "proxiable", 'p', arg_flag
, &proxiable_flag
,
125 NP_("get proxiable tickets", ""), NULL
},
127 { "renew", 'R', arg_flag
, &renew_flag
,
128 NP_("renew TGT", ""), NULL
},
130 { "renewable", 0, arg_flag
, &renewable_flag
,
131 NP_("get renewable tickets", ""), NULL
},
133 { "renewable-life", 'r', arg_string
, &renew_life
,
134 NP_("renewable lifetime of tickets", ""), "time" },
136 { "server", 'S', arg_string
, &server_str
,
137 NP_("server to get ticket for", ""), "principal" },
139 { "start-time", 's', arg_string
, &start_str
,
140 NP_("when ticket gets valid", ""), "time" },
142 { "use-keytab", 'k', arg_flag
, &use_keytab
,
143 NP_("get key from keytab", ""), NULL
},
145 { "validate", 'v', arg_flag
, &validate_flag
,
146 NP_("validate TGT", ""), NULL
},
148 { "enctypes", 'e', arg_strings
, &etype_str
,
149 NP_("encryption types to use", ""), "enctypes" },
151 { "fcache-version", 0, arg_integer
, &fcache_version
,
152 NP_("file cache version to create", ""), NULL
},
154 { "addresses", 'A', arg_negative_flag
, &addrs_flag
,
155 NP_("request a ticket with no addresses", ""), NULL
},
157 { "extra-addresses",'a', arg_strings
, &extra_addresses
,
158 NP_("include these extra addresses", ""), "addresses" },
160 { "anonymous", 'n', arg_flag
, &anonymous_flag
,
161 NP_("request an anonymous ticket", ""), NULL
},
163 { "request-pac", 0, arg_flag
, &pac_flag
,
164 NP_("request a Windows PAC", ""), NULL
},
166 { "password-file", 0, arg_string
, &password_file
,
167 NP_("read the password from a file", ""), NULL
},
169 { "canonicalize",0, arg_flag
, &canonicalize_flag
,
170 NP_("canonicalize client principal", ""), NULL
},
172 { "enterprise",0, arg_flag
, &enterprise_flag
,
173 NP_("parse principal as a KRB5-NT-ENTERPRISE name", ""), NULL
},
175 { "pk-enterprise", 0, arg_flag
, &pk_enterprise_flag
,
176 NP_("use enterprise name from certificate", ""), NULL
},
178 { "pk-user", 'C', arg_string
, &pk_user_id
,
179 NP_("principal's public/private/certificate identifier", ""), "id" },
181 { "x509-anchors", 'D', arg_string
, &pk_x509_anchors
,
182 NP_("directory with CA certificates", ""), "directory" },
184 { "pk-use-enckey", 0, arg_flag
, &pk_use_enckey
,
185 NP_("Use RSA encrypted reply (instead of DH)", ""), NULL
},
188 { "ntlm-domain", 0, arg_string
, &ntlm_domain
,
189 NP_("NTLM domain", ""), "domain" },
192 { "change-default", 0, arg_negative_flag
, &switch_cache_flags
,
193 NP_("switch the default cache to the new credentials cache", ""), NULL
},
195 { "default-for-principal", 0, arg_flag
, &default_for
,
196 NP_("Use a default cache appropriate for the client principal", ""), NULL
},
198 { "ok-as-delegate", 0, arg_flag
, &ok_as_delegate_flag
,
199 NP_("honor ok-as-delegate on tickets", ""), NULL
},
201 { "fast-armor-cache", 0, arg_string
, &fast_armor_cache_string
,
202 NP_("use this credential cache as FAST armor cache", ""), "cache" },
204 { "use-referrals", 0, arg_flag
, &use_referrals_flag
,
205 NP_("only use referrals, no dns canalisation", ""), NULL
},
207 { "windows", 0, arg_flag
, &windows_flag
,
208 NP_("get windows behavior", ""), NULL
},
210 { "version", 0, arg_flag
, &version_flag
, NULL
, NULL
},
211 { "help", 0, arg_flag
, &help_flag
, NULL
, NULL
}
215 get_default_realm(krb5_context context
);
220 arg_printusage_i18n(args
, sizeof(args
)/sizeof(*args
), N_("Usage: ", ""),
221 NULL
, "[principal [command]]", getarg_i18n
);
225 static krb5_error_code
226 tgs_principal(krb5_context context
,
228 krb5_principal client
,
229 krb5_const_realm tgs_realm
,
230 krb5_principal
*out_princ
)
233 krb5_principal tgs_princ
;
238 ret
= krb5_make_principal(context
, &tgs_princ
, tgs_realm
,
239 KRB5_TGS_NAME
, tgs_realm
, NULL
);
244 * Don't fail-over to a different realm just because a TGT expired
246 options
= KRB5_GC_CACHED
| KRB5_GC_EXPIRED_OK
;
248 memset(&creds
, 0, sizeof(creds
));
249 creds
.client
= client
;
250 creds
.server
= tgs_princ
;
251 ret
= krb5_get_credentials(context
, options
, cache
, &creds
, &tick
);
253 krb5_free_creds(context
, tick
);
254 *out_princ
= tgs_princ
;
256 krb5_free_principal(context
, tgs_princ
);
264 * Try TGS specified with '-S',
265 * then TGS of client realm,
266 * then if fallback is FALSE: fail,
267 * otherwise try TGS of default realm,
268 * and finally first TGT in ccache.
270 static krb5_error_code
271 get_server(krb5_context context
,
273 krb5_principal client
,
275 krb5_boolean fallback
,
276 krb5_principal
*princ
)
278 krb5_error_code ret
= 0;
279 krb5_const_realm realm
;
280 krb5_realm def_realm
;
281 krb5_cc_cursor cursor
;
289 ret
= krb5_parse_name(context
, server
, &tgs_service
);
293 /* Try the client realm first */
294 realm
= krb5_principal_get_realm(context
, client
);
295 ret
= tgs_principal(context
, cache
, client
, realm
, &tgs_service
);
296 if (ret
== 0 || ret
!= KRB5_CC_NOTFOUND
)
302 /* Next try the default realm */
303 ret
= krb5_get_default_realm(context
, &def_realm
);
306 ret
= tgs_principal(context
, cache
, client
, def_realm
, &tgs_service
);
308 if (ret
== 0 || ret
!= KRB5_CC_NOTFOUND
)
311 /* Finally try the first TGT with instance == realm in the cache */
312 ret
= krb5_cc_start_seq_get(context
, cache
, &cursor
);
316 for (/**/; ret
== 0; krb5_free_cred_contents (context
, &creds
)) {
318 ret
= krb5_cc_next_cred(context
, cache
, &cursor
, &creds
);
321 if (creds
.server
->name
.name_string
.len
!= 2)
323 pcomp
= krb5_principal_get_comp_string(context
, creds
.server
, 0);
324 if (strcmp(pcomp
, KRB5_TGS_NAME
) != 0)
326 realm
= krb5_principal_get_realm(context
, creds
.server
);
327 pcomp
= krb5_principal_get_comp_string(context
, creds
.server
, 1);
328 if (strcmp(realm
, pcomp
) != 0)
330 ret
= krb5_copy_principal(context
, creds
.server
, &tgs_service
);
333 if (ret
== KRB5_CC_END
) {
334 ret
= KRB5_CC_NOTFOUND
;
335 krb5_set_error_message(context
, ret
,
336 N_("Credential cache contains no TGTs", ""));
338 krb5_cc_end_seq_get(context
, cache
, &cursor
);
342 ret
= krb5_copy_principal(context
, tgs_service
, princ
);
346 static krb5_error_code
347 copy_configs(krb5_context context
,
350 krb5_principal start_ticket_server
)
353 const char *cfg_names
[] = {"realm-config", "FriendlyName", "anon_pkinit_realm", NULL
};
354 const char *cfg_names_w_pname
[] = {"fast_avail", NULL
};
358 for (i
= 0; cfg_names
[i
]; i
++) {
359 ret
= krb5_cc_get_config(context
, src
, NULL
, cfg_names
[i
], &cfg_data
);
360 if (ret
== KRB5_CC_NOTFOUND
|| ret
== KRB5_CC_END
) {
363 krb5_warn(context
, ret
, "krb5_cc_get_config");
366 ret
= krb5_cc_set_config(context
, dst
, NULL
, cfg_names
[i
], &cfg_data
);
368 krb5_warn(context
, ret
, "krb5_cc_set_config");
370 for (i
= 0; start_ticket_server
&& cfg_names_w_pname
[i
]; i
++) {
371 ret
= krb5_cc_get_config(context
, src
, start_ticket_server
,
372 cfg_names_w_pname
[i
], &cfg_data
);
373 if (ret
== KRB5_CC_NOTFOUND
|| ret
== KRB5_CC_END
) {
376 krb5_warn(context
, ret
, "krb5_cc_get_config");
379 ret
= krb5_cc_set_config(context
, dst
, start_ticket_server
,
380 cfg_names_w_pname
[i
], &cfg_data
);
381 if (ret
&& ret
!= KRB5_CC_NOTFOUND
)
382 krb5_warn(context
, ret
, "krb5_cc_set_config");
385 * We don't copy cc configs for any other principals though (mostly
386 * those are per-target time offsets and the like, so it's bad to
387 * lose them, but hardly the end of the world, and as they may not
388 * expire anyways, it's good to let them go).
393 static krb5_error_code
394 get_anon_pkinit_tgs_name(krb5_context context
,
396 krb5_principal
*tgs_name
)
402 ret
= krb5_cc_get_config(context
, ccache
, NULL
, "anon_pkinit_realm", &data
);
404 realm
= strndup(data
.data
, data
.length
);
406 realm
= get_default_realm(context
);
408 krb5_data_free(&data
);
411 return krb5_enomem(context
);
413 ret
= krb5_make_principal(context
, tgs_name
, realm
,
414 KRB5_TGS_NAME
, realm
, NULL
);
421 static krb5_error_code
422 renew_validate(krb5_context context
,
426 krb5_const_principal principal
,
427 krb5_boolean cache_is_default_for
,
432 krb5_ccache tempccache
= NULL
;
433 krb5_ccache cache
= *cachep
;
434 krb5_creds in
, *out
= NULL
;
435 krb5_kdc_flags flags
;
437 memset(&in
, 0, sizeof(in
));
439 ret
= krb5_cc_get_principal(context
, cache
, &in
.client
);
440 if (ret
&& cache_is_default_for
&& principal
) {
441 krb5_error_code ret2
;
442 krb5_ccache def_ccache
= NULL
;
444 ret2
= krb5_cc_default(context
, &def_ccache
);
446 ret2
= krb5_cc_get_principal(context
, def_ccache
, &in
.client
);
448 krb5_principal_compare(context
, principal
, in
.client
)) {
449 krb5_cc_close(context
, *cachep
);
450 cache
= *cachep
= def_ccache
;
454 krb5_cc_close(context
, def_ccache
);
457 krb5_warn(context
, ret
, "krb5_cc_get_principal");
461 if (principal
&& !krb5_principal_compare(context
, principal
, in
.client
)) {
464 (void) krb5_cc_get_full_name(context
, cache
, &ccname
);
465 krb5_errx(context
, 1, "Credentials in cache %s do not match requested "
466 "principal", ccname
? ccname
: "requested");
470 if (server
== NULL
&&
471 krb5_principal_is_anonymous(context
, in
.client
,
472 KRB5_ANON_MATCH_UNAUTHENTICATED
))
473 ret
= get_anon_pkinit_tgs_name(context
, cache
, &in
.server
);
475 ret
= get_server(context
, cache
, in
.client
, server
, TRUE
, &in
.server
);
477 krb5_warn(context
, ret
, "get_server");
483 * no need to check the error here, it's only to be
484 * friendly to the user
486 krb5_get_credentials(context
, KRB5_GC_CACHED
, cache
, &in
, &out
);
490 flags
.b
.renewable
= flags
.b
.renew
= renew
;
491 flags
.b
.validate
= validate
;
493 if (forwardable_flag
!= -1)
494 flags
.b
.forwardable
= forwardable_flag
;
496 flags
.b
.forwardable
= out
->flags
.b
.forwardable
;
498 if (proxiable_flag
!= -1)
499 flags
.b
.proxiable
= proxiable_flag
;
501 flags
.b
.proxiable
= out
->flags
.b
.proxiable
;
504 flags
.b
.request_anonymous
= anonymous_flag
;
506 in
.times
.endtime
= time(NULL
) + life
;
509 krb5_free_creds(context
, out
);
514 ret
= krb5_get_kdc_cred(context
,
522 krb5_warn(context
, ret
, "krb5_get_kdc_cred");
526 ret
= krb5_cc_new_unique(context
, krb5_cc_get_type(context
, cache
),
529 krb5_warn(context
, ret
, "krb5_cc_new_unique");
533 ret
= krb5_cc_initialize(context
, tempccache
, in
.client
);
535 krb5_warn(context
, ret
, "krb5_cc_initialize");
539 ret
= krb5_cc_store_cred(context
, tempccache
, out
);
541 krb5_warn(context
, ret
, "krb5_cc_store_cred");
546 * We want to preserve cc configs as some are security-relevant, and
547 * anyways it's the friendly thing to do.
549 ret
= copy_configs(context
, tempccache
, cache
, out
->server
);
553 ret
= krb5_cc_move(context
, tempccache
, cache
);
555 krb5_warn(context
, ret
, "krb5_cc_move");
562 krb5_cc_destroy(context
, tempccache
);
564 krb5_free_creds(context
, out
);
565 krb5_free_cred_contents(context
, &in
);
571 static krb5_error_code
572 store_ntlmkey(krb5_context context
, krb5_ccache id
,
573 const char *domain
, struct ntlm_buf
*buf
)
580 ret
= krb5_cc_get_config(context
, id
, NULL
, "default-ntlm-domain", &data
);
582 krb5_data_free(&data
);
584 data
.length
= strlen(domain
);
585 data
.data
= rk_UNCONST(domain
);
586 ret
= krb5_cc_set_config(context
, id
, NULL
, "default-ntlm-domain", &data
);
591 aret
= asprintf(&name
, "ntlm-key-%s", domain
);
592 if (aret
== -1 || name
== NULL
)
593 return krb5_enomem(context
);
595 data
.length
= buf
->length
;
596 data
.data
= buf
->data
;
598 ret
= krb5_cc_set_config(context
, id
, NULL
, name
, &data
);
604 static krb5_error_code
605 get_new_tickets(krb5_context context
,
606 krb5_principal principal
,
608 krb5_deltat ticket_life
,
610 int anonymous_pkinit
)
615 krb5_deltat start_time
= 0;
616 krb5_deltat renew
= 0;
617 const char *renewstr
= NULL
;
618 krb5_enctype
*enctype
= NULL
;
619 krb5_ccache tempccache
= NULL
;
620 krb5_init_creds_context ctx
= NULL
;
621 krb5_get_init_creds_opt
*opt
= NULL
;
622 krb5_prompter_fct prompter
= krb5_prompter_posix
;
624 struct ntlm_buf ntlmkey
;
625 memset(&ntlmkey
, 0, sizeof(ntlmkey
));
635 if (strcasecmp("STDIN", password_file
) == 0)
638 f
= fopen(password_file
, "r");
640 krb5_warnx(context
, N_("Failed to open the password file %s", ""),
645 if (fgets(passwd
, sizeof(passwd
), f
) == NULL
) {
646 krb5_warnx(context
, N_("Failed to read password from file %s", ""),
650 return EINVAL
; /* XXX Need a better error */
654 passwd
[strcspn(passwd
, "\n")] = '\0';
657 #ifdef HAVE_FRAMEWORK_SECURITY
658 if (passwd
[0] == '\0') {
665 realm
= krb5_principal_get_realm(context
, principal
);
667 ret
= krb5_unparse_name_flags(context
, principal
,
668 KRB5_PRINCIPAL_UNPARSE_NO_REALM
, &name
);
672 osret
= SecKeychainFindGenericPassword(NULL
, strlen(realm
), realm
,
674 &length
, &buffer
, NULL
);
676 if (osret
== noErr
&& length
< sizeof(passwd
) - 1) {
677 memcpy(passwd
, buffer
, length
);
678 passwd
[length
] = '\0';
685 memset(&cred
, 0, sizeof(cred
));
687 ret
= krb5_get_init_creds_opt_alloc(context
, &opt
);
689 krb5_warn(context
, ret
, "krb5_get_init_creds_opt_alloc");
693 krb5_get_init_creds_opt_set_default_flags(context
, "kinit",
694 krb5_principal_get_realm(context
, principal
), opt
);
696 if (forwardable_flag
!= -1)
697 krb5_get_init_creds_opt_set_forwardable(opt
, forwardable_flag
);
698 if (proxiable_flag
!= -1)
699 krb5_get_init_creds_opt_set_proxiable(opt
, proxiable_flag
);
701 krb5_get_init_creds_opt_set_anonymous(opt
, anonymous_flag
);
703 krb5_get_init_creds_opt_set_pac_request(context
, opt
,
704 pac_flag
? TRUE
: FALSE
);
705 if (canonicalize_flag
)
706 krb5_get_init_creds_opt_set_canonicalize(context
, opt
, TRUE
);
707 if (pk_enterprise_flag
|| enterprise_flag
|| canonicalize_flag
|| windows_flag
)
708 krb5_get_init_creds_opt_set_win2k(context
, opt
, TRUE
);
709 if (pk_user_id
|| ent_user_id
|| anonymous_pkinit
) {
710 ret
= krb5_get_init_creds_opt_set_pkinit(context
, opt
,
716 pk_use_enckey
? KRB5_GIC_OPT_PKINIT_USE_ENCKEY
: 0 |
717 anonymous_pkinit
? KRB5_GIC_OPT_PKINIT_ANONYMOUS
: 0,
722 krb5_warn(context
, ret
, "krb5_get_init_creds_opt_set_pkinit");
726 krb5_get_init_creds_opt_set_pkinit_user_certs(context
, opt
, ent_user_id
);
729 if (addrs_flag
!= -1)
730 krb5_get_init_creds_opt_set_addressless(context
, opt
,
731 addrs_flag
? FALSE
: TRUE
);
733 if (renew_life
== NULL
&& renewable_flag
)
734 renewstr
= "6 months";
736 renewstr
= renew_life
;
738 renew
= parse_time(renewstr
, "s");
740 errx(1, "unparsable time: %s", renewstr
);
742 krb5_get_init_creds_opt_set_renew_life(opt
, renew
);
745 if (ticket_life
!= 0)
746 krb5_get_init_creds_opt_set_tkt_life(opt
, ticket_life
);
749 int tmp
= parse_time(start_str
, "s");
751 errx(1, N_("unparsable time: %s", ""), start_str
);
756 if (etype_str
.num_strings
) {
759 enctype
= malloc(etype_str
.num_strings
* sizeof(*enctype
));
761 errx(1, "out of memory");
762 for(i
= 0; i
< etype_str
.num_strings
; i
++) {
763 ret
= krb5_string_to_enctype(context
,
764 etype_str
.strings
[i
],
767 errx(1, "unrecognized enctype: %s", etype_str
.strings
[i
]);
769 krb5_get_init_creds_opt_set_etype_list(opt
, enctype
,
770 etype_str
.num_strings
);
773 ret
= krb5_init_creds_init(context
, principal
, prompter
, NULL
, start_time
, opt
, &ctx
);
775 krb5_warn(context
, ret
, "krb5_init_creds_init");
780 ret
= krb5_init_creds_set_service(context
, ctx
, server_str
);
782 krb5_warn(context
, ret
, "krb5_init_creds_set_service");
787 if (fast_armor_cache_string
) {
790 ret
= krb5_cc_resolve(context
, fast_armor_cache_string
, &fastid
);
792 krb5_warn(context
, ret
, "krb5_cc_resolve(FAST cache)");
796 ret
= krb5_init_creds_set_fast_ccache(context
, ctx
, fastid
);
798 krb5_warn(context
, ret
, "krb5_init_creds_set_fast_ccache");
803 if (use_keytab
|| keytab_str
) {
804 ret
= krb5_init_creds_set_keytab(context
, ctx
, kt
);
806 krb5_warn(context
, ret
, "krb5_init_creds_set_keytab");
809 } else if (pk_user_id
|| ent_user_id
||
810 krb5_principal_is_anonymous(context
, principal
, KRB5_ANON_MATCH_ANY
)) {
812 } else if (!interactive
&& passwd
[0] == '\0') {
813 static int already_warned
= 0;
816 krb5_warnx(context
, "Not interactive, failed to get "
818 krb5_get_init_creds_opt_free(context
, opt
);
823 if (passwd
[0] == '\0') {
827 ret
= krb5_unparse_name(context
, principal
, &p
);
829 errx(1, "failed to generate passwd prompt: not enough memory");
831 aret
= asprintf(&prompt
, N_("%s's Password: ", ""), p
);
834 errx(1, "failed to generate passwd prompt: not enough memory");
836 if (UI_UTIL_read_pw_string(passwd
, sizeof(passwd
)-1, prompt
, 0)){
837 memset(passwd
, 0, sizeof(passwd
));
838 errx(1, "failed to read password");
844 ret
= krb5_init_creds_set_password(context
, ctx
, passwd
);
846 krb5_warn(context
, ret
, "krb5_init_creds_set_password");
852 ret
= krb5_init_creds_get(context
, ctx
);
855 if (ntlm_domain
&& passwd
[0])
856 heim_ntlm_nt_key(passwd
, &ntlmkey
);
858 memset_s(passwd
, sizeof(passwd
), 0, sizeof(passwd
));
863 case KRB5_LIBOS_PWDINTR
: /* don't print anything if it was just C-c:ed */
865 case KRB5KRB_AP_ERR_BAD_INTEGRITY
:
866 case KRB5KRB_AP_ERR_MODIFIED
:
867 case KRB5KDC_ERR_PREAUTH_FAILED
:
868 case KRB5_GET_IN_TKT_LOOP
:
869 krb5_warnx(context
, N_("Password incorrect", ""));
871 case KRB5KRB_AP_ERR_V4_REPLY
:
872 krb5_warnx(context
, N_("Looks like a Kerberos 4 reply", ""));
874 case KRB5KDC_ERR_KEY_EXPIRED
:
875 krb5_warnx(context
, N_("Password expired", ""));
878 krb5_warn(context
, ret
, "krb5_get_init_creds");
882 krb5_process_last_request(context
, opt
, ctx
);
884 ret
= krb5_init_creds_get_creds(context
, ctx
, &cred
);
886 krb5_warn(context
, ret
, "krb5_init_creds_get_creds");
890 if (ticket_life
!= 0) {
891 if (labs(cred
.times
.endtime
- cred
.times
.starttime
- ticket_life
) > 30) {
893 unparse_time_approx(cred
.times
.endtime
- cred
.times
.starttime
,
895 krb5_warnx(context
, N_("NOTICE: ticket lifetime is %s", ""), life
);
899 if (labs(cred
.times
.renew_till
- cred
.times
.starttime
- renew
) > 30) {
901 unparse_time_approx(cred
.times
.renew_till
- cred
.times
.starttime
,
904 N_("NOTICE: ticket renewable lifetime is %s", ""),
908 krb5_free_cred_contents(context
, &cred
);
910 ret
= krb5_cc_new_unique(context
, krb5_cc_get_type(context
, ccache
),
913 krb5_warn(context
, ret
, "krb5_cc_new_unique");
917 ret
= krb5_init_creds_store(context
, ctx
, tempccache
);
919 krb5_warn(context
, ret
, "krb5_init_creds_store");
923 krb5_init_creds_free(context
, ctx
);
926 ret
= krb5_cc_move(context
, tempccache
, ccache
);
928 krb5_warn(context
, ret
, "krb5_cc_move");
933 if (switch_cache_flags
)
934 krb5_cc_switch(context
, ccache
);
937 if (ntlm_domain
&& ntlmkey
.data
)
938 store_ntlmkey(context
, ccache
, ntlm_domain
, &ntlmkey
);
941 if (ok_as_delegate_flag
|| windows_flag
|| use_referrals_flag
) {
945 if (ok_as_delegate_flag
|| windows_flag
)
947 if (use_referrals_flag
|| windows_flag
)
953 krb5_cc_set_config(context
, ccache
, NULL
, "realm-config", &data
);
956 if (anonymous_pkinit
) {
959 data
.length
= strlen(principal
->realm
);
960 data
.data
= principal
->realm
;
962 krb5_cc_set_config(context
, ccache
, NULL
, "anon_pkinit_realm", &data
);
966 krb5_get_init_creds_opt_free(context
, opt
);
968 krb5_init_creds_free(context
, ctx
);
970 krb5_cc_destroy(context
, tempccache
);
979 ticket_lifetime(krb5_context context
, krb5_ccache cache
, krb5_principal client
,
980 const char *server
, time_t *renew
)
982 krb5_creds in_cred
, *cred
;
987 memset(&in_cred
, 0, sizeof(in_cred
));
992 ret
= krb5_cc_get_principal(context
, cache
, &in_cred
.client
);
994 krb5_warn(context
, ret
, "krb5_cc_get_principal");
998 /* Determine TGS principal without fallback */
999 ret
= get_server(context
, cache
, in_cred
.client
, server
, FALSE
,
1002 krb5_free_principal(context
, in_cred
.client
);
1003 krb5_warn(context
, ret
, "get_server");
1007 ret
= krb5_get_credentials(context
, KRB5_GC_CACHED
,
1008 cache
, &in_cred
, &cred
);
1009 krb5_free_principal(context
, in_cred
.client
);
1010 krb5_free_principal(context
, in_cred
.server
);
1012 krb5_warn(context
, ret
, "krb5_get_credentials");
1015 curtime
= time(NULL
);
1016 timeout
= cred
->times
.endtime
- curtime
;
1020 *renew
= cred
->times
.renew_till
- curtime
;
1024 krb5_free_creds(context
, cred
);
1028 static time_t expire
;
1030 static char siginfo_msg
[1024] = "No credentials\n";
1033 update_siginfo_msg(time_t exp
, const char *srv
)
1035 /* Note that exp is relative time */
1036 memset(siginfo_msg
, 0, sizeof(siginfo_msg
));
1037 memcpy(&siginfo_msg
, "Updating...\n", sizeof("Updating...\n"));
1040 snprintf(siginfo_msg
, sizeof(siginfo_msg
),
1041 N_("kinit: TGT expires in %llu seconds\n", ""),
1042 (unsigned long long)expire
);
1044 snprintf(siginfo_msg
, sizeof(siginfo_msg
),
1045 N_("kinit: Ticket for %s expired\n", ""), srv
);
1052 snprintf(siginfo_msg
, sizeof(siginfo_msg
),
1053 N_("kinit: TGT expired\n", ""));
1055 snprintf(siginfo_msg
, sizeof(siginfo_msg
),
1056 N_("kinit: Ticket for %s expired\n", ""), srv
);
1060 #ifdef HAVE_SIGACTION
1062 handle_siginfo(int sig
)
1064 struct iovec iov
[2];
1066 iov
[0].iov_base
= rk_UNCONST(siginfo_msg
);
1067 iov
[0].iov_len
= strlen(siginfo_msg
);
1068 iov
[1].iov_base
= "\n";
1071 writev(STDERR_FILENO
, iov
, sizeof(iov
)/sizeof(iov
[0]));
1076 krb5_context context
;
1078 krb5_principal principal
;
1079 krb5_deltat ticket_life
;
1080 krb5_deltat timeout
;
1081 int anonymous_pkinit
;
1085 renew_func(void *ptr
)
1087 krb5_error_code ret
;
1088 struct renew_ctx
*ctx
= ptr
;
1089 time_t renew_expire
;
1090 static time_t exp_delay
= 1;
1093 * NOTE: We count on the ccache implementation to notice changes to the
1094 * actual ccache filesystem/whatever objects. There should be no ccache
1095 * types for which this is not the case, but it might not hurt to
1096 * re-krb5_cc_resolve() after each successful renew_validate()/
1097 * get_new_tickets() call.
1100 expire
= ticket_lifetime(ctx
->context
, ctx
->ccache
, ctx
->principal
,
1101 server_str
, &renew_expire
);
1104 * When a keytab is available to obtain new tickets, if we are within
1105 * half of the original ticket lifetime of the renew limit, get a new
1106 * TGT instead of renewing the existing TGT. Note, ctx->ticket_life
1107 * is zero by default (without a '-l' option) and cannot be used to
1108 * set the time scale on which we decide whether we're "close to the
1111 if (use_keytab
|| keytab_str
)
1112 expire
+= ctx
->timeout
;
1113 if (renew_expire
> expire
) {
1114 ret
= renew_validate(ctx
->context
, 1, validate_flag
, &ctx
->ccache
,
1115 NULL
, FALSE
, server_str
, ctx
->ticket_life
);
1117 ret
= get_new_tickets(ctx
->context
, ctx
->principal
, ctx
->ccache
,
1118 ctx
->ticket_life
, 0, ctx
->anonymous_pkinit
);
1120 expire
= ticket_lifetime(ctx
->context
, ctx
->ccache
, ctx
->principal
,
1121 server_str
, &renew_expire
);
1124 if (ret
== 0 && server_str
== NULL
&& do_afslog
&& k_hasafs())
1125 krb5_afslog(ctx
->context
, ctx
->ccache
, NULL
, NULL
);
1128 update_siginfo_msg(expire
, server_str
);
1131 * If our tickets have expired and we been able to either renew them
1132 * or obtain new tickets, then we still call this function but we use
1133 * an exponential backoff. This should take care of the case where
1134 * we are using stored credentials but the KDC has been unavailable
1135 * for some reason...
1140 * We can't ask to keep spamming stderr but not syslog, so we warn
1143 if (exp_delay
== 1) {
1144 krb5_warnx(ctx
->context
, N_("NOTICE: Could not renew/refresh "
1147 if (exp_delay
< 7200)
1148 exp_delay
+= exp_delay
/ 2 + 1;
1153 return expire
/ 2 + 1;
1157 set_princ_realm(krb5_context context
,
1158 krb5_principal principal
,
1161 krb5_error_code ret
;
1163 if ((ret
= krb5_principal_set_realm(context
, principal
, realm
)) != 0)
1164 krb5_err(context
, 1, ret
, "krb5_principal_set_realm");
1168 parse_name_realm(krb5_context context
,
1172 krb5_principal
*princ
)
1174 krb5_error_code ret
;
1177 flags
|= KRB5_PRINCIPAL_PARSE_NO_DEF_REALM
;
1178 if ((ret
= krb5_parse_name_flags(context
, name
, flags
, princ
)) != 0)
1179 krb5_err(context
, 1, ret
, "krb5_parse_name_flags");
1180 if (realm
&& krb5_principal_get_realm(context
, *princ
) == NULL
)
1181 set_princ_realm(context
, *princ
, realm
);
1185 get_default_realm(krb5_context context
)
1188 krb5_error_code ret
;
1190 if ((ret
= krb5_get_default_realm(context
, &realm
)) != 0)
1191 krb5_err(context
, 1, ret
, "krb5_get_default_realm");
1196 get_default_principal(krb5_context context
, krb5_principal
*princ
)
1198 krb5_error_code ret
;
1200 if ((ret
= krb5_get_default_principal(context
, princ
)) != 0)
1201 krb5_err(context
, 1, ret
, "krb5_get_default_principal");
1205 get_user_realm(krb5_context context
)
1207 krb5_error_code ret
;
1208 char *user_realm
= NULL
;
1211 * If memory allocation fails, we don't try to use the wrong realm,
1212 * that will trigger misleading error messages complicate support.
1214 krb5_appdefault_string(context
, "kinit", NULL
, "user_realm", "",
1216 if (user_realm
== NULL
) {
1217 ret
= krb5_enomem(context
);
1218 krb5_err(context
, 1, ret
, "krb5_appdefault_string");
1221 if (*user_realm
== 0) {
1230 get_princ(krb5_context context
,
1231 krb5_principal
*principal
,
1235 krb5_error_code ret
= 0;
1241 krb5_ccache ccache
= NULL
;
1243 /* If credential cache provides a client principal, use that. */
1245 ret
= krb5_cc_resolve(context
, ccname
, &ccache
);
1247 ret
= krb5_cc_default(context
, &ccache
);
1249 ret
= krb5_cc_get_principal(context
, ccache
, principal
);
1250 krb5_cc_close(context
, ccache
);
1255 user_realm
= get_user_realm(context
);
1258 if (enterprise_flag
)
1259 parseflags
|= KRB5_PRINCIPAL_PARSE_ENTERPRISE
;
1261 parse_name_realm(context
, name
, parseflags
, user_realm
, &tmp
);
1263 if (user_realm
&& krb5_principal_get_num_comp(context
, tmp
) > 1) {
1264 /* Principal is instance qualified, reparse with default realm. */
1265 krb5_free_principal(context
, tmp
);
1266 parse_name_realm(context
, name
, parseflags
, NULL
, principal
);
1271 get_default_principal(context
, principal
);
1273 set_princ_realm(context
, *principal
, user_realm
);
1281 get_princ_kt(krb5_context context
,
1282 krb5_principal
*principal
,
1285 krb5_error_code ret
;
1288 krb5_kt_cursor cursor
;
1289 krb5_keytab_entry entry
;
1294 * If the credential cache exists and specifies a client principal,
1297 if (krb5_cc_default(context
, &ccache
) == 0) {
1298 ret
= krb5_cc_get_principal(context
, ccache
, principal
);
1299 krb5_cc_close(context
, ccache
);
1306 /* If the principal specifies an explicit realm, just use that. */
1307 int parseflags
= KRB5_PRINCIPAL_PARSE_NO_DEF_REALM
;
1309 parse_name_realm(context
, name
, parseflags
, NULL
, &tmp
);
1310 if (krb5_principal_get_realm(context
, tmp
) != NULL
) {
1315 /* Otherwise, search keytab for bare name of the default principal. */
1316 get_default_principal(context
, &tmp
);
1317 set_princ_realm(context
, tmp
, NULL
);
1320 def_realm
= get_default_realm(context
);
1322 ret
= krb5_kt_start_seq_get(context
, kt
, &cursor
);
1324 krb5_err(context
, 1, ret
, "krb5_kt_start_seq_get");
1327 krb5_kt_next_entry(context
, kt
, &entry
, &cursor
) == 0) {
1330 if (!krb5_principal_compare_any_realm(context
, tmp
, entry
.principal
))
1333 krb5_principal_compare(context
, *principal
, entry
.principal
))
1335 /* The default realm takes precedence */
1336 realm
= krb5_principal_get_realm(context
, entry
.principal
);
1337 if (*principal
&& strcmp(def_realm
, realm
) == 0) {
1338 krb5_free_principal(context
, *principal
);
1339 ret
= krb5_copy_principal(context
, entry
.principal
, principal
);
1343 ret
= krb5_copy_principal(context
, entry
.principal
, principal
);
1345 if (ret
!= 0 || (ret
= krb5_kt_end_seq_get(context
, kt
, &cursor
)) != 0)
1346 krb5_err(context
, 1, ret
, "get_princ_kt");
1349 parse_name_realm(context
, name
, 0, NULL
, principal
);
1351 krb5_err(context
, 1, KRB5_CC_NOTFOUND
, "get_princ_kt");
1354 krb5_free_principal(context
, tmp
);
1358 static krb5_error_code
1359 get_switched_ccache(krb5_context context
,
1361 krb5_principal principal
,
1362 krb5_ccache
*ccache
)
1364 krb5_error_code ret
;
1367 if (strcmp(type
, "API") == 0) {
1369 * Windows stores the default ccache name in the
1370 * registry which is shared across multiple logon
1371 * sessions for the same user. The API credential
1372 * cache provides a unique name space per logon
1373 * session. Therefore there is no need to generate
1374 * a unique ccache name. Instead use the principal
1375 * name. This provides a friendlier user experience.
1377 char * unparsed_name
;
1380 ret
= krb5_unparse_name(context
, principal
,
1383 krb5_err(context
, 1, ret
,
1384 N_("unparsing principal name", ""));
1386 ret
= asprintf(&cred_cache
, "API:%s", unparsed_name
);
1387 krb5_free_unparsed_name(context
, unparsed_name
);
1388 if (ret
== -1 || cred_cache
== NULL
)
1389 krb5_err(context
, 1, ret
,
1390 N_("building credential cache name", ""));
1392 ret
= krb5_cc_resolve(context
, cred_cache
, ccache
);
1394 } else if (strcmp(type
, "MSLSA") == 0) {
1396 * The Windows MSLSA cache when it is writeable
1397 * stores tickets for multiple client principals
1398 * in a single credential cache.
1400 ret
= krb5_cc_resolve(context
, "MSLSA:", ccache
);
1402 ret
= krb5_cc_new_unique(context
, type
, NULL
, ccache
);
1405 ret
= krb5_cc_new_unique(context
, type
, NULL
, ccache
);
1412 main(int argc
, char **argv
)
1414 krb5_error_code ret
;
1415 krb5_context context
;
1417 krb5_principal principal
= NULL
;
1419 krb5_deltat ticket_life
= 0;
1420 #ifdef HAVE_SIGACTION
1421 struct sigaction sa
;
1423 krb5_boolean unique_ccache
= FALSE
;
1424 krb5_boolean historical_anon_pkinit
= FALSE
;
1425 int anonymous_pkinit
= FALSE
;
1427 setprogname(argv
[0]);
1429 setlocale(LC_ALL
, "");
1430 bindtextdomain("heimdal_kuser", HEIMDAL_LOCALEDIR
);
1431 textdomain("heimdal_kuser");
1433 ret
= krb5_init_context(&context
);
1434 if (ret
== KRB5_CONFIG_BADFORMAT
)
1435 errx(1, "krb5_init_context failed to parse configuration file");
1437 errx(1, "krb5_init_context failed: %d", ret
);
1439 if (getarg(args
, sizeof(args
) / sizeof(args
[0]), argc
, argv
, &optidx
))
1446 print_version(NULL
);
1453 krb5_appdefault_boolean(context
, "kinit", NULL
, "historical_anon_pkinit",
1454 FALSE
, &historical_anon_pkinit
);
1457 * Open the keytab now, we use the keytab to determine the principal's
1458 * realm when the requested principal has no realm.
1460 if (use_keytab
|| keytab_str
) {
1462 ret
= krb5_kt_resolve(context
, keytab_str
, &kt
);
1464 ret
= krb5_kt_default(context
, &kt
);
1466 krb5_err(context
, 1, ret
, "resolving keytab");
1469 if (pk_enterprise_flag
) {
1470 ret
= krb5_pk_enterprise_cert(context
, pk_user_id
,
1471 argv
[0], &principal
,
1474 krb5_err(context
, 1, ret
, "krb5_pk_enterprise_certs");
1478 } else if (anonymous_flag
&& argc
&& argv
[0][0] == '@') {
1479 /* If principal argument as @REALM, try anonymous PKINIT */
1481 ret
= krb5_make_principal(context
, &principal
, &argv
[0][1],
1482 KRB5_WELLKNOWN_NAME
, KRB5_ANON_NAME
,
1485 krb5_err(context
, 1, ret
, "krb5_make_principal");
1486 krb5_principal_set_type(context
, principal
, KRB5_NT_WELLKNOWN
);
1487 anonymous_pkinit
= TRUE
;
1488 } else if (anonymous_flag
&& historical_anon_pkinit
) {
1489 char *realm
= argc
== 0 ? get_default_realm(context
) :
1490 argv
[0][0] == '@' ? &argv
[0][1] : argv
[0];
1492 ret
= krb5_make_principal(context
, &principal
, realm
,
1493 KRB5_WELLKNOWN_NAME
, KRB5_ANON_NAME
, NULL
);
1495 krb5_err(context
, 1, ret
, "krb5_make_principal");
1496 krb5_principal_set_type(context
, principal
, KRB5_NT_WELLKNOWN
);
1497 anonymous_pkinit
= TRUE
;
1498 } else if (use_keytab
|| keytab_str
) {
1499 get_princ_kt(context
, &principal
, argv
[0]);
1501 get_princ(context
, &principal
, cred_cache
, argv
[0]);
1505 krb5_set_fcache_version(context
, fcache_version
);
1507 if (renewable_flag
== -1)
1508 /* this seems somewhat pointless, but whatever */
1509 krb5_appdefault_boolean(context
, "kinit",
1510 krb5_principal_get_realm(context
, principal
),
1511 "renewable", FALSE
, &renewable_flag
);
1512 if (do_afslog
== -1)
1513 krb5_appdefault_boolean(context
, "kinit",
1514 krb5_principal_get_realm(context
, principal
),
1515 "afslog", TRUE
, &do_afslog
);
1520 * - use the given ccache
1521 * - use a new unique ccache for running a command with (in this case we
1522 * get to set KRB5CCNAME, so a new unique ccache makes sense)
1523 * - use the default ccache for the given principal as requested and do
1524 * not later switch the collection's default/primary to it
1525 * - use the default cache, possibly a new unique one that later gets
1528 * The important thing is that, except for the case where we're running a
1529 * command, we _can't set KRB5CCNAME_, and we can't expect the user to read
1530 * our output and figure out to set it (we could have an output-for-shell-
1531 * eval mode, like ssh-agent and such, but we don't). Therefore, in all
1532 * cases where we can't set KRB5CCNAME we must do something that makes
1533 * sense to the user, and that is to either initialize a given ccache, use
1534 * the default, or use a subsidiary ccache named after the principal whose
1535 * creds we're initializing.
1538 /* Use the given ccache */
1539 ret
= krb5_cc_resolve(context
, cred_cache
, &ccache
);
1540 } else if (argc
> 1) {
1544 * A command was given, so use a new unique ccache (and destroy it
1547 ret
= krb5_cc_new_unique(context
, NULL
, NULL
, &ccache
);
1549 krb5_err(context
, 1, ret
, "creating cred cache");
1550 snprintf(s
, sizeof(s
), "%s:%s",
1551 krb5_cc_get_type(context
, ccache
),
1552 krb5_cc_get_name(context
, ccache
));
1553 setenv("KRB5CCNAME", s
, 1);
1554 unique_ccache
= TRUE
;
1555 switch_cache_flags
= 0;
1556 } else if (default_for
) {
1557 ret
= krb5_cc_default_for(context
, principal
, &ccache
);
1558 if (switch_cache_flags
== -1)
1559 switch_cache_flags
= 0;
1561 ret
= krb5_cc_cache_match(context
, principal
, &ccache
);
1564 ret
= krb5_cc_default(context
, &ccache
);
1566 krb5_err(context
, 1, ret
,
1567 N_("resolving credentials cache", ""));
1570 * Check if the type support switching, and we do,
1571 * then do that instead over overwriting the current
1572 * default credential
1574 type
= krb5_cc_get_type(context
, ccache
);
1575 if (krb5_cc_support_switch(context
, type
) &&
1576 strcmp(type
, "FILE")) {
1577 krb5_cc_close(context
, ccache
);
1578 ret
= get_switched_ccache(context
, type
, principal
,
1581 unique_ccache
= TRUE
;
1586 krb5_err(context
, 1, ret
, N_("resolving credentials cache", ""));
1589 if (argc
> 1 && k_hasafs())
1594 int tmp
= parse_time(lifetime
, "s");
1596 errx(1, N_("unparsable time: %s", ""), lifetime
);
1601 if (addrs_flag
== 0 && extra_addresses
.num_strings
> 0)
1602 krb5_errx(context
, 1,
1603 N_("specifying both extra addresses and "
1604 "no addresses makes no sense", ""));
1607 krb5_addresses addresses
;
1608 memset(&addresses
, 0, sizeof(addresses
));
1609 for(i
= 0; i
< extra_addresses
.num_strings
; i
++) {
1610 ret
= krb5_parse_address(context
, extra_addresses
.strings
[i
],
1613 krb5_add_extra_addresses(context
, &addresses
);
1614 krb5_free_addresses(context
, &addresses
);
1617 free_getarg_strings(&extra_addresses
);
1620 if (renew_flag
|| validate_flag
) {
1621 ret
= renew_validate(context
, renew_flag
, validate_flag
,
1623 default_for
? TRUE
: FALSE
, server_str
,
1627 if (ret
== 0 && server_str
== NULL
&& do_afslog
&& k_hasafs())
1628 krb5_afslog(context
, ccache
, NULL
, NULL
);
1632 krb5_cc_destroy(context
, ccache
);
1636 ret
= get_new_tickets(context
, principal
, ccache
, ticket_life
,
1637 1, anonymous_pkinit
);
1640 krb5_cc_destroy(context
, ccache
);
1645 if (ret
== 0 && server_str
== NULL
&& do_afslog
&& k_hasafs())
1646 krb5_afslog(context
, ccache
, NULL
, NULL
);
1650 struct renew_ctx ctx
;
1653 timeout
= ticket_lifetime(context
, ccache
, principal
,
1654 server_str
, NULL
) / 2;
1656 ctx
.context
= context
;
1657 ctx
.ccache
= ccache
;
1658 ctx
.principal
= principal
;
1659 ctx
.ticket_life
= ticket_life
;
1660 ctx
.timeout
= timeout
;
1661 ctx
.anonymous_pkinit
= anonymous_pkinit
;
1663 #ifdef HAVE_SIGACTION
1664 memset(&sa
, 0, sizeof(sa
));
1665 sigemptyset(&sa
.sa_mask
);
1666 sa
.sa_handler
= handle_siginfo
;
1668 sigaction(SIGINFO
, &sa
, NULL
);
1671 ret
= simple_execvp_timed(argv
[1], argv
+1,
1672 renew_func
, &ctx
, timeout
);
1673 #define EX_NOEXEC 126
1674 #define EX_NOTFOUND 127
1675 if (ret
== EX_NOEXEC
)
1676 krb5_warnx(context
, N_("permission denied: %s", ""), argv
[1]);
1677 else if (ret
== EX_NOTFOUND
)
1678 krb5_warnx(context
, N_("command not found: %s", ""), argv
[1]);
1680 krb5_cc_destroy(context
, ccache
);
1686 krb5_cc_close(context
, ccache
);
1689 krb5_free_principal(context
, principal
);
1691 krb5_kt_close(context
, kt
);
1692 krb5_free_context(context
);