5 /* (c) Copyright 1988 by the Massachusetts Institute of Technology. */
6 /* For copying and distribution information, please see the file */
7 /* <mit-copyright.h>. */
10 static char *rcsid_dispatch_c = "$Header$";
13 #include <mit-copyright.h>
22 #include <sys/ioctl.h>
28 extern int auth_001(), inst_001();
29 extern int xfer_002(), xfer_003(), exec_002();
31 extern int sync_proc(), quit();
32 extern char *config_lookup();
34 extern void gdb_debug();
35 extern int abort(), errno;
39 extern STRING instructions;
45 int have_authorization = 0;
47 int have_instructions = 0;
52 (_send_int=(n),send_object(conn,(char *)&_send_int,INTEGER_T))
58 } dispatch_table[] = {
59 { "INST_001", inst_001 },
60 { "AUTH_001", auth_001 },
61 { "XFER_002", xfer_002 },
62 { "XFER_003", xfer_003 },
63 { "EXEC_002", exec_002 },
65 { (char *)NULL, abort }
68 /* general scratch space -- useful for building error messages et al... */
82 gdb_debug(GDB_NOFORK);
85 whoami = strrchr(argv[0], '/');
91 /* interpret arguments here */
93 fprintf(stderr, "Usage: %s\n", whoami);
98 if (!config_lookup("nofork")) {
104 n = open("/dev/tty", O_RDWR|FNDELAY);
106 (void) ioctl(n, TIOCNOTTY, (char *)NULL);
111 gdb_debug(GDB_NOFORK);
115 initialize_sms_error_table();
116 initialize_krb_error_table();
117 mr_update_initialize();
119 /* wait for connection */
121 /* If the config file contains a line "port portname", the daemon
122 * will listen on the named port rather than SERVICE_NAME "sms_update"
124 if ((p = config_lookup("port")) == NULL)
126 conn = create_forking_server(p, 0);
128 /* If the config file contains a line "user username", the
129 * daemon will run with that user's UID.
131 if (p = config_lookup("user")) {
135 com_err(whoami, errno, "Unable to find user %s\n", p);
141 /* If the config file contains a line "chroot /dir/name", the
142 * daemon will run chrooted to that directory.
144 if (p = config_lookup("chroot")) {
146 com_err(whoami, errno, "unable to chroot to %s", p);
152 com_err(whoami, errno, "can't get connection");
155 if (connection_status(conn) == CON_STOPPED) {
156 com_err(whoami, connection_errno(conn), ": can't get connection");
160 mr_log_info("got connection");
161 /* got a connection; loop forever */
164 code = receive_object(conn, (char *)&str, STRING_T);
166 com_err(whoami, connection_errno(conn), "receiving command");
167 sever_connection(conn);
170 cp = strchr(STRING_DATA(str), ' ');
173 for (d = dispatch_table; d->str; d++) {
174 if (!strcmp(d->str, STRING_DATA(str))) {
178 printf("got request: %s\n", STRING_DATA(str));
180 (void)(d->proc)(STRING_DATA(str));
184 sprintf(buf, "unknown request received: %s\n", STRING_DATA(str));
186 code = send_int(MR_UNKNOWN_PROC);
188 com_err(whoami, connection_errno(conn), "sending UNKNOWN_PROC");
199 return((code = send_object(conn, (char *)&zero, INTEGER_T)));
205 /* keep have_authorization around */
207 have_instructions = 0;
209 if (STRING_DATA(instructions) != (char *)NULL)
210 string_free(&instructions);
220 * any arguments are ignored
223 * closes connection from MR
233 sever_connection(conn);
234 mr_log_info("Closing connection.");
242 * put <msg> to log as error, break connection, and exit
248 com_err(whoami, code, msg);
250 sever_connection(conn);
257 * send back (external) <code>; if error, punt big with <lose(msg)>
263 code = send_object(conn, (char *)&code, INTEGER_T);
265 code = connection_errno(conn);
273 * set (external) <code> to <c> and call <report_error>
280 report_error("call rejected");