ucspi-ssl  0.99e
TLS encryption for IPv6 communication
pathexec_env.c
Go to the documentation of this file.
1 /* Public domain. */
2 
3 #include "stralloc.h"
4 #include "alloc.h"
5 #include "str.h"
6 #include "byte.h"
7 #include "env.h"
8 #include "pathexec.h"
9 
10 static stralloc plus;
11 static stralloc tmp;
12 
13 int pathexec_env(const char *s,const char *t)
14 {
15  if (!s) return 1;
16  if (!stralloc_copys(&tmp,s)) return 0;
17  if (t) {
18  if (!stralloc_cats(&tmp,"=")) return 0;
19  if (!stralloc_cats(&tmp,t)) return 0;
20  }
21  if (!stralloc_0(&tmp)) return 0;
22  return stralloc_cat(&plus,&tmp);
23 }
24 
25 int pathexec_multienv(stralloc *sa)
26 {
27  if (!sa) return 1;
28  return stralloc_cat(&plus,sa);
29 }
30 
31 void pathexec(char * const *argv)
32 {
33  char **e;
34  unsigned int elen;
35  unsigned int i;
36  unsigned int j;
37  unsigned int split;
38  unsigned int t;
39 
40  if (!stralloc_cats(&plus,"")) return;
41 
42  elen = 0;
43  for (i = 0;environ[i];++i)
44  ++elen;
45  for (i = 0;i < plus.len;++i)
46  if (!plus.s[i])
47  ++elen;
48 
49  e = (char **) alloc((elen + 1) * sizeof(char *));
50  if (!e) return;
51 
52  elen = 0;
53  for (i = 0;environ[i];++i)
54  e[elen++] = environ[i];
55 
56  j = 0;
57  for (i = 0;i < plus.len;++i)
58  if (!plus.s[i]) {
59  split = str_chr(plus.s + j,'=');
60  for (t = 0;t < elen;++t)
61  if (byte_equal(plus.s + j,split,e[t]))
62  if (e[t][split] == '=') {
63  --elen;
64  e[t] = e[elen];
65  break;
66  }
67  if (plus.s[j + split])
68  e[elen++] = plus.s + j;
69  j = i + 1;
70  }
71  e[elen] = 0;
72 
73  pathexec_run(*argv,argv,e);
74  alloc_free((char *)e);
75 }
char * alloc(unsigned int n)
Definition: alloc.c:15
void pathexec(char *const *argv)
Definition: pathexec_env.c:31
int stralloc_cats(stralloc *, const char *)
Definition: stralloc_cats.c:7
int pathexec_env(const char *s, const char *t)
Definition: pathexec_env.c:13
void pathexec_run(const char *, char *const *, char *const *)
Definition: pathexec_run.c:12
#define stralloc_0(sa)
Definition: stralloc.h:21
char ** environ
unsigned int str_chr(const char *, int)
char ** e
Definition: sslhandle.c:127
int stralloc_cat(stralloc *, const stralloc *)
Definition: stralloc_cat.c:6
void alloc_free(char *x)
Definition: alloc.c:25
int stralloc_copys(stralloc *, const char *)
Definition: stralloc_opys.c:7
#define byte_equal(s, n, t)
Definition: byte.h:13
int pathexec_multienv(stralloc *sa)
Definition: pathexec_env.c:25