[PATCH] Some things from the smb2unix branch

Volker Lendecke Volker.Lendecke at SerNet.DE
Fri Jun 27 04:33:43 MDT 2014


Hi!

Attached find 4 patches from my smb2unix work. The first two
unify unix_timespec_to_nt_time() and
nt_time_to_unix_timespec() to take and return values, not
pointers. Struct timespec is small enough to not hurt when
passed as an argument.

The other two are self-explaining I think.

Review & push would be appreciated!

Thanks,

Volker

-- 
SerNet GmbH, Bahnhofsallee 1b, 37081 Göttingen
phone: +49-551-370000-0, fax: +49-551-370000-9
AG Göttingen, HRB 2816, GF: Dr. Johannes Loxen
http://www.sernet.de, mailto:kontakt at sernet.de
-------------- next part --------------
From 10cec71d15e1d5b83792d0895324151a2aeb9140 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 18 Jun 2014 12:21:06 +0000
Subject: [PATCH 1/4] lib: Align unix_timespec_to_nt_time with
 nt_time_to_unix_timespec

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 lib/util/time.c            |   13 +++++--------
 lib/util/time.h            |    2 +-
 source3/client/client.c    |   16 ++++++++--------
 source3/lib/time.c         |    2 +-
 source3/smbd/dosmode.c     |    2 +-
 source3/smbd/smb2_create.c |    2 +-
 6 files changed, 17 insertions(+), 20 deletions(-)

diff --git a/lib/util/time.c b/lib/util/time.c
index 993a55a..0c30264 100644
--- a/lib/util/time.c
+++ b/lib/util/time.c
@@ -940,21 +940,18 @@ void round_timespec_to_usec(struct timespec *ts)
  Put a 8 byte filetime from a struct timespec. Uses GMT.
 ****************************************************************************/
 
-_PUBLIC_ void unix_timespec_to_nt_time(NTTIME *nt, struct timespec ts)
+_PUBLIC_ NTTIME unix_timespec_to_nt_time(struct timespec ts)
 {
 	uint64_t d;
 
 	if (ts.tv_sec ==0 && ts.tv_nsec == 0) {
-		*nt = 0;
-		return;
+		return 0;
 	}
 	if (ts.tv_sec == TIME_T_MAX) {
-		*nt = 0x7fffffffffffffffLL;
-		return;
+		return 0x7fffffffffffffffLL;
 	}
 	if (ts.tv_sec == (time_t)-1) {
-		*nt = (uint64_t)-1;
-		return;
+		return (uint64_t)-1;
 	}
 
 	d = ts.tv_sec;
@@ -963,5 +960,5 @@ _PUBLIC_ void unix_timespec_to_nt_time(NTTIME *nt, struct timespec ts)
 	/* d is now in 100ns units. */
 	d += (ts.tv_nsec / 100);
 
-	*nt = d;
+	return d;
 }
diff --git a/lib/util/time.h b/lib/util/time.h
index bab8281..f3ed29b 100644
--- a/lib/util/time.h
+++ b/lib/util/time.h
@@ -314,6 +314,6 @@ struct timespec timespec_min(const struct timespec *ts1,
 int timespec_compare(const struct timespec *ts1, const struct timespec *ts2);
 void round_timespec_to_sec(struct timespec *ts);
 void round_timespec_to_usec(struct timespec *ts);
-void unix_timespec_to_nt_time(NTTIME *nt, struct timespec ts);
+NTTIME unix_timespec_to_nt_time(struct timespec ts);
 
 #endif /* _SAMBA_TIME_H_ */
diff --git a/source3/client/client.c b/source3/client/client.c
index 17985b9..c90c450 100644
--- a/source3/client/client.c
+++ b/source3/client/client.c
@@ -1725,16 +1725,16 @@ static int do_allinfo(const char *name)
 		return false;
 	}
 
-	unix_timespec_to_nt_time(&tmp, b_time);
+	tmp = unix_timespec_to_nt_time(b_time);
 	d_printf("create_time:    %s\n", nt_time_string(talloc_tos(), tmp));
 
