From 239d06f465d147a7efcd0bc4dc5b310fec613972 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Love=20H=C3=B6rnquist=20=C3=85strand?= Date: Thu, 14 Apr 2005 16:45:14 +0000 Subject: [PATCH] add option -H --hex to the add command git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@14793 ec53bebd-3082-4978-b11e-865c3cabbd6b --- admin/add.c | 25 +++++++++++++++++++++++-- admin/ktutil-commands.in | 6 ++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/admin/add.c b/admin/add.c index 80edf5eba..9f9f16f4e 100644 --- a/admin/add.c +++ b/admin/add.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997-2004 Kungliga Tekniska Högskolan + * Copyright (c) 1997-2005 Kungliga Tekniska Högskolan * (Royal Institute of Technology, Stockholm, Sweden). * All rights reserved. * @@ -101,7 +101,28 @@ kt_add(struct add_options *opt, int argc, char **argv) opt->password_string = buf; } if(opt->password_string) { - if (!opt->salt_flag) { + if (opt->hex_flag) { + size_t len; + void *data; + + len = (strlen(opt->password_string) + 1) / 2; + + data = malloc(len); + if (data == NULL) { + krb5_warn(context, ENOMEM, "malloc"); + goto out; + } + + if (hex_decode(opt->password_string, data, len) != len) { + free(data); + krb5_warn(context, ENOMEM, "hex decode failed"); + goto out; + } + + ret = krb5_keyblock_init(context, enctype, + data, len, &entry.keyblock); + free(data); + } else if (!opt->salt_flag) { krb5_salt salt; krb5_data pw; diff --git a/admin/ktutil-commands.in b/admin/ktutil-commands.in index c2e6d1d8d..a23b76314 100644 --- a/admin/ktutil-commands.in +++ b/admin/ktutil-commands.in @@ -75,6 +75,12 @@ command = { type = "flag" help = "generate random key" } + option = { + long = "hex" + short = "H" + type = "flag" + help = "password is a hexadecimal string" + } function = "kt_add" help = "Adds a key to a keytab." max_args = "0"