4 #include "ktutil-commands.h"
7 add_wrap(int argc
, char **argv
)
9 struct add_options opt
;
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
}
23 opt
.principal_string
= "";
24 opt
.kvno_integer
= -1;
25 opt
.enctype_string
= NULL
;
26 opt
.password_string
= NULL
;
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
))
40 if(argc
- optidx
> 0) {
41 fprintf(stderr
, "Arguments given (%u) are more than expected (0).\n\n", argc
- optidx
);
46 ret
= kt_add(&opt
, argc
- optidx
, argv
+ optidx
);
49 arg_printusage (args
, 8, "add", "");
54 change_wrap(int argc
, char **argv
)
56 struct change_options opt
;
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
}
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
))
77 ret
= kt_change(&opt
, argc
- optidx
, argv
+ optidx
);
80 arg_printusage (args
, 4, "change", "[principal...]");
85 copy_wrap(int argc
, char **argv
)
89 struct getargs args
[] = {
90 { "help", 'h', arg_flag
, NULL
, NULL
, NULL
}
93 args
[0].value
= &help_flag
;
94 if(getarg(args
, 1, argc
, argv
, &optidx
))
96 if(argc
- optidx
!= 2) {
97 fprintf(stderr
, "Need exactly 2 parameters (%u given).\n\n", argc
- optidx
);
102 ret
= kt_copy(NULL
, argc
- optidx
, argv
+ optidx
);
105 arg_printusage (args
, 1, "copy", "source destination");
110 get_wrap(int argc
, char **argv
)
112 struct get_options opt
;
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
}
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
))
138 if(argc
- optidx
< 1) {
139 fprintf(stderr
, "Arguments given (%u) are less than expected (1).\n\n", argc
- optidx
);
144 ret
= kt_get(&opt
, argc
- optidx
, argv
+ optidx
);
145 free_getarg_strings (&opt
.enctypes_strings
);
148 arg_printusage (args
, 6, "get", "principal...");
149 free_getarg_strings (&opt
.enctypes_strings
);
154 list_wrap(int argc
, char **argv
)
156 struct list_options opt
;
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
}
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
))
172 if(argc
- optidx
> 0) {
173 fprintf(stderr
, "Arguments given (%u) are more than expected (0).\n\n", argc
- optidx
);
178 ret
= kt_list(&opt
, argc
- optidx
, argv
+ optidx
);
181 arg_printusage (args
, 3, "list", "");
186 purge_wrap(int argc
, char **argv
)
188 struct purge_options opt
;
191 struct getargs args
[] = {
192 { "age", 0, arg_string
, NULL
, "age to retiere", "time" },
193 { "help", 'h', arg_flag
, NULL
, NULL
, NULL
}
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
))
201 if(argc
- optidx
> 0) {
202 fprintf(stderr
, "Arguments given (%u) are more than expected (0).\n\n", argc
- optidx
);
207 ret
= kt_purge(&opt
, argc
- optidx
, argv
+ optidx
);
210 arg_printusage (args
, 2, "purge", "");
215 remove_wrap(int argc
, char **argv
)
217 struct remove_options opt
;
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
}
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
))
236 if(argc
- optidx
> 0) {
237 fprintf(stderr
, "Arguments given (%u) are more than expected (0).\n\n", argc
- optidx
);
242 ret
= kt_remove(&opt
, argc
- optidx
, argv
+ optidx
);
245 arg_printusage (args
, 4, "remove", "");
250 rename_wrap(int argc
, char **argv
)
254 struct getargs args
[] = {
255 { "help", 'h', arg_flag
, NULL
, NULL
, NULL
}
258 args
[0].value
= &help_flag
;
259 if(getarg(args
, 1, argc
, argv
, &optidx
))
261 if(argc
- optidx
!= 2) {
262 fprintf(stderr
, "Need exactly 2 parameters (%u given).\n\n", argc
- optidx
);
267 ret
= kt_rename(NULL
, argc
- optidx
, argv
+ optidx
);
270 arg_printusage (args
, 1, "rename", "from to");
275 srvconvert_wrap(int argc
, char **argv
)
277 struct srvconvert_options opt
;
280 struct getargs args
[] = {
281 { "srvtab", 's', arg_string
, NULL
, "name of Kerberos 4 srvtab", "file" },
282 { "help", 'h', arg_flag
, NULL
, NULL
, NULL
}
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
))
290 if(argc
- optidx
> 0) {
291 fprintf(stderr
, "Arguments given (%u) are more than expected (0).\n\n", argc
- optidx
);
296 ret
= srvconv(&opt
, argc
- optidx
, argv
+ optidx
);
299 arg_printusage (args
, 2, "srvconvert", "");
304 srvcreate_wrap(int argc
, char **argv
)
306 struct srvcreate_options opt
;
309 struct getargs args
[] = {
310 { "srvtab", 's', arg_string
, NULL
, "name of Kerberos 4 srvtab", "file" },
311 { "help", 'h', arg_flag
, NULL
, NULL
, NULL
}
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
))
319 if(argc
- optidx
> 0) {
320 fprintf(stderr
, "Arguments given (%u) are more than expected (0).\n\n", argc
- optidx
);
325 ret
= srvcreate(&opt
, argc
- optidx
, argv
+ optidx
);
328 arg_printusage (args
, 2, "srvcreate", "");
333 help_wrap(int argc
, char **argv
)
337 struct getargs args
[] = {
338 { "help", 'h', arg_flag
, NULL
, NULL
, NULL
}
341 args
[0].value
= &help_flag
;
342 if(getarg(args
, 1, argc
, argv
, &optidx
))
344 if(argc
- optidx
> 1) {
345 fprintf(stderr
, "Arguments given (%u) are more than expected (1).\n\n", argc
- optidx
);
350 ret
= help(NULL
, argc
- optidx
, argv
+ optidx
);
353 arg_printusage (args
, 1, "help", "command");
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." },
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." },
378 { "srvcreate", srvcreate_wrap
, "srvcreate", "Convert a keytab to a Kerberos 4 srvtab." },
381 { "help", help_wrap
, "help command", NULL
},