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",
54 SIMPLEFUNC("admin", "Show all items which a given member can administer",
56 SIMPLEFUNC("public", "Show all public mailing lists",
57 ListAllPublicMailLists),
65 Menu list_member_menu = {
66 ListmaintMemberMenuEntry,
67 ListmaintMemberMenuExit,
71 SIMPLEFUNC("add", "Add a member to this list", AddMember),
72 SIMPLEFUNC("remove", "Remove a member from this list", DeleteMember),
73 SIMPLEFUNC("show", "Show the members of this list", ListAllMembers),
74 SIMPLEFUNC("verbose", "Toggle Verbosity of Delete", ToggleVerboseMode)
88 { ShowListInfo, NULLMENU, 2, {
89 {"show", "Display information about a list"},
90 {"list name", "Name of list: "}
92 { UpdateList, NULLMENU, 2, {
93 {"update", "Update characteristics of a list"},
94 {"list name", "Name of list: "}
96 SIMPLEFUNC("query_remove",
97 "Interactively remove a member from all lists",
98 InterRemoveItemFromLists),
99 { NULLFUNC, &list_member_menu, 2, {
100 {"members", "Member Menu - Change/Show Members of a List."},
101 {"list name", "Name of list: "}
103 SUBMENU("lists", "Find Mailing Lists Menu",
105 SIMPLEFUNC("help", "Print Help", NewListHelp)
110 * Post Office Box Menu
116 "Mail Forwarding Menu",
119 {GetUserPOBox, NULLMENU, 2, {
120 {"show", "Show a user's post office box"},
121 {"user name", "user name: "}
123 {SetUserPOBox, NULLMENU, 2, {
124 {"set", "Set a user's post office box (mail forwarding)"},
125 {"user name", "user name: "}
127 {RemoveUserPOBox, NULLMENU, 2, {
128 {"remove", "Remove a user's post office box"},
129 {"user name", "user name: "}
141 "Miscellaneous Menu",
144 SIMPLEFUNC("statistics", "Show database statistics", TableStats),
145 SIMPLEFUNC("clients", "Show active Moira clients", ShowClients),
150 Menu namespace_menu = {
153 "Campus Namespace Database Manipulation",
156 SUBMENU("mail", "Mail Forwarding", &pobox_menu),
157 SUBMENU("list", "Mailing Lists", &list_menu),
158 {ShowUserByLogin, NULLMENU, 2, {
159 {"account", "Show user account information"},
160 {"login name", "Desired login name: "}
162 SUBMENU("misc", "Miscellaneous", &misc_menu)
167 static void Signal_Handler(), CatchInterrupt();
169 static void ErrorExit(), Usage();
172 struct passwd *getpwuid();
174 Bool use_menu = TRUE; /* whether or not we are using a menu. */
176 /* Function Name: main
177 * Description: The main driver for the Moira Client.
178 * Arguments: argc, argv - standard command line args.
179 * Returns: doesn't return.
182 void main(int argc, char **argv)
187 char pname[ANAME_SZ];
188 struct sigaction act;
190 if (!(program_name = strrchr(argv[0], '/')))
191 program_name = argv[0];
194 program_name = Strsave(program_name);
195 whoami = Strsave(program_name); /* used by menu.c, ugh !!! */
201 while (++arg - argv < argc)
205 if (!strcmp(*arg, "-nomenu"))
207 else if (!strcmp(*arg, "-db"))
208 if (arg - argv < argc - 1)
220 if ((status = mr_connect(moira_server)))
221 ErrorExit("\nConnection to Moira server failed", status);
223 /* do this now since calling mr_connect initialized the krb error table
226 if ((status = tf_init(TKT_FILE, R_TKT_FIL)) ||
227 (status = tf_get_pname(pname)))
229 com_err(whoami, status, "cannot find your ticket file");
233 user = Strsave(pname);
235 if ((status = mr_motd(&motd)))
236 ErrorExit("\nUnable to check server status", status);
239 fprintf(stderr, "The Moira server is currently unavailable:\n%s\n",
245 if ((status = mr_auth(program_name)))
247 if (status == MR_USER_AUTH)
250 com_err(program_name, status, "\nPress [RETURN] to continue");
251 fgets(buf, BUFSIZ, stdin);
254 ErrorExit("\nAuthorization failed -- please run kinit", status);
258 * These signals should not be set until just before we fire up the menu
262 sigemptyset(&act.sa_mask);
264 act.sa_handler = (void (*)()) Signal_Handler;
265 sigaction(SIGHUP, &act, NULL);
266 sigaction(SIGQUIT, &act, NULL);
268 sigaction(SIGINT, &act, NULL);
271 act.sa_handler = (void (*)()) CatchInterrupt;
272 sigaction(SIGINT, &act, NULL);
275 menu = &namespace_menu;
277 if (use_menu) /* Start menus that execute program */
283 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");
332 static void CatchInterrupt(void)
334 Put_message("Interrupt! Press RETURN to continue");
339 /* Dummy routine to be able to link against the rest of the moira client */
347 int NewListHelp(void)
349 static char *message[] = {
350 "A list can be a mailing list, an Athena group list, or both. Each",
351 "list has an owner and members. The owner of a list may be the list",
352 "itself, another list, or a user. The members of a list can be users",
353 "(login names), other lists, or foreign address strings. You can use",
354 "certain keys to do the following:",
355 " Refresh the screen - Type ctrl-L.",
356 " Escape from a function - Type ctrl-C.",
360 return PrintHelp(message);