2 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
7 * kadmin/ldap_util/kdb5_ldap_realm.c
9 * Copyright 1990,1991,2001, 2002 by the Massachusetts Institute of Technology.
10 * All Rights Reserved.
12 * Export of this software from the United States of America may
13 * require a specific license from the United States Government.
14 * It is the responsibility of any person or organization contemplating
15 * export to obtain such a license before exporting.
17 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
18 * distribute this software and its documentation for any purpose and
19 * without fee is hereby granted, provided that the above copyright
20 * notice appear in all copies and that both that copyright notice and
21 * this permission notice appear in supporting documentation, and that
22 * the name of M.I.T. not be used in advertising or publicity pertaining
23 * to distribution of the software without specific, written prior
24 * permission. Furthermore if you modify this software you must label
25 * your software as modified software and not distribute it in such a
26 * fashion that it might be confused with the original M.I.T. software.
27 * M.I.T. makes no representations about the suitability of
28 * this software for any purpose. It is provided "as is" without express
29 * or implied warranty.
33 * Copyright (C) 1998 by the FundsXpress, INC.
35 * All rights reserved.
37 * Export of this software from the United States of America may require
38 * a specific license from the United States Government. It is the
39 * responsibility of any person or organization contemplating export to
40 * obtain such a license before exporting.
42 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
43 * distribute this software and its documentation for any purpose and
44 * without fee is hereby granted, provided that the above copyright
45 * notice appear in all copies and that both that copyright notice and
46 * this permission notice appear in supporting documentation, and that
47 * the name of FundsXpress. not be used in advertising or publicity pertaining
48 * to distribution of the software without specific, written prior
49 * permission. FundsXpress makes no representations about the suitability of
50 * this software for any purpose. It is provided "as is" without express
51 * or implied warranty.
53 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
54 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
55 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
58 /* Copyright (c) 2004-2005, Novell, Inc.
59 * All rights reserved.
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions are met:
64 * * Redistributions of source code must retain the above copyright notice,
65 * this list of conditions and the following disclaimer.
66 * * Redistributions in binary form must reproduce the above copyright
67 * notice, this list of conditions and the following disclaimer in the
68 * documentation and/or other materials provided with the distribution.
69 * * The copyright holder's name is not used to endorse or promote products
70 * derived from this software without specific prior written permission.
72 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
73 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
74 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
75 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
76 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
77 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
78 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
79 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
80 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
81 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
82 * POSSIBILITY OF SUCH DAMAGE.
86 * Create / Modify / Destroy / View / List realm(s)
89 /* Needed for getting the definition of KRB5_TL_DB_ARGS */
94 #include <kadm5/admin.h>
97 #include "kdb5_ldap_util.h"
98 #include "kdb5_ldap_list.h"
99 #include <ldap_principal.h>
100 #include <ldap_krbcontainer.h>
101 extern time_t get_date(char *); /* kadmin/cli/getdate.o */
103 char *yes
= "yes\n"; /* \n to compare against result of fgets */
104 krb5_key_salt_tuple def_kslist
= {ENCTYPE_DES_CBC_CRC
, KRB5_KDB_SALTTYPE_NORMAL
};
106 struct realm_info rblock
= {
111 (krb5_keyblock
*) NULL
,
116 krb5_data tgt_princ_entries
[] = {
117 {0, KRB5_TGS_NAME_SIZE
, KRB5_TGS_NAME
},
120 krb5_data db_creator_entries
[] = {
121 {0, sizeof("db_creation")-1, "db_creation"} };
124 static krb5_principal_data db_create_princ
= {
125 0, /* magic number */
126 {0, 0, 0}, /* krb5_data realm */
127 db_creator_entries
, /* krb5_data *data */
129 KRB5_NT_SRV_INST
/* int type */
132 extern char *mkey_password
;
133 extern char *progname
;
134 extern kadm5_config_params global_params
;
136 static void print_realm_params(krb5_ldap_realm_params
*rparams
, int mask
);
137 static int kdb_ldap_create_principal (krb5_context context
, krb5_principal
138 princ
, enum ap_op op
, struct realm_info
*pblock
);
141 static char *strdur(time_t duration
);
142 static int get_ticket_policy(krb5_ldap_realm_params
*rparams
, int *i
, char *argv
[],int argc
);
143 static krb5_error_code
krb5_dbe_update_mod_princ_data_new (krb5_context context
, krb5_db_entry
*entry
, krb5_timestamp mod_date
, krb5_const_principal mod_princ
);
144 static krb5_error_code
krb5_dbe_update_tl_data_new ( krb5_context context
, krb5_db_entry
*entry
, krb5_tl_data
*new_tl_data
);
146 #define ADMIN_LIFETIME 60*60*3 /* 3 hours */
147 #define CHANGEPW_LIFETIME 60*5 /* 5 minutes */
149 static int get_ticket_policy(rparams
,i
,argv
,argc
)
150 krb5_ldap_realm_params
*rparams
;
158 krb5_error_code retval
= 0;
159 krb5_boolean no_msg
= FALSE
;
161 krb5_boolean print_usage
= FALSE
;
162 /* Solaris Kerberos */
166 if (!strcmp(argv
[*i
], "-maxtktlife")) {
169 date
= get_date(argv
[*i
]);
170 if (date
== (time_t)(-1)) {
172 com_err (me
, retval
, gettext("while providing time specification"));
175 rparams
->max_life
= date
-now
;
176 mask
|= LDAP_REALM_MAXTICKETLIFE
;
180 else if (!strcmp(argv
[*i
], "-maxrenewlife")) {
184 date
= get_date(argv
[*i
]);
185 if (date
== (time_t)(-1)) {
187 com_err (me
, retval
, gettext("while providing time specification"));
190 rparams
->max_renewable_life
= date
-now
;
191 mask
|= LDAP_REALM_MAXRENEWLIFE
;
192 } else if (!strcmp((argv
[*i
] + 1), "allow_postdated")) {
193 if (*(argv
[*i
]) == '+')
194 rparams
->tktflags
&= (int)(~KRB5_KDB_DISALLOW_POSTDATED
);
195 else if (*(argv
[*i
]) == '-')
196 rparams
->tktflags
|= KRB5_KDB_DISALLOW_POSTDATED
;
200 mask
|= LDAP_REALM_KRBTICKETFLAGS
;
201 } else if (!strcmp((argv
[*i
] + 1), "allow_forwardable")) {
202 if (*(argv
[*i
]) == '+')
203 rparams
->tktflags
&= (int)(~KRB5_KDB_DISALLOW_FORWARDABLE
);
205 else if (*(argv
[*i
]) == '-')
206 rparams
->tktflags
|= KRB5_KDB_DISALLOW_FORWARDABLE
;
210 mask
|= LDAP_REALM_KRBTICKETFLAGS
;
211 } else if (!strcmp((argv
[*i
] + 1), "allow_renewable")) {
212 if (*(argv
[*i
]) == '+')
213 rparams
->tktflags
&= (int)(~KRB5_KDB_DISALLOW_RENEWABLE
);
214 else if (*(argv
[*i
]) == '-')
215 rparams
->tktflags
|= KRB5_KDB_DISALLOW_RENEWABLE
;
219 mask
|= LDAP_REALM_KRBTICKETFLAGS
;
220 } else if (!strcmp((argv
[*i
] + 1), "allow_proxiable")) {
221 if (*(argv
[*i
]) == '+')
222 rparams
->tktflags
&= (int)(~KRB5_KDB_DISALLOW_PROXIABLE
);
223 else if (*(argv
[*i
]) == '-')
224 rparams
->tktflags
|= KRB5_KDB_DISALLOW_PROXIABLE
;
228 mask
|= LDAP_REALM_KRBTICKETFLAGS
;
229 } else if (!strcmp((argv
[*i
] + 1), "allow_dup_skey")) {
230 if (*(argv
[*i
]) == '+')
231 rparams
->tktflags
&= (int)(~KRB5_KDB_DISALLOW_DUP_SKEY
);
232 else if (*(argv
[*i
]) == '-')
233 rparams
->tktflags
|= KRB5_KDB_DISALLOW_DUP_SKEY
;
237 mask
|= LDAP_REALM_KRBTICKETFLAGS
;
240 else if (!strcmp((argv
[*i
] + 1), "requires_preauth")) {
241 if (*(argv
[*i
]) == '+')
242 rparams
->tktflags
|= KRB5_KDB_REQUIRES_PRE_AUTH
;
243 else if (*(argv
[*i
]) == '-')
244 rparams
->tktflags
&= (int)(~KRB5_KDB_REQUIRES_PRE_AUTH
);
248 mask
|= LDAP_REALM_KRBTICKETFLAGS
;
249 } else if (!strcmp((argv
[*i
] + 1), "requires_hwauth")) {
250 if (*(argv
[*i
]) == '+')
251 rparams
->tktflags
|= KRB5_KDB_REQUIRES_HW_AUTH
;
252 else if (*(argv
[*i
]) == '-')
253 rparams
->tktflags
&= (int)(~KRB5_KDB_REQUIRES_HW_AUTH
);
257 mask
|= LDAP_REALM_KRBTICKETFLAGS
;
258 } else if (!strcmp((argv
[*i
] + 1), "allow_svr")) {
259 if (*(argv
[*i
]) == '+')
260 rparams
->tktflags
&= (int)(~KRB5_KDB_DISALLOW_SVR
);
261 else if (*(argv
[*i
]) == '-')
262 rparams
->tktflags
|= KRB5_KDB_DISALLOW_SVR
;
266 mask
|= LDAP_REALM_KRBTICKETFLAGS
;
267 } else if (!strcmp((argv
[*i
] + 1), "allow_tgs_req")) {
268 if (*(argv
[*i
]) == '+')
269 rparams
->tktflags
&= (int)(~KRB5_KDB_DISALLOW_TGT_BASED
);
270 else if (*(argv
[*i
]) == '-')
271 rparams
->tktflags
|= KRB5_KDB_DISALLOW_TGT_BASED
;
275 mask
|= LDAP_REALM_KRBTICKETFLAGS
;
276 } else if (!strcmp((argv
[*i
] + 1), "allow_tix")) {
277 if (*(argv
[*i
]) == '+')
278 rparams
->tktflags
&= (int)(~KRB5_KDB_DISALLOW_ALL_TIX
);
279 else if (*(argv
[*i
]) == '-')
280 rparams
->tktflags
|= KRB5_KDB_DISALLOW_ALL_TIX
;
284 mask
|= LDAP_REALM_KRBTICKETFLAGS
;
285 } else if (!strcmp((argv
[*i
] + 1), "needchange")) {
286 if (*(argv
[*i
]) == '+')
287 rparams
->tktflags
|= KRB5_KDB_REQUIRES_PWCHANGE
;
288 else if (*(argv
[*i
]) == '-')
289 rparams
->tktflags
&= (int)(~KRB5_KDB_REQUIRES_PWCHANGE
);
293 mask
|= LDAP_REALM_KRBTICKETFLAGS
;
294 } else if (!strcmp((argv
[*i
] + 1), "password_changing_service")) {
295 if (*(argv
[*i
]) == '+')
296 rparams
->tktflags
|= KRB5_KDB_PWCHANGE_SERVICE
;
297 else if (*(argv
[*i
]) == '-')
298 rparams
->tktflags
&= (int)(~KRB5_KDB_PWCHANGE_SERVICE
);
302 mask
|=LDAP_REALM_KRBTICKETFLAGS
;
314 * This function will create a realm on the LDAP Server, with
315 * the specified attributes.
317 void kdb5_ldap_create(argc
, argv
)
321 krb5_error_code retval
= 0;
322 krb5_keyblock master_keyblock
;
323 krb5_ldap_realm_params
*rparams
= NULL
;
324 krb5_principal master_princ
= NULL
;
325 kdb5_dal_handle
*dal_handle
= NULL
;
326 krb5_ldap_context
*ldap_context
=NULL
;
327 krb5_boolean realm_obj_created
= FALSE
;
328 krb5_boolean create_complete
= FALSE
;
329 krb5_boolean print_usage
= FALSE
;
330 krb5_boolean no_msg
= FALSE
;
331 char *oldcontainerref
=NULL
;
335 int mask
= 0, ret_mask
= 0;
337 #ifdef HAVE_EDIRECTORY
341 memset(&master_keyblock
, 0, sizeof(master_keyblock
));
343 rparams
= (krb5_ldap_realm_params
*)malloc(
344 sizeof(krb5_ldap_realm_params
));
345 if (rparams
== NULL
) {
349 memset(rparams
, 0, sizeof(krb5_ldap_realm_params
));
351 /* Parse the arguments */
352 for (i
= 1; i
< argc
; i
++) {
353 if (!strcmp(argv
[i
], "-subtrees")) {
357 if(strncmp(argv
[i
], "", strlen(argv
[i
]))!=0) {
358 list
= (char **) calloc(MAX_LIST_ENTRIES
, sizeof(char *));
363 if ((retval
= krb5_parse_list(argv
[i
], LIST_DELIMITER
, list
))) {
369 rparams
->subtreecount
=0;
370 while(list
[rparams
->subtreecount
]!=NULL
)
371 (rparams
->subtreecount
)++;
372 rparams
->subtree
= list
;
373 } else if(strncmp(argv
[i
], "", strlen(argv
[i
]))==0) {
374 /* dont allow subtree value to be set at the root(NULL, "") of the tree */
375 /* Solaris Kerberos */
376 com_err(progname
, EINVAL
,
377 gettext("for subtree while creating realm '%s'"),
378 global_params
.realm
);
381 rparams
->subtree
[rparams
->subtreecount
] = NULL
;
382 mask
|= LDAP_REALM_SUBTREE
;
383 } else if (!strcmp(argv
[i
], "-containerref")) {
386 if(strncmp(argv
[i
], "", strlen(argv
[i
]))==0) {
387 /* dont allow containerref value to be set at the root(NULL, "") of the tree */
388 /* Solaris Kerberos */
389 com_err(progname
, EINVAL
,
390 gettext("for container reference while creating realm '%s'"),
391 global_params
.realm
);
394 rparams
->containerref
= strdup(argv
[i
]);
395 if (rparams
->containerref
== NULL
) {
399 mask
|= LDAP_REALM_CONTREF
;
400 } else if (!strcmp(argv
[i
], "-sscope")) {
403 /* Possible values for search scope are
404 * one (or 1) and sub (or 2)
406 if (!strcasecmp(argv
[i
], "one")) {
407 rparams
->search_scope
= 1;
408 } else if (!strcasecmp(argv
[i
], "sub")) {
409 rparams
->search_scope
= 2;
411 rparams
->search_scope
= atoi(argv
[i
]);
412 if ((rparams
->search_scope
!= 1) &&
413 (rparams
->search_scope
!= 2)) {
414 /* Solaris Kerberos */
415 com_err(progname
, EINVAL
,
416 gettext("invalid search scope while creating realm '%s'"),
417 global_params
.realm
);
421 mask
|= LDAP_REALM_SEARCHSCOPE
;
423 #ifdef HAVE_EDIRECTORY
424 else if (!strcmp(argv
[i
], "-kdcdn")) {
427 rparams
->kdcservers
= (char **)malloc(
428 sizeof(char *) * MAX_LIST_ENTRIES
);
429 if (rparams
->kdcservers
== NULL
) {
433 memset(rparams
->kdcservers
, 0, sizeof(char*)*MAX_LIST_ENTRIES
);
434 if ((retval
= krb5_parse_list(argv
[i
], LIST_DELIMITER
,
435 rparams
->kdcservers
))) {
438 mask
|= LDAP_REALM_KDCSERVERS
;
439 } else if (!strcmp(argv
[i
], "-admindn")) {
442 rparams
->adminservers
= (char **)malloc(
443 sizeof(char *) * MAX_LIST_ENTRIES
);
444 if (rparams
->adminservers
== NULL
) {
448 memset(rparams
->adminservers
, 0, sizeof(char*)*MAX_LIST_ENTRIES
);
449 if ((retval
= krb5_parse_list(argv
[i
], LIST_DELIMITER
,
450 rparams
->adminservers
))) {
453 mask
|= LDAP_REALM_ADMINSERVERS
;
454 } else if (!strcmp(argv
[i
], "-pwddn")) {
457 rparams
->passwdservers
= (char **)malloc(
458 sizeof(char *) * MAX_LIST_ENTRIES
);
459 if (rparams
->passwdservers
== NULL
) {
463 memset(rparams
->passwdservers
, 0, sizeof(char*)*MAX_LIST_ENTRIES
);
464 if ((retval
= krb5_parse_list(argv
[i
], LIST_DELIMITER
,
465 rparams
->passwdservers
))) {
468 mask
|= LDAP_REALM_PASSWDSERVERS
;
471 else if (!strcmp(argv
[i
], "-s")) {
473 } else if ((ret_mask
= get_ticket_policy(rparams
,&i
,argv
,argc
)) !=0) {
478 printf(gettext("'%s' is an invalid option\n"), argv
[i
]);
483 /* If the default enctype/salttype is not provided, use the
484 * default values and also add to the list of supported
488 rblock
.max_life
= global_params
.max_life
;
489 rblock
.max_rlife
= global_params
.max_rlife
;
490 rblock
.expiration
= global_params
.expiration
;
491 rblock
.flags
= global_params
.flags
;
492 rblock
.nkslist
= global_params
.num_keysalts
;
493 rblock
.kslist
= global_params
.keysalts
;
495 krb5_princ_set_realm_data(util_context
, &db_create_princ
, global_params
.realm
);
496 krb5_princ_set_realm_length(util_context
, &db_create_princ
, strlen(global_params
.realm
));
498 printf(gettext("Initializing database for realm '%s'\n"), global_params
.realm
);
500 if (!mkey_password
) {
501 unsigned int pw_size
;
502 printf(gettext("You will be prompted for the database Master Password.\n"));
503 printf(gettext("It is important that you NOT FORGET this password.\n"));
506 pw_size
= sizeof (pw_str
);
507 memset(pw_str
, 0, pw_size
);
509 retval
= krb5_read_password(util_context
, KRB5_KDC_MKEY_1
, KRB5_KDC_MKEY_2
,
512 /* Solaris Kerberos */
513 com_err(progname
, retval
, gettext("while reading master key from keyboard"));
516 mkey_password
= pw_str
;
519 rparams
->mkey
.enctype
= global_params
.enctype
;
520 /* We are sure that 'mkey_password' is a regular string ... */
521 rparams
->mkey
.length
= strlen(mkey_password
) + 1;
522 rparams
->mkey
.contents
= (krb5_octet
*)strdup(mkey_password
);
523 if (rparams
->mkey
.contents
== NULL
) {
528 rparams
->realm_name
= strdup(global_params
.realm
);
529 if (rparams
->realm_name
== NULL
) {
531 /* Solaris Kerberos */
532 com_err(progname
, ENOMEM
, gettext("while creating realm '%s'"),
533 global_params
.realm
);
537 dal_handle
= (kdb5_dal_handle
*) util_context
->db_context
;
538 ldap_context
= (krb5_ldap_context
*) dal_handle
->db_context
;
544 /* read the kerberos container */
545 if ((retval
=krb5_ldap_read_krbcontainer_params (util_context
,
546 &(ldap_context
->krbcontainer
))) == KRB5_KDB_NOENTRY
) {
547 /* Prompt the user for entering the DN of Kerberos container */
548 char krb_location
[MAX_KRB_CONTAINER_LEN
];
549 krb5_ldap_krbcontainer_params kparams
;
550 int krb_location_len
= 0;
551 memset(&kparams
, 0, sizeof(kparams
));
553 /* Read the kerberos container location from configuration file */
554 if (ldap_context
->conf_section
) {
555 if ((retval
=profile_get_string(util_context
->profile
,
556 KDB_MODULE_SECTION
, ldap_context
->conf_section
,
557 "ldap_kerberos_container_dn", NULL
,
558 &kparams
.DN
)) != 0) {
562 if (kparams
.DN
== NULL
) {
563 if ((retval
=profile_get_string(util_context
->profile
,
564 KDB_MODULE_DEF_SECTION
,
565 "ldap_kerberos_container_dn", NULL
,
566 NULL
, &kparams
.DN
)) != 0) {
571 printf(gettext("\nKerberos container is missing. Creating now...\n"));
572 if (kparams
.DN
== NULL
) {
573 #ifdef HAVE_EDIRECTORY
574 printf(gettext("Enter DN of Kerberos container [cn=Kerberos,cn=Security]: "));
576 printf(gettext("Enter DN of Kerberos container: "));
578 if (fgets(krb_location
, MAX_KRB_CONTAINER_LEN
, stdin
) != NULL
) {
579 /* Remove the newline character at the end */
580 krb_location_len
= strlen(krb_location
);
581 if ((krb_location
[krb_location_len
- 1] == '\n') ||
582 (krb_location
[krb_location_len
- 1] == '\r')) {
583 krb_location
[krb_location_len
- 1] = '\0';
586 /* If the user has not given any input, take the default location */
587 else if (krb_location
[0] == '\0')
590 kparams
.DN
= krb_location
;
595 /* create the kerberos container */
596 retval
= krb5_ldap_create_krbcontainer(util_context
,
597 ((kparams
.DN
!= NULL
) ? &kparams
: NULL
));
601 retval
= krb5_ldap_read_krbcontainer_params(util_context
,
602 &(ldap_context
->krbcontainer
));
604 /* Solaris Kerberos */
605 com_err(progname
, retval
, gettext("while reading kerberos container information"));
609 /* Solaris Kerberos */
610 com_err(progname
, retval
, gettext("while reading kerberos container information"));
614 if ((retval
= krb5_ldap_create_realm(util_context
,
615 /* global_params.realm, */ rparams
, mask
))) {
619 /* We just created the Realm container. Here starts our transaction tracking */
620 realm_obj_created
= TRUE
;
622 if ((retval
= krb5_ldap_read_realm_params(util_context
,
624 &(ldap_context
->lrparams
),
626 /* Solaris Kerberos */
627 com_err(progname
, retval
, gettext("while reading information of realm '%s'"),
628 global_params
.realm
);
631 ldap_context
->lrparams
->realm_name
= strdup(global_params
.realm
);
632 if (ldap_context
->lrparams
->realm_name
== NULL
) {
637 /* assemble & parse the master key name */
638 if ((retval
= krb5_db_setup_mkey_name(util_context
,
639 global_params
.mkey_name
,
641 0, &master_princ
))) {
642 /* Solaris Kerberos */
643 com_err(progname
, retval
, gettext("while setting up master key name"));
647 /* Obtain master key from master password */
649 krb5_data master_salt
, pwd
;
651 pwd
.data
= mkey_password
;
652 pwd
.length
= strlen(mkey_password
);
653 retval
= krb5_principal2salt(util_context
, master_princ
, &master_salt
);
655 /* Solaris Kerberos */
656 com_err(progname
, retval
, gettext("while calculating master key salt"));
660 retval
= krb5_c_string_to_key(util_context
, rparams
->mkey
.enctype
,
661 &pwd
, &master_salt
, &master_keyblock
);
663 free(master_salt
.data
);
666 /* Solaris Kerberos */
667 com_err(progname
, retval
, gettext("while transforming master key from password"));
673 rblock
.key
= &master_keyblock
;
674 ldap_context
->lrparams
->mkey
= master_keyblock
;
675 ldap_context
->lrparams
->mkey
.contents
= (krb5_octet
*) malloc
676 (master_keyblock
.length
);
677 if (ldap_context
->lrparams
->mkey
.contents
== NULL
) {
681 memcpy (ldap_context
->lrparams
->mkey
.contents
, master_keyblock
.contents
,
682 master_keyblock
.length
);
684 /* Create special principals inside the realm subtree */
686 char princ_name
[MAX_PRINC_SIZE
];
687 krb5_principal_data tgt_princ
= {
688 0, /* magic number */
689 {0, 0, 0}, /* krb5_data realm */
690 tgt_princ_entries
, /* krb5_data *data */
692 KRB5_NT_SRV_INST
/* int type */
694 krb5_principal p
, temp_p
=NULL
;
696 krb5_princ_set_realm_data(util_context
, &tgt_princ
, global_params
.realm
);
697 krb5_princ_set_realm_length(util_context
, &tgt_princ
, strlen(global_params
.realm
));
698 krb5_princ_component(util_context
, &tgt_princ
,1)->data
= global_params
.realm
;
699 krb5_princ_component(util_context
, &tgt_princ
,1)->length
= strlen(global_params
.realm
);
700 /* The container reference value is set to NULL, to avoid service principals
701 * getting created within the container reference at realm creation */
702 if (ldap_context
->lrparams
->containerref
!= NULL
) {
703 oldcontainerref
= ldap_context
->lrparams
->containerref
;
704 ldap_context
->lrparams
->containerref
= NULL
;
707 /* Create 'K/M' ... */
708 rblock
.flags
|= KRB5_KDB_DISALLOW_ALL_TIX
;
709 if ((retval
= kdb_ldap_create_principal(util_context
, master_princ
, MASTER_KEY
, &rblock
))) {
710 /* Solaris Kerberos */
711 com_err(progname
, retval
, gettext("while adding entries to the database"));
715 /* Create 'krbtgt' ... */
716 rblock
.flags
= 0; /* reset the flags */
717 if ((retval
= kdb_ldap_create_principal(util_context
, &tgt_princ
, TGT_KEY
, &rblock
))) {
718 /* Solaris Kerberos */
719 com_err(progname
, retval
, gettext("while adding entries to the database"));
724 * The kadmin/admin principal is unused on Solaris. This principal is used
725 * in AUTH_GSSAPI but Solaris doesn't support AUTH_GSSAPI. RPCSEC_GSS can only
726 * be used with host-based principals.
729 #if 0 /* ************ Begin IFDEF'ed OUT ***************************** */
730 /* Create 'kadmin/admin' ... */
731 snprintf(princ_name
, sizeof(princ_name
), "%s@%s", KADM5_ADMIN_SERVICE
, global_params
.realm
);
732 if ((retval
= krb5_parse_name(util_context
, princ_name
, &p
))) {
733 /* Solaris Kerberos */
734 com_err(progname
, retval
, gettext("while adding entries to the database"));
737 rblock
.max_life
= ADMIN_LIFETIME
;
738 rblock
.flags
= KRB5_KDB_DISALLOW_TGT_BASED
;
739 if ((retval
= kdb_ldap_create_principal(util_context
, p
, TGT_KEY
, &rblock
))) {
740 krb5_free_principal(util_context
, p
);
741 /* Solaris Kerberos */
742 com_err(progname
, retval
, gettext("while adding entries to the database"));
745 krb5_free_principal(util_context
, p
);
746 #endif /* ************** END IFDEF'ed OUT ***************************** */
748 /* Create 'kadmin/changepw' ... */
749 snprintf(princ_name
, sizeof(princ_name
), "%s@%s", KADM5_CHANGEPW_SERVICE
, global_params
.realm
);
750 if ((retval
= krb5_parse_name(util_context
, princ_name
, &p
))) {
751 /* Solaris Kerberos */
752 com_err(progname
, retval
, gettext("while adding entries to the database"));
755 rblock
.max_life
= CHANGEPW_LIFETIME
;
756 rblock
.flags
= KRB5_KDB_DISALLOW_TGT_BASED
| KRB5_KDB_PWCHANGE_SERVICE
;
757 if ((retval
= kdb_ldap_create_principal(util_context
, p
, TGT_KEY
, &rblock
))) {
758 krb5_free_principal(util_context
, p
);
759 /* Solaris Kerberos */
760 com_err(progname
, retval
, gettext("while adding entries to the database"));
763 krb5_free_principal(util_context
, p
);
765 /* Create 'kadmin/history' ... */
766 snprintf(princ_name
, sizeof(princ_name
), "%s@%s", KADM5_HIST_PRINCIPAL
, global_params
.realm
);
767 if ((retval
= krb5_parse_name(util_context
, princ_name
, &p
))) {
768 /* Solaris Kerberos */
769 com_err(progname
, retval
, gettext("while adding entries to the database"));
772 rblock
.max_life
= global_params
.max_life
;
774 if ((retval
= kdb_ldap_create_principal(util_context
, p
, TGT_KEY
, &rblock
))) {
775 krb5_free_principal(util_context
, p
);
776 /* Solaris Kerberos */
777 com_err(progname
, retval
, gettext("while adding entries to the database"));
780 krb5_free_principal(util_context
, p
);
782 /* Create 'kadmin/<hostname>' ... */
783 if ((retval
=krb5_sname_to_principal(util_context
, NULL
, KADM5_ADMIN_HOST_SERVICE
, KRB5_NT_SRV_HST
, &p
))) {
784 /* Solaris Kerberos */
785 com_err(progname
, retval
, gettext("krb5_sname_to_principal, while adding entries to the database"));
789 if ((retval
=krb5_copy_principal(util_context
, p
, &temp_p
))) {
790 /* Solaris Kerberos */
791 com_err(progname
, retval
, gettext("krb5_copy_principal, while adding entries to the database"));
795 /* change the realm portion to the default realm */
796 free(temp_p
->realm
.data
);
797 temp_p
->realm
.length
= strlen(util_context
->default_realm
);
798 temp_p
->realm
.data
= strdup(util_context
->default_realm
);
799 if (temp_p
->realm
.data
== NULL
) {
800 /* Solaris Kerberos */
801 com_err(progname
, ENOMEM
, gettext("while adding entries to the database"));
805 rblock
.max_life
= ADMIN_LIFETIME
;
806 rblock
.flags
= KRB5_KDB_DISALLOW_TGT_BASED
;
807 if ((retval
= kdb_ldap_create_principal(util_context
, temp_p
, TGT_KEY
, &rblock
))) {
808 krb5_free_principal(util_context
, p
);
809 /* Solaris Kerberos */
810 com_err(progname
, retval
, gettext("while adding entries to the database"));
813 krb5_free_principal(util_context
, temp_p
);
814 krb5_free_principal(util_context
, p
);
816 /* Solaris Kerberos: Create 'changepw/<hostname>' ... */
817 if ((retval
=krb5_sname_to_principal(util_context
, NULL
, KADM5_CHANGEPW_HOST_SERVICE
, KRB5_NT_SRV_HST
, &p
))) {
818 /* Solaris Kerberos */
819 com_err(progname
, retval
, gettext("krb5_sname_to_principal, while adding entries to the database"));
823 if ((retval
=krb5_copy_principal(util_context
, p
, &temp_p
))) {
824 /* Solaris Kerberos */
825 com_err(progname
, retval
, gettext("krb5_copy_principal, while adding entries to the database"));
829 /* change the realm portion to the default realm */
830 free(temp_p
->realm
.data
);
831 temp_p
->realm
.length
= strlen(util_context
->default_realm
);
832 temp_p
->realm
.data
= strdup(util_context
->default_realm
);
833 if (temp_p
->realm
.data
== NULL
) {
834 /* Solaris Kerberos */
835 com_err(progname
, ENOMEM
, gettext("while adding entries to the database"));
839 rblock
.max_life
= ADMIN_LIFETIME
;
840 rblock
.flags
= KRB5_KDB_DISALLOW_TGT_BASED
| KRB5_KDB_PWCHANGE_SERVICE
;
841 if ((retval
= kdb_ldap_create_principal(util_context
, temp_p
, TGT_KEY
, &rblock
))) {
842 krb5_free_principal(util_context
, p
);
843 /* Solaris Kerberos */
844 com_err(progname
, retval
, gettext("while adding entries to the database"));
847 krb5_free_principal(util_context
, temp_p
);
848 krb5_free_principal(util_context
, p
);
850 if (oldcontainerref
!= NULL
) {
851 ldap_context
->lrparams
->containerref
= oldcontainerref
;
852 oldcontainerref
=NULL
;
856 #ifdef HAVE_EDIRECTORY
857 if ((mask
& LDAP_REALM_KDCSERVERS
) || (mask
& LDAP_REALM_ADMINSERVERS
) ||
858 (mask
& LDAP_REALM_PASSWDSERVERS
)) {
860 printf(gettext("Changing rights for the service object. Please wait ... "));
864 rightsmask
|= LDAP_REALM_RIGHTS
;
865 rightsmask
|= LDAP_SUBTREE_RIGHTS
;
866 if ((rparams
!= NULL
) && (rparams
->kdcservers
!= NULL
)) {
867 for (i
=0; (rparams
->kdcservers
[i
] != NULL
); i
++) {
868 if ((retval
=krb5_ldap_add_service_rights(util_context
,
869 LDAP_KDC_SERVICE
, rparams
->kdcservers
[i
],
870 rparams
->realm_name
, rparams
->subtree
, rightsmask
)) != 0) {
871 printf(gettext("failed\n"));
872 /* Solaris Kerberos */
873 com_err(progname
, retval
, gettext("while assigning rights to '%s'"),
874 rparams
->realm_name
);
881 rightsmask
|= LDAP_REALM_RIGHTS
;
882 rightsmask
|= LDAP_SUBTREE_RIGHTS
;
883 if ((rparams
!= NULL
) && (rparams
->adminservers
!= NULL
)) {
884 for (i
=0; (rparams
->adminservers
[i
] != NULL
); i
++) {
885 if ((retval
=krb5_ldap_add_service_rights(util_context
,
886 LDAP_ADMIN_SERVICE
, rparams
->adminservers
[i
],
887 rparams
->realm_name
, rparams
->subtree
, rightsmask
)) != 0) {
888 printf(gettext("failed\n"));
889 /* Solaris Kerberos */
890 com_err(progname
, retval
, gettext("while assigning rights to '%s'"),
891 rparams
->realm_name
);
898 rightsmask
|= LDAP_REALM_RIGHTS
;
899 rightsmask
|= LDAP_SUBTREE_RIGHTS
;
900 if ((rparams
!= NULL
) && (rparams
->passwdservers
!= NULL
)) {
901 for (i
=0; (rparams
->passwdservers
[i
] != NULL
); i
++) {
902 if ((retval
=krb5_ldap_add_service_rights(util_context
,
903 LDAP_PASSWD_SERVICE
, rparams
->passwdservers
[i
],
904 rparams
->realm_name
, rparams
->subtree
, rightsmask
)) != 0) {
905 printf(gettext("failed\n"));
906 /* Solaris Kerberos */
907 com_err(progname
, retval
, gettext("while assigning rights to '%s'"),
908 rparams
->realm_name
);
914 printf(gettext("done\n"));
917 /* The Realm creation is completed. Here is the end of transaction */
918 create_complete
= TRUE
;
920 /* Stash the master key only if '-s' option is specified */
921 if (do_stash
|| global_params
.mask
& KADM5_CONFIG_STASH_FILE
) {
922 retval
= krb5_def_store_mkey(util_context
,
923 global_params
.stash_file
,
925 &master_keyblock
, NULL
);
927 /* Solaris Kerberos */
928 com_err(progname
, errno
, gettext("while storing key"));
929 printf(gettext("Warning: couldn't stash master key.\n"));
943 /* If the Realm creation is not complete, do the roll-back here */
944 if ((realm_obj_created
) && (!create_complete
))
945 krb5_ldap_delete_realm(util_context
, global_params
.realm
);
948 krb5_ldap_free_realm_params(rparams
);
950 memset (pw_str
, 0, sizeof (pw_str
));
953 db_usage(CREATE_REALM
);
957 /* Solaris Kerberos */
958 com_err(progname
, retval
, gettext("while creating realm '%s'"),
959 global_params
.realm
);
969 * This function will modify the attributes of a given realm object
971 void kdb5_ldap_modify(argc
, argv
)
975 krb5_error_code retval
= 0;
976 krb5_ldap_realm_params
*rparams
= NULL
;
977 krb5_boolean print_usage
= FALSE
;
978 krb5_boolean no_msg
= FALSE
;
979 kdb5_dal_handle
*dal_handle
= NULL
;
980 krb5_ldap_context
*ldap_context
=NULL
;
982 int mask
= 0, rmask
= 0, ret_mask
= 0;
983 char **slist
= {NULL
};
984 #ifdef HAVE_EDIRECTORY
986 char *list
[MAX_LIST_ENTRIES
];
987 int existing_entries
= 0, list_entries
= 0;
988 int newkdcdn
= 0, newadmindn
= 0, newpwddn
= 0;
989 char **tempstr
= NULL
;
990 char **oldkdcdns
= NULL
;
991 char **oldadmindns
= NULL
;
992 char **oldpwddns
= NULL
;
993 char **newkdcdns
= NULL
;
994 char **newsubtrees
= NULL
;
995 char **newadmindns
= NULL
;
996 char **newpwddns
= NULL
;
997 char **oldsubtrees
= {NULL
};
999 int subtree_changed
= 0;
1002 dal_handle
= (kdb5_dal_handle
*) util_context
->db_context
;
1003 ldap_context
= (krb5_ldap_context
*) dal_handle
->db_context
;
1004 if (!(ldap_context
)) {
1009 if ((retval
= krb5_ldap_read_krbcontainer_params(util_context
,
1010 &(ldap_context
->krbcontainer
)))) {
1011 /* Solaris Kerberos */
1012 com_err(progname
, retval
, gettext("while reading Kerberos container information"));
1016 retval
= krb5_ldap_read_realm_params(util_context
,
1017 global_params
.realm
, &rparams
, &rmask
);
1020 /* Parse the arguments */
1021 for (i
= 1; i
< argc
; i
++) {
1023 if (!strcmp(argv
[i
], "-subtrees")) {
1027 if (rmask
& LDAP_REALM_SUBTREE
) {
1028 if (rparams
->subtree
) {
1029 #ifdef HAVE_EDIRECTORY
1030 oldsubtrees
= (char **) calloc(rparams
->subtreecount
+1, sizeof(char *));
1031 if (oldsubtrees
== NULL
) {
1035 for(k
=0; rparams
->subtree
[k
]!=NULL
&& rparams
->subtreecount
; k
++) {
1036 oldsubtrees
[k
] = strdup(rparams
->subtree
[k
]);
1037 if( oldsubtrees
[k
] == NULL
) {
1043 for(k
=0; k
<rparams
->subtreecount
&& rparams
->subtree
[k
]; k
++)
1044 free(rparams
->subtree
[k
]);
1045 rparams
->subtreecount
=0;
1048 if (strncmp(argv
[i
] ,"", strlen(argv
[i
]))!=0) {
1049 slist
= (char **) calloc(MAX_LIST_ENTRIES
, sizeof(char *));
1050 if (slist
== NULL
) {
1054 if (( retval
= krb5_parse_list(argv
[i
], LIST_DELIMITER
, slist
))) {
1060 rparams
->subtreecount
=0;
1061 while(slist
[rparams
->subtreecount
]!=NULL
)
1062 (rparams
->subtreecount
)++;
1063 rparams
->subtree
= slist
;
1064 } else if(strncmp(argv
[i
], "", strlen(argv
[i
]))==0) {
1065 /* dont allow subtree value to be set at the root(NULL, "") of the tree */
1066 /* Solaris Kerberos */
1067 com_err(progname
, EINVAL
,
1068 gettext("for subtree while modifying realm '%s'"),
1069 global_params
.realm
);
1072 rparams
->subtree
[rparams
->subtreecount
] = NULL
;
1073 mask
|= LDAP_REALM_SUBTREE
;
1074 } else if (!strncmp(argv
[i
], "-containerref", strlen(argv
[i
]))) {
1077 if(strncmp(argv
[i
], "", strlen(argv
[i
]))==0) {
1078 /* dont allow containerref value to be set at the root(NULL, "") of the tree */
1079 /* Solaris Kerberos */
1080 com_err(progname
, EINVAL
,
1081 gettext("for container reference while modifying realm '%s'"),
1082 global_params
.realm
);
1085 rparams
->containerref
= strdup(argv
[i
]);
1086 if (rparams
->containerref
== NULL
) {
1090 mask
|= LDAP_REALM_CONTREF
;
1091 } else if (!strcmp(argv
[i
], "-sscope")) {
1094 /* Possible values for search scope are
1095 * one (or 1) and sub (or 2)
1097 if (strcasecmp(argv
[i
], "one") == 0) {
1098 rparams
->search_scope
= 1;
1099 } else if (strcasecmp(argv
[i
], "sub") == 0) {
1100 rparams
->search_scope
= 2;
1102 rparams
->search_scope
= atoi(argv
[i
]);
1103 if ((rparams
->search_scope
!= 1) &&
1104 (rparams
->search_scope
!= 2)) {
1106 /* Solaris Kerberos */
1107 com_err(progname
, retval
,
1108 gettext("specified for search scope while modifying information of realm '%s'"),
1109 global_params
.realm
);
1113 mask
|= LDAP_REALM_SEARCHSCOPE
;
1115 #ifdef HAVE_EDIRECTORY
1116 else if (!strcmp(argv
[i
], "-kdcdn")) {
1120 if ((rmask
& LDAP_REALM_KDCSERVERS
) && (rparams
->kdcservers
)) {
1122 /* Store the old kdc dns list for removing rights */
1123 oldkdcdns
= (char**) calloc(MAX_LIST_ENTRIES
, sizeof(char*));
1124 if (oldkdcdns
== NULL
) {
1129 for (j
=0; rparams
->kdcservers
[j
] != NULL
; j
++) {
1130 oldkdcdns
[j
] = strdup(rparams
->kdcservers
[j
]);
1131 if (oldkdcdns
[j
] == NULL
) {
1136 oldkdcdns
[j
] = NULL
;
1139 krb5_free_list_entries(rparams
->kdcservers
);
1140 free(rparams
->kdcservers
);
1143 rparams
->kdcservers
= (char **)malloc(
1144 sizeof(char *) * MAX_LIST_ENTRIES
);
1145 if (rparams
->kdcservers
== NULL
) {
1149 memset(rparams
->kdcservers
, 0, sizeof(char *)*MAX_LIST_ENTRIES
);
1150 if ((retval
= krb5_parse_list(argv
[i
], LIST_DELIMITER
,
1151 rparams
->kdcservers
))) {
1154 mask
|= LDAP_REALM_KDCSERVERS
;
1155 /* Going to replace the existing value by this new value. Hence
1156 * setting flag indicating that add or clear options will be ignored
1159 } else if (!strcmp(argv
[i
], "-clearkdcdn")) {
1162 if ((!newkdcdn
) && (rmask
& LDAP_REALM_KDCSERVERS
) && (rparams
->kdcservers
)) {
1164 /* Store the old kdc dns list for removing rights */
1165 oldkdcdns
= (char**) calloc(MAX_LIST_ENTRIES
, sizeof(char*));
1166 if (oldkdcdns
== NULL
) {
1171 for (j
=0; rparams
->kdcservers
[j
] != NULL
; j
++) {
1172 oldkdcdns
[j
] = strdup(rparams
->kdcservers
[j
]);
1173 if (oldkdcdns
[j
] == NULL
) {
1178 oldkdcdns
[j
] = NULL
;
1181 memset(list
, 0, sizeof(char *) * MAX_LIST_ENTRIES
);
1182 if ((retval
= krb5_parse_list(argv
[i
], LIST_DELIMITER
, list
))) {
1185 list_modify_str_array(&rparams
->kdcservers
, (const char **)list
,
1187 mask
|= LDAP_REALM_KDCSERVERS
;
1188 krb5_free_list_entries(list
);
1190 } else if (!strcmp(argv
[i
], "-addkdcdn")) {
1194 if ((rmask
& LDAP_REALM_KDCSERVERS
) && (rparams
->kdcservers
) && (!oldkdcdns
)) {
1195 /* Store the old kdc dns list for removing rights */
1196 oldkdcdns
= (char**) calloc(MAX_LIST_ENTRIES
, sizeof(char*));
1197 if (oldkdcdns
== NULL
) {
1202 for (j
= 0; rparams
->kdcservers
[j
] != NULL
; j
++) {
1203 oldkdcdns
[j
] = strdup(rparams
->kdcservers
[j
]);
1204 if (oldkdcdns
[j
] == NULL
) {
1209 oldkdcdns
[j
] = NULL
;
1212 memset(list
, 0, sizeof(char *) * MAX_LIST_ENTRIES
);
1213 if ((retval
= krb5_parse_list(argv
[i
], LIST_DELIMITER
, list
))) {
1216 existing_entries
= list_count_str_array(rparams
->kdcservers
);
1217 list_entries
= list_count_str_array(list
);
1218 if (rmask
& LDAP_REALM_KDCSERVERS
) {
1219 tempstr
= reallocarray(rparams
->kdcservers
,
1220 existing_entries
+ list_entries
+ 1, sizeof (char *));
1221 if (tempstr
== NULL
) {
1225 rparams
->kdcservers
= tempstr
;
1227 rparams
->kdcservers
= (char **)malloc(sizeof(char *) * (list_entries
+1));
1228 if (rparams
->kdcservers
== NULL
) {
1232 memset(rparams
->kdcservers
, 0, sizeof(char *) * (list_entries
+1));
1234 list_modify_str_array(&rparams
->kdcservers
, (const char **)list
,
1236 mask
|= LDAP_REALM_KDCSERVERS
;
1238 } else if (!strcmp(argv
[i
], "-admindn")) {
1242 if ((rmask
& LDAP_REALM_ADMINSERVERS
) && (rparams
->adminservers
)) {
1244 /* Store the old admin dns list for removing rights */
1245 oldadmindns
= (char**) calloc(MAX_LIST_ENTRIES
, sizeof(char*));
1246 if (oldadmindns
== NULL
) {
1251 for (j
=0; rparams
->adminservers
[j
] != NULL
; j
++) {
1252 oldadmindns
[j
] = strdup(rparams
->adminservers
[j
]);
1253 if (oldadmindns
[j
] == NULL
) {
1258 oldadmindns
[j
] = NULL
;
1261 krb5_free_list_entries(rparams
->adminservers
);
1262 free(rparams
->adminservers
);
1265 rparams
->adminservers
= (char **)malloc(
1266 sizeof(char *) * MAX_LIST_ENTRIES
);
1267 if (rparams
->adminservers
== NULL
) {
1271 memset(rparams
->adminservers
, 0, sizeof(char *)*MAX_LIST_ENTRIES
);
1272 if ((retval
= krb5_parse_list(argv
[i
], LIST_DELIMITER
,
1273 rparams
->adminservers
))) {
1276 mask
|= LDAP_REALM_ADMINSERVERS
;
1277 /* Going to replace the existing value by this new value. Hence
1278 * setting flag indicating that add or clear options will be ignored
1281 } else if (!strcmp(argv
[i
], "-clearadmindn")) {
1285 if ((!newadmindn
) && (rmask
& LDAP_REALM_ADMINSERVERS
) && (rparams
->adminservers
)) {
1287 /* Store the old admin dns list for removing rights */
1288 oldadmindns
= (char**) calloc(MAX_LIST_ENTRIES
, sizeof(char*));
1289 if (oldadmindns
== NULL
) {
1294 for (j
=0; rparams
->adminservers
[j
] != NULL
; j
++) {
1295 oldadmindns
[j
] = strdup(rparams
->adminservers
[j
]);
1296 if (oldadmindns
[j
] == NULL
) {
1301 oldadmindns
[j
] = NULL
;
1304 memset(list
, 0, sizeof(char *) * MAX_LIST_ENTRIES
);
1305 if ((retval
= krb5_parse_list(argv
[i
], LIST_DELIMITER
, list
))) {
1308 list_modify_str_array(&rparams
->adminservers
, (const char **)list
,
1310 mask
|= LDAP_REALM_ADMINSERVERS
;
1311 krb5_free_list_entries(list
);
1313 } else if (!strcmp(argv
[i
], "-addadmindn")) {
1317 if ((rmask
& LDAP_REALM_ADMINSERVERS
) && (rparams
->adminservers
) && (!oldadmindns
)) {
1318 /* Store the old admin dns list for removing rights */
1319 oldadmindns
= (char**) calloc(MAX_LIST_ENTRIES
, sizeof(char*));
1320 if (oldadmindns
== NULL
) {
1325 for (j
=0; rparams
->adminservers
[j
] != NULL
; j
++) {
1326 oldadmindns
[j
] = strdup(rparams
->adminservers
[j
]);
1327 if (oldadmindns
[j
] == NULL
) {
1332 oldadmindns
[j
] = NULL
;
1335 memset(list
, 0, sizeof(char *) * MAX_LIST_ENTRIES
);
1336 if ((retval
= krb5_parse_list(argv
[i
], LIST_DELIMITER
, list
))) {
1339 existing_entries
= list_count_str_array(rparams
->adminservers
);
1340 list_entries
= list_count_str_array(list
);
1341 if (rmask
& LDAP_REALM_ADMINSERVERS
) {
1342 tempstr
= (char **)reallocarray(rparams
->adminservers
,
1343 (existing_entries
+ list_entries
+ 1),
1345 if (tempstr
== NULL
) {
1349 rparams
->adminservers
= tempstr
;
1351 rparams
->adminservers
= (char **)malloc(sizeof(char *) * (list_entries
+1));
1352 if (rparams
->adminservers
== NULL
) {
1356 memset(rparams
->adminservers
, 0, sizeof(char *) * (list_entries
+1));
1358 list_modify_str_array(&rparams
->adminservers
, (const char **)list
,
1360 mask
|= LDAP_REALM_ADMINSERVERS
;
1362 } else if (!strcmp(argv
[i
], "-pwddn")) {
1366 if ((rmask
& LDAP_REALM_PASSWDSERVERS
) && (rparams
->passwdservers
)) {
1368 /* Store the old pwd dns list for removing rights */
1369 oldpwddns
= (char**) calloc(MAX_LIST_ENTRIES
, sizeof(char*));
1370 if (oldpwddns
== NULL
) {
1375 for (j
=0; rparams
->passwdservers
[j
] != NULL
; j
++) {
1376 oldpwddns
[j
] = strdup(rparams
->passwdservers
[j
]);
1377 if (oldpwddns
[j
] == NULL
) {
1382 oldpwddns
[j
] = NULL
;
1385 krb5_free_list_entries(rparams
->passwdservers
);
1386 free(rparams
->passwdservers
);
1389 rparams
->passwdservers
= (char **)malloc(
1390 sizeof(char *) * MAX_LIST_ENTRIES
);
1391 if (rparams
->passwdservers
== NULL
) {
1395 memset(rparams
->passwdservers
, 0, sizeof(char *)*MAX_LIST_ENTRIES
);
1396 if ((retval
= krb5_parse_list(argv
[i
], LIST_DELIMITER
,
1397 rparams
->passwdservers
))) {
1400 mask
|= LDAP_REALM_PASSWDSERVERS
;
1401 /* Going to replace the existing value by this new value. Hence
1402 * setting flag indicating that add or clear options will be ignored
1405 } else if (!strcmp(argv
[i
], "-clearpwddn")) {
1409 if ((!newpwddn
) && (rmask
& LDAP_REALM_PASSWDSERVERS
) && (rparams
->passwdservers
)) {
1411 /* Store the old pwd dns list for removing rights */
1412 oldpwddns
= (char**) calloc(MAX_LIST_ENTRIES
, sizeof(char*));
1413 if (oldpwddns
== NULL
) {
1418 for (j
=0; rparams
->passwdservers
[j
] != NULL
; j
++) {
1419 oldpwddns
[j
] = strdup(rparams
->passwdservers
[j
]);
1420 if (oldpwddns
[j
] == NULL
) {
1425 oldpwddns
[j
] = NULL
;
1428 memset(list
, 0, sizeof(char *) * MAX_LIST_ENTRIES
);
1429 if ((retval
= krb5_parse_list(argv
[i
], LIST_DELIMITER
, list
))) {
1432 list_modify_str_array(&rparams
->passwdservers
, (const char**)list
,
1434 mask
|= LDAP_REALM_PASSWDSERVERS
;
1435 krb5_free_list_entries(list
);
1437 } else if (!strcmp(argv
[i
], "-addpwddn")) {
1441 if ((rmask
& LDAP_REALM_PASSWDSERVERS
) && (rparams
->passwdservers
) && (!oldpwddns
)) {
1442 /* Store the old pwd dns list for removing rights */
1443 oldpwddns
= (char**) calloc(MAX_LIST_ENTRIES
, sizeof(char*));
1444 if (oldpwddns
== NULL
) {
1449 for (j
=0; rparams
->passwdservers
[j
] != NULL
; j
++) {
1450 oldpwddns
[j
] = strdup(rparams
->passwdservers
[j
]);
1451 if (oldpwddns
[j
] == NULL
) {
1456 oldpwddns
[j
] = NULL
;
1459 memset(list
, 0, sizeof(char *) * MAX_LIST_ENTRIES
);
1460 if ((retval
= krb5_parse_list(argv
[i
], LIST_DELIMITER
, list
))) {
1463 existing_entries
= list_count_str_array(rparams
->passwdservers
);
1464 list_entries
= list_count_str_array(list
);
1465 if (rmask
& LDAP_REALM_PASSWDSERVERS
) {
1466 tempstr
= (char **)reallocarray(rparams
->passwdservers
,
1467 (existing_entries
+ list_entries
+ 1),
1469 if (tempstr
== NULL
) {
1473 rparams
->passwdservers
= tempstr
;
1475 rparams
->passwdservers
= (char **)malloc(sizeof(char *) * (list_entries
+1));
1476 if (rparams
->passwdservers
== NULL
) {
1480 memset(rparams
->passwdservers
, 0, sizeof(char *) * (list_entries
+1));
1482 list_modify_str_array(&rparams
->passwdservers
, (const char**)list
,
1484 mask
|= LDAP_REALM_PASSWDSERVERS
;
1488 else if ((ret_mask
= get_ticket_policy(rparams
,&i
,argv
,argc
)) !=0) {
1491 printf(gettext("'%s' is an invalid option\n"), argv
[i
]);
1496 if ((retval
= krb5_ldap_modify_realm(util_context
,
1497 /* global_params.realm, */ rparams
, mask
))) {
1501 #ifdef HAVE_EDIRECTORY
1502 if ((mask
& LDAP_REALM_SUBTREE
) || (mask
& LDAP_REALM_KDCSERVERS
) ||
1503 (mask
& LDAP_REALM_ADMINSERVERS
) || (mask
& LDAP_REALM_PASSWDSERVERS
)) {
1505 printf(gettext("Changing rights for the service object. Please wait ... "));
1508 if (!(mask
& LDAP_REALM_SUBTREE
)) {
1509 if (rparams
->subtree
!= NULL
) {
1510 for(i
=0; rparams
->subtree
[i
]!=NULL
;i
++) {
1511 oldsubtrees
[i
] = strdup(rparams
->subtree
[i
]);
1512 if( oldsubtrees
[i
] == NULL
) {
1520 if ((mask
& LDAP_REALM_SUBTREE
)) {
1521 int check_subtree
= 1;
1523 newsubtrees
= (char**) calloc(rparams
->subtreecount
, sizeof(char*));
1525 if (newsubtrees
== NULL
) {
1530 if ( (rparams
!= NULL
) && (rparams
->subtree
!= NULL
) ) {
1531 for (j
=0; j
<rparams
->subtreecount
&& rparams
->subtree
[j
]!= NULL
; j
++) {
1532 newsubtrees
[j
] = strdup(rparams
->subtree
[j
]);
1533 if (newsubtrees
[j
] == NULL
) {
1538 newsubtrees
[j
] = NULL
;
1540 for(j
=0;oldsubtrees
[j
]!=NULL
;j
++) {
1542 for(i
=0; ( (oldsubtrees
[j
] && !rparams
->subtree
[i
]) ||
1543 (!oldsubtrees
[j
] && rparams
->subtree
[i
])); i
++) {
1544 if(strcasecmp( oldsubtrees
[j
], rparams
->subtree
[i
]) == 0) {
1549 if (check_subtree
!= 0) {
1554 /* this will return list of the disjoint members */
1555 disjoint_members( oldsubtrees
, newsubtrees
);
1558 if ((mask
& LDAP_REALM_SUBTREE
) || (mask
& LDAP_REALM_KDCSERVERS
)) {
1560 newkdcdns
= (char**) calloc(MAX_LIST_ENTRIES
, sizeof(char*));
1561 if (newkdcdns
== NULL
) {
1566 if ((rparams
!= NULL
) && (rparams
->kdcservers
!= NULL
)) {
1567 for (j
=0; rparams
->kdcservers
[j
]!= NULL
; j
++) {
1568 newkdcdns
[j
] = strdup(rparams
->kdcservers
[j
]);
1569 if (newkdcdns
[j
] == NULL
) {
1574 newkdcdns
[j
] = NULL
;
1577 if (!subtree_changed
) {
1578 disjoint_members(oldkdcdns
, newkdcdns
);
1579 } else { /* Only the subtrees was changed. Remove the rights on the old subtrees. */
1580 if (!(mask
& LDAP_REALM_KDCSERVERS
)) {
1582 oldkdcdns
= (char**) calloc(MAX_LIST_ENTRIES
, sizeof(char*));
1583 if (oldkdcdns
== NULL
) {
1588 if ((rparams
!= NULL
) && (rparams
->kdcservers
!= NULL
)) {
1589 for (j
=0; rparams
->kdcservers
[j
]!= NULL
; j
++) {
1590 oldkdcdns
[j
] = strdup(rparams
->kdcservers
[j
]);
1591 if (oldkdcdns
[j
] == NULL
) {
1596 oldkdcdns
[j
] = NULL
;
1602 rightsmask
|= LDAP_REALM_RIGHTS
;
1603 rightsmask
|= LDAP_SUBTREE_RIGHTS
;
1604 /* Remove the rights on the old subtrees */
1606 for (i
=0; (oldkdcdns
[i
] != NULL
); i
++) {
1607 if ((retval
=krb5_ldap_delete_service_rights(util_context
,
1608 LDAP_KDC_SERVICE
, oldkdcdns
[i
],
1609 rparams
->realm_name
, oldsubtrees
, rightsmask
)) != 0) {
1610 printf(gettext("failed\n"));
1611 /* Solaris Kerberos */
1612 com_err(progname
, retval
, gettext("while assigning rights '%s'"),
1613 rparams
->realm_name
);
1620 rightsmask
|= LDAP_REALM_RIGHTS
;
1621 rightsmask
|= LDAP_SUBTREE_RIGHTS
;
1623 for (i
=0; (newkdcdns
[i
] != NULL
); i
++) {
1625 if ((retval
=krb5_ldap_add_service_rights(util_context
,
1626 LDAP_KDC_SERVICE
, newkdcdns
[i
], rparams
->realm_name
,
1627 rparams
->subtree
, rightsmask
)) != 0) {
1628 printf(gettext("failed\n"));
1629 /* Solaris Kerberos */
1630 com_err(progname
, retval
, gettext("while assigning rights to '%s'"),
1631 rparams
->realm_name
);
1638 if ((mask
& LDAP_REALM_SUBTREE
) || (mask
& LDAP_REALM_ADMINSERVERS
)) {
1640 newadmindns
= (char**) calloc(MAX_LIST_ENTRIES
, sizeof(char*));
1641 if (newadmindns
== NULL
) {
1646 if ((rparams
!= NULL
) && (rparams
->adminservers
!= NULL
)) {
1647 for (j
=0; rparams
->adminservers
[j
]!= NULL
; j
++) {
1648 newadmindns
[j
] = strdup(rparams
->adminservers
[j
]);
1649 if (newadmindns
[j
] == NULL
) {
1654 newadmindns
[j
] = NULL
;
1657 if (!subtree_changed
) {
1658 disjoint_members(oldadmindns
, newadmindns
);
1659 } else { /* Only the subtrees was changed. Remove the rights on the old subtrees. */
1660 if (!(mask
& LDAP_REALM_ADMINSERVERS
)) {
1662 oldadmindns
= (char**) calloc(MAX_LIST_ENTRIES
, sizeof(char*));
1663 if (oldadmindns
== NULL
) {
1668 if ((rparams
!= NULL
) && (rparams
->adminservers
!= NULL
)) {
1669 for (j
=0; rparams
->adminservers
[j
]!= NULL
; j
++) {
1670 oldadmindns
[j
] = strdup(rparams
->adminservers
[j
]);
1671 if (oldadmindns
[j
] == NULL
) {
1676 oldadmindns
[j
] = NULL
;
1682 rightsmask
|= LDAP_REALM_RIGHTS
;
1683 rightsmask
|= LDAP_SUBTREE_RIGHTS
;
1684 /* Remove the rights on the old subtrees */
1686 for (i
=0; (oldadmindns
[i
] != NULL
); i
++) {
1688 if ((retval
=krb5_ldap_delete_service_rights(util_context
,
1689 LDAP_ADMIN_SERVICE
, oldadmindns
[i
],
1690 rparams
->realm_name
, oldsubtrees
, rightsmask
)) != 0) {
1691 printf(gettext("failed\n"));
1692 /* Solaris Kerberos */
1693 com_err(progname
, retval
, gettext("while assigning rights '%s'"),
1694 rparams
->realm_name
);
1701 rightsmask
|= LDAP_REALM_RIGHTS
;
1702 rightsmask
|= LDAP_SUBTREE_RIGHTS
;
1703 /* Add rights on the new subtree for all the kdc dns */
1705 for (i
=0; (newadmindns
[i
] != NULL
); i
++) {
1707 if ((retval
=krb5_ldap_add_service_rights(util_context
,
1708 LDAP_ADMIN_SERVICE
, newadmindns
[i
],
1709 rparams
->realm_name
, rparams
->subtree
, rightsmask
)) != 0) {
1710 printf(gettext("failed\n"));
1711 /* Solaris Kerberos */
1712 com_err(progname
, retval
, gettext("while assigning rights to '%s'"),
1713 rparams
->realm_name
);
1721 if ((mask
& LDAP_REALM_SUBTREE
) || (mask
& LDAP_REALM_PASSWDSERVERS
)) {
1723 newpwddns
= (char**) calloc(MAX_LIST_ENTRIES
, sizeof(char*));
1724 if (newpwddns
== NULL
) {
1729 if ((rparams
!= NULL
) && (rparams
->passwdservers
!= NULL
)) {
1730 for (j
=0; rparams
->passwdservers
[j
]!= NULL
; j
++) {
1731 newpwddns
[j
] = strdup(rparams
->passwdservers
[j
]);
1732 if (newpwddns
[j
] == NULL
) {
1737 newpwddns
[j
] = NULL
;
1740 if (!subtree_changed
) {
1741 disjoint_members(oldpwddns
, newpwddns
);
1742 } else { /* Only the subtrees was changed. Remove the rights on the old subtrees. */
1743 if (!(mask
& LDAP_REALM_ADMINSERVERS
)) {
1745 oldpwddns
= (char**) calloc(MAX_LIST_ENTRIES
, sizeof(char*));
1746 if (oldpwddns
== NULL
) {
1751 if ((rparams
!= NULL
) && (rparams
->passwdservers
!= NULL
)) {
1752 for (j
=0; rparams
->passwdservers
[j
]!= NULL
; j
++) {
1753 oldpwddns
[j
] = strdup(rparams
->passwdservers
[j
]);
1754 if (oldpwddns
[j
] == NULL
) {
1759 oldpwddns
[j
] = NULL
;
1765 rightsmask
|= LDAP_REALM_RIGHTS
;
1766 rightsmask
|= LDAP_SUBTREE_RIGHTS
;
1767 /* Remove the rights on the old subtrees */
1769 for (i
=0; (oldpwddns
[i
] != NULL
); i
++) {
1770 if ((retval
= krb5_ldap_delete_service_rights(util_context
,
1771 LDAP_PASSWD_SERVICE
, oldpwddns
[i
],
1772 rparams
->realm_name
, oldsubtrees
, rightsmask
))) {
1773 printf(gettext("failed\n"));
1774 /* Solaris Kerberos */
1775 com_err(progname
, retval
, gettext("while assigning rights '%s'"),
1776 rparams
->realm_name
);
1783 rightsmask
|= LDAP_REALM_RIGHTS
;
1784 rightsmask
|= LDAP_SUBTREE_RIGHTS
;
1785 /* Add rights on the new subtree for all the kdc dns */
1787 for (i
=0; (newpwddns
[i
] != NULL
); i
++) {
1788 if ((retval
= krb5_ldap_add_service_rights(util_context
,
1789 LDAP_PASSWD_SERVICE
, newpwddns
[i
],
1790 rparams
->realm_name
, rparams
->subtree
, rightsmask
))) {
1791 printf(gettext("failed\n"));
1792 /* Solaris Kerberos */
1793 com_err(progname
, retval
, gettext("while assigning rights to '%s'"),
1794 rparams
->realm_name
);
1801 printf(gettext("done\n"));
1814 krb5_ldap_free_realm_params(rparams
);
1817 #ifdef HAVE_EDIRECTORY
1819 for (i
=0; oldkdcdns
[i
] != NULL
; i
++)
1824 for (i
=0; oldpwddns
[i
] != NULL
; i
++)
1829 for (i
=0; oldadmindns
[i
] != NULL
; i
++)
1830 free(oldadmindns
[i
]);
1834 for (i
=0; newkdcdns
[i
] != NULL
; i
++)
1839 for (i
=0; newpwddns
[i
] != NULL
; i
++)
1844 for (i
=0; newadmindns
[i
] != NULL
; i
++)
1845 free(newadmindns
[i
]);
1849 for (i
=0;oldsubtrees
[i
]!=NULL
; i
++)
1850 free(oldsubtrees
[i
]);
1854 for (i
=0;newsubtrees
[i
]!=NULL
; i
++)
1855 free(newsubtrees
[i
]);
1860 db_usage(MODIFY_REALM
);
1865 /* Solaris Kerberos */
1866 com_err(progname
, retval
, gettext("while modifying information of realm '%s'"),
1867 global_params
.realm
);
1878 * This function displays the attributes of a Realm
1880 void kdb5_ldap_view(argc
, argv
)
1884 krb5_ldap_realm_params
*rparams
= NULL
;
1885 krb5_error_code retval
= 0;
1886 kdb5_dal_handle
*dal_handle
=NULL
;
1887 krb5_ldap_context
*ldap_context
=NULL
;
1890 dal_handle
= (kdb5_dal_handle
*) util_context
->db_context
;
1891 ldap_context
= (krb5_ldap_context
*) dal_handle
->db_context
;
1892 if (!(ldap_context
)) {
1894 /* Solaris Kerberos */
1895 com_err(progname
, retval
, gettext("while initializing database"));
1900 /* Read the kerberos container information */
1901 if ((retval
= krb5_ldap_read_krbcontainer_params(util_context
,
1902 &(ldap_context
->krbcontainer
))) != 0) {
1903 /* Solaris Kerberos */
1904 com_err(progname
, retval
, gettext("while reading kerberos container information"));
1909 if ((retval
= krb5_ldap_read_realm_params(util_context
,
1910 global_params
.realm
, &rparams
, &mask
)) || (!rparams
)) {
1911 /* Solaris Kerberos */
1912 com_err(progname
, retval
, gettext("while reading information of realm '%s'"),
1913 global_params
.realm
);
1917 print_realm_params(rparams
, mask
);
1918 krb5_ldap_free_realm_params(rparams
);
1923 static char *strdur(duration
)
1926 static char out
[50];
1927 int neg
, days
, hours
, minutes
, seconds
;
1934 days
= duration
/ (24 * 3600);
1935 duration
%= 24 * 3600;
1936 hours
= duration
/ 3600;
1938 minutes
= duration
/ 60;
1941 snprintf(out
, sizeof(out
), "%s%d %s %02d:%02d:%02d", neg
? "-" : "",
1942 days
, days
== 1 ? gettext("day") : gettext("days"),
1943 hours
, minutes
, seconds
);
1948 * This function prints the attributes of a given realm to the
1951 static void print_realm_params(krb5_ldap_realm_params
*rparams
, int mask
)
1953 char **slist
= NULL
;
1954 int num_entry_printed
= 0, i
= 0;
1956 /* Print the Realm Attributes on the standard output */
1957 printf("%25s: %-50s\n", gettext("Realm Name"), global_params
.realm
);
1958 if (mask
& LDAP_REALM_SUBTREE
) {
1959 for (i
=0; rparams
->subtree
[i
]!=NULL
; i
++)
1960 printf("%25s: %-50s\n", gettext("Subtree"), rparams
->subtree
[i
]);
1962 if (mask
& LDAP_REALM_CONTREF
)
1963 printf("%25s: %-50s\n", gettext("Principal Container Reference"), rparams
->containerref
);
1964 if (mask
& LDAP_REALM_SEARCHSCOPE
) {
1965 if ((rparams
->search_scope
!= 1) &&
1966 (rparams
->search_scope
!= 2)) {
1967 printf("%25s: %-50s\n", gettext("SearchScope"), gettext("Invalid !"));
1969 printf("%25s: %-50s\n", gettext("SearchScope"),
1970 (rparams
->search_scope
== 1) ? gettext("ONE") : gettext("SUB"));
1973 if (mask
& LDAP_REALM_KDCSERVERS
) {
1974 printf("%25s:", gettext("KDC Services"));
1975 if (rparams
->kdcservers
!= NULL
) {
1976 num_entry_printed
= 0;
1977 for (slist
= rparams
->kdcservers
; *slist
!= NULL
; slist
++) {
1978 if (num_entry_printed
)
1979 printf(" %25s %-50s\n", " ", *slist
);
1981 printf(" %-50s\n", *slist
);
1982 num_entry_printed
++;
1985 if (num_entry_printed
== 0)
1988 if (mask
& LDAP_REALM_ADMINSERVERS
) {
1989 printf("%25s:", gettext("Admin Services"));
1990 if (rparams
->adminservers
!= NULL
) {
1991 num_entry_printed
= 0;
1992 for (slist
= rparams
->adminservers
; *slist
!= NULL
; slist
++) {
1993 if (num_entry_printed
)
1994 printf(" %25s %-50s\n", " ", *slist
);
1996 printf(" %-50s\n", *slist
);
1997 num_entry_printed
++;
2000 if (num_entry_printed
== 0)
2003 if (mask
& LDAP_REALM_PASSWDSERVERS
) {
2004 printf("%25s:", gettext("Passwd Services"));
2005 if (rparams
->passwdservers
!= NULL
) {
2006 num_entry_printed
= 0;
2007 for (slist
= rparams
->passwdservers
; *slist
!= NULL
; slist
++) {
2008 if (num_entry_printed
)
2009 printf(" %25s %-50s\n", " ", *slist
);
2011 printf(" %-50s\n", *slist
);
2012 num_entry_printed
++;
2015 if (num_entry_printed
== 0)
2018 if (mask
& LDAP_REALM_MAXTICKETLIFE
) {
2019 printf("%25s:", gettext("Maximum Ticket Life"));
2020 printf(" %s \n", strdur(rparams
->max_life
));
2023 if (mask
& LDAP_REALM_MAXRENEWLIFE
) {
2024 printf("%25s:", gettext("Maximum Renewable Life"));
2025 printf(" %s \n", strdur(rparams
->max_renewable_life
));
2028 if (mask
& LDAP_REALM_KRBTICKETFLAGS
) {
2029 int ticketflags
= rparams
->tktflags
;
2031 printf("%25s: ", gettext("Ticket flags"));
2032 if (ticketflags
& KRB5_KDB_DISALLOW_POSTDATED
)
2033 printf("%s ","DISALLOW_POSTDATED");
2035 if (ticketflags
& KRB5_KDB_DISALLOW_FORWARDABLE
)
2036 printf("%s ","DISALLOW_FORWARDABLE");
2038 if (ticketflags
& KRB5_KDB_DISALLOW_RENEWABLE
)
2039 printf("%s ","DISALLOW_RENEWABLE");
2041 if (ticketflags
& KRB5_KDB_DISALLOW_PROXIABLE
)
2042 printf("%s ","DISALLOW_PROXIABLE");
2044 if (ticketflags
& KRB5_KDB_DISALLOW_DUP_SKEY
)
2045 printf("%s ","DISALLOW_DUP_SKEY");
2047 if (ticketflags
& KRB5_KDB_REQUIRES_PRE_AUTH
)
2048 printf("%s ","REQUIRES_PRE_AUTH");
2050 if (ticketflags
& KRB5_KDB_REQUIRES_HW_AUTH
)
2051 printf("%s ","REQUIRES_HW_AUTH");
2053 if (ticketflags
& KRB5_KDB_DISALLOW_SVR
)
2054 printf("%s ","DISALLOW_SVR");
2056 if (ticketflags
& KRB5_KDB_DISALLOW_TGT_BASED
)
2057 printf("%s ","DISALLOW_TGT_BASED");
2059 if (ticketflags
& KRB5_KDB_DISALLOW_ALL_TIX
)
2060 printf("%s ","DISALLOW_ALL_TIX");
2062 if (ticketflags
& KRB5_KDB_REQUIRES_PWCHANGE
)
2063 printf("%s ","REQUIRES_PWCHANGE");
2065 if (ticketflags
& KRB5_KDB_PWCHANGE_SERVICE
)
2066 printf("%s ","PWCHANGE_SERVICE");
2078 * This function lists the Realm(s) present under the Kerberos container
2079 * on the LDAP Server.
2081 void kdb5_ldap_list(argc
, argv
)
2086 char **plist
= NULL
;
2087 krb5_error_code retval
= 0;
2088 kdb5_dal_handle
*dal_handle
=NULL
;
2089 krb5_ldap_context
*ldap_context
=NULL
;
2091 dal_handle
= (kdb5_dal_handle
*)util_context
->db_context
;
2092 ldap_context
= (krb5_ldap_context
*) dal_handle
->db_context
;
2093 if (!(ldap_context
)) {
2099 /* Read the kerberos container information */
2100 if ((retval
= krb5_ldap_read_krbcontainer_params(util_context
,
2101 &(ldap_context
->krbcontainer
))) != 0) {
2102 /* Solaris Kerberos */
2103 com_err(progname
, retval
, gettext("while reading kerberos container information"));
2108 retval
= krb5_ldap_list_realm(util_context
, &list
);
2110 krb5_ldap_free_krbcontainer_params(ldap_context
->krbcontainer
);
2111 ldap_context
->krbcontainer
= NULL
;
2112 /* Solaris Kerberos */
2113 com_err (progname
, retval
, gettext("while listing realms"));
2117 /* This is to handle the case of realm not present */
2119 krb5_ldap_free_krbcontainer_params(ldap_context
->krbcontainer
);
2120 ldap_context
->krbcontainer
= NULL
;
2124 for (plist
= list
; *plist
!= NULL
; plist
++) {
2125 printf("%s\n", *plist
);
2127 krb5_ldap_free_krbcontainer_params(ldap_context
->krbcontainer
);
2128 ldap_context
->krbcontainer
= NULL
;
2129 krb5_free_list_entries(list
);
2136 * Duplicating the following two functions here because
2137 * 'krb5_dbe_update_tl_data' uses backend specific memory allocation. The catch
2138 * here is that the backend is not initialized - kdb5_ldap_util doesn't go
2140 * 1. krb5_dbe_update_tl_data
2141 * 2. krb5_dbe_update_mod_princ_data
2144 /* Start duplicate code ... */
2146 static krb5_error_code
2147 krb5_dbe_update_tl_data_new(context
, entry
, new_tl_data
)
2148 krb5_context context
;
2149 krb5_db_entry
*entry
;
2150 krb5_tl_data
*new_tl_data
;
2152 krb5_tl_data
*tl_data
= NULL
;
2155 /* copy the new data first, so we can fail cleanly if malloc()
2159 (krb5_octet *) krb5_db_alloc(context, NULL,
2160 new_tl_data->tl_data_length)) == NULL)
2162 if ((tmp
= (krb5_octet
*) malloc (new_tl_data
->tl_data_length
)) == NULL
)
2165 /* Find an existing entry of the specified type and point at
2166 * it, or NULL if not found */
2168 if (new_tl_data
->tl_data_type
!= KRB5_TL_DB_ARGS
) { /* db_args can be multiple */
2169 for (tl_data
= entry
->tl_data
; tl_data
;
2170 tl_data
= tl_data
->tl_data_next
)
2171 if (tl_data
->tl_data_type
== new_tl_data
->tl_data_type
)
2175 /* if necessary, chain a new record in the beginning and point at it */
2180 (krb5_tl_data *) krb5_db_alloc(context, NULL,
2181 sizeof(krb5_tl_data)))
2184 if ((tl_data
= (krb5_tl_data
*) malloc (sizeof(krb5_tl_data
))) == NULL
) {
2188 memset(tl_data
, 0, sizeof(krb5_tl_data
));
2189 tl_data
->tl_data_next
= entry
->tl_data
;
2190 entry
->tl_data
= tl_data
;
2194 /* fill in the record */
2196 if (tl_data
->tl_data_contents
)
2197 krb5_db_free(context
, tl_data
->tl_data_contents
);
2199 tl_data
->tl_data_type
= new_tl_data
->tl_data_type
;
2200 tl_data
->tl_data_length
= new_tl_data
->tl_data_length
;
2201 tl_data
->tl_data_contents
= tmp
;
2202 memcpy(tmp
, new_tl_data
->tl_data_contents
, tl_data
->tl_data_length
);
2207 static krb5_error_code
2208 krb5_dbe_update_mod_princ_data_new(context
, entry
, mod_date
, mod_princ
)
2209 krb5_context context
;
2210 krb5_db_entry
* entry
;
2211 krb5_timestamp mod_date
;
2212 krb5_const_principal mod_princ
;
2214 krb5_tl_data tl_data
;
2216 krb5_error_code retval
= 0;
2217 krb5_octet
* nextloc
= 0;
2218 char * unparse_mod_princ
= 0;
2219 unsigned int unparse_mod_princ_size
;
2221 if ((retval
= krb5_unparse_name(context
, mod_princ
,
2222 &unparse_mod_princ
)))
2225 unparse_mod_princ_size
= strlen(unparse_mod_princ
) + 1;
2227 if ((nextloc
= (krb5_octet
*) malloc(unparse_mod_princ_size
+ 4))
2229 free(unparse_mod_princ
);
2233 tl_data
.tl_data_type
= KRB5_TL_MOD_PRINC
;
2234 tl_data
.tl_data_length
= unparse_mod_princ_size
+ 4;
2235 tl_data
.tl_data_contents
= nextloc
;
2238 krb5_kdb_encode_int32(mod_date
, nextloc
);
2241 memcpy(nextloc
+4, unparse_mod_princ
, unparse_mod_princ_size
);
2243 retval
= krb5_dbe_update_tl_data_new(context
, entry
, &tl_data
);
2245 free(unparse_mod_princ
);
2251 static krb5_error_code
2252 kdb_ldap_tgt_keysalt_iterate(ksent
, ptr
)
2253 krb5_key_salt_tuple
*ksent
;
2256 krb5_context context
;
2257 krb5_error_code kret
;
2258 struct iterate_args
*iargs
;
2262 krb5_db_entry
*entry
;
2264 iargs
= (struct iterate_args
*) ptr
;
2267 context
= iargs
->ctx
;
2268 entry
= iargs
->dbentp
;
2271 * Convert the master key password into a key for this particular
2272 * encryption system.
2274 pwd
.data
= mkey_password
;
2275 pwd
.length
= strlen(mkey_password
);
2276 kret
= krb5_c_random_seed(context
, &pwd
);
2280 /*if (!(kret = krb5_dbe_create_key_data(iargs->ctx, iargs->dbentp))) {*/
2281 if ((entry
->key_data
=
2282 (krb5_key_data
*) realloc(entry
->key_data
,
2283 (sizeof(krb5_key_data
) *
2284 (entry
->n_key_data
+ 1)))) == NULL
)
2287 memset(entry
->key_data
+ entry
->n_key_data
, 0, sizeof(krb5_key_data
));
2288 ind
= entry
->n_key_data
++;
2290 if (!(kret
= krb5_c_make_random_key(context
, ksent
->ks_enctype
,
2292 kret
= krb5_dbekd_encrypt_key_data(context
,
2297 &entry
->key_data
[ind
]);
2298 krb5_free_keyblock_contents(context
, &key
);
2304 /* End duplicate code */
2307 * This function creates service principals when
2308 * creating the realm object.
2311 kdb_ldap_create_principal (context
, princ
, op
, pblock
)
2312 krb5_context context
;
2313 krb5_principal princ
;
2315 struct realm_info
*pblock
;
2317 int retval
=0, currlen
=0, princtype
= 2 /* Service Principal */;
2318 unsigned char *curr
=NULL
;
2319 krb5_tl_data
*tl_data
=NULL
;
2320 krb5_db_entry entry
;
2325 kdb5_dal_handle
*dal_handle
= NULL
;
2326 krb5_ldap_context
*ldap_context
=NULL
;
2327 struct iterate_args iargs
;
2330 if ((pblock
== NULL
) || (context
== NULL
)) {
2334 dal_handle
= (kdb5_dal_handle
*) context
->db_context
;
2335 ldap_context
= (krb5_ldap_context
*) dal_handle
->db_context
;
2336 if (!(ldap_context
)) {
2341 memset(&entry
, 0, sizeof(entry
));
2343 tl_data
= malloc(sizeof(*tl_data
));
2344 if (tl_data
== NULL
) {
2348 memset(tl_data
, 0, sizeof(*tl_data
));
2349 tl_data
->tl_data_length
= 1 + 2 + 2 + 1 + 2 + 4;
2350 tl_data
->tl_data_type
= 7; /* KDB_TL_USER_INFO */
2351 curr
= tl_data
->tl_data_contents
= malloc(tl_data
->tl_data_length
);
2352 if (tl_data
->tl_data_contents
== NULL
) {
2357 memset(curr
, 1, 1); /* Passing the mask as principal type */
2360 STORE16_INT(curr
, currlen
);
2362 STORE16_INT(curr
, princtype
);
2365 mask
|= KADM5_PRINCIPAL
;
2366 mask
|= KADM5_ATTRIBUTES
;
2367 mask
|= KADM5_MAX_LIFE
;
2368 mask
|= KADM5_MAX_RLIFE
;
2369 mask
|= KADM5_PRINC_EXPIRE_TIME
;
2370 mask
|= KADM5_KEY_DATA
;
2372 entry
.tl_data
= tl_data
;
2373 entry
.n_tl_data
+= 1;
2374 /* Set the creator's name */
2377 if ((retval
= krb5_timeofday(context
, &now
)))
2379 if ((retval
= krb5_dbe_update_mod_princ_data_new(context
, &entry
,
2380 now
, &db_create_princ
)))
2383 entry
.attributes
= pblock
->flags
;
2384 entry
.max_life
= pblock
->max_life
;
2385 entry
.max_renewable_life
= pblock
->max_rlife
;
2386 entry
.expiration
= pblock
->expiration
;
2388 if ((retval
= krb5_copy_principal(context
, princ
, &entry
.princ
)))
2394 if ((pdata
= krb5_princ_component(context
, princ
, 1)) &&
2395 pdata
->length
== strlen("history") &&
2396 !memcmp(pdata
->data
, "history", strlen("history"))) {
2398 /* Allocate memory for storing the key */
2399 if ((entry
.key_data
= (krb5_key_data
*) malloc(
2400 sizeof(krb5_key_data
))) == NULL
) {
2405 memset(entry
.key_data
, 0, sizeof(krb5_key_data
));
2408 retval
= krb5_c_make_random_key(context
, global_params
.enctype
, &key
);
2412 kvno
= 1; /* New key is getting set */
2413 retval
= krb5_dbekd_encrypt_key_data(context
,
2414 &ldap_context
->lrparams
->mkey
,
2416 &entry
.key_data
[entry
.n_key_data
- 1]);
2417 krb5_free_keyblock_contents(context
, &key
);
2422 /*retval = krb5_c_make_random_key(context, 16, &key) ;*/
2423 iargs
.ctx
= context
;
2424 iargs
.rblock
= pblock
;
2425 iargs
.dbentp
= &entry
;
2428 * create a set of random keys by iterating through the key/salt
2429 * list, ignoring salt types.
2431 if ((retval
= krb5_keysalt_iterate(pblock
->kslist
,
2434 kdb_ldap_tgt_keysalt_iterate
,
2435 (krb5_pointer
) &iargs
)))
2441 /* Allocate memory for storing the key */
2442 if ((entry
.key_data
= (krb5_key_data
*) malloc(
2443 sizeof(krb5_key_data
))) == NULL
) {
2448 memset(entry
.key_data
, 0, sizeof(krb5_key_data
));
2450 kvno
= 1; /* New key is getting set */
2451 retval
= krb5_dbekd_encrypt_key_data(context
, pblock
->key
,
2452 &ldap_context
->lrparams
->mkey
,
2454 &entry
.key_data
[entry
.n_key_data
- 1]);
2463 } /* end of switch */
2465 retval
= krb5_ldap_put_principal(context
, &entry
, &nentry
, NULL
);
2467 com_err(NULL
, retval
, gettext("while adding entries to database"));
2472 krb5_dbe_free_contents(context
, &entry
);
2478 * This function destroys the realm object and the associated principals
2481 kdb5_ldap_destroy(argc
, argv
)
2485 extern char *optarg
;
2489 krb5_error_code retval
= 0;
2492 kdb5_dal_handle
*dal_handle
= NULL
;
2493 krb5_ldap_context
*ldap_context
= NULL
;
2494 #ifdef HAVE_EDIRECTORY
2495 int i
= 0, rightsmask
= 0;
2496 krb5_ldap_realm_params
*rparams
= NULL
;
2498 /* Solaris Kerberos: to remove stash file */
2499 char *stash_file
= NULL
;
2503 while ((optchar
= getopt(argc
, argv
, "f")) != -1) {
2510 db_usage(DESTROY_REALM
);
2517 printf(gettext("Deleting KDC database of '%s', are you sure?\n"), global_params
.realm
);
2518 printf(gettext("(type 'yes' to confirm)? "));
2519 if (fgets(buf
, sizeof(buf
), stdin
) == NULL
) {
2523 if (strcmp(buf
, yes
)) {
2527 printf(gettext("OK, deleting database of '%s'...\n"), global_params
.realm
);
2530 dal_handle
= (kdb5_dal_handle
*)util_context
->db_context
;
2531 ldap_context
= (krb5_ldap_context
*) dal_handle
->db_context
;
2532 if (!(ldap_context
)) {
2533 /* Solaris Kerberos */
2534 com_err(progname
, EINVAL
, gettext("while initializing database"));
2539 /* Read the kerberos container from the LDAP Server */
2540 if ((retval
= krb5_ldap_read_krbcontainer_params(util_context
,
2541 &(ldap_context
->krbcontainer
))) != 0) {
2542 /* Solaris Kerberos */
2543 com_err(progname
, retval
, gettext("while reading kerberos container information"));
2548 /* Read the Realm information from the LDAP Server */
2549 if ((retval
= krb5_ldap_read_realm_params(util_context
, global_params
.realm
,
2550 &(ldap_context
->lrparams
), &mask
)) != 0) {
2551 /* Solaris Kerberos */
2552 com_err(progname
, retval
, gettext("while reading realm information"));
2557 #ifdef HAVE_EDIRECTORY
2558 if ((mask
& LDAP_REALM_KDCSERVERS
) || (mask
& LDAP_REALM_ADMINSERVERS
) ||
2559 (mask
& LDAP_REALM_PASSWDSERVERS
)) {
2561 printf(gettext("Changing rights for the service object. Please wait ... "));
2564 rparams
= ldap_context
->lrparams
;
2566 rightsmask
|= LDAP_REALM_RIGHTS
;
2567 rightsmask
|= LDAP_SUBTREE_RIGHTS
;
2568 if ((rparams
!= NULL
) && (rparams
->kdcservers
!= NULL
)) {
2569 for (i
=0; (rparams
->kdcservers
[i
] != NULL
); i
++) {
2570 if ((retval
= krb5_ldap_delete_service_rights(util_context
,
2571 LDAP_KDC_SERVICE
, rparams
->kdcservers
[i
],
2572 rparams
->realm_name
, rparams
->subtree
, rightsmask
)) != 0) {
2573 printf(gettext("failed\n"));
2574 /* Solaris Kerberos */
2575 com_err(progname
, retval
, gettext("while assigning rights to '%s'"),
2576 rparams
->realm_name
);
2582 rightsmask
|= LDAP_REALM_RIGHTS
;
2583 rightsmask
|= LDAP_SUBTREE_RIGHTS
;
2584 if ((rparams
!= NULL
) && (rparams
->adminservers
!= NULL
)) {
2585 for (i
=0; (rparams
->adminservers
[i
] != NULL
); i
++) {
2586 if ((retval
= krb5_ldap_delete_service_rights(util_context
,
2587 LDAP_ADMIN_SERVICE
, rparams
->adminservers
[i
],
2588 rparams
->realm_name
, rparams
->subtree
, rightsmask
)) != 0) {
2589 printf(gettext("failed\n"));
2590 /* Solaris Kerberos */
2591 com_err(progname
, retval
, gettext("while assigning rights to '%s'"),
2592 rparams
->realm_name
);
2598 rightsmask
|= LDAP_REALM_RIGHTS
;
2599 rightsmask
|= LDAP_SUBTREE_RIGHTS
;
2600 if ((rparams
!= NULL
) && (rparams
->passwdservers
!= NULL
)) {
2601 for (i
=0; (rparams
->passwdservers
[i
] != NULL
); i
++) {
2602 if ((retval
= krb5_ldap_delete_service_rights(util_context
,
2603 LDAP_PASSWD_SERVICE
, rparams
->passwdservers
[i
],
2604 rparams
->realm_name
, rparams
->subtree
, rightsmask
)) != 0) {
2605 printf(gettext("failed\n"));
2606 /* Solaris Kerberos */
2607 com_err(progname
, retval
, gettext("while assigning rights to '%s'"),
2608 rparams
->realm_name
);
2613 printf(gettext("done\n"));
2616 /* Delete the realm container and all the associated principals */
2617 retval
= krb5_ldap_delete_realm(util_context
, global_params
.realm
);
2619 /* Solaris Kerberos */
2620 com_err(progname
, retval
, gettext("deleting database of '%s'"), global_params
.realm
);
2626 * Solaris Kerberos: check for a stash file and delete it if necessary
2627 * This behavior exists in the Solaris version of kdb5_util destroy.
2629 if (global_params
.stash_file
== NULL
) {
2630 char stashbuf
[MAXPATHLEN
+1];
2631 int realm_len
= strlen(global_params
.realm
);
2633 (void) strlcpy(stashbuf
, DEFAULT_KEYFILE_STUB
, sizeof (stashbuf
));
2635 if (realm_len
<= (MAXPATHLEN
-strlen(stashbuf
))) {
2636 (void) strncat(stashbuf
, global_params
.realm
,
2637 (MAXPATHLEN
-strlen(stashbuf
)));
2639 /* Solaris Kerberos */
2640 com_err(progname
, EINVAL
,
2641 gettext("can not determine stash file name for '%s'"),
2642 global_params
.realm
);
2646 stash_file
= stashbuf
;
2648 stash_file
= global_params
.stash_file
;
2650 /* Make sure stash_file is a regular file before unlinking */
2651 if (stat(stash_file
, &stb
) == 0) {
2652 if ((stb
.st_mode
& S_IFMT
) == S_IFREG
) {
2653 (void)unlink(stash_file
);
2655 /* Solaris Kerberos */
2656 com_err(progname
, EINVAL
,
2657 gettext("stash file '%s' not a regular file, can not delete"),
2662 } else if (errno
!= ENOENT
) {
2664 * If the error is something other than the file doesn't exist set an
2667 /* Solaris Kerberos */
2668 com_err(progname
, EINVAL
,
2669 gettext("could not stat stash file '%s', could not delete"),
2675 printf(gettext("** Database of '%s' destroyed.\n"), global_params
.realm
);