]> andersk Git - moira.git/blame - clients/moira/lists.c
added stuff for printer & DCM menus
[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
0a2c64cb 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.
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>
23#include <strings.h>
24#include <sms.h>
25#include <menu.h>
26
27#include "mit-copyright.h"
0a2c64cb 28#include "defs.h"
29#include "f_defs.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
31791cff 205 GetTypeFromUser("What Type of Administrator", "ace_type",&info[L_ACE_TYPE]);
075fe5bb 206 if ( (strcmp(info[L_ACE_TYPE], "USER") == 0) ||
207 (strcmp(info[L_ACE_TYPE], "user") == 0) )
08345b74 208 GetValueFromUser("Who will be the administrator of this list: ",
075fe5bb 209 &info[L_ACE_NAME]);
210 if ( (strcmp(info[L_ACE_TYPE], "LIST") == 0) ||
211 (strcmp(info[L_ACE_TYPE], "list") == 0) )
08345b74 212 GetValueFromUser("Which group will be the administrator of this list: ",
075fe5bb 213 &info[L_ACE_NAME]);
08345b74 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.
461c03b6 233 * Arguments: argc, argv - name of list in argv[1].
08345b74 234 * Returns: DM status code.
235 */
236
85ca828a 237/* ARGSUSED */
08345b74 238int
239ShowListInfo(argc, argv)
240int argc;
241char **argv;
242{
243 struct qelem *top, *list;
244
461c03b6 245 top = list = GetListInfo(LIST, argv[1], (char *) NULL);
08345b74 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
402461ad 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 */
263static void
264RealUpdateList(info, junk)
265char ** info;
266Bool 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
08345b74 281/* Function Name: UpdateList
85ca828a 282 * Description: updates the information on a list.
08345b74 283 * Arguments: argc, argv - name of list in argv[1].
284 * Returns: DM Status code.
285 */
286
85ca828a 287/* ARGSUSED */
08345b74 288int
289UpdateList(argc, argv)
290int argc;
291char **argv;
292{
402461ad 293 struct qelem *top;
294
295 top = GetListInfo(LIST, argv[1], (char *) NULL);
296 QueryLoop(top, NullPrint, RealUpdateList, "Update the list");
08345b74 297
08345b74 298 FreeQueue(top);
299 return(DM_NORMAL);
300}
301
85ca828a 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
309static char **
310SetDefaults(info, name)
311char ** info;
312char * 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);
075fe5bb 321 info[L_ACE_TYPE] = Strsave(DEFAULT_ACE_TYPE);
322 info[L_ACE_NAME] = Strsave(DEFAULT_ACE_NAME);
85ca828a 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
08345b74 328/* Function Name: AddList
329 * Description:
330 * Arguments: argc, argv - name of list in argv[1].
402461ad 331 * Returns: SUB_ERROR if list not created.
08345b74 332 */
333
85ca828a 334/* ARGSUSED */
08345b74 335int
336AddList(argc, argv)
337int argc;
338char **argv;
339{
340 static char *info[MAX_ARGS_SIZE], **add_args;
402461ad 341 int status, ret_code = SUB_NORMAL;
08345b74 342
08345b74 343 status = sms_query("get_list_info", 1, argv + 1, NullFunc,
461c03b6 344 (char *) NULL);
08345b74 345 if (status != SMS_NO_MATCH) {
402461ad 346 if (status == SMS_SUCCESS)
08345b74 347 Put_message("This list already exists.");
348 else
461c03b6 349 com_err(program_name, status, " in AddList.");
402461ad 350 return(SUB_ERROR);
08345b74 351 }
352
85ca828a 353 add_args = AskListInfo(SetDefaults(info,argv[1]), FALSE);
08345b74 354
355 if ( (status = sms_query("add_list", CountArgs(add_args), add_args,
402461ad 356 Scream, (char *) NULL)) != SMS_SUCCESS) {
461c03b6 357 com_err(program_name, status, " in AddList.");
08345b74 358 Put_message("List Not Created.");
402461ad 359 ret_code = SUB_ERROR;
08345b74 360 }
361
362 FreeInfo(info);
402461ad 363 return(ret_code);
08345b74 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
372int
461c03b6 373ListHelp()
08345b74 374{
375 static char * message[] = {
402461ad 376 "Listmaint handles the creation, deletion, and updating of lists.",
377 "A list can be a mailing list, a group list, or both.",
08345b74 378 "The concept behind lists is that a list has an owner",
402461ad 379 "- administrator - and members.",
380 "The administrator of a list may be another list.",
08345b74 381 "The members of a list can be users (login names), other lists,",
402461ad 382 "or address strings.",
08345b74 383 "You can use certain keys to do the following:",
402461ad 384 " Refresh the screen - Type ctrl-L.",
385 " Escape from a function - Type ctrl-C.",
386 " Suspend the program (temporarily) - Type ctrl-Z.",
08345b74 387 NULL,
461c03b6 388 };
08345b74 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 */
403int
404ListmaintMemberMenuEntry(m, argc, argv)
405Menu *m;
406int argc;
407char **argv;
408{
461c03b6 409 char temp_buf[BUFSIZ];
08345b74 410 char *list_name = argv[1];
075fe5bb 411 register int stat;
412
402461ad 413 if (!ValidName(list_name))
414 return(DM_QUIT);
08345b74 415
416 if (*argv[0] == 'a') { /* add_list */
402461ad 417 if (AddList(argc, argv) == SUB_ERROR)
08345b74 418 return(DM_QUIT);
419 (void) sprintf(temp_buf, "List '%s' created. Do you want to %s",
402461ad 420 list_name, "change its membership (y/n)? ");
08345b74 421 if (YesNoQuestion(temp_buf, TRUE) != TRUE )
422 return(DM_QUIT);
423 }
075fe5bb 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_ACCESS:
434 Put_message("You are not allowed to view this list.");
31791cff 435 break;
075fe5bb 436 default:
437 com_err(program_name, stat, " in get_list_info");
438 return(DM_QUIT);
439 }
08345b74 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
455int
456ListmaintMemberMenuExit(m)
457Menu *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
471void
461c03b6 472ListMembersByType(type)
08345b74 473char * type;
474{
475 char temp_buf[BUFSIZ];
461c03b6 476 register int status;
402461ad 477 char * args[10];
478
479 args[0] = current_list;
480 args[1] = NULL;
08345b74 481
482 found_some = FALSE;
402461ad 483 if ( (status = sms_query("get_members_of_list", CountArgs(args), args,
85ca828a 484 PrintByType, type)) != 0)
402461ad 485 com_err(program_name, status, " in ListMembersByType");
08345b74 486 if (!found_some) {
487 if (type == NULL)
488 Put_message("List is empty (no members).");
489 else {
490 sprintf(temp_buf,"No %s Members",type);
491 Put_message(temp_buf);
492 }
493 }
494}
495
496/* Function Name: ListAllMembers
497 * Description: lists all members of the current list.
498 * Arguments:
499 * Returns: DM_NORMAL
500 */
501
502int
503ListAllMembers()
504{
505 ListMembersByType(NULL);
506 return (DM_NORMAL);
507}
508
509/* Function Name: ListUserMembers
510 * Description: This function lists all members of a list of type "USER".
511 * Arguments: none
512 * Returns: DM_NORMAL.
513 */
514
515ListUserMembers()
516{
517 ListMembersByType("USER");
518 return(DM_NORMAL);
519}
520
521/* Function Name: ListListMembers
522 * Description: This function lists all members of a list of type "LIST".
523 * Arguments: none
524 * Returns: DM_NORMAL.
525 */
526
527ListListMembers()
528{
529 ListMembersByType("LIST");
530 return(DM_NORMAL);
531}
532
533/* Function Name: ListStringMembers
534 * Description:This function lists all members of a list of type "STRING".
535 * Arguments: none
536 * Returns: DM_NORMAL.
537 */
538
539ListStringMembers()
540{
541 ListMembersByType("STRING");
542 return(DM_NORMAL);
543}
544
545/* Function Name: GetMemberInfo
546 * Description: This function gets the information needed to
547 * add or delete a user from a list.
548 * Arguments: argc, argv - standard.
549 * action - name of the action to be performed either
550 * "add" or "delete".
551 * ret_argc, ret_argv - the returned value of argc and argv.
552 * Returns: SUB_ERROR or SUB_NORMAL.
553 */
554
555int
556GetMemberInfo(action, ret_argv)
557char *action, **ret_argv;
558{
559 char temp_buf[BUFSIZ], ret_buf[BUFSIZ];
560
561 ret_argv[LM_LIST] = Strsave(current_list);
08345b74 562
31791cff 563 ret_argv[LM_TYPE] = Strsave("user");
564 GetTypeFromUser("Type of member", "member", &ret_argv[LM_TYPE]);
0a2c64cb 565
402461ad 566 sprintf(temp_buf,"Name of %s to %s", ret_argv[LM_TYPE], action);
31791cff 567 ret_argv[LM_MEMBER] = Strsave(user);
568 GetValueFromUser(temp_buf, &ret_argv[LM_MEMBER]);
402461ad 569 ret_argv[LM_END] = NULL; /* NULL terminate this list. */
570
571 if (!ValidName( ret_argv[LM_MEMBER] ) ) {
572 FreeInfo(ret_argv);
573 return(SUB_ERROR);
574 }
08345b74 575 return(SUB_NORMAL);
576}
577
578/* Function Name: AddMember
579 * Description: This function adds a member to a list.
580 * Arguments: none.
581 * Returns: DM_NORMAL.
582 */
583
584int
585AddMember()
586{
402461ad 587 char *args[10], temp_buf[BUFSIZ];
461c03b6 588 register int status;
08345b74 589
402461ad 590 if ( GetMemberInfo("add", args) == SUB_ERROR )
08345b74 591 return(DM_NORMAL);
592
402461ad 593 if ( (status = sms_query("add_member_to_list", CountArgs(args), args,
594 Scream, NULL)) != SMS_SUCCESS) {
595 if (status == SMS_EXISTS) {
596 sprintf(temp_buf, "The %s %s is already a member of LIST %s.",
597 args[LM_TYPE], args[LM_MEMBER], args[LM_LIST]);
598 Put_message(temp_buf);
599 }
600 else
601 com_err(program_name, status, " in AddMember");
602 }
08345b74 603
604 FreeInfo(args);
402461ad 605 return(DM_NORMAL);
08345b74 606}
607
608/* Function Name: DeleteMember
609 * Description: This function deletes a member from a list.
610 * Arguments: none.
611 * Returns: DM_NORMAL
612 */
613
614int
615DeleteMember()
616{
617 char *args[10];
461c03b6 618 register int status;
08345b74 619
620 if( GetMemberInfo("delete", args) == SUB_ERROR )
621 return(DM_NORMAL);
622
623 if (Confirm("Are you sure you want to delete this member?") ) {
624 if (status = sms_query("delete_member_from_list", CountArgs(args),
625 args, Scream, NULL))
402461ad 626 com_err(program_name, status, " in DeleteMember");
08345b74 627 else
628 Put_message("Deletion Completed.");
629 }
630 else
631 Put_message("Deletion has been Aborted.");
632
633 FreeInfo(args);
634 return(DM_NORMAL);
635}
636
08345b74 637/* Function Name: InterRemoveItemFromLists
638 * Description: This function allows interactive removal of an item
639 * (user, string, list) for all list that it is on.
640 * Arguments: none.
641 * Returns: DM_NORMAL.
402461ad 642 * NOTES: QueryLoop() does not work here because info does not have
643 * enough information in it to delete the member from the list.
08345b74 644 */
645
646int
647InterRemoveItemFromLists()
648{
461c03b6 649 register int status;
402461ad 650 char type[BUFSIZ], name[BUFSIZ], *args[10], buf[BUFSIZ];
461c03b6 651 struct qelem *top, *elem;
08345b74 652
402461ad 653 if ( !(PromptWithDefault("Type of member (user, list, string)", type,
08345b74 654 BUFSIZ, "user")) )
655 return(DM_NORMAL);
656
402461ad 657 sprintf(buf, "Name of %s", type);
658 if ( !(PromptWithDefault(buf, name, BUFSIZ, user)) ) {
08345b74 659 return(DM_NORMAL);
660 }
661
402461ad 662 if (!ValidName(name))
663 return(DM_NORMAL);
664
08345b74 665 top = elem = GetListInfo(GLOM, type, name);
666
667 while(elem != NULL) {
402461ad 668 char line[BUFSIZ];
461c03b6 669 char ** info = (char **) elem->q_data;
402461ad 670 sprintf(line, "Delete %s %s from the list \"%s\" (y/n/q)? ", type,
671 name, info[GLOM_NAME]);
672 switch (YesNoQuitQuestion(line, FALSE)) {
673 case TRUE:
08345b74 674 Put_message("deleting...");
461c03b6 675 args[DM_LIST] = info[GLOM_NAME];
08345b74 676 args[DM_TYPE] = type;
677 args[DM_MEMBER] = name;
678 if ( (status = sms_query("delete_member_from_list", 3, args,
679 Scream, (char *) NULL)) != 0)
402461ad 680 /* should probabally check to delete list. */
461c03b6 681 com_err(program_name, status, " in delete_member");
08345b74 682 break;
402461ad 683 case FALSE:
684 break;
685 default:
686 Put_message("Aborting...");
687 FreeQueue(top);
688 return(DM_NORMAL);
08345b74 689 }
690 elem = elem->q_forw;
691 }
692 FreeQueue(top);
693 return(DM_NORMAL);
694}
695
696/*-*-* LIST MENU *-*-*/
697
698/* Function Name: ListByMember
699 * Description: This gets all lists that a given member is a member of.
461c03b6 700 * Arguments: none.
08345b74 701 * Returns: DM_NORMAL.
702 */
703
704int
461c03b6 705ListByMember()
08345b74 706{
402461ad 707 char buf[BUFSIZ], temp_buf[BUFSIZ], *type, *name, **info;
461c03b6 708 Bool maillist, group;
709 struct qelem *top, *elem;
08345b74 710
402461ad 711 if ( !(PromptWithDefault("Type of member (user, list, string)", buf,
08345b74 712 BUFSIZ, "user")) )
713 return(DM_NORMAL);
714
402461ad 715 /* What we really want is a recursive search */
716 sprintf(temp_buf, "R%s", buf);
717 type = Strsave(temp_buf);
718
719 sprintf(temp_buf, "Name of %s", buf);
720 if ( !(PromptWithDefault(temp_buf, buf, BUFSIZ, user)) ) {
08345b74 721 free(type);
722 return(DM_NORMAL);
723 }
724 name = Strsave(buf);
725
726 maillist = YesNoQuestion("Show only Lists that are Maillists (y/n) ?",
727 TRUE);
728 group = YesNoQuestion("Show only Lists that are Groups (y/n) ?", TRUE);
729
730 elem = top = GetListInfo(GLOM, type, name);
731
732 while (elem != NULL) {
733 info = (char**) elem->q_data;
734 if (maillist != TRUE || !strcmp(info[GLOM_MAILLIST], "1"))
735 if (group != TRUE || !strcmp(info[GLOM_GROUP], "1"))
736 Put_message(info[GLOM_NAME]);
737 elem = elem->q_forw;
738 }
739 FreeQueue(top);
740 return (DM_NORMAL);
741}
742
743/* Function Name: ListByAdministrator
744 * Description: This function prints all lists which a given user or
745 * group administers.
461c03b6 746 * Arguments: none.
08345b74 747 * Returns: DM_NORMAL.
748 */
749
750int
461c03b6 751ListByAdministrator()
08345b74 752{
402461ad 753 char buf[BUFSIZ], temp_buf[BUFSIZ], *type, *name;
754 struct qelem *top;
08345b74 755
402461ad 756 if ( !(PromptWithDefault("Type of member (user, list, string)", buf,
08345b74 757 BUFSIZ, "user")) )
758 return(DM_NORMAL);
759
402461ad 760 if ( YesNoQuestion("Do you want a recursive search (y/n)", TRUE) == 1 ) {
761 sprintf(temp_buf, "R%s", buf); /* "USER" to "RUSER" etc. */
762 type = Strsave(temp_buf);
763 }
764 else
765 type = Strsave(buf);
08345b74 766
402461ad 767 sprintf(temp_buf, "Name of %s", buf);
768 if ( !(PromptWithDefault(temp_buf, buf, BUFSIZ, user)) ) {
08345b74 769 free(type);
770 return(DM_NORMAL);
771 }
772 name = Strsave(buf);
773
075fe5bb 774 top = GetListInfo(ACE_USE, type, name);
775 Loop(top, PrintListAce);
402461ad 776
08345b74 777 FreeQueue(top);
778 return (DM_NORMAL);
779}
780
781/* Function Name: ListAllGroups
782 * Description: This function lists all visable groups.
783 * Arguments: none.
784 * Returns: DM_NORMAL.
785 */
786
787ListAllGroups()
788{
461c03b6 789 register int status;
08345b74 790 static char * args[] = {
791 "TRUE", /* active */
792 "DONTCARE", /* public */
793 "FALSE", /* hidden */
794 "DONTCARE", /* maillist */
795 "TRUE", /* group. */
461c03b6 796 };
08345b74 797
798 if (YesNoQuestion("This query will take a while, Do you wish to continue?",
461c03b6 799 TRUE) == TRUE )
08345b74 800 if (status = sms_query("qualified_get_lists", 5, args,
801 Print, (char *) NULL) != 0)
402461ad 802 com_err(program_name, status, " in ListAllGroups");
08345b74 803 return (DM_NORMAL);
804}
805
806/* Function Name: ListAllMailLists
807 * Description: This function lists all visable maillists.
808 * Arguments: none
809 * Returns: DM_NORMAL.
810 */
811
812ListAllMailLists()
813{
461c03b6 814 register int status;
08345b74 815 static char * args[] = {
816 "TRUE", /* active */
817 "DONTCARE", /* public */
818 "FALSE", /* hidden */
819 "TRUE", /* maillist */
820 "DONTCARE", /* group. */
461c03b6 821 };
08345b74 822
823 if (YesNoQuestion("This query will take a while. Do you wish to continue?",
461c03b6 824 TRUE) == TRUE )
08345b74 825 if (status = sms_query("qualified_get_lists", 5, args,
826 Print, (char *) NULL) != 0)
402461ad 827 com_err(program_name, status, " in ListAllGroups");
08345b74 828
829 return (DM_NORMAL);
830}
831
832/* Function Name: ListAllPublicMailLists
833 * Description: This function lists all public mailing lists.
834 * Arguments: none
835 * Returns: DM_NORMAL.
836 */
837
838ListAllPublicMailLists()
839{
461c03b6 840 register int status;
08345b74 841 static char * args[] = {
842 "TRUE", /* active */
843 "TRUE", /* public */
844 "FALSE", /* hidden */
845 "TRUE", /* maillist */
846 "DONTCARE", /* group. */
461c03b6 847 };
08345b74 848
849 if (YesNoQuestion("This query will take a while. Do you wish to continue?",
461c03b6 850 TRUE) == TRUE )
08345b74 851 if (status = sms_query("qualified_get_lists", 5, args,
852 Print, (char *) NULL) != 0)
402461ad 853 com_err(program_name, status, " in ListAllGroups");
08345b74 854
855 return (DM_NORMAL);
856}
857
858/*
859 * Local Variables:
860 * mode: c
861 * c-indent-level: 4
862 * c-continued-statement-offset: 4
863 * c-brace-offset: -4
864 * c-argdecl-indent: 4
865 * c-label-offset: -4
866 * End:
867 */
This page took 0.181535 seconds and 5 git commands to generate.