]> andersk Git - moira.git/blame - clients/moira/main.c
Changed so AIX uses -nomenu option by default, since the curses version
[moira.git] / clients / moira / main.c
CommitLineData
402461ad 1#if (!defined(lint) && !defined(SABER))
08345b74 2 static char rcsid_module_c[] = "$Header$";
3#endif lint
4
1931dc22 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.
08345b74 8 *
9 * Created: 4/12/88
10 * By: Chris D. Peterson
11 *
12 * $Source$
13 * $Author$
14 * $Header$
15 *
0a2c64cb 16 * Copyright 1988 by the Massachusetts Institute of Technology.
08345b74 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>
f071d8a7 25#include <string.h>
461c03b6 26#include <sys/types.h>
8defc06b 27#include <moira.h>
08345b74 28#include <menu.h>
71ca689a 29#include <krb_et.h>
08345b74 30
31#include "mit-copyright.h"
0a2c64cb 32#include "defs.h"
33#include "f_defs.h"
08345b74 34#include "globals.h"
35
85ca828a 36char * whoami; /* used by menu.c ugh!!! */
1931dc22 37char * moira_server;
facd6784 38int interrupt = 0;
85ca828a 39
8defc06b 40extern Menu moira_top_menu, list_menu, user_menu, dcm_menu;
85ca828a 41
402461ad 42#ifndef DEBUG
facd6784 43static void SignalHandler(), CatchInterrupt();
402461ad 44#endif DEBUG
45
46static void ErrorExit(), Usage();
08345b74 47char *getlogin();
48uid_t getuid();
49struct passwd *getpwuid();
50
bef0f44e 51#ifdef _AIX
52Bool use_menu = FALSE; /* whether or not we are using a menu. */
53#else
08345b74 54Bool use_menu = TRUE; /* whether or not we are using a menu. */
bef0f44e 55#endif
08345b74 56
57/* Function Name: main
1931dc22 58 * Description: The main driver for the Moira Client.
08345b74 59 * Arguments: argc, argv - standard command line args.
60 * Returns: doesn't return.
61 */
62
63void
64main(argc, argv)
65 int argc;
66 char ** argv;
67{
461c03b6 68 int status;
ace1dd7b 69 Menu *menu;
1931dc22 70 char *motd, **arg;
f071d8a7 71#ifdef POSIX
72 struct sigaction act;
73#endif
08345b74 74
75 if ((user = getlogin()) == NULL)
76 user = getpwuid((int) getuid())->pw_name;
77 user = (user && strlen(user)) ? Strsave(user) : "";
78
f071d8a7 79 if ((program_name = strrchr(argv[0], '/')) == NULL)
e774e94c 80 program_name = argv[0];
81 else
82 program_name++;
c2be255c 83 program_name = Strsave(program_name);
84 whoami = Strsave(program_name); /* used by menu.c, ugh !!! */
85
461c03b6 86 verbose = TRUE;
576becad 87 arg = argv;
75f991c8 88 moira_server = NULL;
576becad 89
90 while (++arg - argv < argc) {
91 if (**arg == '-') {
92 if (!strcmp(*arg, "-nomenu"))
93 use_menu = FALSE;
bef0f44e 94 else if (!strcmp(*arg, "-menu"))
95 use_menu = TRUE;
576becad 96 else if (!strcmp(*arg, "-db"))
97 if (arg - argv < argc - 1) {
98 ++arg;
1931dc22 99 moira_server = *arg;
576becad 100 } else
101 Usage(argv);
102 else
103 Usage(argv);
104 }
08345b74 105 }
85ca828a 106
8defc06b 107 if ( status = mr_connect(moira_server) )
1931dc22 108 ErrorExit("\nConnection to Moira server failed", status);
08345b74 109
8defc06b 110 if ( status = mr_motd(&motd) )
262ca740 111 ErrorExit("\nUnable to check server status", status);
112 if (motd) {
1931dc22 113 fprintf(stderr, "The Moira server is currently unavailable:\n%s\n", motd);
8defc06b 114 mr_disconnect();
262ca740 115 exit(1);
116 }
117
8defc06b 118 if ( status = mr_auth(program_name) ) {
119 if (status == MR_USER_AUTH) {
1931dc22 120 char buf[BUFSIZ];
121 com_err(program_name, status, "\nPress [RETURN] to continue");
122 gets(buf);
71ca689a 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 }
1931dc22 130 }
08345b74 131
132/*
133 * These signals should not be set until just before we fire up the menu
134 * system.
135 */
85ca828a 136
137#ifndef DEBUG
f071d8a7 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
461c03b6 151 (void) signal(SIGHUP, SignalHandler);
461c03b6 152 (void) signal(SIGQUIT, SignalHandler);
facd6784 153 if (use_menu)
154 (void) signal(SIGINT, SignalHandler);
155 else
156 (void) signal(SIGINT, CatchInterrupt);
f071d8a7 157#endif /* POSIX */
158#endif /* DEBUG */
08345b74 159
e9ed68d9 160 initialize_gdss_error_table();
161
ace1dd7b 162 if (!strcmp(program_name, "listmaint"))
163 menu = &list_menu;
164 else if (!strcmp(program_name, "usermaint"))
165 menu = &user_menu;
bc628e37 166 else if (!strcmp(program_name, "dcmmaint"))
167 menu = &dcm_menu;
ace1dd7b 168 else
8defc06b 169 menu = &moira_top_menu;
ace1dd7b 170
08345b74 171 if (use_menu) { /* Start menus that execute program */
172 Start_paging();
ace1dd7b 173 Start_menu(menu);
08345b74 174 Stop_paging();
175 }
176 else /* Start program without menus. */
ace1dd7b 177 Start_no_menu(menu);
08345b74 178
8defc06b 179 mr_disconnect();
08345b74 180 exit(0);
181}
182
461c03b6 183/* Function Name: ErrorExit
08345b74 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
190static void
461c03b6 191ErrorExit(buf,status)
08345b74 192int status;
461c03b6 193char * buf;
08345b74 194{
195 com_err(program_name, status, buf);
8defc06b 196 mr_disconnect();
08345b74 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
206static void
461c03b6 207Usage()
08345b74 208{
bef0f44e 209 fprintf(stderr, "Usage: %s [-nomenu | -menu] [-db server[:port]]\n", program_name);
08345b74 210 exit(1);
211}
212
402461ad 213#ifndef DEBUG
461c03b6 214/* Function Name: SignalHandler
08345b74 215 * Description: This function cleans up from a signal interrupt.
216 * Arguments: none.
217 * Returns: doesn't
218 */
219
85ca828a 220static void
461c03b6 221SignalHandler()
08345b74 222{
223 Put_message("Signal caught - exiting");
224 if (use_menu)
225 Cleanup_menu();
8defc06b 226 mr_disconnect();
08345b74 227 exit(1);
228}
facd6784 229
230
231static void
232CatchInterrupt()
233{
234 Put_message("Interrupt! Press RETURN to continue");
235 interrupt = 1;
236}
402461ad 237#endif DEBUG
This page took 0.121612 seconds and 5 git commands to generate.