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>
30 static void ErrorExit(char *buf, int status);
31 static void Usage(void);
32 static void Signal_Handler(void);
33 static void CatchInterrupt(void);
34 int NewListHelp(int argc, char **argv);
36 char *whoami; /* used by menu.c ugh!!! */
41 * List Information Menu
44 Menu list_info_menu = {
47 "List Information Menu",
50 SIMPLEFUNC("member", "Show all lists to which a given member belongs",
52 SIMPLEFUNC("admin", "Show all items which a given member can administer",
54 SIMPLEFUNC("public", "Show all public mailing lists",
55 ListAllPublicMailLists),
63 Menu list_member_menu = {
64 ListmaintMemberMenuEntry,
65 ListmaintMemberMenuExit,
69 SIMPLEFUNC("add", "Add a member to this list", AddMember),
70 SIMPLEFUNC("remove", "Remove a member from this list", DeleteMember),
71 SIMPLEFUNC("show", "Show the members of this list", ListAllMembers),
72 SIMPLEFUNC("verbose", "Toggle Verbosity of Delete", ToggleVerboseMode)
86 { ShowListInfo, NULLMENU, 2, {
87 {"show", "Display information about a list"},
88 {"list name", "Name of list: "}
90 { UpdateList, NULLMENU, 2, {
91 {"update", "Update characteristics of a list"},
92 {"list name", "Name of list: "}
94 SIMPLEFUNC("query_remove",
95 "Interactively remove a member from all lists",
96 InterRemoveItemFromLists),
97 { NULLFUNC, &list_member_menu, 2, {
98 {"members", "Member Menu - Change/Show Members of a List."},
99 {"list name", "Name of list: "}
101 SUBMENU("lists", "Find Mailing Lists Menu",
103 SIMPLEFUNC("help", "Print Help", NewListHelp)
108 * Post Office Box Menu
114 "Mail Forwarding Menu",
117 {GetUserPOBox, NULLMENU, 2, {
118 {"show", "Show a user's post office box"},
119 {"user name", "user name: "}
121 {SetUserPOBox, NULLMENU, 2, {
122 {"set", "Set a user's post office box (mail forwarding)"},
123 {"user name", "user name: "}
125 {RemoveUserPOBox, NULLMENU, 2, {
126 {"remove", "Remove a user's post office box"},
127 {"user name", "user name: "}
139 "Miscellaneous Menu",
142 SIMPLEFUNC("statistics", "Show database statistics", TableStats),
143 SIMPLEFUNC("clients", "Show active Moira clients", ShowClients),
148 Menu namespace_menu = {
151 "Campus Namespace Database Manipulation",
154 SUBMENU("mail", "Mail Forwarding", &pobox_menu),
155 SUBMENU("list", "Mailing Lists", &list_menu),
156 {ShowUserByLogin, NULLMENU, 2, {
157 {"account", "Show user account information"},
158 {"login name", "Desired login name: "}
160 SUBMENU("misc", "Miscellaneous", &misc_menu)
165 Bool use_menu = TRUE; /* whether or not we are using a menu. */
168 /* Function Name: main
169 * Description: The main driver for the Moira Client.
170 * Arguments: argc, argv - standard command line args.
171 * Returns: doesn't return.
174 int main(int argc, char **argv)
179 char pname[ANAME_SZ];
180 struct sigaction act;
182 if (!(program_name = strrchr(argv[0], '/')))
183 program_name = argv[0];
186 program_name = strdup(program_name);
187 whoami = strdup(program_name); /* used by menu.c, ugh !!! */
189 user = mrcl_krb_user();
197 while (++arg - argv < argc)
201 if (!strcmp(*arg, "-nomenu"))
209 else if (!strcmp(*arg, "-menu"))
214 fprintf(stderr, "%s: No curses support. -menu option ignored\n",
218 else if (!strcmp(*arg, "-db"))
219 if (arg - argv < argc - 1)
231 if (mrcl_connect(moira_server, program_name, QUERY_VERSION, 0)
235 if ((status = mr_krb5_auth(program_name)))
237 if (status == MR_UNKNOWN_PROC)
238 status = mr_auth(program_name);
242 if (status == MR_USER_AUTH)
245 com_err(program_name, status, "\nPress [RETURN] to continue");
246 fgets(buf, BUFSIZ, stdin);
249 ErrorExit("\nAuthorization failed -- please run kinit", status);
254 * These signals should not be set until just before we fire up the menu
258 sigemptyset(&act.sa_mask);
260 act.sa_handler = Signal_Handler;
261 sigaction(SIGHUP, &act, NULL);
262 sigaction(SIGQUIT, &act, NULL);
265 sigaction(SIGINT, &act, NULL);
269 act.sa_handler = CatchInterrupt;
270 sigaction(SIGINT, &act, NULL);
273 menu = &namespace_menu;
276 if (use_menu) /* Start menus that execute program */
282 else /* Start program without menus. */
290 /* Function Name: ErrorExit
291 * Description: This function does the error handling and exits.
292 * Arguments: buf - the error message to print.
293 * status - the error code.
294 * Returns: doesn't return.
297 static void ErrorExit(char *buf, int status)
299 com_err(program_name, status, buf);
304 /* Function Name: usage
305 * Description: Prints usage info and then exits.
307 * Returns: doesn't return.
310 static void Usage(void)
312 fprintf(stderr, "Usage: %s [-nomenu]\n", program_name);
316 /* Function Name: Signal_Handler
317 * Description: This function cleans up from a signal interrupt.
322 static void Signal_Handler(void)
324 Put_message("Signal caught - exiting");
334 static void CatchInterrupt(void)
336 Put_message("Interrupt! Press RETURN to continue");
341 /* Dummy routine to be able to link against the rest of the moira client */
343 int DeleteUser(int argc, char **argv)
349 int NewListHelp(int argc, char **argv)
351 static char *message[] = {
352 "A list can be a mailing list, an Athena group list, or both. Each",
353 "list has an owner and members. The owner of a list may be the list",
354 "itself, another list, or a user. The members of a list can be users",
355 "(login names), other lists, or foreign address strings. You can use",
356 "certain keys to do the following:",
357 " Refresh the screen - Type ctrl-L.",
358 " Escape from a function - Type ctrl-C.",
362 return PrintHelp(message);