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>
26 #include <sys/types.h>
33 static void ErrorExit(char *buf, int status);
34 static void Usage(void);
35 static void Signal_Handler(void);
36 static void CatchInterrupt(void);
37 int NewListHelp(int argc, char **argv);
39 char *whoami; /* used by menu.c ugh!!! */
44 * List Information Menu
47 Menu list_info_menu = {
50 "List Information Menu",
53 SIMPLEFUNC("member", "Show all lists to which a given member belongs",
55 SIMPLEFUNC("admin", "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)
167 Bool use_menu = TRUE; /* whether or not we are using a menu. */
169 /* Function Name: main
170 * Description: The main driver for the Moira Client.
171 * Arguments: argc, argv - standard command line args.
172 * Returns: doesn't return.
175 void main(int argc, char **argv)
180 char pname[ANAME_SZ];
181 struct sigaction act;
183 if (!(program_name = strrchr(argv[0], '/')))
184 program_name = argv[0];
187 program_name = strdup(program_name);
188 whoami = strdup(program_name); /* used by menu.c, ugh !!! */
194 while (++arg - argv < argc)
198 if (!strcmp(*arg, "-nomenu"))
200 else if (!strcmp(*arg, "-db"))
201 if (arg - argv < argc - 1)
213 if ((status = mr_connect(moira_server)))
214 ErrorExit("\nConnection to Moira server failed", status);
216 /* do this now since calling mr_connect initialized the krb error table
219 if ((status = tf_init(TKT_FILE, R_TKT_FIL)) ||
220 (status = tf_get_pname(pname)))
222 com_err(whoami, status, "cannot find your ticket file");
226 user = strdup(pname);
228 if ((status = mr_motd(&motd)))
229 ErrorExit("\nUnable to check server status", status);
232 fprintf(stderr, "The Moira server is currently unavailable:\n%s\n",
238 if ((status = mr_auth(program_name)))
240 if (status == MR_USER_AUTH)
243 com_err(program_name, status, "\nPress [RETURN] to continue");
244 fgets(buf, BUFSIZ, stdin);
247 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);
261 sigaction(SIGINT, &act, NULL);
264 act.sa_handler = CatchInterrupt;
265 sigaction(SIGINT, &act, NULL);
268 menu = &namespace_menu;
270 if (use_menu) /* Start menus that execute program */
276 else /* Start program without menus. */
283 /* Function Name: ErrorExit
284 * Description: This function does the error handling and exits.
285 * Arguments: buf - the error message to print.
286 * status - the error code.
287 * Returns: doesn't return.
290 static void ErrorExit(char *buf, int 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.
303 static void Usage(void)
305 fprintf(stderr, "Usage: %s [-nomenu]\n", program_name);
309 /* Function Name: Signal_Handler
310 * Description: This function cleans up from a signal interrupt.
315 static void Signal_Handler(void)
317 Put_message("Signal caught - exiting");
325 static void CatchInterrupt(void)
327 Put_message("Interrupt! Press RETURN to continue");
332 /* Dummy routine to be able to link against the rest of the moira client */
334 int DeleteUser(int argc, char **argv)
340 int NewListHelp(int argc, char **argv)
342 static char *message[] = {
343 "A list can be a mailing list, an Athena group list, or both. Each",
344 "list has an owner and members. The owner of a list may be the list",
345 "itself, another list, or a user. The members of a list can be users",
346 "(login names), other lists, or foreign address strings. You can use",
347 "certain keys to do the following:",
348 " Refresh the screen - Type ctrl-L.",
349 " Escape from a function - Type ctrl-C.",
353 return PrintHelp(message);