]> andersk Git - moira.git/blob - clients/moira/namespace.c
break out of case statement, don't fall through.
[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_auth(program_name)))
236     {
237       if (status == MR_USER_AUTH)
238         {
239           char buf[BUFSIZ];
240           com_err(program_name, status, "\nPress [RETURN] to continue");
241           fgets(buf, BUFSIZ, stdin);
242         }
243       else
244         ErrorExit("\nAuthorization failed -- please run kinit", status);
245     }
246
247   /*
248    * These signals should not be set until just before we fire up the menu
249    * system.
250    */
251
252   sigemptyset(&act.sa_mask);
253   act.sa_flags = 0;
254   act.sa_handler = Signal_Handler;
255   sigaction(SIGHUP, &act, NULL);
256   sigaction(SIGQUIT, &act, NULL);
257 #ifdef HAVE_CURSES
258   if (use_menu)
259     sigaction(SIGINT, &act, NULL);
260   else
261 #endif
262     {
263       act.sa_handler = CatchInterrupt;
264       sigaction(SIGINT, &act, NULL);
265     }
266
267   menu = &namespace_menu;
268
269 #ifdef HAVE_CURSES
270   if (use_menu)         /* Start menus that execute program */
271     {
272       Start_paging();
273       Start_menu(menu);
274       Stop_paging();
275     }
276   else                  /* Start program without menus. */
277 #endif
278     Start_no_menu(menu);
279
280   mr_disconnect();
281   exit(0);
282 }
283
284 /*      Function Name: ErrorExit
285  *      Description: This function does the error handling and exits.
286  *      Arguments: buf - the error message to print.
287  *                 status - the error code.
288  *      Returns: doesn't return.
289  */
290
291 static void ErrorExit(char *buf, int status)
292 {
293   com_err(program_name, status, buf);
294   mr_disconnect();
295   exit(1);
296 }
297
298 /*      Function Name: usage
299  *      Description: Prints usage info and then exits.
300  *      Arguments: none
301  *      Returns: doesn't return.
302  */
303
304 static void Usage(void)
305 {
306   fprintf(stderr, "Usage: %s [-nomenu]\n", program_name);
307   exit(1);
308 }
309
310 /*      Function Name: Signal_Handler
311  *      Description: This function cleans up from a signal interrupt.
312  *      Arguments: none.
313  *      Returns: doesn't
314  */
315
316 static void Signal_Handler(void)
317 {
318   Put_message("Signal caught - exiting");
319 #ifdef HAVE_CURSES
320   if (use_menu)
321     Cleanup_menu();
322 #endif
323   mr_disconnect();
324   exit(1);
325 }
326
327
328 static void CatchInterrupt(void)
329 {
330   Put_message("Interrupt! Press RETURN to continue");
331   interrupt = 1;
332 }
333
334
335 /* Dummy routine to be able to link against the rest of the moira client */
336
337 int DeleteUser(int argc, char **argv)
338 {
339   return DM_QUIT;
340 }
341
342
343 int NewListHelp(int argc, char **argv)
344 {
345   static char *message[] = {
346     "A list can be a mailing list, an Athena group list, or both.  Each",
347     "list has an owner and members.  The owner of a list may be the list",
348     "itself, another list, or a user.  The members of a list can be users",
349     "(login names), other lists, or foreign address strings.  You can use",
350     "certain keys to do the following:",
351     "    Refresh the screen - Type ctrl-L.",
352     "    Escape from a function - Type ctrl-C.",
353     NULL,
354   };
355
356   return PrintHelp(message);
357 }
This page took 0.068156 seconds and 5 git commands to generate.