-	unix_timespec_to_nt_time(&tmp, a_time);
+	tmp = unix_timespec_to_nt_time(a_time);
 	d_printf("access_time:    %s\n", nt_time_string(talloc_tos(), tmp));
 
-	unix_timespec_to_nt_time(&tmp, m_time);
+	tmp = unix_timespec_to_nt_time(m_time);
 	d_printf("write_time:     %s\n", nt_time_string(talloc_tos(), tmp));
 
-	unix_timespec_to_nt_time(&tmp, c_time);
+	tmp = unix_timespec_to_nt_time(c_time);
 	d_printf("change_time:    %s\n", nt_time_string(talloc_tos(), tmp));
 
 	d_printf("attributes: %s (%x)\n", attr_str(talloc_tos(), mode), mode);
@@ -1804,13 +1804,13 @@ static int do_allinfo(const char *name)
 			TALLOC_FREE(snap_name);
 			continue;
 		}
-		unix_timespec_to_nt_time(&tmp, b_time);
+		tmp = unix_timespec_to_nt_time(b_time);
 		d_printf("create_time:    %s\n", nt_time_string(talloc_tos(), tmp));
-		unix_timespec_to_nt_time(&tmp, a_time);
+		tmp = unix_timespec_to_nt_time(a_time);
 		d_printf("access_time:    %s\n", nt_time_string(talloc_tos(), tmp));
-		unix_timespec_to_nt_time(&tmp, m_time);
+		tmp =unix_timespec_to_nt_time(m_time);
 		d_printf("write_time:     %s\n", nt_time_string(talloc_tos(), tmp));
-		unix_timespec_to_nt_time(&tmp, c_time);
+		tmp = unix_timespec_to_nt_time(c_time);
 		d_printf("change_time:    %s\n", nt_time_string(talloc_tos(), tmp));
 		d_printf("size: %d\n", (int)size);
 	}
