Bug 11207 - handling of trailing period and trailing space is no longer forbidden
Summary: handling of trailing period and trailing space is no longer forbidden
Status: RESOLVED WONTFIX
Alias: None
Product: Samba 4.1 and newer
Classification: Unclassified
Component: File services (show other bugs)
Version: unspecified
Hardware: All All
: P5 normal (vote)
Target Milestone: ---
Assignee: Ralph Böhme
QA Contact: Samba QA Contact
URL: http://support.microsoft.com/en-us/kb...
Keywords:
Depends on:
Blocks:
 
Reported: 2015-04-08 13:32 UTC by Björn Jacke
Modified: 2021-01-07 12:31 UTC (History)
3 users (show)

See Also:


Attachments
patch to allow trailing spcace and trailing period in smbd/hash2 (1.00 KB, patch)
2015-04-17 12:48 UTC, Björn Jacke
bjacke: review? (jra)
Details
patch to allow trailing spcace and trailing period in smbd/hash (1.48 KB, patch)
2015-04-17 12:50 UTC, Björn Jacke
no flags Details
0001-smbd-mangle-hash-tailing-period-and-space-are-allowe.patch (1.00 KB, patch)
2015-04-17 13:14 UTC, Björn Jacke
no flags Details
patch to allow trailing spcace and trailing period in smbd/hash (1.30 KB, patch)
2015-04-17 13:16 UTC, Björn Jacke
bjacke: review? (jra)
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Björn Jacke 2015-04-08 13:32:45 UTC
trailing period and trailing space, which are (usually) not allowed on NTFS and SMB should be handled gracefully by vfs_fruit for Mac clients, see http://support.microsoft.com/en-us/kb/kbview/117258 :

   Macintosh ANSI                                                  Unicode
   -----------------------------------------------------------------------
   Space (0x20)                                                     0xF028
   only if occurring as the last character of the name

   Period (0x2E)                                                    0xF029
   only if occurring as the last character of the name

see also bug 11206 for a related issues with Linux cifs vfs.
Comment 1 Björn Jacke 2015-04-16 13:40:29 UTC
see checks like in is_legal_name() from source3/smbd/mangle_hash2.c
Comment 2 Björn Jacke 2015-04-16 17:30:20 UTC
ralf and i tested today with w2k8r2 and with win2012r2 ... they no longer disallow trailing dot and trailing space.

creation of such names is possible via smb. explorer also shows those files but renaming is not possible so the windows api or explorer can'handle them correctly.

as it' possible to create them via smb though i think we also don't need to handle them in a special way in fruit. instrad i suggest we also remove the checks in is_legal_name() to get the same behaviour as current windows versions.
Comment 3 Jeremy Allison 2015-04-16 18:44:47 UTC
Oh wow. Does that change in filename semantics match the MS-docs on what is a permissable filename ? So currently smbclient can create filenames on Windows that explorer can't rename ? Can explorer delete them ? What about powershell ?
Comment 4 Björn Jacke 2015-04-17 08:37:07 UTC
also deleting is not possible. same with powershell. both say that those files do not exist when you want to delete or rename them.
Comment 5 Björn Jacke 2015-04-17 12:48:51 UTC
Created attachment 10961 [details]
patch to allow trailing spcace and trailing period in smbd/hash2
Comment 6 Björn Jacke 2015-04-17 12:50:33 UTC
Created attachment 10962 [details]
patch to allow trailing spcace and trailing period in smbd/hash

