]> arthur.barton.de Git - netatalk.git/blobdiff - libatalk/vfs/vfs.c
Add vasprintf compatibility function
[netatalk.git] / libatalk / vfs / vfs.c
index 3dd3ebb4057afab123d6c4d85ea5c074d2e4e157..52c6ea84945b3bffe491df06942d266cc138b404 100644 (file)
@@ -348,31 +348,24 @@ EC_CLEANUP:
     EC_EXIT;
 }
 
-#ifdef HAVE_SOLARIS_ACLS
+#ifdef HAVE_NFSV4_ACLS
 static int RF_solaris_acl(VFS_FUNC_ARGS_ACL)
 {
     static char buf[ MAXPATHLEN + 1];
     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,52 +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 (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 (stat(path, &st) == -1)
+        EC_FAIL;
 
-        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
@@ -496,9 +467,15 @@ static int deletecurdir_ea_osx_chkifempty_loop(const struct vol *vol, struct dir
 static int deletecurdir_ea_osx_loop(const struct vol *vol, struct dirent *de, char *name, void *data _U_, int flag _U_)
 {
     int ret;
-    
-    if ((ret = netatalk_unlink(name)) != 0)
-        return ret;
+    struct stat sb;
+
+    if (strncmp(name, "._", strlen("._")) == 0) {
+        if (lstat(name, &sb) != 0)
+            return -1;
+        if (S_ISREG(sb.st_mode))
+            if ((ret = netatalk_unlink(name)) != 0)
+                return ret;
+    }
 
     return 0;
 }
@@ -509,17 +486,6 @@ static int RF_deletecurdir_ea(VFS_FUNC_ARGS_DELETECURDIR)
 #ifndef HAVE_EAFD
     int err;
     /* delete stray ._AppleDouble files */
-
-    /* first check if there's really no other file besides files starting with ._ */
-    if ((err = for_each_adouble("deletecurdir_ea_osx", ".",
-                                deletecurdir_ea_osx_chkifempty_loop,
-                                vol, NULL, 0)) != 0) {
-        if (err == 1)
-            return AFPERR_DIRNEMPT;
-        return AFPERR_MISC;
-    }
-
-    /* Now delete orphaned ._ files */
     if ((err = for_each_adouble("deletecurdir_ea_osx", ".",
                                 deletecurdir_ea_osx_loop,
                                 vol, NULL, 0)) != 0)
@@ -825,7 +791,7 @@ static struct vfs_ops netatalk_ea_sys = {
  * Tertiary VFS modules for ACLs
  */
 
-#ifdef HAVE_SOLARIS_ACLS
+#ifdef HAVE_NFSV4_ACLS
 static struct vfs_ops netatalk_solaris_acl_adouble = {
     /* validupath:        */ NULL,
     /* rf_chown:          */ NULL,
@@ -893,7 +859,7 @@ void initvol_vfs(struct vol *vol)
     }
 
     /* ACLs */
-#ifdef HAVE_SOLARIS_ACLS
+#ifdef HAVE_NFSV4_ACLS
     vol->vfs_modules[2] = &netatalk_solaris_acl_adouble;
 #endif
 #ifdef HAVE_POSIX_ACLS