2 * Copyright (c) 1997 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by Kungliga Tekniska
20 * Högskolan and its contributors.
22 * 4. Neither the name of the Institute nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 #include "kadmin_locl.h"
40 #include <kadm5/private.h>
45 create_random_entry(krb5_principal princ
, time_t max_life
, time_t max_rlife
,
48 kadm5_principal_ent_rec ent
;
54 memset(&ent
, 0, sizeof(ent
));
55 ent
.principal
= princ
;
56 mask
|= KADM5_PRINCIPAL
;
57 ent
.max_life
= max_life
;
58 mask
|= KADM5_MAX_LIFE
;
59 ent
.max_renewable_life
= max_rlife
;
60 mask
|= KADM5_MAX_RLIFE
;
61 ent
.attributes
|= attributes
| KRB5_KDB_DISALLOW_ALL_TIX
;
62 mask
|= KADM5_ATTRIBUTES
;
64 ret
= kadm5_create_principal(kadm_handle
, &ent
, mask
, "hemlig");
67 ret
= kadm5_randkey_principal(kadm_handle
, princ
, &keys
, &n_keys
);
70 for(i
= 0; i
< n_keys
; i
++)
71 krb5_free_keyblock_contents(context
, &keys
[i
]);
73 ret
= kadm5_get_principal(kadm_handle
, princ
, &ent
,
74 KADM5_PRINCIPAL
| KADM5_ATTRIBUTES
);
77 ent
.attributes
&= (~KRB5_KDB_DISALLOW_ALL_TIX
);
79 ret
= kadm5_modify_principal(kadm_handle
, &ent
,
80 KADM5_ATTRIBUTES
|KADM5_KVNO
);
87 init(int argc
, char **argv
)
92 HDB
*db
= _kadm5_s_get_db(kadm_handle
);
94 ret
= db
->open(context
, db
, O_RDWR
| O_CREAT
, 0600);
96 krb5_warn(context
, ret
, "hdb_open");
99 db
->close(context
, db
);
100 for(i
= 1; i
< argc
; i
++){
101 krb5_principal princ
;
102 unsigned max_life
, max_rlife
;
104 /* Create `krbtgt/REALM' */
105 krb5_make_principal(context
, &princ
, argv
[i
], "krbtgt", argv
[i
], NULL
);
106 get_deltat("Realm max ticket life",
110 max_life
= 24 * 60 * 60;
111 get_deltat("Realm max renewable ticket life",
115 max_rlife
= 7 * max_life
;
116 create_random_entry(princ
, max_life
, max_rlife
, 0);
117 krb5_free_principal(context
, princ
);
118 /* Create `kadmin/changepw' */
119 krb5_make_principal(context
, &princ
, argv
[i
],
120 "kadmin", "changepw", NULL
);
121 create_random_entry(princ
, 5*60, 5*60,
122 KRB5_KDB_DISALLOW_TGT_BASED
|
123 KRB5_KDB_PWCHANGE_SERVICE
|
124 KRB5_KDB_DISALLOW_POSTDATED
|
125 KRB5_KDB_DISALLOW_FORWARDABLE
|
126 KRB5_KDB_DISALLOW_RENEWABLE
|
127 KRB5_KDB_DISALLOW_PROXIABLE
|
128 KRB5_KDB_REQUIRES_PRE_AUTH
);
129 krb5_free_principal(context
, princ
);
130 /* Create `kadmin/admin' */
131 krb5_make_principal(context
, &princ
, argv
[i
],
132 "kadmin", "admin", NULL
);
133 create_random_entry(princ
, 60*60, 60*60, KRB5_KDB_REQUIRES_PRE_AUTH
);
134 krb5_free_principal(context
, princ
);
135 /* Create `default' */
137 kadm5_principal_ent_rec ent
;
140 memset (&ent
, 0, sizeof(ent
));
141 mask
|= KADM5_PRINCIPAL
;
142 krb5_make_principal(context
, &ent
.principal
, argv
[i
],
144 mask
|= KADM5_MAX_LIFE
;
145 ent
.max_life
= 24 * 60 * 60;
146 mask
|= KADM5_MAX_RLIFE
;
147 ent
.max_renewable_life
= 7 * ent
.max_life
;
148 ent
.attributes
= KRB5_KDB_DISALLOW_ALL_TIX
;
149 mask
|= KADM5_ATTRIBUTES
;
151 ret
= kadm5_create_principal(kadm_handle
, &ent
, mask
, "");
153 krb5_err (context
, 1, ret
, "kadm5_create_principal");
155 krb5_free_principal(context
, ent
.principal
);