2 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
6 #pragma ident "%Z%%M% %I% %E% SMI"
9 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
11 * Openvision retains the copyright to derivative works of
12 * this source code. Do *NOT* create a derivative of this
13 * source code before consulting with your legal department.
14 * Do *NOT* integrate *ANY* of this source code into another
15 * product before consulting with your legal department.
17 * For further information, read the top-level Openvision
18 * copyright which is contained in the top-level MIT Kerberos
21 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
27 * kadmin/ktutil/ktutil.c
29 * Copyright 1995, 1996 by the Massachusetts Institute of Technology.
30 * All Rights Reserved.
32 * Export of this software from the United States of America may
33 * require a specific license from the United States Government.
34 * It is the responsibility of any person or organization contemplating
35 * export to obtain such a license before exporting.
37 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
38 * distribute this software and its documentation for any purpose and
39 * without fee is hereby granted, provided that the above copyright
40 * notice appear in all copies and that both that copyright notice and
41 * this permission notice appear in supporting documentation, and that
42 * the name of M.I.T. not be used in advertising or publicity pertaining
43 * to distribution of the software without specific, written prior
44 * permission. Furthermore if you modify this software you must label
45 * your software as modified software and not distribute it in such a
46 * fashion that it might be confused with the original M.I.T. software.
47 * M.I.T. makes no representations about the suitability of
48 * this software for any purpose. It is provided "as is" without express
49 * or implied warranty.
51 * SS user interface for ktutil.
65 extern ss_request_table ktutil_cmds
;
66 krb5_context kcontext
;
67 krb5_kt_list ktlist
= NULL
;
73 krb5_error_code retval
;
76 (void) setlocale(LC_ALL
, "");
78 #if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
79 #define TEXT_DOMAIN "SYS_TEST" /* Use this only if it weren't */
82 (void) textdomain(TEXT_DOMAIN
);
84 retval
= krb5_init_context(&kcontext
);
86 com_err(argv
[0], retval
, gettext("while initializing krb5"));
89 retval
= ktutil_initialize_cmds_table (&ktutil_cmds
);
91 com_err(argv
[0], retval
,
92 gettext("while localizing command description messages"));
95 sci_idx
= ss_create_invocation("ktutil", "5.0", (char *) NULL
,
96 &ktutil_cmds
, &retval
);
98 ss_perror(sci_idx
, retval
, gettext("creating invocation"));
101 retval
= ss_listen(sci_idx
);
102 ktutil_free_kt_list(kcontext
, ktlist
);
106 void ktutil_clear_list(argc
, argv
)
110 krb5_error_code retval
;
113 fprintf(stderr
, gettext("%s: invalid arguments\n"), argv
[0]);
116 retval
= ktutil_free_kt_list(kcontext
, ktlist
);
118 com_err(argv
[0], retval
, gettext("while freeing ktlist"));
122 void ktutil_read_v5(argc
, argv
)
126 krb5_error_code retval
;
130 gettext("%s: must specify keytab to read\n"), argv
[0]);
133 retval
= ktutil_read_keytab(kcontext
, argv
[1], &ktlist
);
135 com_err(argv
[0], retval
,
136 gettext("while reading keytab \"%s\""), argv
[1]);
139 void ktutil_read_v4(argc
, argv
)
143 #ifdef KRB5_KRB4_COMPAT
144 krb5_error_code retval
;
148 gettext("%s: must specify the srvtab to read\n"), argv
[0]);
151 retval
= ktutil_read_srvtab(kcontext
, argv
[1], &ktlist
);
153 com_err(argv
[0], retval
,
154 gettext("while reading srvtab \"%s\""), argv
[1]);
156 fprintf(stderr
, gettext("%s: krb4 support not configured\n"), argv
[0]);
160 void ktutil_write_v5(argc
, argv
)
164 krb5_error_code retval
;
168 gettext("%s: must specify keytab to write\n"), argv
[0]);
171 retval
= ktutil_write_keytab(kcontext
, ktlist
, argv
[1]);
173 com_err(argv
[0], retval
,
174 gettext("while writing keytab \"%s\""), argv
[1]);
177 void ktutil_write_v4(argc
, argv
)
181 #ifdef KRB5_KRB4_COMPAT
182 krb5_error_code retval
;
186 gettext("%s: must specify srvtab to write\n"), argv
[0]);
189 retval
= ktutil_write_srvtab(kcontext
, ktlist
, argv
[1]);
191 com_err(argv
[0], retval
,
192 gettext("while writing srvtab \"%s\""), argv
[1]);
194 fprintf(stderr
, gettext("%s: krb4 support not configured\n"), argv
[0]);
198 void ktutil_add_entry(argc
, argv
)
202 krb5_error_code retval
;
204 char *enctype
= NULL
;
206 int use_pass
= 0, use_key
= 0, i
;
208 for (i
= 1; i
< argc
; i
++) {
209 if ((strlen(argv
[i
]) == 2) && !strncmp(argv
[i
], "-p", 2)) {
213 if ((strlen(argv
[i
]) == 2) && !strncmp(argv
[i
], "-k", 2)) {
214 kvno
= (krb5_kvno
) atoi(argv
[++i
]);
217 if ((strlen(argv
[i
]) == 2) && !strncmp(argv
[i
], "-e", 2)) {
221 if ((strlen(argv
[i
]) == 9) && !strncmp(argv
[i
], "-password", 9)) {
225 if ((strlen(argv
[i
]) == 4) && !strncmp(argv
[i
], "-key", 4)) {
231 if (argc
!= 8 || !(princ
&& kvno
&& enctype
) || (use_pass
+use_key
!= 1)) {
232 fprintf(stderr
, "%s: %s (-key | -password) -p principal "
233 "-k kvno -e enctype\n", gettext("usage"), argv
[0]);
237 retval
= ktutil_add(kcontext
, &ktlist
, princ
, kvno
, enctype
, use_pass
);
239 com_err(argv
[0], retval
, gettext("while adding new entry"));
242 void ktutil_delete_entry(argc
, argv
)
246 krb5_error_code retval
;
250 gettext("%s: must specify entry to delete\n"), argv
[0]);
253 retval
= ktutil_delete(kcontext
, &ktlist
, atoi(argv
[1]));
255 com_err(argv
[0], retval
,
256 gettext("while deleting entry %d"), atoi(argv
[1]));
259 void ktutil_list(argc
, argv
)
263 krb5_error_code retval
;
265 int show_time
= 0, show_keys
= 0, show_enctype
= 0;
269 for (i
= 1; i
< argc
; i
++) {
270 if ((strlen(argv
[i
]) == 2) && !strncmp(argv
[i
], "-t", 2)) {
274 if ((strlen(argv
[i
]) == 2) && !strncmp(argv
[i
], "-k", 2)) {
278 if ((strlen(argv
[i
]) == 2) && !strncmp(argv
[i
], "-e", 2)) {
283 fprintf(stderr
, "%s: %s [-t] [-k] [-e]\n", gettext("usage"), argv
[0]);
287 printf(gettext("slot KVNO Timestamp Principal\n"));
288 printf("---- ---- ----------------- ---------------------------------------------------\n");
290 printf(gettext("slot KVNO Principal\n"));
291 printf("---- ---- ---------------------------------------------------------------------\n");
293 for (i
= 1, lp
= ktlist
; lp
; i
++, lp
= lp
->next
) {
294 retval
= krb5_unparse_name(kcontext
, lp
->entry
->principal
, &pname
);
296 com_err(argv
[0], retval
,
297 gettext("while unparsing principal name"));
300 printf("%4d %4d ", i
, lp
->entry
->vno
);
306 (void) localtime(&tstamp
);
307 lp
->entry
->timestamp
= tstamp
;
309 if (!krb5_timestamp_to_sfstring((krb5_timestamp
)lp
->entry
->
314 printf("%s ", fmtbuf
);
316 printf("%40s", pname
);
318 static char buf
[256];
319 if ((retval
= krb5_enctype_to_string(
320 lp
->entry
->key
.enctype
, buf
, 256))) {
321 if (retval
== EINVAL
)
322 snprintf(buf
, sizeof(buf
), gettext("unsupported encryption type %d"),
323 lp
->entry
->key
.enctype
);
325 com_err(argv
[0], retval
,
326 gettext("While converting "
327 "enctype to string"));
331 printf(" (%s) ", buf
);
336 for (j
= 0; j
< lp
->entry
->key
.length
; j
++)
337 printf("%02x", lp
->entry
->key
.contents
[j
]);