diff options
| author | manuel <manuel@mausz.at> | 2014-01-30 12:27:13 +0100 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2014-01-30 12:27:13 +0100 |
| commit | 10740bbfefe68763b4f0d74b25a074e95a2e13e3 (patch) | |
| tree | 658661065dcd43641e2b60bb9a59724c61dd989e | |
| parent | 0ee64f201ca34603c94f615497cc309317cc6361 (diff) | |
| download | qmail-10740bbfefe68763b4f0d74b25a074e95a2e13e3.tar.gz qmail-10740bbfefe68763b4f0d74b25a074e95a2e13e3.tar.bz2 qmail-10740bbfefe68763b4f0d74b25a074e95a2e13e3.zip | |
replace \r\n with \n in sendmail wrapper
| -rw-r--r-- | Makefile | 11 | ||||
| -rw-r--r-- | sendmail.c | 57 |
2 files changed, 60 insertions, 8 deletions
| @@ -1819,14 +1819,15 @@ compile trysysel.c select.h1 select.h2 | |||
| 1819 | rm -f trysysel.o trysysel | 1819 | rm -f trysysel.o trysysel |
| 1820 | 1820 | ||
| 1821 | sendmail: \ | 1821 | sendmail: \ |
| 1822 | load sendmail.o env.a getopt.a alloc.a substdio.a error.a str.a \ | 1822 | load sendmail.o env.a getopt.a alloc.a getln.a substdio.a error.a str.a \ |
| 1823 | auto_qmail.o | 1823 | auto_qmail.o stralloc.a wait.a fd.a sig.a |
| 1824 | ./load sendmail env.a getopt.a alloc.a substdio.a error.a \ | 1824 | ./load sendmail env.a getopt.a alloc.a getln.a substdio.a error.a \ |
| 1825 | str.a auto_qmail.o | 1825 | str.a auto_qmail.o stralloc.a wait.a fd.a sig.a |
| 1826 | 1826 | ||
| 1827 | sendmail.o: \ | 1827 | sendmail.o: \ |
| 1828 | compile sendmail.c sgetopt.h subgetopt.h substdio.h subfd.h \ | 1828 | compile sendmail.c sgetopt.h subgetopt.h substdio.h subfd.h \ |
| 1829 | substdio.h alloc.h auto_qmail.h exit.h env.h str.h | 1829 | substdio.h alloc.h auto_qmail.h exit.h env.h str.h stralloc.h \ |
| 1830 | getln.h readwrite.h wait.h fd.h sig.h | ||
| 1830 | ./compile sendmail.c | 1831 | ./compile sendmail.c |
| 1831 | 1832 | ||
| 1832 | setup: \ | 1833 | setup: \ |
| @@ -6,6 +6,12 @@ | |||
| 6 | #include "exit.h" | 6 | #include "exit.h" |
| 7 | #include "env.h" | 7 | #include "env.h" |
| 8 | #include "str.h" | 8 | #include "str.h" |
| 9 | #include "stralloc.h" | ||
| 10 | #include "getln.h" | ||
| 11 | #include "readwrite.h" | ||
| 12 | #include "wait.h" | ||
| 13 | #include "fd.h" | ||
| 14 | #include "sig.h" | ||
| 9 | 15 | ||
| 10 | void nomem() | 16 | void nomem() |
| 11 | { | 17 | { |
| @@ -158,7 +164,52 @@ char **argv; | |||
| 158 | for (i = 0;i < argc;++i) *arg++ = argv[i]; | 164 | for (i = 0;i < argc;++i) *arg++ = argv[i]; |
| 159 | *arg = 0; | 165 | *arg = 0; |
| 160 | 166 | ||
| 161 | execv(*qiargv,qiargv); | 167 | int child, pi[2]; |
| 162 | substdio_putsflush(subfderr,"sendmail: fatal: unable to run qmail-inject\n"); | 168 | if (pipe(pi) == -1) { |
| 163 | _exit(111); | 169 | substdio_putsflush(subfderr,"sendmail: fatal: unable to open pipe\n"); |
| 170 | _exit(100); | ||
| 171 | } | ||
| 172 | |||
| 173 | switch(child = fork()) { | ||
| 174 | case -1: | ||
| 175 | substdio_putsflush(subfderr,"sendmail: fatal: unable to fork\n"); | ||
| 176 | _exit(100); | ||
| 177 | case 0: | ||
| 178 | close(pi[1]); | ||
| 179 | if (fd_copy(0,pi[0]) == -1) { | ||
| 180 | substdio_putsflush(subfderr,"sendmail: fatal: unable to fork\n"); | ||
| 181 | _exit(100); | ||
| 182 | } | ||
| 183 | sig_pipedefault(); | ||
| 184 | execv(*qiargv,qiargv); | ||
| 185 | substdio_putsflush(subfderr,"sendmail: fatal: unable to run qmail-inject\n"); | ||
| 186 | _exit(111); | ||
| 187 | } | ||
| 188 | close(pi[0]); | ||
| 189 | |||
| 190 | char buf[256]; | ||
| 191 | static substdio ss; | ||
| 192 | int match; | ||
| 193 | static stralloc line = {0}; | ||
| 194 | substdio_fdbuf(&ss,write,pi[1],buf,sizeof buf); | ||
| 195 | for (;;) { | ||
| 196 | if (getln(subfdin,&line,&match,'\n') != 0) { | ||
| 197 | substdio_putsflush(subfderr,"sendmail: fatal: read error\n"); | ||
| 198 | _exit(111); | ||
| 199 | } | ||
| 200 | |||
| 201 | if (!match && !line.len) break; | ||
| 202 | |||
| 203 | if (match && line.len >= 2 && line.s[line.len - 2] == '\r') { | ||
| 204 | line.s[line.len - 2] = '\n'; | ||
| 205 | line.len--; | ||
| 206 | } | ||
| 207 | substdio_put(&ss, line.s, line.len); | ||
| 208 | } | ||
| 209 | substdio_flush(&ss); | ||
| 210 | close(pi[1]); | ||
| 211 | |||
| 212 | int wstat; | ||
| 213 | if (wait_pid(&wstat,child) == -1) _exit(111); | ||
| 214 | _exit(wait_exitcode(wstat)); | ||
| 164 | } | 215 | } |
