[SCM] Samba Shared Repository - branch master updated

Volker Lendecke vlendec at samba.org
Thu Mar 22 06:52:04 MDT 2012


The branch, master has been updated
       via  42cb8ff s3: Add "notify" cmd to smbclient
       via  9091aec s3: Add sync cli_notify
       via  7a19b18 s3: Add FILE_NOTIFY_CHANGE_ALL #define
       via  c666967 s3-libsmb: Fix parsing a notify response
       via  2351d74 s3: rename "len"->"next", according to wireshark
      from  4816ffa lib/tdb2: fix -Wcast-qual warnings.

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


- Log -----------------------------------------------------------------
commit 42cb8ff71c6177c139b4ecd69bc6d1519b7f4d5f
Author: Volker Lendecke <vl at samba.org>
Date:   Thu Mar 22 12:17:26 2012 +0100

    s3: Add "notify" cmd to smbclient
    
    Autobuild-User: Volker Lendecke <vl at samba.org>
    Autobuild-Date: Thu Mar 22 13:51:50 CET 2012 on sn-devel-104

commit 9091aec724545b0a301f863e4f19f756fb7f7f49
Author: Volker Lendecke <vl at samba.org>
Date:   Thu Mar 22 12:17:14 2012 +0100

    s3: Add sync cli_notify

commit 7a19b18b8238421e682ca7059486c41d5aa4279d
Author: Volker Lendecke <vl at samba.org>
Date:   Thu Mar 22 12:16:52 2012 +0100

    s3: Add FILE_NOTIFY_CHANGE_ALL #define

commit c6669677b1e9628e60c1ffb21a0e8c2516106c50
Author: Volker Lendecke <vl at samba.org>
Date:   Thu Mar 22 12:16:17 2012 +0100

    s3-libsmb: Fix parsing a notify response

commit 2351d74a03d90dea419e83852b83ada8392cda46
Author: Volker Lendecke <vl at samba.org>
Date:   Thu Mar 22 12:09:05 2012 +0100

    s3: rename "len"->"next", according to wireshark

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

Summary of changes:
 source3/client/client.c  |   57 ++++++++++++++++++++++++++++++++++++++++++++++
 source3/include/smb.h    |    8 ++++++
 source3/libsmb/clifile.c |   43 +++++++++++++++++++++++++++++++---
 source3/libsmb/proto.h   |    4 +++
 4 files changed, 108 insertions(+), 4 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source3/client/client.c b/source3/client/client.c
index 9d4ef15..9ace7e4 100644
--- a/source3/client/client.c
+++ b/source3/client/client.c
@@ -3901,6 +3901,62 @@ static int cmd_newer(void)
 }
 
 /****************************************************************************
+ Watch directory changes
+****************************************************************************/
+
+static int cmd_notify(void)
+{
+	TALLOC_CTX *frame = talloc_stackframe();
+	char *name, *buf;
+	NTSTATUS status;
+	uint16_t fnum;
+
+	name = talloc_strdup(talloc_tos(), client_get_cur_dir());
+	if (name == NULL) {
+		goto fail;
+	}
+	if (!next_token_talloc(talloc_tos(), &cmd_ptr, &buf, NULL)) {
+		goto usage;
+	}
+	name = talloc_asprintf_append(name, "%s", buf);
+	if (name == NULL) {
+		goto fail;
+	}
+	status = cli_ntcreate(
+		cli, name, 0, READ_CONTROL_ACCESS, 0,
+		FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE,
+		FILE_OPEN, 0, 0, &fnum);
+	if (!NT_STATUS_IS_OK(status)) {
+		d_printf("Could not open file: %s\n", nt_errstr(status));
+		goto fail;
+	}
+
+	while (1) {
+		uint32_t i, num_changes;
+		struct notify_change *changes;
+
+		status = cli_notify(cli, fnum, 1000, FILE_NOTIFY_CHANGE_ALL,
+				    true,
+				    talloc_tos(), &num_changes, &changes);
+		if (!NT_STATUS_IS_OK(status)) {
+			d_printf("notify returned %s\n",
+				 nt_errstr(status));
+			goto fail;
+		}
+		for (i=0; i<num_changes; i++) {
+			printf("%4.4x %s\n", changes[i].action,
+			       changes[i].name);
+		}
+		TALLOC_FREE(changes);
+	}
+usage:
+	d_printf("notify <file>\n");
+fail:
+	TALLOC_FREE(frame);
+	return 1;
+}
+
+/****************************************************************************
  Set the archive level.
 ****************************************************************************/
 
