From 4aa44f7475e03dcc596f6a13fffffda7268074a1 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 8 May 2007 13:44:36 +0000 Subject: r22761: This introduces lib/conn_tdb.c with two main functions: connections_traverse and connections_forall. This centralizes all the routines that did individual tdb_open("connections.tdb") and direct tdb_traverse. Volker (This used to be commit e43e94cda1ad8876b3cb5d1129080b57fa6ec214) --- source3/lib/conn_tdb.c | 109 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 source3/lib/conn_tdb.c (limited to 'source3/lib/conn_tdb.c') diff --git a/source3/lib/conn_tdb.c b/source3/lib/conn_tdb.c new file mode 100644 index 0000000000..e6f491bbfb --- /dev/null +++ b/source3/lib/conn_tdb.c @@ -0,0 +1,109 @@ +/* + Unix SMB/CIFS implementation. + Low-level connections.tdb access functions + Copyright (C) Volker Lendecke 2007 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +TDB_CONTEXT *conn_tdb_ctx(BOOL rw) +{ + static TDB_CONTEXT *tdb; + + if (tdb != NULL) { + return tdb; + } + + if (rw) { + tdb = tdb_open_log(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); + } + + if (tdb == NULL) { + DEBUG(0, ("Could not open connections.tdb: %s\n", + strerror(errno))); + } + + return tdb; +} + +struct conn_traverse_state { + int (*fn)(TDB_CONTEXT *tdb, + 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) +{ + struct conn_traverse_state *state = + (struct conn_traverse_state *)private_data; + + if ((key.dsize != sizeof(struct connections_key)) + || (data.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); +} + +int connections_traverse(int (*fn)(TDB_CONTEXT *tdb, TDB_DATA key, + TDB_DATA data, 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); + } + + if (tdb == NULL) { + return -1; + } + + return tdb_traverse(tdb, fn, private_data); +} + +int connections_forall(int (*fn)(TDB_CONTEXT *tdb, + const struct connections_key *key, + const struct connections_data *data, + void *private_data), + void *private_data) +{ + struct conn_traverse_state state; + + state.fn = fn; + state.private_data = private_data; + + return connections_traverse(conn_traverse_fn, (void *)&state); +} + +BOOL connections_init(BOOL rw) +{ + return (conn_tdb_ctx(rw) != NULL); +} -- cgit From 054bf2fc8bd8ac62e16ec04001c0a4a8409d0e1d Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 28 May 2007 11:38:42 +0000 Subject: r23171: Convert connections.tdb to dbwrap (This used to be commit 80a1f43825063bbbda896175d99700ede5a4757a) --- source3/lib/conn_tdb.c | 86 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 52 insertions(+), 34 deletions(-) (limited to 'source3/lib/conn_tdb.c') 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); } -- cgit From d824b98f80ba186030cbb70b3a1e5daf80469ecd Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 9 Jul 2007 19:25:36 +0000 Subject: r23779: Change from v2 or later to v3 or later. Jeremy. (This used to be commit 407e6e695b8366369b7c76af1ff76869b45347b3) --- source3/lib/conn_tdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/conn_tdb.c') diff --git a/source3/lib/conn_tdb.c b/source3/lib/conn_tdb.c index 979f202df7..69d666ca25 100644 --- a/source3/lib/conn_tdb.c +++ b/source3/lib/conn_tdb.c @@ -5,7 +5,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, -- cgit From 5e54558c6dea67b56bbfaba5698f3a434d3dffb6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 00:52:41 +0000 Subject: r23784: use the GPLv3 boilerplate as recommended by the FSF and the license text (This used to be commit b0132e94fc5fef936aa766fb99a306b3628e9f07) --- source3/lib/conn_tdb.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/lib/conn_tdb.c') diff --git a/source3/lib/conn_tdb.c b/source3/lib/conn_tdb.c index 69d666ca25..d9552c5f07 100644 --- a/source3/lib/conn_tdb.c +++ b/source3/lib/conn_tdb.c @@ -14,8 +14,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #include "includes.h" -- cgit From 30191d1a5704ad2b158386b511558972d539ce47 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 18 Oct 2007 17:40:25 -0700 Subject: RIP BOOL. Convert BOOL -> bool. I found a few interesting bugs in various places whilst doing this (places that assumed BOOL == int). I also need to fix the Samba4 pidl generation (next checkin). Jeremy. (This used to be commit f35a266b3cbb3e5fa6a86be60f34fe340a3ca71f) --- source3/lib/conn_tdb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/lib/conn_tdb.c') diff --git a/source3/lib/conn_tdb.c b/source3/lib/conn_tdb.c index d9552c5f07..dd0a354a85 100644 --- a/source3/lib/conn_tdb.c +++ b/source3/lib/conn_tdb.c @@ -19,7 +19,7 @@ #include "includes.h" -static struct db_context *connections_db_ctx(BOOL rw) +static struct db_context *connections_db_ctx(bool rw) { static struct db_context *db_ctx; @@ -120,7 +120,7 @@ int connections_forall(int (*fn)(struct db_record *rec, return connections_traverse(conn_traverse_fn, (void *)&state); } -BOOL connections_init(BOOL rw) +bool connections_init(bool rw) { return (connections_db_ctx(rw) != NULL); } -- cgit From 68694369fc96354452979b07425f3f48c4f73bbe Mon Sep 17 00:00:00 2001 From: Alexander Bokovoy Date: Wed, 16 Jan 2008 12:09:48 +0300 Subject: Merge CTDB-related fixes from samba-ctdb 3.0 branch (http://samba.org/~tridge/3_0-ctdb) Signed-off-by: Alexander Bokovoy (This used to be commit 0c8e23afbbb2d081fc23908bafcad04650bfacea) --- source3/lib/conn_tdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/conn_tdb.c') diff --git a/source3/lib/conn_tdb.c b/source3/lib/conn_tdb.c index dd0a354a85..22d85c873d 100644 --- a/source3/lib/conn_tdb.c +++ b/source3/lib/conn_tdb.c @@ -34,7 +34,7 @@ static struct db_context *connections_db_ctx(bool rw) } else { db_ctx = db_open(NULL, lock_path("connections.tdb"), 0, - TDB_DEFAULT, O_RDONLY, 0); + TDB_CLEAR_IF_FIRST|TDB_DEFAULT, O_RDONLY, 0); } return db_ctx; -- cgit