summaryrefslogtreecommitdiffstats
path: root/crypto/heimdal/kadmin/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/heimdal/kadmin/util.c')
-rw-r--r--crypto/heimdal/kadmin/util.c126
1 files changed, 104 insertions, 22 deletions
diff --git a/crypto/heimdal/kadmin/util.c b/crypto/heimdal/kadmin/util.c
index f30c8c5..8d7abc3 100644
--- a/crypto/heimdal/kadmin/util.c
+++ b/crypto/heimdal/kadmin/util.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1997, 1998, 1999 Kungliga Tekniska Högskolan
+ * Copyright (c) 1997 - 2001 Kungliga Tekniska Högskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* All rights reserved.
*
@@ -34,7 +34,7 @@
#include "kadmin_locl.h"
#include <parse_units.h>
-RCSID("$Id: util.c,v 1.23 1999/12/02 17:04:58 joda Exp $");
+RCSID("$Id: util.c,v 1.30 2001/01/11 23:07:29 assar Exp $");
/*
* util.c - functions for parsing, unparsing, and editing different
@@ -103,9 +103,7 @@ parse_attributes (const char *resp, krb5_flags *attr, int *mask, int bit)
{
krb5_flags tmp = *attr;
- if (resp[0] == '\0')
- return 0;
- else if (str2attributes(resp, &tmp) == 0) {
+ if (str2attributes(resp, &tmp) == 0) {
*attr = tmp;
if (mask)
*mask |= bit;
@@ -133,6 +131,8 @@ edit_attributes (const char *prompt, krb5_flags *attr, int *mask, int bit)
attributes2str(*attr, buf, sizeof(buf));
for (;;) {
get_response("Attributes", buf, resp, sizeof(resp));
+ if (resp[0] == '\0')
+ break;
if (parse_attributes (resp, attr, mask, bit) == 0)
break;
}
@@ -168,15 +168,20 @@ time_t2str(time_t t, char *str, size_t len, int include_time)
*/
int
-str2time_t (const char *str, time_t *time)
+str2time_t (const char *str, time_t *t)
{
const char *p;
- struct tm tm;
+ struct tm tm, tm2;
memset (&tm, 0, sizeof (tm));
if(strcasecmp(str, "never") == 0) {
- *time = 0;
+ *t = 0;
+ return 0;
+ }
+
+ if(strcasecmp(str, "now") == 0) {
+ *t = time(NULL);
return 0;
}
@@ -186,13 +191,17 @@ str2time_t (const char *str, time_t *time)
return -1;
/* Do it on the end of the day */
- tm.tm_hour = 23;
- tm.tm_min = 59;
- tm.tm_sec = 59;
-
- strptime (p, "%H:%M:%S", &tm);
+ tm2.tm_hour = 23;
+ tm2.tm_min = 59;
+ tm2.tm_sec = 59;
+
+ if(strptime (p, "%H:%M:%S", &tm2) != NULL) {
+ tm.tm_hour = tm2.tm_hour;
+ tm.tm_min = tm2.tm_min;
+ tm.tm_sec = tm2.tm_sec;
+ }
- *time = tm2time (tm, 0);
+ *t = tm2time (tm, 0);
return 0;
}
@@ -252,10 +261,10 @@ edit_timet (const char *prompt, krb5_timestamp *value, int *mask, int bit)
void
deltat2str(unsigned t, char *str, size_t len)
{
- if(t)
- unparse_time(t, str, len);
- else
+ if(t == 0 || t == INT_MAX)
snprintf(str, len, "unlimited");
+ else
+ unparse_time(t, str, len);
}
/*
@@ -333,27 +342,37 @@ int
edit_entry(kadm5_principal_ent_t ent, int *mask,
kadm5_principal_ent_t default_ent, int default_mask)
{
- if (default_ent && (default_mask & KADM5_MAX_LIFE))
+ if (default_ent
+ && (default_mask & KADM5_MAX_LIFE)
+ && !(*mask & KADM5_MAX_LIFE))
ent->max_life = default_ent->max_life;
edit_deltat ("Max ticket life", &ent->max_life, mask,
KADM5_MAX_LIFE);
- if (default_ent && (default_mask & KADM5_MAX_RLIFE))
+ if (default_ent
+ && (default_mask & KADM5_MAX_RLIFE)
+ && !(*mask & KADM5_MAX_RLIFE))
ent->max_renewable_life = default_ent->max_renewable_life;
edit_deltat ("Max renewable life", &ent->max_renewable_life, mask,
KADM5_MAX_RLIFE);
- if (default_ent && (default_mask & KADM5_PRINC_EXPIRE_TIME))
+ if (default_ent
+ && (default_mask & KADM5_PRINC_EXPIRE_TIME)
+ && !(*mask & KADM5_PRINC_EXPIRE_TIME))
ent->princ_expire_time = default_ent->princ_expire_time;
edit_timet ("Principal expiration time", &ent->princ_expire_time, mask,
KADM5_PRINC_EXPIRE_TIME);
- if (default_ent && (default_mask & KADM5_PW_EXPIRATION))
+ if (default_ent
+ && (default_mask & KADM5_PW_EXPIRATION)
+ && !(*mask & KADM5_PW_EXPIRATION))
ent->pw_expiration = default_ent->pw_expiration;
edit_timet ("Password expiration time", &ent->pw_expiration, mask,
KADM5_PW_EXPIRATION);
- if (default_ent && (default_mask & KADM5_ATTRIBUTES))
+ if (default_ent
+ && (default_mask & KADM5_ATTRIBUTES)
+ && !(*mask & KADM5_ATTRIBUTES))
ent->attributes = default_ent->attributes & ~KRB5_KDB_DISALLOW_ALL_TIX;
edit_attributes ("Attributes", &ent->attributes, mask,
KADM5_ATTRIBUTES);
@@ -518,3 +537,66 @@ get_response(const char *prompt, const char *def, char *buf, size_t len)
strncpy(buf, def, len);
buf[len-1] = 0;
}
+
+/*
+ * return [0, 16) or -1
+ */
+
+static int
+hex2n (char c)
+{
+ static char hexdigits[] = "0123456789abcdef";
+ const char *p;
+
+ p = strchr (hexdigits, tolower((int)c));
+ if (p == NULL)
+ return -1;
+ else
+ return p - hexdigits;
+}
+
+/*
+ * convert a key in a readable format into a keyblock.
+ * return 0 iff succesful, otherwise `err' should point to an error message
+ */
+
+int
+parse_des_key (const char *key_string, krb5_key_data *key_data,
+ const char **err)
+{
+ const char *p = key_string;
+ unsigned char bits[8];
+ int i;
+
+ if (strlen (key_string) != 16) {
+ *err = "bad length, should be 16 for DES key";
+ return 1;
+ }
+ for (i = 0; i < 8; ++i) {
+ int d1, d2;
+
+ d1 = hex2n(p[2 * i]);
+ d2 = hex2n(p[2 * i + 1]);
+ if (d1 < 0 || d2 < 0) {
+ *err = "non-hex character";
+ return 1;
+ }
+ bits[i] = (d1 << 4) | d2;
+ }
+ for (i = 0; i < 3; ++i) {
+ key_data[i].key_data_ver = 2;
+ key_data[i].key_data_kvno = 0;
+ /* key */
+ key_data[i].key_data_type[0] = ETYPE_DES_CBC_CRC;
+ key_data[i].key_data_length[0] = 8;
+ key_data[i].key_data_contents[0] = malloc(8);
+ memcpy (key_data[i].key_data_contents[0], bits, 8);
+ /* salt */
+ key_data[i].key_data_type[1] = KRB5_PW_SALT;
+ key_data[i].key_data_length[1] = 0;
+ key_data[i].key_data_contents[1] = NULL;
+ }
+ key_data[0].key_data_type[0] = ETYPE_DES_CBC_MD5;
+ key_data[1].key_data_type[0] = ETYPE_DES_CBC_MD4;
+ return 0;
+}
OpenPOWER on IntegriCloud