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"
59 while(*p
&& !isspace(*p
))
62 while(*p
&& isspace(*p
)) p
++;
67 parse_time_string(time_t *t
, char *s
)
69 int year
, month
, date
, hour
, minute
, second
;
71 if(strcmp(s
, "-") == 0)
74 t
= malloc(sizeof(*t
));
75 sscanf(s
, "%04d%02d%02d%02d%02d%02d",
76 &year
, &month
, &date
, &hour
, &minute
, &second
);
77 tm
.tm_year
= year
- 1900;
78 tm
.tm_mon
= month
- 1;
89 parse_integer(unsigned *u
, char *s
)
91 if(strcmp(s
, "-") == 0)
94 u
= malloc(sizeof(*u
));
100 parse_keys(hdb_entry
*ent
, char *str
)
106 p
= strsep(&str
, ":");
107 sscanf(p
, "%d", &tmp
);
109 p
= strsep(&str
, ":");
112 key
= realloc(ent
->keys
.val
,
113 (ent
->keys
.len
+ 1) * sizeof(*ent
->keys
.val
));
117 key
= ent
->keys
.val
+ ent
->keys
.len
;
119 memset(key
, 0, sizeof(*key
));
120 sscanf(p
, "%d", &tmp
);
122 p
= strsep(&str
, ":");
123 sscanf(p
, "%d", &tmp
);
124 key
->key
.keytype
= tmp
;
125 p
= strsep(&str
, ":");
126 krb5_data_alloc(&key
->key
.keyvalue
, (strlen(p
) - 1) / 2 + 1);
127 for(i
= 0; i
< strlen(p
); i
+= 2){
128 sscanf(p
+ i
, "%02x", &tmp
);
129 ((u_char
*)key
->key
.keyvalue
.data
)[i
/ 2] = tmp
;
131 p
= strsep(&str
, ":");
132 if(strcmp(p
, "-") != 0){
135 if(sscanf(p
, "%u/", &type
) != 1){
143 key
->salt
= malloc(sizeof(*key
->salt
));
144 key
->salt
->type
= type
;
147 krb5_data_alloc(&key
->salt
->salt
, (p_len
- 1) / 2 + 1);
148 for(i
= 0; i
< p_len
; i
+= 2){
149 sscanf(p
+ i
, "%02x", &tmp
);
150 ((u_char
*)key
->salt
->salt
.data
)[i
/ 2] = tmp
;
153 krb5_data_zero (&key
->salt
->salt
);
155 p
= strsep(&str
, ":");
160 parse_event(Event
*ev
, char *str
)
163 if(strcmp(str
, "-") == 0)
166 ev
= malloc(sizeof(*ev
));
167 memset(ev
, 0, sizeof(*ev
));
168 p
= strsep(&str
, ":");
169 parse_time_string(&ev
->time
, p
);
170 p
= strsep(&str
, ":");
171 krb5_parse_name(context
, p
, &ev
->principal
);
176 parse_hdbflags2int(char *str
)
179 parse_integer(&i
, str
);
181 return int2HDBFlags(i
);
185 doit(char *filename
, int merge
)
198 f
= fopen(filename
, "r");
200 krb5_warn(context
, errno
, "%s: %s", filename
);
204 flags
|= O_CREAT
| O_TRUNC
;
205 err
= hdb_open(context
, &db
, database
, flags
, 0600);
207 krb5_warn(context
, err
, "hdb_open");
212 while(fgets(s
, sizeof(s
), f
)){
218 else if(isspace(*p
)) {
252 memset(&ent
, 0, sizeof(ent
));
253 err
= krb5_parse_name(context
, e
.principal
, &ent
.principal
);
255 fprintf(stderr
, "%s:%s:%s (%s)\n",
258 krb5_get_err_text(context
, err
),
263 parse_keys(&ent
, e
.key
);
265 parse_event(&ent
.created_by
, e
.created
);
266 ent
.modified_by
= parse_event(NULL
, e
.modified
);
267 ent
.valid_start
= parse_time_string(NULL
, e
.valid_start
);
268 ent
.valid_end
= parse_time_string(NULL
, e
.valid_end
);
269 ent
.pw_end
= parse_time_string(NULL
, e
.pw_end
);
270 ent
.max_life
= parse_integer(NULL
, e
.max_life
);
271 ent
.max_renew
= parse_integer(NULL
, e
.max_renew
);
273 ent
.flags
= parse_hdbflags2int(e
.flags
);
274 db
->store(context
, db
, 1, &ent
);
275 hdb_free_entry (context
, &ent
);
277 db
->close(context
, db
);
282 load(int argc
, char **argv
)
285 krb5_warnx(context
, "Usage: load filename");
293 merge(int argc
, char **argv
)
296 krb5_warnx(context
, "Usage: merge filename");