2 #include "kuser_locl.h"
4 static char *etypestr
= 0;
5 static char *ccachestr
= 0;
6 static char *flagstr
= 0;
7 static int exp_only
= 0;
8 static int quiet_flag
= 0;
9 static int help_flag
= 0;
10 static int version_flag
= 0;
12 struct getargs args
[] = {
13 { "cache", 'c', arg_string
, &ccachestr
,
14 "Credentials cache", "cachename" },
15 { "enctype", 'e', arg_string
, &etypestr
,
16 "Encryption type", "enctype" },
17 { "flags", 'f', arg_string
, &flagstr
,
19 { "expired-only", 'E', arg_flag
, &exp_only
,
20 "Delete only expired tickets" },
21 { "quiet", 'q', arg_flag
, &quiet_flag
, "Quiet" },
22 { "version", 0, arg_flag
, &version_flag
},
23 { "help", 0, arg_flag
, &help_flag
}
29 arg_printusage(args
, sizeof(args
)/sizeof(args
[0]),
30 "Usage: ", "service1 [service2 ...]");
34 static void do_kdeltkt (int argc
, char *argv
[], char *ccachestr
, char *etypestr
, int flags
);
36 int main(int argc
, char *argv
[])
43 if (getarg(args
, sizeof(args
)/sizeof(args
[0]), argc
, argv
, &optidx
))
61 flags
= atoi(flagstr
);
63 do_kdeltkt(argc
, argv
, ccachestr
, etypestr
, flags
);
68 static void do_kdeltkt (int count
, char *names
[],
69 char *ccachestr
, char *etypestr
, int flags
)
77 krb5_creds in_creds
, out_creds
;
81 ret
= krb5_init_context(&context
);
83 errx(1, "krb5_init_context failed: %d", ret
);
86 ret
= krb5_string_to_enctype(context
, etypestr
, &etype
);
88 krb5_err(context
, 1, ret
, "Can't convert enctype %s", etypestr
);
89 retflags
= KRB5_TC_MATCH_SRV_NAMEONLY
| KRB5_TC_MATCH_KEYTYPE
;
92 retflags
= KRB5_TC_MATCH_SRV_NAMEONLY
;
96 ret
= krb5_cc_resolve(context
, ccachestr
, &ccache
);
98 ret
= krb5_cc_default(context
, &ccache
);
100 krb5_err(context
, 1, ret
, "Can't open credentials cache");
102 ret
= krb5_cc_get_principal(context
, ccache
, &me
);
104 krb5_err(context
, 1, ret
, "Can't get client principal");
108 for (i
= 0; i
< count
; i
++) {
109 memset(&in_creds
, 0, sizeof(in_creds
));
111 in_creds
.client
= me
;
113 ret
= krb5_parse_name(context
, names
[i
], &in_creds
.server
);
116 krb5_warn(context
, ret
, "Can't parse principal name %s", names
[i
]);
121 ret
= krb5_unparse_name(context
, in_creds
.server
, &princ
);
123 krb5_warn(context
, ret
, "Can't unparse principal name %s", names
[i
]);
128 in_creds
.session
.keytype
= etype
;
131 krb5_timeofday(context
, &in_creds
.times
.endtime
);
132 retflags
|= KRB5_TC_MATCH_TIMES
;
135 ret
= krb5_cc_retrieve_cred(context
, ccache
, retflags
,
136 &in_creds
, &out_creds
);
138 krb5_warn(context
, ret
, "Can't retrieve credentials for %s", princ
);
140 krb5_free_unparsed_name(context
, princ
);
146 ret
= krb5_cc_remove_cred(context
, ccache
, flags
, &out_creds
);
148 krb5_free_principal(context
, in_creds
.server
);
151 krb5_warn(context
, ret
, "Can't remove credentials for %s", princ
);
153 krb5_free_cred_contents(context
, &out_creds
);
154 krb5_free_unparsed_name(context
, princ
);
160 krb5_free_unparsed_name(context
, princ
);
161 krb5_free_cred_contents(context
, &out_creds
);
164 krb5_free_principal(context
, me
);
165 krb5_cc_close(context
, ccache
);
166 krb5_free_context(context
);