-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwtcgi.c
57 lines (44 loc) · 1020 Bytes
/
wtcgi.c
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
/* wtcgi.c
* truefinder, [email protected]
*/
#include <stdio.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <signal.h>
#include <fcntl.h>
#include <stdlib.h>
#define TMPFILE "/tmp/local.sock"
void print_header(void);
main()
{
struct sockaddr_un to;
int s;
int tolen, len, n, maxlen;
char msg[512], inbuf[512];
FILE *fp;
int i;
char *ch;
maxlen = 512;
len = atol(getenv("CONTENT_LENGTH"));
ch = (char*)malloc( sizeof(char)*(len+1) );
fgets( ch , len + 1 , stdin);
print_header();
#ifdef DEBUGZ
printf("CLIENT KEY IS LIKE %c(%x)\n", *ch , *ch);
#endif
s = socket(AF_UNIX,SOCK_STREAM,0);
to.sun_family = AF_UNIX;
strcpy(to.sun_path, TMPFILE );
tolen = sizeof(to.sun_family) + sizeof(to.sun_path);
connect(s,(struct sockaddr *) &to, tolen);
write( s, ch, 1 );
while( (i =read(s,inbuf, sizeof(inbuf)))){
printf("%s", inbuf);
bzero( inbuf, sizeof(inbuf));
}
close(s);
}
void print_header(void)
{
printf("Content-Type : text/html\n\n");
}