2 * Copyright (c) 1997-2007 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 #include "kuser_locl.h"
36 #ifndef HEIMDAL_SMALLER
37 #include "krb5-v4compat.h"
40 struct krb5_dh_moduli
;
41 struct AlgorithmIdentifier
;
42 struct _krb5_krb_auth_data
;
43 #include <krb5-private.h>
49 int forwardable_flag
= -1;
50 int proxiable_flag
= -1;
51 int renewable_flag
= -1;
54 int validate_flag
= 0;
58 struct getarg_strings extra_addresses
;
59 int anonymous_flag
= 0;
60 char *lifetime
= NULL
;
61 char *renew_life
= NULL
;
62 char *server_str
= NULL
;
63 char *cred_cache
= NULL
;
64 char *start_str
= NULL
;
65 static int switch_cache_flags
= 1;
66 struct getarg_strings etype_str
;
68 char *keytab_str
= NULL
;
70 #ifndef HEIMDAL_SMALLER
73 static char *krb4_cc_name
;
76 char *password_file
= NULL
;
77 char *pk_user_id
= NULL
;
78 int pk_enterprise_flag
= 0;
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 int use_referrals_flag
= 0;
85 static int windows_flag
= 0;
87 static char *ntlm_domain
;
91 static struct getargs args
[] = {
101 #ifndef HEIMDAL_SMALLER
102 { "524init", '4', arg_flag
, &get_v4_tgt
,
103 NP_("obtain version 4 TGT", "") },
105 { "524convert", '9', arg_flag
, &convert_524
,
106 NP_("only convert ticket to version 4", "") },
108 { "afslog", 0 , arg_flag
, &do_afslog
,
109 NP_("obtain afs tokens", "") },
111 { "cache", 'c', arg_string
, &cred_cache
,
112 NP_("credentials cache", ""), "cachename" },
114 { "forwardable", 'f', arg_flag
, &forwardable_flag
,
115 NP_("get forwardable tickets", "")},
117 { "keytab", 't', arg_string
, &keytab_str
,
118 NP_("keytab to use", ""), "keytabname" },
120 { "lifetime", 'l', arg_string
, &lifetime
,
121 NP_("lifetime of tickets", ""), "time"},
123 { "proxiable", 'p', arg_flag
, &proxiable_flag
,
124 NP_("get proxiable tickets", "") },
126 { "renew", 'R', arg_flag
, &renew_flag
,
127 NP_("renew TGT", "") },
129 { "renewable", 0, arg_flag
, &renewable_flag
,
130 NP_("get renewable tickets", "") },
132 { "renewable-life", 'r', arg_string
, &renew_life
,
133 NP_("renewable lifetime of tickets", ""), "time" },
135 { "server", 'S', arg_string
, &server_str
,
136 NP_("server to get ticket for", ""), "principal" },
138 { "start-time", 's', arg_string
, &start_str
,
139 NP_("when ticket gets valid", ""), "time" },
141 { "use-keytab", 'k', arg_flag
, &use_keytab
,
142 NP_("get key from keytab", "") },
144 { "validate", 'v', arg_flag
, &validate_flag
,
145 NP_("validate TGT", "") },
147 { "enctypes", 'e', arg_strings
, &etype_str
,
148 NP_("encryption types to use", ""), "enctypes" },
150 { "fcache-version", 0, arg_integer
, &fcache_version
,
151 NP_("file cache version to create", "") },
153 { "addresses", 'A', arg_negative_flag
, &addrs_flag
,
154 NP_("request a ticket with no addresses", "") },
156 { "extra-addresses",'a', arg_strings
, &extra_addresses
,
157 NP_("include these extra addresses", ""), "addresses" },
159 { "anonymous", 0, arg_flag
, &anonymous_flag
,
160 NP_("request an anonymous ticket", "") },
162 { "request-pac", 0, arg_flag
, &pac_flag
,
163 NP_("request a Windows PAC", "") },
165 { "password-file", 0, arg_string
, &password_file
,
166 NP_("read the password from a file", "") },
168 { "canonicalize",0, arg_flag
, &canonicalize_flag
,
169 NP_("canonicalize client principal", "") },
171 { "enterprise",0, arg_flag
, &enterprise_flag
,
172 NP_("parse principal as a KRB5-NT-ENTERPRISE name", "") },
174 { "pk-enterprise", 0, arg_flag
, &pk_enterprise_flag
,
175 NP_("use enterprise name from certificate", "") },
177 { "pk-user", 'C', arg_string
, &pk_user_id
,
178 NP_("principal's public/private/certificate identifier", ""), "id" },
180 { "x509-anchors", 'D', arg_string
, &pk_x509_anchors
,
181 NP_("directory with CA certificates", ""), "directory" },
183 { "pk-use-enckey", 0, arg_flag
, &pk_use_enckey
,
184 NP_("Use RSA encrypted reply (instead of DH)", "") },
187 { "ntlm-domain", 0, arg_string
, &ntlm_domain
,
188 NP_("NTLM domain", ""), "domain" },
191 { "change-default", 0, arg_negative_flag
, &switch_cache_flags
,
192 NP_("switch the default cache to the new credentials cache", "") },
194 { "ok-as-delegate", 0, arg_flag
, &ok_as_delegate_flag
,
195 NP_("honor ok-as-delegate on tickets", "") },
197 { "use-referrals", 0, arg_flag
, &use_referrals_flag
,
198 NP_("only use referrals, no dns canalisation", "") },
200 { "windows", 0, arg_flag
, &windows_flag
,
201 NP_("get windows behavior", "") },
203 { "version", 0, arg_flag
, &version_flag
},
204 { "help", 0, arg_flag
, &help_flag
}
210 arg_printusage_i18n (args
,
211 sizeof(args
)/sizeof(*args
),
214 "[principal [command]]",
219 static krb5_error_code
220 get_server(krb5_context context
,
221 krb5_principal client
,
223 krb5_principal
*princ
)
225 krb5_const_realm realm
;
227 return krb5_parse_name(context
, server
, princ
);
229 realm
= krb5_principal_get_realm(context
, client
);
230 return krb5_make_principal(context
, princ
, realm
,
231 KRB5_TGS_NAME
, realm
, NULL
);
234 #ifndef HEIMDAL_SMALLER
236 static krb5_error_code
237 do_524init(krb5_context context
, krb5_ccache ccache
,
238 krb5_creds
*creds
, const char *server
)
242 struct credentials c
;
243 krb5_creds in_creds
, *real_creds
;
248 krb5_principal client
;
249 krb5_cc_get_principal(context
, ccache
, &client
);
250 memset(&in_creds
, 0, sizeof(in_creds
));
251 ret
= get_server(context
, client
, server
, &in_creds
.server
);
253 krb5_free_principal(context
, client
);
256 in_creds
.client
= client
;
257 ret
= krb5_get_credentials(context
, 0, ccache
, &in_creds
, &real_creds
);
258 krb5_free_principal(context
, client
);
259 krb5_free_principal(context
, in_creds
.server
);
263 ret
= krb524_convert_creds_kdc_ccache(context
, ccache
, real_creds
, &c
);
265 krb5_warn(context
, ret
, "converting creds");
267 krb5_error_code tret
= _krb5_krb_tf_setup(context
, &c
, NULL
, 0);
269 krb5_warn(context
, tret
, "saving v4 creds");
273 krb5_free_creds(context
, real_creds
);
274 memset(&c
, 0, sizeof(c
));
282 renew_validate(krb5_context context
,
290 krb5_creds in
, *out
= NULL
;
291 krb5_kdc_flags flags
;
293 memset(&in
, 0, sizeof(in
));
295 ret
= krb5_cc_get_principal(context
, cache
, &in
.client
);
297 krb5_warn(context
, ret
, "krb5_cc_get_principal");
300 ret
= get_server(context
, in
.client
, server
, &in
.server
);
302 krb5_warn(context
, ret
, "get_server");
308 * no need to check the error here, it's only to be
309 * friendly to the user
311 krb5_get_credentials(context
, KRB5_GC_CACHED
, cache
, &in
, &out
);
315 flags
.b
.renewable
= flags
.b
.renew
= renew
;
316 flags
.b
.validate
= validate
;
318 if (forwardable_flag
!= -1)
319 flags
.b
.forwardable
= forwardable_flag
;
321 flags
.b
.forwardable
= out
->flags
.b
.forwardable
;
323 if (proxiable_flag
!= -1)
324 flags
.b
.proxiable
= proxiable_flag
;
326 flags
.b
.proxiable
= out
->flags
.b
.proxiable
;
329 flags
.b
.request_anonymous
= anonymous_flag
;
331 in
.times
.endtime
= time(NULL
) + life
;
334 krb5_free_creds (context
, out
);
339 ret
= krb5_get_kdc_cred(context
,
347 krb5_warn(context
, ret
, "krb5_get_kdc_cred");
350 ret
= krb5_cc_initialize(context
, cache
, in
.client
);
352 krb5_free_creds (context
, out
);
353 krb5_warn(context
, ret
, "krb5_cc_initialize");
356 ret
= krb5_cc_store_cred(context
, cache
, out
);
358 if(ret
== 0 && server
== NULL
) {
359 /* only do this if it's a general renew-my-tgt request */
360 #ifndef HEIMDAL_SMALLER
362 do_524init(context
, cache
, out
, NULL
);
365 if(do_afslog
&& k_hasafs())
366 krb5_afslog(context
, cache
, NULL
, NULL
);
370 krb5_free_creds (context
, out
);
372 krb5_warn(context
, ret
, "krb5_cc_store_cred");
376 krb5_free_cred_contents(context
, &in
);
382 static krb5_error_code
383 store_ntlmkey(krb5_context context
, krb5_ccache id
,
384 const char *domain
, struct ntlm_buf
*buf
)
390 asprintf(&name
, "ntlm-key-%s", domain
);
392 krb5_clear_error_message(context
);
396 data
.length
= buf
->length
;
397 data
.data
= buf
->data
;
399 ret
= krb5_cc_set_config(context
, id
, NULL
, name
, &data
);
405 static krb5_error_code
406 get_new_tickets(krb5_context context
,
407 krb5_principal principal
,
409 krb5_deltat ticket_life
,
413 krb5_get_init_creds_opt
*opt
;
416 krb5_deltat start_time
= 0;
417 krb5_deltat renew
= 0;
418 char *renewstr
= NULL
;
419 krb5_enctype
*enctype
= NULL
;
420 krb5_ccache tempccache
;
422 struct ntlm_buf ntlmkey
;
423 memset(&ntlmkey
, 0, sizeof(ntlmkey
));
430 if (strcasecmp("STDIN", password_file
) == 0)
433 f
= fopen(password_file
, "r");
435 krb5_errx(context
, 1, "Failed to open the password file %s",
438 if (fgets(passwd
, sizeof(passwd
), f
) == NULL
)
439 krb5_errx(context
, 1,
440 N_("Failed to read password from file %s", ""),
444 passwd
[strcspn(passwd
, "\n")] = '\0';
448 memset(&cred
, 0, sizeof(cred
));
450 ret
= krb5_get_init_creds_opt_alloc (context
, &opt
);
452 krb5_err(context
, 1, ret
, "krb5_get_init_creds_opt_alloc");
454 krb5_get_init_creds_opt_set_default_flags(context
, "kinit",
455 krb5_principal_get_realm(context
, principal
), opt
);
457 if(forwardable_flag
!= -1)
458 krb5_get_init_creds_opt_set_forwardable (opt
, forwardable_flag
);
459 if(proxiable_flag
!= -1)
460 krb5_get_init_creds_opt_set_proxiable (opt
, proxiable_flag
);
462 krb5_get_init_creds_opt_set_anonymous (opt
, anonymous_flag
);
464 krb5_get_init_creds_opt_set_pac_request(context
, opt
,
465 pac_flag
? TRUE
: FALSE
);
466 if (canonicalize_flag
)
467 krb5_get_init_creds_opt_set_canonicalize(context
, opt
, TRUE
);
468 if (pk_enterprise_flag
&& windows_flag
)
469 krb5_get_init_creds_opt_set_win2k(context
, opt
, TRUE
);
470 if (pk_user_id
|| anonymous_flag
) {
471 ret
= krb5_get_init_creds_opt_set_pkinit(context
, opt
,
477 pk_use_enckey
? 2 : 0 |
478 anonymous_flag
? 4 : 0,
483 krb5_err(context
, 1, ret
, "krb5_get_init_creds_opt_set_pkinit");
486 if (addrs_flag
!= -1)
487 krb5_get_init_creds_opt_set_addressless(context
, opt
,
488 addrs_flag
? FALSE
: TRUE
);
490 if (renew_life
== NULL
&& renewable_flag
)
491 renewstr
= "1 month";
493 renewstr
= renew_life
;
495 renew
= parse_time (renewstr
, "s");
497 errx (1, "unparsable time: %s", renewstr
);
499 krb5_get_init_creds_opt_set_renew_life (opt
, renew
);
503 krb5_get_init_creds_opt_set_tkt_life (opt
, ticket_life
);
506 int tmp
= parse_time (start_str
, "s");
508 errx (1, N_("unparsable time: %s", ""), start_str
);
513 if(etype_str
.num_strings
) {
516 enctype
= malloc(etype_str
.num_strings
* sizeof(*enctype
));
518 errx(1, "out of memory");
519 for(i
= 0; i
< etype_str
.num_strings
; i
++) {
520 ret
= krb5_string_to_enctype(context
,
521 etype_str
.strings
[i
],
524 errx(1, "unrecognized enctype: %s", etype_str
.strings
[i
]);
526 krb5_get_init_creds_opt_set_etype_list(opt
, enctype
,
527 etype_str
.num_strings
);
530 if(use_keytab
|| keytab_str
) {
533 ret
= krb5_kt_resolve(context
, keytab_str
, &kt
);
535 ret
= krb5_kt_default(context
, &kt
);
537 krb5_err (context
, 1, ret
, "resolving keytab");
538 ret
= krb5_get_init_creds_keytab (context
,
545 krb5_kt_close(context
, kt
);
546 } else if (pk_user_id
|| anonymous_flag
) {
547 ret
= krb5_get_init_creds_password (context
,
556 } else if (!interactive
) {
557 krb5_warnx(context
, "Not interactive, failed to get initial ticket");
558 krb5_get_init_creds_opt_free(context
, opt
);
562 if (passwd
[0] == '\0') {
565 krb5_unparse_name (context
, principal
, &p
);
566 asprintf (&prompt
, N_("%s's Password: ", ""), p
);
569 if (UI_UTIL_read_pw_string(passwd
, sizeof(passwd
)-1, prompt
, 0)){
570 memset(passwd
, 0, sizeof(passwd
));
577 ret
= krb5_get_init_creds_password (context
,
587 krb5_get_init_creds_opt_free(context
, opt
);
589 if (ntlm_domain
&& passwd
[0])
590 heim_ntlm_nt_key(passwd
, &ntlmkey
);
592 memset(passwd
, 0, sizeof(passwd
));
597 case KRB5_LIBOS_PWDINTR
: /* don't print anything if it was just C-c:ed */
599 case KRB5KRB_AP_ERR_BAD_INTEGRITY
:
600 case KRB5KRB_AP_ERR_MODIFIED
:
601 case KRB5KDC_ERR_PREAUTH_FAILED
:
602 krb5_errx(context
, 1, N_("Password incorrect", ""));
604 case KRB5KRB_AP_ERR_V4_REPLY
:
605 krb5_errx(context
, 1, N_("Looks like a Kerberos 4 reply", ""));
608 krb5_err(context
, 1, ret
, "krb5_get_init_creds");
611 if(ticket_life
!= 0) {
612 if(abs(cred
.times
.endtime
- cred
.times
.starttime
- ticket_life
) > 30) {
614 unparse_time_approx(cred
.times
.endtime
- cred
.times
.starttime
,
616 krb5_warnx(context
, N_("NOTICE: ticket lifetime is %s", ""), life
);
620 if(abs(cred
.times
.renew_till
- cred
.times
.starttime
- renew
) > 30) {
622 unparse_time_approx(cred
.times
.renew_till
- cred
.times
.starttime
,
625 N_("NOTICE: ticket renewable lifetime is %s", ""),
630 ret
= krb5_cc_new_unique(context
, krb5_cc_get_type(context
, ccache
),
633 krb5_err (context
, 1, ret
, "krb5_cc_new_unique");
635 ret
= krb5_cc_initialize (context
, tempccache
, cred
.client
);
637 krb5_err (context
, 1, ret
, "krb5_cc_initialize");
639 ret
= krb5_cc_store_cred (context
, tempccache
, &cred
);
641 krb5_err (context
, 1, ret
, "krb5_cc_store_cred");
643 krb5_free_cred_contents (context
, &cred
);
645 ret
= krb5_cc_move(context
, tempccache
, ccache
);
647 krb5_err (context
, 1, ret
, "krb5_cc_move");
649 if (switch_cache_flags
)
650 krb5_cc_switch(context
, ccache
);
653 if (ntlm_domain
&& ntlmkey
.data
)
654 store_ntlmkey(context
, ccache
, ntlm_domain
, &ntlmkey
);
657 if (ok_as_delegate_flag
|| windows_flag
|| use_referrals_flag
) {
661 if (ok_as_delegate_flag
|| windows_flag
)
663 if (use_referrals_flag
|| windows_flag
)
669 krb5_cc_set_config(context
, ccache
, NULL
, "realm-config", &data
);
680 ticket_lifetime(krb5_context context
, krb5_ccache cache
,
681 krb5_principal client
, const char *server
)
683 krb5_creds in_cred
, *cred
;
687 memset(&in_cred
, 0, sizeof(in_cred
));
689 ret
= krb5_cc_get_principal(context
, cache
, &in_cred
.client
);
691 krb5_warn(context
, ret
, "krb5_cc_get_principal");
694 ret
= get_server(context
, in_cred
.client
, server
, &in_cred
.server
);
696 krb5_free_principal(context
, in_cred
.client
);
697 krb5_warn(context
, ret
, "get_server");
701 ret
= krb5_get_credentials(context
, KRB5_GC_CACHED
,
702 cache
, &in_cred
, &cred
);
703 krb5_free_principal(context
, in_cred
.client
);
704 krb5_free_principal(context
, in_cred
.server
);
706 krb5_warn(context
, ret
, "krb5_get_credentials");
709 timeout
= cred
->times
.endtime
- cred
->times
.starttime
;
712 krb5_free_creds(context
, cred
);
717 krb5_context context
;
719 krb5_principal principal
;
720 krb5_deltat ticket_life
;
724 renew_func(void *ptr
)
726 struct renew_ctx
*ctx
= ptr
;
731 if (renewable_flag
) {
732 ret
= renew_validate(ctx
->context
, renewable_flag
, validate_flag
,
733 ctx
->ccache
, server_str
, ctx
->ticket_life
);
740 get_new_tickets(ctx
->context
, ctx
->principal
,
741 ctx
->ccache
, ctx
->ticket_life
, 0);
743 #ifndef HEIMDAL_SMALLER
744 if(get_v4_tgt
|| convert_524
)
745 do_524init(ctx
->context
, ctx
->ccache
, NULL
, server_str
);
748 if(do_afslog
&& k_hasafs())
749 krb5_afslog(ctx
->context
, ctx
->ccache
, NULL
, NULL
);
752 expire
= ticket_lifetime(ctx
->context
, ctx
->ccache
, ctx
->principal
,
758 main (int argc
, char **argv
)
761 krb5_context context
;
763 krb5_principal principal
;
765 krb5_deltat ticket_life
= 0;
768 setprogname (argv
[0]);
770 setlocale (LC_ALL
, "");
771 bindtextdomain ("heimdal_kuser", HEIMDAL_LOCALEDIR
);
772 textdomain("heimdal_kuser");
774 ret
= krb5_init_context (&context
);
775 if (ret
== KRB5_CONFIG_BADFORMAT
)
776 errx (1, "krb5_init_context failed to parse configuration file");
778 errx(1, "krb5_init_context failed: %d", ret
);
780 if(getarg(args
, sizeof(args
) / sizeof(args
[0]), argc
, argv
, &optidx
))
794 if (canonicalize_flag
|| enterprise_flag
)
795 parseflags
|= KRB5_PRINCIPAL_PARSE_ENTERPRISE
;
797 if (pk_enterprise_flag
) {
798 ret
= _krb5_pk_enterprise_cert(context
, pk_user_id
,
799 argv
[0], &principal
);
801 krb5_err(context
, 1, ret
, "krb5_pk_enterprise_certs");
803 } else if (anonymous_flag
) {
805 ret
= krb5_make_principal(context
, &principal
, argv
[0],
806 KRB5_WELLKNOWN_NAME
, KRB5_ANON_NAME
,
809 krb5_err(context
, 1, ret
, "krb5_build_principal");
810 krb5_principal_set_type(context
, principal
, KRB5_NT_WELLKNOWN
);
814 ret
= krb5_parse_name_flags (context
, argv
[0], parseflags
,
817 krb5_err (context
, 1, ret
, "krb5_parse_name");
819 ret
= krb5_get_default_principal (context
, &principal
);
821 krb5_err (context
, 1, ret
, "krb5_get_default_principal");
826 krb5_set_fcache_version(context
, fcache_version
);
828 if(renewable_flag
== -1)
829 /* this seems somewhat pointless, but whatever */
830 krb5_appdefault_boolean(context
, "kinit",
831 krb5_principal_get_realm(context
, principal
),
832 "renewable", FALSE
, &renewable_flag
);
833 #ifndef HEIMDAL_SMALLER
835 krb5_appdefault_boolean(context
, "kinit",
836 krb5_principal_get_realm(context
, principal
),
837 "krb4_get_tickets", FALSE
, &get_v4_tgt
);
840 krb5_appdefault_boolean(context
, "kinit",
841 krb5_principal_get_realm(context
, principal
),
842 "afslog", TRUE
, &do_afslog
);
845 ret
= krb5_cc_resolve(context
, cred_cache
, &ccache
);
849 ret
= krb5_cc_new_unique(context
, NULL
, NULL
, &ccache
);
851 krb5_err(context
, 1, ret
, "creating cred cache");
852 snprintf(s
, sizeof(s
), "%s:%s",
853 krb5_cc_get_type(context
, ccache
),
854 krb5_cc_get_name(context
, ccache
));
855 setenv("KRB5CCNAME", s
, 1);
856 #ifndef HEIMDAL_SMALLER
859 if (asprintf(&krb4_cc_name
, "%s_XXXXXX", TKT_ROOT
) < 0)
860 krb5_errx(context
, 1, "out of memory");
861 if((fd
= mkstemp(krb4_cc_name
)) >= 0) {
863 setenv("KRBTKFILE", krb4_cc_name
, 1);
871 ret
= krb5_cc_cache_match(context
, principal
, &ccache
);
873 ret
= krb5_cc_default (context
, &ccache
);
877 krb5_err (context
, 1, ret
, N_("resolving credentials cache", ""));
880 if(argc
> 1 && k_hasafs ())
885 int tmp
= parse_time (lifetime
, "s");
887 errx (1, N_("unparsable time: %s", ""), lifetime
);
892 if(addrs_flag
== 0 && extra_addresses
.num_strings
> 0)
893 krb5_errx(context
, 1,
894 N_("specifying both extra addresses and "
895 "no addresses makes no sense", ""));
898 krb5_addresses addresses
;
899 memset(&addresses
, 0, sizeof(addresses
));
900 for(i
= 0; i
< extra_addresses
.num_strings
; i
++) {
901 ret
= krb5_parse_address(context
, extra_addresses
.strings
[i
],
904 krb5_add_extra_addresses(context
, &addresses
);
905 krb5_free_addresses(context
, &addresses
);
908 free_getarg_strings(&extra_addresses
);
911 if(renew_flag
|| validate_flag
) {
912 ret
= renew_validate(context
, renew_flag
, validate_flag
,
913 ccache
, server_str
, ticket_life
);
917 #ifndef HEIMDAL_SMALLER
920 get_new_tickets(context
, principal
, ccache
, ticket_life
, 1);
922 #ifndef HEIMDAL_SMALLER
923 if(get_v4_tgt
|| convert_524
)
924 do_524init(context
, ccache
, NULL
, server_str
);
927 if(do_afslog
&& k_hasafs())
928 krb5_afslog(context
, ccache
, NULL
, NULL
);
931 struct renew_ctx ctx
;
934 timeout
= ticket_lifetime(context
, ccache
, principal
, server_str
) / 2;
936 ctx
.context
= context
;
938 ctx
.principal
= principal
;
939 ctx
.ticket_life
= ticket_life
;
941 ret
= simple_execvp_timed(argv
[1], argv
+1,
942 renew_func
, &ctx
, timeout
);
943 #define EX_NOEXEC 126
944 #define EX_NOTFOUND 127
946 krb5_warnx(context
, N_("permission denied: %s", ""), argv
[1]);
947 else if(ret
== EX_NOTFOUND
)
948 krb5_warnx(context
, N_("command not found: %s", ""), argv
[1]);
950 krb5_cc_destroy(context
, ccache
);
951 #ifndef HEIMDAL_SMALLER
952 _krb5_krb_dest_tkt(context
, krb4_cc_name
);
959 krb5_cc_close (context
, ccache
);
962 krb5_free_principal(context
, principal
);
963 krb5_free_context (context
);