From a4e5039a2852c53016af366db4bad193438e92ae Mon Sep 17 00:00:00 2001 From: Theodore Tso Date: Wed, 6 Mar 1991 13:58:11 +0000 Subject: [PATCH] Improved load_db's parsing of the dump file Added support for dumping and loading the salt entries. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@1865 dc483132-0cff-0310-8789-dd5450dbe970 --- src/admin/edit/dump.c | 96 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 81 insertions(+), 15 deletions(-) diff --git a/src/admin/edit/dump.c b/src/admin/edit/dump.c index fa612f0dc..ad35c19c3 100644 --- a/src/admin/edit/dump.c +++ b/src/admin/edit/dump.c @@ -46,6 +46,8 @@ struct dump_record { FILE *f; }; +static char ld_vers[] = "kdb5_edit load_dump version 1.0\n"; + krb5_encrypt_block master_encblock; extern char *current_dbname; extern krb5_boolean dbactive; @@ -76,9 +78,14 @@ krb5_db_entry *entry; for (i=0; ikey.length; i++) { fprintf(arg->f, "%02x", *(entry->key.contents+i)); } - fprintf(arg->f, "\t%u\t%u\t%u\t%u\t%u\t%s\t%u\t%u\n", entry->kvno, - entry->max_life, entry->max_renewable_life, entry->mkvno, - entry->expiration, mod_name, entry->mod_date, entry->attributes); + fprintf(arg->f, "\t%u\t%u\t%u\t%u\t%u\t%s\t%u\t%u\t%u\t%u\t", entry->kvno, + entry->max_life, entry->max_renewable_life, entry->mkvno, + entry->expiration, mod_name, entry->mod_date, entry->attributes, + entry->salt_type, entry->salt_length); + for (i=0; isalt_length; i++) { + fprintf(arg->f, "%02x", *(entry->salt+i)); + } + fprintf(arg->f, ";\n"); free(name); free(mod_name); return 0; @@ -120,6 +127,7 @@ void dump_db(argc, argv) } else { f = stdout; } + fputs(ld_vers, f); arg.comerr_name = argv[0]; arg.f = f; (void) krb5_db_iterate(dump_iterator, (krb5_pointer) &arg); @@ -167,7 +175,11 @@ void load_db(argc, argv) int name_len, mod_name_len,i,one; char *name, *mod_name; char *new_dbname; + int ch; int load_error = 0; + int lineno = 0; + int stype, slength; + char buf[64]; /* Must be longer than ld_vers */ if (argc != 3) { com_err(argv[0], 0, "Usage: %s filename dbname", argv[0]); @@ -210,7 +222,14 @@ void load_db(argc, argv) "While opening file %s for writing", argv[1]); return; } + fgets(buf, sizeof(buf), f); + if (strcmp(buf, ld_vers)) { + com_err(argv[0], 0, "Bad dump file version"); + load_error++; + goto error_out; + } for (;;) { + lineno++; memset((char *)&entry, 0, sizeof(entry)); if (fscanf(f,"%d\t%d\t", &name_len, &mod_name_len) == EOF) break; @@ -227,8 +246,12 @@ void load_db(argc, argv) load_error++; break; } - fscanf(f, "%s\t%d\t%d\t", name, &entry.key.keytype, - &entry.key.length); + if (fscanf(f, "%s\t%d\t%d\t", name, &entry.key.keytype, + &entry.key.length) != 3) { + fprintf(stderr, "Couldn't parse line #%d\n", lineno); + load_error++; + break; + } if (!(entry.key.contents = (krb5_octet *) malloc(entry.key.length+1))) { free(name); free(mod_name); @@ -238,23 +261,65 @@ void load_db(argc, argv) break; } for (i=0; i