]> arthur.barton.de Git - netatalk.git/commitdiff
Setting POSIX ACLs on Linux
authorFrank Lahm <franklahm@googlemail.com>
Thu, 14 Mar 2013 18:54:52 +0000 (19:54 +0100)
committerRalph Boehme <sloowfranklin@gmail.com>
Fri, 22 Mar 2013 12:13:36 +0000 (13:13 +0100)
The VFS module for setting ACLs on Linux returned an error when
try to set an ACL for a file that doesn't have a ressource fork.

Fix this by checking for ENOENT errno and then returning with 0
from the VFS stack.

NEWS
etc/afpd/acls.c
libatalk/vfs/acl.c
libatalk/vfs/vfs.c

diff --git a/NEWS b/NEWS
index 736a337539da86c538a3f4c49785255a1da818cd..3f7c312cb7311b57cb87f36b4c0b6b81234b89ad 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -41,6 +41,8 @@ Changes in 3.0.3
        From FR #76.
 * FIX: Can't set Finder label on symlinked folder with "follow symlinks = yes".
        Fixes bug #508.
+* FIX: Setting POSIX ACLs on Linux
+       Fixes bug #506.
 
 Changes in 3.0.2
 ================
index 56ffeea9fce9fd11501b38cc04b5eaa042e6f76a..6f2abdf30f43b4c22f7d26a0c7ed7f38d54df9cf 100644 (file)
@@ -1157,17 +1157,21 @@ static int set_acl(const struct vol *vol,
     }
     LOG(log_debug7, logtype_afpd, "set_acl: copied %d trivial ACEs", trivial_ace_count);
 
-    /* Ressourcefork first.
-       Note: for dirs we set the same ACL on the .AppleDouble/.Parent _file_. This
-       might be strange for ACE_DELETE_CHILD and for inheritance flags. */
+    /* Ressourcefork first */
     if ((ret = (vol->vfs->vfs_acl(vol, name, ACE_SETACL, new_aces_count, new_aces))) != 0) {
-        LOG(log_error, logtype_afpd, "set_acl: error setting acl: %s", strerror(errno));
-        if (errno == (EACCES | EPERM))
+        LOG(log_debug, logtype_afpd, "set_acl: error setting acl: %s", strerror(errno));
+        switch (errno) {
+        case EACCES:
+        case EPERM:
             EC_STATUS(AFPERR_ACCESS);
-        else if (errno == ENOENT)
-            EC_STATUS(AFPERR_NOITEM);
-        else
+            break;
+        case ENOENT:
+            EC_STATUS(AFP_OK);
+            break;
+        default:
             EC_STATUS(AFPERR_MISC);
+            break;
+        }
         goto EC_CLEANUP;
     }
     if ((ret = (acl(name, ACE_SETACL, new_aces_count, new_aces))) != 0) {
index c936f178d79bbd8bbbafc8c0269a07275ac550a7..d7c8eb62b46470d2caed350b0b095d48d5ea1b05 100644 (file)
@@ -108,7 +108,7 @@ int remove_acl_vfs(const char *name)
 
 
     /* Remove default ACL if it's a dir */
-    EC_ZERO_LOG_ERR(stat(name, &st), AFPERR_MISC);
+    EC_ZERO_ERR(stat(name, &st), AFPERR_MISC);
     if (S_ISDIR(st.st_mode)) {
         EC_NULL_LOG_ERR(acl = acl_init(0), AFPERR_MISC);
         EC_ZERO_LOG_ERR(acl_set_file(name, ACL_TYPE_DEFAULT, acl), AFPERR_MISC);
@@ -129,6 +129,7 @@ int remove_acl_vfs(const char *name)
     EC_ZERO_LOG_ERR(acl_set_file(name, ACL_TYPE_ACCESS, acl), AFPERR_MISC);
 
 EC_CLEANUP:
+    if (errno == ENOENT) EC_STATUS(0);
     if (acl) acl_free(acl);
 
     EC_EXIT;
index a349cfe8cd4c63b1e6137f1400073ae33b4664c3..d79ac05e1142cb14d53bf226ba45e53722ef74ab 100644 (file)
@@ -355,24 +355,17 @@ static int RF_solaris_acl(VFS_FUNC_ARGS_ACL)
     struct stat st;
     int len;
 
-    if ((stat(path, &st)) != 0)
-       return -1;
-    if (S_ISDIR(st.st_mode)) {
-       len = snprintf(buf, MAXPATHLEN, "%s/.AppleDouble",path);
-       if (len < 0 || len >=  MAXPATHLEN)
-           return -1;
-       /* set acl on .AppleDouble dir first */
-       if ((acl(buf, cmd, count, aces)) != 0)
-           return -1;
-       /* now set ACL on ressource fork */
-       if ((acl(vol->ad_path(path, ADFLAGS_DIR), cmd, count, aces)) != 0)
-           return -1;
-    } else
-       /* set ACL on ressource fork */
-       if ((acl(vol->ad_path(path, ADFLAGS_HF), cmd, count, aces)) != 0)
-           return -1;
-
-    return 0;
+    if ((stat(path, &st)) != 0) {
+        if (errno == ENOENT)
+            return AFP_OK;
+        return AFPERR_MISC;
+    }
+    if (!S_ISDIR(st.st_mode)) {
+        /* set ACL on ressource fork */
+        if ((acl(vol->ad_path(path, ADFLAGS_HF), cmd, count, aces)) != 0)
+            return AFPERR_MISC;
+    }
+    return AFP_OK;
 }
 
 static int RF_solaris_remove_acl(VFS_FUNC_ARGS_REMOVE_ACL)
@@ -381,20 +374,15 @@ static int RF_solaris_remove_acl(VFS_FUNC_ARGS_REMOVE_ACL)
     static char buf[ MAXPATHLEN + 1];
     int len;
 
-    if (dir) {
-       len = snprintf(buf, MAXPATHLEN, "%s/.AppleDouble",path);
-       if (len < 0 || len >=  MAXPATHLEN)
-           return AFPERR_MISC;
-       /* remove ACL from .AppleDouble/.Parent first */
-       if ((ret = remove_acl_vfs(vol->ad_path(path, ADFLAGS_DIR))) != AFP_OK)
-           return ret;
-       /* now remove from .AppleDouble dir */
-       if ((ret = remove_acl_vfs(buf)) != AFP_OK)
-           return ret;
-    } else
-       /* remove ACL from ressource fork */
-       if ((ret = remove_acl_vfs(vol->ad_path(path, ADFLAGS_HF))) != AFP_OK)
-           return ret;
+    if (dir)
+        return AFP_OK;
+
+    /* remove ACL from ressource fork */
+    if ((ret = remove_acl_vfs(vol->ad_path(path, ADFLAGS_HF))) != AFP_OK) {
+        if (errno == ENOENT)
+            return AFP_OK;
+        return ret;
+    }
 
     return AFP_OK;
 }
