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