Bug 421624 - refactor modern discovery out of NB discovery
Summary: refactor modern discovery out of NB discovery
Status: RESOLVED FIXED
Alias: None
Product: kio-extras
Classification: Frameworks and Libraries
Component: Samba (show other bugs)
Version: 20.04
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Harald Sitter
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-05-16 15:51 UTC by Vladimir Yerilov
Modified: 2020-05-25 09:04 UTC (History)
4 users (show)

See Also:
Latest Commit:
Version Fixed In: 20.04.2
Sentry Crash Report:


Attachments
detailed log (12.75 KB, text/plain)
2020-05-18 14:46 UTC, Vladimir Yerilov
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Vladimir Yerilov 2020-05-16 15:51:09 UTC
SUMMARY
Irrelevant error when trying to navigate to smb shares list: "Unable to find any workgroups in your local network. This might be caused by an enabled firewall."

STEPS TO REPRODUCE
1. Have SMB v1 or v2 only share.
2. Navigate to Network -> Shared Folders (SMB)
3. ???
4. The above quoted misleading message.

OBSERVED RESULT
Nothing, just an error. In terminal I see the following (Dolphin 20.04.0):
```
QFSFileEngine::open: No file name specified
QFSFileEngine::open: No file name specified
QFSFileEngine::open: No file name specified
```
In case of Dolphin 20.07.70 I see this:
```
QFSFileEngine::open: No file name specified
QFSFileEngine::open: No file name specified
QFSFileEngine::open: No file name specified
kf5.kio.core: Invalid URL: QUrl("")
QFSFileEngine::open: No file name specified
```
One more error.

EXPECTED RESULT
List of shares in the local network.

SOFTWARE/OS VERSIONS
Windows: 
macOS: 
Linux/KDE Plasma: Manjaro Linux 20.0, kernel 5.7-git
(available in About System)
KDE Plasma Version: 5.18.5
KDE Frameworks Version: 5.70.0
Qt Version: 5.14.2

ADDITIONAL INFORMATION
This message doesn't appear if entering the full address like "smb://192.168.1.1". Also shares on that particular device are listed normally when entering full address.
Comment 1 Patrick Silva 2020-05-16 23:47:17 UTC
On my system Dolphin finds the samba server after the step 2, but it can't find the shares, it just shows an inline error message. Possibly there is some bug with recent samba versions because Dolphin started to fail with samba shares on my system (Arch) when samba 4.10.10-2 was updated. Futhermore, nautilus and pcmanfm also fail to find my samba shares and other Arch users are facing problems with samba since recent updates
https://bbs.archlinux.org/viewtopic.php?id=254083

smb://server/share works on my system too.

Operating System: Arch Linux 
KDE Plasma Version: 5.18.90
KDE Frameworks Version: 5.70.0
Qt Version: 5.15.0 rc2
Comment 3 Vladimir Yerilov 2020-05-18 12:44:23 UTC
Hi Harald,
Thank you for the link! Now I can provide more details.

First of all, preliminary info:

The KDE Frameworks and Dolphin version you're running:
5.70.0 and 20.04.0 respectively;

The libsmbclient version installed:
smbclient version is 4.12.2-3;

The type and version of the smb server:
"Version 3.6.25" according to smbd -V on the server side. No role specified in smb.conf.

