]> arthur.barton.de Git - netatalk.git/blobdiff - etc/afpd/file.c
Dropbox kludge -- fixed file overwrites, I don't plan any more dev. on this.
[netatalk.git] / etc / afpd / file.c
index e8bac0185f57605f638d5b85cbdf7af792c7c004..c1a56edc789d25c7e8fd39426970edb3cfde5264 100644 (file)
@@ -319,13 +319,15 @@ int afp_createfile(obj, ibuf, ibuflen, rbuf, 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;
     struct ofork        *of;
-    char               *path, *upath, adpath[50];
-    int                        creatf, did, openf, uid;
+    char               *path, *upath;
+    int                        creatf, did, openf;
     u_int16_t          vid;
 
     *rbuflen = 0;
@@ -404,7 +406,6 @@ int afp_createfile(obj, ibuf, ibuflen, rbuf, rbuflen )
     ad_close( adp, ADFLAGS_DF|ADFLAGS_HF );
 
 createfile_done:
-    setvoltime(obj, vol );
 
 #ifdef DROPKLUDGE
 
@@ -415,20 +416,45 @@ you are a developer who wants to try it out and fix it. */
       syslog (LOG_ERR, "Error checking directory %s: %m", dir->d_name);
     else {
       uid=geteuid();
-      strcpy (adpath, "./.AppleDouble/");
-      strcat (adpath, path);
-      seteuid(0); /* Become root to change the owner of the file */
-      syslog (LOG_INFO, "Changing %s to uid=%d gid=%d", path, sb.st_uid, sb.st_gid);
-      if (chown(path, sb.st_uid, -1)==-1)
-        syslog (LOG_ERR, "Error changing permissions: %m");
-      if (chown(adpath, sb.st_uid, -1)==-1)
-        syslog (LOG_ERR, "Error changing AppleDouble permissions: %m");
-      syslog (LOG_INFO, "Changing afpd owner back to %d", uid);
-      seteuid(uid); /* Restore process ownership to normal */
+      if ( uid != sb.st_uid )
+      {
+       strcpy (adpath, "./.AppleDouble/");
+       strcat (adpath, path);
+       seteuid(0); /* Become root to change the owner of the file */
+       if (chown(path, sb.st_uid, sb.st_gid) < 0) 
+        {
+         syslog (LOG_ERR, "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(path,(st.st_mode&0x0FFFF)| S_IRGRP| S_IROTH) < 0)
+        {
+          syslog (LOG_ERR, "Error adding file read permissions: %m");
+          return (-1);
+        }
+        else syslog (LOG_DEBUG, "Added S_IRGRP and S_IROTH: %m");
+       if (chown(adpath, sb.st_uid, sb.st_gid) < 0)
+        {
+         syslog (LOG_ERR, "Error changing AppleDouble owner/gid: %m");
+          return (-1);
+        }
+        if (chmod(adpath,(st.st_mode&0x0FFFF)| S_IRGRP| S_IROTH) < 0)
+        {
+          syslog (LOG_ERR, "Error adding AD file read permissions: %m");
+          return (-1);
+        }
+        else syslog (LOG_DEBUG, "Added S_IRGRP and S_IROTH to AD: %m");
+       syslog (LOG_DEBUG, "Changing afpd owner back to %d", uid);
+       seteuid(uid); /* Restore process ownership to normal */
+      }
     }
 
 #endif DROPKLUDGE
 
+    setvoltime(obj, vol );
     return AFP_OK;
 }
 
@@ -1116,7 +1142,6 @@ int afp_createid(obj, ibuf, ibuflen, rbuf, rbuflen )
     cnid_t             did, id;
     u_short            vid;
     
-
     *rbuflen = 0;
     ibuf += 2;
 
@@ -1206,7 +1231,6 @@ int afp_resolveid(obj, ibuf, ibuflen, rbuf, rbuflen )
     cnid_t             id;
     u_int16_t          vid, bitmap;
     
-
     *rbuflen = 0;
     ibuf += 2;
 
@@ -1269,7 +1293,6 @@ int afp_deleteid(obj, ibuf, ibuflen, rbuf, rbuflen )
     cnid_t             id;
     u_short            vid;
     
-
     *rbuflen = 0;
     ibuf += 2;
 
@@ -1347,7 +1370,6 @@ int afp_exchangefiles(obj, ibuf, ibuflen, rbuf, rbuflen )
     cnid_t             sid, did;
     u_int16_t          vid;
     
-
     *rbuflen = 0;
     ibuf += 2;