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