2 * Copyright (c) 2000 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. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 extern krb5_error_code
_hdb_mdb_value2entry(krb5_context context
,
38 krb5_kvno target_kvno
,
41 extern int _hdb_mit_dump2mitdb_entry(krb5_context context
,
48 can have any number of princ stanzas.
49 format is as follows (only \n indicates newlines)
50 princ\t%d\t (%d is KRB5_KDB_V1_BASE_LENGTH, always 38)
51 %d\t (strlen of principal e.g. shadow/foo@ANDREW.CMU.EDU)
52 %d\t (number of tl_data)
53 %d\t (number of key data, e.g. how many keys for this user)
54 %d\t (extra data length)
57 %d\t (max lifetime, seconds)
58 %d\t (max renewable life, seconds)
59 %d\t (expiration, seconds since epoch or 2145830400 for never)
60 %d\t (password expiration, seconds, 0 for never)
61 %d\t (last successful auth, seconds since epoch)
62 %d\t (last failed auth, per above)
63 %d\t (failed auth count)
64 foreach tl_data 0 to number of tl_data - 1 as above
65 %d\t%d\t (data type, data length)
66 foreach tl_data 0 to length-1
67 %02x (tl data contents[element n])
68 except if tl_data length is 0
71 foreach key 0 to number of keys - 1 as above
72 %d\t%d\t (key data version, kvno)
73 foreach version 0 to key data version - 1 (a key or a salt)
74 %d\t%d\t(data type for this key, data length for this key)
75 foreach key data length 0 to length-1
76 %02x (key data contents[element n])
77 except if key_data length is 0
80 foreach extra data length 0 to length - 1
81 %02x (extra data part)
94 } while(q
&& *q
== '\0');
98 #include <kadm5/admin.h>
101 my_fgetln(FILE *f
, char **buf
, size_t *sz
, size_t *len
)
106 *buf
= malloc(*sz
? *sz
: 2048);
113 while ((p
= fgets(&(*buf
)[*len
], *sz
, f
))) {
114 if (strcspn(*buf
, "\r\n") || feof(f
)) {
118 *len
+= strlen(&(*buf
)[*len
]); /* *len should be == *sz */
119 n
= realloc(buf
, *sz
+ (*sz
>> 1));
130 return 0; /* *len == 0 || no EOL -> EOF */
134 mit_prop_dump(void *arg
, const char *file
)
137 size_t line_bufsz
= 0;
142 struct hdb_entry_ex ent
;
143 struct prop_data
*pd
= arg
;
144 krb5_storage
*sp
= NULL
;
147 memset(&ent
, 0, sizeof (ent
));
148 f
= fopen(file
, "r");
153 sp
= krb5_storage_emem();
156 while ((ret
= my_fgetln(f
, &line
, &line_bufsz
, &line_len
)) == 0 &&
162 if(strncmp(line
, "kdb5_util", strlen("kdb5_util")) == 0) {
165 if (strcmp(q
, "kdb5_util"))
166 errx(1, "line %d: unknown version", lineno
);
167 q
= nexttoken(&p
); /* load_dump */
168 if (strcmp(q
, "load_dump"))
169 errx(1, "line %d: unknown version", lineno
);
170 q
= nexttoken(&p
); /* load_dump */
171 if (strcmp(q
, "version"))
172 errx(1, "line %d: unknown version", lineno
);
173 q
= nexttoken(&p
); /* x.0 */
174 if (sscanf(q
, "%d", &major
) != 1)
175 errx(1, "line %d: unknown version", lineno
);
176 if (major
!= 4 && major
!= 5 && major
!= 6)
177 errx(1, "unknown dump file format, got %d, expected 4-6",
180 } else if(strncmp(p
, "policy", strlen("policy")) == 0) {
181 warnx("line: %d: ignoring policy (not supported)", lineno
);
183 } else if(strncmp(p
, "princ", strlen("princ")) != 0) {
184 warnx("line %d: not a principal", lineno
);
187 krb5_storage_truncate(sp
, 0);
188 ret
= _hdb_mit_dump2mitdb_entry(pd
->context
, line
, sp
);
190 warnx("line: %d: failed to parse; ignoring", lineno
);
193 ret
= krb5_storage_to_data(sp
, &kdb_ent
);
195 ret
= _hdb_mdb_value2entry(pd
->context
, &kdb_ent
, 0, &ent
.entry
);
196 krb5_data_free(&kdb_ent
);
198 warnx("line: %d: failed to store; ignoring", lineno
);
201 ret
= v5_prop(pd
->context
, NULL
, &ent
, arg
);
202 hdb_free_entry(pd
->context
, &ent
);
210 krb5_storage_free(sp
);
211 if (ret
&& ret
== ENOMEM
)
212 errx(1, "out of memory");
214 errx(1, "line %d: problem parsing dump line", lineno
);