From 78f4401a1e5d50097be8dd8458273ef1d4a548a7 Mon Sep 17 00:00:00 2001
From: "Erich E. Hoover" <erich.e.hoover@gmail.com>
Date: Tue, 19 Aug 2014 22:10:49 -0600
Subject: [PATCH] ntdll: Implement retrieving DOS attributes in
 NtQueryInformationFile.

---
 configure.ac          | 12 ++++++++++++
 dlls/ntdll/file.c     | 16 ++++++++++++++++
 include/wine/port.h   |  8 ++++++++
 libs/port/Makefile.in |  4 +++-
 libs/port/xattr.c     | 39 +++++++++++++++++++++++++++++++++++++++
 5 files changed, 78 insertions(+), 1 deletion(-)
 create mode 100644 libs/port/xattr.c

diff --git a/configure.ac b/configure.ac
index 9385d20..60d43d3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -85,6 +85,7 @@ AC_ARG_WITH(udev,      AS_HELP_STRING([--without-udev],[do not use udev (plug an
 AC_ARG_WITH(v4l2,      AS_HELP_STRING([--without-v4l2],[do not use v4l2 (video capture)]))
 AC_ARG_WITH(vkd3d,     AS_HELP_STRING([--without-vkd3d],[do not use vkd3d (Direct3D 12 support)]))
 AC_ARG_WITH(vulkan,    AS_HELP_STRING([--without-vulkan],[do not use Vulkan]))
+AC_ARG_WITH(xattr,     AS_HELP_STRING([--without-xattr],[do not use xattr (security attributes support)]))
 AC_ARG_WITH(xcomposite,AS_HELP_STRING([--without-xcomposite],[do not use the Xcomposite extension]),
             [if test "x$withval" = "xno"; then ac_cv_header_X11_extensions_Xcomposite_h=no; fi])
 AC_ARG_WITH(xcursor,   AS_HELP_STRING([--without-xcursor],[do not use the Xcursor extension]),
@@ -711,6 +712,17 @@ AC_CHECK_HEADERS([libprocstat.h],,,
 #include <sys/socket.h>
 #endif])
 
+if test "x$with_xattr" != "xno"
+then
+    AC_CHECK_HEADERS(attr/xattr.h, [HAVE_XATTR=1])
+fi
+if test "x$with_xattr" = "xyes"
+then
+    WINE_ERROR_WITH(xattr,[test "x$HAVE_XATTR" = "x"],[xattr ${notice_platform}development files \
+not found. Wine will be built without extended attribute support, which probably isn't what you \
+want. You will need to install ${notice_platform}development packages of libattr at the very least.])
+fi
+
 dnl **** Check for working dll ****
 
 AC_SUBST(DLLFLAGS,"-D_REENTRANT")
diff --git a/dlls/ntdll/file.c b/dlls/ntdll/file.c
index b70477e..2c99c1d 100644
--- a/dlls/ntdll/file.c
+++ b/dlls/ntdll/file.c
@@ -127,6 +127,22 @@ static const WCHAR ntfsW[] = {'N','T','F','S'};
 NTSTATUS FILE_DecodeSymlink(const char *unix_src, char *unix_dest, USHORT *unix_dest_len,
                             DWORD *tag, ULONG *flags, BOOL *is_dir);
 
+/* Match the Samba conventions for storing DOS file attributes */
+#define SAMBA_XATTR_DOS_ATTRIB XATTR_USER_PREFIX "DOSATTRIB"
+/* We are only interested in some attributes, the others have corresponding Unix attributes */
+#define XATTR_ATTRIBS_MASK     (FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM)
+
+/* decode the xattr-stored DOS attributes */
+static inline int get_file_xattr( char *hexattr, int attrlen )
+{
+    if (attrlen > 2 && hexattr[0] == '0' && hexattr[1] == 'x')
+    {
+        hexattr[attrlen] = 0;
+        return strtol( hexattr+2, NULL, 16 ) & XATTR_ATTRIBS_MASK;
+    }
+    return 0;
+}
+
 /* fetch the attributes of a file */
 static inline ULONG get_file_attributes( const struct stat *st )
 {
diff --git a/include/wine/port.h b/include/wine/port.h
index 19c8682..eaa23bc 100644
--- a/include/wine/port.h
+++ b/include/wine/port.h
@@ -344,6 +344,14 @@ int usleep (unsigned int useconds);
 
 extern int mkstemps(char *template, int suffix_len);
 
+/* Extended attribute functions */
+
+#ifndef XATTR_USER_PREFIX
+# define XATTR_USER_PREFIX "user."
+#endif
+
+extern int xattr_fget( int filedes, const char *name, void *value, size_t size );
+
 /* Interlocked functions */
 
 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
diff --git a/libs/port/Makefile.in b/libs/port/Makefile.in
index db27249..790fd96 100644
--- a/libs/port/Makefile.in
+++ b/libs/port/Makefile.in
@@ -109,4 +109,6 @@ C_SRCS = \
 	usleep.c \
 	utf8.c \
 	wctomb.c \
-	wctype.c
+	wctype.c \
+	xattr.c
+
diff --git a/libs/port/xattr.c b/libs/port/xattr.c
new file mode 100644
index 0000000..94b7713
--- /dev/null
+++ b/libs/port/xattr.c
@@ -0,0 +1,39 @@
+/*
+ * extended attributes functions
+ *
+ * Copyright 2014 Erich E. Hoover
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include "config.h"
+#include "wine/port.h"
+
+#if defined(HAVE_ATTR_XATTR_H)
+# include <attr/xattr.h>
+#endif
+
+#include <ctype.h>
+#include <errno.h>
+
+int xattr_fget( int filedes, const char *name, void *value, size_t size )
+{
+#if defined(HAVE_ATTR_XATTR_H)
+    return fgetxattr( filedes, name, value, size );
+#else
+    errno = ENOSYS;
+    return -1;
+#endif
+}
-- 
1.9.1

