Long filename mangling bug in smbd/mangle_hash.c

Forrest W. Christian fwc at mt.net
Wed Dec 3 02:22:03 GMT 2003


This is applicable to the released version of 3.0.  It does not appear to
have been fixed in CVS (at least according to cvsweb).

I have discovered a bug which causes long filenames which do not need to
be mangled to get mangled into 8.3 names.

I can tell you exactly where the problem occurs, but don't have a patch
because it looks like the solution is going to be fairly involved.

All of the description below is from mangle_hash.c

Samba calls the function "is_valid_name" in the process of determining
whether a long filename needs to be mangled because it isn't a legal
microsoft-ish long filename for some reason.  This function checks several
things (such as dots in wierd spots, or reserved filenames, etc) and also
calls the function "has_valid_chars" to determine if all of the chars
are valid.

"has_valid_chars" subsequently calls "isvalid83_w" (in another file) for
each of the characters in the filename to determine if the characters are
actually valid.  Unfortunately, this function only returns a "character is
ok" value if and only if the characters are valid in an 8.3 filename, not
a long filename (which of course permits certain additional characters
which are not valid in an 8.3 filename).

Because of this action, samba then mangles perfectly valid long filenames
into short filenames because it thinks that they aren't perfectly valid
long filenames.

Of particular note, I noticed this with long filenames containing spaces.

I have hacked on my server to force it not to check for invalid characters
(which should never occur in that directory since there is only SMB access
to it).  I did this by adding a "ret=NT_STATUS_OK;" just below the call to
has_valid_chars in is_valid_name.   This appears to have caused samba to
not rewrite the long filenames (while of course breaking the whole intent
of this function call).  Mainly I did this to verify that this was the
root cause.

I will note that this functionality is NOT broken in the hash2 version of
this file.  However these (for some reason) differ substantially and as
such I couldn't just fix the problem by moving code between the two.

I hope that this is helpful.  I'm willing to try any appropriate patches
to work on resolving this.

-fwc at mt.net
Montana Internet Corporation
System Administration


More information about the samba-technical mailing list