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