]> andersk Git - moira.git/blob - clients/moira/namespace.c
2764443d6a3a77336549ffb754022f722886e299
[moira.git] / clients / moira / namespace.c
1 #if (!defined(lint) && !defined(SABER))
2   static char rcsid_module_c[] = "$Header$";
3 #endif
4
5 /*      This is the file main.c for the Moira Client, which allows a nieve
6  *      user to quickly and easily maintain most parts of the Moira database.
7  *      It Contains: The main driver for the Moira Client.
8  *
9  *      Created:        4/12/88
10  *      By:             Chris D. Peterson
11  *
12  *      $Source$
13  *      $Author$
14  *      $Header$
15  *
16  *      Copyright 1988 by the Massachusetts Institute of Technology.
17  *
18  *      For further information on copyright and distribution
19  *      see the file mit-copyright.h
20  */
21
22 #include <pwd.h>
23 #include <signal.h>
24 #include <stdio.h>
25 #include <string.h>
26 #include <sys/types.h>
27 #include <moira.h>
28 #include <menu.h>
29 #include <krb.h>
30
31
32 #include "mit-copyright.h"
33 #include "defs.h"
34 #include "f_defs.h"
35 #include "globals.h"
36
37 char *whoami;                   /* used by menu.c ugh!!! */
38 char *moira_server;
39 int interrupt = 0;
40 int NewListHelp();
41
42 /*
43  * List Information Menu
44  */
45
46 Menu list_info_menu = {
47   NULLFUNC,
48   NULLFUNC,
49   "List Information Menu",
50   3,
51   {
52     SIMPLEFUNC("member", "Show all lists to which a given member belongs",
53                ListByMember),
54     SIMPLEFUNC("admin", "Show all items which a given member can administer",
55                ListByAdministrator),
56     SIMPLEFUNC("public", "Show all public mailing lists",
57                ListAllPublicMailLists),
58   }
59 };
60
61 /*
62  * List Member Menu
63  */
64
65 Menu list_member_menu = {
66   ListmaintMemberMenuEntry,
67   ListmaintMemberMenuExit,
68   NULL,
69   4,
70   {
71     SIMPLEFUNC("add", "Add a member to this list", AddMember),
72     SIMPLEFUNC("remove", "Remove a member from this list", DeleteMember),
73     SIMPLEFUNC("show", "Show the members of this list", ListAllMembers),
74     SIMPLEFUNC("verbose", "Toggle Verbosity of Delete", ToggleVerboseMode)
75   }
76 };
77
78 /*
79  * List Menu
80  */
81
82 Menu list_menu = {
83   NULLFUNC,
84   NULLFUNC,
85   "List Menu",
86   6,
87   {
88     { ShowListInfo, NULLMENU, 2, {
89       {"show", "Display information about a list"},
90       {"list name", "Name of list: "}
91     } },
92     { UpdateList, NULLMENU, 2, {
93       {"update", "Update characteristics of a list"},
94       {"list name", "Name of list: "}
95     } },
96     SIMPLEFUNC("query_remove",
97                "Interactively remove a member from all lists",
98                InterRemoveItemFromLists),
99     { NULLFUNC, &list_member_menu, 2, {
100       {"members", "Member Menu - Change/Show Members of a List."},
101       {"list name", "Name of list: "}
102     } },
103     SUBMENU("lists", "Find Mailing Lists Menu",
104             &list_info_menu),
105     SIMPLEFUNC("help", "Print Help", NewListHelp)
106   }
107 };
108
109 /*
110  * Post Office Box Menu
111  */
112
113 Menu pobox_menu = {
114   NULLFUNC,
115   NULLFUNC,
116   "Mail Forwarding Menu",
117   3,
118   {
119     {GetUserPOBox, NULLMENU, 2, {
120       {"show", "Show a user's post office box"},
121       {"user name", "user name: "}
122     } },
123     {SetUserPOBox, NULLMENU, 2, {
124       {"set", "Set a user's post office box (mail forwarding)"},
125       {"user name", "user name: "}
126     } },
127     {RemoveUserPOBox, NULLMENU, 2, {
128       {"remove", "Remove a user's post office box"},
129       {"user name", "user name: "}
130     } },
131   }
132 };
133
134 /*
135  * Miscellaneous Menu
136  */
137
138 Menu misc_menu = {
139   NULLFUNC,
140   NULLFUNC,
141   "Miscellaneous Menu",
142   2,
143   {
144     SIMPLEFUNC("statistics", "Show database statistics", TableStats),
145     SIMPLEFUNC("clients", "Show active Moira clients", ShowClients),
146   }
147 };
148
149
150 Menu namespace_menu = {
151   NULLFUNC,
152   NULLFUNC,
153   "Campus Namespace Database Manipulation",
154   4,
155   {
156     SUBMENU("mail", "Mail Forwarding", &pobox_menu),
157     SUBMENU("list", "Mailing Lists", &list_menu),
158     {ShowUserByLogin, NULLMENU, 2, {
159        {"account", "Show user account information"},
160        {"login name", "Desired login name: "}
161      } },
162     SUBMENU("misc", "Miscellaneous", &misc_menu)
163   }
164 };
165
166
167 static void Signal_Handler(), CatchInterrupt();
168
169 static void ErrorExit(), Usage();
170 char *getlogin();
171 uid_t getuid();
172 struct passwd *getpwuid();
173
174 Bool use_menu = TRUE;           /* whether or not we are using a menu. */
175
176 /*      Function Name: main
177  *      Description: The main driver for the Moira Client.
178  *      Arguments: argc, argv - standard command line args.
179  *      Returns: doesn't return.
180  */
181
182 void main(int argc, char **argv)
183 {
184   int status;
185   Menu *menu;
186   char *motd, **arg;
187   char pname[ANAME_SZ];
188   struct sigaction act;
189
190   if (!(program_name = strrchr(argv[0], '/')))
191     program_name = argv[0];
192   else
193     program_name++;
194   program_name = Strsave(program_name);
195   whoami = Strsave(program_name); /* used by menu.c,  ugh !!! */
196
197   verbose = TRUE;
198   arg = argv;
199   moira_server = NULL;
200
201   while (++arg - argv < argc)
202     {
203       if (**arg == '-')
204         {
205           if (!strcmp(*arg, "-nomenu"))
206             use_menu = FALSE;
207           else if (!strcmp(*arg, "-db"))
208             if (arg - argv < argc - 1)
209               {
210                 ++arg;
211                 moira_server = *arg;
212               }
213             else
214               Usage(argv);
215           else
216             Usage(argv);
217         }
218     }
219
220   if ((status = mr_connect(moira_server)))
221     ErrorExit("\nConnection to Moira server failed", status);
222
223   /* do this now since calling mr_connect initialized the krb error table
224    * for us.
225    */
226   if ((status = tf_init(TKT_FILE, R_TKT_FIL)) ||
227       (status = tf_get_pname(pname)))
228     {
229       com_err(whoami, status, "cannot find your ticket file");
230       exit(1);
231     }
232   tf_close();
233   user = Strsave(pname);
234
235   if ((status = mr_motd(&motd)))
236     ErrorExit("\nUnable to check server status", status);
237   if (motd)
238     {
239       fprintf(stderr, "The Moira server is currently unavailable:\n%s\n",
240               motd);
241       mr_disconnect();
242       exit(1);
243     }
244
245   if ((status = mr_auth(program_name)))
246     {
247       if (status == MR_USER_AUTH)
248         {
249           char buf[BUFSIZ];
250           com_err(program_name, status, "\nPress [RETURN] to continue");
251           fgets(buf, BUFSIZ, stdin);
252         }
253       else
254         ErrorExit("\nAuthorization failed -- please run kinit", status);
255     }
256
257   /*
258    * These signals should not be set until just before we fire up the menu
259    * system.
260    */
261
262   sigemptyset(&act.sa_mask);
263   act.sa_flags = 0;
264   act.sa_handler = (void (*)()) Signal_Handler;
265   sigaction(SIGHUP, &act, NULL);
266   sigaction(SIGQUIT, &act, NULL);
267   if (use_menu)
268     sigaction(SIGINT, &act, NULL);
269   else
270     {
271       act.sa_handler = (void (*)()) CatchInterrupt;
272       sigaction(SIGINT, &act, NULL);
273     }
274
275   menu = &namespace_menu;
276
277   if (use_menu)         /* Start menus that execute program */
278     {
279       Start_paging();
280       Start_menu(menu);
281       Stop_paging();
282     }
283   else                  /* Start program without menus. */
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   if (use_menu)
326     Cleanup_menu();
327   mr_disconnect();
328   exit(1);
329 }
330
331
332 static void CatchInterrupt(void)
333 {
334   Put_message("Interrupt! Press RETURN to continue");
335   interrupt = 1;
336 }
337
338
339 /* Dummy routine to be able to link against the rest of the moira client */
340
341 int DeleteUser(void)
342 {
343   return DM_QUIT;
344 }
345
346
347 int NewListHelp(void)
348 {
349   static char *message[] = {
350     "A list can be a mailing list, an Athena group list, or both.  Each",
351     "list has an owner and members.  The owner of a list may be the list",
352     "itself, another list, or a user.  The members of a list can be users",
353     "(login names), other lists, or foreign address strings.  You can use",
354     "certain keys to do the following:",
355     "    Refresh the screen - Type ctrl-L.",
356     "    Escape from a function - Type ctrl-C.",
357     NULL,
358   };
359
360   return PrintHelp(message);
361 }
This page took 0.054775 seconds and 3 git commands to generate.