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