]> andersk Git - moira.git/blame - clients/moira/main.c
Change `SMS' to `Moira' where possible.
[moira.git] / clients / moira / main.c
CommitLineData
402461ad 1#if (!defined(lint) && !defined(SABER))
08345b74 2 static char rcsid_module_c[] = "$Header$";
7798ebc3 3#endif
08345b74 4
59ec8dae 5/* This is the file main.c for the Moira Client, which allows users
6 * to quickly and easily maintain most parts of the Moira database.
1931dc22 7 * It Contains: The main driver for the Moira Client.
5eaef520 8 *
08345b74 9 * Created: 4/12/88
10 * By: Chris D. Peterson
11 *
12 * $Source$
13 * $Author$
14 * $Header$
5eaef520 15 *
0a2c64cb 16 * Copyright 1988 by the Massachusetts Institute of Technology.
08345b74 17 *
5eaef520 18 * For further information on copyright and distribution
08345b74 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
5eaef520 36char *whoami; /* used by menu.c ugh!!! */
37char *moira_server;
facd6784 38int interrupt = 0;
85ca828a 39
8defc06b 40extern Menu moira_top_menu, list_menu, user_menu, dcm_menu;
85ca828a 41
7798ebc3 42static void Signal_Handler(), CatchInterrupt();
402461ad 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
5eaef520 57void main(int argc, char **argv)
08345b74 58{
5eaef520 59 int status;
60 Menu *menu;
61 char *motd, **arg;
62 struct sigaction act;
63
64 if (!(user = getlogin()))
65 user = getpwuid(getuid())->pw_name;
66 user = (user && strlen(user)) ? Strsave(user) : "";
67
68 if (!(program_name = strrchr(argv[0], '/')))
69 program_name = argv[0];
70 else
71 program_name++;
72 program_name = Strsave(program_name);
73 whoami = Strsave(program_name); /* used by menu.c, ugh !!! */
74
75 verbose = TRUE;
76 arg = argv;
77 moira_server = NULL;
78
79 while (++arg - argv < argc)
80 {
81 if (**arg == '-')
82 {
83 if (!strcmp(*arg, "-nomenu"))
84 use_menu = FALSE;
85 else if (!strcmp(*arg, "-menu"))
86 use_menu = TRUE;
87 else if (!strcmp(*arg, "-db"))
88 {
89 if (arg - argv < argc - 1)
90 {
576becad 91 ++arg;
1931dc22 92 moira_server = *arg;
5eaef520 93 } else
94 Usage(argv);
95 }
96 else
97 Usage(argv);
576becad 98 }
08345b74 99 }
85ca828a 100
5eaef520 101 if ((status = mr_connect(moira_server)))
102 ErrorExit("\nConnection to Moira server failed", status);
103
104 if ((status = mr_motd(&motd)))
105 ErrorExit("\nUnable to check server status", status);
106 if (motd)
107 {
108 fprintf(stderr, "The Moira server is currently unavailable:\n%s\n",
109 motd);
110 mr_disconnect();
111 exit(1);
262ca740 112 }
113
5eaef520 114 if ((status = mr_auth(program_name)))
115 {
116 if (status == MR_USER_AUTH)
117 {
118 char buf[BUFSIZ];
119 com_err(program_name, status, "\nPress [RETURN] to continue");
120 fgets(buf, BUFSIZ, stdin);
121 }
122 else
123 {
71ca689a 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
5eaef520 132 /*
133 * These signals should not be set until just before we fire up the menu
134 * system.
135 */
136
137 sigemptyset(&act.sa_mask);
138 act.sa_flags = 0;
139 act.sa_handler = (void (*)()) Signal_Handler;
140 sigaction(SIGHUP, &act, NULL);
141 sigaction(SIGQUIT, &act, NULL);
142 if (use_menu)
143 sigaction(SIGINT, &act, NULL);
144 else
145 {
146 act.sa_handler = (void (*)()) CatchInterrupt;
147 sigaction(SIGINT, &act, NULL);
f071d8a7 148 }
5eaef520 149
150 initialize_gdss_error_table();
151
152 if (!strcmp(program_name, "listmaint"))
153 menu = &list_menu;
154 else if (!strcmp(program_name, "usermaint"))
155 menu = &user_menu;
156 else if (!strcmp(program_name, "dcmmaint"))
157 menu = &dcm_menu;
158 else
159 menu = &moira_top_menu;
160
161 if (use_menu) /* Start menus that execute program */
162 {
163 Start_paging();
164 Start_menu(menu);
165 Stop_paging();
08345b74 166 }
5eaef520 167 else /* Start program without menus. */
168 Start_no_menu(menu);
08345b74 169
5eaef520 170 mr_disconnect();
171 exit(0);
08345b74 172}
173
461c03b6 174/* Function Name: ErrorExit
08345b74 175 * Description: This function does the error handling and exits.
176 * Arguments: buf - the error message to print.
177 * status - the error code.
178 * Returns: doesn't return.
179 */
180
5eaef520 181static void ErrorExit(char *buf, int status)
08345b74 182{
5eaef520 183 com_err(program_name, status, buf);
184 mr_disconnect();
185 exit(1);
08345b74 186}
187
188/* Function Name: usage
189 * Description: Prints usage info and then exits.
190 * Arguments: none
191 * Returns: doesn't return.
192 */
193
5eaef520 194static void Usage(void)
08345b74 195{
5eaef520 196 fprintf(stderr, "Usage: %s [-nomenu | -menu] [-db server[:port]]\n",
197 program_name);
198 exit(1);
08345b74 199}
200
7798ebc3 201/* Function Name: Signal_Handler
08345b74 202 * Description: This function cleans up from a signal interrupt.
203 * Arguments: none.
204 * Returns: doesn't
205 */
206
5eaef520 207static void Signal_Handler(void)
08345b74 208{
5eaef520 209 Put_message("Signal caught - exiting");
210 if (use_menu)
211 Cleanup_menu();
212 mr_disconnect();
213 exit(1);
08345b74 214}
facd6784 215
216
5eaef520 217static void CatchInterrupt(void)
facd6784 218{
5eaef520 219 Put_message("Interrupt! Press RETURN to continue");
220 interrupt = 1;
facd6784 221}
This page took 0.113023 seconds and 5 git commands to generate.