]> andersk Git - moira.git/blob - clients/moira/main.c
Changed so AIX uses -nomenu option by default, since the curses version
[moira.git] / clients / moira / main.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 <string.h>
26 #include <sys/types.h>
27 #include <moira.h>
28 #include <menu.h>
29 #include <krb_et.h>
30
31 #include "mit-copyright.h"
32 #include "defs.h"
33 #include "f_defs.h"
34 #include "globals.h"
35
36 char * whoami;                  /* used by menu.c ugh!!! */
37 char * moira_server;
38 int interrupt = 0;
39
40 extern Menu moira_top_menu, list_menu, user_menu, dcm_menu;
41
42 #ifndef DEBUG
43 static void SignalHandler(), CatchInterrupt();
44 #endif DEBUG
45
46 static void ErrorExit(), Usage();
47 char *getlogin();
48 uid_t getuid();
49 struct passwd *getpwuid();
50
51 #ifdef _AIX
52 Bool use_menu = FALSE;          /* whether or not we are using a menu. */
53 #else
54 Bool use_menu = TRUE;           /* whether or not we are using a menu. */
55 #endif
56
57 /*      Function Name: main
58  *      Description: The main driver for the Moira Client.
59  *      Arguments: argc, argv - standard command line args.
60  *      Returns: doesn't return.
61  */
62
63 void
64 main(argc, argv)
65     int argc;
66     char ** argv;
67 {
68     int status;
69     Menu *menu;
70     char *motd, **arg;
71 #ifdef POSIX
72     struct sigaction act;
73 #endif
74
75     if ((user = getlogin()) == NULL) 
76         user = getpwuid((int) getuid())->pw_name;
77     user = (user && strlen(user)) ? Strsave(user) : "";
78
79     if ((program_name = strrchr(argv[0], '/')) == NULL)
80       program_name = argv[0];
81     else
82       program_name++;
83     program_name = Strsave(program_name);
84     whoami = Strsave(program_name); /* used by menu.c,  ugh !!! */
85
86     verbose = TRUE;
87     arg = argv;
88     moira_server = NULL;
89
90     while (++arg - argv < argc) {
91         if (**arg == '-') {
92             if (!strcmp(*arg, "-nomenu"))
93               use_menu = FALSE;
94             else if (!strcmp(*arg, "-menu"))
95               use_menu = TRUE;
96             else if (!strcmp(*arg, "-db"))
97               if (arg - argv < argc - 1) {
98                   ++arg;
99                   moira_server = *arg;
100               } else
101                 Usage(argv);
102             else
103               Usage(argv);
104         }
105     }
106
107     if ( status = mr_connect(moira_server) ) 
108         ErrorExit("\nConnection to Moira server failed", status);
109
110     if ( status = mr_motd(&motd) )
111         ErrorExit("\nUnable to check server status", status);
112     if (motd) {
113         fprintf(stderr, "The Moira server is currently unavailable:\n%s\n", motd);
114         mr_disconnect();
115         exit(1);
116     }
117
118     if ( status = mr_auth(program_name) ) {
119         if (status == MR_USER_AUTH) {
120             char buf[BUFSIZ];
121             com_err(program_name, status, "\nPress [RETURN] to continue");
122             gets(buf);
123         } else {
124           if (status >= ERROR_TABLE_BASE_krb &&
125               status <= ERROR_TABLE_BASE_krb + 256)
126             ErrorExit("\nAuthorization failed -- please run kinit", status);
127           else
128             ErrorExit("\nAuthorization failed.", status);
129         }
130     }
131
132 /*
133  * These signals should not be set until just before we fire up the menu
134  * system. 
135  */
136
137 #ifndef DEBUG
138 #ifdef POSIX
139     sigemptyset(&act.sa_mask);
140     act.sa_flags = 0;
141     act.sa_handler= (void (*)()) SignalHandler;
142     (void) sigaction(SIGHUP, &act, NULL);
143     (void) sigaction(SIGQUIT, &act, NULL);
144     if (use_menu)
145       (void) sigaction(SIGINT, &act, NULL); 
146     else {
147         act.sa_handler= (void (*)()) CatchInterrupt;
148         (void) sigaction(SIGINT, &act, NULL); 
149     }
150 #else
151     (void) signal(SIGHUP, SignalHandler);
152     (void) signal(SIGQUIT, SignalHandler);
153     if (use_menu)
154       (void) signal(SIGINT, SignalHandler); 
155     else
156       (void) signal(SIGINT, CatchInterrupt); 
157 #endif /* POSIX */
158 #endif /* DEBUG */
159
160     initialize_gdss_error_table();
161
162     if (!strcmp(program_name, "listmaint"))
163       menu = &list_menu;
164     else if (!strcmp(program_name, "usermaint"))
165       menu = &user_menu;
166     else if (!strcmp(program_name, "dcmmaint"))
167       menu = &dcm_menu;
168     else
169       menu = &moira_top_menu;
170
171     if (use_menu) {             /* Start menus that execute program */
172         Start_paging();
173         Start_menu(menu);
174         Stop_paging();
175     }
176     else                        /* Start program without menus. */
177         Start_no_menu(menu);
178
179     mr_disconnect();
180     exit(0);
181 }
182
183 /*      Function Name: ErrorExit
184  *      Description: This function does the error handling and exits.
185  *      Arguments: buf - the error message to print.
186  *                 status - the error code.
187  *      Returns: doesn't return.
188  */
189
190 static void
191 ErrorExit(buf,status)
192 int status;
193 char * buf;    
194 {
195     com_err(program_name, status, buf);
196     mr_disconnect();
197     exit(1);
198 }
199
200 /*      Function Name: usage
201  *      Description: Prints usage info and then exits.
202  *      Arguments: none
203  *      Returns: doesn't return.
204  */
205
206 static void
207 Usage()
208 {
209     fprintf(stderr, "Usage: %s [-nomenu | -menu] [-db server[:port]]\n", program_name);
210     exit(1);
211 }
212
213 #ifndef DEBUG
214 /*      Function Name: SignalHandler
215  *      Description: This function cleans up from a signal interrupt.
216  *      Arguments: none.
217  *      Returns: doesn't
218  */
219
220 static void
221 SignalHandler()
222 {
223     Put_message("Signal caught - exiting");
224     if (use_menu)
225       Cleanup_menu();
226     mr_disconnect();
227     exit(1);
228 }
229
230
231 static void
232 CatchInterrupt()
233 {
234     Put_message("Interrupt! Press RETURN to continue");
235     interrupt = 1;
236 }
237 #endif DEBUG
This page took 0.062651 seconds and 5 git commands to generate.