summaryrefslogtreecommitdiff
path: root/source4/lib
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2004-05-14 12:09:21 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:53:45 -0500
commita2273116fbb5890680c11fecba1bfd0026b7dd9b (patch)
tree6eae6f6e6b6996dce1dcfce2826fc126f34384aa /source4/lib
parenta07f42b4ffee81e62ea7f586241c97fd5e55a819 (diff)
downloadsamba-a2273116fbb5890680c11fecba1bfd0026b7dd9b.tar.gz
samba-a2273116fbb5890680c11fecba1bfd0026b7dd9b.tar.bz2
samba-a2273116fbb5890680c11fecba1bfd0026b7dd9b.zip
r728: - let libldb_tdb depend on new subsystem LIBTDB
- remove tdb logging helper functions out of LIBTDB subsystem - build libtdb shared lib with 'make library_libtdb' the libs are not usable for now, tridge: please remove the dependecy of CatchSignal() and smb_panic() from libtdb maybe use function pointers in the TDB_CONTEXT then run make library_libtdb and then make build/tests/trivial.o and then gcc -o trivial -L./bin -ltdb and then gcc -o trivial -L./bin -lldb metze (This used to be commit 520b9762161d9b5d5223b42910494af80fd5c1e3)
Diffstat (limited to 'source4/lib')
-rw-r--r--source4/lib/basic.m46
-rw-r--r--source4/lib/ldb/config.mk2
-rw-r--r--source4/lib/tdb/config.m49
-rw-r--r--source4/lib/tdb/config.mk23
-rw-r--r--source4/lib/tdb/tdb.h2
-rw-r--r--source4/lib/tdb/tdbutil.c93
-rw-r--r--source4/lib/tdb_helper.c67
7 files changed, 140 insertions, 62 deletions
diff --git a/source4/lib/basic.m4 b/source4/lib/basic.m4
index ac5f82440e..b575bad9b8 100644
--- a/source4/lib/basic.m4
+++ b/source4/lib/basic.m4
@@ -21,6 +21,6 @@ SMB_SUBSYSTEM(LIBBASIC,[lib/version.o],
lib/gencache.o lib/module.o lib/mutex.o
lib/ldap_escape.o lib/events.o
lib/crypto/crc32.o lib/crypto/md5.o
- lib/crypto/hmacmd5.o lib/crypto/md4.o
- lib/tdb/tdb.o lib/tdb/spinlock.o lib/tdb/tdbutil.o],[],
- [CHARSET])
+ lib/crypto/hmacmd5.o lib/crypto/md4.o
+ lib/tdb_helper.o],[],
+ [LIBTDB CHARSET])
diff --git a/source4/lib/ldb/config.mk b/source4/lib/ldb/config.mk
index 09d4d421fb..677c31ac28 100644
--- a/source4/lib/ldb/config.mk
+++ b/source4/lib/ldb/config.mk
@@ -19,6 +19,8 @@ ADD_OBJ_FILES = \
lib/ldb/ldb_tdb/ldb_index.o \
lib/ldb/ldb_tdb/ldb_match.o \
lib/ldb/ldb_tdb/ldb_cache.o
+REQUIRED_SUBSYSTEMS = \
+ LIBTDB
# End MODULE libldb_tdb
################################################
diff --git a/source4/lib/tdb/config.m4 b/source4/lib/tdb/config.m4
new file mode 100644
index 0000000000..12d88ed6a8
--- /dev/null
+++ b/source4/lib/tdb/config.m4
@@ -0,0 +1,9 @@
+
+SMB_SUBSYSTEM_MK(LIBTDB,lib/tdb/config.mk)
+
+if test x"$experimental" = x"yes"; then
+ SMB_LIBRARY_ENABLE(libtdb,YES)
+fi
+
+SMB_LIBRARY_MK(libtdb,lib/tdb/config.mk)
+
diff --git a/source4/lib/tdb/config.mk b/source4/lib/tdb/config.mk
new file mode 100644
index 0000000000..797c793ce3
--- /dev/null
+++ b/source4/lib/tdb/config.mk
@@ -0,0 +1,23 @@
+################################################
+# Start SUBSYSTEM LIBTDB
+[SUBSYSTEM::LIBTDB]
+INIT_OBJ_FILES = \
+ lib/tdb/tdb.o
+ADD_OBJ_FILES = \
+ lib/tdb/tdbutil.o \
+ lib/tdb/spinlock.o
+#
+# End SUBSYSTEM LIBLDB
+################################################
+
+################################################
+# Start LIBRARY LIBTDB
+[LIBRARY::libtdb]
+MAJOR_VERSION = 0
+MINOR_VERSION = 0
+RELEASE_VERSION = 1
+REQUIRED_SUBSYSTEMS = \
+ LIBTDB
+#
+# End LIBRARY LIBLDB
+################################################
diff --git a/source4/lib/tdb/tdb.h b/source4/lib/tdb/tdb.h
index 281925068c..73a0ea8f83 100644
--- a/source4/lib/tdb/tdb.h
+++ b/source4/lib/tdb/tdb.h
@@ -105,6 +105,8 @@ typedef struct tdb_context {
int open_flags; /* flags used in the open - needed by reopen */
} TDB_CONTEXT;
+void tdb_debug(TDB_CONTEXT *, int , const char *, ...);
+
typedef int (*tdb_traverse_func)(TDB_CONTEXT *, TDB_DATA, TDB_DATA, void *);
typedef void (*tdb_log_func)(TDB_CONTEXT *, int , const char *, ...);
diff --git a/source4/lib/tdb/tdbutil.c b/source4/lib/tdb/tdbutil.c
index 4a4423d2ce..9a0e8b0c44 100644
--- a/source4/lib/tdb/tdbutil.c
+++ b/source4/lib/tdb/tdbutil.c
@@ -51,7 +51,7 @@ static TDB_DATA make_tdb_data(const char *dptr, size_t dsize)
Lock a chain with timeout (in seconds).
****************************************************************************/
-static int tdb_chainlock_with_timeout_internal( TDB_CONTEXT *tdb, TDB_DATA key, unsigned int timeout, int rw_type)
+static int tdb_chainlock_with_timeout_internal(TDB_CONTEXT *tdb, TDB_DATA key, unsigned int timeout, int rw_type)
{
/* Allow tdb_chainlock to be interrupted by an alarm. */
int ret;
@@ -72,8 +72,8 @@ static int tdb_chainlock_with_timeout_internal( TDB_CONTEXT *tdb, TDB_DATA key,
alarm(0);
CatchSignal(SIGALRM, SIGNAL_CAST SIG_IGN);
if (gotalarm) {
- DEBUG(0,("tdb_chainlock_with_timeout_internal: alarm (%u) timed out for key %s in tdb %s\n",
- timeout, key.dptr, tdb->name ));
+ tdb_debug(tdb, 0, "tdb_chainlock_with_timeout_internal: alarm (%u) timed out for key %s in tdb %s\n",
+ timeout, key.dptr, tdb->name );
/* TODO: If we time out waiting for a lock, it might
* be nice to use F_GETLK to get the pid of the
* process currently holding the lock and print that
@@ -89,7 +89,7 @@ static int tdb_chainlock_with_timeout_internal( TDB_CONTEXT *tdb, TDB_DATA key,
Write lock a chain. Return -1 if timeout or lock failed.
****************************************************************************/
-int tdb_chainlock_with_timeout( TDB_CONTEXT *tdb, TDB_DATA key, unsigned int timeout)
+int tdb_chainlock_with_timeout(TDB_CONTEXT *tdb, TDB_DATA key, unsigned int timeout)
{
return tdb_chainlock_with_timeout_internal(tdb, key, timeout, F_WRLCK);
}
@@ -384,7 +384,7 @@ BOOL tdb_change_uint32_atomic(TDB_CONTEXT *tdb, const char *keystr, uint32 *oldv
integers and strings.
****************************************************************************/
-size_t tdb_pack(char *buf, int bufsize, const char *fmt, ...)
+size_t tdb_pack(TDB_CONTEXT *tdb, char *buf, int bufsize, const char *fmt, ...)
{
va_list ap;
uint8 bt;
@@ -452,8 +452,8 @@ size_t tdb_pack(char *buf, int bufsize, const char *fmt, ...)
}
break;
default:
- DEBUG(0,("Unknown tdb_pack format %c in %s\n",
- c, fmt));
+ tdb_debug(tdb, 0,"Unknown tdb_pack format %c in %s\n",
+ c, fmt);
len = 0;
break;
}
@@ -467,8 +467,8 @@ size_t tdb_pack(char *buf, int bufsize, const char *fmt, ...)
va_end(ap);
- DEBUG(18,("tdb_pack(%s, %d) -> %d\n",
- fmt0, bufsize0, (int)PTR_DIFF(buf, buf0)));
+ tdb_debug(tdb, 18,"tdb_pack(%s, %d) -> %d\n",
+ fmt0, bufsize0, (int)PTR_DIFF(buf, buf0));
return PTR_DIFF(buf, buf0);
}
@@ -478,7 +478,7 @@ size_t tdb_pack(char *buf, int bufsize, const char *fmt, ...)
integers and strings.
****************************************************************************/
-int tdb_unpack(char *buf, int bufsize, const char *fmt, ...)
+int tdb_unpack(TDB_CONTEXT *tdb, char *buf, int bufsize, const char *fmt, ...)
{
va_list ap;
uint8 *bt;
@@ -559,8 +559,8 @@ int tdb_unpack(char *buf, int bufsize, const char *fmt, ...)
memcpy(*b, buf+4, *i);
break;
default:
- DEBUG(0,("Unknown tdb_unpack format %c in %s\n",
- c, fmt));
+ tdb_debug(tdb, 0, "Unknown tdb_unpack format %c in %s\n",
+ c, fmt);
len = 0;
break;
@@ -572,8 +572,8 @@ int tdb_unpack(char *buf, int bufsize, const char *fmt, ...)
va_end(ap);
- DEBUG(18,("tdb_unpack(%s, %d) -> %d\n",
- fmt0, bufsize0, (int)PTR_DIFF(buf, buf0)));
+ tdb_debug(tdb, 18, "tdb_unpack(%s, %d) -> %d\n",
+ fmt0, bufsize0, (int)PTR_DIFF(buf, buf0));
return PTR_DIFF(buf, buf0);
@@ -591,22 +591,22 @@ int tdb_unpack(char *buf, int bufsize, const char *fmt, ...)
*
* @return length of the packed representation of the whole structure
**/
-size_t tdb_sid_pack(char* pack_buf, int bufsize, DOM_SID* sid)
+size_t tdb_sid_pack(TDB_CONTEXT *tdb, char* pack_buf, int bufsize, DOM_SID* sid)
{
int idx;
size_t len = 0;
if (!sid || !pack_buf) return -1;
- len += tdb_pack(pack_buf + len, bufsize - len, "bb", sid->sid_rev_num,
+ len += tdb_pack(tdb, pack_buf + len, bufsize - len, "bb", sid->sid_rev_num,
sid->num_auths);
for (idx = 0; idx < 6; idx++) {
- len += tdb_pack(pack_buf + len, bufsize - len, "b", sid->id_auth[idx]);
+ len += tdb_pack(tdb, pack_buf + len, bufsize - len, "b", sid->id_auth[idx]);
}
for (idx = 0; idx < MAXSUBAUTHS; idx++) {
- len += tdb_pack(pack_buf + len, bufsize - len, "d", sid->sub_auths[idx]);
+ len += tdb_pack(tdb, pack_buf + len, bufsize - len, "d", sid->sub_auths[idx]);
}
return len;
@@ -622,65 +622,40 @@ size_t tdb_sid_pack(char* pack_buf, int bufsize, DOM_SID* sid)
*
* @return size of structure unpacked from buffer
**/
-size_t tdb_sid_unpack(char* pack_buf, int bufsize, DOM_SID* sid)
+size_t tdb_sid_unpack(TDB_CONTEXT *tdb, char* pack_buf, int bufsize, DOM_SID* sid)
{
int idx, len = 0;
if (!sid || !pack_buf) return -1;
- len += tdb_unpack(pack_buf + len, bufsize - len, "bb",
+ len += tdb_unpack(tdb, pack_buf + len, bufsize - len, "bb",
&sid->sid_rev_num, &sid->num_auths);
for (idx = 0; idx < 6; idx++) {
- len += tdb_unpack(pack_buf + len, bufsize - len, "b", &sid->id_auth[idx]);
+ len += tdb_unpack(tdb, pack_buf + len, bufsize - len, "b", &sid->id_auth[idx]);
}
for (idx = 0; idx < MAXSUBAUTHS; idx++) {
- len += tdb_unpack(pack_buf + len, bufsize - len, "d", &sid->sub_auths[idx]);
+ len += tdb_unpack(tdb, pack_buf + len, bufsize - len, "d", &sid->sub_auths[idx]);
}
return len;
}
+
/****************************************************************************
- Log tdb messages via DEBUG().
+ Print out debug messages.
****************************************************************************/
-static void tdb_log(TDB_CONTEXT *tdb, int level, const char *format, ...)
+void tdb_debug(TDB_CONTEXT *tdb, int level, const char *fmt, ...)
{
va_list ap;
- char *ptr = NULL;
-
- va_start(ap, format);
- vasprintf(&ptr, format, ap);
- va_end(ap);
-
- if (!ptr || !*ptr)
+ if (tdb->log_fn == NULL) {
return;
-
- DEBUG(level, ("tdb(%s): %s", tdb->name ? tdb->name : "unnamed", ptr));
- SAFE_FREE(ptr);
-}
-
-/****************************************************************************
- Like tdb_open() but also setup a logging function that redirects to
- the samba DEBUG() system.
-****************************************************************************/
-
-TDB_CONTEXT *tdb_open_log(const char *name, int hash_size, int tdb_flags,
- int open_flags, mode_t mode)
-{
- TDB_CONTEXT *tdb;
-
- if (!lp_use_mmap())
- tdb_flags |= TDB_NOMMAP;
-
- tdb = tdb_open_ex(name, hash_size, tdb_flags,
- open_flags, mode, tdb_log);
- if (!tdb)
- return NULL;
-
- return tdb;
+ }
+ va_start(ap, fmt);
+ tdb->log_fn(tdb, level, fmt, ap);
+ va_end(ap);
}
@@ -715,11 +690,11 @@ TDB_LIST_NODE *tdb_search_keys(TDB_CONTEXT *tdb, const char* pattern)
/* duplicate key string to ensure null-termination */
char *key_str = (char*) strndup(key.dptr, key.dsize);
if (!key_str) {
- DEBUG(0, ("tdb_search_keys: strndup() failed!\n"));
+ tdb_debug(tdb, 0, "tdb_search_keys: strndup() failed!\n");
smb_panic("strndup failed!\n");
}
-
- DEBUG(18, ("checking %s for match to pattern %s\n", key_str, pattern));
+
+ tdb_debug(tdb, 18, "checking %s for match to pattern %s\n", key_str, pattern);
next = tdb_nextkey(tdb, key);
@@ -732,7 +707,7 @@ TDB_LIST_NODE *tdb_search_keys(TDB_CONTEXT *tdb, const char* pattern)
DLIST_ADD_END(list, rec, TDB_LIST_NODE *);
- DEBUG(18, ("checking %s matched pattern %s\n", key_str, pattern));
+ tdb_debug(tdb, 18, "checking %s matched pattern %s\n", key_str, pattern);
} else {
free(key.dptr);
}
diff --git a/source4/lib/tdb_helper.c b/source4/lib/tdb_helper.c
new file mode 100644
index 0000000000..121243bd0f
--- /dev/null
+++ b/source4/lib/tdb_helper.c
@@ -0,0 +1,67 @@
+/*
+ Unix SMB/CIFS implementation.
+ tdb utility functions
+ Copyright (C) Andrew Tridgell 1992-1998
+
+ 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"
+#include <fnmatch.h>
+
+/* these are little tdb utility functions that are meant to make
+ dealing with a tdb database a little less cumbersome in Samba */
+
+
+/****************************************************************************
+ Log tdb messages via DEBUG().
+****************************************************************************/
+
+static void tdb_log(TDB_CONTEXT *tdb, int level, const char *format, ...)
+{
+ va_list ap;
+ char *ptr = NULL;
+
+ va_start(ap, format);
+ vasprintf(&ptr, format, ap);
+ va_end(ap);
+
+ if (!ptr || !*ptr)
+ return;
+
+ DEBUG(level, ("tdb(%s): %s", tdb->name ? tdb->name : "unnamed", ptr));
+ SAFE_FREE(ptr);
+}
+
+/****************************************************************************
+ Like tdb_open() but also setup a logging function that redirects to
+ the samba DEBUG() system.
+****************************************************************************/
+
+TDB_CONTEXT *tdb_open_log(const char *name, int hash_size, int tdb_flags,
+ int open_flags, mode_t mode)
+{
+ TDB_CONTEXT *tdb;
+
+ if (!lp_use_mmap())
+ tdb_flags |= TDB_NOMMAP;
+
+ tdb = tdb_open_ex(name, hash_size, tdb_flags,
+ open_flags, mode, tdb_log);
+ if (!tdb)
+ return NULL;
+
+ return tdb;
+}