Handle busybox tcpsvd too

This commit is contained in:
Neale Pickett 2012-05-16 12:02:51 -06:00
parent 9f2749512f
commit ef9e02251d
2 changed files with 25 additions and 25 deletions

3
cgi.c
View File

@ -20,8 +20,7 @@ cgi_child(const char *relpath)
env("REQUEST_URI", path); env("REQUEST_URI", path);
env("SERVER_NAME", host); env("SERVER_NAME", host);
env("SCRIPT_NAME", relpath); env("SCRIPT_NAME", relpath);
env("REMOTE_ADDR", remote_ip); env("REMOTE_ADDR", remote_addr);
env("REMOTE_PORT", remote_port);
env("REMOTE_IDENT", remote_ident); env("REMOTE_IDENT", remote_ident);
if (content_length) { if (content_length) {
char cl[20]; char cl[20];

47
eris.c
View File

@ -81,8 +81,7 @@ int portappend = 0;
/* Variables that persist between requests */ /* Variables that persist between requests */
int cwd; int cwd;
int keepalive = 0; int keepalive = 0;
char *remote_ip = NULL; char *remote_addr = NULL;
char *remote_port = NULL;
char *remote_ident = NULL; char *remote_ident = NULL;
/* /*
@ -137,7 +136,7 @@ dolog(int code, off_t len)
sanitize(refer); sanitize(refer);
fprintf(stderr, "%s %d %lu %s %s %s %s\n", fprintf(stderr, "%s %d %lu %s %s %s %s\n",
remote_ip, code, (unsigned long) len, host, user_agent, refer, path); remote_addr, code, (unsigned long) len, host, user_agent, refer, path);
} }
void void
@ -202,6 +201,14 @@ not_found()
fflush(stdout); fflush(stdout);
} }
char *
proto_getenv(char *proto, char *name)
{
char buf[80];
snprintf(buf, sizeof buf, "%s%s", proto, name);
return getenv(buf);
}
void void
get_ucspi_env() get_ucspi_env()
@ -209,30 +216,24 @@ get_ucspi_env()
char *ucspi = getenv("PROTO"); char *ucspi = getenv("PROTO");
if (ucspi) { if (ucspi) {
int protolen = strlen(ucspi); char *p;
char buf[80];
char *p;
if (protolen > 20) { /* Busybox, as usual, has the right idea */
return; if ((p = proto_getenv(ucspi, "REMOTEADDR"))) {
} remote_addr = strdup(p);
strcpy(buf, ucspi); } else {
char *ip = proto_getenv(ucspi, "REMOTEIP");
char *port = proto_getenv(ucspi, "REMOTEPORT");
strcpy(buf + protolen, "REMOTEIP"); if (ip) {
p = getenv(buf); char buf[80];
if (p) {
remote_ip = strdup(p); snprintf(buf, sizeof buf, "%s:%s", ip, port);
remote_addr = strdup(buf);
}
} }
strcpy(buf + protolen, "REMOTEPORT"); if ((p = proto_getenv(ucspi, "REMOTEINFO"))) {
p = getenv(buf);
if (p) {
remote_port = strdup(p);
}
strcpy(buf + protolen, "REMOTEINFO");
p = getenv(buf);
if (p) {
remote_ident = strdup(p); remote_ident = strdup(p);
} }
} }