[SCM] Samba Shared Repository - branch v4-7-test updated

Stefan Metzmacher metze at samba.org
Thu Jul 20 22:37:20 UTC 2017


The branch, v4-7-test has been updated
       via  895bd0d WHATSNEW: add a note about the new 'smbclient deltree' command.
       via  9940042 s3:tests: Fix directory creation and deletion of test_nosymlinks()
       via  293fa76 s3:tests: Fix directory creation and deletion of test_local_symlinks()
       via  3b2d806 s3: tests: Add test for new smbclient "deltree" command.
       via  265070f docs: Document new smbclient deltree command.
       via  d5471ab s3: smbclient: Add new command deltree.
       via  413436b s3: client: Move struct file_list code to using talloc from malloc.
       via  28396c1 WHATSNEW: move the CTDB changes section before the Parameter changes
      from  7cf9a52 unittests: Add missing stdint.h include

https://git.samba.org/?p=samba.git;a=shortlog;h=v4-7-test


- Log -----------------------------------------------------------------
commit 895bd0d84dfae14f0344077d297072efba6e4da5
Author: Stefan Metzmacher <metze at samba.org>
Date:   Wed Jul 19 22:04:44 2017 +0200

    WHATSNEW: add a note about the new 'smbclient deltree' command.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=12914
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    
    Autobuild-User(v4-7-test): Stefan Metzmacher <metze at samba.org>
    Autobuild-Date(v4-7-test): Fri Jul 21 00:36:16 CEST 2017 on sn-devel-144

commit 994004212d6cd7a3dc4a5c9915d91f02982c9813
Author: Andreas Schneider <asn at samba.org>
Date:   Tue Jul 18 12:29:16 2017 +0200

    s3:tests: Fix directory creation and deletion of test_nosymlinks()
    
    This should fix flakey autobuild.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=12914
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    
    Autobuild-User(master): Jeremy Allison <jra at samba.org>
    Autobuild-Date(master): Wed Jul 19 11:59:52 CEST 2017 on sn-devel-144
    
    (cherry picked from commit bd7eab1639bb5eb70ff04b8f4b89373ca47daf08)

commit 293fa76cd29556fdef38fbb5a080b036184960b5
Author: Andreas Schneider <asn at samba.org>
Date:   Tue Jul 18 12:03:32 2017 +0200

    s3:tests: Fix directory creation and deletion of test_local_symlinks()
    
    This should fix flakey autobuild.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=12914
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    (cherry picked from commit b594e0cdd2b68d262377cfe438253244b89d089c)

commit 3b2d806cb97a5877fbd166cb22c3bdc97721e996
Author: Jeremy Allison <jra at samba.org>
Date:   Thu Jul 6 10:52:45 2017 -0700

    s3: tests: Add test for new smbclient "deltree" command.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=12914
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Alexander Bokovoy <ab at samba.org>
    Reviewed-by: Andreas Schneider <asn at samba.org>
    
    Autobuild-User(master): Andreas Schneider <asn at cryptomilk.org>
    Autobuild-Date(master): Fri Jul  7 13:38:24 CEST 2017 on sn-devel-144
    
    (cherry picked from commit b21ee14e2265a6dd11dd83c8e252a40de394585a)

commit 265070f7f62b979da2f4bbcbc085bf936802fb2c
Author: Jeremy Allison <jra at samba.org>
Date:   Wed Jul 5 17:23:48 2017 -0700

    docs: Document new smbclient deltree command.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=12914
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Alexander Bokovoy <ab at samba.org>
    Reviewed-by: Andreas Schneider <asn at samba.org>
    (cherry picked from commit f2f9f51fef8e264fdad11018e3c447db0ad03cc1)

commit d5471ab9d1e9724305b4cadc02d01a64ddaff4ae
Author: Jeremy Allison <jra at samba.org>
Date:   Wed Jul 5 17:21:18 2017 -0700

    s3: smbclient: Add new command deltree.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=12914
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Alexander Bokovoy <ab at samba.org>
    Reviewed-by: Andreas Schneider <asn at samba.org>
    (cherry picked from commit b6f484ae9ca737a0772b279b88fc285fe1cec0e9)