@@ -404,55 +392,35 @@ static int RF_solaris_remove_acl(VFS_FUNC_ARGS_REMOVE_ACL)
 static int RF_posix_acl(VFS_FUNC_ARGS_ACL)
 {
     EC_INIT;
-    static char buf[ MAXPATHLEN + 1];
     struct stat st;
-    int len;
 
     if (stat(path, &st) == -1)
         EC_FAIL;
 
-    if (S_ISDIR(st.st_mode)) {
-        len = snprintf(buf, MAXPATHLEN, "%s/.AppleDouble",path);
-        if (len < 0 || len >=  MAXPATHLEN)
-            EC_FAIL;
-        /* set acl on .AppleDouble dir first */
-        EC_ZERO_LOG(acl_set_file(buf, type, acl));
-
-        if (type == ACL_TYPE_ACCESS)
-            /* set ACL on ressource fork (".Parent") too */
-            EC_ZERO_LOG(acl_set_file(vol->ad_path(path, ADFLAGS_DIR), type, acl));
-    } else {
+    if (!S_ISDIR(st.st_mode)) {
         /* set ACL on ressource fork */
-        EC_ZERO_LOG(acl_set_file(vol->ad_path(path, ADFLAGS_HF), type, acl));
+        EC_ZERO_ERR( acl_set_file(vol->ad_path(path, ADFLAGS_HF), type, acl), AFPERR_MISC );
     }
     
 EC_CLEANUP:
-    if (ret != 0)
-        return AFPERR_MISC;
-    return AFP_OK;
+    if (errno == ENOENT)
+        EC_STATUS(AFP_OK);
+    EC_EXIT;
 }
 
 static int RF_posix_remove_acl(VFS_FUNC_ARGS_REMOVE_ACL)
 {
     EC_INIT;
-    static char buf[ MAXPATHLEN + 1];
-    int len;
 
-    if (dir) {
-        len = snprintf(buf, MAXPATHLEN, "%s/.AppleDouble",path);
-        if (len < 0 || len >=  MAXPATHLEN)
-            return AFPERR_MISC;
-        /* remove ACL from .AppleDouble/.Parent first */
-        EC_ZERO_LOG_ERR(remove_acl_vfs(vol->ad_path(path, ADFLAGS_DIR)), AFPERR_MISC);
+    if (dir)
+        EC_EXIT_STATUS(AFP_OK);
 
-        /* now remove from .AppleDouble dir */
-        EC_ZERO_LOG_ERR(remove_acl_vfs(buf), AFPERR_MISC);
-    } else {
-        /* remove ACL from ressource fork */
-        EC_ZERO_LOG_ERR(remove_acl_vfs(vol->ad_path(path, ADFLAGS_HF)), AFPERR_MISC);
-    }
+    /* remove ACL from ressource fork */
+    EC_ZERO_ERR( remove_acl_vfs(vol->ad_path(path, ADFLAGS_HF)), AFPERR_MISC );
 
 EC_CLEANUP:
+    if (errno == ENOENT)
+        EC_STATUS(AFP_OK);
     EC_EXIT;
 }
 #endif