From 0deb657ba689c8b0e259b385bce30d4ff56f2810 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 9 Jan 2015 12:24:58 +0000 Subject: [PATCH] notifyd: Add notifyd_parse_db() The database format notifyd is "private" to it. This makes it possible for smbcontrol and others to query notifyd's database with MSG_SMB_NOTIFY_GET_DB and inspect it without having to know exactly what format it uses. Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- source3/smbd/notifyd/notifyd.c | 71 ++++++++++++++++++++++++++++++++++ source3/smbd/notifyd/notifyd.h | 13 +++++++ 2 files changed, 84 insertions(+) diff --git a/source3/smbd/notifyd/notifyd.c b/source3/smbd/notifyd/notifyd.c index 0f31a61fd1f..d9fb11d8a36 100644 --- a/source3/smbd/notifyd/notifyd.c +++ b/source3/smbd/notifyd/notifyd.c @@ -1417,3 +1417,74 @@ static void notifyd_snoop_broadcast(uint32_t src_vnn, uint32_t dst_vnn, return; } } + +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) { + DEBUG(10, ("%s: Could not parse entry for path %s\n", + __func__, path)); + return true; + } + + for (i=0; ifn(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; +} diff --git a/source3/smbd/notifyd/notifyd.h b/source3/smbd/notifyd/notifyd.h index dc0a4e8392d..672ffba202d 100644 --- a/source3/smbd/notifyd/notifyd.h +++ b/source3/smbd/notifyd/notifyd.h @@ -140,4 +140,17 @@ struct tevent_req *notifyd_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev, 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 -- 2.34.1