summaryrefslogtreecommitdiffstats
path: root/src/db/sysdb_autofs.c
diff options
context:
space:
mode:
authorJakub Hrozek <jhrozek@redhat.com>2012-12-15 13:19:04 +0100
committerJakub Hrozek <jhrozek@redhat.com>2012-12-18 17:25:34 +0100
commitba153306e0e551731a3ee2c31c26cd1d63052ff8 (patch)
tree4463a76e866ce375ce0bf8a89019cd7dc65f63ac /src/db/sysdb_autofs.c
parent6ab9f4763b516c3a7cdc021f501f276dd805fc97 (diff)
downloadsssd-ba153306e0e551731a3ee2c31c26cd1d63052ff8.tar.gz
sssd-ba153306e0e551731a3ee2c31c26cd1d63052ff8.tar.xz
sssd-ba153306e0e551731a3ee2c31c26cd1d63052ff8.zip
SYSDB: Add API to invalidate all map objects
This sysdb API will be used later to invalidate the autofs maps
Diffstat (limited to 'src/db/sysdb_autofs.c')
-rw-r--r--src/db/sysdb_autofs.c91
1 files changed, 91 insertions, 0 deletions
diff --git a/src/db/sysdb_autofs.c b/src/db/sysdb_autofs.c
index cbef2dfa3..57380cfdc 100644
--- a/src/db/sysdb_autofs.c
+++ b/src/db/sysdb_autofs.c
@@ -417,3 +417,94 @@ done:
talloc_free(tmp_ctx);
return ret;
}
+
+errno_t
+sysdb_invalidate_autofs_maps(struct sysdb_ctx *sysdb)
+{
+ errno_t ret;
+ TALLOC_CTX *tmp_ctx;
+ const char *filter;
+ struct sysdb_attrs *sys_attrs = NULL;
+ const char *attrs[] = { SYSDB_OBJECTCLASS,
+ SYSDB_NAME,
+ SYSDB_CACHE_EXPIRE,
+ NULL };
+ size_t count;
+ struct ldb_message **msgs;
+ const char *name;
+ bool in_transaction = false;
+ int sret;
+ int i;
+
+ tmp_ctx = talloc_new(NULL);
+ if (!tmp_ctx) return ENOMEM;
+
+ filter = talloc_asprintf(tmp_ctx, "(&(objectclass=%s)(%s=*))",
+ SYSDB_AUTOFS_MAP_OC, SYSDB_NAME);
+ if (!filter) {
+ ret = ENOMEM;
+ goto done;
+ }
+
+ ret = sysdb_search_custom(tmp_ctx, sysdb, filter,
+ AUTOFS_MAP_SUBDIR, attrs,
+ &count, &msgs);
+ if (ret != EOK && ret != ENOENT) {
+ DEBUG(SSSDBG_CRIT_FAILURE,
+ ("Error looking up autofs maps"));
+ goto done;
+ } else if (ret == ENOENT) {
+ ret = EOK;
+ goto done;
+ }
+
+ sys_attrs = sysdb_new_attrs(tmp_ctx);
+ if (!sys_attrs) {
+ ret = ENOMEM;
+ goto done;
+ }
+
+ ret = sysdb_attrs_add_time_t(sys_attrs, SYSDB_CACHE_EXPIRE, 1);
+ if (ret != EOK) {
+ goto done;
+ }
+
+ ret = sysdb_transaction_start(sysdb);
+ if (ret != EOK) {
+ DEBUG(SSSDBG_CRIT_FAILURE, ("Failed to start transaction\n"));
+ goto done;
+ }
+ in_transaction = true;
+
+ for (i = 0; i < count; i++) {
+ name = ldb_msg_find_attr_as_string(msgs[i], SYSDB_NAME, NULL);
+ if (!name) {
+ DEBUG(SSSDBG_MINOR_FAILURE, ("A map with no name?\n"));
+ continue;
+ }
+
+ ret = sysdb_set_autofsmap_attr(sysdb, name, sys_attrs, SYSDB_MOD_REP);
+ if (ret != EOK) {
+ DEBUG(SSSDBG_MINOR_FAILURE, ("Could not expire map %s\n", name));
+ continue;
+ }
+ }
+
+ ret = sysdb_transaction_commit(sysdb);
+ if (ret != EOK) {
+ DEBUG(SSSDBG_OP_FAILURE, ("Could not commit transaction\n"));
+ goto done;
+ }
+ in_transaction = false;
+
+ ret = EOK;
+done:
+ if (in_transaction) {
+ sret = sysdb_transaction_cancel(sysdb);
+ if (sret != EOK) {
+ DEBUG(SSSDBG_OP_FAILURE, ("Could not cancel transaction\n"));
+ }
+ }
+ talloc_free(tmp_ctx);
+ return ret;
+}