From 068e0e2b38fb109eb1d1306c6d74bfa86ec0c4b8 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Sat, 23 Mar 2013 17:27:57 +1030 Subject: ntdb: don't call open hook when re-opening an existing database. In particular, the Samba dbwrap wrapper can do this for schannel_store, with the openhook set to clear the database if it can get the lock (which, being in the same process, it can). Signed-off-by: Rusty Russell Autobuild-User(master): Rusty Russell Autobuild-Date(master): Sat Mar 23 09:39:50 CET 2013 on sn-devel-104 --- lib/ntdb/open.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'lib/ntdb/open.c') diff --git a/lib/ntdb/open.c b/lib/ntdb/open.c index abec117236..2a265afe7d 100644 --- a/lib/ntdb/open.c +++ b/lib/ntdb/open.c @@ -679,6 +679,17 @@ _PUBLIC_ struct ntdb_context *ntdb_open(const char *name, int ntdb_flags, ntdb->file->device = st.st_dev; ntdb->file->inode = st.st_ino; + + /* call their open hook if they gave us one. */ + if (ntdb->openhook) { + ecode = ntdb->openhook(ntdb->file->fd, ntdb->openhook_data); + if (ecode != NTDB_SUCCESS) { + ntdb_logerr(ntdb, ecode, NTDB_LOG_ERROR, + "ntdb_open: open hook failed"); + goto fail; + } + open_flags |= O_CREAT; + } } else { /* ensure there is only one process initialising at once */ ecode = ntdb_lock_open(ntdb, openlock, @@ -689,17 +700,6 @@ _PUBLIC_ struct ntdb_context *ntdb_open(const char *name, int ntdb_flags, } } - /* call their open hook if they gave us one. */ - if (ntdb->openhook) { - ecode = ntdb->openhook(ntdb->file->fd, ntdb->openhook_data); - if (ecode != NTDB_SUCCESS) { - ntdb_logerr(ntdb, ecode, NTDB_LOG_ERROR, - "ntdb_open: open hook failed"); - goto fail; - } - open_flags |= O_CREAT; - } - /* If they used O_TRUNC, read will return 0. */ rlen = pread(ntdb->file->fd, &hdr, sizeof(hdr), 0); if (rlen == 0 && (open_flags & O_CREAT)) { -- cgit