No empty .Rs/.Re
[netbsd-mini2440.git] / crypto / dist / heimdal / admin / ktutil-commands.c
blobaf62374108fe5bdb05b0e036aaff7ec57f4b912f
1 #include <stdio.h>
2 #include <getarg.h>
3 #include <sl.h>
4 #include "ktutil-commands.h"
6 static int
7 add_wrap(int argc, char **argv)
9 struct add_options opt;
10 int ret;
11 int optidx = 0;
12 struct getargs args[] = {
13 { "principal", 'p', arg_string, NULL, "principal to add", "principal" },
14 { "kvno", 'V', arg_integer, NULL, "key version number", NULL },
15 { "enctype", 'e', arg_string, NULL, "encryption type", "enctype" },
16 { "password", 'w', arg_string, NULL, "password for key", NULL },
17 { "salt", 's', arg_negative_flag, NULL, "use unsalted keys", NULL },
18 { "random", 'r', arg_flag, NULL, "generate random key", NULL },
19 { "hex", 'H', arg_flag, NULL, "password is a hexadecimal string", NULL },
20 { "help", 'h', arg_flag, NULL, NULL, NULL }
22 int help_flag = 0;
23 opt.principal_string = "";
24 opt.kvno_integer = -1;
25 opt.enctype_string = NULL;
26 opt.password_string = NULL;
27 opt.salt_flag = 1;
28 opt.random_flag = 0;
29 opt.hex_flag = 0;
30 args[0].value = &opt.principal_string;
31 args[1].value = &opt.kvno_integer;
32 args[2].value = &opt.enctype_string;
33 args[3].value = &opt.password_string;
34 args[4].value = &opt.salt_flag;
35 args[5].value = &opt.random_flag;
36 args[6].value = &opt.hex_flag;
37 args[7].value = &help_flag;
38 if(getarg(args, 8, argc, argv, &optidx))
39 goto usage;
40 if(argc - optidx > 0) {
41 fprintf(stderr, "Arguments given (%u) are more than expected (0).\n\n", argc - optidx);
42 goto usage;
44 if(help_flag)
45 goto usage;
46 ret = kt_add(&opt, argc - optidx, argv + optidx);
47 return ret;
48 usage:
49 arg_printusage (args, 8, "add", "");
50 return 0;
53 static int
54 change_wrap(int argc, char **argv)
56 struct change_options opt;
57 int ret;
58 int optidx = 0;
59 struct getargs args[] = {
60 { "realm", 'r', arg_string, NULL, "realm to use", "realm" },
61 { "admin-server", 'a', arg_string, NULL, "server to contact", "host" },
62 { "server-port", 's', arg_integer, NULL, "port number on server", "port number" },
63 { "help", 'h', arg_flag, NULL, NULL, NULL }
65 int help_flag = 0;
66 opt.realm_string = NULL;
67 opt.admin_server_string = NULL;
68 opt.server_port_integer = 0;
69 args[0].value = &opt.realm_string;
70 args[1].value = &opt.admin_server_string;
71 args[2].value = &opt.server_port_integer;
72 args[3].value = &help_flag;
73 if(getarg(args, 4, argc, argv, &optidx))
74 goto usage;
75 if(help_flag)
76 goto usage;
77 ret = kt_change(&opt, argc - optidx, argv + optidx);
78 return ret;
79 usage:
80 arg_printusage (args, 4, "change", "[principal...]");
81 return 0;
84 static int
85 copy_wrap(int argc, char **argv)
87 int ret;
88 int optidx = 0;
89 struct getargs args[] = {
90 { "help", 'h', arg_flag, NULL, NULL, NULL }
92 int help_flag = 0;
93 args[0].value = &help_flag;
94 if(getarg(args, 1, argc, argv, &optidx))
95 goto usage;
96 if(argc - optidx != 2) {
97 fprintf(stderr, "Need exactly 2 parameters (%u given).\n\n", argc - optidx);
98 goto usage;
100 if(help_flag)
101 goto usage;
102 ret = kt_copy(NULL, argc - optidx, argv + optidx);
103 return ret;
104 usage:
105 arg_printusage (args, 1, "copy", "source destination");
106 return 0;
109 static int
110 get_wrap(int argc, char **argv)
112 struct get_options opt;
113 int ret;
114 int optidx = 0;
115 struct getargs args[] = {
116 { "principal", 'p', arg_string, NULL, "admin principal", "principal" },
117 { "enctypes", 'e', arg_strings, NULL, "encryption types to use", "enctype" },
118 { "realm", 'r', arg_string, NULL, "realm to use", "realm" },
119 { "admin-server", 'a', arg_string, NULL, "server to contact", "host" },
120 { "server-port", 's', arg_integer, NULL, "port number on server", "port number" },
121 { "help", 'h', arg_flag, NULL, NULL, NULL }
123 int help_flag = 0;
124 opt.principal_string = NULL;
125 opt.enctypes_strings.num_strings = 0;
126 opt.enctypes_strings.strings = NULL;
127 opt.realm_string = NULL;
128 opt.admin_server_string = NULL;
129 opt.server_port_integer = 0;
130 args[0].value = &opt.principal_string;
131 args[1].value = &opt.enctypes_strings;
132 args[2].value = &opt.realm_string;
133 args[3].value = &opt.admin_server_string;
134 args[4].value = &opt.server_port_integer;
135 args[5].value = &help_flag;
136 if(getarg(args, 6, argc, argv, &optidx))
137 goto usage;
138 if(argc - optidx < 1) {
139 fprintf(stderr, "Arguments given (%u) are less than expected (1).\n\n", argc - optidx);
140 goto usage;
142 if(help_flag)
143 goto usage;
144 ret = kt_get(&opt, argc - optidx, argv + optidx);
145 free_getarg_strings (&opt.enctypes_strings);
146 return ret;
147 usage:
148 arg_printusage (args, 6, "get", "principal...");
149 free_getarg_strings (&opt.enctypes_strings);
150 return 0;
153 static int
154 list_wrap(int argc, char **argv)
156 struct list_options opt;
157 int ret;
158 int optidx = 0;
159 struct getargs args[] = {
160 { "keys", 0, arg_flag, NULL, "show key values", NULL },
161 { "timestamp", 0, arg_flag, NULL, "show timestamps", NULL },
162 { "help", 'h', arg_flag, NULL, NULL, NULL }
164 int help_flag = 0;
165 opt.keys_flag = 0;
166 opt.timestamp_flag = 0;
167 args[0].value = &opt.keys_flag;
168 args[1].value = &opt.timestamp_flag;
169 args[2].value = &help_flag;
170 if(getarg(args, 3, argc, argv, &optidx))
171 goto usage;
172 if(argc - optidx > 0) {
173 fprintf(stderr, "Arguments given (%u) are more than expected (0).\n\n", argc - optidx);
174 goto usage;
176 if(help_flag)
177 goto usage;
178 ret = kt_list(&opt, argc - optidx, argv + optidx);
179 return ret;
180 usage:
181 arg_printusage (args, 3, "list", "");
182 return 0;
185 static int
186 purge_wrap(int argc, char **argv)
188 struct purge_options opt;
189 int ret;
190 int optidx = 0;
191 struct getargs args[] = {
192 { "age", 0, arg_string, NULL, "age to retiere", "time" },
193 { "help", 'h', arg_flag, NULL, NULL, NULL }
195 int help_flag = 0;
196 opt.age_string = "1 week";
197 args[0].value = &opt.age_string;
198 args[1].value = &help_flag;
199 if(getarg(args, 2, argc, argv, &optidx))
200 goto usage;
201 if(argc - optidx > 0) {
202 fprintf(stderr, "Arguments given (%u) are more than expected (0).\n\n", argc - optidx);
203 goto usage;
205 if(help_flag)
206 goto usage;
207 ret = kt_purge(&opt, argc - optidx, argv + optidx);
208 return ret;
209 usage:
210 arg_printusage (args, 2, "purge", "");
211 return 0;
214 static int
215 remove_wrap(int argc, char **argv)
217 struct remove_options opt;
218 int ret;
219 int optidx = 0;
220 struct getargs args[] = {
221 { "principal", 'p', arg_string, NULL, "principal to remove", "principal" },
222 { "kvno", 'V', arg_integer, NULL, "key version to remove", "enctype" },
223 { "enctype", 'e', arg_string, NULL, "enctype to remove", "enctype" },
224 { "help", 'h', arg_flag, NULL, NULL, NULL }
226 int help_flag = 0;
227 opt.principal_string = NULL;
228 opt.kvno_integer = 0;
229 opt.enctype_string = NULL;
230 args[0].value = &opt.principal_string;
231 args[1].value = &opt.kvno_integer;
232 args[2].value = &opt.enctype_string;
233 args[3].value = &help_flag;
234 if(getarg(args, 4, argc, argv, &optidx))
235 goto usage;
236 if(argc - optidx > 0) {
237 fprintf(stderr, "Arguments given (%u) are more than expected (0).\n\n", argc - optidx);
238 goto usage;
240 if(help_flag)
241 goto usage;
242 ret = kt_remove(&opt, argc - optidx, argv + optidx);
243 return ret;
244 usage:
245 arg_printusage (args, 4, "remove", "");
246 return 0;
249 static int
250 rename_wrap(int argc, char **argv)
252 int ret;
253 int optidx = 0;
254 struct getargs args[] = {
255 { "help", 'h', arg_flag, NULL, NULL, NULL }
257 int help_flag = 0;
258 args[0].value = &help_flag;
259 if(getarg(args, 1, argc, argv, &optidx))
260 goto usage;
261 if(argc - optidx != 2) {
262 fprintf(stderr, "Need exactly 2 parameters (%u given).\n\n", argc - optidx);
263 goto usage;
265 if(help_flag)
266 goto usage;
267 ret = kt_rename(NULL, argc - optidx, argv + optidx);
268 return ret;
269 usage:
270 arg_printusage (args, 1, "rename", "from to");
271 return 0;
274 static int
275 srvconvert_wrap(int argc, char **argv)
277 struct srvconvert_options opt;
278 int ret;
279 int optidx = 0;
280 struct getargs args[] = {
281 { "srvtab", 's', arg_string, NULL, "name of Kerberos 4 srvtab", "file" },
282 { "help", 'h', arg_flag, NULL, NULL, NULL }
284 int help_flag = 0;
285 opt.srvtab_string = "/etc/srvtab";
286 args[0].value = &opt.srvtab_string;
287 args[1].value = &help_flag;
288 if(getarg(args, 2, argc, argv, &optidx))
289 goto usage;
290 if(argc - optidx > 0) {
291 fprintf(stderr, "Arguments given (%u) are more than expected (0).\n\n", argc - optidx);
292 goto usage;
294 if(help_flag)
295 goto usage;
296 ret = srvconv(&opt, argc - optidx, argv + optidx);
297 return ret;
298 usage:
299 arg_printusage (args, 2, "srvconvert", "");
300 return 0;
303 static int
304 srvcreate_wrap(int argc, char **argv)
306 struct srvcreate_options opt;
307 int ret;
308 int optidx = 0;
309 struct getargs args[] = {
310 { "srvtab", 's', arg_string, NULL, "name of Kerberos 4 srvtab", "file" },
311 { "help", 'h', arg_flag, NULL, NULL, NULL }
313 int help_flag = 0;
314 opt.srvtab_string = "/etc/srvtab";
315 args[0].value = &opt.srvtab_string;
316 args[1].value = &help_flag;
317 if(getarg(args, 2, argc, argv, &optidx))
318 goto usage;
319 if(argc - optidx > 0) {
320 fprintf(stderr, "Arguments given (%u) are more than expected (0).\n\n", argc - optidx);
321 goto usage;
323 if(help_flag)
324 goto usage;
325 ret = srvcreate(&opt, argc - optidx, argv + optidx);
326 return ret;
327 usage:
328 arg_printusage (args, 2, "srvcreate", "");
329 return 0;
332 static int
333 help_wrap(int argc, char **argv)
335 int ret;
336 int optidx = 0;
337 struct getargs args[] = {
338 { "help", 'h', arg_flag, NULL, NULL, NULL }
340 int help_flag = 0;
341 args[0].value = &help_flag;
342 if(getarg(args, 1, argc, argv, &optidx))
343 goto usage;
344 if(argc - optidx > 1) {
345 fprintf(stderr, "Arguments given (%u) are more than expected (1).\n\n", argc - optidx);
346 goto usage;
348 if(help_flag)
349 goto usage;
350 ret = help(NULL, argc - optidx, argv + optidx);
351 return ret;
352 usage:
353 arg_printusage (args, 1, "help", "command");
354 return 0;
357 SL_cmd commands[] = {
358 { "add", add_wrap, "add", "Adds a key to a keytab." },
360 { "change", change_wrap, "change [principal...]", "Change keys for specified principals (default all)." },
362 { "copy", copy_wrap, "copy source destination", "Copies one keytab to another." },
364 { "get", get_wrap, "get principal...", "Change keys for specified principals, and add them to the keytab." },
366 { "list", list_wrap, "list", "Show contents of keytab." },
368 { "purge", purge_wrap, "purge", "Remove superceded keys from keytab." },
370 { "remove", remove_wrap, "remove", "Remove keys from keytab." },
371 { "delete" },
373 { "rename", rename_wrap, "rename from to", "Renames an entry in the keytab." },
375 { "srvconvert", srvconvert_wrap, "srvconvert", "Convert a Kerberos 4 srvtab to a keytab." },
376 { "srv2keytab" },
378 { "srvcreate", srvcreate_wrap, "srvcreate", "Convert a keytab to a Kerberos 4 srvtab." },
379 { "key2srvtab" },
381 { "help", help_wrap, "help command", NULL },
383 { NULL }