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>
23 #include <sys/ioctl.h>
30 extern int auth_002(), xfer_002(), xfer_003(), exec_002();
32 extern int sync_proc(), quit();
33 extern char *config_lookup();
35 extern void gdb_debug();
39 int code, log_priority;
42 int have_authorization = 0;
49 (_send_int=(n),send_object(conn,(char *)&_send_int,INTEGER_T))
55 } dispatch_table[] = {
56 { "AUTH_002", auth_002 },
57 { "XFER_002", xfer_002 },
58 { "XFER_003", xfer_003 },
59 { "EXEC_002", exec_002 },
61 { (char *)NULL, (int (*)())abort }
64 /* general scratch space -- useful for building error messages et al... */
78 gdb_debug(GDB_NOFORK);
81 whoami = strrchr(argv[0], '/');
87 /* interpret arguments here */
89 fprintf(stderr, "Usage: %s\n", whoami);
94 if (!config_lookup("nofork")) {
100 n = open("/dev/tty", O_RDWR|FNDELAY);
102 (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 = strchr(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 */
213 * any arguments are ignored
216 * closes connection from MR
226 sever_connection(conn);
227 mr_log_info("Closing connection.");
235 * put <msg> to log as error, break connection, and exit
241 com_err(whoami, code, msg);
243 sever_connection(conn);
250 * send back (external) <code>; if error, punt big with <lose(msg)>
256 code = send_object(conn, (char *)&code, INTEGER_T);
258 code = connection_errno(conn);
266 * set (external) <code> to <c> and call <report_error>
273 report_error("call rejected");