sss_cache.c revision 84c986f9bb2767d8930b6f5d92d34b09b8fabe60
97a9a944b5887e91042b019776c41d5dd74557aferikabele/*
97a9a944b5887e91042b019776c41d5dd74557aferikabele SSSD
97a9a944b5887e91042b019776c41d5dd74557aferikabele
a945f35eff8b6a88009ce73de6d4c862ce58de3cslive sss_cache
a945f35eff8b6a88009ce73de6d4c862ce58de3cslive
a945f35eff8b6a88009ce73de6d4c862ce58de3cslive Copyright (C) Jan Zeleny <jzeleny@redhat.com> 2011
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd This program is free software; you can redistribute it and/or modify
fe64b2ba25510d8c9dba5560a2d537763566cf40nd it under the terms of the GNU General Public License as published by
fe64b2ba25510d8c9dba5560a2d537763566cf40nd the Free Software Foundation; either version 3 of the License, or
fe64b2ba25510d8c9dba5560a2d537763566cf40nd (at your option) any later version.
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd This program is distributed in the hope that it will be useful,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd but WITHOUT ANY WARRANTY; without even the implied warranty of
fe64b2ba25510d8c9dba5560a2d537763566cf40nd MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
fe64b2ba25510d8c9dba5560a2d537763566cf40nd GNU General Public License for more details.
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd You should have received a copy of the GNU General Public License
fe64b2ba25510d8c9dba5560a2d537763566cf40nd along with this program. If not, see <http://www.gnu.org/licenses/>.
fe64b2ba25510d8c9dba5560a2d537763566cf40nd*/
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
a63f0ab647ad2ab72efc9bea7a66e24e9ebc5cc2nd#include <stdio.h>
fe64b2ba25510d8c9dba5560a2d537763566cf40nd#include <stdlib.h>
fe64b2ba25510d8c9dba5560a2d537763566cf40nd#include <talloc.h>
fe64b2ba25510d8c9dba5560a2d537763566cf40nd#include <popt.h>
fe64b2ba25510d8c9dba5560a2d537763566cf40nd#include <sys/types.h>
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd#include "util/util.h"
fe64b2ba25510d8c9dba5560a2d537763566cf40nd#include "tools/sss_sync_ops.h"
117c1f888a14e73cdd821dc6c23eb0411144a41cnd#include "db/sysdb.h"
117c1f888a14e73cdd821dc6c23eb0411144a41cnd#include "db/sysdb_services.h"
58699879a562774640b95e9eedfd891f336e38c2nd#include "db/sysdb_autofs.h"
117c1f888a14e73cdd821dc6c23eb0411144a41cnd
117c1f888a14e73cdd821dc6c23eb0411144a41cnd#define INVALIDATE_NONE 0
117c1f888a14e73cdd821dc6c23eb0411144a41cnd#define INVALIDATE_USERS 1
117c1f888a14e73cdd821dc6c23eb0411144a41cnd#define INVALIDATE_GROUPS 2
117c1f888a14e73cdd821dc6c23eb0411144a41cnd#define INVALIDATE_NETGROUPS 4
117c1f888a14e73cdd821dc6c23eb0411144a41cnd#define INVALIDATE_SERVICES 8
117c1f888a14e73cdd821dc6c23eb0411144a41cnd#define INVALIDATE_AUTOFSMAPS 16
117c1f888a14e73cdd821dc6c23eb0411144a41cnd
117c1f888a14e73cdd821dc6c23eb0411144a41cndenum sss_cache_entry {
117c1f888a14e73cdd821dc6c23eb0411144a41cnd TYPE_USER=0,
5f86589186bcc15ee13e288a9d73acbeab2409fbdpejesh TYPE_GROUP,
117c1f888a14e73cdd821dc6c23eb0411144a41cnd TYPE_NETGROUP,
117c1f888a14e73cdd821dc6c23eb0411144a41cnd TYPE_SERVICE,
117c1f888a14e73cdd821dc6c23eb0411144a41cnd TYPE_AUTOFSMAP
117c1f888a14e73cdd821dc6c23eb0411144a41cnd};
117c1f888a14e73cdd821dc6c23eb0411144a41cnd
117c1f888a14e73cdd821dc6c23eb0411144a41cndstatic errno_t search_autofsmaps(TALLOC_CTX *mem_ctx, struct sysdb_ctx *sysdb,
117c1f888a14e73cdd821dc6c23eb0411144a41cnd struct sss_domain_info *domain,
117c1f888a14e73cdd821dc6c23eb0411144a41cnd const char *sub_filter, const char **attrs,
117c1f888a14e73cdd821dc6c23eb0411144a41cnd size_t *msgs_count, struct ldb_message ***msgs);
117c1f888a14e73cdd821dc6c23eb0411144a41cnd
117c1f888a14e73cdd821dc6c23eb0411144a41cndstruct cache_tool_ctx {
117c1f888a14e73cdd821dc6c23eb0411144a41cnd struct confdb_ctx *confdb;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd struct sss_domain_info *domains;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd struct sss_names_ctx *nctx;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd
117c1f888a14e73cdd821dc6c23eb0411144a41cnd char *user_filter;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd char *group_filter;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd char *netgroup_filter;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd char *service_filter;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd char *autofs_filter;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd
117c1f888a14e73cdd821dc6c23eb0411144a41cnd char *user_name;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd char *group_name;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd char *netgroup_name;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd char *service_name;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd char *autofs_name;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd
117c1f888a14e73cdd821dc6c23eb0411144a41cnd bool update_user_filter;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd bool update_group_filter;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd bool update_netgroup_filter;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd bool update_service_filter;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd bool update_autofs_filter;
117c1f888a14e73cdd821dc6c23eb0411144a41cnd};
117c1f888a14e73cdd821dc6c23eb0411144a41cnd
117c1f888a14e73cdd821dc6c23eb0411144a41cnderrno_t init_domains(struct cache_tool_ctx *ctx, const char *domain);
117c1f888a14e73cdd821dc6c23eb0411144a41cnderrno_t init_context(int argc, const char *argv[], struct cache_tool_ctx **tctx);
117c1f888a14e73cdd821dc6c23eb0411144a41cndstatic errno_t invalidate_entry(TALLOC_CTX *ctx, struct sysdb_ctx *sysdb,
117c1f888a14e73cdd821dc6c23eb0411144a41cnd struct sss_domain_info *domain,
117c1f888a14e73cdd821dc6c23eb0411144a41cnd const char *name, int entry_type);
117c1f888a14e73cdd821dc6c23eb0411144a41cndstatic bool invalidate_entries(TALLOC_CTX *ctx,
117c1f888a14e73cdd821dc6c23eb0411144a41cnd struct sss_domain_info *dinfo,
117c1f888a14e73cdd821dc6c23eb0411144a41cnd struct sysdb_ctx *sysdb,
117c1f888a14e73cdd821dc6c23eb0411144a41cnd enum sss_cache_entry entry_type,
117c1f888a14e73cdd821dc6c23eb0411144a41cnd const char *filter, const char *name);
117c1f888a14e73cdd821dc6c23eb0411144a41cndstatic errno_t update_all_filters(struct cache_tool_ctx *tctx,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd char *domain_name);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40ndint main(int argc, const char *argv[])
fe64b2ba25510d8c9dba5560a2d537763566cf40nd{
fe64b2ba25510d8c9dba5560a2d537763566cf40nd errno_t ret;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd struct cache_tool_ctx *tctx = NULL;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd struct sysdb_ctx *sysdb;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd bool skipped = true;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd struct sss_domain_info *dinfo;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = init_context(argc, argv, &tctx);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (ret != EOK) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd DEBUG(SSSDBG_CRIT_FAILURE,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ("Error initializing context for the application\n"));
fe64b2ba25510d8c9dba5560a2d537763566cf40nd goto done;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive for (dinfo = tctx->domains; dinfo; dinfo = dinfo->next) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive sysdb = dinfo->sysdb;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
fb77c505254b6e9c925e23e734463e87574f8f40kess /* Update filters for each domain */
fb77c505254b6e9c925e23e734463e87574f8f40kess ret = update_all_filters(tctx, dinfo->name);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (ret != EOK) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive DEBUG(SSSDBG_CRIT_FAILURE, ("Failed to update filters.\n"));
06ba4a61654b3763ad65f52283832ebf058fdf1cslive goto done;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = sysdb_transaction_start(sysdb);
fb77c505254b6e9c925e23e734463e87574f8f40kess if (ret != EOK) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive DEBUG(SSSDBG_CRIT_FAILURE, ("Could not start the transaction!\n"));
06ba4a61654b3763ad65f52283832ebf058fdf1cslive goto done;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
fb77c505254b6e9c925e23e734463e87574f8f40kess skipped &= !invalidate_entries(tctx, dinfo, sysdb, TYPE_USER,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive tctx->user_filter, tctx->user_name);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive skipped &= !invalidate_entries(tctx, dinfo, sysdb, TYPE_GROUP,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive tctx->group_filter, tctx->group_name);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive skipped &= !invalidate_entries(tctx, dinfo, sysdb, TYPE_NETGROUP,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive tctx->netgroup_filter, tctx->netgroup_name);
fb77c505254b6e9c925e23e734463e87574f8f40kess skipped &= !invalidate_entries(tctx, dinfo, sysdb, TYPE_SERVICE,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive tctx->service_filter, tctx->service_name);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive skipped &= !invalidate_entries(tctx, dinfo, sysdb, TYPE_AUTOFSMAP,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive tctx->autofs_filter, tctx->autofs_name);
fb77c505254b6e9c925e23e734463e87574f8f40kess
fb77c505254b6e9c925e23e734463e87574f8f40kess ret = sysdb_transaction_commit(sysdb);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (ret != EOK) {
fb77c505254b6e9c925e23e734463e87574f8f40kess DEBUG(SSSDBG_CRIT_FAILURE, ("Could not commit the transaction!\n"));
fb77c505254b6e9c925e23e734463e87574f8f40kess ret = sysdb_transaction_cancel(sysdb);
fb77c505254b6e9c925e23e734463e87574f8f40kess if (ret != EOK) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive DEBUG(SSSDBG_CRIT_FAILURE, ("Failed to cancel transaction\n"));
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
fb77c505254b6e9c925e23e734463e87574f8f40kess
fb77c505254b6e9c925e23e734463e87574f8f40kess if (skipped == true) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ERROR("No cache object matched the specified search\n");
fb77c505254b6e9c925e23e734463e87574f8f40kess ret = ENOENT;
fb77c505254b6e9c925e23e734463e87574f8f40kess goto done;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive } else {
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd ret = sss_memcache_clear_all();
130d299c4b2b15be45532a176604c71fdc7bea5bnd if (ret != EOK) {
130d299c4b2b15be45532a176604c71fdc7bea5bnd DEBUG(SSSDBG_CRIT_FAILURE, ("Failed to clear memory cache.\n"));
130d299c4b2b15be45532a176604c71fdc7bea5bnd goto done;
130d299c4b2b15be45532a176604c71fdc7bea5bnd }
130d299c4b2b15be45532a176604c71fdc7bea5bnd }
130d299c4b2b15be45532a176604c71fdc7bea5bnd
130d299c4b2b15be45532a176604c71fdc7bea5bnd ret = EOK;
130d299c4b2b15be45532a176604c71fdc7bea5bnddone:
130d299c4b2b15be45532a176604c71fdc7bea5bnd if (tctx) talloc_free(tctx);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd return ret;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd}
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40ndstatic errno_t update_filter(struct cache_tool_ctx *tctx, char *domain_name,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd char *name, bool update, const char *fmt,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd char **filter)
fe64b2ba25510d8c9dba5560a2d537763566cf40nd{
fe64b2ba25510d8c9dba5560a2d537763566cf40nd errno_t ret;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd char *parsed_domain = NULL;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd char *parsed_name = NULL;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (name && update) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = sss_parse_name(tctx, tctx->nctx, name,
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess &parsed_domain, &parsed_name);
ff797e743eb73c1d45b08158aa6b288c2d0c46eeslive if (ret != EOK) {
ff797e743eb73c1d45b08158aa6b288c2d0c46eeslive DEBUG(SSSDBG_CRIT_FAILURE, ("sss_parse_name failed\n"));
ff797e743eb73c1d45b08158aa6b288c2d0c46eeslive goto done;
ff797e743eb73c1d45b08158aa6b288c2d0c46eeslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd if (parsed_domain) {
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd talloc_free(*filter);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd if (!strcmp(domain_name, parsed_domain)) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (fmt) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive *filter = talloc_asprintf(tctx, fmt,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive SYSDB_NAME, parsed_name);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive } else {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive *filter = talloc_strdup(tctx, parsed_name);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (*filter == NULL) {
130d299c4b2b15be45532a176604c71fdc7bea5bnd DEBUG(SSSDBG_CRIT_FAILURE, ("Out of memory\n"));
130d299c4b2b15be45532a176604c71fdc7bea5bnd ret = ENOMEM;
130d299c4b2b15be45532a176604c71fdc7bea5bnd goto done;
130d299c4b2b15be45532a176604c71fdc7bea5bnd }
130d299c4b2b15be45532a176604c71fdc7bea5bnd } else {
130d299c4b2b15be45532a176604c71fdc7bea5bnd /* Set to NULL to indicate that it will not be used
130d299c4b2b15be45532a176604c71fdc7bea5bnd * in this domain */
fe64b2ba25510d8c9dba5560a2d537763566cf40nd *filter = NULL;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd } else {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (fmt) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd *filter = talloc_asprintf(tctx, fmt, SYSDB_NAME, name);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd } else {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd *filter = talloc_strdup(tctx, name);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (*filter == NULL) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd DEBUG(SSSDBG_CRIT_FAILURE, ("Out of memory\n"));
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = ENOMEM;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd goto done;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = EOK;
fe64b2ba25510d8c9dba5560a2d537763566cf40nddone:
fe64b2ba25510d8c9dba5560a2d537763566cf40nd talloc_free(parsed_domain);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd talloc_free(parsed_name);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive return ret;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive}
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive/* This function updates all filters for specified domain using this
06ba4a61654b3763ad65f52283832ebf058fdf1cslive * domains regex to parse string into domain and name (if exists). */
06ba4a61654b3763ad65f52283832ebf058fdf1cslivestatic errno_t update_all_filters(struct cache_tool_ctx *tctx,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive char *domain_name)
06ba4a61654b3763ad65f52283832ebf058fdf1cslive{
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd errno_t ret;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd ret = sss_names_init(tctx, tctx->confdb, domain_name, &tctx->nctx);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd if (ret != EOK) {
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd DEBUG(SSSDBG_CRIT_FAILURE, ("sss_names_init() failed\n"));
fe64b2ba25510d8c9dba5560a2d537763566cf40nd return ret;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd /* Update user filter */
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = update_filter(tctx, domain_name, tctx->user_name,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd tctx->update_user_filter, "(%s=%s)",
fb77c505254b6e9c925e23e734463e87574f8f40kess &tctx->user_filter);
fb77c505254b6e9c925e23e734463e87574f8f40kess if (ret != EOK) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd return ret;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd /* Update group filter */
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = update_filter(tctx, domain_name, tctx->group_name,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd tctx->update_group_filter, "(%s=%s)",
58699879a562774640b95e9eedfd891f336e38c2nd &tctx->group_filter);
58699879a562774640b95e9eedfd891f336e38c2nd if (ret != EOK) {
58699879a562774640b95e9eedfd891f336e38c2nd return ret;
fb77c505254b6e9c925e23e734463e87574f8f40kess }
fb77c505254b6e9c925e23e734463e87574f8f40kess
fb77c505254b6e9c925e23e734463e87574f8f40kess /* Update netgroup filter */
fb77c505254b6e9c925e23e734463e87574f8f40kess ret = update_filter(tctx, domain_name, tctx->netgroup_name,
fb77c505254b6e9c925e23e734463e87574f8f40kess tctx->update_netgroup_filter, "(%s=%s)",
58699879a562774640b95e9eedfd891f336e38c2nd &tctx->netgroup_filter);
58699879a562774640b95e9eedfd891f336e38c2nd if (ret != EOK) {
58699879a562774640b95e9eedfd891f336e38c2nd return ret;
58699879a562774640b95e9eedfd891f336e38c2nd }
58699879a562774640b95e9eedfd891f336e38c2nd
58699879a562774640b95e9eedfd891f336e38c2nd /* Update service filter */
58699879a562774640b95e9eedfd891f336e38c2nd ret = update_filter(tctx, domain_name, tctx->service_name,
58699879a562774640b95e9eedfd891f336e38c2nd tctx->update_service_filter, "(%s=%s)",
58699879a562774640b95e9eedfd891f336e38c2nd &tctx->service_filter);
58699879a562774640b95e9eedfd891f336e38c2nd if (ret != EOK) {
58699879a562774640b95e9eedfd891f336e38c2nd return ret;
fb77c505254b6e9c925e23e734463e87574f8f40kess }
fb77c505254b6e9c925e23e734463e87574f8f40kess
fb77c505254b6e9c925e23e734463e87574f8f40kess /* Update autofs filter */
58699879a562774640b95e9eedfd891f336e38c2nd ret = update_filter(tctx, domain_name, tctx->autofs_name,
58699879a562774640b95e9eedfd891f336e38c2nd tctx->update_autofs_filter,
58699879a562774640b95e9eedfd891f336e38c2nd "(&(objectclass="SYSDB_AUTOFS_MAP_OC")(%s=%s))",
58699879a562774640b95e9eedfd891f336e38c2nd &tctx->autofs_filter);
58699879a562774640b95e9eedfd891f336e38c2nd if (ret != EOK) {
58699879a562774640b95e9eedfd891f336e38c2nd return ret;
58699879a562774640b95e9eedfd891f336e38c2nd }
58699879a562774640b95e9eedfd891f336e38c2nd
58699879a562774640b95e9eedfd891f336e38c2nd return EOK;
58699879a562774640b95e9eedfd891f336e38c2nd}
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess
4a7affccb2f1f5b94cab395e1bf3825aed715ebcndstatic bool invalidate_entries(TALLOC_CTX *ctx,
4a7affccb2f1f5b94cab395e1bf3825aed715ebcnd struct sss_domain_info *dinfo,
4a7affccb2f1f5b94cab395e1bf3825aed715ebcnd struct sysdb_ctx *sysdb,
4a7affccb2f1f5b94cab395e1bf3825aed715ebcnd enum sss_cache_entry entry_type,
4a7affccb2f1f5b94cab395e1bf3825aed715ebcnd const char *filter, const char *name)
4a7affccb2f1f5b94cab395e1bf3825aed715ebcnd{
4a7affccb2f1f5b94cab395e1bf3825aed715ebcnd const char *attrs[] = {SYSDB_NAME, NULL};
4a7affccb2f1f5b94cab395e1bf3825aed715ebcnd size_t msg_count;
4a7affccb2f1f5b94cab395e1bf3825aed715ebcnd struct ldb_message **msgs;
4a7affccb2f1f5b94cab395e1bf3825aed715ebcnd const char *type_string = "unknown";
ec9b02c6869b75575ada34c800672162833a2c06nd errno_t ret = EINVAL;
58699879a562774640b95e9eedfd891f336e38c2nd int i;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd const char *c_name;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd bool iret;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (!filter) return false;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd switch (entry_type) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd case TYPE_USER:
fe64b2ba25510d8c9dba5560a2d537763566cf40nd type_string = "user";
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = sysdb_search_users(ctx, sysdb, dinfo,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd filter, attrs, &msg_count, &msgs);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd break;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd case TYPE_GROUP:
fe64b2ba25510d8c9dba5560a2d537763566cf40nd type_string = "group";
fb77c505254b6e9c925e23e734463e87574f8f40kess ret = sysdb_search_groups(ctx, sysdb, dinfo,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd filter, attrs, &msg_count, &msgs);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd break;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd case TYPE_NETGROUP:
fe64b2ba25510d8c9dba5560a2d537763566cf40nd type_string = "netgroup";
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = sysdb_search_netgroups(ctx, sysdb, dinfo,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd filter, attrs, &msg_count, &msgs);
fb77c505254b6e9c925e23e734463e87574f8f40kess break;
fb77c505254b6e9c925e23e734463e87574f8f40kess case TYPE_SERVICE:
fb77c505254b6e9c925e23e734463e87574f8f40kess type_string = "service";
fb77c505254b6e9c925e23e734463e87574f8f40kess ret = sysdb_search_services(ctx, sysdb, filter, attrs, &msg_count, &msgs);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive break;
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess case TYPE_AUTOFSMAP:
10673857794a4b3d9568ca2d983722a87ed352f1rbowen type_string = "autofs map";
fb77c505254b6e9c925e23e734463e87574f8f40kess ret = search_autofsmaps(ctx, sysdb, dinfo,
f4f4505fedd39d92f787066b0ba8ec912e778784nd filter, attrs, &msg_count, &msgs);
10673857794a4b3d9568ca2d983722a87ed352f1rbowen break;
10673857794a4b3d9568ca2d983722a87ed352f1rbowen }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
fb77c505254b6e9c925e23e734463e87574f8f40kess if (ret != EOK) {
fb77c505254b6e9c925e23e734463e87574f8f40kess DEBUG(SSSDBG_MINOR_FAILURE,
fb77c505254b6e9c925e23e734463e87574f8f40kess ("Searching for %s in domain %s with filter %s failed\n",
06ba4a61654b3763ad65f52283832ebf058fdf1cslive type_string, dinfo->name, filter));
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (name) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ERROR("No such %1$s named %2$s in domain %3$s, skipping\n",
fb77c505254b6e9c925e23e734463e87574f8f40kess type_string, name, dinfo->name);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive } else {
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd ERROR("No objects of type %1$s from domain %2$s in the cache, "
06ba4a61654b3763ad65f52283832ebf058fdf1cslive "skipping\n", type_string, dinfo->name);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive return false;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive iret = true;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive for (i = 0; i < msg_count; i++) {
1f53e295ebd19aed1767d12da7abfab9936c148cjerenkrantz c_name = ldb_msg_find_attr_as_string(msgs[i], SYSDB_NAME, NULL);
1f53e295ebd19aed1767d12da7abfab9936c148cjerenkrantz if (c_name == NULL) {
cb3a1082aec4b3b4f4ed238c93c3cc54933a7f0end DEBUG(SSSDBG_MINOR_FAILURE,
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess ("Something bad happened, can't find attribute %s", SYSDB_NAME));
1f53e295ebd19aed1767d12da7abfab9936c148cjerenkrantz ERROR("Couldn't invalidate %1$s", type_string);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive iret = false;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive } else {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = invalidate_entry(ctx, sysdb, dinfo, c_name, entry_type);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (ret != EOK) {
97a9a944b5887e91042b019776c41d5dd74557aferikabele DEBUG(SSSDBG_MINOR_FAILURE,
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess ("Couldn't invalidate %s %s", type_string, c_name));
97a9a944b5887e91042b019776c41d5dd74557aferikabele ERROR("Couldn't invalidate %1$s %2$s", type_string, c_name);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive iret = false;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive talloc_zfree(msgs);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive return iret;
97a9a944b5887e91042b019776c41d5dd74557aferikabele}
97a9a944b5887e91042b019776c41d5dd74557aferikabele
97a9a944b5887e91042b019776c41d5dd74557aferikabelestatic errno_t invalidate_entry(TALLOC_CTX *ctx, struct sysdb_ctx *sysdb,
97a9a944b5887e91042b019776c41d5dd74557aferikabele struct sss_domain_info *domain,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive const char *name, int entry_type)
06ba4a61654b3763ad65f52283832ebf058fdf1cslive{
06ba4a61654b3763ad65f52283832ebf058fdf1cslive struct sysdb_attrs *sys_attrs = NULL;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive errno_t ret;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
cb3a1082aec4b3b4f4ed238c93c3cc54933a7f0end sys_attrs = sysdb_new_attrs(ctx);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (sys_attrs) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = sysdb_attrs_add_time_t(sys_attrs,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive SYSDB_CACHE_EXPIRE, 1);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (ret == EOK) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive switch (entry_type) {
97a9a944b5887e91042b019776c41d5dd74557aferikabele case TYPE_USER:
97a9a944b5887e91042b019776c41d5dd74557aferikabele ret = sysdb_set_user_attr(sysdb, domain, name, sys_attrs,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive SYSDB_MOD_REP);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive break;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive case TYPE_GROUP:
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = sysdb_set_group_attr(sysdb, domain, name, sys_attrs,
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd SYSDB_MOD_REP);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd break;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd case TYPE_NETGROUP:
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = sysdb_set_netgroup_attr(sysdb, domain, name,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd sys_attrs, SYSDB_MOD_REP);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd break;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd case TYPE_SERVICE:
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = sysdb_set_service_attr(sysdb, name,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd sys_attrs, SYSDB_MOD_REP);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd break;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd case TYPE_AUTOFSMAP:
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = sysdb_set_autofsmap_attr(sysdb, name,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd sys_attrs, SYSDB_MOD_REP);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd break;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd default:
fe64b2ba25510d8c9dba5560a2d537763566cf40nd return EINVAL;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (ret != EOK) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd DEBUG(3, ("Could not set entry attributes\n"));
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd } else {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd DEBUG(3, ("Could not add expiration time to attributes\n"));
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive talloc_zfree(sys_attrs);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive } else {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive DEBUG(3, ("Could not create sysdb attributes\n"));
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = ENOMEM;
97a9a944b5887e91042b019776c41d5dd74557aferikabele }
cb3a1082aec4b3b4f4ed238c93c3cc54933a7f0end return ret;
cb3a1082aec4b3b4f4ed238c93c3cc54933a7f0end}
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1csliveerrno_t init_domains(struct cache_tool_ctx *ctx, const char *domain)
06ba4a61654b3763ad65f52283832ebf058fdf1cslive{
06ba4a61654b3763ad65f52283832ebf058fdf1cslive char *confdb_path;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd int ret;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd confdb_path = talloc_asprintf(ctx, "%s/%s", DB_PATH, CONFDB_FILE);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (confdb_path == NULL) {
1c9f7cdf2e1bc8313e559a96638c3c36e3143791yoshiki return ENOMEM;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd /* Connect to the conf db */
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = confdb_init(ctx, &ctx->confdb, confdb_path);
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess talloc_free(confdb_path);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (ret != EOK) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd DEBUG(1, ("Could not initialize connection to the confdb\n"));
fe64b2ba25510d8c9dba5560a2d537763566cf40nd return ret;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (domain) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = sssd_domain_init(ctx, ctx->confdb,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd domain, DB_PATH, &ctx->domains);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (ret != EOK) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd SYSDB_VERSION_ERROR(ret);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd DEBUG(1, ("Could not initialize connection to the sysdb\n"));
fe64b2ba25510d8c9dba5560a2d537763566cf40nd return ret;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive } else {
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess ret = confdb_get_domains(ctx->confdb, &ctx->domains);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (ret != EOK) {
97a9a944b5887e91042b019776c41d5dd74557aferikabele DEBUG(1, ("Could not initialize domains\n"));
cb3a1082aec4b3b4f4ed238c93c3cc54933a7f0end return ret;
cb3a1082aec4b3b4f4ed238c93c3cc54933a7f0end }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = sysdb_init(ctx, ctx->domains, NULL, false);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd SYSDB_VERSION_ERROR(ret);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (ret != EOK) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd DEBUG(1, ("Could not initialize connection to the sysdb\n"));
fe64b2ba25510d8c9dba5560a2d537763566cf40nd return ret;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd return EOK;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd}
fb77c505254b6e9c925e23e734463e87574f8f40kess
fe64b2ba25510d8c9dba5560a2d537763566cf40nderrno_t init_context(int argc, const char *argv[], struct cache_tool_ctx **tctx)
fb77c505254b6e9c925e23e734463e87574f8f40kess{
fe64b2ba25510d8c9dba5560a2d537763566cf40nd struct cache_tool_ctx *ctx = NULL;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd int idb = INVALIDATE_NONE;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd char *user = NULL;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd char *group = NULL;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd char *netgroup = NULL;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd char *service = NULL;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd char *map = NULL;
70ada6b79498c38ab85985a3d30ee11248ce897byoshiki char *domain = NULL;
fb77c505254b6e9c925e23e734463e87574f8f40kess int debug = SSSDBG_DEFAULT;
fb77c505254b6e9c925e23e734463e87574f8f40kess errno_t ret = EOK;
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess poptContext pc = NULL;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd struct poptOption long_options[] = {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd POPT_AUTOHELP
fe64b2ba25510d8c9dba5560a2d537763566cf40nd { "debug", '\0', POPT_ARG_INT | POPT_ARGFLAG_DOC_HIDDEN, &debug,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd 0, _("The debug level to run with"), NULL },
fe64b2ba25510d8c9dba5560a2d537763566cf40nd { "user", 'u', POPT_ARG_STRING, &user, 0,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd _("Invalidate particular user"), NULL },
fe64b2ba25510d8c9dba5560a2d537763566cf40nd { "users", 'U', POPT_ARG_NONE, NULL, 'u',
fb77c505254b6e9c925e23e734463e87574f8f40kess _("Invalidate all users"), NULL },
fb77c505254b6e9c925e23e734463e87574f8f40kess { "group", 'g', POPT_ARG_STRING, &group, 0,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd _("Invalidate particular group"), NULL },
fe64b2ba25510d8c9dba5560a2d537763566cf40nd { "groups", 'G', POPT_ARG_NONE, NULL, 'g',
fe64b2ba25510d8c9dba5560a2d537763566cf40nd _("Invalidate all groups"), NULL },
fe64b2ba25510d8c9dba5560a2d537763566cf40nd { "netgroup", 'n', POPT_ARG_STRING, &netgroup, 0,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd _("Invalidate particular netgroup"), NULL },
06ba4a61654b3763ad65f52283832ebf058fdf1cslive { "netgroups", 'N', POPT_ARG_NONE, NULL, 'n',
06ba4a61654b3763ad65f52283832ebf058fdf1cslive _("Invalidate all netgroups"), NULL },
06ba4a61654b3763ad65f52283832ebf058fdf1cslive { "service", 's', POPT_ARG_STRING, &service, 0,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive _("Invalidate particular service"), NULL },
06ba4a61654b3763ad65f52283832ebf058fdf1cslive { "services", 'S', POPT_ARG_NONE, NULL, 's',
06ba4a61654b3763ad65f52283832ebf058fdf1cslive _("Invalidate all services"), NULL },
06ba4a61654b3763ad65f52283832ebf058fdf1cslive#ifdef BUILD_AUTOFS
06ba4a61654b3763ad65f52283832ebf058fdf1cslive { "autofs-map", 'a', POPT_ARG_STRING, &map, 0,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive _("Invalidate particular autofs map"), NULL },
06ba4a61654b3763ad65f52283832ebf058fdf1cslive { "autofs-maps", 'A', POPT_ARG_NONE, NULL, 'a',
06ba4a61654b3763ad65f52283832ebf058fdf1cslive _("Invalidate all autofs maps"), NULL },
06ba4a61654b3763ad65f52283832ebf058fdf1cslive#endif /* BUILD_AUTOFS */
06ba4a61654b3763ad65f52283832ebf058fdf1cslive { "domain", 'd', POPT_ARG_STRING, &domain, 0,
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd _("Only invalidate entries from a particular domain"), NULL },
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd POPT_TABLEEND
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd };
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = set_locale();
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (ret != EOK) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive DEBUG(1, ("set_locale failed (%d): %s\n", ret, strerror(ret)));
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ERROR("Error setting the locale\n");
06ba4a61654b3763ad65f52283832ebf058fdf1cslive goto fini;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
fb77c505254b6e9c925e23e734463e87574f8f40kess
fb77c505254b6e9c925e23e734463e87574f8f40kess pc = poptGetContext(NULL, argc, argv, long_options, 0);
fb77c505254b6e9c925e23e734463e87574f8f40kess while ((ret = poptGetNextOpt(pc)) > 0) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd switch (ret) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd case 'u':
fe64b2ba25510d8c9dba5560a2d537763566cf40nd idb |= INVALIDATE_USERS;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd break;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd case 'g':
fe64b2ba25510d8c9dba5560a2d537763566cf40nd idb |= INVALIDATE_GROUPS;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd break;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd case 'n':
fe64b2ba25510d8c9dba5560a2d537763566cf40nd idb |= INVALIDATE_NETGROUPS;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd break;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd case 's':
fe64b2ba25510d8c9dba5560a2d537763566cf40nd idb |= INVALIDATE_SERVICES;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd break;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd case 'a':
06ba4a61654b3763ad65f52283832ebf058fdf1cslive idb |= INVALIDATE_AUTOFSMAPS;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive break;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (ret != -1) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive BAD_POPT_PARAMS(pc, poptStrerror(ret), ret, fini);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd if (idb == INVALIDATE_NONE && !user && !group &&
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd !netgroup && !service && !map) {
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd BAD_POPT_PARAMS(pc,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive _("Please select at least one object to invalidate\n"),
fb77c505254b6e9c925e23e734463e87574f8f40kess ret, fini);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
97a9a944b5887e91042b019776c41d5dd74557aferikabele
06ba4a61654b3763ad65f52283832ebf058fdf1cslive DEBUG_INIT(debug);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive debug_prg_name = argv[0];
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess CHECK_ROOT(ret, debug_prg_name);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ctx = talloc_zero(NULL, struct cache_tool_ctx);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (ctx == NULL) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd DEBUG(1, ("Could not allocate memory for tools context\n"));
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ret = ENOMEM;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd goto fini;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd }
fe64b2ba25510d8c9dba5560a2d537763566cf40nd
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (idb & INVALIDATE_USERS) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ctx->user_filter = talloc_asprintf(ctx, "(%s=*)", SYSDB_NAME);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ctx->update_user_filter = false;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd } else if (user) {
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ctx->user_name = talloc_strdup(ctx, user);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ctx->update_user_filter = true;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
ff797e743eb73c1d45b08158aa6b288c2d0c46eeslive
ff797e743eb73c1d45b08158aa6b288c2d0c46eeslive if (idb & INVALIDATE_GROUPS) {
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd ctx->group_filter = talloc_asprintf(ctx, "(%s=*)", SYSDB_NAME);
ff797e743eb73c1d45b08158aa6b288c2d0c46eeslive ctx->update_group_filter = false;
fb77c505254b6e9c925e23e734463e87574f8f40kess } else if (group) {
fb77c505254b6e9c925e23e734463e87574f8f40kess ctx->group_name = talloc_strdup(ctx, group);
fb77c505254b6e9c925e23e734463e87574f8f40kess ctx->update_group_filter = true;
fb77c505254b6e9c925e23e734463e87574f8f40kess }
ff797e743eb73c1d45b08158aa6b288c2d0c46eeslive
ff797e743eb73c1d45b08158aa6b288c2d0c46eeslive if (idb & INVALIDATE_NETGROUPS) {
ff797e743eb73c1d45b08158aa6b288c2d0c46eeslive ctx->netgroup_filter = talloc_asprintf(ctx, "(%s=*)", SYSDB_NAME);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd ctx->update_netgroup_filter = false;
130d299c4b2b15be45532a176604c71fdc7bea5bnd } else if (netgroup) {
130d299c4b2b15be45532a176604c71fdc7bea5bnd ctx->netgroup_name = talloc_strdup(ctx, netgroup);
130d299c4b2b15be45532a176604c71fdc7bea5bnd ctx->update_netgroup_filter = true;
130d299c4b2b15be45532a176604c71fdc7bea5bnd }
130d299c4b2b15be45532a176604c71fdc7bea5bnd
130d299c4b2b15be45532a176604c71fdc7bea5bnd if (idb & INVALIDATE_SERVICES) {
130d299c4b2b15be45532a176604c71fdc7bea5bnd ctx->service_filter = talloc_asprintf(ctx, "(%s=*)", SYSDB_NAME);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd ctx->update_service_filter = false;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd } else if (service) {
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd ctx->service_name = talloc_strdup(ctx, service);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd ctx->update_service_filter = true;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd }
fb77c505254b6e9c925e23e734463e87574f8f40kess
fb77c505254b6e9c925e23e734463e87574f8f40kess if (idb & INVALIDATE_AUTOFSMAPS) {
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd ctx->autofs_filter = talloc_asprintf(ctx, "(&(objectclass=%s)(%s=*))",
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd SYSDB_AUTOFS_MAP_OC, SYSDB_NAME);
b06660a3ed3d885e15d99c0209a46c4657df33fbrbowen ctx->update_autofs_filter = false;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive } else if (map) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ctx->autofs_name = talloc_strdup(ctx, map);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ctx->update_autofs_filter = true;
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd }
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd if (((idb & INVALIDATE_USERS) && !ctx->user_filter) ||
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd ((idb & INVALIDATE_GROUPS) && !ctx->group_filter) ||
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd ((idb & INVALIDATE_NETGROUPS) && !ctx->netgroup_filter) ||
fb77c505254b6e9c925e23e734463e87574f8f40kess ((idb & INVALIDATE_SERVICES) && !ctx->service_filter) ||
fb77c505254b6e9c925e23e734463e87574f8f40kess ((idb & INVALIDATE_AUTOFSMAPS) && !ctx->autofs_filter) ||
06ba4a61654b3763ad65f52283832ebf058fdf1cslive (user && !ctx->user_name) || (group && !ctx->group_name) ||
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess (netgroup && !ctx->netgroup_name) || (map && !ctx->autofs_name) ||
06ba4a61654b3763ad65f52283832ebf058fdf1cslive (service && !ctx->service_name)) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive DEBUG(1, ("Construction of filters failed\n"));
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = ENOMEM;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive goto fini;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
130d299c4b2b15be45532a176604c71fdc7bea5bnd
130d299c4b2b15be45532a176604c71fdc7bea5bnd ret = init_domains(ctx, domain);
130d299c4b2b15be45532a176604c71fdc7bea5bnd if (ret != EOK) {
130d299c4b2b15be45532a176604c71fdc7bea5bnd if (domain) {
130d299c4b2b15be45532a176604c71fdc7bea5bnd ERROR("Could not open domain %1$s\n", domain);
130d299c4b2b15be45532a176604c71fdc7bea5bnd } else {
130d299c4b2b15be45532a176604c71fdc7bea5bnd ERROR("Could not open available domains\n");
130d299c4b2b15be45532a176604c71fdc7bea5bnd }
130d299c4b2b15be45532a176604c71fdc7bea5bnd DEBUG(SSSDBG_OP_FAILURE,
130d299c4b2b15be45532a176604c71fdc7bea5bnd ("Initialization of sysdb connections failed\n"));
130d299c4b2b15be45532a176604c71fdc7bea5bnd goto fini;
130d299c4b2b15be45532a176604c71fdc7bea5bnd }
130d299c4b2b15be45532a176604c71fdc7bea5bnd
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd ret = EOK;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslivefini:
06ba4a61654b3763ad65f52283832ebf058fdf1cslive poptFreeContext(pc);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive free(user);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive free(group);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive free(netgroup);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive free(domain);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive if (ret != EOK && ctx) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive talloc_zfree(ctx);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess if (ret == EOK) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive *tctx = ctx;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive }
06ba4a61654b3763ad65f52283832ebf058fdf1cslive return ret;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive}
06ba4a61654b3763ad65f52283832ebf058fdf1cslive
06ba4a61654b3763ad65f52283832ebf058fdf1cslivestatic errno_t
06ba4a61654b3763ad65f52283832ebf058fdf1cslivesearch_autofsmaps(TALLOC_CTX *mem_ctx, struct sysdb_ctx *sysdb,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive struct sss_domain_info *domain,
130d299c4b2b15be45532a176604c71fdc7bea5bnd const char *sub_filter, const char **attrs,
130d299c4b2b15be45532a176604c71fdc7bea5bnd size_t *msgs_count, struct ldb_message ***msgs)
130d299c4b2b15be45532a176604c71fdc7bea5bnd{
130d299c4b2b15be45532a176604c71fdc7bea5bnd#ifdef BUILD_AUTOFS
130d299c4b2b15be45532a176604c71fdc7bea5bnd return sysdb_search_custom(mem_ctx, sysdb, domain, sub_filter,
130d299c4b2b15be45532a176604c71fdc7bea5bnd AUTOFS_MAP_SUBDIR, attrs,
130d299c4b2b15be45532a176604c71fdc7bea5bnd msgs_count, msgs);
06ba4a61654b3763ad65f52283832ebf058fdf1cslive#else
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess return ENOSYS;
fb77c505254b6e9c925e23e734463e87574f8f40kess#endif /* BUILD_AUTOFS */
fb77c505254b6e9c925e23e734463e87574f8f40kess}
06ba4a61654b3763ad65f52283832ebf058fdf1cslive