1 | /* |
---|
2 | * |
---|
3 | * Copyright (C) 1989 by the Massachusetts Institute of Technology |
---|
4 | * Developed by the MIT Student Information Processing Board (SIPB). |
---|
5 | * For copying information, see the file mit-copyright.h in this release. |
---|
6 | * |
---|
7 | */ |
---|
8 | /* |
---|
9 | * |
---|
10 | * do_misc.c -- Routines to implement the miscellaneous lisp requests |
---|
11 | * |
---|
12 | */ |
---|
13 | |
---|
14 | #include <stdio.h> |
---|
15 | #include <sys/types.h> |
---|
16 | #include <sys/file.h> |
---|
17 | #include <signal.h> |
---|
18 | #include <string.h> |
---|
19 | #include <sys/wait.h> |
---|
20 | #include <ctype.h> |
---|
21 | #include <sys/time.h> |
---|
22 | #include <netdb.h> |
---|
23 | #include "edsc.h" |
---|
24 | |
---|
25 | #define MIN(a,b) ((a)<(b)?(a):(b)) |
---|
26 | |
---|
27 | extern char *edsc_protocol_version, *edsc_version_string; |
---|
28 | |
---|
29 | extern const char *local_realm(); |
---|
30 | |
---|
31 | do_gpv(args) |
---|
32 | char *args; |
---|
33 | { |
---|
34 | printf("(%s \"%s\")\n", edsc_protocol_version, edsc_version_string, |
---|
35 | edsc_protocol_version); |
---|
36 | } |
---|
37 | |
---|
38 | int use_vectors; |
---|
39 | |
---|
40 | typedef struct { |
---|
41 | char *val; |
---|
42 | int ok; |
---|
43 | } gotten_word; |
---|
44 | |
---|
45 | do_set (args) |
---|
46 | char *args; |
---|
47 | { |
---|
48 | char *varname, *value, *tmp, delim; |
---|
49 | |
---|
50 | if (get_word (&args, &tmp, " ", &delim) < 0) { |
---|
51 | printf ("; Missing variable name\n"); |
---|
52 | return; |
---|
53 | } |
---|
54 | varname = tmp; |
---|
55 | if (get_word (&args, &tmp, ")", &delim) < 0) { |
---|
56 | printf ("; Missing value\n"); |
---|
57 | return; |
---|
58 | } |
---|
59 | value = tmp; |
---|
60 | if (args[2]) { |
---|
61 | printf ("; Extra parameters supplied\n"); |
---|
62 | return; |
---|
63 | } |
---|
64 | if (!strcmp (varname, "use_vectors")) |
---|
65 | use_vectors = atoi (value); |
---|
66 | } |
---|
67 | |
---|
68 | do_pacl(args) |
---|
69 | char *args; |
---|
70 | { |
---|
71 | char *cp = args, *mtg_name, delim, *filename; |
---|
72 | name_blk nb; |
---|
73 | dsc_acl *list; |
---|
74 | int code,n; |
---|
75 | register dsc_acl_entry *ae; |
---|
76 | FILE *f; |
---|
77 | |
---|
78 | /* First, we get the output filename */ |
---|
79 | if (get_word(&cp, &filename, " ", &delim) < 0) { |
---|
80 | printf(";Missing filename\n"); |
---|
81 | return; |
---|
82 | } |
---|
83 | |
---|
84 | if (get_word(&cp, &mtg_name, ")", &delim) < 0) { |
---|
85 | printf(";Missing meeting name\n"); |
---|
86 | return; |
---|
87 | } |
---|
88 | |
---|
89 | (void) chmod(filename, 0600); |
---|
90 | if ((f = fopen(filename, "w")) == NULL) { |
---|
91 | printf(";%s\n", error_message(errno)); |
---|
92 | return; |
---|
93 | } |
---|
94 | |
---|
95 | dsc_get_mtg (user_id, mtg_name, &nb, &code); |
---|
96 | if (code != 0) { |
---|
97 | printf(";%s\n", error_message(code)); |
---|
98 | fclose(f); |
---|
99 | return; |
---|
100 | } |
---|
101 | |
---|
102 | dsc_get_acl(&nb, &code, &list); |
---|
103 | if (code) { |
---|
104 | printf(";Can't read ACL: %s\n", error_message(code)); |
---|
105 | fclose(f); |
---|
106 | return; |
---|
107 | } |
---|
108 | for (ae = list->acl_entries, n = list->acl_length; n; --n, ++ae) |
---|
109 | fprintf(f, "%-10s %s\n", ae->modes, ae->principal); |
---|
110 | acl_destroy(list); |
---|
111 | |
---|
112 | fclose(f); |
---|
113 | dsc_destroy_name_blk(&nb); |
---|
114 | printf("()\n"); |
---|
115 | } |
---|
116 | |
---|
117 | static char edsc_principal_buf[120]; |
---|
118 | |
---|
119 | char *fix_principal(principal) |
---|
120 | char *principal; |
---|
121 | { |
---|
122 | strcpy(edsc_principal_buf, principal); |
---|
123 | if (strcmp(edsc_principal_buf,"*") != 0 && |
---|
124 | strchr(edsc_principal_buf, '@') == 0) { |
---|
125 | strcat(edsc_principal_buf, "@"); |
---|
126 | strcat(edsc_principal_buf, local_realm()); |
---|
127 | } |
---|
128 | return(edsc_principal_buf); |
---|
129 | } |
---|
130 | |
---|
131 | do_dacl(args) |
---|
132 | char *args; |
---|
133 | { |
---|
134 | char *cp = args, *mtg_name, delim, *principal; |
---|
135 | name_blk nb; |
---|
136 | int code; |
---|
137 | |
---|
138 | if (get_word(&cp, &principal, " ", &delim) < 0) { |
---|
139 | printf(";Missing principal\n"); |
---|
140 | return; |
---|
141 | } |
---|
142 | |
---|
143 | if (get_word(&cp, &mtg_name, ")", &delim) < 0) { |
---|
144 | printf(";Missing meeting name\n"); |
---|
145 | return; |
---|
146 | } |
---|
147 | |
---|
148 | dsc_get_mtg (user_id, mtg_name, &nb, &code); |
---|
149 | if (code != 0) { |
---|
150 | printf(";%s\n", error_message(code)); |
---|
151 | return; |
---|
152 | } |
---|
153 | |
---|
154 | dsc_delete_access(&nb, fix_principal(principal), &code); |
---|
155 | dsc_destroy_name_blk(&nb); |
---|
156 | if (code != 0) { |
---|
157 | printf(";%s\n", error_message(code)); |
---|
158 | return; |
---|
159 | } |
---|
160 | |
---|
161 | printf("()\n"); |
---|
162 | } |
---|
163 | |
---|
164 | do_sacl(args) |
---|
165 | char *args; |
---|
166 | { |
---|
167 | char *cp = args, *mtg_name, delim, *principal, *modes; |
---|
168 | register char *p; |
---|
169 | name_blk nb; |
---|
170 | int code; |
---|
171 | |
---|
172 | /* First, we get the mode bits */ |
---|
173 | if (get_word(&cp, &modes, " ", &delim) < 0) { |
---|
174 | printf(";Missing ACL modes\n"); |
---|
175 | return; |
---|
176 | } |
---|
177 | |
---|
178 | if (modes[0] && (modes[0] == '\"') && |
---|
179 | (modes[strlen(modes)-1] == '\"')) { |
---|
180 | for (p=modes+1; *(p+1); p++) |
---|
181 | *(p-1) = *p; |
---|
182 | *(p-1) = '\0'; |
---|
183 | } |
---|
184 | |
---|
185 | if (get_word(&cp, &principal, " ", &delim) < 0) { |
---|
186 | printf(";Missing principal\n"); |
---|
187 | return; |
---|
188 | } |
---|
189 | |
---|
190 | if (get_word(&cp, &mtg_name, ")", &delim) < 0) { |
---|
191 | printf(";Missing meeting name\n"); |
---|
192 | return; |
---|
193 | } |
---|
194 | |
---|
195 | dsc_get_mtg (user_id, mtg_name, &nb, &code); |
---|
196 | if (code != 0) { |
---|
197 | printf(";%s\n", error_message(code)); |
---|
198 | return; |
---|
199 | } |
---|
200 | |
---|
201 | dsc_set_access(&nb, fix_principal(principal), modes, &code); |
---|
202 | dsc_destroy_name_blk(&nb); |
---|
203 | if (code != 0) { |
---|
204 | printf(";%s\n", error_message(code)); |
---|
205 | return; |
---|
206 | } |
---|
207 | |
---|
208 | printf("()\n"); |
---|
209 | } |
---|
210 | |
---|
211 | static char buffer[1024]; |
---|
212 | |
---|
213 | do_ls(args) |
---|
214 | char *args; |
---|
215 | { |
---|
216 | char *cp = args, *mtg_name, delim, *filename; |
---|
217 | char *low_string, *high_string, *filter_string; |
---|
218 | name_blk nb; |
---|
219 | trn_info2 t_info; |
---|
220 | mtg_info m_info; |
---|
221 | int code, flags; |
---|
222 | FILE *f; |
---|
223 | trn_nums trn_num, low, high; |
---|
224 | int num_printed = 0; |
---|
225 | |
---|
226 | /* First, we get the output filename */ |
---|
227 | if (get_word(&cp, &filename, " ", &delim) < 0) { |
---|
228 | printf(";Missing filename\n"); |
---|
229 | return; |
---|
230 | } |
---|
231 | |
---|
232 | if (get_word(&cp, &low_string, " ", &delim) < 0) { |
---|
233 | printf(";Missing lower limit\n"); |
---|
234 | return; |
---|
235 | } |
---|
236 | |
---|
237 | if (get_word(&cp, &high_string, " ", &delim) < 0) { |
---|
238 | printf(";Missing upper limit\n"); |
---|
239 | return; |
---|
240 | } |
---|
241 | |
---|
242 | if (get_word(&cp, &filter_string, " ", &delim) < 0) { |
---|
243 | printf(";Missing filter flags\n"); |
---|
244 | return; |
---|
245 | } |
---|
246 | |
---|
247 | if (get_word(&cp, &mtg_name, ")", &delim) < 0) { |
---|
248 | printf(";Missing meeting name\n"); |
---|
249 | return; |
---|
250 | } |
---|
251 | low = atoi(low_string); |
---|
252 | high= atoi(high_string); |
---|
253 | flags = atoi(filter_string); |
---|
254 | |
---|
255 | if ((f = fopen(filename, "w")) == NULL) { |
---|
256 | printf(";%s\n", error_message(errno)); |
---|
257 | return; |
---|
258 | } |
---|
259 | (void) chmod(filename, 0600); |
---|
260 | |
---|
261 | dsc_get_mtg (user_id, mtg_name, &nb, &code); |
---|
262 | if (code != 0) { |
---|
263 | printf(";%s\n", error_message(code)); |
---|
264 | fclose(f); |
---|
265 | return; |
---|
266 | } |
---|
267 | |
---|
268 | trn_num = low; |
---|
269 | if (flags & flag_AREF) { |
---|
270 | dsc_get_trn_info2 (&nb, trn_num, &t_info, &code); |
---|
271 | if (code != 0) { |
---|
272 | printf(";[%04d]: %s\n", trn_num, error_message(code)); |
---|
273 | dsc_destroy_name_blk(&nb); |
---|
274 | fclose(f); |
---|
275 | return; |
---|
276 | } |
---|
277 | trn_num = t_info.fref; |
---|
278 | dsc_destroy_trn_info(&t_info); |
---|
279 | } else { |
---|
280 | dsc_get_mtg_info(&nb,&m_info,&code); |
---|
281 | if (code != 0) { |
---|
282 | printf(";%s\n", error_message(code)); |
---|
283 | dsc_destroy_name_blk(&nb); |
---|
284 | fclose(f); |
---|
285 | return; |
---|
286 | } |
---|
287 | if (trn_num < m_info.first) |
---|
288 | trn_num = m_info.first; |
---|
289 | } |
---|
290 | |
---|
291 | while (trn_num) { |
---|
292 | dsc_get_trn_info2 (&nb, trn_num, &t_info, &code); |
---|
293 | if (code == DELETED_TRN) { |
---|
294 | if (!(flags & (filter_INCLUDE_DELETED | |
---|
295 | filter_ONLY_DELETED))) { |
---|
296 | trn_num++; |
---|
297 | dsc_destroy_trn_info(&t_info); |
---|
298 | if ((trn_num > high) || (flags & flag_AREF)) |
---|
299 | break; |
---|
300 | continue; |
---|
301 | } |
---|
302 | } else if (code) { |
---|
303 | printf("-[%04d]: %s\n", trn_num, error_message(code)); |
---|
304 | goto loop_end; |
---|
305 | } |
---|
306 | if (flags & filter_ONLY_DELETED) { |
---|
307 | if (!(t_info.flags & TRN_FDELETED)) |
---|
308 | goto loop_end; |
---|
309 | } else if (!(flags & filter_INCLUDE_DELETED)) |
---|
310 | if (t_info.flags & TRN_FDELETED) |
---|
311 | goto loop_end; |
---|
312 | if (flags & filter_ONLY_INITIAL) |
---|
313 | if (t_info.pref) |
---|
314 | goto loop_end; |
---|
315 | if (flags & filter_ONLY_TERMINAL) |
---|
316 | if (t_info.nref) |
---|
317 | goto loop_end; |
---|
318 | if (flags & filter_FLAG_SET) |
---|
319 | if (!(t_info.flags & TRN_FLAG1)) |
---|
320 | goto loop_end; |
---|
321 | if (flags & filter_FLAG_RESET) |
---|
322 | if (t_info.flags & TRN_FLAG1) |
---|
323 | goto loop_end; |
---|
324 | list_it(&t_info,f, 1); |
---|
325 | num_printed++; |
---|
326 | loop_end: |
---|
327 | if (flags & |
---|
328 | (filter_INCLUDE_DELETED | filter_ONLY_DELETED)) |
---|
329 | trn_num++; |
---|
330 | else if (flags & flag_AREF) |
---|
331 | trn_num = t_info.nref; |
---|
332 | else |
---|
333 | trn_num = t_info.next; |
---|
334 | if (!(flags & flag_AREF)) |
---|
335 | if (trn_num > high) |
---|
336 | trn_num = 0; |
---|
337 | dsc_destroy_trn_info(&t_info); |
---|
338 | } |
---|
339 | fclose(f); |
---|
340 | dsc_destroy_name_blk(&nb); |
---|
341 | printf("(%d)\n", num_printed); |
---|
342 | } |
---|
343 | |
---|
344 | |
---|
345 | |
---|
346 | static list_it(t_infop, f, long_subjects) |
---|
347 | trn_info2 *t_infop; |
---|
348 | FILE *f; |
---|
349 | int long_subjects; |
---|
350 | { |
---|
351 | char newtime[26], nlines[10]; |
---|
352 | char *cp; |
---|
353 | int len; |
---|
354 | |
---|
355 | strcpy(newtime, short_time(&t_infop->date_entered)); |
---|
356 | /* |
---|
357 | * If author ends with current realm, punt the realm. |
---|
358 | */ |
---|
359 | if ((cp=strchr(t_infop->author, '@')) != NULL) |
---|
360 | if (!strcmp(cp+1, local_realm())) |
---|
361 | *cp = '\0'; |
---|
362 | |
---|
363 | (void) sprintf (nlines, "(%d)", t_infop->num_lines); |
---|
364 | (void) sprintf (buffer, " [%04d]%c%c", |
---|
365 | t_infop->current, |
---|
366 | ((t_infop->flags & TRN_FLAG1) != 0) ? 'F' : ' ', |
---|
367 | ((t_infop->flags & TRN_FDELETED) != 0) ? 'D' : ' '); |
---|
368 | if ((len = MIN(5, 13-strlen (buffer)) - strlen (nlines)) > 0) |
---|
369 | (void) strncat (buffer, " ", len); |
---|
370 | |
---|
371 | if (strlen(t_infop->author) > 15) |
---|
372 | (void) strcpy(&t_infop->author[12], "..."); |
---|
373 | |
---|
374 | (void) sprintf (buffer + strlen (buffer), "%s %s %-15s ", |
---|
375 | nlines, newtime, t_infop->author); |
---|
376 | len = 79 - strlen (buffer); |
---|
377 | |
---|
378 | if (!long_subjects && strlen (t_infop->subject) > len) |
---|
379 | (void) strcpy (&t_infop->subject [len - 3], "..."); |
---|
380 | |
---|
381 | (void) fprintf (f, "%s%s\n", buffer, t_infop->subject); |
---|
382 | |
---|
383 | } |
---|
384 | |
---|