[PATCH] Add a test for 'net usershare'

Jeremy Allison jra at samba.org
Thu Jun 22 23:38:44 UTC 2017


On Thu, Jun 22, 2017 at 05:51:28PM +0200, Andreas Schneider via samba-technical wrote:
> Hi,
> 
> I've tried to understand a customer problem, so I've started to write a test 
> for 'net usershare'. Haven't found a bug yet, so here is just a test which 
> checks normal functionality.
> 
> 
> Review and push appreciated.

RB+. Thanks a *LOT* for the tests on this Andreas !

> 
> 
> 
> 	Andreas
> 
> -- 
> Andreas Schneider                   GPG-ID: CC014E3D
> Samba Team                             asn at samba.org
> www.samba.org

> From 410814309185d8471476cecb15f22ccc8342092c Mon Sep 17 00:00:00 2001
> From: Andreas Schneider <asn at samba.org>
> Date: Thu, 22 Jun 2017 16:13:12 +0200
> Subject: [PATCH 1/2] s3:param: Allow to add usershare if uid_wrapper is loaded
> 
> Signed-off-by: Andreas Schneider <asn at samba.org>
> ---
>  source3/param/loadparm.c | 19 +++++++++++++++++--
>  1 file changed, 17 insertions(+), 2 deletions(-)
> 
> diff --git a/source3/param/loadparm.c b/source3/param/loadparm.c
> index 297a7e9175a..91fa85ea7b0 100644
> --- a/source3/param/loadparm.c
> +++ b/source3/param/loadparm.c
> @@ -3513,6 +3513,19 @@ static bool usershare_exists(int iService, struct timespec *last_mod)
>  	return true;
>  }
>  
> +static bool usershare_directory_is_root(uid_t uid)
> +{
> +	if (uid == 0) {
> +		return true;
> +	}
> +
> +	if (uid_wrapper_enabled()) {
> +		return true;
> +	}
> +
> +	return false;
> +}
> +
>  /***************************************************************************
>   Load a usershare service by name. Returns a valid servicenumber or -1.
>  ***************************************************************************/
> @@ -3546,9 +3559,11 @@ int load_usershare_service(const char *servicename)
>  	 */
>  
>  #ifdef S_ISVTX
> -	if (sbuf.st_ex_uid != 0 || !(sbuf.st_ex_mode & S_ISVTX) || (sbuf.st_ex_mode & S_IWOTH)) {
> +	if (!usershare_directory_is_root(sbuf.st_ex_uid) ||
> +	    !(sbuf.st_ex_mode & S_ISVTX) || (sbuf.st_ex_mode & S_IWOTH)) {
>  #else
> -	if (sbuf.st_ex_uid != 0 || (sbuf.st_ex_mode & S_IWOTH)) {
> +	if (!usershare_directory_is_root(sbuf.st_ex_uid) ||
> +	    (sbuf.st_ex_mode & S_IWOTH)) {
>  #endif
>  		DEBUG(0,("load_usershare_service: directory %s is not owned by root "
>  			"or does not have the sticky bit 't' set or is writable by anyone.\n",
> -- 
> 2.13.1
> 
> 
> From 3fcd2c920375f03b9b3a471bd3b483092c79fa5d Mon Sep 17 00:00:00 2001
> From: Andreas Schneider <asn at samba.org>
> Date: Thu, 22 Jun 2017 14:17:07 +0200
> Subject: [PATCH 2/2] s3:tests: Add blackbox test for 'net usershare'
> 
> Signed-off-by: Andreas Schneider <asn at samba.org>
> ---
>  selftest/target/Samba3.pm                  | 13 +++++
>  source3/script/tests/test_net_usershare.sh | 82 ++++++++++++++++++++++++++++++
>  source3/selftest/tests.py                  |  2 +
>  3 files changed, 97 insertions(+)
>  create mode 100755 source3/script/tests/test_net_usershare.sh
> 
> diff --git a/selftest/target/Samba3.pm b/selftest/target/Samba3.pm
> index d93d98e3af3..248a7362abb 100755
> --- a/selftest/target/Samba3.pm
> +++ b/selftest/target/Samba3.pm
> @@ -740,6 +740,8 @@ sub setup_fileserver($$)
>  
>  	mkdir($prefix_abs, 0777);
>  
> +	my $usershare_dir="$prefix_abs/lib/usershare";
> +
>  	my $share_dir="$prefix_abs/share";
>  
>  	# Create share directory structure
> @@ -767,7 +769,15 @@ sub setup_fileserver($$)
>  	my $smbget_sharedir="$share_dir/smbget";
>  	push(@dirs,$smbget_sharedir);
>  
> +	my $usershare_sharedir="$share_dir/usershares";
> +	push(@dirs,$usershare_sharedir);
> +
>  	my $fileserver_options = "
> +	usershare path = $usershare_dir
> +	usershare max shares = 10
> +	usershare allow guests = yes
> +	usershare prefix allow list = $usershare_sharedir
> +
>  [lowercase]
>  	path = $lower_case_share_dir
>  	comment = smb username is [%U]
> @@ -838,6 +848,9 @@ sub setup_fileserver($$)
>  
>  	$self->{vars}->{fileserver} = $vars;
>  
> +	rmdir($usershare_dir);
> +	mkdir($usershare_dir, 01770);
> +
>  	mkdir($_, 0777) foreach(@dirs);
>  
>  	## Create case sensitive lower case share dir
> diff --git a/source3/script/tests/test_net_usershare.sh b/source3/script/tests/test_net_usershare.sh
> new file mode 100755
> index 00000000000..16634487aaa
> --- /dev/null
> +++ b/source3/script/tests/test_net_usershare.sh
> @@ -0,0 +1,82 @@
> +#!/bin/sh
> +
> +if [ $# -lt 5 ]; then
> +cat <<EOF
> +Usage: test_net_usershare.sh SERVER SERVER_IP DOMAIN USERNAME PASSWORD SMBCLIENT <smbclient arguments>
> +EOF
> +exit 1;
> +fi
> +
> +SERVER="$1"
> +SERVER_IP="$2"
> +USERNAME="$3"
> +PASSWORD="$4"
> +smbclient="$5"
> +shift 6
> +ADDARGS="$@"
> +
> +failed=0
> +
> +samba_bindir="$BINDIR"
> +samba_net="$samba_bindir/net"
> +samba_smbcontrol="$samba_bindir/smbcontrol"
> +
> +samba_share_dir="$LOCAL_PATH"
> +samba_usershare_dir="$samba_share_dir/usershares"
> +
> +incdir=`dirname $0`/../../../testprogs/blackbox
> +. $incdir/subunit.sh
> +
> +
> +test_smbclient() {
> +	name="$1"
> +	share="$2"
> +	cmd="$3"
> +	shift 3
> +	echo "test: $name"
> +	$VALGRIND $smbclient $CONFIGURATION //$SERVER/$share -c "$cmd" "$@"
> +	status=$?
> +	if [ x$status = x0 ]; then
> +		echo "success: $name"
> +	else
> +		echo "failure: $name"
> +	fi
> +	return $status
> +}
> +
> +test_net_usershare() {
> +	name="$1"
> +	cmd="$2"
> +	shift
> +	shift
> +	echo "test: $name"
> +	$VALGRIND $samba_net usershare "$cmd" "$@"
> +	status=$?
> +	if [ x$status = x0 ]; then
> +		echo "success: $name"
> +	else
> +		echo "failure: $name"
> +	fi
> +	return $status
> +}
> +
> +###########################################################
> +# Check if we can add and delete a usershare
> +###########################################################
> +
> +samba_usershare_name="test_usershare_1"
> +samba_usershare_path="$samba_usershare_dir/$samba_usershare_name"
> +
> +testit "create usershare dir for $samba_usershare_name" mkdir $samba_usershare_path || failed=`expr $failed + 1`
> +
> +test_net_usershare "net usershare add $samba_usershare_name" "add" "$samba_usershare_name" "$samba_usershare_path" "$samba_usershare_name"
> +
> +test_net_usershare "net usershare info $samba_usershare_name" "info" "$samba_usershare_name"
> +
> +test_smbclient "smbclient to $samba_usershare_name" "$samba_usershare_name" 'ls' -U$USERNAME%$PASSWORD || failed=`expr $failed + 1`
> +
> +# CLEANUP
> +test_net_usershare "net usershare delete $samba_usershare_name" "delete" "$samba_usershare_name"
> +testit "remove usershare dir for $samba_usershare_name" rm -rf $samba_usershare_path || failed=`expr $failed + 1`
> +
> +exit $failed
> diff --git a/source3/selftest/tests.py b/source3/selftest/tests.py
> index ac861e8ba24..07952e02e39 100755
> --- a/source3/selftest/tests.py
> +++ b/source3/selftest/tests.py
> @@ -258,6 +258,8 @@ for env in ["fileserver"]:
>                         '-d', '$PREFIX', '-b', smbclient3,
>                         '--subunit', '--', configuration])
>  
> +plantestsuite("samba3.blackbox.net_usershare", "fileserver:local", [os.path.join(samba3srcdir, "script/tests/test_net_usershare.sh"), '$SERVER', '$SERVER_IP', '$USERNAME', '$PASSWORD', smbclient3])
> +
>  #TODO encrypted against member, with member creds, and with DC creds
>  plantestsuite("samba3.blackbox.net.misc", "nt4_dc:local",
>                [os.path.join(samba3srcdir, "script/tests/test_net_misc.sh"),
> -- 
> 2.13.1
> 




More information about the samba-technical mailing list