3 * This is the file main.c for the Moira Client, which allows users
4 * to quickly and easily maintain most parts of the Moira database.
5 * It Contains: The main driver for the Moira Client.
8 * By: Chris D. Peterson
10 * Copyright (C) 1988-1998 by the Massachusetts Institute of Technology.
11 * For copying and distribution information, please see the file
15 #include <mit-copyright.h>
29 static void ErrorExit(char *buf, int status);
30 static void Usage(void);
31 static void Signal_Handler(void);
32 static void CatchInterrupt(void);
33 int NewListHelp(int argc, char **argv);
35 char *whoami; /* used by menu.c ugh!!! */
40 * List Information Menu
43 Menu list_info_menu = {
46 "List Information Menu",
49 SIMPLEFUNC("member", "Show all lists to which a given member belongs",
51 SIMPLEFUNC("admin", "Show all items which a given member can administer",
53 SIMPLEFUNC("public", "Show all public mailing lists",
54 ListAllPublicMailLists),
62 Menu list_member_menu = {
63 ListmaintMemberMenuEntry,
64 ListmaintMemberMenuExit,
68 SIMPLEFUNC("add", "Add a member to this list", AddMember),
69 SIMPLEFUNC("remove", "Remove a member from this list", DeleteMember),
70 SIMPLEFUNC("show", "Show the members of this list", ListAllMembers),
71 SIMPLEFUNC("verbose", "Toggle Verbosity of Delete", ToggleVerboseMode)
85 { ShowListInfo, NULLMENU, 2, {
86 {"show", "Display information about a list"},
87 {"list name", "Name of list: "}
89 { UpdateList, NULLMENU, 2, {
90 {"update", "Update characteristics of a list"},
91 {"list name", "Name of list: "}
93 SIMPLEFUNC("query_remove",
94 "Interactively remove a member from all lists",
95 InterRemoveItemFromLists),
96 { NULLFUNC, &list_member_menu, 2, {
97 {"members", "Member Menu - Change/Show Members of a List."},
98 {"list name", "Name of list: "}
100 SUBMENU("lists", "Find Mailing Lists Menu",
102 SIMPLEFUNC("help", "Print Help", NewListHelp)
107 * Post Office Box Menu
113 "Mail Forwarding Menu",
116 {GetUserPOBox, NULLMENU, 2, {
117 {"show", "Show a user's post office box"},
118 {"user name", "user name: "}
120 {SetUserPOBox, NULLMENU, 2, {
121 {"set", "Set a user's post office box (mail forwarding)"},
122 {"user name", "user name: "}
124 {RemoveUserPOBox, NULLMENU, 2, {
125 {"remove", "Remove a user's post office box"},
126 {"user name", "user name: "}
138 "Miscellaneous Menu",
141 SIMPLEFUNC("statistics", "Show database statistics", TableStats),
142 SIMPLEFUNC("clients", "Show active Moira clients", ShowClients),
147 Menu namespace_menu = {
150 "Campus Namespace Database Manipulation",
153 SUBMENU("mail", "Mail Forwarding", &pobox_menu),
154 SUBMENU("list", "Mailing Lists", &list_menu),
155 {ShowUserByLogin, NULLMENU, 2, {
156 {"account", "Show user account information"},
157 {"login name", "Desired login name: "}
159 SUBMENU("misc", "Miscellaneous", &misc_menu)
164 Bool use_menu = TRUE; /* whether or not we are using a menu. */
167 /* Function Name: main
168 * Description: The main driver for the Moira Client.
169 * Arguments: argc, argv - standard command line args.
170 * Returns: doesn't return.
173 void main(int argc, char **argv)
178 char pname[ANAME_SZ];
179 struct sigaction act;
181 if (!(program_name = strrchr(argv[0], '/')))
182 program_name = argv[0];
185 program_name = strdup(program_name);
186 whoami = strdup(program_name); /* used by menu.c, ugh !!! */
192 while (++arg - argv < argc)
196 if (!strcmp(*arg, "-nomenu"))
204 else if (!strcmp(*arg, "-menu"))
209 fprintf(stderr, "%s: No curses support. -menu option ignored\n",
213 else if (!strcmp(*arg, "-db"))
214 if (arg - argv < argc - 1)
226 if ((status = mr_connect(moira_server)))
227 ErrorExit("\nConnection to Moira server failed", status);
229 /* do this now since calling mr_connect initialized the krb error table
232 if ((status = tf_init(TKT_FILE, R_TKT_FIL)) ||
233 (status = tf_get_pname(pname)))
235 com_err(whoami, status, "cannot find your ticket file");
239 user = strdup(pname);
241 if ((status = mr_motd(&motd)))
242 ErrorExit("\nUnable to check server status", status);
245 fprintf(stderr, "The Moira server is currently unavailable:\n%s\n",
251 if ((status = mr_auth(program_name)))
253 if (status == MR_USER_AUTH)
256 com_err(program_name, status, "\nPress [RETURN] to continue");
257 fgets(buf, BUFSIZ, stdin);
260 ErrorExit("\nAuthorization failed -- please run kinit", status);
264 * These signals should not be set until just before we fire up the menu
268 sigemptyset(&act.sa_mask);
270 act.sa_handler = Signal_Handler;
271 sigaction(SIGHUP, &act, NULL);
272 sigaction(SIGQUIT, &act, NULL);
275 sigaction(SIGINT, &act, NULL);
279 act.sa_handler = CatchInterrupt;
280 sigaction(SIGINT, &act, NULL);
283 menu = &namespace_menu;
286 if (use_menu) /* Start menus that execute program */
292 else /* Start program without menus. */
300 /* Function Name: ErrorExit
301 * Description: This function does the error handling and exits.
302 * Arguments: buf - the error message to print.
303 * status - the error code.
304 * Returns: doesn't return.
307 static void ErrorExit(char *buf, int 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.
320 static void Usage(void)
322 fprintf(stderr, "Usage: %s [-nomenu]\n", program_name);
326 /* Function Name: Signal_Handler
327 * Description: This function cleans up from a signal interrupt.
332 static void Signal_Handler(void)
334 Put_message("Signal caught - exiting");
344 static void CatchInterrupt(void)
346 Put_message("Interrupt! Press RETURN to continue");
351 /* Dummy routine to be able to link against the rest of the moira client */
353 int DeleteUser(int argc, char **argv)
359 int NewListHelp(int argc, char **argv)
361 static char *message[] = {
362 "A list can be a mailing list, an Athena group list, or both. Each",
363 "list has an owner and members. The owner of a list may be the list",
364 "itself, another list, or a user. The members of a list can be users",
365 "(login names), other lists, or foreign address strings. You can use",
366 "certain keys to do the following:",
367 " Refresh the screen - Type ctrl-L.",
368 " Escape from a function - Type ctrl-C.",
372 return PrintHelp(message);