s/qmail  3.3.23
Next generation secure email transport
pathexec_env.c
Go to the documentation of this file.
1 #include "stralloc.h"
2 #include "alloc.h"
3 #include "str.h"
4 #include "byte.h"
5 #include "env.h"
6 #include "pathexec.h"
7 
8 static stralloc plus;
9 static stralloc tmp;
10 
11 int pathexec_env(char *s,char *t)
12 {
13  if (!s) return 1;
14  if (!stralloc_copys(&tmp,s)) return 0;
15  if (t) {
16  if (!stralloc_cats(&tmp,"=")) return 0;
17  if (!stralloc_cats(&tmp,t)) return 0;
18  }
19  if (!stralloc_0(&tmp)) return 0;
20  return stralloc_cat(&plus,&tmp);
21 }
22 
23 void pathexec(char **argv)
24 {
25  char *path;
26  char **e;
27  unsigned int elen;
28  unsigned int i;
29  unsigned int j;
30  unsigned int split;
31  unsigned int t;
32 
33  if (!stralloc_cats(&plus,"")) return;
34 
35  elen = 0;
36  for (i = 0;environ[i];++i)
37  ++elen;
38  for (i = 0;i < plus.len;++i)
39  if (!plus.s[i])
40  ++elen;
41 
42  e = (char **) alloc((elen + 1) * sizeof(char *));
43  if (!e) return;
44 
45  elen = 0;
46  for (i = 0;environ[i];++i)
47  e[elen++] = environ[i];
48 
49  j = 0;
50  for (i = 0;i < plus.len;++i)
51  if (!plus.s[i]) {
52  split = str_chr(plus.s + j,'=');
53  for (t = 0;t < elen;++t)
54  if (byte_equal(plus.s + j,split,e[t]))
55  if (e[t][split] == '=') {
56  --elen;
57  e[t] = e[elen];
58  break;
59  }
60  if (plus.s[j + split])
61  e[elen++] = plus.s + j;
62  j = i + 1;
63  }
64  e[elen] = 0;
65 
66  pathexec_run(*argv,argv,e);
67  alloc_free(e);
68 }
unsigned int str_chr(char *, int)
char * alloc(unsigned int n)
Definition: alloc.c:16
void pathexec_run(char *, char **, char **)
Definition: pathexec_run.c:9
int pathexec_env(char *s, char *t)
Definition: pathexec_env.c:11
#define stralloc_0(sa)
Definition: stralloc.h:19
char ** environ
char * s
Definition: token822.h:7
int stralloc_cat(stralloc *, stralloc *)
Definition: stralloc_cat.c:4
unsigned i
Definition: matchup.c:36
void split(void(*dofield)(), void(*doline)())
Definition: columnt.c:65
int j
Definition: qmail-send.c:916
void pathexec(char **argv)
Definition: pathexec_env.c:23
stralloc tmp
Definition: newinclude.c:31
int stralloc_copys(stralloc *, char *)
Definition: stralloc_opys.c:5
void alloc_free(char *x)
Definition: alloc.c:26
int stralloc_cats(stralloc *, char *)
Definition: stralloc_cats.c:5
#define byte_equal(s, n, t)
Definition: byte.h:11