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>
29 static void ErrorExit(char *buf, int status);
30 static void Usage(void);
31 static void Signal_Handler(void);
32 static void CatchInterrupt(void);
34 char *whoami; /* used by menu.c ugh!!! */
38 extern Menu moira_top_menu, list_menu, user_menu, dcm_menu;
40 Bool use_menu = TRUE; /* whether or not we are using a menu. */
42 /* Function Name: main
43 * Description: The main driver for the Moira Client.
44 * Arguments: argc, argv - standard command line args.
45 * Returns: doesn't return.
48 void main(int argc, char **argv)
55 if (!(user = getlogin()))
56 user = getpwuid(getuid())->pw_name;
57 user = (user && strlen(user)) ? strdup(user) : "";
59 if (!(program_name = strrchr(argv[0], '/')))
60 program_name = argv[0];
63 program_name = strdup(program_name);
64 whoami = strdup(program_name); /* used by menu.c, ugh !!! */
70 while (++arg - argv < argc)
74 if (!strcmp(*arg, "-nomenu"))
76 else if (!strcmp(*arg, "-menu"))
78 else if (!strcmp(*arg, "-db"))
80 if (arg - argv < argc - 1)
92 if ((status = mr_connect(moira_server)))
93 ErrorExit("\nConnection to Moira server failed", status);
95 if ((status = mr_motd(&motd)))
96 ErrorExit("\nUnable to check server status", status);
99 fprintf(stderr, "The Moira server is currently unavailable:\n%s\n",
105 if ((status = mr_auth(program_name)))
107 if (status == MR_USER_AUTH)
110 com_err(program_name, status, "\nPress [RETURN] to continue");
111 fgets(buf, BUFSIZ, stdin);
115 if (status >= ERROR_TABLE_BASE_krb &&
116 status <= ERROR_TABLE_BASE_krb + 256)
117 ErrorExit("\nAuthorization failed -- please run kinit", status);
119 ErrorExit("\nAuthorization failed.", status);
124 * These signals should not be set until just before we fire up the menu
128 sigemptyset(&act.sa_mask);
130 act.sa_handler = Signal_Handler;
131 sigaction(SIGHUP, &act, NULL);
132 sigaction(SIGQUIT, &act, NULL);
134 sigaction(SIGINT, &act, NULL);
137 act.sa_handler = CatchInterrupt;
138 sigaction(SIGINT, &act, NULL);
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 */
158 else /* Start program without menus. */
165 /* Function Name: ErrorExit
166 * Description: This function does the error handling and exits.
167 * Arguments: buf - the error message to print.
168 * status - the error code.
169 * Returns: doesn't return.
172 static void ErrorExit(char *buf, int status)
174 com_err(program_name, status, buf);
179 /* Function Name: usage
180 * Description: Prints usage info and then exits.
182 * Returns: doesn't return.
185 static void Usage(void)
187 fprintf(stderr, "Usage: %s [-nomenu | -menu] [-db server[:port]]\n",
192 /* Function Name: Signal_Handler
193 * Description: This function cleans up from a signal interrupt.
198 static void Signal_Handler(void)
200 Put_message("Signal caught - exiting");
208 static void CatchInterrupt(void)
210 Put_message("Interrupt! Press RETURN to continue");