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