1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek Jakub Hrozek <jhrozek@redhat.com>
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek Copyright (C) 2012 Red Hat
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek This program is free software; you can redistribute it and/or modify
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek it under the terms of the GNU General Public License as published by
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek the Free Software Foundation; either version 3 of the License, or
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek (at your option) any later version.
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek This program is distributed in the hope that it will be useful,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek but WITHOUT ANY WARRANTY; without even the implied warranty of
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek GNU General Public License for more details.
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek You should have received a copy of the GNU General Public License
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek along with this program. If not, see <http://www.gnu.org/licenses/>.
f17d26a8db285622a5cd5f21c7488b62eedc2cf8Jakub Hrozek#define SYSDB_TMPL_AUTOFS_ENTRY SYSDB_NAME"=%s,"SYSDB_TMPL_CUSTOM
f17d26a8db285622a5cd5f21c7488b62eedc2cf8Jakub Hrozekstatic struct ldb_dn *
e2ac9be4f293b96f3c8992f1171e44bc1da5cfcaMichal Zidek return sysdb_custom_dn(mem_ctx, domain, map_name, AUTOFS_MAP_SUBDIR);
f17d26a8db285622a5cd5f21c7488b62eedc2cf8Jakub Hrozekstatic struct ldb_dn *
e75a152157e054a2ed46acecbe8b5cfb9853773cJakub Hrozek ret = sysdb_dn_sanitize(tmp_ctx, entry_name, &clean_name);
e75a152157e054a2ed46acecbe8b5cfb9853773cJakub Hrozek ret = sysdb_dn_sanitize(tmp_ctx, entry_value, &clean_value);
e75a152157e054a2ed46acecbe8b5cfb9853773cJakub Hrozek rdn = talloc_asprintf(tmp_ctx, "%s%s", clean_name, clean_value);
e7d1cd14ce1a427007b1a7e9789dcb7e9619f84fJakub Hrozek dn = ldb_dn_new_fmt(mem_ctx, domain->sysdb->ldb, SYSDB_TMPL_AUTOFS_ENTRY,
2234d49c8a307ee4f11cc544c862a359f76b44adJakub Hrozek strdn = talloc_strdup(mem_ctx, ldb_dn_get_linearized(dn));
e7d1cd14ce1a427007b1a7e9789dcb7e9619f84fJakub Hrozeksysdb_save_autofsmap(struct sss_domain_info *domain,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek const char *name,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "Adding autofs map %s\n", autofsmapname);
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek ret = sysdb_attrs_add_string(attrs, SYSDB_OBJECTCLASS,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Could not set map object class [%d]: %s\n",
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek ret = sysdb_attrs_add_string(attrs, SYSDB_AUTOFS_MAP_NAME, autofsmapname);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Could not set map name [%d]: %s\n",
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek ret = sysdb_attrs_add_string(attrs, SYSDB_NAME, name);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Could not set name attribute [%d]: %s\n",
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek ret = sysdb_attrs_add_time_t(attrs, SYSDB_LAST_UPDATE, now);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Could not set sysdb lastUpdate [%d]: %s\n",
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek ret = sysdb_attrs_add_time_t(attrs, SYSDB_CACHE_EXPIRE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Could not set sysdb cache expire [%d]: %s\n",
d115f40c7a3999e3cbe705a2ff9cf0fd493f80fbMichal Zidek ret = sysdb_store_custom(domain, name, AUTOFS_MAP_SUBDIR, attrs);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "sysdb_store_custom failed [%d]: %s\n",
e7d1cd14ce1a427007b1a7e9789dcb7e9619f84fJakub Hrozeksysdb_delete_autofsmap(struct sss_domain_info *domain,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek const char *name)
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "Deleting autofs map %s\n", name);
d115f40c7a3999e3cbe705a2ff9cf0fd493f80fbMichal Zidek return sysdb_delete_custom(domain, name, AUTOFS_MAP_SUBDIR);
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek ret = sss_filter_sanitize(tmp_ctx, map_name, &safe_map_name);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Cannot sanitize map [%s] error [%d]: %s\n",
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek filter = talloc_asprintf(tmp_ctx, "(&(objectclass=%s)(%s=%s))",
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek SYSDB_AUTOFS_MAP_OC, SYSDB_NAME, safe_map_name);
d115f40c7a3999e3cbe705a2ff9cf0fd493f80fbMichal Zidek ret = sysdb_search_custom(tmp_ctx, domain, filter,
87f8bee53ee1b4ca87b602ff8536bc5fd5b5b595Lukas Slebodnik "Error looking up autofs map [%s]\n", safe_map_name);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "No such map\n");
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "More than one map named %s\n", safe_map_name);
e7d1cd14ce1a427007b1a7e9789dcb7e9619f84fJakub Hrozeksysdb_save_autofsentry(struct sss_domain_info *domain,
f17d26a8db285622a5cd5f21c7488b62eedc2cf8Jakub Hrozek const char *map,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek const char *key,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Adding autofs entry [%s] - [%s]\n", key, value);
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek ret = sysdb_attrs_add_string(attrs, SYSDB_OBJECTCLASS,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Could not set entry object class [%d]: %s\n",
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek ret = sysdb_attrs_add_string(attrs, SYSDB_AUTOFS_ENTRY_KEY, key);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Could not set entry key [%d]: %s\n",
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek ret = sysdb_attrs_add_string(attrs, SYSDB_AUTOFS_ENTRY_VALUE, value);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Could not set entry key [%d]: %s\n",
e75a152157e054a2ed46acecbe8b5cfb9853773cJakub Hrozek name = talloc_asprintf(tmp_ctx, "%s%s", key, value);
e75a152157e054a2ed46acecbe8b5cfb9853773cJakub Hrozek ret = sysdb_attrs_add_string(attrs, SYSDB_NAME, name);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Could not set name attribute [%d]: %s\n",
e7d1cd14ce1a427007b1a7e9789dcb7e9619f84fJakub Hrozek dn = sysdb_autofsentry_dn(tmp_ctx, domain, map, key, value);
e7d1cd14ce1a427007b1a7e9789dcb7e9619f84fJakub Hrozeksysdb_del_autofsentry(struct sss_domain_info *domain,
e7d1cd14ce1a427007b1a7e9789dcb7e9619f84fJakub Hrozek dn = ldb_dn_new(NULL, sysdb_ctx_get_ldb(domain->sysdb), entry_dn);
e7d1cd14ce1a427007b1a7e9789dcb7e9619f84fJakub Hrozek ret = sysdb_delete_entry(domain->sysdb, dn, true);
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozeksysdb_autofs_entries_by_map(TALLOC_CTX *mem_ctx,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek const char *attrs[] = { SYSDB_AUTOFS_ENTRY_KEY,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "Getting entries for map %s\n", mapname);
e7d1cd14ce1a427007b1a7e9789dcb7e9619f84fJakub Hrozek mapdn = sysdb_autofsmap_dn(tmp_ctx, domain, mapname);
f17d26a8db285622a5cd5f21c7488b62eedc2cf8Jakub Hrozek filter = talloc_asprintf(tmp_ctx, "(objectclass=%s)",
98195e591c4d97caa6125e8214879660b740973fSumit Bose ret = sysdb_search_entry(tmp_ctx, domain->sysdb, mapdn, LDB_SCOPE_SUBTREE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "sysdb search failed: %d\n", ret);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "No entries for the map\n");
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_INTERNAL, "found %zu entries for map %s\n",
e7d1cd14ce1a427007b1a7e9789dcb7e9619f84fJakub Hrozeksysdb_set_autofsmap_attr(struct sss_domain_info *domain,
eb29ae58117ca88868491fe2240e27393c7a9068Jakub Hrozek const char *name,
e7d1cd14ce1a427007b1a7e9789dcb7e9619f84fJakub Hrozek dn = sysdb_autofsmap_dn(tmp_ctx, domain, name);
e7d1cd14ce1a427007b1a7e9789dcb7e9619f84fJakub Hrozek ret = sysdb_set_entry_attr(domain->sysdb, dn, attrs, mod_op);
e7d1cd14ce1a427007b1a7e9789dcb7e9619f84fJakub Hrozeksysdb_invalidate_autofs_maps(struct sss_domain_info *domain)
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek filter = talloc_asprintf(tmp_ctx, "(&(objectclass=%s)(%s=*))",
d115f40c7a3999e3cbe705a2ff9cf0fd493f80fbMichal Zidek ret = sysdb_search_custom(tmp_ctx, domain, filter,
87f8bee53ee1b4ca87b602ff8536bc5fd5b5b595Lukas Slebodnik "Error looking up autofs maps\n");
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek ret = sysdb_attrs_add_time_t(sys_attrs, SYSDB_CACHE_EXPIRE, 1);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to start transaction\n");
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek for (i = 0; i < count; i++) {
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek name = ldb_msg_find_attr_as_string(msgs[i], SYSDB_NAME, NULL);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "A map with no name?\n");
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "Could not expire map %s\n", name);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Could not commit transaction\n");
e7d1cd14ce1a427007b1a7e9789dcb7e9619f84fJakub Hrozek sret = sysdb_transaction_cancel(domain->sysdb);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Could not cancel transaction\n");