1 /* $Cambridge: exim/src/src/routers/rf_get_ugid.c,v 1.4 2007/01/08 10:50:20 ph10 Exp $ */
3 /*************************************************
4 * Exim - an Internet mail transport agent *
5 *************************************************/
7 /* Copyright (c) University of Cambridge 1995 - 2007 */
8 /* See the file NOTICE for conditions of use and distribution. */
11 #include "rf_functions.h"
14 /*************************************************
15 * Get uid/gid for a router *
16 *************************************************/
18 /* This function is called by routers to sort out the uid/gid values which are
19 passed with an address for use by local transports.
22 rblock the router block
23 addr the address being worked on
24 ugid pointer to a ugid block to fill in
26 Returns: TRUE if all goes well, else FALSE
30 rf_get_ugid(router_instance
*rblock
, address_item
*addr
, ugid_block
*ugid
)
32 struct passwd
*upw
= NULL
;
34 /* Initialize from fixed values */
36 ugid
->uid
= rblock
->uid
;
37 ugid
->gid
= rblock
->gid
;
38 ugid
->uid_set
= rblock
->uid_set
;
39 ugid
->gid_set
= rblock
->gid_set
;
40 ugid
->initgroups
= rblock
->initgroups
;
42 /* If there is no fixed uid set, see if there's a dynamic one that can
43 be expanded and possibly looked up. */
45 if (!ugid
->uid_set
&& rblock
->expand_uid
!= NULL
)
47 if (route_find_expanded_user(rblock
->expand_uid
, rblock
->name
, US
"router",
48 &upw
, &(ugid
->uid
), &(addr
->message
))) ugid
->uid_set
= TRUE
;
52 /* Likewise for the gid */
54 if (!ugid
->gid_set
&& rblock
->expand_gid
!= NULL
)
56 if (route_find_expanded_group(rblock
->expand_gid
, rblock
->name
, US
"router",
57 &(ugid
->gid
), &(addr
->message
))) ugid
->gid_set
= TRUE
;
61 /* If a uid is set, then a gid must also be available; use one from the passwd
62 lookup if it happened. */
64 if (ugid
->uid_set
&& !ugid
->gid_set
)
68 ugid
->gid
= upw
->pw_gid
;
73 addr
->message
= string_sprintf("user set without group for %s router",
82 /* End of rf_get_ugid.c */