]> andersk Git - moira.git/blob - clients/moira/namespace.c
reorder fields in filsys forms
[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     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 SignalHandler(), CatchInterrupt();
170 #endif DEBUG
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
195     if ((program_name = rindex(argv[0], '/')) == NULL)
196       program_name = argv[0];
197     else
198       program_name++;
199     program_name = Strsave(program_name);
200     whoami = Strsave(program_name); /* used by menu.c,  ugh !!! */
201
202     verbose = TRUE;
203     arg = argv;
204     moira_server = NULL;
205
206     while (++arg - argv < argc) {
207         if (**arg == '-') {
208             if (!strcmp(*arg, "-nomenu"))
209               use_menu = FALSE;
210             else if (!strcmp(*arg, "-db"))
211               if (arg - argv < argc - 1) {
212                   ++arg;
213                   moira_server = *arg;
214               } else
215                 Usage(argv);
216             else
217               Usage(argv);
218         }
219     }
220
221     if ( status = mr_connect(moira_server) ) 
222         ErrorExit("\nConnection to Moira server failed", status);
223
224     /* do this now since calling mr_connect initialized the krb error table
225      * for us.
226      */
227     if ((status = tf_init(TKT_FILE, R_TKT_FIL)) ||
228         (status = tf_get_pname(pname))) {
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         fprintf(stderr, "The Moira server is currently unavailable:\n%s\n", motd);
239         mr_disconnect();
240         exit(1);
241     }
242
243     if ( status = mr_auth(program_name) ) {
244         if (status == MR_USER_AUTH) {
245             char buf[BUFSIZ];
246             com_err(program_name, status, "\nPress [RETURN] to continue");
247             gets(buf);
248         } else
249           ErrorExit("\nAuthorization failed -- please run kinit", status);
250     }
251
252 /*
253  * These signals should not be set until just before we fire up the menu
254  * system. 
255  */
256
257 #ifndef DEBUG
258     (void) signal(SIGHUP, SignalHandler);
259     (void) signal(SIGQUIT, SignalHandler);
260     if (use_menu)
261       (void) signal(SIGINT, SignalHandler); 
262     else
263       (void) signal(SIGINT, CatchInterrupt); 
264 #endif DEBUG
265
266     menu = &namespace_menu;
267
268     if (use_menu) {             /* Start menus that execute program */
269         Start_paging();
270         Start_menu(menu);
271         Stop_paging();
272     }
273     else                        /* Start program without menus. */
274         Start_no_menu(menu);
275
276     mr_disconnect();
277     exit(0);
278 }
279
280 /*      Function Name: ErrorExit
281  *      Description: This function does the error handling and exits.
282  *      Arguments: buf - the error message to print.
283  *                 status - the error code.
284  *      Returns: doesn't return.
285  */
286
287 static void
288 ErrorExit(buf,status)
289 int status;
290 char * buf;    
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
304 Usage()
305 {
306     fprintf(stderr, "Usage: %s [-nomenu]\n", program_name);
307     exit(1);
308 }
309
310 #ifndef DEBUG
311 /*      Function Name: SignalHandler
312  *      Description: This function cleans up from a signal interrupt.
313  *      Arguments: none.
314  *      Returns: doesn't
315  */
316
317 static void
318 SignalHandler()
319 {
320     Put_message("Signal caught - exiting");
321     if (use_menu)
322       Cleanup_menu();
323     mr_disconnect();
324     exit(1);
325 }
326
327
328 static void
329 CatchInterrupt()
330 {
331     Put_message("Interrupt! Press RETURN to continue");
332     interrupt = 1;
333 }
334 #endif DEBUG
335
336
337 /* Dummy routine to be able to link against the rest of the moira client */
338
339 DeleteUser()
340 {
341     return(DM_QUIT);
342 };
343
344
345 int
346 NewListHelp()
347 {
348     static char * message[] = {
349         "A list can be a mailing list, an Athena group list, or both.  Each",
350         "list has an owner and members.  The owner of a list may be the list",
351         "itself, another list, or a user.  The members of a list can be users",
352         "(login names), other lists, or foreign address strings.  You can use",
353         "certain keys to do the following:",
354         "    Refresh the screen - Type ctrl-L.",
355         "    Escape from a function - Type ctrl-C.",
356         NULL,
357     };
358
359     return(PrintHelp(message));
360 }
This page took 0.065982 seconds and 5 git commands to generate.