dmap_serv.cpp 1.5 KB
/*
 * Copyright 2007 Stephen Liu
 * For license terms, see the file COPYING along with this library.
 */

#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <assert.h>
#include <sys/types.h>
#include <unistd.h>
#include <fcgi_stdio.h>


int main(int argc,char * argv[] )
{
	extern char   **environ;  
    int nlen = 0;  
    int i;  
    char *psz_content = NULL;  
    char **pp_env;
 
    setuid(geteuid()); //设置实际用户id为有效用户id
 
    while(FCGI_Accept() >= 0)
    {
        printf("Content-type: text/html\n\n");  
         
        for ( pp_env = environ; *pp_env; pp_env++ )  
            printf("%s<br>", *pp_env);  
      
        if ( strcmp("GET", getenv("REQUEST_METHOD")) == 0 )  
        {  
            char buf[128];
            printf("<p>%s</p>", getenv("QUERY_STRING"));  
			
            sprintf(buf, "mkdir -p /var/www/cgi-bin/%s", getenv("QUERY_STRING"));
            printf("%s\n", buf);
            system(buf);
        }  
        else  
        {  
            nlen = atoi(getenv("CONTENT_LENGTH"));  
            psz_content = ( char * )malloc( nlen + 1 );
            memset( psz_content, 0, nlen + 1 );
            printf("<p>char value:</p><p>");
            for (i = 0; i < nlen; i++ )     
            {  
                psz_content[i] = fgetc(stdin);
                printf( "%c", psz_content[i] );
            }
            printf("</p><p>string value: %s</p>", psz_content);  
        }
    }
    return 0; 
}