Bug 3218 - On FreeBSD, when fetching xattr, only a maximum of 256 bytes are returned
On FreeBSD, when fetching xattr, only a maximum of 256 bytes are returned
Status: RESOLVED FIXED
Product: Samba 3.0
Classification: Unclassified
Component: File Services
3.0.21
x86 OS/2
: P3 normal
: none
Assigned To: Samba Bugzilla Account
Samba QA Contact
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2005-10-26 13:42 UTC by Guenter Kukkukk
Modified: 2005-10-28 15:21 UTC (History)
1 user (show)

See Also:


Attachments
Fix to the xattr attributes emulation through EA in *BSD (4.70 KB, patch)
2005-10-26 13:52 UTC, Timur Bakeyev
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Guenter Kukkukk 2005-10-26 13:42:50 UTC
Hi all, 
 
when requesting xattr on FreeBSD, only 256 bytes EAs are returned. 
This behaviour has been found by Alex Masterov. :-) 
When looking at the code in smbd/trans2.c, it seems to be clear, that 
the code path with the second try with 65536 bytes is not reached. 
(due to wrong return code or different errno). 
 
static BOOL get_ea_value(TALLOC_CTX *mem_ctx, connection_struct *conn, 
files_struct *fsp, 
				const char *fname, char *ea_name, struct 
ea_struct *pea) 
{ 
	/* Get the value of this xattr. Max size is 64k. */ 
	size_t attr_size = 256; 
	char *val = NULL; 
	ssize_t sizeret; 
 
 again: 
 
	val = TALLOC_REALLOC_ARRAY(mem_ctx, val, char, attr_size); 
	if (!val) { 
		return False; 
	} 
 
	if (fsp && fsp->fh->fd != -1) { 
		sizeret = SMB_VFS_FGETXATTR(fsp, fsp->fh->fd, ea_name, val, 
attr_size); 
	} else { 
		sizeret = SMB_VFS_GETXATTR(conn, fname, ea_name, val, 
attr_size); 
	} 
 
	if (sizeret == -1 && errno == ERANGE && attr_size != 65536) { 
		attr_size = 65536; 
		goto again; 
	} 
---- 
 
Timur I. Bakeyev (BAT), who had coded the special FreeBSD xattr additions, 
had a closer look at that - and found some strange oddities. 
He has prepared a patch, which was tested by Alex Masterov. 
AFAIK - the former seen glitches are gone now. :-) 
I do not run a FreeBSD box here - so Alex might comment on his tests. 
He usually is testing with latest svn revision. 
 
BaT told me on irc, that he will send his patch. 
 
Cheers, Guenter Kukkukk
Comment 1 Timur Bakeyev 2005-10-26 13:49:14 UTC
(In reply to comment #0)
> Hi all, 
>  
> BaT told me on irc, that he will send his patch. 
>  
> Cheers, Guenter Kukkukk

And here I do attach promissed patch which addresses this problem.

With regards,
Timur.
Comment 2 Timur Bakeyev 2005-10-26 13:52:32 UTC
Created attachment 1543 [details]
Fix to the xattr attributes emulation through EA in *BSD

The problem with FreeBSD EA API is that it just uses passed buffer and
truncates the result, if it doesn't fit, no erro is generated.

so this patch checks first, how much space is needed and if buffer not big
enough - function returns error.

Similar fixes are done to support additional flags used by setxattr() function.
Comment 3 Alex Masterov 2005-10-26 19:18:34 UTC
I can prove the truth of this report.
 
Before BaT's patch there was problem - OS/2 could set EA with any size supported
by FreeBSD filesystem. But samba could get only first 256 bytes of EA. FreeBSD
system utility getextattr could get full size EA.

After patching with above patch this problem gone, i.e. now samba can get full
size of EA.

Thanks to Timur & Guenter!
Comment 4 Jeremy Allison 2005-10-28 15:21:41 UTC
Applied, thanks !
Jeremy.