1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
3 * kadmin/ktutil/ktutil.c
5 * Copyright 1995, 1996, 2008 by the Massachusetts Institute of Technology.
8 * Export of this software from the United States of America may
9 * require a specific license from the United States Government.
10 * It is the responsibility of any person or organization contemplating
11 * export to obtain such a license before exporting.
13 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
14 * distribute this software and its documentation for any purpose and
15 * without fee is hereby granted, provided that the above copyright
16 * notice appear in all copies and that both that copyright notice and
17 * this permission notice appear in supporting documentation, and that
18 * the name of M.I.T. not be used in advertising or publicity pertaining
19 * to distribution of the software without specific, written prior
20 * permission. Furthermore if you modify this software you must label
21 * your software as modified software and not distribute it in such a
22 * fashion that it might be confused with the original M.I.T. software.
23 * M.I.T. makes no representations about the suitability of
24 * this software for any purpose. It is provided "as is" without express
25 * or implied warranty.
27 * SS user interface for ktutil.
33 #include "adm_proto.h"
40 extern ss_request_table ktutil_cmds;
41 krb5_context kcontext;
42 krb5_kt_list ktlist = NULL;
48 krb5_error_code retval;
51 retval = krb5_init_context(&kcontext);
53 com_err(argv[0], retval, "while initializing krb5");
56 sci_idx = ss_create_invocation("ktutil", "5.0", (char *)NULL,
57 &ktutil_cmds, &retval);
59 ss_perror(sci_idx, retval, "creating invocation");
62 retval = ss_listen(sci_idx);
63 ktutil_free_kt_list(kcontext, ktlist);
67 void ktutil_clear_list(argc, argv)
71 krb5_error_code retval;
74 fprintf(stderr, "%s: invalid arguments\n", argv[0]);
77 retval = ktutil_free_kt_list(kcontext, ktlist);
79 com_err(argv[0], retval, "while freeing ktlist");
83 void ktutil_read_v5(argc, argv)
87 krb5_error_code retval;
90 fprintf(stderr, "%s: must specify keytab to read\n", argv[0]);
93 retval = ktutil_read_keytab(kcontext, argv[1], &ktlist);
95 com_err(argv[0], retval, "while reading keytab \"%s\"", argv[1]);
98 void ktutil_read_v4(argc, argv)
102 krb5_error_code retval;
105 fprintf(stderr, "%s: must specify the srvtab to read\n", argv[0]);
108 retval = ktutil_read_srvtab(kcontext, argv[1], &ktlist);
110 com_err(argv[0], retval, "while reading srvtab \"%s\"", argv[1]);
113 void ktutil_write_v5(argc, argv)
117 krb5_error_code retval;
120 fprintf(stderr, "%s: must specify keytab to write\n", argv[0]);
123 retval = ktutil_write_keytab(kcontext, ktlist, argv[1]);
125 com_err(argv[0], retval, "while writing keytab \"%s\"", argv[1]);
128 void ktutil_write_v4(argc, argv)
132 fprintf(stderr, "%s: writing srvtabs is no longer supported\n", argv[0]);
135 void ktutil_add_entry(argc, argv)
139 krb5_error_code retval;
141 char *enctype = NULL;
143 int use_pass = 0, use_key = 0, i;
145 for (i = 1; i < argc; i++) {
146 if ((strlen(argv[i]) == 2) && !strncmp(argv[i], "-p", 2)) {
150 if ((strlen(argv[i]) == 2) && !strncmp(argv[i], "-k", 2)) {
151 kvno = (krb5_kvno) atoi(argv[++i]);
154 if ((strlen(argv[i]) == 2) && !strncmp(argv[i], "-e", 2)) {
158 if ((strlen(argv[i]) == 9) && !strncmp(argv[i], "-password", 9)) {
162 if ((strlen(argv[i]) == 4) && !strncmp(argv[i], "-key", 4)) {
168 if (argc != 8 || !(princ && kvno && enctype) || (use_pass+use_key != 1)) {
169 fprintf(stderr, "usage: %s (-key | -password) -p principal "
170 "-k kvno -e enctype\n", argv[0]);
174 retval = ktutil_add(kcontext, &ktlist, princ, kvno, enctype, use_pass);
176 com_err(argv[0], retval, "while adding new entry");
179 void ktutil_delete_entry(argc, argv)
183 krb5_error_code retval;
186 fprintf(stderr, "%s: must specify entry to delete\n", argv[0]);
189 retval = ktutil_delete(kcontext, &ktlist, atoi(argv[1]));
191 com_err(argv[0], retval, "while deleting entry %d", atoi(argv[1]));
194 void ktutil_list(argc, argv)
198 krb5_error_code retval;
200 int show_time = 0, show_keys = 0, show_enctype = 0;
205 for (i = 1; i < argc; i++) {
206 if ((strlen(argv[i]) == 2) && !strncmp(argv[i], "-t", 2)) {
210 if ((strlen(argv[i]) == 2) && !strncmp(argv[i], "-k", 2)) {
214 if ((strlen(argv[i]) == 2) && !strncmp(argv[i], "-e", 2)) {
219 fprintf(stderr, "%s: usage: %s [-t] [-k] [-e]\n", argv[0], argv[0]);
223 printf("slot KVNO Timestamp Principal\n");
224 printf("---- ---- ----------------- ---------------------------------------------------\n");
226 printf("slot KVNO Principal\n");
227 printf("---- ---- ---------------------------------------------------------------------\n");
229 for (i = 1, lp = ktlist; lp; i++, lp = lp->next) {
230 retval = krb5_unparse_name(kcontext, lp->entry->principal, &pname);
232 com_err(argv[0], retval, "while unparsing principal name");
235 printf("%4d %4d ", i, lp->entry->vno);
241 tstamp = lp->entry->timestamp;
242 (void) localtime(&tstamp);
243 lp->entry->timestamp = tstamp;
245 if (!krb5_timestamp_to_sfstring((krb5_timestamp)lp->entry->
250 printf("%s ", fmtbuf);
252 printf("%40s", pname);
254 static char buf[256];
255 if ((retval = krb5_enctype_to_string(
256 lp->entry->key.enctype, buf, 256))) {
257 com_err(argv[0], retval, "While converting enctype to string");
260 printf(" (%s) ", buf);
265 for (j = 0; j < lp->entry->key.length; j++)
266 printf("%02x", lp->entry->key.contents[j]);