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