From: Mitchell Berger Date: Wed, 20 Jun 2001 08:13:20 +0000 (+0000) Subject: * Makefile.in: Include svr_generation.[co] in the build X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1d5ff8ed18c2571237ee9cd12ffde60845b04802;p=thirdparty%2Fkrb5.git * Makefile.in: Include svr_generation.[co] in the build * adb_openclose.c: Changed to include server_internal.h instead of adb.h. (osa_adb_rename_db): Modified to use the new osa_adb_init_db calling sequence. (osa_adb_init_db): Now takes a pointer to a struct _kadm5_server_handle_t, and puts it in the osa db handle. * adb_policy.c: Changed to include server_internal.h instead of adb.h (osa_adb_open_policy): Now takes a pointer to a struct _kadm5_server_handle_t and passes it to osa_adb_init_db. (osa_adb_create_policy): Now makes a call to update the generation number. (osa_adb_destroy_policy): Now makes a call to update the generation number. (osa_adb_put_policy): Now makes a call to update the generation number. * server_kdb.c: Renamed kdb_put_entry to kdb_put_entry_internal and added parameters to it to specify whether the modprinc info and the generation number should be updated, wrote a new kdb_put_entry as a wrapper for kdb_put_entry_internal that specifies both modprinc info and the generation number should be updated. (kdb_delete_entry): Now makes a call to update the generation number. Added a new function kdb_update_generation_number which looks up the master principal and calls krb5_dbe_update_generation_number_general to update the generation number. * server_misc.c: No longer includes adb.h (server_internal.h already pulls this in). (adb_policy_init): Modified to use the new osa_adb_open_policy calling sequence. * svr_iters.c: No longer includes adb.h (server_internal.h already pulls this in). * svr_policy.c: No longer includes adb.h (server_internal.h already pulls this in). * svr_principal.c: No longer includes adb.h (server_internal.h already pulls this in). * svr_generation.c: Added this new file containing the new function kadm5_get_generation_number. git-svn-id: svn://anonsvn.mit.edu/krb5/branches/incremental-propagation-branch@13407 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/lib/kadm5/srv/ChangeLog b/src/lib/kadm5/srv/ChangeLog index 5db7ffacbb..300dad945a 100644 --- a/src/lib/kadm5/srv/ChangeLog +++ b/src/lib/kadm5/srv/ChangeLog @@ -1,3 +1,50 @@ +2001-06-20 Mitchell Berger + + * Makefile.in: Include svr_generation.[co] in the build. + + * adb_openclose.c: Changed to include server_internal.h instead of + adb.h. + (osa_adb_rename_db): Modified to use the new osa_adb_init_db calling + sequence. + (osa_adb_init_db): Now takes a pointer to a struct + _kadm5_server_handle_t, and puts it in the osa db handle. + + * adb_policy.c: Changed to include server_internal.h instead of adb.h + (osa_adb_open_policy): Now takes a pointer to a struct + _kadm5_server_handle_t and passes it to osa_adb_init_db. + (osa_adb_create_policy): Now makes a call to update the generation + number. + (osa_adb_destroy_policy): Now makes a call to update the generation + number. + (osa_adb_put_policy): Now makes a call to update the generation number. + + * server_kdb.c: Renamed kdb_put_entry to kdb_put_entry_internal and + added parameters to it to specify whether the modprinc info and the + generation number should be updated, wrote a new kdb_put_entry as a + wrapper for kdb_put_entry_internal that specifies both modprinc info + and the generation number should be updated. + (kdb_delete_entry): Now makes a call to update the generation number. + Added a new function kdb_update_generation_number which looks up the + master principal and calls krb5_dbe_update_generation_number_general + to update the generation number. + + * server_misc.c: No longer includes adb.h (server_internal.h already + pulls this in). + (adb_policy_init): Modified to use the new osa_adb_open_policy + calling sequence. + + * svr_iters.c: No longer includes adb.h (server_internal.h already + pulls this in). + + * svr_policy.c: No longer includes adb.h (server_internal.h already + pulls this in). + + * svr_principal.c: No longer includes adb.h (server_internal.h already + pulls this in). + + * svr_generation.c: Added this new file containing the new function + kadm5_get_generation_number. + 2001-06-20 Mitchell Berger * server_dict.c: Silly typo fixed. diff --git a/src/lib/kadm5/srv/Makefile.in b/src/lib/kadm5/srv/Makefile.in index 40da944793..6c21260e24 100644 --- a/src/lib/kadm5/srv/Makefile.in +++ b/src/lib/kadm5/srv/Makefile.in @@ -39,7 +39,8 @@ SRCS = $(srcdir)/svr_policy.c \ $(srcdir)/adb_xdr.c \ $(srcdir)/adb_policy.c \ $(srcdir)/adb_free.c \ - $(srcdir)/adb_openclose.c + $(srcdir)/adb_openclose.c \ + $(srcdir)/svr_generation.c OBJS = svr_policy.$(OBJEXT) \ svr_principal.$(OBJEXT) \ @@ -53,7 +54,8 @@ OBJS = svr_policy.$(OBJEXT) \ adb_xdr.$(OBJEXT) \ adb_policy.$(OBJEXT) \ adb_free.$(OBJEXT) \ - adb_openclose.$(OBJEXT) + adb_openclose.$(OBJEXT) \ + svr_generation.$(OBJEXT) STLIBOBJS = \ svr_policy.o \ @@ -68,7 +70,8 @@ STLIBOBJS = \ adb_xdr.o \ adb_policy.o \ adb_free.o \ - adb_openclose.o + adb_openclose.o \ + svr_generation.o all-unix:: includes all-unix:: all-liblinks diff --git a/src/lib/kadm5/srv/adb_openclose.c b/src/lib/kadm5/srv/adb_openclose.c index 12219cdabe..9f165bd8d4 100644 --- a/src/lib/kadm5/srv/adb_openclose.c +++ b/src/lib/kadm5/srv/adb_openclose.c @@ -11,7 +11,7 @@ static char *rcsid = "$Header$"; #include #include #include -#include "adb.h" +#include "server_internal.h" #include #define MAX_LOCK_TRIES 5 @@ -72,9 +72,9 @@ osa_adb_ret_t osa_adb_rename_db(char *filefrom, char *lockfrom, ret != EEXIST) return ret; - if ((ret = osa_adb_init_db(&fromdb, filefrom, lockfrom, magic))) + if ((ret = osa_adb_init_db(&fromdb, filefrom, lockfrom, magic, NULL))) return ret; - if ((ret = osa_adb_init_db(&todb, fileto, lockto, magic))) { + if ((ret = osa_adb_init_db(&todb, fileto, lockto, magic, NULL))) { (void) osa_adb_fini_db(fromdb, magic); return ret; } @@ -109,7 +109,8 @@ osa_adb_ret_t osa_adb_rename_db(char *filefrom, char *lockfrom, } osa_adb_ret_t osa_adb_init_db(osa_adb_db_t *dbp, char *filename, - char *lockfilename, int magic) + char *lockfilename, int magic, + struct _kadm5_server_handle_t *kadm5_handle) { osa_adb_db_t db; static struct _locklist *locklist = NULL; @@ -217,6 +218,8 @@ osa_adb_ret_t osa_adb_init_db(osa_adb_db_t *dbp, char *filename, db->filename = strdup(filename); db->magic = magic; + db->kadm5_handle = kadm5_handle; + *dbp = db; return OSA_ADB_OK; diff --git a/src/lib/kadm5/srv/adb_policy.c b/src/lib/kadm5/srv/adb_policy.c index 7403d31a79..c44b7ba325 100644 --- a/src/lib/kadm5/srv/adb_policy.c +++ b/src/lib/kadm5/srv/adb_policy.c @@ -10,7 +10,7 @@ static char *rcsid = "$Header$"; #include #include -#include "adb.h" +#include "server_internal.h" #include #include @@ -59,11 +59,13 @@ osa_adb_ret_t osa_adb_destroy_policy_db(kadm5_config_params *params) } osa_adb_ret_t osa_adb_open_policy(osa_adb_princ_t *dbp, - kadm5_config_params *rparams) + kadm5_config_params *rparams, + struct _kadm5_server_handle_t *kadm5_handle) { return osa_adb_init_db(dbp, rparams->admin_dbname, rparams->admin_lockfile, - OSA_ADB_POLICY_DB_MAGIC); + OSA_ADB_POLICY_DB_MAGIC, + kadm5_handle); } osa_adb_ret_t osa_adb_close_policy(osa_adb_princ_t db) @@ -140,6 +142,9 @@ osa_adb_create_policy(osa_adb_policy_t db, osa_policy_ent_t entry) } xdr_destroy(&xdrs); + /* The create succeeded, so we should increment the generation number. */ + kdb_update_generation_number(db->kadm5_handle); + error: CLOSELOCK(db); return ret; @@ -197,6 +202,9 @@ osa_adb_destroy_policy(osa_adb_policy_t db, kadm5_policy_t name) goto error; } + /* The destroy succeeded, so we should update the generation number. */ + kdb_update_generation_number(db->kadm5_handle); + error: CLOSELOCK(db); return ret; @@ -336,6 +344,9 @@ osa_adb_put_policy(osa_adb_policy_t db, osa_policy_ent_t entry) } xdr_destroy(&xdrs); + /* The update succeeded, so we should update the generation number. */ + kdb_update_generation_number(db->kadm5_handle); + error: CLOSELOCK(db); return ret; diff --git a/src/lib/kadm5/srv/server_kdb.c b/src/lib/kadm5/srv/server_kdb.c index 231fcb3ef9..980bcff157 100644 --- a/src/lib/kadm5/srv/server_kdb.c +++ b/src/lib/kadm5/srv/server_kdb.c @@ -323,6 +323,14 @@ kdb_free_entry(kadm5_server_handle_t handle, krb5_error_code kdb_put_entry(kadm5_server_handle_t handle, krb5_db_entry *kdb, osa_princ_ent_rec *adb) +{ + return kdb_put_entry_internal(handle, kdb, adb, 1, 1); +} + +krb5_error_code +kdb_put_entry_internal(kadm5_server_handle_t handle, + krb5_db_entry *kdb, osa_princ_ent_rec *adb, int incgen, + int updatemod) { krb5_error_code ret; krb5_int32 now; @@ -330,14 +338,16 @@ kdb_put_entry(kadm5_server_handle_t handle, krb5_tl_data tl_data; int one; - ret = krb5_timeofday(handle->context, &now); - if (ret) - return(ret); + if (updatemod) { + ret = krb5_timeofday(handle->context, &now); + if (ret) + return(ret); - ret = krb5_dbe_update_mod_princ_data(handle->context, kdb, now, - handle->current_caller); - if (ret) - return(ret); + ret = krb5_dbe_update_mod_princ_data(handle->context, kdb, now, + handle->current_caller); + if (ret) + return(ret); + } xdralloc_create(&xdrs, XDR_ENCODE); if(! xdr_osa_princ_ent_rec(&xdrs, adb)) { @@ -361,6 +371,13 @@ kdb_put_entry(kadm5_server_handle_t handle, if (ret) return(ret); + if (incgen) { + /* The update succeeded, so we should change the generation number */ + ret = kdb_update_generation_number(handle); + if (ret) + return(ret); + } + return(0); } @@ -371,8 +388,15 @@ kdb_delete_entry(kadm5_server_handle_t handle, krb5_principal name) krb5_error_code ret; ret = krb5_db_delete_principal(handle->context, name, &one); + if (ret) + return(ret); - return ret; + /* The deletion succeeded, so we should change the generation number */ + ret = kdb_update_generation_number(handle); + if (ret) + return(ret); + + return(0); } typedef struct _iter_data { @@ -407,4 +431,31 @@ kdb_iter_entry(kadm5_server_handle_t handle, return(0); } +krb5_error_code +kdb_update_generation_number(kadm5_server_handle_t handle) +{ + krb5_error_code ret; + krb5_db_entry master_kdb; + osa_princ_ent_rec master_adb; + + ret = kdb_get_entry(handle, master_princ, &master_kdb, &master_adb); + if (ret) + return(ret); + + ret = krb5_dbe_update_generation_number_general(handle->context, + &master_kdb, NULL); + if (ret) + return(ret); + + /* Updating the generation number, while a change to the database, + is not one that should result in updating the generation number + again to avoid an infinite loop. */ + ret = kdb_put_entry_internal(handle, &master_kdb, &master_adb, 0, 0); + if (ret) + return(ret); + + kdb_free_entry(handle->context, &master_kdb, &master_adb); + + return(0); +} diff --git a/src/lib/kadm5/srv/server_misc.c b/src/lib/kadm5/srv/server_misc.c index 02c7dced69..7da6a1a261 100644 --- a/src/lib/kadm5/srv/server_misc.c +++ b/src/lib/kadm5/srv/server_misc.c @@ -11,7 +11,6 @@ static char *rcsid = "$Header$"; #include "k5-int.h" #include #include -#include "adb.h" #include /* for strcasecmp */ @@ -25,7 +24,8 @@ adb_policy_init(kadm5_server_handle_t handle) osa_adb_ret_t ret; if(handle->policy_db == (osa_adb_policy_t) NULL) if((ret = osa_adb_open_policy(&handle->policy_db, - &handle->params)) != OSA_ADB_OK) + &handle->params, + handle)) != OSA_ADB_OK) return ret; return KADM5_OK; } diff --git a/src/lib/kadm5/srv/svr_generation.c b/src/lib/kadm5/srv/svr_generation.c new file mode 100644 index 0000000000..eb0fd7e9e2 --- /dev/null +++ b/src/lib/kadm5/srv/svr_generation.c @@ -0,0 +1,76 @@ +/* + * lib/kadm5/srv/svr_generation.c + * + * (C) Copyright 2001 by the Massachusetts Institute of Technology. + * All Rights Reserved. + * + * Export of this software from the United States of America may + * require a specific license from the United States Government. + * It is the responsibility of any person or organization contemplating + * export to obtain such a license before exporting. + * + * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and + * distribute this software and its documentation for any purpose and + * without fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright notice and + * this permission notice appear in supporting documentation, and that + * the name of M.I.T. not be used in advertising or publicity pertaining + * to distribution of the software without specific, written prior + * permission. Furthermore if you modify this software you must label + * your software as modified software and not distribute it in such a + * fashion that it might be confused with the original M.I.T. software. + * M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" without express + * or implied warranty. + * + */ + +#if !defined(lint) && !defined(__CODECENTER__) +static char *rcsid = "$Header$"; +#endif + +#include +#include +#include +#include "k5-int.h" +#include +#include +#include +#include "server_internal.h" +#include +#include + +kadm5_ret_t +kadm5_get_generation_number(void *server_handle, krb5_int32 *generation) +{ + krb5_principal princ; + krb5_db_entry kdb; + osa_princ_ent_rec adb; + krb5_error_code ret; + kadm5_server_handle_t handle = server_handle; + + CHECK_HANDLE(server_handle); + + ret = krb5_db_setup_mkey_name(handle->context, handle->params.mkey_name, + handle->params.realm, NULL, &princ); + if (ret) + return KADM5_FAILURE; + + ret = kdb_get_entry(handle, princ, &kdb, &adb); + if (ret) + return KADM5_UNK_PRINC; + + ret = krb5_dbe_lookup_generation_number_general(handle->context, &kdb, + generation); + if (ret) + return KADM5_FAILURE; + + ret = kdb_free_entry(handle, &kdb, &adb); + /* if (ret), that sucks, but if we've got the generation number, it + seems wrong to fail out. */ + + krb5_free_principal(handle->context, princ); + + return KADM5_OK; +} + diff --git a/src/lib/kadm5/srv/svr_iters.c b/src/lib/kadm5/srv/svr_iters.c index 1397254e58..78bc12f344 100644 --- a/src/lib/kadm5/srv/svr_iters.c +++ b/src/lib/kadm5/srv/svr_iters.c @@ -21,7 +21,6 @@ static char *rcsid = "$Header$"; #include #include #include -#include "adb.h" #include #ifdef SOLARIS_REGEXPS #include diff --git a/src/lib/kadm5/srv/svr_policy.c b/src/lib/kadm5/srv/svr_policy.c index d03cfd0b67..b828f48a45 100644 --- a/src/lib/kadm5/srv/svr_policy.c +++ b/src/lib/kadm5/srv/svr_policy.c @@ -10,7 +10,6 @@ static char *rcsid = "$Header$"; #include #include -#include "adb.h" #include "server_internal.h" #include diff --git a/src/lib/kadm5/srv/svr_principal.c b/src/lib/kadm5/srv/svr_principal.c index 7552993b10..428f76a6a4 100644 --- a/src/lib/kadm5/srv/svr_principal.c +++ b/src/lib/kadm5/srv/svr_principal.c @@ -11,7 +11,6 @@ static char *rcsid = "$Header$"; #include #include #include -#include "adb.h" #include "k5-int.h" #include #include