1 #ifndef lint
2 static char sccsid[] = "@(#)group.c 1.12 (Berkeley) 5/11/89";
3 #endif
4
5 #include "common.h"
6
7 /*
8 * GROUP newsgroup
9 *
10 * Change the current group to the specified newsgroup.
11 * We also change our current directory to that newsgroup if
12 * a spool directory for it exists.
13 * If the newsgroup specified is invalid, the old newsgroup
14 * remains selected.
15 */
16
17 void
group(argc,argv)18 group(argc, argv)
19 int argc;
20 char *argv[];
21 {
22 char temp_dir[256];
23 int high_msg, low_msg;
24 char *cp;
25 char *reqlist[2];
26
27 if (argc != 2) {
28 printf("%d Usage: GROUP newsgroup.\r\n", ERR_CMDSYN);
29 (void) fflush(stdout);
30 return;
31 }
32
33 if (!canread) {
34 printf("%d You only have permission to transfer, sorry.\r\n",
35 ERR_ACCESS);
36 (void) fflush(stdout);
37 return;
38 }
39
40 if (index(argv[1], '/') != (char *) NULL) {
41 printf("%d Invalid group name (bad format).\r\n", ERR_NOGROUP);
42 (void) fflush(stdout);
43 return;
44 }
45
46 if (find_group(argv[1], &low_msg, &high_msg) < 0) {
47 printf("%d Invalid group name (not in active).\r\n",
48 ERR_NOGROUP);
49 (void) fflush(stdout);
50 return;
51 }
52
53 reqlist[0] = argv[1];
54 reqlist[1] = NULL;
55
56 if (ngpermcount) {
57 if (ngmatch(s1strneql, ALLBUT,
58 ngpermlist, ngpermcount, reqlist, 1) == 0) {
59 printf("%d You're not allowed to read %s, sorry.\r\n",
60 ERR_ACCESS, argv[1]);
61 (void) fflush(stdout);
62 return;
63 }
64 } else if (ALLBUT == 0) {
65 printf("%d You're not allowed to read %s, sorry.\r\n",
66 ERR_ACCESS, argv[1]);
67 (void) fflush(stdout);
68 return;
69 }
70
71 #if defined(XOVER) || defined(XROVER)
72 close_xfiles();
73 #endif
74 close_crnt();
75 if (group_name)
76 free(group_name);
77 (void) chdir(spooldir);
78 if ((group_name = malloc(strlen(argv[1])+1)) != NULL)
79 strcpy(group_name, argv[1]);
80
81 #ifdef LOG
82 syslog(LOG_INFO, "%s group %s", hostname, argv[1]);
83 #endif
84
85 while ((cp = index(argv[1], '.')) != (char *) NULL)
86 *cp = '/';
87
88 (void) strcpy(temp_dir, spooldir);
89 (void) strcat(temp_dir, "/");
90 (void) strcat(temp_dir, argv[1]);
91
92 /*
93 * (void) because a group can be in the active file
94 * but not have a spool directory. Just leave us
95 * chdired to base spool directory if this fails.
96 */
97 (void) chdir(temp_dir);
98
99 #ifdef LOG
100 ++grps_acsd;
101 #endif
102
103 num_arts = scan_dir(low_msg, high_msg);
104 art_ptr = 0;
105
106 ingroup = 1;
107
108 #ifdef XTHREAD
109 threadfile = thread_name(argv[1]);
110 #endif
111
112 while ((cp = index(argv[1], '/')) != (char *) NULL)
113 *cp = '.';
114
115 printf("%d %d %d %d %s\r\n",
116 OK_GROUP,
117 num_arts,
118 (num_arts > 0 ? art_array[0] : 0),
119 (num_arts > 0 ? art_array[num_arts-1] : 0),
120 argv[1]);
121 (void) fflush(stdout);
122 }
123
124 #ifdef LISTGROUP
125 /*
126 * LISTGROUP [group]
127 *
128 * Lists all article numbers (filenames) in the given group. Used by
129 * newsreaders such as nn and trn for fast validation of a database.
130 * If a group name is given it becomes the current group.
131 *
132 * This command is an extension, and not included in RFC 977.
133 */
134
135 void
xlistgroup(argc,argv)136 xlistgroup(argc, argv)
137 int argc;
138 char *argv[];
139 {
140 register int i;
141
142 if (argc == 2) {
143 ingroup = 0;
144 /* This will output a success or failure message */
145 group(argc, argv);
146 if (!ingroup) {
147 return;
148 }
149 } else if (argc > 2) {
150 printf("%d Usage: LISTGROUP [newsgroup].\r\n", ERR_CMDSYN);
151 (void) fflush(stdout);
152 return;
153 } else if (!ingroup) {
154 printf("%d You are not currently in a newsgroup.\r\n",
155 ERR_NCING);
156 (void) fflush(stdout);
157 return;
158 } else if (!canread) {
159 printf("%d You only have permission to transfer, sorry.\r\n",
160 ERR_ACCESS);
161 (void) fflush(stdout);
162 return;
163 } else {
164 /* output a success message when no group name is given */
165 printf("%d %d %d %d %s\r\n",
166 OK_GROUP,
167 num_arts,
168 (num_arts > 0 ? art_array[0] : 0),
169 (num_arts > 0 ? art_array[num_arts-1] : 0),
170 group_name? group_name : "(current group)");
171 }
172
173 #ifdef LOG
174 syslog(LOG_INFO, "%s listgroup", hostname);
175 #endif
176 for (i = 0; i < num_arts; i++) {
177 printf("%d\r\n", art_array[i]);
178 }
179 putline(".");
180 (void) fflush(stdout);
181 }
182
183 #endif /* LISTGROUP */
184