1 /* $Id: group.c 7538 2006-08-26 05:44:06Z eagle $
3 ** Newsgroups and the active file.
9 #include "inn/innconf.h"
14 ** Change to or list the specified newsgroup. If invalid, stay in the old
17 void CMDgroup(int ac, char *av[])
19 static char NOSUCHGROUP[] = NNTP_NOSUCHGROUP;
27 bool hookpresent = false;
30 hookpresent = PY_use_dynamic;
31 #endif /* DO_PYTHON */
33 if (!hookpresent && !PERMcanread) {
35 Reply("%d Permission denied\r\n", NNTP_ACCESS_VAL);
37 Reply("%d Authentication required\r\n", NNTP_AUTH_NEEDED_VAL);
41 /* Parse arguments. */
44 Printf("%d No group specified\r\n", NNTP_XGTITLE_BAD);
47 group = xstrdup(GRPcur);
50 group = xstrdup(av[1]);
53 if (!OVgroupstats(group, &ARTlow, &ARThigh, &count, NULL)) {
54 Reply("%s %s\r\n", NOSUCHGROUP, group);
63 /* Authorize user using Python module method dynamic*/
64 if (PY_dynamic(PERMuser, group, false, &reply) < 0) {
65 syslog(L_NOTICE, "PY_dynamic(): authorization skipped due to no Python dynamic method defined.");
68 syslog(L_TRACE, "PY_dynamic() returned a refuse string for user %s at %s who wants to read %s: %s", PERMuser, ClientHost, group, reply);
69 Reply("%d %s\r\n", NNTP_ACCESS_VAL, reply);
76 #endif /* DO_PYTHON */
82 if (!PERMmatch(PERMreadlist, grplist)) {
83 Reply("%d Permission denied\r\n", NNTP_ACCESS_VAL);
88 Reply("%d Authentication required\r\n", NNTP_AUTH_NEEDED_VAL);
94 /* Close out any existing article, report group stats. */
98 /* Doing a "group" command? */
99 if (strcasecmp(av[0], "group") == 0) {
101 Reply("%d 0 0 0 %s\r\n", NNTP_GROUPOK_VAL, group);
103 /* if we're an NFS reader, check the last nfsreaderdelay
104 * articles in the group to see if they arrived in the
105 * last nfsreaderdelay (default 60) seconds. If they did,
106 * don't report them as we don't want them to appear too
108 if (innconf->nfsreader) {
113 if (ARTlow + innconf->nfsreaderdelay > ARThigh)
116 low = ARThigh - innconf->nfsreaderdelay;
117 handle = OVopensearch(group, low, ARThigh);
119 Reply("%d group disappeared\r\n", NNTP_TEMPERR_VAL);
124 while (OVsearch(handle, &i, NULL, NULL, NULL, &arrived)) {
125 if (arrived + innconf->nfsreaderdelay > now) {
131 OVclosesearch(handle);
133 Reply("%d %d %lu %lu %s\r\n", NNTP_GROUPOK_VAL, count,
134 (unsigned long) ARTlow, (unsigned long) ARThigh, group);
139 if (strcmp(GRPcur, group) != 0) {
140 OVctl(OVCACHEFREE, &boolval);
142 GRPcur = xstrdup(group);
145 GRPcur = xstrdup(group);
147 /* Must be doing a "listgroup" command. We used to just return
148 something bland here ("Article list follows"), but reference NNTP
149 returns the same data as GROUP does and since we have it all
150 available it shouldn't hurt to return the same thing. */
152 Reply("%d 0 0 0 %s\r\n", NNTP_GROUPOK_VAL, group);
154 } else if ((handle = OVopensearch(group, ARTlow, ARThigh)) != NULL) {
155 Reply("%d %d %lu %lu %s\r\n", NNTP_GROUPOK_VAL, count,
156 (unsigned long) ARTlow, (unsigned long) ARThigh, group);
157 while (OVsearch(handle, &i, NULL, NULL, &token, NULL)) {
158 if (PERMaccessconf->nnrpdcheckart && !ARTinstorebytoken(token))
160 Printf("%lu\r\n", (unsigned long) i);
162 OVclosesearch(handle);
167 if (strcmp(GRPcur, group) != 0) {
168 OVctl(OVCACHEFREE, &boolval);
170 GRPcur = xstrdup(group);
173 GRPcur = xstrdup(group);
175 Reply("%s %s\r\n", NOSUCHGROUP, group);
183 ** Report on the number of articles read in the group, and clear the count.
188 char buff[SPOOLNAMEBUFF];
192 strlcpy(buff, GRPcur, sizeof(buff));
193 syslog(L_NOTICE, "%s group %s %lu", ClientHost, buff,
194 (unsigned long) GRParticles);
202 ** Used by ANU-News clients.
216 /* Parse the arguments. */
219 Printf("%d No group specified\r\n", NNTP_XGTITLE_BAD);
227 if (!PERMspecified) {
228 Printf("%d list follows\r\n", NNTP_XGTITLE_OK);
233 /* Open the file, get ready to scan. */
234 if ((qp = QIOopen(NEWSGROUPS)) == NULL) {
235 syslog(L_ERROR, "%s cant open %s %m", ClientHost, NEWSGROUPS);
236 Printf("%d Can't open %s\r\n", NNTP_XGTITLE_BAD, NEWSGROUPS);
239 Printf("%d list follows\r\n", NNTP_XGTITLE_OK);
241 /* Print all lines with matching newsgroup name. */
242 while ((line = QIOread(qp)) != NULL) {
243 for (q = line; *q && !ISWHITE(*q); q++)
247 if (uwildmat(line, p)) {
251 if (!PERMmatch(PERMreadlist, grplist))
255 Printf("%s\r\n", line);