Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[SOLVED] Samba: Unable to edit or delete files
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
Mog01
n00b
n00b


Joined: 17 Mar 2020
Posts: 6

PostPosted: Sat Oct 16, 2021 5:16 am    Post subject: [SOLVED] Samba: Unable to edit or delete files Reply with quote

Hi everyone !

I am having a lot of trouble with samba, and I really don't know what to do anymore ...

I have a htpc running gentoo and samba that contains all my files. I also have a desktop pc from which I connect to it. My issue is that everything is always locked and it's just not usable as it is...
So for example, I create an empty text file. I try to edit it with kate; I save. It will fail because of permission issue. Kate will also create some temp file next to it, and it will throw an error because it is unable to delete it. If I try to delete it manually, it will also fail and dolphin will display an error that the device is busy.

Rebooting the smb service will allow me to delete the file, as with killing the processes displayed in smbstatus. But the issue will reappear the next time I try something.
This issue will happen both by mounting the share in /etc/fstab using cifs, or by accessing it in dolphin with smb://<ip>/share
What I noticed also was really a lot of files being locked when running smbstatus on the server in RDONLY mode. What is opening them? Dolphin? Is there a way to turn that off ?

I tried the samba server + client both from amd64 and ~amd64 with default USE, both have the same issue...
I tried using kernel-gentoo-bin to minimize potential issues, it did not fix it
I tried using 'locking = no' and 'oplocks = no' in my [share] section of my smb.conf, it did not fix it
I tried using 'create mask = 777', no effect
I tried using 'server max protocol = NT1' and then I wasn't able to connect to it anymore.

I also see a lot of spam in the journal about
Code:
oct 16 01:06:36 hostname smbd[1105985]: [2021/10/16 01:06:36.182951,  0] ../../source3/smbd/close.c:1402(close_directory)
oct 16 01:06:36 hostname smbd[1105985]:   close_directory: Could not delete share entry for .

Which is probably related to my issue.

