]>
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 | ||
ace1dd7b | 37 | extern Menu sms_top_menu, list_menu, user_menu; |
85ca828a | 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 | |
219bbe64 | 51 | * Description: The main driver for the SMS Client. |
08345b74 | 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; |
ace1dd7b | 62 | Menu *menu; |
08345b74 | 63 | |
64 | if ((user = getlogin()) == NULL) | |
65 | user = getpwuid((int) getuid())->pw_name; | |
66 | user = (user && strlen(user)) ? Strsave(user) : ""; | |
67 | ||
68 | init_sms_err_tbl(); | |
69 | init_krb_err_tbl(); | |
461c03b6 | 70 | verbose = TRUE; |
08345b74 | 71 | |
72 | switch (argc) { | |
73 | case 2: | |
74 | if (strcmp(argv[1], "-nomenu") == 0) | |
75 | use_menu = FALSE; | |
461c03b6 | 76 | else |
77 | Usage(); | |
08345b74 | 78 | /* Fall Through. */ |
79 | case 1: | |
80 | if ((program_name = rindex(argv[0], '/')) == NULL) | |
81 | program_name = argv[0]; | |
82 | else | |
83 | program_name++; | |
84 | break; | |
85 | default: | |
461c03b6 | 86 | Usage(); |
08345b74 | 87 | break; |
88 | } | |
85ca828a | 89 | |
90 | program_name = Strsave(program_name); | |
91 | whoami = Strsave(program_name); /* used by menu.c, ugh !!! */ | |
92 | ||
08345b74 | 93 | if ( status = sms_connect() ) |
461c03b6 | 94 | ErrorExit("\nConnection to SMS server failed", status); |
08345b74 | 95 | |
461c03b6 | 96 | if ( status = sms_auth(program_name) ) |
97 | ErrorExit("\nAuthorization failed -- please run kinit", status); | |
08345b74 | 98 | |
99 | /* | |
100 | * These signals should not be set until just before we fire up the menu | |
101 | * system. | |
102 | */ | |
85ca828a | 103 | |
104 | #ifndef DEBUG | |
461c03b6 | 105 | (void) signal(SIGHUP, SignalHandler); |
85ca828a | 106 | (void) signal(SIGINT, SignalHandler); |
461c03b6 | 107 | (void) signal(SIGQUIT, SignalHandler); |
85ca828a | 108 | #endif DEBUG |
08345b74 | 109 | |
ace1dd7b | 110 | if (!strcmp(program_name, "listmaint")) |
111 | menu = &list_menu; | |
112 | else if (!strcmp(program_name, "usermaint")) | |
113 | menu = &user_menu; | |
114 | else | |
115 | menu = &sms_top_menu; | |
116 | ||
08345b74 | 117 | if (use_menu) { /* Start menus that execute program */ |
118 | Start_paging(); | |
ace1dd7b | 119 | Start_menu(menu); |
08345b74 | 120 | Stop_paging(); |
121 | } | |
122 | else /* Start program without menus. */ | |
ace1dd7b | 123 | Start_no_menu(menu); |
08345b74 | 124 | |
125 | sms_disconnect(); | |
126 | exit(0); | |
127 | } | |
128 | ||
461c03b6 | 129 | /* Function Name: ErrorExit |
08345b74 | 130 | * Description: This function does the error handling and exits. |
131 | * Arguments: buf - the error message to print. | |
132 | * status - the error code. | |
133 | * Returns: doesn't return. | |
134 | */ | |
135 | ||
136 | static void | |
461c03b6 | 137 | ErrorExit(buf,status) |
08345b74 | 138 | int status; |
461c03b6 | 139 | char * buf; |
08345b74 | 140 | { |
141 | com_err(program_name, status, buf); | |
142 | sms_disconnect(); | |
143 | exit(1); | |
144 | } | |
145 | ||
146 | /* Function Name: usage | |
147 | * Description: Prints usage info and then exits. | |
148 | * Arguments: none | |
149 | * Returns: doesn't return. | |
150 | */ | |
151 | ||
152 | static void | |
461c03b6 | 153 | Usage() |
08345b74 | 154 | { |
155 | fprintf(stderr, "Usage: %s [-nomenu]\n", program_name); | |
156 | exit(1); | |
157 | } | |
158 | ||
402461ad | 159 | #ifndef DEBUG |
461c03b6 | 160 | /* Function Name: SignalHandler |
08345b74 | 161 | * Description: This function cleans up from a signal interrupt. |
162 | * Arguments: none. | |
163 | * Returns: doesn't | |
164 | */ | |
165 | ||
85ca828a | 166 | static void |
461c03b6 | 167 | SignalHandler() |
08345b74 | 168 | { |
169 | Put_message("Signal caught - exiting"); | |
170 | if (use_menu) | |
171 | Cleanup_menu(); | |
172 | sms_disconnect(); | |
173 | exit(1); | |
174 | } | |
402461ad | 175 | #endif DEBUG |