# define PIPE_BUF 4096
#endif
-#define MAX_MEMORY_BUF 8192 /* IO buffer */
+#define IOBUF_SIZE 8192 /* IO buffer */
#define HEADER_READ_TIMEOUT 60
#if ENABLE_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR
Htaccess *script_i; /* config script interpreters */
#endif
- char *iobuf; /* [MAX_MEMORY_BUF] */
+ char *iobuf; /* [IOBUF_SIZE] */
#define hdr_buf bb_common_bufsiz1
char *hdr_ptr;
int hdr_cnt;
return orig;
}
-
-#if ENABLE_FEATURE_HTTPD_CGI
-/*
- * setenv helpers
- */
-static void setenv1(const char *name, const char *value)
-{
- if (!value)
- value = "";
- setenv(name, value, 1);
-}
-#endif
-
#if ENABLE_FEATURE_HTTPD_BASIC_AUTH
/*
* Decode a base64 data stream as per rfc1521.
static void log_and_exit(void) ATTRIBUTE_NORETURN;
static void log_and_exit(void)
{
+ /* Paranoia. IE said to be buggy. It may send some extra data
+ * or be confused by us just exiting without SHUT_WR. Oh well. */
+ shutdown(1, SHUT_WR);
+ ndelay_on(0);
+ while (read(0, iobuf, IOBUF_SIZE) > 0)
+ continue;
+
if (verbose > 2)
bb_error_msg("closed");
_exit(xfunc_error_retval);
iobuf[count] = '\0';
return count;
}
- if (count < (MAX_MEMORY_BUF - 1)) /* check overflow */
+ if (count < (IOBUF_SIZE - 1)) /* check overflow */
count++;
}
return count;
}
#if ENABLE_FEATURE_HTTPD_CGI
+static void setenv1(const char *name, const char *value)
+{
+ setenv(name, value ? value : "", 1);
+}
+
/*
* Spawn CGI script, forward CGI's stdin/out <=> network
*
}
#define PIPESIZE PIPE_BUF
-#if PIPESIZE >= MAX_MEMORY_BUF
-# error "PIPESIZE >= MAX_MEMORY_BUF"
+#if PIPESIZE >= IOBUF_SIZE
+# error "PIPESIZE >= IOBUF_SIZE"
#endif
if (FD_ISSET(fromCgi.rd, &readSet)) {
/* There is something to read from CGI */
fallback:
#endif
- while ((count = safe_read(f, iobuf, MAX_MEMORY_BUF)) > 0) {
+ while ((count = safe_read(f, iobuf, IOBUF_SIZE)) > 0) {
ssize_t n = count;
count = full_write(1, iobuf, count);
if (count != n)
char *pp;
if (strncmp(p, request, u - request) != 0) {
- /* user uncompared */
+ /* user doesn't match */
continue;
}
pp = strchr(p, ':');
- if (pp && pp[1] == '$' && pp[2] == '1' &&
- pp[3] == '$' && pp[4]) {
+ if (pp && pp[1] == '$' && pp[2] == '1'
+ && pp[3] == '$' && pp[4]
+ ) {
pp++;
cipher = pw_encrypt(u+1, pp);
if (strcmp(cipher, pp) == 0)
set_remoteuser_var:
remoteuser = strdup(request);
if (remoteuser)
- remoteuser[(u - request)] = '\0';
+ remoteuser[u - request] = '\0';
return 1; /* Ok */
}
/* unauthorized */
/* Allocation of iobuf is postponed until now
* (IOW, server process doesn't need to waste 8k) */
- iobuf = xmalloc(MAX_MEMORY_BUF);
+ iobuf = xmalloc(IOBUF_SIZE);
rmt_ip = 0;
if (fromAddr->sa.sa_family == AF_INET) {
*/
send_file_and_exit(tptr);
-
-#if 0 /* Is this needed? Why? */
- if (DEBUG)
- fprintf(stderr, "closing socket\n");
-#if ENABLE_FEATURE_HTTPD_CGI
- free(cookie);
- free(content_type);
- free(referer);
- referer = NULL;
-#if ENABLE_FEATURE_HTTPD_BASIC_AUTH
- free(remoteuser);
- remoteuser = NULL;
-#endif
-#endif
- /* Properly wait for remote to closed */
- int retval;
- shutdown(1, SHUT_WR);
- do {
- fd_set s_fd;
- struct timeval tv;
- FD_ZERO(&s_fd);
- FD_SET(0, &s_fd);
- tv.tv_sec = 2;
- tv.tv_usec = 0;
- retval = select(1, &s_fd, NULL, NULL, &tv);
- } while (retval > 0 && read(0, iobuf, sizeof(iobuf) > 0));
- shutdown(0, SHUT_RD);
- log_and_exit();
-#endif
}
/*
/* Run a copy of ourself in inetd mode */
re_exec(argv_copy);
}
- /* parent, or fork failed */
+ /* parent, or vfork failed */
close(n);
} /* while (1) */
/* never reached */