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.
68 if ((user = getlogin()) == NULL)
69 user = getpwuid((int) getuid())->pw_name;
70 user = (user && strlen(user)) ? Strsave(user) : "";
72 if ((program_name = rindex(argv[0], '/')) == NULL)
73 program_name = argv[0];
76 program_name = Strsave(program_name);
77 whoami = Strsave(program_name); /* used by menu.c, ugh !!! */
83 while (++arg - argv < argc) {
85 if (!strcmp(*arg, "-nomenu"))
87 else if (!strcmp(*arg, "-db"))
88 if (arg - argv < argc - 1) {
98 if ( status = mr_connect(moira_server) )
99 ErrorExit("\nConnection to Moira server failed", status);
101 if ( status = mr_motd(&motd) )
102 ErrorExit("\nUnable to check server status", status);
104 fprintf(stderr, "The Moira server is currently unavailable:\n%s\n", motd);
109 if ( status = mr_auth(program_name) ) {
110 if (status == MR_USER_AUTH) {
112 com_err(program_name, status, "\nPress [RETURN] to continue");
115 if (status >= ERROR_TABLE_BASE_krb &&
116 status <= ERROR_TABLE_BASE_krb + 256)
117 ErrorExit("\nAuthorization failed -- please run kinit", status);
119 ErrorExit("\nAuthorization failed.", status);
124 * These signals should not be set until just before we fire up the menu
129 (void) signal(SIGHUP, SignalHandler);
130 (void) signal(SIGQUIT, SignalHandler);
132 (void) signal(SIGINT, SignalHandler);
134 (void) signal(SIGINT, CatchInterrupt);
137 initialize_gdss_error_table();
139 if (!strcmp(program_name, "listmaint"))
141 else if (!strcmp(program_name, "usermaint"))
143 else if (!strcmp(program_name, "dcmmaint"))
146 menu = &moira_top_menu;
148 if (use_menu) { /* Start menus that execute program */
153 else /* Start program without menus. */
160 /* Function Name: ErrorExit
161 * Description: This function does the error handling and exits.
162 * Arguments: buf - the error message to print.
163 * status - the error code.
164 * Returns: doesn't return.
168 ErrorExit(buf,status)
172 com_err(program_name, status, buf);
177 /* Function Name: usage
178 * Description: Prints usage info and then exits.
180 * Returns: doesn't return.
186 fprintf(stderr, "Usage: %s [-nomenu]\n", program_name);
191 /* Function Name: SignalHandler
192 * Description: This function cleans up from a signal interrupt.
200 Put_message("Signal caught - exiting");
211 Put_message("Interrupt! Press RETURN to continue");