3 * Copyright 1988-1998 by the Massachusetts Institute of Technology.
4 * For copying and distribution information, please see the file
8 #include <mit-copyright.h>
10 #include "update_server.h"
29 int code, log_priority;
32 int have_authorization = 0;
39 (_send_int = (n), send_object(conn, (char *)&_send_int, INTEGER_T))
45 } dispatch_table[] = {
46 { "AUTH_002", auth_002 },
47 { "XFER_002", xfer_002 },
48 { "XFER_003", xfer_003 },
49 { "EXEC_002", exec_002 },
51 { NULL, (int (*)(char *))abort }
54 /* general scratch space -- useful for building error messages et al... */
57 int main(int argc, char **argv)
63 whoami = strrchr(argv[0], '/');
69 /* interpret arguments here */
72 fprintf(stderr, "Usage: %s\n", whoami);
76 if (!config_lookup("nofork"))
83 gdb_debug(GDB_NOFORK);
86 initialize_sms_error_table();
87 initialize_krb_error_table();
88 mr_update_initialize();
90 /* wait for connection */
92 /* If the config file contains a line "port portname", the daemon
93 * will listen on the named port rather than SERVICE_NAME "moira_update"
95 if (!(p = config_lookup("port")))
97 conn = create_forking_server(p, 0);
99 /* If the config file contains a line "user username", the
100 * daemon will run with that user's UID.
102 if ((p = config_lookup("user")))
108 com_err(whoami, errno, "Unable to find user %s\n", p);
114 /* If the config file contains a line "chroot /dir/name", the
115 * daemon will run chrooted to that directory.
117 if ((p = config_lookup("chroot")))
121 com_err(whoami, errno, "unable to chroot to %s", p);
128 com_err(whoami, errno, "can't get connection");
131 if (connection_status(conn) == CON_STOPPED)
133 com_err(whoami, connection_errno(conn), ": can't get connection");
137 mr_log_info("got connection");
138 /* got a connection; loop forever */
142 code = receive_object(conn, (char *)&str, STRING_T);
145 com_err(whoami, connection_errno(conn), "receiving command");
146 sever_connection(conn);
149 cp = strchr(STRING_DATA(str), ' ');
152 for (d = dispatch_table; d->str; d++)
154 if (!strcmp(d->str, STRING_DATA(str)))
158 (d->proc)(STRING_DATA(str));
162 sprintf(buf, "unknown request received: %s\n", STRING_DATA(str));
164 code = send_int(MR_UNKNOWN_PROC);
166 com_err(whoami, connection_errno(conn), "sending UNKNOWN_PROC");
175 return code = send_object(conn, (char *)&zero, INTEGER_T);
179 void initialize(void)
181 /* keep have_authorization around */
193 * any arguments are ignored
196 * closes connection from MR
201 sever_connection(conn);
202 mr_log_info("Closing connection.");
210 * put <msg> to log as error, break connection, and exit
215 com_err(whoami, code, msg);
217 sever_connection(conn);
224 * send back (external) <code>; if error, punt big with <lose(msg)>
227 void report_error(char *msg)
229 code = send_object(conn, (char *)&code, INTEGER_T);
232 code = connection_errno(conn);
240 * set (external) <code> to <c> and call <report_error>
243 void reject_call(int c)
246 report_error("call rejected");