diff --git a/source3/lib/time.c b/source3/lib/time.c
index dab9b31..98ab0c7 100644
--- a/source3/lib/time.c
+++ b/source3/lib/time.c
@@ -172,7 +172,7 @@ void put_long_date_timespec(enum timestamp_set_resolution res, char *p, struct t
 {
 	NTTIME nt;
 	round_timespec(res, &ts);
-	unix_timespec_to_nt_time(&nt, ts);
+	nt = unix_timespec_to_nt_time(ts);
 	SBVAL(p, 0, nt);
 }
 
diff --git a/source3/smbd/dosmode.c b/source3/smbd/dosmode.c
index 6a6f673..b31b472 100644
--- a/source3/smbd/dosmode.c
+++ b/source3/smbd/dosmode.c
@@ -399,7 +399,7 @@ static bool set_ea_dos_attribute(connection_struct *conn,
 	dosattrib.info.info3.valid_flags = XATTR_DOSINFO_ATTRIB|
 					XATTR_DOSINFO_CREATE_TIME;
 	dosattrib.info.info3.attrib = dosmode;
-	unix_timespec_to_nt_time(&dosattrib.info.info3.create_time,
+	dosattrib.info.info3.create_time = unix_timespec_to_nt_time(
 				smb_fname->st.st_ex_btime);
 
 	DEBUG(10,("set_ea_dos_attributes: set attribute 0x%x, btime = %s on file %s\n",
diff --git a/source3/smbd/smb2_create.c b/source3/smbd/smb2_create.c
index 976e81a..d22df4d 100644
--- a/source3/smbd/smb2_create.c
+++ b/source3/smbd/smb2_create.c
@@ -974,7 +974,7 @@ static struct tevent_req *smbd_smb2_create_send(TALLOC_CTX *mem_ctx,
 		if (mxac) {
 			NTTIME last_write_time;
 
-			unix_timespec_to_nt_time(&last_write_time,
+			last_write_time = unix_timespec_to_nt_time(
 						 result->fsp_name->st.st_ex_mtime);
 			if (last_write_time != max_access_time) {
 				uint8_t p[8];
-- 
1.7.9.5


From 3f2412d8ede59ff5dc9c4898ddbd4a079ea4a481 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 18 Jun 2014 12:21:06 +0000
Subject: [PATCH 2/4] lib: Align nt_time_to_unix_timespec with
 unix_timespec_to_nt_time

Both take and return values now

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 lib/util/time.c                |    8 ++++----
 lib/util/time.h                |    2 +-
 source3/lib/time.c             |    2 +-
 source3/libsmb/cli_smb2_fnum.c |    6 +++---
 source3/smbd/dosmode.c         |    4 ++--
 5 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/lib/util/time.c b/lib/util/time.c
index 0c30264..03345ec 100644
--- a/lib/util/time.c
+++ b/lib/util/time.c
@@ -134,7 +134,7 @@ struct timespec convert_time_t_to_timespec(time_t t)
 **/
 time_t nt_time_to_unix(NTTIME nt)
 {
-	return convert_timespec_to_time_t(nt_time_to_unix_timespec(&nt));
+	return convert_timespec_to_time_t(nt_time_to_unix_timespec(nt));
 }
 
 
@@ -784,18 +784,18 @@ _PUBLIC_ int get_time_zone(time_t t)
 	return tm_diff(&tm_utc,tm);
 }
 
-struct timespec nt_time_to_unix_timespec(const NTTIME *nt)
+struct timespec nt_time_to_unix_timespec(NTTIME nt)
 {
 	int64_t d;
 	struct timespec ret;
 
-	if (*nt == 0 || *nt == (int64_t)-1) {
+	if (nt == 0 || nt == (int64_t)-1) {
 		ret.tv_sec = 0;
 		ret.tv_nsec = 0;
 		return ret;
 	}
 
-	d = (int64_t)*nt;
+	d = (int64_t)nt;
 	/* d is now in 100ns units, since jan 1st 1601".
 	   Save off the ns fraction. */
 
diff --git a/lib/util/time.h b/lib/util/time.h
index f3ed29b..8595bb0 100644
--- a/lib/util/time.h
+++ b/lib/util/time.h
@@ -298,7 +298,7 @@ bool nt_time_equal(NTTIME *t1, NTTIME *t2);
 
 void interpret_dos_date(uint32_t date,int *year,int *month,int *day,int *hour,int *minute,int *second);
 
-struct timespec nt_time_to_unix_timespec(const NTTIME *nt);
+struct timespec nt_time_to_unix_timespec(NTTIME nt);
 
 time_t convert_timespec_to_time_t(struct timespec ts);
 
diff --git a/source3/lib/time.c b/source3/lib/time.c
index 98ab0c7..30ad1ec 100644
--- a/source3/lib/time.c
+++ b/source3/lib/time.c
@@ -250,7 +250,7 @@ struct timespec interpret_long_date(const char *p)
 		ret.tv_nsec = 0;
 		return ret;
 	}
-	return nt_time_to_unix_timespec(&nt);
+	return nt_time_to_unix_timespec(nt);
 }
 
 /*******************************************************************
diff --git a/source3/libsmb/cli_smb2_fnum.c b/source3/libsmb/cli_smb2_fnum.c
index 87edf4e..9832b09 100644
--- a/source3/libsmb/cli_smb2_fnum.c
+++ b/source3/libsmb/cli_smb2_fnum.c
@@ -822,9 +822,9 @@ NTSTATUS cli_smb2_qpathinfo_basic(struct cli_state *cli,
 
 	ZERO_STRUCTP(sbuf);
 
-	sbuf->st_ex_atime = nt_time_to_unix_timespec(&cr.last_access_time);
-	sbuf->st_ex_mtime = nt_time_to_unix_timespec(&cr.last_write_time);
-	sbuf->st_ex_ctime = nt_time_to_unix_timespec(&cr.change_time);
+	sbuf->st_ex_atime = nt_time_to_unix_timespec(cr.last_access_time);
+	sbuf->st_ex_mtime = nt_time_to_unix_timespec(cr.last_write_time);
+	sbuf->st_ex_ctime = nt_time_to_unix_timespec(cr.change_time);
 	sbuf->st_ex_size = cr.end_of_file;
 	*attributes = cr.file_attributes;
 
diff --git a/source3/smbd/dosmode.c b/source3/smbd/dosmode.c
index b31b472..2e68711 100644
--- a/source3/smbd/dosmode.c
+++ b/source3/smbd/dosmode.c
@@ -319,7 +319,7 @@ static bool get_ea_dos_attribute(connection_struct *conn,
 			if (!null_nttime(dosattrib.info.info1.create_time)) {
 				struct timespec create_time =
 					nt_time_to_unix_timespec(
-						&dosattrib.info.info1.create_time);
+						dosattrib.info.info1.create_time);
 
 				update_stat_ex_create_time(&smb_fname->st,
 							create_time);
@@ -341,7 +341,7 @@ static bool get_ea_dos_attribute(connection_struct *conn,
 					!null_nttime(dosattrib.info.info3.create_time)) {
 				struct timespec create_time =
 					nt_time_to_unix_timespec(
-						&dosattrib.info.info3.create_time);
+						dosattrib.info.info3.create_time);
 
 				update_stat_ex_create_time(&smb_fname->st,
 							create_time);
-- 
1.7.9.5


From d5216650f133c272c1f5d6c98bd50f39a3fbc5c0 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Fri, 27 Jun 2014 09:32:34 +0000
Subject: [PATCH 3/4] libcli: Make smb2cli_create return blobs

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 libcli/smb/smb2cli_create.c     |   15 ++++++++++++---
 libcli/smb/smbXcli_base.h       |    8 ++++++--
 libcli/smb/tstream_smbXcli_np.c |    2 +-
 source3/libsmb/cli_smb2_fnum.c  |    2 +-
 source3/torture/test_smb2.c     |   32 ++++++++++++++++----------------
 5 files changed, 36 insertions(+), 23 deletions(-)

diff --git a/libcli/smb/smb2cli_create.c b/libcli/smb/smb2cli_create.c
index bcd674e..0db546c 100644
--- a/libcli/smb/smb2cli_create.c
+++ b/libcli/smb/smb2cli_create.c
@@ -238,7 +238,9 @@ static void smb2cli_create_done(struct tevent_req *subreq)
 NTSTATUS smb2cli_create_recv(struct tevent_req *req,
 			     uint64_t *fid_persistent,
 			     uint64_t *fid_volatile,
-			     struct smb_create_returns *cr)
+			     struct smb_create_returns *cr,
+			     TALLOC_CTX *mem_ctx,
+			     struct smb2_create_blobs *blobs)
 {
 	struct smb2cli_create_state *state =
 		tevent_req_data(req,
@@ -253,6 +255,10 @@ NTSTATUS smb2cli_create_recv(struct tevent_req *req,
 	if (cr) {
 		*cr = state->cr;
 	}
+	if (blobs) {
+		blobs->num_blobs = state->blobs.num_blobs;
+		blobs->blobs = talloc_move(mem_ctx, &state->blobs.blobs);
+	}
 	return NT_STATUS_OK;
 }
 
@@ -271,7 +277,9 @@ NTSTATUS smb2cli_create(struct smbXcli_conn *conn,
 			struct smb2_create_blobs *blobs,
 			uint64_t *fid_persistent,
 			uint64_t *fid_volatile,
-			struct smb_create_returns *cr)
+			struct smb_create_returns *cr,
+			TALLOC_CTX *mem_ctx,
+			struct smb2_create_blobs *ret_blobs)
 {
 	TALLOC_CTX *frame = talloc_stackframe();
 	struct tevent_context *ev;
@@ -302,7 +310,8 @@ NTSTATUS smb2cli_create(struct smbXcli_conn *conn,
 	if (!tevent_req_poll_ntstatus(req, ev, &status)) {
 		goto fail;
 	}
-	status = smb2cli_create_recv(req, fid_persistent, fid_volatile, cr);
+	status = smb2cli_create_recv(req, fid_persistent, fid_volatile, cr,
+				     mem_ctx, ret_blobs);
  fail:
 	TALLOC_FREE(frame);
 	return status;
diff --git a/libcli/smb/smbXcli_base.h b/libcli/smb/smbXcli_base.h
index 8cde85e..06015b1 100644
--- a/libcli/smb/smbXcli_base.h
+++ b/libcli/smb/smbXcli_base.h
@@ -461,7 +461,9 @@ struct tevent_req *smb2cli_create_send(
 NTSTATUS smb2cli_create_recv(struct tevent_req *req,
 			     uint64_t *fid_persistent,
 			     uint64_t *fid_volatile,
-			     struct smb_create_returns *cr);
+			     struct smb_create_returns *cr,
+			     TALLOC_CTX *mem_ctx,
+			     struct smb2_create_blobs *blobs);
 NTSTATUS smb2cli_create(struct smbXcli_conn *conn,
 			uint32_t timeout_msec,
 			struct smbXcli_session *session,
@@ -477,7 +479,9 @@ NTSTATUS smb2cli_create(struct smbXcli_conn *conn,
 			struct smb2_create_blobs *blobs,
 			uint64_t *fid_persistent,
 			uint64_t *fid_volatile,
-			struct smb_create_returns *cr);
+			struct smb_create_returns *cr,
+			TALLOC_CTX *mem_ctx,
+			struct smb2_create_blobs *ret_blobs);
 
 struct tevent_req *smb2cli_close_send(TALLOC_CTX *mem_ctx,
 				      struct tevent_context *ev,
diff --git a/libcli/smb/tstream_smbXcli_np.c b/libcli/smb/tstream_smbXcli_np.c
index c32fd6f..77a326b 100644
--- a/libcli/smb/tstream_smbXcli_np.c
+++ b/libcli/smb/tstream_smbXcli_np.c
@@ -279,7 +279,7 @@ static void tstream_smbXcli_np_open_done(struct tevent_req *subreq)
 		status = smb2cli_create_recv(subreq,
 					     &state->fid_persistent,
 					     &state->fid_volatile,
-					     NULL);
+					     NULL, NULL, NULL);
 	}
 	TALLOC_FREE(subreq);
 	if (!NT_STATUS_IS_OK(status)) {
diff --git a/source3/libsmb/cli_smb2_fnum.c b/source3/libsmb/cli_smb2_fnum.c
index 9832b09..3fdd49a 100644
--- a/source3/libsmb/cli_smb2_fnum.c
+++ b/source3/libsmb/cli_smb2_fnum.c
@@ -234,7 +234,7 @@ static void cli_smb2_create_fnum_done(struct tevent_req *subreq)
 	NTSTATUS status;
 
 	status = smb2cli_create_recv(subreq, &h.fid_persistent,
-				     &h.fid_volatile, &state->cr);
+				     &h.fid_volatile, &state->cr, NULL, NULL);
 	TALLOC_FREE(subreq);
 	if (tevent_req_nterror(req, status)) {
 		return;
diff --git a/source3/torture/test_smb2.c b/source3/torture/test_smb2.c
index 1923668..49acf3a 100644
--- a/source3/torture/test_smb2.c
+++ b/source3/torture/test_smb2.c
@@ -84,7 +84,7 @@ bool run_smb2_basic(int dummy)
 			NULL, /* smb2_create_blobs *blobs */
 			&fid_persistent,
 			&fid_volatile,
-			NULL);
+			NULL, NULL, NULL);
 	if (!NT_STATUS_IS_OK(status)) {
 		printf("smb2cli_create returned %s\n", nt_errstr(status));
 		return false;
@@ -147,7 +147,7 @@ bool run_smb2_basic(int dummy)
 			NULL, /* smb2_create_blobs *blobs */
 			&fid_persistent,
 			&fid_volatile,
-			NULL);
+			NULL, NULL, NULL);
 	if (!NT_STATUS_IS_OK(status)) {
 		printf("smb2cli_create returned %s\n", nt_errstr(status));
 		return false;
@@ -347,7 +347,7 @@ bool run_smb2_session_reconnect(int dummy)
 			NULL, /* smb2_create_blobs *blobs */
 			&fid_persistent,
 			&fid_volatile,
-			NULL);
+			NULL, NULL, NULL);
 	if (!NT_STATUS_IS_OK(status)) {
 		printf("smb2cli_create on cli1 %s\n", nt_errstr(status));
 		return false;
@@ -584,7 +584,7 @@ bool run_smb2_session_reconnect(int dummy)
 			NULL, /* smb2_create_blobs *blobs */
 			&fid_persistent,
 			&fid_volatile,
-			NULL);
+			NULL, NULL, NULL);
 	if (!NT_STATUS_EQUAL(status, NT_STATUS_ACCESS_DENIED) &&
 	    !NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED)) {
 		printf("smb2cli_create on cli2 %s\n", nt_errstr(status));
@@ -645,7 +645,7 @@ bool run_smb2_session_reconnect(int dummy)
 			NULL, /* smb2_create_blobs *blobs */
 			&fid_persistent,
 			&fid_volatile,
-			NULL);
+			NULL, NULL, NULL);
 	if (!NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED) &&
 	    !NT_STATUS_EQUAL(status, NT_STATUS_NETWORK_NAME_DELETED))
 	{
@@ -673,7 +673,7 @@ bool run_smb2_session_reconnect(int dummy)
 			NULL, /* smb2_create_blobs *blobs */
 			&fid_persistent,
 			&fid_volatile,
-			NULL);
+			NULL, NULL, NULL);
 	if (!NT_STATUS_IS_OK(status)) {
 		printf("smb2cli_create on cli2 %s\n", nt_errstr(status));
 		return false;
@@ -769,7 +769,7 @@ bool run_smb2_tcon_dependence(int dummy)
 			NULL, /* smb2_create_blobs *blobs */
 			&fid_persistent,
 			&fid_volatile,
-			NULL);
+			NULL, NULL, NULL);
 	if (!NT_STATUS_IS_OK(status)) {
 		printf("smb2cli_create on cli %s\n", nt_errstr(status));
 		return false;
@@ -1181,7 +1181,7 @@ bool run_smb2_multi_channel(int dummy)
 			NULL, /* smb2_create_blobs *blobs */
 			&fid_persistent,
 			&fid_volatile,
-			NULL);
+			NULL, NULL, NULL);
 	if (!NT_STATUS_IS_OK(status)) {
 		printf("smb2cli_create on cli2 %s\n", nt_errstr(status));
 		return false;
@@ -1344,7 +1344,7 @@ bool run_smb2_multi_channel(int dummy)
 			NULL, /* smb2_create_blobs *blobs */
 			&fid_persistent,
 			&fid_volatile,
-			NULL);
+			NULL, NULL, NULL);
 	if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
 		printf("smb2cli_create %s\n", nt_errstr(status));
 		return false;
