[PATCH] A few patches
Volker Lendecke
Volker.Lendecke at SerNet.DE
Sun Jun 29 08:36:29 MDT 2014
On Sun, Jun 29, 2014 at 04:35:41PM +0200, Volker Lendecke wrote:
> Hi!
>
> Attached find a collection of patches:
>
> Some libsmb cleanup (survives autobuild now! :-)), the
> bugfix for 10680 and some brlock cleanup.
>
> Review would be appreciated!
... now with attachment!
> 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
--
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 67235747c9d5cf66e3588d3608a67c6261597e34 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 01/10] 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 87edf4e..e4dfbf3 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 1c46b5829a567e9421078873b022217772fa1035 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 02/10] 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 7ee635aded0907e4abe31875d36675db5de0b90c 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 03/10] 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 e4dfbf3..3fdd49a 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 b9b95bd105b038fdcb0931c859c39f66f2b33d3d 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 04/10] 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..3a04ea1 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(subreq);
+ 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
From 8d0f1b19c0a0be7f143c168e6b6b222ce27f9a45 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sun, 29 Jun 2014 08:56:03 +0000
Subject: [PATCH 05/10] smbstatus: Fix an uninitialized variable
We only print valid share mode entries, stale ones don't count. In
traverse, let the callback decide about staleness.
https://bugzilla.samba.org/show_bug.cgi?id=10680
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/locking/share_mode_lock.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/source3/locking/share_mode_lock.c b/source3/locking/share_mode_lock.c
index 5e25404..12f499b 100644
--- a/source3/locking/share_mode_lock.c
+++ b/source3/locking/share_mode_lock.c
@@ -484,6 +484,7 @@ static int traverse_fn(struct db_record *rec, void *_state)
NDR_PRINT_DEBUG(share_mode_data, d);
}
for (i=0; i<d->num_share_modes; i++) {
+ d->share_modes[i].stale = false; /* [skip] in idl */
state->fn(&d->share_modes[i],
d->servicepath, d->base_name,
state->private_data);
--
1.7.9.5
From a8646bebfb0c71c3dccef6ba3662b659e54aa687 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sun, 29 Jun 2014 11:07:08 +0200
Subject: [PATCH 06/10] torture3: Add some brlock entries in cleanup2
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/torture/test_cleanup.c | 28 ++++++++++++++++++++++++++--
1 file changed, 26 insertions(+), 2 deletions(-)
diff --git a/source3/torture/test_cleanup.c b/source3/torture/test_cleanup.c
index a831ed7..e96a5de 100644
--- a/source3/torture/test_cleanup.c
+++ b/source3/torture/test_cleanup.c
@@ -74,9 +74,9 @@ bool run_cleanup1(int dummy)
bool run_cleanup2(int dummy)
{
- struct cli_state *cli1, *cli2;
+ struct cli_state *cli1, *cli2, *cli3;
const char *fname = "\\cleanup2";
- uint16_t fnum1, fnum2;
+ uint16_t fnum1, fnum2, fnum3;
NTSTATUS status;
char buf;
@@ -100,6 +100,30 @@ bool run_cleanup2(int dummy)
return false;
}
+ if (!torture_open_connection(&cli3, 1)) {
+ return false;
+ }
+ status = cli_ntcreate(
+ cli3, fname, 0, FILE_GENERIC_READ|FILE_GENERIC_WRITE,
+ FILE_ATTRIBUTE_NORMAL,
+ FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
+ FILE_OVERWRITE_IF, 0, 0, &fnum3, NULL);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("open of %s failed (%s)\n", fname, nt_errstr(status));
+ return false;
+ }
+ status = cli_lock32(cli3, fnum3, 1, 1, 0, WRITE_LOCK);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("lock failed (%s)\n", nt_errstr(status));
+ return false;
+ }
+
+ status = cli_lock32(cli1, fnum1, 2, 1, 0, WRITE_LOCK);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("lock failed (%s)\n", nt_errstr(status));
+ return false;
+ }
+
/*
* Check the file is indeed locked
*/
--
1.7.9.5
From bd11f5c768e27c3d9b781568fc11a691cddc8794 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sun, 29 Jun 2014 11:22:13 +0200
Subject: [PATCH 07/10] smbd: Simplify validate_lock_entries
... saves >100 bytes object code :-)
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/locking/brlock.c | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/source3/locking/brlock.c b/source3/locking/brlock.c
index e0e042d..eb305a5 100644
--- a/source3/locking/brlock.c
+++ b/source3/locking/brlock.c
@@ -1711,45 +1711,46 @@ static bool validate_lock_entries(TALLOC_CTX *mem_ctx,
unsigned int i;
unsigned int num_valid_entries = 0;
struct lock_struct *locks = *pplocks;
+ unsigned int num_entries = *pnum_entries;
TALLOC_CTX *frame;
struct server_id *ids;
bool *exists;
- if (*pnum_entries == 0) {
+ if (num_entries == 0) {
return true;
}
frame = talloc_stackframe();
- ids = talloc_array(frame, struct server_id, *pnum_entries);
+ ids = talloc_array(frame, struct server_id, num_entries);
if (ids == NULL) {
DEBUG(0, ("validate_lock_entries: "
"talloc_array(struct server_id, %u) failed\n",
- *pnum_entries));
+ num_entries));
talloc_free(frame);
return false;
}
- exists = talloc_array(frame, bool, *pnum_entries);
+ exists = talloc_array(frame, bool, num_entries);
if (exists == NULL) {
DEBUG(0, ("validate_lock_entries: "
"talloc_array(bool, %u) failed\n",
- *pnum_entries));
+ num_entries));
talloc_free(frame);
return false;
}
- for (i = 0; i < *pnum_entries; i++) {
+ for (i = 0; i < num_entries; i++) {
ids[i] = locks[i].context.pid;
}
- if (!serverids_exist(ids, *pnum_entries, exists)) {
+ if (!serverids_exist(ids, num_entries, exists)) {
DEBUG(3, ("validate_lock_entries: serverids_exists failed\n"));
talloc_free(frame);
return false;
}
- for (i = 0; i < *pnum_entries; i++) {
+ for (i = 0; i < num_entries; i++) {
if (exists[i]) {
num_valid_entries++;
continue;
@@ -1768,7 +1769,7 @@ static bool validate_lock_entries(TALLOC_CTX *mem_ctx,
}
TALLOC_FREE(frame);
- if (num_valid_entries != *pnum_entries) {
+ if (num_valid_entries != num_entries) {
struct lock_struct *new_lock_data = NULL;
if (num_valid_entries) {
@@ -1781,7 +1782,7 @@ static bool validate_lock_entries(TALLOC_CTX *mem_ctx,
}
num_valid_entries = 0;
- for (i = 0; i < *pnum_entries; i++) {
+ for (i = 0; i < num_entries; i++) {
struct lock_struct *lock_data = &locks[i];
if (lock_data->context.smblctx &&
lock_data->context.tid) {
--
1.7.9.5
From 70a924f5f4bebf876e99c3393233657ea2ce5bd3 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sun, 29 Jun 2014 11:31:18 +0200
Subject: [PATCH 08/10] smbd: Factor out brl_delete_lock_struct
memmove calculations are never nice, and this is going to be used in
validate_lock_entries soon :-)
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/locking/brlock.c | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/source3/locking/brlock.c b/source3/locking/brlock.c
index eb305a5..ba26a99 100644
--- a/source3/locking/brlock.c
+++ b/source3/locking/brlock.c
@@ -999,6 +999,17 @@ NTSTATUS brl_lock(struct messaging_context *msg_ctx,
return ret;
}
+static void brl_delete_lock_struct(struct lock_struct *locks,
+ unsigned num_locks,
+ unsigned del_idx)
+{
+ if (del_idx >= num_locks) {
+ return;
+ }
+ memmove(&locks[del_idx], &locks[del_idx+1],
+ sizeof(*locks) * (num_locks - del_idx - 1));
+}
+
/****************************************************************************
Unlock a range of bytes - Windows semantics.
****************************************************************************/
@@ -1066,12 +1077,7 @@ bool brl_unlock_windows_default(struct messaging_context *msg_ctx,
unlock_continue:
#endif
- /* Actually delete the lock. */
- if (i < br_lck->num_locks - 1) {
- memmove(&locks[i], &locks[i+1],
- sizeof(*locks)*((br_lck->num_locks-1) - i));
- }
-
+ brl_delete_lock_struct(locks, br_lck->num_locks, i);
br_lck->num_locks -= 1;
br_lck->modified = True;
--
1.7.9.5
From e5988de0c3d8e7f608ab8a365dc892465e4bb5a4 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sun, 29 Jun 2014 11:36:24 +0200
Subject: [PATCH 09/10] smbd: Simplify validate_lock_entries
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/locking/brlock.c | 46 ++++++++++------------------------------------
1 file changed, 10 insertions(+), 36 deletions(-)
diff --git a/source3/locking/brlock.c b/source3/locking/brlock.c
index ba26a99..198d860 100644
--- a/source3/locking/brlock.c
+++ b/source3/locking/brlock.c
@@ -1715,7 +1715,6 @@ static bool validate_lock_entries(TALLOC_CTX *mem_ctx,
bool keep_disconnected)
{
unsigned int i;
- unsigned int num_valid_entries = 0;
struct lock_struct *locks = *pplocks;
unsigned int num_entries = *pnum_entries;
TALLOC_CTX *frame;
@@ -1756,54 +1755,29 @@ static bool validate_lock_entries(TALLOC_CTX *mem_ctx,
return false;
}
- for (i = 0; i < num_entries; i++) {
+ i = 0;
+
+ while (i < num_entries) {
if (exists[i]) {
- num_valid_entries++;
+ i++;
continue;
}
if (keep_disconnected &&
server_id_is_disconnected(&ids[i]))
{
- num_valid_entries++;
+ i++;
continue;
}
- /* This process no longer exists - mark this
- entry as invalid by zeroing it. */
- ZERO_STRUCTP(&locks[i]);
+ /* This process no longer exists */
+
+ brl_delete_lock_struct(locks, num_entries, i);
+ num_entries -= 1;
}
TALLOC_FREE(frame);
- if (num_valid_entries != num_entries) {
- struct lock_struct *new_lock_data = NULL;
-
- if (num_valid_entries) {
- new_lock_data = talloc_array(
- mem_ctx, struct lock_struct,
- num_valid_entries);
- if (!new_lock_data) {
- DEBUG(3, ("malloc fail\n"));
- return False;
- }
-
- num_valid_entries = 0;
- for (i = 0; i < num_entries; i++) {
- struct lock_struct *lock_data = &locks[i];
- if (lock_data->context.smblctx &&
- lock_data->context.tid) {
- /* Valid (nonzero) entry - copy it. */
- memcpy(&new_lock_data[num_valid_entries],
- lock_data, sizeof(struct lock_struct));
- num_valid_entries++;
- }
- }
- }
-
- TALLOC_FREE(*pplocks);
- *pplocks = new_lock_data;
- *pnum_entries = num_valid_entries;
- }
+ *pnum_entries = num_entries;
return True;
}
--
1.7.9.5
From 52c500ff56debb53f21d9fab0fd73b30b8b73748 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Sun, 29 Jun 2014 11:38:35 +0200
Subject: [PATCH 10/10] smbd: validate_lock_entries does not need mem_ctx
anymore
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/locking/brlock.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/source3/locking/brlock.c b/source3/locking/brlock.c
index 198d860..e134aac 100644
--- a/source3/locking/brlock.c
+++ b/source3/locking/brlock.c
@@ -1710,8 +1710,7 @@ bool brl_reconnect_disconnected(struct files_struct *fsp)
/****************************************************************************
Ensure this set of lock entries is valid.
****************************************************************************/
-static bool validate_lock_entries(TALLOC_CTX *mem_ctx,
- unsigned int *pnum_entries, struct lock_struct **pplocks,
+static bool validate_lock_entries(unsigned int *pnum_entries, struct lock_struct **pplocks,
bool keep_disconnected)
{
unsigned int i;
@@ -1824,7 +1823,7 @@ static int brl_traverse_fn(struct db_record *rec, void *state)
/* Ensure the lock db is clean of entries from invalid processes. */
- if (!validate_lock_entries(talloc_tos(), &num_locks, &locks, true)) {
+ if (!validate_lock_entries(&num_locks, &locks, true)) {
TALLOC_FREE(locks);
return -1; /* Terminate traversal */
}
@@ -2025,7 +2024,7 @@ struct byte_range_lock *brl_get_locks(TALLOC_CTX *mem_ctx, files_struct *fsp)
* So we need to clean the disconnected brl entry.
*/
- if (!validate_lock_entries(br_lck, &br_lck->num_locks,
+ if (!validate_lock_entries(&br_lck->num_locks,
&br_lck->lock_data, false)) {
TALLOC_FREE(br_lck);
return NULL;
--
1.7.9.5
More information about the samba-technical
mailing list