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