X-Git-Url: https://git.distorted.org.uk/~mdw/become/blobdiff_plain/afce951bf49ff63b726810860a29ebeec534146c..a340752b9da6b63515d164fd5bb025b2be551a7a:/src/netg.c diff --git a/src/netg.c b/src/netg.c index 87afce0..c198219 100644 --- a/src/netg.c +++ b/src/netg.c @@ -1,10 +1,10 @@ /* -*-c-*- * - * $Id: netg.c,v 1.1 1997/08/07 09:45:00 mdw Exp $ + * $Id: netg.c,v 1.4 1998/04/23 13:24:49 mdw Exp $ * * A local database of netgroups * - * (c) 1997 EBI + * (c) 1998 EBI */ /*----- Licensing notice --------------------------------------------------* @@ -29,6 +29,16 @@ /*----- Revision history --------------------------------------------------* * * $Log: netg.c,v $ + * Revision 1.4 1998/04/23 13:24:49 mdw + * Switch to using the ypstuff interface to YP server. + * + * Revision 1.3 1998/01/12 16:46:17 mdw + * Fix copyright date. + * + * Revision 1.2 1997/08/20 16:19:11 mdw + * Patch memory leak. Replace `name_reinit' by `name_end' for more sensible + * restart. Don't try to trace when tracing's turned off. + * * Revision 1.1 1997/08/07 09:45:00 mdw * New source file added to maintain a netgroups database. * @@ -49,12 +59,6 @@ #include -#ifdef HAVE_YP -# include -# include -# include -#endif - #include #include @@ -71,6 +75,7 @@ #include "sym.h" #include "userdb.h" #include "utils.h" +#include "ypstuff.h" /*----- Type definitions --------------------------------------------------*/ @@ -338,6 +343,8 @@ static int netg__foreach(int st, char *k, int ksz, goto duff_restart; } + free(c->car.atom); + free(c); free(kc); free(vc); return (0); @@ -402,21 +409,23 @@ static void netg__dumpGroup(netg__cons *c, int lev) * Use: Dumps the netgroups table. */ +#ifdef TRACING + static void netg__dump(void) { sym_iter i; netg__sym *sng; -#ifdef TRACING trace(TRACE_DEBUG, "debug: dumping netgroups file"); for (sym_createIter(&i, &netg__table); (sng = sym_next(&i)) != 0; ) { trace(TRACE_DEBUG, "debug: netgroup `%s'...", sng->_base.name); sng->cons->f &= ~f_visit; netg__dumpGroup(sng->cons, 1); } -#endif } +#endif + /* --- @netg_iterate@, @netg_iterate_r@ --- * * * Arguments: @netg_iter *i@ = pointer to a netgroup iterator object @@ -546,29 +555,23 @@ static void netg__breakCycle(netg__cons *c) void netg_init(void) { - char *ypdom; - /* --- Initialise my symbol table --- */ sym_createTable(&netg__table); /* --- Bind myself unto a YP server --- */ - if (yp_get_default_domain(&ypdom) || - yp_bind(ypdom)) + ypstuff_bind(); + if (!yp_domain) return; /* --- Now try to read all the netgroup entries --- */ { static struct ypall_callback ncb = { netg__foreach, 0 }; - yp_all(ypdom, "netgroup", &ncb); + yp_all(yp_domain, "netgroup", &ncb); } - /* --- Unbind from the server --- */ - - yp_unbind(ypdom); - /* --- Dump the table --- */ IF_TRACING(TRACE_DEBUG, netg__dump(); ) @@ -617,16 +620,16 @@ void netg_init(void) IF_TRACING(TRACE_DEBUG, netg__dump(); ) } -/* --- @netg_reinit@ --- * +/* --- @netg_end@ --- * * * Arguments: --- * * Returns: --- * - * Use: Forces a re-read of the netgroups file. + * Use: Empties the netgroups database. */ -void netg_reinit(void) +void netg_end(void) { sym_iter i; netg__sym *sng; @@ -643,6 +646,7 @@ void netg_reinit(void) if (c->car.atom->h) free(c->car.atom->h); if (c->car.atom->u) free(c->car.atom->u); if (c->car.atom->d) free(c->car.atom->d); + free(c->car.atom); } free(c); c = cc; @@ -650,9 +654,7 @@ void netg_reinit(void) sym_remove(&netg__table, sng); } - /* --- Now rebuild the world --- */ - - netg_init(); + sym_destroyTable(&netg__table); } /*----- Test driver -------------------------------------------------------*/