mirror of
https://github.com/samba-team/samba.git
synced 2025-01-12 09:18:10 +03:00
Add dbwrap bystring service routines
This commit is contained in:
parent
aec5f15126
commit
1e214b536b
@ -50,5 +50,10 @@ struct db_context *db_open(TALLOC_CTX *mem_ctx,
|
||||
int hash_size, int tdb_flags,
|
||||
int open_flags, mode_t mode);
|
||||
|
||||
NTSTATUS dbwrap_delete_bystring(struct db_context *db, const char *key);
|
||||
NTSTATUS dbwrap_store_bystring(struct db_context *db, const char *key,
|
||||
TDB_DATA data, int flags);
|
||||
TDB_DATA dbwrap_fetch_bystring(struct db_context *db, TALLOC_CTX *mem_ctx,
|
||||
const char *key);
|
||||
|
||||
#endif /* __DBWRAP_H__ */
|
||||
|
@ -84,3 +84,45 @@ struct db_context *db_open(TALLOC_CTX *mem_ctx,
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
NTSTATUS dbwrap_delete_bystring(struct db_context *db, const char *key)
|
||||
{
|
||||
struct db_record *rec;
|
||||
NTSTATUS status;
|
||||
|
||||
rec = db->fetch_locked(db, talloc_tos(), string_term_tdb_data(key));
|
||||
if (rec == NULL) {
|
||||
return NT_STATUS_NO_MEMORY;
|
||||
}
|
||||
status = rec->delete_rec(rec);
|
||||
TALLOC_FREE(rec);
|
||||
return status;
|
||||
}
|
||||
|
||||
NTSTATUS dbwrap_store_bystring(struct db_context *db, const char *key,
|
||||
TDB_DATA data, int flags)
|
||||
{
|
||||
struct db_record *rec;
|
||||
NTSTATUS status;
|
||||
|
||||
rec = db->fetch_locked(db, talloc_tos(), string_term_tdb_data(key));
|
||||
if (rec == NULL) {
|
||||
return NT_STATUS_NO_MEMORY;
|
||||
}
|
||||
|
||||
status = rec->store(rec, data, flags);
|
||||
TALLOC_FREE(rec);
|
||||
return status;
|
||||
}
|
||||
|
||||
TDB_DATA dbwrap_fetch_bystring(struct db_context *db, TALLOC_CTX *mem_ctx,
|
||||
const char *key)
|
||||
{
|
||||
TDB_DATA result;
|
||||
|
||||
if (db->fetch(db, mem_ctx, string_term_tdb_data(key), &result) == -1) {
|
||||
return make_tdb_data(NULL, 0);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user