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 users
6 * 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;
42 static void Signal_Handler(), CatchInterrupt();
44 static void ErrorExit(), Usage();
47 struct passwd *getpwuid();
49 Bool use_menu = TRUE; /* whether or not we are using a menu. */
51 /* Function Name: main
52 * Description: The main driver for the Moira Client.
53 * Arguments: argc, argv - standard command line args.
54 * Returns: doesn't return.
57 void main(int argc, char **argv)
64 if (!(user = getlogin()))
65 user = getpwuid(getuid())->pw_name;
66 user = (user && strlen(user)) ? Strsave(user) : "";
68 if (!(program_name = strrchr(argv[0], '/')))
69 program_name = argv[0];
72 program_name = Strsave(program_name);
73 whoami = Strsave(program_name); /* used by menu.c, ugh !!! */
79 while (++arg - argv < argc)
83 if (!strcmp(*arg, "-nomenu"))
85 else if (!strcmp(*arg, "-menu"))
87 else if (!strcmp(*arg, "-db"))
89 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);
108 fprintf(stderr, "The Moira server is currently unavailable:\n%s\n",
114 if ((status = mr_auth(program_name)))
116 if (status == MR_USER_AUTH)
119 com_err(program_name, status, "\nPress [RETURN] to continue");
120 fgets(buf, BUFSIZ, stdin);
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
137 sigemptyset(&act.sa_mask);
139 act.sa_handler = (void (*)()) Signal_Handler;
140 sigaction(SIGHUP, &act, NULL);
141 sigaction(SIGQUIT, &act, NULL);
143 sigaction(SIGINT, &act, NULL);
146 act.sa_handler = (void (*)()) CatchInterrupt;
147 sigaction(SIGINT, &act, NULL);
150 initialize_gdss_error_table();
152 if (!strcmp(program_name, "listmaint"))
154 else if (!strcmp(program_name, "usermaint"))
156 else if (!strcmp(program_name, "dcmmaint"))
159 menu = &moira_top_menu;
161 if (use_menu) /* Start menus that execute program */
167 else /* Start program without menus. */
174 /* Function Name: ErrorExit
175 * Description: This function does the error handling and exits.
176 * Arguments: buf - the error message to print.
177 * status - the error code.
178 * Returns: doesn't return.
181 static void ErrorExit(char *buf, int status)
183 com_err(program_name, status, buf);
188 /* Function Name: usage
189 * Description: Prints usage info and then exits.
191 * Returns: doesn't return.
194 static void Usage(void)
196 fprintf(stderr, "Usage: %s [-nomenu | -menu] [-db server[:port]]\n",
201 /* Function Name: Signal_Handler
202 * Description: This function cleans up from a signal interrupt.
207 static void Signal_Handler(void)
209 Put_message("Signal caught - exiting");
217 static void CatchInterrupt(void)
219 Put_message("Interrupt! Press RETURN to continue");