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