]> andersk Git - moira.git/blobdiff - update/get_file.c
Build without krb4 if it's unavailable.
[moira.git] / update / get_file.c
index ff8023979bff7f4b857d3f9f97ac695f141c868f..337947ac112b3d095184b980f7d720387379f52e 100644 (file)
 #include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <unistd.h>
 
+#ifdef HAVE_KRB4
 #include <des.h>
+#endif
 
 RCSID("$Header$");
 
@@ -24,9 +27,11 @@ RCSID("$Header$");
 #define MIN(a, b)    (((a) < (b)) ? (a) : (b))
 #endif /* MIN */
 
+#ifdef HAVE_KRB4
 static des_key_schedule sched;
 static des_cblock ivec;
 extern des_cblock session;
+#endif
 
 static int get_block(int conn, int fd, int max_size, int encrypt);
 
@@ -69,6 +74,8 @@ int get_file(int conn, char *pathname, int file_size, int checksum,
   int found_checksum;
   char buf[BUFSIZ];
 
+  memset(buf, '\0', sizeof(buf));
+
   if (!have_authorization)
     {
       send_int(conn, MR_PERM);
@@ -90,11 +97,6 @@ int get_file(int conn, char *pathname, int file_size, int checksum,
       code = errno;
       com_err(whoami, errno, "creating file %s (get_file)", pathname);
       send_int(conn, code);
-      if (setuid(0) < 0)
-       {
-         com_err(whoami, errno, "Unable to setuid back to %d\n", 0);
-         exit(1);
-       }
       return 1;
     }
 
@@ -115,12 +117,6 @@ int get_file(int conn, char *pathname, int file_size, int checksum,
          unlink(pathname);
          ftruncate(fd, 0);
          close(fd);
-
-         if (setuid(0) < 0)
-           {
-             com_err(whoami, errno, "Unable to setuid back to %d\n", 0);
-             exit(1);
-           }
          return 1;
        }
       n_written += n_wrote;
@@ -131,8 +127,15 @@ int get_file(int conn, char *pathname, int file_size, int checksum,
 
   if (encrypt)
     {
+#ifdef HAVE_KRB4
       des_key_sched(session, sched);
       memcpy(ivec, session, sizeof(ivec));
+#else
+      /* The session key only gets stored if auth happens in krb4 to
+         begin with. If you don't have krb4, you can't possibly be
+         coming up with a valid session key. */
+      return MR_NO_KRB4;
+#endif
     }
 
   n_written = 0;
@@ -144,11 +147,6 @@ int get_file(int conn, char *pathname, int file_size, int checksum,
        {
          /* get_block has already printed a message */
          unlink(pathname);
-         if (setuid(0) < 0)
-           {
-             com_err(whoami, errno, "Unable to setuid back to %d\n", 0);
-             exit(1);
-           }
          return 1;
        }
       n_written += n_got;
@@ -161,12 +159,6 @@ int get_file(int conn, char *pathname, int file_size, int checksum,
   fsync(fd);
   close(fd);
 
-  if (setuid(0) < 0)
-    {
-      com_err(whoami, errno, "Unable to setuid back to %d\n", 0);
-      exit(1);
-    }
-
   /* validate checksum */
   found_checksum = checksum_file(pathname);
   if (checksum != found_checksum)
@@ -192,6 +184,7 @@ static int get_block(int conn, int fd, int max_size, int encrypt)
 
   if (encrypt)
     {
+#ifdef HAVE_KRB4
       char *unenc = malloc(len);
 
       if (!unenc)
@@ -205,6 +198,7 @@ static int get_block(int conn, int fd, int max_size, int encrypt)
        ivec[i] = data[len - 8 + i] ^ unenc[len - 8 + i];
       free(data);
       data = unenc;
+#endif
     }
 
   n_read = MIN(len, max_size);
This page took 0.108801 seconds and 4 git commands to generate.