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