commit 413436b4c83ebf395ce2034b374ec8f4ee5babec
Author: Jeremy Allison <jra at samba.org>
Date:   Wed Jul 5 15:53:07 2017 -0700

    s3: client: Move struct file_list code to using talloc from malloc.
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=12914
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Alexander Bokovoy <ab at samba.org>
    Reviewed-by: Andreas Schneider <asn at samba.org>
    (cherry picked from commit e9d33bf89f7c3932522e7696182bfc590d049095)

commit 28396c103c846851a93b3093da8bae54aab83198
Author: Stefan Metzmacher <metze at samba.org>
Date:   Wed Jul 19 22:06:13 2017 +0200

    WHATSNEW: move the CTDB changes section before the Parameter changes
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>

-----------------------------------------------------------------------

Summary of changes:
 WHATSNEW.txt                              |  73 +++++-----
 docs-xml/manpages/smbclient.1.xml         |  10 ++
 source3/client/client.c                   | 207 ++++++++++++++++++++++++++--
 source3/script/tests/test_smbclient_s3.sh | 221 +++++++++++++++++++++++++++---
 4 files changed, 446 insertions(+), 65 deletions(-)


Changeset truncated at 500 lines:

diff --git a/WHATSNEW.txt b/WHATSNEW.txt
index 2b66242..5d49bb7 100644
--- a/WHATSNEW.txt
+++ b/WHATSNEW.txt
@@ -41,6 +41,9 @@ getfacl and symlink. Using "-mNT1" reenabled them, if the server supports SMB1.
 Note the default ("CORE") for "client min protocol" hasn't changed,
 so it's still possible to connect to SMB1-only servers by default.
 
+smbclient learned a new command "deltree" that is able to do
+a recursive deletion of a directory tree.
+
 
 NEW FEATURES/CHANGES
 ====================
@@ -241,41 +244,6 @@ the talloc_autofree_context() (which is inherently thread-unsafe)
 and still be valgrind-clean on exit. Modules that don't need to
 free long-lived data on exit should use the NULL talloc context.
 
-Parameter changes
------------------
-
-The "strict sync" global parameter has been changed from
-a default of "no" to "yes". This means smbd will by default
-obey client requests to synchronize unwritten data in operating
-system buffers safely onto disk. This is a safer default setting
-for modern SMB1/2/3 clients.
-
-The 'ntlm auth' option default is renamed to 'ntlmv2-only', reflecting
-the previous behaviour.  Two new values have been provided,
-'mschapv2-and-ntlmv2-only' (allowing MSCHAPv2 while denying NTLMv1)
-and 'disabled', totally disabling NTLM authentication and password
-changes.
-
-smb.conf changes
-================
-
-  Parameter Name                     Description             Default
-  --------------                     -----------             -------
-  allow unsafe cluster upgrade       New parameter           no
-  auth event notification            New parameter           no
-  auth methods                       Deprecated
-  client max protocol                Effective               SMB3_11
-                                     default changed
-  map untrusted to domain            New value/              auto
-                                     Default changed/
-                                     Deprecated
-  mit kdc command                    New parameter
-  profile acls                       Deprecated
-  rpc server dynamic port range      New parameter           49152-65535
-  strict sync                        Default changed         yes
-  password hash userPassword schemes New parameter
-  ntlm auth                          New values              ntlmv2-only
-
 CTDB changes
 ------------
 
@@ -320,6 +288,41 @@ CTDB changes
   uses. The data in replicated databases is valid for the lifetime of
   CTDB and cleared on first attach.
 
