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>
32 static void ErrorExit(char *buf, int status);
33 static void Usage(void);
34 static void Signal_Handler(void);
35 static void CatchInterrupt(void);
37 char *whoami; /* used by menu.c ugh!!! */
41 extern Menu moira_top_menu, list_menu, user_menu, dcm_menu;
44 Bool use_menu = TRUE; /* whether or not we are using a menu. */
47 /* Function Name: main
48 * Description: The main driver for the Moira Client.
49 * Arguments: argc, argv - standard command line args.
50 * Returns: doesn't return.
53 int main(int argc, char **argv)
57 char **arg, pname[ANAME_SZ];
60 if (!(program_name = strrchr(argv[0], '/')))
61 program_name = argv[0];
64 program_name = strdup(program_name);
65 whoami = strdup(program_name); /* used by menu.c, ugh !!! */
67 user = mrcl_krb_user();
75 while (++arg - argv < argc)
79 if (!strcmp(*arg, "-nomenu"))
87 else if (!strcmp(*arg, "-menu"))
92 fprintf(stderr, "%s: No curses support. -menu option ignored\n",
96 else if (!strcmp(*arg, "-db"))
98 if (arg - argv < argc - 1)
110 if (mrcl_connect(moira_server, program_name, 2, 0) != MRCL_SUCCESS)
113 if ((status = mr_auth(program_name)))
115 if (status == MR_USER_AUTH)
118 com_err(program_name, status, "\nPress [RETURN] to continue");
119 fgets(buf, BUFSIZ, stdin);
123 if (status >= ERROR_TABLE_BASE_krb &&
124 status <= ERROR_TABLE_BASE_krb + 256)
125 ErrorExit("\nAuthorization failed -- please run kinit", status);
127 ErrorExit("\nAuthorization failed.", status);
132 * These signals should not be set until just before we fire up the menu
136 sigemptyset(&act.sa_mask);
138 act.sa_handler = Signal_Handler;
139 sigaction(SIGHUP, &act, NULL);
140 sigaction(SIGQUIT, &act, NULL);
143 sigaction(SIGINT, &act, NULL);
147 act.sa_handler = CatchInterrupt;
148 sigaction(SIGINT, &act, NULL);
151 if (!strcmp(program_name, "listmaint"))
153 else if (!strcmp(program_name, "usermaint"))
155 else if (!strcmp(program_name, "dcmmaint"))
158 menu = &moira_top_menu;
161 if (use_menu) /* Start menus that execute program */
167 else /* Start program without menus. */
175 /* Function Name: ErrorExit
176 * Description: This function does the error handling and exits.
177 * Arguments: buf - the error message to print.
178 * status - the error code.
179 * Returns: doesn't return.
182 static void ErrorExit(char *buf, int status)
184 com_err(program_name, status, buf);
189 /* Function Name: usage
190 * Description: Prints usage info and then exits.
192 * Returns: doesn't return.
195 static void Usage(void)
197 fprintf(stderr, "Usage: %s [-nomenu | -menu] [-db server[:port]]\n",
202 /* Function Name: Signal_Handler
203 * Description: This function cleans up from a signal interrupt.
208 static void Signal_Handler(void)
210 Put_message("Signal caught - exiting");
220 static void CatchInterrupt(void)
222 Put_message("Interrupt! Press RETURN to continue");