c41d19ebac552ac233738a07dcf6756075ed20f6
1 /*************************************************
2 * Exim - an Internet mail transport agent *
3 *************************************************/
5 /* Copyright (c) Heiko Schlittermann 2016
7 * See the file NOTICE for conditions of use and distribution.
13 extern char **environ
;
16 /* The cleanup_environment() function is used during the startup phase
17 of the Exim process, right after reading the configurations main
18 part, before any expansions take place. It retains the environment
19 variables we trust (via the keep_environment option) and allows to
20 set additional variables (via add_environment).
22 Returns: TRUE if successful
29 if (!keep_environment
|| *keep_environment
== '\0')
31 /* From: https://github.com/dovecot/core/blob/master/src/lib/env-util.c#L55
32 Try to clear the environment.
33 a) environ = NULL crashes on OS X.
34 b) *environ = NULL doesn't work on FreeBSD 7.0.
35 c) environ = emptyenv doesn't work on Haiku OS
36 d) environ = calloc() should work everywhere */
38 if (environ
) *environ
= NULL
;
41 else if (Ustrcmp(keep_environment
, "*") != 0)
44 if (environ
) for (p
= USS environ
; *p
; /* see below */)
46 /* It's considered broken if we do not find the '=', according to
47 Florian Weimer. For now we ignore such strings. unsetenv() would complain,
48 getenv() would complain. */
49 uschar
*eqp
= Ustrchr(*p
, '=');
53 uschar
*name
= string_copyn(*p
, eqp
- *p
);
54 if (OK
!= match_isinlist(name
, CUSS
&keep_environment
,
55 0, NULL
, NULL
, MCL_NOEXPAND
, FALSE
, NULL
))
56 if (unsetenv(CS name
) < 0) return FALSE
;
57 else p
= USS environ
; /* RESTART from the beginning */
67 const uschar
* envlist
= add_environment
;
68 while ((p
= string_nextinlist(&envlist
, &sep
, NULL
, 0)))