* Makefile.in, keytab.c : Move db keytab routines here
authorChris Provenzano <proven@mit.edu>
Wed, 13 Dec 1995 12:11:09 +0000 (12:11 +0000)
committerChris Provenzano <proven@mit.edu>
Wed, 13 Dec 1995 12:11:09 +0000 (12:11 +0000)
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@7223 dc483132-0cff-0310-8789-dd5450dbe970

src/lib/kdb/ChangeLog
src/lib/kdb/Makefile.in
src/lib/kdb/keytab.c [new file with mode: 0644]

index c7fc45f476b8480a9606a76b4276f89968938489..1a23edc8a23d564869ea170d068bf4ca64e5b43e 100644 (file)
@@ -1,3 +1,8 @@
+
+Wed Dec 13 07:09:30 1995  Chris Provenzano (proven@mit.edu)
+
+       * Makefile.in, keytab.c : Move db keytab routines here.
+
 Wed Dec 13 03:51:53 1995  Chris Provenzano (proven@mit.edu)
 
         * kdb_xdr.c : Remove mkvno for krb5_db_entry
index 5c4f3270df9e93e438338629cd2448568df69e5e..e450ad6e4dcd44a543d4c9cf0c4aee02661fbddd 100644 (file)
@@ -4,6 +4,7 @@ CFLAGS = $(CCOPTS) $(DEFS) $(DBFLAGS)
 all:: $(OBJS)
 
 SRCS= \
+       $(srcdir)/keytab.c \
        $(srcdir)/encrypt_key.c \
        $(srcdir)/decrypt_key.c \
        $(srcdir)/kdb_cpw.c \
@@ -15,6 +16,7 @@ SRCS= \
        $(srcdir)/store_mkey.c
 
 OBJS= \
+       keytab.o \
        encrypt_key.o \
        decrypt_key.o \
        kdb_cpw.o \
diff --git a/src/lib/kdb/keytab.c b/src/lib/kdb/keytab.c
new file mode 100644 (file)
index 0000000..9789d30
--- /dev/null
@@ -0,0 +1,117 @@
+/*
+ * kadmin/v5server/keytab.c
+ *
+ * Copyright 1995 by the Massachusetts Institute of Technology.
+ * All Rights Reserved.
+ *
+ * Export of this software from the United States of America may
+ *   require a specific license from the United States Government.
+ *   It is the responsibility of any person or organization contemplating
+ *   export to obtain such a license before exporting.
+ * 
+ * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
+ * distribute this software and its documentation for any purpose and
+ * without fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation, and that
+ * the name of M.I.T. not be used in advertising or publicity pertaining
+ * to distribution of the software without specific, written prior
+ * permission.  M.I.T. makes no representations about the suitability of
+ * this software for any purpose.  It is provided "as is" without express
+ * or implied warranty.
+ * 
+ */
+
+#include "k5-int.h"
+#include "kdb_dbc.h"
+
+krb5_error_code krb5_ktkdb_get_entry(krb5_context, krb5_keytab, krb5_principal,
+                  krb5_kvno, krb5_enctype, krb5_keytab_entry *);
+
+krb5_kt_ops krb5_kt_kdb_ops = {
+    0,
+    "KDB",     /* Prefix -- this string should not appear anywhere else! */
+    NULL,
+    NULL,
+    NULL,
+    krb5_ktkdb_get_entry,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,
+    NULL,              /* (void *) &krb5_ktfile_ser_entry */
+};
+
+typedef struct krb5_ktkdb_data {
+    char * name;
+} krb5_ktkdb_data;
+
+krb5_error_code
+krb5_ktkdb_resolve(context, kdb, id)
+    krb5_context         context;
+    krb5_db_context    * kdb;
+    krb5_keytab                * id;
+{
+    krb5_db_context    * data;
+
+    if ((*id = (krb5_keytab) malloc(sizeof(**id))) == NULL)
+        return(ENOMEM);
+
+    if ((data = (krb5_ktkdb_data *)malloc(sizeof(krb5_db_context))) == NULL) {
+        krb5_xfree(*id);
+        return(ENOMEM);
+    }
+
+    memcpy(data, kdb, sizeof(krb5_db_context)); 
+    (*id)->data = (krb5_pointer)data;
+    (*id)->ops = &krb5_kt_kdb_ops;
+    (*id)->magic = KV5M_KEYTAB;
+    return(0);
+}
+
+krb5_error_code
+krb5_ktkdb_get_entry(context, id, principal, kvno, enctype, entry)
+    krb5_context         context;
+    krb5_keytab          id;
+    krb5_principal       principal;
+    krb5_kvno            kvno;
+    krb5_enctype         enctype;
+    krb5_keytab_entry  * entry;
+{
+    krb5_encrypt_block  * master_key;
+    krb5_error_code      kerror = 0;
+    krb5_key_data      * key_data;
+    krb5_db_entry        db_entry;
+    krb5_boolean         more = 0;
+    int                  n = 0;
+
+    /* Open database */
+    /* krb5_dbm_db_init(context); */
+    if (kerror = krb5_dbm_db_open_database(context)) 
+        return(kerror);
+
+    /* get_principal */
+    if (kerror = krb5_dbm_db_get_principal(context, principal, &db_entry,
+                                          &n, &more)) {
+        krb5_dbm_db_close_database(context);
+        return(kerror);
+    }
+
+    /* match key */
+    krb5_dbm_db_get_mkey(context, id->ops, &master_key);
+    krb5_dbe_find_enctype(context, &db_entry, enctype, -1, kvno, &key_data);
+    if (kerror = krb5_dbekd_decrypt_key_data(context, master_key, key_data, 
+                                            &entry->key, NULL)) 
+       goto error;
+
+    if (kerror = krb5_copy_principal(context, principal, &entry->principal)) 
+       goto error;
+
+    /* Close database */
+error:;
+    krb5_dbe_free_contents(context, &db_entry);
+    krb5_dbm_db_close_database(context);
+    return(kerror);
+}
+