2 ===================================================================
3 --- configure.in (.../tags/lighttpd-1.4.13) (revision 1706)
4 +++ configure.in (.../branches/lighttpd-1.4.x) (revision 1706)
7 AC_MSG_RESULT($WITH_LUA)
8 if test "$WITH_LUA" != "no"; then
9 - if test "$WITH_LUA" == "yes"; then
10 + if test "$WITH_LUA" = "yes"; then
13 PKG_CHECK_MODULES(LUA, $WITH_LUA >= 5.1, [
18 -do_build="mod_cgi mod_fastcgi mod_proxy mod_evhost mod_simple_vhost mod_access mod_alias mod_setenv mod_usertrack mod_auth mod_status mod_accesslog mod_rrdtool mod_secdownload mod_expire mod_compress mod_dirlisting mod_indexfiles mod_userdir mod_webdav mod_staticfile mod_scgi mod_flv_streaming"
19 +do_build="mod_cgi mod_fastcgi mod_extforward mod_proxy mod_evhost mod_simple_vhost mod_access mod_alias mod_setenv mod_usertrack mod_auth mod_status mod_accesslog mod_rrdtool mod_secdownload mod_expire mod_compress mod_dirlisting mod_indexfiles mod_userdir mod_webdav mod_staticfile mod_scgi mod_flv_streaming"
21 plugins="mod_rewrite mod_redirect mod_ssi mod_trigger_b4_dl"
22 features="regex-conditionals"
24 ===================================================================
25 --- src/mod_cgi.c (.../tags/lighttpd-1.4.13) (revision 1706)
26 +++ src/mod_cgi.c (.../branches/lighttpd-1.4.x) (revision 1706)
28 CONST_BUF_LEN(con->authed_user));
32 + if (srv_sock->is_ssl) {
33 + cgi_env_add(&env, CONST_STR_LEN("HTTPS"), CONST_STR_LEN("on"));
37 /* request.content_length < SSIZE_MAX, see request.c */
38 ltostr(buf, con->request.content_length);
39 cgi_env_add(&env, CONST_STR_LEN("CONTENT_LENGTH"), buf, strlen(buf));
41 ===================================================================
42 --- src/base.h (.../tags/lighttpd-1.4.13) (revision 1706)
43 +++ src/base.h (.../branches/lighttpd-1.4.x) (revision 1706)
45 enum { STAT_CACHE_ENGINE_UNSET,
46 STAT_CACHE_ENGINE_NONE,
47 STAT_CACHE_ENGINE_SIMPLE,
52 unsigned short enable_cores;
54 Index: src/connections.c
55 ===================================================================
56 --- src/connections.c (.../tags/lighttpd-1.4.13) (revision 1706)
57 +++ src/connections.c (.../branches/lighttpd-1.4.x) (revision 1706)
65 case 206: /* write_queue is already prepared */
75 Index: src/configfile.c
76 ===================================================================
77 --- src/configfile.c (.../tags/lighttpd-1.4.13) (revision 1706)
78 +++ src/configfile.c (.../branches/lighttpd-1.4.x) (revision 1706)
80 srv->srvconf.stat_cache_engine = STAT_CACHE_ENGINE_SIMPLE;
81 } else if (buffer_is_equal_string(stat_cache_string, CONST_STR_LEN("simple"))) {
82 srv->srvconf.stat_cache_engine = STAT_CACHE_ENGINE_SIMPLE;
84 } else if (buffer_is_equal_string(stat_cache_string, CONST_STR_LEN("fam"))) {
85 srv->srvconf.stat_cache_engine = STAT_CACHE_ENGINE_FAM;
87 } else if (buffer_is_equal_string(stat_cache_string, CONST_STR_LEN("disable"))) {
88 srv->srvconf.stat_cache_engine = STAT_CACHE_ENGINE_NONE;
90 log_error_write(srv, __FILE__, __LINE__, "sb",
91 - "server.stat-cache-engine can be one of \"disable\", \"simple\", \"fam\", but not:", stat_cache_string);
92 + "server.stat-cache-engine can be one of \"disable\", \"simple\","
96 + " but not:", stat_cache_string);
100 Index: src/mod_scgi.c
101 ===================================================================
102 --- src/mod_scgi.c (.../tags/lighttpd-1.4.13) (revision 1706)
103 +++ src/mod_scgi.c (.../branches/lighttpd-1.4.x) (revision 1706)
104 @@ -2528,7 +2528,7 @@
105 hctx->reconnects < 5) {
106 scgi_reconnect(srv, hctx);
108 - log_error_write(srv, __FILE__, __LINE__, "sdsdsd",
109 + log_error_write(srv, __FILE__, __LINE__, "ssdsd",
110 "response not sent, request not sent, reconnection.",
111 "connection-fd:", con->fd,
112 "fcgi-fd:", hctx->fd);
114 ===================================================================
115 --- src/request.c (.../tags/lighttpd-1.4.13) (revision 1706)
116 +++ src/request.c (.../branches/lighttpd-1.4.x) (revision 1706)
119 if (host_len == 0) return -1;
121 + /* if the hostname ends in a "." strip it */
122 + if (host->ptr[host_len-1] == '.') host_len -= 1;
124 /* scan from the right and skip the \0 */
125 for (i = host_len - 1; i + 1 > 0; i--) {
126 const char c = host->ptr[i];
127 Index: src/network_backends.h
128 ===================================================================
129 --- src/network_backends.h (.../tags/lighttpd-1.4.13) (revision 1706)
130 +++ src/network_backends.h (.../branches/lighttpd-1.4.x) (revision 1706)
132 # include <sys/uio.h>
135 -#if defined HAVE_SYS_UIO_H && defined HAVE_SENDFILE && defined HAVE_WRITEV && defined(__FreeBSD__)
136 +#if defined HAVE_SYS_UIO_H && defined HAVE_SENDFILE && defined HAVE_WRITEV && (defined(__FreeBSD__) || defined(__DragonFly__))
137 # define USE_FREEBSD_SENDFILE
138 # include <sys/uio.h>
140 Index: src/mod_proxy.c
141 ===================================================================
142 --- src/mod_proxy.c (.../tags/lighttpd-1.4.13) (revision 1706)
143 +++ src/mod_proxy.c (.../branches/lighttpd-1.4.x) (revision 1706)
147 if (-1 == (r = read(hctx->fd, hctx->response->ptr + hctx->response->used - 1, b))) {
148 + if (errno == EAGAIN) return 0;
149 log_error_write(srv, __FILE__, __LINE__, "sds",
150 "unexpected end-of-file (perhaps the proxy process died):",
151 proxy_fd, strerror(errno));
152 Index: src/mod_extforward.c
153 ===================================================================
154 --- src/mod_extforward.c (.../tags/lighttpd-1.4.13) (revision 0)
155 +++ src/mod_extforward.c (.../branches/lighttpd-1.4.x) (revision 1706)
161 +#include <netinet/in.h>
169 +#include "inet_ntop_cache.h"
170 +#ifdef HAVE_CONFIG_H
175 + * mod_extforward.c for lighttpd, by comman.kang <at> gmail <dot> com
176 + * extended, modified by Lionel Elie Mamane (LEM), lionel <at> mamane <dot> lu
180 + * Trust proxy 10.0.0.232 and 10.0.0.232
181 + * extforward.forwarder = ( "10.0.0.232" => "trust",
182 + * "10.0.0.233" => "trust" )
184 + * Trust all proxies (NOT RECOMMENDED!)
185 + * extforward.forwarder = ( "all" => "trust")
187 + * Note that "all" has precedence over specific entries,
188 + * so "all except" setups will not work.
190 + * Note: The effect of this module is variable on $HTTP["remotip"] directives and
191 + * other module's remote ip dependent actions.
192 + * Things done by modules before we change the remoteip or after we reset it will match on the proxy's IP.
193 + * Things done in between these two moments will match on the real client's IP.
194 + * The moment things are done by a module depends on in which hook it does things and within the same hook
195 + * on whether they are before/after us in the module loading order
196 + * (order in the server.modules directive in the config file).
198 + * Tested behaviours:
200 + * mod_access: Will match on the real client.
203 + * In order to see the "real" ip address in access log ,
204 + * you'll have to load mod_extforward after mod_accesslog.
207 + * server.modules = (
214 + * seems causing segfault with mod_ssl and $HTTP{"socket"} directives
215 + * LEM 2006.05.26: Fixed segfault $SERVER["socket"] directive. Untested with SSL.
218 + * 2005.12.19 Initial Version
219 + * 2005.12.19 fixed conflict with conditional directives
220 + * 2006.05.26 LEM: IPv6 support
221 + * 2006.05.26 LEM: Fix a segfault with $SERVER["socket"] directive.
222 + * 2006.05.26 LEM: Run at uri_raw time, as we don't need to see the URI
223 + * In this manner, we run before mod_access and $HTTP["remoteip"] directives work!
224 + * 2006.05.26 LEM: Clean config_cond cache of tests whose result we probably change.
228 +/* plugin config for all request/connections */
237 + plugin_config **config_storage;
239 + plugin_config conf;
243 +/* context , used for restore remote ip */
246 + sock_addr saved_remote_addr;
247 + buffer *saved_remote_addr_buf;
251 +static handler_ctx * handler_ctx_init(sock_addr oldaddr, buffer *oldaddr_buf) {
252 + handler_ctx * hctx;
253 + hctx = calloc(1, sizeof(*hctx));
254 + hctx->saved_remote_addr = oldaddr;
255 + hctx->saved_remote_addr_buf = oldaddr_buf;
259 +static void handler_ctx_free(handler_ctx *hctx) {
263 +/* init the plugin data */
264 +INIT_FUNC(mod_extforward_init) {
266 + p = calloc(1, sizeof(*p));
270 +/* destroy the plugin data */
271 +FREE_FUNC(mod_extforward_free) {
272 + plugin_data *p = p_d;
276 + if (!p) return HANDLER_GO_ON;
278 + if (p->config_storage) {
281 + for (i = 0; i < srv->config_context->used; i++) {
282 + plugin_config *s = p->config_storage[i];
286 + array_free(s->forwarder);
290 + free(p->config_storage);
296 + return HANDLER_GO_ON;
299 +/* handle plugin config and check values */
301 +SETDEFAULTS_FUNC(mod_extforward_set_defaults) {
302 + plugin_data *p = p_d;
305 + config_values_t cv[] = {
306 + { "extforward.forwarder", NULL, T_CONFIG_ARRAY, T_CONFIG_SCOPE_CONNECTION }, /* 0 */
307 + { NULL, NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET }
310 + if (!p) return HANDLER_ERROR;
312 + p->config_storage = calloc(1, srv->config_context->used * sizeof(specific_config *));
314 + for (i = 0; i < srv->config_context->used; i++) {
317 + s = calloc(1, sizeof(plugin_config));
318 + s->forwarder = array_init();
320 + cv[0].destination = s->forwarder;
322 + p->config_storage[i] = s;
324 + if (0 != config_insert_values_global(srv, ((data_config *)srv->config_context->data[i])->value, cv)) {
325 + return HANDLER_ERROR;
329 + return HANDLER_GO_ON;
334 +static int mod_extforward_patch_connection(server *srv, connection *con, plugin_data *p) {
336 + plugin_config *s = p->config_storage[0];
340 + /* LEM: The purpose of this seems to match extforward configuration
341 + stanzas that are not in the global context, but in some sub-context.
342 + I fear this will break contexts of the form HTTP['remote'] = .
343 + (in the form that they do not work with the real remote, but matching on
344 + the proxy instead).
346 + I'm not sure this this is all thread-safe. Is the p we are passed different
347 + for each connection or is it global?
349 + mod_fastcgi does the same, so it must be safe.
351 + /* skip the first, the global context */
352 + for (i = 1; i < srv->config_context->used; i++) {
353 + data_config *dc = (data_config *)srv->config_context->data[i];
354 + s = p->config_storage[i];
356 + /* condition didn't match */
357 + if (!config_check_cond(srv, con, dc)) continue;
360 + for (j = 0; j < dc->value->used; j++) {
361 + data_unset *du = dc->value->data[j];
363 + if (buffer_is_equal_string(du->key, CONST_STR_LEN("extforward.forwarder"))) {
374 +static void put_string_into_array_len(array *ary, const char *str, int len)
376 + data_string *tempdata;
379 + tempdata = data_string_init();
380 + buffer_copy_string_len(tempdata->value,str,len);
381 + array_insert_unique(ary,(data_unset *)tempdata);
384 + extract a forward array from the environment
386 +static array *extract_forward_array(buffer *pbuffer)
388 + array *result = array_init();
389 + if (pbuffer->used > 0) {
391 + /* state variable, 0 means not in string, 1 means in string */
393 + for (base = pbuffer->ptr, curr = pbuffer->ptr; *curr; curr++)
396 + if ( (*curr > '9' || *curr < '0') && *curr != '.' && *curr != ':' ) {
397 + /* found an separator , insert value into result array */
398 + put_string_into_array_len(result, base, curr-base);
399 + /* change state to not in string */
403 + if (*curr >= '0' && *curr <= '9')
405 + /* found leading char of an IP address, move base pointer and change state */
411 + /* if breaking out while in str, we got to the end of string, so add it */
414 + put_string_into_array_len(result, base, curr-base);
420 +#define IP_TRUSTED 1
421 +#define IP_UNTRUSTED 0
423 + check whether ip is trusted, return 1 for trusted , 0 for untrusted
425 +static int is_proxy_trusted(const char *ipstr, plugin_data *p)
427 + data_string* allds = (data_string *) array_get_element(p->conf.forwarder,"all");
429 + if (strcasecmp(allds->value->ptr,"trust") == 0)
432 + return IP_UNTRUSTED;
434 + return (data_string *)array_get_element(p->conf.forwarder,ipstr) ? IP_TRUSTED : IP_UNTRUSTED ;
437 +struct addrinfo *ipstr_to_sockaddr(const char *host)
439 + struct addrinfo hints, *res0;
441 + memset(&hints, 0, sizeof(hints));
442 + hints.ai_flags = AI_NUMERICHOST | AI_NUMERICSERV;
444 + result = getaddrinfo(host, NULL, &hints, &res0);
447 + fprintf(stderr,"could not resolve hostname %s because %s\n", host,gai_strerror(result));
448 + if (result == EAI_SYSTEM)
449 + perror("The system error is ");
454 + fprintf(stderr, "Problem in resolving hostname %s: succeeded, but no information returned\n", host);
460 +static void clean_cond_cache(server *srv, connection *con)
464 + for (i = 0; i < srv->config_context->used; i++) {
465 + data_config *dc = (data_config *)srv->config_context->data[i];
467 + if (dc->comp == COMP_HTTP_REMOTEIP)
469 + con->cond_cache[i].result = COND_RESULT_UNSET;
470 + con->cond_cache[i].patterncount = 0;
475 +URIHANDLER_FUNC(mod_extforward_uri_handler) {
476 + plugin_data *p = p_d;
477 + data_string *forwarded = NULL;
479 + char b2[INET6_ADDRSTRLEN + 1];
483 + mod_extforward_patch_connection(srv, con, p);
485 +/* log_error_write(srv, __FILE__, __LINE__,"s","mod_extforward_uri_handler called\n"); */
487 + /* if the remote ip itself is not trusted , then do nothing */
489 + s = inet_ntop(con->dst_addr.plain.sa_family,
490 + con->dst_addr.plain.sa_family == AF_INET6 ?
491 + &(con->dst_addr.ipv6.sin6_addr) :
492 + &(con->dst_addr.ipv4.sin_addr),
496 + s = inet_ntoa(con->dst_addr.ipv4.sin_addr);
498 + if (IP_UNTRUSTED == is_proxy_trusted (s, p) )
499 + return HANDLER_GO_ON;
501 + /* log_error_write(srv, __FILE__, __LINE__,"s","remote address is trusted proxy, go on\n");*/
502 + if (con->request.headers &&
503 + ((forwarded = (data_string *) array_get_element(con->request.headers,"X-Forwarded-For")) ||
504 + (forwarded = (data_string *) array_get_element(con->request.headers, "Forwarded-For"))))
506 + /* log_error_write(srv, __FILE__, __LINE__,"s","found forwarded header\n");*/
507 + /* found forwarded for header */
509 + array *forward_array = extract_forward_array(forwarded->value);
510 + char *real_remote_addr = NULL;
512 + struct addrinfo *addrlist = NULL;
514 + /* Testing shows that multiple headers and multiple values in one header
515 + come in _reverse_ order. So the first one we get is the last one in the request. */
516 + for (i = forward_array->used - 1; i >= 0; i--)
518 + data_string *ds = (data_string *) forward_array->data[i];
520 +/* log_error_write(srv, __FILE__, __LINE__,"ss","forward",ds->value->ptr); */
521 + real_remote_addr = ds->value->ptr;
523 + /* LEM: What the hell is this about?
524 + We test whether the forwarded for IP is trusted?
525 + This looks like an ugly hack to handle multiple Forwarded-For's
526 + and avoid those set to our proxies, or something like that.
527 + My testing shows that reverse proxies add a new X-Forwarded-For header,
528 + and we should thus take the last one, which is the first one we see.
530 + The net result of the old code is that we use the first untrusted IP,
531 + or if all are trusted, the last trusted IP.
532 + That's crazy. So I've disabled this.
534 + /* check whether it is trusted */
535 +/* if (IP_UNTRUSTED == is_proxy_trusted(ds->value->ptr,p) ) */
537 +/* log_error_write(srv, __FILE__, __LINE__,"ss",ds->value->ptr," is trusted."); */
541 + /* bug ? bailing out here */
545 + if (real_remote_addr != NULL) /* parsed */
548 + struct addrinfo *addrs_left;
549 +/* log_error_write(srv, __FILE__, __LINE__,"ss","use forward",real_remote_addr); */
551 + addrlist = ipstr_to_sockaddr(real_remote_addr);
552 + s.plain.sa_family = AF_UNSPEC;
553 + for (addrs_left = addrlist; addrs_left != NULL;
554 + addrs_left = addrs_left -> ai_next)
556 + s.plain.sa_family = addrs_left->ai_family;
557 + if ( s.plain.sa_family == AF_INET )
559 + s.ipv4.sin_addr = ((struct sockaddr_in*)addrs_left->ai_addr)->sin_addr;
562 + else if ( s.plain.sa_family == AF_INET6 )
564 + s.ipv6.sin6_addr = ((struct sockaddr_in6*)addrs_left->ai_addr)->sin6_addr;
569 + s.ipv4.sin_addr.s_addr = inet_addr(real_remote_addr);
570 + s.plain.sa_family = (s.ipv4.sin_addr.s_addr == 0xFFFFFFFF) ? AF_UNSPEC : AF_INET;
572 + if (s.plain.sa_family != AF_UNSPEC)
574 + /* we found the remote address, modify current connection and save the old address */
575 + if (con->plugin_ctx[p->id]) {
576 + log_error_write(srv, __FILE__, __LINE__,"patching an already patched connection!");
577 + handler_ctx_free(con->plugin_ctx[p->id]);
578 + con->plugin_ctx[p->id] = NULL;
580 + /* save old address */
581 + con->plugin_ctx[p->id] = handler_ctx_init(con->dst_addr, con->dst_addr_buf);
582 + /* patch connection address */
584 + con->dst_addr_buf = buffer_init();
585 + buffer_copy_string(con->dst_addr_buf, real_remote_addr);
586 +/* log_error_write(srv, __FILE__, __LINE__,"ss","Set dst_addr_buf to ", real_remote_addr); */
587 + /* Now, clean the conf_cond cache, because we may have changed the results of tests */
588 + clean_cond_cache(srv, con);
591 + if (addrlist != NULL ) freeaddrinfo(addrlist);
594 + array_free(forward_array);
598 + return HANDLER_GO_ON;
601 +CONNECTION_FUNC(mod_extforward_restore) {
602 + plugin_data *p = p_d;
605 + /* LEM: This seems completely unuseful, as we are not using
606 + p->conf in this function. Furthermore, it brings a
607 + segfault if one of the conditional configuration
608 + blocks is "SERVER['socket'] == foo", because the
609 + socket is not known yet in the srv/con structure.
611 + /* mod_extforward_patch_connection(srv, con, p); */
613 + /* restore this connection's remote ip */
614 + if (con->plugin_ctx[p->id]) {
615 + handler_ctx *hctx = con->plugin_ctx[p->id];
616 + con->dst_addr = hctx->saved_remote_addr;
617 + buffer_free(con->dst_addr_buf);
618 + con->dst_addr_buf = hctx->saved_remote_addr_buf;
619 +/* log_error_write(srv, __FILE__, __LINE__,"s","LEM: Reset dst_addr_buf"); */
620 + handler_ctx_free(hctx);
621 + con->plugin_ctx[p->id] = NULL;
622 + /* Now, clean the conf_cond cache, because we may have changed the results of tests */
623 + clean_cond_cache(srv, con);
625 + return HANDLER_GO_ON;
629 +/* this function is called at dlopen() time and inits the callbacks */
631 +int mod_extforward_plugin_init(plugin *p) {
632 + p->version = LIGHTTPD_VERSION_ID;
633 + p->name = buffer_init_string("extforward");
635 + p->init = mod_extforward_init;
636 + p->handle_uri_raw = mod_extforward_uri_handler;
637 + p->handle_request_done = mod_extforward_restore;
638 + p->connection_reset = mod_extforward_restore;
639 + p->set_defaults = mod_extforward_set_defaults;
640 + p->cleanup = mod_extforward_free;
648 Property changes on: src/mod_extforward.c
649 ___________________________________________________________________
653 Index: src/Makefile.am
654 ===================================================================
655 --- src/Makefile.am (.../tags/lighttpd-1.4.13) (revision 1706)
656 +++ src/Makefile.am (.../branches/lighttpd-1.4.x) (revision 1706)
658 mod_fastcgi_la_LDFLAGS = -module -export-dynamic -avoid-version -no-undefined
659 mod_fastcgi_la_LIBADD = $(common_libadd)
661 +lib_LTLIBRARIES += mod_extforward.la
662 +mod_extforward_la_SOURCES = mod_extforward.c
663 +mod_extforward_la_LDFLAGS = -module -export-dynamic -avoid-version -no-undefined
664 +mod_extforward_la_LIBADD = $(common_libadd)
666 lib_LTLIBRARIES += mod_access.la
667 mod_access_la_SOURCES = mod_access.c
668 mod_access_la_LDFLAGS = -module -export-dynamic -avoid-version -no-undefined
669 Index: src/network_writev.c
670 ===================================================================
671 --- src/network_writev.c (.../tags/lighttpd-1.4.13) (revision 1706)
672 +++ src/network_writev.c (.../branches/lighttpd-1.4.x) (revision 1706)
674 const size_t max_chunks = MAX_IOVEC;
675 #elif defined(UIO_MAXIOV) /* Linux x86 (glibc-2.2.5-233) */
676 const size_t max_chunks = UIO_MAXIOV;
677 -#elif (defined(__FreeBSD__) && __FreeBSD_version < 500000) /* FreeBSD 4.x */
678 +#elif (defined(__FreeBSD__) && __FreeBSD_version < 500000) || defined(__DragonFly__) /* FreeBSD 4.x */
679 const size_t max_chunks = 1024; /* UIO_MAXIOV value from sys/uio.h */
681 #error "sysconf() doesnt return _SC_IOV_MAX ..., check the output of 'man writev' for the EINVAL error and send the output to jan@kneschke.de"
682 Index: src/mod_expire.c
683 ===================================================================
684 --- src/mod_expire.c (.../tags/lighttpd-1.4.13) (revision 1706)
685 +++ src/mod_expire.c (.../branches/lighttpd-1.4.x) (revision 1706)
690 - * '(access|modification) [plus] {<num> <type>}*'
691 + * '(access|now|modification) [plus] {<num> <type>}*'
693 * e.g. 'access 1 years'
696 if (0 == strncmp(ts, "access ", 7)) {
699 + } else if (0 == strncmp(ts, "now ", 4)) {
702 } else if (0 == strncmp(ts, "modification ", 13)) {
709 - /* the rest is just <number> (years|months|days|hours|minutes|seconds) */
710 + /* the rest is just <number> (years|months|weeks|days|hours|minutes|seconds) */
715 } else if (slen == 6 &&
716 0 == strncmp(ts, "months", slen)) {
717 num *= 60 * 60 * 24 * 30;
718 + } else if (slen == 5 &&
719 + 0 == strncmp(ts, "weeks", slen)) {
720 + num *= 60 * 60 * 24 * 7;
721 } else if (slen == 4 &&
722 0 == strncmp(ts, "days", slen)) {
725 num *= 60 * 60 * 24 * 30 * 12;
726 } else if (0 == strcmp(ts, "months")) {
727 num *= 60 * 60 * 24 * 30;
728 + } else if (0 == strcmp(ts, "weeks")) {
729 + num *= 60 * 60 * 24 * 7;
730 } else if (0 == strcmp(ts, "days")) {
732 } else if (0 == strcmp(ts, "hours")) {
733 Index: src/network_freebsd_sendfile.c
734 ===================================================================
735 --- src/network_freebsd_sendfile.c (.../tags/lighttpd-1.4.13) (revision 1706)
736 +++ src/network_freebsd_sendfile.c (.../branches/lighttpd-1.4.x) (revision 1706)
742 +# if defined(__FreeBSD__) || defined(__DragonFly__)
743 /* FreeBSD 4.7, 4.9 defined it in sys/uio.h only if _KERNEL is specified */
744 # define UIO_MAXIOV 1024
746 Index: src/http_auth.c
747 ===================================================================
748 --- src/http_auth.c (.../tags/lighttpd-1.4.13) (revision 1706)
749 +++ src/http_auth.c (.../branches/lighttpd-1.4.x) (revision 1706)
754 + if (p->conf.auth_ldap_allow_empty_pw != 1 && pw[0] == '\0')
759 buffer_copy_string_buffer(p->ldap_filter, p->conf.ldap_filter_pre);
760 buffer_append_string_buffer(p->ldap_filter, username);
761 Index: src/http_auth.h
762 ===================================================================
763 --- src/http_auth.h (.../tags/lighttpd-1.4.13) (revision 1706)
764 +++ src/http_auth.h (.../branches/lighttpd-1.4.x) (revision 1706)
766 buffer *auth_ldap_filter;
767 buffer *auth_ldap_cafile;
768 unsigned short auth_ldap_starttls;
769 + unsigned short auth_ldap_allow_empty_pw;
771 unsigned short auth_debug;
773 Index: src/mod_auth.c
774 ===================================================================
775 --- src/mod_auth.c (.../tags/lighttpd-1.4.13) (revision 1706)
776 +++ src/mod_auth.c (.../branches/lighttpd-1.4.x) (revision 1706)
778 PATCH(auth_ldap_filter);
779 PATCH(auth_ldap_cafile);
780 PATCH(auth_ldap_starttls);
781 + PATCH(auth_ldap_allow_empty_pw);
784 PATCH(ldap_filter_pre);
786 PATCH(auth_ldap_cafile);
787 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("auth.backend.ldap.starttls"))) {
788 PATCH(auth_ldap_starttls);
789 + } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("auth.backend.ldap.allow-empty-pw"))) {
790 + PATCH(auth_ldap_allow_empty_pw);
795 { "auth.backend.ldap.starttls", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION },
796 { "auth.backend.ldap.bind-dn", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION },
797 { "auth.backend.ldap.bind-pw", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, /* 10 */
798 + { "auth.backend.ldap.allow-empty-pw", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION },
799 { "auth.backend.htdigest.userfile", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION },
800 { "auth.backend.htpasswd.userfile", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION },
801 { "auth.debug", NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION }, /* 13 */
802 @@ -359,11 +363,12 @@
803 cv[6].destination = s->auth_ldap_filter;
804 cv[7].destination = s->auth_ldap_cafile;
805 cv[8].destination = &(s->auth_ldap_starttls);
806 - cv[9].destination = s->auth_ldap_binddn;
807 - cv[10].destination = s->auth_ldap_bindpw;
808 - cv[11].destination = s->auth_htdigest_userfile;
809 - cv[12].destination = s->auth_htpasswd_userfile;
810 - cv[13].destination = &(s->auth_debug);
811 + cv[9].destination = s->auth_ldap_binddn;
812 + cv[10].destination = s->auth_ldap_bindpw;
813 + cv[11].destination = &(s->auth_ldap_allow_empty_pw);
814 + cv[12].destination = s->auth_htdigest_userfile;
815 + cv[13].destination = s->auth_htpasswd_userfile;
816 + cv[14].destination = &(s->auth_debug);
818 p->config_storage[i] = s;
819 ca = ((data_config *)srv->config_context->data[i])->value;
820 Index: src/mod_fastcgi.c
821 ===================================================================
822 --- src/mod_fastcgi.c (.../tags/lighttpd-1.4.13) (revision 1706)
823 +++ src/mod_fastcgi.c (.../branches/lighttpd-1.4.x) (revision 1706)
825 buffer *key; /* like .php */
830 fcgi_extension_host **hosts;
833 fe = calloc(1, sizeof(*fe));
835 fe->key = buffer_init();
836 + fe->last_used_ndx = -1;
837 buffer_copy_string_buffer(fe->key, key);
840 @@ -2365,6 +2367,7 @@
841 * check how much we have to read
843 if (ioctl(hctx->fd, FIONREAD, &toread)) {
844 + if (errno == EAGAIN) return 0;
845 log_error_write(srv, __FILE__, __LINE__, "sd",
846 "unexpected end-of-file (perhaps the fastcgi process died):",
848 @@ -2375,12 +2378,23 @@
852 + chunk *cq_first = hctx->rb->first;
853 + chunk *cq_last = hctx->rb->last;
855 b = chunkqueue_get_append_buffer(hctx->rb);
856 buffer_prepare_copy(b, toread + 1);
858 /* append to read-buffer */
859 if (-1 == (r = read(hctx->fd, b->ptr, toread))) {
860 + if (errno == EAGAIN) {
861 + /* roll back the last chunk allocation,
862 + and continue on next iteration */
863 + buffer_free(hctx->rb->last->mem);
864 + free(hctx->rb->last);
865 + hctx->rb->first = cq_first;
866 + hctx->rb->last = cq_last;
869 log_error_write(srv, __FILE__, __LINE__, "sds",
870 "unexpected end-of-file (perhaps the fastcgi process died):",
871 fcgi_fd, strerror(errno));
872 @@ -2393,6 +2407,7 @@
873 b->used = r + 1; /* one extra for the fake \0 */
874 b->ptr[b->used - 1] = '\0';
876 + if (errno == EAGAIN) return 0;
877 log_error_write(srv, __FILE__, __LINE__, "ssdsb",
878 "unexpected end-of-file (perhaps the fastcgi process died):",
880 @@ -2499,6 +2514,8 @@
884 + if (packet.len == 0) break;
886 log_error_write(srv, __FILE__, __LINE__, "sb",
887 "FastCGI-stderr:", packet.b);
889 @@ -2979,17 +2996,23 @@
893 - /* get best server */
894 - for (k = 0, ndx = -1; k < hctx->ext->used; k++) {
895 - host = hctx->ext->hosts[k];
896 + /* check if the next server has no load. */
897 + ndx = hctx->ext->last_used_ndx + 1;
898 + if(ndx >= hctx->ext->used || ndx < 0) ndx = 0;
899 + host = hctx->ext->hosts[ndx];
900 + if (host->load > 0) {
901 + /* get backend with the least load. */
902 + for (k = 0, ndx = -1; k < hctx->ext->used; k++) {
903 + host = hctx->ext->hosts[k];
905 - /* we should have at least one proc that can do something */
906 - if (host->active_procs == 0) continue;
907 + /* we should have at least one proc that can do something */
908 + if (host->active_procs == 0) continue;
910 - if (used == -1 || host->load < used) {
912 + if (used == -1 || host->load < used) {
921 @@ -3005,6 +3028,7 @@
922 return HANDLER_FINISHED;
925 + hctx->ext->last_used_ndx = ndx;
926 host = hctx->ext->hosts[ndx];
930 ===================================================================
931 --- src/server.c (.../tags/lighttpd-1.4.13) (revision 1706)
932 +++ src/server.c (.../branches/lighttpd-1.4.x) (revision 1706)
936 for (i = 0; i < FILE_CACHE_MAX; i++) {
937 + srv->mtime_cache[i].mtime = (time_t)-1;
938 srv->mtime_cache[i].str = buffer_init();
941 @@ -1231,6 +1232,19 @@
944 /* network_close() will cleanup after us */
946 + if (srv->srvconf.pid_file->used &&
947 + srv->srvconf.changeroot->used == 0) {
948 + if (0 != unlink(srv->srvconf.pid_file->ptr)) {
949 + if (errno != EACCES && errno != EPERM) {
950 + log_error_write(srv, __FILE__, __LINE__, "sbds",
951 + "unlink failed for:",
952 + srv->srvconf.pid_file,
961 @@ -1335,7 +1349,8 @@
964 if (srv->srvconf.pid_file->used &&
965 - srv->srvconf.changeroot->used == 0) {
966 + srv->srvconf.changeroot->used == 0 &&
967 + 0 == graceful_shutdown) {
968 if (0 != unlink(srv->srvconf.pid_file->ptr)) {
969 if (errno != EACCES && errno != EPERM) {
970 log_error_write(srv, __FILE__, __LINE__, "sbds",
971 Index: doc/extforward.txt
972 ===================================================================
973 --- doc/extforward.txt (.../tags/lighttpd-1.4.13) (revision 0)
974 +++ doc/extforward.txt (.../branches/lighttpd-1.4.x) (revision 1706)
985 +Comman Kang <comman.kang at gmail.com> sent me: ::
989 + I've made something rough but similar to mod_extract_forwarded for
990 + Apache. This module will extract the client's "real" ip from
991 + X-Forwarded-For header which is added by squid or other proxies. It might be
992 + useful for servers behind reverse proxy servers.
994 + However, this module is causing segfault with mod_ssl or
995 + $HTTP{''socket"} directive, crashing in config_check_cond while patching
996 + connection , I do not understand architecture of the lighttpd well, does it
997 + need to call patch_connection in either handle_request_done and
1000 +Lionel Elie Mamane <lionel@mamane.lu> improved the patch: ::
1002 + I've taken lighttpd-1.4.10-mod_extforward.c from the wiki and I've
1003 + extended it. Here is the result.
1009 + - Fixed at least one segfault with SERVER['socket']
1011 + - Arrange things so that a url.access-deny under scope of a
1012 + HTTP['remoteip'] condition works well :)
1014 + I've commented the code in some places, mostly where I wasn't sure
1015 + what was going on, or I didn't see what the original author meant to
1021 +extforward.forwarder
1022 + Sets trust level of proxy IP's.
1028 + extforward.forwarder = ("10.0.0.232" => "trust")
1030 + will translate ip addresses coming from 10.0.0.232 to real ip addresses extracted from X-Forwarded-For: HTTP request header.
1035 +The effect of this module is variable on $HTTP["remotip"] directives and other module's remote ip dependent actions.
1036 +Things done by modules before we change the remoteip or after we reset it will match on the proxy's IP.
1037 +Things done in between these two moments will match on the real client's IP.
1038 +The moment things are done by a module depends on in which hook it does things and within the same hook
1039 +on whether they are before/after us in the module loading order
1040 +(order in the server.modules directive in the config file).
1044 + mod_access: Will match on the real client.
1047 + In order to see the "real" ip address in access log ,
1048 + you'll have to load mod_extforward after mod_accesslog.
1051 + server.modules = (
1060 +Trust proxy 10.0.0.232 and 10.0.0.232 ::
1062 + extforward.forwarder = (
1063 + "10.0.0.232" => "trust",
1064 + "10.0.0.233" => "trust",
1067 +Trust all proxies (NOT RECOMMENDED!) ::
1069 + extforward.forwarder = ( "all" => "trust")
1071 +Note that "all" has precedence over specific entries, so "all except" setups will not work.
1072 Index: doc/Makefile.am
1073 ===================================================================
1074 --- doc/Makefile.am (.../tags/lighttpd-1.4.13) (revision 1706)
1075 +++ doc/Makefile.am (.../branches/lighttpd-1.4.x) (revision 1706)
1087 configuration.html \
1089 fastcgi-state.html \
1093 ===================================================================
1094 --- NEWS (.../tags/lighttpd-1.4.13) (revision 1706)
1095 +++ NEWS (.../branches/lighttpd-1.4.x) (revision 1706)
1101 + * added mod_extforward module [1665]
1103 - 1.4.13 - 2006-10-09
1105 * added initgroups in spawn-fcgi (#871)
1107 Property changes on: .
1108 ___________________________________________________________________
1110 + a98e19e4-a712-0410-8832-6551a15ffc53:/local/branches/lighttpd-1.4.x:1557