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