dmap_serv.cpp
1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
* 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;
}