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