add --key

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@8052 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Assar Westerlund
2000-03-23 15:20:43 +00:00
parent 6df8ed90f7
commit 4bfe69645d
2 changed files with 88 additions and 12 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 1998, 1999 Kungliga Tekniska H<>gskolan
* Copyright (c) 1997 - 2000 Kungliga Tekniska H<>gskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* All rights reserved.
*
@@ -39,12 +39,14 @@ struct cpw_entry_data {
int random_key;
int random_password;
char *password;
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]);
@@ -118,6 +120,16 @@ set_password (krb5_principal principal, char *password)
return ret;
}
static int
set_key_data (krb5_principal principal, krb5_key_data *key_data)
{
krb5_error_code ret;
ret = kadm5_chpass_principal_with_key (kadm_handle, principal,
3, key_data);
return ret;
}
static int
do_cpw_entry(krb5_principal principal, void *data)
{
@@ -127,8 +139,12 @@ do_cpw_entry(krb5_principal principal, void *data)
return set_random_key (principal);
else if (e->random_password)
return set_random_password (principal);
else
else if (e->password)
return set_password (principal, e->password);
else if (e->key_data)
return set_key_data (principal, e->key_data);
else
abort ();
}
int
@@ -139,14 +155,20 @@ cpw_entry(int argc, char **argv)
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.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;
@@ -159,19 +181,35 @@ cpw_entry(int argc, char **argv)
++num;
if (data.password)
++num;
if (key_string)
++num;
if (num > 1) {
printf ("give only one of "
"--random-key, --random-password, --password\n");
"--random-key, --random-password, --password, --key\n");
return 0;
}
if (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;
}
data.key_data = key_data;
}
argc -= optind;
argv += optind;
for(i = 0; i < argc; i++)
ret = foreach_principal(argv[i], do_cpw_entry, &data);
if (data.key_data) {
int16_t dummy;
kadm5_free_key_data (kadm_handle, &dummy, key_data);
}
return 0;
}