Skip to content

s3:smbstatus: go to cmdline_messaging_context_free, fix 15282

If the locking.tdb is not found, (for example, fresh new installed samba server is not running yet) smbstatus utility would exit earlier, and lock files are left behind in the directory 'msg.sock' and 'msg.lock'. Consider that a script to run smbstatus utility in a loop, this might result in used space slowly growing-up on the underlying filesystem. Since the samba server is not running yet, there is no cleanupd daemon could delete these files to reclaim space.

Supposed to use 'ret = 0; goto done;' instead of exit(0), this would go through the cmdline_messaging_context_free() which deletes the lock files in the directory msg.sock and msg.lock before smbstatus utility is exiting.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=15282

  1. Before patch: smbstatus utility would exit earlier if locking.tdb is not found, the lock entries '16059' are left behind in the 'msg.sock' and 'msg.lock'.
# smbstatus -L
/var/lock/.samba/lock/locking.tdb not initialised
This is normal if an SMB client has never connected to your server.
# ls -l /var/lock/.samba/lock/msg.lock/ /usr/local/samba/private/msg.sock/
/usr/local/samba/private/msg.sock/:
total 0
srwxr-xr-x 1 admin administrators 0 Jan 11 20:45 16059=

/var/lock/.samba/lock/msg.lock/:
total 4
-rw-r--r-- 1 admin administrators 20 Jan 11 20:45 16059
#

strace shows that the lock entries are created and left behind, not deleted.

# strace smbstatus -L 2>&1 | grep "msg..ock/"
open("/var/lock/.samba/lock/msg.lock/21922", O_RDWR|O_CREAT|O_NONBLOCK, 0644) = 4
unlink("/usr/local/samba/private/msg.sock/21922") = -1 ENOENT (No such file or directory)
bind(5, {sa_family=AF_UNIX, sun_path="/usr/local/samba/private/msg.sock/21922"}, 110) = 0
# 
  1. After patch: strace show that the lock entries are created and then deleted before smbstatus is exiting.
# strace smbstatus -L 2>&1 | grep "msg..ock/"
open("/var/lock/.samba/lock/msg.lock/23482", O_RDWR|O_CREAT|O_NONBLOCK, 0644) = 4
unlink("/usr/local/samba/private/msg.sock/23482") = -1 ENOENT (No such file or directory)
bind(5, {sa_family=AF_UNIX, sun_path="/usr/local/samba/private/msg.sock/23482"}, 110) = 0
unlink("/usr/local/samba/private/msg.sock/23482") = 0
unlink("/var/lock/.samba/lock/msg.lock/23482") = 0
# 

strace with '-k' shows that the destructor is triggered.

# strace -k smbstatus -L
... ...
unlink("/usr/local/samba/private/msg.sock/25539") = 0
 > /lib/libc-2.21.so(unlink+0x7) [0xdccb7]
 > /share/samba/lib/private/libmessages-dgm-samba4.so(messaging_dgm_context_destructor+0x12a) [0x370a]
 > /share/samba/lib/private/libtalloc.so.2.3.3(_tc_free_internal+0xcc9) [0x37a9]
 > /share/samba/lib/private/libmessages-dgm-samba4.so(messaging_dgm_destroy+0x1c) [0x4f7c]
 > /share/samba/lib/private/libmessages-dgm-samba4.so(msg_dgm_ref_destructor+0xc5) [0x5e85]
 > /share/samba/lib/private/libtalloc.so.2.3.3(_tc_free_internal+0xcc9) [0x37a9]
 > /share/samba/lib/private/libtalloc.so.2.3.3(_tc_free_internal+0x160) [0x2c40]
 > /share/samba/lib/libsmbconf.so.0.0.1(global_messaging_context_free+0x1c) [0x540bc]
 > /share/samba/bin/smbstatus(main+0x4d3) [0x3a73]
 > /lib/libc-2.21.so(__libc_start_main+0xf0) [0x20810]
 > /share/samba/bin/smbstatus(_start+0x29) [0x4059]
unlink("/var/lock/.samba/lock/msg.lock/25539") = 0
 > /lib/libc-2.21.so(unlink+0x7) [0xdccb7]
 > /share/samba/lib/private/libmessages-dgm-samba4.so(messaging_dgm_context_destructor+0x155) [0x3735]
 > /share/samba/lib/private/libtalloc.so.2.3.3(_tc_free_internal+0xcc9) [0x37a9]
 > /share/samba/lib/private/libmessages-dgm-samba4.so(messaging_dgm_destroy+0x1c) [0x4f7c]
 > /share/samba/lib/private/libmessages-dgm-samba4.so(msg_dgm_ref_destructor+0xc5) [0x5e85]
 > /share/samba/lib/private/libtalloc.so.2.3.3(_tc_free_internal+0xcc9) [0x37a9]
 > /share/samba/lib/private/libtalloc.so.2.3.3(_tc_free_internal+0x160) [0x2c40]
 > /share/samba/lib/libsmbconf.so.0.0.1(global_messaging_context_free+0x1c) [0x540bc]
 > /share/samba/bin/smbstatus(main+0x4d3) [0x3a73]
 > /lib/libc-2.21.so(__libc_start_main+0xf0) [0x20810]
 > /share/samba/bin/smbstatus(_start+0x29) [0x4059]

Checklist

  • Commits have Signed-off-by: with name/author being identical to the commit author
  • (optional) This MR is just one part towards a larger feature.
  • (optional, if backport required) Bugzilla bug filed and BUG: tag added
  • Test suite updated with functionality tests
  • Test suite updated with negative tests
  • Documentation updated
  • CI timeout is 3h or higher (see Settings/CICD/General pipelines/ Timeout)

Reviewer's checklist:

  • There is a test suite reasonably covering new functionality or modifications
  • Function naming, parameters, return values, types, etc., are consistent and according to README.Coding.md
  • This feature/change has adequate documentation added
  • No obvious mistakes in the code
Edited by Jones Syue

Merge request reports