diff options
author | markm <markm@FreeBSD.org> | 1995-09-07 21:39:00 +0000 |
---|---|---|
committer | markm <markm@FreeBSD.org> | 1995-09-07 21:39:00 +0000 |
commit | 2539acf77b018acd7416a9857a14c466e55cd7e8 (patch) | |
tree | 96ff3578d62372822240f11a1567e45b880f3910 /eBones/lib/libkdb | |
parent | eed9438eb23b62f78af7685dc226228e2bf5c524 (diff) | |
download | FreeBSD-src-2539acf77b018acd7416a9857a14c466e55cd7e8.zip FreeBSD-src-2539acf77b018acd7416a9857a14c466e55cd7e8.tar.gz |
Major cleanup of eBones code:
- Get all functions prototyped or at least defined before use.
- Make code compile (Mostly) clean with -Wall set
- Start to reduce the degree to which DES aka libdes is built in.
- get all functions to the same uniform standard of definition:
int
foo(a, b)
int a;
int *b;
{
:
}
- fix numerous bugs exposed by above processes.
Note - this replaces the previous work which used an unpopular function
definition style.
Diffstat (limited to 'eBones/lib/libkdb')
-rw-r--r-- | eBones/lib/libkdb/krb_cache.c | 39 | ||||
-rw-r--r-- | eBones/lib/libkdb/krb_dbm.c | 169 | ||||
-rw-r--r-- | eBones/lib/libkdb/krb_kdb_utils.c | 59 | ||||
-rw-r--r-- | eBones/lib/libkdb/krb_lib.c | 22 | ||||
-rw-r--r-- | eBones/lib/libkdb/print_princ.c | 5 |
5 files changed, 194 insertions, 100 deletions
diff --git a/eBones/lib/libkdb/krb_cache.c b/eBones/lib/libkdb/krb_cache.c index 0dafb140..1c7c9ce 100644 --- a/eBones/lib/libkdb/krb_cache.c +++ b/eBones/lib/libkdb/krb_cache.c @@ -49,21 +49,21 @@ kerb_cache_init() */ int -kerb_cache_get_principal(char *serv, char *inst, Principal *principal, - unsigned int max) +kerb_cache_get_principal(serv, inst, principal, max) + char *serv; /* could have wild card */ + char *inst; /* could have wild card */ + Principal *principal; + unsigned int max; /* max number of name structs to return */ + { int found = 0; if (!init) kerb_cache_init(); #ifdef DEBUG - if (kerb_debug & 2) + if (kerb_debug & 2) { fprintf(stderr, "cache_get_principal for %s %s max = %d\n", serv, inst, max); -#endif DEBUG - -#ifdef DEBUG - if (kerb_debug & 2) { if (found) { fprintf(stderr, "cache get %s %s found %s %s\n", serv, inst, principal->name, principal->instance); @@ -82,7 +82,11 @@ kerb_cache_get_principal(char *serv, char *inst, Principal *principal, */ int -kerb_cache_put_principal(Principal *principal, unsigned int max) +kerb_cache_put_principal(principal, max) + Principal *principal; + unsigned int max; /* max number of principal structs to + * insert */ + { u_long i; int count = 0; @@ -115,7 +119,12 @@ kerb_cache_put_principal(Principal *principal, unsigned int max) */ int -kerb_cache_get_dba(char *serv, char *inst, Dba *dba, unsigned int max) +kerb_cache_get_dba(serv, inst, dba, max) + char *serv; /* could have wild card */ + char *inst; /* could have wild card */ + Dba *dba; + unsigned int max; /* max number of name structs to return */ + { int found = 0; @@ -123,13 +132,9 @@ kerb_cache_get_dba(char *serv, char *inst, Dba *dba, unsigned int max) kerb_cache_init(); #ifdef DEBUG - if (kerb_debug & 2) + if (kerb_debug & 2) { fprintf(stderr, "cache_get_dba for %s %s max = %d\n", serv, inst, max); -#endif - -#ifdef DEBUG - if (kerb_debug & 2) { if (found) { fprintf(stderr, "cache get %s %s found %s %s\n", serv, inst, dba->name, dba->instance); @@ -146,7 +151,10 @@ kerb_cache_get_dba(char *serv, char *inst, Dba *dba, unsigned int max) */ int -kerb_cache_put_dba(Dba *dba, unsigned int max) +kerb_cache_put_dba(dba, max) + Dba *dba; + unsigned int max; /* max number of dba structs to insert */ + { u_long i; int count = 0; @@ -170,3 +178,4 @@ kerb_cache_put_dba(Dba *dba, unsigned int max) } return count; } + diff --git a/eBones/lib/libkdb/krb_dbm.c b/eBones/lib/libkdb/krb_dbm.c index 68f428b..760bd6f 100644 --- a/eBones/lib/libkdb/krb_dbm.c +++ b/eBones/lib/libkdb/krb_dbm.c @@ -6,7 +6,7 @@ * from: krb_dbm.c,v 4.9 89/04/18 16:15:13 wesommer Exp $ * $Id: krb_dbm.c,v 1.4 1995/08/03 17:15:42 mark Exp $ */ - + #if 0 #ifndef lint static char rcsid[] = @@ -15,16 +15,16 @@ static char rcsid[] = #endif #if defined(__FreeBSD__) || defined(__NetBSD__) -#define NDBM_ +#define _NDBM_ #endif #if defined(__FreeBSD__) || defined(__NetBSD__) -#define DBM_ +#define _DBM_ #endif +#include <unistd.h> #include <stdio.h> #include <stdlib.h> -#include <unistd.h> #include <sys/types.h> #include <netinet/in.h> #include <sys/uio.h> @@ -35,17 +35,17 @@ static char rcsid[] = #include <strings.h> #include <des.h> #include <sys/file.h> -#ifdef NDBM_ +#ifdef _NDBM_ #include <ndbm.h> -#else /*NDBM_*/ +#else /*_NDBM_*/ #include <dbm.h> -#endif /*NDBM_*/ +#endif /*_NDBM_*/ /* before krb_db.h */ #include <krb.h> #include <krb_db.h> #ifdef dbm_pagfno -#define DBM_ +#define DB #endif #define KERB_DB_MAX_RETRY 5 @@ -56,14 +56,18 @@ extern long kerb_debug; extern char *progname; #endif -static init = 0; +static init = 0; static char default_db_name[] = DBM_FILE; static char *current_db_name = default_db_name; -static void encode_princ_key(), decode_princ_key(); -static void encode_princ_contents(), decode_princ_contents(); -static void kerb_dbl_fini(); -static int kerb_dbl_lock(); -static void kerb_dbl_unlock(); +static void encode_princ_key(datum *key, char *name, char *instance); +static void decode_princ_key(datum *key, char *name, char *instance); +static void encode_princ_contents(datum *contents, Principal *principal); +static void decode_princ_contents(datum *contents, Principal *principal); +static void kerb_dbl_fini(void); +static int kerb_dbl_lock(int mode); +static void kerb_dbl_unlock(void); +static long kerb_start_update(char *db_name); +static long kerb_end_update(char *db_name, long age); static struct timeval timestamp;/* current time of request */ static int non_blocking = 0; @@ -128,7 +132,7 @@ static int non_blocking = 0; * Instead, all routines call "dbm_next" instead. */ -#ifndef NDBM_ +#ifndef _NDBM_ typedef char DBM; #define dbm_open(file, flags, mode) ((dbminit(file) == 0)?"":((char *)0)) @@ -145,7 +149,9 @@ typedef char DBM; * Utility routine: generate name of database file. */ -static char *gen_dbsuffix(char *db_name, char *sfx) +static char *gen_dbsuffix(db_name, sfx) + char *db_name; + char *sfx; { char *dbsuffix; @@ -162,7 +168,8 @@ static char *gen_dbsuffix(char *db_name, char *sfx) * initialization for data base routines. */ -int kerb_db_init() +int +kerb_db_init() { init = 1; return (0); @@ -173,7 +180,8 @@ int kerb_db_init() * a kerb_db_init */ -void kerb_db_fini() +void +kerb_db_fini() { } @@ -184,7 +192,9 @@ void kerb_db_fini() * If the alternate database doesn't exist, nothing is changed. */ -int kerb_db_set_name(char *name) +int +kerb_db_set_name(name) + char *name; { DBM *db; @@ -203,7 +213,8 @@ int kerb_db_set_name(char *name) * Return the last modification time of the database. */ -long kerb_get_db_age() +long +kerb_get_db_age() { struct stat st; char *okname; @@ -228,7 +239,9 @@ long kerb_get_db_age() * the server (for example, during slave updates). */ -static long kerb_start_update(char *db_name) +static long +kerb_start_update(db_name) + char *db_name; { char *okname = gen_dbsuffix(db_name, ".ok"); long age = kerb_get_db_age(); @@ -241,7 +254,10 @@ static long kerb_start_update(char *db_name) return age; } -static long kerb_end_update(char *db_name, long age) +static long +kerb_end_update(db_name, age) + char *db_name; + long age; { int fd; int retval = 0; @@ -276,12 +292,15 @@ static long kerb_end_update(char *db_name, long age) return retval; } -static long kerb_start_read() +static long +kerb_start_read() { return kerb_get_db_age(); } -static long kerb_end_read(u_long age) +static long +kerb_end_read(age) + u_long age; { if (kerb_get_db_age() != age || age == -1) { return -1; @@ -293,12 +312,14 @@ static long kerb_end_read(u_long age) * Create the database, assuming it's not there. */ -int kerb_db_create(char *db_name) +int +kerb_db_create(db_name) + char *db_name; { char *okname = gen_dbsuffix(db_name, ".ok"); int fd; register int ret = 0; -#ifdef NDBM_ +#ifdef _NDBM_ DBM *db; db = dbm_open(db_name, O_RDWR|O_CREAT|O_EXCL, 0600); @@ -341,10 +362,12 @@ int kerb_db_create(char *db_name) * necessarily know to complete the transaction the rename, but... */ -int kerb_db_rename(char *from, char *to) +int +kerb_db_rename(from, to) + char *from; + char *to; { - int ok = 0; -#ifdef DBM_ +#ifdef _DBM_ char *fromdb = gen_dbsuffix (from, ".db"); char *todb = gen_dbsuffix (to, ".db"); #else @@ -355,8 +378,9 @@ int kerb_db_rename(char *from, char *to) #endif char *fromok = gen_dbsuffix(from, ".ok"); long trans = kerb_start_update(to); + int ok = 0; -#ifdef DBM_ +#ifdef _DBM_ if (rename (fromdb, todb) == 0) { #else if ((rename (fromdir, todir) == 0) @@ -367,7 +391,7 @@ int kerb_db_rename(char *from, char *to) } free (fromok); -#ifdef DBM_ +#ifdef _DBM_ free (fromdb); free (todb); #else @@ -385,15 +409,16 @@ int kerb_db_rename(char *from, char *to) /* * look up a principal in the data base returns number of principals * found , and whether there were more than requested. - char *name could have wild card - char *inst could have wild card - Principal *principal - unsigned int max max number of name structs to return - int *more where there more than 'max' tuples? */ -int kerb_db_get_principal(char *name, char *inst, Principal *principal, - unsigned int max, int *more) +int +kerb_db_get_principal(name, inst, principal, max, more) + char *name; /* could have wild card */ + char *inst; /* could have wild card */ + Principal *principal; + unsigned int max; /* max number of name structs to return */ + int *more; /* where there more than 'max' tuples? */ + { int found = 0, code; extern int errorproc(); @@ -491,7 +516,12 @@ int kerb_db_get_principal(char *name, char *inst, Principal *principal, * successfully updated. */ -int kerb_db_put_principal(Principal *principal, unsigned int max) +int +kerb_db_put_principal(principal, max) + Principal *principal; + unsigned int max; /* number of principal structs to + * update */ + { int found = 0, code; u_long i; @@ -536,7 +566,9 @@ int kerb_db_put_principal(Principal *principal, unsigned int max) } static void -encode_princ_key(datum *key, char *name, char *instance) +encode_princ_key(key, name, instance) + datum *key; + char *name, *instance; { static char keystring[ANAME_SZ + INST_SZ]; @@ -548,7 +580,9 @@ encode_princ_key(datum *key, char *name, char *instance) } static void -decode_princ_key(datum *key, char *name, char *instance) +decode_princ_key(key, name, instance) + datum *key; + char *name, *instance; { strncpy(name, key->dptr, ANAME_SZ); strncpy(instance, key->dptr + ANAME_SZ, INST_SZ); @@ -557,19 +591,25 @@ decode_princ_key(datum *key, char *name, char *instance) } static void -encode_princ_contents(datum *contents, Principal *principal) +encode_princ_contents(contents, principal) + datum *contents; + Principal *principal; { contents->dsize = sizeof(*principal); contents->dptr = (char *) principal; } static void -decode_princ_contents(datum *contents, Principal *principal) +decode_princ_contents(contents, principal) + datum *contents; + Principal *principal; { bcopy(contents->dptr, (char *) principal, sizeof(*principal)); } -void kerb_db_get_stat(DB_stat *s) +void +kerb_db_get_stat(s) + DB_stat *s; { gettimeofday(×tamp, NULL); @@ -587,11 +627,15 @@ void kerb_db_get_stat(DB_stat *s) /* update local copy too */ } -void kerb_db_put_stat(DB_stat *s) +void +kerb_db_put_stat(s) + DB_stat *s; { } -void delta_stat(DB_stat *a, DB_stat *b, DB_stat *c) +void +delta_stat(a, b, c) + DB_stat *a, *b, *c; { /* c = a - b then b = a for the next time */ @@ -614,14 +658,23 @@ void delta_stat(DB_stat *a, DB_stat *b, DB_stat *c) * whether there were more than requested. */ -int kerb_db_get_dba(char *dba_name, char *dba_inst, Dba *dba, unsigned int max, - int *more) +int +kerb_db_get_dba(dba_name, dba_inst, dba, max, more) + char *dba_name; /* could have wild card */ + char *dba_inst; /* could have wild card */ + Dba *dba; + unsigned int max; /* max number of name structs to return */ + int *more; /* where there more than 'max' tuples? */ + { *more = 0; return (0); } -int kerb_db_iterate (int (*func)(), char *arg) +int +kerb_db_iterate (func, arg) + int (*func)(); + char *arg; /* void *, really */ { datum key, contents; Principal *principal; @@ -650,7 +703,8 @@ static int dblfd = -1; static int mylock = 0; static int inited = 0; -static int kerb_dbl_init() +static void +kerb_dbl_init() { if (!inited) { char *filename = gen_dbsuffix (current_db_name, ".ok"); @@ -663,10 +717,10 @@ static int kerb_dbl_init() free(filename); inited++; } - return (0); } -static void kerb_dbl_fini() +static void +kerb_dbl_fini() { close(dblfd); dblfd = -1; @@ -674,7 +728,9 @@ static void kerb_dbl_fini() mylock = 0; } -static int kerb_dbl_lock(int mode) +static int +kerb_dbl_lock(mode) + int mode; { int flock_mode; @@ -706,7 +762,8 @@ static int kerb_dbl_lock(int mode) return 0; } -static void kerb_dbl_unlock() +static void +kerb_dbl_unlock() { if (!mylock) { /* lock already unlocked */ fprintf(stderr, "Kerberos database lock not locked when unlocking.\n"); @@ -722,7 +779,9 @@ static void kerb_dbl_unlock() mylock = 0; } -int kerb_db_set_lockmode(int mode) +int +kerb_db_set_lockmode(mode) + int mode; { int old = non_blocking; non_blocking = mode; diff --git a/eBones/lib/libkdb/krb_kdb_utils.c b/eBones/lib/libkdb/krb_kdb_utils.c index 275cc39..0256348 100644 --- a/eBones/lib/libkdb/krb_kdb_utils.c +++ b/eBones/lib/libkdb/krb_kdb_utils.c @@ -20,17 +20,20 @@ static char rcsid[] = #endif lint #endif +#include <des.h> +#include <krb.h> +#include <krb_db.h> +#include <kdc.h> #include <stdio.h> -#include <stdlib.h> #include <unistd.h> #include <string.h> #include <sys/file.h> -#include <krb.h> -#include <krb_db.h> -#include <kdc.h> -long kdb_get_master_key(int prompt, C_Block master_key, - Key_schedule master_key_sched) +long +kdb_get_master_key(prompt, master_key, master_key_sched) + int prompt; + C_Block master_key; + Key_schedule master_key_sched; { int kfile; @@ -39,7 +42,7 @@ long kdb_get_master_key(int prompt, C_Block master_key, placebo_read_password(master_key, "\nEnter Kerberos master key: ", 0); #else - des_read_password((C_Block *)master_key, + des_read_password((des_cblock *)master_key, "\nEnter Kerberos master key: ", 0); #endif printf ("\n"); @@ -57,33 +60,21 @@ long kdb_get_master_key(int prompt, C_Block master_key, } #ifndef NOENCRYPTION - key_sched((C_Block *)master_key,master_key_sched); + key_sched((des_cblock *)master_key,master_key_sched); #endif return (0); } -/* The old algorithm used the key schedule as the initial vector which - was byte order depedent ... */ - -void kdb_encrypt_key (C_Block in, C_Block out, C_Block master_key, - Key_schedule master_key_sched, int e_d_flag) -{ - -#ifdef NOENCRYPTION - bcopy(in, out, sizeof(C_Block)); -#else - pcbc_encrypt((C_Block *)in,(C_Block *)out,(long)sizeof(C_Block), - master_key_sched,(C_Block *)master_key, e_d_flag); -#endif -} - /* The caller is reasponsible for cleaning up the master key and sched, even if we can't verify the master key */ /* Returns master key version if successful, otherwise -1 */ -long kdb_verify_master_key (C_Block master_key, Key_schedule master_key_sched, - FILE *out) +long +kdb_verify_master_key (master_key, master_key_sched, out) + C_Block master_key; + Key_schedule master_key_sched; + FILE *out; /* setting this to non-null be do output */ { C_Block key_from_db; Principal principal_data[1]; @@ -137,3 +128,21 @@ long kdb_verify_master_key (C_Block master_key, Key_schedule master_key_sched, return (master_key_version); } + +/* The old algorithm used the key schedule as the initial vector which + was byte order depedent ... */ + +void +kdb_encrypt_key (in, out, master_key, master_key_sched, e_d_flag) + C_Block in, out, master_key; + Key_schedule master_key_sched; + int e_d_flag; +{ + +#ifdef NOENCRYPTION + bcopy(in, out, sizeof(C_Block)); +#else + pcbc_encrypt((des_cblock*)in,(des_cblock*)out,(long)sizeof(C_Block), + master_key_sched,(des_cblock*)master_key,e_d_flag); +#endif +} diff --git a/eBones/lib/libkdb/krb_lib.c b/eBones/lib/libkdb/krb_lib.c index 5610dbb..2cf4fb8 100644 --- a/eBones/lib/libkdb/krb_lib.c +++ b/eBones/lib/libkdb/krb_lib.c @@ -78,8 +78,13 @@ kerb_fini() */ int -kerb_get_principal(char *name, char *inst, Principal *principal, - unsigned int max, int *more) +kerb_get_principal(name, inst, principal, max, more) + char *name; /* could have wild card */ + char *inst; /* could have wild card */ + Principal *principal; + unsigned int max; /* max number of name structs to return */ + int *more; /* more tuples than room for */ + { int found = 0; #ifdef CACHE @@ -131,7 +136,10 @@ kerb_get_principal(char *name, char *inst, Principal *principal, } /* principals */ -int kerb_put_principal(Principal *principal, unsigned int n) +int +kerb_put_principal(principal, n) + Principal *principal; + unsigned int n; /* number of principal structs to write */ { long time(); struct tm *tp, *localtime(); @@ -176,7 +184,13 @@ int kerb_put_principal(Principal *principal, unsigned int n) } int -kerb_get_dba(char *name, char *inst, Dba *dba, unsigned int max, int *more) +kerb_get_dba(name, inst, dba, max, more) + char *name; /* could have wild card */ + char *inst; /* could have wild card */ + Dba *dba; + unsigned int max; /* max number of name structs to return */ + int *more; /* more tuples than room for */ + { int found = 0; #ifdef CACHE diff --git a/eBones/lib/libkdb/print_princ.c b/eBones/lib/libkdb/print_princ.c index b1d1ca9..64e9106 100644 --- a/eBones/lib/libkdb/print_princ.c +++ b/eBones/lib/libkdb/print_princ.c @@ -15,6 +15,7 @@ static char rcsid[] = #endif #include <stdio.h> +#include <time.h> #include <sys/types.h> #include <sys/time.h> #include <strings.h> @@ -26,7 +27,9 @@ extern int debug; long kerb_debug; static struct tm *time_p; -void krb_print_principal(Principal *a_n) +void +krb_print_principal(a_n) + Principal *a_n; { /* run-time database does not contain string versions */ time_p = localtime(&(a_n->exp_date)); |