Directory permissions behavior changed?

Maxim Dounin mdounin at mdounin.ru
Fri Aug 8 13:33:11 MSD 2008


Hello!

On Fri, Aug 08, 2008 at 01:57:18AM -0700, mike wrote:

>More investigation:
>
>nginx-0.7.8/src/http/modules/ngx_http_index_module.c, line 137:
>
>for (i = 0; i < ilcf->indices->nelts; i++) {
>
>it shows the right number of nelts, but the for loop only cycles
>through once. it needs to cycle through all nelts of them!
>
>for example this is my code:
>
>
>    for (i = 0; i < ilcf->indices->nelts; i++) {
>
>            ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, of.err,
>                          ngx_open_file_n " MIKEMIKE: \"%s\" failed",
>index[i].name.data);
>
>            ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, of.err,
>                          ngx_open_file_n " MIKEMIKENUMBER: \"%d\"
>failed", ilcf->indices->nelts);
>
>and it shows the right number for MIKEMIKENUMBER - i changed my
>config, restarted, and it shows the right number of "index" entries.
>
>but the loop for some reason is being broken (it only prints out
>testing for the first one)
>
>i wish i knew C better; i can't find where the loop gets broken...
>
>but it keeps matching these kind of statements:
>
>if (index[i].lengths == NULL) {
>
>if (index[i].values == NULL) {
>
>and i wouldn't think those should be matched after the first
>iteration. Igor i think this is something you could easily hack out in
>a minute.

After failure of first index file lookup nginx tries to check if 
it really hit directory by stat()ing it.  With your 711 permissions 
it gets EACCESS here and fails.

Try the attached patch.

Maxim Dounin
-------------- next part --------------
diff --git a/src/http/modules/ngx_http_index_module.c b/src/http/modules/ngx_http_index_module.c
--- a/src/http/modules/ngx_http_index_module.c
+++ b/src/http/modules/ngx_http_index_module.c
@@ -309,6 +309,11 @@ ngx_http_index_test_dir(ngx_http_request
                 return ngx_http_index_error(r, dir.data, NGX_ENOENT);
             }
 
+            if (of.err == NGX_EACCES) {
+                *last = c;
+                return NGX_OK;
+            }
+
             ngx_log_error(NGX_LOG_CRIT, r->connection->log, of.err,
                           ngx_open_file_n " \"%s\" failed", dir.data);
         }


More information about the nginx mailing list