From 8b7f289b40c899a3353ac4df35df021482d97a6c Mon Sep 17 00:00:00 2001 From: Julian Blake Kongslie Date: Mon, 23 May 2011 21:07:21 -0700 Subject: Copy some environment variables in piny-suid. --- pinyweb/suid/piny-suid.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'pinyweb/suid') diff --git a/pinyweb/suid/piny-suid.c b/pinyweb/suid/piny-suid.c index 40c497f..badc580 100644 --- a/pinyweb/suid/piny-suid.c +++ b/pinyweb/suid/piny-suid.c @@ -1,7 +1,10 @@ +#define _GNU_SOURCE + #include #include #include #include +#include #include #include #include @@ -107,8 +110,32 @@ int main( int argc, char *argv[] ) { char buf[sz]; snprintf( buf, sz, "/usr/share/piny-suid/%s", argv[2] ); + char *path_info; + if ( asprintf( &path_info, "PATH_INFO=%s", getenv( "PATH_INFO" ) ) < 0 ) { + syslog( LOG_ERR, "Unable to allocate PATH_INFO space." ); + fprintf( stderr, "Internal error preparing environment.\n" ); + return 1; + }; + + char *script_name; + if ( asprintf( &script_name, "SCRIPT_NAME=%s", getenv( "SCRIPT_NAME" ) ) < 0 ) { + syslog( LOG_ERR, "Unable to allocate SCRIPT_NAME space." ); + fprintf( stderr, "Internal error preparing environment.\n" ); + return 1; + }; + + char *query_string; + if ( asprintf( &query_string, "QUERY_STRING=%s", getenv( "QUERY_STRING" ) ) < 0 ) { + syslog( LOG_ERR, "Unable to allocate QUERY_STRING space." ); + fprintf( stderr, "Internal error preparing environment.\n" ); + return 1; + }; + char * const env[] = - { NULL + { path_info + , script_name + , query_string + , NULL }; syslog( LOG_NOTICE, "Going to exec '%s' as '%s'", buf, argv[1] ); -- cgit v1.2.3