Ticket #646: path-elements-1.4.9.diff
| File path-elements-1.4.9.diff, 2.9 kB (added by melo, 2 years ago) |
|---|
-
src/mod_secure_download.c
old new 38 38 buffer *uri_prefix; 39 39 40 40 unsigned short timeout; 41 unsigned short path_elements; 41 42 } plugin_config; 42 43 43 44 typedef struct { … … 100 101 { "secdownload.document-root", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, /* 1 */ 101 102 { "secdownload.uri-prefix", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, /* 2 */ 102 103 { "secdownload.timeout", NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION }, /* 3 */ 104 { "secdownload.path-elements", NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION }, /* 4 */ 103 105 { NULL, NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET } 104 106 }; 105 107 … … 115 117 s->doc_root = buffer_init(); 116 118 s->uri_prefix = buffer_init(); 117 119 s->timeout = 60; 120 s->path_elements = 0; 118 121 119 122 cv[0].destination = s->secret; 120 123 cv[1].destination = s->doc_root; 121 124 cv[2].destination = s->uri_prefix; 122 125 cv[3].destination = &(s->timeout); 126 cv[4].destination = &(s->path_elements); 123 127 124 128 p->config_storage[i] = s; 125 129 … … 166 170 PATCH(doc_root); 167 171 PATCH(uri_prefix); 168 172 PATCH(timeout); 173 PATCH(path_elements); 169 174 170 175 /* skip the first, the global context */ 171 176 for (i = 1; i < srv->config_context->used; i++) { … … 187 192 PATCH(uri_prefix); 188 193 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("secdownload.timeout"))) { 189 194 PATCH(timeout); 195 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("secdownload.path-elements"))) { 196 PATCH(path_elements); 190 197 } 191 198 } 192 199 } … … 200 207 plugin_data *p = p_d; 201 208 MD5_CTX Md5Ctx; 202 209 HASH HA1; 203 const char *rel_uri, * ts_str, *md5_str;210 const char *rel_uri, *rel_uri_end, *ts_str, *md5_str; 204 211 time_t ts = 0; 205 size_t i ;212 size_t i, rel_uri_len, count; 206 213 207 214 if (con->uri.path->used == 0) return HANDLER_GO_ON; 208 215 … … 251 258 } 252 259 253 260 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 } 254 279 255 280 /* checking MD5 256 281 * … … 258 283 */ 259 284 260 285 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); 262 287 buffer_append_string_len(p->md5, ts_str, 8); 263 288 264 289 MD5_Init(&Md5Ctx);

