X-Git-Url: https://git.exim.org/exim.git/blobdiff_plain/1950cf85b47f7c8407b3318a4f8fc57c0af6d6ba..1923663b12d44ff1bbf527a5b145a74fb5a751b7:/src/src/lookups/readsock.c diff --git a/src/src/lookups/readsock.c b/src/src/lookups/readsock.c index c2088b7a5..61f729618 100644 --- a/src/src/lookups/readsock.c +++ b/src/src/lookups/readsock.c @@ -3,6 +3,7 @@ *************************************************/ /* Copyright (c) Jeremy Harris 2020 */ +/* Copyright (c) The Exim Maintainers 2021 */ /* See the file NOTICE for conditions of use and distribution. */ #include "../exim.h" @@ -13,8 +14,6 @@ static int internal_readsock_open(client_conn_ctx * cctx, const uschar * sspec, int timeout, BOOL do_tls, uschar ** errmsg) { -int sep = ','; -uschar * ele; const uschar * server_name; host_item host; @@ -182,11 +181,12 @@ struct { } lf = {.do_shutdown = TRUE}; uschar * eol = NULL; int timeout = 5; -FILE * fp; gstring * yield; int ret = DEFER; -DEBUG(D_lookup) debug_printf_indent("readsock: file=\"%s\" key=\"%s\" len=%d opts=\"%s\"\n", filename, keystring, length, opts); +DEBUG(D_lookup) + debug_printf_indent("readsock: file=\"%s\" key=\"%s\" len=%d opts=\"%s\"\n", + filename, keystring, length, opts); /* Parse options */ @@ -200,7 +200,7 @@ if (opts) for (uschar * s; s = string_nextinlist(&opts, &sep, NULL, 0); ) lf.do_tls = TRUE; #endif else if (Ustrncmp(s, "eol=", 4) == 0) - eol = s + 4; + eol = string_unprinting(s + 4); else if (Ustrcmp(s, "cache=yes") == 0) lf.cache = TRUE; else if (Ustrcmp(s, "send=no") == 0) @@ -248,16 +248,28 @@ that reads a file can be used. If we're using a stdio buffered read, and might need later write ops on the socket, the stdio must be in writable mode or the underlying socket goes non-writable. */ -if (!cctx->tls_ctx) - fp = fdopen(cctx->sock, lf.do_shutdown ? "rb" : "wb"); - sigalrm_seen = FALSE; -ALARM(timeout); -yield = -#ifndef DISABLE_TLS - cctx->tls_ctx ? cat_file_tls(cctx->tls_ctx, NULL, eol) : +#ifdef DISABLE_TLS +if (TRUE) +#else +if (!cctx->tls_ctx) #endif - cat_file(fp, NULL, eol); + { + FILE * fp = fdopen(cctx->sock, "rb"); + if (!fp) + { + log_write(0, LOG_MAIN|LOG_PANIC, "readsock fdopen: %s\n", strerror(errno)); + goto out; + } + ALARM(timeout); + yield = cat_file(fp, NULL, eol); + } +else + { + ALARM(timeout); + yield = cat_file_tls(cctx->tls_ctx, NULL, eol); + } + ALARM_CLR(0); if (sigalrm_seen)