Could someone help me please? :(

Thank you very much


Last edited by Mog01 on Sun Oct 17, 2021 8:23 am; edited 1 time in total
Back to top
View user's profile Send private message
mike155
Advocate
Advocate


Joined: 17 Sep 2010
Posts: 4438
Location: Frankfurt, Germany

PostPosted: Sat Oct 16, 2021 1:29 pm    Post subject: Reply with quote

Quote:
So for example, I create an empty text file. I try to edit it with kate; I save. It will fail because of permission issue. Kate will also create some temp file next to it, and it will throw an error because it is unable to delete it. If I try to delete it manually, it will also fail and dolphin will display an error that the device is busy.

Please run the commands below and posts the results. Run the commands on your client as well as on your server, in the directory where the files are located:
Code:
ls -ld .
ls -ldn .
ls -l <name of the empty file>
ls -ln <name of the empty file>
ls -l <name of kate's temp file>
ls -ln <name of kate's temp file>
Back to top
View user's profile Send private message
Mog01
n00b
n00b


Joined: 17 Mar 2020
Posts: 6

PostPosted: Sat Oct 16, 2021 5:05 pm    Post subject: Reply with quote

Hello Mike, thank you for your help

The results on the server:
Code:
mogserver /media/Music # ls -ld .
drwxrwxrwx 1 kodi kodi 172 16 oct 12:40 .
mogserver /media/Music # ls -ldn .
drwxrwxrwx 1 1000 1000 172 16 oct 12:40 .
mogserver /media/Music # ls -l Fichier\ texte.txt
-rwxr--r-- 1 kodi kodi 2 16 oct 12:40 'Fichier texte.txt'
mogserver /media/Music # ls -ln Fichier\ texte.txt
-rwxr--r-- 1 1000 1000 2 16 oct 12:40 'Fichier texte.txt'
mogserver /media/Music # ls -l Fichier\ texte.txt.part
-rwxr--r-- 1 kodi kodi 10 16 oct 12:40 'Fichier texte.txt.part'
mogserver /media/Music # ls -ln Fichier\ texte.txt.part
-rwxr--r-- 1 1000 1000 10 16 oct 12:40 'Fichier texte.txt.part'


The results on the client:
Code:
mog-desktop /mnt/mogserver/Music # ls -ld .
drwxr-xr-x 2 mog mog 0 16 oct 12:40 .
mog-desktop /mnt/mogserver/Music # ls -ldn .
drwxr-xr-x 2 1000 1000 0 16 oct 12:40 .
mog-desktop /mnt/mogserver/Music # ls -l Fichier\ texte.txt
-rwxr-xr-x 1 mog mog 2 16 oct 12:40 'Fichier texte.txt'
mog-desktop /mnt/mogserver/Music # ls -ln Fichier\ texte.txt
-rwxr-xr-x 1 1000 1000 2 16 oct 12:40 'Fichier texte.txt'
mog-desktop /mnt/mogserver/Music # ls -l Fichier\ texte.txt.part
-rwxr-xr-x 1 mog mog 10 16 oct 12:40 'Fichier texte.txt.part'
mog-desktop /mnt/mogserver/Music # ls -ln Fichier\ texte.txt.part
-rwxr-xr-x 1 1000 1000 10 16 oct 12:40 'Fichier texte.txt.part'


The usernames are different, but that's normal. I have also put 'force user = kodi' and 'force group = kodi' in my smb.conf for my share.

Permissions seems ok to me.
What is interesting is, if I do
Code:
rm 'Fichier texte.txt'

from the desktop, it will return successfully without actually erasing the file. If I try to do it again, it will say that the file do not exist while still being there:
Code:
mog-desktop /mnt/mogserver/Music # rm Fichier\ texte.txt
mog-desktop /mnt/mogserver/Music # ls
 'Fichier texte.txt'  'Fichier texte.txt.part'
mog-desktop /mnt/mogserver/Music # rm Fichier\ texte.txt
rm: impossible de supprimer 'Fichier texte.txt': Aucun fichier ou dossier de ce type


This is without any other smb session open from this computer, so it seems to be a samba issue.

When I run smbstatus, I see this:
Code:
Samba version 4.15.0
PID     Username     Group        Machine                                   Protocol Version  Encryption           Signing             
----------------------------------------------------------------------------------------------------------------------------------------
1118795 mog          mog          xx.xx.xx.xx (ipv4:xx.xx.xx.xx:60612)        SMB3_11           partial(AES-128-GCM) partial(AES-128-CMAC)
1118770 mog          mog          xx.xx.xx.xx (ipv4:xx.xx.xx.xx:60608)        SMB3_11           -                    AES-128-GMAC         

Service      pid     Machine       Connected at                     Encryption   Signing     
---------------------------------------------------------------------------------------------
Music        1118795 xx.xx.xx.xx    sam oct 16 12:45:01 2021 EDT     AES-128-GCM  AES-128-CMAC
IPC$         1118795 xx.xx.xx.xx    sam oct 16 12:45:01 2021 EDT     -            -           
Music        1118770 xx.xx.xx.xx    sam oct 16 12:40:06 2021 EDT     -            AES-128-GMAC

Locked files:
Pid          User(ID)   DenyMode   Access      R/W        Oplock           SharePath   Name   Time
--------------------------------------------------------------------------------------------------
[almost infinite list of '.' being locked, truncated...]
1118795      1000       DENY_NONE  0x80        RDONLY     NONE             /media/Music   .   Sat Oct 16 12:45:45 2021
1118795      1000       DENY_NONE  0x80        RDONLY     NONE             /media/Music   .   Sat Oct 16 12:45:31 2021
1118795      1000       DENY_NONE  0x80        RDONLY     NONE             /media/Music   .   Sat Oct 16 12:45:04 2021
1118795      1000       DENY_NONE  0x80        RDONLY     NONE             /media/Music   .   Sat Oct 16 12:45:04 2021
1118795      1000       DENY_NONE  0x81        RDONLY     NONE             /media/Music   .   Sat Oct 16 12:45:04 2021
1118795      1000       DENY_NONE  0x80        RDONLY     NONE             /media/Music   .   Sat Oct 16 12:45:04 2021
1118795      1000       DENY_NONE  0x80        RDONLY     NONE             /media/Music   .   Sat Oct 16 12:45:04 2021
1118795      1000       DENY_NONE  0x80        RDONLY     NONE             /media/Music   .   Sat Oct 16 12:45:01 2021
1118795      1000       DENY_NONE  0x80        RDONLY     NONE             /media/Music   .   Sat Oct 16 12:45:01 2021
1118795      1000       DENY_NONE  0x80        RDONLY     NONE             /media/Music   .   Sat Oct 16 12:45:01 2021
1118795      1000       DENY_NONE  0x80        RDONLY     NONE             /media/Music   .   Sat Oct 16 12:45:01 2021
1118795      1000       DENY_NONE  0x80        RDONLY     NONE             /media/Music   .   Sat Oct 16 12:45:01 2021
1118770      1000       DENY_NONE  0x81        RDONLY     NONE             /media/Music   .   Sat Oct 16 12:40:06 2021
1118770      1000       DENY_NONE  0x81        RDONLY     NONE             /media/Music   .   Sat Oct 16 12:40:06 2021
1118770      1000       DENY_NONE  0x80        RDONLY     NONE             /media/Music   .   Sat Oct 16 12:40:06 2021
1118795      1000       DENY_NONE  0x80        RDONLY     NONE             /media/Music   Fichier texte.txt.part   Sat Oct 16 12:49:02 2021
1118795      1000       DENY_NONE  0x80        RDONLY     NONE             /media/Music   Fichier texte.txt.part   Sat Oct 16 12:48:57 2021
1118795      1000       DENY_NONE  0x10000     RDONLY     NONE             /media/Music   Fichier texte.txt   Sat Oct 16 12:50:34 2021
1118795      1000       DENY_NONE  0x80        RDONLY     NONE             /media/Music   Fichier texte.txt   Sat Oct 16 12:50:34 2021
1118795      1000       DENY_NONE  0x80        RDONLY     NONE             /media/Music   Fichier texte.txt   Sat Oct 16 12:48:45 2021
Back to top
View user's profile Send private message
mike155
Advocate
Advocate


Joined: 17 Sep 2010
Posts: 4438
Location: Frankfurt, Germany

PostPosted: Sat Oct 16, 2021 7:27 pm    Post subject: Reply with quote

Mog01 wrote:
Permissions seems ok to me.

I agree. :)

