- 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);
+/* --- A data type --- */
+
+typedef struct name__scanctx {
+ char *name; /* Netgroup name prefixed with `?_'*/
+ unsigned f; /* Various interesting flags */
+ name *h; /* Name entry for hosts */
+ name *u; /* Name entry for users */
+} name__scanctx;
+
+enum { f_host = 1, f_user = 2 };
+
+/* --- And now for the real code --- */
+
+static int name__scan(netg *n, const char *host, const char *user,
+ const char *domain, void *ctx)
+{
+ name__scanctx *sc = ctx;
+
+ /* --- Add the host to the hosts class --- */
+
+ if (sc->f & f_host && host) {
+ struct hostent *h;
+ struct in_addr in;
+ const char *a;
+
+ /* --- First ensure that I have a host class --- */
+
+ if (!sc->h) {
+ sc->name[0] = 'h';
+ sc->h = name__get(sc->name, clType_host);
+ if (!sc->h) {
+ sc->f &= ~f_host;
+ goto done_host;
+ }
+ }
+
+ /* --- Now that I've done that, try to add the host --- *
+ *
+ * I'll turn it into an IP address. There's less chance of confusion
+ * that way.
+ */
+
+ if ((h = gethostbyname(host)) == 0)
+ goto done_host;
+ memcpy(&in, h->h_addr, sizeof(in));
+ if ((a = inet_ntoa(in)) == 0)
+ goto done_host;
+ sc->h->c = class_addString(sc->h->c, a);
+ done_host:;
+ }
+
+ /* --- Add the user to the users class --- */
+
+ if (sc->f & f_user && user) {
+ struct passwd *pw;
+
+ /* --- First ensure that I have a user class --- */
+
+ if (!sc->u) {
+ sc->name[0] = 'u';
+ sc->u = name__get(sc->name, clType_user);
+ if (!sc->u) {
+ sc->f &= ~f_user;
+ goto done_user;