]>
Commit | Line | Data |
---|---|---|
1 | /* $Id$ | |
2 | * | |
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. | |
6 | * | |
7 | * Created: 4/12/88 | |
8 | * By: Chris D. Peterson | |
9 | * | |
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>. | |
13 | */ | |
14 | ||
15 | #include <mit-copyright.h> | |
16 | #include <moira.h> | |
17 | #include "defs.h" | |
18 | #include "f_defs.h" | |
19 | #include "globals.h" | |
20 | ||
21 | #include <signal.h> | |
22 | #include <stdio.h> | |
23 | #include <string.h> | |
24 | ||
25 | #include <krb.h> | |
26 | ||
27 | RCSID("$Header$"); | |
28 | ||
29 | static void ErrorExit(char *buf, int status); | |
30 | static void Usage(void); | |
31 | static void Signal_Handler(void); | |
32 | static void CatchInterrupt(void); | |
33 | int NewListHelp(int argc, char **argv); | |
34 | ||
35 | char *whoami; /* used by menu.c ugh!!! */ | |
36 | char *moira_server; | |
37 | int interrupt = 0; | |
38 | ||
39 | /* | |
40 | * List Information Menu | |
41 | */ | |
42 | ||
43 | Menu list_info_menu = { | |
44 | NULLFUNC, | |
45 | NULLFUNC, | |
46 | "List Information Menu", | |
47 | 3, | |
48 | { | |
49 | SIMPLEFUNC("member", "Show all lists to which a given member belongs", | |
50 | ListByMember), | |
51 | SIMPLEFUNC("admin", "Show all items which a given member can administer", | |
52 | ListByAdministrator), | |
53 | SIMPLEFUNC("public", "Show all public mailing lists", | |
54 | ListAllPublicMailLists), | |
55 | } | |
56 | }; | |
57 | ||
58 | /* | |
59 | * List Member Menu | |
60 | */ | |
61 | ||
62 | Menu list_member_menu = { | |
63 | ListmaintMemberMenuEntry, | |
64 | ListmaintMemberMenuExit, | |
65 | NULL, | |
66 | 4, | |
67 | { | |
68 | SIMPLEFUNC("add", "Add a member to this list", AddMember), | |
69 | SIMPLEFUNC("remove", "Remove a member from this list", DeleteMember), | |
70 | SIMPLEFUNC("show", "Show the members of this list", ListAllMembers), | |
71 | SIMPLEFUNC("verbose", "Toggle Verbosity of Delete", ToggleVerboseMode) | |
72 | } | |
73 | }; | |
74 | ||
75 | /* | |
76 | * List Menu | |
77 | */ | |
78 | ||
79 | Menu list_menu = { | |
80 | NULLFUNC, | |
81 | NULLFUNC, | |
82 | "List Menu", | |
83 | 6, | |
84 | { | |
85 | { ShowListInfo, NULLMENU, 2, { | |
86 | {"show", "Display information about a list"}, | |
87 | {"list name", "Name of list: "} | |
88 | } }, | |
89 | { UpdateList, NULLMENU, 2, { | |
90 | {"update", "Update characteristics of a list"}, | |
91 | {"list name", "Name of list: "} | |
92 | } }, | |
93 | SIMPLEFUNC("query_remove", | |
94 | "Interactively remove a member from all lists", | |
95 | InterRemoveItemFromLists), | |
96 | { NULLFUNC, &list_member_menu, 2, { | |
97 | {"members", "Member Menu - Change/Show Members of a List."}, | |
98 | {"list name", "Name of list: "} | |
99 | } }, | |
100 | SUBMENU("lists", "Find Mailing Lists Menu", | |
101 | &list_info_menu), | |
102 | SIMPLEFUNC("help", "Print Help", NewListHelp) | |
103 | } | |
104 | }; | |
105 | ||
106 | /* | |
107 | * Post Office Box Menu | |
108 | */ | |
109 | ||
110 | Menu pobox_menu = { | |
111 | NULLFUNC, | |
112 | NULLFUNC, | |
113 | "Mail Forwarding Menu", | |
114 | 3, | |
115 | { | |
116 | {GetUserPOBox, NULLMENU, 2, { | |
117 | {"show", "Show a user's post office box"}, | |
118 | {"user name", "user name: "} | |
119 | } }, | |
120 | {SetUserPOBox, NULLMENU, 2, { | |
121 | {"set", "Set a user's post office box (mail forwarding)"}, | |
122 | {"user name", "user name: "} | |
123 | } }, | |
124 | {RemoveUserPOBox, NULLMENU, 2, { | |
125 | {"remove", "Remove a user's post office box"}, | |
126 | {"user name", "user name: "} | |
127 | } }, | |
128 | } | |
129 | }; | |
130 | ||
131 | /* | |
132 | * Miscellaneous Menu | |
133 | */ | |
134 | ||
135 | Menu misc_menu = { | |
136 | NULLFUNC, | |
137 | NULLFUNC, | |
138 | "Miscellaneous Menu", | |
139 | 2, | |
140 | { | |
141 | SIMPLEFUNC("statistics", "Show database statistics", TableStats), | |
142 | SIMPLEFUNC("clients", "Show active Moira clients", ShowClients), | |
143 | } | |
144 | }; | |
145 | ||
146 | ||
147 | Menu namespace_menu = { | |
148 | NULLFUNC, | |
149 | NULLFUNC, | |
150 | "Campus Namespace Database Manipulation", | |
151 | 4, | |
152 | { | |
153 | SUBMENU("mail", "Mail Forwarding", &pobox_menu), | |
154 | SUBMENU("list", "Mailing Lists", &list_menu), | |
155 | {ShowUserByLogin, NULLMENU, 2, { | |
156 | {"account", "Show user account information"}, | |
157 | {"login name", "Desired login name: "} | |
158 | } }, | |
159 | SUBMENU("misc", "Miscellaneous", &misc_menu) | |
160 | } | |
161 | }; | |
162 | ||
163 | #ifdef HAVE_CURSES | |
164 | Bool use_menu = TRUE; /* whether or not we are using a menu. */ | |
165 | #endif | |
166 | ||
167 | /* Function Name: main | |
168 | * Description: The main driver for the Moira Client. | |
169 | * Arguments: argc, argv - standard command line args. | |
170 | * Returns: doesn't return. | |
171 | */ | |
172 | ||
173 | int main(int argc, char **argv) | |
174 | { | |
175 | int status; | |
176 | Menu *menu; | |
177 | char *motd, **arg; | |
178 | char pname[ANAME_SZ]; | |
179 | struct sigaction act; | |
180 | ||
181 | if (!(program_name = strrchr(argv[0], '/'))) | |
182 | program_name = argv[0]; | |
183 | else | |
184 | program_name++; | |
185 | program_name = strdup(program_name); | |
186 | whoami = strdup(program_name); /* used by menu.c, ugh !!! */ | |
187 | ||
188 | verbose = TRUE; | |
189 | arg = argv; | |
190 | moira_server = NULL; | |
191 | ||
192 | while (++arg - argv < argc) | |
193 | { | |
194 | if (**arg == '-') | |
195 | { | |
196 | if (!strcmp(*arg, "-nomenu")) | |
197 | { | |
198 | #ifdef HAVE_CURSES | |
199 | use_menu = FALSE; | |
200 | #else | |
201 | ; | |
202 | #endif | |
203 | } | |
204 | else if (!strcmp(*arg, "-menu")) | |
205 | { | |
206 | #ifdef HAVE_CURSES | |
207 | use_menu = TRUE; | |
208 | #else | |
209 | fprintf(stderr, "%s: No curses support. -menu option ignored\n", | |
210 | whoami); | |
211 | #endif | |
212 | } | |
213 | else if (!strcmp(*arg, "-db")) | |
214 | if (arg - argv < argc - 1) | |
215 | { | |
216 | ++arg; | |
217 | moira_server = *arg; | |
218 | } | |
219 | else | |
220 | Usage(); | |
221 | else | |
222 | Usage(); | |
223 | } | |
224 | } | |
225 | ||
226 | if ((status = mr_connect(moira_server))) | |
227 | ErrorExit("\nConnection to Moira server failed", status); | |
228 | ||
229 | /* do this now since calling mr_connect initialized the krb error table | |
230 | * for us. | |
231 | */ | |
232 | if ((status = tf_init(TKT_FILE, R_TKT_FIL)) || | |
233 | (status = tf_get_pname(pname))) | |
234 | { | |
235 | com_err(whoami, status, "cannot find your ticket file"); | |
236 | exit(1); | |
237 | } | |
238 | tf_close(); | |
239 | user = strdup(pname); | |
240 | ||
241 | if ((status = mr_motd(&motd))) | |
242 | ErrorExit("\nUnable to check server status", status); | |
243 | if (motd) | |
244 | { | |
245 | fprintf(stderr, "The Moira server is currently unavailable:\n%s\n", | |
246 | motd); | |
247 | mr_disconnect(); | |
248 | exit(1); | |
249 | } | |
250 | ||
251 | if ((status = mr_auth(program_name))) | |
252 | { | |
253 | if (status == MR_USER_AUTH) | |
254 | { | |
255 | char buf[BUFSIZ]; | |
256 | com_err(program_name, status, "\nPress [RETURN] to continue"); | |
257 | fgets(buf, BUFSIZ, stdin); | |
258 | } | |
259 | else | |
260 | ErrorExit("\nAuthorization failed -- please run kinit", status); | |
261 | } | |
262 | ||
263 | /* | |
264 | * These signals should not be set until just before we fire up the menu | |
265 | * system. | |
266 | */ | |
267 | ||
268 | sigemptyset(&act.sa_mask); | |
269 | act.sa_flags = 0; | |
270 | act.sa_handler = Signal_Handler; | |
271 | sigaction(SIGHUP, &act, NULL); | |
272 | sigaction(SIGQUIT, &act, NULL); | |
273 | #ifdef HAVE_CURSES | |
274 | if (use_menu) | |
275 | sigaction(SIGINT, &act, NULL); | |
276 | else | |
277 | #endif | |
278 | { | |
279 | act.sa_handler = CatchInterrupt; | |
280 | sigaction(SIGINT, &act, NULL); | |
281 | } | |
282 | ||
283 | menu = &namespace_menu; | |
284 | ||
285 | #ifdef HAVE_CURSES | |
286 | if (use_menu) /* Start menus that execute program */ | |
287 | { | |
288 | Start_paging(); | |
289 | Start_menu(menu); | |
290 | Stop_paging(); | |
291 | } | |
292 | else /* Start program without menus. */ | |
293 | #endif | |
294 | Start_no_menu(menu); | |
295 | ||
296 | mr_disconnect(); | |
297 | exit(0); | |
298 | } | |
299 | ||
300 | /* Function Name: ErrorExit | |
301 | * Description: This function does the error handling and exits. | |
302 | * Arguments: buf - the error message to print. | |
303 | * status - the error code. | |
304 | * Returns: doesn't return. | |
305 | */ | |
306 | ||
307 | static void ErrorExit(char *buf, int status) | |
308 | { | |
309 | com_err(program_name, status, buf); | |
310 | mr_disconnect(); | |
311 | exit(1); | |
312 | } | |
313 | ||
314 | /* Function Name: usage | |
315 | * Description: Prints usage info and then exits. | |
316 | * Arguments: none | |
317 | * Returns: doesn't return. | |
318 | */ | |
319 | ||
320 | static void Usage(void) | |
321 | { | |
322 | fprintf(stderr, "Usage: %s [-nomenu]\n", program_name); | |
323 | exit(1); | |
324 | } | |
325 | ||
326 | /* Function Name: Signal_Handler | |
327 | * Description: This function cleans up from a signal interrupt. | |
328 | * Arguments: none. | |
329 | * Returns: doesn't | |
330 | */ | |
331 | ||
332 | static void Signal_Handler(void) | |
333 | { | |
334 | Put_message("Signal caught - exiting"); | |
335 | #ifdef HAVE_CURSES | |
336 | if (use_menu) | |
337 | Cleanup_menu(); | |
338 | #endif | |
339 | mr_disconnect(); | |
340 | exit(1); | |
341 | } | |
342 | ||
343 | ||
344 | static void CatchInterrupt(void) | |
345 | { | |
346 | Put_message("Interrupt! Press RETURN to continue"); | |
347 | interrupt = 1; | |
348 | } | |
349 | ||
350 | ||
351 | /* Dummy routine to be able to link against the rest of the moira client */ | |
352 | ||
353 | int DeleteUser(int argc, char **argv) | |
354 | { | |
355 | return DM_QUIT; | |
356 | } | |
357 | ||
358 | ||
359 | int NewListHelp(int argc, char **argv) | |
360 | { | |
361 | static char *message[] = { | |
362 | "A list can be a mailing list, an Athena group list, or both. Each", | |
363 | "list has an owner and members. The owner of a list may be the list", | |
364 | "itself, another list, or a user. The members of a list can be users", | |
365 | "(login names), other lists, or foreign address strings. You can use", | |
366 | "certain keys to do the following:", | |
367 | " Refresh the screen - Type ctrl-L.", | |
368 | " Escape from a function - Type ctrl-C.", | |
369 | NULL, | |
370 | }; | |
371 | ||
372 | return PrintHelp(message); | |
373 | } |