]>
Commit | Line | Data |
---|---|---|
402461ad | 1 | #if (!defined(lint) && !defined(SABER)) |
08345b74 | 2 | static char rcsid_module_c[] = "$Header$"; |
3 | #endif lint | |
4 | ||
0a2c64cb | 5 | /* This is the file main.c for the SMS Client, which allows a nieve |
6 | * user to quickly and easily maintain most parts of the SMS database. | |
7 | * It Contains: The main driver for the SMS 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 | 35 | char * whoami; /* used by menu.c ugh!!! */ |
36 | ||
37 | extern Menu sms_top_menu; | |
38 | ||
402461ad | 39 | #ifndef DEBUG |
40 | static void SignalHandler(); | |
41 | #endif DEBUG | |
42 | ||
43 | static void ErrorExit(), Usage(); | |
08345b74 | 44 | char *getlogin(); |
45 | uid_t getuid(); | |
46 | struct passwd *getpwuid(); | |
47 | ||
48 | Bool use_menu = TRUE; /* whether or not we are using a menu. */ | |
49 | ||
50 | /* Function Name: main | |
51 | * Description: The main driver for allmaint. | |
52 | * Arguments: argc, argv - standard command line args. | |
53 | * Returns: doesn't return. | |
54 | */ | |
55 | ||
56 | void | |
57 | main(argc, argv) | |
58 | int argc; | |
59 | char ** argv; | |
60 | { | |
461c03b6 | 61 | int status; |
08345b74 | 62 | |
63 | if ((user = getlogin()) == NULL) | |
64 | user = getpwuid((int) getuid())->pw_name; | |
65 | user = (user && strlen(user)) ? Strsave(user) : ""; | |
66 | ||
67 | init_sms_err_tbl(); | |
68 | init_krb_err_tbl(); | |
461c03b6 | 69 | verbose = TRUE; |
08345b74 | 70 | |
71 | switch (argc) { | |
72 | case 2: | |
73 | if (strcmp(argv[1], "-nomenu") == 0) | |
74 | use_menu = FALSE; | |
461c03b6 | 75 | else |
76 | Usage(); | |
08345b74 | 77 | /* Fall Through. */ |
78 | case 1: | |
79 | if ((program_name = rindex(argv[0], '/')) == NULL) | |
80 | program_name = argv[0]; | |
81 | else | |
82 | program_name++; | |
83 | break; | |
84 | default: | |
461c03b6 | 85 | Usage(); |
08345b74 | 86 | break; |
87 | } | |
85ca828a | 88 | |
89 | program_name = Strsave(program_name); | |
90 | whoami = Strsave(program_name); /* used by menu.c, ugh !!! */ | |
91 | ||
08345b74 | 92 | if ( status = sms_connect() ) |
461c03b6 | 93 | ErrorExit("\nConnection to SMS server failed", status); |
08345b74 | 94 | |
461c03b6 | 95 | if ( status = sms_auth(program_name) ) |
96 | ErrorExit("\nAuthorization failed -- please run kinit", status); | |
08345b74 | 97 | |
98 | /* | |
99 | * These signals should not be set until just before we fire up the menu | |
100 | * system. | |
101 | */ | |
85ca828a | 102 | |
103 | #ifndef DEBUG | |
461c03b6 | 104 | (void) signal(SIGHUP, SignalHandler); |
85ca828a | 105 | (void) signal(SIGINT, SignalHandler); |
461c03b6 | 106 | (void) signal(SIGQUIT, SignalHandler); |
85ca828a | 107 | #endif DEBUG |
08345b74 | 108 | |
109 | if (use_menu) { /* Start menus that execute program */ | |
110 | Start_paging(); | |
85ca828a | 111 | Start_menu(&sms_top_menu); |
08345b74 | 112 | Stop_paging(); |
113 | } | |
114 | else /* Start program without menus. */ | |
85ca828a | 115 | Start_no_menu(&sms_top_menu); |
08345b74 | 116 | |
117 | sms_disconnect(); | |
118 | exit(0); | |
119 | } | |
120 | ||
461c03b6 | 121 | /* Function Name: ErrorExit |
08345b74 | 122 | * Description: This function does the error handling and exits. |
123 | * Arguments: buf - the error message to print. | |
124 | * status - the error code. | |
125 | * Returns: doesn't return. | |
126 | */ | |
127 | ||
128 | static void | |
461c03b6 | 129 | ErrorExit(buf,status) |
08345b74 | 130 | int status; |
461c03b6 | 131 | char * buf; |
08345b74 | 132 | { |
133 | com_err(program_name, status, buf); | |
134 | sms_disconnect(); | |
135 | exit(1); | |
136 | } | |
137 | ||
138 | /* Function Name: usage | |
139 | * Description: Prints usage info and then exits. | |
140 | * Arguments: none | |
141 | * Returns: doesn't return. | |
142 | */ | |
143 | ||
144 | static void | |
461c03b6 | 145 | Usage() |
08345b74 | 146 | { |
147 | fprintf(stderr, "Usage: %s [-nomenu]\n", program_name); | |
148 | exit(1); | |
149 | } | |
150 | ||
402461ad | 151 | #ifndef DEBUG |
461c03b6 | 152 | /* Function Name: SignalHandler |
08345b74 | 153 | * Description: This function cleans up from a signal interrupt. |
154 | * Arguments: none. | |
155 | * Returns: doesn't | |
156 | */ | |
157 | ||
85ca828a | 158 | static void |
461c03b6 | 159 | SignalHandler() |
08345b74 | 160 | { |
161 | Put_message("Signal caught - exiting"); | |
162 | if (use_menu) | |
163 | Cleanup_menu(); | |
164 | sms_disconnect(); | |
165 | exit(1); | |
166 | } | |
402461ad | 167 | #endif DEBUG |