diff src/http/modules/ngx_http_access_module.c @ 626:a7a5fa2e395b NGINX_1_0_3

nginx 1.0.3 *) Feature: the "auth_basic_user_file" directive supports "$apr1", "{PLAIN}", and "{SSHA}" password encryption methods. Thanks to Maxim Dounin. *) Feature: the "geoip_org" directive and $geoip_org variable. Thanks to Alexander Uskov, Arnaud Granal, and Denis F. Latypoff. *) Feature: ngx_http_geo_module and ngx_http_geoip_module support IPv4 addresses mapped to IPv6 addresses. *) Bugfix: a segmentation fault occurred in a worker process during testing IPv4 address mapped to IPv6 address, if access or deny rules were defined only for IPv6; the bug had appeared in 0.8.22. *) Bugfix: a cached reponse may be broken if proxy/fastcgi/scgi/ uwsgi_cache_bypass and proxy/fastcgi/scgi/uwsgi_no_cache directive values were different; the bug had appeared in 0.8.46.
author Igor Sysoev <http://sysoev.ru>
date Wed, 25 May 2011 00:00:00 +0400
parents 53f5f04a64b8
children d0f7a625f27c
line wrap: on
line diff
--- a/src/http/modules/ngx_http_access_module.c
+++ b/src/http/modules/ngx_http_access_module.c
@@ -108,20 +108,30 @@ ngx_http_access_handler(ngx_http_request
 {
     struct sockaddr_in          *sin;
     ngx_http_access_loc_conf_t  *alcf;
+#if (NGX_HAVE_INET6)
+    u_char                      *p;
+    in_addr_t                    addr;
+    struct sockaddr_in6         *sin6;
+#endif
 
     alcf = ngx_http_get_module_loc_conf(r, ngx_http_access_module);
 
+    switch (r->connection->sockaddr->sa_family) {
+
+    case AF_INET:
+        if (alcf->rules) {
+            sin = (struct sockaddr_in *) r->connection->sockaddr;
+            return ngx_http_access_inet(r, alcf, sin->sin_addr.s_addr);
+        }
+        break;
+
 #if (NGX_HAVE_INET6)
 
-    if (alcf->rules6 && r->connection->sockaddr->sa_family == AF_INET6) {
-        u_char               *p;
-        in_addr_t             addr;
-        struct sockaddr_in6  *sin6;
-
+    case AF_INET6:
         sin6 = (struct sockaddr_in6 *) r->connection->sockaddr;
         p = sin6->sin6_addr.s6_addr;
 
-        if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
+        if (alcf->rules && IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
             addr = p[12] << 24;
             addr += p[13] << 16;
             addr += p[14] << 8;
@@ -129,14 +139,11 @@ ngx_http_access_handler(ngx_http_request
             return ngx_http_access_inet(r, alcf, htonl(addr));
         }
 
-        return ngx_http_access_inet6(r, alcf, p);
-    }
+        if (alcf->rules6) {
+            return ngx_http_access_inet6(r, alcf, p);
+        }
 
 #endif
-
-    if (alcf->rules && r->connection->sockaddr->sa_family == AF_INET) {
-        sin = (struct sockaddr_in *) r->connection->sockaddr;
-        return ngx_http_access_inet(r, alcf, sin->sin_addr.s_addr);
     }
 
     return NGX_DECLINED;