summaryrefslogtreecommitdiff
path: root/source3/lib
diff options
context:
space:
mode:
authorVolker Lendecke <vlendec@samba.org>2007-05-28 11:38:42 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:22:52 -0500
commit054bf2fc8bd8ac62e16ec04001c0a4a8409d0e1d (patch)
tree7d548dccf6d872e3b780c9f7b7b88d8046789f2a /source3/lib
parent7e27c984c4033d4f3cbeec9c18627ef9d8aa5f90 (diff)
downloadsamba-054bf2fc8bd8ac62e16ec04001c0a4a8409d0e1d.tar.gz
samba-054bf2fc8bd8ac62e16ec04001c0a4a8409d0e1d.tar.bz2
samba-054bf2fc8bd8ac62e16ec04001c0a4a8409d0e1d.zip
r23171: Convert connections.tdb to dbwrap
(This used to be commit 80a1f43825063bbbda896175d99700ede5a4757a)
Diffstat (limited to 'source3/lib')
-rw-r--r--source3/lib/conn_tdb.c86
-rw-r--r--source3/lib/messages.c22
2 files changed, 60 insertions, 48 deletions
diff --git a/source3/lib/conn_tdb.c b/source3/lib/conn_tdb.c
index e6f491bbfb..979f202df7 100644
--- a/source3/lib/conn_tdb.c
+++ b/source3/lib/conn_tdb.c
@@ -20,76 +20,94 @@
#include "includes.h"
-TDB_CONTEXT *conn_tdb_ctx(BOOL rw)
+static struct db_context *connections_db_ctx(BOOL rw)
{
- static TDB_CONTEXT *tdb;
+ static struct db_context *db_ctx;
- if (tdb != NULL) {
- return tdb;
+ if (db_ctx != NULL) {
+ return db_ctx;
}
if (rw) {
- tdb = tdb_open_log(lock_path("connections.tdb"), 0,
- TDB_CLEAR_IF_FIRST|TDB_DEFAULT,
- O_RDWR | O_CREAT, 0644);
+ db_ctx = db_open(NULL, lock_path("connections.tdb"), 0,
+ TDB_CLEAR_IF_FIRST|TDB_DEFAULT,
+ O_RDWR | O_CREAT, 0644);
}
else {
- tdb = tdb_open_log(lock_path("connections.tdb"), 0,
- TDB_DEFAULT, O_RDONLY, 0);
+ db_ctx = db_open(NULL, lock_path("connections.tdb"), 0,
+ TDB_DEFAULT, O_RDONLY, 0);
}
- if (tdb == NULL) {
- DEBUG(0, ("Could not open connections.tdb: %s\n",
- strerror(errno)));
+ return db_ctx;
+}
+
+struct db_record *connections_fetch_record(TALLOC_CTX *mem_ctx,
+ TDB_DATA key)
+{
+ struct db_context *ctx = connections_db_ctx(True);
+
+ if (ctx == NULL) {
+ return NULL;
}
- return tdb;
+ return ctx->fetch_locked(ctx, mem_ctx, key);
+}
+
+struct db_record *connections_fetch_entry(TALLOC_CTX *mem_ctx,
+ connection_struct *conn,
+ const char *name)
+{
+ struct connections_key ckey;
+ TDB_DATA key;
+
+ ZERO_STRUCT(ckey);
+ ckey.pid = procid_self();
+ ckey.cnum = conn ? conn->cnum : -1;
+ strlcpy(ckey.name, name, sizeof(ckey.name));
+
+ key.dsize = sizeof(ckey);
+ key.dptr = (uint8 *)&ckey;
+
+ return connections_fetch_record(mem_ctx, key);
}
struct conn_traverse_state {
- int (*fn)(TDB_CONTEXT *tdb,
+ int (*fn)(struct db_record *rec,
const struct connections_key *key,
const struct connections_data *data,
void *private_data);
void *private_data;
};
-static int conn_traverse_fn(TDB_CONTEXT *tdb, TDB_DATA key,
- TDB_DATA data, void *private_data)
+static int conn_traverse_fn(struct db_record *rec, void *private_data)
{
struct conn_traverse_state *state =
(struct conn_traverse_state *)private_data;
- if ((key.dsize != sizeof(struct connections_key))
- || (data.dsize != sizeof(struct connections_data))) {
+ if ((rec->key.dsize != sizeof(struct connections_key))
+ || (rec->value.dsize != sizeof(struct connections_data))) {
return 0;
}
- return state->fn(
- tdb, (const struct connections_key *)key.dptr,
- (const struct connections_data *)data.dptr,
- state->private_data);
+ return state->fn(rec, (const struct connections_key *)rec->key.dptr,
+ (const struct connections_data *)rec->value.dptr,
+ state->private_data);
}
-int connections_traverse(int (*fn)(TDB_CONTEXT *tdb, TDB_DATA key,
- TDB_DATA data, void *private_data),
+int connections_traverse(int (*fn)(struct db_record *rec,
+ void *private_data),
void *private_data)
{
- TDB_CONTEXT *tdb = conn_tdb_ctx(True);
-
- if (tdb == NULL) {
- DEBUG(5, ("Could not open connections.tdb r/w, trying r/o\n"));
- tdb = conn_tdb_ctx(False);
- }
+ struct db_context *ctx = connections_db_ctx(False);
- if (tdb == NULL) {
+ if (ctx == NULL) {
return -1;
}
- return tdb_traverse(tdb, fn, private_data);
+ return ctx->traverse(ctx, fn, private_data);
}
-int connections_forall(int (*fn)(TDB_CONTEXT *tdb,
+int connections_forall(int (*fn)(struct db_record *rec,
const struct connections_key *key,
const struct connections_data *data,
void *private_data),
@@ -105,5 +123,5 @@ int connections_forall(int (*fn)(TDB_CONTEXT *tdb,
BOOL connections_init(BOOL rw)
{
- return (conn_tdb_ctx(rw) != NULL);
+ return (connections_db_ctx(rw) != NULL);
}
diff --git a/source3/lib/messages.c b/source3/lib/messages.c
index 056286f89a..01683bf9ec 100644
--- a/source3/lib/messages.c
+++ b/source3/lib/messages.c
@@ -96,12 +96,12 @@ struct msg_all {
Send one of the messages for the broadcast.
****************************************************************************/
-static int traverse_fn(TDB_CONTEXT *the_tdb,
+static int traverse_fn(struct db_record *rec,
const struct connections_key *ckey,
const struct connections_data *crec,
- void *private_data)
+ void *state)
{
- struct msg_all *msg_all = (struct msg_all *)private_data;
+ struct msg_all *msg_all = (struct msg_all *)state;
NTSTATUS status;
if (crec->cnum != -1)
@@ -120,20 +120,14 @@ static int traverse_fn(TDB_CONTEXT *the_tdb,
(uint8 *)msg_all->buf, msg_all->len);
if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_HANDLE)) {
-
- TDB_DATA key;
- /* If the pid was not found delete the entry from
- * connections.tdb */
-
- DEBUG(2,("pid %s doesn't exist - deleting connections "
- "%d [%s]\n", procid_str_static(&crec->pid),
- crec->cnum, crec->servicename));
+ /* If the pid was not found delete the entry from connections.tdb */
- key.dptr = (uint8 *)ckey;
- key.dsize = sizeof(*ckey);
+ DEBUG(2,("pid %s doesn't exist - deleting connections %d [%s]\n",
+ procid_str_static(&crec->pid), crec->cnum,
+ crec->servicename));
- tdb_delete(the_tdb, key);
+ rec->delete_rec(rec);
}
msg_all->n_sent++;
return 0;