]>
Commit | Line | Data |
---|---|---|
402461ad | 1 | #if (!defined(lint) && !defined(SABER)) |
08345b74 | 2 | static char rcsid_module_c[] = "$Header$"; |
3 | #endif lint | |
4 | ||
1931dc22 | 5 | /* This is the file main.c for the Moira Client, which allows a nieve |
6 | * user to quickly and easily maintain most parts of the Moira database. | |
7 | * It Contains: The main driver for the Moira Client. | |
08345b74 | 8 | * |
9 | * Created: 4/12/88 | |
10 | * By: Chris D. Peterson | |
11 | * | |
12 | * $Source$ | |
13 | * $Author$ | |
14 | * $Header$ | |
15 | * | |
0a2c64cb | 16 | * Copyright 1988 by the Massachusetts Institute of Technology. |
08345b74 | 17 | * |
18 | * For further information on copyright and distribution | |
19 | * see the file mit-copyright.h | |
20 | */ | |
21 | ||
22 | #include <pwd.h> | |
23 | #include <signal.h> | |
24 | #include <stdio.h> | |
25 | #include <strings.h> | |
461c03b6 | 26 | #include <sys/types.h> |
8defc06b | 27 | #include <moira.h> |
08345b74 | 28 | #include <menu.h> |
71ca689a | 29 | #include <krb_et.h> |
08345b74 | 30 | |
31 | #include "mit-copyright.h" | |
0a2c64cb | 32 | #include "defs.h" |
33 | #include "f_defs.h" | |
08345b74 | 34 | #include "globals.h" |
35 | ||
85ca828a | 36 | char * whoami; /* used by menu.c ugh!!! */ |
1931dc22 | 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 | |
402461ad | 42 | #ifndef DEBUG |
facd6784 | 43 | static void SignalHandler(), CatchInterrupt(); |
402461ad | 44 | #endif DEBUG |
45 | ||
46 | static void ErrorExit(), Usage(); | |
08345b74 | 47 | char *getlogin(); |
48 | uid_t getuid(); | |
49 | struct passwd *getpwuid(); | |
50 | ||
4d9855ac | 51 | #ifdef _AIX |
52 | Bool use_menu = FALSE; /* whether or not we are using a menu. */ | |
53 | #else | |
08345b74 | 54 | Bool use_menu = TRUE; /* whether or not we are using a menu. */ |
4d9855ac | 55 | #endif |
08345b74 | 56 | |
57 | /* Function Name: main | |
1931dc22 | 58 | * Description: The main driver for the Moira Client. |
08345b74 | 59 | * Arguments: argc, argv - standard command line args. |
60 | * Returns: doesn't return. | |
61 | */ | |
62 | ||
63 | void | |
64 | main(argc, argv) | |
65 | int argc; | |
66 | char ** argv; | |
67 | { | |
461c03b6 | 68 | int status; |
ace1dd7b | 69 | Menu *menu; |
1931dc22 | 70 | char *motd, **arg; |
08345b74 | 71 | |
72 | if ((user = getlogin()) == NULL) | |
73 | user = getpwuid((int) getuid())->pw_name; | |
74 | user = (user && strlen(user)) ? Strsave(user) : ""; | |
75 | ||
e774e94c | 76 | if ((program_name = rindex(argv[0], '/')) == NULL) |
77 | program_name = argv[0]; | |
78 | else | |
79 | program_name++; | |
c2be255c | 80 | program_name = Strsave(program_name); |
81 | whoami = Strsave(program_name); /* used by menu.c, ugh !!! */ | |
82 | ||
461c03b6 | 83 | verbose = TRUE; |
576becad | 84 | arg = argv; |
75f991c8 | 85 | moira_server = NULL; |
576becad | 86 | |
87 | while (++arg - argv < argc) { | |
88 | if (**arg == '-') { | |
89 | if (!strcmp(*arg, "-nomenu")) | |
90 | use_menu = FALSE; | |
91 | else if (!strcmp(*arg, "-db")) | |
92 | if (arg - argv < argc - 1) { | |
93 | ++arg; | |
1931dc22 | 94 | moira_server = *arg; |
576becad | 95 | } else |
96 | Usage(argv); | |
97 | else | |
98 | Usage(argv); | |
99 | } | |
08345b74 | 100 | } |
85ca828a | 101 | |
8defc06b | 102 | if ( status = mr_connect(moira_server) ) |
1931dc22 | 103 | ErrorExit("\nConnection to Moira server failed", status); |
08345b74 | 104 | |
8defc06b | 105 | if ( status = mr_motd(&motd) ) |
262ca740 | 106 | ErrorExit("\nUnable to check server status", status); |
107 | if (motd) { | |
1931dc22 | 108 | fprintf(stderr, "The Moira server is currently unavailable:\n%s\n", motd); |
8defc06b | 109 | mr_disconnect(); |
262ca740 | 110 | exit(1); |
111 | } | |
112 | ||
8defc06b | 113 | if ( status = mr_auth(program_name) ) { |
114 | if (status == MR_USER_AUTH) { | |
1931dc22 | 115 | char buf[BUFSIZ]; |
116 | com_err(program_name, status, "\nPress [RETURN] to continue"); | |
117 | gets(buf); | |
71ca689a | 118 | } else { |
119 | if (status >= ERROR_TABLE_BASE_krb && | |
120 | status <= ERROR_TABLE_BASE_krb + 256) | |
121 | ErrorExit("\nAuthorization failed -- please run kinit", status); | |
122 | else | |
123 | ErrorExit("\nAuthorization failed.", status); | |
124 | } | |
1931dc22 | 125 | } |
08345b74 | 126 | |
127 | /* | |
128 | * These signals should not be set until just before we fire up the menu | |
129 | * system. | |
130 | */ | |
85ca828a | 131 | |
132 | #ifndef DEBUG | |
461c03b6 | 133 | (void) signal(SIGHUP, SignalHandler); |
461c03b6 | 134 | (void) signal(SIGQUIT, SignalHandler); |
facd6784 | 135 | if (use_menu) |
136 | (void) signal(SIGINT, SignalHandler); | |
137 | else | |
138 | (void) signal(SIGINT, CatchInterrupt); | |
85ca828a | 139 | #endif DEBUG |
08345b74 | 140 | |
e9ed68d9 | 141 | initialize_gdss_error_table(); |
142 | ||
ace1dd7b | 143 | if (!strcmp(program_name, "listmaint")) |
144 | menu = &list_menu; | |
145 | else if (!strcmp(program_name, "usermaint")) | |
146 | menu = &user_menu; | |
bc628e37 | 147 | else if (!strcmp(program_name, "dcmmaint")) |
148 | menu = &dcm_menu; | |
ace1dd7b | 149 | else |
8defc06b | 150 | menu = &moira_top_menu; |
ace1dd7b | 151 | |
08345b74 | 152 | if (use_menu) { /* Start menus that execute program */ |
153 | Start_paging(); | |
ace1dd7b | 154 | Start_menu(menu); |
08345b74 | 155 | Stop_paging(); |
156 | } | |
157 | else /* Start program without menus. */ | |
ace1dd7b | 158 | Start_no_menu(menu); |
08345b74 | 159 | |
8defc06b | 160 | mr_disconnect(); |
08345b74 | 161 | exit(0); |
162 | } | |
163 | ||
461c03b6 | 164 | /* Function Name: ErrorExit |
08345b74 | 165 | * Description: This function does the error handling and exits. |
166 | * Arguments: buf - the error message to print. | |
167 | * status - the error code. | |
168 | * Returns: doesn't return. | |
169 | */ | |
170 | ||
171 | static void | |
461c03b6 | 172 | ErrorExit(buf,status) |
08345b74 | 173 | int status; |
461c03b6 | 174 | char * buf; |
08345b74 | 175 | { |
176 | com_err(program_name, status, buf); | |
8defc06b | 177 | mr_disconnect(); |
08345b74 | 178 | exit(1); |
179 | } | |
180 | ||
181 | /* Function Name: usage | |
182 | * Description: Prints usage info and then exits. | |
183 | * Arguments: none | |
184 | * Returns: doesn't return. | |
185 | */ | |
186 | ||
187 | static void | |
461c03b6 | 188 | Usage() |
08345b74 | 189 | { |
190 | fprintf(stderr, "Usage: %s [-nomenu]\n", program_name); | |
191 | exit(1); | |
192 | } | |
193 | ||
402461ad | 194 | #ifndef DEBUG |
461c03b6 | 195 | /* Function Name: SignalHandler |
08345b74 | 196 | * Description: This function cleans up from a signal interrupt. |
197 | * Arguments: none. | |
198 | * Returns: doesn't | |
199 | */ | |
200 | ||
85ca828a | 201 | static void |
461c03b6 | 202 | SignalHandler() |
08345b74 | 203 | { |
204 | Put_message("Signal caught - exiting"); | |
205 | if (use_menu) | |
206 | Cleanup_menu(); | |
8defc06b | 207 | mr_disconnect(); |
08345b74 | 208 | exit(1); |
209 | } | |
facd6784 | 210 | |
211 | ||
212 | static void | |
213 | CatchInterrupt() | |
214 | { | |
215 | Put_message("Interrupt! Press RETURN to continue"); | |
216 | interrupt = 1; | |
217 | } | |
402461ad | 218 | #endif DEBUG |