[SCM] Samba Shared Repository - branch v3-6-test updated

Jeremy Allison jra at samba.org
Fri Oct 29 14:12:01 MDT 2010


The branch, v3-6-test has been updated
       via  29fc7ae Fix bug #7700 - Improvement of return code of smbclient
      from  6e7e7bb s3:registry: move regio.h from include/ to registry/

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=v3-6-test


- Log -----------------------------------------------------------------
commit 29fc7ae50fa10481425b32dea779474da4c0fc33
Author: Jeremy Allison <jra at samba.org>
Date:   Fri Oct 29 13:11:26 2010 -0700

    Fix bug #7700 - Improvement of return code of smbclient
    
    Based on an initial patch from H Hasegawa <hasegawa.hiroyuki at fujixerox.co.jp>.
    Convert cli_list and associated functions to take calls that return NTSTATUS.
    
    Note that this is different from the code that went into master
    as many of the changes that were made to cli_list in master have
    not been back-ported to v3-6-test.
    
    Jeremy.

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

Summary of changes:
 source3/client/client.c       |  152 +++++++++++++++++++++++++++--------------
 source3/client/client_proto.h |    4 +-
 source3/client/clitar.c       |   45 ++++++++----
 source3/include/proto.h       |    6 +-
 source3/libgpo/gpo_filesync.c |   32 ++++----
 source3/libsmb/clilist.c      |    6 +-
 source3/libsmb/libsmb_dir.c   |   21 +++---
 source3/torture/masktest.c    |    3 +-
 source3/torture/nbio.c        |   18 +++--
 source3/torture/torture.c     |   27 +++++---
 source3/utils/net_rpc.c       |   34 +++++----
 11 files changed, 214 insertions(+), 134 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source3/client/client.c b/source3/client/client.c
index 2731c03..9de5b12 100644
--- a/source3/client/client.c
+++ b/source3/client/client.c
@@ -518,14 +518,15 @@ static bool do_this_one(struct file_info *finfo)
  Display info about a file.
 ****************************************************************************/
 
