cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek/*
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek SSSD
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek LDAP handler for autofs
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek Authors:
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek Jakub Hrozek <jhrozek@redhat.com>
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek Copyright (C) 2012 Red Hat
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek This program is free software; you can redistribute it and/or modify
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek it under the terms of the GNU General Public License as published by
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek the Free Software Foundation; either version 3 of the License, or
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek (at your option) any later version.
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek This program is distributed in the hope that it will be useful,
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek but WITHOUT ANY WARRANTY; without even the implied warranty of
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek GNU General Public License for more details.
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek You should have received a copy of the GNU General Public License
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek along with this program. If not, see <http://www.gnu.org/licenses/>.
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek*/
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek#include <errno.h>
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek#include <tevent.h>
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek#include "providers/ldap/ldap_common.h"
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek#include "providers/ldap/sdap_autofs.h"
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek#include "providers/ldap/sdap.h"
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek#include "providers/ldap/sdap_async.h"
cc2d77d5218c188119fa954c856e858cbde76947Pavel Březina#include "providers/backend.h"
407123c67114bf010cdad4418f291f9fb3762f4aCove Schneider#include "providers/data_provider.h"
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek#include "db/sysdb_autofs.h"
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek#include "util/util.h"
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozekstruct autofs_get_map_state {
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek struct tevent_context *ev;
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek struct sdap_id_ctx *ctx;
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek struct sdap_id_op *op;
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek const char *map_name;
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek int dp_error;
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek};
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozekstatic errno_t
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozeksdap_autofs_get_map_retry(struct tevent_req *req);
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozekstatic void
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozeksdap_autofs_get_map_connect_done(struct tevent_req *subreq);
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozekstatic void
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozeksdap_autofs_get_map_done(struct tevent_req *req);
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozekstatic struct tevent_req *
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozeksdap_autofs_get_map_send(TALLOC_CTX *mem_ctx,
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek struct tevent_context *ev,
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek struct sdap_id_ctx *ctx,
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek const char *map_name)
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek{
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek struct tevent_req *req;
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek struct autofs_get_map_state *state;
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek int ret;
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek req = tevent_req_create(mem_ctx, &state, struct autofs_get_map_state);
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek if (!req) return NULL;
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek state->ev = ev;
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek state->ctx = ctx;
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek state->dp_error = DP_ERR_FATAL;
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek state->map_name = map_name;
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek
dcb44c39dda9699cdd6488fd116a51ced0687de3Jakub Hrozek state->op = sdap_id_op_create(state, state->ctx->conn->conn_cache);
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek if (!state->op) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "sdap_id_op_create failed\n");
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek ret = ENOMEM;
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek goto fail;
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek }
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek ret = sdap_autofs_get_map_retry(req);
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek if (ret != EOK) {
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek goto fail;
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek }
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek return req;
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozekfail:
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek tevent_req_error(req, ret);
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek tevent_req_post(req, ev);
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek return req;
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek}
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozekstatic errno_t
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozeksdap_autofs_get_map_retry(struct tevent_req *req)
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek{
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek struct autofs_get_map_state *state =
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek tevent_req_data(req, struct autofs_get_map_state);
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek struct tevent_req *subreq;
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek int ret = EOK;
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek subreq = sdap_id_op_connect_send(state->op, state, &ret);
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek if (!subreq) {
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek return ret;
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek }
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek tevent_req_set_callback(subreq, sdap_autofs_get_map_connect_done, req);
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek return EOK;
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek}
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozekstatic void
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozeksdap_autofs_get_map_connect_done(struct tevent_req *subreq)
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek{
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek struct tevent_req *req = tevent_req_callback_data(subreq,
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek struct tevent_req);
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek struct autofs_get_map_state *state =
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek tevent_req_data(req, struct autofs_get_map_state);
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek int dp_error = DP_ERR_FATAL;
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek int ret;
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek ret = sdap_id_op_connect_recv(subreq, &dp_error);
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek talloc_zfree(subreq);
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek if (ret != EOK) {
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek state->dp_error = dp_error;
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek tevent_req_error(req, ret);
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek return;
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek }
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek subreq = sdap_autofs_setautomntent_send(state, state->ev,
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek state->ctx->be->domain,
df0596ec12bc5091608371e2977f3111241e8cafSimo Sorce state->ctx->be->domain->sysdb,
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek sdap_id_op_handle(state->op),
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek state->op,
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek state->ctx->opts,
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek state->map_name);
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek if (!subreq) {
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "sdap_autofs_setautomntent_send failed\n");
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek tevent_req_error(req, ENOMEM);
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek return;
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek }
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek tevent_req_set_callback(subreq, sdap_autofs_get_map_done, req);
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek}
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozekstatic void
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozeksdap_autofs_get_map_done(struct tevent_req *subreq)
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek{
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek struct tevent_req *req = tevent_req_callback_data(subreq,
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek struct tevent_req);
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek struct autofs_get_map_state *state =
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek tevent_req_data(req, struct autofs_get_map_state);
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek int dp_error = DP_ERR_FATAL;
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek int ret;
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek ret = sdap_autofs_setautomntent_recv(subreq);
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek talloc_zfree(subreq);
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek ret = sdap_id_op_done(state->op, ret, &dp_error);
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek if (dp_error == DP_ERR_OK && ret != EOK) {
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek /* retry */
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek ret = sdap_autofs_get_map_retry(req);
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek if (ret != EOK) {
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek tevent_req_error(req, ret);
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek return;
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek }
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek return;
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek }
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek if (ret && ret != ENOENT) {
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek state->dp_error = dp_error;
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek tevent_req_error(req, ret);
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek return;
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek }
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek if (ret == ENOENT) {
e7d1cd14ce1a427007b1a7e9789dcb7e9619f84fJakub Hrozek ret = sysdb_delete_autofsmap(state->ctx->be->domain, state->map_name);
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek if (ret != EOK && ret != ENOENT) {
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Cannot delete autofs map %s [%d]: %s\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov state->map_name, ret, strerror(ret));
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek tevent_req_error(req, ret);
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek return;
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek }
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek }
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek state->dp_error = DP_ERR_OK;
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek tevent_req_done(req);
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek}
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozekstatic errno_t
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozeksdap_autofs_get_map_recv(struct tevent_req *req, int *dp_error_out)
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek{
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek struct autofs_get_map_state *state =
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek tevent_req_data(req, struct autofs_get_map_state);
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek if (dp_error_out) {
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek *dp_error_out = state->dp_error;
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek }
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek TEVENT_REQ_RETURN_ON_ERROR(req);
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek return EOK;
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek}
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březinastruct sdap_autofs_handler_state {
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct dp_reply_std reply;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina};
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březinastatic void sdap_autofs_handler_done(struct tevent_req *subreq);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březinastruct tevent_req *
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březinasdap_autofs_handler_send(TALLOC_CTX *mem_ctx,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct sdap_id_ctx *id_ctx,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct dp_autofs_data *data,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct dp_req_params *params)
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek{
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct sdap_autofs_handler_state *state;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct tevent_req *subreq;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct tevent_req *req;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina const char *master_map;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek errno_t ret;
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina req = tevent_req_create(mem_ctx, &state, struct sdap_autofs_handler_state);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina if (req == NULL) {
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "tevent_req_create() failed\n");
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina return NULL;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina }
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina DEBUG(SSSDBG_FUNC_DATA, "Requested refresh for: %s\n", data->mapname);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina master_map = dp_opt_get_string(id_ctx->opts->basic,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina SDAP_AUTOFS_MAP_MASTER_NAME);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina if (strcmp(master_map, data->mapname) == 0) {
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina DEBUG(SSSDBG_FUNC_DATA, "Refresh of automount master map triggered: "
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina "%s\n", data->mapname);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina ret = sysdb_invalidate_autofs_maps(id_ctx->be->domain);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina if (ret != EOK) {
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina DEBUG(SSSDBG_MINOR_FAILURE, "Could not invalidate autofs maps, "
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina "backend might return stale entries\n");
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina }
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina }
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina subreq = sdap_autofs_get_map_send(mem_ctx, params->ev,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina id_ctx, data->mapname);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina if (subreq == NULL) {
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina DEBUG(SSSDBG_CRIT_FAILURE, "Unable to send request for %s.\n",
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina data->mapname);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina ret = ENOMEM;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina goto immediately;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina }
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina tevent_req_set_callback(subreq, sdap_autofs_handler_done, req);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina return req;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březinaimmediately:
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina dp_reply_std_set(&state->reply, DP_ERR_DECIDE, ret, NULL);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina /* TODO For backward compatibility we always return EOK to DP now. */
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina tevent_req_done(req);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina tevent_req_post(req, params->ev);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina return req;
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek}
cc84fd46f356c4a36a721ab135a33ec77c93e34dJakub Hrozek
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březinastatic void sdap_autofs_handler_done(struct tevent_req *subreq)
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina{
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct sdap_autofs_handler_state *state;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct tevent_req *req;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina int dp_error;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina errno_t ret;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina req = tevent_req_callback_data(subreq, struct tevent_req);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina state = tevent_req_data(req, struct sdap_autofs_handler_state);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina ret = sdap_autofs_get_map_recv(subreq, &dp_error);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina talloc_zfree(subreq);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina /* TODO For backward compatibility we always return EOK to DP now. */
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina dp_reply_std_set(&state->reply, dp_error, ret, NULL);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina tevent_req_done(req);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina}
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březinaerrno_t
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březinasdap_autofs_handler_recv(TALLOC_CTX *mem_ctx,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct tevent_req *req,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct dp_reply_std *data)
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina{
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct sdap_autofs_handler_state *state = NULL;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina state = tevent_req_data(req, struct sdap_autofs_handler_state);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina TEVENT_REQ_RETURN_ON_ERROR(req);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina *data = state->reply;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina return EOK;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina}
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březinaerrno_t sdap_autofs_init(TALLOC_CTX *mem_ctx,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct be_ctx *be_ctx,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct sdap_id_ctx *id_ctx,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct dp_method *dp_methods)
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina{
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina errno_t ret;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina DEBUG(SSSDBG_TRACE_INTERNAL, "Initializing autofs LDAP back end\n");
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina ret = ldap_get_autofs_options(id_ctx, be_ctx->cdb, be_ctx->conf_path,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina id_ctx->opts);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina if (ret != EOK) {
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina return ret;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina }
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina dp_set_method(dp_methods, DPM_AUTOFS_HANDLER,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina sdap_autofs_handler_send, sdap_autofs_handler_recv, id_ctx,
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina struct sdap_id_ctx, struct dp_autofs_data, struct dp_reply_std);
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina return EOK;
dea636af4d1902a081ee891f1b19ee2f8729d759Pavel Březina}