From: John Kohl Date: Wed, 25 Apr 1990 16:52:06 +0000 (+0000) Subject: *** empty log message *** X-Git-Tag: krb5-1.0-alpha2~817 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=1a5f98f7a7b8f36e85f6ce14aa7db70f85c3a5ae;p=krb5.git *** empty log message *** git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@579 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/lib/krb5/keytab/file/ktf_close.c b/src/lib/krb5/keytab/file/ktf_close.c new file mode 100644 index 000000000..c961e5bc5 --- /dev/null +++ b/src/lib/krb5/keytab/file/ktf_close.c @@ -0,0 +1,42 @@ +/* + * $Source$ + * $Author$ + * + * Copyright 1990 by the Massachusetts Institute of Technology. + * + * For copying and distribution information, please see the file + * . + * + * "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 +#include + +#include +#include + +#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 */ +} diff --git a/src/lib/krb5/keytab/file/ktf_get_en.c b/src/lib/krb5/keytab/file/ktf_get_en.c new file mode 100644 index 000000000..069bc67aa --- /dev/null +++ b/src/lib/krb5/keytab/file/ktf_get_en.c @@ -0,0 +1,50 @@ +/* + * $Source$ + * $Author$ + * + * Copyright 1990 by the Massachusetts Institute of Technology. + * + * For copying and distribution information, please see the file + * . + * + * 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 +#include + +#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 diff --git a/src/lib/krb5/keytab/file/ktf_get_na.c b/src/lib/krb5/keytab/file/ktf_get_na.c new file mode 100644 index 000000000..156e9c324 --- /dev/null +++ b/src/lib/krb5/keytab/file/ktf_get_na.c @@ -0,0 +1,37 @@ +/* + * $Source$ + * $Author$ + * + * Copyright 1990 by the Massachusetts Institute of Technology. + * + * For copying and distribution information, please see the file + * . + * + * 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 +#include + +#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 */ +} diff --git a/src/lib/krb5/keytab/file/ktf_ops.c b/src/lib/krb5/keytab/file/ktf_ops.c new file mode 100644 index 000000000..e63738273 --- /dev/null +++ b/src/lib/krb5/keytab/file/ktf_ops.c @@ -0,0 +1,34 @@ +/* + * $Source$ + * $Author$ + * + * Copyright 1990 by the Massachusetts Institute of Technology. + * + * For copying and distribution information, please see the file + * . + * + * krb5_ktf_ops + */ + +#if !defined(lint) && !defined(SABER) +static char rcsid_ktf_ops_c[] = +"$Id$"; +#endif /* !lint & !SABER */ + +#include +#include + +#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, +}; diff --git a/src/lib/krb5/keytab/file/ktf_resolv.c b/src/lib/krb5/keytab/file/ktf_resolv.c new file mode 100644 index 000000000..956133aab --- /dev/null +++ b/src/lib/krb5/keytab/file/ktf_resolv.c @@ -0,0 +1,47 @@ +/* + * $Source$ + * $Author$ + * + * Copyright 1990 by the Massachusetts Institute of Technology. + * + * For copying and distribution information, please see the file + * . + * + * 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 +#include + +#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 */ +} + diff --git a/src/lib/krb5/keytab/file/ktf_util.c b/src/lib/krb5/keytab/file/ktf_util.c new file mode 100644 index 000000000..aa615f5ff --- /dev/null +++ b/src/lib/krb5/keytab/file/ktf_util.c @@ -0,0 +1,48 @@ +/* + * $Source$ + * $Author$ + * + * Copyright 1990 by the Massachusetts Institute of Technology. + * + * For copying and distribution information, please see the file + * . + * + * 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 + +#include "ktfile.h" + diff --git a/src/lib/krb5/keytab/file/ktf_wops.c b/src/lib/krb5/keytab/file/ktf_wops.c new file mode 100644 index 000000000..3f657f83b --- /dev/null +++ b/src/lib/krb5/keytab/file/ktf_wops.c @@ -0,0 +1,34 @@ +/* + * $Source$ + * $Author$ + * + * Copyright 1990 by the Massachusetts Institute of Technology. + * + * For copying and distribution information, please see the file + * . + * + * krb5_ktf_writable_ops + */ + +#if !defined(lint) && !defined(SABER) +static char rcsid_ktf_wops_c[] = +"$Id$"; +#endif /* !lint & !SABER */ + +#include +#include + +#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, +}; diff --git a/src/lib/krb5/keytab/file/ktfile.h b/src/lib/krb5/keytab/file/ktfile.h new file mode 100644 index 000000000..09cf3c707 --- /dev/null +++ b/src/lib/krb5/keytab/file/ktfile.h @@ -0,0 +1,62 @@ +/* + * $Source$ + * $Author$ + * $Id$ + * + * Copyright 1990 by the Massachusetts Institute of Technology. + * + * For copying and distribution information, please see the file + * . + * + * This header file contains information needed by internal routines + * of the file-based ticket cache implementation. + */ + +#include + +#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__ */ diff --git a/src/lib/krb5/keytab/ktadd.c b/src/lib/krb5/keytab/ktadd.c new file mode 100644 index 000000000..89e9ce682 --- /dev/null +++ b/src/lib/krb5/keytab/ktadd.c @@ -0,0 +1,31 @@ +/* + * $Source$ + * $Author$ + * + * Copyright 1990 by the Massachusetts Institute of Technology. + * + * For copying and distribution information, please see the file + * . + * + * krb5_kt_add_entry() + */ + +#if !defined(lint) && !defined(SABER) +static char rcsid_ktadd_c[] = +"$Id$"; +#endif /* !lint & !SABER */ + +#include +#include +#include + +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; +} diff --git a/src/lib/krb5/keytab/ktdefault.c b/src/lib/krb5/keytab/ktdefault.c new file mode 100644 index 000000000..be38f24eb --- /dev/null +++ b/src/lib/krb5/keytab/ktdefault.c @@ -0,0 +1,29 @@ +/* + * $Source$ + * $Author$ + * + * Copyright 1990 by the Massachusetts Institute of Technology. + * + * For copying and distribution information, please see the file + * . + * + * Get a default keytab. + */ + +#if !defined(lint) && !defined(SABER) +static char rcsid_ktdefault_c [] = +"$Id$"; +#endif /* !lint & !SABER */ + +#include +#include +#include + +krb5_error_code krb5_kt_default(id) +krb5_keytab *id; +{ + return EOPNOTSUPP; +} + + + diff --git a/src/lib/krb5/keytab/ktfr_entry.c b/src/lib/krb5/keytab/ktfr_entry.c new file mode 100644 index 000000000..a5bb1de48 --- /dev/null +++ b/src/lib/krb5/keytab/ktfr_entry.c @@ -0,0 +1,28 @@ +/* + * $Source$ + * $Author$ + * + * Copyright 1990 by the Massachusetts Institute of Technology. + * + * For copying and distribution information, please see the file + * . + * + * krb5_kt_free_entry() + */ + +#if !defined(lint) && !defined(SABER) +static char rcsid_ktfr_entry_c[] = +"$Id$"; +#endif /* !lint & !SABER */ + +#include +#include + +krb5_error_code +krb5_kt_free_entry (entry) +krb5_keytab_entry *entry; +{ + krb5_free_principal(entry->principal); + krb5_free_keyblock(entry->key); + return 0; +} diff --git a/src/lib/krb5/keytab/ktremove.c b/src/lib/krb5/keytab/ktremove.c new file mode 100644 index 000000000..b8c0fd5c6 --- /dev/null +++ b/src/lib/krb5/keytab/ktremove.c @@ -0,0 +1,31 @@ +/* + * $Source$ + * $Author$ + * + * Copyright 1990 by the Massachusetts Institute of Technology. + * + * For copying and distribution information, please see the file + * . + * + * krb5_kt_remove_entry() + */ + +#if !defined(lint) && !defined(SABER) +static char rcsid_ktremove_c[] = +"$Id$"; +#endif /* !lint & !SABER */ + +#include +#include +#include + +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; +} diff --git a/src/lib/krb5/keytab/read_servi.c b/src/lib/krb5/keytab/read_servi.c new file mode 100644 index 000000000..8ecbae94d --- /dev/null +++ b/src/lib/krb5/keytab/read_servi.c @@ -0,0 +1,94 @@ +/* + * $Source$ + * $Author$ + * + * Copyright 1990 by the Massachusetts Institute of Technology. + * + * For copying and distribution information, please see the file + * . + * + * 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 +#include + +#include +#include +#include + +/* 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); +}