Add smbstatus test (lock file with smbclient)

Jeremy Allison jra at samba.org
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+
(yet).

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
+ls
+!cp ${SERVER_CONFIG_NEW} ${SERVER_CONFIG}
+!${SMBCONTROL} --configfile=${SERVER_CONFIG} all reload-config
+ls
+!cp ${SERVER_CONFIG_SAVE} ${SERVER_CONFIG}
+!${SMBCONTROL} --configfile=${SERVER_CONFIG} all reload-config
+quit
+EOF
+    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 :-).

Cheers,

	Jeremy.



More information about the samba-technical mailing list