1 /*************************************************
2 * Exim - an Internet mail transport agent *
3 *************************************************/
5 /* Copyright (c) The Exim Maintainers 2021 - 2024 */
6 /* Copyright (c) University of Cambridge 1995 - 2009 */
7 /* See the file NOTICE for conditions of use and distribution. */
8 /* SPDX-License-Identifier: GPL-2.0-or-later */
11 #include "rf_functions.h"
14 /*************************************************
15 * Get transport for a router *
16 *************************************************/
18 /* If transport_name contains $, it must be expanded each time and used as a
19 transport name. Otherwise, look up the transport only if the destination is not
22 Some routers (e.g. accept) insist that their transport option is set at
23 initialization time. However, for some (e.g. file_transport in redirect), there
24 is no such check, because the transport may not be required. Calls to this
25 function from the former type of router have require_name = NULL, because it
26 will never be used. NULL is also used in verify_only cases, where a transport
30 tpname the text of the transport name
31 tpptr where to put the transport
32 addr the address being processed
33 router_name for error messages
34 require_name used in the error message if transport is unset
36 Returns: TRUE if *tpptr is already set and tpname has no '$' in it;
37 TRUE if a transport has been placed in tpptr;
38 FALSE if there's a problem, in which case
39 addr->message contains a message, and addr->basic_errno has
40 ERRNO_BADTRANSPORT set in it.
44 rf_get_transport(uschar *tpname, transport_instance **tpptr, address_item *addr,
45 uschar *router_name, uschar *require_name)
50 GET_OPTION("transport");
53 if (!require_name) return TRUE;
54 addr->basic_errno = ERRNO_BADTRANSPORT;
55 addr->message = string_sprintf("%s unset in %s router", require_name,
60 expandable = Ustrchr(tpname, '$') != NULL;
61 if (*tpptr != NULL && !expandable) return TRUE;
65 if (!(ss = expand_string(tpname)))
67 addr->basic_errno = ERRNO_BADTRANSPORT;
68 addr->message = string_sprintf("failed to expand transport "
69 "\"%s\" in %s router: %s", tpname, router_name, expand_string_message);
74 log_write(0, LOG_MAIN|LOG_PANIC,
75 "attempt to use tainted value '%s' from '%s' for transport", ss, tpname);
76 addr->basic_errno = ERRNO_BADTRANSPORT;
77 /* Avoid leaking info to an attacker */
78 addr->message = US"internal configuration error";
85 for (transport_instance * tp = transports; tp; tp = tp->next)
86 if (Ustrcmp(tp->name, ss) == 0)
88 DEBUG(D_route) debug_printf("set transport %s\n", ss);
93 addr->basic_errno = ERRNO_BADTRANSPORT;
94 addr->message = string_sprintf("transport \"%s\" not found in %s router", ss,
99 /* End of rf_get_transport.c */