]> andersk Git - moira.git/blob - clients/moira/namespace.c
Build without krb4 if it's unavailable.
[moira.git] / clients / moira / namespace.c
1 /* $Id$
2  *
3  *      This is the file main.c for the Moira Client, which allows users
4  *      to quickly and easily maintain most parts of the Moira database.
5  *      It Contains: The main driver for the Moira Client.
6  *
7  *      Created:        4/12/88
8  *      By:             Chris D. Peterson
9  *
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>.
13  */
14
15 #include <mit-copyright.h>
16 #include <moira.h>
17 #include <mrclient.h>
18 #include "defs.h"
19 #include "f_defs.h"
20 #include "globals.h"
21
22 #include <signal.h>
23 #include <stdio.h>
24 #include <string.h>
25
26 RCSID("$Header$");
27
28 static void ErrorExit(char *buf, int status);
29 static void Usage(void);
30 static void Signal_Handler(void);
31 static void CatchInterrupt(void);
32 int NewListHelp(int argc, char **argv);
33
34 char *whoami;                   /* used by menu.c ugh!!! */
35 char *moira_server;
36 int interrupt = 0;
37
38 /*
39  * List Information Menu
40  */
41
42 Menu list_info_menu = {
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   }
55 };
56
57 /*
58  * List Member Menu
59  */
60
61 Menu list_member_menu = {
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   }
72 };
73
74 /*
75  * List Menu
76  */
77
78 Menu list_menu = {
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   }
103 };
104
105 /*
106  * Post Office Box Menu
107  */
108
109 Menu 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 };
129
130 /*
131  * Miscellaneous Menu
132  */
133
134 Menu misc_menu = {
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   }
143 };
144
145
146 Menu namespace_menu = {
147   NULLFUNC,
148   NULLFUNC,
149   "Campus Namespace Database Manipulation",
150   4,
151   {
152     SUBMENU("mail", "Mail Forwarding", &pobox_menu),
153     SUBMENU("list", "Mailing Lists", &list_menu),
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
162 #ifdef HAVE_CURSES
163 Bool use_menu = TRUE;           /* whether or not we are using a menu. */
164 #endif
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
172 int main(int argc, char **argv)
173 {
174   int status;
175   Menu *menu;
176   char *motd, **arg;
177   struct sigaction act;
178
179   if (!(program_name = strrchr(argv[0], '/')))
180     program_name = argv[0];
181   else
182     program_name++;
183   program_name = strdup(program_name);
184   whoami = strdup(program_name); /* used by menu.c,  ugh !!! */
185
186   user = mrcl_krb_user();
187   if (!user)
188     exit(1);
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             {
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             }
215           else if (!strcmp(*arg, "-db"))
216             if (arg - argv < argc - 1)
217               {
218                 ++arg;
219                 moira_server = *arg;
220               }
221             else
222               Usage();
223           else
224             Usage();
225         }
226     }
227
228   if (mrcl_connect(moira_server, program_name, QUERY_VERSION, 0)
229       != MRCL_SUCCESS)
230     exit(1);
231
232   if ((status = mr_krb5_auth(program_name)))
233     {
234       if (status == MR_UNKNOWN_PROC)
235         status = mr_auth(program_name);
236
237       if (status)
238         {
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);
247         }
248     }
249
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;
257   act.sa_handler = Signal_Handler;
258   sigaction(SIGHUP, &act, NULL);
259   sigaction(SIGQUIT, &act, NULL);
260 #ifdef HAVE_CURSES
261   if (use_menu)
262     sigaction(SIGINT, &act, NULL);
263   else
264 #endif
265     {
266       act.sa_handler = CatchInterrupt;
267       sigaction(SIGINT, &act, NULL);
268     }
269
270   menu = &namespace_menu;
271
272 #ifdef HAVE_CURSES
273   if (use_menu)         /* Start menus that execute program */
274     {
275       Start_paging();
276       Start_menu(menu);
277       Stop_paging();
278     }
279   else                  /* Start program without menus. */
280 #endif
281     Start_no_menu(menu);
282
283   mr_disconnect();
284   exit(0);
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
294 static void ErrorExit(char *buf, int status)
295 {
296   com_err(program_name, status, buf);
297   mr_disconnect();
298   exit(1);
299 }
300
301 /*      Function Name: usage
302  *      Description: Prints usage info and then exits.
303  *      Arguments: none
304  *      Returns: doesn't return.
305  */
306
307 static void Usage(void)
308 {
309   fprintf(stderr, "Usage: %s [-nomenu]\n", program_name);
310   exit(1);
311 }
312
313 /*      Function Name: Signal_Handler
314  *      Description: This function cleans up from a signal interrupt.
315  *      Arguments: none.
316  *      Returns: doesn't
317  */
318
319 static void Signal_Handler(void)
320 {
321   Put_message("Signal caught - exiting");
322 #ifdef HAVE_CURSES
323   if (use_menu)
324     Cleanup_menu();
325 #endif
326   mr_disconnect();
327   exit(1);
328 }
329
330
331 static void CatchInterrupt(void)
332 {
333   Put_message("Interrupt! Press RETURN to continue");
334   interrupt = 1;
335 }
336
337
338 /* Dummy routine to be able to link against the rest of the moira client */
339
340 int DeleteUser(int argc, char **argv)
341 {
342   return DM_QUIT;
343 }
344
345
346 int NewListHelp(int argc, char **argv)
347 {
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);
360 }
This page took 0.708536 seconds and 5 git commands to generate.