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.
72 if ((user = getlogin()) == NULL)
73 user = getpwuid((int) getuid())->pw_name;
74 user = (user && strlen(user)) ? Strsave(user) : "";
76 if ((program_name = rindex(argv[0], '/')) == NULL)
77 program_name = argv[0];
80 program_name = Strsave(program_name);
81 whoami = Strsave(program_name); /* used by menu.c, ugh !!! */
87 while (++arg - argv < argc) {
89 if (!strcmp(*arg, "-nomenu"))
91 else if (!strcmp(*arg, "-db"))
92 if (arg - argv < argc - 1) {
102 if ( status = mr_connect(moira_server) )
103 ErrorExit("\nConnection to Moira server failed", status);
105 if ( status = mr_motd(&motd) )
106 ErrorExit("\nUnable to check server status", status);
108 fprintf(stderr, "The Moira server is currently unavailable:\n%s\n", motd);
113 if ( status = mr_auth(program_name) ) {
114 if (status == MR_USER_AUTH) {
116 com_err(program_name, status, "\nPress [RETURN] to continue");
119 if (status >= ERROR_TABLE_BASE_krb &&
120 status <= ERROR_TABLE_BASE_krb + 256)
121 ErrorExit("\nAuthorization failed -- please run kinit", status);
123 ErrorExit("\nAuthorization failed.", status);
128 * These signals should not be set until just before we fire up the menu
133 (void) signal(SIGHUP, SignalHandler);
134 (void) signal(SIGQUIT, SignalHandler);
136 (void) signal(SIGINT, SignalHandler);
138 (void) signal(SIGINT, CatchInterrupt);
141 initialize_gdss_error_table();
143 if (!strcmp(program_name, "listmaint"))
145 else if (!strcmp(program_name, "usermaint"))
147 else if (!strcmp(program_name, "dcmmaint"))
150 menu = &moira_top_menu;
152 if (use_menu) { /* Start menus that execute program */
157 else /* Start program without menus. */
164 /* Function Name: ErrorExit
165 * Description: This function does the error handling and exits.
166 * Arguments: buf - the error message to print.
167 * status - the error code.
168 * Returns: doesn't return.
172 ErrorExit(buf,status)
176 com_err(program_name, status, buf);
181 /* Function Name: usage
182 * Description: Prints usage info and then exits.
184 * Returns: doesn't return.
190 fprintf(stderr, "Usage: %s [-nomenu]\n", program_name);
195 /* Function Name: SignalHandler
196 * Description: This function cleans up from a signal interrupt.
204 Put_message("Signal caught - exiting");
215 Put_message("Interrupt! Press RETURN to continue");