Merge branch 'debian'
[hcoop/debian/exim4.git] / src / routers / rf_get_ugid.c
CommitLineData
420a0d19
CE
1/*************************************************
2* Exim - an Internet mail transport agent *
3*************************************************/
4
5/* Copyright (c) University of Cambridge 1995 - 2009 */
6/* See the file NOTICE for conditions of use and distribution. */
7
8#include "../exim.h"
9#include "rf_functions.h"
10
11
12/*************************************************
13* Get uid/gid for a router *
14*************************************************/
15
16/* This function is called by routers to sort out the uid/gid values which are
17passed with an address for use by local transports.
18
19Arguments:
20 rblock the router block
21 addr the address being worked on
22 ugid pointer to a ugid block to fill in
23
24Returns: TRUE if all goes well, else FALSE
25*/
26
27BOOL
28rf_get_ugid(router_instance *rblock, address_item *addr, ugid_block *ugid)
29{
30struct passwd *upw = NULL;
31
32/* Initialize from fixed values */
33
34ugid->uid = rblock->uid;
35ugid->gid = rblock->gid;
36ugid->uid_set = rblock->uid_set;
37ugid->gid_set = rblock->gid_set;
38ugid->initgroups = rblock->initgroups;
39
40/* If there is no fixed uid set, see if there's a dynamic one that can
41be expanded and possibly looked up. */
42
43if (!ugid->uid_set && rblock->expand_uid != NULL)
44 {
45 if (route_find_expanded_user(rblock->expand_uid, rblock->name, US"router",
46 &upw, &(ugid->uid), &(addr->message))) ugid->uid_set = TRUE;
47 else return FALSE;
48 }
49
50/* Likewise for the gid */
51
52if (!ugid->gid_set && rblock->expand_gid != NULL)
53 {
54 if (route_find_expanded_group(rblock->expand_gid, rblock->name, US"router",
55 &(ugid->gid), &(addr->message))) ugid->gid_set = TRUE;
56 else return FALSE;
57 }
58
59/* If a uid is set, then a gid must also be available; use one from the passwd
60lookup if it happened. */
61
62if (ugid->uid_set && !ugid->gid_set)
63 {
64 if (upw != NULL)
65 {
66 ugid->gid = upw->pw_gid;
67 ugid->gid_set = TRUE;
68 }
69 else
70 {
71 addr->message = string_sprintf("user set without group for %s router",
72 rblock->name);
73 return FALSE;
74 }
75 }
76
77return TRUE;
78}
79
80/* End of rf_get_ugid.c */