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(), 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 { "EXEC_002", exec_002 },
57 { (char *)NULL, abort }
60 /* general scratch space -- useful for building error messages et al... */
74 gdb_debug(GDB_NOFORK);
77 whoami = rindex(argv[0], '/');
83 /* interpret arguments here */
85 fprintf(stderr, "Usage: %s\n", whoami);
90 if (!config_lookup("nofork")) {
93 n = open("/dev/tty", O_RDWR|FNDELAY);
95 (void) ioctl(n, TIOCNOTTY, (char *)NULL);
99 gdb_debug(GDB_NOFORK);
103 initialize_sms_error_table();
104 initialize_krb_error_table();
105 mr_update_initialize();
107 /* wait for connection */
109 /* If the config file contains a line "port portname", the daemon
110 * will listen on the named port rather than SERVICE_NAME "sms_update"
112 if ((p = config_lookup("port")) == NULL)
114 conn = create_forking_server(p, 0);
116 /* If the config file contains a line "user username", the
117 * daemon will run with that user's UID.
119 if (p = config_lookup("user")) {
123 com_err(whoami, errno, "Unable to find user %s\n", p);
129 /* If the config file contains a line "chroot /dir/name", the
130 * daemon will run chrooted to that directory.
132 if (p = config_lookup("chroot")) {
134 com_err(whoami, errno, "unable to chroot to %s", p);
140 com_err(whoami, errno, "can't get connection");
143 if (connection_status(conn) == CON_STOPPED) {
144 com_err(whoami, connection_errno(conn), ": can't get connection");
148 mr_log_info("got connection");
149 /* got a connection; loop forever */
152 code = receive_object(conn, (char *)&str, STRING_T);
154 com_err(whoami, connection_errno(conn), "receiving command");
155 sever_connection(conn);
158 cp = index(STRING_DATA(str), ' ');
161 for (d = dispatch_table; d->str; d++) {
162 if (!strcmp(d->str, STRING_DATA(str))) {
166 printf("got request: %s\n", STRING_DATA(str));
168 (void)(d->proc)(STRING_DATA(str));
172 sprintf(buf, "unknown request received: %s\n", STRING_DATA(str));
174 code = send_int(MR_UNKNOWN_PROC);
176 com_err(whoami, connection_errno(conn), "sending UNKNOWN_PROC");
187 return((code = send_object(conn, (char *)&zero, INTEGER_T)));
193 /* keep have_authorization around */
195 have_instructions = 0;
197 if (STRING_DATA(instructions) != (char *)NULL)
198 string_free(&instructions);
208 * any arguments are ignored
211 * closes connection from MR
221 sever_connection(conn);
222 mr_log_info("Closing connection.");
230 * put <msg> to log as error, break connection, and exit
236 com_err(whoami, code, msg);
238 sever_connection(conn);
245 * send back (external) <code>; if error, punt big with <lose(msg)>
251 code = send_object(conn, (char *)&code, INTEGER_T);
253 code = connection_errno(conn);
261 * set (external) <code> to <c> and call <report_error>
268 report_error("call rejected");