-static void display_finfo(struct cli_state *cli_state, struct file_info *finfo,
+static NTSTATUS display_finfo(struct cli_state *cli_state, struct file_info *finfo,
 			  const char *dir)
 {
 	time_t t;
 	TALLOC_CTX *ctx = talloc_tos();
+	NTSTATUS status = NT_STATUS_OK;
 
 	if (!do_this_one(finfo)) {
-		return;
+		return NT_STATUS_OK;
 	}
 
 	t = finfo->mtime_ts.tv_sec; /* the time is assumed to be passed as GMT */
@@ -542,7 +543,7 @@ static void display_finfo(struct cli_state *cli_state, struct file_info *finfo,
 
 		/* skip if this is . or .. */
 		if ( strequal(finfo->name,"..") || strequal(finfo->name,".") )
-			return;
+			return NT_STATUS_OK;
 		/* create absolute filename for cli_ntcreate() FIXME */
 		afname = talloc_asprintf(ctx,
 					"%s%s%s",
@@ -550,7 +551,7 @@ static void display_finfo(struct cli_state *cli_state, struct file_info *finfo,
 					CLI_DIRSEP_STR,
 					finfo->name);
 		if (!afname) {
-			return;
+			return NT_STATUS_NO_MEMORY;
 		}
 		/* print file meta date header */
 		d_printf( "FILENAME:%s\n", finfo->name);
@@ -570,6 +571,7 @@ static void display_finfo(struct cli_state *cli_state, struct file_info *finfo,
 				DEBUG( 0, ("display_finfo() failed to "
 					"get security descriptor: %s",
 					cli_errstr(cli_state)));
+				status = cli_nt_error(cli_state);
 			} else {
 				display_sec_desc(sd);
 			}
@@ -577,18 +579,20 @@ static void display_finfo(struct cli_state *cli_state, struct file_info *finfo,
 		}
 		TALLOC_FREE(afname);
 	}
+	return status;
 }
 
 /****************************************************************************
  Accumulate size of a file.
 ****************************************************************************/
 
-static void do_du(struct cli_state *cli_state, struct file_info *finfo,
+static NTSTATUS do_du(struct cli_state *cli_state, struct file_info *finfo,
 		  const char *dir)
 {
 	if (do_this_one(finfo)) {
 		dir_total += finfo->size;
 	}
+	return NT_STATUS_OK;
 }
 
 static bool do_list_recurse;
@@ -597,7 +601,7 @@ static char *do_list_queue = 0;
 static long do_list_queue_size = 0;
 static long do_list_queue_start = 0;
 static long do_list_queue_end = 0;
-static void (*do_list_fn)(struct cli_state *cli_state, struct file_info *,
+static NTSTATUS (*do_list_fn)(struct cli_state *cli_state, struct file_info *,
 			  const char *dir);
 
 /****************************************************************************
@@ -715,18 +719,19 @@ static int do_list_queue_empty(void)
  A helper for do_list.
 ****************************************************************************/
 
-static void do_list_helper(const char *mntpoint, struct file_info *f,
+static NTSTATUS do_list_helper(const char *mntpoint, struct file_info *f,
 			   const char *mask, void *state)
 {
 	struct cli_state *cli_state = (struct cli_state *)state;
 	TALLOC_CTX *ctx = talloc_tos();
 	char *dir = NULL;
 	char *dir_end = NULL;
+	NTSTATUS status = NT_STATUS_OK;
 
 	/* Work out the directory. */
 	dir = talloc_strdup(ctx, mask);
 	if (!dir) {
-		return;
+		return NT_STATUS_NO_MEMORY;
 	}
 	if ((dir_end = strrchr(dir, CLI_DIRSEP_CHAR)) != NULL) {
 		*dir_end = '\0';
@@ -734,7 +739,10 @@ static void do_list_helper(const char *mntpoint, struct file_info *f,
 
 	if (f->mode & aDIR) {
 		if (do_list_dirs && do_this_one(f)) {
-			do_list_fn(cli_state, f, dir);
+			status = do_list_fn(cli_state, f, dir);
+			if (!NT_STATUS_IS_OK(status)) {
+				return status;
+			}
 		}
 		if (do_list_recurse &&
 		    f->name &&
@@ -746,7 +754,7 @@ static void do_list_helper(const char *mntpoint, struct file_info *f,
 			if (!f->name[0]) {
 				d_printf("Empty dir name returned. Possible server misconfiguration.\n");
 				TALLOC_FREE(dir);
-				return;
+				return NT_STATUS_UNSUCCESSFUL;
 			}
 
 			mask2 = talloc_asprintf(ctx,
@@ -755,7 +763,7 @@ static void do_list_helper(const char *mntpoint, struct file_info *f,
 					mask);
 			if (!mask2) {
 				TALLOC_FREE(dir);
-				return;
+				return NT_STATUS_NO_MEMORY;
 			}
 			p = strrchr_m(mask2,CLI_DIRSEP_CHAR);
 			if (p) {
@@ -769,28 +777,29 @@ static void do_list_helper(const char *mntpoint, struct file_info *f,
 					CLI_DIRSEP_STR);
 			if (!mask2) {
 				TALLOC_FREE(dir);
-				return;
+				return NT_STATUS_NO_MEMORY;
 			}
 			add_to_do_list_queue(mask2);
 			TALLOC_FREE(mask2);
 		}
 		TALLOC_FREE(dir);
-		return;
+		return NT_STATUS_OK;
 	}
 
 	if (do_this_one(f)) {
-		do_list_fn(cli_state, f, dir);
+		status = do_list_fn(cli_state, f, dir);
 	}
 	TALLOC_FREE(dir);
+	return status;
 }
 
 /****************************************************************************
  A wrapper around cli_list that adds recursion.
 ****************************************************************************/
 
-void do_list(const char *mask,
+NTSTATUS do_list(const char *mask,
 			uint16 attribute,
-			void (*fn)(struct cli_state *cli_state, struct file_info *,
+			NTSTATUS (*fn)(struct cli_state *cli_state, struct file_info *,
 				   const char *dir),
 			bool rec,
 			bool dirs)
@@ -799,6 +808,7 @@ void do_list(const char *mask,
 	TALLOC_CTX *ctx = talloc_tos();
 	struct cli_state *targetcli = NULL;
 	char *targetpath = NULL;
+	NTSTATUS ret_status = NT_STATUS_OK;
 
 	if (in_do_list && rec) {
 		fprintf(stderr, "INTERNAL ERROR: do_list called recursively when the recursive flag is true\n");
@@ -826,7 +836,7 @@ void do_list(const char *mask,
 			char *head = talloc_strdup(ctx, do_list_queue_head());
 
 			if (!head) {
-				return;
+				return NT_STATUS_NO_MEMORY;
 			}
 
 			/* check for dfs */
@@ -837,8 +847,12 @@ void do_list(const char *mask,
 				continue;
 			}
 
-			cli_list(targetcli, targetpath, attribute,
-				 do_list_helper, targetcli);
+			if (cli_list(targetcli, targetpath, attribute,
+				 do_list_helper, targetcli) < 0) {
+				d_printf("%s listing %s\n",
+					 cli_errstr(targetcli), targetpath);
+				ret_status = cli_nt_error(targetcli);
+			}
 			remove_do_list_queue_head();
 			if ((! do_list_queue_empty()) && (fn == display_finfo)) {
 				char *next_file = do_list_queue_head();
@@ -867,18 +881,21 @@ void do_list(const char *mask,
 		/* check for dfs */
 		if (cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli, &targetpath)) {
 			if (cli_list(targetcli, targetpath, attribute,
-				     do_list_helper, targetcli) == -1) {
+				     do_list_helper, targetcli) < 0) {
 				d_printf("%s listing %s\n",
 					cli_errstr(targetcli), targetpath);
+				ret_status = cli_nt_error(targetcli);
 			}
 			TALLOC_FREE(targetpath);
 		} else {
 			d_printf("do_list: [%s] %s\n", mask, cli_errstr(cli));
+			ret_status = cli_nt_error(cli);
 		}
 	}
 
 	in_do_list = 0;
 	reset_do_list_queue();
+	return ret_status;
 }
 
 /****************************************************************************
@@ -892,6 +909,7 @@ static int cmd_dir(void)
 	char *mask = NULL;
 	char *buf = NULL;
 	int rc = 1;
+	NTSTATUS status;
 
 	dir_total = 0;
 	mask = talloc_strdup(ctx, client_get_cur_dir());
@@ -918,7 +936,10 @@ static int cmd_dir(void)
 		client_set_cwd(client_get_cur_dir());
 	}
 
-	do_list(mask, attribute, display_finfo, recurse, true);
+	status = do_list(mask, attribute, display_finfo, recurse, true);
+	if (!NT_STATUS_IS_OK(status)) {
+		return 1;
+	}
 
 	rc = do_dskattr();
 
@@ -937,6 +958,7 @@ static int cmd_du(void)
 	uint16 attribute = aDIR | aSYSTEM | aHIDDEN;
 	char *mask = NULL;
 	char *buf = NULL;
+	NTSTATUS status;
 	int rc = 1;
 
 	dir_total = 0;
@@ -962,7 +984,10 @@ static int cmd_du(void)
 		mask = talloc_strdup(ctx, "*");
 	}
 
-	do_list(mask, attribute, do_du, recurse, true);
+	status = do_list(mask, attribute, do_du, recurse, true);
+	if (!NT_STATUS_IS_OK(status)) {
+		return 1;
+	}
 
 	rc = do_dskattr();
 
@@ -1160,10 +1185,11 @@ static int cmd_get(void)
  Do an mget operation on one file.
 ****************************************************************************/
 
-static void do_mget(struct cli_state *cli_state, struct file_info *finfo,
+static NTSTATUS do_mget(struct cli_state *cli_state, struct file_info *finfo,
 		    const char *dir)
 {
 	TALLOC_CTX *ctx = talloc_tos();
+	NTSTATUS status = NT_STATUS_OK;
 	char *rname = NULL;
 	char *quest = NULL;
 	char *saved_curdir = NULL;
@@ -1171,32 +1197,32 @@ static void do_mget(struct cli_state *cli_state, struct file_info *finfo,
 	char *new_cd = NULL;
 
 	if (!finfo->name) {
-		return;
+		return NT_STATUS_OK;
 	}
 
 	if (strequal(finfo->name,".") || strequal(finfo->name,".."))
-		return;
+		return NT_STATUS_OK;
 
 	if (abort_mget)	{
 		d_printf("mget aborted\n");
-		return;
+		return NT_STATUS_UNSUCCESSFUL;
 	}
 
 	if (finfo->mode & aDIR) {
 		if (asprintf(&quest,
 			 "Get directory %s? ",finfo->name) < 0) {
-			return;
+			return NT_STATUS_NO_MEMORY;
 		}
 	} else {
 		if (asprintf(&quest,
 			 "Get file %s? ",finfo->name) < 0) {
-			return;
+			return NT_STATUS_NO_MEMORY;
 		}
 	}
 
 	if (prompt && !yesno(quest)) {
 		SAFE_FREE(quest);
-		return;
+		return NT_STATUS_OK;
 	}
 	SAFE_FREE(quest);
 
@@ -1206,17 +1232,17 @@ static void do_mget(struct cli_state *cli_state, struct file_info *finfo,
 				client_get_cur_dir(),
 				finfo->name);
 		if (!rname) {
-			return;
+			return NT_STATUS_NO_MEMORY;
 		}
 		do_get(rname, finfo->name, false);
 		TALLOC_FREE(rname);
-		return;
+		return NT_STATUS_OK;
 	}
 
 	/* handle directories */
 	saved_curdir = talloc_strdup(ctx, client_get_cur_dir());
 	if (!saved_curdir) {
-		return;
+		return NT_STATUS_NO_MEMORY;
 	}
 
 	new_cd = talloc_asprintf(ctx,
@@ -1225,7 +1251,7 @@ static void do_mget(struct cli_state *cli_state, struct file_info *finfo,
 				finfo->name,
 				CLI_DIRSEP_STR);
 	if (!new_cd) {
-		return;
+		return NT_STATUS_NO_MEMORY;
 	}
 	client_set_cur_dir(new_cd);
 
@@ -1238,13 +1264,13 @@ static void do_mget(struct cli_state *cli_state, struct file_info *finfo,
 	    mkdir(finfo->name,0777) != 0) {
 		d_printf("failed to create directory %s\n",finfo->name);
 		client_set_cur_dir(saved_curdir);
-		return;
+		return map_nt_error_from_unix(errno);
 	}
 
 	if (chdir(finfo->name) != 0) {
 		d_printf("failed to chdir to directory %s\n",finfo->name);
 		client_set_cur_dir(saved_curdir);
-		return;
+		return map_nt_error_from_unix(errno);
 	}
 
 	mget_mask = talloc_asprintf(ctx,
@@ -1252,18 +1278,24 @@ static void do_mget(struct cli_state *cli_state, struct file_info *finfo,
 			client_get_cur_dir());
 
 	if (!mget_mask) {
-		return;
+		return NT_STATUS_NO_MEMORY;
+	}
+
+	status = do_list(mget_mask, aSYSTEM | aHIDDEN | aDIR,do_mget,false, true);
+	if (!NT_STATUS_IS_OK(status)) {
+		return status;
 	}
 
-	do_list(mget_mask, aSYSTEM | aHIDDEN | aDIR,do_mget,false, true);
 	if (chdir("..") == -1) {
 		d_printf("do_mget: failed to chdir to .. (error %s)\n",
 			strerror(errno) );
+		return map_nt_error_from_unix(errno);
 	}
 	client_set_cur_dir(saved_curdir);
 	TALLOC_FREE(mget_mask);
 	TALLOC_FREE(saved_curdir);
 	TALLOC_FREE(new_cd);
+	return NT_STATUS_OK;
 }
 
 /****************************************************************************
@@ -1341,6 +1373,7 @@ static int cmd_mget(void)
 	uint16 attribute = aSYSTEM | aHIDDEN;
 	char *mget_mask = NULL;
 	char *buf = NULL;
+	NTSTATUS status = NT_STATUS_OK;
 
 	if (recurse) {
 		attribute |= aDIR;
@@ -1349,6 +1382,7 @@ static int cmd_mget(void)
 	abort_mget = false;
 
 	while (next_token_talloc(ctx, &cmd_ptr,&buf,NULL)) {
+
 		mget_mask = talloc_strdup(ctx, client_get_cur_dir());
 		if (!mget_mask) {
 			return 1;
@@ -1362,7 +1396,10 @@ static int cmd_mget(void)
 		if (!mget_mask) {
 			return 1;
 		}
-		do_list(mget_mask, attribute, do_mget, false, true);
+		status = do_list(mget_mask, attribute, do_mget, false, true);
+		if (!NT_STATUS_IS_OK(status)) {
+			return 1;
+		}
 	}
 
 	if (mget_mask == NULL) {
@@ -1377,7 +1414,10 @@ static int cmd_mget(void)
 		if (!mget_mask) {
 			return 1;
 		}
-		do_list(mget_mask, attribute, do_mget, false, true);
+		status = do_list(mget_mask, attribute, do_mget, false, true);
+		if (!NT_STATUS_IS_OK(status)) {
+			return 1;
+		}
 	}
 
 	return 0;
@@ -2138,10 +2178,11 @@ static int cmd_queue(void)
  Delete some files.
 ****************************************************************************/
 
-static void do_del(struct cli_state *cli_state, struct file_info *finfo,
+static NTSTATUS do_del(struct cli_state *cli_state, struct file_info *finfo,
 		   const char *dir)
 {
 	TALLOC_CTX *ctx = talloc_tos();
+	NTSTATUS status = NT_STATUS_OK;
 	char *mask = NULL;
 
 	mask = talloc_asprintf(ctx,
@@ -2150,19 +2191,21 @@ static void do_del(struct cli_state *cli_state, struct file_info *finfo,
 				CLI_DIRSEP_CHAR,
 				finfo->name);
 	if (!mask) {
-		return;
+		return NT_STATUS_NO_MEMORY;
 	}
 
 	if (finfo->mode & aDIR) {
 		TALLOC_FREE(mask);
-		return;
+		return NT_STATUS_OK;
 	}
 
-	if (!NT_STATUS_IS_OK(cli_unlink(cli_state, mask, aSYSTEM | aHIDDEN))) {
+	status = cli_unlink(cli_state, mask, aSYSTEM | aHIDDEN);
+	if (!NT_STATUS_IS_OK(status)) {
 		d_printf("%s deleting remote file %s\n",
 				cli_errstr(cli_state),mask);
 	}
 	TALLOC_FREE(mask);
+	return status;
 }
 
 /****************************************************************************
@@ -2174,6 +2217,7 @@ static int cmd_del(void)
 	TALLOC_CTX *ctx = talloc_tos();
 	char *mask = NULL;
 	char *buf = NULL;
+	NTSTATUS status = NT_STATUS_OK;
 	uint16 attribute = aSYSTEM | aHIDDEN;
 
 	if (recurse) {
@@ -2193,7 +2237,10 @@ static int cmd_del(void)
 		return 1;
 	}
 
-	do_list(mask,attribute,do_del,false,false);
+	status = do_list(mask,attribute,do_del,false,false);
+	if (!NT_STATUS_IS_OK(status)) {
+		return 1;
+	}
 	return 0;
 }
 
@@ -4204,7 +4251,7 @@ struct completion_remote {
 	int len;
 };
 
-static void completion_remote_filter(const char *mnt,
+static NTSTATUS completion_remote_filter(const char *mnt,
 				struct file_info *f,
 				const char *mask,
 				void *state)
@@ -4212,13 +4259,13 @@ static void completion_remote_filter(const char *mnt,
 	struct completion_remote *info = (struct completion_remote *)state;
 
 	if (info->count >= MAX_COMPLETIONS - 1) {
-		return;
+		return NT_STATUS_OK;
 	}


-- 
Samba Shared Repository


More information about the samba-cvs mailing list