[PATCH] Upstream: path_access_rights and file_access_rights of proxy_cache_path and friends
Krzysztof Grzadziel
poczta at krzysztofgrzadziel.pl
Sun Jan 18 16:25:11 UTC 2015
# HG changeset patch
# User Krzysztof Grzadziel <poczta at krzysztofgrzadziel.pl>
# Date 1421595254 -3600
# Sun Jan 18 16:34:14 2015 +0100
# Node ID d43b6b438baf90b38bd6b95986527d40fc9a9d41
# Parent 0a198a517eaf48baad03a76b182698c50496d380
Upstream: path_access_rights and file_access_rights of proxy_cache_path and friends.
Add two optional parameters to proxy_cache_path and friends.
path_access_rights for set chmod for directories under cache path.
file_access_rights for set chmod for files under cache path.
diff -r 0a198a517eaf -r d43b6b438baf src/core/ngx_string.c
--- a/src/core/ngx_string.c Wed Jan 14 09:03:35 2015 +0300
+++ b/src/core/ngx_string.c Sun Jan 18 16:34:14 2015 +0100
@@ -1085,6 +1085,33 @@
}
+/* parse octal number string representation to integer */
+ngx_int_t
+ngx_octtoi(u_char *line, size_t n)
+{
+ ngx_int_t value;
+
+ if (n == 0) {
+ return NGX_ERROR;
+ }
+
+ for (value = 0; n--; line++) {
+ if (*line < '0' || *line > '7') {
+ return NGX_ERROR;
+ }
+
+ value = value * 8 + (*line - '0');
+ }
+
+ if (value < 0) {
+ return NGX_ERROR;
+
+ } else {
+ return value;
+ }
+}
+
+
u_char *
ngx_hex_dump(u_char *dst, u_char *src, size_t len)
{
diff -r 0a198a517eaf -r d43b6b438baf src/core/ngx_string.h
--- a/src/core/ngx_string.h Wed Jan 14 09:03:35 2015 +0300
+++ b/src/core/ngx_string.h Sun Jan 18 16:34:14 2015 +0100
@@ -175,6 +175,7 @@
off_t ngx_atoof(u_char *line, size_t n);
time_t ngx_atotm(u_char *line, size_t n);
ngx_int_t ngx_hextoi(u_char *line, size_t n);
+ngx_int_t ngx_octtoi(u_char *line, size_t n);
u_char *ngx_hex_dump(u_char *dst, u_char *src, size_t len);
diff -r 0a198a517eaf -r d43b6b438baf src/http/ngx_http_cache.h
--- a/src/http/ngx_http_cache.h Wed Jan 14 09:03:35 2015 +0300
+++ b/src/http/ngx_http_cache.h Sun Jan 18 16:34:14 2015 +0100
@@ -154,6 +154,9 @@
ngx_msec_t loader_sleep;
ngx_msec_t loader_threshold;
+ ngx_int_t file_access_rights;
+ ngx_int_t path_access_rights;
+
ngx_shm_zone_t *shm_zone;
ngx_uint_t use_temp_path;
diff -r 0a198a517eaf -r d43b6b438baf src/http/ngx_http_file_cache.c
--- a/src/http/ngx_http_file_cache.c Wed Jan 14 09:03:35 2015 +0300
+++ b/src/http/ngx_http_file_cache.c Sun Jan 18 16:34:14 2015 +0100
@@ -1268,8 +1268,8 @@
"http file cache rename: \"%s\" to \"%s\"",
tf->file.name.data, c->file.name.data);
- ext.access = NGX_FILE_OWNER_ACCESS;
- ext.path_access = NGX_FILE_OWNER_ACCESS;
+ ext.access = cache->file_access_rights;
+ ext.path_access = cache->path_access_rights;
ext.time = -1;
ext.create_path = 1;
ext.delete_file = 1;
@@ -2075,6 +2075,7 @@
ngx_int_t loader_files;
ngx_msec_t loader_sleep, loader_threshold;
ngx_uint_t i, n, use_temp_path;
+ ngx_int_t file_access_rights, path_access_rights;
ngx_array_t *caches;
ngx_http_file_cache_t *cache, **ce;
@@ -2094,6 +2095,8 @@
loader_files = 100;
loader_sleep = 50;
loader_threshold = 200;
+ file_access_rights = NGX_FILE_OWNER_ACCESS;
+ path_access_rights = NGX_FILE_OWNER_ACCESS;
name.len = 0;
size = 0;
@@ -2236,6 +2239,30 @@
continue;
}
+ if (ngx_strncmp(value[i].data, "file_access_rights=", 19) == 0) {
+
+ file_access_rights = ngx_octtoi(value[i].data + 19, value[i].len - 19);
+ if (file_access_rights == NGX_ERROR) {
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+ "invalid file_access_rights value \"%V\"", &value[i]);
+ return NGX_CONF_ERROR;
+ }
+
+ continue;
+ }
+
+ if (ngx_strncmp(value[i].data, "path_access_rights=", 19) == 0) {
+
+ path_access_rights = ngx_octtoi(value[i].data + 19, value[i].len - 19);
+ if (path_access_rights == NGX_ERROR) {
+ ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+ "invalid path_access_rights value \"%V\"", &value[i]);
+ return NGX_CONF_ERROR;
+ }
+
+ continue;
+ }
+
if (ngx_strncmp(value[i].data, "loader_sleep=", 13) == 0) {
s.len = value[i].len - 13;
@@ -2286,6 +2313,8 @@
cache->loader_files = loader_files;
cache->loader_sleep = loader_sleep;
cache->loader_threshold = loader_threshold;
+ cache->file_access_rights = file_access_rights;
+ cache->path_access_rights = path_access_rights;
if (ngx_add_path(cf, &cache->path) != NGX_OK) {
return NGX_CONF_ERROR;
More information about the nginx-devel
mailing list