void dofor(){ if( mfetch(rp) ){ mstore( mfetch(rp)-1, rp ); ip=ip+CELL; return; } rp=rp+CELL; bra(); }
void push(){ rp=rp-CELL; mstore(mpop(),rp); }
int main(int argc, char *argv[]) { FILE *fp; char readbuf[LINSIZ]; struct group_entry *gcur; struct member_entry *mcur; char *host, *user, *domain; int ch; char *key = NULL, *data = NULL; int hosts = -1, i; if (argc < 2) usage(); while ((ch = getopt(argc, argv, "uhf:")) != -1) { switch(ch) { case 'u': if (hosts != -1) { warnx("please use only one of -u or -h"); usage(); } hosts = 0; break; case 'h': if (hosts != -1) { warnx("please use only one of -u or -h"); usage(); } hosts = 1; break; case 'f': netgroup = optarg; break; default: usage(); break; } } if (hosts == -1) usage(); if (strcmp(netgroup, "-")) { if ((fp = fopen(netgroup, "r")) == NULL) { err(1, "%s", netgroup); } } else { fp = stdin; } /* Stuff all the netgroup names and members into a hash table. */ while (fgets(readbuf, LINSIZ, fp)) { if (readbuf[0] == '#') continue; /* handle backslash line continuations */ while(readbuf[strlen(readbuf) - 2] == '\\') { fgets((char *)&readbuf[strlen(readbuf) - 2], sizeof(readbuf) - strlen(readbuf), fp); } data = NULL; if ((data = (char *)(strpbrk(readbuf, " \t") + 1)) < (char *)2) continue; key = (char *)&readbuf; *(data - 1) = '\0'; store(gtable, key, data); } fclose(fp); /* * Find all members of each netgroup and keep track of which * group they belong to. */ for (i = 0; i < TABLESIZE; i++) { gcur = gtable[i]; while(gcur) { __setnetgrent(gcur->key); while(__getnetgrent(&host, &user, &domain) != 0) { if (hosts) { if (!(host && !strcmp(host,"-"))) { mstore(mtable, host ? host : "*", gcur->key, domain ? domain : "*"); } } else { if (!(user && !strcmp(user,"-"))) { mstore(mtable, user ? user : "******", gcur->key, domain ? domain : "*"); } } } gcur = gcur->next; } } /* Release resources used by the netgroup parser code. */ __endnetgrent(); /* Spew out the results. */ for (i = 0; i < TABLESIZE; i++) { mcur = mtable[i]; while(mcur) { struct grouplist *tmp; printf ("%s.%s\t", mcur->key, mcur->domain); tmp = mcur->groups; while(tmp) { printf ("%s", tmp->groupname); tmp = tmp->next; if (tmp) printf(","); } mcur = mcur->next; printf ("\n"); } } /* Let the OS free all our resources. */ exit(0); }
// Pushes data onto the data stack void mpush( cell data ){ sp=sp-CELL; mstore( data, sp ); }
int main(int argc, char *argv[]) { struct group_entry *gcur; struct member_entry *mcur; FILE *fp; char *line, *p, *host, *user, *domain; int ch, i; size_t len; char *key; int hosts = -1; if (argc < 2) usage(); while ((ch = getopt(argc, argv, "uhf:")) != -1) { switch(ch) { case 'u': if (hosts != -1) { warnx("please use only one of -u or -h"); usage(); } hosts = 0; break; case 'h': if (hosts != -1) { warnx("please use only one of -u or -h"); usage(); } hosts = 1; break; case 'f': netgroup = optarg; break; default: usage(); break; } } if (hosts == -1) usage(); if (strcmp(netgroup, "-")) { if ((fp = fopen(netgroup, "r")) == NULL) { err(1, "%s", netgroup); } } else { fp = stdin; } /* Stuff all the netgroup names and members into a hash table. */ for (; (line = fparseln(fp, &len, NULL, NULL, FPARSELN_UNESCALL)); free(line)) { if (len == 0) continue; p = line; for (key = p; *p && isspace((unsigned char)*p) == 0; p++) ; while (*p && isspace((unsigned char)*p)) *p++ = '\0'; store(gtable, key, p); } fclose(fp); /* * Find all members of each netgroup and keep track of which * group they belong to. */ for (i = 0; i < TABLESIZE; i++) { gcur = gtable[i]; while (gcur) { rng_setnetgrent(gcur->key); while (rng_getnetgrent(&host, &user, &domain) != 0) { if (hosts) { if (!(host && !strcmp(host,"-"))) { mstore(mtable, host ? host : "*", gcur->key, domain ? domain : "*"); } } else { if (!(user && !strcmp(user,"-"))) { mstore(mtable, user ? user : "******", gcur->key, domain ? domain : "*"); } } } gcur = gcur->next; } } /* Release resources used by the netgroup parser code. */ rng_endnetgrent(); /* Spew out the results. */ for (i = 0; i < TABLESIZE; i++) { mcur = mtable[i]; while (mcur) { struct grouplist *tmp; printf ("%s.%s\t", mcur->key, mcur->domain); tmp = mcur->groups; while (tmp) { printf ("%s", tmp->groupname); tmp = tmp->next; if (tmp) printf(","); } mcur = mcur->next; printf ("\n"); } } /* Let the OS free all our resources. */ exit(0); }