File: sendmail.c

package info (click to toggle)
qmail 1.01-5
  • links: PTS
  • area: non-free
  • in suites: hamm
  • size: 2,188 kB
  • ctags: 1,711
  • sloc: ansic: 13,993; makefile: 1,914; perl: 448; sh: 377
file content (98 lines) | stat: -rw-r--r-- 2,283 bytes parent folder | download
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include "sgetopt.h"
#include "substdio.h"
#include "subfd.h"
#include "alloc.h"
#include "auto_qmail.h"
#include "exit.h"
#include "env.h"
#include "str.h"

void nomem()
{
 substdio_putsflush(subfderr,"sendmail: fatal: out of memory\n");
 _exit(111);
}

int flagh;
char *sender;

void main(argc,argv)
int argc;
char **argv;
{
 int opt;
 char **qiargv;
 char **arg;
 int i;

 if (chdir(auto_qmail) == -1)
  {
   substdio_putsflush(subfderr,"sendmail: fatal: unable to switch to qmail home directory\n");
   _exit(111);
  }

 flagh = 0;
 sender = 0;
 while ((opt = getopt(argc,argv,"vimte:f:p:o:B:F:EJx")) != opteof)
   switch(opt)
    {
     case 'B': break;
     case 't': flagh = 1; break;
     case 'f': sender = optarg; break;
     case 'F': if (!env_put2("MAILNAME",optarg)) nomem(); break;
     case 'p': break; /* could generate a Received line from optarg */
     case 'v': break;
     case 'i': break; /* what an absurd concept */
     case 'x': break; /* SVR4 stupidity */
     case 'm': break; /* twisted-paper-path blindness, incompetent design */
     case 'e': break; /* qmail has only one error mode */
     case 'o':
       switch(optarg[0])
	{
	 case 'd': break; /* qmail has only one delivery mode */
	 case 'e': break; /* see 'e' above */
	 case 'i': break; /* see 'i' above */
	 case 'm': break; /* see 'm' above */
	}
       break;
     case 'E': case 'J': /* Sony NEWS-OS */
       while (argv[optind][optpos]) ++optpos; /* skip optional argument */
       break;
     default:
       _exit(100);
    }
 argc -= optind;
 argv += optind;

 if (str_equal(optprogname,"mailq"))
  {
   substdio_putsflush(subfderr,"sendmail: fatal: please use qmail-qread instead\n");
   _exit(100);
  }

 if (str_equal(optprogname,"newaliases"))
  {
   substdio_putsflush(subfderr,"sendmail: fatal: please use the qmsmac newaliases instead\n");
   _exit(100);
  }

 qiargv = (char **) alloc((argc + 10) * sizeof(char *));
 if (!qiargv) nomem();

 arg = qiargv;
 *arg++ = "/usr/sbin/qmail-inject";
 *arg++ = (flagh ? "-H" : "-a");
 if (sender)
  {
   *arg++ = "-f";
   *arg++ = sender;
  }
 *arg++ = "--";
 for (i = 0;i < argc;++i) *arg++ = argv[i];
 *arg = 0;

 execv(*qiargv,qiargv);
 
 substdio_putsflush(subfderr,"sendmail: fatal: unable to run qmail-inject\n");
 _exit(111);
}