From 068992c623d0f3c18e57558040cea1afff9860ac Mon Sep 17 00:00:00 2001 From: pyama86 Date: Thu, 13 Aug 2020 10:44:21 +0900 Subject: [PATCH 1/2] add cached directive --- stns.c | 15 ++++++++++----- stns.h | 1 + stns_test.c | 14 +++++++++----- test/stns.conf | 3 +++ 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/stns.c b/stns.c index ed07e73..a370c63 100644 --- a/stns.c +++ b/stns.c @@ -37,7 +37,7 @@ ID_QUERY_AVAILABLE(group, low, >) static void stns_force_create_cache_dir(stns_conf_t *c) { - if (c->cache && geteuid() == 0 && !c->use_cached) { + if (c->cache && geteuid() == 0 && !c->cached_enable) { struct stat statBuf; char path[MAXBUF]; @@ -88,6 +88,7 @@ int stns_load_config(char *filename, stns_conf_t *c) GET_TOML_BY_TABLE_KEY(tls, key, toml_rtos, NULL, TOML_NULL_OR_INT); GET_TOML_BY_TABLE_KEY(tls, cert, toml_rtos, NULL, TOML_NULL_OR_INT); GET_TOML_BY_TABLE_KEY(tls, ca, toml_rtos, NULL, TOML_NULL_OR_INT); + GET_TOML_BY_TABLE_KEY(cached, enable, toml_rtob, 0, TOML_NULL_OR_INT); GET_TOML_BYKEY(uid_shift, toml_rtoi, 0, TOML_NULL_OR_INT); GET_TOML_BYKEY(gid_shift, toml_rtoi, 0, TOML_NULL_OR_INT); @@ -149,6 +150,10 @@ int stns_load_config(char *filename, stns_conf_t *c) #ifdef DEBUG syslog(LOG_ERR, "%s(stns)[L%d] after free", __func__, __LINE__); #endif + + if (c->use_cached) { + c->cached_enable = 1; + } return 0; } @@ -265,7 +270,7 @@ static CURLcode inner_http_request(stns_conf_t *c, char *path, stns_response_t * syslog(LOG_ERR, "%s(stns)[L%d] init http request: %s", __func__, __LINE__, url); #endif - if (!c->use_cached) { + if (!c->cached_enable) { if (c->auth_token != NULL) { len = strlen(c->auth_token) + 22; auth = (char *)malloc(len); @@ -362,7 +367,7 @@ static CURLcode inner_http_request(stns_conf_t *c, char *path, stns_response_t * #ifdef DEBUG syslog(LOG_ERR, "%s(stns)[L%d] before free", __func__, __LINE__); #endif - if (!c->use_cached) { + if (!c->cached_enable) { if (c->auth_token != NULL) { free(auth); } @@ -530,7 +535,7 @@ int stns_request(stns_conf_t *c, char *path, stns_response_t *res) syslog(LOG_ERR, "%s(stns)[L%d] after free", __func__, __LINE__); #endif - if (c->cache && !c->use_cached) { + if (c->cache && !c->cached_enable) { struct stat statbuf; if (stat(fpath, &statbuf) == 0 && statbuf.st_uid == geteuid()) { unsigned long now = time(NULL); @@ -581,7 +586,7 @@ int stns_request(stns_conf_t *c, char *path, stns_response_t *res) stns_make_lockfile(STNS_LOCK_FILE); } - if (c->cache && !c->use_cached) { + if (c->cache && !c->cached_enable) { stns_export_file(dpath, fpath, res->data); } return result; diff --git a/stns.h b/stns.h index db106c3..70381ab 100644 --- a/stns.h +++ b/stns.h @@ -61,6 +61,7 @@ struct stns_conf_t { char *tls_cert; char *tls_key; char *tls_ca; + int cached_enable; stns_user_httpheaders_t *http_headers; int uid_shift; int gid_shift; diff --git a/stns_test.c b/stns_test.c index fce0251..0c761d5 100644 --- a/stns_test.c +++ b/stns_test.c @@ -12,6 +12,7 @@ stns_conf_t test_conf() c.user = NULL; c.ssl_verify = 0; c.use_cached = 0; + c.cached_enable = 0; c.password = NULL; c.query_wrapper = NULL; c.tls_cert = NULL; @@ -73,7 +74,7 @@ Test(stns_load_config, load_ok) cr_assert_str_eq(c.unix_socket, "/var/run/cache-stnsd.sock"); cr_assert_str_eq(c.http_proxy, "http://your.proxy.com"); cr_assert_eq(c.ssl_verify, 1); - cr_assert_eq(c.use_cached, 0); + cr_assert_eq(c.cached_enable, 1); cr_assert_eq(c.uid_shift, 1000); cr_assert_eq(c.gid_shift, 2000); cr_assert_eq(c.request_timeout, 3); @@ -112,6 +113,7 @@ Test(stns_request, http_cache) c.cache_ttl = 1; c.negative_cache_ttl = 1; c.use_cached = 0; + c.cached_enable = 0; stns_request(&c, "get?notfound", &r); cr_assert_eq(stat(path, &st), -1); @@ -238,8 +240,9 @@ Test(query_available, ok) Test(stns_request, http_request_with_cached) { char expect_body[1024]; - stns_conf_t c = test_conf(); - c.use_cached = 1; + stns_conf_t c = test_conf(); + c.use_cached = 1; + c.cached_enable = 1; stns_response_t r; stns_request(&c, "user-agent", &r); @@ -250,8 +253,9 @@ Test(stns_request, http_request_with_cached) Test(stns_request, http_request_notfound_with_cached) { char expect_body[1024]; - stns_conf_t c = test_conf(); - c.use_cached = 1; + stns_conf_t c = test_conf(); + c.use_cached = 1; + c.cached_enable = 1; stns_response_t r; cr_assert_eq(stns_request(&c, "status/404", &r), CURLE_HTTP_RETURNED_ERROR); diff --git a/test/stns.conf b/test/stns.conf index 485e7ef..43e1c30 100644 --- a/test/stns.conf +++ b/test/stns.conf @@ -18,3 +18,6 @@ ca = "ca_cert" [http_headers] X-API-TOKEN = "token" + +[cached] +enable = true From 3d5b53f3cf783c053199b7aa7fcec92183ac7b00 Mon Sep 17 00:00:00 2001 From: pyama86 Date: Thu, 13 Aug 2020 10:46:19 +0900 Subject: [PATCH 2/2] bump --- debian/changelog | 5 +++++ rpm/stns.spec | 4 +++- version | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/debian/changelog b/debian/changelog index 0000b6c..c29a577 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,8 @@ +libnss-stns-v2 (2.6.1-1) xenial; urgency=medium + + * add cached directive + + -- pyama86 Thu, 13 Aug 2020 12:00:00 +0900 libnss-stns-v2 (2.6.0-1) xenial; urgency=medium * add cache-stnsd options diff --git a/rpm/stns.spec b/rpm/stns.spec index 9c70304..b57ecae 100644 --- a/rpm/stns.spec +++ b/rpm/stns.spec @@ -1,6 +1,6 @@ Summary: SimpleTomlNameService Nss Module Name: libnss-stns-v2 -Version: 2.6.0 +Version: 2.6.1 Release: 1 License: GPLv3 URL: https://github.com/STNS/STNS @@ -61,6 +61,8 @@ sed -i "s/^IPAddressDeny=any/#IPAddressDeny=any/" /lib/systemd/system/systemd-lo %config(noreplace) /etc/stns/client/stns.conf %changelog +* Thu Aug 13 2020 pyama86 - 2.6.1-1 +- add cached directive * Tue Jul 14 2020 pyama86 - 2.6.0-1 - add cache-stnsd options - static build openssl and curl diff --git a/version b/version index e70b452..6a6a3d8 100644 --- a/version +++ b/version @@ -1 +1 @@ -2.6.0 +2.6.1