/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1982-2012 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* David Korn <dgk@research.att.com> *
* *
***********************************************************************/
#pragma prototyped
/*
* regression test intercept control
* enable with SHOPT_REGRESS==1 in Makefile
* not for production use
* see --man for details
* all string constants inline here instead of in data/...
*
* David Korn
* at&t research
*/
#include "defs.h"
#if SHOPT_REGRESS
#include <error.h>
#include <ls.h>
#include "io.h"
#include "builtins.h"
#include <tmx.h>
static const char usage[] =
"[-1p0?\n@(#)$Id: __regress__ (AT&T Research) 2009-03-29 $\n]"
"[+NAME?__regress__ - shell regression test intercept control]"
"[+DESCRIPTION?\b__regress__\b controls the regression test intercepts "
"for shells compiled with SHOPT_REGRESS==1. Shells compiled this way are "
"for testing only. In addition to \b__regress__\b and the \b--regress\b "
"command line option, these shells may contain system library function "
"intercepts that behave different from the native counterparts.]"
"[+?Each option controls a different test and possibly a different set "
"of intercepts. The options are interpreted \bdd\b(1) style -- '-' or "
"'--' prefix not required. This simplifies the specification of the "
"command line \b--regress\b=\avalue\a option, where \avalue\a is passed "
"as an option to the \b__regress__\b builtin. Typically regression test "
"intercepts are enabled with one or more command line \b--regress\b "
"options, with optional specific calls to \b__regress__\b in test "
"[+?Each enabled intercept may result in trace lines of the form \b" REGRESS_HEADER
"\aoption\a:\aintercept\a:\ainfo\a on the standard error, where "
"\aoption\a is one of the options below, \aintercept\a is the name of "
"the specific intercept for \aoption\a, and \ainfo\a is \aoption\a "
"specific information. Unless noted otherwise, one regression test trace "
"line is produced each time an enabled intercept is called.]"
"[101:egid?The intercept effective gid is set to \aoriginal-egid\a. The "
"effective gid of the underlying system process is not affected. The "
"trace line info is either \begid==rgid\b or \begid!=rgid\b. The "
"intercepts are:]#?[original-egid:=1]"
"{"
"[+getegid()?The intercept effecive gid is returned. The "
"\bsetgid\b() intercept may change this between the real gid and "
"\aoriginal-egid\a.]"
"[+setgid(gid)?Sets the intercept effective gid to \agid\a. "
"Fails if \agid\a is neither the real gid nor "
"\aoriginal-egid\a.]"
"}"
"[102:euid?The intercept effective uid is set to \aoriginal-euid\a. The "
"effective uid of the underlying system process is not affected. The "
"trace line info is either \beuid==ruid\b or \beuid!=ruid\b. The "
"intercepts are:]#?[original-euid:=1]"
"{"
"[+geteuid()?The intercept effecive uid is returned. The "
"\bsetuid\b() intercept may change this between the real uid and "
"\aoriginal-euid\a.]"
"[+setuid(uid)?Sets the intercept effective uid to \auid\a. "
"Fails if \auid\a is neither the real uid nor "
"\aoriginal-euid\a.]"
"}"
"[103:p_suid?Specifies a value for SHOPT_P_SUID. Effective uids greater "
"than the non-privileged-uid disable the priveleged mode. The intercepts "
"are:]#?[non-privileged-uid:=1]"
"{"
"[+SHOPT_P_SUID?The SHOPT_P_SUID macro value is overridden by "
"\bp_suid\b. A trace line is output for each SHOPT_P_SUID "
"access.]"
"}"
"[104:source?The intercepts are:]"
"{"
"[+sh_source()?The trace line info is the path of the script "
"being sourced. Used to trace shell startup scripts.]"
"}"
"intercepts are:]:[etc-dir:=/etc]"
"{"
"\aetc-dir\a/*.]"
"}"
"[+SEE ALSO?\bksh\b(1), \bregress\b(1), \brt\b(1)]"
;
static const char* regress_options[] =
{
"ERROR",
"egid",
"euid",
"p_suid",
"source",
"etc",
};
{
}
/*
* regress info trace output
*/
void sh_regress(unsigned int index, const char* intercept, const char* info, unsigned int line, const char* file)
{
char* name;
else
}
/*
* egid intercepts
*/
{
if (intercept_rgid == -1)
intercept_rgid = getgid();
if (sh_isregress(REGRESS_egid))
{
return intercept_egid;
}
return intercept_rgid;
}
{
if (intercept_rgid == -1)
intercept_rgid = getgid();
if (sh_isregress(REGRESS_egid))
{
{
return -1;
}
}
else if (gid != intercept_rgid)
{
return -1;
}
return 0;
}
/*
* euid intercepts
*/
{
if (intercept_ruid == -1)
intercept_ruid = getuid();
if (sh_isregress(REGRESS_euid))
{
return intercept_euid;
}
return intercept_ruid;
}
{
if (intercept_ruid == -1)
intercept_ruid = getuid();
if (sh_isregress(REGRESS_euid))
{
{
return -1;
}
}
else if (uid != intercept_ruid)
{
return -1;
}
return 0;
}
/*
* p_suid intercept
*/
{
return intercept_p_suid;
}
/*
* p_suid intercept
*/
static char* intercept_etc = 0;
{
return intercept_etc;
}
/*
* __regress__ builtin
*/
{
int n;
for (;;)
{
{
case '?':
break;
case ':':
break;
case 0:
break;
default:
if (n < -100)
{
n = -(n + 100);
sh_onregress(n);
else
sh_offregress(n);
switch (n)
{
case REGRESS_egid:
if (sh_isregress(n))
{
}
else
break;
case REGRESS_euid:
if (sh_isregress(n))
{
}
else
break;
case REGRESS_p_suid:
if (sh_isregress(n))
{
}
else
break;
case REGRESS_source:
break;
case REGRESS_etc:
if (sh_isregress(n))
{
}
else
break;
}
}
continue;
}
break;
}
return 0;
}
#else
#endif