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!!! */
42 * List Information Menu
45 Menu list_info_menu = {
48 "List Information Menu",
51 SIMPLEFUNC("member", "Show all lists to which a given member belongs",
54 "Show all items which a given member can administer",
56 SIMPLEFUNC("public", "Show all public mailing lists",
57 ListAllPublicMailLists),
58 SIMPLEFUNC("maillists", "Show all mailing lists",
67 Menu list_member_menu = {
68 ListmaintMemberMenuEntry,
69 ListmaintMemberMenuExit,
73 SIMPLEFUNC("add", "Add a member to this list", AddMember),
74 SIMPLEFUNC("remove", "Remove a member from this list", DeleteMember),
75 SIMPLEFUNC("show", "Show the members of this list", ListAllMembers),
76 SIMPLEFUNC("verbose", "Toggle Verbosity of Delete", ToggleVerboseMode)
90 { ShowListInfo, NULLMENU, 2, {
91 {"show", "Display information about a list"},
92 {"list name", "Name of list: "}
94 { UpdateList, NULLMENU, 2, {
95 {"update", "Update characteristics of a list"},
96 {"list name", "Name of list: "}
98 SIMPLEFUNC("query_remove",
99 "Interactively remove a member from all lists",
100 InterRemoveItemFromLists),
101 { NULLFUNC, &list_member_menu, 2, {
102 {"members", "Member Menu - Change/Show Members of a List."},
103 {"list name", "Name of list: "}
105 SUBMENU("lists", "Find Mailing Lists Menu",
107 SIMPLEFUNC("help", "Print Help", NewListHelp)
112 * Post Office Box Menu
118 "Mail Forwarding Menu",
121 {GetUserPOBox, NULLMENU, 2, {
122 {"show", "Show a user's post office box"},
123 {"user name", "user name: "}
125 {SetUserPOBox, NULLMENU, 2, {
126 {"set", "Set a user's post office box (mail forwarding)"},
127 {"user name", "user name: "}
129 {RemoveUserPOBox, NULLMENU, 2, {
130 {"remove", "Remove a user's post office box"},
131 {"user name", "user name: "}
143 "Miscellaneous Menu",
146 SIMPLEFUNC("statistics", "Show database statistics", TableStats),
147 SIMPLEFUNC("clients", "Show active Moira clients", ShowClients),
152 Menu namespace_menu = {
155 "Campus Namespace Database Manipulation",
158 SUBMENU("mail","Mail Forwarding", &pobox_menu),
159 SUBMENU("list","Mailing Lists", &list_menu),
160 {ShowUserByLogin, NULLMENU, 2, {
161 {"account", "Show user account information"},
162 {"login name", "Desired login name: "}
164 SUBMENU("misc", "Miscellaneous", &misc_menu)
170 static void SignalHandler();
173 static void ErrorExit(), Usage();
176 struct passwd *getpwuid();
178 Bool use_menu = TRUE; /* whether or not we are using a menu. */
180 /* Function Name: main
181 * Description: The main driver for the Moira Client.
182 * Arguments: argc, argv - standard command line args.
183 * Returns: doesn't return.
194 char pname[ANAME_SZ];
196 if ((program_name = rindex(argv[0], '/')) == NULL)
197 program_name = argv[0];
200 program_name = Strsave(program_name);
201 whoami = Strsave(program_name); /* used by menu.c, ugh !!! */
207 while (++arg - argv < argc) {
209 if (!strcmp(*arg, "-nomenu"))
211 else if (!strcmp(*arg, "-db"))
212 if (arg - argv < argc - 1) {
222 if ( status = mr_connect(moira_server) )
223 ErrorExit("\nConnection to Moira server failed", status);
225 /* do this now since calling mr_connect initialized the krb error table
228 if ((status = tf_init(TKT_FILE, R_TKT_FIL)) ||
229 (status = tf_get_pname(pname))) {
230 com_err(whoami, status, "cannot find your ticket file");
234 user = Strsave(pname);
236 if ( status = mr_motd(&motd) )
237 ErrorExit("\nUnable to check server status", status);
239 fprintf(stderr, "The Moira server is currently unavailable:\n%s\n", motd);
244 if ( status = mr_auth(program_name) ) {
245 if (status == MR_USER_AUTH) {
247 com_err(program_name, status, "\nPress [RETURN] to continue");
250 ErrorExit("\nAuthorization failed -- please run kinit", status);
254 * These signals should not be set until just before we fire up the menu
259 (void) signal(SIGHUP, SignalHandler);
260 (void) signal(SIGINT, SignalHandler);
261 (void) signal(SIGQUIT, SignalHandler);
264 menu = &namespace_menu;
266 if (use_menu) { /* Start menus that execute program */
271 else /* Start program without menus. */
278 /* Function Name: ErrorExit
279 * Description: This function does the error handling and exits.
280 * Arguments: buf - the error message to print.
281 * status - the error code.
282 * Returns: doesn't return.
286 ErrorExit(buf,status)
290 com_err(program_name, status, buf);
295 /* Function Name: usage
296 * Description: Prints usage info and then exits.
298 * Returns: doesn't return.
304 fprintf(stderr, "Usage: %s [-nomenu]\n", program_name);
309 /* Function Name: SignalHandler
310 * Description: This function cleans up from a signal interrupt.
318 Put_message("Signal caught - exiting");
327 /* Dummy routine to be able to link against the rest of the moira client */
338 static char * message[] = {
339 "A list can be a mailing list, an Athena group list, or both. Each",
340 "list has an owner and members. The owner of a list may be the list",
341 "itself, another list, or a user. The members of a list can be users",
342 "(login names), other lists, or foreign address strings. You can use",
343 "certain keys to do the following:",
344 " Refresh the screen - Type ctrl-L.",
345 " Escape from a function - Type ctrl-C.",
349 return(PrintHelp(message));