[SCM] Samba Shared Repository - branch master updated
Jeremy Allison
jra at samba.org
Fri Jul 10 07:36:07 UTC 2015
The branch, master has been updated
via 8a58a48 libsmb: Implement smbc_notify
via b1ea985 dfs_server: Fix whitespace
via 936a799 Replace random() and related calls with generate_random_buffer()
via 57e2c0d smbcontrol: Set internal log level to 0
via 5f20813 smbstatus: Set internal log level to 0
via 3d920b9 rpcclient: Set internal log level to 0
from fdea2fe rpc_server: Fix CID 1311342 Null pointer dereferences (REVERSE_INULL)
https://git.samba.org/?p=samba.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit 8a58a48f8692880df7f42980c9a981d4ed08e3b7
Author: Volker Lendecke <vl at samba.org>
Date: Fri Jun 26 13:36:43 2015 +0200
libsmb: Implement smbc_notify
Signed-off-by: Volker Lendecke <vl at samba.org>
Reviewed-by: Jeremy Allison <jra at samba.org>
Autobuild-User(master): Jeremy Allison <jra at samba.org>
Autobuild-Date(master): Fri Jul 10 09:35:13 CEST 2015 on sn-devel-104
commit b1ea9856e03c21b52c13aee29971a5326c8cd652
Author: Robin McCorkell <rmccorkell at karoshi.org.uk>
Date: Thu Jul 9 15:28:05 2015 +0100
dfs_server: Fix whitespace
Signed-off-by: Robin McCorkell <rmccorkell at karoshi.org.uk>
Reviewed-by: Volker Lendecke <Volker.Lendecke at SerNet.DE>
Reviewed-by: Jeremy Allison <jra at samba.org>
commit 936a799d32c28dc8857b97a5fe90f0150a280fa4
Author: Robin McCorkell <rmccorkell at karoshi.org.uk>
Date: Thu Jul 9 15:28:05 2015 +0100
Replace random() and related calls with generate_random_buffer()
Result: better seeded random numbers that are cryptographically secure
(not that it matters in this case)
Please let it be right this time...
Signed-off-by: Robin McCorkell <rmccorkell at karoshi.org.uk>
Reviewed-by: Volker Lendecke <Volker.Lendecke at SerNet.DE>
Reviewed-by: Jeremy Allison <jra at samba.org>
commit 57e2c0dfa6a66b5ad27748f3d7e675a74675e14f
Author: Christof Schmitt <cs at samba.org>
Date: Wed Jul 8 15:16:33 2015 -0700
smbcontrol: Set internal log level to 0
Signed-off-by: Christof Schmitt <cs at samba.org>
Reviewed-by: Jeremy Allison <jra at samba.org>
commit 5f208135316ed80cb33467d4f5bd0b5f3077c30e
Author: Christof Schmitt <cs at samba.org>
Date: Wed Jul 8 15:15:38 2015 -0700
smbstatus: Set internal log level to 0
Signed-off-by: Christof Schmitt <cs at samba.org>
Reviewed-by: Jeremy Allison <jra at samba.org>
commit 3d920b952552fd3f018231fd61b7b585fb8f4601
Author: Christof Schmitt <cs at samba.org>
Date: Wed Jul 8 15:14:54 2015 -0700
rpcclient: Set internal log level to 0
Signed-off-by: Christof Schmitt <cs at samba.org>
Reviewed-by: Jeremy Allison <jra at samba.org>
-----------------------------------------------------------------------
Summary of changes:
dfs_server/dfs_server_ad.c | 20 +-
examples/libsmbclient/testnotify.c | 78 +++++++
examples/libsmbclient/wscript_build | 1 +
source3/include/libsmb_internal.h | 7 +
source3/include/libsmbclient.h | 65 ++++++
.../{smbclient-0.2.2.sigs => smbclient-0.2.3.sigs} | 3 +
source3/libsmb/libsmb_compat.c | 11 +
source3/libsmb/libsmb_context.c | 1 +
source3/libsmb/libsmb_dir.c | 254 +++++++++++++++++++++
source3/libsmb/libsmb_setget.c | 12 +
source3/libsmb/wscript | 2 +-
source3/rpcclient/rpcclient.c | 1 +
source3/smbd/msdfs.c | 7 +-
source3/utils/smbcontrol.c | 1 +
source3/utils/status.c | 1 +
15 files changed, 448 insertions(+), 16 deletions(-)
create mode 100644 examples/libsmbclient/testnotify.c
copy source3/libsmb/ABI/{smbclient-0.2.2.sigs => smbclient-0.2.3.sigs} (97%)
Changeset truncated at 500 lines:
diff --git a/dfs_server/dfs_server_ad.c b/dfs_server/dfs_server_ad.c
index 3d93e19..2a1d9ec 100644
--- a/dfs_server/dfs_server_ad.c
+++ b/dfs_server/dfs_server_ad.c
@@ -40,20 +40,18 @@ struct dc_set {
static void shuffle_dc_set(struct dc_set *list)
{
- uint32_t i;
-
- srandom(time(NULL));
+ uint32_t i;
- for (i = list->count; i > 1; i--) {
- uint32_t r;
- const char *tmp;
+ for (i = list->count; i > 1; i--) {
+ uint32_t r;
+ const char *tmp;
- r = random() % i;
+ r = generate_random() % i;
- tmp = list->names[i - 1];
- list->names[i - 1] = list->names[r];
- list->names[r] = tmp;
- }
+ tmp = list->names[i - 1];
+ list->names[i - 1] = list->names[r];
+ list->names[r] = tmp;
+ }
}
/*
diff --git a/examples/libsmbclient/testnotify.c b/examples/libsmbclient/testnotify.c
new file mode 100644
index 0000000..68513af
--- /dev/null
+++ b/examples/libsmbclient/testnotify.c
@@ -0,0 +1,78 @@
+#include <sys/types.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <time.h>
+#include <errno.h>
+#include <libsmbclient.h>
+#include <inttypes.h>
+#include "get_auth_data_fn.h"
+
+static int notify_cb(const struct smbc_notify_callback_action *actions,
+ size_t num_actions, void *private_data)
+{
+ int *count = private_data;
+ size_t i;
+
+ printf("%zu\n", num_actions);
+
+ for (i=0; i<num_actions; i++) {
+ const struct smbc_notify_callback_action *a = &actions[i];
+ printf("%s: %"PRIu32"\n", a->filename, a->action);
+ }
+
+ *count -= 1;
+ if (*count < 0) {
+ return 1;
+ }
+
+ return 0;
+}
+
+int main(int argc, char * argv[])
+{
+ int fd;
+ int ret;
+ int debug = 0;
+ int saved_errno;
+ char path[2048];
+ char * p;
+ int count = 1000;
+
+ smbc_init(get_auth_data_fn, debug);
+
+ fprintf(stdout, "Path: ");
+ *path = '\0';
+ fgets(path, sizeof(path) - 1, stdin);
+ if (strlen(path) == 0) {
+ return 0;
+ }
+
+ p = path + strlen(path) - 1;
+ if (*p == '\n') {
+ *p = '\0';
+ }
+
+ fd = smbc_opendir(path);
+ if (fd < 0) {
+ perror("smbc_open");
+ return 1;
+ }
+
+ ret = smbc_notify(fd, 1,
+ SMBC_NOTIFY_CHANGE_SECURITY|
+ SMBC_NOTIFY_CHANGE_FILE_NAME,
+ 1000, notify_cb, &count);
+ if (ret < 0) {
+ saved_errno = errno;
+ }
+
+ smbc_close(fd);
+
+ if (ret < 0) {
+ errno = saved_errno;
+ perror("notify");
+ }
+
+ return 0;
+}
diff --git a/examples/libsmbclient/wscript_build b/examples/libsmbclient/wscript_build
index aa39965..c58a5b9 100644
--- a/examples/libsmbclient/wscript_build
+++ b/examples/libsmbclient/wscript_build
@@ -6,6 +6,7 @@ names = ['testsmbc',
'testacl3',
'testbrowse',
'testbrowse2',
+ 'testnotify',
'teststat',
'teststat2',
'teststat3',
diff --git a/source3/include/libsmb_internal.h b/source3/include/libsmb_internal.h
index cf51f34..0e0045e 100644
--- a/source3/include/libsmb_internal.h
+++ b/source3/include/libsmb_internal.h
@@ -247,6 +247,7 @@ struct SMBC_internal_data {
struct
{
smbc_splice_fn splice_fn;
+ smbc_notify_fn notify_fn;
} smb;
uint16_t port;
@@ -344,6 +345,12 @@ SMBC_rename_ctx(SMBCCTX *ocontext,
SMBCCTX *ncontext,
const char *nname);
+int
+SMBC_notify_ctx(SMBCCTX *c, SMBCFILE *dir, smbc_bool recursive,
+ uint32_t completion_filter, unsigned callback_timeout_ms,
+ smbc_notify_callback_fn cb, void *private_data);
+
+
/* Functions in libsmb_file.c */
SMBCFILE *
diff --git a/source3/include/libsmbclient.h b/source3/include/libsmbclient.h
index faaab2e..cf67b1d 100644
--- a/source3/include/libsmbclient.h
+++ b/source3/include/libsmbclient.h
@@ -993,6 +993,30 @@ typedef int (*smbc_fstatdir_fn)(SMBCCTX *c,
smbc_fstatdir_fn smbc_getFunctionFstatdir(SMBCCTX *c);
void smbc_setFunctionFstatdir(SMBCCTX *c, smbc_fstatdir_fn fn);
+#define SMBC_NOTIFY_ACTION_ADDED 1
+#define SMBC_NOTIFY_ACTION_REMOVED 2
+#define SMBC_NOTIFY_ACTION_MODIFIED 3
+#define SMBC_NOTIFY_ACTION_OLD_NAME 4
+#define SMBC_NOTIFY_ACTION_NEW_NAME 5
+#define SMBC_NOTIFY_ACTION_ADDED_STREAM 6
+#define SMBC_NOTIFY_ACTION_REMOVED_STREAM 7
+#define SMBC_NOTIFY_ACTION_MODIFIED_STREAM 8
+
+struct smbc_notify_callback_action {
+ uint32_t action;
+ const char *filename;
+};
+
+typedef int (*smbc_notify_callback_fn)(
+ const struct smbc_notify_callback_action *actions,
+ size_t num_actions, void *private_data);
+
+typedef int (*smbc_notify_fn)(SMBCCTX *c, SMBCFILE *dir, smbc_bool recursive,
+ uint32_t completion_filter,
+ unsigned callback_timeout_ms,
+ smbc_notify_callback_fn cb, void *private_data);
+smbc_notify_fn smbc_getFunctionNotify(SMBCCTX *c);
+void smbc_setFunctionNotify(SMBCCTX *c, smbc_notify_fn fn);
/*****************************************************************
@@ -1620,6 +1644,47 @@ int smbc_mkdir(const char *durl, mode_t mode);
*/
int smbc_rmdir(const char *durl);
+/**@ingroup directory
+ * Request directory notifications
+ *
+ * @param dh Valid directory as returned by smbc_opendir()
+ *
+ * @param recursive Are changes in subdirectories wanted?
+ *
+ * @param completion_filter Bitwise-or of the SMBC_NOTIFY_CHANGE_*
+ * events that are interesting
+ *
+ * @param callback_timeout_ms If set to non-zero, interval in milliseconds
+ * that "cb" will be called with 0 actions.
+ * This gives "cb" the chance to cancel the
+ * smbc_notify call.
+ *
+ * @param cb Callback functions taking events. If "cb"
+ * returns nonzero, smbc_notify will return.
+ *
+ * @param private_data Pointer given to "cb"
+ *
+ * @return 0 on success, -1 on error with errno set
+ *
+ * @see smbc_opendir(), smbc_closedir()
+ */
+
+#define SMBC_NOTIFY_CHANGE_FILE_NAME 0x001
+#define SMBC_NOTIFY_CHANGE_DIR_NAME 0x002
+#define SMBC_NOTIFY_CHANGE_ATTRIBUTES 0x004
+#define SMBC_NOTIFY_CHANGE_SIZE 0x008
+#define SMBC_NOTIFY_CHANGE_LAST_WRITE 0x010
+#define SMBC_NOTIFY_CHANGE_LAST_ACCESS 0x020
+#define SMBC_NOTIFY_CHANGE_CREATION 0x040
+#define SMBC_NOTIFY_CHANGE_EA 0x080
+#define SMBC_NOTIFY_CHANGE_SECURITY 0x100
+#define SMBC_NOTIFY_CHANGE_STREAM_NAME 0x200
+#define SMBC_NOTIFY_CHANGE_STREAM_SIZE 0x400
+#define SMBC_NOTIFY_CHANGE_STREAM_WRITE 0x800
+
+int smbc_notify(int dh, smbc_bool recursive, uint32_t completion_filter,
+ unsigned callback_timeout_ms,
+ smbc_notify_callback_fn cb, void *private_data);
/**@ingroup attribute
* Get information about a file or directory.
diff --git a/source3/libsmb/ABI/smbclient-0.2.2.sigs b/source3/libsmb/ABI/smbclient-0.2.3.sigs
similarity index 97%
copy from source3/libsmb/ABI/smbclient-0.2.2.sigs
copy to source3/libsmb/ABI/smbclient-0.2.3.sigs
index fdafdd0..cda537c 100644
--- a/source3/libsmb/ABI/smbclient-0.2.2.sigs
+++ b/source3/libsmb/ABI/smbclient-0.2.3.sigs
@@ -31,6 +31,7 @@ smbc_getFunctionListxattr: smbc_listxattr_fn (SMBCCTX *)
smbc_getFunctionLseek: smbc_lseek_fn (SMBCCTX *)
smbc_getFunctionLseekdir: smbc_lseekdir_fn (SMBCCTX *)
smbc_getFunctionMkdir: smbc_mkdir_fn (SMBCCTX *)
+smbc_getFunctionNotify: smbc_notify_fn (SMBCCTX *)
smbc_getFunctionOpen: smbc_open_fn (SMBCCTX *)
smbc_getFunctionOpenPrintJob: smbc_open_print_job_fn (SMBCCTX *)
smbc_getFunctionOpendir: smbc_opendir_fn (SMBCCTX *)
@@ -86,6 +87,7 @@ smbc_lseekdir: int (int, off_t)
smbc_lsetxattr: int (const char *, const char *, const void *, size_t, int)
smbc_mkdir: int (const char *, mode_t)
smbc_new_context: SMBCCTX *(void)
+smbc_notify: int (int, smbc_bool, uint32_t, unsigned int, smbc_notify_callback_fn, void *)
smbc_open: int (const char *, int, mode_t)
smbc_open_print_job: int (const char *)
smbc_opendir: int (const char *)
@@ -118,6 +120,7 @@ smbc_setFunctionListxattr: void (SMBCCTX *, smbc_listxattr_fn)
smbc_setFunctionLseek: void (SMBCCTX *, smbc_lseek_fn)
smbc_setFunctionLseekdir: void (SMBCCTX *, smbc_lseekdir_fn)
smbc_setFunctionMkdir: void (SMBCCTX *, smbc_mkdir_fn)
+smbc_setFunctionNotify: void (SMBCCTX *, smbc_notify_fn)
smbc_setFunctionOpen: void (SMBCCTX *, smbc_open_fn)
smbc_setFunctionOpenPrintJob: void (SMBCCTX *, smbc_open_print_job_fn)
smbc_setFunctionOpendir: void (SMBCCTX *, smbc_opendir_fn)
diff --git a/source3/libsmb/libsmb_compat.c b/source3/libsmb/libsmb_compat.c
index 38f7d36..5fed44a 100644
--- a/source3/libsmb/libsmb_compat.c
+++ b/source3/libsmb/libsmb_compat.c
@@ -314,6 +314,17 @@ smbc_rmdir(const char *durl)
}
int
+smbc_notify(int dh, smbc_bool recursive, uint32_t completion_filter,
+ unsigned callback_timeout_ms,
+ smbc_notify_callback_fn cb, void *private_data)
+{
+ SMBCFILE *dir = find_fd(dh);
+ return smbc_getFunctionNotify(statcont)(
+ statcont, dir, recursive, completion_filter,
+ callback_timeout_ms, cb, private_data);
+}
+
+int
smbc_stat(const char *url,
struct stat *st)
{
diff --git a/source3/libsmb/libsmb_context.c b/source3/libsmb/libsmb_context.c
index 9541fc1..5e31dfb 100644
--- a/source3/libsmb/libsmb_context.c
+++ b/source3/libsmb/libsmb_context.c
@@ -214,6 +214,7 @@ smbc_new_context(void)
smbc_setFunctionTelldir(context, SMBC_telldir_ctx);
smbc_setFunctionLseekdir(context, SMBC_lseekdir_ctx);
smbc_setFunctionFstatdir(context, SMBC_fstatdir_ctx);
+ smbc_setFunctionNotify(context, SMBC_notify_ctx);
smbc_setFunctionChmod(context, SMBC_chmod_ctx);
smbc_setFunctionUtimes(context, SMBC_utimes_ctx);
smbc_setFunctionSetxattr(context, SMBC_setxattr_ctx);
diff --git a/source3/libsmb/libsmb_dir.c b/source3/libsmb/libsmb_dir.c
index d131c30..f332525 100644
--- a/source3/libsmb/libsmb_dir.c
+++ b/source3/libsmb/libsmb_dir.c
@@ -31,6 +31,8 @@
#include "../librpc/gen_ndr/ndr_srvsvc_c.h"
#include "libsmb/nmblib.h"
#include "../libcli/smb/smbXcli_base.h"
+#include "../libcli/security/security.h"
+#include "lib/util/tevent_ntstatus.h"
/*
* Routine to open a directory
@@ -2047,3 +2049,255 @@ SMBC_rename_ctx(SMBCCTX *ocontext,
return 0; /* Success */
}
+struct smbc_notify_cb_state {
+ struct tevent_context *ev;
+ struct cli_state *cli;
+ uint16_t fnum;
+ bool recursive;
+ uint32_t completion_filter;
+ unsigned callback_timeout_ms;
+ smbc_notify_callback_fn cb;
+ void *private_data;
+};
+
+static void smbc_notify_cb_got_changes(struct tevent_req *subreq);
+static void smbc_notify_cb_timedout(struct tevent_req *subreq);
+
+static struct tevent_req *smbc_notify_cb_send(
+ TALLOC_CTX *mem_ctx, struct tevent_context *ev, struct cli_state *cli,
+ uint16_t fnum, bool recursive, uint32_t completion_filter,
+ unsigned callback_timeout_ms,
+ smbc_notify_callback_fn cb, void *private_data)
+{
+ struct tevent_req *req, *subreq;
+ struct smbc_notify_cb_state *state;
+
+ req = tevent_req_create(mem_ctx, &state, struct smbc_notify_cb_state);
+ if (req == NULL) {
+ return NULL;
+ }
+ state->ev = ev;
+ state->cli = cli;
+ state->fnum = fnum;
+ state->recursive = recursive;
+ state->completion_filter = completion_filter;
+ state->callback_timeout_ms = callback_timeout_ms;
+ state->cb = cb;
+ state->private_data = private_data;
+
+ subreq = cli_notify_send(
+ state, state->ev, state->cli, state->fnum, 1000,
+ state->completion_filter, state->recursive);
+ if (tevent_req_nomem(subreq, req)) {
+ return tevent_req_post(req, ev);
+ }
+ tevent_req_set_callback(subreq, smbc_notify_cb_got_changes, req);
+
+ if (state->callback_timeout_ms == 0) {
+ return req;
+ }
+
+ subreq = tevent_wakeup_send(
+ state, state->ev,
+ tevent_timeval_current_ofs(state->callback_timeout_ms/1000,
+ state->callback_timeout_ms*1000));
+ if (tevent_req_nomem(subreq, req)) {
+ return tevent_req_post(req, ev);
+ }
+ tevent_req_set_callback(subreq, smbc_notify_cb_timedout, req);
+
+ return req;
+}
+
+static void smbc_notify_cb_got_changes(struct tevent_req *subreq)
+{
+ struct tevent_req *req = tevent_req_callback_data(
+ subreq, struct tevent_req);
+ struct smbc_notify_cb_state *state = tevent_req_data(
+ req, struct smbc_notify_cb_state);
+ uint32_t num_changes;
+ struct notify_change *changes;
+ NTSTATUS status;
+ int cb_ret;
+
+ status = cli_notify_recv(subreq, state, &num_changes, &changes);
+ TALLOC_FREE(subreq);
+ if (tevent_req_nterror(req, status)) {
+ return;
+ }
+
+ {
+ struct smbc_notify_callback_action actions[num_changes];
+ uint32_t i;
+
+ for (i=0; i<num_changes; i++) {
+ actions[i].action = changes[i].action;
+ actions[i].filename = changes[i].name;
+ }
+
+ cb_ret = state->cb(actions, num_changes, state->private_data);
+ }
+
+ TALLOC_FREE(changes);
+
+ if (cb_ret != 0) {
+ tevent_req_done(req);
+ return;
+ }
+
+ subreq = cli_notify_send(
+ state, state->ev, state->cli, state->fnum, 1000,
+ state->completion_filter, state->recursive);
+ if (tevent_req_nomem(subreq, req)) {
+ return;
+ }
+ tevent_req_set_callback(subreq, smbc_notify_cb_got_changes, req);
+}
+
+static void smbc_notify_cb_timedout(struct tevent_req *subreq)
+{
+ struct tevent_req *req = tevent_req_callback_data(
+ subreq, struct tevent_req);
+ struct smbc_notify_cb_state *state = tevent_req_data(
+ req, struct smbc_notify_cb_state);
+ int cb_ret;
+ bool ok;
+
+ ok = tevent_wakeup_recv(subreq);
+ TALLOC_FREE(subreq);
+ if (!ok) {
+ tevent_req_oom(req);
+ return;
+ }
+
+ cb_ret = state->cb(NULL, 0, state->private_data);
+ if (cb_ret != 0) {
+ tevent_req_done(req);
+ return;
+ }
+
+ subreq = tevent_wakeup_send(
+ state, state->ev,
+ tevent_timeval_current_ofs(state->callback_timeout_ms/1000,
+ state->callback_timeout_ms*1000));
+ if (tevent_req_nomem(subreq, req)) {
+ return;
+ }
+ tevent_req_set_callback(subreq, smbc_notify_cb_timedout, req);
+}
+
+static NTSTATUS smbc_notify_cb_recv(struct tevent_req *req)
+{
+ return tevent_req_simple_recv_ntstatus(req);
+}
+
+static NTSTATUS smbc_notify_cb(struct cli_state *cli, uint16_t fnum,
+ bool recursive, uint32_t completion_filter,
+ unsigned callback_timeout_ms,
+ smbc_notify_callback_fn cb, void *private_data)
+{
+ TALLOC_CTX *frame = talloc_stackframe();
+ struct tevent_context *ev;
+ struct tevent_req *req;
+ NTSTATUS status = NT_STATUS_NO_MEMORY;
+
+ ev = samba_tevent_context_init(frame);
+ if (ev == NULL) {
+ goto fail;
+ }
+ req = smbc_notify_cb_send(frame, ev, cli, fnum, recursive,
+ completion_filter,
+ callback_timeout_ms, cb, private_data);
+ if (req == NULL) {
+ goto fail;
+ }
+ if (!tevent_req_poll_ntstatus(req, ev, &status)) {
+ goto fail;
+ }
+ status = smbc_notify_cb_recv(req);
+ TALLOC_FREE(req);
+fail:
+ TALLOC_FREE(frame);
+ return status;
+}
+
+int
+SMBC_notify_ctx(SMBCCTX *context, SMBCFILE *dir, smbc_bool recursive,
+ uint32_t completion_filter, unsigned callback_timeout_ms,
+ smbc_notify_callback_fn cb, void *private_data)
+{
+ TALLOC_CTX *frame = talloc_stackframe();
+ struct cli_state *cli = dir->srv->cli;
+ char *server = NULL;
--
Samba Shared Repository
More information about the samba-cvs
mailing list