some better error interpretation and sequencing when a database
authorJohn Kohl <jtkohl@mit.edu>
Fri, 4 Jan 1991 14:51:45 +0000 (14:51 +0000)
committerJohn Kohl <jtkohl@mit.edu>
Fri, 4 Jan 1991 14:51:45 +0000 (14:51 +0000)
exists already

git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@1616 dc483132-0cff-0310-8789-dd5450dbe970

src/admin/create/kdb5_create.c

index a4d436bd9735c147c79465b6b04d066b8824eee7..e0e2de6d2370438574242e0935dd0a5dec86ab32 100644 (file)
@@ -173,13 +173,12 @@ char *argv[];
     if (!dbname)
        dbname = DEFAULT_DBM_FILE;      /* XXX? */
 
-    if (retval = krb5_db_create(dbname)) {
-       com_err(argv[0], retval, "while creating database '%s'",
-               dbname);
-       exit(1);
-    }
-    if (retval = krb5_db_set_name(dbname)) {
-       com_err(argv[0], retval, "while setting active database to '%s'",
+    retval = krb5_db_set_name(dbname);
+    if (!retval) retval = EEXIST;
+
+    if (retval == EEXIST || retval == EACCES || retval == EPERM) {
+       /* it exists ! */
+       com_err(argv[0], 0, "The database '%s' appears to already exist",
                dbname);
        exit(1);
     }
@@ -228,6 +227,20 @@ master key name '%s'\n",
        (void) krb5_finish_key(&master_encblock);
        exit(1);
     }
+    if (retval = krb5_db_create(dbname)) {
+       (void) krb5_finish_key(&master_encblock);
+       (void) krb5_finish_random_key(&master_encblock, &rblock.rseed);
+       com_err(argv[0], retval, "while creating database '%s'",
+               dbname);
+       exit(1);
+    }
+    if (retval = krb5_db_set_name(dbname)) {
+       (void) krb5_finish_key(&master_encblock);
+       (void) krb5_finish_random_key(&master_encblock, &rblock.rseed);
+        com_err(argv[0], retval, "while setting active database to '%s'",
+                dbname);
+        exit(1);
+    }
     if (retval = krb5_db_init()) {
        (void) krb5_finish_key(&master_encblock);
        (void) krb5_finish_random_key(&master_encblock, &rblock.rseed);