]> andersk Git - moira.git/blame - clients/moira/main.c
changed word "SMS" to "Moira"
[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>
25#include <strings.h>
461c03b6 26#include <sys/types.h>
08345b74 27#include <sms.h>
28#include <menu.h>
29
30#include "mit-copyright.h"
0a2c64cb 31#include "defs.h"
32#include "f_defs.h"
08345b74 33#include "globals.h"
34
85ca828a 35char * whoami; /* used by menu.c ugh!!! */
1931dc22 36char * moira_server;
85ca828a 37
bc628e37 38extern Menu sms_top_menu, list_menu, user_menu, dcm_menu;
85ca828a 39
402461ad 40#ifndef DEBUG
41static void SignalHandler();
42#endif DEBUG
43
44static void ErrorExit(), Usage();
08345b74 45char *getlogin();
46uid_t getuid();
47struct passwd *getpwuid();
48
49Bool use_menu = TRUE; /* whether or not we are using a menu. */
50
51/* Function Name: main
1931dc22 52 * Description: The main driver for the Moira Client.
08345b74 53 * Arguments: argc, argv - standard command line args.
54 * Returns: doesn't return.
55 */
56
57void
58main(argc, argv)
59 int argc;
60 char ** argv;
61{
461c03b6 62 int status;
ace1dd7b 63 Menu *menu;
1931dc22 64 char *motd, **arg;
08345b74 65
66 if ((user = getlogin()) == NULL)
67 user = getpwuid((int) getuid())->pw_name;
68 user = (user && strlen(user)) ? Strsave(user) : "";
69
e774e94c 70 if ((program_name = rindex(argv[0], '/')) == NULL)
71 program_name = argv[0];
72 else
73 program_name++;
c2be255c 74 program_name = Strsave(program_name);
75 whoami = Strsave(program_name); /* used by menu.c, ugh !!! */
76
461c03b6 77 verbose = TRUE;
576becad 78 arg = argv;
1931dc22 79 moira_server = SMS_SERVER;
576becad 80
81 while (++arg - argv < argc) {
82 if (**arg == '-') {
83 if (!strcmp(*arg, "-nomenu"))
84 use_menu = FALSE;
85 else if (!strcmp(*arg, "-db"))
86 if (arg - argv < argc - 1) {
87 ++arg;
1931dc22 88 moira_server = *arg;
576becad 89 } else
90 Usage(argv);
91 else
92 Usage(argv);
93 }
08345b74 94 }
85ca828a 95
1931dc22 96 if ( status = sms_connect(moira_server) )
97 ErrorExit("\nConnection to Moira server failed", status);
08345b74 98
262ca740 99 if ( status = sms_motd(&motd) )
100 ErrorExit("\nUnable to check server status", status);
101 if (motd) {
1931dc22 102 fprintf(stderr, "The Moira server is currently unavailable:\n%s\n", motd);
262ca740 103 sms_disconnect();
104 exit(1);
105 }
106
1931dc22 107 if ( status = sms_auth(program_name) ) {
108 if (status == SMS_USER_AUTH) {
109 char buf[BUFSIZ];
110 com_err(program_name, status, "\nPress [RETURN] to continue");
111 gets(buf);
112 } else
113 ErrorExit("\nAuthorization failed -- please run kinit", status);
114 }
08345b74 115
116/*
117 * These signals should not be set until just before we fire up the menu
118 * system.
119 */
85ca828a 120
121#ifndef DEBUG
461c03b6 122 (void) signal(SIGHUP, SignalHandler);
85ca828a 123 (void) signal(SIGINT, SignalHandler);
461c03b6 124 (void) signal(SIGQUIT, SignalHandler);
85ca828a 125#endif DEBUG
08345b74 126
ace1dd7b 127 if (!strcmp(program_name, "listmaint"))
128 menu = &list_menu;
129 else if (!strcmp(program_name, "usermaint"))
130 menu = &user_menu;
bc628e37 131 else if (!strcmp(program_name, "dcmmaint"))
132 menu = &dcm_menu;
ace1dd7b 133 else
134 menu = &sms_top_menu;
135
08345b74 136 if (use_menu) { /* Start menus that execute program */
137 Start_paging();
ace1dd7b 138 Start_menu(menu);
08345b74 139 Stop_paging();
140 }
141 else /* Start program without menus. */
ace1dd7b 142 Start_no_menu(menu);
08345b74 143
144 sms_disconnect();
145 exit(0);
146}
147
461c03b6 148/* Function Name: ErrorExit
08345b74 149 * Description: This function does the error handling and exits.
150 * Arguments: buf - the error message to print.
151 * status - the error code.
152 * Returns: doesn't return.
153 */
154
155static void
461c03b6 156ErrorExit(buf,status)
08345b74 157int status;
461c03b6 158char * buf;
08345b74 159{
160 com_err(program_name, status, buf);
161 sms_disconnect();
162 exit(1);
163}
164
165/* Function Name: usage
166 * Description: Prints usage info and then exits.
167 * Arguments: none
168 * Returns: doesn't return.
169 */
170
171static void
461c03b6 172Usage()
08345b74 173{
174 fprintf(stderr, "Usage: %s [-nomenu]\n", program_name);
175 exit(1);
176}
177
402461ad 178#ifndef DEBUG
461c03b6 179/* Function Name: SignalHandler
08345b74 180 * Description: This function cleans up from a signal interrupt.
181 * Arguments: none.
182 * Returns: doesn't
183 */
184
85ca828a 185static void
461c03b6 186SignalHandler()
08345b74 187{
188 Put_message("Signal caught - exiting");
189 if (use_menu)
190 Cleanup_menu();
191 sms_disconnect();
192 exit(1);
193}
402461ad 194#endif DEBUG
This page took 0.092031 seconds and 5 git commands to generate.