static krb5_error_code krb5_dbm_db_end_update
PROTOTYPE((krb5_context));
-#ifdef BERK_DB_DBM
-/*
- * This module contains all of the code which directly interfaces to
- * the underlying representation of the Kerberos database; this
- * implementation uses a Berkeley hashed database file to store the
- * relations, plus a second file as a semaphore to allow the database
- * to be replaced out from underneath the KDC server.
- */
-extern DBM *db_dbm_open PROTOTYPE((char *, int, int));
-extern void db_dbm_close PROTOTYPE((DBM *));
-extern datum db_dbm_fetch PROTOTYPE((DBM *, datum));
-extern datum db_dbm_firstkey PROTOTYPE((DBM *));
-extern datum db_dbm_nextkey PROTOTYPE((DBM *));
-extern int db_dbm_delete PROTOTYPE((DBM *, datum));
-extern int db_dbm_store PROTOTYPE((DBM *, datum, datum, int));
-extern int db_dbm_error PROTOTYPE((DBM *));
-extern int db_dbm_clearerr PROTOTYPE((DBM *));
-extern int db_dbm_dirfno PROTOTYPE((DBM *));
-
-static kdb5_dispatch_table kdb5_default_dispatch = {
- "Berkeley Hashed Database",
- ".db", /* Index file name ext */
- (char *) NULL, /* Data file name ext */
- ".ok", /* Lock file name ext */
- db_dbm_open, /* Open Database */
- db_dbm_close, /* Close Database */
- db_dbm_fetch, /* Fetch Key */
- db_dbm_firstkey, /* Fetch First Key */
- db_dbm_nextkey, /* Fetch Next Key */
- db_dbm_delete, /* Delete Key */
- db_dbm_store, /* Store Key */
- db_dbm_error, /* Get Database Error */
- db_dbm_clearerr, /* Clear Database Error */
- db_dbm_dirfno, /* Get DB index FD num */
- (int (*)()) NULL /* Get DB data FD num */
-};
-#else /* BERK_DB_DBM */
-/*
- * The following prototypes are necessary in case dbm_error and
- * dbm_clearerr are in the library but not prototyped
- * (e.g. NetBSD-1.0)
- */
-#if defined(MISSING_ERROR_PROTO) && !defined(dbm_error)
-int dbm_error PROTOTYPE((DBM *));
-#endif
-#if defined(MISSING_CLEARERR_PROTO) && !defined(dbm_clearerr)
-int dbm_clearerr PROTOTYPE((DBM *));
-#endif
-
/*
* This module contains all of the code which directly interfaces to
* the underlying representation of the Kerberos database; this
* from underneath the KDC server.
*/
static kdb5_dispatch_table kdb5_default_dispatch = {
- "Stock [N]DBM Database",
- ".dir", /* Index file name ext */
- ".pag", /* Data file name ext */
+ "Berkeley Hashed Database w/ DBM interface",
+ ".db", /* Index file name ext */
+ (char *) NULL, /* Data file name ext */
".ok", /* Lock file name ext */
dbm_open, /* Open Database */
dbm_close, /* Close Database */
* The following are #ifdef'd because they have the potential to be
* macros rather than functions.
*/
-#ifdef dbm_error
- (int (*)()) NULL, /* Get Database Error */
-#else /* dbm_error */
- dbm_error, /* Get Database Error */
-#endif /* dbm_error */
-#ifdef dbm_clearerr
- (int (*)()) NULL, /* Clear Database Error */
-#else /* dbm_clearerr */
- dbm_clearerr, /* Clear Database Error */
-#endif /* dbm_clearerr */
(int (*)()) NULL, /* Get DB index FD num */
(int (*)()) NULL, /* Get DB data FD num */
};
-#endif /* BERK_DB_DBM */
/*
* These macros dispatch via the dispatch table.
#define KDBM_STORE(dbc, db, key, c, f) ((*(((krb5_db_context *)dbc)-> \
db_dispatch->kdb5_dbm_store)) \
(db, key, c, f))
-#define KDBM_ERROR(dbc, db) ((((krb5_db_context *)dbc)-> \
- db_dispatch->kdb5_dbm_error) ? \
- ((*(((krb5_db_context *)dbc)-> \
- db_dispatch->kdb5_dbm_error)) \
- (db)) : \
- dbm_error(db))
-#define KDBM_CLEARERR(dbc, db) ((((krb5_db_context *)dbc)-> \
- db_dispatch->kdb5_dbm_clearerr) ? \
- ((*(((krb5_db_context *)dbc)-> \
- db_dispatch->kdb5_dbm_clearerr)) \
- (db)) : \
- dbm_clearerr(db))
#define KDBM_INDEX_EXT(dbc) (((krb5_db_context *)dbc)-> \
db_dispatch->kdb5_db_index_ext)
#define KDBM_DATA_EXT(dbc) (((krb5_db_context *)dbc)-> \
krb5_db_context * db_ctx;
if (context->db_context == NULL) {
- if (db_ctx = (krb5_db_context *) malloc(sizeof(krb5_db_context))) {
+ if ((db_ctx = (krb5_db_context *) malloc(sizeof(krb5_db_context)))) {
memset((char *) db_ctx, 0, sizeof(krb5_db_context));
k5dbm_clear_context((krb5_db_context *)db_ctx);
context->db_context = (void *) db_ctx;
#define KDB5_DISPATCH
#include "k5-int.h"
+#include <ctype.h>
#include <sys/time.h>
+#include <sys/wait.h>
+#include "com_err.h"
#if HAVE_SRAND48
#define RAND() lrand48()
krb5_context kcontext;
int nentries;
{
- if (recorded_principals = (krb5_principal *)
- malloc(nentries * sizeof(krb5_principal)))
- memset((char *) recorded_principals, 0,
- nentries * sizeof(krb5_principal));
- if (recorded_names = (char **) malloc(nentries * sizeof(char *)))
- memset((char *) recorded_names, 0, nentries * sizeof(char *));
+ recorded_principals = (krb5_principal *)
+ malloc(nentries * sizeof(krb5_principal));
+ if (!recorded_principals)
+ abort();
+ memset((char *) recorded_principals, 0,
+ nentries * sizeof(krb5_principal));
+ recorded_names = (char **) malloc(nentries * sizeof(char *));
+ if (!recorded_names)
+ abort();
+ memset((char *) recorded_names, 0, nentries * sizeof(char *));
}
/*
{
krb5_error_code kret;
krb5_db_entry dbent;
- krb5_tl_mod_princ mod_princ;
krb5_keyblock * rkey = NULL;
+ krb5_timestamp timenow;
int nentries = 1;
memset((char *) &dbent, 0, sizeof(dbent));
dbent.expiration = KRB5_KDB_EXPIRATION;
dbent.max_renewable_life = KRB5_KDB_MAX_RLIFE;
- if (kret = krb5_copy_principal(kcontext, principal, &dbent.princ))
+ if ((kret = krb5_copy_principal(kcontext, principal, &dbent.princ)))
goto out;
- mod_princ.mod_princ = principal;
- if (kret = krb5_timeofday(kcontext, &mod_princ.mod_date))
- goto out;
- if (kret = krb5_dbe_encode_mod_princ_data(kcontext, &mod_princ, &dbent))
+ if ((kret = krb5_timeofday(kcontext, &timenow)))
goto out;
+ if ((kret = krb5_dbe_update_mod_princ_data(kcontext, &dbent,
+ timenow, principal)))
+ goto out;
if (!key) {
- if (kret = krb5_random_key(kcontext, eblock, rseed, &rkey))
+ if ((kret = krb5_random_key(kcontext, eblock, rseed, &rkey)))
goto out;
} else
rkey = key;
- if (kret = krb5_dbe_create_key_data(kcontext, &dbent))
+ if ((kret = krb5_dbe_create_key_data(kcontext, &dbent)))
goto out;
- if (kret = krb5_dbekd_encrypt_key_data(kcontext, eblock, rkey, NULL, 1,
- &dbent.key_data[0]))
+ if ((kret = krb5_dbekd_encrypt_key_data(kcontext, eblock, rkey, NULL, 1,
+ &dbent.key_data[0])))
goto out;
if (!key)
{
krb5_error_code kret;
krb5_db_entry dbent;
- krb5_tl_mod_princ * mod_princ;
+ krb5_principal mod_princ;
+ krb5_timestamp mod_time;
int how_many;
krb5_boolean more;
more = 0;
how_many = 1;
- if (kret = krb5_db_get_principal(kcontext, principal, &dbent,
- &how_many, &more))
+ if ((kret = krb5_db_get_principal(kcontext, principal, &dbent,
+ &how_many, &more)))
return(kret);
if (how_many == 0)
return(KRB5_KDB_NOENTRY);
- if (kret = krb5_dbe_decode_mod_princ_data(kcontext, &dbent, &mod_princ)) {
- krb5_db_free_principal(kcontext, &dbent, how_many);
- return(kret);
- }
+ if ((kret = krb5_dbe_lookup_mod_princ_data(kcontext, &dbent,
+ &mod_time, &mod_princ)))
+ return(kret);
+
if (docompare) {
if ((dbent.max_life != KRB5_KDB_MAX_LIFE) ||
(dbent.max_renewable_life != KRB5_KDB_MAX_RLIFE) ||
(dbent.expiration != KRB5_KDB_EXPIRATION) ||
(dbent.attributes != KRB5_KDB_DEF_FLAGS) ||
!krb5_principal_compare(kcontext, principal, dbent.princ) ||
- !krb5_principal_compare(kcontext, principal, mod_princ->mod_princ))
+ !krb5_principal_compare(kcontext, principal, mod_princ))
kret = KRB5_PRINC_NOMATCH;
}
krb5_db_free_principal(kcontext, &dbent, how_many);
- krb5_free_principal(kcontext, mod_princ->mod_princ);
- krb5_xfree(mod_princ);
+ krb5_free_principal(kcontext, mod_princ);
if (!kret)
return(((how_many == 1) && (more == 0)) ? 0 : KRB5KRB_ERR_GENERIC);
else
int num2delete;
num2delete = 1;
- if (kret = krb5_db_delete_principal(kcontext,
- principal,
- &num2delete))
+ if ((kret = krb5_db_delete_principal(kcontext, principal, &num2delete)))
return(kret);
return((num2delete == 1) ? 0 : KRB5KRB_ERR_GENERIC);
}
static int
do_testing(db, passes, verbose, timing, rcases, check, save_db, dontclean,
- db_type, ptest)
+ ptest)
char *db;
int passes;
int verbose;
int check;
int save_db;
int dontclean;
- enum dbtype db_type;
int ptest;
{
krb5_error_code kret;
krb5_init_context(&kcontext);
krb5_init_ets(kcontext);
- switch (db_type) {
-#ifdef BERK_DB_DBM
- case DB_BERKELEY:
- op = "setting up Berkeley database operations";
- if (kret = kdb5_db_set_dbops(kcontext, &berkeley_dispatch))
- goto goodbye;
- break;
-#endif
-#if defined(ODBM) || defined(NDBM)
- case DB_DBM:
- op = "setting up DBM database operations";
- if (kret = kdb5_db_set_dbops(kcontext, &dbm_dispatch))
- goto goodbye;
- break;
-#endif
- case DB_DEFAULT:
- break;
- default:
- op = "checking database type";
- kret = EINVAL;
- goto goodbye;
- break;
- }
-
/*
* The database had better not exist.
*/
/* Set up the master key name */
op = "setting up master key name";
- if (kret = krb5_db_setup_mkey_name(kcontext,
- mkey_name,
- realm,
- &mkey_fullname,
- &master_princ))
+ if ((kret = krb5_db_setup_mkey_name(kcontext, mkey_name, realm,
+ &mkey_fullname, &master_princ)))
goto goodbye;
if (verbose)
programname, db, mkey_fullname);
op = "salting master key";
- if (kret = krb5_principal2salt(kcontext, master_princ, &salt_data))
+ if ((kret = krb5_principal2salt(kcontext, master_princ, &salt_data)))
goto goodbye;
op = "converting master key";
master_keyblock.enctype = DEFAULT_KDC_ENCTYPE;
passwd.length = strlen(master_passwd);
passwd.data = master_passwd;
- if (kret = krb5_string_to_key(kcontext, &master_encblock, &master_keyblock,
- &passwd, &salt_data))
+ if ((kret = krb5_string_to_key(kcontext, &master_encblock,
+ &master_keyblock, &passwd, &salt_data)))
goto goodbye;
/* Clean up */
free(salt_data.data);
/* Process master key */
op = "processing master key";
- if (kret = krb5_process_key(kcontext, &master_encblock, &master_keyblock))
+ if ((kret = krb5_process_key(kcontext, &master_encblock,
+ &master_keyblock)))
goto goodbye;
/* Initialize random key generator */
op = "initializing random key generator";
- if (kret = krb5_init_random_key(kcontext,
- &master_encblock,
- &master_keyblock,
- &rseed))
+ if ((kret = krb5_init_random_key(kcontext,
+ &master_encblock,
+ &master_keyblock,
+ &rseed)))
goto goodbye;
/* Create database */
op = "creating database";
- if (kret = krb5_db_create(kcontext, db))
+ if ((kret = krb5_db_create(kcontext, db)))
goto goodbye;
db_created = 1;
/* Set this database as active. */
op = "setting active database";
- if (kret = krb5_db_set_name(kcontext, db))
+ if ((kret = krb5_db_set_name(kcontext, db)))
goto goodbye;
/* Initialize database */
op = "initializing database";
- if (kret = krb5_db_init(kcontext))
+ if ((kret = krb5_db_init(kcontext)))
goto goodbye;
db_open = 1;
op = "adding master principal";
- if (kret = add_principal(kcontext,
- master_princ,
- &master_encblock,
- &master_keyblock,
- rseed))
+ if ((kret = add_principal(kcontext,
+ master_princ,
+ &master_encblock,
+ &master_keyblock,
+ rseed)))
goto goodbye;
for (passno=0; passno<passes; passno++) {
op = "generating principal name";
do {
- if (kret = gen_principal(kcontext,
- realm,
- rcases,
- passno,
- &principal,
- &pname))
- goto goodbye;
+ if ((kret = gen_principal(kcontext, realm, rcases,
+ passno, &principal, &pname)))
+ goto goodbye;
} while (principal_found(passno-1, pname));
record_principal(passno, principal, pname);
}
if (timing) {
swatch_on();
}
- if (kret = add_principal(kcontext,
- playback_principal(passno),
- &master_encblock,
- kbp,
- rseed)) {
+ if ((kret = add_principal(kcontext, playback_principal(passno),
+ &master_encblock, kbp, rseed))) {
linkage = "initially ";
oparg = playback_name(passno);
goto cya;
if (timing) {
swatch_on();
}
- if (kret = add_principal(kcontext,
- playback_principal(nvalid),
- &master_encblock,
- kbp,
- rseed)) {
+ if ((kret = add_principal(kcontext,
+ playback_principal(nvalid),
+ &master_encblock,
+ kbp, rseed))) {
oparg = playback_name(nvalid);
goto cya;
}
if (timing) {
swatch_on();
}
- if (kret = delete_principal(kcontext,
- playback_principal(nvalid-1))) {
+ if ((kret = delete_principal(kcontext,
+ playback_principal(nvalid-1)))) {
oparg = playback_name(nvalid-1);
goto cya;
}
if (timing) {
swatch_on();
}
- if (kret = find_principal(kcontext,
- playback_principal(passno),
- check)) {
+ if ((kret = find_principal(kcontext,
+ playback_principal(passno),
+ check))) {
oparg = playback_name(passno);
goto cya;
}
if (timing) {
swatch_on();
}
- if (kret = delete_principal(kcontext,
- playback_principal(passno))) {
+ if ((kret = delete_principal(kcontext,
+ playback_principal(passno)))) {
linkage = "finally ";
oparg = playback_name(passno);
goto cya;
*/
for (passno=0; passno<passes; passno++) {
op = "generating principal name";
- if (kret = gen_principal(kcontext,
- realm,
- rcases,
- passno,
- &principal,
- &pname))
+ if ((kret = gen_principal(kcontext, realm, rcases,
+ passno, &principal, &pname)))
goto goodbye;
record_principal(passno, principal, pname);
}
}
for (passno=0; passno<passes; passno++) {
op = "adding principal";
- if (kret = add_principal(kcontext,
- playback_principal(passno),
- &master_encblock,
- &stat_kb,
- rseed))
+ if ((kret = add_principal(kcontext, playback_principal(passno),
+ &master_encblock, &stat_kb, rseed)))
goto goodbye;
if (verbose > 4)
fprintf(stderr, "*A(%s)\n", playback_name(passno));
}
for (passno=0; passno<passes; passno++) {
op = "looking up principal";
- if (kret = find_principal(kcontext,
- playback_principal(passno),
- check))
+ if ((kret = find_principal(kcontext, playback_principal(passno),
+ check)))
goto goodbye;
if (verbose > 4)
fprintf(stderr, "-S(%s)\n", playback_name(passno));
}
for (passno=passes-1; passno>=0; passno--) {
op = "deleting principal";
- if (kret = delete_principal(kcontext,
- playback_principal(passno)))
+ if ((kret = delete_principal(kcontext,
+ playback_principal(passno))))
goto goodbye;
if (verbose > 4)
fprintf(stderr, "XD(%s)\n", playback_name(passno));
while (stat("./test.lock", &stbuf) == -1)
krb5_init_context(&ccontext);
krb5_init_ets(ccontext);
- switch (db_type) {
-#ifdef BERK_DB_DBM
- case DB_BERKELEY:
- if (kret = kdb5_db_set_dbops(ccontext, &berkeley_dispatch))
- exit(1);
- break;
-#endif
-#if defined(ODBM) || defined(NDBM)
- case DB_DBM:
- if (kret = kdb5_db_set_dbops(ccontext, &dbm_dispatch))
- exit(1);
- break;
-#endif
- case DB_DEFAULT:
- break;
- default:
- exit(1);
- break;
- }
if ((kret = krb5_db_set_name(ccontext, db)) ||
(kret = krb5_db_init(ccontext)))
exit(1);
(void) krb5_db_fini(kcontext);
if (db_created) {
if (!kret && !save_db) {
- switch (db_type) {
-#ifdef BERK_DB_DBM
- case DB_BERKELEY:
- op = "setting up Berkeley database operations";
- if (kret = kdb5_db_set_dbops(kcontext, &berkeley_dispatch))
- goto goodbye1;
- break;
-#endif
-#if defined(ODBM) || defined(NDBM)
- case DB_DBM:
- op = "setting up DBM database operations";
- if (kret = kdb5_db_set_dbops(kcontext, &dbm_dispatch))
- goto goodbye1;
- break;
-#endif
- case DB_DEFAULT:
- break;
- default:
- op = "checking database type";
- kret = EINVAL;
- goto goodbye1;
- break;
- }
kdb5_db_destroy(kcontext, db);
krb5_db_fini(kcontext);
- }
- else {
+ } else {
if (kret && verbose)
fprintf(stderr, "%s: database not deleted because of error\n",
programname);
}
}
- goodbye1:
return((kret) ? 1 : 0);
}
* [-d <dbname>] - Database name.
* [-s] - Save database even on successful completion.
* [-D] - Leave database dirty.
- * [-o] - Use dbm instead of default.
- * [-O] - Use Berkeley db instead of default.
*/
int
main(argc, argv)
int do_time, do_random, num_passes, check_cont, verbose, error;
int save_db, dont_clean, do_ptest;
- enum dbtype db_type;
char *db_name;
programname = argv[0];
db_name = T_KDB_DEF_DB;
save_db = 0;
dont_clean = 0;
- db_type = DB_DEFAULT;
error = 0;
do_ptest = 0;
/* Parse argument list */
- while ((option = getopt(argc, argv, "cd:n:oprstvDO")) != EOF) {
+ while ((option = getopt(argc, argv, "cd:n:prstvD")) != EOF) {
switch (option) {
case 'c':
check_cont = 1;
case 'D':
dont_clean = 1;
break;
- case 'o':
- db_type = DB_DBM;
- break;
- case 'O':
- db_type = DB_BERKELEY;
- break;
default:
error++;
break;
check_cont,
save_db,
dont_clean,
- db_type,
do_ptest);
return(error);
}