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>
21 #include <sys/ioctl.h>
24 extern int auth_001(), inst_001();
25 extern int xfer_002(), xfer_003(), exec_002();
27 extern int sync_proc(), quit();
28 extern char *config_lookup();
30 extern void gdb_debug();
31 extern int exit(), abort(), errno;
32 extern STRING instructions;
38 int have_authorization = 0;
40 int have_instructions = 0;
45 (_send_int=(n),send_object(conn,(char *)&_send_int,INTEGER_T))
51 } dispatch_table[] = {
52 { "INST_001", inst_001 },
53 { "AUTH_001", auth_001 },
54 { "XFER_002", xfer_002 },
55 { "XFER_003", xfer_003 },
56 { "EXEC_002", exec_002 },
58 { (char *)NULL, abort }
61 /* general scratch space -- useful for building error messages et al... */
75 gdb_debug(GDB_NOFORK);
78 whoami = rindex(argv[0], '/');
84 /* interpret arguments here */
86 fprintf(stderr, "Usage: %s\n", whoami);
91 if (!config_lookup("nofork")) {
94 n = open("/dev/tty", O_RDWR|FNDELAY);
96 (void) ioctl(n, TIOCNOTTY, (char *)NULL);
100 gdb_debug(GDB_NOFORK);
104 initialize_sms_error_table();
105 initialize_krb_error_table();
106 mr_update_initialize();
108 /* wait for connection */
110 /* If the config file contains a line "port portname", the daemon
111 * will listen on the named port rather than SERVICE_NAME "sms_update"
113 if ((p = config_lookup("port")) == NULL)
115 conn = create_forking_server(p, 0);
117 /* If the config file contains a line "user username", the
118 * daemon will run with that user's UID.
120 if (p = config_lookup("user")) {
124 com_err(whoami, errno, "Unable to find user %s\n", p);
130 /* If the config file contains a line "chroot /dir/name", the
131 * daemon will run chrooted to that directory.
133 if (p = config_lookup("chroot")) {
135 com_err(whoami, errno, "unable to chroot to %s", p);
141 com_err(whoami, errno, "can't get connection");
144 if (connection_status(conn) == CON_STOPPED) {
145 com_err(whoami, connection_errno(conn), ": can't get connection");
149 mr_log_info("got connection");
150 /* got a connection; loop forever */
153 code = receive_object(conn, (char *)&str, STRING_T);
155 com_err(whoami, connection_errno(conn), "receiving command");
156 sever_connection(conn);
159 cp = index(STRING_DATA(str), ' ');
162 for (d = dispatch_table; d->str; d++) {
163 if (!strcmp(d->str, STRING_DATA(str))) {
167 printf("got request: %s\n", STRING_DATA(str));
169 (void)(d->proc)(STRING_DATA(str));
173 sprintf(buf, "unknown request received: %s\n", STRING_DATA(str));
175 code = send_int(MR_UNKNOWN_PROC);
177 com_err(whoami, connection_errno(conn), "sending UNKNOWN_PROC");
188 return((code = send_object(conn, (char *)&zero, INTEGER_T)));
194 /* keep have_authorization around */
196 have_instructions = 0;
198 if (STRING_DATA(instructions) != (char *)NULL)
199 string_free(&instructions);
209 * any arguments are ignored
212 * closes connection from MR
222 sever_connection(conn);
223 mr_log_info("Closing connection.");
231 * put <msg> to log as error, break connection, and exit
237 com_err(whoami, code, msg);
239 sever_connection(conn);
246 * send back (external) <code>; if error, punt big with <lose(msg)>
252 code = send_object(conn, (char *)&code, INTEGER_T);
254 code = connection_errno(conn);
262 * set (external) <code> to <c> and call <report_error>
269 report_error("call rejected");