]> andersk Git - moira.git/blob - clients/moira/namespace.c
6020d8fecdc442f888b5933ff704e5b2cecab1ec
[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   user = mrcl_krb_user();
190   if (!user)
191     exit(1);
192
193   verbose = TRUE;
194   arg = argv;
195   moira_server = NULL;
196
197   while (++arg - argv < argc)
198     {
199       if (**arg == '-')
200         {
201           if (!strcmp(*arg, "-nomenu"))
202             {
203 #ifdef HAVE_CURSES
204               use_menu = FALSE;
205 #else
206               ;
207 #endif
208             }
209           else if (!strcmp(*arg, "-menu"))
210             {
211 #ifdef HAVE_CURSES
212               use_menu = TRUE;
213 #else
214               fprintf(stderr, "%s: No curses support. -menu option ignored\n",
215                       whoami);
216 #endif
217             }
218           else if (!strcmp(*arg, "-db"))
219             if (arg - argv < argc - 1)
220               {
221                 ++arg;
222                 moira_server = *arg;
223               }
224             else
225               Usage();
226           else
227             Usage();
228         }
229     }
230
231   if (mrcl_connect(moira_server, program_name, QUERY_VERSION, 0)
232       != MRCL_SUCCESS)
233     exit(1);
234
235   if ((status = mr_krb5_auth(program_name)))
236     {
237       if (status == MR_UNKNOWN_PROC)
238         status = mr_auth(program_name);
239
240       if (status)
241         {
242           if (status == MR_USER_AUTH)
243             {
244               char buf[BUFSIZ];
245               com_err(program_name, status, "\nPress [RETURN] to continue");
246               fgets(buf, BUFSIZ, stdin);
247             }
248           else
249             ErrorExit("\nAuthorization failed -- please run kinit", status);
250         }
251     }
252
253   /*
254    * These signals should not be set until just before we fire up the menu
255    * system.
256    */
257
258   sigemptyset(&act.sa_mask);
259   act.sa_flags = 0;
260   act.sa_handler = Signal_Handler;
261   sigaction(SIGHUP, &act, NULL);
262   sigaction(SIGQUIT, &act, NULL);
263 #ifdef HAVE_CURSES
264   if (use_menu)
265     sigaction(SIGINT, &act, NULL);
266   else
267 #endif
268     {
269       act.sa_handler = CatchInterrupt;
270       sigaction(SIGINT, &act, NULL);
271     }
272
273   menu = &namespace_menu;
274
275 #ifdef HAVE_CURSES
276   if (use_menu)         /* Start menus that execute program */
277     {
278       Start_paging();
279       Start_menu(menu);
280       Stop_paging();
281     }
282   else                  /* Start program without menus. */
283 #endif
284     Start_no_menu(menu);
285
286   mr_disconnect();
287   exit(0);
288 }
289
290 /*      Function Name: ErrorExit
291  *      Description: This function does the error handling and exits.
292  *      Arguments: buf - the error message to print.
293  *                 status - the error code.
294  *      Returns: doesn't return.
295  */
296
297 static void ErrorExit(char *buf, int status)
298 {
299   com_err(program_name, status, buf);
300   mr_disconnect();
301   exit(1);
302 }
303
304 /*      Function Name: usage
305  *      Description: Prints usage info and then exits.
306  *      Arguments: none
307  *      Returns: doesn't return.
308  */
309
310 static void Usage(void)
311 {
312   fprintf(stderr, "Usage: %s [-nomenu]\n", program_name);
313   exit(1);
314 }
315
316 /*      Function Name: Signal_Handler
317  *      Description: This function cleans up from a signal interrupt.
318  *      Arguments: none.
319  *      Returns: doesn't
320  */
321
322 static void Signal_Handler(void)
323 {
324   Put_message("Signal caught - exiting");
325 #ifdef HAVE_CURSES
326   if (use_menu)
327     Cleanup_menu();
328 #endif
329   mr_disconnect();
330   exit(1);
331 }
332
333
334 static void CatchInterrupt(void)
335 {
336   Put_message("Interrupt! Press RETURN to continue");
337   interrupt = 1;
338 }
339
340
341 /* Dummy routine to be able to link against the rest of the moira client */
342
343 int DeleteUser(int argc, char **argv)
344 {
345   return DM_QUIT;
346 }
347
348
349 int NewListHelp(int argc, char **argv)
350 {
351   static char *message[] = {
352     "A list can be a mailing list, an Athena group list, or both.  Each",
353     "list has an owner and members.  The owner of a list may be the list",
354     "itself, another list, or a user.  The members of a list can be users",
355     "(login names), other lists, or foreign address strings.  You can use",
356     "certain keys to do the following:",
357     "    Refresh the screen - Type ctrl-L.",
358     "    Escape from a function - Type ctrl-C.",
359     NULL,
360   };
361
362   return PrintHelp(message);
363 }
This page took 0.548671 seconds and 3 git commands to generate.