PATCH: Fix for *xattr() support on Mac OS X

Michael Bennett michaelone-gen at flylady.net
Tue Aug 29 17:46:19 GMT 2006


In lib/system.c the wrappers for extended attribute calls detect the  
presence of the functions getxattr(), fgetxattr(), listxattr(),  
flistxattr(), removexattr(), fremovexattr(),  setxattr(), and  
fsetxattr() for Mac OS X, but the parameters for these function calls  
are different on this operating system.

For example, getxattr() takes two extra parameters, one is the  
position within the extended attribute (used for the resource fork)  
and the other is a bitmask for options (http://developer.apple.com/ 
documentation/Darwin/Reference/Manpages/man2/getxattr.2.html).  The  
default setting for the first parameter is simple, since samba  
doesn't deal with the resource fork anyway.  The second only has one  
value you can set it to: XATTR_NOFOLLOW.  Setting this is turns  
getxattr() into the Linux equivalent of lgetxattr(), so for normal  
operation, 0 will suffice.

These extended attribute functions first appeared in Mac OS X 10.4.0,  
so paring them with HAVE_GETXATTR, etc, ensures that Samba works on  
older versions.

-- Michael Bennett
(patch below)


--- system.c	2006-08-29 12:31:24.000000000 -0400
+++ system_osx.c	2006-08-29 12:57:43.000000000 -0400
@@ -1417,7 +1417,11 @@
ssize_t sys_getxattr (const char *path, const char *name, void  
*value, size_t size)
{
#if defined(HAVE_GETXATTR)
+#if defined(DARWINOS)
+	return getxattr(path, name, value, size, 0, 0);
+#else
	return getxattr(path, name, value, size);
+#endif
#elif defined(HAVE_GETEA)
	return getea(path, name, value, size);
#elif defined(HAVE_EXTATTR_GET_FILE)
@@ -1462,6 +1466,8 @@
{
#if defined(HAVE_LGETXATTR)
	return lgetxattr(path, name, value, size);
+#elif defined(HAVE_GETXATTR) && defined(DARWINOS)
+	return getxattr(path, name, value, size, 0, XATTR_NOFOLLOW);
#elif defined(HAVE_LGETEA)
	return lgetea(path, name, value, size);
#elif defined(HAVE_EXTATTR_GET_LINK)
@@ -1501,7 +1507,11 @@
ssize_t sys_fgetxattr (int filedes, const char *name, void *value,  
size_t size)
{
#if defined(HAVE_FGETXATTR)
+#if defined(DARWINOS)
+	return fgetxattr(filedes, name, value, size, 0, 0);
+#else
	return fgetxattr(filedes, name, value, size);
+#endif
#elif defined(HAVE_FGETEA)
	return fgetea(filedes, name, value, size);
#elif defined(HAVE_EXTATTR_GET_FD)
@@ -1702,7 +1712,11 @@
ssize_t sys_listxattr (const char *path, char *list, size_t size)
{
#if defined(HAVE_LISTXATTR)
+#if defined(DARWINOS)
+	return listxattr(path, list, size, 0);
+#else
	return listxattr(path, list, size);
+#endif
#elif defined(HAVE_LISTEA)
	return listea(path, list, size);
#elif defined(HAVE_EXTATTR_LIST_FILE)
@@ -1721,6 +1735,8 @@
{
#if defined(HAVE_LLISTXATTR)
	return llistxattr(path, list, size);
+#elif defined(HAVE_LISTXATTR) && defined(DARWINOS)
+	return listxattr(path, list, size, XATTR_NOFOLLOW);
#elif defined(HAVE_LLISTEA)
	return llistea(path, list, size);
#elif defined(HAVE_EXTATTR_LIST_LINK)
@@ -1738,7 +1754,11 @@
ssize_t sys_flistxattr (int filedes, char *list, size_t size)
{
#if defined(HAVE_FLISTXATTR)
+#if defined(DARWINOS)
+	return flistxattr(filedes, list, size, 0);
+#else
	return flistxattr(filedes, list, size);
+#endif
#elif defined(HAVE_FLISTEA)
	return flistea(filedes, list, size);
#elif defined(HAVE_EXTATTR_LIST_FD)
@@ -1756,7 +1776,11 @@
int sys_removexattr (const char *path, const char *name)
{
#if defined(HAVE_REMOVEXATTR)
+#if defined(DARWINOS)
+	return removexattr(path, name, 0);
+#else
	return removexattr(path, name);
+#endif
#elif defined(HAVE_REMOVEEA)
	return removeea(path, name);
#elif defined(HAVE_EXTATTR_DELETE_FILE)
@@ -1783,6 +1807,8 @@
{
#if defined(HAVE_LREMOVEXATTR)
	return lremovexattr(path, name);
+#elif defined(HAVE_REMOVEXATTR) && defined(DARWINOS)
+	return removexattr(path, name, XATTR_NOFOLLOW);
#elif defined(HAVE_LREMOVEEA)
	return lremoveea(path, name);
#elif defined(HAVE_EXTATTR_DELETE_LINK)
@@ -1808,7 +1834,11 @@
int sys_fremovexattr (int filedes, const char *name)
{
#if defined(HAVE_FREMOVEXATTR)
+#if defined(DARWINOS)
+	return fremovexattr(filedes, name, 0);
+#else
	return fremovexattr(filedes, name);
+#endif
#elif defined(HAVE_FREMOVEEA)
	return fremoveea(filedes, name);
#elif defined(HAVE_EXTATTR_DELETE_FD)
@@ -1839,7 +1869,11 @@
int sys_setxattr (const char *path, const char *name, const void  
*value, size_t size, int flags)
{
#if defined(HAVE_SETXATTR)
+#if defined(DARWINOS)
+	return setxattr(path, name, value, size, 0, flags);
+#else
	return setxattr(path, name, value, size, flags);
+#endif
#elif defined(HAVE_SETEA)
	return setea(path, name, value, size, flags);
#elif defined(HAVE_EXTATTR_SET_FILE)
@@ -1888,6 +1922,8 @@
{
#if defined(HAVE_LSETXATTR)
	return lsetxattr(path, name, value, size, flags);
+#elif defined(HAVE_SETXATTR) && defined(DARWINOS)
+	return setxattr(path, name, value, size, 0, flags | XATTR_NOFOLLOW);
#elif defined(LSETEA)
	return lsetea(path, name, value, size, flags);
#elif defined(HAVE_EXTATTR_SET_LINK)
@@ -1936,7 +1972,11 @@
int sys_fsetxattr (int filedes, const char *name, const void *value,  
size_t size, int flags)
{
#if defined(HAVE_FSETXATTR)
+#if defined(DARWINOS)
+	return fsetxattr(filedes, name, value, size, 0, flags);
+#else
	return fsetxattr(filedes, name, value, size, flags);
+#endif
#elif defined(HAVE_FSETEA)
	return fsetea(filedes, name, value, size, flags);
#elif defined(HAVE_EXTATTR_SET_FD)


More information about the samba-technical mailing list