summaryrefslogtreecommitdiff
path: root/src/tls/s6tls_clean_and_exec.c
blob: 9432e3a375fb4636c3c0c6c8159059e73ddbf929 (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
/* ISC license. */

#include <stddef.h>

#include <skalibs/posixplz.h>
#include <skalibs/bytestr.h>
#include <skalibs/env.h>
#include <skalibs/exec.h>

#include "s6tls-internal.h"

void s6tls_clean_and_exec (char const *const *argv, uint32_t options, char const *modif, size_t modiflen)
{
  if (options & 1)
  {
    static char const *const toclean[] =
    {
      "CADIR=",
      "CAFILE=",
      "KEYFILE=",
      "CERTFILE=",
      "TLS_UID=",
      "TLS_GID=",
      "KEYFILE:",
      "CERTFILE:",
      0
    } ;
    char const *const *envp = (char const *const *)environ ;
    size_t m = 0 ;
    size_t n = env_len(envp) ;
    char const *newenvp[n + 1] ;
    for (; *envp ; envp++)
    {
      char const *const *var = toclean ;
      for (; *var ; var++)
        if (str_start(*envp, *var)) break ;
      if (!*var) newenvp[m++] = *envp ;
    }
    newenvp[m] = 0 ;
    xmexec_fm(argv, newenvp, m, modif, modiflen) ;
  }
  else xmexec_m(argv, modif, modiflen) ;
}