|
|
| version 1.1.1.2, 2014/06/15 20:20:06 | version 1.1.1.3, 2016/11/02 10:35:00 |
|---|---|
| Line 1 | Line 1 |
| #include "first.h" | |
| #include "base.h" | #include "base.h" |
| #include "log.h" | #include "log.h" |
| #include "buffer.h" | #include "buffer.h" |
| Line 60 FREE_FUNC(mod_userdir_free) { | Line 62 FREE_FUNC(mod_userdir_free) { |
| for (i = 0; i < srv->config_context->used; i++) { | for (i = 0; i < srv->config_context->used; i++) { |
| plugin_config *s = p->config_storage[i]; | plugin_config *s = p->config_storage[i]; |
| if (NULL == s) continue; | |
| array_free(s->include_user); | array_free(s->include_user); |
| array_free(s->exclude_user); | array_free(s->exclude_user); |
| buffer_free(s->path); | buffer_free(s->path); |
| Line 99 SETDEFAULTS_FUNC(mod_userdir_set_defaults) { | Line 103 SETDEFAULTS_FUNC(mod_userdir_set_defaults) { |
| p->config_storage = calloc(1, srv->config_context->used * sizeof(plugin_config *)); | p->config_storage = calloc(1, srv->config_context->used * sizeof(plugin_config *)); |
| for (i = 0; i < srv->config_context->used; i++) { | for (i = 0; i < srv->config_context->used; i++) { |
| data_config const* config = (data_config const*)srv->config_context->data[i]; | |
| plugin_config *s; | plugin_config *s; |
| s = calloc(1, sizeof(plugin_config)); | s = calloc(1, sizeof(plugin_config)); |
| Line 120 SETDEFAULTS_FUNC(mod_userdir_set_defaults) { | Line 125 SETDEFAULTS_FUNC(mod_userdir_set_defaults) { |
| p->config_storage[i] = s; | p->config_storage[i] = s; |
| if (0 != config_insert_values_global(srv, ((data_config *)srv->config_context->data[i])->value, cv)) { | if (0 != config_insert_values_global(srv, config->value, cv, i == 0 ? T_CONFIG_SCOPE_SERVER : T_CONFIG_SCOPE_CONNECTION)) { |
| return HANDLER_ERROR; | return HANDLER_ERROR; |
| } | } |
| } | } |
| Line 181 URIHANDLER_FUNC(mod_userdir_docroot_handler) { | Line 186 URIHANDLER_FUNC(mod_userdir_docroot_handler) { |
| struct passwd *pwd = NULL; | struct passwd *pwd = NULL; |
| #endif | #endif |
| if (con->uri.path->used == 0) return HANDLER_GO_ON; | if (buffer_is_empty(con->uri.path)) return HANDLER_GO_ON; |
| mod_userdir_patch_connection(srv, con, p); | mod_userdir_patch_connection(srv, con, p); |
| /* enforce the userdir.path to be set in the config, ugly fix for #1587; | /* enforce the userdir.path to be set in the config, ugly fix for #1587; |
| * should be replaced with a clean .enabled option in 1.5 | * should be replaced with a clean .enabled option in 1.5 |
| */ | */ |
| if (!p->conf.active || p->conf.path->used == 0) return HANDLER_GO_ON; | if (!p->conf.active || buffer_is_empty(p->conf.path)) return HANDLER_GO_ON; |
| /* /~user/foo.html -> /home/user/public_html/foo.html */ | /* /~user/foo.html -> /home/user/public_html/foo.html */ |
| Line 209 URIHANDLER_FUNC(mod_userdir_docroot_handler) { | Line 214 URIHANDLER_FUNC(mod_userdir_docroot_handler) { |
| buffer_copy_string_len(p->username, con->uri.path->ptr + 2, rel_url - (con->uri.path->ptr + 2)); | buffer_copy_string_len(p->username, con->uri.path->ptr + 2, rel_url - (con->uri.path->ptr + 2)); |
| if (buffer_is_empty(p->conf.basepath) | if (buffer_string_is_empty(p->conf.basepath) |
| #ifdef HAVE_PWD_H | #ifdef HAVE_PWD_H |
| && NULL == (pwd = getpwnam(p->username->ptr)) | && NULL == (pwd = getpwnam(p->username->ptr)) |
| #endif | #endif |
| Line 245 URIHANDLER_FUNC(mod_userdir_docroot_handler) { | Line 250 URIHANDLER_FUNC(mod_userdir_docroot_handler) { |
| /* we build the physical path */ | /* we build the physical path */ |
| if (buffer_is_empty(p->conf.basepath)) { | if (buffer_string_is_empty(p->conf.basepath)) { |
| #ifdef HAVE_PWD_H | #ifdef HAVE_PWD_H |
| buffer_copy_string(p->temp_path, pwd->pw_dir); | buffer_copy_string(p->temp_path, pwd->pw_dir); |
| #endif | #endif |
| Line 272 URIHANDLER_FUNC(mod_userdir_docroot_handler) { | Line 277 URIHANDLER_FUNC(mod_userdir_docroot_handler) { |
| buffer_to_lower(p->username); | buffer_to_lower(p->username); |
| } | } |
| buffer_copy_string_buffer(p->temp_path, p->conf.basepath); | buffer_copy_buffer(p->temp_path, p->conf.basepath); |
| BUFFER_APPEND_SLASH(p->temp_path); | buffer_append_slash(p->temp_path); |
| if (p->conf.letterhomes) { | if (p->conf.letterhomes) { |
| buffer_append_string_len(p->temp_path, p->username->ptr, 1); | buffer_append_string_len(p->temp_path, p->username->ptr, 1); |
| BUFFER_APPEND_SLASH(p->temp_path); | buffer_append_slash(p->temp_path); |
| } | } |
| buffer_append_string_buffer(p->temp_path, p->username); | buffer_append_string_buffer(p->temp_path, p->username); |
| } | } |
| BUFFER_APPEND_SLASH(p->temp_path); | buffer_append_slash(p->temp_path); |
| buffer_append_string_buffer(p->temp_path, p->conf.path); | buffer_append_string_buffer(p->temp_path, p->conf.path); |
| if (buffer_is_empty(p->conf.basepath)) { | if (buffer_string_is_empty(p->conf.basepath)) { |
| struct stat st; | struct stat st; |
| int ret; | int ret; |
| Line 293 URIHANDLER_FUNC(mod_userdir_docroot_handler) { | Line 298 URIHANDLER_FUNC(mod_userdir_docroot_handler) { |
| } | } |
| } | } |
| buffer_copy_string_buffer(con->physical.basedir, p->temp_path); | buffer_copy_buffer(con->physical.basedir, p->temp_path); |
| /* the physical rel_path is basically the same as uri.path; | /* the physical rel_path is basically the same as uri.path; |
| * but it is converted to lowercase in case of force_lowercase_filenames and some special handling | * but it is converted to lowercase in case of force_lowercase_filenames and some special handling |
| * for trailing '.', ' ' and '/' on windows | * for trailing '.', ' ' and '/' on windows |
| * we assume that no docroot/physical handler changed this | * we assume that no docroot/physical handler changed this |
| * (docroot should only set the docroot/server name, phyiscal should only change the phyiscal.path; | * (docroot should only set the docroot/server name, phyiscal should only change the phyiscal.path; |
| * the exception mod_secure_download doesn't work with userdir anyway) | * the exception mod_secdownload doesn't work with userdir anyway) |
| */ | */ |
| BUFFER_APPEND_SLASH(p->temp_path); | buffer_append_slash(p->temp_path); |
| /* if no second '/' is found, we assume that it was stripped from the uri.path for the special handling | /* if no second '/' is found, we assume that it was stripped from the uri.path for the special handling |
| * on windows. | * on windows. |
| * we do not care about the trailing slash here on windows, as we already ensured it is a directory | * we do not care about the trailing slash here on windows, as we already ensured it is a directory |
| Line 313 URIHANDLER_FUNC(mod_userdir_docroot_handler) { | Line 318 URIHANDLER_FUNC(mod_userdir_docroot_handler) { |
| if (NULL != (rel_url = strchr(con->physical.rel_path->ptr + 2, '/'))) { | if (NULL != (rel_url = strchr(con->physical.rel_path->ptr + 2, '/'))) { |
| buffer_append_string(p->temp_path, rel_url + 1); /* skip the / */ | buffer_append_string(p->temp_path, rel_url + 1); /* skip the / */ |
| } | } |
| buffer_copy_string_buffer(con->physical.path, p->temp_path); | buffer_copy_buffer(con->physical.path, p->temp_path); |
| buffer_reset(p->temp_path); | buffer_reset(p->temp_path); |