]> arthur.barton.de Git - netatalk.git/blobdiff - etc/afpd/file.c
DROPKLUDGE fix to "move" procedure and a few general code cleanup things
[netatalk.git] / etc / afpd / file.c
index af6da8b13d56c5aeaac09f306ffd2424f38d3210..fd1a980bab7662a739dbe0db0f96d7b2d0f91a1a 100644 (file)
@@ -3,6 +3,10 @@
  * All Rights Reserved.  See COPYRIGHT.
  */
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -313,6 +317,11 @@ int afp_createfile(obj, ibuf, ibuflen, rbuf, rbuflen )
     int                ibuflen, *rbuflen;
 {
     struct stat         st;
+#ifdef DROPKLUDGE
+    struct stat                sb;
+    char               adpath[50];
+    int                        uid;
+#endif DROPKLUDGE
     struct adouble     ad, *adp;
     struct vol         *vol;
     struct dir         *dir;
@@ -397,6 +406,56 @@ int afp_createfile(obj, ibuf, ibuflen, rbuf, rbuflen )
     ad_close( adp, ADFLAGS_DF|ADFLAGS_HF );
 
 createfile_done:
+
+#ifdef DROPKLUDGE
+
+/* The below code changes the way file ownership is determined in the name of
+fixing dropboxes.  It has known security problem.  See the netatalk FAQ for
+more information */
+    if (stat(".", &sb) < 0) {
+      syslog (LOG_ERR, "afp_createfile:  Error checking directory \"%s\": %m", dir->d_name);
+      return(-1);
+    }
+    else {
+      uid=geteuid();
+      if ( uid != sb.st_uid )
+      {
+       strcpy (adpath, "./.AppleDouble/");
+       strcat (adpath, upath);
+       seteuid(0); /* Become root to change the owner of the file */
+       if (lchown(upath, sb.st_uid, sb.st_gid) < 0) 
+        {
+         syslog (LOG_ERR, "afp_createfile:  Error changing owner/gid: %m");
+          return (-1);
+        }
+        /* In order to write information to the file, the Mac client needs
+        to be able to read from it too, so read bits have to be turned on.
+        Directory permissions remain unchanged */
+        stat(upath, &st);
+        if (chmod(upath,(st.st_mode&0x0FFFF)| S_IRGRP| S_IROTH) < 0)
+        {
+          syslog (LOG_ERR, "afp_createfile:  Error adding file read permissions: %m");
+          return (-1);
+        }
+        else syslog (LOG_DEBUG, "afp_createfile:  Added S_IRGRP and S_IROTH: %m");
+       if (lchown(adpath, sb.st_uid, sb.st_gid) < 0)
+        {
+         syslog (LOG_ERR, "afp_createfile:  Error changing AppleDouble owner/gid: %m");
+          return (-1);
+        }
+        if (chmod(adpath, (st.st_mode&0x0FFFF)| S_IRGRP| S_IROTH) < 0)
+        {
+          syslog (LOG_ERR, "afp_createfile:  Error adding AD file read permissions: %m");
+          return (-1);
+        }
+        else syslog (LOG_DEBUG, "afp_createfile:  Added S_IRGRP and S_IROTH to AD: %m");
+       syslog (LOG_DEBUG, "afp_createfile:  Changing afpd owner back to %d", uid);
+       seteuid(uid); /* Restore process ownership to normal */
+      }
+    }
+
+#endif DROPKLUDGE
+
     setvoltime(obj, vol );
     return AFP_OK;
 }
@@ -1085,7 +1144,6 @@ int afp_createid(obj, ibuf, ibuflen, rbuf, rbuflen )
     cnid_t             did, id;
     u_short            vid;
     
-
     *rbuflen = 0;
     ibuf += 2;
 
@@ -1175,7 +1233,6 @@ int afp_resolveid(obj, ibuf, ibuflen, rbuf, rbuflen )
     cnid_t             id;
     u_int16_t          vid, bitmap;
     
-
     *rbuflen = 0;
     ibuf += 2;
 
@@ -1238,7 +1295,6 @@ int afp_deleteid(obj, ibuf, ibuflen, rbuf, rbuflen )
     cnid_t             id;
     u_short            vid;
     
-
     *rbuflen = 0;
     ibuf += 2;
 
@@ -1316,7 +1372,6 @@ int afp_exchangefiles(obj, ibuf, ibuflen, rbuf, rbuflen )
     cnid_t             sid, did;
     u_int16_t          vid;
     
-
     *rbuflen = 0;
     ibuf += 2;