void smtpd() { if (!env_get("PROTO")) { if (!env_put("RELAYCLIENT=")) nomem(); if (!env_put("DATABYTES=0")) nomem(); if (!env_put("PROTO=TCP")) nomem(); if (!env_put("TCPLOCALIP=127.0.0.1")) nomem(); if (!env_put("TCPLOCALHOST=localhost")) nomem(); if (!env_put("TCPREMOTEIP=127.0.0.1")) nomem(); if (!env_put("TCPREMOTEHOST=localhost")) nomem(); if (!env_put("TCPREMOTEINFO=sendmail-bs")) nomem(); } execv(*smtpdarg,(char **)smtpdarg); substdio_putsflush(subfderr,"sendmail: fatal: unable to run qmail-smtpd\n"); _exit(111); }
static void execute(const char *fn,const char *def) /* Load and execute a qmail command file. */ { stralloc file = {0,0,0}; int code; if (def != 0) env_put2("DEFAULT",def); else env_unset("DEFAULT"); if (slurp(fn,&file,256) != 1) strerr_die6sys(111,FATAL,ERR_READ_INPUT,basedir.s,"/",fn,": "); code = execute_file(fn,&file); substdio_puts(subfderr,"did 0+"); substdio_put(subfderr,strnum,fmt_ulong(strnum,did_forward)); substdio_puts(subfderr,"+"); substdio_put(subfderr,strnum,fmt_ulong(strnum,did_program)); substdio_putsflush(subfderr,"\n"); _exit(code); }
static void forward(const char *rcpt) { char buf[4096]; const char *dtline; const char *err; int r; if (qmail_open(&qq,0) == -1) strerr_die2sys(111,FATAL,MSG(ERR_QMAIL_QUEUE)); if ((dtline = env_get("DTLINE")) != 0) qmail_puts(&qq,dtline); while ((r = read(0,buf,sizeof buf)) > 0) qmail_put(&qq,buf,r); if (r == -1) strerr_die2sys(111,FATAL,MSG(ERR_READ_STDIN)); qmail_from(&qq,sender); qmail_to(&qq,rcpt); if (*(err = qmail_close(&qq)) != '\0') strerr_die4x(111,FATAL,MSG(ERR_TMP_QMAIL_QUEUE),": ",err + 1); strnum[fmt_ulong(strnum,qmail_qp(&qq))] = 0; substdio_puts(subfderr,"qp "); substdio_puts(subfderr,strnum); substdio_putsflush(subfderr,"\n"); ++did_forward; }
void die_reada() { substdio_putsflush(subfderr,"qmail-newu: fatal: unable to read users/assign\n"); die_temp(); }
void die_nomem() { substdio_putsflush(subfderr,"qmail-newu: fatal: out of memory\n"); die_temp(); }
void die_chdir() { substdio_putsflush(subfderr,"qmail-newu: fatal: unable to chdir\n"); die_temp(); }
void main(int argc,char **argv) { char *dir; char *sender; char *moddir; const char *queryext = (char *) 0; int opt; int ret = 0; int dontact = 0; unsigned int i,j; const char *program; stralloc *opts; umask(022); sig_pipeignore(); /* storeopts to ezmlm-store only. Others to both (ezmlm-store may */ /* pass them on to ezmlm-send. */ if (!stralloc_copys(&sendopt,"-")) die_nomem(); if (!stralloc_copys(&storeopt,"-")) die_nomem(); while ((opt = getopt(argc,argv, "0cCmMpPq:Q:sSrRt:T:vVyY")) != opteof) switch(opt) { /* pass on unrecognized options */ case 'c': /* ezmlm-send flags */ case 'C': case 'r': case 'Q': case 'R': szchar[0] = opt; if (!stralloc_append(&sendopt,szchar)) die_nomem(); if (!stralloc_append(&storeopt,szchar)) die_nomem(); break; case 'm': /* ezmlm-store flags */ case 'M': case 'p': case 'P': case 's': case 'S': case 'y': case 'Y': szchar[0] = opt; if (!stralloc_append(&storeopt,szchar)) die_nomem(); break; case 'q': if (optarg) queryext = optarg; break; case 'v': case 'V': strerr_die2x(0,"ezmlm-gate version: ",auto_version); case '0': dontact = 1; break; default: /* ezmlm-store flags */ die_usage(); } startup(dir = argv[optind++]); sender = env_get("SENDER"); pmod = (char *) 0; if (queryext) { getconf(&cmds,queryext,1,dir); i = 0; for (j = 0;j < cmds.len; ++j) if (!cmds.s[j]) { switch (cmds.s[i]) { case '\0': case '#': break; /* ignore blank/comment */ case '|': ret = mailprog(cmds.s + i + 1); break; default: ret = mailprog(cmds.s + i); break; } if (ret) break; i = j + 1; } if (!ret || ret == 99) /* 111 => temp error */ pmod = ""; /* 0, 99 => post */ /* other => moderate */ } moddir = argv[optind++]; if (moddir && !ret) { /* if exit 0 and moddir, add issub */ pmod = (char *) 0; while (moddir && !pmod && sender) { pmod = (moddir[0] == '/') ? issub(moddir,0,sender) : issub(dir,moddir,sender); closesub(); moddir = argv[optind++]; } } if (pmod) { program = "/ezmlm-send"; opts = &sendopt; } else { program = "/ezmlm-store"; opts = &storeopt; } if (dontact) { substdio_puts(subfderr, auto_bin); substdio_puts(subfderr, program); substdio_put(subfderr, " ", 1); substdio_put(subfderr, opts->s, opts->len); substdio_put(subfderr, " ", 1); substdio_puts(subfderr, dir); substdio_putsflush(subfderr, "\n"); _exit(0); } if ((child = wrap_fork()) == 0) wrap_execbin(program, opts, dir); /* parent */ wrap_exitcode(child); _exit(0); }
void die_usage() { substdio_putsflush(subfderr,"sendmail: usage: sendmail [ -t ] [ -fsender ] [ -Fname ] [ -bp ] [ -bs ] [ arg ... ]\n"); _exit(100); }
void die_rename() { substdio_putsflush(subfderr,"qmail-newu: fatal: unable to move users/cdb.tmp to users/cdb\n"); die_temp(); }
void die_write() { substdio_putsflush(subfderr,"qmail-pw2u: fatal: unable to write output\n"); _exit(111); }
void die_read() { substdio_putsflush(subfderr,"qmail-pw2u: fatal: unable to read input\n"); _exit(111); }
void die_nomem() { substdio_putsflush(subfderr,"qmail-pw2u: fatal: out of memory\n"); _exit(111); }
void die_chdir() { substdio_putsflush(subfderr,"qmail-pw2u: fatal: unable to chdir\n"); _exit(111); }
void mailq() { execv(*qreadarg,(char **)qreadarg); substdio_putsflush(subfderr,"sendmail: fatal: unable to run qmail-qread\n"); _exit(111); }
void die_format() { substdio_putsflush(subfderr,"qmail-newu: fatal: bad format in users/assign\n"); die_temp(); }
void die_writet() { substdio_putsflush(subfderr,"qmail-newu: fatal: unable to write users/cdb.tmp\n"); die_temp(); }
void die_control() { substdio_putsflush(subfderr,"qmail-pw2u: fatal: unable to read controls\n"); _exit(111); }
int main(int argc,char **argv) { const char *dir; const char *sender; const char *moddir; int opt; int ret = 0; unsigned int i,j; const char *program; stralloc *opts; stralloc cmds = {0}; int child; int ismod; umask(022); sig_pipeignore(); if (!stralloc_copys(&sendopt,"-")) die_nomem(); if (!stralloc_copys(&storeopt,"-")) die_nomem(); opt = getconfopt(argc,argv,options,1,&dir); /* storeopts to ezmlm-store only. Others to both (ezmlm-store may */ /* pass them on to ezmlm-send. */ if (!stralloc_catb(&storeopt,sendopt.s+1,sendopt.len-1)) die_nomem(); initsub(0); sender = get_sender(); ismod = 0; if (queryext) { getconf(&cmds,queryext,1); i = 0; for (j = 0;j < cmds.len; ++j) if (!cmds.s[j]) { switch (cmds.s[i]) { case '\0': case '#': break; /* ignore blank/comment */ case '|': ret = mailprog(cmds.s + i + 1); break; default: ret = mailprog(cmds.s + i); break; } if (ret) break; i = j + 1; } if (!ret || ret == 99) /* 111 => temp error */ ismod = 1; /* 0, 99 => post */ /* other => moderate */ } moddir = argv[opt++]; if (moddir && !ret) { /* if exit 0 and moddir, add issub */ ismod = 0; while (moddir && !ismod && sender) { ismod = issub(moddir,sender,0); closesub(); moddir = argv[opt++]; } } if (ismod) { program = "/ezmlm-send"; opts = &sendopt; } else { program = "/ezmlm-store"; opts = &storeopt; } if (dontact) { substdio_puts(subfderr, auto_bin()); substdio_puts(subfderr, program); substdio_put(subfderr, " ", 1); substdio_put(subfderr, opts->s, opts->len); substdio_put(subfderr, " ", 1); substdio_puts(subfderr, dir); substdio_putsflush(subfderr, "\n"); _exit(0); } if ((child = wrap_fork()) == 0) wrap_execbin(program, opts, dir); /* parent */ wrap_exitcode(child); _exit(0); }
void nomem() { substdio_putsflush(subfderr,"sendmail: fatal: out of memory\n"); _exit(111); }