1
0
mirror of https://github.com/samba-team/samba.git synced 2025-02-26 21:57:41 +03:00

notify: Re-add notify_walk()

This used to be a tdb traverse wrapper. Now we get the notify db from
notifyd via messages.

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:48:56 +00:00 committed by Jeremy Allison
parent 0deb657ba6
commit c118c301c9
3 changed files with 96 additions and 34 deletions

View File

@ -252,14 +252,72 @@ void notify_walk_idx(struct notify_context *notify,
return;
}
void notify_walk(struct notify_context *notify,
void (*fn)(const char *path,
struct notify_db_entry *entries,
size_t num_entries,
time_t deleted_time, void *private_data),
void *private_data)
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)
{
return;
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)) {
DEBUG(10, ("%s: messaging_send_buf failed\n",
nt_errstr(status)));
TALLOC_FREE(ev);
return status;
}
ok = tevent_req_poll(req, ev);
if (!ok) {
DEBUG(10, ("%s: tevent_req_poll failed\n", __func__));
TALLOC_FREE(ev);
return NT_STATUS_INTERNAL_ERROR;
}
ret = messaging_read_recv(req, ev, &rec);
if (ret != 0) {
DEBUG(10, ("%s: messaging_read_recv failed: %s\n",
__func__, 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) {
DEBUG(10, ("%s: notifyd_parse_db failed: %s\n",
__func__, strerror(ret)));
TALLOC_FREE(ev);
return map_nt_error_from_unix(ret);
}
TALLOC_FREE(ev);
return NT_STATUS_OK;
}
void notify_cleanup(struct notify_context *notify)

View File

@ -574,12 +574,14 @@ void notify_walk_idx(struct notify_context *notify,
uint32_t *vnns, size_t num_vnns,
void *private_data),
void *private_data);
void notify_walk(struct notify_context *notify,
void (*fn)(const char *path,
struct notify_db_entry *entries,
size_t num_entries,
time_t deleted_time, void *private_data),
void *private_data);
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);
void notify_cleanup(struct notify_context *notify);
/* The following definitions come from smbd/ntquotas.c */

View File

@ -45,6 +45,7 @@
#include "lib/conn_tdb.h"
#include "serverid.h"
#include "status_profile.h"
#include "smbd/notifyd/notifyd.h"
#define SMB_MAXPIDS 2048
static uid_t Ucrit_uid = 0; /* added by OH */
@ -326,27 +327,17 @@ static int traverse_sessionid(const char *key, struct sessionid *session,
}
static void print_notify_recs(const char *path,
struct notify_db_entry *entries,
size_t num_entries,
time_t deleted_time, void *private_data)
static bool print_notify_rec(const char *path, struct server_id server,
const struct notify_instance *instance,
void *private_data)
{
size_t i;
d_printf("%s\n", path);
struct server_id_buf idbuf;
if (num_entries == 0) {
d_printf("deleted %s\n", time_to_asc(deleted_time));
}
d_printf("%s\\%s\\%x\\%x\n", path, server_id_str_buf(server, &idbuf),
(unsigned)instance->filter,
(unsigned)instance->subdir_filter);
for (i=0; i<num_entries; i++) {
struct notify_db_entry *e = &entries[i];
struct server_id_buf idbuf;
printf("%s %x %x\n", server_id_str_buf(e->server, &idbuf),
(unsigned)e->filter,
(unsigned)e->subdir_filter);
}
printf("\n");
return true;
}
int main(int argc, const char *argv[])
@ -375,7 +366,7 @@ int main(int argc, const char *argv[])
};
TALLOC_CTX *frame = talloc_stackframe();
int ret = 0;
struct messaging_context *msg_ctx;
struct messaging_context *msg_ctx = NULL;
char *db_path;
bool ok;
@ -586,11 +577,22 @@ int main(int argc, const char *argv[])
if (show_notify) {
struct notify_context *n;
n = notify_init(talloc_tos(), NULL, NULL);
if (msg_ctx == NULL) {
msg_ctx = messaging_init(
NULL, samba_tevent_context_init(NULL));
if (msg_ctx == NULL) {
fprintf(stderr, "messaging_init failed\n");
ret = -1;
goto done;
}
}
n = notify_init(talloc_tos(), msg_ctx,
messaging_tevent_context(msg_ctx));
if (n == NULL) {
goto done;
}
notify_walk(n, print_notify_recs, NULL);
notify_walk(n, print_notify_rec, NULL);
TALLOC_FREE(n);
}