* kdb5_util.c (add_db_arg): New function.
authorKen Raeburn <raeburn@mit.edu>
Thu, 29 Jun 2006 23:51:55 +0000 (23:51 +0000)
committerKen Raeburn <raeburn@mit.edu>
Thu, 29 Jun 2006 23:51:55 +0000 (23:51 +0000)
(main): Use it.
* kdb5_util.h (add_db_arg): Declare it.
* kdb5_create.c (kdb5_create): Use it.
* dump.c (load_db): Use it.

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

src/kadmin/dbutil/dump.c
src/kadmin/dbutil/kdb5_create.c
src/kadmin/dbutil/kdb5_util.c
src/kadmin/dbutil/kdb5_util.h

index 2ce811d0b5a9e053968044938e51a3c521e23e4d..f0d277c12280e25fe4b842914431b7c1bc1ecf5e 100644 (file)
@@ -2121,23 +2121,12 @@ load_db(argc, argv)
            verbose = 1;
        else if (!strcmp(argv[aindex], updateoption))
            update = 1;
-       else if (!strcmp(argv[aindex], hashoption))
-       {
-           db5util_db_args_size++;
-           {
-               char **temp = realloc( db5util_db_args, sizeof(char*) * (db5util_db_args_size+1)); /* one for NULL */
-               if( temp == NULL )
-               {
-                   com_err(progname, ENOMEM, "while parsing command arguments\n");
-                   exit(1);
-               }
-
-               db5util_db_args = temp;
+       else if (!strcmp(argv[aindex], hashoption)) {
+           if (!add_db_arg("hash=true")) {
+               com_err(progname, ENOMEM, "while parsing command arguments\n");
+               exit(1);
            }
-           db5util_db_args[db5util_db_args_size-1] = "hash=true";
-           db5util_db_args[db5util_db_args_size]   = NULL;
-       }
-       else
+       } else
            break;
     }
     if ((argc - aindex) != 1) {
index b04595d65c64e22068b7f56a550063adc84f4f8d..46bccce4304ac221ba9469b182a793d65c3fa9ee 100644 (file)
@@ -171,19 +171,11 @@ void kdb5_create(argc, argv)
            do_stash++;
            break;
        case 'h':
-           db5util_db_args_size++;
-           {
-               char **temp = realloc( db5util_db_args, sizeof(char*) * (db5util_db_args_size+1)); /* one for NULL */
-               if( temp == NULL )
-               {
-                   com_err(progname, ENOMEM, "while parsing command arguments\n");
-                   exit(1);
-               }
-
-               db5util_db_args = temp;
+           if (!add_db_arg("hash=true")) {
+               com_err(progname, ENOMEM, "while parsing command arguments\n");
+               exit(1);
            }
-           db5util_db_args[db5util_db_args_size-1] = "hash=true";
-           db5util_db_args[db5util_db_args_size]   = NULL;
+           break;
        case '?':
        default:
            usage();
index 0e308e54ecb9e310f47a500b3e3911cdc2925538..5abe708ad62d9e89b93b887eb86fca5db48380c4 100644 (file)
@@ -156,6 +156,19 @@ static void extended_com_err_fn (const char *myprog, errcode_t code,
     fprintf (stderr, "\n");
 }
 
+int add_db_arg(char *arg)
+{
+    char **temp;
+    db5util_db_args_size++;
+    temp = realloc(db5util_db_args,
+                  sizeof(char *) * (db5util_db_args_size + 1));
+    if (temp == NULL)
+       return 0;
+    db5util_db_args[db5util_db_args_size-1] = arg;
+    db5util_db_args[db5util_db_args_size]   = NULL;
+    return 1;
+}
+
 int main(argc, argv)
     int argc;
     char *argv[];
@@ -205,35 +218,18 @@ int main(argc, argv)
            strcpy( db_name_tmp, "dbname=");
            strcat( db_name_tmp, global_params.dbname );
 
-           db5util_db_args_size++;
-           {
-               char **temp = realloc( db5util_db_args, sizeof(char*) * (db5util_db_args_size+1)); /* one for NULL */
-               if( temp == NULL )
-               {
-                   com_err(progname, ENOMEM, "while parsing command arguments\n");
-                   exit(1);
-               }
-
-               db5util_db_args = temp;
+           if (!add_db_arg(db_name_tmp)) {
+               com_err(progname, ENOMEM, "while parsing command arguments\n");
+               exit(1);
            }
-           db5util_db_args[db5util_db_args_size-1] = db_name_tmp;
-           db5util_db_args[db5util_db_args_size]   = NULL;
 
        } else if (strcmp(*argv, "-x") == 0 && ARG_VAL) {
           db5util_db_args_size++;
-          {
-              char **temp = realloc( db5util_db_args, sizeof(char*) * (db5util_db_args_size+1)); /* one for NULL */
-              if( temp == NULL )
-              {
-                  fprintf(stderr,"%s: Cannot initialize. Not enough memory\n",
-                          argv[0]);
-                  exit(1);
-              }
-
-              db5util_db_args = temp;
+          if (!add_db_arg(koptarg)) {
+              fprintf(stderr,"%s: Cannot initialize. Not enough memory\n",
+                      argv[0]);
+              exit(1);
           }
-          db5util_db_args[db5util_db_args_size-1] = koptarg;
-          db5util_db_args[db5util_db_args_size]   = NULL;
 
        } else if (strcmp(*argv, "-r") == 0 && ARG_VAL) {
            global_params.realm = koptarg;
index bb6b0ac64ae9ef97720b3be90be58d4a336615c6..90b7b43ef35c364d2b77e09f2aeab09f63874735 100644 (file)
@@ -42,6 +42,7 @@ extern int valid_master_key;
 extern krb5_db_entry master_db;
 extern char **db5util_db_args;
 extern int    db5util_db_args_size;
+extern int add_db_arg(char *arg);
 
 extern void usage(void);