]> andersk Git - moira.git/blobdiff - update/update_server.c
added xfer_003 operation (encrypted transfer)
[moira.git] / update / update_server.c
index d4ab26d2a1fd0adc3019c867dcac02ee7b013280..ce79b5a53e86fbdbced3d83406cbde7b8ba7506f 100644 (file)
@@ -2,28 +2,30 @@
  *     $Source$
  *     $Header$
  */
+/*  (c) Copyright 1988 by the Massachusetts Institute of Technology. */
+/*  For copying and distribution information, please see the file */
+/*  <mit-copyright.h>. */
 
 #ifndef lint
 static char *rcsid_dispatch_c = "$Header$";
 #endif lint
 
+#include <mit-copyright.h>
 #include <stdio.h>
 #include <gdb.h>
 #include <errno.h>
 #include <strings.h>
-#include <sms.h>
+#include <pwd.h>
+#include <moira.h>
 #include <sys/file.h>
 #include <sys/ioctl.h>
 #include "update.h"
 
-/* XXX */
-#include "kludge.h"
-/* XXX */
-
 extern int auth_001(), inst_001();
-extern int xfer_002(), exec_002();
+extern int xfer_002(), xfer_003(), exec_002();
 
 extern int sync_proc(), quit();
+extern char *config_lookup();
 
 extern void gdb_debug();
 extern int exit(), abort(), errno;
@@ -37,7 +39,7 @@ int have_authorization = 0;
 int have_file = 0;
 int have_instructions = 0;
 int done = 0;
-
+int uid = 0;
 
 #define send_int(n) \
      (_send_int=(n),send_object(conn,(char *)&_send_int,INTEGER_T))
@@ -50,23 +52,15 @@ struct _dt {
      { "INST_001", inst_001 },
      { "AUTH_001", auth_001 },
      { "XFER_002", xfer_002 },
+     { "XFER_003", xfer_003 },
      { "EXEC_002", exec_002 },
      { "quit", quit },
      { (char *)NULL, abort }
 };
 
-/*
- * general scratch space -- useful for building
- * error messages et al...
- */
+/* general scratch space -- useful for building error messages et al... */
 char buf[BUFSIZ];
-err(code, fmt)
-     int code;
-     char *fmt;
-{
-     sprintf(buf, fmt, error_message(code));
-     sms_log_error(buf);
-}
+
 
 main(argc, argv)
      int argc;
@@ -74,6 +68,7 @@ main(argc, argv)
 {
      STRING str;
      struct _dt *d;
+     char *p;
      int n;
 
 #ifdef DEBUG
@@ -91,44 +86,75 @@ main(argc, argv)
          fprintf(stderr, "Usage:  %s\n", whoami);
          exit(1);
      }
-     /* well, sort of... */
 
 #ifndef DEBUG
-     if (fork())
-       exit(0);
-     n = open("/dev/tty", O_RDWR|O_NDELAY);
-     if (n > 0) {
-        (void) ioctl(n, TIOCNOTTY, (char *)NULL);
-        (void) close(n);
-     }
+     if (!config_lookup("nofork")) {
+        if (fork())
+          exit(0);
+        n = open("/dev/tty", O_RDWR|FNDELAY);
+        if (n > 0) {
+            (void) ioctl(n, TIOCNOTTY, (char *)NULL);
+            (void) close(n);
+        }
+     } else
+       gdb_debug(GDB_NOFORK);
 #endif
 
      umask(0022);
-     init_sms_err_tbl();
-     init_krb_err_tbl();
-     sms_update_initialize();
+     initialize_sms_error_table();
+     initialize_krb_error_table();
+     mr_update_initialize();
 
      /* wait for connection */
      gdb_init();
-     conn = create_forking_server(SERVICE_NAME, 0);
+     /* If the config file contains a line "port portname", the daemon
+      * will listen on the named port rather than SERVICE_NAME "sms_update"
+      */
+     if ((p = config_lookup("port")) == NULL)
+       p = SERVICE_NAME;
+     conn = create_forking_server(p, 0);
+
+     /* If the config file contains a line "user username", the
+      * daemon will run with that user's UID.
+      */
+     if (p = config_lookup("user")) {
+        struct passwd *pw;
+        pw = getpwnam(p);
+        if (pw == 0) {
+            com_err(whoami, errno, "Unable to find user %s\n", p);
+            exit(1);
+        }
+        uid = pw->pw_uid;
+     }
+
+     /* If the config file contains a line "chroot /dir/name", the
+      * daemon will run chrooted to that directory.
+      */
+     if (p = config_lookup("chroot")) {
+        if (chroot(p) < 0) {
+            com_err(whoami, errno, "unable to chroot to %s", p);
+            exit(1);
+        }
+     }
+
      if (!conn) {
-         err(errno, "%s: can't get connection");
-         exit(1);
+        com_err(whoami, errno, "can't get connection");
+        exit(1);
      }
      if (connection_status(conn) == CON_STOPPED) {
         com_err(whoami, connection_errno(conn), ": can't get connection");
         exit(1);
      }
 
-     sms_log_info("got connection");
+     mr_log_info("got connection");
      /* got a connection; loop forever */
      while (1) {
          register char *cp;
          code = receive_object(conn, (char *)&str, STRING_T);
          if (code) {
-              err(connection_errno(conn), "%s: receiving command");
-              sever_connection(conn);
-              exit(1);
+             com_err(whoami, connection_errno(conn), "receiving command");
+             sever_connection(conn);
+             exit(1);
          }
          cp = index(STRING_DATA(str), ' ');
          if (cp)
@@ -145,10 +171,10 @@ main(argc, argv)
              }
          }
          sprintf(buf, "unknown request received: %s\n", STRING_DATA(str));
-         sms_log_error(buf);
-         code = send_int(SMS_UNKNOWN_PROC);
+         mr_log_error(buf);
+         code = send_int(MR_UNKNOWN_PROC);
          if (code) {
-             err(connection_errno(conn), "%s: sending UNKNOWN_PROC");
+             com_err(whoami, connection_errno(conn), "sending UNKNOWN_PROC");
          }
      ok:
          string_free(&str);
@@ -183,7 +209,7 @@ initialize()
  * any arguments are ignored
  *
  * function:
- *     closes connection from SMS
+ *     closes connection from MR
  */
 int
 quit(str)
@@ -194,8 +220,8 @@ quit(str)
 #endif /* lint */
      (void) send_ok();
      sever_connection(conn);
-     sms_log_info("Closing connection.");
-     exit(0);
+     mr_log_info("Closing connection.");
+     return(exit(0));
 }
 
 
@@ -208,8 +234,7 @@ quit(str)
 lose(msg)
     char *msg;
 {
-    sprintf(buf, "%s: %s", error_message(code), msg);
-    sms_log_error(buf);
+    com_err(whoami, code, msg);
     if (conn)
        sever_connection(conn);
     exit(1);
This page took 0.045095 seconds and 4 git commands to generate.