3 * This is the file main.c for the Moira Client, which allows users
4 * to quickly and easily maintain most parts of the Moira database.
5 * It Contains: The main driver for the Moira Client.
8 * By: Chris D. Peterson
10 * Copyright (C) 1988-1998 by the Massachusetts Institute of Technology.
11 * For copying and distribution information, please see the file
15 #include <mit-copyright.h>
27 #endif /* HAVE_UNISTD_H */
31 static void ErrorExit(char *buf, int status);
32 static void Usage(void);
33 static void Signal_Handler(int sig);
34 static void CatchInterrupt(int sig);
35 static void SetHandlers(void);
36 static char* get_program_name(char *arg);
38 char *whoami; /* used by menu.c ugh!!! */
42 extern Menu moira_top_menu, list_menu, user_menu, dcm_menu;
45 Bool use_menu = TRUE; /* whether or not we are using a menu. */
48 /* Function Name: main
49 * Description: The main driver for the Moira Client.
50 * Arguments: argc, argv - standard command line args.
51 * Returns: doesn't return.
54 int main(int argc, char **argv)
60 program_name = get_program_name(argv[0]);
61 whoami = strdup(program_name); /* used by menu.c, ugh !!! */
63 user = mrcl_krb_user();
71 while (++arg - argv < argc)
75 if (!strcmp(*arg, "-nomenu"))
83 else if (!strcmp(*arg, "-menu"))
88 fprintf(stderr, "%s: No curses support. -menu option ignored\n",
92 else if (!strcmp(*arg, "-db"))
94 if (arg - argv < argc - 1)
106 if (mrcl_connect(moira_server, program_name, QUERY_VERSION, 0)
110 if ((status = mr_auth(program_name)))
112 if (status == MR_USER_AUTH)
115 com_err(program_name, status, "\nPress [RETURN] to continue");
116 fgets(buf, BUFSIZ, stdin);
120 if (status >= ERROR_TABLE_BASE_krb &&
121 status <= ERROR_TABLE_BASE_krb + 256)
122 ErrorExit("\nAuthorization failed -- please run kinit", status);
124 ErrorExit("\nAuthorization failed.", status);
129 * These signals should not be set until just before we fire up the menu
134 if (!strcmp(program_name, "listmaint"))
136 else if (!strcmp(program_name, "usermaint"))
138 else if (!strcmp(program_name, "dcmmaint"))
141 menu = &moira_top_menu;
144 if (use_menu) /* Start menus that execute program */
150 else /* Start program without menus. */
158 /* Function Name: ErrorExit
159 * Description: This function does the error handling and exits.
160 * Arguments: buf - the error message to print.
161 * status - the error code.
162 * Returns: doesn't return.
165 static void ErrorExit(char *buf, int status)
167 com_err(program_name, status, buf);
172 /* Function Name: usage
173 * Description: Prints usage info and then exits.
175 * Returns: doesn't return.
178 static void Usage(void)
180 fprintf(stderr, "Usage: %s [-nomenu | -menu] [-db server[:port]]\n",
185 /* Function Name: Signal_Handler
186 * Description: This function cleans up from a signal interrupt.
191 static void Signal_Handler(int sig)
193 Put_message("Signal caught - exiting");
203 static void CatchInterrupt(int sig)
205 Put_message("Interrupt! Press RETURN to continue");
209 #ifdef HAVE_POSIX_SIGNALS
210 static void SetHandlers(void)
212 struct sigaction act;
214 sigemptyset(&act.sa_mask);
216 act.sa_handler = Signal_Handler;
217 sigaction(SIGHUP, &act, NULL);
218 sigaction(SIGQUIT, &act, NULL);
221 sigaction(SIGINT, &act, NULL);
225 act.sa_handler = CatchInterrupt;
226 sigaction(SIGINT, &act, NULL);
230 static void SetHandlers(void)
232 signal(SIGTERM, Signal_Handler);
235 signal(SIGINT, Signal_Handler);
238 signal(SIGINT, CatchInterrupt);
243 static char* get_program_name(char *arg)
247 prog = max(max(strrchr(arg, '/'), strrchr(arg, '\\')) + 1, arg);
248 prog = _strlwr(prog);
250 ext = strrchr(prog, '.');
251 if (ext && !strcmp(ext, ".exe"))
256 static char* get_program_name(char *arg)
259 if (!(prog = strrchr(arg, '/')))