Quote:
What is interesting is, if I do
Code:
rm 'Fichier texte.txt'

from the desktop, it will return successfully without actually erasing the file. If I try to do it again, it will say that the file do not exist while still being there:
Code:
mog-desktop /mnt/mogserver/Music # rm Fichier\ texte.txt
mog-desktop /mnt/mogserver/Music # ls
 'Fichier texte.txt'  'Fichier texte.txt.part'
mog-desktop /mnt/mogserver/Music # rm Fichier\ texte.txt
rm: impossible de supprimer 'Fichier texte.txt': Aucun fichier ou dossier de ce type

This looks like a cache problem. Have you tried to mount the CIFS share with option "cache=none", see: https://linux.die.net/man/8/mount.cifs?

Please show us the output of "emerge -pv samba" on the server.
Back to top
View user's profile Send private message
Mog01
n00b
n00b


Joined: 17 Mar 2020
Posts: 6

PostPosted: Sun Oct 17, 2021 6:21 am    Post subject: Reply with quote

I didn't know about this option :o I tried it, but unfortunately I have the same issue. To be sure my client was not at fault, I tried to connect using a laptop I had that has kubuntu 20.04 installed on it and had the same bug.

The output is the following (with color, for easier reading):
Quote:
mogserver /media/Music # emerge -pv samba

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild R ] net-fs/samba-4.15.0-r1::gentoo USE="acl pam regedit syslog system-mitkrb5 systemd -addc -ads -ceph -client -cluster -cups -debug (-dmapi) (-fam) -glusterfs -gpg -iprint -json -ldap -profiling-data -python -quota (-selinux) -snapper -spotlight (-system-heimdal) (-test) -winbind -zeroconf" ABI_X86="(64) -32 (-x32)" PYTHON_SINGLE_TARGET="python3_9 -python3_8" 0 KiB
Back to top
View user's profile Send private message
Logicien
Veteran
Veteran


