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