From: Mark Wooding Date: Sat, 19 May 2018 20:12:10 +0000 (+0100) Subject: server/keymgmt.c, server/tripe.c: Add `km_clear' to shut down keyrings. X-Git-Tag: 1.5.0~15 X-Git-Url: https://git.distorted.org.uk/~mdw/tripe/commitdiff_plain/b50ba1bda8722c66c40005f43707ebc63515732b?hp=bf302d900e1658e664e4e7c05bb2748c4677dfc6 server/keymgmt.c, server/tripe.c: Add `km_clear' to shut down keyrings. A bit more fiddly than our previous efforts, but this completes the job of unwinding all of the configurable components of the server. The main thing that doesn't get reset is the set of extant admin connections, and I intend to leave those running until we have no choice. --- diff --git a/server/keymgmt.c b/server/keymgmt.c index e181d0ef..a72164e5 100644 --- a/server/keymgmt.c +++ b/server/keymgmt.c @@ -528,6 +528,28 @@ static int kh_refresh(keyhalf *kh) return (changep); } +/* --- @kh_clear@ --- * + * + * Arguments: @keyhalf *kh@ = pointer to keyhalf structure + * + * Returns: --- + * + * Use: Clears out the keyhalf's keyring and flushes the cache. + */ + +static void kh_clear(keyhalf *kh) +{ + sym_iter i; + knode *kn; + + if (!kh->kf) return; + for (sym_mkiter(&i, &kh->tab); (kn = sym_next(&i)) != 0; ) + if (kn->kd) km_unref(kn->kd); + sym_destroy(&kh->tab); + key_close(kh->kf); + kh->kf = 0; +} + /*----- Main code ---------------------------------------------------------*/ const char *tag_priv; @@ -593,6 +615,25 @@ int km_reload(void) return (changep); } +/* --- @km_clear@ --- * + * + * Arguments: --- + * + * Returns: --- + * + * Use: Forget the currently loaded keyrings. The @master@ key will + * be cleared, but other keys already loaded will continue to + * exist until their reference count drops to zero. Call + * @km_init@ to make everything work again. + */ + +void km_clear(void) +{ + kh_clear(&priv); + kh_clear(&pub); + if (master) { km_unref(master); master = 0; } +} + /* --- @km_findpub@, @km_findpriv@ --- * * * Arguments: @const char *tag@ = key tag to load diff --git a/server/tripe.c b/server/tripe.c index 931c0fca..fb1d3375 100644 --- a/server/tripe.c +++ b/server/tripe.c @@ -437,6 +437,7 @@ int main(int argc, char *argv[]) p_destroyall(); p_unbind(); a_unlisten(); + km_clear(); ps_quit(); return (0); } diff --git a/server/tripe.h b/server/tripe.h index ba47232b..b062b366 100644 --- a/server/tripe.h +++ b/server/tripe.h @@ -859,6 +859,20 @@ extern void km_init(const char */*privkr*/, const char */*pubkr*/, extern int km_reload(void); +/* --- @km_clear@ --- * + * + * Arguments: --- + * + * Returns: --- + * + * Use: Forget the currently loaded keyrings. The @master@ key will + * be cleared, but other keys already loaded will continue to + * exist until their reference count drops to zero. Call + * @km_init@ to make everything work again. + */ + +extern void km_clear(void); + /* --- @km_findpub@, @km_findpriv@ --- * * * Arguments: @const char *tag@ = key tag to load