2 * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
6 * Copyright 1994 by the Massachusetts Institute of Technology.
9 * Export of this software from the United States of America may
10 * require a specific license from the United States Government.
11 * It is the responsibility of any person or organization contemplating
12 * export to obtain such a license before exporting.
14 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
15 * distribute this software and its documentation for any purpose and
16 * without fee is hereby granted, provided that the above copyright
17 * notice appear in all copies and that both that copyright notice and
18 * this permission notice appear in supporting documentation, and that
19 * the name of M.I.T. not be used in advertising or publicity pertaining
20 * to distribution of the software without specific, written prior
21 * permission. Furthermore if you modify this software you must label
22 * your software as modified software and not distribute it in such a
23 * fashion that it might be confused with the original M.I.T. software.
24 * M.I.T. makes no representations about the suitability of
25 * this software for any purpose. It is provided "as is" without express
26 * or implied warranty.
28 * kadmin.c: base functions for a kadmin command line interface using
29 * the OVSecure library
32 #include <kadm5/admin.h>
33 #include <krb5/adm_proto.h>
36 #include <sys/types.h>
40 /* #include <sys/timeb.h> */
47 * Solaris: the following are needed for paging
52 /* command name when called "locally" (i.e. non-networked client ) */
53 #define KADMIN_LOCAL_NAME "kadmin.local"
55 /* functions defined in remote/local specific files */
56 extern void usage(const char *);
58 /* special struct to convert flag names for principals
59 to actual krb5_flags for a principal */
61 char *flagname
; /* name of flag as typed to CLI */
62 int flaglen
; /* length of string (not counting -,+) */
63 krb5_flags theflag
; /* actual principal flag to set/clear */
64 int set
; /* 0 means clear, 1 means set (on '-') */
67 static struct pflag flags
[] = {
68 {"allow_postdated", 15, KRB5_KDB_DISALLOW_POSTDATED
, 1},
69 {"allow_forwardable", 17, KRB5_KDB_DISALLOW_FORWARDABLE
, 1},
70 {"allow_tgs_req", 13, KRB5_KDB_DISALLOW_TGT_BASED
, 1},
71 {"allow_renewable", 15, KRB5_KDB_DISALLOW_RENEWABLE
, 1},
72 {"allow_proxiable", 15, KRB5_KDB_DISALLOW_PROXIABLE
, 1},
73 {"allow_dup_skey", 14, KRB5_KDB_DISALLOW_DUP_SKEY
, 1},
74 {"allow_tix", 9, KRB5_KDB_DISALLOW_ALL_TIX
, 1},
75 {"requires_preauth", 16, KRB5_KDB_REQUIRES_PRE_AUTH
, 0},
76 {"requires_hwauth", 15, KRB5_KDB_REQUIRES_HW_AUTH
, 0},
77 {"needchange", 10, KRB5_KDB_REQUIRES_PWCHANGE
, 0},
78 {"allow_svr", 9, KRB5_KDB_DISALLOW_SVR
, 1},
79 {"password_changing_service", 25, KRB5_KDB_PWCHANGE_SERVICE
, 0 },
80 {"support_desmd5", 14, KRB5_KDB_SUPPORT_DESMD5
, 0 }
83 static char *prflags
[] = {
84 "DISALLOW_POSTDATED", /* 0x00000001 */
85 "DISALLOW_FORWARDABLE", /* 0x00000002 */
86 "DISALLOW_TGT_BASED", /* 0x00000004 */
87 "DISALLOW_RENEWABLE", /* 0x00000008 */
88 "DISALLOW_PROXIABLE", /* 0x00000010 */
89 "DISALLOW_DUP_SKEY", /* 0x00000020 */
90 "DISALLOW_ALL_TIX", /* 0x00000040 */
91 "REQUIRES_PRE_AUTH", /* 0x00000080 */
92 "REQUIRES_HW_AUTH", /* 0x00000100 */
93 "REQUIRES_PWCHANGE", /* 0x00000200 */
94 "UNKNOWN_0x00000400", /* 0x00000400 */
95 "UNKNOWN_0x00000800", /* 0x00000800 */
96 "DISALLOW_SVR", /* 0x00001000 */
97 "PWCHANGE_SERVICE", /* 0x00002000 */
98 "SUPPORT_DESMD5", /* 0x00004000 */
99 "NEW_PRINC", /* 0x00008000 */
104 char *def_realm
= NULL
;
108 krb5_context context
;
109 char *ccache_name
= NULL
;
112 static char *strdur(duration
)
116 int neg
, days
, hours
, minutes
, seconds
;
123 days
= duration
/ (24 * 3600);
124 duration
%= 24 * 3600;
125 hours
= duration
/ 3600;
127 minutes
= duration
/ 60;
130 snprintf(out
, sizeof (out
), "%s%d %s %02d:%02d:%02d", neg
? "-" : "",
131 days
, days
== 1 ? gettext("day") : gettext("days"),
132 hours
, minutes
, seconds
);
136 static char *strdate(when
)
142 time_t lcltim
= when
;
143 tm
= localtime(&lcltim
);
144 strftime(out
, sizeof(out
), gettext("%a %b %d %H:%M:%S %Z %Y"), tm
);
148 /* this is a wrapper to go around krb5_parse_principal so we can set
149 the default realm up properly */
150 static krb5_error_code
151 kadmin_parse_name(name
, principal
)
153 krb5_principal
*principal
;
156 krb5_error_code retval
;
161 /* assumes def_realm is initialized! */
162 fullname
= (char *)malloc(strlen(name
) + 1 + strlen(def_realm
) + 1);
163 if (fullname
== NULL
)
165 strcpy(fullname
, name
);
166 cp
= strchr(fullname
, '@');
168 if (cp
- fullname
&& *(cp
- 1) != '\\')
171 cp
= strchr(cp
+ 1, '@');
174 strcat(fullname
, "@");
175 strcat(fullname
, def_realm
);
177 retval
= krb5_parse_name(context
, fullname
, principal
);
182 static void extended_com_err_fn (const char *myprog
, errcode_t code
,
183 const char *fmt
, va_list args
)
187 emsg
= krb5_get_error_message (context
, code
);
188 fprintf (stderr
, "%s: %s ", myprog
, emsg
);
189 krb5_free_error_message (context
, emsg
);
191 fprintf (stderr
, "%s: ", myprog
);
193 vfprintf (stderr
, fmt
, args
);
194 fprintf (stderr
, "\n");
196 char *kadmin_startup(argc
, argv
)
201 char *princstr
= NULL
, *keytab_name
= NULL
, *query
= NULL
;
202 char *password
= NULL
;
203 char *luser
, *canon
, *cp
;
204 int optchar
, freeprinc
= 0, use_keytab
= 0;
208 krb5_principal princ
;
209 kadm5_config_params params
;
210 char **db_args
= NULL
;
211 int db_args_size
= 0;
212 char *db_name
= NULL
;
213 char *svcname
= NULL
;
215 memset((char *) ¶ms
, 0, sizeof(params
));
217 if (strcmp (whoami
, "kadmin.local") == 0)
218 set_com_err_hook(extended_com_err_fn
);
220 retval
= kadm5_init_krb5_context(&context
);
222 com_err(whoami
, retval
, gettext("while initializing krb5 library"));
226 while ((optchar
= getopt(argc
, argv
, "x:r:p:kq:w:d:s:mc:t:e:ON")) != EOF
) {
231 char **temp
= reallocarray(db_args
, db_args_size
+ 1,
234 fprintf(stderr
, gettext("%s: Cannot initialize. Not enough memory\n"),
241 db_args
[db_args_size
-1] = optarg
;
242 db_args
[db_args_size
] = NULL
;
252 ccache_name
= optarg
;
258 keytab_name
= optarg
;
267 /* now db_name is not a seperate argument. It has to be passed as part of the db_args */
269 db_name
= malloc(strlen(optarg
) + sizeof("dbname="));
271 db_name
= realloc(db_name
, strlen(optarg
) + sizeof("dbname="));
274 strcpy(db_name
, "dbname=");
275 strcat(db_name
, optarg
);
279 char **temp
= reallocarray(db_args
, db_args_size
+ 1,
280 sizeof (char *)); /* one for NULL */
283 gettext("%s: Cannot initialize. Not enough memory\n"),
290 db_args
[db_args_size
-1] = db_name
;
291 db_args
[db_args_size
] = NULL
;
294 params
.admin_server
= optarg
;
295 params
.mask
|= KADM5_CONFIG_ADMIN_SERVER
;
298 params
.mkey_from_kbd
= 1;
299 params
.mask
|= KADM5_CONFIG_MKEY_FROM_KBD
;
302 retval
= krb5_string_to_keysalts(optarg
,
307 ¶ms
.num_keysalts
);
309 com_err(whoami
, retval
,
310 gettext("while parsing keysalts %s"), optarg
);
313 params
.mask
|= KADM5_CONFIG_ENCTYPES
;
315 case 'O': /* Undocumented option for testing only */
316 svcname
= KADM5_ADMIN_SERVICE_P
;
322 if ((ccache_name
&& use_keytab
) ||
323 (keytab_name
&& !use_keytab
))
326 if (def_realm
== NULL
&& krb5_get_default_realm(context
, &def_realm
)) {
330 gettext("%s: unable to get default realm\n"), whoami
);
334 params
.mask
|= KADM5_CONFIG_REALM
;
335 params
.realm
= def_realm
;
337 if (svcname
== NULL
) {
338 if (kadm5_get_adm_host_srv_name(context
,
339 def_realm
, &svcname
)) {
341 gettext("%s: unable to get host based "
342 "service name for realm %s\n"),
351 * Set cc to an open credentials cache, either specified by the -c
352 * argument or the default.
354 if (ccache_name
== NULL
) {
355 if ((retval
= krb5_cc_default(context
, &cc
))) {
356 com_err(whoami
, retval
,
357 gettext("while opening default "
358 "credentials cache"));
362 if ((retval
= krb5_cc_resolve(context
, ccache_name
, &cc
))) {
363 com_err(whoami
, retval
,
364 gettext("while opening credentials cache %s"),
371 * If no principal name is specified: If a ccache was specified
372 * and its primary principal name can be read, it is used, else if
373 * a keytab was specified, the principal name is host/hostname,
374 * otherwise append "/admin" to the primary name of the default
375 * ccache, $USER, or pw_name.
377 * Gee, 100+ lines to figure out the client principal name. This
378 * should be compressed...
381 if (princstr
== NULL
) {
382 if (ccache_name
!= NULL
&&
383 !krb5_cc_get_principal(context
, cc
, &princ
)) {
384 if ((retval
= krb5_unparse_name(context
, princ
, &princstr
))) {
385 com_err(whoami
, retval
,
386 gettext("while canonicalizing principal name"));
387 krb5_free_principal(context
, princ
);
390 krb5_free_principal(context
, princ
);
392 } else if (use_keytab
!= 0) {
393 if ((retval
= krb5_sname_to_principal(context
, NULL
,
397 com_err(whoami
, retval
,
398 gettext("creating host service principal"));
401 if ((retval
= krb5_unparse_name(context
, princ
, &princstr
))) {
402 com_err(whoami
, retval
,
403 gettext("while canonicalizing principal name"));
404 krb5_free_principal(context
, princ
);
407 krb5_free_principal(context
, princ
);
409 } else if (!krb5_cc_get_principal(context
, cc
, &princ
)) {
411 if (krb5_unparse_name(context
, princ
, &canon
)) {
413 gettext("%s: unable to canonicalize "
414 "principal\n"), whoami
);
415 krb5_free_principal(context
, princ
);
418 /* strip out realm of principal if it's there */
419 realm
= strchr(canon
, '@');
421 if (realm
- canon
&& *(realm
- 1) != '\\')
424 realm
= strchr(realm
+1, '@');
428 cp
= strchr(canon
, '/');
430 if (cp
- canon
&& *(cp
- 1) != '\\')
433 cp
= strchr(cp
+1, '/');
437 princstr
= (char*)malloc(strlen(canon
) + 6 /* "/admin" */ +
438 (realm
? 1 + strlen(realm
) : 0) + 1);
439 if (princstr
== NULL
) {
441 gettext("%s: out of memory\n"),
445 strcpy(princstr
, canon
);
446 strcat(princstr
, "/admin");
448 strcat(princstr
, "@");
449 strcat(princstr
, realm
);
452 krb5_free_principal(context
, princ
);
454 } else if ((luser
= getenv("USER"))) {
455 princstr
= (char *) malloc(strlen(luser
) + 7 /* "/admin@" */
456 + strlen(def_realm
) + 1);
457 if (princstr
== NULL
) {
459 gettext("%s: out of memory\n"),
463 strcpy(princstr
, luser
);
464 strcat(princstr
, "/admin");
465 strcat(princstr
, "@");
466 strcat(princstr
, def_realm
);
468 } else if ((pw
= getpwuid(getuid()))) {
469 princstr
= (char *) malloc(strlen(pw
->pw_name
) + 7 /* "/admin@" */
470 + strlen(def_realm
) + 1);
471 if (princstr
== NULL
) {
473 gettext("%s: out of memory\n"),
477 strcpy(princstr
, pw
->pw_name
);
478 strcat(princstr
, "/admin@");
479 strcat(princstr
, def_realm
);
483 gettext("%s: unable to figure out "
484 "a principal name\n"),
490 retval
= krb5_klog_init(context
, "admin_server", whoami
, 0);
492 com_err(whoami
, retval
, "while setting up logging");
497 * Initialize the kadm5 connection. If we were given a ccache,
498 * use it. Otherwise, use/prompt for the password.
502 * Send warnings to stderr
505 fprintf(stderr
, gettext("Authenticating as principal %s with existing credentials.\n"),
507 retval
= kadm5_init_with_creds(princstr
, cc
,
510 KADM5_STRUCT_VERSION
,
514 } else if (use_keytab
) {
516 fprintf(stderr
, gettext("Authenticating as principal %s with keytab %s.\n"),
517 princstr
, keytab_name
);
519 fprintf(stderr
, gettext("Authenticating as principal %s with default keytab.\n"),
521 retval
= kadm5_init_with_skey(princstr
, keytab_name
,
524 KADM5_STRUCT_VERSION
,
529 fprintf(stderr
, gettext("Authenticating as principal %s with password.\n"),
531 retval
= kadm5_init_with_password(princstr
, password
,
534 KADM5_STRUCT_VERSION
,
540 if (retval
== KADM5_RPC_ERROR_CANTENCODEARGS
||
541 retval
== KADM5_RPC_ERROR_CANTDECODEARGS
) {
542 com_err(whoami
, KADM5_RPC_ERROR
,
543 gettext("while initializing %s interface"), whoami
);
545 /* privacy-enabled mech probably not installed/configed */
546 com_err(whoami
, retval
, gettext("."), whoami
);
548 com_err(whoami
, retval
,
549 gettext("while initializing %s interface"), whoami
);
550 if (retval
== KADM5_BAD_CLIENT_PARAMS
||
551 retval
== KADM5_BAD_SERVER_PARAMS
)
560 free(db_name
), db_name
=NULL
;
563 free(db_args
), db_args
=NULL
;
565 if ((retval
= krb5_cc_close(context
, cc
))) {
566 com_err(whoami
, retval
, gettext("while closing ccache %s"),
571 /* register the WRFILE keytab type and set it as the default */
573 #define DEFAULT_KEYTAB "WRFILE:/etc/krb5/krb5.keytab"
574 /* XXX krb5_defkeyname is an internal library global and
576 extern char *krb5_defkeyname
;
577 krb5_defkeyname
= DEFAULT_KEYTAB
;
580 if ((retval
= kadm5_init_iprop(handle
)) != 0) {
581 com_err(whoami
, retval
, gettext("while mapping update log"));
585 /* Solaris kerberos: fix memory leak */
596 retval
= kadm5_unlock(handle
);
598 com_err("quit", retval
, gettext("while unlocking locked database"));
604 kadm5_destroy(handle
);
605 if (ccache_name
!= NULL
) {
607 gettext("\n\a\a\aAdministration credentials "
608 "NOT DESTROYED.\n"));
611 /* insert more random cleanup here */
612 krb5_klog_close(context
);
613 krb5_free_context(context
);
618 void kadmin_lock(argc
, argv
)
626 retval
= kadm5_lock(handle
);
628 com_err("lock", retval
, "");
634 void kadmin_unlock(argc
, argv
)
642 retval
= kadm5_unlock(handle
);
644 com_err("unlock", retval
, "");
650 void kadmin_delprinc(argc
, argv
)
655 krb5_principal princ
;
660 (argc
== 3 && !strcmp("-force", argv
[1])))) {
661 fprintf(stderr
, "%s: delete_principal [-force] %s\n",
662 gettext("usage"), gettext("principal"));
665 retval
= kadmin_parse_name(argv
[argc
- 1], &princ
);
667 com_err("delete_principal", retval
,
668 gettext("while parsing principal name"));
671 retval
= krb5_unparse_name(context
, princ
, &canon
);
673 com_err("delete_principal", retval
,
674 gettext("while canonicalizing principal"));
675 krb5_free_principal(context
, princ
);
679 printf(gettext("Are you sure you want to delete "
680 "the principal \"%s\"? (yes/no): "), canon
);
681 fgets(reply
, sizeof (reply
), stdin
);
682 if (strncmp(gettext("yes\n"), reply
, sizeof (reply
)) &&
683 strncmp(gettext("y\n"), reply
, sizeof (reply
)) &&
684 strncmp(gettext("Y\n"), reply
, sizeof (reply
))) {
686 gettext("Principal \"%s\" not deleted\n"),
689 krb5_free_principal(context
, princ
);
693 retval
= kadm5_delete_principal(handle
, princ
);
694 krb5_free_principal(context
, princ
);
696 com_err("delete_principal", retval
,
697 gettext("while deleting principal \"%s\""), canon
);
701 printf(gettext("Principal \"%s\" deleted.\n"), canon
);
702 printf(gettext("Make sure that you have removed this principal "
703 "from all ACLs before reusing.\n"));
708 void kadmin_cpw(argc
, argv
)
713 static char newpw
[1024];
714 static char prompt1
[1024], prompt2
[1024];
717 int n_ks_tuple
= 0, randkey
= 0;
718 krb5_boolean keepold
= FALSE
;
719 krb5_key_salt_tuple
*ks_tuple
= NULL
;
720 krb5_principal princ
;
721 char **db_args
= NULL
;
722 int db_args_size
= 0;
723 int local_kadmin
= 0;
725 local_kadmin
= (strcmp(whoami
, KADMIN_LOCAL_NAME
) == 0);
730 for (argv
++, argc
--; argc
> 1; argc
--, argv
++) {
731 if (!strcmp("-x", *argv
)) {
734 fprintf(stderr
, gettext("change_password: missing db argument\n"));
739 char **temp
= reallocarray(db_args
, db_args_size
+ 1,
740 sizeof (char *)); /* one for NULL */
742 fprintf(stderr
, gettext("change_password: Not enough memory\n"));
743 free(db_args
), db_args
= NULL
;
749 db_args
[db_args_size
-1] = *++argv
;
750 db_args
[db_args_size
] = NULL
;
753 if (!strcmp("-pw", *argv
)) {
756 fprintf(stderr
, "change_password: %s",
757 gettext("missing password arg\n"));
763 if (!strcmp("-randkey", *argv
)) {
767 if (!strcmp("-keepold", *argv
)) {
771 if (!strcmp("-e", *argv
)) {
774 fprintf(stderr
, "change_password: %s",
775 gettext("missing keysaltlist arg\n"));
778 retval
= krb5_string_to_keysalts(*++argv
, ", \t", ":.-", 0,
779 &ks_tuple
, &n_ks_tuple
);
781 com_err("change_password", retval
,
782 gettext("while parsing keysalts %s"), *argv
);
790 com_err("change_password", 0, "missing principal name");
793 retval
= kadmin_parse_name(*argv
, &princ
);
795 com_err("change_password", retval
,
796 gettext("while parsing principal name"));
801 retval
= krb5_unparse_name(context
, princ
, &canon
);
803 com_err("change_password", retval
,
804 gettext("while canonicalizing principal"));
805 krb5_free_principal(context
, princ
);
811 if (keepold
|| ks_tuple
!= NULL
) {
812 retval
= kadm5_chpass_principal_3(handle
, princ
, keepold
,
813 n_ks_tuple
, ks_tuple
, pwarg
);
816 retval
= kadm5_chpass_principal(handle
, princ
, pwarg
);
818 krb5_free_principal(context
, princ
);
820 com_err("change_password", retval
,
821 gettext("while changing password for \"%s\"."),
827 printf(gettext("Password for \"%s\" changed.\n"), canon
);
831 } else if (randkey
) {
832 if (keepold
|| ks_tuple
!= NULL
|| local_kadmin
) {
833 retval
= kadm5_randkey_principal_3(handle
, princ
, keepold
,
834 n_ks_tuple
, ks_tuple
,
838 retval
= kadm5_randkey_principal(handle
, princ
, NULL
, NULL
);
840 krb5_free_principal(context
, princ
);
842 com_err("change_password", retval
,
843 gettext("while randomizing key for \"%s\"."),
849 printf(gettext("Key for \"%s\" randomized.\n"), canon
);
853 } else if (argc
== 1) {
854 unsigned int i
= sizeof (newpw
) - 1;
856 snprintf(prompt1
, sizeof (prompt1
),
857 gettext("Enter password for principal \"%.900s\""),
859 snprintf(prompt2
, sizeof (prompt2
),
860 gettext("Re-enter password for principal \"%.900s\""),
862 retval
= krb5_read_password(context
, prompt1
, prompt2
,
865 com_err("change_password", retval
,
866 gettext("while reading password for \"%s\"."),
870 krb5_free_principal(context
, princ
);
874 if (keepold
|| ks_tuple
!= NULL
) {
875 retval
= kadm5_chpass_principal_3(handle
, princ
, keepold
,
876 n_ks_tuple
, ks_tuple
,
880 retval
= kadm5_chpass_principal(handle
, princ
, newpw
);
882 krb5_free_principal(context
, princ
);
883 memset(newpw
, 0, sizeof (newpw
));
885 com_err("change_password", retval
,
886 gettext("while changing password for \"%s\"."),
892 printf(gettext("Password for \"%s\" changed.\n"), canon
);
898 krb5_free_principal(context
, princ
);
901 fprintf(stderr
, "%s: change_password [-randkey] [-keepold] "
902 "[-e keysaltlist] [-pw password] %s\n",
903 gettext("usage"), gettext("principal"));
909 kadmin_free_tl_data(kadm5_principal_ent_t princ
)
911 krb5_tl_data
*tl_data
= princ
->tl_data
;
912 int n_tl_data
= princ
->n_tl_data
;
915 princ
->n_tl_data
= 0;
916 princ
->tl_data
= NULL
;
918 for (i
= 0; tl_data
&& (i
< n_tl_data
); i
++) {
919 krb5_tl_data
*next
= tl_data
->tl_data_next
;
920 free(tl_data
->tl_data_contents
);
926 #define KRB5_TL_DB_ARGS 0x7fff
928 kadmin_parse_princ_args(argc
, argv
, oprinc
, mask
, pass
, randkey
,
929 ks_tuple
, n_ks_tuple
, caller
)
932 kadm5_principal_ent_t oprinc
;
936 krb5_key_salt_tuple
**ks_tuple
;
940 int i
, j
, attrib_set
;
943 krb5_error_code retval
;
944 krb5_tl_data
*tl_data
, *tail
= NULL
;
952 for (i
= 1; i
< argc
- 1; i
++) {
954 if (strlen(argv
[i
]) == 2 &&
955 !strcmp("-x",argv
[i
])) {
959 tl_data
= malloc(sizeof(krb5_tl_data
));
960 if (tl_data
== NULL
) {
961 fprintf(stderr
, gettext("Not enough memory\n"));
965 memset(tl_data
, 0, sizeof(krb5_tl_data
));
966 tl_data
->tl_data_type
= KRB5_TL_DB_ARGS
;
967 tl_data
->tl_data_length
= strlen(argv
[i
])+1;
968 tl_data
->tl_data_contents
= (unsigned char*)strdup(argv
[i
]);
971 tail
->tl_data_next
= tl_data
;
973 oprinc
->tl_data
= tl_data
;
978 if (tl_data
->tl_data_contents
== NULL
) {
979 fprintf(stderr
, gettext("Not enough memory\n"));
982 *mask
|= KADM5_TL_DATA
;
985 if (strlen(argv
[i
]) == 7 &&
986 !strcmp("-expire", argv
[i
])) {
990 date
= get_date(argv
[i
]);
991 if (date
== (time_t)-1) {
993 gettext("Invalid date "
999 oprinc
->princ_expire_time
= date
;
1000 *mask
|= KADM5_PRINC_EXPIRE_TIME
;
1004 if (strlen(argv
[i
]) == 9 &&
1005 !strcmp("-pwexpire", argv
[i
])) {
1009 date
= get_date(argv
[i
]);
1010 if (date
== (time_t)-1) {
1012 gettext("Invalid date "
1018 oprinc
->pw_expiration
= date
;
1019 *mask
|= KADM5_PW_EXPIRATION
;
1023 if (strlen(argv
[i
]) == 8 &&
1024 !strcmp("-maxlife", argv
[i
])) {
1028 date
= get_date(argv
[i
]);
1029 if (date
== (time_t)-1) {
1031 gettext("Invalid date "
1037 oprinc
->max_life
= date
- now
;
1038 *mask
|= KADM5_MAX_LIFE
;
1042 if (strlen(argv
[i
]) == 13 &&
1043 !strcmp("-maxrenewlife", argv
[i
])) {
1047 date
= get_date(argv
[i
]);
1048 if (date
== (time_t)-1) {
1050 gettext("Invalid date "
1056 oprinc
->max_renewable_life
= date
- now
;
1057 *mask
|= KADM5_MAX_RLIFE
;
1061 if (strlen(argv
[i
]) == 5 &&
1062 !strcmp("-kvno", argv
[i
])) {
1066 oprinc
->kvno
= atoi(argv
[i
]);
1067 *mask
|= KADM5_KVNO
;
1071 if (strlen(argv
[i
]) == 7 &&
1072 !strcmp("-policy", argv
[i
])) {
1076 oprinc
->policy
= argv
[i
];
1077 *mask
|= KADM5_POLICY
;
1081 if (strlen(argv
[i
]) == 12 &&
1082 !strcmp("-clearpolicy", argv
[i
])) {
1083 oprinc
->policy
= NULL
;
1084 *mask
|= KADM5_POLICY_CLR
;
1087 if (strlen(argv
[i
]) == 3 &&
1088 !strcmp("-pw", argv
[i
])) {
1096 if (strlen(argv
[i
]) == 8 &&
1097 !strcmp("-randkey", argv
[i
])) {
1101 if (!strcmp("-e", argv
[i
])) {
1105 retval
= krb5_string_to_keysalts(argv
[i
], ", \t", ":.-", 0,
1106 ks_tuple
, n_ks_tuple
);
1108 com_err(caller
, retval
,
1109 gettext("while parsing keysalts %s"), argv
[i
]);
1115 for (j
= 0; j
< sizeof (flags
) / sizeof (struct pflag
); j
++) {
1116 if (strlen(argv
[i
]) == flags
[j
].flaglen
+ 1 &&
1117 !strcmp(flags
[j
].flagname
,
1118 &argv
[i
][1] /* strip off leading + or - */)) {
1119 if ((flags
[j
].set
&& argv
[i
][0] == '-') ||
1120 (!flags
[j
].set
&& argv
[i
][0] == '+')) {
1121 oprinc
->attributes
|= flags
[j
].theflag
;
1122 *mask
|= KADM5_ATTRIBUTES
;
1125 } else if ((flags
[j
].set
&& argv
[i
][0] == '+') ||
1126 (!flags
[j
].set
&& argv
[i
][0] == '-')) {
1127 oprinc
->attributes
&= ~flags
[j
].theflag
;
1128 *mask
|= KADM5_ATTRIBUTES
;
1137 return -1; /* nothing was parsed */
1139 if (i
!= argc
- 1) {
1142 retval
= kadmin_parse_name(argv
[i
], &oprinc
->principal
);
1144 com_err(caller
, retval
, gettext("while parsing principal"));
1151 kadmin_addprinc_usage(func
)
1154 fprintf(stderr
, "%s: %s %s\n", gettext("usage"), func
,
1155 gettext("[options] principal"));
1156 fprintf(stderr
, gettext("\toptions are:\n"));
1157 fprintf(stderr
, "\t\t[-expire expdate] [-pwexpire pwexpdate] "
1158 "[-maxlife maxtixlife]\n\t\t[-kvno kvno] [-policy policy] "
1159 "[-randkey] [-pw password]\n\t\t[-maxrenewlife maxrenewlife] "
1160 "[-e keysaltlist] [{+|-}attribute]\n");
1161 fprintf(stderr
, gettext("\tattributes are:\n"));
1162 fprintf(stderr
, "%s%s%s",
1163 "\t\tallow_postdated allow_forwardable allow_tgs_req "
1164 "allow_renewable\n",
1165 "\t\tallow_proxiable allow_dup_skey allow_tix "
1166 "requires_preauth\n",
1167 "\t\trequires_hwauth needchange allow_svr "
1168 "password_changing_service\n");
1172 kadmin_modprinc_usage(func
)
1175 fprintf(stderr
, "%s: %s %s\n", gettext("usage"), func
,
1176 gettext("[options] principal"));
1177 fprintf(stderr
, gettext("\toptions are:\n"));
1178 fprintf(stderr
, "\t\t[-expire expdate] [-pwexpire pwexpdate] "
1179 "[-maxlife maxtixlife]\n\t\t[-kvno kvno] [-policy policy] "
1180 "[-clearpolicy]\n\t\t[-maxrenewlife maxrenewlife] "
1181 "[{+|-}attribute]\n");
1182 fprintf(stderr
, gettext("\tattributes are:\n"));
1183 fprintf(stderr
, "%s%s%s",
1184 "\t\tallow_postdated allow_forwardable allow_tgs_req "
1185 "allow_renewable\n",
1186 "\t\tallow_proxiable allow_dup_skey allow_tix "
1187 "requires_preauth\n",
1188 "\t\trequires_hwauth needchange allow_svr "
1189 "password_changing_service\n");
1192 void kadmin_addprinc(argc
, argv
)
1196 kadm5_principal_ent_rec princ
, dprinc
;
1197 kadm5_policy_ent_rec defpol
;
1201 krb5_key_salt_tuple
*ks_tuple
;
1203 krb5_error_code retval
;
1204 static char newpw
[1024], dummybuf
[256];
1205 static char prompt1
[1024], prompt2
[1024];
1206 int local_kadmin
= 0;
1208 local_kadmin
= (strcmp(whoami
, KADMIN_LOCAL_NAME
) == 0);
1210 if (dummybuf
[0] == 0) {
1211 for (i
= 0; i
< 256; i
++)
1212 dummybuf
[i
] = (i
+1) % 256;
1215 /* Zero all fields in request structure */
1216 memset(&princ
, 0, sizeof(princ
));
1217 memset(&dprinc
, 0, sizeof(dprinc
));
1219 princ
.attributes
= dprinc
.attributes
= 0;
1220 if (kadmin_parse_princ_args(argc
, argv
,
1221 &princ
, &mask
, &pass
, &randkey
,
1222 &ks_tuple
, &n_ks_tuple
,
1224 kadmin_addprinc_usage("add_principal");
1225 kadmin_free_tl_data(&princ
); /* need to free ks_tuple also??? */
1229 retval
= krb5_unparse_name(context
, princ
.principal
, &canon
);
1231 com_err("add_principal",
1232 retval
, gettext("while canonicalizing principal"));
1233 krb5_free_principal(context
, princ
.principal
);
1235 kadmin_free_tl_data(&princ
);
1240 * If -policy was not specified, and -clearpolicy was not
1241 * specified, and the policy "default" exists, assign it. If
1242 * -clearpolicy was specified, then KADM5_POLICY_CLR should be
1243 * unset, since it is never valid for kadm5_create_principal.
1245 if ((! (mask
& KADM5_POLICY
)) &&
1246 (! (mask
& KADM5_POLICY_CLR
))) {
1247 if (! kadm5_get_policy(handle
, "default", &defpol
)) {
1249 gettext("NOTICE: no policy specified for %s; assigning \"default\"\n"),
1251 princ
.policy
= "default";
1252 mask
|= KADM5_POLICY
;
1253 (void) kadm5_free_policy_ent(handle
, &defpol
);
1256 gettext("WARNING: no policy specified for %s; defaulting to no policy\n"),
1259 mask
&= ~KADM5_POLICY_CLR
;
1262 * Set 'notix' for randkey principals and also for principals which have
1263 * specified flag options on the cmdline. This is because we want to apply
1264 * generic flag settings from 'default_principal_flags' first (during
1265 * principal creation), followed by a kadm5_modify_principal() which
1266 * correctly applies the cli flag options. So, we do *not* want any tix
1267 * issued in the interim.
1269 if (randkey
|| (mask
& KADM5_ATTRIBUTES
))
1270 princ
.attributes
|= KRB5_KDB_DISALLOW_ALL_TIX
;
1273 mask
|= KADM5_ATTRIBUTES
;
1275 } else if (pass
== NULL
) {
1276 unsigned int sz
= sizeof (newpw
) - 1;
1277 snprintf(prompt1
, sizeof (prompt1
),
1278 gettext("Enter password for principal \"%.900s\""),
1280 snprintf(prompt2
, sizeof (prompt1
),
1281 gettext("Re-enter password for principal \"%.900s\""),
1283 retval
= krb5_read_password(context
, prompt1
, prompt2
,
1286 com_err("add_principal", retval
,
1287 gettext("while reading password for \"%s\"."), canon
);
1289 krb5_free_principal(context
, princ
.principal
);
1290 kadmin_free_tl_data(&princ
);
1295 mask
|= KADM5_PRINCIPAL
;
1298 * If the client being used is local, always use the new
1299 * API so we get the full set of enctype support.
1301 if (ks_tuple
!= NULL
|| local_kadmin
) {
1302 retval
= kadm5_create_principal_3(handle
, &princ
, mask
,
1303 n_ks_tuple
, ks_tuple
, pass
);
1305 retval
= kadm5_create_principal(handle
, &princ
, mask
, pass
);
1308 com_err("add_principal", retval
,
1309 gettext("while creating \"%s\"."), canon
);
1310 krb5_free_principal(context
, princ
.principal
);
1313 kadmin_free_tl_data(&princ
);
1316 if (randkey
) { /* more special stuff for -randkey */
1317 if (ks_tuple
!= NULL
|| local_kadmin
) {
1318 retval
= kadm5_randkey_principal_3(handle
, princ
.principal
,
1320 n_ks_tuple
, ks_tuple
,
1323 retval
= kadm5_randkey_principal(handle
, princ
.principal
,
1327 com_err("add_principal", retval
,
1328 gettext("while randomizing key for \"%s\"."), canon
);
1329 krb5_free_principal(context
, princ
.principal
);
1332 kadmin_free_tl_data(&princ
);
1338 * We now retrieve the intersection set of the generic flag settings and
1339 * the ones specified on the cli & re-parse the princ args, just to make
1340 * sure we account for conflicts between 'default_principal_flags' and
1341 * the cmdline flag args. While we are here, also clear 'notix'.
1343 if (randkey
|| (mask
& KADM5_ATTRIBUTES
)) {
1344 retval
= kadm5_get_principal(handle
, princ
.principal
, &dprinc
,
1345 KADM5_PRINCIPAL_NORMAL_MASK
);
1347 if (dprinc
.attributes
!= 0)
1348 princ
.attributes
= dprinc
.attributes
;
1350 com_err("add_principal", retval
,
1351 gettext("while doing a get_principal on \"%s\"."), canon
);
1352 printf(gettext("\nWarning: Principal \"%s\" could have incomplete "
1353 "flag settings, as a result of a failed get_principal.\n"
1354 "Check the 'default_principal_flags' setting in kdc.conf(4).\n"
1355 "If there is a mismatch, use modprinc in kadmin(1M) to rectify "
1356 "the same.\n\n"), canon
);
1360 * Solaris Kerberos: We unset KRB5_KDB_DISALLOW_ALL_TIX before
1361 * kadmin_parse_princ_args is called, because -allow_tix may
1362 * have been an argument. We still have to unset here because
1363 * kadmin_parse_princ_args will not reset the attribute unless
1364 * it is was explicity defined.
1366 princ
.attributes
&= ~KRB5_KDB_DISALLOW_ALL_TIX
;
1367 (void) kadmin_parse_princ_args(argc
, argv
, &princ
, &mask
, &pass
,
1368 &randkey
, &ks_tuple
, &n_ks_tuple
, "add_principal");
1369 mask
= KADM5_ATTRIBUTES
;
1370 retval
= kadm5_modify_principal(handle
, &princ
, mask
);
1372 com_err("add_principal", retval
,
1373 gettext("while doing a modify_principal to restore flag "
1374 "settings for \"%s\"."), canon
);
1375 krb5_free_principal(context
, princ
.principal
);
1378 kadmin_free_tl_data(&princ
);
1382 krb5_free_principal(context
, princ
.principal
);
1383 printf(gettext("Principal \"%s\" created.\n"), canon
);
1386 kadmin_free_tl_data(&princ
);
1390 void kadmin_modprinc(argc
, argv
)
1394 kadm5_principal_ent_rec princ
, oldprinc
;
1395 krb5_principal kprinc
;
1397 krb5_error_code retval
;
1401 krb5_key_salt_tuple
*ks_tuple
;
1404 kadmin_modprinc_usage("modify_principal");
1408 memset(&oldprinc
, 0, sizeof(oldprinc
));
1409 memset(&princ
, 0, sizeof(princ
));
1411 retval
= kadmin_parse_name(argv
[argc
- 1], &kprinc
);
1413 com_err("modify_principal", retval
,
1414 gettext("while parsing principal"));
1417 retval
= krb5_unparse_name(context
, kprinc
, &canon
);
1419 com_err("modify_principal", retval
,
1420 gettext("while canonicalizing principal"));
1421 krb5_free_principal(context
, kprinc
);
1424 retval
= kadm5_get_principal(handle
, kprinc
, &oldprinc
,
1425 KADM5_PRINCIPAL_NORMAL_MASK
);
1426 krb5_free_principal(context
, kprinc
);
1428 com_err("modify_principal", retval
,
1429 gettext("while getting \"%s\"."), canon
);
1433 princ
.attributes
= oldprinc
.attributes
;
1434 kadm5_free_principal_ent(handle
, &oldprinc
);
1435 retval
= kadmin_parse_princ_args(argc
, argv
,
1438 &ks_tuple
, &n_ks_tuple
,
1439 "modify_principal");
1440 if (ks_tuple
!= NULL
) {
1442 kadmin_modprinc_usage("modify_principal");
1444 kadmin_free_tl_data(&princ
);
1448 kadmin_modprinc_usage("modify_principal");
1450 kadmin_free_tl_data(&princ
);
1454 fprintf(stderr
, "modify_principal: -randkey %s ",
1455 gettext("not allowed\n"));
1456 krb5_free_principal(context
, princ
.principal
);
1458 kadmin_free_tl_data(&princ
);
1463 "modify_principal: -pw %s change_password\n",
1464 gettext("not allowed; use"));
1465 krb5_free_principal(context
, princ
.principal
);
1467 kadmin_free_tl_data(&princ
);
1470 retval
= kadm5_modify_principal(handle
, &princ
, mask
);
1471 krb5_free_principal(context
, princ
.principal
);
1473 com_err("modify_principal", retval
,
1474 gettext("while modifying \"%s\"."), canon
);
1476 kadmin_free_tl_data(&princ
);
1479 printf(gettext("Principal \"%s\" modified.\n"), canon
);
1480 kadmin_free_tl_data(&princ
);
1484 void kadmin_getprinc(argc
, argv
)
1488 kadm5_principal_ent_rec dprinc
;
1489 krb5_principal princ
;
1490 krb5_error_code retval
;
1491 char *canon
, *modcanon
;
1495 (argc
== 3 && !strcmp("-terse", argv
[1])))) {
1496 fprintf(stderr
, "%s: get_principal [-terse] %s\n",
1497 gettext("usage"), gettext("principal"));
1502 memset(&dprinc
, 0, sizeof(dprinc
));
1503 memset(&princ
, 0, sizeof(princ
));
1505 retval
= kadmin_parse_name(argv
[argc
- 1], &princ
);
1507 com_err("get_principal", retval
,
1508 gettext("while parsing principal"));
1511 retval
= krb5_unparse_name(context
, princ
, &canon
);
1513 com_err("get_principal", retval
,
1514 gettext("while canonicalizing principal"));
1515 krb5_free_principal(context
, princ
);
1518 retval
= kadm5_get_principal(handle
, princ
, &dprinc
,
1519 KADM5_PRINCIPAL_NORMAL_MASK
| KADM5_KEY_DATA
);
1520 krb5_free_principal(context
, princ
);
1522 com_err("get_principal", retval
,
1523 gettext("while retrieving \"%s\"."), canon
);
1527 retval
= krb5_unparse_name(context
, dprinc
.mod_name
, &modcanon
);
1529 com_err("get_principal", retval
,
1530 gettext("while unparsing modname"));
1531 kadm5_free_principal_ent(handle
, &dprinc
);
1536 printf(gettext("Principal: %s\n"), canon
);
1537 printf(gettext("Expiration date: %s\n"),
1538 dprinc
.princ_expire_time
?
1539 strdate(dprinc
.princ_expire_time
) :
1540 gettext("[never]"));
1541 printf(gettext("Last password change: %s\n"),
1542 dprinc
.last_pwd_change
?
1543 strdate(dprinc
.last_pwd_change
) :
1544 gettext("[never]"));
1545 printf(gettext("Password expiration date: %s\n"),
1546 dprinc
.pw_expiration
?
1547 strdate(dprinc
.pw_expiration
) : gettext("[none]"));
1548 printf(gettext("Maximum ticket life: %s\n"),
1549 strdur(dprinc
.max_life
));
1550 printf(gettext("Maximum renewable life: %s\n"),
1551 strdur(dprinc
.max_renewable_life
));
1552 printf(gettext("Last modified: %s (%s)\n"),
1553 strdate(dprinc
.mod_date
), modcanon
);
1554 printf(gettext("Last successful authentication: %s\n"),
1555 dprinc
.last_success
? strdate(dprinc
.last_success
) :
1556 gettext("[never]"));
1557 printf(gettext("Last failed authentication: %s\n"),
1558 dprinc
.last_failed
? strdate(dprinc
.last_failed
) :
1559 gettext("[never]"));
1560 printf(gettext("Failed password attempts: %d\n"),
1561 dprinc
.fail_auth_count
);
1562 printf(gettext("Number of keys: %d\n"), dprinc
.n_key_data
);
1563 for (i
= 0; i
< dprinc
.n_key_data
; i
++) {
1564 krb5_key_data
*key_data
= &dprinc
.key_data
[i
];
1565 char enctype
[BUFSIZ
], salttype
[BUFSIZ
];
1567 if (krb5_enctype_to_string(key_data
->key_data_type
[0],
1568 enctype
, sizeof(enctype
)))
1569 snprintf(enctype
, sizeof (enctype
), gettext("<Encryption type 0x%x>"),
1570 key_data
->key_data_type
[0]);
1571 printf("Key: vno %d, %s, ", key_data
->key_data_kvno
, enctype
);
1572 if (key_data
->key_data_ver
> 1) {
1573 if (krb5_salttype_to_string(key_data
->key_data_type
[1],
1574 salttype
, sizeof(salttype
)))
1575 snprintf(salttype
, sizeof(salttype
), gettext("<Salt type 0x%x>"),
1576 key_data
->key_data_type
[1]);
1577 printf("%s\n", salttype
);
1579 printf(gettext("no salt\n"));
1582 printf(gettext("Attributes:"));
1583 for (i
= 0; i
< sizeof (prflags
) / sizeof (char *); i
++) {
1584 if (dprinc
.attributes
& (krb5_flags
) 1 << i
)
1585 printf(" %s", prflags
[i
]);
1588 printf(gettext("Policy: %s\n"),
1589 dprinc
.policy
? dprinc
.policy
: gettext("[none]"));
1591 printf("\"%s\"\t%d\t%d\t%d\t%d\t\"%s\"\t%d\t%d\t%d\t%d\t\"%s\""
1592 "\t%d\t%d\t%d\t%d\t%d",
1593 canon
, dprinc
.princ_expire_time
, dprinc
.last_pwd_change
,
1594 dprinc
.pw_expiration
, dprinc
.max_life
, modcanon
,
1595 dprinc
.mod_date
, dprinc
.attributes
, dprinc
.kvno
,
1596 dprinc
.mkvno
, dprinc
.policy
? dprinc
.policy
: gettext("[none]"),
1597 dprinc
.max_renewable_life
, dprinc
.last_success
,
1598 dprinc
.last_failed
, dprinc
.fail_auth_count
,
1600 for (i
= 0; i
< dprinc
.n_key_data
; i
++)
1601 printf("\t%d\t%d\t%d\t%d",
1602 dprinc
.key_data
[i
].key_data_ver
,
1603 dprinc
.key_data
[i
].key_data_kvno
,
1604 dprinc
.key_data
[i
].key_data_type
[0],
1605 dprinc
.key_data
[i
].key_data_type
[1]);
1609 kadm5_free_principal_ent(handle
, &dprinc
);
1613 void kadmin_getprincs(argc
, argv
)
1617 krb5_error_code retval
;
1618 char *expr
, **names
;
1623 struct sigaction nsig
, osig
;
1624 sigset_t nmask
, omask
;
1628 if (! (argc
== 1 || (argc
== 2 && (expr
= argv
[1])))) {
1629 fprintf(stderr
, "%s: get_principals %s\n",
1630 gettext("usage"), gettext("[expression]"));
1633 retval
= kadm5_get_principals(handle
, expr
, &names
, &count
);
1635 com_err("get_principals", retval
,
1636 gettext("while retrieving list."));
1641 * Solaris: the following code is used for paging
1644 sigemptyset(&nmask
);
1645 sigaddset(&nmask
, SIGINT
);
1646 sigprocmask(SIG_BLOCK
, &nmask
, &omask
);
1648 nsig
.sa_handler
= SIG_IGN
;
1649 sigemptyset(&nsig
.sa_mask
);
1651 sigaction(SIGINT
, &nsig
, &osig
);
1653 fd
= ss_pager_create();
1654 output
= fdopen(fd
, "w");
1656 sigprocmask(SIG_SETMASK
, &omask
, (sigset_t
*)0);
1658 for (i
= 0; i
< count
; i
++)
1659 fprintf(output
, "%s\n", names
[i
]);
1665 /* Solaris Kerberos:
1666 * Restore the original handler for SIGINT
1668 if (sigaction(SIGINT
, &osig
, NULL
) == -1) {
1669 perror("sigaction");
1672 kadm5_free_name_list(handle
, names
, count
);
1676 kadmin_parse_policy_args(argc
, argv
, policy
, mask
, caller
)
1679 kadm5_policy_ent_t policy
;
1689 for (i
= 1; i
< argc
- 1; i
++) {
1690 if (strlen(argv
[i
]) == 8 &&
1691 !strcmp(argv
[i
], "-maxlife")) {
1695 date
= get_date(argv
[i
]);
1696 if (date
== (time_t)-1) {
1697 fprintf(stderr
, gettext("Invalid date specification \"%s\".\n"),
1701 policy
->pw_max_life
= date
- now
;
1702 *mask
|= KADM5_PW_MAX_LIFE
;
1705 } else if (strlen(argv
[i
]) == 8 &&
1706 !strcmp(argv
[i
], "-minlife")) {
1710 date
= get_date(argv
[i
]);
1711 if (date
== (time_t)-1) {
1712 fprintf(stderr
, gettext("Invalid date specification \"%s\".\n"),
1716 policy
->pw_min_life
= date
- now
;
1717 *mask
|= KADM5_PW_MIN_LIFE
;
1720 } else if (strlen(argv
[i
]) == 10 &&
1721 !strcmp(argv
[i
], "-minlength")) {
1725 policy
->pw_min_length
= atoi(argv
[i
]);
1726 *mask
|= KADM5_PW_MIN_LENGTH
;
1729 } else if (strlen(argv
[i
]) == 11 &&
1730 !strcmp(argv
[i
], "-minclasses")) {
1734 policy
->pw_min_classes
= atoi(argv
[i
]);
1735 *mask
|= KADM5_PW_MIN_CLASSES
;
1738 } else if (strlen(argv
[i
]) == 8 &&
1739 !strcmp(argv
[i
], "-history")) {
1743 policy
->pw_history_num
= atoi(argv
[i
]);
1744 *mask
|= KADM5_PW_HISTORY_NUM
;
1751 fprintf(stderr
, gettext("%s: parser lost count!\n"), caller
);
1758 kadmin_addmodpol_usage(func
)
1761 fprintf(stderr
, "%s: %s %s\n", gettext("usage"), func
,
1762 gettext("[options] policy"));
1763 fprintf(stderr
, gettext("\toptions are:\n"));
1764 fprintf(stderr
, "\t\t[-maxlife time] [-minlife time] "
1765 "[-minlength length]\n\t\t[-minclasses number] "
1766 "[-history number]\n");
1769 void kadmin_addpol(argc
, argv
)
1773 krb5_error_code retval
;
1775 kadm5_policy_ent_rec policy
;
1777 memset(&policy
, 0, sizeof(policy
));
1778 if (kadmin_parse_policy_args(argc
, argv
, &policy
, &mask
, "add_policy")) {
1779 kadmin_addmodpol_usage("add_policy");
1782 policy
.policy
= argv
[argc
- 1];
1783 mask
|= KADM5_POLICY
;
1784 retval
= kadm5_create_policy(handle
, &policy
, mask
);
1786 com_err("add_policy", retval
,
1787 gettext("while creating policy \"%s\"."),
1795 void kadmin_modpol(argc
, argv
)
1799 krb5_error_code retval
;
1801 kadm5_policy_ent_rec policy
;
1803 memset(&policy
, 0, sizeof(policy
));
1804 if (kadmin_parse_policy_args(argc
, argv
, &policy
, &mask
,
1806 kadmin_addmodpol_usage("modify_policy");
1809 policy
.policy
= argv
[argc
- 1];
1810 retval
= kadm5_modify_policy(handle
, &policy
, mask
);
1812 com_err("modify_policy", retval
, gettext("while modifying policy \"%s\"."),
1820 void kadmin_delpol(argc
, argv
)
1824 krb5_error_code retval
;
1828 (argc
== 3 && !strcmp("-force", argv
[1])))) {
1829 fprintf(stderr
, "%s: delete_policy [-force] %s\n",
1830 gettext("usage"), gettext("policy"));
1834 printf(gettext("Are you sure you want to delete the policy "
1835 "\"%s\"? (yes/no): "), argv
[1]);
1836 fgets(reply
, sizeof (reply
), stdin
);
1837 if (strncmp(gettext("yes\n"), reply
, sizeof (reply
)) &&
1838 strncmp(gettext("y\n"), reply
, sizeof (reply
)) &&
1839 strncmp(gettext("Y\n"), reply
, sizeof (reply
))
1842 gettext("Policy \"%s\" not deleted.\n"),
1847 retval
= kadm5_delete_policy(handle
, argv
[argc
- 1]);
1849 com_err("delete_policy:", retval
,
1850 gettext("while deleting policy \"%s\""),
1857 void kadmin_getpol(argc
, argv
)
1861 krb5_error_code retval
;
1862 kadm5_policy_ent_rec policy
;
1865 (argc
== 3 && !strcmp("-terse", argv
[1])))) {
1866 fprintf(stderr
, "%s: get_policy [-terse] %s\n",
1867 gettext("usage"), gettext("policy"));
1870 retval
= kadm5_get_policy(handle
, argv
[argc
- 1], &policy
);
1872 com_err("get_policy", retval
,
1873 gettext("while retrieving policy \"%s\"."),
1878 printf(gettext("Policy: %s\n"), policy
.policy
);
1879 printf(gettext("Maximum password life: %ld\n"),
1880 policy
.pw_max_life
);
1881 printf(gettext("Minimum password life: %ld\n"),
1882 policy
.pw_min_life
);
1883 printf(gettext("Minimum password length: %ld\n"),
1884 policy
.pw_min_length
);
1885 printf(gettext("Minimum number of password "
1886 "character classes: %ld\n"),
1887 policy
.pw_min_classes
);
1888 printf(gettext("Number of old keys kept: %ld\n"),
1889 policy
.pw_history_num
);
1890 printf(gettext("Reference count: %ld\n"), policy
.policy_refcnt
);
1892 printf("\"%s\"\t%ld\t%ld\t%ld\t%ld\t%ld\t%ld\n",
1893 policy
.policy
, policy
.pw_max_life
, policy
.pw_min_life
,
1894 policy
.pw_min_length
, policy
.pw_min_classes
,
1895 policy
.pw_history_num
, policy
.policy_refcnt
);
1897 kadm5_free_policy_ent(handle
, &policy
);
1901 void kadmin_getpols(argc
, argv
)
1905 krb5_error_code retval
;
1906 char *expr
, **names
;
1909 /* Solaris Kerberos:
1910 * Use a pager for listing policies (similar to listing princs)
1912 FILE *output
= NULL
;
1914 struct sigaction nsig
, osig
;
1915 sigset_t nmask
, omask
;
1919 if (! (argc
== 1 || (argc
== 2 && (expr
= argv
[1])))) {
1920 fprintf(stderr
, "%s: get_policies %s\n",
1921 gettext("usage"), gettext("[expression]\n"));
1924 retval
= kadm5_get_policies(handle
, expr
, &names
, &count
);
1926 com_err("get_policies", retval
,
1927 gettext("while retrieving list."));
1931 if (sigemptyset(&nmask
) == -1) {
1932 perror("sigemptyset");
1933 kadm5_free_name_list(handle
, names
, count
);
1937 if (sigaddset(&nmask
, SIGINT
) == -1) {
1938 perror("sigaddset");
1939 kadm5_free_name_list(handle
, names
, count
);
1943 if (sigemptyset(&nsig
.sa_mask
) == -1) {
1944 perror("sigemptyset");
1945 kadm5_free_name_list(handle
, names
, count
);
1949 if (sigprocmask(SIG_BLOCK
, &nmask
, &omask
) == -1) {
1950 perror("sigprocmask");
1951 kadm5_free_name_list(handle
, names
, count
);
1955 nsig
.sa_handler
= SIG_IGN
;
1957 if (sigaction(SIGINT
, &nsig
, &osig
) == -1) {
1958 perror("sigaction");
1959 if (sigprocmask(SIG_SETMASK
, &omask
, (sigset_t
*)0) == -1) {
1960 perror("sigprocmask");
1962 kadm5_free_name_list(handle
, names
, count
);
1966 fd
= ss_pager_create();
1968 fprintf(stderr
, "%s: failed to create pager\n", whoami
);
1969 if (sigprocmask(SIG_SETMASK
, &omask
, (sigset_t
*)0) == -1) {
1970 perror("sigprocmask");
1973 if (sigaction(SIGINT
, &osig
, NULL
) == -1) {
1974 perror("sigaction");
1977 kadm5_free_name_list(handle
, names
, count
);
1981 output
= fdopen(fd
, "w");
1982 if (output
== NULL
) {
1986 if (sigprocmask(SIG_SETMASK
, &omask
, (sigset_t
*)0) == -1) {
1987 perror("sigprocmask");
1990 if (output
!= NULL
) {
1991 for (i
= 0; i
< count
; i
++)
1992 fprintf(output
, "%s\n", names
[i
]);
1995 if (output
!= NULL
&& fclose(output
) != 0) {
1999 if (wait(&waitb
) == -1) {
2003 if (sigaction(SIGINT
, &osig
, NULL
) == -1) {
2004 perror("sigaction");
2006 kadm5_free_name_list(handle
, names
, count
);