📜 ⬆️ ⬇️

Samba and forbidden characters

Samba (samba) under Linux. This amazing software gave Linux users the opportunity to connect with the world of Windows.
I remember that wonderful feeling when my first samba server appeared in the local network. Ah, there was a time!

But the post is not about that. Not by hearsay I know that many are annoyed by the limited support for special characters in Windows. But this is no reason to abandon them, is not it?

image
')
Details of my misadventures and (almost) a happy ending under the cut. Let's get started!

I am fond of collecting films. At first they were placed on one disk and it was easy. Then there were more disks, helped by paper and Excel. But all good things come to an end and had to think about creating a full-fledged database. One of the consequences of this development appeared virtual folders / lists of films.

Beg a lyrical digression. Samba has one great feature - working with symlinks. And if these symlinks do not lead to an accessible resource, then they are not visible. This allows you to have a directory (and not one) in which each position is a symlink to a specific repository. If the disk is connected, then the symlink is displayed as an accessible directory. If not, then the directory is not displayed at all. For this reason (and also for other, unrelated to the topic), samba and similar folders have been used for many years (visible in players, Windows, and on Linux clients).

However, this idyll is destroyed by the fact that having a colon, for example, turns an excellent view folder (here I deliberately inserted a colon, later I will explain why this particular film was chosen): 2008 - Babylon N.E. - Babylon: AD to this: 2NIQRO ~ 7

What to do?


At first, I mistakenly looked in the direction of the mapchars mount option. But she really did not solve anything, and she additionally could lead to strange file names.

I understood that you need to look for something that can replace file names on the fly. That means auto substitution. But there was still no such modules, or they did not work the way we would like. During the search, the third version of the samba has become stable. And it appeared so-called. Stackable VFS modules, i.e. virtual file system modules. That was what I was looking for!

However, the module I needed was not found. The samba version from the third turned into the fourth one and I was close to trying to write the module myself (although I am only remotely familiar with system programming). But the ongoing search led me to the vfs_catia module, which was created to solve problems with Catia CAD, which also creates names with forbidden characters, but did exactly what was required. Its full functionality is revealed from the version of samba 3.5.0 and further. I have been testing on versions 4.1.x for quite some time.

Further was a matter of technique. The system I use - Debian - already has a samba-vfs-modules package containing this plugin. It was installed and configured to replace illegal characters with their counterparts (config file: /etc/samba/smb.conf, section [global]):

# 002: maps illegal symbols # vfs_catia, removed default translations: 0x20:0xb1 # vfs_catia, list of special characters: # Unix & replacement chars: # 0x22: " 0xa8: ¨ # 0x2a: * 0xa4: ¤ # 0x2f: / 0xf8: ø (forbidden range, should never exists in names) # 0x3a: : 0xf7: ÷ # 0x3c: < 0xab: « # 0x3e: > 0xbb: » # 0x3f: ? 0xbf: ¿ # 0x5c: \ 0xff: ÿ (forbidden range) # 0x7c: | 0xa6: ¦ # 0x20: 0xb1: ± vfs objects = catia catia:mappings = 0x22:0xa8,0x2a:0xa4,0x2f:0xf8,0x3a:0xf7,0x3c:0xab,0x3e:0xbb,0x3f:0xbf,0x5c:0xff,0x7c:0xa6 


I added comments for myself to understand which characters are replaced by their visual counterparts. I hope it will be useful not only for me.

Happy ending


After adding the code, we overload the samba daemon and the magic in action:
2015 - Terminator ÷ Genesis - Terminator Genisys

It is worth noting that the replacements work in both directions, i.e. working with the same file is transparent and without damaging the original name in the system. Although if you try, you can, changing the character to one of the usual. But in my example there is no such thing.

Now let me remind you why I chose the film Babylon N. E as the first example ... The point is that the dot at the end of the name of the file or directory in the Windows file system is invalid. That is why 2008 - Babylon N.E. - Babylon AD still shows up as 2XJW59 ~ H
This is the very spoon of tar, in a large barrel of honey. So far I don’t know how to replace the dot at the end, but not all the dots in a row, and I will be grateful to everyone who responds and helps to close the last mosaic element.

Thank you for your attention and may the Force be with you!

Source: https://habr.com/ru/post/270877/


All Articles