summaryrefslogtreecommitdiff
path: root/src/mod_access.c
diff options
context:
space:
mode:
authorGlenn Strauss <gstrauss@gluelogic.com>2018-09-16 17:27:54 -0400
committerGlenn Strauss <gstrauss@gluelogic.com>2018-09-23 18:01:58 -0400
commitd61f33817cc79e00e7b0fedbd8f2692160fe24e5 (patch)
tree7fcef28a5f2884329e416903b419148a6be4108c /src/mod_access.c
parent863dff6191139a24b1bfaedf4904bf81a7ca7c0b (diff)
downloadlighttpd-git-d61f33817cc79e00e7b0fedbd8f2692160fe24e5.tar.gz
[multiple] code reuse: employ array_match_*()
Diffstat (limited to 'src/mod_access.c')
-rw-r--r--src/mod_access.c65
1 files changed, 11 insertions, 54 deletions
diff --git a/src/mod_access.c b/src/mod_access.c
index 3c36e404..1377c854 100644
--- a/src/mod_access.c
+++ b/src/mod_access.c
@@ -146,46 +146,23 @@ static int mod_access_patch_connection(server *srv, connection *con, plugin_data
*/
URIHANDLER_FUNC(mod_access_uri_handler) {
plugin_data *p = p_d;
- int s_len;
- size_t k;
+ const buffer *match;
if (buffer_is_empty(con->uri.path)) return HANDLER_GO_ON;
mod_access_patch_connection(srv, con, p);
- s_len = buffer_string_length(con->uri.path);
-
if (con->conf.log_request_handling) {
log_error_write(srv, __FILE__, __LINE__, "s",
"-- mod_access_uri_handler called");
}
- for (k = 0; k < p->conf.access_allow->used; ++k) {
- data_string *ds = (data_string *)p->conf.access_allow->data[k];
- int ct_len = buffer_string_length(ds->value);
- int allowed = 0;
-
- if (ct_len > s_len) continue;
- if (buffer_is_empty(ds->value)) continue;
-
- /* if we have a case-insensitive FS we have to lower-case the URI here too */
-
- if (con->conf.force_lowercase_filenames) {
- if (0 == strncasecmp(con->uri.path->ptr + s_len - ct_len, ds->value->ptr, ct_len)) {
- allowed = 1;
- }
- } else {
- if (0 == strncmp(con->uri.path->ptr + s_len - ct_len, ds->value->ptr, ct_len)) {
- allowed = 1;
- }
- }
-
- if (allowed) {
- return HANDLER_GO_ON;
- }
- }
+ match = (!con->conf.force_lowercase_filenames)
+ ? array_match_value_suffix(p->conf.access_allow, con->uri.path)
+ : array_match_value_suffix_nc(p->conf.access_allow, con->uri.path);
+ if (match) return HANDLER_GO_ON; /* allowed */
- if (k > 0) { /* have access_allow but none matched */
+ if (p->conf.access_allow->used) { /* have access_allow but none matched */
con->http_status = 403;
con->mode = DIRECT;
@@ -197,41 +174,21 @@ URIHANDLER_FUNC(mod_access_uri_handler) {
return HANDLER_FINISHED;
}
- for (k = 0; k < p->conf.access_deny->used; k++) {
- data_string *ds = (data_string *)p->conf.access_deny->data[k];
- int ct_len = buffer_string_length(ds->value);
- int denied = 0;
-
-
- if (ct_len > s_len) continue;
- if (buffer_is_empty(ds->value)) continue;
-
- /* if we have a case-insensitive FS we have to lower-case the URI here too */
-
- if (con->conf.force_lowercase_filenames) {
- if (0 == strncasecmp(con->uri.path->ptr + s_len - ct_len, ds->value->ptr, ct_len)) {
- denied = 1;
- }
- } else {
- if (0 == strncmp(con->uri.path->ptr + s_len - ct_len, ds->value->ptr, ct_len)) {
- denied = 1;
- }
- }
-
- if (denied) {
+ match = (!con->conf.force_lowercase_filenames)
+ ? array_match_value_suffix(p->conf.access_deny, con->uri.path)
+ : array_match_value_suffix_nc(p->conf.access_deny, con->uri.path);
+ if (match) { /* denied */
con->http_status = 403;
con->mode = DIRECT;
if (con->conf.log_request_handling) {
log_error_write(srv, __FILE__, __LINE__, "sb",
- "url denied as we match:", ds->value);
+ "url denied as we match:", match);
}
return HANDLER_FINISHED;
- }
}
- /* not found */
return HANDLER_GO_ON;
}