summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2012-06-22 09:44:41 +0930
committerRusty Russell <rusty@rustcorp.com.au>2012-06-22 07:35:17 +0200
commit88ad365caf7811772b754bc00e5ca3d0b92812ea (patch)
tree09954fc6ceea3ed7049cc0a162bcb24942d8aa1e
parent8113d53bb421217040a8184ba00f61308e8959d6 (diff)
downloadsamba-88ad365caf7811772b754bc00e5ca3d0b92812ea.tar.gz
samba-88ad365caf7811772b754bc00e5ca3d0b92812ea.tar.bz2
samba-88ad365caf7811772b754bc00e5ca3d0b92812ea.zip
util: util_ntdb.c gains bystring functions.
Very similar to the util_tdb versions, but these return the error. I've only implemented those functions actually used. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
-rw-r--r--lib/util/util_ntdb.c41
-rw-r--r--lib/util/util_ntdb.h45
2 files changed, 85 insertions, 1 deletions
diff --git a/lib/util/util_ntdb.c b/lib/util/util_ntdb.c
index 10d60c2b84..f0fc158651 100644
--- a/lib/util/util_ntdb.c
+++ b/lib/util/util_ntdb.c
@@ -195,3 +195,44 @@ struct ntdb_context *ntdb_new(TALLOC_CTX *ctx,
return talloc_steal(ctx, ntdb);
}
+
+enum NTDB_ERROR ntdb_lock_bystring(struct ntdb_context *ntdb,
+ const char *keyval)
+{
+ NTDB_DATA key = string_term_ntdb_data(keyval);
+
+ return ntdb_chainlock(ntdb, key);
+}
+
+void ntdb_unlock_bystring(struct ntdb_context *ntdb, const char *keyval)
+{
+ NTDB_DATA key = string_term_ntdb_data(keyval);
+
+ ntdb_chainunlock(ntdb, key);
+}
+
+enum NTDB_ERROR ntdb_delete_bystring(struct ntdb_context *ntdb,
+ const char *keystr)
+{
+ NTDB_DATA key = string_term_ntdb_data(keystr);
+
+ return ntdb_delete(ntdb, key);
+}
+
+enum NTDB_ERROR ntdb_store_bystring(struct ntdb_context *ntdb,
+ const char *keystr,
+ NTDB_DATA data, int nflags)
+{
+ NTDB_DATA key = string_term_ntdb_data(keystr);
+
+ return ntdb_store(ntdb, key, data, nflags);
+}
+
+enum NTDB_ERROR ntdb_fetch_bystring(struct ntdb_context *ntdb,
+ const char *keystr,
+ NTDB_DATA *data)
+{
+ NTDB_DATA key = string_term_ntdb_data(keystr);
+
+ return ntdb_fetch(ntdb, key, data);
+}
diff --git a/lib/util/util_ntdb.h b/lib/util/util_ntdb.h
index d65d8b6f7b..41531791e1 100644
--- a/lib/util/util_ntdb.h
+++ b/lib/util/util_ntdb.h
@@ -27,7 +27,6 @@
struct loadparm_context;
union ntdb_attribute;
-
/* You only need this on databases with NTDB_CLEAR_IF_FIRST */
int ntdb_reopen(struct ntdb_context *ntdb);
@@ -59,4 +58,48 @@ struct ntdb_context *ntdb_new(TALLOC_CTX *ctx,
int open_flags, mode_t mode,
union ntdb_attribute *attr,
struct loadparm_context *lp_ctx);
+
+/****************************************************************************
+ Lock a chain by string.
+****************************************************************************/
+enum NTDB_ERROR ntdb_lock_bystring(struct ntdb_context *ntdb,
+ const char *keyval);
+
+/****************************************************************************
+ Unlock a chain by string.
+****************************************************************************/
+void ntdb_unlock_bystring(struct ntdb_context *ntdb, const char *keyval);
+
+/****************************************************************************
+ Delete an entry using a null terminated string key.
+****************************************************************************/
+enum NTDB_ERROR ntdb_delete_bystring(struct ntdb_context *ntdb,
+ const char *keystr);
+
+/****************************************************************************
+ Store a buffer by a null terminated string key. Return 0 on success, -ve
+ on failure.
+****************************************************************************/
+enum NTDB_ERROR ntdb_store_bystring(struct ntdb_context *ntdb,
+ const char *keystr,
+ NTDB_DATA data, int nflags);
+
+/****************************************************************************
+ Fetch a buffer using a null terminated string key. Don't forget to call
+ free() on the result dptr (unless the ntdb is from ntdb_new, in which case
+ it will be a child of ntdb).
+****************************************************************************/
+enum NTDB_ERROR ntdb_fetch_bystring(struct ntdb_context *ntdb,
+ const char *keystr,
+ NTDB_DATA *data);
+
+
+/****************************************************************************
+ Turn a nul-terminated string into an NTDB_DATA.
+****************************************************************************/
+static inline NTDB_DATA string_term_ntdb_data(const char *string)
+{
+ return ntdb_mkdata(string, string ? strlen(string) + 1 : 0);
+}
+
#endif /* _____LIB_UTIL_UTIL_NTDB_H__ */