}
db = db_open(NULL, state_path("group_mapping.tdb"), 0,
- TDB_DEFAULT, O_RDWR|O_CREAT, 0600);
+ TDB_DEFAULT, O_RDWR|O_CREAT, 0600,
+ DBWRAP_LOCK_ORDER_1);
if (db == NULL) {
DEBUG(0, ("Failed to open group mapping database: %s\n",
strerror(errno)));
open_flags = rw ? (O_RDWR|O_CREAT) : O_RDONLY;
db_ctx = db_open(NULL, lock_path("connections.tdb"), 0,
- TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH|TDB_DEFAULT, open_flags, 0644);
+ TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH|TDB_DEFAULT,
+ open_flags, 0644, DBWRAP_LOCK_ORDER_1);
return db_ctx;
}
struct db_context *db_open(TALLOC_CTX *mem_ctx,
const char *name,
int hash_size, int tdb_flags,
- int open_flags, mode_t mode)
+ int open_flags, mode_t mode,
+ enum dbwrap_lock_order lock_order)
{
struct db_context *result = NULL;
#ifdef CLUSTER_SUPPORT
- const char *sockname = lp_ctdbd_socket();
+ const char *sockname;
+#endif
+
+ if ((lock_order != DBWRAP_LOCK_ORDER_1) &&
+ (lock_order != DBWRAP_LOCK_ORDER_2)) {
+ /*
+ * Only allow 2 levels. ctdb gives us 3, and we will
+ * have the watchers database soon.
+ */
+ errno = EINVAL;
+ return NULL;
+ }
+
+#ifdef CLUSTER_SUPPORT
+ sockname = lp_ctdbd_socket();
if(!sockname || !*sockname) {
sockname = CTDB_PATH;
*/
bool db_is_local(const char *name);
+enum dbwrap_lock_order {
+ DBWRAP_LOCK_ORDER_1 = 1,
+ DBWRAP_LOCK_ORDER_2 = 2
+};
+
/**
* Convenience function that will determine whether to
* open a tdb database via the tdb backend or via the ctdb
struct db_context *db_open(TALLOC_CTX *mem_ctx,
const char *name,
int hash_size, int tdb_flags,
- int open_flags, mode_t mode);
+ int open_flags, mode_t mode,
+ enum dbwrap_lock_order lock_order);
#endif /* __DBWRAP_OPEN_H__ */
#ifndef __DBWRAP_PRIVATE_H__
#define __DBWRAP_PRIVATE_H__
+#include "dbwrap/dbwrap_open.h"
+
struct db_record {
TDB_DATA key, value;
NTSTATUS (*store)(struct db_record *rec, TDB_DATA data, int flag);
result->db = db_open(result, lock_path("g_lock.tdb"), 0,
TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH,
- O_RDWR|O_CREAT, 0600);
+ O_RDWR|O_CREAT, 0600,
+ DBWRAP_LOCK_ORDER_2);
if (result->db == NULL) {
DEBUG(1, ("g_lock_init: Could not open g_lock.tdb\n"));
TALLOC_FREE(result);
return db;
}
db = db_open(NULL, lock_path("serverid.tdb"), 0,
- TDB_DEFAULT|TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH, O_RDWR|O_CREAT, 0644);
+ TDB_DEFAULT|TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH,
+ O_RDWR|O_CREAT, 0644, DBWRAP_LOCK_ORDER_2);
return db;
}
session_db_ctx_ptr = db_open(NULL, lock_path("sessionid.tdb"), 0,
TDB_CLEAR_IF_FIRST|TDB_DEFAULT|TDB_INCOMPATIBLE_HASH,
- O_RDWR | O_CREAT, 0644);
+ O_RDWR | O_CREAT, 0644,
+ DBWRAP_LOCK_ORDER_1);
return session_db_ctx_ptr;
}
}
share_db = db_open(NULL, state_path("share_info.tdb"), 0,
- TDB_DEFAULT, O_RDWR|O_CREAT, 0600);
+ TDB_DEFAULT, O_RDWR|O_CREAT, 0600,
+ DBWRAP_LOCK_ORDER_1);
if (share_db == NULL) {
DEBUG(0,("Failed to open share info database %s (%s)\n",
state_path("share_info.tdb"), strerror(errno) ));
brlock_db = db_open(NULL, lock_path("brlock.tdb"),
lp_open_files_db_hash_size(), tdb_flags,
- read_only?O_RDONLY:(O_RDWR|O_CREAT), 0644 );
+ read_only?O_RDONLY:(O_RDWR|O_CREAT), 0644,
+ DBWRAP_LOCK_ORDER_2);
if (!brlock_db) {
DEBUG(0,("Failed to open byte range locking database %s\n",
lock_path("brlock.tdb")));
lock_db = db_open(NULL, lock_path("locking.tdb"),
lp_open_files_db_hash_size(),
TDB_DEFAULT|TDB_VOLATILE|TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH,
- read_only?O_RDONLY:O_RDWR|O_CREAT, 0644);
+ read_only?O_RDONLY:O_RDWR|O_CREAT, 0644,
+ DBWRAP_LOCK_ORDER_1);
if (!lock_db) {
DEBUG(0,("ERROR: Failed to initialise locking database\n"));
become_root();
mapping_db = db_open(NULL, dbname, 0, TDB_DEFAULT,
- O_RDONLY, 0600);
+ O_RDONLY, 0600,
+ DBWRAP_LOCK_ORDER_1);
unbecome_root();
if (mapping_db == NULL) {
}
become_root();
- acl_db = db_open(NULL, dbname, 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0600);
+ acl_db = db_open(NULL, dbname, 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0600,
+ DBWRAP_LOCK_ORDER_1);
unbecome_root();
if (acl_db == NULL) {
/* now we know dbname is not NULL */
become_root();
- db = db_open(NULL, dbname, 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0600);
+ db = db_open(NULL, dbname, 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0600,
+ DBWRAP_LOCK_ORDER_2);
unbecome_root();
if (db == NULL) {
}
db = db_open(NULL, state_path("account_policy.tdb"), 0, TDB_DEFAULT,
- O_RDWR, 0600);
+ O_RDWR, 0600, DBWRAP_LOCK_ORDER_1);
if (db == NULL) { /* the account policies files does not exist or open
* failed, try to create a new one */
db = db_open(NULL, state_path("account_policy.tdb"), 0,
- TDB_DEFAULT, O_RDWR|O_CREAT, 0600);
+ TDB_DEFAULT, O_RDWR|O_CREAT, 0600,
+ DBWRAP_LOCK_ORDER_1);
if (db == NULL) {
DEBUG(0,("Failed to open account policy database\n"));
return False;
* it to stay around after we return from here. */
tmp_db = db_open(NULL, tmp_fname, 0,
- TDB_DEFAULT, O_CREAT|O_RDWR, 0600);
+ TDB_DEFAULT, O_CREAT|O_RDWR, 0600,
+ DBWRAP_LOCK_ORDER_1);
if (tmp_db == NULL) {
DEBUG(0, ("tdbsam_convert_backup: Failed to create backup TDB passwd "
"[%s]\n", tmp_fname));
/* re-open the converted TDB */
orig_db = db_open(NULL, dbname, 0,
- TDB_DEFAULT, O_CREAT|O_RDWR, 0600);
+ TDB_DEFAULT, O_CREAT|O_RDWR, 0600,
+ DBWRAP_LOCK_ORDER_1);
if (orig_db == NULL) {
DEBUG(0, ("tdbsam_convert_backup: Failed to re-open "
"converted passdb TDB [%s]\n", dbname));
/* Try to open tdb passwd. Create a new one if necessary */
- db_sam = db_open(NULL, name, 0, TDB_DEFAULT, O_CREAT|O_RDWR, 0600);
+ db_sam = db_open(NULL, name, 0, TDB_DEFAULT, O_CREAT|O_RDWR, 0600,
+ DBWRAP_LOCK_ORDER_1);
if (db_sam == NULL) {
DEBUG(0, ("tdbsam_open: Failed to open/create TDB passwd "
"[%s]\n", name));
}
db_ctx = db_open(NULL, fname, 0,
- TDB_DEFAULT, O_RDWR|O_CREAT, 0600);
+ TDB_DEFAULT, O_RDWR|O_CREAT, 0600,
+ DBWRAP_LOCK_ORDER_1);
if (db_ctx == NULL) {
DEBUG(0,("Failed to open %s\n", fname));
}
db = db_open(NULL, PL_DB_NAME(), 0,
TDB_DEFAULT|TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH,
- O_RDWR|O_CREAT, 0644);
+ O_RDWR|O_CREAT, 0644, DBWRAP_LOCK_ORDER_1);
return db;
}
}
regdb = db_open(NULL, state_path("registry.tdb"), 0,
- REG_TDB_FLAGS, O_RDWR, 0600);
+ REG_TDB_FLAGS, O_RDWR, 0600,
+ DBWRAP_LOCK_ORDER_1);
if (!regdb) {
regdb = db_open(NULL, state_path("registry.tdb"), 0,
- REG_TDB_FLAGS, O_RDWR|O_CREAT, 0600);
+ REG_TDB_FLAGS, O_RDWR|O_CREAT, 0600,
+ DBWRAP_LOCK_ORDER_1);
if (!regdb) {
werr = ntstatus_to_werror(map_nt_error_from_unix(errno));
DEBUG(1,("regdb_init: Failed to open registry %s (%s)\n",
become_root();
regdb = db_open(NULL, state_path("registry.tdb"), 0,
- REG_TDB_FLAGS, O_RDWR, 0600);
+ REG_TDB_FLAGS, O_RDWR, 0600,
+ DBWRAP_LOCK_ORDER_1);
if ( !regdb ) {
result = ntstatus_to_werror( map_nt_error_from_unix( errno ) );
DEBUG(0,("regdb_open: Failed to open %s! (%s)\n",
notify->db_recursive = db_open(notify, lock_path("notify.tdb"),
0, TDB_SEQNUM|TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH,
- O_RDWR|O_CREAT, 0644);
+ O_RDWR|O_CREAT, 0644,
+ DBWRAP_LOCK_ORDER_2);
if (notify->db_recursive == NULL) {
talloc_free(notify);
return NULL;
notify->db_onelevel = db_open(notify, lock_path("notify_onelevel.tdb"),
0, TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH,
- O_RDWR|O_CREAT, 0644);
+ O_RDWR|O_CREAT, 0644,
+ DBWRAP_LOCK_ORDER_2);
if (notify->db_onelevel == NULL) {
talloc_free(notify);
return NULL;
TDB_DATA value;
db = db_open(talloc_tos(), "transtest.tdb", 0, TDB_DEFAULT,
- O_RDWR|O_CREAT, 0600);
+ O_RDWR|O_CREAT, 0600, DBWRAP_LOCK_ORDER_1);
if (db == NULL) {
printf("Could not open transtest.db\n");
return false;
goto done;
}
- db = db_open(mem_ctx, dbname, 0, TDB_DEFAULT, O_RDWR | O_CREAT, 0644);
+ db = db_open(mem_ctx, dbname, 0, TDB_DEFAULT, O_RDWR | O_CREAT, 0644,
+ DBWRAP_LOCK_ORDER_1);
if (db == NULL) {
d_fprintf(stderr, "ERROR: could not open dbname\n");
goto done;
tdb_flags |= TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH;
}
- db = db_open(mem_ctx, db_name, 0, tdb_flags, O_RDWR | O_CREAT, 0644);
+ db = db_open(mem_ctx, db_name, 0, tdb_flags, O_RDWR | O_CREAT, 0644,
+ DBWRAP_LOCK_ORDER_1);
if (db == NULL) {
d_fprintf(stderr, "failed to open db '%s': %s\n", db_name,
}
d_fprintf(stderr, _("dumping id mapping from %s\n"), dbfile);
- db = db_open(mem_ctx, dbfile, 0, TDB_DEFAULT, O_RDONLY, 0);
+ db = db_open(mem_ctx, dbfile, 0, TDB_DEFAULT, O_RDONLY, 0,
+ DBWRAP_LOCK_ORDER_1);
if (db == NULL) {
d_fprintf(stderr, _("Could not open idmap db (%s): %s\n"),
dbfile, strerror(errno));
input = stdin;
}
- db = db_open(mem_ctx, dbfile, 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0644);
+ db = db_open(mem_ctx, dbfile, 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0644,
+ DBWRAP_LOCK_ORDER_1);
if (db == NULL) {
d_fprintf(stderr, _("Could not open idmap db (%s): %s\n"),
dbfile, strerror(errno));
}
d_fprintf(stderr, _("deleting id mapping from %s\n"), dbfile);
- db = db_open(mem_ctx, dbfile, 0, TDB_DEFAULT, O_RDWR, 0);
+ db = db_open(mem_ctx, dbfile, 0, TDB_DEFAULT, O_RDWR, 0,
+ DBWRAP_LOCK_ORDER_1);
if (db == NULL) {
d_fprintf(stderr, _("Could not open idmap db (%s): %s\n"),
dbfile, strerror(errno));
}
if (!(db = db_open(mem_ctx, argv[0], 0, TDB_DEFAULT,
- O_RDWR|O_CREAT, 0600))) {
+ O_RDWR|O_CREAT, 0600,
+ DBWRAP_LOCK_ORDER_1))) {
d_fprintf(stderr, _("db_open failed: %s\n"), strerror(errno));
goto fail;
}
}
}
- ctx->db = db_open(ctx, name, 0, TDB_DEFAULT, oflags, 0);
+ ctx->db = db_open(ctx, name, 0, TDB_DEFAULT, oflags, 0,
+ DBWRAP_LOCK_ORDER_1);
if (ctx->db == NULL) {
d_fprintf(stderr,
_("Could not open idmap db (%s) for writing: %s\n"),
ctx->opt.wipe = true;
}
- ctx->odb = db_open(ctx, ctx->opt.output, 0, TDB_DEFAULT, oflags, 0644);
+ ctx->odb = db_open(ctx, ctx->opt.output, 0, TDB_DEFAULT, oflags, 0644,
+ DBWRAP_LOCK_ORDER_1);
if (ctx->odb == NULL) {
d_fprintf(stderr,
_("Could not open db (%s) for writing: %s\n"),
static bool check_ctx_open_input(struct check_ctx *ctx) {
- ctx->idb = db_open(ctx, ctx->fname, 0, TDB_DEFAULT, O_RDONLY, 0);
+ ctx->idb = db_open(ctx, ctx->fname, 0, TDB_DEFAULT, O_RDONLY, 0,
+ DBWRAP_LOCK_ORDER_1);
if (ctx->idb == NULL) {
d_fprintf(stderr,
_("Could not open db (%s) for reading: %s\n"),
int result;
struct db_context *db;
db = db_open(NULL, lock_path("locking.tdb"), 0,
- TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH, O_RDONLY, 0);
+ TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH, O_RDONLY, 0,
+ DBWRAP_LOCK_ORDER_1);
if (!db) {
d_printf("%s not initialised\n",
/* Open idmap repository */
autorid_db = db_open(NULL, state_path("autorid.tdb"), 0,
- TDB_DEFAULT, O_RDWR | O_CREAT, 0644);
+ TDB_DEFAULT, O_RDWR | O_CREAT, 0644,
+ DBWRAP_LOCK_ORDER_1);
if (!autorid_db) {
DEBUG(0, ("Unable to open idmap_autorid database '%s'\n",
DEBUG(10,("Opening tdbfile %s\n", tdbfile ));
/* Open idmap repository */
- db = db_open(mem_ctx, tdbfile, 0, TDB_DEFAULT, O_RDWR | O_CREAT, 0644);
+ db = db_open(mem_ctx, tdbfile, 0, TDB_DEFAULT, O_RDWR | O_CREAT, 0644,
+ DBWRAP_LOCK_ORDER_1);
if (!db) {
DEBUG(0, ("Unable to open idmap database\n"));
ret = NT_STATUS_UNSUCCESSFUL;
NT_STATUS_HAVE_NO_MEMORY(db_path);
/* Open idmap repository */
- ctx->db = db_open(ctx, db_path, 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0644);
+ ctx->db = db_open(ctx, db_path, 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0644,
+ DBWRAP_LOCK_ORDER_1);
TALLOC_FREE(db_path);
if (ctx->db == NULL) {