summaryrefslogtreecommitdiffstats
path: root/src/routers/rf_get_ugid.c
blob: 1735e59192c95d240a43818aae0ac19b53089633 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*************************************************
*     Exim - an Internet mail transport agent    *
*************************************************/

/* Copyright (c) University of Cambridge 1995 - 2009 */
/* See the file NOTICE for conditions of use and distribution. */

#include "../exim.h"
#include "rf_functions.h"


/*************************************************
*            Get uid/gid for a router            *
*************************************************/

/* This function is called by routers to sort out the uid/gid values which are
passed with an address for use by local transports.

Arguments:
  rblock       the router block
  addr         the address being worked on
  ugid         pointer to a ugid block to fill in

Returns:       TRUE if all goes well, else FALSE
*/

BOOL
rf_get_ugid(router_instance *rblock, address_item *addr, ugid_block *ugid)
{
struct passwd *upw = NULL;

/* Initialize from fixed values */

ugid->uid = rblock->uid;
ugid->gid = rblock->gid;
ugid->uid_set = rblock->uid_set;
ugid->gid_set = rblock->gid_set;
ugid->initgroups = rblock->initgroups;

/* If there is no fixed uid set, see if there's a dynamic one that can
be expanded and possibly looked up. */

if (!ugid->uid_set && rblock->expand_uid != NULL)
  {
  if (route_find_expanded_user(rblock->expand_uid, rblock->name, US"router",
    &upw, &(ugid->uid), &(addr->message))) ugid->uid_set = TRUE;
  else return FALSE;
  }

/* Likewise for the gid */

if (!ugid->gid_set && rblock->expand_gid != NULL)
  {
  if (route_find_expanded_group(rblock->expand_gid, rblock->name, US"router",
    &(ugid->gid), &(addr->message))) ugid->gid_set = TRUE;
  else return FALSE;
  }

/* If a uid is set, then a gid must also be available; use one from the passwd
lookup if it happened. */

if (ugid->uid_set && !ugid->gid_set)
  {
  if (upw != NULL)
    {
    ugid->gid = upw->pw_gid;
    ugid->gid_set = TRUE;
    }
  else
    {
    addr->message = string_sprintf("user set without group for %s router",
      rblock->name);
    return FALSE;
    }
  }

return TRUE;
}

/* End of rf_get_ugid.c */