]>
Commit | Line | Data |
---|---|---|
2d7360ca | 1 | /* $Header$ |
2 | * | |
d44cee72 | 3 | * Command line oriented Moira List tool. |
2d7360ca | 4 | * |
5 | * by Mark Rosenstein, September 1988. | |
6 | * | |
7 | * Copyright 1989 by the Massachusetts Institute of Technology. | |
1b6b0a57 | 8 | * |
9 | * (c) Copyright 1988 by the Massachusetts Institute of Technology. | |
10 | * For copying and distribution information, please see the file | |
11 | * <mit-copyright.h>. | |
2d7360ca | 12 | */ |
13 | ||
1b6b0a57 | 14 | /* ### Aren't there a lot of sq abstraction barrier violations here? |
15 | Do we need to improve the support for queue operations? */ | |
16 | ||
2d7360ca | 17 | #include <mit-copyright.h> |
9eb9cfb9 | 18 | #include <errno.h> |
2d7360ca | 19 | #include <stdio.h> |
20 | #include <ctype.h> | |
f071d8a7 | 21 | #include <string.h> |
8defc06b | 22 | #include <moira.h> |
23 | #include <moira_site.h> | |
2d7360ca | 24 | |
25 | #ifndef LINT | |
d44cee72 | 26 | static char blanche_rcsid[] = "$Header$"; |
2d7360ca | 27 | #endif |
28 | ||
29 | ||
30 | struct member { | |
31 | int type; | |
32 | char *name; | |
33 | }; | |
34 | ||
b5b167d6 | 35 | /* It is important to membercmp that M_USER < M_LIST < M_STRING */ |
2d7360ca | 36 | #define M_ANY 0 |
37 | #define M_USER 1 | |
38 | #define M_LIST 2 | |
39 | #define M_STRING 3 | |
8c3b414d | 40 | #define M_KERBEROS 4 |
2d7360ca | 41 | |
1b6b0a57 | 42 | /* argument parsing macro */ |
43 | #define argis(a,b) ((strcmp(*arg+1, a) == 0) || (strcmp(*arg+1, b) == 0)) | |
44 | ||
2d7360ca | 45 | /* flags from command line */ |
8b494222 | 46 | int infoflg, verbose, syncflg, memberflg, recursflg, debugflg, noauth; |
8c3b414d | 47 | int showusers, showstrings, showkerberos, showlists; |
2d7360ca | 48 | |
49 | /* various member lists */ | |
50 | struct save_queue *addlist, *dellist, *memberlist, *synclist; | |
51 | ||
52 | char *listname, *whoami; | |
53 | ||
f071d8a7 | 54 | #ifndef POSIX |
2d7360ca | 55 | extern int errno; |
f071d8a7 | 56 | #endif |
2d7360ca | 57 | |
58 | int show_list_info(), show_list_count(), get_list_members(), scream(); | |
135cd06a | 59 | int show_list_members(), membercmp(); |
2d7360ca | 60 | struct member *parse_member(); |
61 | ||
62 | ||
63 | ||
64 | main(argc, argv) | |
65 | int argc; | |
66 | char **argv; | |
67 | { | |
68 | int status; | |
69 | char **arg = argv; | |
37e3ac2d | 70 | char *membervec[3], *motd; |
2d7360ca | 71 | struct member *memberstruct; |
99bdafb8 | 72 | char *server = NULL, *p; |
2d7360ca | 73 | |
74 | /* clear all flags & lists */ | |
1b6b0a57 | 75 | infoflg = verbose = syncflg = memberflg = debugflg = recursflg = 0; |
8c3b414d | 76 | noauth = showusers = showstrings = showkerberos = showlists = 0; |
2d7360ca | 77 | listname = NULL; |
78 | addlist = sq_create(); | |
79 | dellist = sq_create(); | |
80 | memberlist = sq_create(); | |
81 | synclist = sq_create(); | |
82 | whoami = argv[0]; | |
83 | ||
84 | /* parse args, building addlist, dellist, & synclist */ | |
85 | while (++arg - argv < argc) { | |
86 | if (**arg == '-') | |
1b6b0a57 | 87 | { |
88 | if (argis("m", "members")) | |
89 | memberflg++; | |
8b494222 | 90 | else if (argis("u", "users")) |
91 | showusers++; | |
92 | else if (argis("s", "strings")) | |
93 | showstrings++; | |
94 | else if (argis("l", "lists")) | |
95 | showlists++; | |
8c3b414d | 96 | else if (argis("k", "kerberos")) |
97 | showkerberos++; | |
1b6b0a57 | 98 | else if (argis("D", "debug")) |
99 | debugflg++; | |
62a6860a | 100 | else if (argis("i","info")) |
2d7360ca | 101 | infoflg++; |
8b494222 | 102 | else if (argis("n","noauth")) |
103 | noauth++; | |
1b6b0a57 | 104 | else if (argis("v","verbose")) |
2d7360ca | 105 | verbose++; |
1b6b0a57 | 106 | else if (argis("r","recursive")) |
107 | recursflg++; | |
8c3b414d | 108 | else if (argis("S","server")) |
109 | if (arg - argv < argc - 1) { | |
110 | ++arg; | |
111 | server = *arg; | |
112 | } else | |
113 | usage(argv); | |
1b6b0a57 | 114 | else if (argis("a","add")) |
115 | if (arg - argv < argc - 1) { | |
116 | ++arg; | |
117 | if (memberstruct = parse_member(*arg)) | |
118 | sq_save_data(addlist, memberstruct); | |
119 | } else | |
120 | usage(argv); | |
7c02cbdb | 121 | else if (argis("al","addlist")) |
122 | if (arg - argv < argc - 1) { | |
123 | ++arg; | |
124 | get_members_from_file(*arg, addlist); | |
125 | } else | |
126 | usage(argv); | |
1b6b0a57 | 127 | else if (argis("d","delete")) |
128 | if (arg - argv < argc - 1) { | |
129 | ++arg; | |
130 | if (memberstruct = parse_member(*arg)) | |
131 | sq_save_data(dellist, memberstruct); | |
132 | } else | |
133 | usage(argv); | |
7c02cbdb | 134 | else if (argis("dl","deletelist")) |
135 | if (arg - argv < argc - 1) { | |
136 | ++arg; | |
137 | get_members_from_file(*arg, dellist); | |
138 | } else | |
139 | usage(argv); | |
1b6b0a57 | 140 | else if (argis("f","file")) |
141 | if (arg - argv < argc - 1) { | |
1b6b0a57 | 142 | syncflg++; |
143 | ++arg; | |
7c02cbdb | 144 | get_members_from_file(*arg, synclist); |
1b6b0a57 | 145 | } else |
b5b167d6 | 146 | usage(argv); |
1b6b0a57 | 147 | else |
2d7360ca | 148 | usage(argv); |
1b6b0a57 | 149 | } |
2d7360ca | 150 | else if (listname == NULL) |
151 | listname = *arg; | |
152 | else | |
153 | usage(argv); | |
154 | } | |
155 | if (listname == NULL) | |
156 | usage(argv); | |
157 | ||
158 | /* if no other options specified, turn on list members flag */ | |
159 | if (!(infoflg || syncflg || | |
160 | addlist->q_next != addlist || dellist->q_next != dellist)) | |
161 | memberflg++; | |
162 | ||
8c3b414d | 163 | /* If none of {users,strings,lists,kerberos} specified, turn them all on */ |
164 | if (!(showusers || showstrings || showlists || showkerberos)) | |
165 | showusers = showstrings = showlists = showkerberos = 1; | |
8b494222 | 166 | |
d44cee72 | 167 | /* fire up Moira */ |
8defc06b | 168 | if (status = mr_connect(server)) { |
d44cee72 | 169 | com_err(whoami, status, "unable to connect to the Moira server"); |
2d7360ca | 170 | exit(2); |
171 | } | |
8defc06b | 172 | if ( status = mr_motd(&motd) ) { |
d44cee72 | 173 | com_err(whoami, status, "unable to check server status"); |
37e3ac2d | 174 | exit(2); |
175 | } | |
176 | if (motd) { | |
95cd286e | 177 | fprintf(stderr, "The Moira server is currently unavailable:\n%s\n", motd); |
8defc06b | 178 | mr_disconnect(); |
37e3ac2d | 179 | exit(2); |
180 | } | |
181 | ||
8defc06b | 182 | if (!noauth && (status = mr_auth("blanche"))) { |
ece49f32 | 183 | if (status == MR_USER_AUTH) |
184 | com_err(whoami, status, ""); | |
185 | else { | |
186 | com_err(whoami, status, "unable to authenticate to Moira"); | |
187 | com_err(whoami, 0, | |
188 | " Try the -noauth flag if you don't need authentication"); | |
189 | exit(2); | |
190 | } | |
2d7360ca | 191 | } |
192 | ||
193 | /* display list info if requested to */ | |
194 | if (infoflg) { | |
8defc06b | 195 | status = mr_query("get_list_info", 1, &listname, show_list_info,NULL); |
2d7360ca | 196 | if (status) |
d44cee72 | 197 | com_err(whoami, status, "while getting list information"); |
2d7360ca | 198 | if (verbose && !memberflg) { |
8defc06b | 199 | status = mr_query("count_members_of_list", 1, &listname, |
2d7360ca | 200 | show_list_count, NULL); |
201 | if (status) | |
d44cee72 | 202 | com_err(whoami, status, "while getting list count"); |
2d7360ca | 203 | } |
204 | } | |
205 | ||
206 | /* if we're synchronizing to a file, we need to: | |
207 | * get the current members of the list | |
208 | * for each member of the sync file | |
209 | * if they are on the list, remove them from the in-memory copy | |
210 | * if they're not on the list, add them to add-list | |
211 | * if anyone is left on the in-memory copy, put them on the delete-list | |
212 | * lastly, reset memberlist so we can use it again later | |
213 | */ | |
214 | if (syncflg) { | |
8defc06b | 215 | status = mr_query("get_members_of_list", 1, &listname, |
1b6b0a57 | 216 | get_list_members, (char *)memberlist); |
2d7360ca | 217 | if (status) |
d44cee72 | 218 | com_err(whoami, status, "getting members of list %s", listname); |
2d7360ca | 219 | while (sq_get_data(synclist, &memberstruct)) { |
220 | struct save_queue *q; | |
221 | int removed = 0; | |
222 | ||
223 | for (q = memberlist->q_next; q != memberlist; q = q->q_next) { | |
1b6b0a57 | 224 | if (membercmp(q->q_data, memberstruct) == 0) { |
2d7360ca | 225 | q->q_prev->q_next = q->q_next; |
226 | q->q_next->q_prev = q->q_prev; | |
227 | removed++; | |
228 | break; | |
229 | } | |
230 | } | |
231 | if (!removed) | |
232 | sq_save_data(addlist, memberstruct); | |
233 | } | |
234 | while (sq_get_data(memberlist, &memberstruct)) | |
235 | sq_save_data(dellist, memberstruct); | |
236 | sq_destroy(memberlist); | |
237 | memberlist = sq_create(); | |
238 | } | |
239 | ||
240 | /* Process the add list */ | |
241 | while (sq_get_data(addlist, &memberstruct)) { | |
f1f92ff7 | 242 | if ((memberstruct->type == M_STRING || |
243 | memberstruct->type == M_ANY) && | |
244 | strchr(memberstruct->name, '\'')) { | |
245 | fprintf(stderr, "Illegal character \"'\" in \"STRING:%s\", aborting blanche.\n", | |
246 | memberstruct->name); | |
247 | fprintf(stderr, "No changes were made.\n"); | |
248 | exit(1); | |
249 | } | |
99bdafb8 | 250 | /* canonicalize string if necessary */ |
251 | if (memberstruct->type == M_STRING && | |
f071d8a7 | 252 | (p = strchr(memberstruct->name, '@'))) { |
99bdafb8 | 253 | char *host = canonicalize_hostname(strsave(++p)); |
254 | static char **mailhubs = NULL; | |
255 | char *argv[4]; | |
256 | int i, collect(); | |
257 | ||
258 | if (!mailhubs) { | |
259 | argv[0] = "mailhub"; | |
260 | argv[1] = "TYPE"; | |
261 | argv[2] = "*"; | |
262 | mailhubs = (char **)malloc(sizeof(char *)); | |
263 | mailhubs[0] = NULL; | |
f416d13d | 264 | status = mr_query("get_alias", 3, argv, collect, |
265 | (char *)&mailhubs); | |
99bdafb8 | 266 | if (status != MR_SUCCESS && status != MR_NO_MATCH) { |
267 | com_err(whoami, status, | |
268 | " while reading list of MAILHUB servers"); | |
269 | mailhubs[0] = NULL; | |
270 | } | |
271 | } | |
272 | for (i = 0; p = mailhubs[i]; i++) { | |
273 | if (!strcasecmp(p, host)) { | |
274 | host = strsave(memberstruct->name); | |
f071d8a7 | 275 | *(strchr(memberstruct->name, '@')) = 0; |
99bdafb8 | 276 | memberstruct->type = M_ANY; |
277 | fprintf(stderr, "Warning: \"STRING:%s\" converted to \"%s\" because it is a local name.\n", | |
278 | host, memberstruct->name); | |
279 | break; | |
280 | } | |
281 | } | |
282 | free(host); | |
283 | } | |
284 | /* now continue adding member */ | |
2d7360ca | 285 | membervec[0] = listname; |
286 | membervec[2] = memberstruct->name; | |
97f4e1fa | 287 | if (verbose) { |
b5b167d6 | 288 | printf("Adding member "); |
289 | show_list_member(memberstruct); | |
290 | } | |
2d7360ca | 291 | switch (memberstruct->type) { |
292 | case M_ANY: | |
293 | case M_USER: | |
294 | membervec[1] = "USER"; | |
8defc06b | 295 | status = mr_query("add_member_to_list", 3, membervec, scream, NULL); |
296 | if (status == MR_SUCCESS) | |
2d7360ca | 297 | break; |
8defc06b | 298 | else if (status != MR_USER || memberstruct->type != M_ANY) { |
d44cee72 | 299 | com_err(whoami, status, "while adding member %s to %s", |
2d7360ca | 300 | memberstruct->name, listname); |
301 | break; | |
302 | } | |
303 | case M_LIST: | |
304 | membervec[1] = "LIST"; | |
8defc06b | 305 | status = mr_query("add_member_to_list", 3, membervec, |
2d7360ca | 306 | scream, NULL); |
8defc06b | 307 | if (status == MR_SUCCESS) |
2d7360ca | 308 | break; |
8defc06b | 309 | else if (status != MR_LIST || memberstruct->type != M_ANY) { |
d44cee72 | 310 | com_err(whoami, status, "while adding member %s to %s", |
2d7360ca | 311 | memberstruct->name, listname); |
312 | break; | |
313 | } | |
314 | case M_STRING: | |
315 | membervec[1] = "STRING"; | |
8defc06b | 316 | status = mr_query("add_member_to_list", 3, membervec, |
2d7360ca | 317 | scream, NULL); |
8defc06b | 318 | if (status != MR_SUCCESS) |
d44cee72 | 319 | com_err(whoami, status, "while adding member %s to %s", |
2d7360ca | 320 | memberstruct->name, listname); |
f1f92ff7 | 321 | else if (!strchr(memberstruct->name, '@') && |
322 | !strchr(memberstruct->name, '!') && | |
323 | !strchr(memberstruct->name, '%')) { | |
324 | fprintf(stderr, "\nWARNING: \"STRING:%s\" was just added to list \"%s\".\n", | |
325 | memberstruct->name, listname); | |
326 | fprintf(stderr, "\tIf %s is a mailing list, this may cause it to stop working.\n", listname); | |
327 | fprintf(stderr, "\tYou should consider removing \"STRING:%s\" from the list.\n", memberstruct->name); | |
328 | } | |
8c3b414d | 329 | break; |
330 | case M_KERBEROS: | |
331 | membervec[1] = "KERBEROS"; | |
8defc06b | 332 | status = mr_query("add_member_to_list", 3, membervec, |
8c3b414d | 333 | scream, NULL); |
8defc06b | 334 | if (status != MR_SUCCESS) |
d44cee72 | 335 | com_err(whoami, status, "while adding member %s to %s", |
8c3b414d | 336 | memberstruct->name, listname); |
2d7360ca | 337 | } |
338 | } | |
339 | ||
340 | /* Process the delete list */ | |
341 | while (sq_get_data(dellist, &memberstruct)) { | |
342 | membervec[0] = listname; | |
343 | membervec[2] = memberstruct->name; | |
97f4e1fa | 344 | if (verbose) { |
b5b167d6 | 345 | printf("Deleting member "); |
346 | show_list_member(memberstruct); | |
347 | } | |
2d7360ca | 348 | switch (memberstruct->type) { |
349 | case M_ANY: | |
350 | case M_USER: | |
351 | membervec[1] = "USER"; | |
8defc06b | 352 | status = mr_query("delete_member_from_list", 3, membervec, |
2d7360ca | 353 | scream, NULL); |
8defc06b | 354 | if (status == MR_SUCCESS) |
2d7360ca | 355 | break; |
8defc06b | 356 | else if ((status != MR_USER && status != MR_NO_MATCH) || |
2d7360ca | 357 | memberstruct->type != M_ANY) { |
d44cee72 | 358 | com_err(whoami, status, "while deleting member %s from %s", |
2d7360ca | 359 | memberstruct->name, listname); |
360 | break; | |
361 | } | |
362 | case M_LIST: | |
363 | membervec[1] = "LIST"; | |
8defc06b | 364 | status = mr_query("delete_member_from_list", 3, membervec, |
2d7360ca | 365 | scream, NULL); |
8defc06b | 366 | if (status == MR_SUCCESS) |
2d7360ca | 367 | break; |
8defc06b | 368 | else if ((status != MR_LIST && status != MR_NO_MATCH) || |
2d7360ca | 369 | memberstruct->type != M_ANY) { |
40637dba | 370 | if (status == MR_PERM && memberstruct->type == M_ANY) { |
371 | /* M_ANY means we've fallen through from the user case | |
372 | * The fact that we didn't get MR_PERM there indicates | |
373 | * that we had permission to remove the specified member | |
374 | * from the list if it is a user, but not a list. This is | |
375 | * if we are the member in question. Since we exist as a user | |
376 | * we must have gotten the MR_NO_MATCH error, so we will | |
377 | * return that, since it will be less confusing. However, | |
378 | * This will generate the wrongerror if the user was trying | |
379 | * to remove the list with his/her username from a list they | |
380 | * don't administrate, without explicitly specifying "list:". | |
381 | */ | |
382 | status = MR_NO_MATCH; | |
383 | } | |
d44cee72 | 384 | com_err(whoami, status, "while deleting member %s from %s", |
2d7360ca | 385 | memberstruct->name, listname); |
386 | break; | |
387 | } | |
388 | case M_STRING: | |
389 | membervec[1] = "STRING"; | |
8defc06b | 390 | status = mr_query("delete_member_from_list", 3, membervec, |
2d7360ca | 391 | scream, NULL); |
8defc06b | 392 | if (status == MR_STRING && memberstruct->type == M_ANY) |
d44cee72 | 393 | com_err(whoami, 0, " Unable to find member %s to delete from %s", |
2d7360ca | 394 | memberstruct->name, listname); |
8defc06b | 395 | else if (status != MR_SUCCESS) |
d44cee72 | 396 | com_err(whoami, status, "while deleting member %s from %s", |
2d7360ca | 397 | memberstruct->name, listname); |
8c3b414d | 398 | break; |
399 | case M_KERBEROS: | |
400 | membervec[1] = "KERBEROS"; | |
8defc06b | 401 | status = mr_query("delete_member_from_list", 3, membervec, |
8c3b414d | 402 | scream, NULL); |
8defc06b | 403 | if (status != MR_SUCCESS) |
d44cee72 | 404 | com_err(whoami, status, "while deleting member %s from %s", |
8c3b414d | 405 | memberstruct->name, listname); |
2d7360ca | 406 | } |
407 | } | |
408 | ||
409 | /* Display the members of the list now, if requested */ | |
b5b167d6 | 410 | if (memberflg) { |
411 | if (recursflg) | |
412 | recursive_display_list_members(); | |
413 | else { | |
8defc06b | 414 | status = mr_query("get_members_of_list", 1, &listname, |
b5b167d6 | 415 | get_list_members, (char *)memberlist); |
416 | if (status) | |
d44cee72 | 417 | com_err(whoami, status, "while getting members of list %s", |
b5b167d6 | 418 | listname); |
419 | while (sq_get_data(memberlist, &memberstruct)) | |
420 | show_list_member(memberstruct); | |
421 | } | |
422 | } | |
2d7360ca | 423 | |
424 | /* We're done! */ | |
8defc06b | 425 | mr_disconnect(); |
2d7360ca | 426 | exit(0); |
427 | } | |
428 | ||
429 | usage(argv) | |
430 | char **argv; | |
431 | { | |
d465790c | 432 | fprintf(stderr, "Usage: %s listname [options]\n",argv[0]); |
1b6b0a57 | 433 | fprintf(stderr, "Options are\n"); |
434 | fprintf(stderr, " -v | -verbose\n"); | |
435 | fprintf(stderr, " -m | -members\n"); | |
8b494222 | 436 | fprintf(stderr, " -u | -users\n"); |
437 | fprintf(stderr, " -l | -lists\n"); | |
438 | fprintf(stderr, " -s | -strings\n"); | |
8c3b414d | 439 | fprintf(stderr, " -k | -kerberos\n"); |
1b6b0a57 | 440 | fprintf(stderr, " -i | -info\n"); |
441 | fprintf(stderr, " -r | -recursive\n"); | |
442 | fprintf(stderr, " -a | -add member\n"); | |
443 | fprintf(stderr, " -d | -delete member\n"); | |
7c02cbdb | 444 | fprintf(stderr, " -al | -addlist filename\n"); |
445 | fprintf(stderr, " -dl | -deletelist filename\n"); | |
1b6b0a57 | 446 | fprintf(stderr, " -f | -file filename\n"); |
8b494222 | 447 | fprintf(stderr, " -n | -noauth\n"); |
7c02cbdb | 448 | fprintf(stderr, " -S | -server host[:port]\n"); |
1b6b0a57 | 449 | fprintf(stderr, " -D | -debug\n"); |
2d7360ca | 450 | exit(1); |
451 | } | |
452 | ||
453 | ||
b5b167d6 | 454 | /* Display the members stored in the queue */ |
1b6b0a57 | 455 | |
b5b167d6 | 456 | show_list_member(memberstruct) |
457 | struct member *memberstruct; | |
458 | { | |
24582af9 | 459 | char *s = ""; |
8b494222 | 460 | |
461 | switch (memberstruct->type) { | |
462 | case M_USER: | |
463 | if (!showusers) | |
464 | return; | |
465 | s = "USER"; | |
466 | break; | |
467 | case M_LIST: | |
468 | if (!showlists) | |
469 | return; | |
470 | s = "LIST"; | |
471 | break; | |
472 | case M_STRING: | |
473 | if (!showstrings) | |
474 | return; | |
475 | s = "STRING"; | |
476 | break; | |
8c3b414d | 477 | case M_KERBEROS: |
478 | if (!showkerberos) | |
479 | return; | |
480 | s = "KERBEROS"; | |
481 | break; | |
8b494222 | 482 | case M_ANY: |
483 | printf("%s\n", memberstruct->name); | |
484 | return; | |
485 | } | |
486 | ||
487 | if (verbose) | |
488 | printf("%s:%s\n", s, memberstruct->name); | |
489 | else { | |
b5b167d6 | 490 | if (memberstruct->type == M_LIST) |
491 | printf("LIST:%s\n", memberstruct->name); | |
8c3b414d | 492 | else if (memberstruct->type == M_KERBEROS) |
493 | printf("KERBEROS:%s\n", memberstruct->name); | |
b5b167d6 | 494 | else if (memberstruct->type == M_STRING && |
f071d8a7 | 495 | !strchr(memberstruct->name, '@')) |
b5b167d6 | 496 | printf("STRING:%s\n", memberstruct->name); |
497 | else | |
498 | printf("%s\n", memberstruct->name); | |
1b6b0a57 | 499 | } |
500 | } | |
501 | ||
b5b167d6 | 502 | |
503 | /* Show the retrieved information about a list */ | |
504 | ||
2d7360ca | 505 | show_list_info(argc, argv, hint) |
506 | int argc; | |
507 | char **argv; | |
508 | int hint; | |
509 | { | |
510 | printf("List: %s\n", argv[0]); | |
511 | printf("Description: %s\n", argv[9]); | |
512 | printf("Flags: %s, %s, and %s\n", | |
513 | atoi(argv[1]) ? "active" : "inactive", | |
514 | atoi(argv[2]) ? "public" : "private", | |
515 | atoi(argv[3]) ? "hidden" : "visible"); | |
1b6b0a57 | 516 | printf("%s is %sa maillist and is %sa group", argv[0], |
2d7360ca | 517 | atoi(argv[4]) ? "" : "not ", |
518 | atoi(argv[5]) ? "" : "not "); | |
519 | if (atoi(argv[5])) | |
520 | printf(" with GID %d\n", atoi(argv[6])); | |
521 | else | |
522 | printf("\n"); | |
523 | printf("Owner: %s %s\n", argv[7], argv[8]); | |
524 | printf("Last modified by %s with %s on %s\n", argv[11], argv[12], argv[10]); | |
8defc06b | 525 | return(MR_CONT); |
2d7360ca | 526 | } |
527 | ||
528 | ||
b5b167d6 | 529 | /* Show the retrieve list member count */ |
530 | ||
2d7360ca | 531 | show_list_count(argc, argv, hint) |
532 | int argc; | |
533 | char **argv; | |
534 | int hint; | |
535 | { | |
536 | printf("Members: %s\n", argv[0]); | |
537 | } | |
538 | ||
539 | ||
b5b167d6 | 540 | /* Recursively find all of the members of listname, and then display them */ |
541 | ||
542 | recursive_display_list_members() | |
1b6b0a57 | 543 | { |
b5b167d6 | 544 | int status, count, savecount; |
545 | struct save_queue *lists, *members; | |
546 | struct member *m, *m1, *data; | |
547 | ||
548 | lists = sq_create(); | |
549 | members = sq_create(); | |
550 | m = (struct member *) malloc(sizeof(struct member)); | |
551 | m->type = M_LIST; | |
552 | m->name = listname; | |
553 | sq_save_data(lists, m); | |
554 | ||
555 | while (sq_get_data(lists, &m)) { | |
556 | sq_destroy(memberlist); | |
557 | memberlist = sq_create(); | |
558 | if (debugflg) | |
559 | fprintf(stderr, "Fetching members of %s\n", m->name); | |
8defc06b | 560 | status = mr_query("get_members_of_list", 1, &(m->name), |
b5b167d6 | 561 | get_list_members, (char *)memberlist); |
562 | if (status) | |
d44cee72 | 563 | com_err(whoami, status, "while getting members of list %s", m->name); |
b5b167d6 | 564 | while (sq_get_data(memberlist, &m1)) { |
565 | if (m1->type == M_LIST) | |
566 | unique_add_member(lists, m1); | |
567 | else | |
568 | unique_add_member(members, m1); | |
569 | } | |
570 | } | |
571 | savecount = count = sq_count_elts(members); | |
572 | data = (struct member *) malloc(count * sizeof(struct member)); | |
573 | count = 0; | |
574 | while (sq_get_data(members, &m)) | |
f071d8a7 | 575 | memcpy(&data[count++], m, sizeof(struct member)); |
b5b167d6 | 576 | qsort(data, count, sizeof(struct member), membercmp); |
577 | for (count = 0; count < savecount; count++) { | |
578 | show_list_member(&data[count]); | |
579 | } | |
580 | } | |
581 | ||
582 | ||
583 | /* add a struct member to a queue if that member isn't already there. */ | |
584 | ||
585 | unique_add_member(q, m) | |
586 | struct save_queue *q; | |
587 | struct member *m; | |
588 | { | |
589 | struct save_queue *qp; | |
1b6b0a57 | 590 | |
b5b167d6 | 591 | for (qp = q->q_next; qp != q; qp = qp->q_next) { |
592 | if (!membercmp(qp->q_data, m)) | |
593 | return; | |
594 | } | |
595 | sq_save_data(q, m); | |
1b6b0a57 | 596 | } |
597 | ||
b5b167d6 | 598 | |
599 | /* Collect the retrieved members of the list */ | |
600 | ||
2d7360ca | 601 | get_list_members(argc, argv, q) |
602 | int argc; | |
603 | char **argv; | |
604 | struct save_queue *q; | |
605 | { | |
606 | struct member *m; | |
607 | ||
608 | m = (struct member *) malloc(sizeof(struct member)); | |
609 | switch (argv[0][0]) { | |
610 | case 'U': | |
611 | m->type = M_USER; | |
612 | break; | |
613 | case 'L': | |
614 | m->type = M_LIST; | |
615 | break; | |
616 | case 'S': | |
617 | m->type = M_STRING; | |
618 | break; | |
8c3b414d | 619 | case 'K': |
620 | m->type = M_KERBEROS; | |
621 | break; | |
2d7360ca | 622 | } |
623 | m->name = strsave(argv[1]); | |
624 | sq_save_data(q, m); | |
8defc06b | 625 | return(MR_CONT); |
2d7360ca | 626 | } |
627 | ||
628 | ||
b5b167d6 | 629 | /* Called only if a query returns a value that we weren't expecting */ |
630 | ||
2d7360ca | 631 | scream() |
632 | { | |
633 | fprintf(stderr, "Programmer botch\n"); | |
634 | exit(3); | |
635 | } | |
636 | ||
637 | ||
7c02cbdb | 638 | /* Open file, parse members from file, and put them on the specified queue */ |
639 | get_members_from_file(filename, queue) | |
640 | char *filename; | |
641 | struct save_queue *queue; | |
642 | { | |
643 | FILE *in; | |
644 | char buf[BUFSIZ]; | |
645 | struct member *memberstruct; | |
646 | ||
647 | if (!strcmp(filename, "-")) | |
648 | in = stdin; | |
649 | else { | |
650 | in = fopen(filename, "r"); | |
651 | if (!in) { | |
652 | com_err(whoami, errno, "while opening %s for input", filename); | |
653 | exit(2); | |
654 | } | |
655 | } | |
656 | ||
657 | while (fgets(buf, BUFSIZ, in)) | |
658 | if (memberstruct = parse_member(buf)) | |
659 | sq_save_data(queue, memberstruct); | |
660 | if (!feof(in)) | |
661 | com_err(whoami, errno, "while reading from %s", filename); | |
662 | } | |
663 | ||
664 | ||
99bdafb8 | 665 | /* Collect the possible expansions of the alias MAILHUB */ |
666 | ||
667 | int collect(argc, argv, list) | |
668 | int argc; | |
669 | char **argv; | |
670 | char ***list; | |
671 | { | |
672 | int i; | |
673 | ||
674 | for (i = 0; (*list)[i]; i++); | |
675 | *list = (char **)realloc(*list, (i + 2) * sizeof(char *)); | |
676 | (*list)[i] = strsave(argv[2]); | |
677 | (*list)[i+1] = NULL; | |
678 | return(MR_CONT); | |
679 | } | |
680 | ||
681 | ||
b5b167d6 | 682 | /* Parse a line of input, fetching a member. NULL is returned if a member |
7c02cbdb | 683 | * is not found. ';' is a comment character. |
b5b167d6 | 684 | */ |
685 | ||
2d7360ca | 686 | struct member *parse_member(s) |
687 | register char *s; | |
688 | { | |
689 | register struct member *m; | |
7c02cbdb | 690 | char *p, *lastchar; |
2d7360ca | 691 | |
692 | while (*s && isspace(*s)) | |
693 | s++; | |
7c02cbdb | 694 | lastchar = p = s; |
695 | while (*p && *p != '\n' && *p != ';') | |
696 | if (isprint(*p) && !isspace(*p)) | |
697 | lastchar = p++; | |
698 | else | |
699 | p++; | |
700 | lastchar++; | |
701 | *lastchar = 0; | |
2d7360ca | 702 | if (p == s || strlen(s) == 0) |
703 | return(NULL); | |
704 | ||
705 | if ((m = (struct member *) malloc(sizeof(struct member))) == NULL) | |
706 | return(NULL); | |
707 | ||
f071d8a7 | 708 | if (p = strchr(s, ':')) { |
2d7360ca | 709 | *p = 0; |
710 | m->name = ++p; | |
711 | if (!strcasecmp("user", s)) | |
712 | m->type = M_USER; | |
713 | else if (!strcasecmp("list", s)) | |
714 | m->type = M_LIST; | |
715 | else if (!strcasecmp("string", s)) | |
716 | m->type = M_STRING; | |
8c3b414d | 717 | else if (!strcasecmp("kerberos", s)) |
718 | m->type = M_KERBEROS; | |
2d7360ca | 719 | else { |
720 | m->type = M_STRING; | |
721 | *(--p) = ':'; | |
722 | m->name = s; | |
723 | } | |
724 | m->name = strsave(m->name); | |
99bdafb8 | 725 | } else { |
726 | m->name = strsave(s); | |
f071d8a7 | 727 | if (strchr(s, '@') || strchr(s, '!') || strchr(s, '%') || strchr(s, ' ')) |
99bdafb8 | 728 | m->type = M_STRING; |
729 | else | |
730 | m->type = M_ANY; | |
2d7360ca | 731 | } |
2d7360ca | 732 | return(m); |
733 | } | |
734 | ||
735 | ||
1b6b0a57 | 736 | /* |
737 | * This routine two compares members by the following rules: | |
738 | * 1. A USER is less than a LIST | |
739 | * 2. A LIST is less than a STRING | |
740 | * 3. If two members are of the same type, the one alphabetically first | |
741 | * is less than the other | |
742 | * It returs < 0 if the first member is less, 0 if they are identical, and | |
743 | * > 0 if the second member is less (the first member is greater). | |
744 | */ | |
b5b167d6 | 745 | |
746 | int membercmp(m1, m2) | |
747 | struct member *m1, *m2; | |
2d7360ca | 748 | { |
1b6b0a57 | 749 | if (m1->type == M_ANY || m2->type == M_ANY || (m1->type == m2->type)) |
750 | return(strcmp(m1->name, m2->name)); | |
2d7360ca | 751 | else |
1b6b0a57 | 752 | return(m1->type - m2->type); |
2d7360ca | 753 | } |
b5b167d6 | 754 | |
755 | ||
756 | sq_count_elts(q) | |
757 | struct save_queue *q; | |
758 | { | |
759 | char *foo; | |
760 | int count; | |
761 | ||
762 | count = 0; | |
763 | while (sq_get_data(q, &foo)) | |
764 | count++; | |
765 | return(count); | |
766 | } |