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 struct sigaction act;
198 if ((program_name = strrchr(argv[0], '/')) == NULL)
199 program_name = argv[0];
202 program_name = Strsave(program_name);
203 whoami = Strsave(program_name); /* used by menu.c, ugh !!! */
209 while (++arg - argv < argc) {
211 if (!strcmp(*arg, "-nomenu"))
213 else if (!strcmp(*arg, "-db"))
214 if (arg - argv < argc - 1) {
224 if ( status = mr_connect(moira_server) )
225 ErrorExit("\nConnection to Moira server failed", status);
227 /* do this now since calling mr_connect initialized the krb error table
230 if ((status = tf_init(TKT_FILE, R_TKT_FIL)) ||
231 (status = tf_get_pname(pname))) {
232 com_err(whoami, status, "cannot find your ticket file");
236 user = Strsave(pname);
238 if ( status = mr_motd(&motd) )
239 ErrorExit("\nUnable to check server status", status);
241 fprintf(stderr, "The Moira server is currently unavailable:\n%s\n", motd);
246 if ( status = mr_auth(program_name) ) {
247 if (status == MR_USER_AUTH) {
249 com_err(program_name, status, "\nPress [RETURN] to continue");
252 ErrorExit("\nAuthorization failed -- please run kinit", status);
256 * These signals should not be set until just before we fire up the menu
262 sigemptyset(&act.sa_mask);
264 act.sa_handler= (void (*)()) SignalHandler;
265 (void) sigaction(SIGHUP, &act, NULL);
266 (void) sigaction(SIGQUIT, &act, NULL);
268 (void) sigaction(SIGINT, &act, NULL);
270 act.sa_handler= (void (*)()) CatchInterrupt;
271 (void) sigaction(SIGINT, &act, NULL);
274 (void) signal(SIGHUP, SignalHandler);
275 (void) signal(SIGQUIT, SignalHandler);
277 (void) signal(SIGINT, SignalHandler);
279 (void) signal(SIGINT, CatchInterrupt);
283 menu = &namespace_menu;
285 if (use_menu) { /* Start menus that execute program */
290 else /* Start program without menus. */
297 /* Function Name: ErrorExit
298 * Description: This function does the error handling and exits.
299 * Arguments: buf - the error message to print.
300 * status - the error code.
301 * Returns: doesn't return.
305 ErrorExit(buf,status)
309 com_err(program_name, status, buf);
314 /* Function Name: usage
315 * Description: Prints usage info and then exits.
317 * Returns: doesn't return.
323 fprintf(stderr, "Usage: %s [-nomenu]\n", program_name);
328 /* Function Name: SignalHandler
329 * Description: This function cleans up from a signal interrupt.
337 Put_message("Signal caught - exiting");
348 Put_message("Interrupt! Press RETURN to continue");
354 /* Dummy routine to be able to link against the rest of the moira client */
365 static char * message[] = {
366 "A list can be a mailing list, an Athena group list, or both. Each",
367 "list has an owner and members. The owner of a list may be the list",
368 "itself, another list, or a user. The members of a list can be users",
369 "(login names), other lists, or foreign address strings. You can use",
370 "certain keys to do the following:",
371 " Refresh the screen - Type ctrl-L.",
372 " Escape from a function - Type ctrl-C.",
376 return(PrintHelp(message));