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 = rindex(argv[0], '/');
91 /* interpret arguments here */
93 fprintf(stderr, "Usage: %s\n", whoami);
98 if (!config_lookup("nofork")) {
101 n = open("/dev/tty", O_RDWR|FNDELAY);
103 (void) ioctl(n, TIOCNOTTY, (char *)NULL);
107 gdb_debug(GDB_NOFORK);
111 initialize_sms_error_table();
112 initialize_krb_error_table();
113 mr_update_initialize();
115 /* wait for connection */
117 /* If the config file contains a line "port portname", the daemon
118 * will listen on the named port rather than SERVICE_NAME "sms_update"
120 if ((p = config_lookup("port")) == NULL)
122 conn = create_forking_server(p, 0);
124 /* If the config file contains a line "user username", the
125 * daemon will run with that user's UID.
127 if (p = config_lookup("user")) {
131 com_err(whoami, errno, "Unable to find user %s\n", p);
137 /* If the config file contains a line "chroot /dir/name", the
138 * daemon will run chrooted to that directory.
140 if (p = config_lookup("chroot")) {
142 com_err(whoami, errno, "unable to chroot to %s", p);
148 com_err(whoami, errno, "can't get connection");
151 if (connection_status(conn) == CON_STOPPED) {
152 com_err(whoami, connection_errno(conn), ": can't get connection");
156 mr_log_info("got connection");
157 /* got a connection; loop forever */
160 code = receive_object(conn, (char *)&str, STRING_T);
162 com_err(whoami, connection_errno(conn), "receiving command");
163 sever_connection(conn);
166 cp = index(STRING_DATA(str), ' ');
169 for (d = dispatch_table; d->str; d++) {
170 if (!strcmp(d->str, STRING_DATA(str))) {
174 printf("got request: %s\n", STRING_DATA(str));
176 (void)(d->proc)(STRING_DATA(str));
180 sprintf(buf, "unknown request received: %s\n", STRING_DATA(str));
182 code = send_int(MR_UNKNOWN_PROC);
184 com_err(whoami, connection_errno(conn), "sending UNKNOWN_PROC");
195 return((code = send_object(conn, (char *)&zero, INTEGER_T)));
201 /* keep have_authorization around */
203 have_instructions = 0;
205 if (STRING_DATA(instructions) != (char *)NULL)
206 string_free(&instructions);
216 * any arguments are ignored
219 * closes connection from MR
229 sever_connection(conn);
230 mr_log_info("Closing connection.");
238 * put <msg> to log as error, break connection, and exit
244 com_err(whoami, code, msg);
246 sever_connection(conn);
253 * send back (external) <code>; if error, punt big with <lose(msg)>
259 code = send_object(conn, (char *)&code, INTEGER_T);
261 code = connection_errno(conn);
269 * set (external) <code> to <c> and call <report_error>
276 report_error("call rejected");