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