diff options
Diffstat (limited to 'crypto/heimdal/kdc/hpropd.c')
-rw-r--r-- | crypto/heimdal/kdc/hpropd.c | 254 |
1 files changed, 43 insertions, 211 deletions
diff --git a/crypto/heimdal/kdc/hpropd.c b/crypto/heimdal/kdc/hpropd.c index d27ff25..12a9766 100644 --- a/crypto/heimdal/kdc/hpropd.c +++ b/crypto/heimdal/kdc/hpropd.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997-2002 Kungliga Tekniska Högskolan + * Copyright (c) 1997-2006 Kungliga Tekniska Högskolan * (Royal Institute of Technology, Stockholm, Sweden). * All rights reserved. * @@ -33,142 +33,15 @@ #include "hprop.h" -RCSID("$Id: hpropd.c,v 1.36 2003/04/16 15:46:32 lha Exp $"); - -#ifdef KRB4 -static des_cblock mkey4; -static des_key_schedule msched4; - -static char * -time2str(time_t t) -{ - static char buf[128]; - strftime(buf, sizeof(buf), "%Y%m%d%H%M", gmtime(&t)); - return buf; -} - -static int -dump_krb4(krb5_context context, hdb_entry *ent, int fd) -{ - char name[ANAME_SZ]; - char instance[INST_SZ]; - char realm[REALM_SZ]; - char buf[1024]; - char *p; - int i; - int ret; - char *princ_name; - Event *modifier; - krb5_realm *realms; - int cmp; - - ret = krb5_524_conv_principal(context, ent->principal, - name, instance, realm); - if (ret) { - krb5_unparse_name(context, ent->principal, &princ_name); - krb5_warn(context, ret, "%s", princ_name); - free(princ_name); - return -1; - } - - ret = krb5_get_default_realms (context, &realms); - if (ret) { - krb5_warn(context, ret, "krb5_get_default_realms"); - return -1; - } - - cmp = strcmp (realms[0], ent->principal->realm); - krb5_free_host_realm (context, realms); - if (cmp != 0) - return -1; - - snprintf (buf, sizeof(buf), "%s %s ", name, - (strlen(instance) != 0) ? instance : "*"); - - if (ent->max_life) { - asprintf(&p, "%d", krb_time_to_life(0, *ent->max_life)); - strlcat(buf, p, sizeof(buf)); - free(p); - } else - strlcat(buf, "255", sizeof(buf)); - strlcat(buf, " ", sizeof(buf)); - - i = 0; - while (i < ent->keys.len && - ent->keys.val[i].key.keytype != KEYTYPE_DES) - ++i; - - if (i == ent->keys.len) { - krb5_warnx(context, "No DES key for %s.%s", name, instance); - return -1; - } - - if (ent->keys.val[i].mkvno) - asprintf(&p, "%d ", *ent->keys.val[i].mkvno); - else - asprintf(&p, "%d ", 1); - strlcat(buf, p, sizeof(buf)); - free(p); - - asprintf(&p, "%d ", ent->kvno); - strlcat(buf, p, sizeof(buf)); - free(p); - - asprintf(&p, "%d ", 0); /* Attributes are always 0*/ - strlcat(buf, p, sizeof(buf)); - free(p); - - { - u_int32_t *key = ent->keys.val[i].key.keyvalue.data; - kdb_encrypt_key((des_cblock*)key, (des_cblock*)key, - &mkey4, msched4, DES_ENCRYPT); - asprintf(&p, "%x %x ", (int)htonl(*key), (int)htonl(*(key+1))); - strlcat(buf, p, sizeof(buf)); - free(p); - } - - if (ent->valid_end == NULL) - strlcat(buf, time2str(60*60*24*365*50), sizeof(buf)); /*no expiration*/ - else - strlcat(buf, time2str(*ent->valid_end), sizeof(buf)); - strlcat(buf, " ", sizeof(buf)); - - if (ent->modified_by == NULL) - modifier = &ent->created_by; - else - modifier = ent->modified_by; - - ret = krb5_524_conv_principal(context, modifier->principal, - name, instance, realm); - if (ret) { - krb5_unparse_name(context, modifier->principal, &princ_name); - krb5_warn(context, ret, "%s", princ_name); - free(princ_name); - return -1; - } - asprintf(&p, "%s %s %s\n", time2str(modifier->time), - (strlen(name) != 0) ? name : "*", - (strlen(instance) != 0) ? instance : "*"); - strlcat(buf, p, sizeof(buf)); - free(p); - - ret = write(fd, buf, strlen(buf)); - if (ret == -1) - krb5_warnx(context, "write"); - return 0; -} -#endif /* KRB4 */ +RCSID("$Id: hpropd.c 22245 2007-12-08 23:48:52Z lha $"); static int inetd_flag = -1; static int help_flag; static int version_flag; static int print_dump; -static const char *database = HDB_DEFAULT_DB; +static const char *database; static int from_stdin; static char *local_realm; -#ifdef KRB4 -static int v4dump; -#endif static char *ktname = NULL; struct getargs args[] = { @@ -179,9 +52,6 @@ struct getargs args[] = { "Not started from inetd" }, { "keytab", 'k', arg_string, &ktname, "keytab to use for authentication", "keytab" }, { "realm", 'r', arg_string, &local_realm, "realm to use" }, -#ifdef KRB4 - { "v4dump", '4', arg_flag, &v4dump, "create v4 type DB" }, -#endif { "version", 0, arg_flag, &version_flag, NULL, NULL }, { "help", 'h', arg_flag, &help_flag, NULL, NULL} }; @@ -206,14 +76,10 @@ main(int argc, char **argv) krb5_keytab keytab; int fd; HDB *db; - int optind = 0; + int optidx = 0; char *tmp_db; krb5_log_facility *fac; int nprincs; -#ifdef KRB4 - int e; - int fd_out = -1; -#endif setprogname(argv[0]); @@ -226,14 +92,9 @@ main(int argc, char **argv) ; krb5_set_warn_dest(context, fac); - if(getarg(args, num_args, argc, argv, &optind)) + if(getarg(args, num_args, argc, argv, &optidx)) usage(1); -#ifdef KRB4 - if (v4dump && database == HDB_DEFAULT_DB) - database = "/var/kerberos/524_dump"; -#endif /* KRB4 */ - if(local_realm != NULL) krb5_set_default_realm(context, local_realm); @@ -244,12 +105,15 @@ main(int argc, char **argv) exit(0); } - argc -= optind; - argv += optind; + argc -= optidx; + argv += optidx; if (argc != 0) usage(1); + if (database == NULL) + database = hdb_default_db(context); + if(from_stdin) fd = STDIN_FILENO; else { @@ -280,7 +144,7 @@ main(int argc, char **argv) addr_name, sizeof(addr_name)) == NULL) strlcpy (addr_name, "unknown address", - sizeof(addr_name)); + sizeof(addr_name)); krb5_log(context, fac, 0, "Connection from %s", addr_name); @@ -319,10 +183,13 @@ main(int argc, char **argv) ret = krb5_make_principal(context, &c1, NULL, "kadmin", "hprop", NULL); if(ret) krb5_err(context, 1, ret, "krb5_make_principal"); - principalname2krb5_principal(&c2, authent->cname, authent->crealm); + _krb5_principalname2krb5_principal(context, &c2, + authent->cname, authent->crealm); if(!krb5_principal_compare(context, c1, c2)) { char *s; - krb5_unparse_name(context, c2, &s); + ret = krb5_unparse_name(context, c2, &s); + if (ret) + s = "unparseable name"; krb5_errx(context, 1, "Unauthorized connection from %s", s); } krb5_free_principal(context, c1); @@ -335,37 +202,19 @@ main(int argc, char **argv) if(!print_dump) { asprintf(&tmp_db, "%s~", database); -#ifdef KRB4 - if (v4dump) { - fd_out = open(tmp_db, O_WRONLY | O_CREAT | O_TRUNC, 0600); - if (fd_out == -1) - krb5_errx(context, 1, "%s", strerror(errno)); - } - else -#endif /* KRB4 */ - { - ret = hdb_create(context, &db, tmp_db); - if(ret) - krb5_err(context, 1, ret, "hdb_create(%s)", tmp_db); - ret = db->open(context, db, O_RDWR | O_CREAT | O_TRUNC, 0600); - if(ret) - krb5_err(context, 1, ret, "hdb_open(%s)", tmp_db); - } - } -#ifdef KRB4 - if (v4dump) { - e = kdb_get_master_key(0, &mkey4, msched4); - if(e) - krb5_errx(context, 1, "kdb_get_master_key: %s", - krb_get_err_text(e)); + ret = hdb_create(context, &db, tmp_db); + if(ret) + krb5_err(context, 1, ret, "hdb_create(%s)", tmp_db); + ret = db->hdb_open(context, db, O_RDWR | O_CREAT | O_TRUNC, 0600); + if(ret) + krb5_err(context, 1, ret, "hdb_open(%s)", tmp_db); } -#endif /* KRB4 */ nprincs = 0; while(1){ krb5_data data; - hdb_entry entry; + hdb_entry_ex entry; if(from_stdin) { ret = krb5_read_message(context, &fd, &data); @@ -384,52 +233,35 @@ main(int argc, char **argv) krb5_write_priv_message(context, ac, &fd, &data); } if(!print_dump) { -#ifdef KRB4 - if (v4dump) { - ret = rename(tmp_db, database); - if (ret) - krb5_errx(context, 1, "rename"); - ret = close(fd_out); - if (ret) - krb5_errx(context, 1, "close"); - } else -#endif /* KRB4 */ - { - ret = db->rename(context, db, database); - if(ret) - krb5_err(context, 1, ret, "db_rename"); - ret = db->close(context, db); - if(ret) - krb5_err(context, 1, ret, "db_close"); - } + ret = db->hdb_rename(context, db, database); + if(ret) + krb5_err(context, 1, ret, "db_rename"); + ret = db->hdb_close(context, db); + if(ret) + krb5_err(context, 1, ret, "db_close"); } break; } - ret = hdb_value2entry(context, &data, &entry); + memset(&entry, 0, sizeof(entry)); + ret = hdb_value2entry(context, &data, &entry.entry); + krb5_data_free(&data); if(ret) krb5_err(context, 1, ret, "hdb_value2entry"); if(print_dump) hdb_print_entry(context, db, &entry, stdout); else { -#ifdef KRB4 - if (v4dump) { - ret = dump_krb4(context, &entry, fd_out); - if(!ret) nprincs++; - } + ret = db->hdb_store(context, db, 0, &entry); + if(ret == HDB_ERR_EXISTS) { + char *s; + ret = krb5_unparse_name(context, entry.entry.principal, &s); + if (ret) + s = strdup("unparseable name"); + krb5_warnx(context, "Entry exists: %s", s); + free(s); + } else if(ret) + krb5_err(context, 1, ret, "db_store"); else -#endif /* KRB4 */ - { - ret = db->store(context, db, 0, &entry); - if(ret == HDB_ERR_EXISTS) { - char *s; - krb5_unparse_name(context, entry.principal, &s); - krb5_warnx(context, "Entry exists: %s", s); - free(s); - } else if(ret) - krb5_err(context, 1, ret, "db_store"); - else - nprincs++; - } + nprincs++; } hdb_free_entry(context, &entry); } |