diff options
| author | bwarsaw | 1998-05-26 18:42:44 +0000 |
|---|---|---|
| committer | bwarsaw | 1998-05-26 18:42:44 +0000 |
| commit | 4b77f88dc96acf9e971908c1badf3305ee618ca1 (patch) | |
| tree | c425088f9db12fb3f826136f167be5cdc77a9bb4 /src/mail-wrapper.c | |
| parent | a38041fa64fb30b661a9a55a6c9a3c313ba453a4 (diff) | |
| download | mailman-4b77f88dc96acf9e971908c1badf3305ee618ca1.tar.gz mailman-4b77f88dc96acf9e971908c1badf3305ee618ca1.tar.zst mailman-4b77f88dc96acf9e971908c1badf3305ee618ca1.zip | |
Diffstat (limited to 'src/mail-wrapper.c')
| -rw-r--r-- | src/mail-wrapper.c | 174 |
1 files changed, 58 insertions, 116 deletions
diff --git a/src/mail-wrapper.c b/src/mail-wrapper.c index ea15c409c..1c5390ee9 100644 --- a/src/mail-wrapper.c +++ b/src/mail-wrapper.c @@ -1,49 +1,40 @@ -/* -** mail-wrapper.c: -** generic wrapper that will take info from a environment -** variable, and pass it to two commands. -** -** Copyright (C) 1998 by the Free Software Foundation, Inc. -** -** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -** -** 10-17-96 : Hal Schechner (hal-j@channel21.com) -** -** 12-14-96 : John Viega (viega@list.org) -** changed to work on 1 command, take a list of -** valid commands, just pass on argv, and use -** execvp() Also threw in some useful feedback for -** when there's a failure, mainly for future -** debugging. Made it a root script so we could -** call setuid() -** -** Chmod this 4755. -** -*/ -#include <stdio.h> +/* mail-wrapper.c --- Generic wrapper that will take info from a environment + * variable, and pass it to two commands. + * + * Copyright (C) 1998 by the Free Software Foundation, Inc. + * + * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include "common.h" -const char *COMMAND_LOCATION = "/home/mailman/mailman/scripts"; +/* TBD: Should make these arrays too?... */ +#define LEGAL_PARENT_UID MAIL_UID /* mail's UID */ +#define LEGAL_PARENT_GID MAIL_GID /* mail's GID */ -extern int errno; -FILE *f; +const int parentuid = LEGAL_PARENT_UID; +const int parentgid = LEGAL_PARENT_GID; +const char* logident = "Mailman mail-wrapper"; + + const char *VALID_COMMANDS[] = { "post", "mailcmd", "mailowner", - NULL /* Sentinal, don't remove */ + NULL /* Sentinel, don't remove */ }; @@ -52,115 +43,66 @@ const char *VALID_COMMANDS[] = { */ const char *LEGAL_PARENT_NAMES[] = { "sendmail", - NULL /* Sentinal, don't remove */ + NULL /* Sentinel, don't remove */ }; -/* Should make these arrays too... */ -const int LEGAL_PARENT_UID = 1; /* mail's UID */ -const int LEGAL_PARENT_GID = 1; /* mail's GID */ - - -/* -** what is the name of the process with pid of 'pid' -*/ -char * -get_process_name(int pid) -{ - FILE *proc; - char fname[30]; - char tmp[255]; - static char procname[255]; - - sprintf(fname, "/proc/%d/status", pid); - proc = fopen(fname, "r"); - fgets(tmp, 256, proc); - sscanf(tmp, "Name: %s\n", procname); - fclose(proc); - return procname; -} - + int -valid_parent(char *parent) +check_parent(char *parent) { int i = 0; - while (LEGAL_PARENT_NAMES[i] != NULL) { - if (!strcmp(parent, LEGAL_PARENT_NAMES[i])) { + while (LEGAL_PARENT_NAMES[i]) { + if (!strcmp(parent, LEGAL_PARENT_NAMES[i])) return 1; - } i++; } return 0; } -/* -** is the parent process allowed to call us? -*/ -int -legal_caller() -{ - /* compare to our parent's uid */ - if (LEGAL_PARENT_UID != getuid()) { - /* fprintf(f,"GOT UID %d.\n", getuid()); */ - printf("GOT UID %d.\n", getuid()); - return 0; - } - if (LEGAL_PARENT_GID != getgid()) { - /* fprintf(f,"GOT GID %d.\n", getgid()); */ - printf("GOT GID %d.\n", getgid()); - return 0; - } - return 1; -} - - int -valid_command(char *command) +check_command(char *command) { int i = 0; while (VALID_COMMANDS[i] != NULL) { - if (!strcmp(command, VALID_COMMANDS[i])) { + if (!strcmp(command, VALID_COMMANDS[i])) return 1; - } i++; } return 0; } + int -main(int argc, char **argv) +main(int argc, char** argv, char** env) { - char *command; - int i; - - if (argc < 2) { - printf("Usage: %s program [args...]\n", argv[0]); - fflush(stdout); - exit(0); - } - i = strlen(argv[1]) + strlen(COMMAND_LOCATION) + 2; - command = (char *)malloc(sizeof(char) * i); - sprintf(command, "%s/%s", COMMAND_LOCATION, argv[1]); + int status; - if (!valid_command(argv[1])) { - printf("Illegal command.\n"); - } - else { - if (legal_caller()) { - setuid(geteuid()); - execv(command, &argv[1]); - } - else { - printf("Illegal caller!\n"); - } - } + /* sanity check arguments */ + if (argc < 2) + fatal(logident, "Usage: %s program [args...]\n", argv[0]); + + if (!check_command(argv[1])) + fatal(logident, "Illegal command: %s", argv[1]); + + check_caller(logident, parentuid, parentgid); + + /* If we got here, everything must be OK */ + status = setuid(geteuid()); + if (status) + fatal(logident, "%s", strerror(errno)); + + status = run_script(argv[1], argc, argv, env); + fatal(logident, "%s", strerror(errno)); + return status; } + /* * Local Variables: |
