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();
51 Bool use_menu = TRUE; /* whether or not we are using a menu. */
53 /* Function Name: main
54 * Description: The main driver for the Moira Client.
55 * Arguments: argc, argv - standard command line args.
56 * Returns: doesn't return.
71 if ((user = getlogin()) == NULL)
72 user = getpwuid((int) getuid())->pw_name;
73 user = (user && strlen(user)) ? Strsave(user) : "";
75 if ((program_name = strrchr(argv[0], '/')) == NULL)
76 program_name = argv[0];
79 program_name = Strsave(program_name);
80 whoami = Strsave(program_name); /* used by menu.c, ugh !!! */
86 while (++arg - argv < argc) {
88 if (!strcmp(*arg, "-nomenu"))
90 else if (!strcmp(*arg, "-db"))
91 if (arg - argv < argc - 1) {
101 if ( status = mr_connect(moira_server) )
102 ErrorExit("\nConnection to Moira server failed", status);
104 if ( status = mr_motd(&motd) )
105 ErrorExit("\nUnable to check server status", status);
107 fprintf(stderr, "The Moira server is currently unavailable:\n%s\n", motd);
112 if ( status = mr_auth(program_name) ) {
113 if (status == MR_USER_AUTH) {
115 com_err(program_name, status, "\nPress [RETURN] to continue");
118 if (status >= ERROR_TABLE_BASE_krb &&
119 status <= ERROR_TABLE_BASE_krb + 256)
120 ErrorExit("\nAuthorization failed -- please run kinit", status);
122 ErrorExit("\nAuthorization failed.", status);
127 * These signals should not be set until just before we fire up the menu
133 sigemptyset(&act.sa_mask);
135 act.sa_handler= (void (*)()) SignalHandler;
136 (void) sigaction(SIGHUP, &act, NULL);
137 (void) sigaction(SIGQUIT, &act, NULL);
139 (void) sigaction(SIGINT, &act, NULL);
141 act.sa_handler= (void (*)()) CatchInterrupt;
142 (void) sigaction(SIGINT, &act, NULL);
145 (void) signal(SIGHUP, SignalHandler);
146 (void) signal(SIGQUIT, SignalHandler);
148 (void) signal(SIGINT, SignalHandler);
150 (void) signal(SIGINT, CatchInterrupt);
154 initialize_gdss_error_table();
156 if (!strcmp(program_name, "listmaint"))
158 else if (!strcmp(program_name, "usermaint"))
160 else if (!strcmp(program_name, "dcmmaint"))
163 menu = &moira_top_menu;
165 if (use_menu) { /* Start menus that execute program */
170 else /* Start program without menus. */
177 /* Function Name: ErrorExit
178 * Description: This function does the error handling and exits.
179 * Arguments: buf - the error message to print.
180 * status - the error code.
181 * Returns: doesn't return.
185 ErrorExit(buf,status)
189 com_err(program_name, status, buf);
194 /* Function Name: usage
195 * Description: Prints usage info and then exits.
197 * Returns: doesn't return.
203 fprintf(stderr, "Usage: %s [-nomenu] [-db server[:port]]\n", program_name);
208 /* Function Name: SignalHandler
209 * Description: This function cleans up from a signal interrupt.
217 Put_message("Signal caught - exiting");
228 Put_message("Interrupt! Press RETURN to continue");