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>
31 static void ErrorExit(char *buf, int status);
32 static void Usage(void);
33 static void Signal_Handler(void);
34 static void CatchInterrupt(void);
36 char *whoami; /* used by menu.c ugh!!! */
40 extern Menu moira_top_menu, list_menu, user_menu, dcm_menu;
43 Bool use_menu = TRUE; /* whether or not we are using a menu. */
46 /* Function Name: main
47 * Description: The main driver for the Moira Client.
48 * Arguments: argc, argv - standard command line args.
49 * Returns: doesn't return.
52 int main(int argc, char **argv)
56 char *motd, **arg, pname[ANAME_SZ];
59 if ((status = tf_init(TKT_FILE, R_TKT_FIL)) ||
60 (status = tf_get_pname(pname)))
62 initialize_krb_error_table();
63 com_err(whoami, status + ERROR_TABLE_BASE_krb,
64 "reading Kerberos ticket file");
70 if (!(program_name = strrchr(argv[0], '/')))
71 program_name = argv[0];
74 program_name = strdup(program_name);
75 whoami = strdup(program_name); /* used by menu.c, ugh !!! */
81 while (++arg - argv < argc)
85 if (!strcmp(*arg, "-nomenu"))
93 else if (!strcmp(*arg, "-menu"))
98 fprintf(stderr, "%s: No curses support. -menu option ignored\n",
102 else if (!strcmp(*arg, "-db"))
104 if (arg - argv < argc - 1)
116 if ((status = mr_connect(moira_server)))
117 ErrorExit("\nConnection to Moira server failed", status);
119 if ((status = mr_motd(&motd)))
120 ErrorExit("\nUnable to check server status", status);
123 fprintf(stderr, "The Moira server is currently unavailable:\n%s\n",
129 if ((status = mr_auth(program_name)))
131 if (status == MR_USER_AUTH)
134 com_err(program_name, status, "\nPress [RETURN] to continue");
135 fgets(buf, BUFSIZ, stdin);
139 if (status >= ERROR_TABLE_BASE_krb &&
140 status <= ERROR_TABLE_BASE_krb + 256)
141 ErrorExit("\nAuthorization failed -- please run kinit", status);
143 ErrorExit("\nAuthorization failed.", status);
148 * These signals should not be set until just before we fire up the menu
152 sigemptyset(&act.sa_mask);
154 act.sa_handler = Signal_Handler;
155 sigaction(SIGHUP, &act, NULL);
156 sigaction(SIGQUIT, &act, NULL);
159 sigaction(SIGINT, &act, NULL);
163 act.sa_handler = CatchInterrupt;
164 sigaction(SIGINT, &act, NULL);
167 initialize_gdss_error_table();
169 if (!strcmp(program_name, "listmaint"))
171 else if (!strcmp(program_name, "usermaint"))
173 else if (!strcmp(program_name, "dcmmaint"))
176 menu = &moira_top_menu;
179 if (use_menu) /* Start menus that execute program */
185 else /* Start program without menus. */
193 /* Function Name: ErrorExit
194 * Description: This function does the error handling and exits.
195 * Arguments: buf - the error message to print.
196 * status - the error code.
197 * Returns: doesn't return.
200 static void ErrorExit(char *buf, int status)
202 com_err(program_name, status, buf);
207 /* Function Name: usage
208 * Description: Prints usage info and then exits.
210 * Returns: doesn't return.
213 static void Usage(void)
215 fprintf(stderr, "Usage: %s [-nomenu | -menu] [-db server[:port]]\n",
220 /* Function Name: Signal_Handler
221 * Description: This function cleans up from a signal interrupt.
226 static void Signal_Handler(void)
228 Put_message("Signal caught - exiting");
238 static void CatchInterrupt(void)
240 Put_message("Interrupt! Press RETURN to continue");