sss_cache.c revision 4fcc50e133f90cd4c5931a3ac48c84cb628b16fc
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen/*
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen SSSD
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen sss_cache
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen Copyright (C) Jan Zeleny <jzeleny@redhat.com> 2011
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen This program is free software; you can redistribute it and/or modify
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen it under the terms of the GNU General Public License as published by
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen the Free Software Foundation; either version 3 of the License, or
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen (at your option) any later version.
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen This program is distributed in the hope that it will be useful,
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen but WITHOUT ANY WARRANTY; without even the implied warranty of
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen GNU General Public License for more details.
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen You should have received a copy of the GNU General Public License
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen along with this program. If not, see <http://www.gnu.org/licenses/>.
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen*/
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen#include <stdio.h>
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen#include <stdlib.h>
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen#include <talloc.h>
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen#include <popt.h>
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen#include <sys/types.h>
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen#include "util/util.h"
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen#include "tools/sss_sync_ops.h"
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen#include "db/sysdb.h"
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen#include "db/sysdb_services.h"
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen#include "db/sysdb_autofs.h"
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen#define INVALIDATE_NONE 0
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen#define INVALIDATE_USERS 1
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen#define INVALIDATE_GROUPS 2
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen#define INVALIDATE_NETGROUPS 4
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen#define INVALIDATE_SERVICES 8
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen#define INVALIDATE_AUTOFSMAPS 16
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen#ifdef BUILD_AUTOFS
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen#define INVALIDATE_EVERYTHING (INVALIDATE_USERS | INVALIDATE_GROUPS | \
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen INVALIDATE_NETGROUPS | INVALIDATE_SERVICES | \
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen INVALIDATE_AUTOFSMAPS)
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen#else
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen#define INVALIDATE_EVERYTHING (INVALIDATE_USERS | INVALIDATE_GROUPS | \
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen INVALIDATE_NETGROUPS | INVALIDATE_SERVICES)
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen#endif
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainenenum sss_cache_entry {
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen TYPE_USER=0,
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen TYPE_GROUP,
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen TYPE_NETGROUP,
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen TYPE_SERVICE,
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen TYPE_AUTOFSMAP
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen};
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainenstatic errno_t search_autofsmaps(TALLOC_CTX *mem_ctx, struct sysdb_ctx *sysdb,
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen struct sss_domain_info *domain,
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen const char *sub_filter, const char **attrs,
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen size_t *msgs_count, struct ldb_message ***msgs);
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainenstruct cache_tool_ctx {
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen struct confdb_ctx *confdb;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen struct sss_domain_info *domains;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen struct sss_names_ctx *nctx;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen char *user_filter;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen char *group_filter;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen char *netgroup_filter;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen char *service_filter;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen char *autofs_filter;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen char *user_name;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen char *group_name;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen char *netgroup_name;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen char *service_name;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen char *autofs_name;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen bool update_user_filter;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen bool update_group_filter;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen bool update_netgroup_filter;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen bool update_service_filter;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen bool update_autofs_filter;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen};
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainenerrno_t init_domains(struct cache_tool_ctx *ctx, const char *domain);
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainenerrno_t init_context(int argc, const char *argv[], struct cache_tool_ctx **tctx);
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainenstatic errno_t invalidate_entry(TALLOC_CTX *ctx, struct sysdb_ctx *sysdb,
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen struct sss_domain_info *domain,
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen const char *name, int entry_type);
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainenstatic bool invalidate_entries(TALLOC_CTX *ctx,
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen struct sss_domain_info *dinfo,
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen struct sysdb_ctx *sysdb,
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen enum sss_cache_entry entry_type,
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen const char *filter, const char *name);
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainenstatic errno_t update_all_filters(struct cache_tool_ctx *tctx,
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen struct sss_domain_info *dinfo);
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainenint main(int argc, const char *argv[])
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen{
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen errno_t ret;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen struct cache_tool_ctx *tctx = NULL;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen struct sysdb_ctx *sysdb;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen bool skipped = true;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen struct sss_domain_info *dinfo;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen ret = init_context(argc, argv, &tctx);
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen if (ret != EOK) {
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen DEBUG(SSSDBG_CRIT_FAILURE,
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen ("Error initializing context for the application\n"));
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen goto done;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen }
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen for (dinfo = tctx->domains; dinfo; dinfo = get_next_domain(dinfo, true)) {
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen sysdb = dinfo->sysdb;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen if (!IS_SUBDOMAIN(dinfo)) {
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen /* Update list of subdomains for this domain */
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen ret = sysdb_update_subdomains(dinfo);
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen if (ret != EOK) {
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen DEBUG(SSSDBG_MINOR_FAILURE,
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen ("Failed to update subdomains for domain %s.\n", dinfo->name));
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen }
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen }
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen sysdb = dinfo->sysdb;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen /* Update filters for each domain */
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen ret = update_all_filters(tctx, dinfo);
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen if (ret != EOK) {
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen DEBUG(SSSDBG_CRIT_FAILURE, ("Failed to update filters.\n"));
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen goto done;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen }
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen ret = sysdb_transaction_start(sysdb);
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen if (ret != EOK) {
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen DEBUG(SSSDBG_CRIT_FAILURE,
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen ("Could not start the transaction!\n"));
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen goto done;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen }
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen skipped &= !invalidate_entries(tctx, dinfo, sysdb, TYPE_USER,
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen tctx->user_filter,
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen tctx->user_name);
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen skipped &= !invalidate_entries(tctx, dinfo, sysdb, TYPE_GROUP,
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen tctx->group_filter,
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen tctx->group_name);
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen skipped &= !invalidate_entries(tctx, dinfo, sysdb, TYPE_NETGROUP,
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen tctx->netgroup_filter,
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen tctx->netgroup_name);
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen skipped &= !invalidate_entries(tctx, dinfo, sysdb, TYPE_SERVICE,
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen tctx->service_filter,
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen tctx->service_name);
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen skipped &= !invalidate_entries(tctx, dinfo, sysdb, TYPE_AUTOFSMAP,
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen tctx->autofs_filter,
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen tctx->autofs_name);
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen ret = sysdb_transaction_commit(sysdb);
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen if (ret != EOK) {
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen DEBUG(SSSDBG_CRIT_FAILURE,
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen ("Could not commit the transaction!\n"));
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen ret = sysdb_transaction_cancel(sysdb);
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen if (ret != EOK) {
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen DEBUG(SSSDBG_CRIT_FAILURE,
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen ("Failed to cancel transaction\n"));
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen }
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen }
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen }
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen if (skipped == true) {
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen ERROR("No cache object matched the specified search\n");
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen ret = ENOENT;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen goto done;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen } else {
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen ret = sss_memcache_clear_all();
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen if (ret != EOK) {
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen DEBUG(SSSDBG_CRIT_FAILURE, ("Failed to clear memory cache.\n"));
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen goto done;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen }
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen }
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen ret = EOK;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainendone:
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen if (tctx) talloc_free(tctx);
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen return ret;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen}
21fed972adb354b92771eefad27f8ac8cbd5dd45Timo Sirainen
21fed972adb354b92771eefad27f8ac8cbd5dd45Timo Sirainenstatic errno_t update_filter(struct cache_tool_ctx *tctx,
21fed972adb354b92771eefad27f8ac8cbd5dd45Timo Sirainen struct sss_domain_info *dinfo,
21fed972adb354b92771eefad27f8ac8cbd5dd45Timo Sirainen char *name, bool update, const char *fmt,
21fed972adb354b92771eefad27f8ac8cbd5dd45Timo Sirainen bool force_case_sensitivity,
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen char **_filter)
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen{
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen errno_t ret;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen char *parsed_domain = NULL;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen char *parsed_name = NULL;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen TALLOC_CTX *tmp_ctx = NULL;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen char *use_name = NULL;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen char *filter;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen if (!name || !update) {
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen /* Nothing to do */
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen return EOK;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen }
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen
21fed972adb354b92771eefad27f8ac8cbd5dd45Timo Sirainen tmp_ctx = talloc_new(NULL);
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen if (tmp_ctx == NULL) {
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen DEBUG(SSSDBG_CRIT_FAILURE, ("Out of memory.\n"));
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen return ENOMEM;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen }
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen ret = sss_parse_name(tmp_ctx, tctx->nctx, name,
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen &parsed_domain, &parsed_name);
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen if (ret != EOK) {
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen DEBUG(SSSDBG_CRIT_FAILURE, ("sss_parse_name failed\n"));
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen goto done;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen }
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen if (!dinfo->case_sensitive && !force_case_sensitivity) {
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen use_name = sss_tc_utf8_str_tolower(tmp_ctx, parsed_name);
9ab0786966c0afa8fa09a2faff7c067bc388e694Timo Sirainen if (!use_name) {
9ab0786966c0afa8fa09a2faff7c067bc388e694Timo Sirainen DEBUG(SSSDBG_CRIT_FAILURE, ("Out of memory\n"));
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen ret = ENOMEM;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen goto done;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen }
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen } else {
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen use_name = parsed_name;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen }
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen if (parsed_domain) {
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen use_name = sss_get_domain_name(tmp_ctx, use_name, dinfo);
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen if (!use_name) {
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen ret = ENOMEM;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen goto done;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen }
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen if (!strcasecmp(dinfo->name, parsed_domain)) {
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen if (fmt) {
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen filter = talloc_asprintf(tmp_ctx, fmt,
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen SYSDB_NAME, use_name);
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen } else {
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen filter = talloc_strdup(tmp_ctx, use_name);
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen }
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen if (filter == NULL) {
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen DEBUG(SSSDBG_CRIT_FAILURE, ("Out of memory\n"));
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen ret = ENOMEM;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen goto done;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen }
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen } else {
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen /* We were able to parse the domain from given fqdn, but it
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen * does not match with currently processed domain. */
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen filter = NULL;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen }
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen } else {
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen if (fmt) {
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen filter = talloc_asprintf(tmp_ctx, fmt, SYSDB_NAME, name);
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen } else {
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen filter = talloc_strdup(tmp_ctx, name);
21fed972adb354b92771eefad27f8ac8cbd5dd45Timo Sirainen }
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen if (filter == NULL) {
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen DEBUG(SSSDBG_CRIT_FAILURE, ("Out of memory\n"));
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen ret = ENOMEM;
21fed972adb354b92771eefad27f8ac8cbd5dd45Timo Sirainen goto done;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen }
21fed972adb354b92771eefad27f8ac8cbd5dd45Timo Sirainen }
21fed972adb354b92771eefad27f8ac8cbd5dd45Timo Sirainen
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen talloc_free(*_filter);
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen *_filter = talloc_steal(tctx, filter);
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen ret = EOK;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainendone:
e21a2c0821c559080550ead6a901f613e59af10eTimo Sirainen talloc_free(tmp_ctx);
e21a2c0821c559080550ead6a901f613e59af10eTimo Sirainen return ret;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen}
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen/* This function updates all filters for specified domain using this
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen * domains regex to parse string into domain and name (if exists). */
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainenstatic errno_t update_all_filters(struct cache_tool_ctx *tctx,
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen struct sss_domain_info *dinfo)
21fed972adb354b92771eefad27f8ac8cbd5dd45Timo Sirainen{
21fed972adb354b92771eefad27f8ac8cbd5dd45Timo Sirainen errno_t ret;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen if (IS_SUBDOMAIN(dinfo)) {
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen ret = sss_names_init(tctx, tctx->confdb, dinfo->parent->name,
21fed972adb354b92771eefad27f8ac8cbd5dd45Timo Sirainen &tctx->nctx);
21fed972adb354b92771eefad27f8ac8cbd5dd45Timo Sirainen } else {
21fed972adb354b92771eefad27f8ac8cbd5dd45Timo Sirainen ret = sss_names_init(tctx, tctx->confdb, dinfo->name, &tctx->nctx);
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen }
148a8396be2c1cf7d2aaa55566f7f7dea05388ddTimo Sirainen if (ret != EOK) {
148a8396be2c1cf7d2aaa55566f7f7dea05388ddTimo Sirainen DEBUG(SSSDBG_CRIT_FAILURE, ("sss_names_init() failed\n"));
c2c0c1e5d2e97ae114ad83d8cb486b0aab23ac38Timo Sirainen return ret;
148a8396be2c1cf7d2aaa55566f7f7dea05388ddTimo Sirainen }
c2c0c1e5d2e97ae114ad83d8cb486b0aab23ac38Timo Sirainen
148a8396be2c1cf7d2aaa55566f7f7dea05388ddTimo Sirainen /* Update user filter */
148a8396be2c1cf7d2aaa55566f7f7dea05388ddTimo Sirainen ret = update_filter(tctx, dinfo, tctx->user_name,
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen tctx->update_user_filter, "(%s=%s)", false,
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen &tctx->user_filter);
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen if (ret != EOK) {
21fed972adb354b92771eefad27f8ac8cbd5dd45Timo Sirainen return ret;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen }
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen /* Update group filter */
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen ret = update_filter(tctx, dinfo, tctx->group_name,
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen tctx->update_group_filter, "(%s=%s)", false,
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen &tctx->group_filter);
21fed972adb354b92771eefad27f8ac8cbd5dd45Timo Sirainen if (ret != EOK) {
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen return ret;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen }
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen
21fed972adb354b92771eefad27f8ac8cbd5dd45Timo Sirainen /* Update netgroup filter */
21fed972adb354b92771eefad27f8ac8cbd5dd45Timo Sirainen ret = update_filter(tctx, dinfo, tctx->netgroup_name,
c2c0c1e5d2e97ae114ad83d8cb486b0aab23ac38Timo Sirainen tctx->update_netgroup_filter, "(%s=%s)", false,
c2c0c1e5d2e97ae114ad83d8cb486b0aab23ac38Timo Sirainen &tctx->netgroup_filter);
c2c0c1e5d2e97ae114ad83d8cb486b0aab23ac38Timo Sirainen if (ret != EOK) {
c2c0c1e5d2e97ae114ad83d8cb486b0aab23ac38Timo Sirainen return ret;
c2c0c1e5d2e97ae114ad83d8cb486b0aab23ac38Timo Sirainen }
c2c0c1e5d2e97ae114ad83d8cb486b0aab23ac38Timo Sirainen
c2c0c1e5d2e97ae114ad83d8cb486b0aab23ac38Timo Sirainen /* Update service filter */
c2c0c1e5d2e97ae114ad83d8cb486b0aab23ac38Timo Sirainen ret = update_filter(tctx, dinfo, tctx->service_name,
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen tctx->update_service_filter, "(%s=%s)", false,
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen &tctx->service_filter);
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen if (ret != EOK) {
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen return ret;
21fed972adb354b92771eefad27f8ac8cbd5dd45Timo Sirainen }
21fed972adb354b92771eefad27f8ac8cbd5dd45Timo Sirainen
21fed972adb354b92771eefad27f8ac8cbd5dd45Timo Sirainen /* Update autofs filter */
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen ret = update_filter(tctx, dinfo, tctx->autofs_name,
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen tctx->update_autofs_filter,
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen "(&(objectclass="SYSDB_AUTOFS_MAP_OC")(%s=%s))", true,
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen &tctx->autofs_filter);
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen if (ret != EOK) {
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen return ret;
6c6b1e9fd9ab19249e73f5269931d01d831e4346Timo Sirainen }
6c6b1e9fd9ab19249e73f5269931d01d831e4346Timo Sirainen
6c6b1e9fd9ab19249e73f5269931d01d831e4346Timo Sirainen return EOK;
6c6b1e9fd9ab19249e73f5269931d01d831e4346Timo Sirainen}
6c6b1e9fd9ab19249e73f5269931d01d831e4346Timo Sirainen
6c6b1e9fd9ab19249e73f5269931d01d831e4346Timo Sirainenstatic bool invalidate_entries(TALLOC_CTX *ctx,
6c6b1e9fd9ab19249e73f5269931d01d831e4346Timo Sirainen struct sss_domain_info *dinfo,
6c6b1e9fd9ab19249e73f5269931d01d831e4346Timo Sirainen struct sysdb_ctx *sysdb,
6c6b1e9fd9ab19249e73f5269931d01d831e4346Timo Sirainen enum sss_cache_entry entry_type,
6c6b1e9fd9ab19249e73f5269931d01d831e4346Timo Sirainen const char *filter, const char *name)
6c6b1e9fd9ab19249e73f5269931d01d831e4346Timo Sirainen{
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen const char *attrs[] = {SYSDB_NAME, NULL};
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen size_t msg_count;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen struct ldb_message **msgs;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen const char *type_string = "unknown";
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen errno_t ret = EINVAL;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen int i;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen const char *c_name;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen bool iret;
6c6b1e9fd9ab19249e73f5269931d01d831e4346Timo Sirainen
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen if (!filter) return false;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen switch (entry_type) {
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen case TYPE_USER:
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen type_string = "user";
21fed972adb354b92771eefad27f8ac8cbd5dd45Timo Sirainen ret = sysdb_search_users(ctx, sysdb, dinfo,
21fed972adb354b92771eefad27f8ac8cbd5dd45Timo Sirainen filter, attrs, &msg_count, &msgs);
21fed972adb354b92771eefad27f8ac8cbd5dd45Timo Sirainen break;
21fed972adb354b92771eefad27f8ac8cbd5dd45Timo Sirainen case TYPE_GROUP:
21fed972adb354b92771eefad27f8ac8cbd5dd45Timo Sirainen type_string = "group";
21fed972adb354b92771eefad27f8ac8cbd5dd45Timo Sirainen ret = sysdb_search_groups(ctx, sysdb, dinfo,
21fed972adb354b92771eefad27f8ac8cbd5dd45Timo Sirainen filter, attrs, &msg_count, &msgs);
21fed972adb354b92771eefad27f8ac8cbd5dd45Timo Sirainen break;
21fed972adb354b92771eefad27f8ac8cbd5dd45Timo Sirainen case TYPE_NETGROUP:
21fed972adb354b92771eefad27f8ac8cbd5dd45Timo Sirainen type_string = "netgroup";
21fed972adb354b92771eefad27f8ac8cbd5dd45Timo Sirainen ret = sysdb_search_netgroups(ctx, sysdb, dinfo,
21fed972adb354b92771eefad27f8ac8cbd5dd45Timo Sirainen filter, attrs, &msg_count, &msgs);
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen break;
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen case TYPE_SERVICE:
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen type_string = "service";
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen ret = sysdb_search_services(ctx, dinfo,
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen filter, attrs, &msg_count, &msgs);
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen break;
ed41ec8aa0efaa50954fd16cb44c86c8350dadccTimo Sirainen case TYPE_AUTOFSMAP:
ed41ec8aa0efaa50954fd16cb44c86c8350dadccTimo Sirainen type_string = "autofs map";
ed41ec8aa0efaa50954fd16cb44c86c8350dadccTimo Sirainen ret = search_autofsmaps(ctx, sysdb, dinfo,
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen filter, attrs, &msg_count, &msgs);
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen break;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen }
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen if (ret != EOK) {
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen if (ret == ENOENT) {
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen DEBUG(SSSDBG_TRACE_FUNC, ("'%s' %s: Not found in domain '%s'\n",
21fed972adb354b92771eefad27f8ac8cbd5dd45Timo Sirainen type_string, name ? name : "", dinfo->name));
ed41ec8aa0efaa50954fd16cb44c86c8350dadccTimo Sirainen } else {
ed41ec8aa0efaa50954fd16cb44c86c8350dadccTimo Sirainen DEBUG(SSSDBG_CRIT_FAILURE,
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen ("Searching for %s in domain %s with filter %s failed\n",
21fed972adb354b92771eefad27f8ac8cbd5dd45Timo Sirainen type_string, dinfo->name, filter));
c2c0c1e5d2e97ae114ad83d8cb486b0aab23ac38Timo Sirainen }
c2c0c1e5d2e97ae114ad83d8cb486b0aab23ac38Timo Sirainen return false;
c2c0c1e5d2e97ae114ad83d8cb486b0aab23ac38Timo Sirainen }
c2c0c1e5d2e97ae114ad83d8cb486b0aab23ac38Timo Sirainen
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen iret = true;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen for (i = 0; i < msg_count; i++) {
6c6b1e9fd9ab19249e73f5269931d01d831e4346Timo Sirainen c_name = ldb_msg_find_attr_as_string(msgs[i], SYSDB_NAME, NULL);
6c6b1e9fd9ab19249e73f5269931d01d831e4346Timo Sirainen if (c_name == NULL) {
c2c0c1e5d2e97ae114ad83d8cb486b0aab23ac38Timo Sirainen DEBUG(SSSDBG_MINOR_FAILURE,
c2c0c1e5d2e97ae114ad83d8cb486b0aab23ac38Timo Sirainen ("Something bad happened, can't find attribute %s", SYSDB_NAME));
c2c0c1e5d2e97ae114ad83d8cb486b0aab23ac38Timo Sirainen ERROR("Couldn't invalidate %1$s", type_string);
c2c0c1e5d2e97ae114ad83d8cb486b0aab23ac38Timo Sirainen iret = false;
6c6b1e9fd9ab19249e73f5269931d01d831e4346Timo Sirainen } else {
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen ret = invalidate_entry(ctx, sysdb, dinfo, c_name, entry_type);
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen if (ret != EOK) {
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen DEBUG(SSSDBG_MINOR_FAILURE,
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen ("Couldn't invalidate %s %s", type_string, c_name));
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen ERROR("Couldn't invalidate %1$s %2$s", type_string, c_name);
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen iret = false;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen }
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen }
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen }
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen talloc_zfree(msgs);
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen return iret;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen}
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainenstatic errno_t invalidate_entry(TALLOC_CTX *ctx, struct sysdb_ctx *sysdb,
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen struct sss_domain_info *domain,
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen const char *name, int entry_type)
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen{
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen struct sysdb_attrs *sys_attrs = NULL;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen errno_t ret;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen sys_attrs = sysdb_new_attrs(ctx);
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen if (sys_attrs) {
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen ret = sysdb_attrs_add_time_t(sys_attrs,
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen SYSDB_CACHE_EXPIRE, 1);
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen if (ret == EOK) {
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen switch (entry_type) {
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen case TYPE_USER:
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen ret = sysdb_set_user_attr(sysdb, domain, name, sys_attrs,
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen SYSDB_MOD_REP);
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen break;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen case TYPE_GROUP:
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen ret = sysdb_set_group_attr(sysdb, domain, name, sys_attrs,
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen SYSDB_MOD_REP);
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen break;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen case TYPE_NETGROUP:
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen ret = sysdb_set_netgroup_attr(sysdb, domain, name,
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen sys_attrs, SYSDB_MOD_REP);
ed41ec8aa0efaa50954fd16cb44c86c8350dadccTimo Sirainen break;
ed41ec8aa0efaa50954fd16cb44c86c8350dadccTimo Sirainen case TYPE_SERVICE:
ed41ec8aa0efaa50954fd16cb44c86c8350dadccTimo Sirainen ret = sysdb_set_service_attr(domain, name,
ed41ec8aa0efaa50954fd16cb44c86c8350dadccTimo Sirainen sys_attrs, SYSDB_MOD_REP);
ed41ec8aa0efaa50954fd16cb44c86c8350dadccTimo Sirainen break;
ed41ec8aa0efaa50954fd16cb44c86c8350dadccTimo Sirainen case TYPE_AUTOFSMAP:
ed41ec8aa0efaa50954fd16cb44c86c8350dadccTimo Sirainen ret = sysdb_set_autofsmap_attr(domain, name,
ed41ec8aa0efaa50954fd16cb44c86c8350dadccTimo Sirainen sys_attrs, SYSDB_MOD_REP);
ed41ec8aa0efaa50954fd16cb44c86c8350dadccTimo Sirainen break;
ed41ec8aa0efaa50954fd16cb44c86c8350dadccTimo Sirainen default:
ed41ec8aa0efaa50954fd16cb44c86c8350dadccTimo Sirainen return EINVAL;
ed41ec8aa0efaa50954fd16cb44c86c8350dadccTimo Sirainen }
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen if (ret != EOK) {
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen DEBUG(3, ("Could not set entry attributes\n"));
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen }
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen } else {
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen DEBUG(3, ("Could not add expiration time to attributes\n"));
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen }
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen talloc_zfree(sys_attrs);
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen } else {
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen DEBUG(3, ("Could not create sysdb attributes\n"));
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen ret = ENOMEM;
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen }
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen return ret;
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen}
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainenerrno_t init_domains(struct cache_tool_ctx *ctx, const char *domain)
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen{
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen char *confdb_path;
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen int ret;
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen confdb_path = talloc_asprintf(ctx, "%s/%s", DB_PATH, CONFDB_FILE);
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen if (confdb_path == NULL) {
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen return ENOMEM;
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen }
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen /* Connect to the conf db */
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen ret = confdb_init(ctx, &ctx->confdb, confdb_path);
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen talloc_free(confdb_path);
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen if (ret != EOK) {
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen DEBUG(1, ("Could not initialize connection to the confdb\n"));
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen return ret;
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen }
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen if (domain) {
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen ret = sssd_domain_init(ctx, ctx->confdb,
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen domain, DB_PATH, &ctx->domains);
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen if (ret != EOK) {
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen SYSDB_VERSION_ERROR(ret);
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen DEBUG(1, ("Could not initialize connection to the sysdb\n"));
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen return ret;
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen }
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen } else {
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen ret = confdb_get_domains(ctx->confdb, &ctx->domains);
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen if (ret != EOK) {
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen DEBUG(1, ("Could not initialize domains\n"));
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen return ret;
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen }
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen ret = sysdb_init(ctx, ctx->domains, false);
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen SYSDB_VERSION_ERROR(ret);
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen if (ret != EOK) {
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen DEBUG(1, ("Could not initialize connection to the sysdb\n"));
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen return ret;
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen }
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen }
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen return EOK;
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen}
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainenerrno_t init_context(int argc, const char *argv[], struct cache_tool_ctx **tctx)
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen{
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen struct cache_tool_ctx *ctx = NULL;
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen int idb = INVALIDATE_NONE;
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen char *user = NULL;
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen char *group = NULL;
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen char *netgroup = NULL;
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen char *service = NULL;
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen char *map = NULL;
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen char *domain = NULL;
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen int debug = SSSDBG_DEFAULT;
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen errno_t ret = EOK;
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen poptContext pc = NULL;
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen struct poptOption long_options[] = {
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen POPT_AUTOHELP
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen { "debug", '\0', POPT_ARG_INT | POPT_ARGFLAG_DOC_HIDDEN, &debug,
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen 0, _("The debug level to run with"), NULL },
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen { "everything", 'E', POPT_ARG_NONE, NULL, 'e',
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen _("Invalidate all cached entries except for sudo rules"), NULL },
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen { "user", 'u', POPT_ARG_STRING, &user, 0,
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen _("Invalidate particular user"), NULL },
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen { "users", 'U', POPT_ARG_NONE, NULL, 'u',
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen _("Invalidate all users"), NULL },
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen { "group", 'g', POPT_ARG_STRING, &group, 0,
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen _("Invalidate particular group"), NULL },
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen { "groups", 'G', POPT_ARG_NONE, NULL, 'g',
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen _("Invalidate all groups"), NULL },
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen { "netgroup", 'n', POPT_ARG_STRING, &netgroup, 0,
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen _("Invalidate particular netgroup"), NULL },
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen { "netgroups", 'N', POPT_ARG_NONE, NULL, 'n',
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen _("Invalidate all netgroups"), NULL },
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen { "service", 's', POPT_ARG_STRING, &service, 0,
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen _("Invalidate particular service"), NULL },
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen { "services", 'S', POPT_ARG_NONE, NULL, 's',
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen _("Invalidate all services"), NULL },
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen#ifdef BUILD_AUTOFS
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen { "autofs-map", 'a', POPT_ARG_STRING, &map, 0,
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen _("Invalidate particular autofs map"), NULL },
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen { "autofs-maps", 'A', POPT_ARG_NONE, NULL, 'a',
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen _("Invalidate all autofs maps"), NULL },
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen#endif /* BUILD_AUTOFS */
21fed972adb354b92771eefad27f8ac8cbd5dd45Timo Sirainen { "domain", 'd', POPT_ARG_STRING, &domain, 0,
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen _("Only invalidate entries from a particular domain"), NULL },
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen POPT_TABLEEND
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen };
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen ret = set_locale();
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen if (ret != EOK) {
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen DEBUG(1, ("set_locale failed (%d): %s\n", ret, strerror(ret)));
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen ERROR("Error setting the locale\n");
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen goto fini;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen }
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen pc = poptGetContext(NULL, argc, argv, long_options, 0);
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen while ((ret = poptGetNextOpt(pc)) > 0) {
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen switch (ret) {
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen case 'u':
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen idb |= INVALIDATE_USERS;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen break;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen case 'g':
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen idb |= INVALIDATE_GROUPS;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen break;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen case 'n':
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen idb |= INVALIDATE_NETGROUPS;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen break;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen case 's':
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen idb |= INVALIDATE_SERVICES;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen break;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen case 'a':
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen idb |= INVALIDATE_AUTOFSMAPS;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen break;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen case 'e':
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen idb = INVALIDATE_EVERYTHING;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen break;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen }
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen }
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen DEBUG_INIT(debug);
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen debug_prg_name = argv[0];
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen if (ret != -1) {
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen BAD_POPT_PARAMS(pc, poptStrerror(ret), ret, fini);
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen }
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen if (idb == INVALIDATE_NONE && !user && !group &&
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen !netgroup && !service && !map) {
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen BAD_POPT_PARAMS(pc,
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen _("Please select at least one object to invalidate\n"),
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen ret, fini);
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen }
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen
1c4f8e4c4e5f3a5f05692a2d5c57f96a5b612f3dTimo Sirainen CHECK_ROOT(ret, debug_prg_name);
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen ctx = talloc_zero(NULL, struct cache_tool_ctx);
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen if (ctx == NULL) {
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen DEBUG(1, ("Could not allocate memory for tools context\n"));
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen ret = ENOMEM;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen goto fini;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen }
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen if (idb & INVALIDATE_USERS) {
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen ctx->user_filter = talloc_asprintf(ctx, "(%s=*)", SYSDB_NAME);
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen ctx->update_user_filter = false;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen } else if (user) {
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen ctx->user_name = talloc_strdup(ctx, user);
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen ctx->update_user_filter = true;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen }
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen if (idb & INVALIDATE_GROUPS) {
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen ctx->group_filter = talloc_asprintf(ctx, "(%s=*)", SYSDB_NAME);
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen ctx->update_group_filter = false;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen } else if (group) {
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen ctx->group_name = talloc_strdup(ctx, group);
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen ctx->update_group_filter = true;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen }
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen
68a8f0794a1c2c2267ae4015ef3ccc00604e9175Timo Sirainen if (idb & INVALIDATE_NETGROUPS) {
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen ctx->netgroup_filter = talloc_asprintf(ctx, "(%s=*)", SYSDB_NAME);
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen ctx->update_netgroup_filter = false;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen } else if (netgroup) {
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen ctx->netgroup_name = talloc_strdup(ctx, netgroup);
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen ctx->update_netgroup_filter = true;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen }
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen if (idb & INVALIDATE_SERVICES) {
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen ctx->service_filter = talloc_asprintf(ctx, "(%s=*)", SYSDB_NAME);
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen ctx->update_service_filter = false;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen } else if (service) {
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen ctx->service_name = talloc_strdup(ctx, service);
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen ctx->update_service_filter = true;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen }
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen if (idb & INVALIDATE_AUTOFSMAPS) {
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen ctx->autofs_filter = talloc_asprintf(ctx, "(&(objectclass=%s)(%s=*))",
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen SYSDB_AUTOFS_MAP_OC, SYSDB_NAME);
8f2444f788368b08edb4ac037d5f7e5919cdee0aTimo Sirainen ctx->update_autofs_filter = false;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen } else if (map) {
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen ctx->autofs_name = talloc_strdup(ctx, map);
8f2444f788368b08edb4ac037d5f7e5919cdee0aTimo Sirainen ctx->update_autofs_filter = true;
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen }
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen if (((idb & INVALIDATE_USERS) && !ctx->user_filter) ||
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen ((idb & INVALIDATE_GROUPS) && !ctx->group_filter) ||
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen ((idb & INVALIDATE_NETGROUPS) && !ctx->netgroup_filter) ||
e98de01b5644c88b6053e2921eb5e9a506fe263fTimo Sirainen ((idb & INVALIDATE_SERVICES) && !ctx->service_filter) ||
((idb & INVALIDATE_AUTOFSMAPS) && !ctx->autofs_filter) ||
(user && !ctx->user_name) || (group && !ctx->group_name) ||
(netgroup && !ctx->netgroup_name) || (map && !ctx->autofs_name) ||
(service && !ctx->service_name)) {
DEBUG(1, ("Construction of filters failed\n"));
ret = ENOMEM;
goto fini;
}
ret = init_domains(ctx, domain);
if (ret != EOK) {
if (domain) {
ERROR("Could not open domain %1$s. If the domain is a subdomain "
"(trusted domain), use fully qualified name instead of "
"--domain/-d parameter.\n", domain);
} else {
ERROR("Could not open available domains\n");
}
DEBUG(SSSDBG_OP_FAILURE,
("Initialization of sysdb connections failed\n"));
goto fini;
}
ret = EOK;
fini:
poptFreeContext(pc);
free(user);
free(group);
free(netgroup);
free(domain);
if (ret != EOK && ctx) {
talloc_zfree(ctx);
}
if (ret == EOK) {
*tctx = ctx;
}
return ret;
}
static errno_t
search_autofsmaps(TALLOC_CTX *mem_ctx, struct sysdb_ctx *sysdb,
struct sss_domain_info *domain,
const char *sub_filter, const char **attrs,
size_t *msgs_count, struct ldb_message ***msgs)
{
#ifdef BUILD_AUTOFS
return sysdb_search_custom(mem_ctx, sysdb, domain, sub_filter,
AUTOFS_MAP_SUBDIR, attrs,
msgs_count, msgs);
#else
return ENOSYS;
#endif /* BUILD_AUTOFS */
}