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),
66 Menu list_member_menu = {
67 ListmaintMemberMenuEntry,
68 ListmaintMemberMenuExit,
72 SIMPLEFUNC("add", "Add a member to this list", AddMember),
73 SIMPLEFUNC("remove", "Remove a member from this list", DeleteMember),
74 SIMPLEFUNC("show", "Show the members of this list", ListAllMembers),
75 SIMPLEFUNC("verbose", "Toggle Verbosity of Delete", ToggleVerboseMode)
89 { ShowListInfo, NULLMENU, 2, {
90 {"show", "Display information about a list"},
91 {"list name", "Name of list: "}
93 { UpdateList, NULLMENU, 2, {
94 {"update", "Update characteristics of a list"},
95 {"list name", "Name of list: "}
97 SIMPLEFUNC("query_remove",
98 "Interactively remove a member from all lists",
99 InterRemoveItemFromLists),
100 { NULLFUNC, &list_member_menu, 2, {
101 {"members", "Member Menu - Change/Show Members of a List."},
102 {"list name", "Name of list: "}
104 SUBMENU("lists", "Find Mailing Lists Menu",
106 SIMPLEFUNC("help", "Print Help", NewListHelp)
111 * Post Office Box Menu
117 "Mail Forwarding Menu",
120 {GetUserPOBox, NULLMENU, 2, {
121 {"show", "Show a user's post office box"},
122 {"user name", "user name: "}
124 {SetUserPOBox, NULLMENU, 2, {
125 {"set", "Set a user's post office box (mail forwarding)"},
126 {"user name", "user name: "}
128 {RemoveUserPOBox, NULLMENU, 2, {
129 {"remove", "Remove a user's post office box"},
130 {"user name", "user name: "}
142 "Miscellaneous Menu",
145 SIMPLEFUNC("statistics", "Show database statistics", TableStats),
146 SIMPLEFUNC("clients", "Show active Moira clients", ShowClients),
151 Menu namespace_menu = {
154 "Campus Namespace Database Manipulation",
157 SUBMENU("mail","Mail Forwarding", &pobox_menu),
158 SUBMENU("list","Mailing Lists", &list_menu),
159 {ShowUserByLogin, NULLMENU, 2, {
160 {"account", "Show user account information"},
161 {"login name", "Desired login name: "}
163 SUBMENU("misc", "Miscellaneous", &misc_menu)
169 static void SignalHandler(), CatchInterrupt();
172 static void ErrorExit(), Usage();
175 struct passwd *getpwuid();
177 Bool use_menu = TRUE; /* whether or not we are using a menu. */
179 /* Function Name: main
180 * Description: The main driver for the Moira Client.
181 * Arguments: argc, argv - standard command line args.
182 * Returns: doesn't return.
193 char pname[ANAME_SZ];
195 if ((program_name = rindex(argv[0], '/')) == NULL)
196 program_name = argv[0];
199 program_name = Strsave(program_name);
200 whoami = Strsave(program_name); /* used by menu.c, ugh !!! */
206 while (++arg - argv < argc) {
208 if (!strcmp(*arg, "-nomenu"))
210 else if (!strcmp(*arg, "-db"))
211 if (arg - argv < argc - 1) {
221 if ( status = mr_connect(moira_server) )
222 ErrorExit("\nConnection to Moira server failed", status);
224 /* do this now since calling mr_connect initialized the krb error table
227 if ((status = tf_init(TKT_FILE, R_TKT_FIL)) ||
228 (status = tf_get_pname(pname))) {
229 com_err(whoami, status, "cannot find your ticket file");
233 user = Strsave(pname);
235 if ( status = mr_motd(&motd) )
236 ErrorExit("\nUnable to check server status", status);
238 fprintf(stderr, "The Moira server is currently unavailable:\n%s\n", motd);
243 if ( status = mr_auth(program_name) ) {
244 if (status == MR_USER_AUTH) {
246 com_err(program_name, status, "\nPress [RETURN] to continue");
249 ErrorExit("\nAuthorization failed -- please run kinit", status);
253 * These signals should not be set until just before we fire up the menu
258 (void) signal(SIGHUP, SignalHandler);
259 (void) signal(SIGQUIT, SignalHandler);
261 (void) signal(SIGINT, SignalHandler);
263 (void) signal(SIGINT, CatchInterrupt);
266 menu = &namespace_menu;
268 if (use_menu) { /* Start menus that execute program */
273 else /* Start program without menus. */
280 /* Function Name: ErrorExit
281 * Description: This function does the error handling and exits.
282 * Arguments: buf - the error message to print.
283 * status - the error code.
284 * Returns: doesn't return.
288 ErrorExit(buf,status)
292 com_err(program_name, status, buf);
297 /* Function Name: usage
298 * Description: Prints usage info and then exits.
300 * Returns: doesn't return.
306 fprintf(stderr, "Usage: %s [-nomenu]\n", program_name);
311 /* Function Name: SignalHandler
312 * Description: This function cleans up from a signal interrupt.
320 Put_message("Signal caught - exiting");
331 Put_message("Interrupt! Press RETURN to continue");
337 /* Dummy routine to be able to link against the rest of the moira client */
348 static char * message[] = {
349 "A list can be a mailing list, an Athena group list, or both. Each",
350 "list has an owner and members. The owner of a list may be the list",
351 "itself, another list, or a user. The members of a list can be users",
352 "(login names), other lists, or foreign address strings. You can use",
353 "certain keys to do the following:",
354 " Refresh the screen - Type ctrl-L.",
355 " Escape from a function - Type ctrl-C.",
359 return(PrintHelp(message));