SPDX: license tags (mostly by guesswork)
[exim.git] / src / src / routers / rf_queue_add.c
1 /*************************************************
2 *     Exim - an Internet mail transport agent    *
3 *************************************************/
4
5 /* Copyright (c) University of Cambridge 1995 - 2018 */
6 /* Copyright (c) The Exim Maintainers 2021 */
7 /* See the file NOTICE for conditions of use and distribution. */
8 /* SPDX-License-Identifier: GPL-2.0-only */
9
10 #include "../exim.h"
11 #include "rf_functions.h"
12
13
14 /*************************************************
15 *        Queue address for transport             *
16 *************************************************/
17
18 /* This function is called to put an address onto the local or remote transport
19 queue, as appropriate. When the driver is for verifying only, a transport need
20 not be set, in which case it doesn't actually matter which queue the address
21 gets put on.
22
23 The generic uid/gid options are inspected and put into the address if they are
24 set. For a remote transport, if there are fallback hosts, they are added to the
25 address.
26
27 Arguments:
28   addr          the address, with the transport field set (if not verify only)
29   paddr_local   pointer to the anchor of the local transport chain
30   paddr_remote  pointer to the anchor of the remote transport chain
31   rblock        the router block
32   pw            password entry if check_local_user was set, or NULL
33
34 Returns:        FALSE on error; the only case is failing to get a uid/gid
35 */
36
37 BOOL
38 rf_queue_add(address_item *addr, address_item **paddr_local,
39   address_item **paddr_remote, router_instance *rblock, struct passwd *pw)
40 {
41 addr->prop.domain_data = deliver_domain_data;         /* Save these values for */
42 addr->prop.localpart_data = deliver_localpart_data;   /* use in the transport */
43
44 /* Handle a local transport */
45
46 if (addr->transport && addr->transport->info->local)
47   {
48   ugid_block ugid;
49
50   /* Default uid/gid and transport-time home directory are from the passwd file
51   when check_local_user is set, but can be overridden by explicit settings.
52   When getting the home directory out of the password information, set the
53   flag that prevents expansion later. */
54
55   if (pw)
56     {
57     addr->uid = pw->pw_uid;
58     addr->gid = pw->pw_gid;
59     setflag(addr, af_uid_set);
60     setflag(addr, af_gid_set);
61     setflag(addr, af_home_expanded);
62     addr->home_dir = string_copy(US pw->pw_dir);
63     }
64
65   if (!rf_get_ugid(rblock, addr, &ugid)) return FALSE;
66   rf_set_ugid(addr, &ugid);
67
68   /* transport_home_directory (in rblock->home_directory) takes priority;
69   otherwise use the expanded value of router_home_directory. The flag also
70   tells the transport not to re-expand it. */
71
72   if (rblock->home_directory)
73     {
74     addr->home_dir = rblock->home_directory;
75     clearflag(addr, af_home_expanded);
76     }
77   else if (!addr->home_dir && testflag(addr, af_home_expanded))
78     addr->home_dir = deliver_home;
79
80   addr->current_dir = rblock->current_directory;
81
82   addr->next = *paddr_local;
83   *paddr_local = addr;
84   }
85
86 /* For a remote transport, set up the fallback host list, and keep a count of
87 the total number of addresses routed to remote transports. */
88
89 else
90   {
91   addr->fallback_hosts = rblock->fallback_hostlist;
92   addr->next = *paddr_remote;
93   *paddr_remote = addr;
94   remote_delivery_count++;
95   }
96
97 DEBUG(D_route)
98   {
99   debug_printf("queued for %s transport: local_part = %s\ndomain = %s\n"
100     "  errors_to=%s\n",
101     addr->transport ? addr->transport->name : US"<unset>",
102     addr->local_part, addr->domain, addr->prop.errors_address);
103   debug_printf("  domain_data=%s local_part_data=%s\n", addr->prop.domain_data,
104     addr->prop.localpart_data);
105   }
106
107 return TRUE;
108 }
109
110 /* End of rf_queue_add.c */