[SCM] Samba Shared Repository - branch master updated - release-4-0-0alpha7-1453-g4cbd0c7

Jeremy Allison jra at samba.org
Wed May 6 04:00:41 GMT 2009


The branch, master has been updated
       via  4cbd0c77e42627c76dda88af5326ef91415a652d (commit)
      from  1db0b20d8a26fb60299d0ed7553d7a4847aee84f (commit)

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


- Log -----------------------------------------------------------------
commit 4cbd0c77e42627c76dda88af5326ef91415a652d
Author: Jeremy Allison <jra at samba.org>
Date:   Tue May 5 20:59:22 2009 -0700

    Make cli_getatr() async.
    Jeremy.

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

Summary of changes:
 source3/client/clitar.c      |    4 +-
 source3/include/proto.h      |   16 ++++-
 source3/lib/time.c           |    2 +-
 source3/libsmb/clifile.c     |  151 ++++++++++++++++++++++++++++++++++-------
 source3/libsmb/libsmb_file.c |    2 +-
 source3/torture/torture.c    |   10 ++--
 6 files changed, 149 insertions(+), 36 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source3/client/clitar.c b/source3/client/clitar.c
index fd6c4cc..80f6c81 100644
--- a/source3/client/clitar.c
+++ b/source3/client/clitar.c
@@ -594,7 +594,9 @@ static void do_setrattr(char *name, uint16 attr, int set)
 {
 	uint16 oldattr;
 
-	if (!cli_getatr(cli, name, &oldattr, NULL, NULL)) return;
+	if (!NT_STATUS_IS_OK(cli_getatr(cli, name, &oldattr, NULL, NULL))) {
+		return;
+	}
 
 	if (set == ATTRSET) {
 		attr |= oldattr;
diff --git a/source3/include/proto.h b/source3/include/proto.h
index 30c11a5..194d74d 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -1018,6 +1018,7 @@ struct timespec get_ctimespec(const SMB_STRUCT_STAT *pst);
 void set_ctimespec(SMB_STRUCT_STAT *pst, struct timespec ts);
 void dos_filetime_timespec(struct timespec *tsp);
 time_t make_unix_date2(const void *date_ptr, int zone_offset);
+time_t make_unix_date3(const void *date_ptr, int zone_offset);
 time_t srv_make_unix_date(const void *date_ptr);
 time_t srv_make_unix_date2(const void *date_ptr);
 time_t srv_make_unix_date3(const void *date_ptr);
@@ -2459,12 +2460,23 @@ NTSTATUS cli_getattrE(struct cli_state *cli,
 			time_t *change_time,
 			time_t *access_time,
 			time_t *write_time);
-bool cli_getatr(struct cli_state *cli, const char *fname,
-		uint16_t *attr, SMB_OFF_T *size, time_t *write_time);
 bool cli_setattrE(struct cli_state *cli, int fd,
 		  time_t change_time,
                   time_t access_time,
                   time_t write_time);
+struct tevent_req *cli_getatr_send(TALLOC_CTX *mem_ctx,
+				struct event_context *ev,
+				struct cli_state *cli,
+				const char *fname);
+NTSTATUS cli_getatr_recv(struct tevent_req *req,
+				uint16_t *attr,
+				SMB_OFF_T *size,
+				time_t *write_time);
+NTSTATUS cli_getatr(struct cli_state *cli,
+			const char *fname,
+			uint16_t *attr,
+			SMB_OFF_T *size,
+			time_t *write_time);
 bool cli_setatr(struct cli_state *cli, const char *fname, uint16_t attr, time_t t);
 struct tevent_req *cli_chkpath_send(TALLOC_CTX *mem_ctx,
 				  struct event_context *ev,
diff --git a/source3/lib/time.c b/source3/lib/time.c
index 3e45a2e..611debe 100644
--- a/source3/lib/time.c
+++ b/source3/lib/time.c
@@ -621,7 +621,7 @@ time_t make_unix_date2(const void *date_ptr, int zone_offset)
  these generally arrive as localtimes, with corresponding DST.
 ******************************************************************/
 
-static time_t make_unix_date3(const void *date_ptr, int zone_offset)
+time_t make_unix_date3(const void *date_ptr, int zone_offset)
 {
 	time_t t = (time_t)IVAL(date_ptr,0);
 	if (!null_mtime(t)) {
diff --git a/source3/libsmb/clifile.c b/source3/libsmb/clifile.c
index bc466d1..357923a 100644
--- a/source3/libsmb/clifile.c
+++ b/source3/libsmb/clifile.c
@@ -2243,49 +2243,148 @@ NTSTATUS cli_getattrE(struct cli_state *cli,
  Do a SMBgetatr call
 ****************************************************************************/
 
-bool cli_getatr(struct cli_state *cli, const char *fname,
-		uint16_t *attr, SMB_OFF_T *size, time_t *write_time)
-{
-	char *p;
+static void cli_getatr_done(struct tevent_req *subreq);
 
-	memset(cli->outbuf,'\0',smb_size);
-	memset(cli->inbuf,'\0',smb_size);
+struct cli_getatr_state {
+	int zone_offset;
+	uint16_t attr;
+	SMB_OFF_T size;
+	time_t write_time;
+};
 
-	cli_set_message(cli->outbuf,0,0,True);
+struct tevent_req *cli_getatr_send(TALLOC_CTX *mem_ctx,
+				struct event_context *ev,
+				struct cli_state *cli,
+				const char *fname)
+{
+	struct tevent_req *req = NULL, *subreq = NULL;
+	struct cli_getatr_state *state = NULL;
+	uint8_t additional_flags = 0;
+	uint8_t *bytes = NULL;
 
-	SCVAL(cli->outbuf,smb_com,SMBgetatr);
-	SSVAL(cli->outbuf,smb_tid,cli->cnum);
-	cli_setup_packet(cli);
+	req = tevent_req_create(mem_ctx, &state, struct cli_getatr_state);
+	if (req == NULL) {
+		return NULL;
+	}
 
-	p = smb_buf(cli->outbuf);
-	*p++ = 4;
-	p += clistr_push(cli, p, fname,
-			cli->bufsize - PTR_DIFF(p,cli->outbuf), STR_TERMINATE);
+	state->zone_offset = cli->serverzone;
 
-	cli_setup_bcc(cli, p);
+	bytes = talloc_array(state, uint8_t, 1);
+	if (tevent_req_nomem(bytes, req)) {
+		return tevent_req_post(req, ev);
+	}
+	bytes[0] = 4;
+	bytes = smb_bytes_push_str(bytes, cli_ucs2(cli), fname,
+				   strlen(fname)+1, NULL);
 
-	cli_send_smb(cli);
-	if (!cli_receive_smb(cli)) {
-		return False;
+	if (tevent_req_nomem(bytes, req)) {
+		return tevent_req_post(req, ev);
 	}
 
-	if (cli_is_error(cli)) {
-		return False;
+	subreq = cli_smb_send(state, ev, cli, SMBgetatr, additional_flags,
+			      0, NULL, talloc_get_size(bytes), bytes);
+	if (tevent_req_nomem(subreq, req)) {
+		return tevent_req_post(req, ev);
 	}
+	tevent_req_set_callback(subreq, cli_getatr_done, req);
+	return req;
+}
 
-	if (size) {
-		*size = IVAL(cli->inbuf, smb_vwv3);
+static void cli_getatr_done(struct tevent_req *subreq)
+{
+	struct tevent_req *req = tevent_req_callback_data(
+		subreq, struct tevent_req);
+	struct cli_getatr_state *state = tevent_req_data(
+		req, struct cli_getatr_state);
+	uint8_t wct;
+	uint16_t *vwv = NULL;
+	NTSTATUS status;
+
+	status = cli_smb_recv(subreq, 4, &wct, &vwv, NULL, NULL);
+	if (!NT_STATUS_IS_OK(status)) {
+		tevent_req_nterror(req, status);
+		return;
 	}
 
+	state->attr = SVAL(vwv+0,0);
+	state->size = (SMB_OFF_T)IVAL(vwv+3,0);
+	state->write_time = make_unix_date3(vwv+1, state->zone_offset);
+
+	TALLOC_FREE(subreq);
+	tevent_req_done(req);
+}
+
+NTSTATUS cli_getatr_recv(struct tevent_req *req,
+			uint16_t *attr,
+			SMB_OFF_T *size,
+			time_t *write_time)
+{
+	struct cli_getatr_state *state = tevent_req_data(
+				req, struct cli_getatr_state);
+	NTSTATUS status;
+
+	if (tevent_req_is_nterror(req, &status)) {
+		return status;
+	}
+	if (attr) {
+		*attr = state->attr;
+	}
+	if (size) {
+		*size = state->size;
+	}
 	if (write_time) {
-		*write_time = cli_make_unix_date3(cli, cli->inbuf+smb_vwv1);
+		*write_time = state->write_time;
 	}
+	return NT_STATUS_OK;
+}
 
-	if (attr) {
-		*attr = SVAL(cli->inbuf,smb_vwv0);
+NTSTATUS cli_getatr(struct cli_state *cli,
+			const char *fname,
+			uint16_t *attr,
+			SMB_OFF_T *size,
+			time_t *write_time)
+{
+	TALLOC_CTX *frame = talloc_stackframe();
+	struct event_context *ev = NULL;
+	struct tevent_req *req = NULL;
+	NTSTATUS status = NT_STATUS_OK;
+
+	if (cli_has_async_calls(cli)) {
+		/*
+		 * Can't use sync call while an async call is in flight
+		 */
+		status = NT_STATUS_INVALID_PARAMETER;
+		goto fail;
 	}
 
-	return True;
+	ev = event_context_init(frame);
+	if (ev == NULL) {
+		status = NT_STATUS_NO_MEMORY;
+		goto fail;
+	}
+
+	req = cli_getatr_send(frame, ev, cli, fname);
+	if (req == NULL) {
+		status = NT_STATUS_NO_MEMORY;
+		goto fail;
+	}
+
+	if (!tevent_req_poll(req, ev)) {
+		status = map_nt_error_from_unix(errno);
+		goto fail;
+	}
+
+	status = cli_getatr_recv(req,
+				attr,
+				size,
+				write_time);
+
+ fail:
+	TALLOC_FREE(frame);
+	if (!NT_STATUS_IS_OK(status)) {
+		cli_set_error(cli, status);
+	}
+	return status;
 }
 
 /****************************************************************************
diff --git a/source3/libsmb/libsmb_file.c b/source3/libsmb/libsmb_file.c
index a561265..63590d2 100644
--- a/source3/libsmb/libsmb_file.c
+++ b/source3/libsmb/libsmb_file.c
@@ -578,7 +578,7 @@ SMBC_getatr(SMBCCTX * context,
                 return False;
         }
         
-	if (cli_getatr(targetcli, targetpath, mode, size, &write_time)) {
+	if (NT_STATUS_IS_OK(cli_getatr(targetcli, targetpath, mode, size, &write_time))) {
                 
                 struct timespec w_time_ts;
                 
diff --git a/source3/torture/torture.c b/source3/torture/torture.c
index 00e8266..bc7ac12 100644
--- a/source3/torture/torture.c
+++ b/source3/torture/torture.c
@@ -2471,7 +2471,7 @@ static bool run_attrtest(int dummy)
 	cli_open(cli, fname, 
 			O_RDWR | O_CREAT | O_TRUNC, DENY_NONE, &fnum);
 	cli_close(cli, fnum);
-	if (!cli_getatr(cli, fname, NULL, NULL, &t)) {
+	if (!NT_STATUS_IS_OK(cli_getatr(cli, fname, NULL, NULL, &t))) {
 		printf("getatr failed (%s)\n", cli_errstr(cli));
 		correct = False;
 	}
@@ -2490,7 +2490,7 @@ static bool run_attrtest(int dummy)
 		correct = True;
 	}
 
-	if (!cli_getatr(cli, fname, NULL, NULL, &t)) {
+	if (!NT_STATUS_IS_OK(cli_getatr(cli, fname, NULL, NULL, &t))) {
 		printf("getatr failed (%s)\n", cli_errstr(cli));
 		correct = True;
 	}
@@ -3796,7 +3796,7 @@ static bool run_opentest(int dummy)
 	}
 
 	/* Ensure size == 20. */
-	if (!cli_getatr(cli1, fname, NULL, &fsize, NULL)) {
+	if (!NT_STATUS_IS_OK(cli_getatr(cli1, fname, NULL, &fsize, NULL))) {
 		printf("(3) getatr failed (%s)\n", cli_errstr(cli1));
 		return False;
 	}
@@ -3819,7 +3819,7 @@ static bool run_opentest(int dummy)
 	}
 
 	/* Ensure size == 0. */
-	if (!cli_getatr(cli1, fname, NULL, &fsize, NULL)) {
+	if (!NT_STATUS_IS_OK(cli_getatr(cli1, fname, NULL, &fsize, NULL))) {
 		printf("(3) getatr failed (%s)\n", cli_errstr(cli1));
 		return False;
 	}
@@ -4285,7 +4285,7 @@ static bool run_openattrtest(int dummy)
 				return False;
 			}
 
-			if (!cli_getatr(cli1, fname, &attr, NULL, NULL)) {
+			if (!NT_STATUS_IS_OK(cli_getatr(cli1, fname, &attr, NULL, NULL))) {
 				printf("getatr(2) failed (%s)\n", cli_errstr(cli1));
 				return False;
 			}


-- 
Samba Shared Repository


More information about the samba-cvs mailing list