Joined: 16 Sep 2005
Posts: 1555
Location: Montréal

PostPosted: Sun Oct 17, 2021 6:41 am    Post subject: Reply with quote

There is three things to considers with Samba, the permissions on the host share directory, they must allow read write, I do 0775 on directories and 0660 on files with root as owner and users as group. Than the samba server on the host share must honore this too, the same permissions, owner and group is good. On the client side the share must be mount to allow the user or users to read and write on the share.

I use the legacy outdated version 1 of Cifs to allow read write when I mount the share on the client side. Version 3 have been problematic for me in read write. It need root access to write but work well in read only.
_________________
Paul
Back to top
View user's profile Send private message
Mog01
n00b
n00b


Joined: 17 Mar 2020
Posts: 6

PostPosted: Sun Oct 17, 2021 8:11 am    Post subject: Reply with quote

Wow Thank you Logicien, I finally was able to make it work by setting on the server:
Code:
server min protocol = NT1

and on the client:
Code:
client min protocol = NT1
client max protocol = NT1


I also tried to make it work using Version 3, so putting on the server
Code:
create mask = 666
directory mask = 777
force user = root
work wonderfully !

Is that not kind of a big deal though? I would expect things to work just fine without having to use a version of the protocol that is off by default. And I haven't seen anywhere documented that the user absolutely needs to be root for write access to work properly. Oh well...
Back to top
View user's profile Send private message
Fitzcarraldo
Advocate
Advocate


Joined: 30 Aug 2008
Posts: 2034
Location: United Kingdom

PostPosted: Tue Oct 19, 2021 3:55 pm    Post subject: Reply with quote

I'm not sure what you guys are doing, but it is not advisable to use the deprecated and unsafe NT1 (SMB1) protocol. Preferably you should be using the SMB2 or SMB3 protocols. I allow the SMB2 protocol (as 'min protocol') in my network because the File Manager+ app I use on my Android mobile phone requires it, but for my laptops and desktops running Linux and Windows 10 I allow the SMB3 protocol (as 'max protocol'). Both SMB2 and SMB3 work without hitch in my home network.

The method I used to set up the Samba server and Samba clients is outlined in my 2016 blog post (see link below), which works fine for all the devices in my home network, currently comprising a mixture of Linux (Gentoo Linux amd64 and ~amd64, and Lubuntu 20.10), Android (10 & 11) and Windows 10.

A correct method of configuring Samba for browsing SMB shares in a home network
(Also read the comments below the blog post regarding SMB2 and SMB3.)

The following blog posts are also applicable:

Prevent Linux firewalls interfering with Samba commands in a home network that uses broadcast NetBIOS name resolution

Using WS-Discovery to enable Windows 10 to browse SMB shares in my home network of Linux computers

How to enable a Windows application in WINE to access a Samba share on a NAS (continued)

There is no root ownership of shared directories and files on my Linux server nor on the Linux client machines, as can be seen in the examples below.

Samba Server:

Code:
bsf@nas:~$ grep protocol /etc/samba/smb.conf
        min protocol = SMB2                                                                                 
        max protocol = SMB3                                                                                 
        client min protocol = SMB2
        client max protocol = SMB3
bsf@nas:~$ grep mask /etc/samba/smb.conf
bsf@nas:~$ grep force /etc/samba/smb.conf
bsf@nas:~$


Notice owner and permissions of directories and files:

