summaryrefslogtreecommitdiff
path: root/src/responder/common
diff options
context:
space:
mode:
authorStephen Gallagher <sgallagh@redhat.com>2010-06-16 15:33:57 -0400
committerStephen Gallagher <sgallagh@redhat.com>2010-06-17 15:40:13 -0400
commita56cdc811fec8d2c0e69fce3970a1032d1e3d2a8 (patch)
treeac06e8944c9bed459b6ec2198c8eb4d4a18e22d0 /src/responder/common
parentae5716d87c7b126ab01b0d4fcacd4f519585e5fb (diff)
downloadsssd-a56cdc811fec8d2c0e69fce3970a1032d1e3d2a8.tar.gz
sssd-a56cdc811fec8d2c0e69fce3970a1032d1e3d2a8.tar.bz2
sssd-a56cdc811fec8d2c0e69fce3970a1032d1e3d2a8.zip
Move setup of filter_users and filter_groups to negcache.c
Creates a new function - sss_ncache_prepopulate() - that can be shared with other responders, such as PAM.
Diffstat (limited to 'src/responder/common')
-rw-r--r--src/responder/common/negcache.c207
-rw-r--r--src/responder/common/negcache.h8
2 files changed, 215 insertions, 0 deletions
diff --git a/src/responder/common/negcache.c b/src/responder/common/negcache.c
index aef9080a..521a2e76 100644
--- a/src/responder/common/negcache.c
+++ b/src/responder/common/negcache.c
@@ -20,6 +20,7 @@
*/
#include "util/util.h"
+#include "confdb/confdb.h"
#include <fcntl.h>
#include <time.h>
#include "tdb.h"
@@ -319,3 +320,209 @@ int sss_ncache_reset_permament(struct sss_nc_ctx *ctx)
return EOK;
}
+
+errno_t sss_ncache_prepopulate(struct sss_nc_ctx *ncache,
+ struct confdb_ctx *cdb,
+ struct sss_names_ctx *names_ctx,
+ struct sss_domain_info *domain_list)
+{
+ errno_t ret;
+ bool filter_set = false;
+ char **filter_list = NULL;
+ char *name = NULL;
+ struct sss_domain_info *dom = NULL;
+ char *domainname = NULL;
+ char *conf_path = NULL;
+ TALLOC_CTX *tmpctx = talloc_new(NULL);
+ int i;
+
+ /* Populate domain-specific negative cache entries */
+ for (dom = domain_list; dom; dom = dom->next) {
+ conf_path = talloc_asprintf(tmpctx, CONFDB_DOMAIN_PATH_TMPL,
+ dom->name);
+ if (!conf_path) {
+ ret = ENOMEM;
+ goto done;
+ }
+
+ talloc_zfree(filter_list);
+ ret = confdb_get_string_as_list(cdb, tmpctx, conf_path,
+ CONFDB_NSS_FILTER_USERS,
+ &filter_list);
+ if (ret == ENOENT) continue;
+ if (ret != EOK) goto done;
+ filter_set = true;
+
+ for (i = 0; (filter_list && filter_list[i]); i++) {
+ ret = sss_parse_name(tmpctx, names_ctx, filter_list[i],
+ &domainname, &name);
+ if (ret != EOK) {
+ DEBUG(1, ("Invalid name in filterUsers list: [%s] (%d)\n",
+ filter_list[i], ret));
+ continue;
+ }
+
+ if (domainname && strcmp(domainname, dom->name)) {
+ DEBUG(1, ("Mismatch between domain name (%s) and name "
+ "set in FQN (%s), skipping user %s\n",
+ dom->name, domainname, name));
+ continue;
+ }
+
+ ret = sss_ncache_set_user(ncache, true, dom->name, name);
+ if (ret != EOK) {
+ DEBUG(1, ("Failed to store permanent user filter for [%s]"
+ " (%d [%s])\n", filter_list[i],
+ ret, strerror(ret)));
+ continue;
+ }
+ }
+ }
+
+ ret = confdb_get_string_as_list(cdb, tmpctx, CONFDB_NSS_CONF_ENTRY,
+ CONFDB_NSS_FILTER_USERS, &filter_list);
+ if (ret == ENOENT) {
+ if (!filter_set) {
+ filter_list = talloc_array(tmpctx, char *, 2);
+ if (!filter_list) {
+ ret = ENOMEM;
+ goto done;
+ }
+ filter_list[0] = talloc_strdup(tmpctx, "root");
+ if (!filter_list[0]) {
+ ret = ENOMEM;
+ goto done;
+ }
+ filter_list[1] = NULL;
+ }
+ ret = EOK;
+ }
+ else if (ret != EOK) goto done;
+
+ for (i = 0; (filter_list && filter_list[i]); i++) {
+ ret = sss_parse_name(tmpctx, names_ctx, filter_list[i],
+ &domainname, &name);
+ if (ret != EOK) {
+ DEBUG(1, ("Invalid name in filterUsers list: [%s] (%d)\n",
+ filter_list[i], ret));
+ continue;
+ }
+ if (domainname) {
+ ret = sss_ncache_set_user(ncache, true, domainname, name);
+ if (ret != EOK) {
+ DEBUG(1, ("Failed to store permanent user filter for [%s]"
+ " (%d [%s])\n", filter_list[i],
+ ret, strerror(ret)));
+ continue;
+ }
+ } else {
+ for (dom = domain_list; dom; dom = dom->next) {
+ ret = sss_ncache_set_user(ncache, true, dom->name, name);
+ if (ret != EOK) {
+ DEBUG(1, ("Failed to store permanent user filter for"
+ " [%s:%s] (%d [%s])\n",
+ dom->name, filter_list[i],
+ ret, strerror(ret)));
+ continue;
+ }
+ }
+ }
+ }
+
+ filter_set = false;
+ for (dom = domain_list; dom; dom = dom->next) {
+ conf_path = talloc_asprintf(tmpctx, CONFDB_DOMAIN_PATH_TMPL, dom->name);
+ if (!conf_path) {
+ ret = ENOMEM;
+ goto done;
+ }
+
+ talloc_zfree(filter_list);
+ ret = confdb_get_string_as_list(cdb, tmpctx, conf_path,
+ CONFDB_NSS_FILTER_GROUPS, &filter_list);
+ if (ret == ENOENT) continue;
+ if (ret != EOK) goto done;
+ filter_set = true;
+
+ for (i = 0; (filter_list && filter_list[i]); i++) {
+ ret = sss_parse_name(tmpctx, names_ctx, filter_list[i],
+ &domainname, &name);
+ if (ret != EOK) {
+ DEBUG(1, ("Invalid name in filterGroups list: [%s] (%d)\n",
+ filter_list[i], ret));
+ continue;
+ }
+
+ if (domainname && strcmp(domainname, dom->name)) {
+ DEBUG(1, ("Mismatch betwen domain name (%s) and name "
+ "set in FQN (%s), skipping group %s\n",
+ dom->name, domainname, name));
+ continue;
+ }
+
+ ret = sss_ncache_set_group(ncache, true, dom->name, name);
+ if (ret != EOK) {
+ DEBUG(1, ("Failed to store permanent group filter for [%s]"
+ " (%d [%s])\n", filter_list[i],
+ ret, strerror(ret)));
+ continue;
+ }
+ }
+ }
+
+ ret = confdb_get_string_as_list(cdb, tmpctx, CONFDB_NSS_CONF_ENTRY,
+ CONFDB_NSS_FILTER_GROUPS, &filter_list);
+ if (ret == ENOENT) {
+ if (!filter_set) {
+ filter_list = talloc_array(tmpctx, char *, 2);
+ if (!filter_list) {
+ ret = ENOMEM;
+ goto done;
+ }
+ filter_list[0] = talloc_strdup(tmpctx, "root");
+ if (!filter_list[0]) {
+ ret = ENOMEM;
+ goto done;
+ }
+ filter_list[1] = NULL;
+ }
+ ret = EOK;
+ }
+ else if (ret != EOK) goto done;
+
+ for (i = 0; (filter_list && filter_list[i]); i++) {
+ ret = sss_parse_name(tmpctx, names_ctx, filter_list[i],
+ &domainname, &name);
+ if (ret != EOK) {
+ DEBUG(1, ("Invalid name in filterGroups list: [%s] (%d)\n",
+ filter_list[i], ret));
+ continue;
+ }
+ if (domainname) {
+ ret = sss_ncache_set_group(ncache, true, domainname, name);
+ if (ret != EOK) {
+ DEBUG(1, ("Failed to store permanent group filter for"
+ " [%s] (%d [%s])\n", filter_list[i],
+ ret, strerror(ret)));
+ continue;
+ }
+ } else {
+ for (dom = domain_list; dom; dom = dom->next) {
+ ret = sss_ncache_set_group(ncache, true, dom->name, name);
+ if (ret != EOK) {
+ DEBUG(1, ("Failed to store permanent group filter for"
+ " [%s:%s] (%d [%s])\n",
+ dom->name, filter_list[i],
+ ret, strerror(ret)));
+ continue;
+ }
+ }
+ }
+ }
+
+ ret = EOK;
+
+done:
+ talloc_free(tmpctx);
+ return ret;
+}
diff --git a/src/responder/common/negcache.h b/src/responder/common/negcache.h
index d310c9e3..68be9f02 100644
--- a/src/responder/common/negcache.h
+++ b/src/responder/common/negcache.h
@@ -48,4 +48,12 @@ int sss_ncache_set_gid(struct sss_nc_ctx *ctx, bool permanent, gid_t gid);
int sss_ncache_reset_permament(struct sss_nc_ctx *ctx);
+/* Set up the negative cache with values from filter_users and
+ * filter_groups in the sssd.conf
+ */
+errno_t sss_ncache_prepopulate(struct sss_nc_ctx *ncache,
+ struct confdb_ctx *cdb,
+ struct sss_names_ctx *names_ctx,
+ struct sss_domain_info *domain_list);
+
#endif /* _NSS_NEG_CACHE_H_ */