]>
Commit | Line | Data |
---|---|---|
c441a31a | 1 | /* $Id$ |
7ac48069 | 2 | * |
3 | * This is the file main.c for the Moira Client, which allows users | |
59ec8dae | 4 | * to quickly and easily maintain most parts of the Moira database. |
1931dc22 | 5 | * It Contains: The main driver for the Moira Client. |
5eaef520 | 6 | * |
08345b74 | 7 | * Created: 4/12/88 |
8 | * By: Chris D. Peterson | |
9 | * | |
7ac48069 | 10 | * Copyright (C) 1988-1998 by the Massachusetts Institute of Technology. |
11 | * For copying and distribution information, please see the file | |
12 | * <mit-copyright.h>. | |
08345b74 | 13 | */ |
14 | ||
7ac48069 | 15 | #include <mit-copyright.h> |
16 | #include <moira.h> | |
17 | #include "defs.h" | |
18 | #include "f_defs.h" | |
19 | #include "globals.h" | |
20 | ||
08345b74 | 21 | #include <pwd.h> |
22 | #include <signal.h> | |
23 | #include <stdio.h> | |
f071d8a7 | 24 | #include <string.h> |
7ac48069 | 25 | #include <unistd.h> |
08345b74 | 26 | |
7a40dcd4 | 27 | #include <krb.h> |
28 | ||
7ac48069 | 29 | RCSID("$Header$"); |
30 | ||
31 | static void ErrorExit(char *buf, int status); | |
32 | static void Usage(void); | |
33 | static void Signal_Handler(void); | |
34 | static void CatchInterrupt(void); | |
08345b74 | 35 | |
5eaef520 | 36 | char *whoami; /* used by menu.c ugh!!! */ |
37 | char *moira_server; | |
facd6784 | 38 | int interrupt = 0; |
85ca828a | 39 | |
8defc06b | 40 | extern Menu moira_top_menu, list_menu, user_menu, dcm_menu; |
85ca828a | 41 | |
ea0caf4a | 42 | #ifdef HAVE_CURSES |
08345b74 | 43 | Bool use_menu = TRUE; /* whether or not we are using a menu. */ |
ea0caf4a | 44 | #endif |
08345b74 | 45 | |
46 | /* Function Name: main | |
1931dc22 | 47 | * Description: The main driver for the Moira Client. |
08345b74 | 48 | * Arguments: argc, argv - standard command line args. |
49 | * Returns: doesn't return. | |
50 | */ | |
51 | ||
3bad18e8 | 52 | int main(int argc, char **argv) |
08345b74 | 53 | { |
5eaef520 | 54 | int status; |
55 | Menu *menu; | |
7a40dcd4 | 56 | char *motd, **arg, pname[ANAME_SZ]; |
5eaef520 | 57 | struct sigaction act; |
58 | ||
7a40dcd4 | 59 | if ((status = tf_init(TKT_FILE, R_TKT_FIL)) || |
60 | (status = tf_get_pname(pname))) | |
61 | { | |
aa0c5824 | 62 | initialize_krb_error_table(); |
63 | com_err(whoami, status + ERROR_TABLE_BASE_krb, | |
64 | "reading Kerberos ticket file"); | |
7a40dcd4 | 65 | exit(1); |
66 | } | |
67 | tf_close(); | |
68 | user = pname; | |
5eaef520 | 69 | |
70 | if (!(program_name = strrchr(argv[0], '/'))) | |
71 | program_name = argv[0]; | |
72 | else | |
73 | program_name++; | |
7ac48069 | 74 | program_name = strdup(program_name); |
75 | whoami = strdup(program_name); /* used by menu.c, ugh !!! */ | |
5eaef520 | 76 | |
77 | verbose = TRUE; | |
78 | arg = argv; | |
79 | moira_server = NULL; | |
80 | ||
81 | while (++arg - argv < argc) | |
82 | { | |
83 | if (**arg == '-') | |
84 | { | |
85 | if (!strcmp(*arg, "-nomenu")) | |
ea0caf4a | 86 | { |
87 | #ifdef HAVE_CURSES | |
88 | use_menu = FALSE; | |
89 | #else | |
90 | ; | |
91 | #endif | |
92 | } | |
5eaef520 | 93 | else if (!strcmp(*arg, "-menu")) |
ea0caf4a | 94 | { |
95 | #ifdef HAVE_CURSES | |
96 | use_menu = TRUE; | |
97 | #else | |
98 | fprintf(stderr, "%s: No curses support. -menu option ignored\n", | |
99 | whoami); | |
100 | #endif | |
101 | } | |
5eaef520 | 102 | else if (!strcmp(*arg, "-db")) |
103 | { | |
104 | if (arg - argv < argc - 1) | |
105 | { | |
576becad | 106 | ++arg; |
1931dc22 | 107 | moira_server = *arg; |
5eaef520 | 108 | } else |
7ac48069 | 109 | Usage(); |
5eaef520 | 110 | } |
111 | else | |
7ac48069 | 112 | Usage(); |
576becad | 113 | } |
08345b74 | 114 | } |
85ca828a | 115 | |
5eaef520 | 116 | if ((status = mr_connect(moira_server))) |
117 | ErrorExit("\nConnection to Moira server failed", status); | |
118 | ||
119 | if ((status = mr_motd(&motd))) | |
120 | ErrorExit("\nUnable to check server status", status); | |
121 | if (motd) | |
122 | { | |
123 | fprintf(stderr, "The Moira server is currently unavailable:\n%s\n", | |
124 | motd); | |
125 | mr_disconnect(); | |
126 | exit(1); | |
262ca740 | 127 | } |
128 | ||
5eaef520 | 129 | if ((status = mr_auth(program_name))) |
130 | { | |
131 | if (status == MR_USER_AUTH) | |
132 | { | |
133 | char buf[BUFSIZ]; | |
134 | com_err(program_name, status, "\nPress [RETURN] to continue"); | |
135 | fgets(buf, BUFSIZ, stdin); | |
136 | } | |
137 | else | |
138 | { | |
71ca689a | 139 | if (status >= ERROR_TABLE_BASE_krb && |
140 | status <= ERROR_TABLE_BASE_krb + 256) | |
141 | ErrorExit("\nAuthorization failed -- please run kinit", status); | |
142 | else | |
143 | ErrorExit("\nAuthorization failed.", status); | |
144 | } | |
1931dc22 | 145 | } |
08345b74 | 146 | |
5eaef520 | 147 | /* |
148 | * These signals should not be set until just before we fire up the menu | |
149 | * system. | |
150 | */ | |
151 | ||
152 | sigemptyset(&act.sa_mask); | |
153 | act.sa_flags = 0; | |
7ac48069 | 154 | act.sa_handler = Signal_Handler; |
5eaef520 | 155 | sigaction(SIGHUP, &act, NULL); |
156 | sigaction(SIGQUIT, &act, NULL); | |
ea0caf4a | 157 | #ifdef HAVE_CURSES |
5eaef520 | 158 | if (use_menu) |
159 | sigaction(SIGINT, &act, NULL); | |
160 | else | |
ea0caf4a | 161 | #endif |
5eaef520 | 162 | { |
7ac48069 | 163 | act.sa_handler = CatchInterrupt; |
5eaef520 | 164 | sigaction(SIGINT, &act, NULL); |
f071d8a7 | 165 | } |
5eaef520 | 166 | |
167 | initialize_gdss_error_table(); | |
168 | ||
169 | if (!strcmp(program_name, "listmaint")) | |
170 | menu = &list_menu; | |
171 | else if (!strcmp(program_name, "usermaint")) | |
172 | menu = &user_menu; | |
173 | else if (!strcmp(program_name, "dcmmaint")) | |
174 | menu = &dcm_menu; | |
175 | else | |
176 | menu = &moira_top_menu; | |
177 | ||
ea0caf4a | 178 | #ifdef HAVE_CURSES |
5eaef520 | 179 | if (use_menu) /* Start menus that execute program */ |
180 | { | |
181 | Start_paging(); | |
182 | Start_menu(menu); | |
183 | Stop_paging(); | |
08345b74 | 184 | } |
5eaef520 | 185 | else /* Start program without menus. */ |
ea0caf4a | 186 | #endif |
5eaef520 | 187 | Start_no_menu(menu); |
08345b74 | 188 | |
5eaef520 | 189 | mr_disconnect(); |
190 | exit(0); | |
08345b74 | 191 | } |
192 | ||
461c03b6 | 193 | /* Function Name: ErrorExit |
08345b74 | 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. | |
198 | */ | |
199 | ||
5eaef520 | 200 | static void ErrorExit(char *buf, int status) |
08345b74 | 201 | { |
5eaef520 | 202 | com_err(program_name, status, buf); |
203 | mr_disconnect(); | |
204 | exit(1); | |
08345b74 | 205 | } |
206 | ||
207 | /* Function Name: usage | |
208 | * Description: Prints usage info and then exits. | |
209 | * Arguments: none | |
210 | * Returns: doesn't return. | |
211 | */ | |
212 | ||
5eaef520 | 213 | static void Usage(void) |
08345b74 | 214 | { |
5eaef520 | 215 | fprintf(stderr, "Usage: %s [-nomenu | -menu] [-db server[:port]]\n", |
216 | program_name); | |
217 | exit(1); | |
08345b74 | 218 | } |
219 | ||
7798ebc3 | 220 | /* Function Name: Signal_Handler |
08345b74 | 221 | * Description: This function cleans up from a signal interrupt. |
222 | * Arguments: none. | |
223 | * Returns: doesn't | |
224 | */ | |
225 | ||
5eaef520 | 226 | static void Signal_Handler(void) |
08345b74 | 227 | { |
5eaef520 | 228 | Put_message("Signal caught - exiting"); |
ea0caf4a | 229 | #ifdef HAVE_CURSES |
5eaef520 | 230 | if (use_menu) |
231 | Cleanup_menu(); | |
ea0caf4a | 232 | #endif |
5eaef520 | 233 | mr_disconnect(); |
234 | exit(1); | |
08345b74 | 235 | } |
facd6784 | 236 | |
237 | ||
5eaef520 | 238 | static void CatchInterrupt(void) |
facd6784 | 239 | { |
5eaef520 | 240 | Put_message("Interrupt! Press RETURN to continue"); |
241 | interrupt = 1; | |
facd6784 | 242 | } |