X-Git-Url: https://git.distorted.org.uk/~mdw/become/blobdiff_plain/607937a4e1c4cdb3da09617fa7bfda536278ca95..af4f4d6a77aceba8e2d6f58d15e894df320e7c24:/src/name.c diff --git a/src/name.c b/src/name.c index aaf7491..1ea34a0 100644 --- a/src/name.c +++ b/src/name.c @@ -1,10 +1,10 @@ /* -*-c-*- * - * $Id: name.c,v 1.3 1997/08/07 09:49:39 mdw Exp $ + * $Id: name.c,v 1.10 2004/04/08 01:36:20 mdw Exp $ * * Looking up of names in symbol tables * - * (c) 1997 EBI + * (c) 1998 EBI */ /*----- Licensing notice --------------------------------------------------* @@ -26,21 +26,6 @@ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/*----- Revision history --------------------------------------------------* - * - * $Log: name.c,v $ - * Revision 1.3 1997/08/07 09:49:39 mdw - * Extensive modifications to handle netgroups. Also sanitise user and group - * names before adding them to the symbol table. - * - * Revision 1.2 1997/08/04 10:24:24 mdw - * Sources placed under CVS control. - * - * Revision 1.1 1997/07/21 13:47:46 mdw - * Initial revision - * - */ - /*----- Header files ------------------------------------------------------*/ /* --- ANSI headers --- */ @@ -63,6 +48,11 @@ #include #include +/* --- mLib headers --- */ + +#include +#include + /* --- Local headers --- */ #include "config.h" @@ -71,9 +61,7 @@ #include "class.h" #include "name.h" #include "netg.h" -#include "sym.h" #include "userdb.h" -#include "utils.h" /*----- Static variables --------------------------------------------------*/ @@ -96,12 +84,9 @@ static name *name__get(const char *p, unsigned type) { unsigned f; name *n = sym_find(&name__table, p, -1, sizeof(*n), &f); - if (!f) { - sym_table *t = xmalloc(sizeof(*t)); - sym_createTable(t); - n->c = class_create(type, t); - } - return (n->c->type == type ? n : 0); + if (!f) + n->c = 0; + return ((n->c && !(n->c->type & type)) ? 0 : n); } /* --- @name__sanitise@ --- * @@ -153,22 +138,20 @@ static void name__users(void) userdb_iterateUsers(); while ((pw = userdb_nextUser()) != 0) { name *n; - int u = pw->pw_uid; - - /* --- Make the name into something nice --- */ + uid_t u = pw->pw_uid; /* --- First, add the user to the table --- */ if (name__sanitise(pw->pw_name, buf, sizeof(buf)) && (n = name__get(buf, clType_user)) != 0) - sym_find(n->c->t, (char *)&u, sizeof(u), sizeof(sym_base), 0); + n->c = class_addUser(n->c, u); /* --- Now handle the user's default group --- */ if ((gr = userdb_groupById(pw->pw_gid)) != 0 && name__sanitise(gr->gr_name, buf, sizeof(buf)) && (n = name__get(buf, clType_user)) != 0) - sym_find(n->c->t, (char *)&u, sizeof(u), sizeof(sym_base), 0); + n->c = class_addUser(n->c, u); } } @@ -191,7 +174,6 @@ static void name__groups(void) userdb_iterateGroups(); while ((gr = userdb_nextGroup()) != 0) { name *n; - int u; if (name__sanitise(gr->gr_name, buf, sizeof(buf)) && (n = name__get(buf, clType_user)) != 0) { @@ -199,11 +181,11 @@ static void name__groups(void) /* --- Now add all of the members --- */ for (p = gr->gr_mem; *p; p++) { - if ((pw = userdb_userByName(*p)) != 0) { - u = pw->pw_uid; - sym_find(n->c->t, (char *)&u, sizeof(u), sizeof(sym_base), 0); - } + if ((pw = userdb_userByName(*p)) != 0) + n->c = class_addUser(n->c, pw->pw_uid); } + if (!n->c) + n->c = class_none; } } } @@ -268,7 +250,7 @@ static int name__scan(netg *n, const char *host, const char *user, memcpy(&in, h->h_addr, sizeof(in)); if ((a = inet_ntoa(in)) == 0) goto done_host; - sym_find(sc->h->c->t, a, -1, sizeof(sym_base), 0); + sc->h->c = class_addString(sc->h->c, a); done_host:; } @@ -276,7 +258,6 @@ static int name__scan(netg *n, const char *host, const char *user, if (sc->f & f_user && user) { struct passwd *pw; - int u; /* --- First ensure that I have a user class --- */ @@ -293,8 +274,7 @@ static int name__scan(netg *n, const char *host, const char *user, if ((pw = userdb_userByName(user)) == 0) goto done_user; - u = pw->pw_uid; - sym_find(sc->u->c->t, (char *)&u, sizeof(u), sizeof(sym_base), 0); + sc->u->c = class_addUser(sc->u->c, pw->pw_uid); done_user:; } @@ -345,7 +325,7 @@ void name_init(void) { /* --- Initialise the name table --- */ - sym_createTable(&name__table); + sym_create(&name__table); /* --- Add everyone into the table --- */ @@ -353,9 +333,9 @@ void name_init(void) name__groups(); name__netgroups(); - /* --- Finally add in the `all' class --- * + /* --- Finally add in the `all' and `none' classes --- * * - * Do that now, to prevent it being overwritten by the above. + * Do that now, to prevent them being overwritten by the above. */ { @@ -366,21 +346,25 @@ void name_init(void) if (f) class_dec(n->c); n->c = class_all; + + n = sym_find(&name__table, "none", -1, sizeof(name), &f); + if (f) + class_dec(n->c); + n->c = class_none; } } -/* --- @name_reinit@ --- * +/* --- @name_end@ --- * * * Arguments: --- * * Returns: --- * - * Use: Reinitialises the names table. It's cleared and then - * initialised with the current user and group ids as for - * @name_init@ above. + * Use: Closes down the name database, so that it can be + * reinitialised. */ -void name_reinit(void) +void name_end(void) { /* --- Empty the symbol table --- */ @@ -388,7 +372,7 @@ void name_reinit(void) sym_iter i; name *n; - for (sym_createIter(&i, &name__table); (n = sym_next(&i)) != 0; ) { + for (sym_mkiter(&i, &name__table); (n = sym_next(&i)) != 0; ) { if (n->c) class_dec(n->c); } @@ -396,8 +380,7 @@ void name_reinit(void) /* --- Destroy and recreate the table --- */ - sym_destroyTable(&name__table); - name_init(); + sym_destroy(&name__table); } /* --- @name_find@ --- * @@ -432,14 +415,19 @@ name *name_find(const char *p, unsigned create, unsigned *f) void name_dump(void) { +#ifdef TRACING sym_iter i; name *n; trace(TRACE_DEBUG, "name: dumping names"); - for (sym_createIter(&i, &name__table); (n = sym_next(&i)) != 0; ) { + for (sym_mkiter(&i, &name__table); (n = sym_next(&i)) != 0; ) { trace(TRACE_DEBUG, "name: dumping `%s'", n->base.name); - class_dump(n->c); + if (!n->c) + trace(TRACE_DEBUG, "name: "); + else + class_dump(n->c, 1); } +#endif } /*----- Test driver -------------------------------------------------------*/ @@ -449,13 +437,32 @@ void name_dump(void) int main(void) { ego("name-test"); - traceon(stdout, TRACE_ALL); + trace_on(stdout, TRACE_ALL); userdb_init(); userdb_local(); userdb_yp(); netg_init(); name_init(); + /* printf("loaded (%lu)\n", track_memused()); */ +#ifdef notdef + getchar(); + for (;;) { + name_end(); + netg_end(); + userdb_end(); + /* printf("cleared (%lu)\n", track_memused()); */ + /* track_memlist(); */ + userdb_init(); + userdb_local(); + userdb_yp(); + netg_init(); + name_init(); + /* printf("reloaded (%lu)\n", track_memused()); */ + getchar(); + } +#else name_dump(); +#endif return (0); }