@@ -1362,7 +1362,7 @@ bool run_smb2_multi_channel(int dummy)
 			NULL, /* smb2_create_blobs *blobs */
 			&fid_persistent,
 			&fid_volatile,
-			NULL);
+			NULL, NULL, NULL);
 	if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
 		printf("smb2cli_create %s\n", nt_errstr(status));
 		return false;
@@ -1380,7 +1380,7 @@ bool run_smb2_multi_channel(int dummy)
 			NULL, /* smb2_create_blobs *blobs */
 			&fid_persistent,
 			&fid_volatile,
-			NULL);
+			NULL, NULL, NULL);
 	if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
 		printf("smb2cli_create %s\n", nt_errstr(status));
 		return false;
@@ -1512,7 +1512,7 @@ bool run_smb2_session_reauth(int dummy)
 			NULL, /* smb2_create_blobs *blobs */
 			&fid_persistent,
 			&fid_volatile,
-			NULL);
+			NULL, NULL, NULL);
 	if (!NT_STATUS_IS_OK(status)) {
 		printf("smb2cli_create %s\n", nt_errstr(status));
 		return false;
@@ -1532,7 +1532,7 @@ bool run_smb2_session_reauth(int dummy)
 			NULL, /* smb2_create_blobs *blobs */
 			&dir_persistent,
 			&dir_volatile,
-			NULL);
+			NULL, NULL, NULL);
 	if (!NT_STATUS_IS_OK(status)) {
 		printf("smb2cli_create returned %s\n", nt_errstr(status));
 		return false;
@@ -1718,7 +1718,7 @@ bool run_smb2_session_reauth(int dummy)
 			NULL, /* smb2_create_blobs *blobs */
 			&fid_persistent,
 			&fid_volatile,
-			NULL);
+			NULL, NULL, NULL);
 	if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
 		printf("smb2cli_create %s\n", nt_errstr(status));
 		return false;
