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>
29 extern int auth_001(), inst_001();
30 extern int xfer_002(), xfer_003(), exec_002();
32 extern int sync_proc(), quit();
33 extern char *config_lookup();
35 extern void gdb_debug();
37 extern STRING instructions;
40 int code, log_priority;
43 int have_authorization = 0;
45 int have_instructions = 0;
50 (_send_int=(n),send_object(conn,(char *)&_send_int,INTEGER_T))
56 } dispatch_table[] = {
57 { "INST_001", inst_001 },
58 { "AUTH_001", auth_001 },
59 { "XFER_002", xfer_002 },
60 { "XFER_003", xfer_003 },
61 { "EXEC_002", exec_002 },
63 { (char *)NULL, (int (*)())abort }
66 /* general scratch space -- useful for building error messages et al... */
80 gdb_debug(GDB_NOFORK);
83 whoami = strrchr(argv[0], '/');
89 /* interpret arguments here */
91 fprintf(stderr, "Usage: %s\n", whoami);
96 if (!config_lookup("nofork")) {
102 n = open("/dev/tty", O_RDWR|FNDELAY);
104 (void) ioctl(n, TIOCNOTTY, (char *)NULL);
109 gdb_debug(GDB_NOFORK);
113 initialize_sms_error_table();
114 initialize_krb_error_table();
115 mr_update_initialize();
117 /* wait for connection */
119 /* If the config file contains a line "port portname", the daemon
120 * will listen on the named port rather than SERVICE_NAME "sms_update"
122 if ((p = config_lookup("port")) == NULL)
124 conn = create_forking_server(p, 0);
126 /* If the config file contains a line "user username", the
127 * daemon will run with that user's UID.
129 if (p = config_lookup("user")) {
133 com_err(whoami, errno, "Unable to find user %s\n", p);
139 /* If the config file contains a line "chroot /dir/name", the
140 * daemon will run chrooted to that directory.
142 if (p = config_lookup("chroot")) {
144 com_err(whoami, errno, "unable to chroot to %s", p);
150 com_err(whoami, errno, "can't get connection");
153 if (connection_status(conn) == CON_STOPPED) {
154 com_err(whoami, connection_errno(conn), ": can't get connection");
158 mr_log_info("got connection");
159 /* got a connection; loop forever */
162 code = receive_object(conn, (char *)&str, STRING_T);
164 com_err(whoami, connection_errno(conn), "receiving command");
165 sever_connection(conn);
168 cp = strchr(STRING_DATA(str), ' ');
171 for (d = dispatch_table; d->str; d++) {
172 if (!strcmp(d->str, STRING_DATA(str))) {
176 printf("got request: %s\n", STRING_DATA(str));
178 (void)(d->proc)(STRING_DATA(str));
182 sprintf(buf, "unknown request received: %s\n", STRING_DATA(str));
184 code = send_int(MR_UNKNOWN_PROC);
186 com_err(whoami, connection_errno(conn), "sending UNKNOWN_PROC");
197 return((code = send_object(conn, (char *)&zero, INTEGER_T)));
203 /* keep have_authorization around */
205 have_instructions = 0;
207 if (STRING_DATA(instructions) != (char *)NULL)
208 string_free(&instructions);
218 * any arguments are ignored
221 * closes connection from MR
231 sever_connection(conn);
232 mr_log_info("Closing connection.");
240 * put <msg> to log as error, break connection, and exit
246 com_err(whoami, code, msg);
248 sever_connection(conn);
255 * send back (external) <code>; if error, punt big with <lose(msg)>
261 code = send_object(conn, (char *)&code, INTEGER_T);
263 code = connection_errno(conn);
271 * set (external) <code> to <c> and call <report_error>
278 report_error("call rejected");