From 048c1ff248ce0491ab1e2a41707eb9a2c87cf47d Mon Sep 17 00:00:00 2001 From: Kalamatee Date: Mon, 6 Oct 2025 16:12:19 +0100 Subject: [PATCH] # inline FreeListVec # disable debug by default. --- workbench/devs/netinfo/base.h | 3 --- workbench/devs/netinfo/entries.c | 18 ++++++++++++++--- workbench/devs/netinfo/groupunit.c | 4 ++++ workbench/devs/netinfo/misc.c | 30 ----------------------------- workbench/devs/netinfo/misc.h | 28 +++++++++++++++++++++++++++ workbench/devs/netinfo/netinfo.c | 4 ++++ workbench/devs/netinfo/netinfo.conf | 2 +- workbench/devs/netinfo/passwdunit.c | 23 +++++++++++++++++++--- workbench/devs/netinfo/server.c | 4 ++++ 9 files changed, 76 insertions(+), 40 deletions(-) create mode 100644 workbench/devs/netinfo/misc.h diff --git a/workbench/devs/netinfo/base.h b/workbench/devs/netinfo/base.h index 490172257e..cab672a277 100644 --- a/workbench/devs/netinfo/base.h +++ b/workbench/devs/netinfo/base.h @@ -161,8 +161,5 @@ void UnknownCommand(struct NetInfoDevice *, struct NetInfoReq *, struct NetInfoM /* support functions */ struct NetInfoMap *CheckUnit(struct NetInfoDevice *, struct Unit *u); -void FreeListVec(struct NetInfoDevice *, struct List *list); -struct Node *FindNode(struct List *list, struct Node *node); -char *strsep(register char **stringp, register const char *delim); #endif /* _BASE_H_ */ diff --git a/workbench/devs/netinfo/entries.c b/workbench/devs/netinfo/entries.c index 11e739e832..0d14f23b97 100644 --- a/workbench/devs/netinfo/entries.c +++ b/workbench/devs/netinfo/entries.c @@ -7,12 +7,17 @@ * Helsinki University of Technology, Finland. */ +#ifdef DEBUG +#undef DEBUG +#endif +#define DEBUG 0 #include #include #include #include "entries.h" +#include "misc.h" #include #if defined(DEBUG) @@ -20,6 +25,7 @@ #include "assert.h" #endif +#define DENTS(x) static struct NetInfoPointer *FindPointer(struct List *list, struct Ent*to); void GetByNameCmd(struct NetInfoDevice *nid, struct NetInfoReq *req, struct NetInfoMap *nim); @@ -93,13 +99,16 @@ void DeInitNetInfoMap(struct NetInfoDevice *nid, struct NetInfoMap *nim) */ void GetByNameCmd(struct NetInfoDevice *nid, struct NetInfoReq *req, struct NetInfoMap *nim) { - struct Ent *e = InternalSetEnts(nid, nim); const UBYTE *name = (const UBYTE *) ((struct NetInfoEnt*)req->io_Data)->nie_name; + struct Ent *e; LONG retval = NIERR_NOTFOUND; D(bug("[NetInfo] %s()\n", __func__)); + e = InternalSetEnts(nid, nim); + D(bug("[NetInfo] %s: Ents @ 0x%p\n", __func__, e)); + while (e = GetNextEnt(e)) { if (strcmp(e->e_name, name) == 0) { if (Method(copy_out, nim)(req, e)) { @@ -122,12 +131,15 @@ void GetByNameCmd(struct NetInfoDevice *nid, struct NetInfoReq *req, struct NetI */ void GetByIDCmd(struct NetInfoDevice *nid, struct NetInfoReq *req, struct NetInfoMap *nim) { - struct Ent *e = InternalSetEnts(nid, nim); + struct Ent *e; LONG id = ((struct NetInfoEnt*)req->io_Data)->nie_id; BYTE retval = NIERR_NOTFOUND; D(bug("[NetInfo] %s()\n", __func__)); + e = InternalSetEnts(nid, nim); + D(bug("[NetInfo] %s: Ents @ 0x%p\n", __func__, e)); + while (e = GetNextEnt(e)) { if (e->e_id == id) { if (Method(copy_out, nim)(req, e)) { @@ -456,7 +468,7 @@ void InternalEndEnts(struct NetInfoDevice *nid, struct NetInfoMap *nim) */ struct Ent *GetNextEnt(struct Ent *e) { - D(bug("[NetInfo] %s()\n", __func__)); + DENTS(bug("[NetInfo] %s()\n", __func__)); e = (struct Ent *)e->e_node.ln_Succ; diff --git a/workbench/devs/netinfo/groupunit.c b/workbench/devs/netinfo/groupunit.c index 2d8e7e5048..a873e23df7 100644 --- a/workbench/devs/netinfo/groupunit.c +++ b/workbench/devs/netinfo/groupunit.c @@ -7,6 +7,10 @@ * Helsinki University of Technology, Finland. */ +#ifdef DEBUG +#undef DEBUG +#endif +#define DEBUG 0 #include #include diff --git a/workbench/devs/netinfo/misc.c b/workbench/devs/netinfo/misc.c index cfec0b9347..927fe3825f 100644 --- a/workbench/devs/netinfo/misc.c +++ b/workbench/devs/netinfo/misc.c @@ -11,36 +11,6 @@ #include "base.h" -/* - * Free nodes of a list (they should all be allocated with AllocVec()) - */ -void FreeListVec(struct NetInfoDevice *nid, struct List *list) -{ - struct Node *entry, *next; - - for (entry = list->lh_Head; next = entry->ln_Succ; entry = next) { - Remove(entry); - FreeVec(entry); - entry = NULL; - } -} - -/* - * Ensure that a node is in list - * return node if it is, NULL otherwise - */ -struct Node *FindNode(struct List *list, struct Node *node) -{ - struct Node *entry, *next; - - for (entry = list->lh_Head; next = entry->ln_Succ; entry = next) - if (entry == node) { - return node; - } - - return NULL; -} - /* * Get next token from string *stringp, where tokens are nonempty * strings separated by characters from delim. diff --git a/workbench/devs/netinfo/misc.h b/workbench/devs/netinfo/misc.h new file mode 100644 index 0000000000..ea9566992d --- /dev/null +++ b/workbench/devs/netinfo/misc.h @@ -0,0 +1,28 @@ +/* + * misc.c + * + * Author: ppessi + * + * Copyright © 1993 AmiTCP/IP Group, + * Helsinki University of Technology, Finland. + */ + +#include + +#include "base.h" + +/* + * Free nodes of a list (they should all be allocated with AllocVec()) + */ +static inline void FreeListVec(struct NetInfoDevice *nid, struct List *list) +{ + struct Node *entry, *next; + + for (entry = list->lh_Head; next = entry->ln_Succ; entry = next) { + Remove(entry); + FreeVec(entry); + entry = NULL; + } +} + +char *strsep(register char **stringp, register const char *delim); diff --git a/workbench/devs/netinfo/netinfo.c b/workbench/devs/netinfo/netinfo.c index f1f8d37513..141e1e2e2b 100644 --- a/workbench/devs/netinfo/netinfo.c +++ b/workbench/devs/netinfo/netinfo.c @@ -109,6 +109,10 @@ **************************************************************************** */ +#ifdef DEBUG +#undef DEBUG +#endif +#define DEBUG 0 #include #include diff --git a/workbench/devs/netinfo/netinfo.conf b/workbench/devs/netinfo/netinfo.conf index 1174f61b52..5919f850ed 100644 --- a/workbench/devs/netinfo/netinfo.conf +++ b/workbench/devs/netinfo/netinfo.conf @@ -1,5 +1,5 @@ ##begin config -version 3.4 +version 3.5 basename NetInfo libbasetype struct NetInfoDevice residentpri 0 diff --git a/workbench/devs/netinfo/passwdunit.c b/workbench/devs/netinfo/passwdunit.c index 8bfd0f1cb0..16c7fa423f 100644 --- a/workbench/devs/netinfo/passwdunit.c +++ b/workbench/devs/netinfo/passwdunit.c @@ -7,6 +7,10 @@ * Helsinki University of Technology, Finland. */ +#ifdef DEBUG +#undef DEBUG +#endif +#define DEBUG 0 #include #include @@ -260,18 +264,29 @@ static struct Ent *ParsePasswd(struct NetInfoDevice *nid, register UBYTE *p) assert(np != NULL); #endif if (i < PASSWDFIELDS || !np) { + if (i < PASSWDFIELDS) { + bug("[NetInfo] %s: ERROR: malformed enry\n", __func__); + } else { + bug("[NetInfo] %s: ERROR: no line-end?\n", __func__); + } return NULL; } - if ((i = StrToLong(field[2], &uid)) <= 0 || field[2][i] != '\0') + if ((i = StrToLong(field[2], &uid)) <= 0 || field[2][i] != '\0') { + bug("[NetInfo] %s: ERROR: failed to parse uid\n", __func__); return NULL; - if ((i = StrToLong(field[3], &gid)) <= 0 || field[3][i] != '\0') + } + if ((i = StrToLong(field[3], &gid)) <= 0 || field[3][i] != '\0') { + bug("[NetInfo] %s: ERROR: failed to parse gid\n", __func__); return NULL; + } txtlen = np - field[0] - (field[4] - field[2]); pe = AllocVec(sizeof(*pe) + txtlen, MEMF_CLEAR); - if (!pe) + if (!pe) { + bug("[NetInfo] %s: Failed to allocate entry storage\n", __func__); return NULL; + } pe->pe_node.ln_Type = ENT_PASSWD; pe->pe_tlen = txtlen; @@ -285,6 +300,8 @@ static struct Ent *ParsePasswd(struct NetInfoDevice *nid, register UBYTE *p) to = stpcopy(pe->pe_passwd->pw_dir = to, field[5]); to = stpcopy(pe->pe_passwd->pw_shell = to, field[6]); + D(bug("[NetInfo] %s: <%d:%d> '%s'\n", __func__, pe->pe_passwd->pw_uid, pe->pe_passwd->pw_gid, pe->pe_passwd->pw_name)); + #if defined(DEBUG) assert(to == pe->pe_passwd->pw_name + txtlen); #endif diff --git a/workbench/devs/netinfo/server.c b/workbench/devs/netinfo/server.c index f09621c862..6abae7dff3 100644 --- a/workbench/devs/netinfo/server.c +++ b/workbench/devs/netinfo/server.c @@ -7,6 +7,10 @@ * Helsinki University of Technology, Finland. */ +#ifdef DEBUG +#undef DEBUG +#endif +#define DEBUG 0 #include #include