+return TRUE;
+}
+
+/* Used for accessing Exim's hints databases.
+
+Arguments:
+ name The single-component name of one of Exim's database files.
+ flags Either O_RDONLY or O_RDWR, indicating the type of open required;
+ optionally O_CREAT
+ dbblock Points to an open_db block to be filled in.
+ lof If TRUE, write to the log for actual open failures (locking failures
+ are always logged).
+ panic If TRUE, panic on failure to create the db directory
+
+Returns: NULL if the open failed, or the locking failed. After locking
+ failures, errno is zero.
+
+ On success, dbblock is returned. This contains the dbm pointer and
+ the fd of the locked lock file.
+*/
+
+open_db *
+dbfn_open(const uschar * name, int flags, open_db * dbblock,
+ BOOL lof, BOOL panic)
+{
+int save_errno, dlen, flen;
+uschar dirname[PATHLEN], filename[PATHLEN];
+
+DEBUG(D_hints_lookup) acl_level++;
+
+/* The first thing to do is to open a separate file on which to lock. This
+ensures that Exim has exclusive use of the database before it even tries to
+open it. Early versions tried to lock on the open database itself, but that
+gave rise to mysterious problems from time to time - it was suspected that some
+DB libraries "do things" on their open() calls which break the interlocking.
+The lock file is never written to, but we open it for writing so we can get a
+write lock if required. If it does not exist, we create it. This is done
+separately so we know when we have done it, because when running as root we
+need to change the ownership - see the bottom of this function. We also try to
+make the directory as well, just in case. We won't be doing this many times
+unnecessarily, because usually the lock file will be there. If the directory
+exists, there is no error. */
+
+dlen = snprintf(CS dirname, sizeof(dirname), "%s/db", spool_directory);
+
+dbblock->readonly = (flags & O_ACCMODE) == O_RDONLY;
+dbblock->lockfd = -1;
+if (!exim_lockfile_needed())
+ db_dir_make(panic);
+else
+ {
+ flen = Ustrlen(name);
+ snprintf(CS filename, sizeof(filename), "%.*s/%.*s.lockfile",
+ (int)sizeof(filename) - dlen - flen - 11, dirname,
+ flen, name);
+ if (!lockfile_take(dbblock, filename, flags == O_RDONLY, panic))
+ {
+ DEBUG(D_hints_lookup) acl_level--;
+ return NULL;
+ }
+ }