4c11f752e1f10cf5740d53a3206bb795e9e34fe8Jan Zeleny System Database - SELinux support
4c11f752e1f10cf5740d53a3206bb795e9e34fe8Jan Zeleny Copyright (C) Jan Zeleny <jzeleny@redhat.com> 2012
4c11f752e1f10cf5740d53a3206bb795e9e34fe8Jan Zeleny This program is free software; you can redistribute it and/or modify
4c11f752e1f10cf5740d53a3206bb795e9e34fe8Jan Zeleny it under the terms of the GNU General Public License as published by
4c11f752e1f10cf5740d53a3206bb795e9e34fe8Jan Zeleny the Free Software Foundation; either version 3 of the License, or
4c11f752e1f10cf5740d53a3206bb795e9e34fe8Jan Zeleny (at your option) any later version.
4c11f752e1f10cf5740d53a3206bb795e9e34fe8Jan Zeleny This program is distributed in the hope that it will be useful,
4c11f752e1f10cf5740d53a3206bb795e9e34fe8Jan Zeleny but WITHOUT ANY WARRANTY; without even the implied warranty of
4c11f752e1f10cf5740d53a3206bb795e9e34fe8Jan Zeleny MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4c11f752e1f10cf5740d53a3206bb795e9e34fe8Jan Zeleny GNU General Public License for more details.
4c11f752e1f10cf5740d53a3206bb795e9e34fe8Jan Zeleny You should have received a copy of the GNU General Public License
4c11f752e1f10cf5740d53a3206bb795e9e34fe8Jan Zeleny along with this program. If not, see <http://www.gnu.org/licenses/>.
4c11f752e1f10cf5740d53a3206bb795e9e34fe8Jan Zeleny/* Some generic routines */
4c11f752e1f10cf5740d53a3206bb795e9e34fe8Jan Zeleny ret = sysdb_attrs_add_string(attrs, SYSDB_OBJECTCLASS, objectclass);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Could not set map object class [%d]: %s\n",
4c11f752e1f10cf5740d53a3206bb795e9e34fe8Jan Zeleny ret = sysdb_attrs_add_time_t(attrs, SYSDB_CREATE_TIME, now);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_LIBS, "Error: %d (%s)\n", ret, strerror(ret));
17759fc794c22898d1db609b736fbcd77536d150Jakub Hrozekstatic errno_t sysdb_store_selinux_entity(struct sss_domain_info *domain,
4c11f752e1f10cf5740d53a3206bb795e9e34fe8Jan Zeleny ret = sysdb_attrs_get_string(attrs, SYSDB_NAME, &name);
4c11f752e1f10cf5740d53a3206bb795e9e34fe8Jan Zeleny ret = sysdb_dn_sanitize(tmp_ctx, name, &clean_name);
4c11f752e1f10cf5740d53a3206bb795e9e34fe8Jan Zeleny dn = ldb_dn_new_fmt(tmp_ctx, sysdb->ldb, SYSDB_TMPL_SEUSERMAP,
4c11f752e1f10cf5740d53a3206bb795e9e34fe8Jan Zeleny dn = ldb_dn_new_fmt(tmp_ctx, sysdb->ldb, SYSDB_TMPL_SELINUX_BASE,
4c11f752e1f10cf5740d53a3206bb795e9e34fe8Jan Zeleny if (type != SELINUX_CONFIG && type != SELINUX_USER_MAP) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Bad SELinux entity type: [%d]\n", type);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to start transaction\n");
4c11f752e1f10cf5740d53a3206bb795e9e34fe8Jan Zeleny ret = sysdb_attrs_add_time_t(attrs, SYSDB_LAST_UPDATE, now);
894d18ff4178f40a18bbfece8fae270d8307eac6Jakub Hrozek ret = sysdb_add_selinux_entity(sysdb, dn, objectclass, attrs, now);
894d18ff4178f40a18bbfece8fae270d8307eac6Jakub Hrozek ret = sysdb_set_entry_attr(sysdb, dn, attrs, SYSDB_MOD_REP);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to commit transaction\n");
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Could not cancel transaction\n");
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "Error: %d (%s)\n", ret, strerror(ret));
17759fc794c22898d1db609b736fbcd77536d150Jakub Hrozekerrno_t sysdb_store_selinux_usermap(struct sss_domain_info *domain,
17759fc794c22898d1db609b736fbcd77536d150Jakub Hrozek return sysdb_store_selinux_entity(domain, attrs, SELINUX_USER_MAP);
17759fc794c22898d1db609b736fbcd77536d150Jakub Hrozekerrno_t sysdb_store_selinux_config(struct sss_domain_info *domain,
4c11f752e1f10cf5740d53a3206bb795e9e34fe8Jan Zeleny const char *order)
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "The SELinux order is missing\n");
894d18ff4178f40a18bbfece8fae270d8307eac6Jakub Hrozek ret = sysdb_attrs_add_string(attrs, SYSDB_SELINUX_DEFAULT_USER,
4c11f752e1f10cf5740d53a3206bb795e9e34fe8Jan Zeleny ret = sysdb_attrs_add_string(attrs, SYSDB_SELINUX_DEFAULT_ORDER,
17759fc794c22898d1db609b736fbcd77536d150Jakub Hrozek ret = sysdb_store_selinux_entity(domain, attrs, SELINUX_CONFIG);
17759fc794c22898d1db609b736fbcd77536d150Jakub Hrozekerrno_t sysdb_delete_usermaps(struct sss_domain_info *domain)
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "sysdb_delete_recursive failed.\n");
4c11f752e1f10cf5740d53a3206bb795e9e34fe8Jan Zeleny/* --- SYSDB SELinux search routines --- */
6f0daa807ac0bb560353c5d5e25638cf1972f79fJakub Hrozek const char **attrs,
6f0daa807ac0bb560353c5d5e25638cf1972f79fJakub Hrozek basedn = ldb_dn_new_fmt(mem_ctx, sysdb_ctx_get_ldb(sysdb),
6f0daa807ac0bb560353c5d5e25638cf1972f79fJakub Hrozek SYSDB_OBJECTCLASS, SYSDB_SELINUX_USERMAP_CLASS);
6f0daa807ac0bb560353c5d5e25638cf1972f79fJakub Hrozek ret = sysdb_search_entry(mem_ctx, sysdb, basedn, LDB_SCOPE_SUBTREE, filter,
6f0daa807ac0bb560353c5d5e25638cf1972f79fJakub Hrozek } else if (ret) {
4c11f752e1f10cf5740d53a3206bb795e9e34fe8Jan Zelenyerrno_t sysdb_search_selinux_config(TALLOC_CTX *mem_ctx,
4c11f752e1f10cf5740d53a3206bb795e9e34fe8Jan Zeleny const char **attrs,
4c11f752e1f10cf5740d53a3206bb795e9e34fe8Jan Zeleny const char *def_attrs[] = { SYSDB_SELINUX_DEFAULT_USER,
17759fc794c22898d1db609b736fbcd77536d150Jakub Hrozek basedn = ldb_dn_new_fmt(tmp_ctx, domain->sysdb->ldb,
17759fc794c22898d1db609b736fbcd77536d150Jakub Hrozek ret = sysdb_search_entry(tmp_ctx, domain->sysdb, basedn, LDB_SCOPE_BASE,
17759fc794c22898d1db609b736fbcd77536d150Jakub Hrozek NULL, attrs?attrs:def_attrs, &msgs_count, &msgs);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "No SELinux root entry found\n");
4c11f752e1f10cf5740d53a3206bb795e9e34fe8Jan Zeleny } else if (ret) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "Error: %d (%s)\n", ret, strerror(ret));