Ticket #430: auth.patch

File auth.patch, 5.3 kB (added by anonymous, 3 years ago)
  • src/mod_auth.c

    diff -urNp lighttpd-1.4.8/src/mod_auth.c lighttpd-new2/src/mod_auth.c
    old new  
    168168} 
    169169#undef PATCH 
    170170 
    171 static handler_t mod_auth_uri_handler(server *srv, connection *con, void *p_d) { 
     171static handler_t mod_auth_subrequest_handler(server *srv, connection *con, void *p_d) { 
    172172        size_t k; 
    173173        int auth_required = 0, auth_satisfied = 0; 
    174174        char *http_authorization = NULL; 
     
    193193         
    194194        /* search auth-directives for path */ 
    195195        for (k = 0; k < p->conf.auth_require->used; k++) { 
     196                data_string *use_physical; 
    196197                if (p->conf.auth_require->data[k]->key->used == 0) continue; 
    197                  
    198                 if (0 == strncmp(con->uri.path->ptr, p->conf.auth_require->data[k]->key->ptr, p->conf.auth_require->data[k]->key->used - 1)) { 
    199                         auth_required = 1; 
    200                         break; 
     198 
     199                req = ((data_array *)(p->conf.auth_require->data[k]))->value; 
     200                use_physical = (data_string *)array_get_element(req, "use_physical"); 
     201                if (con->physical.path != NULL && con->physical.path->ptr != NULL && use_physical != NULL &&  
     202                    use_physical->value->ptr != NULL && strcmp(use_physical->value->ptr, "yes") == 0) 
     203                { 
     204                    char resolved_path[PATH_MAX]; 
     205 
     206                    if (realpath(con->physical.path->ptr, resolved_path) == NULL) continue; 
     207                    if (strncmp(resolved_path, p->conf.auth_require->data[k]->key->ptr,  
     208                                p->conf.auth_require->data[k]->key->used - 1) == 0) 
     209                    { 
     210                        auth_required = 1; 
     211                        break; 
     212                    } 
     213                } 
     214                else if (0 == strncmp(con->uri.path->ptr, p->conf.auth_require->data[k]->key->ptr, p->conf.auth_require->data[k]->key->used - 1))  
     215                { 
     216                    data_string *authority; 
     217                    authority = (data_string *)array_get_element(req, "authority"); 
     218                    if (authority == NULL || authority->value->ptr == NULL || 
     219                        strcmp(authority->value->ptr, con->uri.authority->ptr) == 0) 
     220                    { 
     221                        auth_required = 1; 
     222                        break; 
     223                    } 
    201224                } 
    202225        } 
    203226         
     
    384407                for (n = 0; n < da->value->used; n++) { 
    385408                        size_t m; 
    386409                        data_array *da_file = (data_array *)da->value->data[n]; 
    387                         const char *method, *realm, *require; 
     410                        const char *method, *realm, *require, *authority, *use_physical; 
    388411                         
    389412                        if (da->value->data[n]->type != TYPE_ARRAY) { 
    390413                                log_error_write(srv, __FILE__, __LINE__, "sssbs",  
     
    393416                                return HANDLER_ERROR; 
    394417                        } 
    395418                                         
    396                         method = realm = require = NULL; 
     419                        method = realm = require = authority = use_physical = NULL; 
    397420                                         
    398421                        for (m = 0; m < da_file->value->used; m++) { 
    399422                                if (da_file->value->data[m]->type == TYPE_STRING) { 
     
    403426                                                realm = ((data_string *)(da_file->value->data[m]))->value->ptr; 
    404427                                        } else if (0 == strcmp(da_file->value->data[m]->key->ptr, "require")) { 
    405428                                                require = ((data_string *)(da_file->value->data[m]))->value->ptr; 
     429                                        } else if (0 == strcmp(da_file->value->data[m]->key->ptr, "authority")) { 
     430                                                authority = ((data_string *)(da_file->value->data[m]))->value->ptr; 
     431                                        } else if (0 == strcmp(da_file->value->data[m]->key->ptr, "use_physical")) { 
     432                                                use_physical = ((data_string *)(da_file->value->data[m]))->value->ptr; 
    406433                                        } else { 
    407434                                                log_error_write(srv, __FILE__, __LINE__, "sssbs", "unexpected type for key: ", "auth.require", "[", da_file->value->data[m]->key, "](string)"); 
    408435                                                return HANDLER_ERROR; 
     
    462489                                buffer_copy_string(ds->value, require); 
    463490                                 
    464491                                array_insert_unique(a->value, (data_unset *)ds); 
     492 
     493                                if (authority) 
     494                                { 
     495                                    ds = data_string_init(); 
     496 
     497                                    buffer_copy_string(ds->key, "authority"); 
     498                                    buffer_copy_string(ds->value, authority); 
     499 
     500                                    array_insert_unique(a->value, (data_unset *)ds); 
     501                                } 
     502 
     503                                if (use_physical) 
     504                                { 
     505                                    ds = data_string_init(); 
     506 
     507                                    buffer_copy_string(ds->key, "use_physical"); 
     508                                    buffer_copy_string(ds->value, use_physical); 
     509 
     510                                    array_insert_unique(a->value, (data_unset *)ds); 
     511                                } 
    465512                                 
    466513                                array_insert_unique(s->auth_require, (data_unset *)a); 
    467514                        } 
     
    609656        p->name        = buffer_init_string("auth"); 
    610657        p->init        = mod_auth_init; 
    611658        p->set_defaults = mod_auth_set_defaults; 
    612         p->handle_uri_clean = mod_auth_uri_handler; 
     659        p->handle_subrequest_start = mod_auth_subrequest_handler; 
    613660        p->cleanup     = mod_auth_free; 
    614661         
    615662        p->data        = NULL;