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>
31 #include "mit-copyright.h"
36 char * whoami; /* used by menu.c ugh!!! */
40 extern Menu moira_top_menu, list_menu, user_menu, dcm_menu;
43 static void SignalHandler(), CatchInterrupt();
46 static void ErrorExit(), Usage();
49 struct passwd *getpwuid();
52 Bool use_menu = FALSE; /* whether or not we are using a menu. */
54 Bool use_menu = TRUE; /* whether or not we are using a menu. */
57 /* Function Name: main
58 * Description: The main driver for the Moira Client.
59 * Arguments: argc, argv - standard command line args.
60 * Returns: doesn't return.
75 if ((user = getlogin()) == NULL)
76 user = getpwuid((int) getuid())->pw_name;
77 user = (user && strlen(user)) ? Strsave(user) : "";
79 if ((program_name = strrchr(argv[0], '/')) == NULL)
80 program_name = argv[0];
83 program_name = Strsave(program_name);
84 whoami = Strsave(program_name); /* used by menu.c, ugh !!! */
90 while (++arg - argv < argc) {
92 if (!strcmp(*arg, "-nomenu"))
94 else if (!strcmp(*arg, "-menu"))
96 else if (!strcmp(*arg, "-db"))
97 if (arg - argv < argc - 1) {
107 if ( status = mr_connect(moira_server) )
108 ErrorExit("\nConnection to Moira server failed", status);
110 if ( status = mr_motd(&motd) )
111 ErrorExit("\nUnable to check server status", status);
113 fprintf(stderr, "The Moira server is currently unavailable:\n%s\n", motd);
118 if ( status = mr_auth(program_name) ) {
119 if (status == MR_USER_AUTH) {
121 com_err(program_name, status, "\nPress [RETURN] to continue");
124 if (status >= ERROR_TABLE_BASE_krb &&
125 status <= ERROR_TABLE_BASE_krb + 256)
126 ErrorExit("\nAuthorization failed -- please run kinit", status);
128 ErrorExit("\nAuthorization failed.", status);
133 * These signals should not be set until just before we fire up the menu
139 sigemptyset(&act.sa_mask);
141 act.sa_handler= (void (*)()) SignalHandler;
142 (void) sigaction(SIGHUP, &act, NULL);
143 (void) sigaction(SIGQUIT, &act, NULL);
145 (void) sigaction(SIGINT, &act, NULL);
147 act.sa_handler= (void (*)()) CatchInterrupt;
148 (void) sigaction(SIGINT, &act, NULL);
151 (void) signal(SIGHUP, SignalHandler);
152 (void) signal(SIGQUIT, SignalHandler);
154 (void) signal(SIGINT, SignalHandler);
156 (void) signal(SIGINT, CatchInterrupt);
160 initialize_gdss_error_table();
162 if (!strcmp(program_name, "listmaint"))
164 else if (!strcmp(program_name, "usermaint"))
166 else if (!strcmp(program_name, "dcmmaint"))
169 menu = &moira_top_menu;
171 if (use_menu) { /* Start menus that execute program */
176 else /* Start program without menus. */
183 /* Function Name: ErrorExit
184 * Description: This function does the error handling and exits.
185 * Arguments: buf - the error message to print.
186 * status - the error code.
187 * Returns: doesn't return.
191 ErrorExit(buf,status)
195 com_err(program_name, status, buf);
200 /* Function Name: usage
201 * Description: Prints usage info and then exits.
203 * Returns: doesn't return.
209 fprintf(stderr, "Usage: %s [-nomenu | -menu] [-db server[:port]]\n", program_name);
214 /* Function Name: SignalHandler
215 * Description: This function cleans up from a signal interrupt.
223 Put_message("Signal caught - exiting");
234 Put_message("Interrupt! Press RETURN to continue");