(shouldn't we use a common function in hash/hash2 to check for illegal names?)
Comment 7 Björn Jacke 2015-04-17 12:58:34 UTC
(In reply to Jeremy Allison from comment #3)
In

https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247%28v=vs.85%29.aspx

I don't find mentioning of trailing perio or space to be illegal. I thought in previous times it was mentioned there.

A comment also says:

--snip--
I wanted to make some corrections and answer a few questions.  Note, I don't work for MS and probably know more about linux than MS, but I know a few things.  To test many of these corrections/answers, I used the 'bash' shell from the cygwin distribution (from cygwin.com).  It allows you to get around cmd.exe restrictions, but cannot, obviously, do things that the OS doesn't support.


Note that while bash can create Windows incompatible file names (like ones with '*, ?,  |, >, etc...'), those that are really NT incompatible will be 'faked' and only display correctly in cygwin (it substitutes a character from the private-code page area in the Unicode character set as a place holder.  It will work as the real character in cygwin-based programs, but ISN'T win-compatible.  I won't bother to address characters that aren't "REAL" -- i.e. they will display correctly under Windows programs).
--snap--
Comment 8 Björn Jacke 2015-04-17 13:00:30 UTC
and this part of the comment actually:

--snip--
Last point:  About spaces and dots in filenames and directories.   The limits are in the windows shell -- not in Windows or NT.   Using 'bash', you can create files with spaces (or dots), both, at the beginning and end of a filename.  You can then list and open those files in explorer, and you can 'list' them in the shell (cmd.exe), but you won't necessarily be able to open them from the shell (especially trailing spaces and dots).   The shell strips them out.  If you want such things, use another shell, but WARNING -- if you put spaces after your filename, it will be hard to figure out how many there are.   To do it, you'd have to dump your directory listing to a file and do a hexdump of the file to see how many space characters there actually are.   Not a major problem, but still a bit of a pain.
--snap--
Comment 9 Ralph Böhme 2015-04-17 13:09:02 UTC
(In reply to Björn Jacke from comment #7)
Somewhere on the page it says:

  Do not end a file or directory name with a space or a period
Comment 10 Björn Jacke 2015-04-17 13:14:28 UTC
Created attachment 10963 [details]
0001-smbd-mangle-hash-tailing-period-and-space-are-allowe.patch

updated patch that removes now unused variable also
Comment 11 Björn Jacke 2015-04-17 13:16:29 UTC
Created attachment 10964 [details]
patch to allow trailing spcace and trailing period in smbd/hash

updated patch that removes now unused variable also
Comment 12 Jeremy Allison 2015-04-17 17:46:52 UTC
(In reply to Björn Jacke from comment #4)

Isn't this a DOS bug ? I can sit in an smbclient loop creating files in a directory that no Windows command can remove....
Comment 13 Johnny Martin 2015-06-18 22:21:07 UTC
Applied the patches for both mangle_hash.c and mangle_hash2.c. A directory with a space at the end became unmangled but it appears empty on OS X 10.10.3.
Comment 14 Björn Jacke 2015-06-19 06:34:23 UTC
a windows server allows tailing spaces but OS X clients map the trailing space to 0xF028, see bug 11255.

Same like windows client behave weird if there are files with unmapped trailing space or period, OS X clients also will.

Nonetheless the patches on the server side do what current Windows servers also do these days.
Comment 15 Björn Jacke 2017-11-06 23:30:03 UTC
I mean always map tailing space (0x20) on local disc to 0xF028 on the wire and local trailing period (0x2E) to 0xF029 on the wire.
Comment 16 Björn Jacke 2017-11-06 23:31:59 UTC
(last comment was meant to go to bug 11255)
Comment 17 Björn Jacke 2017-11-07 13:39:49 UTC
(In reply to Björn Jacke from comment #14)
> Nonetheless the patches on the server side do what current Windows servers also > do these days.

a file with a trailing dot can be created via smbclient but this is actually like a DOS attack because it cannot be deleted/renamed on the windows site. I reported that to the ms secure team when we discussed it here in 2015 but the behavour is still the same these days. Such a trailing dot/space file created by smbclient is also served via SMB by Windows clients "as is" as a plain trailing character. This seems not to be the desired behaviour for Windows either though but that is not our business. I just checked that the MS docs currently clearly forbid trailing dot and space.

The best solution for Samba should be to map trailing dot/space to the SFM mapped unicode codepoints and this is what bug 11255 is all about.
Comment 18 Claudius Ellsel 2021-01-06 22:30:28 UTC
To my understanding this is the corresponding patch that will implement the suggested behaviour from https://bugzilla.samba.org/show_bug.cgi?id=11255?

Why is it resolved as wontfix then?
Comment 19 Jeremy Allison 2021-01-06 22:42:10 UTC
It's WONTFIX because this patch is incorrect. Names ending in space or dot are ILLEGAL FILENAMES in the SMB2 protocol. Ignoring that will cause great problems.
Comment 20 Claudius Ellsel 2021-01-07 12:31:27 UTC
Ah, I didn't look at the patch itself. I thought it would introduce the substitution of those characters by the private unicode ones as suggested in the bug I linked, but it turns out this is just deleting the check which would preserve the characters leading to problems on Windows. So yes, totally understandable that this way is not accepted as a patch.