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