1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek/*
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek Authors:
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek Jakub Hrozek <jhrozek@redhat.com>
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek Copyright (C) 2012 Red Hat
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
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
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
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/>.
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek*/
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek#include <talloc.h>
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek#include "db/sysdb.h"
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek#include "db/sysdb_private.h"
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek#include "db/sysdb_autofs.h"
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
f17d26a8db285622a5cd5f21c7488b62eedc2cf8Jakub Hrozek#define SYSDB_TMPL_AUTOFS_ENTRY SYSDB_NAME"=%s,"SYSDB_TMPL_CUSTOM
f17d26a8db285622a5cd5f21c7488b62eedc2cf8Jakub Hrozek
f17d26a8db285622a5cd5f21c7488b62eedc2cf8Jakub Hrozekstatic struct ldb_dn *
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozeksysdb_autofsmap_dn(TALLOC_CTX *mem_ctx,
2913240aee51ce81195148a4d814e967f66839c4Simo Sorce struct sss_domain_info *domain,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek const char *map_name)
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek{
e2ac9be4f293b96f3c8992f1171e44bc1da5cfcaMichal Zidek return sysdb_custom_dn(mem_ctx, domain, map_name, AUTOFS_MAP_SUBDIR);
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek}
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
f17d26a8db285622a5cd5f21c7488b62eedc2cf8Jakub Hrozekstatic struct ldb_dn *
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozeksysdb_autofsentry_dn(TALLOC_CTX *mem_ctx,
2913240aee51ce81195148a4d814e967f66839c4Simo Sorce struct sss_domain_info *domain,
f17d26a8db285622a5cd5f21c7488b62eedc2cf8Jakub Hrozek const char *map_name,
e75a152157e054a2ed46acecbe8b5cfb9853773cJakub Hrozek const char *entry_name,
e75a152157e054a2ed46acecbe8b5cfb9853773cJakub Hrozek const char *entry_value)
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek{
f17d26a8db285622a5cd5f21c7488b62eedc2cf8Jakub Hrozek errno_t ret;
e75a152157e054a2ed46acecbe8b5cfb9853773cJakub Hrozek TALLOC_CTX *tmp_ctx;
f17d26a8db285622a5cd5f21c7488b62eedc2cf8Jakub Hrozek char *clean_name;
e75a152157e054a2ed46acecbe8b5cfb9853773cJakub Hrozek char *clean_value;
e75a152157e054a2ed46acecbe8b5cfb9853773cJakub Hrozek const char *rdn;
e75a152157e054a2ed46acecbe8b5cfb9853773cJakub Hrozek struct ldb_dn *dn = NULL;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
e75a152157e054a2ed46acecbe8b5cfb9853773cJakub Hrozek tmp_ctx = talloc_new(NULL);
e75a152157e054a2ed46acecbe8b5cfb9853773cJakub Hrozek if (!tmp_ctx) {
f17d26a8db285622a5cd5f21c7488b62eedc2cf8Jakub Hrozek return NULL;
f17d26a8db285622a5cd5f21c7488b62eedc2cf8Jakub Hrozek }
f17d26a8db285622a5cd5f21c7488b62eedc2cf8Jakub Hrozek
e75a152157e054a2ed46acecbe8b5cfb9853773cJakub Hrozek ret = sysdb_dn_sanitize(tmp_ctx, entry_name, &clean_name);
e75a152157e054a2ed46acecbe8b5cfb9853773cJakub Hrozek if (ret != EOK) {
e75a152157e054a2ed46acecbe8b5cfb9853773cJakub Hrozek goto done;
e75a152157e054a2ed46acecbe8b5cfb9853773cJakub Hrozek }
e75a152157e054a2ed46acecbe8b5cfb9853773cJakub Hrozek
e75a152157e054a2ed46acecbe8b5cfb9853773cJakub Hrozek ret = sysdb_dn_sanitize(tmp_ctx, entry_value, &clean_value);
e75a152157e054a2ed46acecbe8b5cfb9853773cJakub Hrozek if (ret != EOK) {
e75a152157e054a2ed46acecbe8b5cfb9853773cJakub Hrozek goto done;
e75a152157e054a2ed46acecbe8b5cfb9853773cJakub Hrozek }
e75a152157e054a2ed46acecbe8b5cfb9853773cJakub Hrozek
e75a152157e054a2ed46acecbe8b5cfb9853773cJakub Hrozek rdn = talloc_asprintf(tmp_ctx, "%s%s", clean_name, clean_value);
e75a152157e054a2ed46acecbe8b5cfb9853773cJakub Hrozek if (!rdn) {
e75a152157e054a2ed46acecbe8b5cfb9853773cJakub Hrozek goto done;
e75a152157e054a2ed46acecbe8b5cfb9853773cJakub Hrozek }
e75a152157e054a2ed46acecbe8b5cfb9853773cJakub Hrozek
e7d1cd14ce1a427007b1a7e9789dcb7e9619f84fJakub Hrozek dn = ldb_dn_new_fmt(mem_ctx, domain->sysdb->ldb, SYSDB_TMPL_AUTOFS_ENTRY,
2913240aee51ce81195148a4d814e967f66839c4Simo Sorce rdn, map_name, AUTOFS_MAP_SUBDIR, domain->name);
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
e75a152157e054a2ed46acecbe8b5cfb9853773cJakub Hrozekdone:
e75a152157e054a2ed46acecbe8b5cfb9853773cJakub Hrozek talloc_free(tmp_ctx);
f17d26a8db285622a5cd5f21c7488b62eedc2cf8Jakub Hrozek return dn;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek}
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
2234d49c8a307ee4f11cc544c862a359f76b44adJakub Hrozekchar *
2234d49c8a307ee4f11cc544c862a359f76b44adJakub Hrozeksysdb_autofsentry_strdn(TALLOC_CTX *mem_ctx,
2234d49c8a307ee4f11cc544c862a359f76b44adJakub Hrozek struct sss_domain_info *domain,
2234d49c8a307ee4f11cc544c862a359f76b44adJakub Hrozek const char *map_name,
2234d49c8a307ee4f11cc544c862a359f76b44adJakub Hrozek const char *entry_name,
2234d49c8a307ee4f11cc544c862a359f76b44adJakub Hrozek const char *entry_value)
2234d49c8a307ee4f11cc544c862a359f76b44adJakub Hrozek{
2234d49c8a307ee4f11cc544c862a359f76b44adJakub Hrozek struct ldb_dn *dn;
2234d49c8a307ee4f11cc544c862a359f76b44adJakub Hrozek char *strdn;
2234d49c8a307ee4f11cc544c862a359f76b44adJakub Hrozek
e7d1cd14ce1a427007b1a7e9789dcb7e9619f84fJakub Hrozek dn = sysdb_autofsentry_dn(mem_ctx, domain,
2234d49c8a307ee4f11cc544c862a359f76b44adJakub Hrozek map_name, entry_name, entry_value);
2234d49c8a307ee4f11cc544c862a359f76b44adJakub Hrozek if (!dn) return NULL;
2234d49c8a307ee4f11cc544c862a359f76b44adJakub Hrozek
2234d49c8a307ee4f11cc544c862a359f76b44adJakub Hrozek strdn = talloc_strdup(mem_ctx, ldb_dn_get_linearized(dn));
2234d49c8a307ee4f11cc544c862a359f76b44adJakub Hrozek talloc_free(dn);
2234d49c8a307ee4f11cc544c862a359f76b44adJakub Hrozek return strdn;
2234d49c8a307ee4f11cc544c862a359f76b44adJakub Hrozek}
2234d49c8a307ee4f11cc544c862a359f76b44adJakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozekerrno_t
e7d1cd14ce1a427007b1a7e9789dcb7e9619f84fJakub Hrozeksysdb_save_autofsmap(struct sss_domain_info *domain,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek const char *name,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek const char *autofsmapname,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek struct sysdb_attrs *attrs,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek int cache_timeout,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek time_t now)
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek{
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek errno_t ret;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek TALLOC_CTX *tmp_ctx;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "Adding autofs map %s\n", autofsmapname);
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek tmp_ctx = talloc_new(NULL);
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek if (!tmp_ctx) {
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek return ENOMEM;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek }
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek if (!attrs) {
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek attrs = sysdb_new_attrs(tmp_ctx);
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek if (!attrs) {
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek ret = ENOMEM;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek goto done;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek }
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek }
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek ret = sysdb_attrs_add_string(attrs, SYSDB_OBJECTCLASS,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek SYSDB_AUTOFS_MAP_OC);
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Could not set map object class [%d]: %s\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret, strerror(ret));
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek goto done;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek }
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek ret = sysdb_attrs_add_string(attrs, SYSDB_AUTOFS_MAP_NAME, autofsmapname);
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Could not set map name [%d]: %s\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret, strerror(ret));
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek goto done;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek }
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek ret = sysdb_attrs_add_string(attrs, SYSDB_NAME, name);
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Could not set name attribute [%d]: %s\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret, strerror(ret));
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek goto done;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek }
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek ret = sysdb_attrs_add_time_t(attrs, SYSDB_LAST_UPDATE, now);
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek if (ret) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Could not set sysdb lastUpdate [%d]: %s\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret, strerror(ret));
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek goto done;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek }
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek ret = sysdb_attrs_add_time_t(attrs, SYSDB_CACHE_EXPIRE,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek ((cache_timeout) ?
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek (now + cache_timeout) : 0));
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek if (ret) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Could not set sysdb cache expire [%d]: %s\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret, strerror(ret));
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek goto done;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek }
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
d115f40c7a3999e3cbe705a2ff9cf0fd493f80fbMichal Zidek ret = sysdb_store_custom(domain, name, AUTOFS_MAP_SUBDIR, attrs);
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "sysdb_store_custom failed [%d]: %s\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret, strerror(ret));
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek goto done;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek }
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek ret = EOK;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozekdone:
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek talloc_free(tmp_ctx);
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek return ret;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek}
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozekerrno_t
e7d1cd14ce1a427007b1a7e9789dcb7e9619f84fJakub Hrozeksysdb_delete_autofsmap(struct sss_domain_info *domain,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek const char *name)
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek{
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}
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozekerrno_t
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozeksysdb_get_map_byname(TALLOC_CTX *mem_ctx,
2913240aee51ce81195148a4d814e967f66839c4Simo Sorce struct sss_domain_info *domain,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek const char *map_name,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek struct ldb_message **_map)
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek{
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek errno_t ret;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek TALLOC_CTX *tmp_ctx;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek const char *filter;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek char *safe_map_name;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek size_t count;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek struct ldb_message **msgs;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek const char *attrs[] = { SYSDB_OBJECTCLASS,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek SYSDB_CACHE_EXPIRE,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek SYSDB_LAST_UPDATE,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek SYSDB_AUTOFS_MAP_NAME,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek SYSDB_MEMBER,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek NULL };
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek tmp_ctx = talloc_new(NULL);
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek if (!tmp_ctx) return ENOMEM;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek ret = sss_filter_sanitize(tmp_ctx, map_name, &safe_map_name);
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek if (ret != EOK) {
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Cannot sanitize map [%s] error [%d]: %s\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov map_name, ret, strerror(ret));
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek goto done;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek }
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek filter = talloc_asprintf(tmp_ctx, "(&(objectclass=%s)(%s=%s))",
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek SYSDB_AUTOFS_MAP_OC, SYSDB_NAME, safe_map_name);
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek if (!filter) {
6ab9f4763b516c3a7cdc021f501f276dd805fc97Jakub Hrozek ret = ENOMEM;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek goto done;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek }
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
d115f40c7a3999e3cbe705a2ff9cf0fd493f80fbMichal Zidek ret = sysdb_search_custom(tmp_ctx, domain, filter,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek AUTOFS_MAP_SUBDIR, attrs,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek &count, &msgs);
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek if (ret != EOK && ret != ENOENT) {
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE,
87f8bee53ee1b4ca87b602ff8536bc5fd5b5b595Lukas Slebodnik "Error looking up autofs map [%s]\n", safe_map_name);
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek goto done;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek } else if (ret == ENOENT) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "No such map\n");
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek *_map = NULL;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek goto done;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek }
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek if (count != 1) {
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "More than one map named %s\n", safe_map_name);
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek goto done;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek }
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek *_map = talloc_steal(mem_ctx, msgs[0]);
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek ret = EOK;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozekdone:
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek talloc_free(tmp_ctx);
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek return ret;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek}
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozekerrno_t
e7d1cd14ce1a427007b1a7e9789dcb7e9619f84fJakub Hrozeksysdb_save_autofsentry(struct sss_domain_info *domain,
f17d26a8db285622a5cd5f21c7488b62eedc2cf8Jakub Hrozek const char *map,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek const char *key,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek const char *value,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek struct sysdb_attrs *attrs)
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek{
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek errno_t ret;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek TALLOC_CTX *tmp_ctx;
f17d26a8db285622a5cd5f21c7488b62eedc2cf8Jakub Hrozek struct ldb_message *msg;
f17d26a8db285622a5cd5f21c7488b62eedc2cf8Jakub Hrozek struct ldb_dn *dn;
e75a152157e054a2ed46acecbe8b5cfb9853773cJakub Hrozek const char *name;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek DEBUG(SSSDBG_TRACE_FUNC,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Adding autofs entry [%s] - [%s]\n", key, value);
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek tmp_ctx = talloc_new(NULL);
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek if (!tmp_ctx) {
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek return ENOMEM;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek }
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek if (!attrs) {
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek attrs = sysdb_new_attrs(tmp_ctx);
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek if (!attrs) {
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek ret = ENOMEM;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek goto done;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek }
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek }
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek ret = sysdb_attrs_add_string(attrs, SYSDB_OBJECTCLASS,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek SYSDB_AUTOFS_ENTRY_OC);
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Could not set entry object class [%d]: %s\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret, strerror(ret));
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek goto done;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek }
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek ret = sysdb_attrs_add_string(attrs, SYSDB_AUTOFS_ENTRY_KEY, key);
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Could not set entry key [%d]: %s\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret, strerror(ret));
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek goto done;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek }
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek ret = sysdb_attrs_add_string(attrs, SYSDB_AUTOFS_ENTRY_VALUE, value);
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Could not set entry key [%d]: %s\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret, strerror(ret));
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek goto done;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek }
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
e75a152157e054a2ed46acecbe8b5cfb9853773cJakub Hrozek name = talloc_asprintf(tmp_ctx, "%s%s", key, value);
e75a152157e054a2ed46acecbe8b5cfb9853773cJakub Hrozek if (!name) {
e75a152157e054a2ed46acecbe8b5cfb9853773cJakub Hrozek ret = ENOMEM;
e75a152157e054a2ed46acecbe8b5cfb9853773cJakub Hrozek goto done;
e75a152157e054a2ed46acecbe8b5cfb9853773cJakub Hrozek }
e75a152157e054a2ed46acecbe8b5cfb9853773cJakub Hrozek
e75a152157e054a2ed46acecbe8b5cfb9853773cJakub Hrozek ret = sysdb_attrs_add_string(attrs, SYSDB_NAME, name);
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Could not set name attribute [%d]: %s\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret, strerror(ret));
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek goto done;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek }
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
e7d1cd14ce1a427007b1a7e9789dcb7e9619f84fJakub Hrozek dn = sysdb_autofsentry_dn(tmp_ctx, domain, map, key, value);
f17d26a8db285622a5cd5f21c7488b62eedc2cf8Jakub Hrozek if (!dn) {
f17d26a8db285622a5cd5f21c7488b62eedc2cf8Jakub Hrozek ret = ENOMEM;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek goto done;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek }
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
f17d26a8db285622a5cd5f21c7488b62eedc2cf8Jakub Hrozek msg = ldb_msg_new(tmp_ctx);
f17d26a8db285622a5cd5f21c7488b62eedc2cf8Jakub Hrozek if (!msg) {
f17d26a8db285622a5cd5f21c7488b62eedc2cf8Jakub Hrozek ret = ENOMEM;
f17d26a8db285622a5cd5f21c7488b62eedc2cf8Jakub Hrozek goto done;
f17d26a8db285622a5cd5f21c7488b62eedc2cf8Jakub Hrozek }
f17d26a8db285622a5cd5f21c7488b62eedc2cf8Jakub Hrozek
f17d26a8db285622a5cd5f21c7488b62eedc2cf8Jakub Hrozek msg->dn = dn;
f17d26a8db285622a5cd5f21c7488b62eedc2cf8Jakub Hrozek msg->elements = attrs->a;
f17d26a8db285622a5cd5f21c7488b62eedc2cf8Jakub Hrozek msg->num_elements = attrs->num;
f17d26a8db285622a5cd5f21c7488b62eedc2cf8Jakub Hrozek
e7d1cd14ce1a427007b1a7e9789dcb7e9619f84fJakub Hrozek ret = ldb_add(domain->sysdb->ldb, msg);
f17d26a8db285622a5cd5f21c7488b62eedc2cf8Jakub Hrozek ret = sysdb_error_to_errno(ret);
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozekdone:
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek talloc_free(tmp_ctx);
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek return ret;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek}
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
f17d26a8db285622a5cd5f21c7488b62eedc2cf8Jakub Hrozekerrno_t
e7d1cd14ce1a427007b1a7e9789dcb7e9619f84fJakub Hrozeksysdb_del_autofsentry(struct sss_domain_info *domain,
2234d49c8a307ee4f11cc544c862a359f76b44adJakub Hrozek const char *entry_dn)
f17d26a8db285622a5cd5f21c7488b62eedc2cf8Jakub Hrozek{
f17d26a8db285622a5cd5f21c7488b62eedc2cf8Jakub Hrozek struct ldb_dn *dn;
f17d26a8db285622a5cd5f21c7488b62eedc2cf8Jakub Hrozek errno_t ret;
f17d26a8db285622a5cd5f21c7488b62eedc2cf8Jakub Hrozek
e7d1cd14ce1a427007b1a7e9789dcb7e9619f84fJakub Hrozek dn = ldb_dn_new(NULL, sysdb_ctx_get_ldb(domain->sysdb), entry_dn);
f17d26a8db285622a5cd5f21c7488b62eedc2cf8Jakub Hrozek if (!dn) {
f17d26a8db285622a5cd5f21c7488b62eedc2cf8Jakub Hrozek return ENOMEM;
f17d26a8db285622a5cd5f21c7488b62eedc2cf8Jakub Hrozek }
f17d26a8db285622a5cd5f21c7488b62eedc2cf8Jakub Hrozek
e7d1cd14ce1a427007b1a7e9789dcb7e9619f84fJakub Hrozek ret = sysdb_delete_entry(domain->sysdb, dn, true);
f17d26a8db285622a5cd5f21c7488b62eedc2cf8Jakub Hrozek talloc_free(dn);
f17d26a8db285622a5cd5f21c7488b62eedc2cf8Jakub Hrozek return ret;
f17d26a8db285622a5cd5f21c7488b62eedc2cf8Jakub Hrozek}
f17d26a8db285622a5cd5f21c7488b62eedc2cf8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozekerrno_t
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozeksysdb_autofs_entries_by_map(TALLOC_CTX *mem_ctx,
2913240aee51ce81195148a4d814e967f66839c4Simo Sorce struct sss_domain_info *domain,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek const char *mapname,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek size_t *_count,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek struct ldb_message ***_entries)
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek{
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek errno_t ret;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek TALLOC_CTX *tmp_ctx;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek char *filter;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek const char *attrs[] = { SYSDB_AUTOFS_ENTRY_KEY,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek SYSDB_AUTOFS_ENTRY_VALUE,
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek NULL };
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek size_t count;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek struct ldb_message **msgs;
f17d26a8db285622a5cd5f21c7488b62eedc2cf8Jakub Hrozek struct ldb_dn *mapdn;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "Getting entries for map %s\n", mapname);
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek tmp_ctx = talloc_new(NULL);
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek if (!tmp_ctx) {
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek return ENOMEM;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek }
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
e7d1cd14ce1a427007b1a7e9789dcb7e9619f84fJakub Hrozek mapdn = sysdb_autofsmap_dn(tmp_ctx, domain, mapname);
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek if (!mapdn) {
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek ret = ENOMEM;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek goto done;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek }
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
f17d26a8db285622a5cd5f21c7488b62eedc2cf8Jakub Hrozek filter = talloc_asprintf(tmp_ctx, "(objectclass=%s)",
f17d26a8db285622a5cd5f21c7488b62eedc2cf8Jakub Hrozek SYSDB_AUTOFS_ENTRY_OC);
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek if (!filter) {
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek ret = ENOMEM;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek goto done;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek }
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
98195e591c4d97caa6125e8214879660b740973fSumit Bose ret = sysdb_search_entry(tmp_ctx, domain->sysdb, mapdn, LDB_SCOPE_SUBTREE,
f17d26a8db285622a5cd5f21c7488b62eedc2cf8Jakub Hrozek filter, attrs, &count, &msgs);
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek if (ret != EOK && ret != ENOENT) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "sysdb search failed: %d\n", ret);
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek goto done;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek } else if (ret == ENOENT) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "No entries for the map\n");
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek *_count = 0;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek *_entries = NULL;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek goto done;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek }
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek *_count = count;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek *_entries = talloc_steal(mem_ctx, msgs);
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek ret = EOK;
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_INTERNAL, "found %zu entries for map %s\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov count, mapname);
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozekdone:
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek talloc_free(tmp_ctx);
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek return ret;
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek}
1f1e6cbc59868f06dee3ab4b3df660fcb77ce1c8Jakub Hrozek
eb29ae58117ca88868491fe2240e27393c7a9068Jakub Hrozekerrno_t
e7d1cd14ce1a427007b1a7e9789dcb7e9619f84fJakub Hrozeksysdb_set_autofsmap_attr(struct sss_domain_info *domain,
eb29ae58117ca88868491fe2240e27393c7a9068Jakub Hrozek const char *name,
eb29ae58117ca88868491fe2240e27393c7a9068Jakub Hrozek struct sysdb_attrs *attrs,
eb29ae58117ca88868491fe2240e27393c7a9068Jakub Hrozek int mod_op)
eb29ae58117ca88868491fe2240e27393c7a9068Jakub Hrozek{
eb29ae58117ca88868491fe2240e27393c7a9068Jakub Hrozek errno_t ret;
eb29ae58117ca88868491fe2240e27393c7a9068Jakub Hrozek struct ldb_dn *dn;
eb29ae58117ca88868491fe2240e27393c7a9068Jakub Hrozek TALLOC_CTX *tmp_ctx;
eb29ae58117ca88868491fe2240e27393c7a9068Jakub Hrozek
eb29ae58117ca88868491fe2240e27393c7a9068Jakub Hrozek tmp_ctx = talloc_new(NULL);
eb29ae58117ca88868491fe2240e27393c7a9068Jakub Hrozek if (!tmp_ctx) {
eb29ae58117ca88868491fe2240e27393c7a9068Jakub Hrozek return ENOMEM;
eb29ae58117ca88868491fe2240e27393c7a9068Jakub Hrozek }
eb29ae58117ca88868491fe2240e27393c7a9068Jakub Hrozek
e7d1cd14ce1a427007b1a7e9789dcb7e9619f84fJakub Hrozek dn = sysdb_autofsmap_dn(tmp_ctx, domain, name);
eb29ae58117ca88868491fe2240e27393c7a9068Jakub Hrozek if (!dn) {
eb29ae58117ca88868491fe2240e27393c7a9068Jakub Hrozek ret = ENOMEM;
eb29ae58117ca88868491fe2240e27393c7a9068Jakub Hrozek goto done;
eb29ae58117ca88868491fe2240e27393c7a9068Jakub Hrozek }
eb29ae58117ca88868491fe2240e27393c7a9068Jakub Hrozek
e7d1cd14ce1a427007b1a7e9789dcb7e9619f84fJakub Hrozek ret = sysdb_set_entry_attr(domain->sysdb, dn, attrs, mod_op);
eb29ae58117ca88868491fe2240e27393c7a9068Jakub Hrozek
eb29ae58117ca88868491fe2240e27393c7a9068Jakub Hrozekdone:
eb29ae58117ca88868491fe2240e27393c7a9068Jakub Hrozek talloc_free(tmp_ctx);
eb29ae58117ca88868491fe2240e27393c7a9068Jakub Hrozek return ret;
eb29ae58117ca88868491fe2240e27393c7a9068Jakub Hrozek}
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozekerrno_t
e7d1cd14ce1a427007b1a7e9789dcb7e9619f84fJakub Hrozeksysdb_invalidate_autofs_maps(struct sss_domain_info *domain)
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek{
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek errno_t ret;
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek TALLOC_CTX *tmp_ctx;
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek const char *filter;
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek struct sysdb_attrs *sys_attrs = NULL;
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek const char *attrs[] = { SYSDB_OBJECTCLASS,
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek SYSDB_NAME,
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek SYSDB_CACHE_EXPIRE,
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek NULL };
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek size_t count;
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek struct ldb_message **msgs;
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek const char *name;
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek bool in_transaction = false;
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek int sret;
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek int i;
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek tmp_ctx = talloc_new(NULL);
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek if (!tmp_ctx) return ENOMEM;
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek filter = talloc_asprintf(tmp_ctx, "(&(objectclass=%s)(%s=*))",
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek SYSDB_AUTOFS_MAP_OC, SYSDB_NAME);
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek if (!filter) {
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek ret = ENOMEM;
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek goto done;
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek }
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek
d115f40c7a3999e3cbe705a2ff9cf0fd493f80fbMichal Zidek ret = sysdb_search_custom(tmp_ctx, domain, filter,
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek AUTOFS_MAP_SUBDIR, attrs,
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek &count, &msgs);
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek if (ret != EOK && ret != ENOENT) {
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE,
87f8bee53ee1b4ca87b602ff8536bc5fd5b5b595Lukas Slebodnik "Error looking up autofs maps\n");
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek goto done;
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek } else if (ret == ENOENT) {
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek ret = EOK;
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek goto done;
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek }
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek sys_attrs = sysdb_new_attrs(tmp_ctx);
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek if (!sys_attrs) {
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek ret = ENOMEM;
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek goto done;
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek }
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek ret = sysdb_attrs_add_time_t(sys_attrs, SYSDB_CACHE_EXPIRE, 1);
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek if (ret != EOK) {
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek goto done;
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek }
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek
e7d1cd14ce1a427007b1a7e9789dcb7e9619f84fJakub Hrozek ret = sysdb_transaction_start(domain->sysdb);
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Failed to start transaction\n");
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek goto done;
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek }
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek in_transaction = true;
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek for (i = 0; i < count; i++) {
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek name = ldb_msg_find_attr_as_string(msgs[i], SYSDB_NAME, NULL);
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek if (!name) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "A map with no name?\n");
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek continue;
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek }
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek
e7d1cd14ce1a427007b1a7e9789dcb7e9619f84fJakub Hrozek ret = sysdb_set_autofsmap_attr(domain, name,
2913240aee51ce81195148a4d814e967f66839c4Simo Sorce sys_attrs, SYSDB_MOD_REP);
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "Could not expire map %s\n", name);
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek continue;
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek }
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek }
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek
e7d1cd14ce1a427007b1a7e9789dcb7e9619f84fJakub Hrozek ret = sysdb_transaction_commit(domain->sysdb);
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Could not commit transaction\n");
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek goto done;
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek }
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek in_transaction = false;
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek ret = EOK;
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozekdone:
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek if (in_transaction) {
e7d1cd14ce1a427007b1a7e9789dcb7e9619f84fJakub Hrozek sret = sysdb_transaction_cancel(domain->sysdb);
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek if (sret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Could not cancel transaction\n");
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek }
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek }
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek talloc_free(tmp_ctx);
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek return ret;
ba153306e0e551731a3ee2c31c26cd1d63052ff8Jakub Hrozek}