1
0
mirror of https://github.com/samba-team/samba.git synced 2025-03-20 22:50:26 +03:00

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 <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
This commit is contained in:
Volker Lendecke 2015-01-09 12:24:58 +00:00 committed by Jeremy Allison
parent 730b025d7b
commit 0deb657ba6
2 changed files with 84 additions and 0 deletions

View File

@ -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; 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;
}

View File

@ -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