From 04c6c727da625d54e91d0a38fa6e2d96b697271f Mon Sep 17 00:00:00 2001 From: Ken Raeburn Date: Thu, 29 Jun 2006 23:51:55 +0000 Subject: [PATCH] * 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 --- src/kadmin/dbutil/dump.c | 21 ++++------------ src/kadmin/dbutil/kdb5_create.c | 16 +++--------- src/kadmin/dbutil/kdb5_util.c | 44 +++++++++++++++------------------ 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 2ce811d0b..f0d277c12 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 b04595d65..46bccce43 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 0e308e54e..5abe708ad 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 bb6b0ac64..90b7b43ef 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); -- 2.26.2