sss_cache.c revision 84c986f9bb2767d8930b6f5d92d34b09b8fabe60
a945f35eff8b6a88009ce73de6d4c862ce58de3cslive Copyright (C) Jan Zeleny <jzeleny@redhat.com> 2011
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 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 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/>.
117c1f888a14e73cdd821dc6c23eb0411144a41cndstatic errno_t search_autofsmaps(TALLOC_CTX *mem_ctx, struct sysdb_ctx *sysdb,
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,
117c1f888a14e73cdd821dc6c23eb0411144a41cndstatic errno_t update_all_filters(struct cache_tool_ctx *tctx,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd bool skipped = true;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ("Error initializing context for the application\n"));
06ba4a61654b3763ad65f52283832ebf058fdf1cslive for (dinfo = tctx->domains; dinfo; dinfo = dinfo->next) {
fb77c505254b6e9c925e23e734463e87574f8f40kess /* Update filters for each domain */
06ba4a61654b3763ad65f52283832ebf058fdf1cslive DEBUG(SSSDBG_CRIT_FAILURE, ("Failed to update filters.\n"));
06ba4a61654b3763ad65f52283832ebf058fdf1cslive DEBUG(SSSDBG_CRIT_FAILURE, ("Could not start the transaction!\n"));
fb77c505254b6e9c925e23e734463e87574f8f40kess skipped &= !invalidate_entries(tctx, dinfo, sysdb, TYPE_USER,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive skipped &= !invalidate_entries(tctx, dinfo, sysdb, TYPE_GROUP,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive skipped &= !invalidate_entries(tctx, dinfo, sysdb, TYPE_NETGROUP,
fb77c505254b6e9c925e23e734463e87574f8f40kess skipped &= !invalidate_entries(tctx, dinfo, sysdb, TYPE_SERVICE,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive skipped &= !invalidate_entries(tctx, dinfo, sysdb, TYPE_AUTOFSMAP,
fb77c505254b6e9c925e23e734463e87574f8f40kess DEBUG(SSSDBG_CRIT_FAILURE, ("Could not commit the transaction!\n"));
06ba4a61654b3763ad65f52283832ebf058fdf1cslive DEBUG(SSSDBG_CRIT_FAILURE, ("Failed to cancel transaction\n"));
fb77c505254b6e9c925e23e734463e87574f8f40kess if (skipped == true) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ERROR("No cache object matched the specified search\n");
130d299c4b2b15be45532a176604c71fdc7bea5bnd DEBUG(SSSDBG_CRIT_FAILURE, ("Failed to clear memory cache.\n"));
fe64b2ba25510d8c9dba5560a2d537763566cf40ndstatic errno_t update_filter(struct cache_tool_ctx *tctx, char *domain_name,
ff797e743eb73c1d45b08158aa6b288c2d0c46eeslive DEBUG(SSSDBG_CRIT_FAILURE, ("sss_parse_name failed\n"));
130d299c4b2b15be45532a176604c71fdc7bea5bnd /* Set to NULL to indicate that it will not be used
130d299c4b2b15be45532a176604c71fdc7bea5bnd * in this domain */
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,
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd ret = sss_names_init(tctx, tctx->confdb, domain_name, &tctx->nctx);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd DEBUG(SSSDBG_CRIT_FAILURE, ("sss_names_init() failed\n"));
fe64b2ba25510d8c9dba5560a2d537763566cf40nd /* Update user filter */
fe64b2ba25510d8c9dba5560a2d537763566cf40nd /* Update group filter */
fb77c505254b6e9c925e23e734463e87574f8f40kess /* Update netgroup filter */
fb77c505254b6e9c925e23e734463e87574f8f40kess ret = update_filter(tctx, domain_name, tctx->netgroup_name,
58699879a562774640b95e9eedfd891f336e38c2nd /* Update service filter */
58699879a562774640b95e9eedfd891f336e38c2nd ret = update_filter(tctx, domain_name, tctx->service_name,
fb77c505254b6e9c925e23e734463e87574f8f40kess /* Update autofs filter */
58699879a562774640b95e9eedfd891f336e38c2nd ret = update_filter(tctx, domain_name, tctx->autofs_name,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd const char *c_name;
fe64b2ba25510d8c9dba5560a2d537763566cf40nd if (!filter) return false;
fb77c505254b6e9c925e23e734463e87574f8f40kess ret = sysdb_search_services(ctx, sysdb, filter, attrs, &msg_count, &msgs);
fb77c505254b6e9c925e23e734463e87574f8f40kess ("Searching for %s in domain %s with filter %s failed\n",
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ERROR("No such %1$s named %2$s in domain %3$s, skipping\n",
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd ERROR("No objects of type %1$s from domain %2$s in the cache, "
06ba4a61654b3763ad65f52283832ebf058fdf1cslive return false;
06ba4a61654b3763ad65f52283832ebf058fdf1cslive for (i = 0; i < msg_count; i++) {
1f53e295ebd19aed1767d12da7abfab9936c148cjerenkrantz c_name = ldb_msg_find_attr_as_string(msgs[i], SYSDB_NAME, NULL);
313bb560bc5c323cfd40c9cad7335b4b8e060aedkess ("Something bad happened, can't find attribute %s", SYSDB_NAME));
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = invalidate_entry(ctx, sysdb, dinfo, c_name, entry_type);
97a9a944b5887e91042b019776c41d5dd74557aferikabele ERROR("Couldn't invalidate %1$s %2$s", type_string, c_name);
97a9a944b5887e91042b019776c41d5dd74557aferikabelestatic errno_t invalidate_entry(TALLOC_CTX *ctx, struct sysdb_ctx *sysdb,
97a9a944b5887e91042b019776c41d5dd74557aferikabele ret = sysdb_set_user_attr(sysdb, domain, name, sys_attrs,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive ret = sysdb_set_group_attr(sysdb, domain, name, sys_attrs,
fe64b2ba25510d8c9dba5560a2d537763566cf40nd DEBUG(3, ("Could not add expiration time to attributes\n"));
06ba4a61654b3763ad65f52283832ebf058fdf1csliveerrno_t init_domains(struct cache_tool_ctx *ctx, const char *domain)
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd confdb_path = talloc_asprintf(ctx, "%s/%s", DB_PATH, CONFDB_FILE);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd /* Connect to the conf db */
fe64b2ba25510d8c9dba5560a2d537763566cf40nd DEBUG(1, ("Could not initialize connection to the confdb\n"));
fe64b2ba25510d8c9dba5560a2d537763566cf40nd DEBUG(1, ("Could not initialize connection to the sysdb\n"));
fe64b2ba25510d8c9dba5560a2d537763566cf40nd DEBUG(1, ("Could not initialize connection to the sysdb\n"));
fe64b2ba25510d8c9dba5560a2d537763566cf40nderrno_t init_context(int argc, const char *argv[], struct cache_tool_ctx **tctx)
fe64b2ba25510d8c9dba5560a2d537763566cf40nd { "debug", '\0', POPT_ARG_INT | POPT_ARGFLAG_DOC_HIDDEN, &debug,
06ba4a61654b3763ad65f52283832ebf058fdf1cslive#endif /* BUILD_AUTOFS */
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd _("Only invalidate entries from a particular domain"), NULL },
06ba4a61654b3763ad65f52283832ebf058fdf1cslive DEBUG(1, ("set_locale failed (%d): %s\n", ret, strerror(ret)));
fb77c505254b6e9c925e23e734463e87574f8f40kess pc = poptGetContext(NULL, argc, argv, long_options, 0);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd switch (ret) {
06ba4a61654b3763ad65f52283832ebf058fdf1cslive _("Please select at least one object to invalidate\n"),
fe64b2ba25510d8c9dba5560a2d537763566cf40nd DEBUG(1, ("Could not allocate memory for tools context\n"));
fe64b2ba25510d8c9dba5560a2d537763566cf40nd ctx->user_filter = talloc_asprintf(ctx, "(%s=*)", SYSDB_NAME);
fe64b2ba25510d8c9dba5560a2d537763566cf40nd } else if (user) {
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd ctx->group_filter = talloc_asprintf(ctx, "(%s=*)", SYSDB_NAME);
fb77c505254b6e9c925e23e734463e87574f8f40kess } else if (group) {
ff797e743eb73c1d45b08158aa6b288c2d0c46eeslive ctx->netgroup_filter = talloc_asprintf(ctx, "(%s=*)", SYSDB_NAME);
130d299c4b2b15be45532a176604c71fdc7bea5bnd } else if (netgroup) {
130d299c4b2b15be45532a176604c71fdc7bea5bnd ctx->service_filter = talloc_asprintf(ctx, "(%s=*)", SYSDB_NAME);
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd } else if (service) {
a7f40ca49262952d6dd69d021cf5b0c2b452ae4cnd ctx->autofs_filter = talloc_asprintf(ctx, "(&(objectclass=%s)(%s=*))",
06ba4a61654b3763ad65f52283832ebf058fdf1cslive } else if (map) {
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) ||
130d299c4b2b15be45532a176604c71fdc7bea5bnd ("Initialization of sysdb connections failed\n"));
06ba4a61654b3763ad65f52283832ebf058fdf1cslivesearch_autofsmaps(TALLOC_CTX *mem_ctx, struct sysdb_ctx *sysdb,
130d299c4b2b15be45532a176604c71fdc7bea5bnd return sysdb_search_custom(mem_ctx, sysdb, domain, sub_filter,
fb77c505254b6e9c925e23e734463e87574f8f40kess#endif /* BUILD_AUTOFS */