diff options
Diffstat (limited to 'debian/local/sensible-mda.c')
-rw-r--r-- | debian/local/sensible-mda.c | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/debian/local/sensible-mda.c b/debian/local/sensible-mda.c new file mode 100644 index 0000000..d42b0cb --- /dev/null +++ b/debian/local/sensible-mda.c @@ -0,0 +1,124 @@ +/* + * sensible-mda.c + * Copyright (c) 1998, Johnie Ingram. + * Copyright (c) 1998, Richard Nelson <cowboy@debian.org>. + * Time-stamp: <1998/08/13 10:00:00 cowboy> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +#include <stdio.h> +#include <stdlib.h> +#include <sys/stat.h> +#include <unistd.h> +#include <pwd.h> +#include <sys/types.h> + +// TODO: declare -x TCPREMOTEIP="$3" + +#define PROCMAIL "/usr/bin/procmail" +#define DELIVER "/usr/bin/deliver" +#define PROCMAILRCS "/etc/procmailrcs/" + +static void help(void); +static unsigned char program[64]; + +static struct stat MDA_stat; +static struct stat procmailrc_stat; +static int done = 1; +static struct passwd* passwd_entry; + +int +main (int argc, char *argv[]) +{ + + char *procmailrc; + + /*----------------------------------------------------------------*/ + /* Parse input to determine to whom to speak and who we are... */ + /* Must have at least three parameters unless first is ?,-?,/?. */ + /*----------------------------------------------------------------*/ + (void) strcpy(program, argv[0]); + if (argc >= 2 && + (strcmp(argv[1],"?") == 0 || strcmp(argv[1],"-?") == 0 || + strcmp(argv[1],"/?") == 0 || strcmp(argv[1],"\\?") == 0 || + strcmp(argv[1],"-h") == 0 || strcmp(argv[1],"--help") == 0)) { + help(); + return (0); + } + if (argc < 3) { + (void)printf("%s - Required parameters elided.\n",program); + help(); + return (0); + } + + + if (!stat(PROCMAIL, &MDA_stat)) { + if (MDA_stat.st_mode & S_ISUID) { + procmailrc=malloc(strlen(PROCMAILRCS)+strlen(argv[2])+1); + sprintf(procmailrc,"%s%s",PROCMAILRCS,argv[2]); + passwd_entry=getpwnam(argv[2]); + /* + * If argv[2] is a valid user & + * /etc/procmailrcs/argv[2] exists & is owned by argv[2] + */ + if (passwd_entry && + !stat(procmailrc, &procmailrc_stat) && + procmailrc_stat.st_uid==passwd_entry->pw_uid) { + done = 0; + execl (PROCMAIL, PROCMAIL, "-t", + "-f", argv[1], "-m", procmailrc, "-a", argv[3], NULL); + } else { + done = 0; + execl (PROCMAIL, PROCMAIL, "-t", + "-f", argv[1], "-a", argv[3], "-d", argv[2], NULL); + } + } + else + fprintf(stderr, "Ack!?! %s is not setuid!\n", PROCMAIL); + } + + if (done && !stat(DELIVER, &MDA_stat)) { + if (MDA_stat.st_mode & S_ISUID) { + done = 0; + execl (DELIVER, DELIVER, "-r", argv[1], argv[2], NULL); + } + else + fprintf(stderr, "Ack!?! %s is not setuid!\n", DELIVER); + } + + fprintf (stderr, "Huh? Neither %s nor %s was found (or was suid)!\n", + PROCMAIL, DELIVER); + + return (75); +} + + +/*-------------------------------------------------------------------*/ +/* Help... */ +/*-------------------------------------------------------------------*/ +static void help(void) +{ + (void)printf("\n%s - Help information.\n" + "%s: sendmail MTA->MDA wrapper, supporting these MDAs:\n" + "\tprocmail, deliver\n" + "\n" + "Syntax: %s from to\n" + ,program, program, program + ); + return; +} + |