Push remote host into input.c.

This commit is contained in:
kristapsdz committed 2014-11-23 23:58:33 +00:00
1 parent b64e77e0bc
commit 11cba6bf23
5 files changed
+23 -47

No files matched your search

-30
View File
@@ -20,36 +20,6 @@
<i>Version @VERSION@</i> is a minor-number bump due to a significantly changing API.
Not much has changed in the back-end of the system (with one significant exception!); most of these changes are organisational.
</p>
<ul>
<li>
Add a <a href="http://www.cl.cam.ac.uk/research/security/capsicum/freebsd.html">Capsicum</a>
sandbox on <a href="http://www.freebsd.org">FreeBSD</a>.
</li>
<li>
Split <span class="file">libkcgi</span>, <a href="kcgi.3.html">kcgi(3)</a>, into
<span class="file">libkcgihtml</span>, <a href="kcgihtml.3.html">kcgihtml(3)</a>.
This simplifies the system dramatically and allows for more extensions (e.g., JSON) outside of
the main body of code.
</li>
<li>
Split <a href="kcgi.3.html">kcgi(3)</a> into per-function manpages, e.g., <a
href="khttp_parse.3.html">khttp_parse(3)</a>.
This makes system reading documentation much easier.
</li>
<li>
Merge small fix to escape quotes in HTML text and <a
href="kvalid_string.3.html">kvalid_date(3)</a> month calculator.
</li>
<li>
Add <a href="khttp_free.3.html">khttp_child_free(3)</a> for closing the HTTP in a child of the
CGI process.
This is useful if your web application forks to perform some long-running function (e.g.,
mailing).
</li>
<li>
Add a few more commonly-used media types.
</li>
</p>
</section>
</header>
<article>
+16 -5
View File
@@ -981,6 +981,9 @@ khttp_input_parent(int fd, struct kreq *r, pid_t pid)
} else if (fullread(fd, &r->auth, sizeof(enum kauth), 0) < 0) {
XWARNX("failed to read authorisation type");
goto out;
} if (fullreadword(fd, &r->remote) < 0) {
XWARNX("failed to read fullpath");
goto out;
} if (fullreadword(fd, &r->fullpath) < 0) {
XWARNX("failed to read fullpath");
goto out;
@@ -1073,6 +1076,7 @@ khttp_input_child(int fd, const struct kvalid *keys,
{
struct parms pp;
char *cp, *ep, *sub;
const char *ccp;
enum kmethod meth;
enum kauth auth;
size_t len;
@@ -1086,24 +1090,31 @@ khttp_input_child(int fd, const struct kvalid *keys,
/* RFC 3875, 4.1.12. */
/* We assume GET if not supplied. */
meth = KMETHOD_GET;
if (NULL != (cp = getenv("REQUEST_METHOD")))
if (NULL != (ccp = getenv("REQUEST_METHOD")))
for (meth = 0; meth < KMETHOD__MAX; meth++)
if (0 == strcmp(kmethods[meth], cp))
if (0 == strcmp(kmethods[meth], ccp))
break;
fullwrite(fd, &meth, sizeof(enum kmethod));
/* Determine authenticaiton: RFC 3875, 4.1.1. */
auth = KAUTH_NONE;
if (NULL != (cp = getenv("AUTH_TYPE")))
if (NULL != (ccp = getenv("AUTH_TYPE")))
for (auth = 0; auth < KAUTH_UNKNOWN; auth++) {
if (NULL == kauths[auth])
continue;
if (0 == strcmp(kauths[auth], cp))
if (0 == strcmp(kauths[auth], ccp))
break;
}
fullwrite(fd, &auth, sizeof(enum kauth));
/* RFC 3875, 4.1.8. */
/* Never supposed to be NULL, but to be sure... */
if (NULL == (ccp = getenv("REMOTE_ADDR")))
ccp = "127.0.0.1";
len = strlen(ccp);
fullwrite(fd, &len, sizeof(size_t));
fullwrite(fd, ccp, len);
/*
* Now parse the first path element (the page we want to
* access), subsequent path information, and the file suffix.
-10
View File
@@ -756,16 +756,6 @@ khttp_parsex(struct kreq *req,
if (NULL == req->pname)
goto err;
/* RFC 3875, 4.1.8. */
/* Never supposed to be NULL, but to be sure... */
if (NULL == (cp = getenv("REMOTE_ADDR")))
req->remote = XSTRDUP("127.0.0.1");
else
req->remote = XSTRDUP(cp);
if (NULL == req->remote)
goto err;
/* Never supposed to be NULL, but to be sure... */
if (NULL == (cp = getenv("HTTP_HOST")))
req->host = XSTRDUP("localhost");
+6 -1
View File
@@ -59,6 +59,7 @@ enum key {
enum templ {
TEMPL_TITLE,
TEMPL_NAME,
TEMPL_REMOTE_ADDR,
TEMPL__MAX
};
@@ -87,7 +88,8 @@ static const struct kvalid keys[KEY__MAX] = {
*/
static const char *const templs[TEMPL__MAX] = {
"title", /* TEMPL_TITLE */
"name" /* TEMPL_NAME */
"name", /* TEMPL_NAME */
"remote_addr", /* TEMPL_REMOTE_ADDR */
};
/*
@@ -128,6 +130,9 @@ template(size_t key, void *arg)
case (TEMPL_NAME):
khtml_text(req, "name");
break;
case (TEMPL_REMOTE_ADDR):
khtml_text(req, req->req->remote);
break;
default:
abort();
}
+1 -1
View File
@@ -8,7 +8,7 @@
<h1>@@name@@</h1>
</header>
<article>
Hello, world.
Hello, @@remote_addr@@.
</article>
</body>
</html>