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 { NULL, (int (*)())abort }
64 /* general scratch space -- useful for building error messages et al... */
67 int main(int argc, char **argv)
74 whoami = strrchr(argv[0], '/');
80 /* interpret arguments here */
83 fprintf(stderr, "Usage: %s\n", whoami);
87 if (!config_lookup("nofork"))
94 gdb_debug(GDB_NOFORK);
97 initialize_sms_error_table();
98 initialize_krb_error_table();
99 mr_update_initialize();
101 /* wait for connection */
103 /* If the config file contains a line "port portname", the daemon
104 * will listen on the named port rather than SERVICE_NAME "moira_update"
106 if (!(p = config_lookup("port")))
108 conn = create_forking_server(p, 0);
110 /* If the config file contains a line "user username", the
111 * daemon will run with that user's UID.
113 if ((p = config_lookup("user")))
119 com_err(whoami, errno, "Unable to find user %s\n", p);
125 /* If the config file contains a line "chroot /dir/name", the
126 * daemon will run chrooted to that directory.
128 if ((p = config_lookup("chroot")))
132 com_err(whoami, errno, "unable to chroot to %s", p);
139 com_err(whoami, errno, "can't get connection");
142 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 */
153 code = receive_object(conn, (char *)&str, STRING_T);
156 com_err(whoami, connection_errno(conn), "receiving command");
157 sever_connection(conn);
160 cp = strchr(STRING_DATA(str), ' ');
163 for (d = dispatch_table; d->str; d++)
165 if (!strcmp(d->str, STRING_DATA(str)))
169 (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");
186 return code = send_object(conn, (char *)&zero, INTEGER_T);
192 /* keep have_authorization around */
204 * any arguments are ignored
207 * closes connection from MR
212 sever_connection(conn);
213 mr_log_info("Closing connection.");
221 * put <msg> to log as error, break connection, and exit
226 com_err(whoami, code, msg);
228 sever_connection(conn);
235 * send back (external) <code>; if error, punt big with <lose(msg)>
238 report_error(char *msg)
240 code = send_object(conn, (char *)&code, INTEGER_T);
243 code = connection_errno(conn);
251 * set (external) <code> to <c> and call <report_error>
257 report_error("call rejected");