sss_cache.c revision e7d1cd14ce1a427007b1a7e9789dcb7e9619f84f
00bf64c70c231f647c12c2fd49925ef73cb07f07Timo Sirainen Copyright (C) Jan Zeleny <jzeleny@redhat.com> 2011
e15b305e90c9834734ccf35ed78f0ad29d570ee9Timo Sirainen This program is free software; you can redistribute it and/or modify
e15b305e90c9834734ccf35ed78f0ad29d570ee9Timo Sirainen it under the terms of the GNU General Public License as published by
e15b305e90c9834734ccf35ed78f0ad29d570ee9Timo Sirainen the Free Software Foundation; either version 3 of the License, or
e15b305e90c9834734ccf35ed78f0ad29d570ee9Timo Sirainen (at your option) any later version.
e15b305e90c9834734ccf35ed78f0ad29d570ee9Timo Sirainen This program is distributed in the hope that it will be useful,
e15b305e90c9834734ccf35ed78f0ad29d570ee9Timo Sirainen but WITHOUT ANY WARRANTY; without even the implied warranty of
e15b305e90c9834734ccf35ed78f0ad29d570ee9Timo Sirainen MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e15b305e90c9834734ccf35ed78f0ad29d570ee9Timo Sirainen GNU General Public License for more details.
e15b305e90c9834734ccf35ed78f0ad29d570ee9Timo Sirainen You should have received a copy of the GNU General Public License
e15b305e90c9834734ccf35ed78f0ad29d570ee9Timo Sirainen along with this program. If not, see <http://www.gnu.org/licenses/>.
e15b305e90c9834734ccf35ed78f0ad29d570ee9Timo Sirainen#define INVALIDATE_EVERYTHING (INVALIDATE_USERS | INVALIDATE_GROUPS | \
063254ba79239f1c0a78ea08d4aa22f8f11d984cTimo Sirainen INVALIDATE_NETGROUPS | INVALIDATE_SERVICES | \
e15b305e90c9834734ccf35ed78f0ad29d570ee9Timo Sirainen#define INVALIDATE_EVERYTHING (INVALIDATE_USERS | INVALIDATE_GROUPS | \
e15b305e90c9834734ccf35ed78f0ad29d570ee9Timo Sirainenstatic errno_t search_autofsmaps(TALLOC_CTX *mem_ctx, struct sysdb_ctx *sysdb,
e15b305e90c9834734ccf35ed78f0ad29d570ee9Timo Sirainen size_t *msgs_count, struct ldb_message ***msgs);
13f6c879a84b3edd2fcc8f9832812be1f8c5d3b6Timo Sirainenerrno_t init_domains(struct cache_tool_ctx *ctx, const char *domain);
13f6c879a84b3edd2fcc8f9832812be1f8c5d3b6Timo Sirainenerrno_t init_context(int argc, const char *argv[], struct cache_tool_ctx **tctx);
8ddc45fe2080010715c212ecbb2b12b6734f6d4bTimo Sirainenstatic errno_t invalidate_entry(TALLOC_CTX *ctx, struct sysdb_ctx *sysdb,
e15b305e90c9834734ccf35ed78f0ad29d570ee9Timo Sirainenstatic bool invalidate_entries(TALLOC_CTX *ctx,
e15b305e90c9834734ccf35ed78f0ad29d570ee9Timo Sirainenstatic errno_t update_all_filters(struct cache_tool_ctx *tctx,
e15b305e90c9834734ccf35ed78f0ad29d570ee9Timo Sirainen ("Error initializing context for the application\n"));
e15b305e90c9834734ccf35ed78f0ad29d570ee9Timo Sirainen for (dinfo = tctx->domains; dinfo; dinfo = get_next_domain(dinfo, true)) {
f87844c400cf9741abad57d9815121d0738a738fTimo Sirainen /* Update list of subdomains for this domain */
e15b305e90c9834734ccf35ed78f0ad29d570ee9Timo Sirainen ("Failed to update subdomains for domain %s.\n", dinfo->name));
b1a2d2042e8c7e99983175eb462b82cc7a8cb70bTimo Sirainen /* Update filters for each domain */
b1a2d2042e8c7e99983175eb462b82cc7a8cb70bTimo Sirainen DEBUG(SSSDBG_CRIT_FAILURE, ("Failed to update filters.\n"));
b1a2d2042e8c7e99983175eb462b82cc7a8cb70bTimo Sirainen ("Could not start the transaction!\n"));
b1a2d2042e8c7e99983175eb462b82cc7a8cb70bTimo Sirainen skipped &= !invalidate_entries(tctx, dinfo, sysdb, TYPE_USER,
b1a2d2042e8c7e99983175eb462b82cc7a8cb70bTimo Sirainen skipped &= !invalidate_entries(tctx, dinfo, sysdb, TYPE_GROUP,
b1a2d2042e8c7e99983175eb462b82cc7a8cb70bTimo Sirainen skipped &= !invalidate_entries(tctx, dinfo, sysdb, TYPE_NETGROUP,
e15b305e90c9834734ccf35ed78f0ad29d570ee9Timo Sirainen skipped &= !invalidate_entries(tctx, dinfo, sysdb, TYPE_SERVICE,
e15b305e90c9834734ccf35ed78f0ad29d570ee9Timo Sirainen skipped &= !invalidate_entries(tctx, dinfo, sysdb, TYPE_AUTOFSMAP,
e15b305e90c9834734ccf35ed78f0ad29d570ee9Timo Sirainen ("Could not commit the transaction!\n"));
adcb46fe2c6d1139dfbd8ab08a8fbe96e53f8fd6Timo Sirainen ("Failed to cancel transaction\n"));
e15b305e90c9834734ccf35ed78f0ad29d570ee9Timo Sirainen if (skipped == true) {
e15b305e90c9834734ccf35ed78f0ad29d570ee9Timo Sirainen ERROR("No cache object matched the specified search\n");
e15b305e90c9834734ccf35ed78f0ad29d570ee9Timo Sirainen DEBUG(SSSDBG_CRIT_FAILURE, ("Failed to clear memory cache.\n"));
9ed77dd00248e88d731ec129116db5dddc0dd3b5Timo Sirainenstatic errno_t update_filter(struct cache_tool_ctx *tctx,
9ed77dd00248e88d731ec129116db5dddc0dd3b5Timo Sirainen /* Nothing to do */
9ed77dd00248e88d731ec129116db5dddc0dd3b5Timo Sirainen DEBUG(SSSDBG_CRIT_FAILURE, ("Out of memory.\n"));
e15b305e90c9834734ccf35ed78f0ad29d570ee9Timo Sirainen ret = sss_parse_name(tmp_ctx, tctx->nctx, name,
e15b305e90c9834734ccf35ed78f0ad29d570ee9Timo Sirainen DEBUG(SSSDBG_CRIT_FAILURE, ("sss_parse_name failed\n"));
df452e9628fe8d3356c42dd644b020ea9733c0c1Timo Sirainen if (!dinfo->case_sensitive && !force_case_sensitivity) {
df452e9628fe8d3356c42dd644b020ea9733c0c1Timo Sirainen use_name = sss_tc_utf8_str_tolower(tmp_ctx, parsed_name);
df452e9628fe8d3356c42dd644b020ea9733c0c1Timo Sirainen DEBUG(SSSDBG_CRIT_FAILURE, ("Out of memory\n"));
9ed77dd00248e88d731ec129116db5dddc0dd3b5Timo Sirainen use_name = sss_get_domain_name(tmp_ctx, use_name, dinfo);
e15b305e90c9834734ccf35ed78f0ad29d570ee9Timo Sirainen if (!strcasecmp(dinfo->name, parsed_domain)) {
e15b305e90c9834734ccf35ed78f0ad29d570ee9Timo Sirainen DEBUG(SSSDBG_CRIT_FAILURE, ("Out of memory\n"));
e15b305e90c9834734ccf35ed78f0ad29d570ee9Timo Sirainen /* We were able to parse the domain from given fqdn, but it
e15b305e90c9834734ccf35ed78f0ad29d570ee9Timo Sirainen * does not match with currently processed domain. */
e15b305e90c9834734ccf35ed78f0ad29d570ee9Timo Sirainen filter = talloc_asprintf(tmp_ctx, fmt, SYSDB_NAME, name);
00bf64c70c231f647c12c2fd49925ef73cb07f07Timo Sirainen DEBUG(SSSDBG_CRIT_FAILURE, ("Out of memory\n"));
530f80fcbfa8be7378ff0d36ec7ecef41f198e2cTimo Sirainen/* This function updates all filters for specified domain using this
530f80fcbfa8be7378ff0d36ec7ecef41f198e2cTimo Sirainen * domains regex to parse string into domain and name (if exists). */
530f80fcbfa8be7378ff0d36ec7ecef41f198e2cTimo Sirainenstatic errno_t update_all_filters(struct cache_tool_ctx *tctx,
530f80fcbfa8be7378ff0d36ec7ecef41f198e2cTimo Sirainen ret = sss_names_init(tctx, tctx->confdb, dinfo->parent->name,
530f80fcbfa8be7378ff0d36ec7ecef41f198e2cTimo Sirainen ret = sss_names_init(tctx, tctx->confdb, dinfo->name, &tctx->nctx);
530f80fcbfa8be7378ff0d36ec7ecef41f198e2cTimo Sirainen DEBUG(SSSDBG_CRIT_FAILURE, ("sss_names_init() failed\n"));
530f80fcbfa8be7378ff0d36ec7ecef41f198e2cTimo Sirainen /* Update user filter */
530f80fcbfa8be7378ff0d36ec7ecef41f198e2cTimo Sirainen ret = update_filter(tctx, dinfo, tctx->user_name,
530f80fcbfa8be7378ff0d36ec7ecef41f198e2cTimo Sirainen /* Update group filter */
530f80fcbfa8be7378ff0d36ec7ecef41f198e2cTimo Sirainen ret = update_filter(tctx, dinfo, tctx->group_name,
530f80fcbfa8be7378ff0d36ec7ecef41f198e2cTimo Sirainen /* Update netgroup filter */
530f80fcbfa8be7378ff0d36ec7ecef41f198e2cTimo Sirainen ret = update_filter(tctx, dinfo, tctx->netgroup_name,
e15b305e90c9834734ccf35ed78f0ad29d570ee9Timo Sirainen tctx->update_netgroup_filter, "(%s=%s)", false,
e15b305e90c9834734ccf35ed78f0ad29d570ee9Timo Sirainen /* Update service filter */
530f80fcbfa8be7378ff0d36ec7ecef41f198e2cTimo Sirainen ret = update_filter(tctx, dinfo, tctx->service_name,
e15b305e90c9834734ccf35ed78f0ad29d570ee9Timo Sirainen tctx->update_service_filter, "(%s=%s)", false,
b1a2d2042e8c7e99983175eb462b82cc7a8cb70bTimo Sirainen /* Update autofs filter */
b1a2d2042e8c7e99983175eb462b82cc7a8cb70bTimo Sirainen ret = update_filter(tctx, dinfo, tctx->autofs_name,
b1a2d2042e8c7e99983175eb462b82cc7a8cb70bTimo Sirainen "(&(objectclass="SYSDB_AUTOFS_MAP_OC")(%s=%s))", true,
e15b305e90c9834734ccf35ed78f0ad29d570ee9Timo Sirainenstatic bool invalidate_entries(TALLOC_CTX *ctx,
e15b305e90c9834734ccf35ed78f0ad29d570ee9Timo Sirainen if (!filter) return false;
e15b305e90c9834734ccf35ed78f0ad29d570ee9Timo Sirainen ret = sysdb_search_netgroups(ctx, sysdb, dinfo,
e15b305e90c9834734ccf35ed78f0ad29d570ee9Timo Sirainen ret = sysdb_search_services(ctx, sysdb, dinfo,
e15b305e90c9834734ccf35ed78f0ad29d570ee9Timo Sirainen DEBUG(SSSDBG_TRACE_FUNC, ("'%s' %s: Not found in domain '%s'\n",
e15b305e90c9834734ccf35ed78f0ad29d570ee9Timo Sirainen ("Searching for %s in domain %s with filter %s failed\n",
e15b305e90c9834734ccf35ed78f0ad29d570ee9Timo Sirainen return false;
adcb46fe2c6d1139dfbd8ab08a8fbe96e53f8fd6Timo Sirainen for (i = 0; i < msg_count; i++) {
adcb46fe2c6d1139dfbd8ab08a8fbe96e53f8fd6Timo Sirainen c_name = ldb_msg_find_attr_as_string(msgs[i], SYSDB_NAME, NULL);
df452e9628fe8d3356c42dd644b020ea9733c0c1Timo Sirainen ("Something bad happened, can't find attribute %s", SYSDB_NAME));
df452e9628fe8d3356c42dd644b020ea9733c0c1Timo Sirainen ERROR("Couldn't invalidate %1$s", type_string);
df452e9628fe8d3356c42dd644b020ea9733c0c1Timo Sirainen ret = invalidate_entry(ctx, sysdb, dinfo, c_name, entry_type);
e15b305e90c9834734ccf35ed78f0ad29d570ee9Timo Sirainen ("Couldn't invalidate %s %s", type_string, c_name));
e15b305e90c9834734ccf35ed78f0ad29d570ee9Timo Sirainen ERROR("Couldn't invalidate %1$s %2$s", type_string, c_name);
return iret;
if (sys_attrs) {
switch (entry_type) {
case TYPE_USER:
case TYPE_GROUP:
case TYPE_NETGROUP:
case TYPE_SERVICE:
case TYPE_AUTOFSMAP:
return EINVAL;
return ret;
char *confdb_path;
int ret;
return ENOMEM;
return ret;
if (domain) {
return ret;
return ret;
return ret;
return EOK;
#ifdef BUILD_AUTOFS
goto fini;
switch (ret) {
goto fini;
} else if (user) {
} else if (group) {
} else if (netgroup) {
} else if (service) {
} else if (map) {
goto fini;
if (domain) {
goto fini;
fini:
return ret;
static errno_t
#ifdef BUILD_AUTOFS
return ENOSYS;