X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fsrc%2Fexim_dbutil.c;h=45bad208c48f2d7a432ddfa50783df599a5593e8;hb=8b4556856d2434c8006df5011d4855c07a7ba2b8;hp=4f3c4fadbcc0796a2c3f043ebddba19b2b8ff993;hpb=c5db348c5e29e93e51389fa0079f829967c5da82;p=user%2Fhenk%2Fcode%2Fexim.git diff --git a/src/src/exim_dbutil.c b/src/src/exim_dbutil.c index 4f3c4fadb..45bad208c 100644 --- a/src/src/exim_dbutil.c +++ b/src/src/exim_dbutil.c @@ -2,7 +2,7 @@ * Exim - an Internet mail transport agent * *************************************************/ -/* Copyright (c) University of Cambridge 1995 - 2017 */ +/* Copyright (c) University of Cambridge 1995 - 2018 */ /* See the file NOTICE for conditions of use and distribution. */ @@ -253,14 +253,20 @@ dbfn_open(uschar *name, int flags, open_db *dbblock, BOOL lof) int rc; struct flock lock_data; BOOL read_only = flags == O_RDONLY; -uschar dirname[256], filename[256]; +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. */ -snprintf(CS dirname, sizeof(dirname), "%s/db", spool_directory); -snprintf(CS filename, sizeof(filename), "%s/%.200s.lockfile", dirname, name); +#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) @@ -273,14 +279,14 @@ if (dbblock->lockfd < 0) /* Now we must get a lock on the opened lock file; do this with a blocking lock that times out. */ -lock_data.l_type = read_only? F_RDLCK : F_WRLCK; +lock_data.l_type = read_only ? F_RDLCK : F_WRLCK; lock_data.l_whence = lock_data.l_start = lock_data.l_len = 0; sigalrm_seen = FALSE; os_non_restarting_signal(SIGALRM, sigalrm_handler); -alarm(EXIMDB_LOCK_TIMEOUT); +ALARM(EXIMDB_LOCK_TIMEOUT); rc = fcntl(dbblock->lockfd, F_SETLKW, &lock_data); -alarm(0); +ALARM_CLR(0); if (sigalrm_seen) errno = ETIMEDOUT; if (rc < 0) @@ -296,10 +302,14 @@ if (rc < 0) /* 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. */ -sprintf(CS filename, "%s/%s", dirname, name); +#ifdef COMPILE_UTILITY +if (asprintf(CSS &filename, "%s/%s", dirname, name) < 0) return NULL; +#else +filename = string_sprintf("%s/%s", dirname, name); +#endif EXIM_DBOPEN(filename, dirname, flags, 0, &(dbblock->dbptr)); -if (dbblock->dbptr == NULL) +if (!dbblock->dbptr) { printf("** Failed to open DBM file %s for %s:\n %s%s\n", filename, read_only? "reading" : "writing", strerror(errno),