diff options
author | Stefan Metzmacher <metze@samba.org> | 2007-03-27 08:41:45 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 12:18:54 -0500 |
commit | 2aee3c26891e1fee94c26384231a54ec89789abd (patch) | |
tree | 9aef5502713941dd78e80cdc30674638fc74301a | |
parent | 8b63654c2e63448cc21505d7996e1a4805e391df (diff) | |
download | samba-2aee3c26891e1fee94c26384231a54ec89789abd.tar.gz samba-2aee3c26891e1fee94c26384231a54ec89789abd.tar.bz2 samba-2aee3c26891e1fee94c26384231a54ec89789abd.zip |
r21972: - add string_term_tdb_data() it creates a null-terminates tdb key from a string
(the current string_tdb_data() creates a non-terminates tdb key from a string!)
- pass TDB_DATA instead of const char *, size_t len to some functions
metze
(This used to be commit 815ef8acdc7f89d30f3fd1812b12bd0e2dc62473)
-rw-r--r-- | source3/lib/util_tdb.c | 55 |
1 files changed, 32 insertions, 23 deletions
diff --git a/source3/lib/util_tdb.c b/source3/lib/util_tdb.c index 9e911a653c..66ea929e81 100644 --- a/source3/lib/util_tdb.c +++ b/source3/lib/util_tdb.c @@ -56,6 +56,11 @@ TDB_DATA string_tdb_data(const char *string) return make_tdb_data(string, strlen(string)); } +TDB_DATA string_term_tdb_data(const char *string) +{ + return make_tdb_data(string, strlen(string) + 1); +} + /**************************************************************************** Lock a chain with timeout (in seconds). ****************************************************************************/ @@ -108,7 +113,7 @@ int tdb_chainlock_with_timeout( TDB_CONTEXT *tdb, TDB_DATA key, unsigned int tim int tdb_lock_bystring(TDB_CONTEXT *tdb, const char *keyval) { - TDB_DATA key = make_tdb_data(keyval, strlen(keyval)+1); + TDB_DATA key = string_term_tdb_data(keyval); return tdb_chainlock(tdb, key); } @@ -116,7 +121,7 @@ int tdb_lock_bystring(TDB_CONTEXT *tdb, const char *keyval) int tdb_lock_bystring_with_timeout(TDB_CONTEXT *tdb, const char *keyval, int timeout) { - TDB_DATA key = make_tdb_data(keyval, strlen(keyval)+1); + TDB_DATA key = string_term_tdb_data(keyval); return tdb_chainlock_with_timeout(tdb, key, timeout); } @@ -127,7 +132,7 @@ int tdb_lock_bystring_with_timeout(TDB_CONTEXT *tdb, const char *keyval, void tdb_unlock_bystring(TDB_CONTEXT *tdb, const char *keyval) { - TDB_DATA key = make_tdb_data(keyval, strlen(keyval)+1); + TDB_DATA key = string_term_tdb_data(keyval); tdb_chainunlock(tdb, key); } @@ -138,7 +143,7 @@ void tdb_unlock_bystring(TDB_CONTEXT *tdb, const char *keyval) int tdb_read_lock_bystring_with_timeout(TDB_CONTEXT *tdb, const char *keyval, unsigned int timeout) { - TDB_DATA key = make_tdb_data(keyval, strlen(keyval)+1); + TDB_DATA key = string_term_tdb_data(keyval); return tdb_chainlock_with_timeout_internal(tdb, key, timeout, F_RDLCK); } @@ -149,7 +154,7 @@ int tdb_read_lock_bystring_with_timeout(TDB_CONTEXT *tdb, const char *keyval, un void tdb_read_unlock_bystring(TDB_CONTEXT *tdb, const char *keyval) { - TDB_DATA key = make_tdb_data(keyval, strlen(keyval)+1); + TDB_DATA key = string_term_tdb_data(keyval); tdb_chainunlock_read(tdb, key); } @@ -160,9 +165,8 @@ void tdb_read_unlock_bystring(TDB_CONTEXT *tdb, const char *keyval) Output is int32 in native byte order. ****************************************************************************/ -int32 tdb_fetch_int32_byblob(TDB_CONTEXT *tdb, const char *keyval, size_t len) +int32 tdb_fetch_int32_byblob(TDB_CONTEXT *tdb, TDB_DATA key) { - TDB_DATA key = make_tdb_data(keyval, len); TDB_DATA data; int32 ret; @@ -184,7 +188,9 @@ int32 tdb_fetch_int32_byblob(TDB_CONTEXT *tdb, const char *keyval, size_t len) int32 tdb_fetch_int32(TDB_CONTEXT *tdb, const char *keystr) { - return tdb_fetch_int32_byblob(tdb, keystr, strlen(keystr) + 1); + TDB_DATA key = string_term_tdb_data(keystr); + + return tdb_fetch_int32_byblob(tdb, key); } /**************************************************************************** @@ -192,9 +198,8 @@ int32 tdb_fetch_int32(TDB_CONTEXT *tdb, const char *keystr) Input is int32 in native byte order. Output in tdb is in little-endian. ****************************************************************************/ -int tdb_store_int32_byblob(TDB_CONTEXT *tdb, const char *keystr, size_t len, int32 v) +int tdb_store_int32_byblob(TDB_CONTEXT *tdb, TDB_DATA key, int32 v) { - TDB_DATA key = make_tdb_data(keystr, len); TDB_DATA data; int32 v_store; @@ -212,7 +217,9 @@ int tdb_store_int32_byblob(TDB_CONTEXT *tdb, const char *keystr, size_t len, int int tdb_store_int32(TDB_CONTEXT *tdb, const char *keystr, int32 v) { - return tdb_store_int32_byblob(tdb, keystr, strlen(keystr) + 1, v); + TDB_DATA key = string_term_tdb_data(keystr); + + return tdb_store_int32_byblob(tdb, key, v); } /**************************************************************************** @@ -220,9 +227,8 @@ int tdb_store_int32(TDB_CONTEXT *tdb, const char *keystr, int32 v) Output is uint32 in native byte order. ****************************************************************************/ -BOOL tdb_fetch_uint32_byblob(TDB_CONTEXT *tdb, const char *keyval, size_t len, uint32 *value) +BOOL tdb_fetch_uint32_byblob(TDB_CONTEXT *tdb, TDB_DATA key, uint32 *value) { - TDB_DATA key = make_tdb_data(keyval, len); TDB_DATA data; data = tdb_fetch(tdb, key); @@ -243,7 +249,9 @@ BOOL tdb_fetch_uint32_byblob(TDB_CONTEXT *tdb, const char *keyval, size_t len, u BOOL tdb_fetch_uint32(TDB_CONTEXT *tdb, const char *keystr, uint32 *value) { - return tdb_fetch_uint32_byblob(tdb, keystr, strlen(keystr) + 1, value); + TDB_DATA key = string_term_tdb_data(keystr); + + return tdb_fetch_uint32_byblob(tdb, key, value); } /**************************************************************************** @@ -251,9 +259,8 @@ BOOL tdb_fetch_uint32(TDB_CONTEXT *tdb, const char *keystr, uint32 *value) Input is uint32 in native byte order. Output in tdb is in little-endian. ****************************************************************************/ -BOOL tdb_store_uint32_byblob(TDB_CONTEXT *tdb, const char *keystr, size_t len, uint32 value) +BOOL tdb_store_uint32_byblob(TDB_CONTEXT *tdb, TDB_DATA key, uint32 value) { - TDB_DATA key = make_tdb_data(keystr, len); TDB_DATA data; uint32 v_store; BOOL ret = True; @@ -275,7 +282,9 @@ BOOL tdb_store_uint32_byblob(TDB_CONTEXT *tdb, const char *keystr, size_t len, u BOOL tdb_store_uint32(TDB_CONTEXT *tdb, const char *keystr, uint32 value) { - return tdb_store_uint32_byblob(tdb, keystr, strlen(keystr) + 1, value); + TDB_DATA key = string_term_tdb_data(keystr); + + return tdb_store_uint32_byblob(tdb, key, value); } /**************************************************************************** Store a buffer by a null terminated string key. Return 0 on success, -1 @@ -284,15 +293,15 @@ BOOL tdb_store_uint32(TDB_CONTEXT *tdb, const char *keystr, uint32 value) int tdb_store_bystring(TDB_CONTEXT *tdb, const char *keystr, TDB_DATA data, int flags) { - TDB_DATA key = make_tdb_data(keystr, strlen(keystr)+1); - + TDB_DATA key = string_term_tdb_data(keystr); + return tdb_store(tdb, key, data, flags); } int tdb_trans_store_bystring(TDB_CONTEXT *tdb, const char *keystr, TDB_DATA data, int flags) { - TDB_DATA key = make_tdb_data(keystr, strlen(keystr)+1); + TDB_DATA key = string_term_tdb_data(keystr); return tdb_trans_store(tdb, key, data, flags); } @@ -304,7 +313,7 @@ int tdb_trans_store_bystring(TDB_CONTEXT *tdb, const char *keystr, TDB_DATA tdb_fetch_bystring(TDB_CONTEXT *tdb, const char *keystr) { - TDB_DATA key = make_tdb_data(keystr, strlen(keystr)+1); + TDB_DATA key = string_term_tdb_data(keystr); return tdb_fetch(tdb, key); } @@ -315,7 +324,7 @@ TDB_DATA tdb_fetch_bystring(TDB_CONTEXT *tdb, const char *keystr) int tdb_delete_bystring(TDB_CONTEXT *tdb, const char *keystr) { - TDB_DATA key = make_tdb_data(keystr, strlen(keystr)+1); + TDB_DATA key = string_term_tdb_data(keystr); return tdb_delete(tdb, key); } @@ -725,7 +734,7 @@ TDB_LIST_NODE *tdb_search_keys(TDB_CONTEXT *tdb, const char* pattern) for (key = tdb_firstkey(tdb); key.dptr; key = next) { /* duplicate key string to ensure null-termination */ - char *key_str = (char*) SMB_STRNDUP(key.dptr, key.dsize); + char *key_str = SMB_STRNDUP(key.dptr, key.dsize); if (!key_str) { DEBUG(0, ("tdb_search_keys: strndup() failed!\n")); smb_panic("strndup failed!\n"); |