/* * 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 * */ #include #include #include #include #include #include #include #include #include #include #include "config.h" #include "globals.h" #include "nntp.h" #include "changi.h" /* * GROUP newsgroup * * Change the current group to the specified newsgroup. * We also change our current directory to that newsgroup if * a spool directory for it exists. * If the newsgroup specified is invalid, the old newsgroup * remains selected. */ void group(PNEWSCLIENT pnc, int argc, char *argv[]) { long high_msg, low_msg; char *cp; char *reqlist[2]; if (argc != 2) { so_printf(pnc -> s, "%d Usage: GROUP newsgroup.\r\n", ERR_CMDSYN); lprintf("%s: Syntax error in group command", pnc->remotehost); return; } if (!pnc -> canread) { so_printf(pnc -> s, "%d You only have permission to transfer, sorry.\r\n", ERR_ACCESS); lprintf("%s: Illegal read access", pnc->remotehost); return; } /* * Do not allow groupnames containing slash/backslash. */ if (strchr(argv[1], '/') || strchr(argv[1], '\\')) { so_printf(pnc -> s, "%d Invalid group name (bad format).\r\n", ERR_NOGROUP); lprintf("%s: Bad groupname format in group command", pnc->remotehost); return; } if (find_active(cfg.activefile, argv[1], &low_msg, &high_msg) < 0) { so_printf(pnc -> s, "%d Invalid group name (not in active).\r\n", ERR_NOGROUP); return; } reqlist[0] = argv[1]; reqlist[1] = NULL; if (pnc->ngpermcount) { if (ngmatch(s1strneql, 1, pnc->ngpermlist, pnc->ngpermcount, reqlist, 1) == 0) { so_printf(pnc -> s, "%d You're not allowed to read %s, sorry.\r\n", ERR_ACCESS, argv[1]); lprintf("%s: Illegal newsgroup access", pnc->remotehost); return; } } if (pnc -> art_fp) { fclose(pnc -> art_fp); pnc -> art_fp = NULL; } strcpy(pnc -> group_name, argv[1]); while ((cp = strchr(argv[1], '.')) != (char *)NULL) *cp = '\\'; strcpy(pnc->mydir, cfg.newsdir); strcat(pnc->mydir, "\\"); strcat(pnc->mydir, argv[1]); pnc -> num_arts = scan_dir(pnc->mydir, low_msg, high_msg, pnc -> art_array, MAX_ARTICLES); pnc -> art_ptr = 0; pnc -> ingroup = 1; while ((cp = strchr(argv[1], '\\')) != (char *)NULL) *cp = '.'; so_printf(pnc -> s, "%d %d %ld %ld %s\r\n", OK_GROUP, pnc -> num_arts, (pnc -> num_arts > 0 ? pnc -> art_array[0] : 0L), (pnc -> num_arts > 0 ? pnc -> art_array[pnc -> num_arts - 1] : 0L), argv[1]); } /* * LISTGROUP [group] * * Lists all article numbers (filenames) in the given group. Used by * newsreaders such as nn and trn for fast validation of a database. * If a group name is given it becomes the current group. * * This command is an extension, and not included in RFC 977. */ void listgroup(PNEWSCLIENT pnc, int argc, char *argv[]) { register int i; if (argc == 2) { pnc -> ingroup = 0; /* This will output a success or failure message */ group(pnc, argc, argv); if (!pnc -> ingroup) { return; } } else if (argc > 2) { so_printf(pnc -> s, "%d Usage: LISTGROUP [newsgroup].\r\n", ERR_CMDSYN); lprintf("%s: Syntax error in listgroup command", pnc->remotehost); return; } else if (!pnc -> ingroup) { so_printf(pnc -> s, "%d You are not currently in a newsgroup.\r\n", ERR_NCING); return; } else if (!pnc -> canread) { so_printf(pnc -> s, "%d You only have permission to transfer, sorry.\r\n", ERR_ACCESS); lprintf("%s: Illegal read access", pnc->remotehost); return; } else { /* output a success message when no group name is given */ so_printf(pnc -> s, "%d %d %ld %ld %s\r\n", OK_GROUP, pnc -> num_arts, (pnc -> num_arts > 0 ? pnc -> art_array[0] : 0L), (pnc -> num_arts > 0 ? pnc -> art_array[pnc -> num_arts - 1] : 0L), pnc -> group_name ? pnc -> group_name : "(current group)"); } for (i = 0; i < pnc -> num_arts; i++) if(so_printf(pnc -> s, "%ld\r\n", pnc -> art_array[i]) == -1) return; so_puts(pnc -> s, ".\r\n"); }