@@ -4561,6 +4617,7 @@ static struct {
   {"more",cmd_more,"<remote name> view a remote file with your pager",{COMPL_REMOTE,COMPL_NONE}},  
   {"mput",cmd_mput,"<mask> put all matching files",{COMPL_REMOTE,COMPL_NONE}},
   {"newer",cmd_newer,"<file> only mget files newer than the specified local file",{COMPL_LOCAL,COMPL_NONE}},
+  {"notify",cmd_notify,"<file>Get notified by dir changes",{COMPL_REMOTE,COMPL_NONE}},
   {"open",cmd_open,"<mask> open a file",{COMPL_REMOTE,COMPL_NONE}},
   {"posix", cmd_posix, "turn on all POSIX capabilities", {COMPL_REMOTE,COMPL_NONE}},
   {"posix_encrypt",cmd_posix_encrypt,"<domain> <user> <password> start up transport encryption",{COMPL_REMOTE,COMPL_NONE}},
diff --git a/source3/include/smb.h b/source3/include/smb.h
index a12ca54..01253f0 100644
--- a/source3/include/smb.h
+++ b/source3/include/smb.h
@@ -915,6 +915,14 @@ struct connections_data {
 #define FILE_NOTIFY_CHANGE_NAME \
 	(FILE_NOTIFY_CHANGE_FILE_NAME|FILE_NOTIFY_CHANGE_DIR_NAME)
 
+#define FILE_NOTIFY_CHANGE_ALL \
+	(FILE_NOTIFY_CHANGE_FILE_NAME   | FILE_NOTIFY_CHANGE_DIR_NAME | \
+	 FILE_NOTIFY_CHANGE_ATTRIBUTES  | FILE_NOTIFY_CHANGE_SIZE | \
+	 FILE_NOTIFY_CHANGE_LAST_WRITE  | FILE_NOTIFY_CHANGE_LAST_ACCESS | \
+	 FILE_NOTIFY_CHANGE_CREATION    | FILE_NOTIFY_CHANGE_EA | \
+	 FILE_NOTIFY_CHANGE_SECURITY	| FILE_NOTIFY_CHANGE_STREAM_NAME | \
+	 FILE_NOTIFY_CHANGE_STREAM_SIZE | FILE_NOTIFY_CHANGE_STREAM_WRITE)
+
 /* change notify action results */
 #define NOTIFY_ACTION_ADDED 1
 #define NOTIFY_ACTION_REMOVED 2
diff --git a/source3/libsmb/clifile.c b/source3/libsmb/clifile.c
index 0c8a340..48a0636 100644
--- a/source3/libsmb/clifile.c
+++ b/source3/libsmb/clifile.c
@@ -5004,13 +5004,13 @@ static void cli_notify_done(struct tevent_req *subreq)
 	ofs = 0;
 
 	while (num_params - ofs > 12) {
-		uint32_t len = IVAL(params, ofs);
+		uint32_t next = IVAL(params, ofs);
 		state->num_changes += 1;
 
-		if ((len == 0) || (ofs+len >= num_params)) {
+		if ((next == 0) || (ofs+next >= num_params)) {
 			break;
 		}
-		ofs += len;
+		ofs += next;
 	}
 
 	state->changes = talloc_array(state, struct notify_change,
@@ -5028,7 +5028,7 @@ static void cli_notify_done(struct tevent_req *subreq)
 		ssize_t ret;
 		char *name;
 
-		if ((next != 0) && (len+12 != next)) {
+		if (trans_oob(num_params, ofs + 12, len)) {
 			TALLOC_FREE(params);
 			tevent_req_nterror(
 				req, NT_STATUS_INVALID_NETWORK_RESPONSE);
@@ -5069,6 +5069,41 @@ NTSTATUS cli_notify_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
 	return NT_STATUS_OK;
 }
 
+NTSTATUS cli_notify(struct cli_state *cli, uint16_t fnum, uint32_t buffer_size,
+		    uint32_t completion_filter, bool recursive,
+		    TALLOC_CTX *mem_ctx, uint32_t *pnum_changes,
+		    struct notify_change **pchanges)
+{
+	TALLOC_CTX *frame = talloc_stackframe();
+	struct tevent_context *ev;
+	struct tevent_req *req;
+	NTSTATUS status = NT_STATUS_NO_MEMORY;
+
+	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;
+	}
+	ev = tevent_context_init(frame);
+	if (ev == NULL) {
+		goto fail;
+	}
+	req = cli_notify_send(ev, ev, cli, fnum, buffer_size,
+			      completion_filter, recursive);
+	if (req == NULL) {
+		goto fail;
+	}
+	if (!tevent_req_poll_ntstatus(req, ev, &status)) {
+		goto fail;
+	}
+	status = cli_notify_recv(req, mem_ctx, pnum_changes, pchanges);
+ fail:
+	TALLOC_FREE(frame);
+	return status;
+}
+
 struct cli_qpathinfo_state {
 	uint8_t *param;
 	uint8_t *data;
diff --git a/source3/libsmb/proto.h b/source3/libsmb/proto.h
index 9e03ec4..336c95f 100644
--- a/source3/libsmb/proto.h
+++ b/source3/libsmb/proto.h
@@ -593,6 +593,10 @@ struct tevent_req *cli_notify_send(TALLOC_CTX *mem_ctx,
 NTSTATUS cli_notify_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
 			 uint32_t *pnum_changes,
 			 struct notify_change **pchanges);
+NTSTATUS cli_notify(struct cli_state *cli, uint16_t fnum, uint32_t buffer_size,
+		    uint32_t completion_filter, bool recursive,
+		    TALLOC_CTX *mem_ctx, uint32_t *pnum_changes,
+		    struct notify_change **pchanges);
 
 struct tevent_req *cli_nttrans_create_send(TALLOC_CTX *mem_ctx,
 					   struct event_context *ev,


-- 
Samba Shared Repository


More information about the samba-cvs mailing list