+Parameter changes
+-----------------
+
+The "strict sync" global parameter has been changed from
+a default of "no" to "yes". This means smbd will by default
+obey client requests to synchronize unwritten data in operating
+system buffers safely onto disk. This is a safer default setting
+for modern SMB1/2/3 clients.
+
+The 'ntlm auth' option default is renamed to 'ntlmv2-only', reflecting
+the previous behaviour.  Two new values have been provided,
+'mschapv2-and-ntlmv2-only' (allowing MSCHAPv2 while denying NTLMv1)
+and 'disabled', totally disabling NTLM authentication and password
+changes.
+
+smb.conf changes
+================
+
+  Parameter Name                     Description             Default
+  --------------                     -----------             -------
+  allow unsafe cluster upgrade       New parameter           no
+  auth event notification            New parameter           no
+  auth methods                       Deprecated
+  client max protocol                Effective               SMB3_11
+                                     default changed
+  map untrusted to domain            New value/              auto
+                                     Default changed/
+                                     Deprecated
+  mit kdc command                    New parameter
+  profile acls                       Deprecated
+  rpc server dynamic port range      New parameter           49152-65535
+  strict sync                        Default changed         yes
+  password hash userPassword schemes New parameter
+  ntlm auth                          New values              ntlmv2-only
+
 
 KNOWN ISSUES
 ============
diff --git a/docs-xml/manpages/smbclient.1.xml b/docs-xml/manpages/smbclient.1.xml
index 2b712fe..432f60d 100644
--- a/docs-xml/manpages/smbclient.1.xml
+++ b/docs-xml/manpages/smbclient.1.xml
@@ -655,6 +655,16 @@
 		</varlistentry>
 
 		<varlistentry>
+		<term>deltree <mask></term>
+		<listitem><para>The client will request that the server attempt
+		to delete all files and directories matching <replaceable>mask</replaceable> from the current working
+		directory on the server. Note this will recursively delete files and directories within
+		the directories selected even without the recurse command being set. If any of the delete
+		requests fail the command will stop processing at that point, leaving files and directories
+		not yet processed untouched. This is by design.</para></listitem>
+		</varlistentry>
+
+		<varlistentry>
 		<term>dir <mask></term>
 		<listitem><para>A list of the files matching <replaceable>mask</replaceable> in the current
 		working directory on the server will be retrieved from the server
diff --git a/source3/client/client.c b/source3/client/client.c
index c431a01..d8c96e6 100644
--- a/source3/client/client.c
+++ b/source3/client/client.c
@@ -2061,8 +2061,7 @@ static void free_file_list (struct file_list *l_head)
 	for (list = l_head; list; list = next) {
 		next = list->next;
 		DLIST_REMOVE(l_head, list);
-		SAFE_FREE(list->file_path);
-		SAFE_FREE(list);
+		TALLOC_FREE(list);
 	}
 }
 
@@ -2107,8 +2106,11 @@ static int cmd_select(void)
   match must be always set to true when calling this function
 ****************************************************************************/
 
