1995-12-02 17:30:23 +00:00
|
|
|
/*
|
2005-02-14 02:39:14 +00:00
|
|
|
* Copyright (c) 1998-2004 Sendmail, Inc. and its suppliers.
|
2000-08-12 22:19:16 +00:00
|
|
|
* All rights reserved.
|
1998-08-03 05:56:20 +00:00
|
|
|
* Copyright (c) 1993 Eric P. Allman. All rights reserved.
|
1995-12-02 17:30:23 +00:00
|
|
|
* Copyright (c) 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
1998-08-03 05:56:20 +00:00
|
|
|
* By using this file, you agree to the terms and conditions set
|
|
|
|
* forth in the LICENSE file which can be found at the top level of
|
|
|
|
* the sendmail distribution.
|
1995-12-02 17:30:23 +00:00
|
|
|
*
|
2003-10-31 22:12:09 +00:00
|
|
|
* $FreeBSD$
|
1995-12-02 17:30:23 +00:00
|
|
|
*/
|
|
|
|
|
2002-02-17 21:58:34 +00:00
|
|
|
#include <sm/gen.h>
|
|
|
|
|
|
|
|
SM_IDSTR(copyright,
|
2005-02-14 02:39:14 +00:00
|
|
|
"@(#) Copyright (c) 1998-2004 Sendmail, Inc. and its suppliers.\n\
|
2000-08-12 22:19:16 +00:00
|
|
|
All rights reserved.\n\
|
|
|
|
Copyright (c) 1993 Eric P. Allman. All rights reserved.\n\
|
|
|
|
Copyright (c) 1993\n\
|
2002-02-17 21:58:34 +00:00
|
|
|
The Regents of the University of California. All rights reserved.\n")
|
2000-08-12 22:19:16 +00:00
|
|
|
|
2005-02-14 02:39:14 +00:00
|
|
|
SM_IDSTR(id, "@(#)$Id: smrsh.c,v 8.65 2004/08/06 18:54:22 ca Exp $")
|
2000-08-12 22:19:16 +00:00
|
|
|
|
1995-12-02 17:30:23 +00:00
|
|
|
/*
|
|
|
|
** SMRSH -- sendmail restricted shell
|
|
|
|
**
|
|
|
|
** This is a patch to get around the prog mailer bugs in most
|
|
|
|
** versions of sendmail.
|
|
|
|
**
|
|
|
|
** Use this in place of /bin/sh in the "prog" mailer definition
|
|
|
|
** in your sendmail.cf file. You then create CMDDIR (owned by
|
|
|
|
** root, mode 755) and put links to any programs you want
|
|
|
|
** available to prog mailers in that directory. This should
|
|
|
|
** include things like "vacation" and "procmail", but not "sed"
|
|
|
|
** or "sh".
|
|
|
|
**
|
|
|
|
** Leading pathnames are stripped from program names so that
|
|
|
|
** existing .forward files that reference things like
|
1998-08-04 13:08:41 +00:00
|
|
|
** "/usr/bin/vacation" will continue to work.
|
1995-12-02 17:30:23 +00:00
|
|
|
**
|
|
|
|
** The following characters are completely illegal:
|
2000-08-12 22:19:16 +00:00
|
|
|
** < > ^ & ` ( ) \n \r
|
|
|
|
** The following characters are sometimes illegal:
|
|
|
|
** | &
|
1995-12-02 17:30:23 +00:00
|
|
|
** This is more restrictive than strictly necessary.
|
|
|
|
**
|
2000-08-12 22:19:16 +00:00
|
|
|
** To use this, add FEATURE(`smrsh') to your .mc file.
|
1995-12-02 17:30:23 +00:00
|
|
|
**
|
|
|
|
** This can be used on any version of sendmail.
|
|
|
|
**
|
|
|
|
** In loving memory of RTM. 11/02/93.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <unistd.h>
|
2002-02-17 21:58:34 +00:00
|
|
|
#include <sm/io.h>
|
2002-06-11 21:16:51 +00:00
|
|
|
#include <sm/limits.h>
|
2002-02-17 21:58:34 +00:00
|
|
|
#include <sm/string.h>
|
1995-12-02 17:30:23 +00:00
|
|
|
#include <sys/file.h>
|
2002-10-13 00:56:58 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
1995-12-02 17:30:23 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
2000-08-12 22:19:16 +00:00
|
|
|
#include <errno.h>
|
1995-12-02 17:30:23 +00:00
|
|
|
#ifdef EX_OK
|
|
|
|
# undef EX_OK
|
2000-08-12 22:19:16 +00:00
|
|
|
#endif /* EX_OK */
|
1995-12-02 17:30:23 +00:00
|
|
|
#include <sysexits.h>
|
|
|
|
#include <syslog.h>
|
1997-11-10 01:58:17 +00:00
|
|
|
#include <stdlib.h>
|
1995-12-02 17:30:23 +00:00
|
|
|
|
2002-02-17 21:58:34 +00:00
|
|
|
#include <sm/conf.h>
|
|
|
|
#include <sm/errstring.h>
|
2000-08-12 22:19:16 +00:00
|
|
|
|
1995-12-02 17:30:23 +00:00
|
|
|
/* directory in which all commands must reside */
|
|
|
|
#ifndef CMDDIR
|
2002-02-17 21:58:34 +00:00
|
|
|
# ifdef SMRSH_CMDDIR
|
|
|
|
# define CMDDIR SMRSH_CMDDIR
|
|
|
|
# else /* SMRSH_CMDDIR */
|
|
|
|
# define CMDDIR "/usr/adm/sm.bin"
|
|
|
|
# endif /* SMRSH_CMDDIR */
|
2000-08-12 22:19:16 +00:00
|
|
|
#endif /* ! CMDDIR */
|
1995-12-02 17:30:23 +00:00
|
|
|
|
|
|
|
/* characters disallowed in the shell "-c" argument */
|
|
|
|
#define SPECIALS "<|>^();&`$\r\n"
|
|
|
|
|
|
|
|
/* default search path */
|
|
|
|
#ifndef PATH
|
2002-02-17 21:58:34 +00:00
|
|
|
# ifdef SMRSH_PATH
|
|
|
|
# define PATH SMRSH_PATH
|
|
|
|
# else /* SMRSH_PATH */
|
|
|
|
# define PATH "/bin:/usr/bin:/usr/ucb"
|
|
|
|
# endif /* SMRSH_PATH */
|
2000-08-12 22:19:16 +00:00
|
|
|
#endif /* ! PATH */
|
|
|
|
|
|
|
|
char newcmdbuf[1000];
|
|
|
|
char *prg, *par;
|
|
|
|
|
2005-02-14 02:39:14 +00:00
|
|
|
static void addcmd __P((char *, bool, size_t));
|
|
|
|
|
2000-08-12 22:19:16 +00:00
|
|
|
/*
|
|
|
|
** ADDCMD -- add a string to newcmdbuf, check for overflow
|
|
|
|
**
|
|
|
|
** Parameters:
|
|
|
|
** s -- string to add
|
|
|
|
** cmd -- it's a command: prepend CMDDIR/
|
|
|
|
** len -- length of string to add
|
|
|
|
**
|
|
|
|
** Side Effects:
|
|
|
|
** changes newcmdbuf or exits with a failure.
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
2005-02-14 02:39:14 +00:00
|
|
|
static void
|
2000-08-12 22:19:16 +00:00
|
|
|
addcmd(s, cmd, len)
|
|
|
|
char *s;
|
2002-02-17 21:58:34 +00:00
|
|
|
bool cmd;
|
|
|
|
size_t len;
|
2000-08-12 22:19:16 +00:00
|
|
|
{
|
|
|
|
if (s == NULL || *s == '\0')
|
|
|
|
return;
|
|
|
|
|
2004-02-14 21:58:08 +00:00
|
|
|
/* enough space for s (len) and CMDDIR + "/" and '\0'? */
|
2000-08-12 22:19:16 +00:00
|
|
|
if (sizeof newcmdbuf - strlen(newcmdbuf) <=
|
2004-02-14 21:58:08 +00:00
|
|
|
len + 1 + (cmd ? (strlen(CMDDIR) + 1) : 0))
|
2000-08-12 22:19:16 +00:00
|
|
|
{
|
2002-02-17 21:58:34 +00:00
|
|
|
(void)sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
|
|
|
|
"%s: command too long: %s\n", prg, par);
|
2000-08-12 22:19:16 +00:00
|
|
|
#ifndef DEBUG
|
|
|
|
syslog(LOG_WARNING, "command too long: %.40s", par);
|
|
|
|
#endif /* ! DEBUG */
|
|
|
|
exit(EX_UNAVAILABLE);
|
|
|
|
}
|
|
|
|
if (cmd)
|
2002-06-11 21:16:51 +00:00
|
|
|
(void) sm_strlcat2(newcmdbuf, CMDDIR, "/", sizeof newcmdbuf);
|
2004-02-14 21:58:08 +00:00
|
|
|
(void) strncat(newcmdbuf, s, len);
|
2000-08-12 22:19:16 +00:00
|
|
|
}
|
1995-12-02 17:30:23 +00:00
|
|
|
|
1998-08-03 05:56:20 +00:00
|
|
|
int
|
1995-12-02 17:30:23 +00:00
|
|
|
main(argc, argv)
|
|
|
|
int argc;
|
|
|
|
char **argv;
|
|
|
|
{
|
|
|
|
register char *p;
|
|
|
|
register char *q;
|
2000-08-12 22:19:16 +00:00
|
|
|
register char *r;
|
1995-12-02 17:30:23 +00:00
|
|
|
register char *cmd;
|
2000-08-12 22:19:16 +00:00
|
|
|
int isexec;
|
|
|
|
int save_errno;
|
1995-12-02 17:30:23 +00:00
|
|
|
char *newenv[2];
|
|
|
|
char pathbuf[1000];
|
2000-08-12 22:19:16 +00:00
|
|
|
char specialbuf[32];
|
2002-10-13 00:56:58 +00:00
|
|
|
struct stat st;
|
1995-12-02 17:30:23 +00:00
|
|
|
|
2000-08-12 22:19:16 +00:00
|
|
|
#ifndef DEBUG
|
|
|
|
# ifndef LOG_MAIL
|
1995-12-02 17:30:23 +00:00
|
|
|
openlog("smrsh", 0);
|
2000-08-12 22:19:16 +00:00
|
|
|
# else /* ! LOG_MAIL */
|
1995-12-02 17:30:23 +00:00
|
|
|
openlog("smrsh", LOG_ODELAY|LOG_CONS, LOG_MAIL);
|
2000-08-12 22:19:16 +00:00
|
|
|
# endif /* ! LOG_MAIL */
|
|
|
|
#endif /* ! DEBUG */
|
1995-12-02 17:30:23 +00:00
|
|
|
|
2002-06-11 21:16:51 +00:00
|
|
|
(void) sm_strlcpyn(pathbuf, sizeof pathbuf, 2, "PATH=", PATH);
|
1995-12-02 17:30:23 +00:00
|
|
|
newenv[0] = pathbuf;
|
|
|
|
newenv[1] = NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Do basic argv usage checking
|
|
|
|
*/
|
|
|
|
|
2000-08-12 22:19:16 +00:00
|
|
|
prg = argv[0];
|
|
|
|
|
1995-12-02 17:30:23 +00:00
|
|
|
if (argc != 3 || strcmp(argv[1], "-c") != 0)
|
|
|
|
{
|
2002-02-17 21:58:34 +00:00
|
|
|
(void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
|
|
|
|
"Usage: %s -c command\n", prg);
|
2000-08-12 22:19:16 +00:00
|
|
|
#ifndef DEBUG
|
1995-12-02 17:30:23 +00:00
|
|
|
syslog(LOG_ERR, "usage");
|
2000-08-12 22:19:16 +00:00
|
|
|
#endif /* ! DEBUG */
|
1995-12-02 17:30:23 +00:00
|
|
|
exit(EX_USAGE);
|
|
|
|
}
|
|
|
|
|
2001-05-28 17:10:35 +00:00
|
|
|
par = argv[2];
|
|
|
|
|
1995-12-02 17:30:23 +00:00
|
|
|
/*
|
|
|
|
** Disallow special shell syntax. This is overly restrictive,
|
|
|
|
** but it should shut down all attacks.
|
|
|
|
** Be sure to include 8-bit versions, since many shells strip
|
|
|
|
** the address to 7 bits before checking.
|
|
|
|
*/
|
|
|
|
|
2000-08-12 22:19:16 +00:00
|
|
|
if (strlen(SPECIALS) * 2 >= sizeof specialbuf)
|
1995-12-02 17:30:23 +00:00
|
|
|
{
|
2000-08-12 22:19:16 +00:00
|
|
|
#ifndef DEBUG
|
|
|
|
syslog(LOG_ERR, "too many specials: %.40s", SPECIALS);
|
|
|
|
#endif /* ! DEBUG */
|
1995-12-02 17:30:23 +00:00
|
|
|
exit(EX_UNAVAILABLE);
|
|
|
|
}
|
2002-02-17 21:58:34 +00:00
|
|
|
(void) sm_strlcpy(specialbuf, SPECIALS, sizeof specialbuf);
|
2000-08-12 22:19:16 +00:00
|
|
|
for (p = specialbuf; *p != '\0'; p++)
|
|
|
|
*p |= '\200';
|
2002-02-17 21:58:34 +00:00
|
|
|
(void) sm_strlcat(specialbuf, SPECIALS, sizeof specialbuf);
|
1995-12-02 17:30:23 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
** Do a quick sanity check on command line length.
|
|
|
|
*/
|
|
|
|
|
2002-02-17 21:58:34 +00:00
|
|
|
if (strlen(par) > (sizeof newcmdbuf - sizeof CMDDIR - 2))
|
1995-12-02 17:30:23 +00:00
|
|
|
{
|
2002-02-17 21:58:34 +00:00
|
|
|
(void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
|
|
|
|
"%s: command too long: %s\n", prg, par);
|
2000-08-12 22:19:16 +00:00
|
|
|
#ifndef DEBUG
|
|
|
|
syslog(LOG_WARNING, "command too long: %.40s", par);
|
|
|
|
#endif /* ! DEBUG */
|
1995-12-02 17:30:23 +00:00
|
|
|
exit(EX_UNAVAILABLE);
|
|
|
|
}
|
|
|
|
|
2000-08-12 22:19:16 +00:00
|
|
|
q = par;
|
|
|
|
newcmdbuf[0] = '\0';
|
2002-02-17 21:58:34 +00:00
|
|
|
isexec = false;
|
1995-12-02 17:30:23 +00:00
|
|
|
|
2002-06-11 21:16:51 +00:00
|
|
|
while (*q != '\0')
|
1995-12-02 17:30:23 +00:00
|
|
|
{
|
2000-08-12 22:19:16 +00:00
|
|
|
/*
|
|
|
|
** Strip off a leading pathname on the command name. For
|
|
|
|
** example, change /usr/ucb/vacation to vacation.
|
|
|
|
*/
|
1995-12-02 17:30:23 +00:00
|
|
|
|
2000-08-12 22:19:16 +00:00
|
|
|
/* strip leading spaces */
|
|
|
|
while (*q != '\0' && isascii(*q) && isspace(*q))
|
|
|
|
q++;
|
|
|
|
if (*q == '\0')
|
1995-12-02 17:30:23 +00:00
|
|
|
{
|
2000-08-12 22:19:16 +00:00
|
|
|
if (isexec)
|
|
|
|
{
|
2002-02-17 21:58:34 +00:00
|
|
|
(void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
|
|
|
|
"%s: missing command to exec\n",
|
|
|
|
prg);
|
2000-08-12 22:19:16 +00:00
|
|
|
#ifndef DEBUG
|
2002-02-17 21:58:34 +00:00
|
|
|
syslog(LOG_CRIT, "uid %d: missing command to exec", (int) getuid());
|
2000-08-12 22:19:16 +00:00
|
|
|
#endif /* ! DEBUG */
|
|
|
|
exit(EX_UNAVAILABLE);
|
|
|
|
}
|
1995-12-02 17:30:23 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2000-08-12 22:19:16 +00:00
|
|
|
/* find the end of the command name */
|
|
|
|
p = strpbrk(q, " \t");
|
|
|
|
if (p == NULL)
|
|
|
|
cmd = &q[strlen(q)];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*p = '\0';
|
|
|
|
cmd = p;
|
|
|
|
}
|
|
|
|
/* search backwards for last / (allow for 0200 bit) */
|
|
|
|
while (cmd > q)
|
|
|
|
{
|
|
|
|
if ((*--cmd & 0177) == '/')
|
|
|
|
{
|
|
|
|
cmd++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* cmd now points at final component of path name */
|
1995-12-02 17:30:23 +00:00
|
|
|
|
2000-08-12 22:19:16 +00:00
|
|
|
/* allow a few shell builtins */
|
|
|
|
if (strcmp(q, "exec") == 0 && p != NULL)
|
|
|
|
{
|
2002-02-17 21:58:34 +00:00
|
|
|
addcmd("exec ", false, strlen("exec "));
|
2002-06-11 21:16:51 +00:00
|
|
|
|
2000-08-12 22:19:16 +00:00
|
|
|
/* test _next_ arg */
|
|
|
|
q = ++p;
|
2002-02-17 21:58:34 +00:00
|
|
|
isexec = true;
|
2000-08-12 22:19:16 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (strcmp(q, "exit") == 0 || strcmp(q, "echo") == 0)
|
|
|
|
{
|
2002-02-17 21:58:34 +00:00
|
|
|
addcmd(cmd, false, strlen(cmd));
|
2002-06-11 21:16:51 +00:00
|
|
|
|
2000-08-12 22:19:16 +00:00
|
|
|
/* test following chars */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-06-11 21:16:51 +00:00
|
|
|
char cmdbuf[MAXPATHLEN];
|
|
|
|
|
2000-08-12 22:19:16 +00:00
|
|
|
/*
|
|
|
|
** Check to see if the command name is legal.
|
|
|
|
*/
|
2002-06-11 21:16:51 +00:00
|
|
|
|
|
|
|
if (sm_strlcpyn(cmdbuf, sizeof cmdbuf, 3, CMDDIR,
|
|
|
|
"/", cmd) >= sizeof cmdbuf)
|
|
|
|
{
|
|
|
|
/* too long */
|
|
|
|
(void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
|
2003-02-08 20:35:51 +00:00
|
|
|
"%s: \"%s\" not available for sendmail programs (filename too long)\n",
|
2002-06-11 21:16:51 +00:00
|
|
|
prg, cmd);
|
|
|
|
if (p != NULL)
|
|
|
|
*p = ' ';
|
|
|
|
#ifndef DEBUG
|
2003-02-08 20:35:51 +00:00
|
|
|
syslog(LOG_CRIT, "uid %d: attempt to use \"%s\" (filename too long)",
|
2002-06-11 21:16:51 +00:00
|
|
|
(int) getuid(), cmd);
|
|
|
|
#endif /* ! DEBUG */
|
|
|
|
exit(EX_UNAVAILABLE);
|
|
|
|
}
|
|
|
|
|
1995-12-02 17:30:23 +00:00
|
|
|
#ifdef DEBUG
|
2002-02-17 21:58:34 +00:00
|
|
|
(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT,
|
|
|
|
"Trying %s\n", cmdbuf);
|
2000-08-12 22:19:16 +00:00
|
|
|
#endif /* DEBUG */
|
2002-10-13 00:56:58 +00:00
|
|
|
if (stat(cmdbuf, &st) < 0)
|
|
|
|
{
|
|
|
|
/* can't stat it */
|
|
|
|
(void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
|
2003-02-08 20:35:51 +00:00
|
|
|
"%s: \"%s\" not available for sendmail programs (stat failed)\n",
|
2002-10-13 00:56:58 +00:00
|
|
|
prg, cmd);
|
|
|
|
if (p != NULL)
|
|
|
|
*p = ' ';
|
|
|
|
#ifndef DEBUG
|
2003-02-08 20:35:51 +00:00
|
|
|
syslog(LOG_CRIT, "uid %d: attempt to use \"%s\" (stat failed)",
|
2002-10-13 00:56:58 +00:00
|
|
|
(int) getuid(), cmd);
|
|
|
|
#endif /* ! DEBUG */
|
|
|
|
exit(EX_UNAVAILABLE);
|
|
|
|
}
|
|
|
|
if (!S_ISREG(st.st_mode)
|
|
|
|
#ifdef S_ISLNK
|
|
|
|
&& !S_ISLNK(st.st_mode)
|
|
|
|
#endif /* S_ISLNK */
|
|
|
|
)
|
|
|
|
{
|
|
|
|
/* can't stat it */
|
|
|
|
(void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
|
2003-02-08 20:35:51 +00:00
|
|
|
"%s: \"%s\" not available for sendmail programs (not a file)\n",
|
2002-10-13 00:56:58 +00:00
|
|
|
prg, cmd);
|
|
|
|
if (p != NULL)
|
|
|
|
*p = ' ';
|
|
|
|
#ifndef DEBUG
|
2003-02-08 20:35:51 +00:00
|
|
|
syslog(LOG_CRIT, "uid %d: attempt to use \"%s\" (not a file)",
|
2002-10-13 00:56:58 +00:00
|
|
|
(int) getuid(), cmd);
|
|
|
|
#endif /* ! DEBUG */
|
|
|
|
exit(EX_UNAVAILABLE);
|
|
|
|
}
|
2000-08-12 22:19:16 +00:00
|
|
|
if (access(cmdbuf, X_OK) < 0)
|
|
|
|
{
|
|
|
|
/* oops.... crack attack possiblity */
|
2002-02-17 21:58:34 +00:00
|
|
|
(void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
|
2003-02-08 20:35:51 +00:00
|
|
|
"%s: \"%s\" not available for sendmail programs\n",
|
2002-02-17 21:58:34 +00:00
|
|
|
prg, cmd);
|
2000-08-12 22:19:16 +00:00
|
|
|
if (p != NULL)
|
|
|
|
*p = ' ';
|
|
|
|
#ifndef DEBUG
|
2003-02-08 20:35:51 +00:00
|
|
|
syslog(LOG_CRIT, "uid %d: attempt to use \"%s\"",
|
2002-02-17 21:58:34 +00:00
|
|
|
(int) getuid(), cmd);
|
2000-08-12 22:19:16 +00:00
|
|
|
#endif /* ! DEBUG */
|
|
|
|
exit(EX_UNAVAILABLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Create the actual shell input.
|
|
|
|
*/
|
|
|
|
|
2002-02-17 21:58:34 +00:00
|
|
|
addcmd(cmd, true, strlen(cmd));
|
2000-08-12 22:19:16 +00:00
|
|
|
}
|
2002-02-17 21:58:34 +00:00
|
|
|
isexec = false;
|
2000-08-12 22:19:16 +00:00
|
|
|
|
1995-12-02 17:30:23 +00:00
|
|
|
if (p != NULL)
|
|
|
|
*p = ' ';
|
2000-08-12 22:19:16 +00:00
|
|
|
else
|
|
|
|
break;
|
1995-12-02 17:30:23 +00:00
|
|
|
|
2000-08-12 22:19:16 +00:00
|
|
|
r = strpbrk(p, specialbuf);
|
2002-02-17 21:58:34 +00:00
|
|
|
if (r == NULL)
|
|
|
|
{
|
|
|
|
addcmd(p, false, strlen(p));
|
2000-08-12 22:19:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
#if ALLOWSEMI
|
2002-02-17 21:58:34 +00:00
|
|
|
if (*r == ';')
|
|
|
|
{
|
|
|
|
addcmd(p, false, r - p + 1);
|
2000-08-12 22:19:16 +00:00
|
|
|
q = r + 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
#endif /* ALLOWSEMI */
|
|
|
|
if ((*r == '&' && *(r + 1) == '&') ||
|
|
|
|
(*r == '|' && *(r + 1) == '|'))
|
|
|
|
{
|
2002-02-17 21:58:34 +00:00
|
|
|
addcmd(p, false, r - p + 2);
|
2000-08-12 22:19:16 +00:00
|
|
|
q = r + 2;
|
|
|
|
continue;
|
|
|
|
}
|
1995-12-02 17:30:23 +00:00
|
|
|
|
2002-02-17 21:58:34 +00:00
|
|
|
(void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
|
|
|
|
"%s: cannot use %c in command\n", prg, *r);
|
2000-08-12 22:19:16 +00:00
|
|
|
#ifndef DEBUG
|
|
|
|
syslog(LOG_CRIT, "uid %d: attempt to use %c in command: %s",
|
2002-02-17 21:58:34 +00:00
|
|
|
(int) getuid(), *r, par);
|
2000-08-12 22:19:16 +00:00
|
|
|
#endif /* ! DEBUG */
|
|
|
|
exit(EX_UNAVAILABLE);
|
2002-06-11 21:16:51 +00:00
|
|
|
}
|
2000-08-12 22:19:16 +00:00
|
|
|
if (isexec)
|
|
|
|
{
|
2002-02-17 21:58:34 +00:00
|
|
|
(void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
|
|
|
|
"%s: missing command to exec\n", prg);
|
2000-08-12 22:19:16 +00:00
|
|
|
#ifndef DEBUG
|
2002-02-17 21:58:34 +00:00
|
|
|
syslog(LOG_CRIT, "uid %d: missing command to exec",
|
|
|
|
(int) getuid());
|
2000-08-12 22:19:16 +00:00
|
|
|
#endif /* ! DEBUG */
|
|
|
|
exit(EX_UNAVAILABLE);
|
|
|
|
}
|
|
|
|
/* make sure we created something */
|
|
|
|
if (newcmdbuf[0] == '\0')
|
|
|
|
{
|
2002-02-17 21:58:34 +00:00
|
|
|
(void) sm_io_fprintf(smioerr, SM_TIME_DEFAULT,
|
|
|
|
"Usage: %s -c command\n", prg);
|
2000-08-12 22:19:16 +00:00
|
|
|
#ifndef DEBUG
|
|
|
|
syslog(LOG_ERR, "usage");
|
|
|
|
#endif /* ! DEBUG */
|
|
|
|
exit(EX_USAGE);
|
|
|
|
}
|
1995-12-02 17:30:23 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
** Now invoke the shell
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2002-02-17 21:58:34 +00:00
|
|
|
(void) sm_io_fprintf(smioout, SM_TIME_DEFAULT, "%s\n", newcmdbuf);
|
2000-08-12 22:19:16 +00:00
|
|
|
#endif /* DEBUG */
|
2003-10-31 22:12:09 +00:00
|
|
|
(void) execle("/bin/sh", "/bin/sh", "-c", newcmdbuf,
|
|
|
|
(char *)NULL, newenv);
|
2000-08-12 22:19:16 +00:00
|
|
|
save_errno = errno;
|
|
|
|
#ifndef DEBUG
|
2002-02-17 21:58:34 +00:00
|
|
|
syslog(LOG_CRIT, "Cannot exec /bin/sh: %s", sm_errstring(errno));
|
2000-08-12 22:19:16 +00:00
|
|
|
#endif /* ! DEBUG */
|
|
|
|
errno = save_errno;
|
2002-02-17 21:58:34 +00:00
|
|
|
sm_perror("/bin/sh");
|
1995-12-02 17:30:23 +00:00
|
|
|
exit(EX_OSFILE);
|
2000-08-12 22:19:16 +00:00
|
|
|
/* NOTREACHED */
|
|
|
|
return EX_OSFILE;
|
1995-12-02 17:30:23 +00:00
|
|
|
}
|