]>
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 | |
189 | verbose = TRUE; | |
190 | arg = argv; | |
191 | moira_server = NULL; | |
192 | ||
193 | while (++arg - argv < argc) | |
194 | { | |
195 | if (**arg == '-') | |
196 | { | |
197 | if (!strcmp(*arg, "-nomenu")) | |
ea0caf4a | 198 | { |
199 | #ifdef HAVE_CURSES | |
200 | use_menu = FALSE; | |
201 | #else | |
202 | ; | |
203 | #endif | |
204 | } | |
205 | else if (!strcmp(*arg, "-menu")) | |
206 | { | |
207 | #ifdef HAVE_CURSES | |
208 | use_menu = TRUE; | |
209 | #else | |
210 | fprintf(stderr, "%s: No curses support. -menu option ignored\n", | |
211 | whoami); | |
212 | #endif | |
213 | } | |
5eaef520 | 214 | else if (!strcmp(*arg, "-db")) |
215 | if (arg - argv < argc - 1) | |
216 | { | |
217 | ++arg; | |
218 | moira_server = *arg; | |
219 | } | |
cca09928 | 220 | else |
7ac48069 | 221 | Usage(); |
5eaef520 | 222 | else |
7ac48069 | 223 | Usage(); |
cca09928 | 224 | } |
225 | } | |
226 | ||
5853547e | 227 | if (mrcl_connect(moira_server, program_name, QUERY_VERSION, 0) |
228 | != MRCL_SUCCESS) | |
229 | exit(1); | |
cca09928 | 230 | |
5eaef520 | 231 | if ((status = mr_auth(program_name))) |
232 | { | |
233 | if (status == MR_USER_AUTH) | |
234 | { | |
235 | char buf[BUFSIZ]; | |
236 | com_err(program_name, status, "\nPress [RETURN] to continue"); | |
237 | fgets(buf, BUFSIZ, stdin); | |
238 | } | |
239 | else | |
240 | ErrorExit("\nAuthorization failed -- please run kinit", status); | |
241 | } | |
cca09928 | 242 | |
5eaef520 | 243 | /* |
244 | * These signals should not be set until just before we fire up the menu | |
245 | * system. | |
246 | */ | |
247 | ||
248 | sigemptyset(&act.sa_mask); | |
249 | act.sa_flags = 0; | |
7ac48069 | 250 | act.sa_handler = Signal_Handler; |
5eaef520 | 251 | sigaction(SIGHUP, &act, NULL); |
252 | sigaction(SIGQUIT, &act, NULL); | |
ea0caf4a | 253 | #ifdef HAVE_CURSES |
5eaef520 | 254 | if (use_menu) |
255 | sigaction(SIGINT, &act, NULL); | |
256 | else | |
ea0caf4a | 257 | #endif |
5eaef520 | 258 | { |
7ac48069 | 259 | act.sa_handler = CatchInterrupt; |
5eaef520 | 260 | sigaction(SIGINT, &act, NULL); |
f071d8a7 | 261 | } |
5eaef520 | 262 | |
263 | menu = &namespace_menu; | |
264 | ||
ea0caf4a | 265 | #ifdef HAVE_CURSES |
5eaef520 | 266 | if (use_menu) /* Start menus that execute program */ |
267 | { | |
268 | Start_paging(); | |
269 | Start_menu(menu); | |
270 | Stop_paging(); | |
cca09928 | 271 | } |
5eaef520 | 272 | else /* Start program without menus. */ |
ea0caf4a | 273 | #endif |
5eaef520 | 274 | Start_no_menu(menu); |
cca09928 | 275 | |
5eaef520 | 276 | mr_disconnect(); |
277 | exit(0); | |
cca09928 | 278 | } |
279 | ||
280 | /* Function Name: ErrorExit | |
281 | * Description: This function does the error handling and exits. | |
282 | * Arguments: buf - the error message to print. | |
283 | * status - the error code. | |
284 | * Returns: doesn't return. | |
285 | */ | |
286 | ||
5eaef520 | 287 | static void ErrorExit(char *buf, int status) |
cca09928 | 288 | { |
5eaef520 | 289 | com_err(program_name, status, buf); |
290 | mr_disconnect(); | |
291 | exit(1); | |
cca09928 | 292 | } |
293 | ||
294 | /* Function Name: usage | |
295 | * Description: Prints usage info and then exits. | |
296 | * Arguments: none | |
297 | * Returns: doesn't return. | |
298 | */ | |
299 | ||
5eaef520 | 300 | static void Usage(void) |
cca09928 | 301 | { |
5eaef520 | 302 | fprintf(stderr, "Usage: %s [-nomenu]\n", program_name); |
303 | exit(1); | |
cca09928 | 304 | } |
305 | ||
7798ebc3 | 306 | /* Function Name: Signal_Handler |
cca09928 | 307 | * Description: This function cleans up from a signal interrupt. |
308 | * Arguments: none. | |
309 | * Returns: doesn't | |
310 | */ | |
311 | ||
5eaef520 | 312 | static void Signal_Handler(void) |
cca09928 | 313 | { |
5eaef520 | 314 | Put_message("Signal caught - exiting"); |
ea0caf4a | 315 | #ifdef HAVE_CURSES |
5eaef520 | 316 | if (use_menu) |
317 | Cleanup_menu(); | |
ea0caf4a | 318 | #endif |
5eaef520 | 319 | mr_disconnect(); |
320 | exit(1); | |
cca09928 | 321 | } |
facd6784 | 322 | |
323 | ||
5eaef520 | 324 | static void CatchInterrupt(void) |
facd6784 | 325 | { |
5eaef520 | 326 | Put_message("Interrupt! Press RETURN to continue"); |
327 | interrupt = 1; | |
facd6784 | 328 | } |
cca09928 | 329 | |
330 | ||
331 | /* Dummy routine to be able to link against the rest of the moira client */ | |
332 | ||
7ac48069 | 333 | int DeleteUser(int argc, char **argv) |
cca09928 | 334 | { |
5eaef520 | 335 | return DM_QUIT; |
7798ebc3 | 336 | } |
cca09928 | 337 | |
338 | ||
7ac48069 | 339 | int NewListHelp(int argc, char **argv) |
cca09928 | 340 | { |
5eaef520 | 341 | static char *message[] = { |
342 | "A list can be a mailing list, an Athena group list, or both. Each", | |
343 | "list has an owner and members. The owner of a list may be the list", | |
344 | "itself, another list, or a user. The members of a list can be users", | |
345 | "(login names), other lists, or foreign address strings. You can use", | |
346 | "certain keys to do the following:", | |
347 | " Refresh the screen - Type ctrl-L.", | |
348 | " Escape from a function - Type ctrl-C.", | |
349 | NULL, | |
350 | }; | |
351 | ||
352 | return PrintHelp(message); | |
cca09928 | 353 | } |