]> arthur.barton.de Git - netatalk.git/blobdiff - libatalk/vfs/ea_sys.c
Ignore object files
[netatalk.git] / libatalk / vfs / ea_sys.c
index e94956c21d44ce2e5c2f75f87133c201c7d81543..f9b305aa89764360454e95b6d9479bf2a2b85d98 100644 (file)
@@ -1,5 +1,5 @@
 /*
-  $Id: ea_sys.c,v 1.4 2009-12-04 10:26:10 franklahm Exp $
+  $Id: ea_sys.c,v 1.8 2010-04-13 08:05:06 franklahm Exp $
   Copyright (c) 2009 Frank Lahm <franklahm@gmail.com>
 
   This program is free software; you can redistribute it and/or modify
@@ -49,6 +49,7 @@
 #include <atalk/vfs.h>
 #include <atalk/util.h>
 #include <atalk/unix.h>
+#include <atalk/compat.h>
 
 #ifndef ENOATTR
 #define ENOATTR ENODATA
@@ -97,7 +98,7 @@ int sys_get_easize(VFS_FUNC_ARGS_EA_GETSIZE)
         memset(rbuf, 0, 4);
         *rbuflen += 4;
         switch(errno) {
-        case ELOOP:
+        case OPEN_NOFOLLOW_ERRNO:
             /* its a symlink and client requested O_NOFOLLOW  */
             LOG(log_debug, logtype_afpd, "sys_getextattr_size(%s): encountered symlink with kXAttrNoFollow", uname);
             return AFP_OK;
@@ -172,7 +173,7 @@ int sys_get_eacontent(VFS_FUNC_ARGS_EA_GETCONTENT)
         memset(rbuf, 0, 4);
         *rbuflen += 4;
         switch(errno) {
-        case ELOOP:
+        case OPEN_NOFOLLOW_ERRNO:
             /* its a symlink and client requested O_NOFOLLOW  */
             LOG(log_debug, logtype_afpd, "sys_getextattr_content(%s): encountered symlink with kXAttrNoFollow", uname);
             return AFP_OK;
@@ -234,7 +235,7 @@ int sys_list_eas(VFS_FUNC_ARGS_EA_LIST)
     }
 
     if (ret == -1) switch(errno) {
-        case ELOOP:
+        case OPEN_NOFOLLOW_ERRNO:
             /* its a symlink and client requested O_NOFOLLOW */
             ret = AFPERR_BADTYPE;
         default:
@@ -315,11 +316,15 @@ int sys_set_ea(VFS_FUNC_ARGS_EA_SET)
 
     if (ret == -1) {
         switch(errno) {
-        case ELOOP:
+        case OPEN_NOFOLLOW_ERRNO:
             /* its a symlink and client requested O_NOFOLLOW  */
             LOG(log_debug, logtype_afpd, "sys_set_ea(%s/%s): encountered symlink with kXAttrNoFollow",
                 uname, attruname);
             return AFP_OK;
+        case EEXIST:
+            LOG(log_debug, logtype_afpd, "sys_set_ea(%s/%s): EA already exists",
+                uname, attruname);
+            return AFPERR_EXIST;
         default:
             LOG(log_error, logtype_afpd, "sys_set_ea(%s/%s): error: %s", uname, attruname, strerror(errno));
             return AFPERR_MISC;
@@ -360,7 +365,7 @@ int sys_remove_ea(VFS_FUNC_ARGS_EA_REMOVE)
 
     if (ret == -1) {
         switch(errno) {
-        case ELOOP:
+        case OPEN_NOFOLLOW_ERRNO:
             /* its a symlink and client requested O_NOFOLLOW  */
             LOG(log_debug, logtype_afpd, "sys_remove_ea(%s/%s): encountered symlink with kXAttrNoFollow", uname);
             return AFP_OK;
@@ -376,16 +381,37 @@ int sys_remove_ea(VFS_FUNC_ARGS_EA_REMOVE)
     return AFP_OK;
 }
 
-/* --------------------- 
-   copy EA 
-*/
+/*
+ * @brief Copy EAs
+ *
+ * @note Supports *at semantics, therfor switches back and forth between sfd and cwd
+ */
 int sys_ea_copyfile(VFS_FUNC_ARGS_COPYFILE)
 {
        int ret = 0;
+    int cwd = -1;
        ssize_t size;
        char *names = NULL, *end_names, *name, *value = NULL;
        unsigned int setxattr_ENOTSUP = 0;
 
+    if (sfd != -1) {
+        if ((cwd = open(".", O_RDONLY)) == -1) {
+            LOG(log_error, logtype_afpd, "sys_ea_copyfile: cant open cwd: %s",
+                strerror(errno));
+            ret = -1;
+            goto getout;
+        }
+    }
+
+    if (sfd != -1) {
+        if (fchdir(sfd) == -1) {
+            LOG(log_error, logtype_afpd, "sys_ea_copyfile: cant chdir to sfd: %s",
+                strerror(errno));
+            ret = -1;
+            goto getout;
+        }
+    }
+
        size = sys_listxattr(src, NULL, 0);
        if (size < 0) {
                if (errno != ENOSYS && errno != ENOTSUP) {
@@ -407,6 +433,15 @@ int sys_ea_copyfile(VFS_FUNC_ARGS_COPYFILE)
                end_names = names + size;
        }
 
+    if (sfd != -1) {
+        if (fchdir(cwd) == -1) {
+            LOG(log_error, logtype_afpd, "sys_ea_copyfile: cant chdir to cwd: %s",
+                strerror(errno));
+            ret = -1;
+            goto getout;
+        }
+    }
+
        for (name = names; name != end_names; name = strchr(name, '\0') + 1) {
                void *old_value;
 
@@ -414,6 +449,15 @@ int sys_ea_copyfile(VFS_FUNC_ARGS_COPYFILE)
                if (!*name)
                        continue;
 
+        if (sfd != -1) {
+            if (fchdir(sfd) == -1) {
+                LOG(log_error, logtype_afpd, "sys_ea_copyfile: cant chdir to sfd: %s",
+                    strerror(errno));
+                ret = -1;
+                goto getout;
+            }
+        }
+
                size = sys_getxattr (src, name, NULL, 0);
                if (size < 0) {
                        ret = -1;
@@ -429,6 +473,16 @@ int sys_ea_copyfile(VFS_FUNC_ARGS_COPYFILE)
                        ret = -1;
                        continue;
                }
+
+        if (sfd != -1) {
+            if (fchdir(cwd) == -1) {
+                LOG(log_error, logtype_afpd, "sys_ea_copyfile: cant chdir to cwd: %s",
+                    strerror(errno));
+                ret = -1;
+                goto getout;
+            }
+        }
+
                if (sys_setxattr(dst, name, value, size, 0) != 0) {
                        if (errno == ENOTSUP)
                                setxattr_ENOTSUP++;
@@ -449,6 +503,9 @@ int sys_ea_copyfile(VFS_FUNC_ARGS_COPYFILE)
        }
 
 getout:
+    if (cwd != -1)
+        close(cwd);
+        
        free(value);
        free(names);