1 #if (!defined(lint) && !defined(SABER))
2 static char rcsid_module_c[] = "$Header$";
5 /* This is the file main.c for the Moira Client, which allows a nieve
6 * user to quickly and easily maintain most parts of the Moira database.
7 * It Contains: The main driver for the Moira Client.
10 * By: Chris D. Peterson
16 * Copyright 1988 by the Massachusetts Institute of Technology.
18 * For further information on copyright and distribution
19 * see the file mit-copyright.h
26 #include <sys/types.h>
32 #include "mit-copyright.h"
37 char * whoami; /* used by menu.c ugh!!! */
43 * List Information Menu
46 Menu list_info_menu = {
49 "List Information Menu",
52 SIMPLEFUNC("member", "Show all lists to which a given member belongs",
55 "Show all items which a given member can administer",
57 SIMPLEFUNC("public", "Show all public mailing lists",
58 ListAllPublicMailLists),
59 SIMPLEFUNC("maillists", "Show all mailing lists",
68 Menu list_member_menu = {
69 ListmaintMemberMenuEntry,
70 ListmaintMemberMenuExit,
74 SIMPLEFUNC("add", "Add a member to this list", AddMember),
75 SIMPLEFUNC("remove", "Remove a member from this list", DeleteMember),
76 SIMPLEFUNC("show", "Show the members of this list", ListAllMembers),
77 SIMPLEFUNC("verbose", "Toggle Verbosity of Delete", ToggleVerboseMode)
91 { ShowListInfo, NULLMENU, 2, {
92 {"show", "Display information about a list"},
93 {"list name", "Name of list: "}
95 { UpdateList, NULLMENU, 2, {
96 {"update", "Update characteristics of a list"},
97 {"list name", "Name of list: "}
99 SIMPLEFUNC("query_remove",
100 "Interactively remove a member from all lists",
101 InterRemoveItemFromLists),
102 { NULLFUNC, &list_member_menu, 2, {
103 {"members", "Member Menu - Change/Show Members of a List."},
104 {"list name", "Name of list: "}
106 SUBMENU("lists", "Find Mailing Lists Menu",
108 SIMPLEFUNC("help", "Print Help", NewListHelp)
113 * Post Office Box Menu
119 "Mail Forwarding Menu",
122 {GetUserPOBox, NULLMENU, 2, {
123 {"show", "Show a user's post office box"},
124 {"user name", "user name: "}
126 {SetUserPOBox, NULLMENU, 2, {
127 {"set", "Set a user's post office box (mail forwarding)"},
128 {"user name", "user name: "}
130 {RemoveUserPOBox, NULLMENU, 2, {
131 {"remove", "Remove a user's post office box"},
132 {"user name", "user name: "}
144 "Miscellaneous Menu",
147 SIMPLEFUNC("statistics", "Show database statistics", TableStats),
148 SIMPLEFUNC("clients", "Show active Moira clients", ShowClients),
153 Menu namespace_menu = {
156 "Campus Namespace Database Manipulation",
159 SUBMENU("mail","Mail Forwarding", &pobox_menu),
160 SUBMENU("list","Mailing Lists", &list_menu),
161 {ShowUserByLogin, NULLMENU, 2, {
162 {"account", "Show user account information"},
163 {"login name", "Desired login name: "}
165 SUBMENU("misc", "Miscellaneous", &misc_menu)
171 static void SignalHandler(), CatchInterrupt();
174 static void ErrorExit(), Usage();
177 struct passwd *getpwuid();
179 Bool use_menu = TRUE; /* whether or not we are using a menu. */
181 /* Function Name: main
182 * Description: The main driver for the Moira Client.
183 * Arguments: argc, argv - standard command line args.
184 * Returns: doesn't return.
195 char pname[ANAME_SZ];
197 if ((program_name = rindex(argv[0], '/')) == NULL)
198 program_name = argv[0];
201 program_name = Strsave(program_name);
202 whoami = Strsave(program_name); /* used by menu.c, ugh !!! */
208 while (++arg - argv < argc) {
210 if (!strcmp(*arg, "-nomenu"))
212 else if (!strcmp(*arg, "-db"))
213 if (arg - argv < argc - 1) {
223 if ( status = mr_connect(moira_server) )
224 ErrorExit("\nConnection to Moira server failed", status);
226 /* do this now since calling mr_connect initialized the krb error table
229 if ((status = tf_init(TKT_FILE, R_TKT_FIL)) ||
230 (status = tf_get_pname(pname))) {
231 com_err(whoami, status, "cannot find your ticket file");
235 user = Strsave(pname);
237 if ( status = mr_motd(&motd) )
238 ErrorExit("\nUnable to check server status", status);
240 fprintf(stderr, "The Moira server is currently unavailable:\n%s\n", motd);
245 if ( status = mr_auth(program_name) ) {
246 if (status == MR_USER_AUTH) {
248 com_err(program_name, status, "\nPress [RETURN] to continue");
251 ErrorExit("\nAuthorization failed -- please run kinit", status);
255 * These signals should not be set until just before we fire up the menu
260 (void) signal(SIGHUP, SignalHandler);
261 (void) signal(SIGQUIT, SignalHandler);
263 (void) signal(SIGINT, SignalHandler);
265 (void) signal(SIGINT, CatchInterrupt);
268 menu = &namespace_menu;
270 if (use_menu) { /* Start menus that execute program */
275 else /* Start program without menus. */
282 /* Function Name: ErrorExit
283 * Description: This function does the error handling and exits.
284 * Arguments: buf - the error message to print.
285 * status - the error code.
286 * Returns: doesn't return.
290 ErrorExit(buf,status)
294 com_err(program_name, status, buf);
299 /* Function Name: usage
300 * Description: Prints usage info and then exits.
302 * Returns: doesn't return.
308 fprintf(stderr, "Usage: %s [-nomenu]\n", program_name);
313 /* Function Name: SignalHandler
314 * Description: This function cleans up from a signal interrupt.
322 Put_message("Signal caught - exiting");
333 Put_message("Interrupt! Press RETURN to continue");
339 /* Dummy routine to be able to link against the rest of the moira client */
350 static char * message[] = {
351 "A list can be a mailing list, an Athena group list, or both. Each",
352 "list has an owner and members. The owner of a list may be the list",
353 "itself, another list, or a user. The members of a list can be users",
354 "(login names), other lists, or foreign address strings. You can use",
355 "certain keys to do the following:",
356 " Refresh the screen - Type ctrl-L.",
357 " Escape from a function - Type ctrl-C.",
361 return(PrintHelp(message));