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