--- /dev/null
+/*
+ * $Source$
+ * $Author$
+ *
+ * Copyright 1990 by the Massachusetts Institute of Technology.
+ *
+ * For copying and distribution information, please see the file
+ * <krb5/mit-copyright.h>.
+ *
+ * "Close" a file-based keytab and invalidate the id. This means
+ * free memory hidden in the structures.
+ */
+
+#if !defined(lint) && !defined(SABER)
+static char rcsid_krb5_ktfile_close_c[] =
+"$Id$";
+#endif /* !lint & !SABER */
+
+#include <krb5/copyright.h>
+#include <krb5/krb5.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "ktfile.h"
+
+krb5_error_code
+krb5_ktfile_close(id)
+ krb5_keytab *id;
+ /*
+ * This routine is responsible for freeing all memory allocated
+ * for this keytab. There are no system resources that need
+ * to be freed nor are there any open files.
+ *
+ * This routine should undo anything done by krb5_ktfile_resolve().
+ */
+{
+ (void) free(KTFILENAME(*id));
+ (void) free((krb5_pointer)(*id)->data);
+ *id = NULL;
+ return (0); /* XXX */
+}
--- /dev/null
+/*
+ * $Source$
+ * $Author$
+ *
+ * Copyright 1990 by the Massachusetts Institute of Technology.
+ *
+ * For copying and distribution information, please see the file
+ * <krb5/mit-copyright.h>.
+ *
+ * This is the get_entry routine for the file based keytab implementation.
+ * It opens the keytab file, and either retrieves the entry or returns
+ * an error.
+ */
+
+#if !defined(lint) && !defined(SABER)
+static char rcsid_krb5_ktfile_get_entry_c[] =
+"$Id$";
+#endif /* !lint & !SABER */
+
+#include <krb5/copyright.h>
+#include <krb5/krb5.h>
+
+#include "ktfile.h"
+
+krb5_error_code
+krb5_ktfile_get_entry(id, principal, kvno, entry)
+ krb5_keytab id;
+ krb5_principal principal;
+ krb5_kvno kvno;
+ krb5_keytab_entry *entry;
+{
+ krb5_keytab_entry cur_entry;
+ krb5_error_code kerror = 0; /* XXX */
+
+ bzero((char *)&cur_entry, sizeof(krb5_keytab_entry));
+
+ /* Open the keyfile for reading */
+ if (kerror = krb5_ktfileint_openr(id))
+ return(kerror); /* XXX */
+
+ /*
+ * For efficiency and simplicity, we'll use a while true that
+ * is exited with a break statement.
+ */
+ while (TRUE) {
+ if (kerror = krb5_ktfileint_read_entry(id, &entry))
+ break;
+
+ if (((kvno == IGNORE_VNO) || (kvno == entry.kvno)) &&
+ (principal XXXXX here XXXXX
--- /dev/null
+/*
+ * $Source$
+ * $Author$
+ *
+ * Copyright 1990 by the Massachusetts Institute of Technology.
+ *
+ * For copying and distribution information, please see the file
+ * <krb5/mit-copyright.h>.
+ *
+ * Get the name of the file containing a file-based keytab.
+ */
+
+#if !defined(lint) && !defined(SABER)
+static char krb5_ktfile_get_name_c[] =
+"$Id$";
+#endif /* !lint & !SABER */
+
+#include <krb5/copyright.h>
+#include <krb5/krb5.h>
+
+#include "ktfile.h"
+
+krb5_error_code
+krb5_ktfile_get_name(id, name, len)
+ krb5_keytab id;
+ char *name;
+ int len;
+ /*
+ * This routine returns the name of the name of the file associated with
+ * this file-based keytab. name is zeroed and the filename is truncated
+ * to fit in name if necessary.
+ */
+{
+ bzero(name, len);
+ strncpy(name, KTFILENAME(id), len);
+ return(0); /* XXX */
+}
--- /dev/null
+/*
+ * $Source$
+ * $Author$
+ *
+ * Copyright 1990 by the Massachusetts Institute of Technology.
+ *
+ * For copying and distribution information, please see the file
+ * <krb5/copyright.h>.
+ *
+ * krb5_ktf_ops
+ */
+
+#if !defined(lint) && !defined(SABER)
+static char rcsid_ktf_ops_c[] =
+"$Id$";
+#endif /* !lint & !SABER */
+
+#include <krb5/copyright.h>
+#include <krb5/krb5.h>
+
+#include "ktfile.h"
+
+struct _krb5_kt_ops krb5_ktf_ops = {
+ "FILE", /* Prefix -- this string should not appear anywhere else! */
+ krb5_ktfile_resolve,
+ krb5_ktfile_get_name,
+ krb5_ktfile_close,
+ krb5_ktfile_get,
+ krb5_ktfile_start_seq_get,
+ krb5_ktfile_get_next,
+ krb5_ktfile_end_get,
+ 0,
+ 0,
+};
--- /dev/null
+/*
+ * $Source$
+ * $Author$
+ *
+ * Copyright 1990 by the Massachusetts Institute of Technology.
+ *
+ * For copying and distribution information, please see the file
+ * <krb5/mit-copyright.h>.
+ *
+ * This is an implementation specific resolver. It returns a keytab id
+ * initialized with file keytab routines.
+ */
+
+#if !defined(lint) && !defined(SABER)
+static char krb5_ktfile_resolve_c[] =
+"$Id$";
+#endif /* !lint & !SABER */
+
+#include <krb5/copyright.h>
+#include <krb5/krb5.h>
+
+#include "ktfile.h"
+
+krb5_error_code
+krb5_ktfile_resolve(name, id)
+ char *name;
+ krb5_keytab *id;
+{
+ krb5_ktfile_data *data;
+
+ if ((*id = malloc(sizeof(struct _krb5_kt))) == NULL)
+ return(KRB5_NO_MEMORY); /* XXX */
+
+ (*id)->ops = &krb5_ktf_ops;
+ if ((data = (krb5_ktfile_data *)malloc(sizeof(krb5_ktfile_data))) == NULL)
+ return(KRB5_NO_MEMORY); /* XXX */
+
+ if ((data->name = (char *)calloc(strlen(name) + 1, sizeof(char))) == NULL)
+ return(KRB5_NO_MEMORY); /* XXX */
+
+ (void) strcpy(data->name, name);
+
+ id->data = (krb5_pointer)data;
+
+ return(0); /* XXX */
+}
+
--- /dev/null
+/*
+ * $Source$
+ * $Author$
+ *
+ * Copyright 1990 by the Massachusetts Institute of Technology.
+ *
+ * For copying and distribution information, please see the file
+ * <krb5/mit-copyright.h>.
+ *
+ * This function contains utilities for the file based implementation of
+ * the keytab. There are no public functions in this file.
+ *
+ * This file is the only one that has knowledge of the format of a
+ * keytab file.
+ *
+ * The format is as follows:
+ *
+ * principal vno key
+ * principal vno key
+ * ....
+ *
+ * There are no separators between fields of an entry or between entries.
+ * A principal is a length-encoded array of length-encoded strings. The
+ * length is a krb5_length XXX in each case. The specific format, then, is
+ * multiple entries concatinated with no separators. An entry has this
+ * exact format:
+ *
+ * sizeof(krb5_length) bytes for number of components in the principal;
+ * then, each component listed in ordser.
+ * For each component, sizeof(krb5_length) bytes for the number of bytes
+ * in the component, followed by the component.
+ * sizeof(krb5_kvno) bytes for the key version number
+ * sizeof(krb5_key_block) bytes for the key
+ *
+ * Extra garbage at the end of a keytab will be not be searched for, but
+ *
+ *
+ */
+
+#if !defined(lint) && !defined(SABER)
+static char rcsid_ktf_util_c[] =
+"$Id$";
+#endif /* !lint & !SABER */
+
+#include <krb5/copyright.h>
+
+#include "ktfile.h"
+
--- /dev/null
+/*
+ * $Source$
+ * $Author$
+ *
+ * Copyright 1990 by the Massachusetts Institute of Technology.
+ *
+ * For copying and distribution information, please see the file
+ * <krb5/copyright.h>.
+ *
+ * krb5_ktf_writable_ops
+ */
+
+#if !defined(lint) && !defined(SABER)
+static char rcsid_ktf_wops_c[] =
+"$Id$";
+#endif /* !lint & !SABER */
+
+#include <krb5/copyright.h>
+#include <krb5/krb5.h>
+
+#include "ktfile.h"
+
+struct _krb5_kt_ops krb5_ktf_writable_ops = {
+ "WRFILE", /* Prefix -- this string should not appear anywhere else! */
+ krb5_ktfile_resolve,
+ krb5_ktfile_get_name,
+ krb5_ktfile_close,
+ krb5_ktfile_get,
+ krb5_ktfile_start_seq_get,
+ krb5_ktfile_get_next,
+ krb5_ktfile_end_get,
+ krb5_ktfile_add,
+ krb5_ktfile_remove,
+};
--- /dev/null
+/*
+ * $Source$
+ * $Author$
+ * $Id$
+ *
+ * Copyright 1990 by the Massachusetts Institute of Technology.
+ *
+ * For copying and distribution information, please see the file
+ * <krb5/mit-copyright.h>.
+ *
+ * This header file contains information needed by internal routines
+ * of the file-based ticket cache implementation.
+ */
+
+#include <krb5/copyright.h>
+
+#ifndef __KTFILE__
+#define __KTFILE__
+
+/*
+ * Constants
+ */
+#define IGNORE_VNO 0
+
+
+/*
+ * Types
+ */
+typedef struct _krb5_ktfile_data {
+ char *name; /* Name of the file */
+} krb5_ktfile_data;
+
+/*
+ * Macros
+ */
+#define KTFILENAME(id) (((krb5_ktfile_data *)(id)->data)->name)
+
+extern struct _krb5_kt_ops krb5_ktf_ops;
+krb5_error_code krb5_ktfile_resolve PROTOTYPE((char *,
+ krb5_keytab *));
+krb5_error_code krb5_ktfile_get_name PROTOTYPE((krb5_keytab,
+ char *,
+ int));
+krb5_error_code krb5_ktfile_close PROTOTYPE((krb5_keytab));
+krb5_error_code krb5_ktfile_get PROTOTYPE((krb5_keytab,
+ krb5_principal,
+ krb5_kvno,
+ krb5_keytab_entry *));
+krb5_error_code krb5_ktfile_start_seq_get PROTOTYPE((krb5_keytab,
+ krb5_kt_cursor *));
+krb5_error_code krb5_ktfile_get_next PROTOTYPE((krb5_keytab,
+ krb5_keytab_entry *,
+ krb5_kt_cursor));
+krb5_error_code krb5_ktfile_end_get PROTOTYPE((krb5_keytab,
+ krb5_kt_cursor));
+/* routines to be included on extended version (write routines) */
+krb5_error_code krb5_ktfile_add PROTOTYPE((krb5_keytab,
+ krb5_keytab_entry *));
+krb5_error_code krb5_ktfile_remove PROTOTYPE((krb5_keytab,
+ krb5_keytab_entry *));
+
+#endif /* __KTFILE__ */
--- /dev/null
+/*
+ * $Source$
+ * $Author$
+ *
+ * Copyright 1990 by the Massachusetts Institute of Technology.
+ *
+ * For copying and distribution information, please see the file
+ * <krb5/copyright.h>.
+ *
+ * krb5_kt_add_entry()
+ */
+
+#if !defined(lint) && !defined(SABER)
+static char rcsid_ktadd_c[] =
+"$Id$";
+#endif /* !lint & !SABER */
+
+#include <krb5/copyright.h>
+#include <krb5/krb5.h>
+#include <krb5/krb5_err.h>
+
+krb5_error_code
+krb5_kt_add_entry (id, entry)
+krb5_keytab id;
+krb5_keytab_entry *entry;
+{
+ if (id->ops->add)
+ return (*id->ops->add)(id, entry);
+ else
+ return KRB5_KT_NOWRITE;
+}
--- /dev/null
+/*
+ * $Source$
+ * $Author$
+ *
+ * Copyright 1990 by the Massachusetts Institute of Technology.
+ *
+ * For copying and distribution information, please see the file
+ * <krb5/copyright.h>.
+ *
+ * Get a default keytab.
+ */
+
+#if !defined(lint) && !defined(SABER)
+static char rcsid_ktdefault_c [] =
+"$Id$";
+#endif /* !lint & !SABER */
+
+#include <krb5/copyright.h>
+#include <krb5/krb5.h>
+#include <errno.h>
+
+krb5_error_code krb5_kt_default(id)
+krb5_keytab *id;
+{
+ return EOPNOTSUPP;
+}
+
+
+
--- /dev/null
+/*
+ * $Source$
+ * $Author$
+ *
+ * Copyright 1990 by the Massachusetts Institute of Technology.
+ *
+ * For copying and distribution information, please see the file
+ * <krb5/copyright.h>.
+ *
+ * krb5_kt_free_entry()
+ */
+
+#if !defined(lint) && !defined(SABER)
+static char rcsid_ktfr_entry_c[] =
+"$Id$";
+#endif /* !lint & !SABER */
+
+#include <krb5/copyright.h>
+#include <krb5/krb5.h>
+
+krb5_error_code
+krb5_kt_free_entry (entry)
+krb5_keytab_entry *entry;
+{
+ krb5_free_principal(entry->principal);
+ krb5_free_keyblock(entry->key);
+ return 0;
+}
--- /dev/null
+/*
+ * $Source$
+ * $Author$
+ *
+ * Copyright 1990 by the Massachusetts Institute of Technology.
+ *
+ * For copying and distribution information, please see the file
+ * <krb5/copyright.h>.
+ *
+ * krb5_kt_remove_entry()
+ */
+
+#if !defined(lint) && !defined(SABER)
+static char rcsid_ktremove_c[] =
+"$Id$";
+#endif /* !lint & !SABER */
+
+#include <krb5/copyright.h>
+#include <krb5/krb5.h>
+#include <krb5/krb5_err.h>
+
+krb5_error_code
+krb5_kt_remove_entry (id, entry)
+krb5_keytab id;
+krb5_keytab_entry *entry;
+{
+ if (id->ops->remove)
+ return (*id->ops->remove)(id, entry);
+ else
+ return KRB5_KT_NOWRITE;
+}
--- /dev/null
+/*
+ * $Source$
+ * $Author$
+ *
+ * Copyright 1990 by the Massachusetts Institute of Technology.
+ *
+ * For copying and distribution information, please see the file
+ * <krb5/mit-copyright.h>.
+ *
+ * This routine is designed to be passed to krb5_rd_req.
+ * It is a convenience function that reads a key out of a keytab.
+ * It handles all of the opening and closing of the keytab
+ * internally.
+ */
+
+#if !defined(lint) && !defined(SABER)
+static char rcsid_krb5_kt_read_service_key_c[] =
+"$Id$";
+#endif /* !lint & !SABER */
+
+#include <krb5/copyright.h>
+#include <krb5/krb5.h>
+
+#include <krb5/ext-proto.h>
+#include <errno.h>
+#include <stdio.h>
+
+/* XXX Things that I need and don't know where to get yet */
+#define KSUCCESS 0
+
+krb5_error_code
+krb5_kt_read_service_key(DECLARG(krb5_pointer, keyprocarg),
+ DECLARG(krb5_principal, principal),
+ DECLARG(krb5_kvno, vno),
+ DECLARG(krb5_keyblock **, key))
+OLDDECLARG(krb5_pointer, keyprocarg)
+OLDDECLARG(krb5_principal, principal)
+OLDDECLARG(krb5_kvno, vno)
+OLDDECLARG(krb5_keyblock **, key)
+/*
+ effects: If keyprocarg is not NULL, it is taken to be
+ the name of a keytab. Otherwise, the default
+ keytab will be used. This routine opens the
+ keytab and finds the principal associated with
+ principal and vno, returning the resulting key
+ in *key or returning an error code if it is not
+ found.
+ returns: nothing
+ errors: error code if not found
+*/
+{
+ krb5_error_code kerror = KSUCCESS;
+ char keytabname[MAX_KEYTAB_NAME_LEN + 1]; /* + 1 for NULL termination */
+ krb5_keytab id;
+ krb5_keytab_entry entry;
+
+ /*
+ * Get the name of the file that we should use.
+ */
+ if (keyprocarg == NULL)
+ if ((kerror = krb5_kt_default_name((char *)keytabname,
+ sizeof(keytabname) - 1))!= KSUCCESS)
+ return (kerror);
+ else {
+ bzero(keytabname, sizeof(keytabname));
+ (void) strncpy(keytabname, (char *)keyprocarg,
+ sizeof(keytabname) - 1);
+ }
+
+ if (kerror = krb5_kt_resolve((char *)keytabname, &id))
+ return (kerror);
+
+ kerror = krb5_kt_get_entry(id, principal, vno, &entry);
+ krb5_kt_close(id);
+
+ if (kerror)
+ return(kerror);
+
+ /*
+ * This routine takes a krb5_keyblock **. Should it? I assume this
+ * means that it is supposed allocate the key and return it...
+ * XXX
+ */
+
+ if ((*key = (krb5_keyblock *)malloc(sizeof(krb5_keyblock))) == NULL)
+ return (ENOMEM); /* XXX */
+
+ krb5_copy_keyblock(entry.key, *key);
+
+ /* Zero the memory containing the key */
+ bzero((char *)&entry, sizeof(krb5_keytab_entry));
+
+ return (KSUCCESS);
+}