summaryrefslogtreecommitdiffstats
path: root/src/db
diff options
context:
space:
mode:
authorWilliam B <william@adelaide.edu.au>2014-07-21 11:13:25 +0200
committerJakub Hrozek <jhrozek@redhat.com>2014-09-05 11:40:39 +0200
commit3ac7c4fe618ede980a4df8d90341ef1fd0f1f62f (patch)
tree940c252ca1538b4d8cd60e94d95073d6a845f040 /src/db
parent61602026ed8c91efd166000562899670449f1b50 (diff)
downloadsssd-3ac7c4fe618ede980a4df8d90341ef1fd0f1f62f.tar.gz
sssd-3ac7c4fe618ede980a4df8d90341ef1fd0f1f62f.tar.xz
sssd-3ac7c4fe618ede980a4df8d90341ef1fd0f1f62f.zip
SSS_CACHE: Allow sss_cache tool to flush SSH hosts cache
Resolves: https://fedorahosted.org/sssd/ticket/2358 Signed-off-by: Jan Cholasta <jcholast@redhat.com> Reviewed-by: Jan Cholasta <jcholast@redhat.com> Reviewed-by: Pavel Reichl <preichl@redhat.com>
Diffstat (limited to 'src/db')
-rw-r--r--src/db/sysdb_ssh.c63
-rw-r--r--src/db/sysdb_ssh.h15
2 files changed, 71 insertions, 7 deletions
diff --git a/src/db/sysdb_ssh.c b/src/db/sysdb_ssh.c
index 7dd98cfdb..4983dcc34 100644
--- a/src/db/sysdb_ssh.c
+++ b/src/db/sysdb_ssh.c
@@ -23,6 +23,14 @@
#include "db/sysdb_ssh.h"
#include "db/sysdb_private.h"
+static struct ldb_dn *
+sysdb_ssh_host_dn(TALLOC_CTX *mem_ctx,
+ struct sss_domain_info *domain,
+ const char *name)
+{
+ return sysdb_custom_dn(mem_ctx, domain, name, SSH_HOSTS_SUBDIR);
+}
+
static errno_t
sysdb_update_ssh_host(struct sss_domain_info *domain,
const char *name,
@@ -45,6 +53,7 @@ errno_t
sysdb_store_ssh_host(struct sss_domain_info *domain,
const char *name,
const char *alias,
+ int cache_timeout,
time_t now,
struct sysdb_attrs *attrs)
{
@@ -147,6 +156,14 @@ sysdb_store_ssh_host(struct sss_domain_info *domain,
goto done;
}
+ ret = sysdb_attrs_add_time_t(attrs, SYSDB_CACHE_EXPIRE,
+ cache_timeout ? (now + cache_timeout) : 0);
+ if (ret != EOK) {
+ DEBUG(SSSDBG_OP_FAILURE, "Could not set sysdb cache expire [%d]: %s\n",
+ ret, strerror(ret));
+ goto done;
+ }
+
ret = sysdb_update_ssh_host(domain, name, attrs);
if (ret != EOK) {
goto done;
@@ -176,6 +193,34 @@ done:
}
errno_t
+sysdb_set_ssh_host_attr(struct sss_domain_info *domain,
+ const char *name,
+ struct sysdb_attrs *attrs,
+ int mod_op)
+{
+ errno_t ret;
+ struct ldb_dn *dn;
+ TALLOC_CTX *tmp_ctx;
+
+ tmp_ctx = talloc_new(NULL);
+ if (!tmp_ctx) {
+ return ENOMEM;
+ }
+
+ dn = sysdb_ssh_host_dn(tmp_ctx, domain, name);
+ if (!dn) {
+ ret = ENOMEM;
+ goto done;
+ }
+
+ ret = sysdb_set_entry_attr(domain->sysdb, dn, attrs, mod_op);
+
+done:
+ talloc_free(tmp_ctx);
+ return ret;
+}
+
+errno_t
sysdb_update_ssh_known_host_expire(struct sss_domain_info *domain,
const char *name,
time_t now,
@@ -229,13 +274,13 @@ sysdb_delete_ssh_host(struct sss_domain_info *domain,
return sysdb_delete_custom(domain, name, SSH_HOSTS_SUBDIR);
}
-static errno_t
+errno_t
sysdb_search_ssh_hosts(TALLOC_CTX *mem_ctx,
struct sss_domain_info *domain,
const char *filter,
const char **attrs,
- struct ldb_message ***hosts,
- size_t *num_hosts)
+ size_t *num_hosts,
+ struct ldb_message ***hosts)
{
errno_t ret;
TALLOC_CTX *tmp_ctx;
@@ -297,7 +342,7 @@ sysdb_get_ssh_host(TALLOC_CTX *mem_ctx,
}
ret = sysdb_search_ssh_hosts(tmp_ctx, domain, filter, attrs,
- &hosts, &num_hosts);
+ &num_hosts, &hosts);
if (ret != EOK) {
goto done;
}
@@ -335,15 +380,19 @@ sysdb_get_ssh_known_hosts(TALLOC_CTX *mem_ctx,
return ENOMEM;
}
- filter = talloc_asprintf(tmp_ctx, "(%s>=%ld)",
- SYSDB_SSH_KNOWN_HOSTS_EXPIRE, (long)now);
+ filter = talloc_asprintf(tmp_ctx,
+ "(&(|(!(%s=*))(%s=0)(%s>=%lld))(%s>=%lld))",
+ SYSDB_CACHE_EXPIRE,
+ SYSDB_CACHE_EXPIRE,
+ SYSDB_CACHE_EXPIRE, (long long)now + 1,
+ SYSDB_SSH_KNOWN_HOSTS_EXPIRE, (long long)now + 1);
if (!filter) {
ret = ENOMEM;
goto done;
}
ret = sysdb_search_ssh_hosts(mem_ctx, domain, filter, attrs,
- hosts, num_hosts);
+ num_hosts, hosts);
done:
talloc_free(tmp_ctx);
diff --git a/src/db/sysdb_ssh.h b/src/db/sysdb_ssh.h
index e8aca776b..960a13fd5 100644
--- a/src/db/sysdb_ssh.h
+++ b/src/db/sysdb_ssh.h
@@ -33,6 +33,7 @@ errno_t
sysdb_store_ssh_host(struct sss_domain_info *domain,
const char *name,
const char *alias,
+ int cache_timeout,
time_t now,
struct sysdb_attrs *attrs);
@@ -42,11 +43,25 @@ sysdb_update_ssh_known_host_expire(struct sss_domain_info *domain,
time_t now,
int known_hosts_timeout);
+int
+sysdb_set_ssh_host_attr(struct sss_domain_info *domain,
+ const char *name,
+ struct sysdb_attrs *attrs,
+ int mod_op);
+
errno_t
sysdb_delete_ssh_host(struct sss_domain_info *domain,
const char *name);
errno_t
+sysdb_search_ssh_hosts(TALLOC_CTX *mem_ctx,
+ struct sss_domain_info *domain,
+ const char *filter,
+ const char **attrs,
+ size_t *num_hosts,
+ struct ldb_message ***hosts);
+
+errno_t
sysdb_get_ssh_host(TALLOC_CTX *mem_ctx,
struct sss_domain_info *domain,
const char *name,