* Exim - an Internet mail transport agent *
*************************************************/
+/* Copyright (c) The Exim Maintainers 2020 - 2024 */
/* Copyright (c) University of Cambridge 1995 - 2018 */
-/* Copyright (c) The Exim Maintainers 2020 - 2021 */
/* See the file NOTICE for conditions of use and distribution. */
+/* SPDX-License-Identifier: GPL-2.0-or-later */
/* This single source file is used to compile three utility programs for
readconf_printtime(int t)
{ return NULL; }
gstring *
+string_catn(gstring * g, const uschar * s, int count)
+{ return NULL; }
+gstring *
string_vformat_trc(gstring * g, const uschar * func, unsigned line,
unsigned size_limit, unsigned flags, const char *format, va_list ap)
{ return NULL; }
*/
open_db *
-dbfn_open(uschar *name, int flags, open_db *dbblock, BOOL lof, BOOL panic)
+dbfn_open(const uschar * name, int flags, open_db * dbblock,
+ BOOL lof, BOOL panic)
{
int rc;
struct flock lock_data;
-BOOL read_only = flags == O_RDONLY;
+BOOL read_only = flags & O_RDONLY;
uschar * dirname, * filename;
/* 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. If there is a database, there should be a lock file in existence. */
-#ifdef COMPILE_UTILITY
if ( asprintf(CSS &dirname, "%s/db", spool_directory) < 0
|| asprintf(CSS &filename, "%s/%s.lockfile", dirname, name) < 0)
return NULL;
-#else
-dirname = string_sprintf("%s/db", spool_directory);
-filename = string_sprintf("%s/%s.lockfile", dirname, name);
-#endif
-dbblock->lockfd = Uopen(filename, flags, 0);
-if (dbblock->lockfd < 0)
+if ((dbblock->lockfd = Uopen(filename, O_RDWR|O_CREAT, 0)) < 0)
{
printf("** Failed to open database lock file %s: %s\n", filename,
strerror(errno));
if (rc < 0)
{
printf("** Failed to get %s lock for %s: %s",
- flags & O_WRONLY ? "write" : "read",
+ read_only ? "read" : "write",
filename,
errno == ETIMEDOUT ? "timed out" : strerror(errno));
(void)close(dbblock->lockfd);
/* At this point we have an opened and locked separate lock file, that is,
exclusive access to the database, so we can go ahead and open it. */
-#ifdef COMPILE_UTILITY
if (asprintf(CSS &filename, "%s/%s", dirname, name) < 0) return NULL;
-#else
-filename = string_sprintf("%s/%s", dirname, name);
-#endif
-dbblock->dbptr = exim_dbopen(filename, dirname, flags, 0);
-if (!dbblock->dbptr)
+if (flags & O_RDWR) flags |= O_CREAT;
+
+if (!(dbblock->dbptr = exim_dbopen(filename, dirname, flags, 0)))
{
printf("** Failed to open DBM file %s for %s:\n %s%s\n", filename,
read_only? "reading" : "writing", strerror(errno),
*/
void *
-dbfn_read_with_length(open_db *dbblock, const uschar *key, int *length)
+dbfn_read_with_length(open_db * dbblock, const uschar * key, int * length)
{
-void *yield;
+void * yield;
EXIM_DATUM key_datum, result_datum;
int klen = Ustrlen(key) + 1;
uschar * key_copy = store_get(klen, key);
+unsigned dlen;
memcpy(key_copy, key, klen);
/* Assume for now that anything stored could have been tainted. Properly
we should store the taint status along with the data. */
-yield = store_get(exim_datum_size_get(&result_datum), GET_TAINTED);
-memcpy(yield, exim_datum_data_get(&result_datum), exim_datum_size_get(&result_datum));
-if (length) *length = exim_datum_size_get(&result_datum);
+dlen = exim_datum_size_get(&result_datum);
+yield = store_get(dlen, GET_TAINTED);
+memcpy(yield, exim_datum_data_get(&result_datum), dlen);
+if (length) *length = dlen;
exim_datum_free(&result_datum); /* Some DBM libs require freeing */
return yield;
cursor a pointer to a pointer to a cursor anchor, for those dbm libraries
that use the notion of a cursor
-Returns: the next record from the file, or
+Returns: the next *key* (nul-terminated) from the file, or
NULL if there are no more
*/
print_time(retry->first_failed));
printf("%s ", print_time(retry->last_try));
printf("%s %s\n", print_time(retry->next_try),
- (retry->expired)? "*" : "");
+ retry->expired ? "*" : "");
break;
case type_wait:
#endif /* EXIM_TIDYDB */
/* End of exim_dbutil.c */
+/* vi: aw ai sw=2
+*/