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/krb_dbm.c | |
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/krb_dbm.c')
-rw-r--r-- | eBones/lib/libkdb/krb_dbm.c | 169 |
1 files changed, 114 insertions, 55 deletions
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; |