From d41513c4f9804af962214f0a57c197f4cb35c96b Mon Sep 17 00:00:00 2001 From: Barry Jaspan Date: Thu, 1 Aug 1996 19:56:53 +0000 Subject: [PATCH] * dump.c, kadm5_create.c, kdb5_create.c: create policy database and kadm5 principals when loading a databas git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@8891 dc483132-0cff-0310-8789-dd5450dbe970 --- src/kadmin/dbutil/ChangeLog | 3 +++ src/kadmin/dbutil/dump.c | 10 ++++++++ src/kadmin/dbutil/kadm5_create.c | 39 +++++++++++++++++++------------- src/kadmin/dbutil/kdb5_create.c | 5 ++-- src/kadmin/dbutil/loadv4.c | 17 +++++++++----- 5 files changed, 49 insertions(+), 25 deletions(-) diff --git a/src/kadmin/dbutil/ChangeLog b/src/kadmin/dbutil/ChangeLog index 82e18f593..d22b83a07 100644 --- a/src/kadmin/dbutil/ChangeLog +++ b/src/kadmin/dbutil/ChangeLog @@ -1,5 +1,8 @@ Thu Aug 1 14:34:51 1996 Barry Jaspan + * dump.c, kadm5_create.c, kdb5_create.c: create policy database + and kadm5 principals when loading a databas + * loadv4.c: create empty policy database after loading V4 dump file * dumpv4.c (dump_v4db): use global_params.stash_file diff --git a/src/kadmin/dbutil/dump.c b/src/kadmin/dbutil/dump.c index 29bda177a..d362bc121 100644 --- a/src/kadmin/dbutil/dump.c +++ b/src/kadmin/dbutil/dump.c @@ -2040,6 +2040,16 @@ load_db(argc, argv) if (!update && (kret = osa_adb_create_policy_db(&newparams))) { fprintf(stderr, "%s: %s while creating policy database\n", programname, error_message(kret)); + exit_status++; + kadm5_free_config_params(kcontext, &newparams); + if (dumpfile) fclose(f); + return; + } + if (!update && (load != &beta7_version) && + (kret = kadm5_create_magic_princs(&newparams, kcontext))) { + fprintf(stderr, "%s: %s while creating KADM5 principals\n", + programname, error_message(kret)); + exit_status++; kadm5_free_config_params(kcontext, &newparams); if (dumpfile) fclose(f); return; diff --git a/src/kadmin/dbutil/kadm5_create.c b/src/kadmin/dbutil/kadm5_create.c index d31ce3319..45eeef29b 100644 --- a/src/kadmin/dbutil/kadm5_create.c +++ b/src/kadmin/dbutil/kadm5_create.c @@ -29,7 +29,7 @@ int add_admin_princ(void *handle, krb5_context context, #define ADMIN_LIFETIME 60*60*3 /* 3 hours */ #define CHANGEPW_LIFETIME 60*5 /* 5 minutes */ -extern char *whoami; +extern char *progname; extern krb5_encrypt_block master_encblock; extern krb5_keyblock master_keyblock; @@ -63,34 +63,41 @@ int kadm5_create(kadm5_config_params *params) */ if (retval = kadm5_get_config_params(context, NULL, NULL, params, params)) { - com_err(whoami, retval, str_INITING_KCONTEXT); + com_err(progname, retval, str_INITING_KCONTEXT); return 1; } if (retval = osa_adb_create_policy_db(params)) { - com_err(whoami, retval, str_CREATING_POLICY_DB); + com_err(progname, retval, str_CREATING_POLICY_DB); return 1; } - if ((retval = kadm5_init(whoami, NULL, NULL, params, + retval = kadm5_create_magic_princs(params, context); + + krb5_free_context(context); + + return retval; +} + +int kadm5_create_magic_princs(kadm5_config_params *params, + krb5_context *context) +{ + int retval; + void *handle; + + if ((retval = kadm5_init(progname, NULL, NULL, params, KADM5_STRUCT_VERSION, KADM5_API_VERSION_2, &handle))) { - com_err(whoami, retval, str_INITING_KCONTEXT); - - krb5_free_context(context); - exit(ERR); + com_err(progname, retval, str_INITING_KCONTEXT); + return retval; } retval = add_admin_princs(handle, context, params->realm); kadm5_destroy(handle); - krb5_free_context(context); - if (retval) - exit(retval); - - return 0; + return retval; } /* @@ -202,7 +209,7 @@ int add_admin_princ(void *handle, krb5_context context, fullname = build_name_with_realm(name, realm); if (ret = krb5_parse_name(context, fullname, &ent.principal)) { - com_err(whoami, ret, str_PARSE_NAME); + com_err(progname, ret, str_PARSE_NAME); return(ERR); } ent.max_life = lifetime; @@ -220,7 +227,7 @@ int add_admin_princ(void *handle, krb5_context context, KADM5_ATTRIBUTES)); if (ret) { - com_err(whoami, ret, str_PUT_PRINC, fullname); + com_err(progname, ret, str_PUT_PRINC, fullname); krb5_free_principal(context, ent.principal); free(fullname); return ERR; @@ -233,7 +240,7 @@ int add_admin_princ(void *handle, krb5_context context, free(fullname); if (ret) { - com_err(whoami, ret, str_RANDOM_KEY, fullname); + com_err(progname, ret, str_RANDOM_KEY, fullname); return ERR; } diff --git a/src/kadmin/dbutil/kdb5_create.c b/src/kadmin/dbutil/kdb5_create.c index 2e22e2294..e05cc4ee0 100644 --- a/src/kadmin/dbutil/kdb5_create.c +++ b/src/kadmin/dbutil/kdb5_create.c @@ -114,8 +114,8 @@ krb5_principal_data db_create_princ = { }; static char *mkey_password = 0; -char *whoami; +extern char *progname; extern int exit_status; extern osa_adb_policy_t policy_db; extern kadm5_config_params global_params; @@ -123,7 +123,7 @@ extern krb5_context util_context; static void usage() { - fprintf(stderr, "usage: %s [-s]\n", whoami); + fprintf(stderr, "usage: %s [-s]\n", progname); exit_status++; } @@ -144,7 +144,6 @@ void kdb5_create(argc, argv) if (strrchr(argv[0], '/')) argv[0] = strrchr(argv[0], '/')+1; - whoami = argv[0]; mkey_password = NULL; optind = 1; diff --git a/src/kadmin/dbutil/loadv4.c b/src/kadmin/dbutil/loadv4.c index f4e54a278..7dfade9f5 100644 --- a/src/kadmin/dbutil/loadv4.c +++ b/src/kadmin/dbutil/loadv4.c @@ -429,8 +429,7 @@ master key name '%s'\n", memset((char *)master_keyblock.contents, 0, master_keyblock.length); /* - * Cons up config params for new policy database (which will be - * empty). The policy dbname keys off the dbname. + * Cons up config params for new database. */ newparams = global_params; newparams.mask &= ~(KADM5_CONFIG_ADBNAME | KADM5_CONFIG_ADB_LOCKFILE); @@ -442,18 +441,24 @@ master key name '%s'\n", "parameters"); return; } + /* * Always create the policy db, even if we are not loading a dump - * file with policy info, because they are probably loading an old - * dump intending to use it with the new kadm5 system (ie: using - * load as create). + * file with policy info. */ if (retval = osa_adb_create_policy_db(&newparams)) { com_err(PROGNAME, retval, "while creating policy database"); kadm5_free_config_params(context, &newparams); return; } - + /* + * Create the magic principals in the database. + */ + if (retval = kadm5_create_magic_princs(&newparams, context)) { + com_err(PROGNAME, retval, "while creating KADM5 principals"); + return; + } + krb5_free_context(context); return; } -- 2.26.2