Code:
bsf@nas:~$ ls -la /nas/shares/brian
total 12560
drwxr-xr-x 56 brian shares    4096 Oct 15 15:31 .
drwxr-xr-x  8 root  root      4096 Oct 25  2019 ..
drwxr-xr-x  2 brian brian     4096 May 11 14:37 Acer_Aspire_XC600
drwxr-xr-x  2 brian brian     4096 Aug 13  2017 ASRock_ION_330
drwxr-xr-x  2 brian brian     4096 Apr 15  2017 AutoMod
drwxr-xr-x  3 brian brian     4096 Oct  4 17:32 Blackview_Tablet
drwxr-xr-x  5 brian brian     4096 Oct  4 11:33 Blog
-rwxr--r--  1 brian brian   574428 Jan  2  2017 catsign.odt
drwxr-xr-x  2 brian brian     4096 Jul 26  2020 Certificates
-rwxr--r--  1 brian brian  2069571 Apr 17  2021 Code Table 5.pdf
drwxr-xr-x  2 brian brian     4096 Jul 16  2018 Copa_do_Mundo
drwxr-xr-x  2 brian brian     4096 Apr 24 20:50 CyberFlix Titanic
drwxr-xr-x 12 brian brian     4096 May 11 14:35 Dell_OptiPlex_780_SFF
drwxr-xr-x  2 brian brian     4096 Jul  8  2020 discover
-rw-r--r--  1 brian brian    25471 May 10  2020 Engineering_Flowchart.jpg
-rw-r--r--  1 brian brian  5898018 Jan  3  2018 fall-autumn-red-season.jpg
-rw-r--r--  1 brian brian  1179707 Aug  6  2018 Fast_Show_Jazz_Club_Nice.gif
[...]


Samba Client running Lubuntu 20.10 (LXQt):

Code:
fitz@aspirexc600:~$ grep protocol /etc/samba/smb.conf
min protocol = SMB2
max protocol = SMB3
client min protocol = SMB2
client max protocol = SMB3
fitz@aspirexc600:~$ grep -B 5 -A 1 mask /etc/samba/smb.conf
[printers]
comment = All Printers
path = /var/spool/samba
guest ok = yes
printable = yes
create mask = 0700
fitz@aspirexc600:~$ grep force /etc/samba/smb.conf
fitz@aspirexc600:~$


