Add smbstatus test (lock file with smbclient)

Jeremy Allison jra at
Fri Mar 15 18:28:33 UTC 2019

On Wed, Mar 13, 2019 at 12:08:59PM +0100, Andreas Schneider wrote:
> Hi Jeremy,
> I've created a patch for 'smbstatus -L --resolve-uids' to show usernames 
> instead of UIDs as I have a customer request for it.
> However Andrew rejected the patch to go in without a test. I've tried to 
> implement a test for smbstatus but it doesn't work. My problem is that I'm not 
> able to create a lock on a file to show up with smbstatus later.

Don't create a lock file or add the sleep command to smbclient.

As you already pointed out, lock isn't implemented for SMB2+

The correct way to test this is to use the same technique
I used in 7b21b4c1f538650f23ec77fb3c02fe1e224d89aa
(s3: tests: Add regression test for smbd crash on share force group change with existing connection.)

smbclient has a '!' command, which shells out and runs
an external command then returns.

Here is a snippet from that patch which explains how
to do this:

+    tmpfile=$PREFIX/smbclient_force_group_change_commands
+    cat > $tmpfile <<EOF
+!${SMBCONTROL} --configfile=${SERVER_CONFIG} all reload-config
+!${SMBCONTROL} --configfile=${SERVER_CONFIG} all reload-config
+    cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/force_group_test $CONFIGURATION < $tmpfile 2>&1'
+    eval echo "$cmd"
+    out=$(eval $cmd)

In this case I'm doing '!cp' and '!${SMBCONTROL}'.

In your case you need to create a temp file locally,
connect, do the 'open $tmpfile' request to create a parsable record
from the smbclient script, and then call:

'!${SMBSTATUS} --resolve-uids'

The output will be stored in "$out" for you to
parse and test against.

Let me know if you need help coding this up, or
if you really get stuck I could do it for you (not
my preferred choice but if I gotta, I gotta :-).



More information about the samba-technical mailing list