[SCM] Samba Shared Repository - branch master updated

Andreas Schneider asn at samba.org
Fri Jul 7 11:39:03 UTC 2017


The branch, master has been updated
       via  b21ee14 s3: tests: Add test for new smbclient "deltree" command.
       via  f2f9f51 docs: Document new smbclient deltree command.
       via  b6f484a s3: smbclient: Add new command deltree.
       via  e9d33bf s3: client: Move struct file_list code to using talloc from malloc.
       via  98e30cf waf: Do not install _ldb_text.py if we have system libldb
      from  5eccc2f messaging: Remove messaging_handler_send

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit b21ee14e2265a6dd11dd83c8e252a40de394585a
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.
    
    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

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

    docs: Document new smbclient deltree command.
    
    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>

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

    s3: smbclient: Add new command deltree.
    
    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>

commit e9d33bf89f7c3932522e7696182bfc590d049095
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.
    
    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>

commit 98e30cf491c63eb0b69c13ad42b720d22944adda
Author: Andreas Schneider <asn at samba.org>
Date:   Thu Jul 6 07:44:28 2017 +0200

    waf: Do not install _ldb_text.py if we have system libldb
    
    _ldb_text.py is installed as part of the ldb package and also if you
    compile Samba with the system ldb version. This way we have have the
    file twice in the same location and run into file confilcts.
    
    This has already been fixed some time ago:
        60dc26bfe1573265dcbd87b9dd3439f945e57d97
    
    BUG: https://bugzilla.samba.org/show_bug.cgi?id=12882
    
    Signed-off-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Alexander Bokovoy <ab at samba.org>

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

Summary of changes:
 docs-xml/manpages/smbclient.1.xml         |  10 ++
 lib/ldb/wscript                           |  13 +-
 source3/client/client.c                   | 207 ++++++++++++++++++++++++++++--
 source3/script/tests/test_smbclient_s3.sh |  47 +++++++
 4 files changed, 261 insertions(+), 16 deletions(-)


Changeset truncated at 500 lines:

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/lib/ldb/wscript b/lib/ldb/wscript
index 7f81fe3..b4ae62a 100644
--- a/lib/ldb/wscript
+++ b/lib/ldb/wscript
@@ -177,12 +177,15 @@ def build(bld):
                                      realname='ldb.so',
                                      cflags='-DPACKAGE_VERSION=\"%s\"' % VERSION)
 
-        for env in bld.gen_python_environments(['PKGCONFIGDIR']):
-                bld.SAMBA_SCRIPT('_ldb_text.py',
-                                 pattern='_ldb_text.py',
-                                 installdir='python')
+        # Do only install this file as part of the Samba build if we do not
+        # use the system libldb!
+        if not bld.CONFIG_SET('USING_SYSTEM_PYLDB_UTIL'):
+            for env in bld.gen_python_environments(['PKGCONFIGDIR']):
+                    bld.SAMBA_SCRIPT('_ldb_text.py',
+                                     pattern='_ldb_text.py',
+                                     installdir='python')
 
-                bld.INSTALL_FILES('${PYTHONARCHDIR}', '_ldb_text.py')
+                    bld.INSTALL_FILES('${PYTHONARCHDIR}', '_ldb_text.py')
 
     if not bld.CONFIG_SET('USING_SYSTEM_LDB'):
         if bld.is_install:
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..3cbe6f5 100755
--- a/source3/script/tests/test_smbclient_s3.sh
+++ b/source3/script/tests/test_smbclient_s3.sh
@@ -1189,6 +1189,49 @@ EOF
     fi
 }
 
+# Test smbclient deltree command
+test_deltree()
+{
+    tmpfile=$PREFIX/smbclient_interactive_prompt_commands
+    deltree_dir=$PREFIX/deltree_dir
+
+    rm -rf $deltree_dir
+    cat > $tmpfile <<EOF
+mkdir deltree_dir
+mkdir deltree_dir/foo
+mkdir deltree_dir/foo/bar
+put ${SMBCLIENT} deltree_dir/foo/bar/client
+deltree deltree_dir
+quit
+EOF
+    cmd='CLI_FORCE_INTERACTIVE=yes $SMBCLIENT "$@" -U$USERNAME%$PASSWORD //$SERVER/tmp -I $SERVER_IP $ADDARGS < $tmpfile 2>&1'
+    eval echo "$cmd"
+    out=`eval $cmd`
+    ret=$?
+
+    if [ $ret != 0 ] ; then
+	echo "$out"
+	echo "failed deltree test with output $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
+
+    if [ -d $deltree_dir ] ; then
+	echo "deltree did not delete everything"
+	false
+	return
+    fi
+}
+
 test_server_os_message()
 {
     tmpfile=$PREFIX/smbclient_interactive_prompt_commands
@@ -1326,6 +1369,10 @@ testit "follow local symlinks" \
     test_local_symlinks || \
     failed=`expr $failed + 1`
 
+testit "smbclient deltree command" \
+    test_deltree || \
+    failed=`expr $failed + 1`
+
 testit "server os message" \
     test_server_os_message || \
     failed=`expr $failed + 1`


-- 
Samba Shared Repository



More information about the samba-cvs mailing list