2 * Copyright (c) 1999-2002 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 KTH nor the names of its contributors may be
18 * used to endorse or promote products derived from this software without
19 * specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY KTH AND ITS CONTRIBUTORS ``AS IS'' AND ANY
22 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KTH OR ITS CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
28 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
36 RCSID("$Id: print.c,v 1.8 2002/05/24 15:18:02 joda Exp $");
39 This is the present contents of a dump line. This might change at
40 any time. Fields are separated by white space.
49 salt (- means use normal salt)
50 creation date and principal
51 modification date and principal
52 principal valid from date (not used)
53 principal valid end date (not used)
54 principal key expires (not used)
61 static krb5_error_code
62 append_string(krb5_context context, krb5_storage *sp, const char *fmt, ...)
68 vasprintf(&s, fmt, ap);
71 krb5_set_error_string(context, "malloc: out of memory");
74 ret = krb5_storage_write(sp, s, strlen(s));
79 static krb5_error_code
80 append_hex(krb5_context context, krb5_storage *sp, krb5_data *data)
86 for(i = 0; i < data->length; i++)
87 if(!isalnum((unsigned char)p[i]) && p[i] != '.'){
92 return append_string(context, sp, "\"%.*s\"",
93 data->length, data->data);
94 for(i = 0; i < data->length; i++)
95 append_string(context, sp, "%02x", ((unsigned char*)data->data)[i]);
102 static char buf[128];
103 strftime(buf, sizeof(buf), "%Y%m%d%H%M%S", gmtime(&t));
107 static krb5_error_code
108 append_event(krb5_context context, krb5_storage *sp, Event *ev)
113 return append_string(context, sp, "- ");
114 if (ev->principal != NULL) {
115 ret = krb5_unparse_name(context, ev->principal, &pr);
119 ret = append_string(context, sp, "%s:%s ",
120 time2str(ev->time), pr ? pr : "UNKNOWN");
125 static krb5_error_code
126 entry2string_int (krb5_context context, krb5_storage *sp, hdb_entry *ent)
133 ret = krb5_unparse_name(context, ent->principal, &p);
136 append_string(context, sp, "%s ", p);
139 append_string(context, sp, "%d", ent->kvno);
141 for(i = 0; i < ent->keys.len; i++){
142 /* --- mkvno, keytype */
143 if(ent->keys.val[i].mkvno)
144 append_string(context, sp, ":%d:%d:",
145 *ent->keys.val[i].mkvno,
146 ent->keys.val[i].key.keytype);
148 append_string(context, sp, "::%d:",
149 ent->keys.val[i].key.keytype);
151 append_hex(context, sp, &ent->keys.val[i].key.keyvalue);
152 append_string(context, sp, ":");
154 if(ent->keys.val[i].salt){
155 append_string(context, sp, "%u/", ent->keys.val[i].salt->type);
156 append_hex(context, sp, &ent->keys.val[i].salt->salt);
158 append_string(context, sp, "-");
160 append_string(context, sp, " ");
162 append_event(context, sp, &ent->created_by);
163 /* --- modified by */
164 append_event(context, sp, ent->modified_by);
166 /* --- valid start */
168 append_string(context, sp, "%s ", time2str(*ent->valid_start));
170 append_string(context, sp, "- ");
174 append_string(context, sp, "%s ", time2str(*ent->valid_end));
176 append_string(context, sp, "- ");
178 /* --- password ends */
180 append_string(context, sp, "%s ", time2str(*ent->pw_end));
182 append_string(context, sp, "- ");
186 append_string(context, sp, "%d ", *ent->max_life);
188 append_string(context, sp, "- ");
190 /* --- max renewable life */
192 append_string(context, sp, "%d ", *ent->max_renew);
194 append_string(context, sp, "- ");
197 append_string(context, sp, "%d ", HDBFlags2int(ent->flags));
199 /* --- generation number */
200 if(ent->generation) {
201 append_string(context, sp, "%s:%d:%d", time2str(ent->generation->time),
202 ent->generation->usec,
203 ent->generation->gen);
205 append_string(context, sp, "-");
211 hdb_entry2string (krb5_context context, hdb_entry *ent, char **str)
217 sp = krb5_storage_emem();
219 krb5_set_error_string(context, "malloc: out of memory");
223 ret = entry2string_int(context, sp, ent);
225 krb5_storage_free(sp);
229 krb5_storage_write(sp, "\0", 1);
230 krb5_storage_to_data(sp, &data);
231 krb5_storage_free(sp);
236 /* print a hdb_entry to (FILE*)data; suitable for hdb_foreach */
239 hdb_print_entry(krb5_context context, HDB *db, hdb_entry *entry, void *data)
247 sp = krb5_storage_from_fd(fileno(f));
249 krb5_set_error_string(context, "malloc: out of memory");
253 ret = entry2string_int(context, sp, entry);
255 krb5_storage_free(sp);
259 krb5_storage_write(sp, "\n", 1);
260 krb5_storage_free(sp);