Skip to content

Commit

Permalink
Merge branch 'master' of github.com:STNS/libnss
Browse files Browse the repository at this point in the history
  • Loading branch information
pyama86 committed Aug 13, 2020
2 parents 3b767fc + f638377 commit b197b98
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 12 deletions.
5 changes: 5 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
libnss-stns-v2 (2.6.1-1) xenial; urgency=medium

* add cached directive

-- pyama86 <[email protected]> Thu, 13 Aug 2020 12:00:00 +0900
libnss-stns-v2 (2.6.0-1) xenial; urgency=medium

* add cache-stnsd options
Expand Down
4 changes: 3 additions & 1 deletion rpm/stns.spec
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 <[email protected]> - 2.6.1-1
- add cached directive
* Tue Jul 14 2020 pyama86 <[email protected]> - 2.6.0-1
- add cache-stnsd options
- static build openssl and curl
Expand Down
15 changes: 10 additions & 5 deletions stns.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions stns.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 9 additions & 5 deletions stns_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;

mkdir("/var/cache/stns/", S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO);
stns_request(&c, "get?notfound", &r);
Expand Down Expand Up @@ -239,8 +241,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);

Expand All @@ -251,8 +254,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);
Expand Down
3 changes: 3 additions & 0 deletions test/stns.conf
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ ca = "ca_cert"

[http_headers]
X-API-TOKEN = "token"

[cached]
enable = true
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.6.0
2.6.1

0 comments on commit b197b98

Please sign in to comment.