Now let's get to logs:
```
[openm@reiwa ~]$ export KDE_FORK_SLAVES=1
[openm@reiwa ~]$ export QT_MESSAGE_PATTERN='(%{pid})/(%{category}) %{function}: %{message}'
[openm@reiwa ~]$ export QT_LOGGING_RULES='log_kio_smb=true'
[openm@reiwa ~]$ dolphin --new-window smb://
(144764)/(log_kio_smb) unknown: Using libsmbclient library version 4.12.2
(144764)/(log_kio_smb) unknown: auth_initialize_smbc
(144764)/(log_kio_smb) unknown: smbc_new_context call
(144764)/(log_kio_smb) unknown: Setting debug level to: 0
(144764)/(log_kio_smb) unknown: QUrl("smb://")
(144764)/(log_kio_smb) unknown: checkURL  QUrl("smb://")
(144764)/(log_kio_smb) unknown: updateCache  ""
(144773)/(log_kio_smb) unknown: Using libsmbclient library version 4.12.2
(144773)/(log_kio_smb) unknown: auth_initialize_smbc
(144773)/(log_kio_smb) unknown: smbc_new_context call
(144775)/(log_kio_smb) unknown: Using libsmbclient library version 4.12.2
(144775)/(log_kio_smb) unknown: auth_initialize_smbc
(144775)/(log_kio_smb) unknown: smbc_new_context call
(144773)/(log_kio_smb) unknown: Setting debug level to: 0
(144773)/(log_kio_smb) unknown: QUrl("smb://")
(144773)/(log_kio_smb) unknown: QUrl("smb://")
(144773)/(log_kio_smb) unknown: checkURL  QUrl("smb://")
(144773)/(log_kio_smb) unknown: updateCache  ""
(144775)/(log_kio_smb) unknown: Setting debug level to: 0
(144775)/(log_kio_smb) unknown: QUrl("smb://")
(144775)/(log_kio_smb) unknown: checkURL  QUrl("smb://")
(144775)/(log_kio_smb) unknown: updateCache  ""
(144773)/(log_kio_smb) unknown: QUrl("smb://")
(144773)/(log_kio_smb) unknown: checkURL  QUrl("smb://")
(144773)/(log_kio_smb) unknown: updateCache  ""
(144771)/(log_kio_smb) unknown: Using libsmbclient library version 4.12.2
(144771)/(log_kio_smb) unknown: auth_initialize_smbc
(144771)/(log_kio_smb) unknown: smbc_new_context call
(144771)/(log_kio_smb) unknown: Setting debug level to: 0
(144777)/(log_kio_smb) unknown: Using libsmbclient library version 4.12.2
(144777)/(log_kio_smb) unknown: auth_initialize_smbc
(144777)/(log_kio_smb) unknown: smbc_new_context call
(144777)/(log_kio_smb) unknown: Setting debug level to: 0
(144719)/(default) unknown: QFSFileEngine::open: No file name specified
(144771)/(log_kio_smb) unknown: QUrl("smb://")
(144777)/(log_kio_smb) unknown: QUrl("smb:///")
(144777)/(log_kio_smb) unknown: checkURL  QUrl("smb:///")
(144777)/(log_kio_smb) unknown: checkURL return3  QUrl("smb:///")
(144775)/(log_kio_smb) unknown: QUrl("smb://")
(144777)/(log_kio_smb) unknown: updateCache  "/"
(144775)/(log_kio_smb) unknown: checkURL  QUrl("smb://")
(144775)/(log_kio_smb) unknown: updateCache  ""
(144777)/(log_kio_smb) unknown: we don't really need to authenticate for this top level url, returning
(144771)/(log_kio_smb) unknown: QUrl("smb://")
(144771)/(log_kio_smb) unknown: checkURL  QUrl("smb://")
(144771)/(log_kio_smb) unknown: updateCache  ""
(144775)/(log_kio_smb) unknown: QUrl("smb://")
(144775)/(log_kio_smb) unknown: checkURL  QUrl("smb://")
(144775)/(log_kio_smb) unknown: updateCache  ""
(144764)/(log_kio_smb) unknown: open  "smb://" url-type: 1 dirfd: -1 errNum: 2
(144764)/(log_kio_smb) unknown: reporting generic error: 2
(144764)/(log_kio_smb) unknown: errNum 2
(144764)/(log_kio_smb) unknown: QUrl("smb://")
(144764)/(log_kio_smb) unknown: checkURL  QUrl("smb://")
(144764)/(log_kio_smb) unknown: updateCache  ""
(144764)/(log_kio_smb) unknown: QUrl("smb://")
(144764)/(log_kio_smb) unknown: checkURL  QUrl("smb://")
(144764)/(log_kio_smb) unknown: updateCache  ""
(144775)/(log_kio_smb) unknown: QUrl("smb://")
(144775)/(log_kio_smb) unknown: checkURL  QUrl("smb://")
(144775)/(log_kio_smb) unknown: updateCache  ""
(144777)/(log_kio_smb) unknown: open  "smb:///" url-type: 1 dirfd: -1 errNum: 111
(144777)/(log_kio_smb) unknown: reporting generic error: 111
(144777)/(log_kio_smb) unknown: errNum 111
(144777)/(log_kio_smb) unknown: QUrl("smb://")
(144777)/(log_kio_smb) unknown: QUrl("smb://")
(144777)/(log_kio_smb) unknown: QUrl("smb://")
```

