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 "admin_locl.h"
40 #include <parse_units.h>
43 init_des_key(hdb_entry
*ent
)
46 ent
->keys
.val
= realloc(ent
->keys
.val
,
47 (ent
->keys
.len
+ 1) * sizeof(*ent
->keys
.val
));
48 k
= ent
->keys
.val
+ ent
->keys
.len
;
50 memset(k
, 0, sizeof(*k
));
51 krb5_generate_random_keyblock(context
, KEYTYPE_DES
, &k
->key
);
57 set_keys(hdb_entry
*ent
, char *password
)
62 memset(&salt
, 0, sizeof(salt
));
63 krb5_get_salt(ent
->principal
, &salt
);
64 for(i
= 0; i
< ent
->keys
.len
; i
++) {
65 krb5_string_to_key(password
, &salt
, &ent
->keys
.val
[i
].key
); /* XXX */
66 seal_key(&ent
->keys
.val
[i
]);
68 krb5_data_free(&salt
);
76 strftime(buf
, sizeof(buf
), "%Y%m%d%H%M%S", gmtime(&t
));
81 event2string(Event
*ev
, char **str
)
89 krb5_unparse_name(context
, ev
->principal
, &pr
);
90 asprintf(&p
, "%s:%s", time2str(ev
->time
), pr
);
96 print_hdbflags (FILE *fp
, HDBFlags flags
)
100 unparse_flags (HDBFlags2int(flags
), HDBFlags_units
, buf
, sizeof(buf
));
101 fprintf (fp
, "%s", buf
);
105 parse_hdbflags (const char *s
, HDBFlags
*flags
)
109 t
= parse_flags (s
, HDBFlags_units
, HDBFlags2int(*flags
));
113 *flags
= int2HDBFlags(t
);
119 init_entry (HDB
*db
, hdb_entry
*ent
)
122 krb5_principal def_principal
;
125 realm
= krb5_princ_realm(context
, ent
->principal
);
126 krb5_build_principal(context
, &def_principal
,
131 def
.principal
= def_principal
;
132 if(db
->fetch(context
, db
, &def
)) {
133 krb5_free_principal(context
, def_principal
);
134 krb5_make_principal(context
, &def_principal
, NULL
, "default", NULL
);
135 def
.principal
= def_principal
;
136 if(db
->fetch(context
, db
, &def
)){
137 krb5_warnx(context
, "No `default' entry found. "
138 "(have you initialised the database?)");
139 memset(&def
, 0, sizeof(def
));
141 krb5_warnx(context
, "No `default' principal found for %s, "
142 "using local realms default.", *realm
);
144 krb5_free_principal (context
, def_principal
);
145 ent
->flags
.client
= 1;
146 ent
->flags
.server
= 1;
147 ent
->flags
.forwardable
= 1;
148 ent
->flags
.proxiable
= 1;
149 ent
->flags
.renewable
= 1;
150 ent
->flags
.postdate
= 1;
152 ent
->max_life
= malloc(sizeof(*ent
->max_life
));
153 *ent
->max_life
= *def
.max_life
;
156 ent
->max_renew
= malloc(sizeof(*ent
->max_renew
));
157 *ent
->max_renew
= *def
.max_renew
;
159 hdb_free_entry(context
, &def
);
163 set_event (hdb_entry
*ent
, Event
*ev
)
167 ev
->time
= time(NULL
);
168 realm
= krb5_princ_realm(context
, ent
->principal
);
170 krb5_build_principal(context
, &ev
->principal
,
178 set_created_by (hdb_entry
*ent
)
180 set_event (ent
, &ent
->created_by
);
184 set_modified_by (hdb_entry
*ent
)
186 if (ent
->modified_by
)
187 free_Event(ent
->modified_by
);
189 ent
->modified_by
= malloc(sizeof(*ent
->modified_by
));
190 set_event (ent
, ent
->modified_by
);
194 get_life (const char *name
, unsigned **v
)
200 unparse_time (**v
, buf
, sizeof(buf
));
201 t
= getlife (name
, buf
);
203 t
= getlife (name
, "unlimited");
207 *v
= malloc(sizeof(**v
));
216 get_time (const char *name
, time_t **v
)
222 get_flags(const char *name
, HDBFlags
*flags
)
226 fprintf (stderr
, "%s [", name
);
227 print_hdbflags (stderr
, *flags
);
228 fprintf (stderr
, "]: ");
229 if(fgets(buf
, sizeof(buf
), stdin
) == NULL
)
231 buf
[strlen(buf
) - 1] = '\0';
233 parse_hdbflags(buf
, flags
);
237 edit_entry(hdb_entry
*ent
)
239 get_time ("Valid start", &ent
->valid_start
);
240 get_time ("Valid end", &ent
->valid_end
);
241 get_time ("Password end", &ent
->pw_end
);
242 get_life ("Max ticket life", &ent
->max_life
);
243 get_life ("Max renewable life", &ent
->max_renew
);
244 get_flags ("Flags", &ent
->flags
);
248 set_password(hdb_entry
*ent
)
253 if(des_read_pw_string(buf
, sizeof(buf
), "Password:", 1))
255 for (i
= 0; i
< ent
->keys
.len
; ++i
)
256 free_Key (&ent
->keys
.val
[i
]);
257 free (ent
->keys
.val
);
258 if(strcasecmp(buf
, "random") == 0) {
260 ent
->keys
.val
= NULL
;
264 ent
->keys
.val
= calloc(1, sizeof(*ent
->keys
.val
));