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