Here is router's smb.conf:
```
# cat /etc/smb.conf 
[global]
netbios name = RT-AC68U-ASMT
server string = RT-AC68U
workgroup = WORKGROUP
username level = 20
unix charset = UTF8
display charset = UTF8
load printers = no
printing = bsd
printcap name = /dev/null
log file = /var/log/samba.log
log level = 0
max log size = 5
security = USER
guest ok = no
map to guest = Bad User
encrypt passwords = yes
pam password change = no
null passwords = yes
force directory mode = 0777
force create mode = 0777
max connections = 5
socket options = IPTOS_LOWDELAY TCP_NODELAY SO_KEEPALIVE
obey pam restrictions = no
use spnego = yes
client use spnego = no
disable spoolss = yes
host msdfs = no
strict allocate = no
wide links = no
bind interfaces only = yes
interfaces = lo br0 10.0.0.1/255.255.255.0 
use sendfile = yes
map archive = no
map hidden = no
map read only = no
map system = no
store dos attributes = no
dos filemode = yes
oplocks = yes
level2 oplocks = yes
kernel oplocks = no
enable core files = no
deadtime = 30
load printers = no
printable = no
max protocol = SMB2
smb encrypt = disabled
min receivefile size = 16384
passdb backend = smbpasswd
smb passwd file = /etc/samba/smbpasswd
[Video (at ASMT)]
comment = ASMT's Video in ASMT 2105
path = /tmp/mnt/ASMT/Video
dos filetimes = yes
fake directory create times = yes
valid users = openm
invalid users = 
read list = openm
write list = openm
[Backup (at ASMT)]
comment = ASMT's Backup in ASMT 2105
path = /tmp/mnt/ASMT/Backup
dos filetimes = yes
fake directory create times = yes
valid users = openm
invalid users = 
read list = openm
write list = openm
[Music (at ASMT)]
comment = ASMT's Music in ASMT 2105
path = /tmp/mnt/ASMT/Music
dos filetimes = yes
fake directory create times = yes
valid users = openm
invalid users = 
read list = openm
write list = openm
[Photo (at ASMT)]
comment = ASMT's Photo in ASMT 2105
path = /tmp/mnt/ASMT/Photo
dos filetimes = yes
fake directory create times = yes
valid users = openm
invalid users = 
read list = openm
write list = openm
[entware (at ASMT)]
comment = ASMT's entware in ASMT 2105
path = /tmp/mnt/ASMT/entware
dos filetimes = yes
fake directory create times = yes
valid users = openm
invalid users = 
read list = openm
write list = openm
[Transmission (at ASMT)]
comment = ASMT's Transmission in ASMT 2105
path = /tmp/mnt/ASMT/Transmission
dos filetimes = yes
fake directory create times = yes
valid users = openm
invalid users = 
read list = openm
write list = openm
```
Comment 4 Harald Sitter 2020-05-18 14:00:11 UTC
Hmmmm. You don't have an smb.conf on the client?
Comment 5 Vladimir Yerilov 2020-05-18 14:05:28 UTC
(In reply to Harald Sitter from comment #4)
> Hmmmm. You don't have an smb.conf on the client?

Aw, of course I do. Here it is (stock Manjaro one, edited a bit to allow browsing my router's smb shares via Dolphin AND share my laptop stuff to my Android phone):

```
$ cat /etc/samba/smb.conf 

[global]
   workgroup = WORKGROUP
   dns proxy = no
   log file = /var/log/samba/%m.log
   max log size = 1000
   client min protocol = NT1
   server min protocol = SMB2
   server role = standalone server
   passdb backend = tdbsam
   obey pam restrictions = yes
   unix password sync = yes
   passwd program = /usr/bin/passwd %u
   passwd chat = *New*UNIX*password* %n\n *ReType*new*UNIX*password* %n\n *passwd:*all*authentication*tokens*updated*successfully*
   pam password change = yes
   map to guest = Bad Password
   usershare allow guests = yes
   name resolve order = lmhosts bcast host wins
   security = user
   guest account = nobody
   usershare path = /var/lib/samba/usershare
   usershare max shares = 100
   usershare owner only = yes
   force create mode = 0070
   force directory mode = 0070

[homes]
   comment = Home Directories
   browseable = no
   read only = yes
   create mask = 0700
   directory mask = 0700
   valid users = %S

[printers]
   comment = All Printers
   browseable = no
   path = /var/spool/samba
   printable = yes
   guest ok = no
   read only = yes
   create mask = 0700

[print$]
   comment = Printer Drivers
   path = /var/lib/samba/printers
   browseable = yes
   read only = yes
   guest ok = no
```
Comment 6 Harald Sitter 2020-05-18 14:24:30 UTC
Please also enable smbclient debugging and get another log
https://community.kde.org/Guidelines_and_HOWTOs/Debugging/Debugging_IOSlaves/Debugging_kio_smb#Logging_with_libsmbclient_debug_output

The internal error codes do rather point at netbios broadcasts as a whole not working. Which is weird as I think only the client could prevent that from working and you have no settings to that extent (i.e. only `disable netbios=yes` does that AFAIK). Whatever is wrong is way deeper than dolphin though, so Patrick is probably onto something when he suspects a bug in samba.

There's also a problem on our end here. Modern discovery a la DNSSD and WSD is conditional on libsmbclient being able to deploy the netbios broadcast. When that fails all discovery is aborted, but in fact one could feasibly want to disable netbios and rely solely on DNSSD. That's not quite right either, albeit unrelated to your specific problem.
Comment 7 Vladimir Yerilov 2020-05-18 14:46:16 UTC
Created attachment 128574 [details]
detailed log

Here is a detailed smbclient log.
Comment 8 Vladimir Yerilov 2020-05-18 15:07:34 UTC
One note I should add is that I'm having this issue for a long time, about a year or even more, I don't remember. It is a minor thing because I'm fine with NFS serving me well. I raised this problem just because I had faced another issue I reported below, and I thought that something's gradually goes wrong with KDE + Samba tandem.
https://bugs.kde.org/show_bug.cgi?id=421626
Comment 9 Harald Sitter 2020-05-18 15:16:44 UTC
Alrighty, so, I think this is a configuration problem.

What is going on is that libsmbclient sends a netbios broadcast but appears to get no response which I am guessing means that there is simply no server in the entire network that has netbios enabled (or you have a firewall and that filters all netbios traffic). This then causes the error you see. On top of that, as mentioned, our modern replacements for netbios also do not run when the netbios query errors out.

I'm going to look into a way to detangle this on our end but that only helps iff your server has DNSSD or WSD enabled, neither are builtin into samba 3.6 I think, so you'll either want to upgrade or look into having avahi (on the server) and manually define an smb service through that. If all else fails you can also have another server play "proxy" for the discovery see this comment for details https://bugs.kde.org/show_bug.cgi?id=418417#c1

If you actually want to have NB-based discovery, which is kind of required if you have SMB1-exclusive clients, your server is probably misconfigured (as-in: not running nmbd; or a firewall gets in the way of the NB traffic).

In short: the caveat heer is that all this depends on what you expect to happen here.
- If you think netbios should work, which is the more legacy windows tech, then something is wrong with the server-side setup as no NB replies arrive on the client
- If you think dnssd/wsd should work then this is a bug in kio-extras which I'll look into. Your server needs to be exposed on one of those discovery services though

Regardless I am sure that in the meantime if you simply run nmbd *anywhere* in your network, even localhost, it should make the error go away.
Comment 10 Vladimir Yerilov 2020-05-20 14:17:12 UTC
OK it seems I have sorted it out (and I am extremely sorry).

Firewalld was the culprit. I had it configured to allow samba traffic (ports 137, 138, 139, 445) and it worked when using full server address like "smb://10.0.0.1". But there was no this auto-detection. As soon as I disabled it, available servers became detectable with simple "smb://".

This is strange however. I remember I had no such problem when I had ufw running (configured the same way).
Comment 11 Harald Sitter 2020-05-25 09:04:38 UTC
Git commit 4e41727c9626e714477b91cf14bd9a1efa1e8c8b by Harald Sitter.
Committed on 19/05/2020 at 13:16.
Pushed by sitter into branch 'release/20.04'.

smb: reshuffle discovery systems

the modern discoveries were conditional on smbc_opendir succeeding but
that is rather silly since smbc can fail on ENOENT if (for example)
netbios is disabled. since top level server discovery may happen through
all or none of NB/DNSSD/WSD that made no sense as even when NB fails
we may be able to produce service listing through one of the other two
discovery services.

this piece of code would actually benefit from major refactoring because
all three discovery systems should actually run at the same time while
currently NB holds up the entire show. alas, too invasive for 20.04...
so, reshuffling it is:

smbc_opendir still runs initially. after that, if the url is browsing
smb:// we'll jump into modern discovery. any errors produced by opendir
will be ignored! authentication errors and the like cannot happen for
smb:// because we aren't yet talking to any one server, which leaves
actual browsing errors which are not fatal considering we have other
options.
for non-top-level urls we'll otherwise jump into error handling (e.g.
server requires auth or something)
at the end if we haven't returned early with an error we'll inject our
`.` entries as per usual

test plan:
- add `disable netbios = yes` to smb.conf
- browse network
- discovers dnssd/wsd servers
- also works with the option removed again

FIXED-IN: 20.04.2

M  +83   -83   smb/kio_smb_browse.cpp

https://invent.kde.org/network/kio-extras/commit/4e41727c9626e714477b91cf14bd9a1efa1e8c8b