]> andersk Git - moira.git/blob - clients/moira/main.c
init gdss et
[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 <strings.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
72     if ((user = getlogin()) == NULL) 
73         user = getpwuid((int) getuid())->pw_name;
74     user = (user && strlen(user)) ? Strsave(user) : "";
75
76     if ((program_name = rindex(argv[0], '/')) == NULL)
77       program_name = argv[0];
78     else
79       program_name++;
80     program_name = Strsave(program_name);
81     whoami = Strsave(program_name); /* used by menu.c,  ugh !!! */
82
83     verbose = TRUE;
84     arg = argv;
85     moira_server = NULL;
86
87     while (++arg - argv < argc) {
88         if (**arg == '-') {
89             if (!strcmp(*arg, "-nomenu"))
90               use_menu = FALSE;
91             else if (!strcmp(*arg, "-db"))
92               if (arg - argv < argc - 1) {
93                   ++arg;
94                   moira_server = *arg;
95               } else
96                 Usage(argv);
97             else
98               Usage(argv);
99         }
100     }
101
102     if ( status = mr_connect(moira_server) ) 
103         ErrorExit("\nConnection to Moira server failed", status);
104
105     if ( status = mr_motd(&motd) )
106         ErrorExit("\nUnable to check server status", status);
107     if (motd) {
108         fprintf(stderr, "The Moira server is currently unavailable:\n%s\n", motd);
109         mr_disconnect();
110         exit(1);
111     }
112
113     if ( status = mr_auth(program_name) ) {
114         if (status == MR_USER_AUTH) {
115             char buf[BUFSIZ];
116             com_err(program_name, status, "\nPress [RETURN] to continue");
117             gets(buf);
118         } else {
119           if (status >= ERROR_TABLE_BASE_krb &&
120               status <= ERROR_TABLE_BASE_krb + 256)
121             ErrorExit("\nAuthorization failed -- please run kinit", status);
122           else
123             ErrorExit("\nAuthorization failed.", status);
124         }
125     }
126
127 /*
128  * These signals should not be set until just before we fire up the menu
129  * system. 
130  */
131
132 #ifndef DEBUG
133     (void) signal(SIGHUP, SignalHandler);
134     (void) signal(SIGQUIT, SignalHandler);
135     if (use_menu)
136       (void) signal(SIGINT, SignalHandler); 
137     else
138       (void) signal(SIGINT, CatchInterrupt); 
139 #endif DEBUG
140
141     initialize_gdss_error_table();
142
143     if (!strcmp(program_name, "listmaint"))
144       menu = &list_menu;
145     else if (!strcmp(program_name, "usermaint"))
146       menu = &user_menu;
147     else if (!strcmp(program_name, "dcmmaint"))
148       menu = &dcm_menu;
149     else
150       menu = &moira_top_menu;
151
152     if (use_menu) {             /* Start menus that execute program */
153         Start_paging();
154         Start_menu(menu);
155         Stop_paging();
156     }
157     else                        /* Start program without menus. */
158         Start_no_menu(menu);
159
160     mr_disconnect();
161     exit(0);
162 }
163
164 /*      Function Name: ErrorExit
165  *      Description: This function does the error handling and exits.
166  *      Arguments: buf - the error message to print.
167  *                 status - the error code.
168  *      Returns: doesn't return.
169  */
170
171 static void
172 ErrorExit(buf,status)
173 int status;
174 char * buf;    
175 {
176     com_err(program_name, status, buf);
177     mr_disconnect();
178     exit(1);
179 }
180
181 /*      Function Name: usage
182  *      Description: Prints usage info and then exits.
183  *      Arguments: none
184  *      Returns: doesn't return.
185  */
186
187 static void
188 Usage()
189 {
190     fprintf(stderr, "Usage: %s [-nomenu]\n", program_name);
191     exit(1);
192 }
193
194 #ifndef DEBUG
195 /*      Function Name: SignalHandler
196  *      Description: This function cleans up from a signal interrupt.
197  *      Arguments: none.
198  *      Returns: doesn't
199  */
200
201 static void
202 SignalHandler()
203 {
204     Put_message("Signal caught - exiting");
205     if (use_menu)
206       Cleanup_menu();
207     mr_disconnect();
208     exit(1);
209 }
210
211
212 static void
213 CatchInterrupt()
214 {
215     Put_message("Interrupt! Press RETURN to continue");
216     interrupt = 1;
217 }
218 #endif DEBUG
This page took 0.120007 seconds and 5 git commands to generate.