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