diff options
Diffstat (limited to 'crypto/heimdal/kadmin/cpw.c')
-rw-r--r-- | crypto/heimdal/kadmin/cpw.c | 67 |
1 files changed, 19 insertions, 48 deletions
diff --git a/crypto/heimdal/kadmin/cpw.c b/crypto/heimdal/kadmin/cpw.c index 50c1cb2..c5fa9ed 100644 --- a/crypto/heimdal/kadmin/cpw.c +++ b/crypto/heimdal/kadmin/cpw.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997 - 2001 Kungliga Tekniska Högskolan + * Copyright (c) 1997 - 2004 Kungliga Tekniska Högskolan * (Royal Institute of Technology, Stockholm, Sweden). * All rights reserved. * @@ -32,8 +32,9 @@ */ #include "kadmin_locl.h" +#include "kadmin-commands.h" -RCSID("$Id: cpw.c,v 1.13 2001/08/10 08:05:35 joda Exp $"); +RCSID("$Id: cpw.c 16755 2006-02-18 23:30:32Z lha $"); struct cpw_entry_data { int random_key; @@ -42,21 +43,6 @@ struct cpw_entry_data { krb5_key_data *key_data; }; -static struct getargs args[] = { - { "random-key", 'r', arg_flag, NULL, "set random key" }, - { "random-password", 0, arg_flag, NULL, "set random password" }, - { "password", 'p', arg_string, NULL, "princial's password" }, - { "key", 0, arg_string, NULL, "DES key in hex" } -}; - -static int num_args = sizeof(args) / sizeof(args[0]); - -static void -usage(void) -{ - arg_printusage(args, num_args, "passwd", "principal..."); -} - static int set_random_key (krb5_principal principal) { @@ -87,7 +73,7 @@ set_random_password (krb5_principal principal) krb5_unparse_name(context, principal, &princ_name); - printf ("%s's password set to `%s'\n", princ_name, pw); + printf ("%s's password set to \"%s\"\n", princ_name, pw); free (princ_name); } memset (pw, 0, sizeof(pw)); @@ -107,7 +93,7 @@ set_password (krb5_principal principal, char *password) krb5_unparse_name(context, principal, &princ_name); asprintf(&prompt, "%s's Password: ", princ_name); free (princ_name); - ret = des_read_pw_string(pwbuf, sizeof(pwbuf), prompt, 1); + ret = UI_UTIL_read_pw_string(pwbuf, sizeof(pwbuf), prompt, 1); free (prompt); if(ret){ return 0; /* XXX error code? */ @@ -146,32 +132,19 @@ do_cpw_entry(krb5_principal principal, void *data) } int -cpw_entry(int argc, char **argv) +cpw_entry(struct passwd_options *opt, int argc, char **argv) { - krb5_error_code ret; + krb5_error_code ret = 0; int i; - int optind = 0; struct cpw_entry_data data; int num; - char *key_string; krb5_key_data key_data[3]; - data.random_key = 0; - data.random_password = 0; - data.password = NULL; + data.random_key = opt->random_key_flag; + data.random_password = opt->random_password_flag; + data.password = opt->password_string; data.key_data = NULL; - key_string = NULL; - - args[0].value = &data.random_key; - args[1].value = &data.random_password; - args[2].value = &data.password; - args[3].value = &key_string; - if(getarg(args, num_args, argc, argv, &optind)){ - usage(); - return 0; - } - num = 0; if (data.random_key) ++num; @@ -179,28 +152,26 @@ cpw_entry(int argc, char **argv) ++num; if (data.password) ++num; - if (key_string) + if (opt->key_string) ++num; if (num > 1) { - printf ("give only one of " + fprintf (stderr, "give only one of " "--random-key, --random-password, --password, --key\n"); - return 0; + return 1; } - if (key_string) { + if (opt->key_string) { const char *error; - if (parse_des_key (key_string, key_data, &error)) { - printf ("failed parsing key `%s': %s\n", key_string, error); - return 0; + if (parse_des_key (opt->key_string, key_data, &error)) { + fprintf (stderr, "failed parsing key \"%s\": %s\n", + opt->key_string, error); + return 1; } data.key_data = key_data; } - argc -= optind; - argv += optind; - for(i = 0; i < argc; i++) ret = foreach_principal(argv[i], do_cpw_entry, "cpw", &data); @@ -209,5 +180,5 @@ cpw_entry(int argc, char **argv) kadm5_free_key_data (kadm_handle, &dummy, key_data); } - return 0; + return ret != 0; } |