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>
28 static void ErrorExit(char *buf, int status);
29 static void Usage(void);
30 static void Signal_Handler(void);
31 static void CatchInterrupt(void);
32 int NewListHelp(int argc, char **argv);
34 char *whoami; /* used by menu.c ugh!!! */
39 * List Information Menu
42 Menu list_info_menu = {
45 "List Information Menu",
48 SIMPLEFUNC("member", "Show all lists to which a given member belongs",
50 SIMPLEFUNC("admin", "Show all items which a given member can administer",
52 SIMPLEFUNC("public", "Show all public mailing lists",
53 ListAllPublicMailLists),
61 Menu list_member_menu = {
62 ListmaintMemberMenuEntry,
63 ListmaintMemberMenuExit,
67 SIMPLEFUNC("add", "Add a member to this list", AddMember),
68 SIMPLEFUNC("remove", "Remove a member from this list", DeleteMember),
69 SIMPLEFUNC("show", "Show the members of this list", ListAllMembers),
70 SIMPLEFUNC("verbose", "Toggle Verbosity of Delete", ToggleVerboseMode)
84 { ShowListInfo, NULLMENU, 2, {
85 {"show", "Display information about a list"},
86 {"list name", "Name of list: "}
88 { UpdateList, NULLMENU, 2, {
89 {"update", "Update characteristics of a list"},
90 {"list name", "Name of list: "}
92 SIMPLEFUNC("query_remove",
93 "Interactively remove a member from all lists",
94 InterRemoveItemFromLists),
95 { NULLFUNC, &list_member_menu, 2, {
96 {"members", "Member Menu - Change/Show Members of a List."},
97 {"list name", "Name of list: "}
99 SUBMENU("lists", "Find Mailing Lists Menu",
101 SIMPLEFUNC("help", "Print Help", NewListHelp)
106 * Post Office Box Menu
112 "Mail Forwarding Menu",
115 {GetUserPOBox, NULLMENU, 2, {
116 {"show", "Show a user's post office box"},
117 {"user name", "user name: "}
119 {SetUserPOBox, NULLMENU, 2, {
120 {"set", "Set a user's post office box (mail forwarding)"},
121 {"user name", "user name: "}
123 {RemoveUserPOBox, NULLMENU, 2, {
124 {"remove", "Remove a user's post office box"},
125 {"user name", "user name: "}
137 "Miscellaneous Menu",
140 SIMPLEFUNC("statistics", "Show database statistics", TableStats),
141 SIMPLEFUNC("clients", "Show active Moira clients", ShowClients),
146 Menu namespace_menu = {
149 "Campus Namespace Database Manipulation",
152 SUBMENU("mail", "Mail Forwarding", &pobox_menu),
153 SUBMENU("list", "Mailing Lists", &list_menu),
154 {ShowUserByLogin, NULLMENU, 2, {
155 {"account", "Show user account information"},
156 {"login name", "Desired login name: "}
158 SUBMENU("misc", "Miscellaneous", &misc_menu)
163 Bool use_menu = TRUE; /* whether or not we are using a menu. */
166 /* Function Name: main
167 * Description: The main driver for the Moira Client.
168 * Arguments: argc, argv - standard command line args.
169 * Returns: doesn't return.
172 int main(int argc, char **argv)
177 struct sigaction act;
179 if (!(program_name = strrchr(argv[0], '/')))
180 program_name = argv[0];
183 program_name = strdup(program_name);
184 whoami = strdup(program_name); /* used by menu.c, ugh !!! */
186 user = mrcl_krb_user();
194 while (++arg - argv < argc)
198 if (!strcmp(*arg, "-nomenu"))
206 else if (!strcmp(*arg, "-menu"))
211 fprintf(stderr, "%s: No curses support. -menu option ignored\n",
215 else if (!strcmp(*arg, "-db"))
216 if (arg - argv < argc - 1)
228 if (mrcl_connect(moira_server, program_name, QUERY_VERSION, 0)
232 if ((status = mr_krb5_auth(program_name)))
234 if (status == MR_UNKNOWN_PROC)
235 status = mr_auth(program_name);
239 if (status == MR_USER_AUTH)
242 com_err(program_name, status, "\nPress [RETURN] to continue");
243 fgets(buf, BUFSIZ, stdin);
246 ErrorExit("\nAuthorization failed -- please run kinit", status);
251 * These signals should not be set until just before we fire up the menu
255 sigemptyset(&act.sa_mask);
257 act.sa_handler = Signal_Handler;
258 sigaction(SIGHUP, &act, NULL);
259 sigaction(SIGQUIT, &act, NULL);
262 sigaction(SIGINT, &act, NULL);
266 act.sa_handler = CatchInterrupt;
267 sigaction(SIGINT, &act, NULL);
270 menu = &namespace_menu;
273 if (use_menu) /* Start menus that execute program */
279 else /* Start program without menus. */
287 /* Function Name: ErrorExit
288 * Description: This function does the error handling and exits.
289 * Arguments: buf - the error message to print.
290 * status - the error code.
291 * Returns: doesn't return.
294 static void ErrorExit(char *buf, int status)
296 com_err(program_name, status, buf);
301 /* Function Name: usage
302 * Description: Prints usage info and then exits.
304 * Returns: doesn't return.
307 static void Usage(void)
309 fprintf(stderr, "Usage: %s [-nomenu]\n", program_name);
313 /* Function Name: Signal_Handler
314 * Description: This function cleans up from a signal interrupt.
319 static void Signal_Handler(void)
321 Put_message("Signal caught - exiting");
331 static void CatchInterrupt(void)
333 Put_message("Interrupt! Press RETURN to continue");
338 /* Dummy routine to be able to link against the rest of the moira client */
340 int DeleteUser(int argc, char **argv)
346 int NewListHelp(int argc, char **argv)
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);