]> andersk Git - moira.git/blob - clients/moira/namespace.c
${CRYPT} in Imakefile
[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",
55                    "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
168 #ifndef DEBUG
169 static void Signal_Handler(), CatchInterrupt();
170 #endif
171
172 static void ErrorExit(), Usage();
173 char *getlogin();
174 uid_t getuid();
175 struct passwd *getpwuid();
176
177 Bool use_menu = TRUE;           /* whether or not we are using a menu. */
178
179 /*      Function Name: main
180  *      Description: The main driver for the Moira Client.
181  *      Arguments: argc, argv - standard command line args.
182  *      Returns: doesn't return.
183  */
184
185 void
186 main(argc, argv)
187     int argc;
188     char ** argv;
189 {
190     int status;
191     Menu *menu;
192     char *motd, **arg;
193     char pname[ANAME_SZ];
194 #ifdef POSIX
195     struct sigaction act;
196 #endif
197
198     if ((program_name = strrchr(argv[0], '/')) == NULL)
199       program_name = argv[0];
200     else
201       program_name++;
202     program_name = Strsave(program_name);
203     whoami = Strsave(program_name); /* used by menu.c,  ugh !!! */
204
205     verbose = TRUE;
206     arg = argv;
207     moira_server = NULL;
208
209     while (++arg - argv < argc) {
210         if (**arg == '-') {
211             if (!strcmp(*arg, "-nomenu"))
212               use_menu = FALSE;
213             else if (!strcmp(*arg, "-db"))
214               if (arg - argv < argc - 1) {
215                   ++arg;
216                   moira_server = *arg;
217               } else
218                 Usage(argv);
219             else
220               Usage(argv);
221         }
222     }
223
224     if ( status = mr_connect(moira_server) ) 
225         ErrorExit("\nConnection to Moira server failed", status);
226
227     /* do this now since calling mr_connect initialized the krb error table
228      * for us.
229      */
230     if ((status = tf_init(TKT_FILE, R_TKT_FIL)) ||
231         (status = tf_get_pname(pname))) {
232         com_err(whoami, status, "cannot find your ticket file");
233         exit(1);
234     }
235     tf_close();
236     user = Strsave(pname);
237
238     if ( status = mr_motd(&motd) )
239         ErrorExit("\nUnable to check server status", status);
240     if (motd) {
241         fprintf(stderr, "The Moira server is currently unavailable:\n%s\n", motd);
242         mr_disconnect();
243         exit(1);
244     }
245
246     if ( status = mr_auth(program_name) ) {
247         if (status == MR_USER_AUTH) {
248             char buf[BUFSIZ];
249             com_err(program_name, status, "\nPress [RETURN] to continue");
250             gets(buf);
251         } else
252           ErrorExit("\nAuthorization failed -- please run kinit", status);
253     }
254
255 /*
256  * These signals should not be set until just before we fire up the menu
257  * system. 
258  */
259
260 #ifndef DEBUG
261 #ifdef POSIX
262     sigemptyset(&act.sa_mask);
263     act.sa_flags = 0;
264     act.sa_handler= (void (*)()) Signal_Handler;
265     (void) sigaction(SIGHUP, &act, NULL);
266     (void) sigaction(SIGQUIT, &act, NULL);
267     if (use_menu)
268       (void) sigaction(SIGINT, &act, NULL); 
269     else {
270         act.sa_handler= (void (*)()) CatchInterrupt;
271         (void) sigaction(SIGINT, &act, NULL); 
272     }
273 #else
274     (void) signal(SIGHUP, Signal_Handler);
275     (void) signal(SIGQUIT, Signal_Handler);
276     if (use_menu)
277       (void) signal(SIGINT, Signal_Handler); 
278     else
279       (void) signal(SIGINT, CatchInterrupt); 
280 #endif /* POSIX */
281 #endif /* DEBUG */
282
283     menu = &namespace_menu;
284
285     if (use_menu) {             /* Start menus that execute program */
286         Start_paging();
287         Start_menu(menu);
288         Stop_paging();
289     }
290     else                        /* Start program without menus. */
291         Start_no_menu(menu);
292
293     mr_disconnect();
294     exit(0);
295 }
296
297 /*      Function Name: ErrorExit
298  *      Description: This function does the error handling and exits.
299  *      Arguments: buf - the error message to print.
300  *                 status - the error code.
301  *      Returns: doesn't return.
302  */
303
304 static void
305 ErrorExit(buf,status)
306 int status;
307 char * buf;    
308 {
309     com_err(program_name, status, buf);
310     mr_disconnect();
311     exit(1);
312 }
313
314 /*      Function Name: usage
315  *      Description: Prints usage info and then exits.
316  *      Arguments: none
317  *      Returns: doesn't return.
318  */
319
320 static void
321 Usage()
322 {
323     fprintf(stderr, "Usage: %s [-nomenu]\n", program_name);
324     exit(1);
325 }
326
327 #ifndef DEBUG
328 /*      Function Name: Signal_Handler
329  *      Description: This function cleans up from a signal interrupt.
330  *      Arguments: none.
331  *      Returns: doesn't
332  */
333
334 static void
335 Signal_Handler()
336 {
337     Put_message("Signal caught - exiting");
338     if (use_menu)
339       Cleanup_menu();
340     mr_disconnect();
341     exit(1);
342 }
343
344
345 static void
346 CatchInterrupt()
347 {
348     Put_message("Interrupt! Press RETURN to continue");
349     interrupt = 1;
350 }
351 #endif
352
353
354 /* Dummy routine to be able to link against the rest of the moira client */
355
356 DeleteUser()
357 {
358     return(DM_QUIT);
359 }
360
361
362 int
363 NewListHelp()
364 {
365     static char * message[] = {
366         "A list can be a mailing list, an Athena group list, or both.  Each",
367         "list has an owner and members.  The owner of a list may be the list",
368         "itself, another list, or a user.  The members of a list can be users",
369         "(login names), other lists, or foreign address strings.  You can use",
370         "certain keys to do the following:",
371         "    Refresh the screen - Type ctrl-L.",
372         "    Escape from a function - Type ctrl-C.",
373         NULL,
374     };
375
376     return(PrintHelp(message));
377 }
This page took 0.071934 seconds and 5 git commands to generate.