2 #include "kuser_locl.h"
4 static char *etypestr
= 0;
5 static char *fromccachestr
= 0;
6 static char *flagstr
= 0;
7 static int quiet_flag
= 0;
8 static int version_flag
= 0;
9 static int help_flag
= 0;
11 struct getargs args
[] = {
12 { "cache", 'c', arg_string
, &fromccachestr
,
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: ", "dest_ccache service1 [service2 ...]");
31 static void do_kcpytkt (int argc
, char *argv
[], char *fromccachestr
, 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_kcpytkt(argc
, argv
, fromccachestr
, etypestr
, flags
);
65 static void do_kcpytkt (int count
, char *names
[],
66 char *fromccachestr
, char *etypestr
, int flags
)
72 krb5_ccache fromccache
;
73 krb5_ccache destccache
;
75 krb5_creds in_creds
, out_creds
;
79 ret
= krb5_init_context(&context
);
81 errx(1, "krb5_init_context failed: %d", ret
);
84 ret
= krb5_string_to_enctype(context
, etypestr
, &etype
);
86 krb5_err(context
, 1, ret
, "Can't convert enctype %s", etypestr
);
87 retflags
= KRB5_TC_MATCH_SRV_NAMEONLY
| KRB5_TC_MATCH_KEYTYPE
;
90 retflags
= KRB5_TC_MATCH_SRV_NAMEONLY
;
94 ret
= krb5_cc_resolve(context
, fromccachestr
, &fromccache
);
96 ret
= krb5_cc_default(context
, &fromccache
);
98 krb5_err(context
, 1, ret
, "Can't resolve credentials cache");
100 ret
= krb5_cc_get_principal(context
, fromccache
, &me
);
102 krb5_err(context
, 1, ret
, "Can't query client principal name");
104 ret
= krb5_cc_resolve(context
, names
[0], &destccache
);
106 krb5_err(context
, 1, ret
, "Can't resolve destination cache");
110 for (i
= 1; i
< count
; i
++) {
111 memset(&in_creds
, 0, sizeof(in_creds
));
113 in_creds
.client
= me
;
115 ret
= krb5_parse_name(context
, names
[i
], &in_creds
.server
);
118 krb5_warn(context
, ret
, "Parse error for %s", names
[i
]);
123 ret
= krb5_unparse_name(context
, in_creds
.server
, &princ
);
125 krb5_warn(context
, ret
, "Unparse error for %s", names
[i
]);
130 in_creds
.session
.keytype
= etype
;
132 ret
= krb5_cc_retrieve_cred(context
, fromccache
, retflags
,
133 &in_creds
, &out_creds
);
135 krb5_warn(context
, ret
, "Can't retrieve credentials for %s", princ
);
137 krb5_free_unparsed_name(context
, princ
);
143 ret
= krb5_cc_store_cred(context
, destccache
, &out_creds
);
145 krb5_free_principal(context
, in_creds
.server
);
148 krb5_warn(context
, ret
, "Can't store credentials for %s", princ
);
150 krb5_free_cred_contents(context
, &out_creds
);
151 krb5_free_unparsed_name(context
, princ
);
157 krb5_free_unparsed_name(context
, princ
);
158 krb5_free_cred_contents(context
, &out_creds
);
161 krb5_free_principal(context
, me
);
162 krb5_cc_close(context
, fromccache
);
163 krb5_cc_close(context
, destccache
);
164 krb5_free_context(context
);