X-Git-Url: https://git.exim.org/exim.git/blobdiff_plain/80fea873648ca2ab2e592999a336c59cf054ab55..5aba2a452669cc19defd5732e2512984ecd1603e:/src/src/transport.c diff --git a/src/src/transport.c b/src/src/transport.c index 8ac6f30a0..9737acc58 100644 --- a/src/src/transport.c +++ b/src/src/transport.c @@ -1027,8 +1027,9 @@ if (!(dkim_private_key && dkim_domain && dkim_selector)) check_string, escape_string, rewrite_rules, rewrite_existflags); -(void)string_format(dkim_spool_name, 256, "%s/input/%s/%s-%d-K", - spool_directory, message_subdir, message_id, (int)getpid()); +(void)string_format(dkim_spool_name, sizeof(dkim_spool_name), + "%s/input/%s/%s/%s-%d-K", + spool_directory, queue_name, message_subdir, message_id, (int)getpid()); if ((dkim_fd = Uopen(dkim_spool_name, O_RDWR|O_CREAT|O_TRUNC, SPOOL_MODE)) < 0) { @@ -1654,15 +1655,10 @@ open_db dbblock; open_db *dbm_file; uschar buffer[256]; -msgq_t *msgq = NULL; -int msgq_count = 0; -int msgq_actual = 0; int i; -BOOL bFound = FALSE; uschar spool_dir [PATH_MAX]; uschar spool_file [PATH_MAX]; struct stat statbuf; -BOOL bContinuation = FALSE; *more = FALSE; @@ -1692,8 +1688,7 @@ if (dbm_file == NULL) return FALSE; /* See if there is a record for this host; if not, there's nothing to do. */ -host_record = dbfn_read(dbm_file, hostname); -if (host_record == NULL) +if (!(host_record = dbfn_read(dbm_file, hostname))) { dbfn_close(dbm_file); DEBUG(D_transport) debug_printf("no messages waiting for %s\n", hostname); @@ -1726,6 +1721,12 @@ host_length = host_record->count * MESSAGE_ID_LENGTH; while (1) { + msgq_t *msgq; + int msgq_count = 0; + int msgq_actual = 0; + BOOL bFound = FALSE; + BOOL bContinuation = FALSE; + /* create an array to read entire message queue into memory for processing */ msgq = (msgq_t*) malloc(sizeof(msgq_t) * host_record->count); @@ -1752,15 +1753,14 @@ while (1) /* now find the next acceptable message_id */ - bFound = FALSE; - for (i = msgq_count - 1; i >= 0; --i) if (msgq[i].bKeep) { if (split_spool_directory) - sprintf(CS spool_file, "%s%c/%s-D", - spool_dir, msgq[i].message_id[5], msgq[i].message_id); + snprintf(CS spool_file, sizeof(spool_file), "%s/%s/%c/%s-D", + spool_dir, queue_name, msgq[i].message_id[5], msgq[i].message_id); else - sprintf(CS spool_file, "%s%s-D", spool_dir, msgq[i].message_id); + snprintf(CS spool_file, sizeof(spool_file), "%s/%s/%s-D", + spool_dir, queue_name, msgq[i].message_id); if (Ustat(spool_file, &statbuf) != 0) msgq[i].bKeep = FALSE; @@ -1779,8 +1779,7 @@ while (1) msgq_actual++; /* reassemble the host record, based on removed message ids, from in - * memory queue. - */ + memory queue */ if (msgq_actual <= 0) { @@ -1807,8 +1806,6 @@ while (1) /* Jeremy: check for a continuation record, this code I do not know how to test but the code should work */ - bContinuation = FALSE; - while (host_length <= 0) { int i; @@ -1839,8 +1836,11 @@ test but the code should work */ bContinuation = TRUE; } - if (bFound) + if (bFound) /* Usual exit from main loop */ + { + free (msgq); break; + } /* If host_length <= 0 we have emptied a record and not found a good message, and there are no continuation records. Otherwise there is a continuation @@ -1859,20 +1859,13 @@ test but the code should work */ if (!bContinuation) { - Ustrcpy (new_message_id, message_id); + Ustrcpy(new_message_id, message_id); dbfn_close(dbm_file); return FALSE; } - } /* we need to process a continuation record */ -/* clean up in memory queue */ -if (msgq) - { - free (msgq); - msgq = NULL; - msgq_count = 0; - msgq_actual = 0; - } + free(msgq); + } /* we need to process a continuation record */ /* Control gets here when an existing message has been encountered; its id is in new_message_id, and host_length is the revised length of the @@ -1881,19 +1874,8 @@ record if required, close the database, and return TRUE. */ if (host_length > 0) { - uschar msg [MESSAGE_ID_LENGTH + 1]; - int i; - host_record->count = host_length/MESSAGE_ID_LENGTH; - /* rebuild the host_record->text */ - - for (i = 0; i < host_record->count; ++i) - { - Ustrncpy(msg, host_record->text + (i*MESSAGE_ID_LENGTH), MESSAGE_ID_LENGTH); - msg[MESSAGE_ID_LENGTH] = 0; - } - dbfn_write(dbm_file, hostname, host_record, (int)sizeof(dbdata_wait) + host_length); *more = TRUE; } @@ -1947,7 +1929,12 @@ if ((pid = fork()) == 0) argv = CUSS child_exec_exim(CEE_RETURN_ARGV, TRUE, &i, FALSE, 0); - /* Call with the dsn flag */ + if (*queue_name) + { + argv[i++] = US"-MCG"; + argv[i++] = queue_name; + } + if (smtp_use_dsn) argv[i++] = US"-MCD"; if (smtp_authenticated) argv[i++] = US"-MCA";