summaryrefslogtreecommitdiff
path: root/source3/smbd
diff options
context:
space:
mode:
authorVolker Lendecke <vlendec@samba.org>2007-05-29 10:50:25 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:22:53 -0500
commit9c6f9fa28a849035ee40bb65e8a79c5f555242d6 (patch)
tree3986362a0a2a08eee50e0c563ec2b612646a954a /source3/smbd
parentfb76516ccd06bd5d2e013d07c4477e28df74962a (diff)
downloadsamba-9c6f9fa28a849035ee40bb65e8a79c5f555242d6.tar.gz
samba-9c6f9fa28a849035ee40bb65e8a79c5f555242d6.tar.bz2
samba-9c6f9fa28a849035ee40bb65e8a79c5f555242d6.zip
r23186: Checkin on behalf of Tridge:
Change notify.tdb to use dbwrap (This used to be commit 3a089403871df88f4a3bf86c3db0d169cd4fb434)
Diffstat (limited to 'source3/smbd')
-rw-r--r--source3/smbd/notify_internal.c114
1 files changed, 57 insertions, 57 deletions
diff --git a/source3/smbd/notify_internal.c b/source3/smbd/notify_internal.c
index 940ff8aae9..20bfb74a29 100644
--- a/source3/smbd/notify_internal.c
+++ b/source3/smbd/notify_internal.c
@@ -28,13 +28,14 @@
#include "librpc/gen_ndr/ndr_notify.h"
struct notify_context {
- struct tdb_wrap *w;
+ struct db_context *db;
struct server_id server;
struct messaging_context *messaging_ctx;
struct notify_list *list;
struct notify_array *array;
int seqnum;
struct sys_notify_context *sys_notify_ctx;
+ TDB_DATA key;
};
@@ -91,10 +92,10 @@ struct notify_context *notify_init(TALLOC_CTX *mem_ctx, struct server_id server,
return NULL;
}
- notify->w = tdb_wrap_open(notify, lock_path("notify.tdb"),
+ notify->db = db_open(notify, lock_path("notify.tdb"),
0, TDB_SEQNUM|TDB_CLEAR_IF_FIRST,
O_RDWR|O_CREAT, 0644);
- if (notify->w == NULL) {
+ if (notify->db == NULL) {
talloc_free(notify);
return NULL;
}
@@ -103,7 +104,8 @@ struct notify_context *notify_init(TALLOC_CTX *mem_ctx, struct server_id server,
notify->messaging_ctx = messaging_ctx;
notify->list = NULL;
notify->array = NULL;
- notify->seqnum = tdb_get_seqnum(notify->w->tdb);
+ notify->seqnum = notify->db->get_seqnum(notify->db);
+ notify->key = string_term_tdb_data(NOTIFY_KEY);
talloc_set_destructor(notify, notify_destructor);
@@ -117,37 +119,29 @@ struct notify_context *notify_init(TALLOC_CTX *mem_ctx, struct server_id server,
return notify;
}
-
/*
- lock the notify db
+ lock and fetch the record
*/
-static NTSTATUS notify_lock(struct notify_context *notify)
+static NTSTATUS notify_fetch_locked(struct notify_context *notify, struct db_record **rec)
{
- if (tdb_lock_bystring(notify->w->tdb, NOTIFY_KEY) != 0) {
+ *rec = notify->db->fetch_locked(notify->db, notify, notify->key);
+ if (*rec == NULL) {
return NT_STATUS_INTERNAL_DB_CORRUPTION;
}
return NT_STATUS_OK;
}
/*
- unlock the notify db
-*/
-static void notify_unlock(struct notify_context *notify)
-{
- tdb_unlock_bystring(notify->w->tdb, NOTIFY_KEY);
-}
-
-/*
load the notify array
*/
-static NTSTATUS notify_load(struct notify_context *notify)
+static NTSTATUS notify_load(struct notify_context *notify, struct db_record *rec)
{
TDB_DATA dbuf;
DATA_BLOB blob;
NTSTATUS status;
int seqnum;
- seqnum = tdb_get_seqnum(notify->w->tdb);
+ seqnum = notify->db->get_seqnum(notify->db);
if (seqnum == notify->seqnum && notify->array != NULL) {
return NT_STATUS_OK;
@@ -159,23 +153,32 @@ static NTSTATUS notify_load(struct notify_context *notify)
notify->array = TALLOC_ZERO_P(notify, struct notify_array);
NT_STATUS_HAVE_NO_MEMORY(notify->array);
- dbuf = tdb_fetch_bystring(notify->w->tdb, NOTIFY_KEY);
- if (dbuf.dptr == NULL) {
- return NT_STATUS_OK;
+ if (!rec) {
+ if (notify->db->fetch(notify->db, notify, notify->key, &dbuf) != 0) {
+ return NT_STATUS_INTERNAL_DB_CORRUPTION;
+ }
+ } else {
+ dbuf = rec->value;
}
blob.data = (uint8 *)dbuf.dptr;
blob.length = dbuf.dsize;
- status = ndr_pull_struct_blob(&blob, notify->array, notify->array,
- (ndr_pull_flags_fn_t)ndr_pull_notify_array);
+ if (blob.length == 0) {
+ status = NT_STATUS_OK;
+ } else {
+ status = ndr_pull_struct_blob(&blob, notify->array, notify->array,
+ (ndr_pull_flags_fn_t)ndr_pull_notify_array);
+ }
if (DEBUGLEVEL >= 10) {
DEBUG(10, ("notify_load:\n"));
NDR_PRINT_DEBUG(notify_array, notify->array);
}
- free(dbuf.dptr);
+ if (!rec) {
+ talloc_free(dbuf.dptr);
+ }
return status;
}
@@ -193,12 +196,11 @@ static int notify_compare(const void *p1, const void *p2)
/*
save the notify array
*/
-static NTSTATUS notify_save(struct notify_context *notify)
+static NTSTATUS notify_save(struct notify_context *notify, struct db_record *rec)
{
TDB_DATA dbuf;
DATA_BLOB blob;
NTSTATUS status;
- int ret;
TALLOC_CTX *tmp_ctx;
/* if possible, remove some depth arrays */
@@ -209,11 +211,7 @@ static NTSTATUS notify_save(struct notify_context *notify)
/* we might just be able to delete the record */
if (notify->array->num_depths == 0) {
- ret = tdb_delete_bystring(notify->w->tdb, NOTIFY_KEY);
- if (ret != 0) {
- return NT_STATUS_INTERNAL_DB_CORRUPTION;
- }
- return NT_STATUS_OK;
+ return rec->delete_rec(rec);
}
tmp_ctx = talloc_new(notify);
@@ -233,14 +231,11 @@ static NTSTATUS notify_save(struct notify_context *notify)
dbuf.dptr = blob.data;
dbuf.dsize = blob.length;
-
- ret = tdb_store_bystring(notify->w->tdb, NOTIFY_KEY, dbuf, TDB_REPLACE);
+
+ status = rec->store(rec, dbuf, TDB_REPLACE);
talloc_free(tmp_ctx);
- if (ret != 0) {
- return NT_STATUS_INTERNAL_DB_CORRUPTION;
- }
- return NT_STATUS_OK;
+ return status;
}
@@ -293,7 +288,8 @@ static void sys_notify_callback(struct sys_notify_context *ctx,
/*
add an entry to the notify array
*/
-static NTSTATUS notify_add_array(struct notify_context *notify, struct notify_entry *e,
+static NTSTATUS notify_add_array(struct notify_context *notify, struct db_record *rec,
+ struct notify_entry *e,
void *private_data, int depth)
{
int i;
@@ -341,7 +337,7 @@ static NTSTATUS notify_add_array(struct notify_context *notify, struct notify_en
d->max_mask_subdir |= d->entries[i].subdir_filter;
}
- return notify_save(notify);
+ return notify_save(notify, rec);
}
/*
@@ -358,18 +354,20 @@ NTSTATUS notify_add(struct notify_context *notify, struct notify_entry *e0,
struct notify_list *listel;
size_t len;
int depth;
+ struct db_record *rec;
/* see if change notify is enabled at all */
if (notify == NULL) {
return NT_STATUS_NOT_IMPLEMENTED;
}
- status = notify_lock(notify);
+ status = notify_fetch_locked(notify, &rec);
NT_STATUS_NOT_OK_RETURN(status);
- status = notify_load(notify);
+ status = notify_load(notify, rec);
if (!NT_STATUS_IS_OK(status)) {
- goto done;
+ talloc_free(rec);
+ return status;
}
/* cope with /. on the end of the path */
@@ -415,11 +413,11 @@ NTSTATUS notify_add(struct notify_context *notify, struct notify_entry *e0,
then we need to install it in the array used for the
intra-samba notify handling */
if (e.filter != 0 || e.subdir_filter != 0) {
- status = notify_add_array(notify, &e, private_data, depth);
+ status = notify_add_array(notify, rec, &e, private_data, depth);
}
done:
- notify_unlock(notify);
+ talloc_free(rec);
talloc_free(tmp_path);
return status;
@@ -434,6 +432,7 @@ NTSTATUS notify_remove(struct notify_context *notify, void *private_data)
struct notify_list *listel;
int i, depth;
struct notify_depth *d;
+ struct db_record *rec;
/* see if change notify is enabled at all */
if (notify == NULL) {
@@ -454,17 +453,17 @@ NTSTATUS notify_remove(struct notify_context *notify, void *private_data)
talloc_free(listel);
- status = notify_lock(notify);
+ status = notify_fetch_locked(notify, &rec);
NT_STATUS_NOT_OK_RETURN(status);
- status = notify_load(notify);
+ status = notify_load(notify, rec);
if (!NT_STATUS_IS_OK(status)) {
- notify_unlock(notify);
+ talloc_free(rec);
return status;
}
if (depth >= notify->array->num_depths) {
- notify_unlock(notify);
+ talloc_free(rec);
return NT_STATUS_OBJECT_NAME_NOT_FOUND;
}
@@ -478,7 +477,7 @@ NTSTATUS notify_remove(struct notify_context *notify, void *private_data)
}
}
if (i == d->num_entries) {
- notify_unlock(notify);
+ talloc_free(rec);
return NT_STATUS_OBJECT_NAME_NOT_FOUND;
}
@@ -488,9 +487,9 @@ NTSTATUS notify_remove(struct notify_context *notify, void *private_data)
}
d->num_entries--;
- status = notify_save(notify);
+ status = notify_save(notify, rec);
- notify_unlock(notify);
+ talloc_free(rec);
return status;
}
@@ -503,13 +502,14 @@ static NTSTATUS notify_remove_all(struct notify_context *notify,
{
NTSTATUS status;
int i, depth, del_count=0;
+ struct db_record *rec;
- status = notify_lock(notify);
+ status = notify_fetch_locked(notify, &rec);
NT_STATUS_NOT_OK_RETURN(status);
- status = notify_load(notify);
+ status = notify_load(notify, rec);
if (!NT_STATUS_IS_OK(status)) {
- notify_unlock(notify);
+ talloc_free(rec);
return status;
}
@@ -531,10 +531,10 @@ static NTSTATUS notify_remove_all(struct notify_context *notify,
}
if (del_count > 0) {
- status = notify_save(notify);
+ status = notify_save(notify, rec);
}
- notify_unlock(notify);
+ talloc_free(rec);
return status;
}
@@ -594,7 +594,7 @@ void notify_trigger(struct notify_context *notify,
}
again:
- status = notify_load(notify);
+ status = notify_load(notify, NULL);
if (!NT_STATUS_IS_OK(status)) {
return;
}