2 #include "kuser_locl.h"
4 static char *etypestr
= 0;
5 static char *ccachestr
= 0;
6 static char *flagstr
= 0;
7 static int quiet_flag
= 0;
8 static int help_flag
= 0;
9 static int version_flag
= 0;
11 struct getargs args
[] = {
12 { "cache", 'c', arg_string
, &ccachestr
,
13 "Credentials cache", "cachename" },
14 { "enctype", 'e', arg_string
, &etypestr
,
15 "Encryption type", "enctype" },
16 { "flags", 'f', arg_string
, &flagstr
,
18 { "quiet", 'q', arg_flag
, &quiet_flag
, "Quiet" },
19 { "version", 0, arg_flag
, &version_flag
},
20 { "help", 0, arg_flag
, &help_flag
}
26 arg_printusage(args
, sizeof(args
)/sizeof(args
[0]),
27 "Usage: ", "service1 [service2 ...]");
31 static void do_kdeltkt (int argc
, char *argv
[], char *ccachestr
, char *etypestr
, int flags
);
33 int main(int argc
, char *argv
[])
40 if (getarg(args
, sizeof(args
)/sizeof(args
[0]), argc
, argv
, &optidx
))
58 flags
= atoi(flagstr
);
60 do_kdeltkt(argc
, argv
, ccachestr
, etypestr
, flags
);
65 static void do_kdeltkt (int count
, char *names
[],
66 char *ccachestr
, char *etypestr
, int flags
)
74 krb5_creds in_creds
, out_creds
;
78 ret
= krb5_init_context(&context
);
80 errx(1, "krb5_init_context failed: %d", ret
);
83 ret
= krb5_string_to_enctype(context
, etypestr
, &etype
);
85 krb5_err(context
, 1, ret
, "Can't convert enctype %s", etypestr
);
86 retflags
= KRB5_TC_MATCH_SRV_NAMEONLY
| KRB5_TC_MATCH_KEYTYPE
;
89 retflags
= KRB5_TC_MATCH_SRV_NAMEONLY
;
93 ret
= krb5_cc_resolve(context
, ccachestr
, &ccache
);
95 ret
= krb5_cc_default(context
, &ccache
);
97 krb5_err(context
, 1, ret
, "Can't open credentials cache");
99 ret
= krb5_cc_get_principal(context
, ccache
, &me
);
101 krb5_err(context
, 1, ret
, "Can't get client principal");
105 for (i
= 0; i
< count
; i
++) {
106 memset(&in_creds
, 0, sizeof(in_creds
));
108 in_creds
.client
= me
;
110 ret
= krb5_parse_name(context
, names
[i
], &in_creds
.server
);
113 krb5_warn(context
, ret
, "Can't parse principal name %s", names
[i
]);
118 ret
= krb5_unparse_name(context
, in_creds
.server
, &princ
);
120 krb5_warn(context
, ret
, "Can't unparse principal name %s", names
[i
]);
125 in_creds
.session
.keytype
= etype
;
127 ret
= krb5_cc_retrieve_cred(context
, ccache
, retflags
,
128 &in_creds
, &out_creds
);
130 krb5_warn(context
, ret
, "Can't retrieve credentials for %s", princ
);
132 krb5_free_unparsed_name(context
, princ
);
138 ret
= krb5_cc_remove_cred(context
, ccache
, flags
, &out_creds
);
140 krb5_free_principal(context
, in_creds
.server
);
143 krb5_warn(context
, ret
, "Can't remove credentials for %s", princ
);
145 krb5_free_cred_contents(context
, &out_creds
);
146 krb5_free_unparsed_name(context
, princ
);
152 krb5_free_unparsed_name(context
, princ
);
153 krb5_free_cred_contents(context
, &out_creds
);
156 krb5_free_principal(context
, me
);
157 krb5_cc_close(context
, ccache
);
158 krb5_free_context(context
);