popen.c revision 982b4ad2dc6b5ed2a2c8c1670e94ecf1fe63fc56
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/****************************************************************************
Copyright (c) 1999,2000 WU-FTPD Development Group.
All rights reserved.
Portions Copyright (c) 1980, 1985, 1988, 1989, 1990, 1991, 1993, 1994
The Regents of the University of California.
Portions Copyright (c) 1993, 1994 Washington University in Saint Louis.
Portions Copyright (c) 1996, 1998 Berkeley Software Design, Inc.
Portions Copyright (c) 1989 Massachusetts Institute of Technology.
Portions Copyright (c) 1998 Sendmail, Inc.
Portions Copyright (c) 1983, 1995, 1996, 1997 Eric P. Allman.
Portions Copyright (c) 1997 by Stan Barber.
Portions Copyright (c) 1997 by Kent Landfield.
Portions Copyright (c) 1991, 1992, 1993, 1994, 1995, 1996, 1997
Free Software Foundation, Inc.
Use and distribution of this software and its source code are governed
by the terms and conditions of the WU-FTPD Software License ("LICENSE").
If you did not receive a copy of the license, it may be obtained online
$Id: popen.c,v 1.16 2000/07/01 18:17:39 wuftpd Exp $
****************************************************************************/
#include "config.h"
#include <signal.h>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#if defined(HAVE_FCNTL_H)
#include <fcntl.h>
#endif
#include "pathnames.h"
#include "proto.h"
/*
* Special version of popen which avoids call to shell. This insures noone
* may create a pipe to a hidden program as a side effect of a list or dir
* command.
*/
static int popen_fd = -1;
/*
* The globbed argv could end up being huge, so we must dynamically allocate
* it. Allocate it in chunks of GARGV_INC pointers.
*/
#define GARGV_INC 100
#define ARGV_INC 5
static char **argv;
static char **gargv;
static int argv_size;
static int gargv_size;
{
register char *cp;
extern char *globerr;
/*
* ftpd never needs more than one pipe open at a time, so only one PID is
* stored (in popen_pid). Protect against multiple pipes in case this
* changes.
*/
if (popen_fd != -1)
return (NULL);
return (NULL);
return (NULL);
}
}
return (NULL);
}
}
return (NULL);
/* empty the array */
/* break up string into pieces */
break;
}
char **tmp;
return (NULL);
} else {
}
}
}
/* glob each piece */
if (pop) {
}
}
while (*pop) {
if (gargc >= gargv_size) {
char **tmp;
(gargv_size + GARGV_INC) * sizeof (char *));
goto pfree;
} else {
gargv_size += GARGV_INC;
}
}
}
}
#ifdef SIGCHLD
#endif
case -1: /* error */
goto pfree;
/* NOTREACHED */
case 0: /* child */
if (*type == 'r') {
if (closestderr) {
(void) close(2);
/* stderr output is written to fd 2, so make sure it isn't
* available to be assigned to another file */
if (devnullfd != 2) {
}
}
}
else
}
}
else {
if (pdes[0] != 0) {
}
}
closefds(3);
/* begin CERT suggested fixes */
close(0);
i = geteuid();
setid_priv_on(0);
setuid(i);
setid_priv_off(i);
/* end CERT suggested fixes */
_exit(1);
}
/* parent; assume fdopen can't fail... */
if (*type == 'r') {
}
else {
}
}
return (iop);
}
{
int stat_loc;
sigemptyset(&sig);
#elif defined (_OSF_SOURCE)
int omask;
int status;
#else
int omask;
#endif
/* pclose returns -1 if stream is not associated with a `popened'
* command, or, if already `pclosed'. */
return (-1);
#else
#endif
#else
#endif
popen_pid = -1;
popen_fd = -1;
#ifdef SIGCHLD
#endif
#else
(void) sigsetmask(omask);
#ifdef _OSF_SOURCE
#else
#endif
#endif
}
#ifdef CLOSEFROM
{
}
#else
#ifdef HAVE_GETRLIMIT
#include <sys/resource.h>
#endif
{
int i, fds;
#ifdef HAVE_GETRLIMIT
#endif
#ifdef OPEN_MAX
#else
fds = 31;
#endif
#ifdef HAVE_GETRLIMIT
}
#else
#ifdef HAVE_GETDTABLESIZE
if ((i = getdtablesize()) > 0)
fds = i;
#else
#ifdef HAVE_SYSCONF
#endif /* HAVE_SYSCONF */
#endif /* HAVE_GETDTABLESIZE */
#endif /* HAVE_GETRLIMIT */
close(i);
}
#endif /* CLOSEFROM */