diff options
Diffstat (limited to 'src/mod_userdir.c')
-rw-r--r-- | src/mod_userdir.c | 102 |
1 files changed, 51 insertions, 51 deletions
diff --git a/src/mod_userdir.c b/src/mod_userdir.c index 9612fa8..2fef0f2 100644 --- a/src/mod_userdir.c +++ b/src/mod_userdir.c @@ -25,54 +25,54 @@ typedef struct { typedef struct { PLUGIN_DATA; - + buffer *username; buffer *temp_path; - + plugin_config **config_storage; - - plugin_config conf; + + plugin_config conf; } plugin_data; /* init the plugin data */ INIT_FUNC(mod_userdir_init) { plugin_data *p; - + p = calloc(1, sizeof(*p)); - + p->username = buffer_init(); p->temp_path = buffer_init(); - + return p; } /* detroy the plugin data */ FREE_FUNC(mod_userdir_free) { plugin_data *p = p_d; - + if (!p) return HANDLER_GO_ON; - + if (p->config_storage) { size_t i; - + for (i = 0; i < srv->config_context->used; i++) { plugin_config *s = p->config_storage[i]; - + array_free(s->include_user); array_free(s->exclude_user); buffer_free(s->path); buffer_free(s->basepath); - + free(s); } free(p->config_storage); } - + buffer_free(p->username); buffer_free(p->temp_path); - + free(p); - + return HANDLER_GO_ON; } @@ -81,40 +81,40 @@ FREE_FUNC(mod_userdir_free) { SETDEFAULTS_FUNC(mod_userdir_set_defaults) { plugin_data *p = p_d; size_t i; - - config_values_t cv[] = { + + config_values_t cv[] = { { "userdir.path", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, /* 0 */ { "userdir.exclude-user", NULL, T_CONFIG_ARRAY, T_CONFIG_SCOPE_CONNECTION }, /* 1 */ { "userdir.include-user", NULL, T_CONFIG_ARRAY, T_CONFIG_SCOPE_CONNECTION }, /* 2 */ { "userdir.basepath", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION }, /* 3 */ { NULL, NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET } }; - + if (!p) return HANDLER_ERROR; - + p->config_storage = calloc(1, srv->config_context->used * sizeof(specific_config *)); - + for (i = 0; i < srv->config_context->used; i++) { plugin_config *s; - + s = calloc(1, sizeof(plugin_config)); s->exclude_user = array_init(); s->include_user = array_init(); s->path = buffer_init(); s->basepath = buffer_init(); - + cv[0].destination = s->path; cv[1].destination = s->exclude_user; cv[2].destination = s->include_user; cv[3].destination = s->basepath; - + p->config_storage[i] = s; - + if (0 != config_insert_values_global(srv, ((data_config *)srv->config_context->data[i])->value, cv)) { return HANDLER_ERROR; } } - + return HANDLER_GO_ON; } @@ -123,24 +123,24 @@ SETDEFAULTS_FUNC(mod_userdir_set_defaults) { static int mod_userdir_patch_connection(server *srv, connection *con, plugin_data *p) { size_t i, j; plugin_config *s = p->config_storage[0]; - + PATCH(path); PATCH(exclude_user); PATCH(include_user); PATCH(basepath); - + /* skip the first, the global context */ for (i = 1; i < srv->config_context->used; i++) { data_config *dc = (data_config *)srv->config_context->data[i]; s = p->config_storage[i]; - + /* condition didn't match */ if (!config_check_cond(srv, con, dc)) continue; - + /* merge config */ for (j = 0; j < dc->value->used; j++) { data_unset *du = dc->value->data[j]; - + if (buffer_is_equal_string(du->key, CONST_STR_LEN("userdir.path"))) { PATCH(path); } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("userdir.exclude-user"))) { @@ -152,7 +152,7 @@ static int mod_userdir_patch_connection(server *srv, connection *con, plugin_dat } } } - + return 0; } #undef PATCH @@ -169,18 +169,18 @@ URIHANDLER_FUNC(mod_userdir_docroot_handler) { if (con->uri.path->used == 0) return HANDLER_GO_ON; mod_userdir_patch_connection(srv, con, p); - + uri_len = con->uri.path->used - 1; - + /* /~user/foo.html -> /home/user/public_html/foo.html */ - + if (con->uri.path->ptr[0] != '/' || con->uri.path->ptr[1] != '~') return HANDLER_GO_ON; - + if (NULL == (rel_url = strchr(con->uri.path->ptr + 2, '/'))) { /* / is missing -> redirect to .../ as we are a user - DIRECTORY ! :) */ http_response_redirect_to_directory(srv, con); - + return HANDLER_FINISHED; } @@ -188,10 +188,10 @@ URIHANDLER_FUNC(mod_userdir_docroot_handler) { if (0 == rel_url - (con->uri.path->ptr + 2)) { return HANDLER_GO_ON; } - + 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_is_empty(p->conf.basepath) #ifdef HAVE_PWD_H && NULL == (pwd = getpwnam(p->username->ptr)) #endif @@ -200,31 +200,31 @@ URIHANDLER_FUNC(mod_userdir_docroot_handler) { return HANDLER_GO_ON; } - + for (k = 0; k < p->conf.exclude_user->used; k++) { data_string *ds = (data_string *)p->conf.exclude_user->data[k]; - + if (buffer_is_equal(ds->value, p->username)) { /* user in exclude list */ return HANDLER_GO_ON; } } - + if (p->conf.include_user->used) { int found_user = 0; for (k = 0; k < p->conf.include_user->used; k++) { data_string *ds = (data_string *)p->conf.include_user->data[k]; - + if (buffer_is_equal(ds->value, p->username)) { /* user in include list */ found_user = 1; break; } } - + if (!found_user) return HANDLER_GO_ON; } - + /* we build the physical path */ if (buffer_is_empty(p->conf.basepath)) { @@ -256,16 +256,16 @@ URIHANDLER_FUNC(mod_userdir_docroot_handler) { buffer_append_string_buffer(p->temp_path, p->username); } 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)) { struct stat st; int ret; - + ret = stat(p->temp_path->ptr, &st); if (ret < 0 || S_ISDIR(st.st_mode) != 1) { return HANDLER_GO_ON; - } + } } BUFFER_APPEND_SLASH(p->temp_path); @@ -282,13 +282,13 @@ URIHANDLER_FUNC(mod_userdir_docroot_handler) { int mod_userdir_plugin_init(plugin *p) { p->version = LIGHTTPD_VERSION_ID; p->name = buffer_init_string("userdir"); - + p->init = mod_userdir_init; p->handle_physical = mod_userdir_docroot_handler; p->set_defaults = mod_userdir_set_defaults; p->cleanup = mod_userdir_free; - + p->data = NULL; - + return 0; } |