diff options
author | Björn Jacke <bj@sernet.de> | 2019-03-02 05:01:28 +0100 |
---|---|---|
committer | Bjoern Jacke <bjacke@samba.org> | 2019-08-29 15:53:30 +0000 |
commit | b8f4be98f5d22eb034a953ebefab88752bf4a099 (patch) | |
tree | a69eac8b40203f7339bc5eaca1037b740e0ea859 /lib/replace | |
parent | 0be320393b85003f65d74e4e6a1b867a8d21eb1c (diff) | |
download | samba-b8f4be98f5d22eb034a953ebefab88752bf4a099.tar.gz |
replace/setxattr: set reasonable and unified errno value in case the EA value was too big
FreeBSD and AIX already set errno to ENAMETOOLONG, this is what we should map
other platforms also to to finally map to the correct NT error code also.
Signed-off-by: Bjoern Jacke <bjacke@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Diffstat (limited to 'lib/replace')
-rw-r--r-- | lib/replace/xattr.c | 54 |
1 files changed, 41 insertions, 13 deletions
diff --git a/lib/replace/xattr.c b/lib/replace/xattr.c index 2420ee1f808..f142ed61723 100644 --- a/lib/replace/xattr.c +++ b/lib/replace/xattr.c @@ -515,19 +515,31 @@ int rep_fremovexattr (int filedes, const char *name) int rep_setxattr (const char *path, const char *name, const void *value, size_t size, int flags) { + int retval = -1; #if defined(HAVE_XATTR_XATTR) #ifndef XATTR_ADDITIONAL_OPTIONS - return setxattr(path, name, value, size, flags); + retval = setxattr(path, name, value, size, flags); + if (retval < 0) { + if (errno == ENOSPC || errno == E2BIG) { + errno = ENAMETOOLONG; + } + } + return retval; #else /* So that we do not recursivly call this function */ #undef setxattr int options = 0; - return setxattr(path, name, value, size, 0, options); + retval = setxattr(path, name, value, size, 0, options); + if (retval < 0) { + if (errno == E2BIG) { + errno = ENAMETOOLONG; + } + } + return retval; #endif #elif defined(HAVE_XATTR_EA) return setea(path, name, value, size, flags); #elif defined(HAVE_XATTR_EXTATTR) - int retval = 0; int attrnamespace; const char *attrname; @@ -571,19 +583,24 @@ int rep_setxattr (const char *path, const char *name, const void *value, size_t if (flags & XATTR_CREATE) myflags |= ATTR_CREATE; if (flags & XATTR_REPLACE) myflags |= ATTR_REPLACE; - return attr_set(path, attrname, (const char *)value, size, myflags); + retval = attr_set(path, attrname, (const char *)value, size, myflags); + if (retval < 0) { + if (errno == E2BIG) { + errno = ENAMETOOLONG; + } + } + return retval; #elif defined(HAVE_ATTROPEN) - int ret = -1; int myflags = O_RDWR; int attrfd; if (flags & XATTR_CREATE) myflags |= O_EXCL; if (!(flags & XATTR_REPLACE)) myflags |= O_CREAT; attrfd = solaris_attropen(path, name, myflags, (mode_t) SOLARIS_ATTRMODE); if (attrfd >= 0) { - ret = solaris_write_xattr(attrfd, value, size); + retval = solaris_write_xattr(attrfd, value, size); close(attrfd); } - return ret; + return retval; #else errno = ENOSYS; return -1; @@ -592,19 +609,31 @@ int rep_setxattr (const char *path, const char *name, const void *value, size_t int rep_fsetxattr (int filedes, const char *name, const void *value, size_t size, int flags) { + int retval = -1; #if defined(HAVE_XATTR_XATTR) #ifndef XATTR_ADDITIONAL_OPTIONS - return fsetxattr(filedes, name, value, size, flags); + retval = fsetxattr(filedes, name, value, size, flags); + if (retval < 0) { + if (errno == ENOSPC) { + errno = ENAMETOOLONG; + } + } + return retval; #else /* So that we do not recursivly call this function */ #undef fsetxattr int options = 0; - return fsetxattr(filedes, name, value, size, 0, options); + retval = fsetxattr(filedes, name, value, size, 0, options); + if (retval < 0) { + if (errno == E2BIG) { + errno = ENAMETOOLONG; + } + } + return retval; #endif #elif defined(HAVE_XATTR_EA) return fsetea(filedes, name, value, size, flags); #elif defined(HAVE_XATTR_EXTATTR) - int retval = 0; int attrnamespace; const char *attrname; @@ -650,17 +679,16 @@ int rep_fsetxattr (int filedes, const char *name, const void *value, size_t size return attr_setf(filedes, attrname, (const char *)value, size, myflags); #elif defined(HAVE_ATTROPEN) - int ret = -1; int myflags = O_RDWR | O_XATTR; int attrfd; if (flags & XATTR_CREATE) myflags |= O_EXCL; if (!(flags & XATTR_REPLACE)) myflags |= O_CREAT; attrfd = solaris_openat(filedes, name, myflags, (mode_t) SOLARIS_ATTRMODE); if (attrfd >= 0) { - ret = solaris_write_xattr(attrfd, value, size); + retval = solaris_write_xattr(attrfd, value, size); close(attrfd); } - return ret; + return retval; #else errno = ENOSYS; return -1; |