-static int file_find(struct file_list **list, const char *directory,
-		      const char *expression, bool match)
+static int file_find(TALLOC_CTX *ctx,
+			struct file_list **list,
+			const char *directory,
+			const char *expression,
+			bool match)
 {
 	DIR *dir;
 	struct file_list *entry;
@@ -2128,7 +2130,8 @@ static int file_find(struct file_list **list, const char *directory,
 		if (!strcmp(".", dname))
 			continue;
 
-		if (asprintf(&path, "%s/%s", directory, dname) <= 0) {
+		path = talloc_asprintf(ctx, "%s/%s", directory, dname);
+		if (path == NULL) {
 			continue;
 		}
 
@@ -2139,29 +2142,33 @@ static int file_find(struct file_list **list, const char *directory,
 				if (ret == 0) {
 					if (S_ISDIR(statbuf.st_mode)) {
 						isdir = true;
-						ret = file_find(list, path, expression, false);
+						ret = file_find(ctx,
+								list,
+								path,
+								expression,
+								false);
 					}
 				} else {
 					d_printf("file_find: cannot stat file %s\n", path);
 				}
 
 				if (ret == -1) {
-					SAFE_FREE(path);
+					TALLOC_FREE(path);
 					closedir(dir);
 					return -1;
 				}
 			}
-			entry = SMB_MALLOC_P(struct file_list);
+			entry = talloc_zero(ctx, struct file_list);
 			if (!entry) {
 				d_printf("Out of memory in file_find\n");
 				closedir(dir);
 				return -1;
 			}
-			entry->file_path = path;
+			entry->file_path = talloc_move(entry, &path);
 			entry->isdir = isdir;
                         DLIST_ADD(*list, entry);
 		} else {
-			SAFE_FREE(path);
+			TALLOC_FREE(path);
 		}
         }
 
@@ -2185,7 +2192,7 @@ static int cmd_mput(void)
 
 		file_list = NULL;
 
-		ret = file_find(&file_list, ".", p, true);
+		ret = file_find(ctx, &file_list, ".", p, true);
 		if (ret) {
 			free_file_list(file_list);
 			continue;
@@ -2432,6 +2439,183 @@ static int cmd_del(void)
 }
 
 /****************************************************************************
+ Delete some files.
+****************************************************************************/
+
+static NTSTATUS delete_remote_files_list(struct cli_state *cli_state,
+					 struct file_list *flist)
+{
+	NTSTATUS status = NT_STATUS_OK;
+	struct file_list *deltree_list_iter = NULL;
+
+	for (deltree_list_iter = flist;
+			deltree_list_iter != NULL;
+			deltree_list_iter = deltree_list_iter->next) {
+		if (CLI_DIRSEP_CHAR == '/') {
+			/* POSIX. */
+			status = cli_posix_unlink(cli_state,
+					deltree_list_iter->file_path);
+		} else if (deltree_list_iter->isdir) {
+			status = cli_rmdir(cli_state,
+					deltree_list_iter->file_path);
+		} else {
+			status = cli_unlink(cli_state,
+					deltree_list_iter->file_path,
+					FILE_ATTRIBUTE_SYSTEM |
+					FILE_ATTRIBUTE_HIDDEN);
+		}
+		if (!NT_STATUS_IS_OK(status)) {
+			d_printf("%s deleting remote %s %s\n",
+				nt_errstr(status),
+				deltree_list_iter->isdir ?
+				"directory" : "file",
+				deltree_list_iter->file_path);
+			return status;
+		}
+	}
+	return NT_STATUS_OK;
+}
+
+/****************************************************************************
+ Save a list of files to delete.
+****************************************************************************/
+
+static struct file_list *deltree_list_head;
+
+static NTSTATUS do_deltree_list(struct cli_state *cli_state,
+				struct file_info *finfo,
+				const char *dir)
+{
+	struct file_list **file_list_head_pp = &deltree_list_head;
+	struct file_list *dt = NULL;
+
+	if (!do_this_one(finfo)) {
+		return NT_STATUS_OK;
+	}
+
+	/* skip if this is . or .. */
+	if (ISDOT(finfo->name) || ISDOTDOT(finfo->name)) {
+		return NT_STATUS_OK;
+	}
+
+	dt = talloc_zero(NULL, struct file_list);
+	if (dt == NULL) {
+		return NT_STATUS_NO_MEMORY;
+	}
+
+	/* create absolute filename for cli_ntcreate() */
+	dt->file_path = talloc_asprintf(dt,
+					"%s%s%s",
+					dir,
+					CLI_DIRSEP_STR,
+					finfo->name);
+	if (dt->file_path == NULL) {
+		TALLOC_FREE(dt);
+		return NT_STATUS_NO_MEMORY;
+	}
+
+	if (finfo->mode & FILE_ATTRIBUTE_DIRECTORY) {
+		dt->isdir = true;
+	}
+
+	DLIST_ADD(*file_list_head_pp, dt);
+	return NT_STATUS_OK;
+}
+
+static int cmd_deltree(void)
+{
+	TALLOC_CTX *ctx = talloc_tos();
+	char *buf = NULL;
+	NTSTATUS status = NT_STATUS_OK;
+	struct file_list *deltree_list_norecurse = NULL;
+	struct file_list *deltree_list_iter = NULL;
+	uint16_t attribute = FILE_ATTRIBUTE_SYSTEM |
+			     FILE_ATTRIBUTE_HIDDEN |
+			     FILE_ATTRIBUTE_DIRECTORY;
+	bool ok;
+	char *mask = talloc_strdup(ctx, client_get_cur_dir());
+	if (mask == NULL) {
+		return 1;
+	}
+	ok = next_token_talloc(ctx, &cmd_ptr, &buf, NULL);
+	if (!ok) {
+		d_printf("deltree <filename>\n");
+		return 1;
+	}
+	mask = talloc_asprintf_append(mask, "%s", buf);
+	if (mask == NULL) {
+		return 1;
+	}
+
+	deltree_list_head = NULL;
+
+	/*
+	 * Get the list of directories to
+	 * delete (in case mask has a wildcard).
+	 */
+	status = do_list(mask, attribute, do_deltree_list, false, true);
+	if (!NT_STATUS_IS_OK(status)) {
+		goto err;
+	}
+	deltree_list_norecurse = deltree_list_head;
+	deltree_list_head = NULL;
+
+	for (deltree_list_iter = deltree_list_norecurse;
+	     deltree_list_iter != NULL;
+	     deltree_list_iter = deltree_list_iter->next) {
+
+		if (deltree_list_iter->isdir == false) {
+			/* Just a regular file. */
+			if (CLI_DIRSEP_CHAR == '/') {
+				/* POSIX. */
+				status = cli_posix_unlink(cli,
+					deltree_list_iter->file_path);
+			} else {
+				status = cli_unlink(cli,
+					deltree_list_iter->file_path,
+					FILE_ATTRIBUTE_SYSTEM |
+					FILE_ATTRIBUTE_HIDDEN);
+			}
+			if (!NT_STATUS_IS_OK(status)) {
+				goto err;
+			}
+			continue;
+		}
+
+		/*
+		 * Get the list of files or directories to
+		 * delete in depth order.
+		 */
+		status = do_list(deltree_list_iter->file_path,
+				 attribute,
+				 do_deltree_list,
+				 true,
+				 true);
+		if (!NT_STATUS_IS_OK(status)) {
+			goto err;
+		}
+		status = delete_remote_files_list(cli, deltree_list_head);
+		free_file_list(deltree_list_head);
+		deltree_list_head = NULL;
+		if (!NT_STATUS_IS_OK(status)) {
+			goto err;
+		}
+	}
+
+	free_file_list(deltree_list_norecurse);
+	free_file_list(deltree_list_head);
+	return 0;
+
+  err:
+
+	free_file_list(deltree_list_norecurse);
+	free_file_list(deltree_list_head);
+	deltree_list_head = NULL;
+	return 1;
+}
+
+
+/****************************************************************************
  Wildcard delete some files.
 ****************************************************************************/
 
@@ -4998,6 +5182,7 @@ static struct {
   {"chown",cmd_chown,"<src> <uid> <gid> chown a file using UNIX uids and gids",{COMPL_REMOTE,COMPL_NONE}},
   {"close",cmd_close,"<fid> close a file given a fid",{COMPL_REMOTE,COMPL_NONE}},
   {"del",cmd_del,"<mask> delete all matching files",{COMPL_REMOTE,COMPL_NONE}},
+  {"deltree",cmd_deltree,"<mask> recursively delete all matching files and directories",{COMPL_REMOTE,COMPL_NONE}},
   {"dir",cmd_dir,"<mask> list the contents of the current directory",{COMPL_REMOTE,COMPL_NONE}},
   {"du",cmd_du,"<mask> computes the total size of the current directory",{COMPL_REMOTE,COMPL_NONE}},
   {"echo",cmd_echo,"ping the server",{COMPL_NONE,COMPL_NONE}},
diff --git a/source3/script/tests/test_smbclient_s3.sh b/source3/script/tests/test_smbclient_s3.sh
index 4cfd054..59d742f 100755
--- a/source3/script/tests/test_smbclient_s3.sh
+++ b/source3/script/tests/test_smbclient_s3.sh
@@ -1042,21 +1042,61 @@ EOF
 test_nosymlinks()
 {
 # Setup test dirs.
-    test_dir="$LOCAL_PATH/nosymlinks/test"
+    local_test_dir="$LOCAL_PATH/nosymlinks/test"
+    local_slink_name="$local_test_dir/source"
+    local_slink_target="$local_test_dir/nosymlink_target_file"
 
-    slink_name="$test_dir/source"
-    slink_target="$test_dir/target"
-    foobar_dir="$test_dir/foo/bar"
-    get_target="$test_dir/foo/bar/testfile"
+    share_test_dir="test"
+    share_foo_dir="$share_test_dir/foo"
+    share_foobar_dir="$share_test_dir/foo/bar"
+    share_target_file="$share_test_dir/foo/bar/testfile"
 
-    rm -rf $test_dir
+    rm -rf $local_test_dir
 
-    mkdir -p $test_dir
-    echo "$slink_target" > $slink_target
-    ln -s $slink_target $slink_name
+    local_nosymlink_target_file="nosymlink_target_file"
+    echo "$local_slink_target" > $local_nosymlink_target_file
+
+    local_foobar_target_file="testfile"
+    echo "$share_target_file" > $local_foobar_target_file
+
+    tmpfile=$PREFIX/smbclient_interactive_prompt_commands
+    cat > $tmpfile <<EOF
+mkdir $share_test_dir
+mkdir $share_foo_dir
+mkdir $share_foobar_dir
+cd /$share_test_dir
+put $local_nosymlink_target_file
+cd /$share_foobar_dir
+put $local_foobar_target_file
+quit
+EOF
+
+    cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/nosymlinks -I $SERVER_IP $LOCAL_ADDARGS < $tmpfile 2>&1'
+    eval echo "$cmd"
+    out=`eval $cmd`
+    ret=$?
+    rm -f $tmpfile
+    rm -f $local_nosymlink_target_file
+    rm -f $local_foobar_target_file
+
+    if [ $ret -ne 0 ] ; then
+       echo "$out"
+       echo "failed accessing local_symlinks with error $ret"
+       false
+       return
+    fi
+
+    echo "$out" | grep 'NT_STATUS_'
+    ret=$?
+    if [ $ret -eq 0 ] ; then
+       echo "$out"
+       echo "failed - got an NT_STATUS error"
+       false
+       return
+    fi
 
-    mkdir -p $foobar_dir
-    echo "$get_target" > $get_target
+# Create the symlink locally
+    ln -s $local_slink_target $local_slink_name
 
 # Getting a file through a symlink name should fail.
     tmpfile=$PREFIX/smbclient_interactive_prompt_commands
@@ -1136,6 +1176,33 @@ EOF
        echo "failed - NT_STATUS_XXXX doing cd foo\\bar; get testfile on \\nosymlinks"
        return 1
     fi
+
+# CLEANUP
+    rm -f $local_slink_name
+
+    cat > $tmpfile <<EOF
+deltree test
+quit
+EOF
+    cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/nosymlinks -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
+    eval echo "$cmd"
+    out=`eval $cmd`
+    ret=$?
+    rm -f $tmpfile
+
+    if [ $ret -ne 0 ] ; then
+       echo "$out"
+       echo "failed accessing nosymlinks with error $ret"
+       return 1
+    fi
+
+    echo "$out" | grep 'NT_STATUS'
+    ret=$?


-- 
Samba Shared Repository



More information about the samba-cvs mailing list