From f1f6ecfe4e6aebd7ce538a5bd18b93d0de429761 Mon Sep 17 00:00:00 2001 From: Theodore Tso Date: Thu, 20 Dec 1990 15:29:15 +0000 Subject: [PATCH] Added code to support the load_db and dump_db requests git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@1586 dc483132-0cff-0310-8789-dd5450dbe970 --- src/admin/edit/dump.c | 182 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 172 insertions(+), 10 deletions(-) diff --git a/src/admin/edit/dump.c b/src/admin/edit/dump.c index d4c56f1a8..0f1b1ea72 100644 --- a/src/admin/edit/dump.c +++ b/src/admin/edit/dump.c @@ -47,21 +47,41 @@ struct dump_record { FILE *f; }; +krb5_encrypt_block master_encblock; +extern char *current_dbname; +extern krb5_boolean dbactive; + +void update_ok_file(); + krb5_error_code dump_iterator(ptr, entry) krb5_pointer ptr; krb5_db_entry *entry; { krb5_error_code retval; - struct dump_record *arg = (struct dump_record *) entry; - char *name; + struct dump_record *arg = (struct dump_record *) ptr; + char *name=NULL, *mod_name=NULL; + int i; if (retval = krb5_unparse_name(entry->principal, &name)) { com_err(arg->comerr_name, retval, "while unparsing principal"); return retval; } - printf("entry: %s\n", name); + if (retval = krb5_unparse_name(entry->mod_name, &mod_name)) { + free(name); + com_err(arg->comerr_name, retval, "while unparsing principal"); + return retval; + } + fprintf(arg->f, "%d\t%d\t%s\t%d\t%d\t", strlen(name), strlen(mod_name), + name, entry->key.keytype, entry->key.length); + 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); free(name); + free(mod_name); return 0; } /*ARGSUSED*/ @@ -73,18 +93,26 @@ void dump_db(argc, argv) FILE *f; struct dump_record arg; - if (argc != 2) { + if (argc > 2) { com_err(argv[0], 0, "Usage: %s filename", argv[0]); return; } - if (!(f = fopen(argv[1], "w"))) { - com_err(argv[0], errno, - "While opening file %s for writing", argv[1]); - return; + if (argc == 2) { + if (!(f = fopen(argv[1], "w"))) { + com_err(argv[0], errno, + "While opening file %s for writing", argv[1]); + return; + } + } else { + f = stdout; } arg.comerr_name = argv[0]; arg.f = f; - (void) krb5_db_iterate(dump_iterator, &arg); + (void) krb5_db_iterate(dump_iterator, (krb5_pointer) &arg); + if (argc == 2) + fclose(f); + if (argv[1]) + update_ok_file(argv[1]); } @@ -105,7 +133,7 @@ void update_ok_file (file_name) } strcpy(file_ok, file_name); strcat(file_ok, ok); - if ((fd = open(file_ok, O_WRONLY|O_CREAT|O_TRUNC, 0400)) < 0) { + if ((fd = open(file_ok, O_WRONLY|O_CREAT|O_TRUNC, 0600)) < 0) { fprintf(stderr, "Error creating 'ok' file, '%s'", file_ok); perror(""); (void) fflush (stderr); @@ -115,3 +143,137 @@ void update_ok_file (file_name) close(fd); return; } + +void load_db(argc, argv) + int argc; + char **argv; +{ + FILE *f; + krb5_db_entry entry; + krb5_error_code retval; + int name_len, mod_name_len,i,one; + char *name, *mod_name; + char *new_dbname; + + if (argc != 3) { + com_err(argv[0], 0, "Usage: %s filename dbname", argv[0]); + return; + } + if (!(new_dbname = malloc(strlen(argv[2])+2))) { + com_err(argv[0], 0, "No room to allocate new database name!"); + return; + } + strcpy(new_dbname, argv[2]); + strcat(new_dbname, "~"); + if (retval = krb5_db_create(new_dbname)) { + com_err(argv[0], retval, "while creating database '%s'", + new_dbname); + return; + } + if (dbactive) { + if ((retval = krb5_db_fini()) && + retval != KRB5_KDB_DBNOTINITED) { + com_err(argv[0], retval, + "while closing previous database"); + return; + } + } + if (retval = krb5_db_set_name(new_dbname)) { + com_err(argv[0], retval, + "while setting active database to '%s'", new_dbname + ); + exit(1); + } + if (retval = krb5_db_init()) { + com_err(argv[0], retval, + "while initializing database %s", + new_dbname + ); + exit(1); + } + if (!(f = fopen(argv[1], "r"))) { + com_err(argv[0], errno, + "While opening file %s for writing", argv[1]); + return; + } + for (;;) { + memset((char *)&entry, 0, sizeof(entry)); + if (fscanf(f,"%d\t%d\t", &name_len, &mod_name_len) == EOF) + break; + if (!(name = malloc(name_len+1))) { + com_err(argv[0], errno, + "While allocating speace for name"); + break; + } + if (!(mod_name = malloc(mod_name_len+1))) { + free(name); + com_err(argv[0], errno, + "While allocating speace for name"); + break; + } + fscanf(f, "%s\t%d\t%d\t", name, &entry.key.keytype, + &entry.key.length); + if (!(entry.key.contents = (krb5_octet *) malloc(entry.key.length+1))) { + free(name); + free(mod_name); + com_err(argv[0], errno, + "While allocating speace for name"); + break; + } + for (i=0; i