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"
13 #include <sys/utsname.h>
15 #include <netinet/in.h>
16 #include <arpa/inet.h>
30 char *whoami, *hostname;
32 int have_authorization = 0;
38 void (*proc)(int, char *);
39 } dispatch_table[] = {
40 { "AUTH_002", auth_002 },
41 { "XFER_002", xfer_002 },
42 { "XFER_003", xfer_003 },
43 { "EXEC_002", exec_002 },
45 { NULL, (void (*)(int, char *))abort }
48 int main(int argc, char **argv)
56 whoami = strrchr(argv[0], '/');
62 /* interpret arguments here */
65 fprintf(stderr, "Usage: %s\n", whoami);
69 if (!config_lookup("nofork"))
77 hostname = name.nodename;
82 /* If the config file contains a line "user username", the
83 * daemon will run with that user's UID.
85 if ((p = config_lookup("user")))
91 com_err(whoami, errno, "Unable to find user %s\n", p);
97 /* If the config file contains a line "port portname", the daemon
98 * will listen on the named port rather than SERVICE_NAME ("moira_update")
100 if (!(p = config_lookup("port")))
106 com_err(whoami, errno, "creating listening socket");
110 /* now loop waiting for connections */
113 struct sockaddr_in client;
117 conn = mr_accept(s, &client);
120 com_err(whoami, errno, "accepting on listening socket");
126 if (config_lookup("nofork") || (fork() <= 0))
132 /* If the config file contains a line "chroot /dir/name", the
133 * daemon will run chrooted to that directory.
135 if ((p = config_lookup("chroot")))
139 com_err(whoami, errno, "unable to chroot to %s", p);
144 com_err(whoami, 0, "got connection");
152 code = recv_string(conn, &str, &len);
155 com_err(whoami, code, "receiving command");
160 cp = strchr(str, ' ');
163 for (d = dispatch_table; d->str; d++)
165 if (!strcmp(d->str, str))
169 (d->proc)(conn, str);
173 com_err(whoami, 0, "unknown request received: %s", str);
174 code = send_int(conn, MR_UNKNOWN_PROC);
176 com_err(whoami, code, "sending UNKNOWN_PROC");
182 int send_ok(int conn)
184 return send_int(conn, 0);
193 * any arguments are ignored
196 * closes connection from MR
199 void quit(int conn, char *str)
203 com_err(whoami, 0, "Closing connection.");
207 void fail(int conn, int err, char *msg)
209 com_err(whoami, err, msg);