/* * This OS/2 port was hacked by Harald Kipp from the * * Network News Transfer Protocol server * * Phil Lapsley * University of California, Berkeley * Stan Barber * Baylor College of Medicine * * Bug reports related to THIS modified version should be sent to * * harald@os2point.ping.de * harald@sesam.com * Fido: 2:2448/434 * */ #define OS2 #include #include #include #include #include #include #include #include "config.h" #include "globals.h" #include "changi.h" static int domainmatch(char *domainsuffix, char *hostname); /* * host_access -- determine if the client has permission to * read, transfer, and/or post news. * * Returns: Nothing. * * Side effects: None. */ void host_access(PNEWSCLIENT pnc) { int count; char *gdlist = NULL; char *hostornet; char *readperm; char *postperm; char *groups; char *line; char *cp; FILE *fp; pnc -> canread = pnc -> canpost = pnc -> canxfer = 0; if ((fp = xopen(cfg.accessfile, "r")) == NULL) { lperror(cfg.accessfile); return; } hostornet = malloc(MAXBUFLEN); readperm = malloc(MAXBUFLEN); postperm = malloc(MAXBUFLEN); groups = malloc(MAXBUFLEN); line = malloc(MAXBUFLEN); while (fgets(line, MAXBUFLEN, fp) != NULL) { if ((cp = strchr(line, '\n')) != NULL) *cp = '\0'; if ((cp = strchr(line, '#')) != NULL) *cp = '\0'; if (*line == '\0') continue; count = sscanf(line, "%s %s %s %s", hostornet, readperm, postperm, groups); if (count < 4) { if (count < 3) continue; groups[0] = '\0'; /* No groups specified */ } if (domainmatch(hostornet, pnc->remotehost)) { pnc->canread = (readperm[0] == 'r' || readperm[0] == 'R'); pnc->canxfer = (readperm[0] == 'X' || readperm[0] == 'x'); if (readperm[0] == 'B' || readperm[0] == 'b') pnc->canxfer = pnc->canread = 1; pnc->canpost = (postperm[0] == 'p' || postperm[0] == 'P'); if(groups[0]) { if(gdlist) free(gdlist); gdlist = strdup(groups); } break; } if (!stricmp(hostornet, "default")) { pnc->canread = (readperm[0] == 'r' || readperm[0] == 'R'); pnc->canxfer = (readperm[0] == 'X' || readperm[0] == 'x'); if (readperm[0] == 'B' || readperm[0] == 'b') pnc->canxfer = pnc->canread = 1; pnc->canpost = (postperm[0] == 'p' || postperm[0] == 'P'); if(groups[0]) { if(gdlist) free(gdlist); gdlist = strdup(groups); } } } fclose(fp); if(gdlist) { pnc->ngpermcount = get_nglist(&pnc->ngpermlist, gdlist); free(gdlist); } free(hostornet); free(readperm); free(postperm); free(groups); free(line); if(pnc->ngpermcount) lprintf("Access restrictions apply to %s", pnc->remotehost); } /************************************************************************/ /* */ /************************************************************************/ static int domainmatch(char *domainsuffix, char *hostname) { size_t dlen; char *lineptr = domainsuffix; if (!stricmp(domainsuffix, hostname)) return (1); if (*domainsuffix++ != '*') return (0); if (*domainsuffix++ != '.') { lprintf("%s: no period following asterisk: %s", cfg.accessfile, lineptr); return (0); } dlen = strlen(domainsuffix); hostname += (strlen(hostname) - strlen(domainsuffix)); if (!stricmp(domainsuffix, hostname)) return (1); return (0); }