* Exim - an Internet mail transport agent *
*************************************************/
-/* Copyright (c) University of Cambridge 1995 - 2016 */
+/* Copyright (c) University of Cambridge 1995 - 2017 */
/* See the file NOTICE for conditions of use and distribution. */
int rc;
struct flock lock_data;
BOOL read_only = flags == O_RDONLY;
-uschar buffer[256];
+uschar dirname[256], filename[256];
/* 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. */
-sprintf(CS buffer, "%s/db/%.200s.lockfile", spool_directory, name);
+snprintf(CS dirname, sizeof(dirname), "%s/db", spool_directory);
+snprintf(CS filename, sizeof(filename), "%s/%.200s.lockfile", dirname, name);
-dbblock->lockfd = Uopen(buffer, flags, 0);
+dbblock->lockfd = Uopen(filename, flags, 0);
if (dbblock->lockfd < 0)
{
- printf("** Failed to open database lock file %s: %s\n", buffer,
+ printf("** Failed to open database lock file %s: %s\n", filename,
strerror(errno));
return NULL;
}
{
printf("** Failed to get %s lock for %s: %s",
flags & O_WRONLY ? "write" : "read",
- buffer,
+ filename,
errno == ETIMEDOUT ? "timed out" : strerror(errno));
(void)close(dbblock->lockfd);
return NULL;
/* 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 buffer, "%s/db/%s", spool_directory, name);
-EXIM_DBOPEN(buffer, flags, 0, &(dbblock->dbptr));
+sprintf(CS filename, "%s/%s", dirname, name);
+EXIM_DBOPEN(filename, dirname, flags, 0, &(dbblock->dbptr));
if (dbblock->dbptr == NULL)
{
- printf("** Failed to open DBM file %s for %s:\n %s%s\n", buffer,
+ printf("** Failed to open DBM file %s for %s:\n %s%s\n", filename,
read_only? "reading" : "writing", strerror(errno),
#ifdef USE_DB
" (or Berkeley DB error while opening)"
dbdata_type = check_args(argc, argv, US"dumpdb", US"");
spool_directory = argv[1];
-dbm = dbfn_open(argv[2], O_RDONLY, &dbblock, FALSE);
-if (dbm == NULL) exit(1);
+if (!(dbm = dbfn_open(argv[2], O_RDONLY, &dbblock, FALSE)))
+ exit(1);
/* Scan the file, formatting the information for each entry. Note
that data is returned in a malloc'ed block, in order that it be
correctly aligned. */
-key = dbfn_scan(dbm, TRUE, &cursor);
-while (key != NULL)
+for (key = dbfn_scan(dbm, TRUE, &cursor);
+ key;
+ key = dbfn_scan(dbm, FALSE, &cursor))
{
dbdata_retry *retry;
dbdata_wait *wait;
return 1;
}
Ustrcpy(keybuffer, key);
- value = dbfn_read_with_length(dbm, keybuffer, &length);
- if (value == NULL)
+ if (!(value = dbfn_read_with_length(dbm, keybuffer, &length)))
fprintf(stderr, "**** Entry \"%s\" was in the key scan, but the record "
"was not found in the file - something is wrong!\n",
CS keybuffer);
}
store_reset(value);
}
- key = dbfn_scan(dbm, FALSE, &cursor);
}
dbfn_close(dbm);
{
int verify = 1;
spool_directory = argv[1];
- dbm = dbfn_open(argv[2], O_RDWR, &dbblock, FALSE);
- if (dbm == NULL) continue;
+
+ if (!(dbm = dbfn_open(argv[2], O_RDWR, &dbblock, FALSE)))
+ continue;
if (Ustrcmp(field, "d") == 0)
{
/* Handle a read request, or verify after an update. */
spool_directory = argv[1];
- dbm = dbfn_open(argv[2], O_RDONLY, &dbblock, FALSE);
- if (dbm == NULL) continue;
+ if (!(dbm = dbfn_open(argv[2], O_RDONLY, &dbblock, FALSE)))
+ continue;
- record = dbfn_read_with_length(dbm, name, &oldlength);
- if (record == NULL)
+ if (!(record = dbfn_read_with_length(dbm, name, &oldlength)))
{
printf("record %s not found\n", name);
name[0] = 0;
printf("Tidying Exim hints database %s/db/%s\n", argv[1], argv[2]);
spool_directory = argv[1];
-dbm = dbfn_open(argv[2], O_RDWR, &dbblock, FALSE);
-if (dbm == NULL) exit(1);
+if (!(dbm = dbfn_open(argv[2], O_RDWR, &dbblock, FALSE)))
+ exit(1);
/* Prepare for building file names */
Therefore, we scan and build a list of all the keys. Then we use that to
read the records and possibly update them. */
-key = dbfn_scan(dbm, TRUE, &cursor);
-while (key != NULL)
+for (key = dbfn_scan(dbm, TRUE, &cursor);
+ key;
+ key = dbfn_scan(dbm, FALSE, &cursor))
{
key_item *k = store_get(sizeof(key_item) + Ustrlen(key));
k->next = keychain;
keychain = k;
Ustrcpy(k->key, key);
- key = dbfn_scan(dbm, FALSE, &cursor);
}
/* Now scan the collected keys and operate on the records, resetting
reset_point = store_get(0);
-while (keychain != NULL)
+while (keychain)
{
dbdata_generic *value;