]>
Commit | Line | Data |
---|---|---|
402461ad | 1 | #if (!defined(lint) && !defined(SABER)) |
08345b74 | 2 | static char rcsid_module_c[] = "$Header$"; |
3 | #endif lint | |
4 | ||
8defc06b | 5 | /* This is the file lists.c for the MOIRA Client, which allows a nieve |
6 | * user to quickly and easily maintain most parts of the MOIRA database. | |
0a2c64cb | 7 | * It Contains: All list manipulation functions, except delete. |
08345b74 | 8 | * |
0a2c64cb | 9 | * Created: 4/12/88 |
10 | * By: Chris D. Peterson | |
08345b74 | 11 | * |
12 | * $Source$ | |
13 | * $Author$ | |
14 | * $Header$ | |
15 | * | |
0a2c64cb | 16 | * Copyright 1988 by the Massachusetts Institute of Technology. |
08345b74 | 17 | * |
18 | * For further information on copyright and distribution | |
19 | * see the file mit-copyright.h | |
20 | */ | |
21 | ||
22 | #include <stdio.h> | |
f071d8a7 | 23 | #include <string.h> |
8defc06b | 24 | #include <moira.h> |
25 | #include <moira_site.h> | |
08345b74 | 26 | #include <menu.h> |
27 | ||
28 | #include "mit-copyright.h" | |
0a2c64cb | 29 | #include "defs.h" |
30 | #include "f_defs.h" | |
08345b74 | 31 | #include "globals.h" |
08345b74 | 32 | |
33 | #define LIST 0 | |
34 | #define MEMBERS 1 | |
35 | #define GLOM 2 | |
075fe5bb | 36 | #define ACE_USE 3 |
08345b74 | 37 | |
85ca828a | 38 | #define DEFAULT_ACTIVE DEFAULT_YES |
39 | #define DEFAULT_PUBLIC DEFAULT_YES | |
40 | #define DEFAULT_HIDDEN DEFAULT_NO | |
41 | #define DEFAULT_MAILLIST DEFAULT_YES | |
42 | #define DEFAULT_GROUP DEFAULT_NO | |
43 | #define DEFAULT_GID UNIQUE_GID | |
075fe5bb | 44 | #define DEFAULT_ACE_TYPE "user" |
45 | #define DEFAULT_ACE_NAME (user) | |
85ca828a | 46 | #define DEFAULT_DESCRIPTION DEFAULT_COMMENT |
47 | ||
461c03b6 | 48 | /* globals only for this file. */ |
49 | ||
85ca828a | 50 | static char current_list[BUFSIZ]; |
461c03b6 | 51 | |
075fe5bb | 52 | /* Function Name: PrintListAce |
53 | * Description: This function prints the list ace information. | |
402461ad | 54 | * Arguments: info - an info structure. |
55 | * Returns: none. | |
56 | */ | |
57 | ||
58 | static void | |
075fe5bb | 59 | PrintListAce(info) |
402461ad | 60 | char ** info; |
61 | { | |
62 | char buf[BUFSIZ]; | |
63 | ||
6d9ec158 | 64 | sprintf(buf, "Item: %-20s Name: %s", info[ACE_TYPE], |
075fe5bb | 65 | info[ACE_NAME]); |
402461ad | 66 | Put_message(buf); |
67 | } | |
68 | ||
08345b74 | 69 | /* Function Name: PrintListInfo |
70 | * Description: This function Prints out the List info in a coherent form. | |
71 | * Arguments: info - the List info. | |
72 | * Returns: none. | |
73 | */ | |
74 | ||
402461ad | 75 | static void |
08345b74 | 76 | PrintListInfo(info) |
77 | char ** info; | |
78 | { | |
79 | char buf[BUFSIZ]; | |
80 | ||
402461ad | 81 | Put_message(" "); |
82 | (void) sprintf(buf, "%20sList: %s", "", info[L_NAME]); | |
08345b74 | 83 | (void) Put_message(buf); |
85ca828a | 84 | (void) sprintf(buf, "Description: %s", info[L_DESC]); |
08345b74 | 85 | (void) Put_message(buf); |
86 | if ( atoi(info[L_MAILLIST])) | |
87 | Put_message("This list is a mailing list."); | |
88 | else | |
89 | Put_message("This list is NOT a mailing list."); | |
90 | if ( atoi(info[L_GROUP]) ) { | |
589fdf24 | 91 | (void) sprintf(buf,"This list is a Group and its ID number is %s", |
08345b74 | 92 | info[L_GID]); |
93 | Put_message(buf); | |
94 | } | |
95 | else | |
402461ad | 96 | Put_message("This list is NOT a Group."); |
08345b74 | 97 | |
075fe5bb | 98 | if (strcmp(info[L_ACE_TYPE],"NONE") == 0) |
08345b74 | 99 | Put_message("This list has no Administrator, how strange?!"); |
100 | else { | |
402461ad | 101 | sprintf(buf, "The Administrator of this list is the %s: %s", |
075fe5bb | 102 | info[L_ACE_TYPE], info[L_ACE_NAME]); |
08345b74 | 103 | Put_message(buf); |
104 | } | |
105 | ||
106 | (void) sprintf(buf, "This list is: %s, %s, and %s", | |
85ca828a | 107 | atoi(info[L_ACTIVE]) ? "active" : "inactive", |
108 | atoi(info[L_PUBLIC]) ? "public" : "private", | |
109 | atoi(info[L_HIDDEN]) ? "hidden" : "visible"); | |
08345b74 | 110 | (void) Put_message(buf); |
075fe5bb | 111 | sprintf(buf, MOD_FORMAT, info[L_MODBY], info[L_MODTIME], info[L_MODWITH]); |
08345b74 | 112 | (void) Put_message(buf); |
113 | } | |
114 | ||
115 | /* Function Name: GetListInfo | |
116 | * Description: Stores all info about a group of lists in a queue. | |
117 | * Arguments: type - type of info to store. | |
118 | * name - name of the info. | |
119 | * Returns: the first element in the queue. | |
120 | */ | |
121 | ||
122 | /* ARGSUSED */ | |
123 | struct qelem * | |
124 | GetListInfo(type, name1, name2) | |
125 | int type; | |
461c03b6 | 126 | char * name1, *name2; |
08345b74 | 127 | { |
128 | char *args[2]; | |
461c03b6 | 129 | struct qelem * elem = NULL; |
130 | register int status; | |
08345b74 | 131 | |
132 | switch(type) { | |
133 | case LIST: | |
134 | args[0] = name1; | |
8defc06b | 135 | if ( (status = do_mr_query("get_list_info", 1, args, |
08345b74 | 136 | StoreInfo, (char *) &elem)) != 0) { |
85ca828a | 137 | com_err(program_name, status, " in get_list_info"); |
08345b74 | 138 | return (NULL); |
139 | } | |
140 | break; | |
141 | case MEMBERS: | |
142 | args[0] = name1; | |
8defc06b | 143 | if ( (status = do_mr_query("get_members_of_list", 1, args, |
08345b74 | 144 | StoreInfo, (char *) &elem)) != 0) { |
85ca828a | 145 | com_err(program_name, status, " in get_members_of_list"); |
08345b74 | 146 | return (NULL); |
147 | } | |
148 | break; | |
149 | case GLOM: | |
150 | args[0] = name1; | |
151 | args[1] = name2; | |
8defc06b | 152 | if ( (status = do_mr_query("get_lists_of_member", 2, args, |
08345b74 | 153 | StoreInfo, (char *) &elem)) != 0) { |
85ca828a | 154 | com_err(program_name, status, " in get_list_of_members"); |
08345b74 | 155 | return (NULL); |
156 | } | |
157 | break; | |
075fe5bb | 158 | case ACE_USE: |
08345b74 | 159 | args[0] = name1; |
160 | args[1] = name2; | |
8defc06b | 161 | if ( (status = do_mr_query("get_ace_use", 2, args, |
08345b74 | 162 | StoreInfo, (char *) &elem)) != 0) { |
075fe5bb | 163 | com_err(program_name, status, " in get_ace_use"); |
08345b74 | 164 | return (NULL); |
165 | } | |
166 | break; | |
167 | } | |
168 | return( QueueTop(elem) ); | |
169 | } | |
170 | ||
171 | /* Function Name: AskListInfo. | |
172 | * Description: This function askes the user for information about a | |
173 | * machine and saves it into a structure. | |
174 | * Arguments: info - a pointer the the structure to put the | |
175 | * info into. | |
176 | * name - add a newname field? (T/F) | |
177 | * Returns: SUB_ERROR or SUB_NORMAL. | |
178 | */ | |
179 | ||
180 | char ** | |
461c03b6 | 181 | AskListInfo(info, name) |
08345b74 | 182 | char ** info; |
183 | Bool name; | |
184 | { | |
461c03b6 | 185 | char temp_buf[BUFSIZ], *newname; |
08345b74 | 186 | |
402461ad | 187 | Put_message(" "); |
188 | sprintf(temp_buf,"Setting information of list %s.",info[L_NAME]); | |
08345b74 | 189 | Put_message(temp_buf); |
402461ad | 190 | Put_message(" "); |
08345b74 | 191 | |
192 | if (name) { | |
5df6f171 | 193 | while (1) { |
194 | newname = Strsave(info[L_NAME]); | |
eb5eb5de | 195 | if (GetValueFromUser("The new name for this list", &newname) == |
196 | SUB_ERROR) | |
197 | return(NULL); | |
5df6f171 | 198 | if (ValidName(newname)) |
199 | break; | |
200 | } | |
08345b74 | 201 | } |
eb5eb5de | 202 | if (GetYesNoValueFromUser("Is this an active list", &info[L_ACTIVE]) == |
203 | SUB_ERROR) | |
204 | return(NULL); | |
205 | if (GetYesNoValueFromUser("Is this a public list", &info[L_PUBLIC]) == | |
206 | SUB_ERROR) | |
207 | return(NULL); | |
208 | if (GetYesNoValueFromUser("Is this a hidden list", &info[L_HIDDEN]) == | |
209 | SUB_ERROR) | |
210 | return(NULL); | |
211 | if (GetYesNoValueFromUser("Is this a maillist", &info[L_MAILLIST]) == | |
212 | SUB_ERROR) | |
213 | return(NULL); | |
214 | if (GetYesNoValueFromUser("Is this a group", &info[L_GROUP]) == SUB_ERROR) | |
215 | return(NULL); | |
85ca828a | 216 | if (atoi(info[L_GROUP])) |
eb5eb5de | 217 | if (GetValueFromUser("What is the GID for this group.", &info[L_GID]) == |
218 | SUB_ERROR) | |
219 | return(NULL); | |
85ca828a | 220 | |
eb5eb5de | 221 | if (GetTypeFromUser("What Type of Administrator", "ace_type", |
222 | &info[L_ACE_TYPE]) == SUB_ERROR) | |
223 | return(NULL); | |
20b2d2f0 | 224 | if ((strcasecmp(info[L_ACE_TYPE], "NONE") != 0) && |
225 | (strcasecmp(info[L_ACE_TYPE], "none") != 0)) { | |
226 | sprintf(temp_buf, "Which %s will be the administrator of this list: ", | |
227 | info[L_ACE_TYPE]); | |
eb5eb5de | 228 | if (GetValueFromUser(temp_buf, &info[L_ACE_NAME]) == SUB_ERROR) |
229 | return(NULL); | |
20b2d2f0 | 230 | } |
eb5eb5de | 231 | if (GetValueFromUser("Description: ", &info[L_DESC]) == SUB_ERROR) |
232 | return(NULL); | |
08345b74 | 233 | |
234 | FreeAndClear(&info[L_MODTIME], TRUE); | |
235 | FreeAndClear(&info[L_MODBY], TRUE); | |
236 | FreeAndClear(&info[L_MODWITH], TRUE); | |
237 | /* | |
238 | * Slide the newname into the #2 slot, this screws up all future references | |
239 | * to this list. | |
240 | */ | |
241 | if (name) /* slide the newname into the #2 slot. */ | |
242 | SlipInNewName(info, newname); | |
243 | ||
244 | return(info); | |
245 | } | |
246 | ||
247 | /* -------------- List functions. -------------- */ | |
248 | ||
249 | /* Function Name: ShowListInfo. | |
250 | * Description: shows info on a list. | |
461c03b6 | 251 | * Arguments: argc, argv - name of list in argv[1]. |
08345b74 | 252 | * Returns: DM status code. |
253 | */ | |
254 | ||
85ca828a | 255 | /* ARGSUSED */ |
08345b74 | 256 | int |
257 | ShowListInfo(argc, argv) | |
258 | int argc; | |
259 | char **argv; | |
260 | { | |
261 | struct qelem *top, *list; | |
262 | ||
461c03b6 | 263 | top = list = GetListInfo(LIST, argv[1], (char *) NULL); |
08345b74 | 264 | while (list != NULL) { |
265 | PrintListInfo( (char **) list->q_data); | |
266 | list = list->q_forw; | |
267 | } | |
268 | ||
269 | FreeQueue(top); | |
270 | return(DM_NORMAL); | |
271 | } | |
272 | ||
402461ad | 273 | /* Function Name: RealUpdateList |
274 | * Description: performs the actual update of the list. | |
275 | * Arguments: info - all information needed to update the list. | |
276 | * junk - an UNUSED boolean. | |
277 | * Returns: none. | |
278 | */ | |
279 | ||
280 | /* ARGSUSED */ | |
281 | static void | |
282 | RealUpdateList(info, junk) | |
283 | char ** info; | |
284 | Bool junk; | |
285 | { | |
286 | register int stat; | |
287 | char ** args; | |
288 | ||
eb5eb5de | 289 | if ((args = AskListInfo(info, TRUE)) == NULL) { |
290 | Put_message("Aborted."); | |
291 | return; | |
292 | } | |
8defc06b | 293 | if ( (stat = do_mr_query("update_list", CountArgs(args), args, |
294 | Scream, (char *) NULL)) != MR_SUCCESS) { | |
402461ad | 295 | com_err(program_name, stat, " in UpdateList."); |
296 | Put_message("List ** NOT ** Updated."); | |
297 | } | |
298 | else | |
299 | Put_message("List successfully updated."); | |
300 | } | |
301 | ||
08345b74 | 302 | /* Function Name: UpdateList |
85ca828a | 303 | * Description: updates the information on a list. |
08345b74 | 304 | * Arguments: argc, argv - name of list in argv[1]. |
305 | * Returns: DM Status code. | |
306 | */ | |
307 | ||
85ca828a | 308 | /* ARGSUSED */ |
08345b74 | 309 | int |
310 | UpdateList(argc, argv) | |
311 | int argc; | |
312 | char **argv; | |
313 | { | |
402461ad | 314 | struct qelem *top; |
315 | ||
316 | top = GetListInfo(LIST, argv[1], (char *) NULL); | |
317 | QueryLoop(top, NullPrint, RealUpdateList, "Update the list"); | |
08345b74 | 318 | |
08345b74 | 319 | FreeQueue(top); |
320 | return(DM_NORMAL); | |
321 | } | |
322 | ||
85ca828a | 323 | /* Function Name: SetDefaults |
324 | * Description: sets defaults for AddList function | |
325 | * Arguments: info - the array to add them to. | |
326 | * name - name of the program to add. | |
327 | * Returns: defaults - the default information. | |
328 | */ | |
329 | ||
330 | static char ** | |
331 | SetDefaults(info, name) | |
332 | char ** info; | |
333 | char * name; | |
334 | { | |
335 | info[L_NAME] = Strsave(name); | |
336 | info[L_ACTIVE] = Strsave(DEFAULT_ACTIVE); | |
337 | info[L_PUBLIC] = Strsave(DEFAULT_PUBLIC); | |
338 | info[L_HIDDEN] = Strsave(DEFAULT_HIDDEN); | |
339 | info[L_MAILLIST] = Strsave(DEFAULT_MAILLIST); | |
340 | info[L_GROUP] = Strsave(DEFAULT_GROUP); | |
341 | info[L_GID] = Strsave(DEFAULT_GID); | |
075fe5bb | 342 | info[L_ACE_TYPE] = Strsave(DEFAULT_ACE_TYPE); |
343 | info[L_ACE_NAME] = Strsave(DEFAULT_ACE_NAME); | |
85ca828a | 344 | info[L_DESC] = Strsave(DEFAULT_DESCRIPTION); |
345 | info[L_MODTIME] = info[L_MODBY] = info[L_MODWITH] = info[L_END] = NULL; | |
346 | return(info); | |
347 | } | |
348 | ||
08345b74 | 349 | /* Function Name: AddList |
350 | * Description: | |
351 | * Arguments: argc, argv - name of list in argv[1]. | |
402461ad | 352 | * Returns: SUB_ERROR if list not created. |
08345b74 | 353 | */ |
354 | ||
85ca828a | 355 | /* ARGSUSED */ |
08345b74 | 356 | int |
357 | AddList(argc, argv) | |
358 | int argc; | |
359 | char **argv; | |
360 | { | |
361 | static char *info[MAX_ARGS_SIZE], **add_args; | |
402461ad | 362 | int status, ret_code = SUB_NORMAL; |
08345b74 | 363 | |
5df6f171 | 364 | if (!ValidName(argv[1])) |
365 | return(DM_NORMAL); | |
8defc06b | 366 | status = do_mr_query("get_list_info", 1, argv + 1, NullFunc, |
461c03b6 | 367 | (char *) NULL); |
8defc06b | 368 | if (status != MR_NO_MATCH) { |
369 | if (status == MR_SUCCESS) | |
08345b74 | 370 | Put_message("This list already exists."); |
371 | else | |
461c03b6 | 372 | com_err(program_name, status, " in AddList."); |
402461ad | 373 | return(SUB_ERROR); |
08345b74 | 374 | } |
375 | ||
eb5eb5de | 376 | if ((add_args = AskListInfo(SetDefaults(info,argv[1]), FALSE)) == NULL) { |
377 | Put_message("Aborted."); | |
378 | return(SUB_ERROR); | |
379 | } | |
08345b74 | 380 | |
8defc06b | 381 | if ( (status = do_mr_query("add_list", CountArgs(add_args), add_args, |
382 | Scream, (char *) NULL)) != MR_SUCCESS) { | |
461c03b6 | 383 | com_err(program_name, status, " in AddList."); |
08345b74 | 384 | Put_message("List Not Created."); |
402461ad | 385 | ret_code = SUB_ERROR; |
08345b74 | 386 | } |
387 | ||
388 | FreeInfo(info); | |
402461ad | 389 | return(ret_code); |
08345b74 | 390 | } |
391 | ||
392 | /* Function Name: Instructions | |
393 | * Description: This func prints out instruction on manipulating lists. | |
394 | * Arguments: none | |
395 | * Returns: DM Status Code. | |
396 | */ | |
397 | ||
398 | int | |
461c03b6 | 399 | ListHelp() |
08345b74 | 400 | { |
401 | static char * message[] = { | |
402461ad | 402 | "Listmaint handles the creation, deletion, and updating of lists.", |
403 | "A list can be a mailing list, a group list, or both.", | |
08345b74 | 404 | "The concept behind lists is that a list has an owner", |
402461ad | 405 | "- administrator - and members.", |
406 | "The administrator of a list may be another list.", | |
08345b74 | 407 | "The members of a list can be users (login names), other lists,", |
402461ad | 408 | "or address strings.", |
08345b74 | 409 | "You can use certain keys to do the following:", |
402461ad | 410 | " Refresh the screen - Type ctrl-L.", |
411 | " Escape from a function - Type ctrl-C.", | |
412 | " Suspend the program (temporarily) - Type ctrl-Z.", | |
08345b74 | 413 | NULL, |
461c03b6 | 414 | }; |
08345b74 | 415 | |
416 | return(PrintHelp(message)); | |
417 | } | |
418 | ||
419 | /*-*-* LISTMAINT UPDATE MENU *-*-*/ | |
420 | ||
421 | /* Function Name: ListmaintMemberMenuEntry | |
422 | * Description: entry routine into the listmaint member menu. | |
423 | * Arguments: m - the member menu. | |
424 | * argc, argv - name of the list in argv[1]. | |
425 | * Returns: none. | |
426 | */ | |
427 | ||
428 | /* ARGSUSED */ | |
429 | int | |
430 | ListmaintMemberMenuEntry(m, argc, argv) | |
431 | Menu *m; | |
432 | int argc; | |
433 | char **argv; | |
434 | { | |
461c03b6 | 435 | char temp_buf[BUFSIZ]; |
08345b74 | 436 | char *list_name = argv[1]; |
075fe5bb | 437 | register int stat; |
438 | ||
402461ad | 439 | if (!ValidName(list_name)) |
440 | return(DM_QUIT); | |
08345b74 | 441 | |
442 | if (*argv[0] == 'a') { /* add_list */ | |
402461ad | 443 | if (AddList(argc, argv) == SUB_ERROR) |
08345b74 | 444 | return(DM_QUIT); |
445 | (void) sprintf(temp_buf, "List '%s' created. Do you want to %s", | |
402461ad | 446 | list_name, "change its membership (y/n)? "); |
08345b74 | 447 | if (YesNoQuestion(temp_buf, TRUE) != TRUE ) |
448 | return(DM_QUIT); | |
449 | } | |
075fe5bb | 450 | else |
451 | /* All we want to know is if it exists. */ | |
8defc06b | 452 | switch( (stat = do_mr_query("count_members_of_list", 1, argv + 1, |
075fe5bb | 453 | NullFunc, (char *) NULL))) { |
8defc06b | 454 | case MR_SUCCESS: |
075fe5bb | 455 | break; |
8defc06b | 456 | case MR_LIST: |
075fe5bb | 457 | Put_message("This list does not exist."); |
458 | return(DM_QUIT); | |
8defc06b | 459 | case MR_PERM: |
075fe5bb | 460 | Put_message("You are not allowed to view this list."); |
31791cff | 461 | break; |
075fe5bb | 462 | default: |
463 | com_err(program_name, stat, " in get_list_info"); | |
464 | return(DM_QUIT); | |
465 | } | |
08345b74 | 466 | |
467 | (void) sprintf(temp_buf, | |
468 | "Change/Display membership of '%s'", list_name); | |
469 | m->m_title = Strsave(temp_buf); | |
470 | strcpy(current_list, list_name); | |
471 | return(DM_NORMAL); | |
472 | } | |
473 | ||
474 | /* Function Name: ListmaintMemberMenuExit | |
475 | * Description: This is the function called when the member menu is | |
476 | * exited, it frees the memory that is storing the name. | |
477 | * Arguments: m - the menu | |
478 | * Returns: DM_NORMAL | |
479 | */ | |
480 | ||
481 | int | |
482 | ListmaintMemberMenuExit(m) | |
483 | Menu *m; | |
484 | { | |
485 | free(m->m_title); | |
486 | strcpy(current_list, ""); | |
487 | return(DM_NORMAL); | |
488 | } | |
489 | ||
490 | /* Function Name: ListMembersByType | |
491 | * Description: This function lists the users of a list by type. | |
492 | * Arguments: type - the type of the list "USER", "LIST", or "STRING". | |
493 | * Returns: none. | |
494 | * NOTE: if type is NULL, all lists members are listed. | |
495 | */ | |
496 | ||
84b46f02 | 497 | int |
461c03b6 | 498 | ListMembersByType(type) |
08345b74 | 499 | char * type; |
500 | { | |
501 | char temp_buf[BUFSIZ]; | |
461c03b6 | 502 | register int status; |
402461ad | 503 | char * args[10]; |
504 | ||
505 | args[0] = current_list; | |
506 | args[1] = NULL; | |
08345b74 | 507 | |
508 | found_some = FALSE; | |
8defc06b | 509 | if ( (status = do_mr_query("get_members_of_list", CountArgs(args), args, |
a42a06d7 | 510 | PrintByType, type)) != 0) { |
402461ad | 511 | com_err(program_name, status, " in ListMembersByType"); |
a42a06d7 | 512 | return(DM_NORMAL); |
513 | } | |
08345b74 | 514 | if (!found_some) { |
515 | if (type == NULL) | |
516 | Put_message("List is empty (no members)."); | |
517 | else { | |
518 | sprintf(temp_buf,"No %s Members",type); | |
519 | Put_message(temp_buf); | |
520 | } | |
521 | } | |
522 | } | |
523 | ||
524 | /* Function Name: ListAllMembers | |
525 | * Description: lists all members of the current list. | |
526 | * Arguments: | |
527 | * Returns: DM_NORMAL | |
528 | */ | |
529 | ||
530 | int | |
531 | ListAllMembers() | |
532 | { | |
533 | ListMembersByType(NULL); | |
534 | return (DM_NORMAL); | |
535 | } | |
536 | ||
537 | /* Function Name: ListUserMembers | |
538 | * Description: This function lists all members of a list of type "USER". | |
539 | * Arguments: none | |
540 | * Returns: DM_NORMAL. | |
541 | */ | |
542 | ||
543 | ListUserMembers() | |
544 | { | |
545 | ListMembersByType("USER"); | |
546 | return(DM_NORMAL); | |
547 | } | |
548 | ||
549 | /* Function Name: ListListMembers | |
550 | * Description: This function lists all members of a list of type "LIST". | |
551 | * Arguments: none | |
552 | * Returns: DM_NORMAL. | |
553 | */ | |
554 | ||
555 | ListListMembers() | |
556 | { | |
557 | ListMembersByType("LIST"); | |
558 | return(DM_NORMAL); | |
559 | } | |
560 | ||
561 | /* Function Name: ListStringMembers | |
562 | * Description:This function lists all members of a list of type "STRING". | |
563 | * Arguments: none | |
564 | * Returns: DM_NORMAL. | |
565 | */ | |
566 | ||
567 | ListStringMembers() | |
568 | { | |
569 | ListMembersByType("STRING"); | |
570 | return(DM_NORMAL); | |
571 | } | |
572 | ||
573 | /* Function Name: GetMemberInfo | |
574 | * Description: This function gets the information needed to | |
575 | * add or delete a user from a list. | |
576 | * Arguments: argc, argv - standard. | |
577 | * action - name of the action to be performed either | |
578 | * "add" or "delete". | |
579 | * ret_argc, ret_argv - the returned value of argc and argv. | |
580 | * Returns: SUB_ERROR or SUB_NORMAL. | |
581 | */ | |
582 | ||
583 | int | |
584 | GetMemberInfo(action, ret_argv) | |
585 | char *action, **ret_argv; | |
586 | { | |
7b53f00f | 587 | char temp_buf[BUFSIZ]; |
08345b74 | 588 | |
589 | ret_argv[LM_LIST] = Strsave(current_list); | |
08345b74 | 590 | |
31791cff | 591 | ret_argv[LM_TYPE] = Strsave("user"); |
eb5eb5de | 592 | if (GetTypeFromUser("Type of member", "member", &ret_argv[LM_TYPE]) == |
593 | SUB_ERROR) | |
594 | return(SUB_ERROR); | |
0a2c64cb | 595 | |
402461ad | 596 | sprintf(temp_buf,"Name of %s to %s", ret_argv[LM_TYPE], action); |
31791cff | 597 | ret_argv[LM_MEMBER] = Strsave(user); |
eb5eb5de | 598 | if (GetValueFromUser(temp_buf, &ret_argv[LM_MEMBER]) == SUB_ERROR) |
599 | return(SUB_ERROR); | |
402461ad | 600 | ret_argv[LM_END] = NULL; /* NULL terminate this list. */ |
601 | ||
68c57b15 | 602 | if (strcasecmp(ret_argv[LM_TYPE], "string") && |
603 | !ValidName( ret_argv[LM_MEMBER] ) ) { | |
402461ad | 604 | FreeInfo(ret_argv); |
605 | return(SUB_ERROR); | |
606 | } | |
08345b74 | 607 | return(SUB_NORMAL); |
608 | } | |
609 | ||
610 | /* Function Name: AddMember | |
611 | * Description: This function adds a member to a list. | |
612 | * Arguments: none. | |
613 | * Returns: DM_NORMAL. | |
614 | */ | |
615 | ||
616 | int | |
617 | AddMember() | |
618 | { | |
fc2df2d9 | 619 | char *args[10], temp_buf[BUFSIZ], *p; |
461c03b6 | 620 | register int status; |
fc2df2d9 | 621 | struct qelem *mailhubs, *elem, *GetTypeValues(); |
08345b74 | 622 | |
402461ad | 623 | if ( GetMemberInfo("add", args) == SUB_ERROR ) |
08345b74 | 624 | return(DM_NORMAL); |
625 | ||
fc2df2d9 | 626 | if (!strcmp(args[LM_TYPE], "STRING")) { |
f071d8a7 | 627 | if (p = strchr(args[LM_MEMBER], '@')) { |
fc2df2d9 | 628 | char *host = canonicalize_hostname(strsave(++p)); |
629 | mailhubs = GetTypeValues("mailhub"); | |
630 | for (elem = mailhubs; elem; elem = elem->q_forw) { | |
631 | if (!strcasecmp(host, elem->q_data)) { | |
632 | free(host); | |
633 | host = strsave(args[LM_MEMBER]); | |
634 | *(--p) = 0; | |
635 | sprintf(temp_buf, "String \"%s\" should be USER or LIST \"%s\" because it is a local name.", | |
636 | host, args[LM_MEMBER]); | |
637 | Put_message(temp_buf); | |
638 | free(args[LM_TYPE]); | |
639 | free(host); | |
640 | return(DM_NORMAL); | |
641 | } | |
642 | } | |
643 | free(host); | |
f071d8a7 | 644 | } else if (!strchr(args[LM_MEMBER], '!')) { |
fc2df2d9 | 645 | Put_message("Member which is not a foreign mail address should not be type STRING."); |
646 | return(DM_NORMAL); | |
647 | } | |
648 | } | |
649 | ||
8defc06b | 650 | if ( (status = do_mr_query("add_member_to_list", CountArgs(args), args, |
651 | Scream, NULL)) != MR_SUCCESS) { | |
652 | if (status == MR_EXISTS) { | |
402461ad | 653 | sprintf(temp_buf, "The %s %s is already a member of LIST %s.", |
654 | args[LM_TYPE], args[LM_MEMBER], args[LM_LIST]); | |
655 | Put_message(temp_buf); | |
656 | } | |
657 | else | |
658 | com_err(program_name, status, " in AddMember"); | |
659 | } | |
08345b74 | 660 | |
661 | FreeInfo(args); | |
402461ad | 662 | return(DM_NORMAL); |
08345b74 | 663 | } |
664 | ||
665 | /* Function Name: DeleteMember | |
666 | * Description: This function deletes a member from a list. | |
667 | * Arguments: none. | |
668 | * Returns: DM_NORMAL | |
669 | */ | |
670 | ||
671 | int | |
672 | DeleteMember() | |
673 | { | |
674 | char *args[10]; | |
461c03b6 | 675 | register int status; |
08345b74 | 676 | |
677 | if( GetMemberInfo("delete", args) == SUB_ERROR ) | |
678 | return(DM_NORMAL); | |
679 | ||
680 | if (Confirm("Are you sure you want to delete this member?") ) { | |
8defc06b | 681 | if (status = do_mr_query("delete_member_from_list", CountArgs(args), |
08345b74 | 682 | args, Scream, NULL)) |
402461ad | 683 | com_err(program_name, status, " in DeleteMember"); |
08345b74 | 684 | else |
685 | Put_message("Deletion Completed."); | |
686 | } | |
687 | else | |
688 | Put_message("Deletion has been Aborted."); | |
689 | ||
690 | FreeInfo(args); | |
691 | return(DM_NORMAL); | |
692 | } | |
693 | ||
08345b74 | 694 | /* Function Name: InterRemoveItemFromLists |
695 | * Description: This function allows interactive removal of an item | |
696 | * (user, string, list) for all list that it is on. | |
697 | * Arguments: none. | |
698 | * Returns: DM_NORMAL. | |
402461ad | 699 | * NOTES: QueryLoop() does not work here because info does not have |
700 | * enough information in it to delete the member from the list. | |
08345b74 | 701 | */ |
702 | ||
703 | int | |
704 | InterRemoveItemFromLists() | |
705 | { | |
461c03b6 | 706 | register int status; |
eb5eb5de | 707 | char *type, *name, *args[10], buf[BUFSIZ]; |
461c03b6 | 708 | struct qelem *top, *elem; |
08345b74 | 709 | |
eb5eb5de | 710 | type = strsave("USER"); |
711 | if (GetTypeFromUser("Type of member", "member", &type) == SUB_ERROR) | |
08345b74 | 712 | return(DM_NORMAL); |
713 | ||
402461ad | 714 | sprintf(buf, "Name of %s", type); |
eb5eb5de | 715 | name = strsave(user); |
716 | if (GetValueFromUser(buf, &name) == SUB_ERROR) | |
717 | return(DM_NORMAL); | |
08345b74 | 718 | |
402461ad | 719 | if (!ValidName(name)) |
720 | return(DM_NORMAL); | |
721 | ||
08345b74 | 722 | top = elem = GetListInfo(GLOM, type, name); |
723 | ||
724 | while(elem != NULL) { | |
402461ad | 725 | char line[BUFSIZ]; |
461c03b6 | 726 | char ** info = (char **) elem->q_data; |
402461ad | 727 | sprintf(line, "Delete %s %s from the list \"%s\" (y/n/q)? ", type, |
728 | name, info[GLOM_NAME]); | |
729 | switch (YesNoQuitQuestion(line, FALSE)) { | |
730 | case TRUE: | |
08345b74 | 731 | Put_message("deleting..."); |
461c03b6 | 732 | args[DM_LIST] = info[GLOM_NAME]; |
08345b74 | 733 | args[DM_TYPE] = type; |
734 | args[DM_MEMBER] = name; | |
8defc06b | 735 | if ( (status = do_mr_query("delete_member_from_list", 3, args, |
08345b74 | 736 | Scream, (char *) NULL)) != 0) |
402461ad | 737 | /* should probabally check to delete list. */ |
461c03b6 | 738 | com_err(program_name, status, " in delete_member"); |
08345b74 | 739 | break; |
402461ad | 740 | case FALSE: |
741 | break; | |
742 | default: | |
743 | Put_message("Aborting..."); | |
744 | FreeQueue(top); | |
745 | return(DM_NORMAL); | |
08345b74 | 746 | } |
747 | elem = elem->q_forw; | |
748 | } | |
749 | FreeQueue(top); | |
750 | return(DM_NORMAL); | |
751 | } | |
752 | ||
753 | /*-*-* LIST MENU *-*-*/ | |
754 | ||
755 | /* Function Name: ListByMember | |
756 | * Description: This gets all lists that a given member is a member of. | |
461c03b6 | 757 | * Arguments: none. |
08345b74 | 758 | * Returns: DM_NORMAL. |
759 | */ | |
760 | ||
761 | int | |
461c03b6 | 762 | ListByMember() |
08345b74 | 763 | { |
402461ad | 764 | char buf[BUFSIZ], temp_buf[BUFSIZ], *type, *name, **info; |
461c03b6 | 765 | Bool maillist, group; |
766 | struct qelem *top, *elem; | |
08345b74 | 767 | |
eb5eb5de | 768 | type = strsave("USER"); |
769 | if (GetTypeFromUser("Type of member", "member", &type) == SUB_ERROR) | |
08345b74 | 770 | return(DM_NORMAL); |
eb5eb5de | 771 | |
772 | sprintf(buf, "Name of %s", type); | |
773 | name = strsave(user); | |
774 | if (GetValueFromUser(buf, &name) == SUB_ERROR) | |
775 | return(DM_NORMAL); | |
08345b74 | 776 | |
402461ad | 777 | /* What we really want is a recursive search */ |
eb5eb5de | 778 | sprintf(temp_buf, "R%s", type); |
779 | free(type); type = Strsave(temp_buf); | |
402461ad | 780 | |
eb5eb5de | 781 | if ((maillist = YesNoQuestion("Show Lists that are Maillists (y/n) ?", |
782 | TRUE)) == -1) | |
783 | return(DM_NORMAL); | |
784 | if ((group = YesNoQuestion("Show Lists that are Groups (y/n) ?", | |
785 | TRUE)) == -1) | |
786 | return(DM_NORMAL); | |
08345b74 | 787 | |
788 | elem = top = GetListInfo(GLOM, type, name); | |
789 | ||
790 | while (elem != NULL) { | |
791 | info = (char**) elem->q_data; | |
5151666e | 792 | if ((maillist == TRUE && !strcmp(info[GLOM_MAILLIST], "1")) || |
793 | (group == TRUE && !strcmp(info[GLOM_GROUP], "1"))) | |
08345b74 | 794 | Put_message(info[GLOM_NAME]); |
795 | elem = elem->q_forw; | |
796 | } | |
797 | FreeQueue(top); | |
798 | return (DM_NORMAL); | |
799 | } | |
800 | ||
801 | /* Function Name: ListByAdministrator | |
802 | * Description: This function prints all lists which a given user or | |
803 | * group administers. | |
461c03b6 | 804 | * Arguments: none. |
08345b74 | 805 | * Returns: DM_NORMAL. |
806 | */ | |
807 | ||
808 | int | |
461c03b6 | 809 | ListByAdministrator() |
08345b74 | 810 | { |
402461ad | 811 | char buf[BUFSIZ], temp_buf[BUFSIZ], *type, *name; |
812 | struct qelem *top; | |
08345b74 | 813 | |
eb5eb5de | 814 | type = strsave("USER"); |
815 | if (GetTypeFromUser("Type of member", "member", &type) == SUB_ERROR) | |
08345b74 | 816 | return(DM_NORMAL); |
08345b74 | 817 | |
eb5eb5de | 818 | sprintf(buf, "Name of %s", type); |
819 | name = strsave(user); | |
820 | if (GetValueFromUser(buf, &name) == SUB_ERROR) | |
821 | return(DM_NORMAL); | |
822 | ||
823 | switch (YesNoQuestion("Do you want a recursive search (y/n)", FALSE)) { | |
824 | case TRUE: | |
825 | sprintf(temp_buf, "R%s", type); /* "USER" to "RUSER" etc. */ | |
08345b74 | 826 | free(type); |
eb5eb5de | 827 | type = Strsave(temp_buf); |
828 | break; | |
829 | case FALSE: | |
830 | break; | |
831 | default: | |
08345b74 | 832 | return(DM_NORMAL); |
833 | } | |
eb5eb5de | 834 | |
075fe5bb | 835 | top = GetListInfo(ACE_USE, type, name); |
836 | Loop(top, PrintListAce); | |
402461ad | 837 | |
08345b74 | 838 | FreeQueue(top); |
839 | return (DM_NORMAL); | |
840 | } | |
841 | ||
08345b74 | 842 | /* Function Name: ListAllPublicMailLists |
843 | * Description: This function lists all public mailing lists. | |
844 | * Arguments: none | |
845 | * Returns: DM_NORMAL. | |
846 | */ | |
847 | ||
848 | ListAllPublicMailLists() | |
849 | { | |
461c03b6 | 850 | register int status; |
08345b74 | 851 | static char * args[] = { |
852 | "TRUE", /* active */ | |
853 | "TRUE", /* public */ | |
854 | "FALSE", /* hidden */ | |
855 | "TRUE", /* maillist */ | |
856 | "DONTCARE", /* group. */ | |
461c03b6 | 857 | }; |
08345b74 | 858 | |
859 | if (YesNoQuestion("This query will take a while. Do you wish to continue?", | |
461c03b6 | 860 | TRUE) == TRUE ) |
8defc06b | 861 | if (status = do_mr_query("qualified_get_lists", 5, args, |
08345b74 | 862 | Print, (char *) NULL) != 0) |
402461ad | 863 | com_err(program_name, status, " in ListAllGroups"); |
08345b74 | 864 | |
865 | return (DM_NORMAL); | |
866 | } |