Ticket #646: path-elements-1.4.9.diff

File path-elements-1.4.9.diff, 2.9 kB (added by melo, 2 years ago)

diff against 1.4.9: path-elements is used instead of path_elements

  • src/mod_secure_download.c

    old new  
    3838        buffer *uri_prefix; 
    3939         
    4040        unsigned short timeout; 
     41        unsigned short path_elements; 
    4142} plugin_config; 
    4243 
    4344typedef struct { 
     
    100101                { "secdownload.document-root",     NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION },       /* 1 */ 
    101102                { "secdownload.uri-prefix",        NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION },       /* 2 */ 
    102103                { "secdownload.timeout",           NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION },        /* 3 */ 
     104                { "secdownload.path-elements",     NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION },        /* 4 */ 
    103105                { NULL,                            NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET } 
    104106        }; 
    105107         
     
    115117                s->doc_root      = buffer_init(); 
    116118                s->uri_prefix    = buffer_init(); 
    117119                s->timeout       = 60; 
     120                s->path_elements = 0; 
    118121                 
    119122                cv[0].destination = s->secret; 
    120123                cv[1].destination = s->doc_root; 
    121124                cv[2].destination = s->uri_prefix; 
    122125                cv[3].destination = &(s->timeout); 
     126                cv[4].destination = &(s->path_elements); 
    123127                 
    124128                p->config_storage[i] = s; 
    125129         
     
    166170        PATCH(doc_root); 
    167171        PATCH(uri_prefix); 
    168172        PATCH(timeout); 
     173        PATCH(path_elements); 
    169174         
    170175        /* skip the first, the global context */ 
    171176        for (i = 1; i < srv->config_context->used; i++) { 
     
    187192                                PATCH(uri_prefix); 
    188193                        } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("secdownload.timeout"))) { 
    189194                                PATCH(timeout); 
     195                        } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("secdownload.path-elements"))) { 
     196                                PATCH(path_elements); 
    190197                        } 
    191198                } 
    192199        } 
     
    200207        plugin_data *p = p_d; 
    201208        MD5_CTX Md5Ctx; 
    202209        HASH HA1; 
    203         const char *rel_uri, *ts_str, *md5_str; 
     210        const char *rel_uri, *rel_uri_end, *ts_str, *md5_str; 
    204211        time_t ts = 0; 
    205         size_t i; 
     212        size_t i, rel_uri_len, count; 
    206213         
    207214        if (con->uri.path->used == 0) return HANDLER_GO_ON; 
    208215         
     
    251258        } 
    252259         
    253260        rel_uri = ts_str + 8; 
     261        rel_uri_end = 0; 
     262 
     263        count = p->conf.path_elements; 
     264        if (count) { 
     265          rel_uri_end = rel_uri; 
     266          while (rel_uri_end && *rel_uri_end && count--) { 
     267            rel_uri_end = strchr(rel_uri_end+1, '/'); 
     268          } 
     269        } 
     270        if (rel_uri_end) { 
     271          log_error_write(srv, __FILE__, __LINE__, "ss", "full local_path: ", rel_uri); 
     272          log_error_write(srv, __FILE__, __LINE__, "ss", "discarding: ", rel_uri_end); 
     273          rel_uri_len = rel_uri_end - rel_uri; 
     274        } 
     275        else { 
     276          log_error_write(srv, __FILE__, __LINE__, "ss", "checking will be done with full local_path: ", rel_uri); 
     277          rel_uri_len = strlen(rel_uri); 
     278        } 
    254279         
    255280        /* checking MD5  
    256281         *  
     
    258283         */ 
    259284         
    260285        buffer_copy_string_buffer(p->md5, p->conf.secret); 
    261         buffer_append_string(p->md5, rel_uri); 
     286        buffer_append_string_len(p->md5, rel_uri, rel_uri_len); 
    262287        buffer_append_string_len(p->md5, ts_str, 8); 
    263288         
    264289        MD5_Init(&Md5Ctx);