]> andersk Git - moira.git/blob - clients/moira/lists.c
If creating a list which has the same name as a username, prompt and ask
[moira.git] / clients / moira / lists.c
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 MOIRA Client, which allows a nieve
6  *      user to quickly and easily maintain most parts of the MOIRA 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 <string.h>
24 #include <moira.h>
25 #include <moira_site.h>
26 #include <menu.h>
27
28 #include "mit-copyright.h"
29 #include "defs.h"
30 #include "f_defs.h"
31 #include "globals.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     sprintf(buf, "Item: %-20s Name: %s", info[ACE_TYPE], 
65             info[ACE_NAME]);
66     Put_message(buf);
67 }
68
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
75 static void
76 PrintListInfo(info)
77 char ** info;
78 {
79     char buf[BUFSIZ];
80
81     Put_message(" ");
82     (void) sprintf(buf, "%20sList: %s", "", info[L_NAME]);
83     (void) Put_message(buf);
84     (void) sprintf(buf, "Description: %s", info[L_DESC]);
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]) ) {
91         (void) sprintf(buf,"This list is a Group and its ID number is %s",
92                        info[L_GID]);
93         Put_message(buf);
94     }
95     else
96         Put_message("This list is NOT a Group.");
97
98     if (strcmp(info[L_ACE_TYPE],"NONE") == 0)
99         Put_message("This list has no Administrator, how strange?!");
100     else {
101         sprintf(buf, "The Administrator of this list is the %s: %s",
102                 info[L_ACE_TYPE], info[L_ACE_NAME]);
103         Put_message(buf);
104     }
105
106     (void) sprintf(buf, "This list is: %s, %s, and %s",
107                    atoi(info[L_ACTIVE]) ? "active" : "inactive",
108                    atoi(info[L_PUBLIC]) ? "public" : "private",
109                    atoi(info[L_HIDDEN]) ? "hidden" : "visible");
110     (void) Put_message(buf);
111     sprintf(buf, MOD_FORMAT, info[L_MODBY], info[L_MODTIME], info[L_MODWITH]);
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;
126 char * name1, *name2;
127 {
128     char *args[2];
129     struct qelem * elem = NULL;
130     register int status;
131
132     switch(type) {
133     case LIST:
134         args[0] = name1;
135         if ( (status = do_mr_query("get_list_info", 1, args,
136                                StoreInfo, (char *) &elem)) != 0) {
137             com_err(program_name, status, " in get_list_info");
138             return (NULL);
139         }
140         break;
141     case MEMBERS:
142         args[0] = name1;
143         if ( (status = do_mr_query("get_members_of_list", 1, args,
144                                StoreInfo, (char *) &elem)) != 0) {
145             com_err(program_name, status, " in get_members_of_list");
146             return (NULL);
147         }
148         break;
149     case GLOM:
150         args[0] = name1;        
151         args[1] = name2;        
152         if ( (status =  do_mr_query("get_lists_of_member", 2, args,
153                                StoreInfo, (char *) &elem)) != 0) {
154             com_err(program_name, status, " in get_list_of_members");
155             return (NULL);
156         }
157         break;
158     case ACE_USE:
159         args[0] = name1;        
160         args[1] = name2;        
161         if ( (status =  do_mr_query("get_ace_use", 2, args,
162                                StoreInfo, (char *) &elem)) != 0) {
163             com_err(program_name, status, " in get_ace_use");
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 **
181 AskListInfo(info, name)
182 char ** info;
183 Bool name;
184 {
185     char temp_buf[BUFSIZ], *newname;
186
187     Put_message(" ");
188     sprintf(temp_buf,"Setting information of list %s.",info[L_NAME]);
189     Put_message(temp_buf);
190     Put_message(" ");
191
192     if (name) {
193         while (1) {
194             newname = Strsave(info[L_NAME]);
195             if (GetValueFromUser("The new name for this list", &newname) ==
196                 SUB_ERROR)
197               return(NULL);
198             if (ValidName(newname))
199               break;
200         }
201     }
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);
216     if (atoi(info[L_GROUP]))
217       if (GetValueFromUser("What is the GID for this group.", &info[L_GID]) ==
218           SUB_ERROR)
219         return(NULL);
220
221     if (GetTypeFromUser("What Type of Administrator", "ace_type",
222                         &info[L_ACE_TYPE]) == SUB_ERROR)
223       return(NULL);
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]);
228         if (GetValueFromUser(temp_buf, &info[L_ACE_NAME]) == SUB_ERROR)
229           return(NULL);
230     }
231     if (GetValueFromUser("Description: ", &info[L_DESC]) == SUB_ERROR)
232       return(NULL);
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.
251  *      Arguments: argc, argv - name of list in argv[1].
252  *      Returns: DM status code.
253  */
254
255 /* ARGSUSED */
256 int
257 ShowListInfo(argc, argv)
258 int argc;
259 char **argv;
260 {
261     struct qelem *top, *list;
262
263     top = list = GetListInfo(LIST, argv[1], (char *) NULL);
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
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     
289     if ((args = AskListInfo(info, TRUE)) == NULL) {
290         Put_message("Aborted.");
291         return;
292     }
293     if ( (stat = do_mr_query("update_list", CountArgs(args), args, 
294                            Scream, (char *) NULL)) != MR_SUCCESS) {
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
302 /*      Function Name: UpdateList
303  *      Description: updates the information on a list.
304  *      Arguments: argc, argv - name of list in argv[1].
305  *      Returns: DM Status code.
306  */
307
308 /* ARGSUSED */
309 int
310 UpdateList(argc, argv)
311 int argc;
312 char **argv;
313 {
314     struct qelem *top;
315
316     top = GetListInfo(LIST, argv[1], (char *) NULL);
317     QueryLoop(top, NullPrint, RealUpdateList, "Update the list");
318
319     FreeQueue(top);
320     return(DM_NORMAL);
321 }
322
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);
342    info[L_ACE_TYPE] = Strsave(DEFAULT_ACE_TYPE);
343    info[L_ACE_NAME] = Strsave(DEFAULT_ACE_NAME);
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
349 /*      Function Name: AddList
350  *      Description: 
351  *      Arguments: argc, argv - name of list in argv[1].
352  *      Returns: SUB_ERROR if list not created.
353  */
354
355 /* ARGSUSED */
356 int
357 AddList(argc, argv)
358 int argc;
359 char **argv;
360 {
361     static char *info[MAX_ARGS_SIZE], **add_args;
362     int status, ret_code = SUB_NORMAL;
363     struct qelem *elem = NULL;
364
365     if (!ValidName(argv[1]))
366       return(DM_NORMAL);
367     status = do_mr_query("get_list_info", 1, argv + 1, NullFunc, 
368                        (char *) NULL);
369     if (status != MR_NO_MATCH) {
370         if (status == MR_SUCCESS)
371             Put_message("This list already exists.");
372         else
373             com_err(program_name, status, " in AddList.");      
374         return(SUB_ERROR);
375     }
376
377     if (do_mr_query("get_user_account_by_login", 1, argv + 1,
378                     StoreInfo, (char *) &elem) == 0) {
379             Put_message("A user by that name already exists in the database.");
380             Loop(QueueTop(elem), FreeInfo);
381             FreeQueue(elem);
382             if (YesNoQuestion("Crate a list with the same name",
383                               FALSE) != TRUE)
384                     return(SUB_ERROR);
385     }
386     
387     if ((add_args = AskListInfo(SetDefaults(info,argv[1]), FALSE)) == NULL) {
388         Put_message("Aborted.");
389         return(SUB_ERROR);
390     }
391
392     if ( (status = do_mr_query("add_list", CountArgs(add_args), add_args,
393                              Scream, (char *) NULL)) != MR_SUCCESS) {
394         com_err(program_name, status, " in AddList.");  
395         Put_message("List Not Created.");
396         ret_code = SUB_ERROR;
397     }
398
399     FreeInfo(info);
400     return(ret_code);
401 }
402
403 /*      Function Name: Instructions
404  *      Description: This func prints out instruction on manipulating lists.
405  *      Arguments: none
406  *      Returns: DM Status Code.
407  */
408
409 int
410 ListHelp()
411 {
412     static char * message[] = {
413         "Listmaint handles the creation, deletion, and updating of lists.",
414         "A list can be a mailing list, a group list, or both.",
415         "The concept behind lists is that a list has an owner",
416         "- administrator -  and members.",
417         "The administrator of a list may be another list.",
418         "The members of a list can be users (login names), other lists,",
419         "or address strings.",
420         "You can use certain keys to do the following:",
421         "    Refresh the screen - Type ctrl-L.",
422         "    Escape from a function - Type ctrl-C.",
423         "    Suspend the program (temporarily) - Type ctrl-Z.",
424         NULL,
425     };
426
427     return(PrintHelp(message));
428 }
429
430 /*-*-* LISTMAINT UPDATE MENU *-*-*/
431
432 /*      Function Name: ListmaintMemberMenuEntry
433  *      Description: entry routine into the listmaint member menu.
434  *      Arguments: m - the member menu.
435  *                 argc, argv - name of the list in argv[1].
436  *      Returns: none.
437  */
438
439 /* ARGSUSED */
440 int
441 ListmaintMemberMenuEntry(m, argc, argv)
442 Menu *m;
443 int argc;
444 char **argv;
445 {
446     char temp_buf[BUFSIZ];
447     char *list_name = argv[1];
448     register int stat;    
449
450     if (!ValidName(list_name))
451         return(DM_QUIT);
452
453     if (*argv[0] == 'a') {      /* add_list */
454         if (AddList(argc, argv) == SUB_ERROR)
455             return(DM_QUIT);
456         (void) sprintf(temp_buf, "List '%s' created. Do you want to %s",
457                        list_name, "change its membership (y/n)? ");
458         if (YesNoQuestion(temp_buf, TRUE) != TRUE )
459             return(DM_QUIT);
460     }
461     else 
462         /* All we want to know is if it exists. */
463         switch( (stat = do_mr_query("count_members_of_list", 1, argv + 1,
464                                    NullFunc, (char *) NULL))) {
465         case MR_SUCCESS:
466             break;
467         case MR_LIST:
468             Put_message("This list does not exist.");
469             return(DM_QUIT);
470         case MR_PERM:
471             Put_message("You are not allowed to view this list.");
472             break;
473         default:
474             com_err(program_name, stat, " in get_list_info");
475             return(DM_QUIT);
476         }
477
478     (void) sprintf(temp_buf, 
479                    "Change/Display membership of '%s'", list_name);
480     m->m_title = Strsave(temp_buf);
481     strcpy(current_list, list_name);
482     return(DM_NORMAL);
483 }
484
485 /*      Function Name: ListmaintMemberMenuExit
486  *      Description: This is the function called when the member menu is
487  *                   exited, it frees the memory that is storing the name.
488  *      Arguments: m - the menu
489  *      Returns: DM_NORMAL 
490  */
491
492 int
493 ListmaintMemberMenuExit(m)
494 Menu *m;
495 {
496     free(m->m_title);
497     strcpy(current_list, "");
498     return(DM_NORMAL);
499 }
500
501 /*      Function Name: ListMembersByType
502  *      Description: This function lists the users of a list by type.
503  *      Arguments: type - the type of the list "USER", "LIST", or "STRING".
504  *      Returns: none.
505  *      NOTE: if type is NULL, all lists members are listed.
506  */
507
508 int
509 ListMembersByType(type)
510 char * type;
511 {
512     char temp_buf[BUFSIZ];
513     register int status;
514     char * args[10];
515
516     args[0] = current_list;
517     args[1] = NULL;
518
519     found_some = FALSE;
520     if ( (status = do_mr_query("get_members_of_list", CountArgs(args), args, 
521                              PrintByType, type)) != 0) {
522         com_err(program_name, status, " in ListMembersByType");
523         return(DM_NORMAL);
524     }
525     if (!found_some) {
526         if (type == NULL)
527             Put_message("List is empty (no members).");
528         else {
529             sprintf(temp_buf,"No %s Members",type);
530             Put_message(temp_buf);
531         }
532     }
533 }
534
535 /*      Function Name: ListAllMembers
536  *      Description: lists all members of the current list.
537  *      Arguments: 
538  *      Returns: DM_NORMAL
539  */
540
541 int
542 ListAllMembers()
543 {
544     ListMembersByType(NULL);
545     return (DM_NORMAL);
546 }
547
548 /*      Function Name: ListUserMembers
549  *      Description: This function lists all members of a list of type "USER".
550  *      Arguments: none
551  *      Returns: DM_NORMAL.
552  */
553
554 ListUserMembers()
555 {
556     ListMembersByType("USER");
557     return(DM_NORMAL);
558 }
559
560 /*      Function Name: ListListMembers
561  *      Description: This function lists all members of a list of type "LIST".
562  *      Arguments: none
563  *      Returns: DM_NORMAL.
564  */
565
566 ListListMembers()
567 {
568     ListMembersByType("LIST");
569     return(DM_NORMAL);
570 }
571
572 /*      Function Name: ListStringMembers
573  *      Description:This function lists all members of a list of type "STRING".
574  *      Arguments: none
575  *      Returns: DM_NORMAL.
576  */
577
578 ListStringMembers()
579 {
580     ListMembersByType("STRING");
581     return(DM_NORMAL);
582 }
583
584 /*      Function Name: GetMemberInfo
585  *      Description: This function gets the information needed to
586  *                   add or delete a user from a list.
587  *      Arguments: argc, argv - standard.
588  *                 action - name of the action to be performed either
589  *                          "add" or "delete".
590  *                 ret_argc, ret_argv - the returned value of argc and argv.
591  *      Returns: SUB_ERROR or SUB_NORMAL.
592  */
593
594 int
595 GetMemberInfo(action, ret_argv)
596 char *action, **ret_argv;
597 {
598     char temp_buf[BUFSIZ];
599
600     ret_argv[LM_LIST] = Strsave(current_list);
601
602     ret_argv[LM_TYPE] = Strsave("user");
603     if (GetTypeFromUser("Type of member", "member", &ret_argv[LM_TYPE]) ==
604         SUB_ERROR)
605       return(SUB_ERROR);
606
607     sprintf(temp_buf,"Name of %s to %s", ret_argv[LM_TYPE], action);
608     ret_argv[LM_MEMBER] = Strsave(user);
609     if (GetValueFromUser(temp_buf, &ret_argv[LM_MEMBER]) == SUB_ERROR)
610       return(SUB_ERROR);
611     ret_argv[LM_END] = NULL;            /* NULL terminate this list. */
612
613     if (strcasecmp(ret_argv[LM_TYPE], "string") &&
614         !ValidName( ret_argv[LM_MEMBER] ) ) {
615         FreeInfo(ret_argv);
616         return(SUB_ERROR);
617     }
618     return(SUB_NORMAL);
619 }
620
621 /*      Function Name: AddMember
622  *      Description: This function adds a member to a list.
623  *      Arguments: none.
624  *      Returns: DM_NORMAL.
625  */
626
627 int
628 AddMember()
629 {
630     char *args[10], temp_buf[BUFSIZ], *p;
631     register int status;
632     struct qelem *mailhubs, *elem, *GetTypeValues();
633
634     if ( GetMemberInfo("add", args) == SUB_ERROR )
635         return(DM_NORMAL);
636
637     if (!strcmp(args[LM_TYPE], "STRING")) {
638         if (p = strchr(args[LM_MEMBER], '@')) {
639             char *host = canonicalize_hostname(strsave(++p));
640             mailhubs = GetTypeValues("mailhub");
641             for (elem = mailhubs; elem; elem = elem->q_forw) {
642                 if (!strcasecmp(host, elem->q_data)) {
643                     free(host);
644                     host = strsave(args[LM_MEMBER]);
645                     *(--p) = 0;
646                     sprintf(temp_buf, "String \"%s\" should be USER or LIST \"%s\" because it is a local name.",
647                             host, args[LM_MEMBER]);
648                     Put_message(temp_buf);
649                     free(args[LM_TYPE]);
650                     free(host);
651                     return(DM_NORMAL);
652                 }
653             }
654             free(host);
655         } else if (!strchr(args[LM_MEMBER], '!')) {
656             Put_message("Member which is not a foreign mail address should not be type STRING.");
657             return(DM_NORMAL);
658         }
659     }
660
661     if ( (status = do_mr_query("add_member_to_list", CountArgs(args), args,
662                            Scream, NULL)) != MR_SUCCESS) {
663         if (status == MR_EXISTS) {
664             sprintf(temp_buf, "The %s %s is already a member of LIST %s.",
665                     args[LM_TYPE], args[LM_MEMBER], args[LM_LIST]);
666             Put_message(temp_buf);
667         }
668         else 
669             com_err(program_name, status, " in AddMember");
670     }
671
672     FreeInfo(args);
673     return(DM_NORMAL);
674 }
675
676 /*      Function Name: DeleteMember
677  *      Description: This function deletes a member from a list.
678  *      Arguments: none.
679  *      Returns: DM_NORMAL
680  */
681
682 int
683 DeleteMember()
684 {
685     char *args[10];
686     register int status;
687
688     if( GetMemberInfo("delete", args) == SUB_ERROR )
689         return(DM_NORMAL);
690
691     if (Confirm("Are you sure you want to delete this member?") ) {
692         if (status = do_mr_query("delete_member_from_list", CountArgs(args),
693                                args, Scream, NULL))
694             com_err(program_name, status, " in DeleteMember");
695         else
696             Put_message("Deletion Completed.");
697     }
698     else 
699         Put_message("Deletion has been Aborted.");
700
701     FreeInfo(args);
702     return(DM_NORMAL);
703 }
704
705 /*      Function Name: InterRemoveItemFromLists
706  *      Description: This function allows interactive removal of an item
707  *                   (user, string, list) for all list  that it is on.
708  *      Arguments: none.
709  *      Returns: DM_NORMAL.
710  *      NOTES: QueryLoop() does not work here because info does not have
711  *             enough information in it to delete the member from the list.
712  */
713
714 int
715 InterRemoveItemFromLists()
716 {
717     register int status;
718     char *type, *name, *args[10], buf[BUFSIZ];
719     struct qelem *top, *elem;
720
721     type = strsave("USER");
722     if (GetTypeFromUser("Type of member", "member", &type) == SUB_ERROR)
723         return(DM_NORMAL);
724     
725     sprintf(buf, "Name of %s", type);
726     name = strsave(user);
727     if (GetValueFromUser(buf, &name) == SUB_ERROR)
728       return(DM_NORMAL);
729
730     if (!ValidName(name))
731         return(DM_NORMAL);
732
733     top = elem = GetListInfo(GLOM, type, name);
734
735     while(elem != NULL) {
736         char line[BUFSIZ];
737         char ** info = (char **) elem->q_data;
738         sprintf(line, "Delete %s %s from the list \"%s\" (y/n/q)? ", type,
739                 name, info[GLOM_NAME]);
740         switch (YesNoQuitQuestion(line, FALSE)) {
741         case TRUE:
742             Put_message("deleting...");
743             args[DM_LIST] = info[GLOM_NAME];
744             args[DM_TYPE] = type;
745             args[DM_MEMBER] = name;
746             if ( (status = do_mr_query("delete_member_from_list", 3, args,
747                                Scream, (char *) NULL)) != 0)
748                 /* should probabally check to delete list. */
749                 com_err(program_name, status, " in delete_member");
750             break;
751         case FALSE:
752             break;
753         default:
754             Put_message("Aborting...");
755             FreeQueue(top);
756             return(DM_NORMAL);
757         }
758         elem = elem->q_forw;
759     }
760     FreeQueue(top);
761     return(DM_NORMAL);
762 }
763
764 /*-*-* LIST MENU *-*-*/
765
766 /*      Function Name: ListByMember
767  *      Description: This gets all lists that a given member is a member of.
768  *      Arguments: none.
769  *      Returns: DM_NORMAL.
770  */
771
772 int
773 ListByMember()
774 {
775     char buf[BUFSIZ], temp_buf[BUFSIZ], *type, *name, **info;
776     Bool maillist, group;
777     struct qelem *top, *elem;
778
779     type = strsave("USER");
780     if (GetTypeFromUser("Type of member", "member", &type) == SUB_ERROR)
781         return(DM_NORMAL);
782     
783     sprintf(buf, "Name of %s", type);
784     name = strsave(user);
785     if (GetValueFromUser(buf, &name) == SUB_ERROR)
786       return(DM_NORMAL);
787
788     /* What we really want is a recursive search */
789     sprintf(temp_buf, "R%s", type);
790     free(type); type = Strsave(temp_buf);
791
792     if ((maillist = YesNoQuestion("Show Lists that are Maillists (y/n) ?",
793                                   TRUE)) == -1)
794       return(DM_NORMAL);
795     if ((group = YesNoQuestion("Show Lists that are Groups (y/n) ?",
796                                TRUE)) == -1)
797       return(DM_NORMAL);
798
799     elem = top = GetListInfo(GLOM, type, name);
800
801     while (elem != NULL) {
802         info = (char**) elem->q_data;
803         if ((maillist == TRUE && !strcmp(info[GLOM_MAILLIST], "1")) ||
804             (group == TRUE && !strcmp(info[GLOM_GROUP], "1")))
805                 Put_message(info[GLOM_NAME]);
806         elem = elem->q_forw;
807     }
808     FreeQueue(top);
809     return (DM_NORMAL);
810 }
811
812 /*      Function Name: ListByAdministrator
813  *      Description: This function prints all lists which a given user or
814  *                   group administers.
815  *      Arguments: none.
816  *      Returns: DM_NORMAL.
817  */
818
819 int
820 ListByAdministrator()
821 {
822     char buf[BUFSIZ], temp_buf[BUFSIZ], *type, *name;
823     struct qelem *top;
824
825     type = strsave("USER");
826     if (GetTypeFromUser("Type of member", "member", &type) == SUB_ERROR)
827         return(DM_NORMAL);
828     
829     sprintf(buf, "Name of %s", type);
830     name = strsave(user);
831     if (GetValueFromUser(buf, &name) == SUB_ERROR)
832       return(DM_NORMAL);
833
834     switch (YesNoQuestion("Do you want a recursive search (y/n)", FALSE)) {
835     case TRUE:
836         sprintf(temp_buf, "R%s", type); /* "USER" to "RUSER" etc. */
837         free(type);
838         type = Strsave(temp_buf);
839         break;
840     case FALSE:
841         break;
842     default:
843         return(DM_NORMAL);
844     }
845     
846     top = GetListInfo(ACE_USE, type, name);
847     Loop(top, PrintListAce);
848
849     FreeQueue(top);
850     return (DM_NORMAL);
851 }
852
853 /*      Function Name: ListAllPublicMailLists
854  *      Description: This function lists all public mailing lists.
855  *      Arguments: none
856  *      Returns: DM_NORMAL.
857  */
858
859 ListAllPublicMailLists()
860 {
861     register int status;
862     static char * args[] = {
863         "TRUE",                 /* active */
864         "TRUE",                 /* public */
865         "FALSE",                /* hidden */
866         "TRUE",                 /* maillist */
867         "DONTCARE",             /* group. */
868     };
869
870     if (YesNoQuestion("This query will take a while. Do you wish to continue?",
871                        TRUE) == TRUE )
872         if (status = do_mr_query("qualified_get_lists", 5, args,
873                                Print, (char *) NULL) != 0)
874             com_err(program_name, status, " in ListAllGroups");
875
876     return (DM_NORMAL); 
877 }
This page took 0.110519 seconds and 5 git commands to generate.