The branch, master has been updated via 5eccc2f messaging: Remove messaging_handler_send via 197186a notifyd: Remove notifyd_handler_done via 9430fab notifyd: Use messaging_register for MSG_SMB_NOTIFY_DB via dc39bb4 notifyd: Use messaging_register for MSG_SMB_NOTIFY_GET_DB via db15feb notifyd: Use messaging_register for MSG_SMB_NOTIFY_TRIGGER via b6079af notifyd: Use messaging_register for MSG_SMB_NOTIFY_REC_CHANGE via 0c1e08b messaging: make messaging_rec_create public via b8dccd1 notifyd: Avoid an if-expression via d0a7bcc notifyd: Consolidate two #ifdef CLUSTER into one via 939576d notifyd: Only ask for messaging_ctdb_conn when clustering via b6d6f67 Add support for passing the max_referral_level into the cli call to get a DFS referral. This is being done so I can write tests of the DFS referral code on the server side. from 1de4390 unittests: Do not install the test_dummy rpc module
https://git.samba.org/?p=samba.git;a=shortlog;h=master - Log ----------------------------------------------------------------- commit 5eccc2fd0072409f166c63e6876266f926411423 Author: Volker Lendecke <v...@samba.org> Date: Sat Jun 24 09:01:46 2017 +0200 messaging: Remove messaging_handler_send This did not really take off, notifyd was the only user Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> Autobuild-User(master): Jeremy Allison <j...@samba.org> Autobuild-Date(master): Fri Jul 7 05:11:48 CEST 2017 on sn-devel-144 commit 197186a1fcc2c190fac9a16893234c337e6ec01c Author: Volker Lendecke <v...@samba.org> Date: Sat Jun 24 08:57:18 2017 +0200 notifyd: Remove notifyd_handler_done Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit 9430fab61cb746e590db307af37219f8f29b7fd8 Author: Volker Lendecke <v...@samba.org> Date: Sat Jun 24 08:56:35 2017 +0200 notifyd: Use messaging_register for MSG_SMB_NOTIFY_DB Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit dc39bb45624f8d6859dadc3c9a9a85793a5a7d0d Author: Volker Lendecke <v...@samba.org> Date: Sat Jun 24 08:48:45 2017 +0200 notifyd: Use messaging_register for MSG_SMB_NOTIFY_GET_DB Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit db15feb162326cb03fb06df24bcdafa5d5cb3087 Author: Volker Lendecke <v...@samba.org> Date: Sat Jun 24 08:45:17 2017 +0200 notifyd: Use messaging_register for MSG_SMB_NOTIFY_TRIGGER Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit b6079af1c41481714ac981fdd19f89ee197b4200 Author: Volker Lendecke <v...@samba.org> Date: Sat Jun 24 08:38:53 2017 +0200 notifyd: Use messaging_register for MSG_SMB_NOTIFY_REC_CHANGE Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit 0c1e08b5901e54c70cf72c74837a8ed8cc77f0b8 Author: Volker Lendecke <v...@samba.org> Date: Sat Jun 24 08:38:19 2017 +0200 messaging: make messaging_rec_create public Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit b8dccd11ea3d43b9ee51811c1ce7d81b91a549ca Author: Volker Lendecke <v...@samba.org> Date: Wed Jul 5 09:37:14 2017 +0200 notifyd: Avoid an if-expression Best reviewed with "git show -b -U10" Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit d0a7bccae9856aba44a057c09499aa0de6b21862 Author: Volker Lendecke <v...@samba.org> Date: Wed Jul 5 09:34:51 2017 +0200 notifyd: Consolidate two #ifdef CLUSTER into one Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit 939576d968d1e0159456baf6dd1e3c454b98995a Author: Volker Lendecke <v...@samba.org> Date: Fri Jun 16 15:20:22 2017 +0200 notifyd: Only ask for messaging_ctdb_conn when clustering Without clustering, messaging_ctdb_conn will fail anyway. Review with "git show -b". Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Jeremy Allison <j...@samba.org> commit b6d6f67bad397f30b6b5779c4e8ba8bf12f49d4b Author: Richard Sharpe <richard.sha...@primarydata.com> Date: Mon Jun 26 09:43:31 2017 -0700 Add support for passing the max_referral_level into the cli call to get a DFS referral. This is being done so I can write tests of the DFS referral code on the server side. Signed-off-by: Richard Sharpe <richard.sha...@primarydata.com> Reviewed-by: Jeremy Allison <j...@samba.org> ----------------------------------------------------------------------- Summary of changes: source3/include/messages.h | 13 +-- source3/lib/messages.c | 83 +------------- source3/libsmb/clidfs.c | 21 +++- source3/libsmb/proto.h | 7 ++ source3/smbd/notifyd/notifyd.c | 244 ++++++++++++++++++++--------------------- source3/smbd/server.c | 8 +- 6 files changed, 156 insertions(+), 220 deletions(-) Changeset truncated at 500 lines: diff --git a/source3/include/messages.h b/source3/include/messages.h index 806f7b0..970dc38 100644 --- a/source3/include/messages.h +++ b/source3/include/messages.h @@ -133,18 +133,15 @@ struct tevent_req *messaging_read_send(TALLOC_CTX *mem_ctx, int messaging_read_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx, struct messaging_rec **presult); -struct tevent_req *messaging_handler_send( - TALLOC_CTX *mem_ctx, struct tevent_context *ev, - struct messaging_context *msg_ctx, uint32_t msg_type, - bool (*handler)(struct messaging_context *msg_ctx, - struct messaging_rec **rec, void *private_data), - void *private_data); -int messaging_handler_recv(struct tevent_req *req); - int messaging_cleanup(struct messaging_context *msg_ctx, pid_t pid); bool messaging_parent_dgm_cleanup_init(struct messaging_context *msg); +struct messaging_rec *messaging_rec_create( + TALLOC_CTX *mem_ctx, struct server_id src, struct server_id dst, + uint32_t msg_type, const struct iovec *iov, int iovlen, + const int *fds, size_t num_fds); + #include "librpc/gen_ndr/ndr_messaging.h" #endif diff --git a/source3/lib/messages.c b/source3/lib/messages.c index b0edb30..b94a696 100644 --- a/source3/lib/messages.c +++ b/source3/lib/messages.c @@ -110,7 +110,7 @@ static void ping_message(struct messaging_context *msg_ctx, messaging_send(msg_ctx, src, MSG_PONG, data); } -static struct messaging_rec *messaging_rec_create( +struct messaging_rec *messaging_rec_create( TALLOC_CTX *mem_ctx, struct server_id src, struct server_id dst, uint32_t msg_type, const struct iovec *iov, int iovlen, const int *fds, size_t num_fds) @@ -906,87 +906,6 @@ int messaging_read_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx, return 0; } -struct messaging_handler_state { - struct tevent_context *ev; - struct messaging_context *msg_ctx; - uint32_t msg_type; - bool (*handler)(struct messaging_context *msg_ctx, - struct messaging_rec **rec, void *private_data); - void *private_data; -}; - -static void messaging_handler_got_msg(struct tevent_req *subreq); - -struct tevent_req *messaging_handler_send( - TALLOC_CTX *mem_ctx, struct tevent_context *ev, - struct messaging_context *msg_ctx, uint32_t msg_type, - bool (*handler)(struct messaging_context *msg_ctx, - struct messaging_rec **rec, void *private_data), - void *private_data) -{ - struct tevent_req *req, *subreq; - struct messaging_handler_state *state; - - req = tevent_req_create(mem_ctx, &state, - struct messaging_handler_state); - if (req == NULL) { - return NULL; - } - state->ev = ev; - state->msg_ctx = msg_ctx; - state->msg_type = msg_type; - state->handler = handler; - state->private_data = private_data; - - subreq = messaging_read_send(state, state->ev, state->msg_ctx, - state->msg_type); - if (tevent_req_nomem(subreq, req)) { - return tevent_req_post(req, ev); - } - tevent_req_set_callback(subreq, messaging_handler_got_msg, req); - return req; -} - -static void messaging_handler_got_msg(struct tevent_req *subreq) -{ - struct tevent_req *req = tevent_req_callback_data( - subreq, struct tevent_req); - struct messaging_handler_state *state = tevent_req_data( - req, struct messaging_handler_state); - struct messaging_rec *rec; - int ret; - bool ok; - - ret = messaging_read_recv(subreq, state, &rec); - TALLOC_FREE(subreq); - if (tevent_req_error(req, ret)) { - return; - } - - subreq = messaging_read_send(state, state->ev, state->msg_ctx, - state->msg_type); - if (tevent_req_nomem(subreq, req)) { - return; - } - tevent_req_set_callback(subreq, messaging_handler_got_msg, req); - - ok = state->handler(state->msg_ctx, &rec, state->private_data); - TALLOC_FREE(rec); - if (ok) { - /* - * Next round - */ - return; - } - TALLOC_FREE(subreq); - tevent_req_done(req); -} - -int messaging_handler_recv(struct tevent_req *req) -{ - return tevent_req_simple_recv_unix(req); -} - static bool messaging_append_new_waiters(struct messaging_context *msg_ctx) { if (msg_ctx->num_new_waiters == 0) { diff --git a/source3/libsmb/clidfs.c b/source3/libsmb/clidfs.c index 207b324..b740007 100644 --- a/source3/libsmb/clidfs.c +++ b/source3/libsmb/clidfs.c @@ -662,9 +662,10 @@ static bool cli_dfs_check_error(struct cli_state *cli, NTSTATUS expected, Get the dfs referral link. ********************************************************************/ -NTSTATUS cli_dfs_get_referral(TALLOC_CTX *ctx, +NTSTATUS cli_dfs_get_referral_ex(TALLOC_CTX *ctx, struct cli_state *cli, const char *path, + uint16_t max_referral_level, struct client_dfs_referral **refs, size_t *num_refs, size_t *consumed) @@ -691,7 +692,7 @@ NTSTATUS cli_dfs_get_referral(TALLOC_CTX *ctx, status = NT_STATUS_NO_MEMORY; goto out; } - SSVAL(param, 0, 0x03); /* max referral level */ + SSVAL(param, 0, max_referral_level); param = trans2_bytes_push_str(param, smbXcli_conn_use_unicode(cli->conn), path, strlen(path)+1, @@ -857,6 +858,22 @@ NTSTATUS cli_dfs_get_referral(TALLOC_CTX *ctx, return status; } +NTSTATUS cli_dfs_get_referral(TALLOC_CTX *ctx, + struct cli_state *cli, + const char *path, + struct client_dfs_referral **refs, + size_t *num_refs, + size_t *consumed) +{ + return cli_dfs_get_referral_ex(ctx, + cli, + path, + 3, + refs, /* Max referral level we want */ + num_refs, + consumed); +} + /******************************************************************** ********************************************************************/ struct cli_dfs_path_split { diff --git a/source3/libsmb/proto.h b/source3/libsmb/proto.h index 47b9cf1..05d91f7 100644 --- a/source3/libsmb/proto.h +++ b/source3/libsmb/proto.h @@ -152,6 +152,13 @@ NTSTATUS cli_cm_open(TALLOC_CTX *ctx, struct cli_state **pcli); void cli_cm_display(struct cli_state *c); struct client_dfs_referral; +NTSTATUS cli_dfs_get_referral_ex(TALLOC_CTX *ctx, + struct cli_state *cli, + const char *path, + uint16_t max_referral_level, + struct client_dfs_referral **refs, + size_t *num_refs, + size_t *consumed); NTSTATUS cli_dfs_get_referral(TALLOC_CTX *ctx, struct cli_state *cli, const char *path, diff --git a/source3/smbd/notifyd/notifyd.c b/source3/smbd/notifyd/notifyd.c index f02ccfa..caf894e 100644 --- a/source3/smbd/notifyd/notifyd.c +++ b/source3/smbd/notifyd/notifyd.c @@ -32,6 +32,7 @@ #include "notifyd.h" #include "lib/util/server_id_db.h" #include "lib/util/tevent_unix.h" +#include "lib/util/tevent_ntstatus.h" #include "ctdbd_conn.h" #include "ctdb_srvids.h" #include "server_id_db_util.h" @@ -122,20 +123,20 @@ struct notifyd_peer { time_t last_broadcast; }; -static bool notifyd_rec_change(struct messaging_context *msg_ctx, - struct messaging_rec **prec, - void *private_data); -static bool notifyd_trigger(struct messaging_context *msg_ctx, - struct messaging_rec **prec, - void *private_data); -static bool notifyd_get_db(struct messaging_context *msg_ctx, - struct messaging_rec **prec, - void *private_data); +static void notifyd_rec_change(struct messaging_context *msg_ctx, + void *private_data, uint32_t msg_type, + struct server_id src, DATA_BLOB *data); +static void notifyd_trigger(struct messaging_context *msg_ctx, + void *private_data, uint32_t msg_type, + struct server_id src, DATA_BLOB *data); +static void notifyd_get_db(struct messaging_context *msg_ctx, + void *private_data, uint32_t msg_type, + struct server_id src, DATA_BLOB *data); #ifdef CLUSTER_SUPPORT -static bool notifyd_got_db(struct messaging_context *msg_ctx, - struct messaging_rec **prec, - void *private_data); +static void notifyd_got_db(struct messaging_context *msg_ctx, + void *private_data, uint32_t msg_type, + struct server_id src, DATA_BLOB *data); static void notifyd_broadcast_reclog(struct ctdbd_connection *ctdbd_conn, struct server_id src, struct messaging_reclog *log); @@ -175,8 +176,6 @@ static int sys_notify_watch_dummy( return 0; } -static void notifyd_handler_done(struct tevent_req *subreq); - #ifdef CLUSTER_SUPPORT static void notifyd_broadcast_reclog_finished(struct tevent_req *subreq); static void notifyd_clean_peers_finished(struct tevent_req *subreq); @@ -192,9 +191,13 @@ struct tevent_req *notifyd_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, sys_notify_watch_fn sys_notify_watch, struct sys_notify_context *sys_notify_ctx) { - struct tevent_req *req, *subreq; + struct tevent_req *req; +#ifdef CLUSTER_SUPPORT + struct tevent_req *subreq; +#endif struct notifyd_state *state; struct server_id_db *names_db; + NTSTATUS status; int ret; req = tevent_req_create(mem_ctx, &state, struct notifyd_state); @@ -217,39 +220,23 @@ struct tevent_req *notifyd_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, return tevent_req_post(req, ev); } - subreq = messaging_handler_send(state, ev, msg_ctx, - MSG_SMB_NOTIFY_REC_CHANGE, - notifyd_rec_change, state); - if (tevent_req_nomem(subreq, req)) { - return tevent_req_post(req, ev); - } - tevent_req_set_callback(subreq, notifyd_handler_done, req); - - subreq = messaging_handler_send(state, ev, msg_ctx, - MSG_SMB_NOTIFY_TRIGGER, - notifyd_trigger, state); - if (tevent_req_nomem(subreq, req)) { + status = messaging_register(msg_ctx, state, MSG_SMB_NOTIFY_REC_CHANGE, + notifyd_rec_change); + if (tevent_req_nterror(req, status)) { return tevent_req_post(req, ev); } - tevent_req_set_callback(subreq, notifyd_handler_done, req); - subreq = messaging_handler_send(state, ev, msg_ctx, - MSG_SMB_NOTIFY_GET_DB, - notifyd_get_db, state); - if (tevent_req_nomem(subreq, req)) { - return tevent_req_post(req, ev); + status = messaging_register(msg_ctx, state, MSG_SMB_NOTIFY_TRIGGER, + notifyd_trigger); + if (tevent_req_nterror(req, status)) { + goto deregister_rec_change; } - tevent_req_set_callback(subreq, notifyd_handler_done, req); -#ifdef CLUSTER_SUPPORT - subreq = messaging_handler_send(state, ev, msg_ctx, - MSG_SMB_NOTIFY_DB, - notifyd_got_db, state); - if (tevent_req_nomem(subreq, req)) { - return tevent_req_post(req, ev); + status = messaging_register(msg_ctx, state, MSG_SMB_NOTIFY_GET_DB, + notifyd_get_db); + if (tevent_req_nterror(req, status)) { + goto deregister_trigger; } - tevent_req_set_callback(subreq, notifyd_handler_done, req); -#endif names_db = messaging_names_db(msg_ctx); @@ -258,7 +245,7 @@ struct tevent_req *notifyd_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, DEBUG(10, ("%s: server_id_db_add failed: %s\n", __func__, strerror(ret))); tevent_req_error(req, ret); - return tevent_req_post(req, ev); + goto deregister_get_db; } if (ctdbd_conn == NULL) { @@ -270,47 +257,57 @@ struct tevent_req *notifyd_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, } #ifdef CLUSTER_SUPPORT + status = messaging_register(msg_ctx, state, MSG_SMB_NOTIFY_DB, + notifyd_got_db); + if (tevent_req_nterror(req, status)) { + goto deregister_get_db; + } + state->log = talloc_zero(state, struct messaging_reclog); if (tevent_req_nomem(state->log, req)) { - return tevent_req_post(req, ev); + goto deregister_db; } subreq = notifyd_broadcast_reclog_send( - state->log, ev, ctdbd_conn, messaging_server_id(msg_ctx), + state->log, ev, ctdbd_conn, + messaging_server_id(msg_ctx), state->log); if (tevent_req_nomem(subreq, req)) { - return tevent_req_post(req, ev); + goto deregister_db; } - tevent_req_set_callback(subreq, notifyd_broadcast_reclog_finished, + tevent_req_set_callback(subreq, + notifyd_broadcast_reclog_finished, req); subreq = notifyd_clean_peers_send(state, ev, state); if (tevent_req_nomem(subreq, req)) { - return tevent_req_post(req, ev); + goto deregister_db; } tevent_req_set_callback(subreq, notifyd_clean_peers_finished, req); - ret = register_with_ctdbd(ctdbd_conn, CTDB_SRVID_SAMBA_NOTIFY_PROXY, + ret = register_with_ctdbd(ctdbd_conn, + CTDB_SRVID_SAMBA_NOTIFY_PROXY, notifyd_snoop_broadcast, state); if (ret != 0) { tevent_req_error(req, ret); - return tevent_req_post(req, ev); + goto deregister_db; } #endif return req; -} - -static void notifyd_handler_done(struct tevent_req *subreq) -{ - struct tevent_req *req = tevent_req_callback_data( - subreq, struct tevent_req); - int ret; - ret = messaging_handler_recv(subreq); - TALLOC_FREE(subreq); - tevent_req_error(req, ret); +#ifdef CLUSTER_SUPPORT +deregister_db: + messaging_deregister(msg_ctx, MSG_SMB_NOTIFY_DB, state); +#endif +deregister_get_db: + messaging_deregister(msg_ctx, MSG_SMB_NOTIFY_GET_DB, state); +deregister_trigger: + messaging_deregister(msg_ctx, MSG_SMB_NOTIFY_TRIGGER, state); +deregister_rec_change: + messaging_deregister(msg_ctx, MSG_SMB_NOTIFY_REC_CHANGE, state); + return tevent_req_post(req, ev); } #ifdef CLUSTER_SUPPORT @@ -567,40 +564,38 @@ static bool notifyd_parse_rec_change(uint8_t *buf, size_t bufsize, return true; } -static bool notifyd_rec_change(struct messaging_context *msg_ctx, - struct messaging_rec **prec, - void *private_data) +static void notifyd_rec_change(struct messaging_context *msg_ctx, + void *private_data, uint32_t msg_type, + struct server_id src, DATA_BLOB *data) { struct notifyd_state *state = talloc_get_type_abort( private_data, struct notifyd_state); struct server_id_buf idbuf; - struct messaging_rec *rec = *prec; struct notify_rec_change_msg *msg; size_t pathlen; bool ok; - DEBUG(10, ("%s: Got %d bytes from %s\n", __func__, - (unsigned)rec->buf.length, - server_id_str_buf(rec->src, &idbuf))); + DBG_DEBUG("Got %zu bytes from %s\n", data->length, + server_id_str_buf(src, &idbuf)); - ok = notifyd_parse_rec_change(rec->buf.data, rec->buf.length, + ok = notifyd_parse_rec_change(data->data, data->length, &msg, &pathlen); if (!ok) { - return true; + return; } ok = notifyd_apply_rec_change( - &rec->src, msg->path, pathlen, &msg->instance, + &src, msg->path, pathlen, &msg->instance, state->entries, state->sys_notify_watch, state->sys_notify_ctx, state->msg_ctx); if (!ok) { DEBUG(1, ("%s: notifyd_apply_rec_change failed, ignoring\n", __func__)); - return true; + return; } if ((state->log == NULL) || (state->ctdbd_conn == NULL)) { - return true; + return; } #ifdef CLUSTER_SUPPORT @@ -608,6 +603,7 @@ static bool notifyd_rec_change(struct messaging_context *msg_ctx, struct messaging_rec **tmp; struct messaging_reclog *log; + struct iovec iov = { .iov_base = data->data, .iov_len = data->length }; log = state->log; @@ -615,11 +611,19 @@ static bool notifyd_rec_change(struct messaging_context *msg_ctx, log->num_recs+1); if (tmp == NULL) { DEBUG(1, ("%s: talloc_realloc failed, ignoring\n", __func__)); - return true; + return; } log->recs = tmp; - log->recs[log->num_recs] = talloc_move(log->recs, prec); + log->recs[log->num_recs] = messaging_rec_create( + log->recs, src, messaging_server_id(msg_ctx), + msg_type, &iov, 1, NULL, 0); + + if (log->recs[log->num_recs] == NULL) { + DBG_WARNING("messaging_rec_create failed, ignoring\n"); + return; + } + log->num_recs += 1; if (log->num_recs >= 100) { @@ -632,8 +636,6 @@ static bool notifyd_rec_change(struct messaging_context *msg_ctx, } #endif - - return true; } struct notifyd_trigger_state { @@ -646,34 +648,33 @@ struct notifyd_trigger_state { static void notifyd_trigger_parser(TDB_DATA key, TDB_DATA data, void *private_data); -static bool notifyd_trigger(struct messaging_context *msg_ctx, - struct messaging_rec **prec, - void *private_data) +static void notifyd_trigger(struct messaging_context *msg_ctx, + void *private_data, uint32_t msg_type, + struct server_id src, DATA_BLOB *data) { -- Samba Shared Repository