@@ -1738,7 +1738,7 @@ bool run_smb2_session_reauth(int dummy)
 			NULL, /* smb2_create_blobs *blobs */
 			&dir_persistent,
 			&dir_volatile,
-			NULL);
+			NULL, NULL, NULL);
 	if (!NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
 		printf("smb2cli_create returned %s\n", nt_errstr(status));
 		return false;
@@ -1894,7 +1894,7 @@ bool run_smb2_session_reauth(int dummy)
 			NULL, /* smb2_create_blobs *blobs */
 			&fid_persistent,
 			&fid_volatile,
-			NULL);
+			NULL, NULL, NULL);
 	if (!NT_STATUS_IS_OK(status)) {
 		printf("smb2cli_create %s\n", nt_errstr(status));
 		return false;
-- 
1.7.9.5


From 8b314a2c2ec0152deb79d9f78229aca704ea0ef9 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Fri, 27 Jun 2014 09:47:36 +0000
Subject: [PATCH 4/4] libcli: Make cli_smb2_close_fnum async

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/libsmb/cli_smb2_fnum.c |  110 +++++++++++++++++++++++++++++++---------
 source3/libsmb/cli_smb2_fnum.h |    5 ++
 2 files changed, 92 insertions(+), 23 deletions(-)

diff --git a/source3/libsmb/cli_smb2_fnum.c b/source3/libsmb/cli_smb2_fnum.c
index 3fdd49a..dc9652c 100644
--- a/source3/libsmb/cli_smb2_fnum.c
+++ b/source3/libsmb/cli_smb2_fnum.c
@@ -318,45 +318,109 @@ NTSTATUS cli_smb2_create_fnum(struct cli_state *cli,
 
 /***************************************************************
  Small wrapper that allows SMB2 close to use a uint16_t fnum.
- Synchronous only.
 ***************************************************************/
 
-NTSTATUS cli_smb2_close_fnum(struct cli_state *cli, uint16_t fnum)
+struct cli_smb2_close_fnum_state {
+	struct cli_state *cli;
+	uint16_t fnum;
+	struct smb2_hnd *ph;
+};
+
+static void cli_smb2_close_fnum_done(struct tevent_req *subreq);
+
+struct tevent_req *cli_smb2_close_fnum_send(TALLOC_CTX *mem_ctx,
+					    struct tevent_context *ev,
+					    struct cli_state *cli,
+					    uint16_t fnum)
 {
-	struct smb2_hnd *ph = NULL;
+	struct tevent_req *req, *subreq;
+	struct cli_smb2_close_fnum_state *state;
 	NTSTATUS status;
 
-	if (smbXcli_conn_has_async_calls(cli->conn)) {
-		/*
-		 * Can't use sync call while an async call is in flight
-		 */
-		return NT_STATUS_INVALID_PARAMETER;
+	req = tevent_req_create(mem_ctx, &state,
+				struct cli_smb2_close_fnum_state);
+	if (req == NULL) {
+		return NULL;
 	}
+	state->cli = cli;
+	state->fnum = fnum;
 
 	if (smbXcli_conn_protocol(cli->conn) < PROTOCOL_SMB2_02) {
-		return NT_STATUS_INVALID_PARAMETER;
+		tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
+		return tevent_req_post(req, ev);
 	}
 
-	status = map_fnum_to_smb2_handle(cli,
-					fnum,
-					&ph);
-	if (!NT_STATUS_IS_OK(status)) {
-		return status;
+	status = map_fnum_to_smb2_handle(cli, fnum, &state->ph);
+	if (tevent_req_nterror(req, status)) {
+		return tevent_req_post(req, ev);
 	}
 
-	status = smb2cli_close(cli->conn,
-				cli->timeout,
-				cli->smb2.session,
-				cli->smb2.tcon,
-				0,
-				ph->fid_persistent,
-				ph->fid_volatile);
+	subreq = smb2cli_close_send(state, ev, cli->conn, cli->timeout,
+				    cli->smb2.session, cli->smb2.tcon,
+				    0, state->ph->fid_persistent,
+				    state->ph->fid_volatile);
+	if (tevent_req_nomem(subreq, req)) {
+		return tevent_req_post(req, ev);
+	}
+	tevent_req_set_callback(subreq, cli_smb2_close_fnum_done, req);
+	return req;
+}
+
+static void cli_smb2_close_fnum_done(struct tevent_req *subreq)
+{
+	struct tevent_req *req = tevent_req_callback_data(
+		subreq, struct tevent_req);
+	struct cli_smb2_close_fnum_state *state = tevent_req_data(
+		req, struct cli_smb2_close_fnum_state);
+	NTSTATUS status;
+
+	status = smb2cli_close_recv(req);
+	if (tevent_req_nterror(req, status)) {
+		return;
+	}
 
 	/* Delete the fnum -> handle mapping. */
-	if (NT_STATUS_IS_OK(status)) {
-		status = delete_smb2_handle_mapping(cli, &ph, fnum);
+	status = delete_smb2_handle_mapping(state->cli, &state->ph,
+					    state->fnum);
+	if (tevent_req_nterror(req, status)) {
+		return;
 	}
+	tevent_req_done(req);
+}
+
+NTSTATUS cli_smb2_close_fnum_recv(struct tevent_req *req)
+{
+	return tevent_req_simple_recv_ntstatus(req);
+}
+
+NTSTATUS cli_smb2_close_fnum(struct cli_state *cli, uint16_t fnum)
+{
+	TALLOC_CTX *frame = talloc_stackframe();
+	struct tevent_context *ev;
+	struct tevent_req *req;
+	NTSTATUS status = NT_STATUS_NO_MEMORY;
 
+	if (smbXcli_conn_has_async_calls(cli->conn)) {
+		/*
+		 * Can't use sync call while an async call is in flight
+		 */
+		status = NT_STATUS_INVALID_PARAMETER;
+		goto fail;
+	}
+	ev = samba_tevent_context_init(frame);
+	if (ev == NULL) {
+		goto fail;
+	}
+	req = cli_smb2_close_fnum_send(frame, ev, cli, fnum);
+	if (req == NULL) {
+		goto fail;
+	}
+	if (!tevent_req_poll_ntstatus(req, ev, &status)) {
+		goto fail;
+	}
+	status = cli_smb2_close_fnum_recv(req);
+ fail:
+	TALLOC_FREE(frame);
 	return status;
 }
 
diff --git a/source3/libsmb/cli_smb2_fnum.h b/source3/libsmb/cli_smb2_fnum.h
index 9394918..173dba0 100644
--- a/source3/libsmb/cli_smb2_fnum.h
+++ b/source3/libsmb/cli_smb2_fnum.h
@@ -48,6 +48,11 @@ NTSTATUS cli_smb2_create_fnum(struct cli_state *cli,
 			uint16_t *pfid,
 			struct smb_create_returns *cr);
 
+struct tevent_req *cli_smb2_close_fnum_send(TALLOC_CTX *mem_ctx,
+					    struct tevent_context *ev,
+					    struct cli_state *cli,
+					    uint16_t fnum);
+NTSTATUS cli_smb2_close_fnum_recv(struct tevent_req *req);
 NTSTATUS cli_smb2_close_fnum(struct cli_state *cli, uint16_t fnum);
 NTSTATUS cli_smb2_mkdir(struct cli_state *cli, const char *dirname);
 NTSTATUS cli_smb2_rmdir(struct cli_state *cli, const char *dirname);
-- 
1.7.9.5



More information about the samba-technical mailing list