/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
* Copyright 2012 Milan Jurik. All rights reserved.
*/
/* Copyright (c) 1988 AT&T */
/* All Rights Reserved */
/* from S5R4 1.6 */
#include <sys/sysmacros.h>
#include <sys/pathname.h>
/*
* This is the loadable module wrapper.
*/
0,
2,
};
/*
* Module linkage information for the kernel.
*/
extern struct mod_ops mod_execops;
};
};
int
_init()
{
return (mod_install(&modlinkage));
}
int
_fini()
{
return (mod_remove(&modlinkage));
}
int
{
}
/*
* Crack open a '#!' line.
*/
static int
{
int error;
/*
* Read the entire line and confirm that it starts with '#!'.
*/
return (error);
return (ENOEXEC);
/*
* Blank all white space and find the newline.
*/
if (*cp == '\t')
*cp = ' ';
return (ENOEXEC);
*cp = '\0';
/*
* Locate the beginning and end of the interpreter name.
* In addition to the name, one additional argument may
* optionally be included here, to be prepended to the
* arguments provided on the command line. Thus, for
* example, you can say
*
*/
;
if (*cp == '\0')
return (ENOEXEC);
cp++;
if (*cp == '\0') {
} else {
*cp++ = '\0';
while (*cp == ' ')
cp++;
if (*cp == '\0')
else {
cp++;
*cp = '\0';
}
}
return (0);
}
/*
* We support nested interpreters up to a depth of INTP_MAXDEPTH (this value
* matches the depth on Linux). When a nested interpreter is in use, the
* previous name and argument must be passed along. We use the intpdata_t
* name and argument arrays for this. In the normal, non-nested case, only the
* first element in those arrays will be populated.
*
* For setid scripts the "script hole" is a security race condition between
* when we exec the interpreter and when the interpreter reads the script. We
* handle this below for the initial script, but we don't allow setid scripts
* when using nested interpreters. Because gexec only modifies the credentials
* for a setid script at level 0, then if we come back through for a nested
* interpreter we know that args->fname will be set (the first script is setid)
* and we can return an error. If an intermediate nested interpreter is setid
* then it will not be run with different credentials because of the gexec
* handling, so it is effectively no longer setid and we don't have to worry
* about the "script hole".
*/
int
int level,
long *execsz,
int setid,
int brand_action)
{
int error = 0;
char *opath;
goto bad;
}
if (level == 0)
/*
* Allocate a buffer to read in the interpreter pathname.
*/
goto fail;
/*
* Look the new vnode up.
*/
goto fail;
goto fail;
}
if (level > 0) {
/*
* We have a nested interpreter. The previous name(s) and
* argument(s) need to be passed along. We also keep track
* of how often this zone uses nested interpreters.
*/
int i;
/* since we're shifting up, loop stops one short */
for (i = 0; i < (INTP_MAXDEPTH - 1); i++) {
}
void *, nvp);
}
/* don't free resolvepn until we are done with args */
/*
* Disallow setuid or additional privilege execution for nested
* interpreters.
*/
goto done;
}
/*
* When we're executing a set-uid script resulting in uids
* mismatching or when we execute with additional privileges,
* we close the "replace script between exec and open by shell"
*/
if ((setid & EXECSETID_PRIVS) != 0 ||
goto done;
}
EBA_NONE);
if (!error) {
/*
* Close this executable as the interpreter
* will open and close it later on.
*/
}
done:
fail:
bad:
return (error);
}