4 #include "kadmin-commands.h"
7 stash_wrap(int argc
, char **argv
)
9 struct stash_options opt
;
12 struct getargs args
[] = {
13 { "enctype", 'e', arg_string
, NULL
, "encryption type", NULL
},
14 { "key-file", 'k', arg_string
, NULL
, "master key file", "file" },
15 { "convert-file", 0, arg_flag
, NULL
, "just convert keyfile to new format", NULL
},
16 { "master-key-fd", 0, arg_integer
, NULL
, "filedescriptor to read passphrase from", "fd" },
17 { "help", 'h', arg_flag
, NULL
, NULL
, NULL
}
20 opt
.enctype_string
= "des3-cbc-sha1";
21 opt
.key_file_string
= NULL
;
22 opt
.convert_file_flag
= 0;
23 opt
.master_key_fd_integer
= -1;
24 args
[0].value
= &opt
.enctype_string
;
25 args
[1].value
= &opt
.key_file_string
;
26 args
[2].value
= &opt
.convert_file_flag
;
27 args
[3].value
= &opt
.master_key_fd_integer
;
28 args
[4].value
= &help_flag
;
29 if(getarg(args
, 5, argc
, argv
, &optidx
))
31 if(argc
- optidx
> 0) {
32 fprintf(stderr
, "Arguments given (%u) are more than expected (0).\n\n", argc
- optidx
);
37 ret
= stash(&opt
, argc
- optidx
, argv
+ optidx
);
40 arg_printusage (args
, 5, "stash", "");
45 dump_wrap(int argc
, char **argv
)
47 struct dump_options opt
;
50 struct getargs args
[] = {
51 { "decrypt", 'd', arg_flag
, NULL
, "decrypt keys", NULL
},
52 { "help", 'h', arg_flag
, NULL
, NULL
, NULL
}
56 args
[0].value
= &opt
.decrypt_flag
;
57 args
[1].value
= &help_flag
;
58 if(getarg(args
, 2, argc
, argv
, &optidx
))
60 if(argc
- optidx
> 1) {
61 fprintf(stderr
, "Arguments given (%u) are more than expected (1).\n\n", argc
- optidx
);
64 if(argc
- optidx
< 0) {
65 fprintf(stderr
, "Arguments given (%u) are less than expected (0).\n\n", argc
- optidx
);
70 ret
= dump(&opt
, argc
- optidx
, argv
+ optidx
);
73 arg_printusage (args
, 2, "dump", "[dump-file]");
78 init_wrap(int argc
, char **argv
)
80 struct init_options opt
;
83 struct getargs args
[] = {
84 { "realm-max-ticket-life", 0, arg_string
, NULL
, "realm max ticket lifetime", NULL
},
85 { "realm-max-renewable-life", 0, arg_string
, NULL
, "realm max renewable lifetime", NULL
},
86 { "help", 'h', arg_flag
, NULL
, NULL
, NULL
}
89 opt
.realm_max_ticket_life_string
= NULL
;
90 opt
.realm_max_renewable_life_string
= NULL
;
91 args
[0].value
= &opt
.realm_max_ticket_life_string
;
92 args
[1].value
= &opt
.realm_max_renewable_life_string
;
93 args
[2].value
= &help_flag
;
94 if(getarg(args
, 3, argc
, argv
, &optidx
))
96 if(argc
- optidx
< 1) {
97 fprintf(stderr
, "Arguments given (%u) are less than expected (1).\n\n", argc
- optidx
);
102 ret
= init(&opt
, argc
- optidx
, argv
+ optidx
);
105 arg_printusage (args
, 3, "init", "realm...");
110 load_wrap(int argc
, char **argv
)
114 struct getargs args
[] = {
115 { "help", 'h', arg_flag
, NULL
, NULL
, NULL
}
118 args
[0].value
= &help_flag
;
119 if(getarg(args
, 1, argc
, argv
, &optidx
))
121 if(argc
- optidx
!= 1) {
122 fprintf(stderr
, "Need exactly 1 parameters (%u given).\n\n", argc
- optidx
);
127 ret
= load(NULL
, argc
- optidx
, argv
+ optidx
);
130 arg_printusage (args
, 1, "load", "file");
135 merge_wrap(int argc
, char **argv
)
139 struct getargs args
[] = {
140 { "help", 'h', arg_flag
, NULL
, NULL
, NULL
}
143 args
[0].value
= &help_flag
;
144 if(getarg(args
, 1, argc
, argv
, &optidx
))
146 if(argc
- optidx
!= 1) {
147 fprintf(stderr
, "Need exactly 1 parameters (%u given).\n\n", argc
- optidx
);
152 ret
= merge(NULL
, argc
- optidx
, argv
+ optidx
);
155 arg_printusage (args
, 1, "merge", "file");
160 add_wrap(int argc
, char **argv
)
162 struct add_options opt
;
165 struct getargs args
[] = {
166 { "random-key", 'r', arg_flag
, NULL
, "set random key", NULL
},
167 { "random-password", 0, arg_flag
, NULL
, "set random password", NULL
},
168 { "password", 'p', arg_string
, NULL
, "principal's password", NULL
},
169 { "key", 0, arg_string
, NULL
, "DES-key in hex", NULL
},
170 { "max-ticket-life", 0, arg_string
, NULL
, "max ticket lifetime", "lifetime" },
171 { "max-renewable-life", 0, arg_string
, NULL
, "max renewable life", "lifetime" },
172 { "attributes", 0, arg_string
, NULL
, "principal attributes", "attributes" },
173 { "expiration-time", 0, arg_string
, NULL
, "principal expiration time", "time" },
174 { "pw-expiration-time", 0, arg_string
, NULL
, "password expiration time", "time" },
175 { "use-defaults", 0, arg_flag
, NULL
, "use default values", NULL
},
176 { "help", 'h', arg_flag
, NULL
, NULL
, NULL
}
179 opt
.random_key_flag
= 0;
180 opt
.random_password_flag
= 0;
181 opt
.password_string
= NULL
;
182 opt
.key_string
= NULL
;
183 opt
.max_ticket_life_string
= NULL
;
184 opt
.max_renewable_life_string
= NULL
;
185 opt
.attributes_string
= NULL
;
186 opt
.expiration_time_string
= NULL
;
187 opt
.pw_expiration_time_string
= NULL
;
188 opt
.use_defaults_flag
= 0;
189 args
[0].value
= &opt
.random_key_flag
;
190 args
[1].value
= &opt
.random_password_flag
;
191 args
[2].value
= &opt
.password_string
;
192 args
[3].value
= &opt
.key_string
;
193 args
[4].value
= &opt
.max_ticket_life_string
;
194 args
[5].value
= &opt
.max_renewable_life_string
;
195 args
[6].value
= &opt
.attributes_string
;
196 args
[7].value
= &opt
.expiration_time_string
;
197 args
[8].value
= &opt
.pw_expiration_time_string
;
198 args
[9].value
= &opt
.use_defaults_flag
;
199 args
[10].value
= &help_flag
;
200 if(getarg(args
, 11, argc
, argv
, &optidx
))
202 if(argc
- optidx
< 1) {
203 fprintf(stderr
, "Arguments given (%u) are less than expected (1).\n\n", argc
- optidx
);
208 ret
= add_new_key(&opt
, argc
- optidx
, argv
+ optidx
);
211 arg_printusage (args
, 11, "add", "principal...");
216 passwd_wrap(int argc
, char **argv
)
218 struct passwd_options opt
;
221 struct getargs args
[] = {
222 { "random-key", 'r', arg_flag
, NULL
, "set random key", NULL
},
223 { "random-password", 0, arg_flag
, NULL
, "set random password", NULL
},
224 { "password", 'p', arg_string
, NULL
, "princial's password", NULL
},
225 { "key", 0, arg_string
, NULL
, "DES key in hex", NULL
},
226 { "help", 'h', arg_flag
, NULL
, NULL
, NULL
}
229 opt
.random_key_flag
= 0;
230 opt
.random_password_flag
= 0;
231 opt
.password_string
= NULL
;
232 opt
.key_string
= NULL
;
233 args
[0].value
= &opt
.random_key_flag
;
234 args
[1].value
= &opt
.random_password_flag
;
235 args
[2].value
= &opt
.password_string
;
236 args
[3].value
= &opt
.key_string
;
237 args
[4].value
= &help_flag
;
238 if(getarg(args
, 5, argc
, argv
, &optidx
))
240 if(argc
- optidx
< 1) {
241 fprintf(stderr
, "Arguments given (%u) are less than expected (1).\n\n", argc
- optidx
);
246 ret
= cpw_entry(&opt
, argc
- optidx
, argv
+ optidx
);
249 arg_printusage (args
, 5, "passwd", "principal...");
254 delete_wrap(int argc
, char **argv
)
258 struct getargs args
[] = {
259 { "help", 'h', arg_flag
, NULL
, NULL
, NULL
}
262 args
[0].value
= &help_flag
;
263 if(getarg(args
, 1, argc
, argv
, &optidx
))
265 if(argc
- optidx
< 1) {
266 fprintf(stderr
, "Arguments given (%u) are less than expected (1).\n\n", argc
- optidx
);
271 ret
= del_entry(NULL
, argc
- optidx
, argv
+ optidx
);
274 arg_printusage (args
, 1, "delete", "principal...");
279 del_enctype_wrap(int argc
, char **argv
)
283 struct getargs args
[] = {
284 { "help", 'h', arg_flag
, NULL
, NULL
, NULL
}
287 args
[0].value
= &help_flag
;
288 if(getarg(args
, 1, argc
, argv
, &optidx
))
290 if(argc
- optidx
< 2) {
291 fprintf(stderr
, "Arguments given (%u) are less than expected (2).\n\n", argc
- optidx
);
296 ret
= del_enctype(NULL
, argc
- optidx
, argv
+ optidx
);
299 arg_printusage (args
, 1, "del_enctype", "principal enctype...");
304 add_enctype_wrap(int argc
, char **argv
)
306 struct add_enctype_options opt
;
309 struct getargs args
[] = {
310 { "random-key", 'r', arg_flag
, NULL
, "set random key", NULL
},
311 { "help", 'h', arg_flag
, NULL
, NULL
, NULL
}
314 opt
.random_key_flag
= 0;
315 args
[0].value
= &opt
.random_key_flag
;
316 args
[1].value
= &help_flag
;
317 if(getarg(args
, 2, argc
, argv
, &optidx
))
319 if(argc
- optidx
< 2) {
320 fprintf(stderr
, "Arguments given (%u) are less than expected (2).\n\n", argc
- optidx
);
325 ret
= add_enctype(&opt
, argc
- optidx
, argv
+ optidx
);
328 arg_printusage (args
, 2, "add_enctype", "principal enctype...");
333 ext_keytab_wrap(int argc
, char **argv
)
335 struct ext_keytab_options opt
;
338 struct getargs args
[] = {
339 { "keytab", 'k', arg_string
, NULL
, "keytab to use", NULL
},
340 { "help", 'h', arg_flag
, NULL
, NULL
, NULL
}
343 opt
.keytab_string
= NULL
;
344 args
[0].value
= &opt
.keytab_string
;
345 args
[1].value
= &help_flag
;
346 if(getarg(args
, 2, argc
, argv
, &optidx
))
348 if(argc
- optidx
< 1) {
349 fprintf(stderr
, "Arguments given (%u) are less than expected (1).\n\n", argc
- optidx
);
354 ret
= ext_keytab(&opt
, argc
- optidx
, argv
+ optidx
);
357 arg_printusage (args
, 2, "ext_keytab", "principal...");
362 get_wrap(int argc
, char **argv
)
364 struct get_options opt
;
367 struct getargs args
[] = {
368 { "long", 'l', arg_flag
, NULL
, "long format", NULL
},
369 { "short", 's', arg_flag
, NULL
, "short format", NULL
},
370 { "terse", 't', arg_flag
, NULL
, "terse format", NULL
},
371 { "column-info", 'o', arg_string
, NULL
, "columns to print for short output", NULL
},
372 { "help", 'h', arg_flag
, NULL
, NULL
, NULL
}
378 opt
.column_info_string
= NULL
;
379 args
[0].value
= &opt
.long_flag
;
380 args
[1].value
= &opt
.short_flag
;
381 args
[2].value
= &opt
.terse_flag
;
382 args
[3].value
= &opt
.column_info_string
;
383 args
[4].value
= &help_flag
;
384 if(getarg(args
, 5, argc
, argv
, &optidx
))
386 if(argc
- optidx
< 1) {
387 fprintf(stderr
, "Arguments given (%u) are less than expected (1).\n\n", argc
- optidx
);
392 ret
= get_entry(&opt
, argc
- optidx
, argv
+ optidx
);
395 arg_printusage (args
, 5, "get", "principal...");
400 rename_wrap(int argc
, char **argv
)
404 struct getargs args
[] = {
405 { "help", 'h', arg_flag
, NULL
, NULL
, NULL
}
408 args
[0].value
= &help_flag
;
409 if(getarg(args
, 1, argc
, argv
, &optidx
))
411 if(argc
- optidx
!= 2) {
412 fprintf(stderr
, "Need exactly 2 parameters (%u given).\n\n", argc
- optidx
);
417 ret
= rename_entry(NULL
, argc
- optidx
, argv
+ optidx
);
420 arg_printusage (args
, 1, "rename", "from to");
425 modify_wrap(int argc
, char **argv
)
427 struct modify_options opt
;
430 struct getargs args
[] = {
431 { "max-ticket-life", 0, arg_string
, NULL
, "max ticket lifetime", "lifetime" },
432 { "max-renewable-life", 0, arg_string
, NULL
, "max renewable life", "lifetime" },
433 { "attributes", 'a', arg_string
, NULL
, "principal attributes", "attributes" },
434 { "expiration-time", 0, arg_string
, NULL
, "principal expiration time", "time" },
435 { "pw-expiration-time", 0, arg_string
, NULL
, "password expiration time", "time" },
436 { "kvno", 0, arg_integer
, NULL
, "key version number", NULL
},
437 { "constrained-delegation", 0, arg_strings
, NULL
, "allowed target principals", "principal" },
438 { "alias", 0, arg_strings
, NULL
, "aliases", "principal" },
439 { "pkinit-acl", 0, arg_strings
, NULL
, "aliases", "subject dn" },
440 { "help", 'h', arg_flag
, NULL
, NULL
, NULL
}
443 opt
.max_ticket_life_string
= NULL
;
444 opt
.max_renewable_life_string
= NULL
;
445 opt
.attributes_string
= NULL
;
446 opt
.expiration_time_string
= NULL
;
447 opt
.pw_expiration_time_string
= NULL
;
448 opt
.kvno_integer
= -1;
449 opt
.constrained_delegation_strings
.num_strings
= 0;
450 opt
.constrained_delegation_strings
.strings
= NULL
;
451 opt
.alias_strings
.num_strings
= 0;
452 opt
.alias_strings
.strings
= NULL
;
453 opt
.pkinit_acl_strings
.num_strings
= 0;
454 opt
.pkinit_acl_strings
.strings
= NULL
;
455 args
[0].value
= &opt
.max_ticket_life_string
;
456 args
[1].value
= &opt
.max_renewable_life_string
;
457 args
[2].value
= &opt
.attributes_string
;
458 args
[3].value
= &opt
.expiration_time_string
;
459 args
[4].value
= &opt
.pw_expiration_time_string
;
460 args
[5].value
= &opt
.kvno_integer
;
461 args
[6].value
= &opt
.constrained_delegation_strings
;
462 args
[7].value
= &opt
.alias_strings
;
463 args
[8].value
= &opt
.pkinit_acl_strings
;
464 args
[9].value
= &help_flag
;
465 if(getarg(args
, 10, argc
, argv
, &optidx
))
467 if(argc
- optidx
!= 1) {
468 fprintf(stderr
, "Need exactly 1 parameters (%u given).\n\n", argc
- optidx
);
473 ret
= mod_entry(&opt
, argc
- optidx
, argv
+ optidx
);
474 free_getarg_strings (&opt
.constrained_delegation_strings
);
475 free_getarg_strings (&opt
.alias_strings
);
476 free_getarg_strings (&opt
.pkinit_acl_strings
);
479 arg_printusage (args
, 10, "modify", "principal");
480 free_getarg_strings (&opt
.constrained_delegation_strings
);
481 free_getarg_strings (&opt
.alias_strings
);
482 free_getarg_strings (&opt
.pkinit_acl_strings
);
487 privileges_wrap(int argc
, char **argv
)
491 struct getargs args
[] = {
492 { "help", 'h', arg_flag
, NULL
, NULL
, NULL
}
495 args
[0].value
= &help_flag
;
496 if(getarg(args
, 1, argc
, argv
, &optidx
))
498 if(argc
- optidx
> 0) {
499 fprintf(stderr
, "Arguments given (%u) are more than expected (0).\n\n", argc
- optidx
);
504 ret
= get_privs(NULL
, argc
- optidx
, argv
+ optidx
);
507 arg_printusage (args
, 1, "privileges", "");
512 list_wrap(int argc
, char **argv
)
514 struct list_options opt
;
517 struct getargs args
[] = {
518 { "long", 'l', arg_flag
, NULL
, "long format", NULL
},
519 { "short", 's', arg_flag
, NULL
, "short format", NULL
},
520 { "terse", 't', arg_flag
, NULL
, "terse format", NULL
},
521 { "column-info", 'o', arg_string
, NULL
, "columns to print for short output", NULL
},
522 { "help", 'h', arg_flag
, NULL
, NULL
, NULL
}
528 opt
.column_info_string
= NULL
;
529 args
[0].value
= &opt
.long_flag
;
530 args
[1].value
= &opt
.short_flag
;
531 args
[2].value
= &opt
.terse_flag
;
532 args
[3].value
= &opt
.column_info_string
;
533 args
[4].value
= &help_flag
;
534 if(getarg(args
, 5, argc
, argv
, &optidx
))
536 if(argc
- optidx
< 1) {
537 fprintf(stderr
, "Arguments given (%u) are less than expected (1).\n\n", argc
- optidx
);
542 ret
= list_princs(&opt
, argc
- optidx
, argv
+ optidx
);
545 arg_printusage (args
, 5, "list", "principal...");
550 verify_password_quality_wrap(int argc
, char **argv
)
554 struct getargs args
[] = {
555 { "help", 'h', arg_flag
, NULL
, NULL
, NULL
}
558 args
[0].value
= &help_flag
;
559 if(getarg(args
, 1, argc
, argv
, &optidx
))
561 if(argc
- optidx
!= 2) {
562 fprintf(stderr
, "Need exactly 2 parameters (%u given).\n\n", argc
- optidx
);
567 ret
= password_quality(NULL
, argc
- optidx
, argv
+ optidx
);
570 arg_printusage (args
, 1, "verify-password-quality", "principal password");
575 check_wrap(int argc
, char **argv
)
579 struct getargs args
[] = {
580 { "help", 'h', arg_flag
, NULL
, NULL
, NULL
}
583 args
[0].value
= &help_flag
;
584 if(getarg(args
, 1, argc
, argv
, &optidx
))
586 if(argc
- optidx
> 1) {
587 fprintf(stderr
, "Arguments given (%u) are more than expected (1).\n\n", argc
- optidx
);
590 if(argc
- optidx
< 0) {
591 fprintf(stderr
, "Arguments given (%u) are less than expected (0).\n\n", argc
- optidx
);
596 ret
= check(NULL
, argc
- optidx
, argv
+ optidx
);
599 arg_printusage (args
, 1, "check", "[realm]");
604 help_wrap(int argc
, char **argv
)
608 struct getargs args
[] = {
609 { "help", 'h', arg_flag
, NULL
, NULL
, NULL
}
612 args
[0].value
= &help_flag
;
613 if(getarg(args
, 1, argc
, argv
, &optidx
))
615 if(argc
- optidx
> 1) {
616 fprintf(stderr
, "Arguments given (%u) are more than expected (1).\n\n", argc
- optidx
);
619 if(argc
- optidx
< 0) {
620 fprintf(stderr
, "Arguments given (%u) are less than expected (0).\n\n", argc
- optidx
);
625 ret
= help(NULL
, argc
- optidx
, argv
+ optidx
);
628 arg_printusage (args
, 1, "help", "[command]");
633 exit_wrap(int argc
, char **argv
)
637 struct getargs args
[] = {
638 { "help", 'h', arg_flag
, NULL
, NULL
, NULL
}
641 args
[0].value
= &help_flag
;
642 if(getarg(args
, 1, argc
, argv
, &optidx
))
644 if(argc
- optidx
> 0) {
645 fprintf(stderr
, "Arguments given (%u) are more than expected (0).\n\n", argc
- optidx
);
650 ret
= exit_kadmin(NULL
, argc
- optidx
, argv
+ optidx
);
653 arg_printusage (args
, 1, "exit", "");
657 SL_cmd commands
[] = {
658 { "stash", stash_wrap
, "stash", "Writes the Kerberos master key to a file used by the KDC. \nLocal (-l) mode only." },
661 { "dump", dump_wrap
, "dump [dump-file]", "Dumps the database in a human readable format to the specified file, \nor the standard out. Local (-l) mode only." },
663 { "init", init_wrap
, "init realm...", "Initializes the default principals for a realm. Creates the database\nif necessary. Local (-l) mode only." },
665 { "load", load_wrap
, "load file", "Loads a previously dumped file. Local (-l) mode only." },
667 { "merge", merge_wrap
, "merge file", "Merges the contents of a dump file into the database. Local (-l) mode only." },
669 { "add", add_wrap
, "add principal...", "Adds a principal to the database." },
673 { "passwd", passwd_wrap
, "passwd principal...", "Changes the password of one or more principals matching the expressions." },
675 { "change_password" },
677 { "delete", delete_wrap
, "delete principal...", "Deletes all principals matching the expressions." },
681 { "del_enctype", del_enctype_wrap
, "del_enctype principal enctype...", "Delete all the mentioned enctypes for principal." },
683 { "add_enctype", add_enctype_wrap
, "add_enctype principal enctype...", "Add new enctypes for principal." },
685 { "ext_keytab", ext_keytab_wrap
, "ext_keytab principal...", "Extracts the keys of all principals matching the expressions, and stores them in a keytab." },
687 { "get", get_wrap
, "get principal...", "Shows information about principals matching the expressions." },
690 { "rename", rename_wrap
, "rename from to", "Renames a principal." },
692 { "modify", modify_wrap
, "modify principal", "Modifies some attributes of the specified principal." },
694 { "privileges", privileges_wrap
, "privileges", "Shows which operations you are allowed to perform." },
697 { "list", list_wrap
, "list principal...", "Lists principals in a terse format. Equivalent to \"get -t\"." },
699 { "verify-password-quality", verify_password_quality_wrap
, "verify-password-quality principal password", "Try run the password quality function locally (not doing RPC out to server)." },
702 { "check", check_wrap
, "check [realm]", "Check the realm (if not given, the default realm) for configuration errors." },
704 { "help", help_wrap
, "help [command]", "Help! I need somebody." },
707 { "exit", exit_wrap
, "exit", "Quits." },