ctx->msg_ctx, ctx->notifyd, MSG_SMB_NOTIFY_TRIGGER,
iov, ARRAY_SIZE(iov), NULL, 0);
}
-
-NTSTATUS notify_walk(struct notify_context *notify,
- bool (*fn)(const char *path, struct server_id server,
- const struct notify_instance *instance,
- void *private_data),
- void *private_data)
-{
- struct tevent_context *ev;
- struct tevent_req *req;
- struct messaging_rec *rec;
- uint64_t log_idx;
- NTSTATUS status;
- int ret;
- bool ok;
-
- ev = samba_tevent_context_init(notify);
- if (ev == NULL) {
- return NT_STATUS_NO_MEMORY;
- }
-
- req = messaging_read_send(ev, ev, notify->msg_ctx, MSG_SMB_NOTIFY_DB);
- if (req == NULL) {
- TALLOC_FREE(ev);
- return NT_STATUS_NO_MEMORY;
- }
-
- ok = tevent_req_set_endtime(req, ev, timeval_current_ofs(10, 0));
- if (!ok) {
- TALLOC_FREE(ev);
- return NT_STATUS_NO_MEMORY;
- }
-
- status = messaging_send_buf(notify->msg_ctx, notify->notifyd,
- MSG_SMB_NOTIFY_GET_DB, NULL, 0);
- if (!NT_STATUS_IS_OK(status)) {
- DBG_DEBUG("messaging_send_buf failed: %s\n",
- nt_errstr(status));
- TALLOC_FREE(ev);
- return status;
- }
-
- ok = tevent_req_poll(req, ev);
- if (!ok) {
- DBG_DEBUG("tevent_req_poll failed\n");
- TALLOC_FREE(ev);
- return NT_STATUS_INTERNAL_ERROR;
- }
-
- ret = messaging_read_recv(req, ev, &rec);
- if (ret != 0) {
- DBG_DEBUG("messaging_read_recv failed: %s\n",
- strerror(ret));
- TALLOC_FREE(ev);
- return map_nt_error_from_unix(ret);
- }
-
- ret = notifyd_parse_db(rec->buf.data, rec->buf.length, &log_idx,
- fn, private_data);
- if (ret != 0) {
- DBG_DEBUG("notifyd_parse_db failed: %s\n",
- strerror(ret));
- TALLOC_FREE(ev);
- return map_nt_error_from_unix(ret);
- }
-
- TALLOC_FREE(ev);
- return NT_STATUS_OK;
-}
return 0;
}
#endif
-
-struct notifyd_parse_db_state {
- bool (*fn)(const char *path,
- struct server_id server,
- const struct notify_instance *instance,
- void *private_data);
- void *private_data;
-};
-
-static bool notifyd_parse_db_parser(TDB_DATA key, TDB_DATA value,
- void *private_data)
-{
- struct notifyd_parse_db_state *state = private_data;
- char path[key.dsize+1];
- struct notifyd_instance *instances = NULL;
- size_t num_instances = 0;
- size_t i;
- bool ok;
-
- memcpy(path, key.dptr, key.dsize);
- path[key.dsize] = 0;
-
- ok = notifyd_parse_entry(value.dptr, value.dsize, &instances,
- &num_instances);
- if (!ok) {
- DBG_DEBUG("Could not parse entry for path %s\n", path);
- return true;
- }
-
- for (i=0; i<num_instances; i++) {
- ok = state->fn(path, instances[i].client,
- &instances[i].instance,
- state->private_data);
- if (!ok) {
- return false;
- }
- }
-
- return true;
-}
-
-int notifyd_parse_db(const uint8_t *buf, size_t buflen,
- uint64_t *log_index,
- bool (*fn)(const char *path,
- struct server_id server,
- const struct notify_instance *instance,
- void *private_data),
- void *private_data)
-{
- struct notifyd_parse_db_state state = {
- .fn = fn, .private_data = private_data
- };
- NTSTATUS status;
-
- if (buflen < 8) {
- return EINVAL;
- }
- *log_index = BVAL(buf, 0);
-
- buf += 8;
- buflen -= 8;
-
- status = dbwrap_parse_marshall_buf(
- buf, buflen, notifyd_parse_db_parser, &state);
- if (!NT_STATUS_IS_OK(status)) {
- return map_errno_from_nt_status(status);
- }
-
- return 0;
-}
struct sys_notify_context *sys_notify_ctx);
int notifyd_recv(struct tevent_req *req);
-/*
- * Parse a database received via the MSG_SMB_NOTIFY_[GET_]DB messages to the
- * notify daemon
- */
-int notifyd_parse_db(const uint8_t *buf, size_t buflen,
- uint64_t *log_index,
- bool (*fn)(const char *path,
- struct server_id server,
- const struct notify_instance *instance,
- void *private_data),
- void *private_data);
-
-
#endif
--- /dev/null
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "replace.h"
+#include "lib/util/debug.h"
+#include "lib/util/server_id_db.h"
+#include "notifyd_private.h"
+#include "notifyd_db.h"
+
+struct notifyd_parse_db_state {
+ bool (*fn)(const char *path,
+ struct server_id server,
+ const struct notify_instance *instance,
+ void *private_data);
+ void *private_data;
+};
+
+static bool notifyd_parse_db_parser(TDB_DATA key, TDB_DATA value,
+ void *private_data)
+{
+ struct notifyd_parse_db_state *state = private_data;
+ char path[key.dsize+1];
+ struct notifyd_instance *instances = NULL;
+ size_t num_instances = 0;
+ size_t i;
+ bool ok;
+
+ memcpy(path, key.dptr, key.dsize);
+ path[key.dsize] = 0;
+
+ ok = notifyd_parse_entry(value.dptr, value.dsize, &instances,
+ &num_instances);
+ if (!ok) {
+ DBG_DEBUG("Could not parse entry for path %s\n", path);
+ return true;
+ }
+
+ for (i=0; i<num_instances; i++) {
+ ok = state->fn(path, instances[i].client,
+ &instances[i].instance,
+ state->private_data);
+ if (!ok) {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+static NTSTATUS notifyd_parse_db(
+ const uint8_t *buf,
+ size_t buflen,
+ uint64_t *log_index,
+ bool (*fn)(const char *path,
+ struct server_id server,
+ const struct notify_instance *instance,
+ void *private_data),
+ void *private_data)
+{
+ struct notifyd_parse_db_state state = {
+ .fn = fn, .private_data = private_data
+ };
+ NTSTATUS status;
+
+ if (buflen < 8) {
+ return NT_STATUS_INTERNAL_DB_CORRUPTION;
+ }
+ *log_index = BVAL(buf, 0);
+
+ buf += 8;
+ buflen -= 8;
+
+ status = dbwrap_parse_marshall_buf(
+ buf, buflen, notifyd_parse_db_parser, &state);
+ return status;
+}
+
+NTSTATUS notify_walk(struct messaging_context *msg_ctx,
+ bool (*fn)(const char *path, struct server_id server,
+ const struct notify_instance *instance,
+ void *private_data),
+ void *private_data)
+{
+ struct server_id_db *names_db = NULL;
+ struct server_id notifyd = { .pid = 0, };
+ struct tevent_context *ev = NULL;
+ struct tevent_req *req = NULL;
+ struct messaging_rec *rec = NULL;
+ uint64_t log_idx;
+ NTSTATUS status;
+ int ret;
+ bool ok;
+
+ names_db = messaging_names_db(msg_ctx);
+ ok = server_id_db_lookup_one(names_db, "notify-daemon", ¬ifyd);
+ if (!ok) {
+ DBG_WARNING("No notify daemon around\n");
+ return NT_STATUS_SERVER_UNAVAILABLE;
+ }
+
+ ev = samba_tevent_context_init(msg_ctx);
+ if (ev == NULL) {
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ req = messaging_read_send(ev, ev, msg_ctx, MSG_SMB_NOTIFY_DB);
+ if (req == NULL) {
+ TALLOC_FREE(ev);
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ ok = tevent_req_set_endtime(req, ev, timeval_current_ofs(10, 0));
+ if (!ok) {
+ TALLOC_FREE(ev);
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ status = messaging_send_buf(
+ msg_ctx, notifyd, MSG_SMB_NOTIFY_GET_DB, NULL, 0);
+ if (!NT_STATUS_IS_OK(status)) {
+ DBG_DEBUG("messaging_send_buf failed: %s\n",
+ nt_errstr(status));
+ TALLOC_FREE(ev);
+ return status;
+ }
+
+ ok = tevent_req_poll(req, ev);
+ if (!ok) {
+ DBG_DEBUG("tevent_req_poll failed\n");
+ TALLOC_FREE(ev);
+ return NT_STATUS_INTERNAL_ERROR;
+ }
+
+ ret = messaging_read_recv(req, ev, &rec);
+ if (ret != 0) {
+ DBG_DEBUG("messaging_read_recv failed: %s\n",
+ strerror(ret));
+ TALLOC_FREE(ev);
+ return map_nt_error_from_unix(ret);
+ }
+
+ status = notifyd_parse_db(
+ rec->buf.data, rec->buf.length, &log_idx, fn, private_data);
+ if (!NT_STATUS_IS_OK(status)) {
+ DBG_DEBUG("notifyd_parse_db failed: %s\n",
+ nt_errstr(status));
+ TALLOC_FREE(ev);
+ return status;
+ }
+
+ TALLOC_FREE(ev);
+ return NT_STATUS_OK;
+}
--- /dev/null
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __NOTIFYD_NOTIFYD_DB_H__
+#define __NOTIFYD_NOTIFYD_DB_H__
+#include "replace.h"
+#include "notifyd.h"
+
+NTSTATUS notify_walk(struct messaging_context *msg_ctx,
+ bool (*fn)(const char *path, struct server_id server,
+ const struct notify_instance *instance,
+ void *private_data),
+ void *private_data);
+
+#endif
#!/usr/bin/env python
bld.SAMBA3_SUBSYSTEM('notifyd_db',
- source='notifyd_entry.c',
- deps='samba-debug')
+ source='notifyd_entry.c notifyd_db.c',
+ deps='samba-debug dbwrap errors3')
bld.SAMBA3_SUBSYSTEM('notifyd',
source='notifyd.c',
uint32_t action, uint32_t filter,
const char *dir, const char *path);
-struct notify_instance;
-NTSTATUS notify_walk(struct notify_context *notify,
- bool (*fn)(const char *path, struct server_id server,
- const struct notify_instance *instance,
- void *private_data),
- void *private_data);
-
/* The following definitions come from smbd/ntquotas.c */
NTSTATUS vfs_get_ntquota(files_struct *fsp, enum SMB_QUOTA_TYPE qtype,
#include "conn_tdb.h"
#include "serverid.h"
#include "status_profile.h"
-#include "smbd/notifyd/notifyd.h"
+#include "smbd/notifyd/notifyd_db.h"
#include "cmdline_contexts.h"
#include "locking/leases_db.h"
#include "lib/util/string_wrappers.h"
}
if (show_notify) {
- struct notify_context *n;
-
- n = notify_init(talloc_tos(), msg_ctx,
- NULL, NULL);
- if (n == NULL) {
- goto done;
- }
- notify_walk(n, print_notify_rec, NULL);
- TALLOC_FREE(n);
+ notify_walk(msg_ctx, print_notify_rec, NULL);
}
done: