9a18f78f38e274f4906af6ef8e1a82d844fde4ccFabiano Fidêncio Stephen Gallagher <sgallagh@redhat.com>
9a18f78f38e274f4906af6ef8e1a82d844fde4ccFabiano Fidêncio Copyright (C) 2011 Red Hat
9a18f78f38e274f4906af6ef8e1a82d844fde4ccFabiano Fidêncio This program is free software; you can redistribute it and/or modify
9a18f78f38e274f4906af6ef8e1a82d844fde4ccFabiano Fidêncio it under the terms of the GNU General Public License as published by
9a18f78f38e274f4906af6ef8e1a82d844fde4ccFabiano Fidêncio the Free Software Foundation; either version 3 of the License, or
9a18f78f38e274f4906af6ef8e1a82d844fde4ccFabiano Fidêncio (at your option) any later version.
9a18f78f38e274f4906af6ef8e1a82d844fde4ccFabiano Fidêncio This program is distributed in the hope that it will be useful,
9a18f78f38e274f4906af6ef8e1a82d844fde4ccFabiano Fidêncio but WITHOUT ANY WARRANTY; without even the implied warranty of
9a18f78f38e274f4906af6ef8e1a82d844fde4ccFabiano Fidêncio MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9a18f78f38e274f4906af6ef8e1a82d844fde4ccFabiano Fidêncio GNU General Public License for more details.
9a18f78f38e274f4906af6ef8e1a82d844fde4ccFabiano Fidêncio You should have received a copy of the GNU General Public License
9a18f78f38e274f4906af6ef8e1a82d844fde4ccFabiano Fidêncio along with this program. If not, see <http://www.gnu.org/licenses/>.
9a18f78f38e274f4906af6ef8e1a82d844fde4ccFabiano Fidêncioipa_common_save_list(struct sss_domain_info *domain,
9a18f78f38e274f4906af6ef8e1a82d844fde4ccFabiano Fidêncio DEBUG(SSSDBG_CRIT_FAILURE, "talloc_new failed.\n");
9a18f78f38e274f4906af6ef8e1a82d844fde4ccFabiano Fidêncio base_dn = sysdb_custom_subtree_dn(tmp_ctx, domain, subdir);
9a18f78f38e274f4906af6ef8e1a82d844fde4ccFabiano Fidêncio ret = sysdb_delete_recursive(domain->sysdb, base_dn, true);
9a18f78f38e274f4906af6ef8e1a82d844fde4ccFabiano Fidêncio DEBUG(SSSDBG_CRIT_FAILURE, "sysdb_delete_recursive failed.\n");
9a18f78f38e274f4906af6ef8e1a82d844fde4ccFabiano Fidêncio for (c = 0; c < count; c++) {
9a18f78f38e274f4906af6ef8e1a82d844fde4ccFabiano Fidêncio ret = sysdb_attrs_get_el(list[c], naming_attribute, &el);
9a18f78f38e274f4906af6ef8e1a82d844fde4ccFabiano Fidêncio DEBUG(SSSDBG_CRIT_FAILURE, "sysdb_attrs_get_el failed.\n");
9a18f78f38e274f4906af6ef8e1a82d844fde4ccFabiano Fidêncio DEBUG(SSSDBG_CRIT_FAILURE, "[%s] not found.\n", naming_attribute);
9a18f78f38e274f4906af6ef8e1a82d844fde4ccFabiano Fidêncio object_name = talloc_strndup(tmp_ctx, (const char *)el->values[0].data,
9a18f78f38e274f4906af6ef8e1a82d844fde4ccFabiano Fidêncio DEBUG(SSSDBG_CRIT_FAILURE, "talloc_strndup failed.\n");
9a18f78f38e274f4906af6ef8e1a82d844fde4ccFabiano Fidêncio DEBUG(SSSDBG_TRACE_ALL, "Object name: [%s].\n", object_name);
9a18f78f38e274f4906af6ef8e1a82d844fde4ccFabiano Fidêncio ret = sysdb_store_custom(domain, object_name, subdir, list[c]);
9a18f78f38e274f4906af6ef8e1a82d844fde4ccFabiano Fidêncio DEBUG(SSSDBG_CRIT_FAILURE, "sysdb_store_custom failed.\n");
9a18f78f38e274f4906af6ef8e1a82d844fde4ccFabiano Fidêncioipa_common_entries_and_groups_sysdb_save(struct sss_domain_info *domain,
9a18f78f38e274f4906af6ef8e1a82d844fde4ccFabiano Fidêncio if ((primary_count == 0 || primary == NULL)
9a18f78f38e274f4906af6ef8e1a82d844fde4ccFabiano Fidêncio /* There always has to be at least one
9a18f78f38e274f4906af6ef8e1a82d844fde4ccFabiano Fidêncio * primary entry.
9a18f78f38e274f4906af6ef8e1a82d844fde4ccFabiano Fidêncio /* Save the entries and groups to the cache */
9a18f78f38e274f4906af6ef8e1a82d844fde4ccFabiano Fidêncio ret = sysdb_transaction_start(domain->sysdb);
9a18f78f38e274f4906af6ef8e1a82d844fde4ccFabiano Fidêncio DEBUG(SSSDBG_CRIT_FAILURE, "Failed to start transaction\n");
9a18f78f38e274f4906af6ef8e1a82d844fde4ccFabiano Fidêncio /* First, save the specific entries */
9a18f78f38e274f4906af6ef8e1a82d844fde4ccFabiano Fidêncio ret = ipa_common_save_list(domain, true, primary_subdir,
9a18f78f38e274f4906af6ef8e1a82d844fde4ccFabiano Fidêncio DEBUG(SSSDBG_CRIT_FAILURE, "Could not save %s. [%d][%s]\n",
9a18f78f38e274f4906af6ef8e1a82d844fde4ccFabiano Fidêncio /* Second, save the groups */
9a18f78f38e274f4906af6ef8e1a82d844fde4ccFabiano Fidêncio ret = ipa_common_save_list(domain, true, group_subdir,
9a18f78f38e274f4906af6ef8e1a82d844fde4ccFabiano Fidêncio DEBUG(SSSDBG_CRIT_FAILURE, "Could not save %s. [%d][%s]\n",
9a18f78f38e274f4906af6ef8e1a82d844fde4ccFabiano Fidêncio ret = sysdb_transaction_commit(domain->sysdb);
9a18f78f38e274f4906af6ef8e1a82d844fde4ccFabiano Fidêncio DEBUG(SSSDBG_CRIT_FAILURE, "Failed to commit transaction\n");
9a18f78f38e274f4906af6ef8e1a82d844fde4ccFabiano Fidêncio sret = sysdb_transaction_cancel(domain->sysdb);
9a18f78f38e274f4906af6ef8e1a82d844fde4ccFabiano Fidêncio DEBUG(SSSDBG_FATAL_FAILURE, "Could not cancel sysdb transaction\n");
9a18f78f38e274f4906af6ef8e1a82d844fde4ccFabiano Fidêncio DEBUG(SSSDBG_MINOR_FAILURE, "Error [%d][%s]\n", ret, strerror(ret));
e17e37cd0e2109e7f1bd4ae48edfc8cca85b3f93Fabiano Fidêncioipa_common_get_cached_rules(TALLOC_CTX *mem_ctx,
e17e37cd0e2109e7f1bd4ae48edfc8cca85b3f93Fabiano Fidêncio filter = talloc_asprintf(tmp_ctx, "(objectClass=%s)", rule);
e17e37cd0e2109e7f1bd4ae48edfc8cca85b3f93Fabiano Fidêncio ret = sysdb_search_custom(tmp_ctx, domain, filter,
e17e37cd0e2109e7f1bd4ae48edfc8cca85b3f93Fabiano Fidêncio DEBUG(SSSDBG_CRIT_FAILURE, "Error looking up HBAC rules\n");
e17e37cd0e2109e7f1bd4ae48edfc8cca85b3f93Fabiano Fidêncio ret = sysdb_msg2attrs(tmp_ctx, rule_count, msgs, &rules);
e17e37cd0e2109e7f1bd4ae48edfc8cca85b3f93Fabiano Fidêncio "Could not convert ldb message to sysdb_attrs\n");
d2a0b4a6a220bf9a58c7306c3f673891efc419ebFabiano Fidêncioipa_common_purge_rules(struct sss_domain_info *domain,
d2a0b4a6a220bf9a58c7306c3f673891efc419ebFabiano Fidêncio base_dn = sysdb_custom_subtree_dn(tmp_ctx, domain, subtree_name);
d2a0b4a6a220bf9a58c7306c3f673891efc419ebFabiano Fidêncio ret = sysdb_delete_recursive(domain->sysdb, base_dn, true);
d2a0b4a6a220bf9a58c7306c3f673891efc419ebFabiano Fidêncio DEBUG(SSSDBG_CRIT_FAILURE, "sysdb_delete_recursive failed.\n");
0f623456437c96f50330fe0ff21afd9638d14e57Fabiano Fidêncioerrno_t ipa_common_save_rules(struct sss_domain_info *domain,
0f623456437c96f50330fe0ff21afd9638d14e57Fabiano Fidêncio ret = sysdb_transaction_start(domain->sysdb);
0f623456437c96f50330fe0ff21afd9638d14e57Fabiano Fidêncio DEBUG(SSSDBG_FATAL_FAILURE, "Could not start transaction\n");
0f623456437c96f50330fe0ff21afd9638d14e57Fabiano Fidêncio /* Save the hosts */
0f623456437c96f50330fe0ff21afd9638d14e57Fabiano Fidêncio ret = ipa_common_entries_and_groups_sysdb_save(domain,
0f623456437c96f50330fe0ff21afd9638d14e57Fabiano Fidêncio DEBUG(SSSDBG_CRIT_FAILURE, "Error saving hosts [%d]: %s\n",
0f623456437c96f50330fe0ff21afd9638d14e57Fabiano Fidêncio /* Save the services */
0f623456437c96f50330fe0ff21afd9638d14e57Fabiano Fidêncio ret = ipa_common_entries_and_groups_sysdb_save(domain,
0f623456437c96f50330fe0ff21afd9638d14e57Fabiano Fidêncio DEBUG(SSSDBG_CRIT_FAILURE, "Error saving services [%d]: %s\n",
0f623456437c96f50330fe0ff21afd9638d14e57Fabiano Fidêncio /* Save the rules */
0f623456437c96f50330fe0ff21afd9638d14e57Fabiano Fidêncio ret = ipa_common_entries_and_groups_sysdb_save(domain,
0f623456437c96f50330fe0ff21afd9638d14e57Fabiano Fidêncio DEBUG(SSSDBG_CRIT_FAILURE, "Error saving rules [%d]: %s\n",
0f623456437c96f50330fe0ff21afd9638d14e57Fabiano Fidêncio ret = sysdb_transaction_commit(domain->sysdb);
0f623456437c96f50330fe0ff21afd9638d14e57Fabiano Fidêncio DEBUG(SSSDBG_CRIT_FAILURE, "Failed to commit transaction\n");
0f623456437c96f50330fe0ff21afd9638d14e57Fabiano Fidêncio sret = sysdb_transaction_cancel(domain->sysdb);
0f623456437c96f50330fe0ff21afd9638d14e57Fabiano Fidêncio DEBUG(SSSDBG_OP_FAILURE, "Could not cancel transaction\n");
ee164913f9c12a557044eb469f4498b9be9a8f50Fabiano Fidêncioipa_common_get_hostgroupname(TALLOC_CTX *mem_ctx,
ee164913f9c12a557044eb469f4498b9be9a8f50Fabiano Fidêncio /* This is an IPA-specific hack. It may not
ee164913f9c12a557044eb469f4498b9be9a8f50Fabiano Fidêncio * work for non-IPA servers and will need to
ee164913f9c12a557044eb469f4498b9be9a8f50Fabiano Fidêncio * be changed if SSSD ever supports HBAC on
ee164913f9c12a557044eb469f4498b9be9a8f50Fabiano Fidêncio * a non-IPA server.
ee164913f9c12a557044eb469f4498b9be9a8f50Fabiano Fidêncio dn = ldb_dn_new(mem_ctx, sysdb_ctx_get_ldb(sysdb), host_dn);
ee164913f9c12a557044eb469f4498b9be9a8f50Fabiano Fidêncio /* RDN, hostgroups, accounts, and at least one DC= */
ee164913f9c12a557044eb469f4498b9be9a8f50Fabiano Fidêncio /* If it's fewer, it's not a group DN */
ee164913f9c12a557044eb469f4498b9be9a8f50Fabiano Fidêncio /* If the RDN name is 'cn' */
ee164913f9c12a557044eb469f4498b9be9a8f50Fabiano Fidêncio /* Shouldn't happen if ldb_dn_validate()
ee164913f9c12a557044eb469f4498b9be9a8f50Fabiano Fidêncio * passed, but we'll be careful.
ee164913f9c12a557044eb469f4498b9be9a8f50Fabiano Fidêncio /* RDN has the wrong attribute name.
ee164913f9c12a557044eb469f4498b9be9a8f50Fabiano Fidêncio * It's not a host.
ee164913f9c12a557044eb469f4498b9be9a8f50Fabiano Fidêncio /* and the second component is "cn=hostgroups" */
ee164913f9c12a557044eb469f4498b9be9a8f50Fabiano Fidêncio hostgroup_comp_name = ldb_dn_get_component_name(dn, 1);
ee164913f9c12a557044eb469f4498b9be9a8f50Fabiano Fidêncio if (strcasecmp("cn", hostgroup_comp_name) != 0) {
ee164913f9c12a557044eb469f4498b9be9a8f50Fabiano Fidêncio /* The second component name is not "cn" */
ee164913f9c12a557044eb469f4498b9be9a8f50Fabiano Fidêncio hostgroup_comp_val = ldb_dn_get_component_val(dn, 1);
ee164913f9c12a557044eb469f4498b9be9a8f50Fabiano Fidêncio /* The second component value is not "hostgroups" */
ee164913f9c12a557044eb469f4498b9be9a8f50Fabiano Fidêncio /* and the third component is "accounts" */
ee164913f9c12a557044eb469f4498b9be9a8f50Fabiano Fidêncio account_comp_name = ldb_dn_get_component_name(dn, 2);
ee164913f9c12a557044eb469f4498b9be9a8f50Fabiano Fidêncio if (strcasecmp("cn", account_comp_name) != 0) {
ee164913f9c12a557044eb469f4498b9be9a8f50Fabiano Fidêncio /* The third component name is not "cn" */
ee164913f9c12a557044eb469f4498b9be9a8f50Fabiano Fidêncio account_comp_val = ldb_dn_get_component_val(dn, 2);
ee164913f9c12a557044eb469f4498b9be9a8f50Fabiano Fidêncio /* The third component value is not "accounts" */
ee164913f9c12a557044eb469f4498b9be9a8f50Fabiano Fidêncio /* Then the value of the RDN is the group name */