diff options
author | Jakub Hrozek <jhrozek@redhat.com> | 2012-12-15 13:19:04 +0100 |
---|---|---|
committer | Jakub Hrozek <jhrozek@redhat.com> | 2012-12-18 17:25:34 +0100 |
commit | ba153306e0e551731a3ee2c31c26cd1d63052ff8 (patch) | |
tree | 4463a76e866ce375ce0bf8a89019cd7dc65f63ac /src | |
parent | 6ab9f4763b516c3a7cdc021f501f276dd805fc97 (diff) | |
download | sssd-ba153306e0e551731a3ee2c31c26cd1d63052ff8.tar.gz sssd-ba153306e0e551731a3ee2c31c26cd1d63052ff8.tar.bz2 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')
-rw-r--r-- | src/db/sysdb_autofs.c | 91 | ||||
-rw-r--r-- | src/db/sysdb_autofs.h | 3 |
2 files changed, 94 insertions, 0 deletions
diff --git a/src/db/sysdb_autofs.c b/src/db/sysdb_autofs.c index cbef2dfa..57380cfd 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; +} diff --git a/src/db/sysdb_autofs.h b/src/db/sysdb_autofs.h index c4b5253a..8c8d0f56 100644 --- a/src/db/sysdb_autofs.h +++ b/src/db/sysdb_autofs.h @@ -78,4 +78,7 @@ sysdb_set_autofsmap_attr(struct sysdb_ctx *sysdb, struct sysdb_attrs *attrs, int mod_op); +errno_t +sysdb_invalidate_autofs_maps(struct sysdb_ctx *sysdb); + #endif /* _SYSDB_AUTOFS_H_ */ |