]> andersk Git - moira.git/blobdiff - update/send_file.c
randomized continuation lines
[moira.git] / update / send_file.c
index da007b602b5c0e39f007745c736c651a3ff6b160..0d524d2d0fd7295fa0e3e7c227b0349cfc7436c6 100644 (file)
@@ -2,24 +2,33 @@
  *     $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_send_file_c = "$Header$";
 #endif lint
 
+#include <mit-copyright.h>
 #include <stdio.h>
 #include <com_err.h>
 #include <gdb.h>
 #include <dcm.h>
-#include <sms.h>
+#include <moira.h>
 #include <sys/file.h>
 #include <sys/stat.h>
+#include <des.h>
+#include <krb.h>
 #include <update.h>
-
+#ifdef POSIX
+#include <fcntl.h>
+#endif
 
 extern CONNECTION conn;
 extern int errno;
 char buf[BUFSIZ];
+extern C_Block session;
 
 /*
  * syntax:
@@ -39,45 +48,49 @@ char buf[BUFSIZ];
  */
 
 int
-send_file(pathname, target_path)
+send_file(pathname, target_path, encrypt)
 char *pathname;
 char *target_path;
+int  encrypt;
 {
-    int n, fd, code, n_to_send;
+    int n, fd, code, n_to_send, i;
     STRING data;
+    unsigned char dst[UPDATE_BUFSIZ + 8], *src;
     struct stat statb;
-
-    string_alloc(&data, UPDATE_BUFSIZ);
+    des_key_schedule sched;
+    des_cblock ivec;
 
     /* send file over */
     fd = open(pathname, O_RDONLY, 0);
     if (fd < 0) {
        com_err(whoami, errno, "unable to open %s for read", pathname);
-       return(SMS_OCONFIG);
+       return(MR_OCONFIG);
     }
     if (fstat(fd, &statb)) {
        com_err(whoami, errno, "unable to stat %s", pathname);
        close(fd);
-       return(SMS_OCONFIG);
+       return(MR_OCONFIG);
     }
     n_to_send = statb.st_size;
     
-    sprintf(STRING_DATA(data), "XFER_002 %d %d %s",
-           n_to_send, checksum_file(pathname), target_path);
+    string_alloc(&data, UPDATE_BUFSIZ);
+    sprintf(STRING_DATA(data), "XFER_00%c %d %d %s",
+           (encrypt ? '3' : '2'), n_to_send,
+           checksum_file(pathname), target_path);
     code = send_object(conn, (char *)&data, STRING_T);
     if (code) {
-       com_err(whoami, code, " sending XFER_002 request");
+       com_err(whoami, code, " sending XFER request");
        close(fd);
        return(code);
     }
     code = receive_object(conn, (char *)&n, INTEGER_T);
     if (code) {
-       com_err(whoami, code, " getting reply from XFER_002 request");
+       com_err(whoami, code, " getting reply from XFER request");
        close(fd);
        return(code);
     }
     if (n) {
-       com_err(whoami, n, " transfer request (XFER_002) rejected");
+       com_err(whoami, n, " transfer request (XFER) rejected");
        close(fd);
        return(n);
     }
@@ -94,6 +107,21 @@ char *target_path;
        close(fd);
        return(n);
     }
+
+    if (encrypt) {
+#ifdef DEBUG
+       printf("Session key %02x %02x %02x %02x  %02x %02x %02x %02x\n",
+              session[0], session[1], session[2], session[3], 
+              session[4], session[5], session[6], session[7]);
+#endif /* DEBUG */
+       des_key_sched(session, sched);
+#ifdef POSIX
+       memmove(ivec, session, sizeof(ivec));
+#else
+       bcopy(session, ivec, sizeof(ivec));
+#endif
+    }
+
     while (n_to_send > 0) {
 #ifdef DEBUG
        printf("n_to_send = %d\n", n_to_send);
@@ -102,9 +130,25 @@ char *target_path;
        if (n < 0) {
            com_err(whoami, errno, " reading %s for transmission", pathname);
            close(fd);
-           return(SMS_ABORTED);
+           return(MR_ABORTED);
        }
        MAX_STRING_SIZE(data) = n;
+       if (encrypt) {
+           src = (unsigned char *)STRING_DATA(data);
+#ifdef POSIX
+           memmove(dst, src, n);
+#else
+           bcopy(src, dst, n);
+#endif
+           memset(dst + n, 0, 7);
+           /* encrypt! */
+           des_pcbc_encrypt(dst, src, n, sched, ivec, 0);
+           /* save vector to continue chaining */
+           for (i = 0; i < 8; i++)
+             ivec[i] = dst[n - 8 + i] ^ src[n - 8 + i];
+           /* round up to multiple of 8 */
+           data.length = (data.length + 7) & 0xfffffff8;
+       }
        code = send_object(conn, (char *)&data, STRING_T);
        if (code) {
            com_err(whoami, connection_errno(conn), " transmitting file %s",
@@ -128,6 +172,22 @@ char *target_path;
            return(n);
        }
     }
+    if (statb.st_size == 0) {
+       code = receive_object(conn, (char *)&n, INTEGER_T);
+       if (code) {
+           com_err(whoami, connection_errno(conn),
+                   " awaiting ACK remote server after transmission of %s",
+                   pathname);
+           close(fd);
+           return(code);
+       }
+       if (n) {
+           com_err(whoami, n, " from remote server after transmission of %s",
+                   pathname);
+           close(fd);
+           return(n);
+       }
+    }
     close(fd);
-    return(SMS_SUCCESS);
+    return(MR_SUCCESS);
 }
This page took 0.14967 seconds and 4 git commands to generate.