c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny/*
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny SSSD
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny sss_cache
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny Copyright (C) Jan Zeleny <jzeleny@redhat.com> 2011
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny This program is free software; you can redistribute it and/or modify
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny it under the terms of the GNU General Public License as published by
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny the Free Software Foundation; either version 3 of the License, or
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny (at your option) any later version.
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny This program is distributed in the hope that it will be useful,
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny but WITHOUT ANY WARRANTY; without even the implied warranty of
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny GNU General Public License for more details.
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny You should have received a copy of the GNU General Public License
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny along with this program. If not, see <http://www.gnu.org/licenses/>.
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny*/
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny#include <stdio.h>
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny#include <stdlib.h>
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny#include <talloc.h>
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny#include <popt.h>
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny#include <sys/types.h>
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny#include "util/util.h"
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny#include "tools/sss_sync_ops.h"
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny#include "db/sysdb.h"
82b5429d1438392c45e70a0f84dd4d0f5fa1a171Jakub Hrozek#include "db/sysdb_services.h"
82b5429d1438392c45e70a0f84dd4d0f5fa1a171Jakub Hrozek#include "db/sysdb_autofs.h"
3ac7c4fe618ede980a4df8d90341ef1fd0f1f62fWilliam B#include "db/sysdb_ssh.h"
fd3cbf6bfe86a245d7e90d2a355794eb9c70d525Petr Cech#include "db/sysdb_sudo.h"
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny#define INVALIDATE_NONE 0
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny#define INVALIDATE_USERS 1
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny#define INVALIDATE_GROUPS 2
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny#define INVALIDATE_NETGROUPS 4
82b5429d1438392c45e70a0f84dd4d0f5fa1a171Jakub Hrozek#define INVALIDATE_SERVICES 8
82b5429d1438392c45e70a0f84dd4d0f5fa1a171Jakub Hrozek#define INVALIDATE_AUTOFSMAPS 16
3ac7c4fe618ede980a4df8d90341ef1fd0f1f62fWilliam B#define INVALIDATE_SSH_HOSTS 32
fd3cbf6bfe86a245d7e90d2a355794eb9c70d525Petr Cech#define INVALIDATE_SUDO_RULES 64
82b5429d1438392c45e70a0f84dd4d0f5fa1a171Jakub Hrozek
9651a27ec14f3a378e861ca39852480f37f1ef08Michal Zidek#ifdef BUILD_AUTOFS
3ac7c4fe618ede980a4df8d90341ef1fd0f1f62fWilliam B#ifdef BUILD_SSH
9651a27ec14f3a378e861ca39852480f37f1ef08Michal Zidek#define INVALIDATE_EVERYTHING (INVALIDATE_USERS | INVALIDATE_GROUPS | \
9651a27ec14f3a378e861ca39852480f37f1ef08Michal Zidek INVALIDATE_NETGROUPS | INVALIDATE_SERVICES | \
3ac7c4fe618ede980a4df8d90341ef1fd0f1f62fWilliam B INVALIDATE_AUTOFSMAPS | INVALIDATE_SSH_HOSTS )
3ac7c4fe618ede980a4df8d90341ef1fd0f1f62fWilliam B#else /* BUILD_SSH */
9651a27ec14f3a378e861ca39852480f37f1ef08Michal Zidek#define INVALIDATE_EVERYTHING (INVALIDATE_USERS | INVALIDATE_GROUPS | \
3ac7c4fe618ede980a4df8d90341ef1fd0f1f62fWilliam B INVALIDATE_NETGROUPS | INVALIDATE_SERVICES | \
3ac7c4fe618ede980a4df8d90341ef1fd0f1f62fWilliam B INVALIDATE_AUTOFSMAPS )
3ac7c4fe618ede980a4df8d90341ef1fd0f1f62fWilliam B#endif /* BUILD_SSH */
3ac7c4fe618ede980a4df8d90341ef1fd0f1f62fWilliam B#else /* BUILD_AUTOFS */
3ac7c4fe618ede980a4df8d90341ef1fd0f1f62fWilliam B#ifdef BUILD_SSH
3ac7c4fe618ede980a4df8d90341ef1fd0f1f62fWilliam B#define INVALIDATE_EVERYTHING (INVALIDATE_USERS | INVALIDATE_GROUPS | \
3ac7c4fe618ede980a4df8d90341ef1fd0f1f62fWilliam B INVALIDATE_NETGROUPS | INVALIDATE_SERVICES | \
3ac7c4fe618ede980a4df8d90341ef1fd0f1f62fWilliam B INVALIDATE_SSH_HOSTS )
3ac7c4fe618ede980a4df8d90341ef1fd0f1f62fWilliam B#else /* BUILD_SSH */
3ac7c4fe618ede980a4df8d90341ef1fd0f1f62fWilliam B#define INVALIDATE_EVERYTHING (INVALIDATE_USERS | INVALIDATE_GROUPS | \
3ac7c4fe618ede980a4df8d90341ef1fd0f1f62fWilliam B INVALIDATE_NETGROUPS | INVALIDATE_SERVICES )
3ac7c4fe618ede980a4df8d90341ef1fd0f1f62fWilliam B#endif /* BUILD_SSH */
3ac7c4fe618ede980a4df8d90341ef1fd0f1f62fWilliam B#endif /* BUILD_AUTOFS */
9651a27ec14f3a378e861ca39852480f37f1ef08Michal Zidek
82b5429d1438392c45e70a0f84dd4d0f5fa1a171Jakub Hrozekenum sss_cache_entry {
82b5429d1438392c45e70a0f84dd4d0f5fa1a171Jakub Hrozek TYPE_USER=0,
82b5429d1438392c45e70a0f84dd4d0f5fa1a171Jakub Hrozek TYPE_GROUP,
82b5429d1438392c45e70a0f84dd4d0f5fa1a171Jakub Hrozek TYPE_NETGROUP,
82b5429d1438392c45e70a0f84dd4d0f5fa1a171Jakub Hrozek TYPE_SERVICE,
3ac7c4fe618ede980a4df8d90341ef1fd0f1f62fWilliam B TYPE_AUTOFSMAP,
fd3cbf6bfe86a245d7e90d2a355794eb9c70d525Petr Cech TYPE_SSH_HOST,
fd3cbf6bfe86a245d7e90d2a355794eb9c70d525Petr Cech TYPE_SUDO_RULE
82b5429d1438392c45e70a0f84dd4d0f5fa1a171Jakub Hrozek};
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny
78c4b29420855b9f5384cd5e052fc9369c57d899Lukas Slebodnikstatic errno_t search_autofsmaps(TALLOC_CTX *mem_ctx,
770896b194b7b66b09c2a30545b4d091fd86b1f4Simo Sorce struct sss_domain_info *domain,
82b5429d1438392c45e70a0f84dd4d0f5fa1a171Jakub Hrozek const char *sub_filter, const char **attrs,
82b5429d1438392c45e70a0f84dd4d0f5fa1a171Jakub Hrozek size_t *msgs_count, struct ldb_message ***msgs);
82b5429d1438392c45e70a0f84dd4d0f5fa1a171Jakub Hrozek
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cechstruct input_values {
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech char *domain;
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech char *group;
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech char *map;
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech char *netgroup;
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech char *service;
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech char *ssh_host;
fd3cbf6bfe86a245d7e90d2a355794eb9c70d525Petr Cech char *sudo_rule;
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech char *user;
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech};
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zelenystruct cache_tool_ctx {
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny struct confdb_ctx *confdb;
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny struct sss_domain_info *domains;
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny char *user_filter;
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny char *group_filter;
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny char *netgroup_filter;
82b5429d1438392c45e70a0f84dd4d0f5fa1a171Jakub Hrozek char *service_filter;
82b5429d1438392c45e70a0f84dd4d0f5fa1a171Jakub Hrozek char *autofs_filter;
3ac7c4fe618ede980a4df8d90341ef1fd0f1f62fWilliam B char *ssh_host_filter;
fd3cbf6bfe86a245d7e90d2a355794eb9c70d525Petr Cech char *sudo_rule_filter;
da0b829a2002987339aadaa01b85adbb5ddba20dJakub Hrozek
da0b829a2002987339aadaa01b85adbb5ddba20dJakub Hrozek char *user_name;
da0b829a2002987339aadaa01b85adbb5ddba20dJakub Hrozek char *group_name;
da0b829a2002987339aadaa01b85adbb5ddba20dJakub Hrozek char *netgroup_name;
da0b829a2002987339aadaa01b85adbb5ddba20dJakub Hrozek char *service_name;
da0b829a2002987339aadaa01b85adbb5ddba20dJakub Hrozek char *autofs_name;
3ac7c4fe618ede980a4df8d90341ef1fd0f1f62fWilliam B char *ssh_host_name;
fd3cbf6bfe86a245d7e90d2a355794eb9c70d525Petr Cech char *sudo_rule_name;
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek bool update_user_filter;
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek bool update_group_filter;
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek bool update_netgroup_filter;
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek bool update_service_filter;
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek bool update_autofs_filter;
3ac7c4fe618ede980a4df8d90341ef1fd0f1f62fWilliam B bool update_ssh_host_filter;
fd3cbf6bfe86a245d7e90d2a355794eb9c70d525Petr Cech bool update_sudo_rule_filter;
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny};
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cechstatic void free_input_values(struct input_values *values);
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cechstatic bool is_filter_valid(struct cache_tool_ctx *ctx,
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech struct input_values *values, int idb);
643b48013c1f556530eb2a89a8baf4aa40357278Jakub Hrozekstatic errno_t init_domains(struct cache_tool_ctx *ctx,
643b48013c1f556530eb2a89a8baf4aa40357278Jakub Hrozek const char *domain);
643b48013c1f556530eb2a89a8baf4aa40357278Jakub Hrozekstatic errno_t init_context(int argc, const char *argv[],
643b48013c1f556530eb2a89a8baf4aa40357278Jakub Hrozek struct cache_tool_ctx **tctx);
e2640b7a0ccfe2b00311d20ae18006ccc82a834cLukas Slebodnikstatic errno_t invalidate_entry(TALLOC_CTX *ctx,
3f94d6718d44185137e13b6d326dfd63e8dc61c6Simo Sorce struct sss_domain_info *domain,
3f94d6718d44185137e13b6d326dfd63e8dc61c6Simo Sorce const char *name, int entry_type);
1e6f2180724de4722a5218826c9401181168d9d4Simo Sorcestatic bool invalidate_entries(TALLOC_CTX *ctx,
1e6f2180724de4722a5218826c9401181168d9d4Simo Sorce struct sss_domain_info *dinfo,
480195bd70467bf05e2fd92cf25cec822a670cedSimo Sorce enum sss_cache_entry entry_type,
480195bd70467bf05e2fd92cf25cec822a670cedSimo Sorce const char *filter, const char *name);
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidekstatic errno_t update_all_filters(struct cache_tool_ctx *tctx,
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek struct sss_domain_info *dinfo);
57a924e71230ea360b19a88e0d5818cf01017161Petr Čechstatic int sysdb_invalidate_user_cache_entry(struct sss_domain_info *domain,
57a924e71230ea360b19a88e0d5818cf01017161Petr Čech const char *name);
57a924e71230ea360b19a88e0d5818cf01017161Petr Čechstatic int sysdb_invalidate_group_cache_entry(struct sss_domain_info *domain,
57a924e71230ea360b19a88e0d5818cf01017161Petr Čech const char *name);
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zelenyint main(int argc, const char *argv[])
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny{
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny errno_t ret;
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny struct cache_tool_ctx *tctx = NULL;
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny struct sysdb_ctx *sysdb;
69f6f2ed116d1c987851bfcc410cf2bdd1b0cc97Michal Zidek bool skipped = true;
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek struct sss_domain_info *dinfo;
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny ret = init_context(argc, argv, &tctx);
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny if (ret != EOK) {
da0b829a2002987339aadaa01b85adbb5ddba20dJakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Error initializing context for the application\n");
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny goto done;
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny }
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny
877b92e80bde510d5cd9f03dbf01e2bcf73ab072Michal Židek for (dinfo = tctx->domains; dinfo;
877b92e80bde510d5cd9f03dbf01e2bcf73ab072Michal Židek dinfo = get_next_domain(dinfo, SSS_GND_DESCEND)) {
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek if (!IS_SUBDOMAIN(dinfo)) {
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek /* Update list of subdomains for this domain */
a63d74f65db2db7389cd373cb37adcdaaa2d56eaMichal Židek ret = sysdb_update_subdomains(dinfo, tctx->confdb);
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek if (ret != EOK) {
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek DEBUG(SSSDBG_MINOR_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Failed to update subdomains for domain %s.\n", dinfo->name);
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek }
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek }
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek sysdb = dinfo->sysdb;
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek /* Update filters for each domain */
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek ret = update_all_filters(tctx, dinfo);
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to update filters.\n");
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek goto done;
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek }
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny ret = sysdb_transaction_start(sysdb);
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny if (ret != EOK) {
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek DEBUG(SSSDBG_CRIT_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Could not start the transaction!\n");
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny goto done;
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny }
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny
78c4b29420855b9f5384cd5e052fc9369c57d899Lukas Slebodnik skipped &= !invalidate_entries(tctx, dinfo, TYPE_USER,
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek tctx->user_filter,
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek tctx->user_name);
78c4b29420855b9f5384cd5e052fc9369c57d899Lukas Slebodnik skipped &= !invalidate_entries(tctx, dinfo, TYPE_GROUP,
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek tctx->group_filter,
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek tctx->group_name);
78c4b29420855b9f5384cd5e052fc9369c57d899Lukas Slebodnik skipped &= !invalidate_entries(tctx, dinfo, TYPE_NETGROUP,
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek tctx->netgroup_filter,
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek tctx->netgroup_name);
78c4b29420855b9f5384cd5e052fc9369c57d899Lukas Slebodnik skipped &= !invalidate_entries(tctx, dinfo, TYPE_SERVICE,
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek tctx->service_filter,
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek tctx->service_name);
78c4b29420855b9f5384cd5e052fc9369c57d899Lukas Slebodnik skipped &= !invalidate_entries(tctx, dinfo, TYPE_AUTOFSMAP,
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek tctx->autofs_filter,
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek tctx->autofs_name);
3ac7c4fe618ede980a4df8d90341ef1fd0f1f62fWilliam B skipped &= !invalidate_entries(tctx, dinfo, TYPE_SSH_HOST,
3ac7c4fe618ede980a4df8d90341ef1fd0f1f62fWilliam B tctx->ssh_host_filter,
3ac7c4fe618ede980a4df8d90341ef1fd0f1f62fWilliam B tctx->ssh_host_name);
fd3cbf6bfe86a245d7e90d2a355794eb9c70d525Petr Cech skipped &= !invalidate_entries(tctx, dinfo, TYPE_SUDO_RULE,
fd3cbf6bfe86a245d7e90d2a355794eb9c70d525Petr Cech tctx->sudo_rule_filter,
fd3cbf6bfe86a245d7e90d2a355794eb9c70d525Petr Cech tctx->sudo_rule_name);
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny ret = sysdb_transaction_commit(sysdb);
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny if (ret != EOK) {
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek DEBUG(SSSDBG_CRIT_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Could not commit the transaction!\n");
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek ret = sysdb_transaction_cancel(sysdb);
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek if (ret != EOK) {
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek DEBUG(SSSDBG_CRIT_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Failed to cancel transaction\n");
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek }
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny }
69f6f2ed116d1c987851bfcc410cf2bdd1b0cc97Michal Zidek }
da0b829a2002987339aadaa01b85adbb5ddba20dJakub Hrozek
69f6f2ed116d1c987851bfcc410cf2bdd1b0cc97Michal Zidek if (skipped == true) {
69f6f2ed116d1c987851bfcc410cf2bdd1b0cc97Michal Zidek ERROR("No cache object matched the specified search\n");
69f6f2ed116d1c987851bfcc410cf2bdd1b0cc97Michal Zidek ret = ENOENT;
69f6f2ed116d1c987851bfcc410cf2bdd1b0cc97Michal Zidek goto done;
69f6f2ed116d1c987851bfcc410cf2bdd1b0cc97Michal Zidek } else {
a290ace39af184d878568e17588b6b2210aea63fMichal Zidek ret = sss_memcache_clear_all();
33cbb789ff71be5dccbb4a0acd68814b0d53da34Michal Zidek if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to clear memory cache.\n");
da0b829a2002987339aadaa01b85adbb5ddba20dJakub Hrozek goto done;
69f6f2ed116d1c987851bfcc410cf2bdd1b0cc97Michal Zidek }
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny }
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny
a290ace39af184d878568e17588b6b2210aea63fMichal Zidek ret = EOK;
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zelenydone:
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny if (tctx) talloc_free(tctx);
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny return ret;
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny}
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cechstatic void free_input_values(struct input_values *values)
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech{
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech free(values->domain);
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech free(values->group);
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech free(values->map);
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech free(values->netgroup);
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech free(values->service);
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech free(values->ssh_host);
fd3cbf6bfe86a245d7e90d2a355794eb9c70d525Petr Cech free(values->sudo_rule);
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech free(values->user);
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech}
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidekstatic errno_t update_filter(struct cache_tool_ctx *tctx,
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek struct sss_domain_info *dinfo,
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek char *name, bool update, const char *fmt,
281748ae307a1842d55712335acbe54821793de5Jakub Hrozek enum sss_cache_entry entry_type,
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek bool force_case_sensitivity,
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek char **_filter)
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek{
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek errno_t ret;
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek char *parsed_domain = NULL;
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek char *parsed_name = NULL;
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek TALLOC_CTX *tmp_ctx = NULL;
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek char *use_name = NULL;
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek char *filter;
c246e2315cb8df1e347bec3b728f91b0c1264f93Sumit Bose char *sanitized;
c246e2315cb8df1e347bec3b728f91b0c1264f93Sumit Bose char *lc_sanitized;
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek if (!name || !update) {
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek /* Nothing to do */
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek return EOK;
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek }
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek tmp_ctx = talloc_new(NULL);
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek if (tmp_ctx == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Out of memory.\n");
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek return ENOMEM;
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek }
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek
d2791a492d8f0a9df73fc7a683b3f712abf80f3fSumit Bose ret = sss_parse_name(tmp_ctx, dinfo->names, name,
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek &parsed_domain, &parsed_name);
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "sss_parse_name failed\n");
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek goto done;
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek }
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek
c246e2315cb8df1e347bec3b728f91b0c1264f93Sumit Bose if (parsed_domain != NULL && strcasecmp(dinfo->name, parsed_domain) != 0) {
c246e2315cb8df1e347bec3b728f91b0c1264f93Sumit Bose /* We were able to parse the domain from given fqdn, but it
c246e2315cb8df1e347bec3b728f91b0c1264f93Sumit Bose * does not match with currently processed domain. */
c246e2315cb8df1e347bec3b728f91b0c1264f93Sumit Bose filter = NULL;
c246e2315cb8df1e347bec3b728f91b0c1264f93Sumit Bose ret = EOK;
c246e2315cb8df1e347bec3b728f91b0c1264f93Sumit Bose goto done;
c246e2315cb8df1e347bec3b728f91b0c1264f93Sumit Bose }
c246e2315cb8df1e347bec3b728f91b0c1264f93Sumit Bose
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek if (!dinfo->case_sensitive && !force_case_sensitivity) {
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek use_name = sss_tc_utf8_str_tolower(tmp_ctx, parsed_name);
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek if (!use_name) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Out of memory\n");
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek ret = ENOMEM;
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek goto done;
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek }
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek } else {
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek use_name = parsed_name;
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek }
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek
281748ae307a1842d55712335acbe54821793de5Jakub Hrozek switch (entry_type) {
281748ae307a1842d55712335acbe54821793de5Jakub Hrozek case TYPE_USER:
281748ae307a1842d55712335acbe54821793de5Jakub Hrozek case TYPE_GROUP:
281748ae307a1842d55712335acbe54821793de5Jakub Hrozek use_name = sss_create_internal_fqname(tmp_ctx, use_name, dinfo->name);
281748ae307a1842d55712335acbe54821793de5Jakub Hrozek default:
281748ae307a1842d55712335acbe54821793de5Jakub Hrozek break;
281748ae307a1842d55712335acbe54821793de5Jakub Hrozek }
281748ae307a1842d55712335acbe54821793de5Jakub Hrozek if (!use_name) {
281748ae307a1842d55712335acbe54821793de5Jakub Hrozek ret = ENOMEM;
281748ae307a1842d55712335acbe54821793de5Jakub Hrozek goto done;
c246e2315cb8df1e347bec3b728f91b0c1264f93Sumit Bose }
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek
c246e2315cb8df1e347bec3b728f91b0c1264f93Sumit Bose ret = sss_filter_sanitize_for_dom(tmp_ctx, use_name, dinfo,
c246e2315cb8df1e347bec3b728f91b0c1264f93Sumit Bose &sanitized, &lc_sanitized);
c246e2315cb8df1e347bec3b728f91b0c1264f93Sumit Bose if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to sanitize the given name.\n");
c246e2315cb8df1e347bec3b728f91b0c1264f93Sumit Bose goto done;
c246e2315cb8df1e347bec3b728f91b0c1264f93Sumit Bose }
c246e2315cb8df1e347bec3b728f91b0c1264f93Sumit Bose
c246e2315cb8df1e347bec3b728f91b0c1264f93Sumit Bose if (fmt) {
c246e2315cb8df1e347bec3b728f91b0c1264f93Sumit Bose if (!dinfo->case_sensitive && !force_case_sensitivity) {
c246e2315cb8df1e347bec3b728f91b0c1264f93Sumit Bose filter = talloc_asprintf(tmp_ctx, "(|(%s=%s)(%s=%s))",
c246e2315cb8df1e347bec3b728f91b0c1264f93Sumit Bose SYSDB_NAME_ALIAS, lc_sanitized,
c246e2315cb8df1e347bec3b728f91b0c1264f93Sumit Bose SYSDB_NAME_ALIAS, sanitized);
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek } else {
c246e2315cb8df1e347bec3b728f91b0c1264f93Sumit Bose filter = talloc_asprintf(tmp_ctx, fmt, SYSDB_NAME, sanitized);
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek }
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek } else {
c246e2315cb8df1e347bec3b728f91b0c1264f93Sumit Bose filter = talloc_strdup(tmp_ctx, sanitized);
c246e2315cb8df1e347bec3b728f91b0c1264f93Sumit Bose }
c246e2315cb8df1e347bec3b728f91b0c1264f93Sumit Bose if (filter == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Out of memory\n");
c246e2315cb8df1e347bec3b728f91b0c1264f93Sumit Bose ret = ENOMEM;
c246e2315cb8df1e347bec3b728f91b0c1264f93Sumit Bose goto done;
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek }
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek ret = EOK;
c246e2315cb8df1e347bec3b728f91b0c1264f93Sumit Bose
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidekdone:
c246e2315cb8df1e347bec3b728f91b0c1264f93Sumit Bose if (ret == EOK) {
c246e2315cb8df1e347bec3b728f91b0c1264f93Sumit Bose talloc_free(*_filter);
c246e2315cb8df1e347bec3b728f91b0c1264f93Sumit Bose *_filter = talloc_steal(tctx, filter);
c246e2315cb8df1e347bec3b728f91b0c1264f93Sumit Bose }
c246e2315cb8df1e347bec3b728f91b0c1264f93Sumit Bose
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek talloc_free(tmp_ctx);
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek return ret;
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek}
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek/* This function updates all filters for specified domain using this
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek * domains regex to parse string into domain and name (if exists). */
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidekstatic errno_t update_all_filters(struct cache_tool_ctx *tctx,
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek struct sss_domain_info *dinfo)
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek{
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek errno_t ret;
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek /* Update user filter */
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek ret = update_filter(tctx, dinfo, tctx->user_name,
281748ae307a1842d55712335acbe54821793de5Jakub Hrozek tctx->update_user_filter, "(%s=%s)",
281748ae307a1842d55712335acbe54821793de5Jakub Hrozek TYPE_USER, false,
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek &tctx->user_filter);
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek if (ret != EOK) {
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek return ret;
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek }
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek /* Update group filter */
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek ret = update_filter(tctx, dinfo, tctx->group_name,
281748ae307a1842d55712335acbe54821793de5Jakub Hrozek tctx->update_group_filter, "(%s=%s)",
281748ae307a1842d55712335acbe54821793de5Jakub Hrozek TYPE_GROUP, false,
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek &tctx->group_filter);
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek if (ret != EOK) {
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek return ret;
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek }
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek /* Update netgroup filter */
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek ret = update_filter(tctx, dinfo, tctx->netgroup_name,
281748ae307a1842d55712335acbe54821793de5Jakub Hrozek tctx->update_netgroup_filter, "(%s=%s)",
281748ae307a1842d55712335acbe54821793de5Jakub Hrozek TYPE_NETGROUP, false,
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek &tctx->netgroup_filter);
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek if (ret != EOK) {
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek return ret;
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek }
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek /* Update service filter */
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek ret = update_filter(tctx, dinfo, tctx->service_name,
281748ae307a1842d55712335acbe54821793de5Jakub Hrozek tctx->update_service_filter, "(%s=%s)",
281748ae307a1842d55712335acbe54821793de5Jakub Hrozek TYPE_SERVICE, false,
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek &tctx->service_filter);
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek if (ret != EOK) {
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek return ret;
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek }
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek /* Update autofs filter */
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek ret = update_filter(tctx, dinfo, tctx->autofs_name,
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek tctx->update_autofs_filter,
281748ae307a1842d55712335acbe54821793de5Jakub Hrozek "(&(objectclass="SYSDB_AUTOFS_MAP_OC")(%s=%s))",
281748ae307a1842d55712335acbe54821793de5Jakub Hrozek TYPE_AUTOFSMAP, true,
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek &tctx->autofs_filter);
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek if (ret != EOK) {
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek return ret;
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek }
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek
3ac7c4fe618ede980a4df8d90341ef1fd0f1f62fWilliam B /* Update ssh host filter */
3ac7c4fe618ede980a4df8d90341ef1fd0f1f62fWilliam B ret = update_filter(tctx, dinfo, tctx->ssh_host_name,
281748ae307a1842d55712335acbe54821793de5Jakub Hrozek tctx->update_ssh_host_filter, "(%s=%s)",
281748ae307a1842d55712335acbe54821793de5Jakub Hrozek TYPE_SSH_HOST, false,
3ac7c4fe618ede980a4df8d90341ef1fd0f1f62fWilliam B &tctx->ssh_host_filter);
3ac7c4fe618ede980a4df8d90341ef1fd0f1f62fWilliam B if (ret != EOK) {
3ac7c4fe618ede980a4df8d90341ef1fd0f1f62fWilliam B return ret;
3ac7c4fe618ede980a4df8d90341ef1fd0f1f62fWilliam B }
3ac7c4fe618ede980a4df8d90341ef1fd0f1f62fWilliam B
fd3cbf6bfe86a245d7e90d2a355794eb9c70d525Petr Cech /* Update sudo rule filter */
fd3cbf6bfe86a245d7e90d2a355794eb9c70d525Petr Cech ret = update_filter(tctx, dinfo, tctx->sudo_rule_name,
26c722d568b0061e0f1edb8d07093bf051d76083Jakub Hrozek tctx->update_sudo_rule_filter,
26c722d568b0061e0f1edb8d07093bf051d76083Jakub Hrozek "(%s=%s)", TYPE_SUDO_RULE, false,
fd3cbf6bfe86a245d7e90d2a355794eb9c70d525Petr Cech &tctx->sudo_rule_filter);
fd3cbf6bfe86a245d7e90d2a355794eb9c70d525Petr Cech if (ret != EOK) {
fd3cbf6bfe86a245d7e90d2a355794eb9c70d525Petr Cech return ret;
fd3cbf6bfe86a245d7e90d2a355794eb9c70d525Petr Cech }
fd3cbf6bfe86a245d7e90d2a355794eb9c70d525Petr Cech
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek return EOK;
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek}
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek
1e6f2180724de4722a5218826c9401181168d9d4Simo Sorcestatic bool invalidate_entries(TALLOC_CTX *ctx,
1e6f2180724de4722a5218826c9401181168d9d4Simo Sorce struct sss_domain_info *dinfo,
480195bd70467bf05e2fd92cf25cec822a670cedSimo Sorce enum sss_cache_entry entry_type,
480195bd70467bf05e2fd92cf25cec822a670cedSimo Sorce const char *filter, const char *name)
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny{
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny const char *attrs[] = {SYSDB_NAME, NULL};
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny size_t msg_count;
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny struct ldb_message **msgs;
480195bd70467bf05e2fd92cf25cec822a670cedSimo Sorce const char *type_string = "unknown";
480195bd70467bf05e2fd92cf25cec822a670cedSimo Sorce errno_t ret = EINVAL;
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny int i;
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny const char *c_name;
da0b829a2002987339aadaa01b85adbb5ddba20dJakub Hrozek bool iret;
da0b829a2002987339aadaa01b85adbb5ddba20dJakub Hrozek
da0b829a2002987339aadaa01b85adbb5ddba20dJakub Hrozek if (!filter) return false;
2eaf2045b5b55cdaff6ae5704225cf9a75b16950Simo Sorce switch (entry_type) {
2eaf2045b5b55cdaff6ae5704225cf9a75b16950Simo Sorce case TYPE_USER:
2eaf2045b5b55cdaff6ae5704225cf9a75b16950Simo Sorce type_string = "user";
d115f40c7a3999e3cbe705a2ff9cf0fd493f80fbMichal Zidek ret = sysdb_search_users(ctx, dinfo,
044868b388b4e47499f12a9105310b247bbe1ce2Simo Sorce filter, attrs, &msg_count, &msgs);
2eaf2045b5b55cdaff6ae5704225cf9a75b16950Simo Sorce break;
2eaf2045b5b55cdaff6ae5704225cf9a75b16950Simo Sorce case TYPE_GROUP:
2eaf2045b5b55cdaff6ae5704225cf9a75b16950Simo Sorce type_string = "group";
d115f40c7a3999e3cbe705a2ff9cf0fd493f80fbMichal Zidek ret = sysdb_search_groups(ctx, dinfo,
2b7ee2a760e7fcc70f4970a3bbee6fbf8f2ccb9dSimo Sorce filter, attrs, &msg_count, &msgs);
2eaf2045b5b55cdaff6ae5704225cf9a75b16950Simo Sorce break;
2eaf2045b5b55cdaff6ae5704225cf9a75b16950Simo Sorce case TYPE_NETGROUP:
2eaf2045b5b55cdaff6ae5704225cf9a75b16950Simo Sorce type_string = "netgroup";
d115f40c7a3999e3cbe705a2ff9cf0fd493f80fbMichal Zidek ret = sysdb_search_netgroups(ctx, dinfo,
84c986f9bb2767d8930b6f5d92d34b09b8fabe60Simo Sorce filter, attrs, &msg_count, &msgs);
2eaf2045b5b55cdaff6ae5704225cf9a75b16950Simo Sorce break;
2eaf2045b5b55cdaff6ae5704225cf9a75b16950Simo Sorce case TYPE_SERVICE:
2eaf2045b5b55cdaff6ae5704225cf9a75b16950Simo Sorce type_string = "service";
4fcc50e133f90cd4c5931a3ac48c84cb628b16fcMichal Zidek ret = sysdb_search_services(ctx, dinfo,
681742138b2afbbefa7f14de937beb438409208eSimo Sorce filter, attrs, &msg_count, &msgs);
2eaf2045b5b55cdaff6ae5704225cf9a75b16950Simo Sorce break;
2eaf2045b5b55cdaff6ae5704225cf9a75b16950Simo Sorce case TYPE_AUTOFSMAP:
2eaf2045b5b55cdaff6ae5704225cf9a75b16950Simo Sorce type_string = "autofs map";
78c4b29420855b9f5384cd5e052fc9369c57d899Lukas Slebodnik ret = search_autofsmaps(ctx, dinfo, filter, attrs, &msg_count, &msgs);
2eaf2045b5b55cdaff6ae5704225cf9a75b16950Simo Sorce break;
3ac7c4fe618ede980a4df8d90341ef1fd0f1f62fWilliam B case TYPE_SSH_HOST:
3ac7c4fe618ede980a4df8d90341ef1fd0f1f62fWilliam B type_string = "ssh_host";
3ac7c4fe618ede980a4df8d90341ef1fd0f1f62fWilliam B#ifdef BUILD_SSH
3ac7c4fe618ede980a4df8d90341ef1fd0f1f62fWilliam B ret = sysdb_search_ssh_hosts(ctx, dinfo,
3ac7c4fe618ede980a4df8d90341ef1fd0f1f62fWilliam B filter, attrs, &msg_count, &msgs);
3ac7c4fe618ede980a4df8d90341ef1fd0f1f62fWilliam B#else /* BUILD_SSH */
3ac7c4fe618ede980a4df8d90341ef1fd0f1f62fWilliam B ret = ENOSYS;
3ac7c4fe618ede980a4df8d90341ef1fd0f1f62fWilliam B#endif /* BUILD_SSH */
3ac7c4fe618ede980a4df8d90341ef1fd0f1f62fWilliam B break;
fd3cbf6bfe86a245d7e90d2a355794eb9c70d525Petr Cech case TYPE_SUDO_RULE:
fd3cbf6bfe86a245d7e90d2a355794eb9c70d525Petr Cech type_string = "sudo_rule";
fd3cbf6bfe86a245d7e90d2a355794eb9c70d525Petr Cech#ifdef BUILD_SUDO
fd3cbf6bfe86a245d7e90d2a355794eb9c70d525Petr Cech ret = sysdb_search_sudo_rules(ctx, dinfo,
fd3cbf6bfe86a245d7e90d2a355794eb9c70d525Petr Cech filter, attrs, &msg_count, &msgs);
fd3cbf6bfe86a245d7e90d2a355794eb9c70d525Petr Cech#else /* BUILD_SUDO */
fd3cbf6bfe86a245d7e90d2a355794eb9c70d525Petr Cech ret = ENOSYS;
fd3cbf6bfe86a245d7e90d2a355794eb9c70d525Petr Cech#endif /* BUILD_SUDO */
fd3cbf6bfe86a245d7e90d2a355794eb9c70d525Petr Cech break;
2eaf2045b5b55cdaff6ae5704225cf9a75b16950Simo Sorce }
2eaf2045b5b55cdaff6ae5704225cf9a75b16950Simo Sorce
da0b829a2002987339aadaa01b85adbb5ddba20dJakub Hrozek if (ret != EOK) {
eeee8d4e089830d337f217ec4921421ab448a8ecMichal Zidek if (ret == ENOENT) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "'%s' %s: Not found in domain '%s'\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov type_string, name ? name : "", dinfo->name);
da0b829a2002987339aadaa01b85adbb5ddba20dJakub Hrozek } else {
eeee8d4e089830d337f217ec4921421ab448a8ecMichal Zidek DEBUG(SSSDBG_CRIT_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Searching for %s in domain %s with filter %s failed\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov type_string, dinfo->name, filter);
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny }
da0b829a2002987339aadaa01b85adbb5ddba20dJakub Hrozek return false;
da0b829a2002987339aadaa01b85adbb5ddba20dJakub Hrozek }
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny
da0b829a2002987339aadaa01b85adbb5ddba20dJakub Hrozek iret = true;
da0b829a2002987339aadaa01b85adbb5ddba20dJakub Hrozek for (i = 0; i < msg_count; i++) {
da0b829a2002987339aadaa01b85adbb5ddba20dJakub Hrozek c_name = ldb_msg_find_attr_as_string(msgs[i], SYSDB_NAME, NULL);
da0b829a2002987339aadaa01b85adbb5ddba20dJakub Hrozek if (c_name == NULL) {
da0b829a2002987339aadaa01b85adbb5ddba20dJakub Hrozek DEBUG(SSSDBG_MINOR_FAILURE,
b07a3b729892d2bc2ffa73d93de95e19003cc6c8Pavel Reichl "Something bad happened, can't find attribute %s\n",
b07a3b729892d2bc2ffa73d93de95e19003cc6c8Pavel Reichl SYSDB_NAME);
b07a3b729892d2bc2ffa73d93de95e19003cc6c8Pavel Reichl ERROR("Couldn't invalidate %1$s\n", type_string);
da0b829a2002987339aadaa01b85adbb5ddba20dJakub Hrozek iret = false;
da0b829a2002987339aadaa01b85adbb5ddba20dJakub Hrozek } else {
e2640b7a0ccfe2b00311d20ae18006ccc82a834cLukas Slebodnik ret = invalidate_entry(ctx, dinfo, c_name, entry_type);
da0b829a2002987339aadaa01b85adbb5ddba20dJakub Hrozek if (ret != EOK) {
da0b829a2002987339aadaa01b85adbb5ddba20dJakub Hrozek DEBUG(SSSDBG_MINOR_FAILURE,
b07a3b729892d2bc2ffa73d93de95e19003cc6c8Pavel Reichl "Couldn't invalidate %s %s\n", type_string, c_name);
b07a3b729892d2bc2ffa73d93de95e19003cc6c8Pavel Reichl ERROR("Couldn't invalidate %1$s %2$s\n", type_string, c_name);
da0b829a2002987339aadaa01b85adbb5ddba20dJakub Hrozek iret = false;
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny }
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny }
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny }
da0b829a2002987339aadaa01b85adbb5ddba20dJakub Hrozek talloc_zfree(msgs);
da0b829a2002987339aadaa01b85adbb5ddba20dJakub Hrozek return iret;
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny}
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny
e2640b7a0ccfe2b00311d20ae18006ccc82a834cLukas Slebodnikstatic errno_t invalidate_entry(TALLOC_CTX *ctx,
3f94d6718d44185137e13b6d326dfd63e8dc61c6Simo Sorce struct sss_domain_info *domain,
3f94d6718d44185137e13b6d326dfd63e8dc61c6Simo Sorce const char *name, int entry_type)
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny{
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny struct sysdb_attrs *sys_attrs = NULL;
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny errno_t ret;
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny sys_attrs = sysdb_new_attrs(ctx);
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny if (sys_attrs) {
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny ret = sysdb_attrs_add_time_t(sys_attrs,
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny SYSDB_CACHE_EXPIRE, 1);
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny if (ret == EOK) {
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny switch (entry_type) {
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny case TYPE_USER:
30ee051025753b63ceb19d3b83c44019a19554a1Jakub Hrozek /* For users, we also need to reset the initgroups
30ee051025753b63ceb19d3b83c44019a19554a1Jakub Hrozek * cache expiry */
30ee051025753b63ceb19d3b83c44019a19554a1Jakub Hrozek ret = sysdb_attrs_add_time_t(sys_attrs,
30ee051025753b63ceb19d3b83c44019a19554a1Jakub Hrozek SYSDB_INITGR_EXPIRE, 1);
30ee051025753b63ceb19d3b83c44019a19554a1Jakub Hrozek if (ret != EOK) return ret;
30ee051025753b63ceb19d3b83c44019a19554a1Jakub Hrozek
4c08db0fb0dda3d27b1184248ca5c800d7ce23f0Michal Zidek ret = sysdb_set_user_attr(domain, name, sys_attrs,
e79d23932ef9d52cf4eb32ddec2d0a9b3af9a9ebJan Zeleny SYSDB_MOD_REP);
57a924e71230ea360b19a88e0d5818cf01017161Petr Čech if (ret != EOK) break;
57a924e71230ea360b19a88e0d5818cf01017161Petr Čech
57a924e71230ea360b19a88e0d5818cf01017161Petr Čech /* WARNING: Direct writing to persistent cache!! */
57a924e71230ea360b19a88e0d5818cf01017161Petr Čech ret = sysdb_invalidate_user_cache_entry(domain, name);
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny break;
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny case TYPE_GROUP:
4c08db0fb0dda3d27b1184248ca5c800d7ce23f0Michal Zidek ret = sysdb_set_group_attr(domain, name, sys_attrs,
e79d23932ef9d52cf4eb32ddec2d0a9b3af9a9ebJan Zeleny SYSDB_MOD_REP);
57a924e71230ea360b19a88e0d5818cf01017161Petr Čech if (ret != EOK) break;
57a924e71230ea360b19a88e0d5818cf01017161Petr Čech
57a924e71230ea360b19a88e0d5818cf01017161Petr Čech /* WARNING: Direct writing to persistent cache!! */
57a924e71230ea360b19a88e0d5818cf01017161Petr Čech ret = sysdb_invalidate_group_cache_entry(domain, name);
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny break;
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny case TYPE_NETGROUP:
d115f40c7a3999e3cbe705a2ff9cf0fd493f80fbMichal Zidek ret = sysdb_set_netgroup_attr(domain, name, sys_attrs,
d115f40c7a3999e3cbe705a2ff9cf0fd493f80fbMichal Zidek SYSDB_MOD_REP);
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny break;
82b5429d1438392c45e70a0f84dd4d0f5fa1a171Jakub Hrozek case TYPE_SERVICE:
4fcc50e133f90cd4c5931a3ac48c84cb628b16fcMichal Zidek ret = sysdb_set_service_attr(domain, name,
82b5429d1438392c45e70a0f84dd4d0f5fa1a171Jakub Hrozek sys_attrs, SYSDB_MOD_REP);
82b5429d1438392c45e70a0f84dd4d0f5fa1a171Jakub Hrozek break;
82b5429d1438392c45e70a0f84dd4d0f5fa1a171Jakub Hrozek case TYPE_AUTOFSMAP:
e7d1cd14ce1a427007b1a7e9789dcb7e9619f84fJakub Hrozek ret = sysdb_set_autofsmap_attr(domain, name,
82b5429d1438392c45e70a0f84dd4d0f5fa1a171Jakub Hrozek sys_attrs, SYSDB_MOD_REP);
82b5429d1438392c45e70a0f84dd4d0f5fa1a171Jakub Hrozek break;
3ac7c4fe618ede980a4df8d90341ef1fd0f1f62fWilliam B case TYPE_SSH_HOST:
3ac7c4fe618ede980a4df8d90341ef1fd0f1f62fWilliam B#ifdef BUILD_SSH
3ac7c4fe618ede980a4df8d90341ef1fd0f1f62fWilliam B ret = sysdb_set_ssh_host_attr(domain, name,
3ac7c4fe618ede980a4df8d90341ef1fd0f1f62fWilliam B sys_attrs, SYSDB_MOD_REP);
3ac7c4fe618ede980a4df8d90341ef1fd0f1f62fWilliam B#else /* BUILD_SSH */
3ac7c4fe618ede980a4df8d90341ef1fd0f1f62fWilliam B ret = ENOSYS;
3ac7c4fe618ede980a4df8d90341ef1fd0f1f62fWilliam B#endif /* BUILD_SSH */
3ac7c4fe618ede980a4df8d90341ef1fd0f1f62fWilliam B break;
fd3cbf6bfe86a245d7e90d2a355794eb9c70d525Petr Cech case TYPE_SUDO_RULE:
fd3cbf6bfe86a245d7e90d2a355794eb9c70d525Petr Cech#ifdef BUILD_SUDO
fd3cbf6bfe86a245d7e90d2a355794eb9c70d525Petr Cech ret = sysdb_set_sudo_rule_attr(domain, name,
fd3cbf6bfe86a245d7e90d2a355794eb9c70d525Petr Cech sys_attrs, SYSDB_MOD_REP);
fd3cbf6bfe86a245d7e90d2a355794eb9c70d525Petr Cech#else /* BUILD_SUDO */
fd3cbf6bfe86a245d7e90d2a355794eb9c70d525Petr Cech ret = ENOSYS;
fd3cbf6bfe86a245d7e90d2a355794eb9c70d525Petr Cech#endif /* BUILD_SUDO */
fd3cbf6bfe86a245d7e90d2a355794eb9c70d525Petr Cech break;
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny default:
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny return EINVAL;
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny }
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny if (ret != EOK) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "Could not set entry attributes\n");
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny }
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny } else {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "Could not add expiration time to attributes\n");
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny }
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny talloc_zfree(sys_attrs);
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny } else {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "Could not create sysdb attributes\n");
d35c8317ed23aff66fde8147bfa2ea91f43a12e4Jan Zeleny ret = ENOMEM;
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny }
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny return ret;
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny}
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny
643b48013c1f556530eb2a89a8baf4aa40357278Jakub Hrozekstatic errno_t init_domains(struct cache_tool_ctx *ctx,
643b48013c1f556530eb2a89a8baf4aa40357278Jakub Hrozek const char *domain)
82b5429d1438392c45e70a0f84dd4d0f5fa1a171Jakub Hrozek{
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny char *confdb_path;
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny int ret;
d2791a492d8f0a9df73fc7a683b3f712abf80f3fSumit Bose struct sss_domain_info *dinfo;
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny confdb_path = talloc_asprintf(ctx, "%s/%s", DB_PATH, CONFDB_FILE);
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny if (confdb_path == NULL) {
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny return ENOMEM;
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny }
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny /* Connect to the conf db */
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny ret = confdb_init(ctx, &ctx->confdb, confdb_path);
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny talloc_free(confdb_path);
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny if (ret != EOK) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "Could not initialize connection to the confdb\n");
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny return ret;
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny }
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny if (domain) {
234958be042980242fff6da936af674da877c5efSimo Sorce ret = sssd_domain_init(ctx, ctx->confdb,
234958be042980242fff6da936af674da877c5efSimo Sorce domain, DB_PATH, &ctx->domains);
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny if (ret != EOK) {
4c9a85ab708ec7debecad51e4240e04d8bc6ca4eOndrej Kos SYSDB_VERSION_ERROR(ret);
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "Could not initialize connection to the sysdb\n");
72aa8e7b1d234b6b68446d42efa1cff22b70c81bSimo Sorce return ret;
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny }
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny
72aa8e7b1d234b6b68446d42efa1cff22b70c81bSimo Sorce } else {
72aa8e7b1d234b6b68446d42efa1cff22b70c81bSimo Sorce ret = confdb_get_domains(ctx->confdb, &ctx->domains);
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny if (ret != EOK) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Could not initialize domains\n");
72aa8e7b1d234b6b68446d42efa1cff22b70c81bSimo Sorce return ret;
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny }
72aa8e7b1d234b6b68446d42efa1cff22b70c81bSimo Sorce
ebbeac5c6b8b87ab478ee5a04ec48fbbba0c9efcJakub Hrozek ret = sysdb_init(ctx, ctx->domains);
4c9a85ab708ec7debecad51e4240e04d8bc6ca4eOndrej Kos SYSDB_VERSION_ERROR(ret);
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny if (ret != EOK) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "Could not initialize connection to the sysdb\n");
72aa8e7b1d234b6b68446d42efa1cff22b70c81bSimo Sorce return ret;
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny }
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny }
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny
877b92e80bde510d5cd9f03dbf01e2bcf73ab072Michal Židek for (dinfo = ctx->domains; dinfo; dinfo = get_next_domain(dinfo, 0)) {
d2791a492d8f0a9df73fc7a683b3f712abf80f3fSumit Bose ret = sss_names_init(ctx, ctx->confdb, dinfo->name, &dinfo->names);
d2791a492d8f0a9df73fc7a683b3f712abf80f3fSumit Bose if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "sss_names_init() failed\n");
d2791a492d8f0a9df73fc7a683b3f712abf80f3fSumit Bose return ret;
d2791a492d8f0a9df73fc7a683b3f712abf80f3fSumit Bose }
d2791a492d8f0a9df73fc7a683b3f712abf80f3fSumit Bose }
d2791a492d8f0a9df73fc7a683b3f712abf80f3fSumit Bose
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny return EOK;
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny}
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny
643b48013c1f556530eb2a89a8baf4aa40357278Jakub Hrozekstatic errno_t init_context(int argc, const char *argv[],
643b48013c1f556530eb2a89a8baf4aa40357278Jakub Hrozek struct cache_tool_ctx **tctx)
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny{
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny struct cache_tool_ctx *ctx = NULL;
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny int idb = INVALIDATE_NONE;
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech struct input_values values = { 0 };
89caf5edcc99f5731e89bd51e6ffaad3ec11c304Pavel Březina int debug = SSSDBG_DEFAULT;
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny errno_t ret = EOK;
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny poptContext pc = NULL;
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny struct poptOption long_options[] = {
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny POPT_AUTOHELP
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny { "debug", '\0', POPT_ARG_INT | POPT_ARGFLAG_DOC_HIDDEN, &debug,
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny 0, _("The debug level to run with"), NULL },
9651a27ec14f3a378e861ca39852480f37f1ef08Michal Zidek { "everything", 'E', POPT_ARG_NONE, NULL, 'e',
fd3cbf6bfe86a245d7e90d2a355794eb9c70d525Petr Cech _("Invalidate all cached entries"), NULL },
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech { "user", 'u', POPT_ARG_STRING, &(values.user), 0,
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny _("Invalidate particular user"), NULL },
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny { "users", 'U', POPT_ARG_NONE, NULL, 'u',
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny _("Invalidate all users"), NULL },
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech { "group", 'g', POPT_ARG_STRING, &(values.group), 0,
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny _("Invalidate particular group"), NULL },
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny { "groups", 'G', POPT_ARG_NONE, NULL, 'g',
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny _("Invalidate all groups"), NULL },
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech { "netgroup", 'n', POPT_ARG_STRING, &(values.netgroup), 0,
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny _("Invalidate particular netgroup"), NULL },
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny { "netgroups", 'N', POPT_ARG_NONE, NULL, 'n',
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny _("Invalidate all netgroups"), NULL },
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech { "service", 's', POPT_ARG_STRING, &(values.service), 0,
82b5429d1438392c45e70a0f84dd4d0f5fa1a171Jakub Hrozek _("Invalidate particular service"), NULL },
82b5429d1438392c45e70a0f84dd4d0f5fa1a171Jakub Hrozek { "services", 'S', POPT_ARG_NONE, NULL, 's',
82b5429d1438392c45e70a0f84dd4d0f5fa1a171Jakub Hrozek _("Invalidate all services"), NULL },
82b5429d1438392c45e70a0f84dd4d0f5fa1a171Jakub Hrozek#ifdef BUILD_AUTOFS
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech { "autofs-map", 'a', POPT_ARG_STRING, &(values.map), 0,
82b5429d1438392c45e70a0f84dd4d0f5fa1a171Jakub Hrozek _("Invalidate particular autofs map"), NULL },
82b5429d1438392c45e70a0f84dd4d0f5fa1a171Jakub Hrozek { "autofs-maps", 'A', POPT_ARG_NONE, NULL, 'a',
82b5429d1438392c45e70a0f84dd4d0f5fa1a171Jakub Hrozek _("Invalidate all autofs maps"), NULL },
82b5429d1438392c45e70a0f84dd4d0f5fa1a171Jakub Hrozek#endif /* BUILD_AUTOFS */
3ac7c4fe618ede980a4df8d90341ef1fd0f1f62fWilliam B#ifdef BUILD_SSH
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech { "ssh-host", 'h', POPT_ARG_STRING, &(values.ssh_host), 0,
3ac7c4fe618ede980a4df8d90341ef1fd0f1f62fWilliam B _("Invalidate particular SSH host"), NULL },
3ac7c4fe618ede980a4df8d90341ef1fd0f1f62fWilliam B { "ssh-hosts", 'H', POPT_ARG_NONE, NULL, 'h',
3ac7c4fe618ede980a4df8d90341ef1fd0f1f62fWilliam B _("Invalidate all SSH hosts"), NULL },
3ac7c4fe618ede980a4df8d90341ef1fd0f1f62fWilliam B#endif /* BUILD_SSH */
fd3cbf6bfe86a245d7e90d2a355794eb9c70d525Petr Cech#ifdef BUILD_SUDO
fd3cbf6bfe86a245d7e90d2a355794eb9c70d525Petr Cech { "sudo-rule", 'r', POPT_ARG_STRING, &(values.sudo_rule), 0,
fd3cbf6bfe86a245d7e90d2a355794eb9c70d525Petr Cech _("Invalidate particular sudo rule"), NULL },
fd3cbf6bfe86a245d7e90d2a355794eb9c70d525Petr Cech { "sudo-rules", 'R', POPT_ARG_NONE, NULL, 'r',
fd3cbf6bfe86a245d7e90d2a355794eb9c70d525Petr Cech _("Invalidate all cached sudo rules"), NULL },
fd3cbf6bfe86a245d7e90d2a355794eb9c70d525Petr Cech#endif /* BUILD_SUDO */
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech { "domain", 'd', POPT_ARG_STRING, &(values.domain), 0,
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny _("Only invalidate entries from a particular domain"), NULL },
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny POPT_TABLEEND
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny };
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny ret = set_locale();
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny if (ret != EOK) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "set_locale failed (%d): %s\n", ret, strerror(ret));
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny ERROR("Error setting the locale\n");
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny goto fini;
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny }
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny pc = poptGetContext(NULL, argc, argv, long_options, 0);
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny while ((ret = poptGetNextOpt(pc)) > 0) {
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny switch (ret) {
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny case 'u':
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny idb |= INVALIDATE_USERS;
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny break;
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny case 'g':
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny idb |= INVALIDATE_GROUPS;
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny break;
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny case 'n':
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny idb |= INVALIDATE_NETGROUPS;
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny break;
82b5429d1438392c45e70a0f84dd4d0f5fa1a171Jakub Hrozek case 's':
82b5429d1438392c45e70a0f84dd4d0f5fa1a171Jakub Hrozek idb |= INVALIDATE_SERVICES;
82b5429d1438392c45e70a0f84dd4d0f5fa1a171Jakub Hrozek break;
82b5429d1438392c45e70a0f84dd4d0f5fa1a171Jakub Hrozek case 'a':
82b5429d1438392c45e70a0f84dd4d0f5fa1a171Jakub Hrozek idb |= INVALIDATE_AUTOFSMAPS;
82b5429d1438392c45e70a0f84dd4d0f5fa1a171Jakub Hrozek break;
3ac7c4fe618ede980a4df8d90341ef1fd0f1f62fWilliam B case 'h':
3ac7c4fe618ede980a4df8d90341ef1fd0f1f62fWilliam B idb |= INVALIDATE_SSH_HOSTS;
3ac7c4fe618ede980a4df8d90341ef1fd0f1f62fWilliam B break;
fd3cbf6bfe86a245d7e90d2a355794eb9c70d525Petr Cech case 'r':
fd3cbf6bfe86a245d7e90d2a355794eb9c70d525Petr Cech idb |= INVALIDATE_SUDO_RULES;
fd3cbf6bfe86a245d7e90d2a355794eb9c70d525Petr Cech break;
9651a27ec14f3a378e861ca39852480f37f1ef08Michal Zidek case 'e':
9651a27ec14f3a378e861ca39852480f37f1ef08Michal Zidek idb = INVALIDATE_EVERYTHING;
fd3cbf6bfe86a245d7e90d2a355794eb9c70d525Petr Cech#ifdef BUILD_SUDO
fd3cbf6bfe86a245d7e90d2a355794eb9c70d525Petr Cech idb |= INVALIDATE_SUDO_RULES;
fd3cbf6bfe86a245d7e90d2a355794eb9c70d525Petr Cech#endif /* BUILD_SUDO */
9651a27ec14f3a378e861ca39852480f37f1ef08Michal Zidek break;
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny }
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny }
da0b829a2002987339aadaa01b85adbb5ddba20dJakub Hrozek
6b57784f0f175275fd900eca21c77415e3a5ea52Jakub Hrozek DEBUG_CLI_INIT(debug);
f82135b75f0574e65c73269d6f24d42ba025b8e2Michal Zidek debug_prg_name = argv[0];
f82135b75f0574e65c73269d6f24d42ba025b8e2Michal Zidek
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny if (ret != -1) {
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny BAD_POPT_PARAMS(pc, poptStrerror(ret), ret, fini);
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny }
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny
1330390c698ca0802200725df43356557aa633a2Justin Stephenson if (poptGetArg(pc)) {
1330390c698ca0802200725df43356557aa633a2Justin Stephenson BAD_POPT_PARAMS(pc,
1330390c698ca0802200725df43356557aa633a2Justin Stephenson _("Unexpected argument(s) provided, options that "
1330390c698ca0802200725df43356557aa633a2Justin Stephenson "invalidate a single object only accept a single "
1330390c698ca0802200725df43356557aa633a2Justin Stephenson "provided argument.\n"),
1330390c698ca0802200725df43356557aa633a2Justin Stephenson ret, fini);
1330390c698ca0802200725df43356557aa633a2Justin Stephenson }
1330390c698ca0802200725df43356557aa633a2Justin Stephenson
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech if (idb == INVALIDATE_NONE && !values.user && !values.group &&
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech !values.netgroup && !values.service && !values.map &&
fd3cbf6bfe86a245d7e90d2a355794eb9c70d525Petr Cech !values.ssh_host && !values.sudo_rule) {
da0b829a2002987339aadaa01b85adbb5ddba20dJakub Hrozek BAD_POPT_PARAMS(pc,
da0b829a2002987339aadaa01b85adbb5ddba20dJakub Hrozek _("Please select at least one object to invalidate\n"),
da0b829a2002987339aadaa01b85adbb5ddba20dJakub Hrozek ret, fini);
da0b829a2002987339aadaa01b85adbb5ddba20dJakub Hrozek }
da0b829a2002987339aadaa01b85adbb5ddba20dJakub Hrozek
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny CHECK_ROOT(ret, debug_prg_name);
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny ctx = talloc_zero(NULL, struct cache_tool_ctx);
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny if (ctx == NULL) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov "Could not allocate memory for tools context\n");
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny ret = ENOMEM;
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny goto fini;
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny }
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny if (idb & INVALIDATE_USERS) {
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny ctx->user_filter = talloc_asprintf(ctx, "(%s=*)", SYSDB_NAME);
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek ctx->update_user_filter = false;
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech } else if (values.user) {
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech ctx->user_name = talloc_strdup(ctx, values.user);
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek ctx->update_user_filter = true;
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny }
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny if (idb & INVALIDATE_GROUPS) {
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny ctx->group_filter = talloc_asprintf(ctx, "(%s=*)", SYSDB_NAME);
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek ctx->update_group_filter = false;
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech } else if (values.group) {
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech ctx->group_name = talloc_strdup(ctx, values.group);
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek ctx->update_group_filter = true;
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny }
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny if (idb & INVALIDATE_NETGROUPS) {
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny ctx->netgroup_filter = talloc_asprintf(ctx, "(%s=*)", SYSDB_NAME);
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek ctx->update_netgroup_filter = false;
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech } else if (values.netgroup) {
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech ctx->netgroup_name = talloc_strdup(ctx, values.netgroup);
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek ctx->update_netgroup_filter = true;
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny }
82b5429d1438392c45e70a0f84dd4d0f5fa1a171Jakub Hrozek
82b5429d1438392c45e70a0f84dd4d0f5fa1a171Jakub Hrozek if (idb & INVALIDATE_SERVICES) {
e3ce042be3a6c66aa720fc139f557b065ae6dc5eSimo Sorce ctx->service_filter = talloc_asprintf(ctx, "(%s=*)", SYSDB_NAME);
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek ctx->update_service_filter = false;
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech } else if (values.service) {
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech ctx->service_name = talloc_strdup(ctx, values.service);
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek ctx->update_service_filter = true;
82b5429d1438392c45e70a0f84dd4d0f5fa1a171Jakub Hrozek }
82b5429d1438392c45e70a0f84dd4d0f5fa1a171Jakub Hrozek
82b5429d1438392c45e70a0f84dd4d0f5fa1a171Jakub Hrozek if (idb & INVALIDATE_AUTOFSMAPS) {
82b5429d1438392c45e70a0f84dd4d0f5fa1a171Jakub Hrozek ctx->autofs_filter = talloc_asprintf(ctx, "(&(objectclass=%s)(%s=*))",
82b5429d1438392c45e70a0f84dd4d0f5fa1a171Jakub Hrozek SYSDB_AUTOFS_MAP_OC, SYSDB_NAME);
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek ctx->update_autofs_filter = false;
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech } else if (values.map) {
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech ctx->autofs_name = talloc_strdup(ctx, values.map);
d27d11b360b92f1728206802005bb3da359e1ea4Michal Zidek ctx->update_autofs_filter = true;
82b5429d1438392c45e70a0f84dd4d0f5fa1a171Jakub Hrozek }
82b5429d1438392c45e70a0f84dd4d0f5fa1a171Jakub Hrozek
3ac7c4fe618ede980a4df8d90341ef1fd0f1f62fWilliam B if (idb & INVALIDATE_SSH_HOSTS) {
3ac7c4fe618ede980a4df8d90341ef1fd0f1f62fWilliam B ctx->ssh_host_filter = talloc_asprintf(ctx, "(%s=*)", SYSDB_NAME);
3ac7c4fe618ede980a4df8d90341ef1fd0f1f62fWilliam B ctx->update_ssh_host_filter = false;
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech } else if (values.ssh_host) {
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech ctx->ssh_host_name = talloc_strdup(ctx, values.ssh_host);
3ac7c4fe618ede980a4df8d90341ef1fd0f1f62fWilliam B ctx->update_ssh_host_filter = true;
3ac7c4fe618ede980a4df8d90341ef1fd0f1f62fWilliam B }
3ac7c4fe618ede980a4df8d90341ef1fd0f1f62fWilliam B
fd3cbf6bfe86a245d7e90d2a355794eb9c70d525Petr Cech if (idb & INVALIDATE_SUDO_RULES) {
fd3cbf6bfe86a245d7e90d2a355794eb9c70d525Petr Cech ctx->sudo_rule_filter = talloc_asprintf(ctx, "(%s=*)", SYSDB_NAME);
fd3cbf6bfe86a245d7e90d2a355794eb9c70d525Petr Cech ctx->update_sudo_rule_filter = false;
fd3cbf6bfe86a245d7e90d2a355794eb9c70d525Petr Cech } else if (values.sudo_rule) {
fd3cbf6bfe86a245d7e90d2a355794eb9c70d525Petr Cech ctx->sudo_rule_name = talloc_strdup(ctx, values.sudo_rule);
fd3cbf6bfe86a245d7e90d2a355794eb9c70d525Petr Cech ctx->update_sudo_rule_filter = true;
fd3cbf6bfe86a245d7e90d2a355794eb9c70d525Petr Cech }
fd3cbf6bfe86a245d7e90d2a355794eb9c70d525Petr Cech
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech if (is_filter_valid(ctx, &values, idb) == false) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Construction of filters failed\n");
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny ret = ENOMEM;
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny goto fini;
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny }
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech ret = init_domains(ctx, values.domain);
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny if (ret != EOK) {
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech if (values.domain) {
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek ERROR("Could not open domain %1$s. If the domain is a subdomain "
72bb31d9a093bff7b8c7f973b057ed4e9e41d4caMichal Zidek "(trusted domain), use fully qualified name instead of "
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech "--domain/-d parameter.\n", values.domain);
da0b829a2002987339aadaa01b85adbb5ddba20dJakub Hrozek } else {
da0b829a2002987339aadaa01b85adbb5ddba20dJakub Hrozek ERROR("Could not open available domains\n");
da0b829a2002987339aadaa01b85adbb5ddba20dJakub Hrozek }
da0b829a2002987339aadaa01b85adbb5ddba20dJakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Initialization of sysdb connections failed\n");
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny goto fini;
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny }
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny ret = EOK;
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zelenyfini:
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny poptFreeContext(pc);
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech free_input_values(&values);
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny if (ret != EOK && ctx) {
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny talloc_zfree(ctx);
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny }
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny if (ret == EOK) {
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny *tctx = ctx;
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny }
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny return ret;
c737e1444fb186e349e59bfa9dac4995b720b4b1Jan Zeleny}
82b5429d1438392c45e70a0f84dd4d0f5fa1a171Jakub Hrozek
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cechstatic bool is_filter_valid(struct cache_tool_ctx *ctx,
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech struct input_values *values, int idb)
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech{
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech if ((idb & INVALIDATE_USERS) && ctx->user_filter == NULL) {
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech return false;
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech }
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech if ((idb & INVALIDATE_GROUPS) && ctx->group_filter == NULL) {
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech return false;
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech }
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech if ((idb & INVALIDATE_NETGROUPS) && ctx->netgroup_filter == NULL) {
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech return false;
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech }
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech if ((idb & INVALIDATE_SERVICES) && ctx->service_filter == NULL) {
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech return false;
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech }
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech if ((idb & INVALIDATE_AUTOFSMAPS) && ctx->autofs_filter == NULL) {
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech return false;
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech }
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech if ((idb & INVALIDATE_SSH_HOSTS) && ctx->ssh_host_filter == NULL) {
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech return false;
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech }
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech if (values->user && ctx->user_name == NULL) {
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech return false;
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech }
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech if (values->group && ctx->group_name == NULL) {
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech return false;
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech }
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech if (values->netgroup && ctx->netgroup_name == NULL) {
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech return false;
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech }
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech if (values->service && ctx->service_name == NULL) {
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech return false;
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech }
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech if (values->map && ctx->autofs_name == NULL) {
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech return false;
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech }
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech if (values->ssh_host && ctx->ssh_host_name == NULL) {
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech return false;
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech }
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech
fd3cbf6bfe86a245d7e90d2a355794eb9c70d525Petr Cech if (values->sudo_rule && ctx->sudo_rule_name == NULL) {
fd3cbf6bfe86a245d7e90d2a355794eb9c70d525Petr Cech return false;
fd3cbf6bfe86a245d7e90d2a355794eb9c70d525Petr Cech }
fd3cbf6bfe86a245d7e90d2a355794eb9c70d525Petr Cech
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech return true;
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech}
be6d25ea38ddda232175aab5e297d8c6cb223551Petr Cech
82b5429d1438392c45e70a0f84dd4d0f5fa1a171Jakub Hrozekstatic errno_t
78c4b29420855b9f5384cd5e052fc9369c57d899Lukas Slebodniksearch_autofsmaps(TALLOC_CTX *mem_ctx,
770896b194b7b66b09c2a30545b4d091fd86b1f4Simo Sorce struct sss_domain_info *domain,
82b5429d1438392c45e70a0f84dd4d0f5fa1a171Jakub Hrozek const char *sub_filter, const char **attrs,
82b5429d1438392c45e70a0f84dd4d0f5fa1a171Jakub Hrozek size_t *msgs_count, struct ldb_message ***msgs)
82b5429d1438392c45e70a0f84dd4d0f5fa1a171Jakub Hrozek{
82b5429d1438392c45e70a0f84dd4d0f5fa1a171Jakub Hrozek#ifdef BUILD_AUTOFS
d115f40c7a3999e3cbe705a2ff9cf0fd493f80fbMichal Zidek return sysdb_search_custom(mem_ctx, domain, sub_filter,
82b5429d1438392c45e70a0f84dd4d0f5fa1a171Jakub Hrozek AUTOFS_MAP_SUBDIR, attrs,
82b5429d1438392c45e70a0f84dd4d0f5fa1a171Jakub Hrozek msgs_count, msgs);
82b5429d1438392c45e70a0f84dd4d0f5fa1a171Jakub Hrozek#else
82b5429d1438392c45e70a0f84dd4d0f5fa1a171Jakub Hrozek return ENOSYS;
82b5429d1438392c45e70a0f84dd4d0f5fa1a171Jakub Hrozek#endif /* BUILD_AUTOFS */
82b5429d1438392c45e70a0f84dd4d0f5fa1a171Jakub Hrozek}
57a924e71230ea360b19a88e0d5818cf01017161Petr Čech
57a924e71230ea360b19a88e0d5818cf01017161Petr Čech/* WARNING: Direct writing to persistent cache!! */
57a924e71230ea360b19a88e0d5818cf01017161Petr Čechstatic int sysdb_invalidate_user_cache_entry(struct sss_domain_info *domain,
57a924e71230ea360b19a88e0d5818cf01017161Petr Čech const char *name)
57a924e71230ea360b19a88e0d5818cf01017161Petr Čech{
57a924e71230ea360b19a88e0d5818cf01017161Petr Čech return sysdb_invalidate_cache_entry(domain, name, true);
57a924e71230ea360b19a88e0d5818cf01017161Petr Čech}
57a924e71230ea360b19a88e0d5818cf01017161Petr Čech
57a924e71230ea360b19a88e0d5818cf01017161Petr Čech/* WARNING: Direct writing to persistent cache!! */
57a924e71230ea360b19a88e0d5818cf01017161Petr Čechstatic int sysdb_invalidate_group_cache_entry(struct sss_domain_info *domain,
57a924e71230ea360b19a88e0d5818cf01017161Petr Čech const char *name)
57a924e71230ea360b19a88e0d5818cf01017161Petr Čech{
57a924e71230ea360b19a88e0d5818cf01017161Petr Čech return sysdb_invalidate_cache_entry(domain, name, false);
57a924e71230ea360b19a88e0d5818cf01017161Petr Čech}