]>
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 | ||
51 | Bool use_menu = TRUE; /* whether or not we are using a menu. */ | |
52 | ||
53 | /* Function Name: main | |
1931dc22 | 54 | * Description: The main driver for the Moira Client. |
08345b74 | 55 | * Arguments: argc, argv - standard command line args. |
56 | * Returns: doesn't return. | |
57 | */ | |
58 | ||
59 | void | |
60 | main(argc, argv) | |
61 | int argc; | |
62 | char ** argv; | |
63 | { | |
461c03b6 | 64 | int status; |
ace1dd7b | 65 | Menu *menu; |
1931dc22 | 66 | char *motd, **arg; |
08345b74 | 67 | |
68 | if ((user = getlogin()) == NULL) | |
69 | user = getpwuid((int) getuid())->pw_name; | |
70 | user = (user && strlen(user)) ? Strsave(user) : ""; | |
71 | ||
e774e94c | 72 | if ((program_name = rindex(argv[0], '/')) == NULL) |
73 | program_name = argv[0]; | |
74 | else | |
75 | program_name++; | |
c2be255c | 76 | program_name = Strsave(program_name); |
77 | whoami = Strsave(program_name); /* used by menu.c, ugh !!! */ | |
78 | ||
461c03b6 | 79 | verbose = TRUE; |
576becad | 80 | arg = argv; |
75f991c8 | 81 | moira_server = NULL; |
576becad | 82 | |
83 | while (++arg - argv < argc) { | |
84 | if (**arg == '-') { | |
85 | if (!strcmp(*arg, "-nomenu")) | |
86 | use_menu = FALSE; | |
87 | else if (!strcmp(*arg, "-db")) | |
88 | if (arg - argv < argc - 1) { | |
89 | ++arg; | |
1931dc22 | 90 | moira_server = *arg; |
576becad | 91 | } else |
92 | Usage(argv); | |
93 | else | |
94 | Usage(argv); | |
95 | } | |
08345b74 | 96 | } |
85ca828a | 97 | |
8defc06b | 98 | if ( status = mr_connect(moira_server) ) |
1931dc22 | 99 | ErrorExit("\nConnection to Moira server failed", status); |
08345b74 | 100 | |
8defc06b | 101 | if ( status = mr_motd(&motd) ) |
262ca740 | 102 | ErrorExit("\nUnable to check server status", status); |
103 | if (motd) { | |
1931dc22 | 104 | fprintf(stderr, "The Moira server is currently unavailable:\n%s\n", motd); |
8defc06b | 105 | mr_disconnect(); |
262ca740 | 106 | exit(1); |
107 | } | |
108 | ||
8defc06b | 109 | if ( status = mr_auth(program_name) ) { |
110 | if (status == MR_USER_AUTH) { | |
1931dc22 | 111 | char buf[BUFSIZ]; |
112 | com_err(program_name, status, "\nPress [RETURN] to continue"); | |
113 | gets(buf); | |
71ca689a | 114 | } else { |
115 | if (status >= ERROR_TABLE_BASE_krb && | |
116 | status <= ERROR_TABLE_BASE_krb + 256) | |
117 | ErrorExit("\nAuthorization failed -- please run kinit", status); | |
118 | else | |
119 | ErrorExit("\nAuthorization failed.", status); | |
120 | } | |
1931dc22 | 121 | } |
08345b74 | 122 | |
123 | /* | |
124 | * These signals should not be set until just before we fire up the menu | |
125 | * system. | |
126 | */ | |
85ca828a | 127 | |
128 | #ifndef DEBUG | |
461c03b6 | 129 | (void) signal(SIGHUP, SignalHandler); |
461c03b6 | 130 | (void) signal(SIGQUIT, SignalHandler); |
facd6784 | 131 | if (use_menu) |
132 | (void) signal(SIGINT, SignalHandler); | |
133 | else | |
134 | (void) signal(SIGINT, CatchInterrupt); | |
85ca828a | 135 | #endif DEBUG |
08345b74 | 136 | |
e9ed68d9 | 137 | initialize_gdss_error_table(); |
138 | ||
ace1dd7b | 139 | if (!strcmp(program_name, "listmaint")) |
140 | menu = &list_menu; | |
141 | else if (!strcmp(program_name, "usermaint")) | |
142 | menu = &user_menu; | |
bc628e37 | 143 | else if (!strcmp(program_name, "dcmmaint")) |
144 | menu = &dcm_menu; | |
ace1dd7b | 145 | else |
8defc06b | 146 | menu = &moira_top_menu; |
ace1dd7b | 147 | |
08345b74 | 148 | if (use_menu) { /* Start menus that execute program */ |
149 | Start_paging(); | |
ace1dd7b | 150 | Start_menu(menu); |
08345b74 | 151 | Stop_paging(); |
152 | } | |
153 | else /* Start program without menus. */ | |
ace1dd7b | 154 | Start_no_menu(menu); |
08345b74 | 155 | |
8defc06b | 156 | mr_disconnect(); |
08345b74 | 157 | exit(0); |
158 | } | |
159 | ||
461c03b6 | 160 | /* Function Name: ErrorExit |
08345b74 | 161 | * Description: This function does the error handling and exits. |
162 | * Arguments: buf - the error message to print. | |
163 | * status - the error code. | |
164 | * Returns: doesn't return. | |
165 | */ | |
166 | ||
167 | static void | |
461c03b6 | 168 | ErrorExit(buf,status) |
08345b74 | 169 | int status; |
461c03b6 | 170 | char * buf; |
08345b74 | 171 | { |
172 | com_err(program_name, status, buf); | |
8defc06b | 173 | mr_disconnect(); |
08345b74 | 174 | exit(1); |
175 | } | |
176 | ||
177 | /* Function Name: usage | |
178 | * Description: Prints usage info and then exits. | |
179 | * Arguments: none | |
180 | * Returns: doesn't return. | |
181 | */ | |
182 | ||
183 | static void | |
461c03b6 | 184 | Usage() |
08345b74 | 185 | { |
186 | fprintf(stderr, "Usage: %s [-nomenu]\n", program_name); | |
187 | exit(1); | |
188 | } | |
189 | ||
402461ad | 190 | #ifndef DEBUG |
461c03b6 | 191 | /* Function Name: SignalHandler |
08345b74 | 192 | * Description: This function cleans up from a signal interrupt. |
193 | * Arguments: none. | |
194 | * Returns: doesn't | |
195 | */ | |
196 | ||
85ca828a | 197 | static void |
461c03b6 | 198 | SignalHandler() |
08345b74 | 199 | { |
200 | Put_message("Signal caught - exiting"); | |
201 | if (use_menu) | |
202 | Cleanup_menu(); | |
8defc06b | 203 | mr_disconnect(); |
08345b74 | 204 | exit(1); |
205 | } | |
facd6784 | 206 | |
207 | ||
208 | static void | |
209 | CatchInterrupt() | |
210 | { | |
211 | Put_message("Interrupt! Press RETURN to continue"); | |
212 | interrupt = 1; | |
213 | } | |
402461ad | 214 | #endif DEBUG |