If I press F4 in PCManFM-Qt (LXQt's file manager) to open a QTerminal window, I can list the shared directories and files (notice owner and permissions):

Code:
fitz@aspirexc600:/run/user/1000/gvfs/smb-share:server=nas,share=brian$ ls -la
total 12292
drwx------ 1 fitz fitz       0 Oct 15 15:31  .
dr-x------ 3 fitz fitz       0 Oct 19 13:40  ..
drwx------ 1 fitz fitz       0 May 11 14:37  Acer_Aspire_XC600
drwx------ 1 fitz fitz       0 Aug 13  2017  ASRock_ION_330
drwx------ 1 fitz fitz       0 Apr 15  2017  AutoMod
drwx------ 1 fitz fitz       0 Oct  4 17:32  Blackview_Tablet
drwx------ 1 fitz fitz       0 Oct  4 11:33  Blog
-rwx------ 1 fitz fitz  574428 Jan  2  2017  catsign.odt
drwx------ 1 fitz fitz       0 Jul 26  2020  Certificates
-rwx------ 1 fitz fitz 2069571 Apr 17  2021 'Code Table 5.pdf'
drwx------ 1 fitz fitz       0 Jul 16  2018  Copa_do_Mundo
drwx------ 1 fitz fitz       0 Apr 24 20:50 'CyberFlix Titanic'
drwx------ 1 fitz fitz       0 May 11 14:35  Dell_OptiPlex_780_SFF
drwx------ 1 fitz fitz       0 Jul  8  2020  discover
-rwx------ 1 fitz fitz   25471 May 10  2020  Engineering_Flowchart.jpg
-rwx------ 1 fitz fitz 5898018 Jan  3  2018  fall-autumn-red-season.jpg
-rwx------ 1 fitz fitz 1179707 Aug  6  2018  Fast_Show_Jazz_Club_Nice.gif
[...]


Samba Client running Gentoo Linux and KDE:

Dolphin displays the shares fine and I can read/write/create/delete/copy anything. Pressing F4 in Dolphin launches Konsole which does not enter the SMB-shared directory so I mount the directory myself* if I want to access SMB shares from the command line. I can list the shared directories and files (notice owner and permissions):

(* This is a laptop, so I prefer not to mount it in /etc/fstab. I double-click on a Desktop icon to launch a script to do it.)

Code:
fitz@clevow230ss /media/nas/brian $ ls -la
total 26628
drwxr-xr-x 2 fitz fitz       0 Oct 19 15:57  .
drwxr-xr-x 3 root root    4096 Sep 18  2016  ..
drwxr-xr-x 2 fitz fitz       0 Oct 25  2019  .Trash-1000
drwxr-xr-x 2 fitz fitz       0 Aug 13  2017  ASRock_ION_330
drwxr-xr-x 2 fitz fitz       0 May 11 14:37  Acer_Aspire_XC600
drwxr-xr-x 2 fitz fitz       0 Apr 15  2017  AutoMod
drwxr-xr-x 2 fitz fitz       0 Oct  4 17:32  Blackview_Tablet
drwxr-xr-x 2 fitz fitz       0 Oct  4 11:33  Blog
drwxr-xr-x 2 fitz fitz       0 Jul 26  2020  Certificates
-rwxr-xr-x 1 fitz fitz 2069571 Apr 17  2021 'Code Table 5.pdf'
drwxr-xr-x 2 fitz fitz       0 Jul 16  2018  Copa_do_Mundo
drwxr-xr-x 2 fitz fitz       0 Apr 24 20:50 'CyberFlix Titanic'
drwxr-xr-x 2 fitz fitz       0 May 11 14:35  Dell_OptiPlex_780_SFF
-rwxr-xr-x 1 fitz fitz   25471 May 10  2020  Engineering_Flowchart.jpg
-rwxr-xr-x 1 fitz fitz 1179707 Aug  6  2018  Fast_Show_Jazz_Club_Nice.gif
[...]

(Order of listing is different in Gentoo Linux: all upper-case directories/files are listed before lower-case ones.)
_________________
Clevo W230SS: amd64, VIDEO_CARDS="intel modesetting nvidia".
Compal NBLB2: ~amd64, xf86-video-ati. Dual boot Win 7 Pro 64-bit.
OpenRC udev elogind & KDE on both.

Fitzcarraldo's blog
Back to top
View user's profile Send private message
Logicien
Veteran
Veteran


Joined: 16 Sep 2005
Posts: 1555
Location: Montréal

PostPosted: Tue Oct 19, 2021 4:37 pm    Post subject: Reply with quote

Thank-you for the links Fitzcarraldo I'll check them. I would prefer too to use SMB2 and SMB3. I need to set SMB2 and SMB3 to allow a normal user to have write access on the share. Unfortunately for me I need sudo to do that. If I find a way to do it without root previleges I'll be happy.

:D
_________________
Paul
Back to top
View user's profile Send private message
Fitzcarraldo
Advocate
Advocate


Joined: 30 Aug 2008
Posts: 2034
Location: United Kingdom

PostPosted: Tue Oct 19, 2021 4:59 pm    Post subject: Reply with quote

My pleasure, Logicien. If you are also using machines running Windows 10 in your home network, the link I gave regarding WS-Discovery is also important. As explained in detail in that post I also have the wsdd daemon running on all my Linux machines (server and clients) in parallel to broadcast NetBIOS, so that Windows 10 can browse SMB shares on all machines since Microsoft dropped NetBIOS (and SMB1).
_________________
Clevo W230SS: amd64, VIDEO_CARDS="intel modesetting nvidia".
Compal NBLB2: ~amd64, xf86-video-ati. Dual boot Win 7 Pro 64-bit.
OpenRC udev elogind & KDE on both.

Fitzcarraldo's blog
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum