diff options
author | Ken Raeburn <raeburn@mit.edu> | 2006-06-29 23:51:55 +0000 |
---|---|---|
committer | Ken Raeburn <raeburn@mit.edu> | 2006-06-29 23:51:55 +0000 |
commit | 04c6c727da625d54e91d0a38fa6e2d96b697271f (patch) | |
tree | 46bd042df1cc589d98efd2266da8c679a31c73f9 /src/kadmin | |
parent | 34bab3b31b6f748bdb88badc3607495050b88ac0 (diff) | |
download | krb5-04c6c727da625d54e91d0a38fa6e2d96b697271f.tar.gz krb5-04c6c727da625d54e91d0a38fa6e2d96b697271f.tar.xz krb5-04c6c727da625d54e91d0a38fa6e2d96b697271f.zip |
* kdb5_util.c (add_db_arg): New function.
(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
Diffstat (limited to 'src/kadmin')
-rw-r--r-- | src/kadmin/dbutil/dump.c | 21 | ||||
-rw-r--r-- | src/kadmin/dbutil/kdb5_create.c | 16 | ||||
-rw-r--r-- | src/kadmin/dbutil/kdb5_util.c | 44 | ||||
-rw-r--r-- | src/kadmin/dbutil/kdb5_util.h | 1 |
4 files changed, 30 insertions, 52 deletions
diff --git a/src/kadmin/dbutil/dump.c b/src/kadmin/dbutil/dump.c index 2ce811d0b5..f0d277c122 100644 --- a/src/kadmin/dbutil/dump.c +++ b/src/kadmin/dbutil/dump.c @@ -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) { diff --git a/src/kadmin/dbutil/kdb5_create.c b/src/kadmin/dbutil/kdb5_create.c index b04595d65c..46bccce430 100644 --- a/src/kadmin/dbutil/kdb5_create.c +++ b/src/kadmin/dbutil/kdb5_create.c @@ -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(); diff --git a/src/kadmin/dbutil/kdb5_util.c b/src/kadmin/dbutil/kdb5_util.c index 0e308e54ec..5abe708ad6 100644 --- a/src/kadmin/dbutil/kdb5_util.c +++ b/src/kadmin/dbutil/kdb5_util.c @@ -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; diff --git a/src/kadmin/dbutil/kdb5_util.h b/src/kadmin/dbutil/kdb5_util.h index bb6b0ac64a..90b7b43ef3 100644 --- a/src/kadmin/dbutil/kdb5_util.h +++ b/src/kadmin/dbutil/kdb5_util.h @@ -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); |