autofssrv_cmd.c revision 5dfb1257f62839eea1c31669cf3bbcb114c22183
eac684ef1c29684b1bcd27a89c38c202e568e469Tom Gundersen/*
eac684ef1c29684b1bcd27a89c38c202e568e469Tom Gundersen Authors:
12b42c76672a66c2d4ea7212c14f8f1b5a62b78dTom Gundersen Jakub Hrozek <jhrozek@redhat.com>
eac684ef1c29684b1bcd27a89c38c202e568e469Tom Gundersen
eac684ef1c29684b1bcd27a89c38c202e568e469Tom Gundersen Copyright (C) 2012 Red Hat
eac684ef1c29684b1bcd27a89c38c202e568e469Tom Gundersen
eac684ef1c29684b1bcd27a89c38c202e568e469Tom Gundersen Autofs responder: commands
eac684ef1c29684b1bcd27a89c38c202e568e469Tom Gundersen
eac684ef1c29684b1bcd27a89c38c202e568e469Tom Gundersen This program is free software; you can redistribute it and/or modify
eac684ef1c29684b1bcd27a89c38c202e568e469Tom Gundersen it under the terms of the GNU General Public License as published by
eac684ef1c29684b1bcd27a89c38c202e568e469Tom Gundersen the Free Software Foundation; either version 3 of the License, or
eac684ef1c29684b1bcd27a89c38c202e568e469Tom Gundersen (at your option) any later version.
eac684ef1c29684b1bcd27a89c38c202e568e469Tom Gundersen
eac684ef1c29684b1bcd27a89c38c202e568e469Tom Gundersen This program is distributed in the hope that it will be useful,
eac684ef1c29684b1bcd27a89c38c202e568e469Tom Gundersen but WITHOUT ANY WARRANTY; without even the implied warranty of
eac684ef1c29684b1bcd27a89c38c202e568e469Tom Gundersen MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
eac684ef1c29684b1bcd27a89c38c202e568e469Tom Gundersen GNU General Public License for more details.
eac684ef1c29684b1bcd27a89c38c202e568e469Tom Gundersen
eac684ef1c29684b1bcd27a89c38c202e568e469Tom Gundersen You should have received a copy of the GNU General Public License
eac684ef1c29684b1bcd27a89c38c202e568e469Tom Gundersen along with this program. If not, see <http://www.gnu.org/licenses/>.
eac684ef1c29684b1bcd27a89c38c202e568e469Tom Gundersen*/
eac684ef1c29684b1bcd27a89c38c202e568e469Tom Gundersen
eac684ef1c29684b1bcd27a89c38c202e568e469Tom Gundersen#include <talloc.h>
eac684ef1c29684b1bcd27a89c38c202e568e469Tom Gundersen
eac684ef1c29684b1bcd27a89c38c202e568e469Tom Gundersen#include "util/util.h"
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek#include "responder/common/responder.h"
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek#include "responder/common/responder_packet.h"
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek#include "responder/autofs/autofs_private.h"
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek#include "db/sysdb.h"
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek#include "db/sysdb_autofs.h"
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek#include "confdb/confdb.h"
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmekstatic int autofs_cmd_send_error(struct autofs_cmd_ctx *cmdctx, int err)
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek{
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek return sss_cmd_send_error(cmdctx->cctx, err);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek}
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmekstatic int
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmekautofs_cmd_send_empty(struct autofs_cmd_ctx *cmdctx)
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek{
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek return sss_cmd_send_empty(cmdctx->cctx, cmdctx);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek}
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmekstatic int
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmekautofs_cmd_done(struct autofs_cmd_ctx *cmdctx, int ret)
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek{
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek switch (ret) {
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek case EOK:
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek /* all fine, just return here */
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek break;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek case ENOENT:
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek ret = autofs_cmd_send_empty(cmdctx);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek if (ret) {
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek return EFAULT;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek }
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek break;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek case EAGAIN:
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek /* async processing, just return here */
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek break;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek case EFAULT:
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek /* very bad error */
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek return EFAULT;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
12b42c76672a66c2d4ea7212c14f8f1b5a62b78dTom Gundersen default:
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek ret = autofs_cmd_send_error(cmdctx, ret);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek if (ret) {
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek return EFAULT;
12b42c76672a66c2d4ea7212c14f8f1b5a62b78dTom Gundersen }
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek sss_cmd_done(cmdctx->cctx, cmdctx);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek break;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek }
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek return EOK;
12b42c76672a66c2d4ea7212c14f8f1b5a62b78dTom Gundersen}
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmekstatic errno_t
12b42c76672a66c2d4ea7212c14f8f1b5a62b78dTom Gundersenautofs_setent_add_ref(TALLOC_CTX *memctx,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek struct autofs_map_ctx *map_ctx,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek struct tevent_req *req)
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek{
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek return setent_add_ref(memctx, map_ctx, &map_ctx->reqs, req);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek}
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmekstatic void
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmekautofs_setent_notify(struct autofs_map_ctx *map_ctx, errno_t ret)
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek{
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek setent_notify(&map_ctx->reqs, ret);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek}
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmekstatic errno_t
a22e1850c36e52cb9d593b99be59b6ba7639d80aLennart Poetteringget_autofs_map(struct autofs_ctx *actx,
a22e1850c36e52cb9d593b99be59b6ba7639d80aLennart Poettering char *mapname,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek struct autofs_map_ctx **map)
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek{
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek hash_key_t key;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek hash_value_t value;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek int hret;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek key.type = HASH_KEY_STRING;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek key.str = mapname;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek hret = hash_lookup(actx->maps, &key, &value);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek if (hret == HASH_SUCCESS) {
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek *map = talloc_get_type(value.ptr, struct autofs_map_ctx);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek return EOK;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek } else if (hret == HASH_ERROR_KEY_NOT_FOUND) {
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek return ENOENT;
5256e00e8b9015dd1a976d647fc71dc7efbd8cf8Tom Gundersen }
5256e00e8b9015dd1a976d647fc71dc7efbd8cf8Tom Gundersen
5256e00e8b9015dd1a976d647fc71dc7efbd8cf8Tom Gundersen DEBUG(SSSDBG_CRIT_FAILURE,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek ("Unexpected error reading from autofs map hash [%d][%s]\n",
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek hret, hash_error_string(hret)));
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek return EIO;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek}
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
5256e00e8b9015dd1a976d647fc71dc7efbd8cf8Tom Gundersenstatic int autofs_map_hash_remove (TALLOC_CTX *ctx);
5256e00e8b9015dd1a976d647fc71dc7efbd8cf8Tom Gundersen
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmekstatic errno_t
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmekset_autofs_map(struct autofs_ctx *actx,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek struct autofs_map_ctx *map)
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek{
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek hash_key_t key;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek hash_value_t value;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek int hret;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek if (map->mapname == NULL) {
5256e00e8b9015dd1a976d647fc71dc7efbd8cf8Tom Gundersen DEBUG(SSSDBG_CRIT_FAILURE, ("Missing autofs map name.\n"));
5256e00e8b9015dd1a976d647fc71dc7efbd8cf8Tom Gundersen return EINVAL;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek }
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek /* Add this entry to the hash table */
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek key.type = HASH_KEY_STRING;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek key.str = map->mapname;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek value.type = HASH_VALUE_PTR;
5256e00e8b9015dd1a976d647fc71dc7efbd8cf8Tom Gundersen value.ptr = map;
5256e00e8b9015dd1a976d647fc71dc7efbd8cf8Tom Gundersen hret = hash_enter(actx->maps, &key, &value);
5256e00e8b9015dd1a976d647fc71dc7efbd8cf8Tom Gundersen if (hret != EOK) {
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek DEBUG(SSSDBG_CRIT_FAILURE,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek ("Unable to add hash table entry for [%s]", key.str));
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek DEBUG(SSSDBG_MINOR_FAILURE,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek ("Hash error [%d][%s]", hret, hash_error_string(hret)));
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek return EIO;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek }
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek talloc_steal(actx->maps, map);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek talloc_set_destructor((TALLOC_CTX *) map, autofs_map_hash_remove);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek return EOK;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek}
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmekstatic int
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmekautofs_map_hash_remove(TALLOC_CTX *ctx)
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek{
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek int hret;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek hash_key_t key;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek struct autofs_map_ctx *map =
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek talloc_get_type(ctx, struct autofs_map_ctx);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek key.type = HASH_KEY_STRING;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek key.str = map->mapname;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek /* Remove the autofs map result object from the lookup table */
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek hret = hash_delete(map->map_table, &key);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek if (hret != HASH_SUCCESS) {
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek DEBUG(SSSDBG_CRIT_FAILURE,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek ("Could not remove key from table! [%d][%s]\n",
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek hret, hash_error_string(hret)));
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek return -1;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek }
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek return 0;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek}
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmekstatic struct tevent_req *
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmeksetautomntent_send(TALLOC_CTX *mem_ctx,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek const char *rawname,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek struct autofs_cmd_ctx *cmdctx);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmekstatic errno_t setautomntent_recv(struct tevent_req *req);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmekstatic void sss_autofs_cmd_setautomntent_done(struct tevent_req *req);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek/* FIXME - file a ticket to have per-responder private
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek * data instead of growing the cli_ctx structure */
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmekstatic int
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmeksss_autofs_cmd_setautomntent(struct cli_ctx *client)
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek{
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek struct autofs_cmd_ctx *cmdctx;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek uint8_t *body;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek size_t blen;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek errno_t ret = EOK;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek const char *rawname;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek struct tevent_req *req;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek DEBUG(SSSDBG_TRACE_INTERNAL, ("sss_autofs_cmd_setautomntent\n"));
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek cmdctx = talloc_zero(client, struct autofs_cmd_ctx);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek if (!cmdctx) {
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek return ENOMEM;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek }
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek cmdctx->cctx = client;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek sss_packet_get_body(client->creq->in, &body, &blen);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek /* if not terminated fail */
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek if (body[blen -1] != '\0') {
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek ret = EINVAL;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek goto done;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek }
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek /* If the body isn't valid UTF-8, fail */
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek if (!sss_utf8_check(body, blen -1)) {
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek ret = EINVAL;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek goto done;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek }
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek rawname = (const char *)body;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek DEBUG(SSSDBG_TRACE_FUNC,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek ("Got request for automount map named %s\n", rawname));
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek req = setautomntent_send(cmdctx, rawname, cmdctx);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek if (!req) {
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek DEBUG(SSSDBG_CRIT_FAILURE,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek ("Fatal error calling setautomntent_send\n"));
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek ret = EIO;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek goto done;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek }
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek tevent_req_set_callback(req, sss_autofs_cmd_setautomntent_done, cmdctx);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek ret = EOK;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmekdone:
e88d8021ba34be32ef5ace32e7243da798b0d1c5Zbigniew Jędrzejewski-Szmek return autofs_cmd_done(cmdctx, ret);
e88d8021ba34be32ef5ace32e7243da798b0d1c5Zbigniew Jędrzejewski-Szmek}
e88d8021ba34be32ef5ace32e7243da798b0d1c5Zbigniew Jędrzejewski-Szmek
e88d8021ba34be32ef5ace32e7243da798b0d1c5Zbigniew Jędrzejewski-Szmekstatic void sss_autofs_cmd_setautomntent_done(struct tevent_req *req)
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek{
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek struct autofs_cmd_ctx *cmdctx =
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek tevent_req_callback_data(req, struct autofs_cmd_ctx);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek errno_t ret;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek errno_t reqret;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek struct sss_packet *packet;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek uint8_t *body;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek size_t blen;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek DEBUG(SSSDBG_TRACE_INTERNAL, ("setautomntent done\n"));
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
56fd6bf795926409b087bce406ea851ad89f9fe8Tom Gundersen reqret = setautomntent_recv(req);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek talloc_zfree(req);
d0d6a4cd70477970812bff0a37e70f66208d7c14Tom Gundersen if (reqret != EOK && reqret != ENOENT) {
d0d6a4cd70477970812bff0a37e70f66208d7c14Tom Gundersen DEBUG(SSSDBG_CRIT_FAILURE, ("setautomntent_recv failed\n"));
d0d6a4cd70477970812bff0a37e70f66208d7c14Tom Gundersen autofs_cmd_done(cmdctx, reqret);
d0d6a4cd70477970812bff0a37e70f66208d7c14Tom Gundersen return;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek }
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek /* Either we succeeded or no domains were eligible */
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek ret = sss_packet_new(cmdctx->cctx->creq, 0,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek sss_packet_get_cmd(cmdctx->cctx->creq->in),
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek &cmdctx->cctx->creq->out);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek if (ret == EOK) {
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek if (reqret == ENOENT) {
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek DEBUG(SSSDBG_TRACE_FUNC, ("setautomntent did not find requested map\n"));
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek /* Notify the caller that this entry wasn't found */
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek sss_cmd_empty_packet(cmdctx->cctx->creq->out);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek } else {
113bfde15f9393fa8bc22cbd839c0bc64e733ee2Tom Gundersen DEBUG(SSSDBG_TRACE_FUNC, ("setautomntent found data\n"));
113bfde15f9393fa8bc22cbd839c0bc64e733ee2Tom Gundersen packet = cmdctx->cctx->creq->out;
113bfde15f9393fa8bc22cbd839c0bc64e733ee2Tom Gundersen ret = sss_packet_grow(packet, 2*sizeof(uint32_t));
113bfde15f9393fa8bc22cbd839c0bc64e733ee2Tom Gundersen if (ret != EOK) {
113bfde15f9393fa8bc22cbd839c0bc64e733ee2Tom Gundersen DEBUG(SSSDBG_CRIT_FAILURE, ("Couldn't grow the packet\n"));
113bfde15f9393fa8bc22cbd839c0bc64e733ee2Tom Gundersen talloc_free(cmdctx);
113bfde15f9393fa8bc22cbd839c0bc64e733ee2Tom Gundersen return;
113bfde15f9393fa8bc22cbd839c0bc64e733ee2Tom Gundersen }
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek sss_packet_get_body(packet, &body, &blen);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek ((uint32_t *)body)[0] = 1; /* Got some results */
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek ((uint32_t *)body)[1] = 0; /* reserved */
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek }
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek sss_cmd_done(cmdctx->cctx, NULL);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek return;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek }
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek DEBUG(SSSDBG_CRIT_FAILURE, ("Error creating packet\n"));
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek return;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek}
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmekstruct setautomntent_state {
0d4ad91dd4fc831c31a9775b0eadf97fea6cd7f6Alin Rauta struct autofs_cmd_ctx *cmdctx;
0d4ad91dd4fc831c31a9775b0eadf97fea6cd7f6Alin Rauta struct autofs_dom_ctx *dctx;
0d4ad91dd4fc831c31a9775b0eadf97fea6cd7f6Alin Rauta
0d4ad91dd4fc831c31a9775b0eadf97fea6cd7f6Alin Rauta char *mapname;
0d4ad91dd4fc831c31a9775b0eadf97fea6cd7f6Alin Rauta struct autofs_map_ctx *map;
0d4ad91dd4fc831c31a9775b0eadf97fea6cd7f6Alin Rauta};
0d4ad91dd4fc831c31a9775b0eadf97fea6cd7f6Alin Rauta
0d4ad91dd4fc831c31a9775b0eadf97fea6cd7f6Alin Rautastruct setautomntent_lookup_ctx {
0d4ad91dd4fc831c31a9775b0eadf97fea6cd7f6Alin Rauta struct autofs_ctx *actx;
0d4ad91dd4fc831c31a9775b0eadf97fea6cd7f6Alin Rauta struct autofs_dom_ctx *dctx;
0d4ad91dd4fc831c31a9775b0eadf97fea6cd7f6Alin Rauta struct resp_ctx *rctx;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek struct cli_ctx *cctx;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek bool returned_to_mainloop;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek char *mapname;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek struct autofs_map_ctx *map;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek};
3ba3a79df4ae094d1008c04a9af8d1ff970124c4Zbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmekstatic errno_t
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmeklookup_automntmap_step(struct setautomntent_lookup_ctx *lookup_ctx);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmekstatic void
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmekautofs_map_result_timeout(struct tevent_context *ev,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek struct tevent_timer *te,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek struct timeval current_time,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek void *pvt)
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek{
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek struct autofs_map_ctx *map =
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek talloc_get_type(pvt, struct autofs_map_ctx);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek /* Free the autofs map result context
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek * The destructor for the autofs map will remove itself
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek * from the hash table
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek */
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek talloc_free(map);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek}
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmekstatic void
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmekset_autofs_map_lifetime(uint32_t lifetime,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek struct setautomntent_lookup_ctx *lookup_ctx,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek struct autofs_map_ctx *map)
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek{
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek struct timeval tv;
3ba3a79df4ae094d1008c04a9af8d1ff970124c4Zbigniew Jędrzejewski-Szmek struct tevent_timer *te;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek tv = tevent_timeval_current_ofs(lifetime, 0);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek te = tevent_add_timer(lookup_ctx->rctx->ev,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek lookup_ctx->rctx, tv,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek autofs_map_result_timeout,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek map);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek if (!te) {
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek DEBUG(SSSDBG_CRIT_FAILURE,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek ("Could not set up life timer for autofs maps. "
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek "Entries may become stale.\n"));
3ba3a79df4ae094d1008c04a9af8d1ff970124c4Zbigniew Jędrzejewski-Szmek }
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek}
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmekstatic struct tevent_req *
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmeksetautomntent_send(TALLOC_CTX *mem_ctx,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek const char *rawname,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek struct autofs_cmd_ctx *cmdctx)
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek{
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek char *domname;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek errno_t ret;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek struct tevent_req *req;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek struct setautomntent_state *state;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek struct cli_ctx *client = cmdctx->cctx;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek struct autofs_dom_ctx *dctx;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek struct autofs_ctx *actx =
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek talloc_get_type(client->rctx->pvt_ctx, struct autofs_ctx);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek struct setautomntent_lookup_ctx *lookup_ctx;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek req = tevent_req_create(mem_ctx, &state, struct setautomntent_state);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek if (!req) {
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek DEBUG(SSSDBG_FATAL_FAILURE,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek ("Could not create tevent request for setautomntent\n"));
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek goto fail;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek }
2972cba11712c3bfbe9fa07d1f3c3c4330127733Nick Owens state->cmdctx = cmdctx;
2972cba11712c3bfbe9fa07d1f3c3c4330127733Nick Owens
4046d8361c55c80ab8577aea52523b9e6eab0d0cLennart Poettering dctx = talloc_zero(state, struct autofs_dom_ctx);
4046d8361c55c80ab8577aea52523b9e6eab0d0cLennart Poettering if (!dctx) {
4046d8361c55c80ab8577aea52523b9e6eab0d0cLennart Poettering DEBUG(SSSDBG_FATAL_FAILURE, ("Out of memory\n"));
4046d8361c55c80ab8577aea52523b9e6eab0d0cLennart Poettering goto fail;
4046d8361c55c80ab8577aea52523b9e6eab0d0cLennart Poettering }
4046d8361c55c80ab8577aea52523b9e6eab0d0cLennart Poettering dctx->cmd_ctx = state->cmdctx;
4046d8361c55c80ab8577aea52523b9e6eab0d0cLennart Poettering state->dctx = dctx;
4046d8361c55c80ab8577aea52523b9e6eab0d0cLennart Poettering
2972cba11712c3bfbe9fa07d1f3c3c4330127733Nick Owens ret = sss_parse_name(state, client->rctx->names, rawname,
2972cba11712c3bfbe9fa07d1f3c3c4330127733Nick Owens &domname, &state->mapname);
4046d8361c55c80ab8577aea52523b9e6eab0d0cLennart Poettering if (ret != EOK) {
e2bccc9d9974eb1290653ecfa3ccfd03c313842bDavid Herrmann DEBUG(SSSDBG_FATAL_FAILURE,
e2bccc9d9974eb1290653ecfa3ccfd03c313842bDavid Herrmann ("Invalid name received [%s]\n", rawname));
e2bccc9d9974eb1290653ecfa3ccfd03c313842bDavid Herrmann goto fail;
505c5f6de1a5c0afb238a46db94fe3571902cc9dBenedikt Morbach }
4046d8361c55c80ab8577aea52523b9e6eab0d0cLennart Poettering
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek DEBUG(SSSDBG_TRACE_FUNC,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek ("Requesting info for automount map [%s] from [%s]\n",
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek state->mapname, domname?domname:"<ALL>"));
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek if (domname) {
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek dctx->domain = responder_get_domain(client->rctx->domains, domname);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek if (!dctx->domain) {
5c82dd13e1eef502afcef209a3b14a2100966909Benedikt Morbach goto fail;
4046d8361c55c80ab8577aea52523b9e6eab0d0cLennart Poettering }
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
a46e37cb1225a36a33e8728005693e825cdbc01aSusant Sahani client->automntmap_name = talloc_strdup(client, rawname);
a46e37cb1225a36a33e8728005693e825cdbc01aSusant Sahani if (!client->automntmap_name) {
1f0d9695125bf8e66d0e53e37d454755a84899bbLennart Poettering goto fail;
1f0d9695125bf8e66d0e53e37d454755a84899bbLennart Poettering }
1f0d9695125bf8e66d0e53e37d454755a84899bbLennart Poettering } else {
1f0d9695125bf8e66d0e53e37d454755a84899bbLennart Poettering /* this is a multidomain search */
1f0d9695125bf8e66d0e53e37d454755a84899bbLennart Poettering dctx->domain = client->rctx->domains;
1f0d9695125bf8e66d0e53e37d454755a84899bbLennart Poettering cmdctx->check_next = true;
1f0d9695125bf8e66d0e53e37d454755a84899bbLennart Poettering
1f0d9695125bf8e66d0e53e37d454755a84899bbLennart Poettering client->automntmap_name = talloc_strdup(client, state->mapname);
1f0d9695125bf8e66d0e53e37d454755a84899bbLennart Poettering if (!client->automntmap_name) {
1f0d9695125bf8e66d0e53e37d454755a84899bbLennart Poettering goto fail;
1f0d9695125bf8e66d0e53e37d454755a84899bbLennart Poettering }
1f0d9695125bf8e66d0e53e37d454755a84899bbLennart Poettering }
1f0d9695125bf8e66d0e53e37d454755a84899bbLennart Poettering
a46e37cb1225a36a33e8728005693e825cdbc01aSusant Sahani dctx->check_provider = NEED_CHECK_PROVIDER(dctx->domain->provider);
a46e37cb1225a36a33e8728005693e825cdbc01aSusant Sahani /* Is the result context already available?
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek * Check for existing lookups for this map
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek */
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek ret = get_autofs_map(actx, state->mapname, &state->map);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek if (ret == EOK) {
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek /* Another process already requested this map
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek * Check whether it's ready for processing.
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek */
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek if (state->map->ready) {
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek if (state->map->found) {
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek DEBUG(SSSDBG_TRACE_LIBS,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek ("Map %s is ready to be processed\n", state->mapname));
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek tevent_req_done(req);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek tevent_req_post(req, actx->rctx->ev);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek return req;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek } else {
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek DEBUG(SSSDBG_TRACE_LIBS,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek ("Map %s was marked as nonexistent\n", state->mapname));
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek tevent_req_error(req, ENOENT);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek tevent_req_post(req, actx->rctx->ev);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek return req;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek }
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek }
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek /* Result object is still being constructed
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek * Register for notification when it's ready
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek */
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek DEBUG(SSSDBG_TRACE_LIBS,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek ("Map %s is being looked up, registering for notification\n",
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek state->mapname));
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek ret = autofs_setent_add_ref(state, state->map, req);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek if (ret != EOK) {
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek goto fail;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek }
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek /* Will return control below */
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek } else if (ret == ENOENT) {
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek DEBUG(SSSDBG_TRACE_LIBS,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek ("Map %s needs to be looked up\n", state->mapname));
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek state->map = talloc_zero(actx, struct autofs_map_ctx);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek if (!state->map) {
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek ret = ENOMEM;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek goto fail;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek }
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek dctx->map_ctx = state->map;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek state->map->mapname = talloc_strdup(state->map, state->mapname);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek if (!state->map->mapname) {
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek talloc_free(state->map);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek ret = ENOMEM;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek goto fail;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek }
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek state->map->map_table = actx->maps;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek ret = autofs_setent_add_ref(state, state->map, req);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek if (ret != EOK) {
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek talloc_free(state->map);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek goto fail;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek }
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek ret = set_autofs_map(actx, state->map);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek if (ret != EOK) {
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek talloc_free(state->map);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek goto fail;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek }
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek /* Perform lookup */
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek lookup_ctx = talloc_zero(state->map, struct setautomntent_lookup_ctx);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek if (!lookup_ctx) {
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek talloc_free(state->map);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek ret = ENOMEM;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek goto fail;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek }
3ba3a79df4ae094d1008c04a9af8d1ff970124c4Zbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek /* Steal the dom_ctx onto the lookup_ctx so it doesn't go out of scope if
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek * this request is canceled while other requests are in-progress.
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek */
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek lookup_ctx->dctx = talloc_steal(lookup_ctx, state->dctx);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek lookup_ctx->actx = actx;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek lookup_ctx->map = state->map;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek lookup_ctx->rctx = client->rctx;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek lookup_ctx->mapname =
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek talloc_strdup(lookup_ctx, state->mapname);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek if (!lookup_ctx->mapname) {
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek talloc_free(state->map);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek ret = ENOMEM;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek goto fail;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek }
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek ret = lookup_automntmap_step(lookup_ctx);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek if (ret == EAGAIN) {
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek DEBUG(SSSDBG_TRACE_INTERNAL, ("lookup_automntmap_step "
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek "is refreshing the cache, re-entering the mainloop\n"));
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek return req;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek } else if (ret != EOK) {
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek DEBUG(SSSDBG_CRIT_FAILURE, ("Could not get data from cache\n"));
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek talloc_free(state->map);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek goto fail;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek }
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek tevent_req_done(req);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek tevent_req_post(req, cmdctx->cctx->ev);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek return req;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek } else {
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek DEBUG(SSSDBG_CRIT_FAILURE,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek ("Unexpected error from get_autofs_map [%d]: %s\n",
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek ret, strerror(ret)));
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek goto fail;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek }
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek return req;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmekfail:
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek talloc_free(req);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek return NULL;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek}
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmekstatic errno_t
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmeklookup_automntmap_update_cache(struct setautomntent_lookup_ctx *lookup_ctx);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmekstatic errno_t
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmeklookup_automntmap_step(struct setautomntent_lookup_ctx *lookup_ctx)
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek{
769b56a308c3f3d3952eda87fd4fb004207f4f49Tom Gundersen errno_t ret;
769b56a308c3f3d3952eda87fd4fb004207f4f49Tom Gundersen struct sss_domain_info *dom = lookup_ctx->dctx->domain;
769b56a308c3f3d3952eda87fd4fb004207f4f49Tom Gundersen struct autofs_dom_ctx *dctx = lookup_ctx->dctx;
769b56a308c3f3d3952eda87fd4fb004207f4f49Tom Gundersen struct sysdb_ctx *sysdb;
769b56a308c3f3d3952eda87fd4fb004207f4f49Tom Gundersen struct autofs_map_ctx *map;
769b56a308c3f3d3952eda87fd4fb004207f4f49Tom Gundersen
769b56a308c3f3d3952eda87fd4fb004207f4f49Tom Gundersen /* Check each domain for this map name */
769b56a308c3f3d3952eda87fd4fb004207f4f49Tom Gundersen while (dom) {
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek /* if it is a domainless search, skip domains that require fully
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek * qualified names instead */
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek while (dom && dctx->cmd_ctx->check_next && dom->fqnames) {
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek dom = dom->next;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek }
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek /* No domains left to search */
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek if (!dom) break;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek if (dom != dctx->domain) {
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek /* make sure we reset the check_provider flag when we check
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek * a new domain */
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek dctx->check_provider =
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek NEED_CHECK_PROVIDER(dom->provider);
e88d8021ba34be32ef5ace32e7243da798b0d1c5Zbigniew Jędrzejewski-Szmek }
e88d8021ba34be32ef5ace32e7243da798b0d1c5Zbigniew Jędrzejewski-Szmek
e88d8021ba34be32ef5ace32e7243da798b0d1c5Zbigniew Jędrzejewski-Szmek /* make sure to update the dctx if we changed domain */
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek dctx->domain = dom;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
301f4073fe1c2757e602aef24cee9ccf5f81a3a3Michael Marineau DEBUG(SSSDBG_TRACE_FUNC, ("Requesting info for [%s@%s]\n",
301f4073fe1c2757e602aef24cee9ccf5f81a3a3Michael Marineau lookup_ctx->mapname, dom->name));
301f4073fe1c2757e602aef24cee9ccf5f81a3a3Michael Marineau ret = sysdb_get_ctx_from_list(lookup_ctx->rctx->db_list, dom, &sysdb);
301f4073fe1c2757e602aef24cee9ccf5f81a3a3Michael Marineau if (ret != EOK) {
301f4073fe1c2757e602aef24cee9ccf5f81a3a3Michael Marineau DEBUG(SSSDBG_FATAL_FAILURE,
301f4073fe1c2757e602aef24cee9ccf5f81a3a3Michael Marineau ("Fatal: Sysdb CTX not found for this domain!\n"));
301f4073fe1c2757e602aef24cee9ccf5f81a3a3Michael Marineau return EIO;
301f4073fe1c2757e602aef24cee9ccf5f81a3a3Michael Marineau }
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek /* Look into the cache */
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek talloc_free(dctx->map);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek ret = sysdb_get_map_byname(dctx, sysdb, lookup_ctx->mapname,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek &dctx->map);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek if (ret != EOK && ret != ENOENT) {
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek DEBUG(SSSDBG_OP_FAILURE, ("Could not check cache\n"));
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek return ret;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek } else if (ret == ENOENT) {
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek DEBUG(SSSDBG_MINOR_FAILURE,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek ("No automount map [%s] in cache for domain [%s]\n",
d59be2cf702dd29d0bb228013cef801f2e9dd22fZbigniew Jędrzejewski-Szmek lookup_ctx->mapname, dom->name));
d59be2cf702dd29d0bb228013cef801f2e9dd22fZbigniew Jędrzejewski-Szmek if (!dctx->check_provider) {
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek if (dctx->cmd_ctx->check_next) {
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek DEBUG(SSSDBG_TRACE_INTERNAL, ("Moving on to next domain\n"));
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek dom = dom->next;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek continue;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek }
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek else break;
d59be2cf702dd29d0bb228013cef801f2e9dd22fZbigniew Jędrzejewski-Szmek }
d59be2cf702dd29d0bb228013cef801f2e9dd22fZbigniew Jędrzejewski-Szmek ret = EOK;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek }
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
1adc5d0bcd17fc8a8cd22fcd03174bfd75306dcdSusant Sahani ret = get_autofs_map(lookup_ctx->actx, lookup_ctx->mapname, &map);
1adc5d0bcd17fc8a8cd22fcd03174bfd75306dcdSusant Sahani if (ret != EOK) {
1adc5d0bcd17fc8a8cd22fcd03174bfd75306dcdSusant Sahani /* Something really bad happened! */
d59be2cf702dd29d0bb228013cef801f2e9dd22fZbigniew Jędrzejewski-Szmek DEBUG(SSSDBG_CRIT_FAILURE, ("Autofs map entry was lost!\n"));
d59be2cf702dd29d0bb228013cef801f2e9dd22fZbigniew Jędrzejewski-Szmek return ret;
1adc5d0bcd17fc8a8cd22fcd03174bfd75306dcdSusant Sahani }
1adc5d0bcd17fc8a8cd22fcd03174bfd75306dcdSusant Sahani
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek if (dctx->map == NULL && !dctx->check_provider) {
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek DEBUG(SSSDBG_MINOR_FAILURE,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek ("Autofs map not found, setting negative cache\n"));
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek map->ready = true;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek map->found = false;
e88d8021ba34be32ef5ace32e7243da798b0d1c5Zbigniew Jędrzejewski-Szmek set_autofs_map_lifetime(lookup_ctx->actx->neg_timeout, lookup_ctx, map);
e88d8021ba34be32ef5ace32e7243da798b0d1c5Zbigniew Jędrzejewski-Szmek return ENOENT;
e88d8021ba34be32ef5ace32e7243da798b0d1c5Zbigniew Jędrzejewski-Szmek }
e88d8021ba34be32ef5ace32e7243da798b0d1c5Zbigniew Jędrzejewski-Szmek
e88d8021ba34be32ef5ace32e7243da798b0d1c5Zbigniew Jędrzejewski-Szmek if (dctx->check_provider) {
e88d8021ba34be32ef5ace32e7243da798b0d1c5Zbigniew Jędrzejewski-Szmek ret = lookup_automntmap_update_cache(lookup_ctx);
e88d8021ba34be32ef5ace32e7243da798b0d1c5Zbigniew Jędrzejewski-Szmek if (ret == EAGAIN) {
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek DEBUG(SSSDBG_TRACE_INTERNAL,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek ("Looking up automount maps from the DP\n"));
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek return EAGAIN;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek } else if (ret != EOK) {
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek DEBUG(SSSDBG_OP_FAILURE,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek ("Error looking up automount maps [%d]: %s\n",
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek ret, strerror(ret)));
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek return ret;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek }
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek }
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek /* OK, the map is in cache and valid.
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek * Let's get all members and return it
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek */
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek ret = sysdb_autofs_entries_by_map(map, sysdb, map->mapname,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek &map->entry_count,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek &map->entries);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek if (ret != EOK && ret != ENOENT) {
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek DEBUG(SSSDBG_OP_FAILURE,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek ("Error looking automount map entries [%d]: %s\n",
3e43b2cd97bd82efe6a09e8b9b2e6b5f33f578a0Jan Janssen ret, strerror(ret)));
3e43b2cd97bd82efe6a09e8b9b2e6b5f33f578a0Jan Janssen map->ready = true;
3e43b2cd97bd82efe6a09e8b9b2e6b5f33f578a0Jan Janssen map->found = false;
3e43b2cd97bd82efe6a09e8b9b2e6b5f33f578a0Jan Janssen set_autofs_map_lifetime(lookup_ctx->actx->neg_timeout, lookup_ctx, map);
3e43b2cd97bd82efe6a09e8b9b2e6b5f33f578a0Jan Janssen return EIO;
4a6970c5354cd367b1fa62114057d8e084a20403Torstein Husebø }
3e43b2cd97bd82efe6a09e8b9b2e6b5f33f578a0Jan Janssen
3e43b2cd97bd82efe6a09e8b9b2e6b5f33f578a0Jan Janssen map->map = talloc_steal(map, dctx->map);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek DEBUG(SSSDBG_TRACE_FUNC,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek ("setautomntent done for map %s\n", lookup_ctx->mapname));
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek map->ready = true;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek map->found = true;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek set_autofs_map_lifetime(dom->autofsmap_timeout, lookup_ctx, map);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek return EOK;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek }
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek map = talloc_zero(lookup_ctx->actx, struct autofs_map_ctx);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek if (!map) {
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek return ENOMEM;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek }
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek map->ready = true;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek map->found = false;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek map->map_table = lookup_ctx->actx->maps;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek map->mapname = talloc_strdup(map, lookup_ctx->mapname);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek if (!map->mapname) {
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek talloc_free(map);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek return ENOMEM;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek }
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek ret = set_autofs_map(lookup_ctx->actx, map);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek if (ret != EOK) {
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek talloc_free(map);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek return ENOMEM;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek }
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek set_autofs_map_lifetime(lookup_ctx->actx->neg_timeout, lookup_ctx, map);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek /* If we've gotten here, then no domain contained this map */
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek return ENOENT;
165c41a99ab6002ef3ba6bd1f9361abf32c077f2Susant Sahani}
165c41a99ab6002ef3ba6bd1f9361abf32c077f2Susant Sahani
165c41a99ab6002ef3ba6bd1f9361abf32c077f2Susant Sahanistatic void lookup_automntmap_cache_updated(uint16_t err_maj, uint32_t err_min,
165c41a99ab6002ef3ba6bd1f9361abf32c077f2Susant Sahani const char *err_msg, void *ptr);
165c41a99ab6002ef3ba6bd1f9361abf32c077f2Susant Sahanistatic void autofs_dp_send_map_req_done(struct tevent_req *req);
165c41a99ab6002ef3ba6bd1f9361abf32c077f2Susant Sahani
165c41a99ab6002ef3ba6bd1f9361abf32c077f2Susant Sahanistatic errno_t
165c41a99ab6002ef3ba6bd1f9361abf32c077f2Susant Sahanilookup_automntmap_update_cache(struct setautomntent_lookup_ctx *lookup_ctx)
165c41a99ab6002ef3ba6bd1f9361abf32c077f2Susant Sahani{
165c41a99ab6002ef3ba6bd1f9361abf32c077f2Susant Sahani errno_t ret;
165c41a99ab6002ef3ba6bd1f9361abf32c077f2Susant Sahani uint64_t cache_expire = 0;
165c41a99ab6002ef3ba6bd1f9361abf32c077f2Susant Sahani struct autofs_dom_ctx *dctx = lookup_ctx->dctx;
165c41a99ab6002ef3ba6bd1f9361abf32c077f2Susant Sahani struct tevent_req *req = NULL;
165c41a99ab6002ef3ba6bd1f9361abf32c077f2Susant Sahani struct dp_callback_ctx *cb_ctx = NULL;
165c41a99ab6002ef3ba6bd1f9361abf32c077f2Susant Sahani
165c41a99ab6002ef3ba6bd1f9361abf32c077f2Susant Sahani if (dctx->map != NULL) {
165c41a99ab6002ef3ba6bd1f9361abf32c077f2Susant Sahani cache_expire = ldb_msg_find_attr_as_uint64(dctx->map,
165c41a99ab6002ef3ba6bd1f9361abf32c077f2Susant Sahani SYSDB_CACHE_EXPIRE, 0);
165c41a99ab6002ef3ba6bd1f9361abf32c077f2Susant Sahani
165c41a99ab6002ef3ba6bd1f9361abf32c077f2Susant Sahani /* if we have any reply let's check cache validity */
165c41a99ab6002ef3ba6bd1f9361abf32c077f2Susant Sahani ret = sss_cmd_check_cache(dctx->map, 0, cache_expire);
165c41a99ab6002ef3ba6bd1f9361abf32c077f2Susant Sahani if (ret == EOK) {
165c41a99ab6002ef3ba6bd1f9361abf32c077f2Susant Sahani DEBUG(SSSDBG_TRACE_FUNC, ("Cached entry is valid, returning..\n"));
165c41a99ab6002ef3ba6bd1f9361abf32c077f2Susant Sahani return EOK;
165c41a99ab6002ef3ba6bd1f9361abf32c077f2Susant Sahani } else if (ret != EAGAIN && ret != ENOENT) {
165c41a99ab6002ef3ba6bd1f9361abf32c077f2Susant Sahani DEBUG(SSSDBG_CRIT_FAILURE, ("Error checking cache: %d\n", ret));
165c41a99ab6002ef3ba6bd1f9361abf32c077f2Susant Sahani goto error;
165c41a99ab6002ef3ba6bd1f9361abf32c077f2Susant Sahani }
165c41a99ab6002ef3ba6bd1f9361abf32c077f2Susant Sahani }
165c41a99ab6002ef3ba6bd1f9361abf32c077f2Susant Sahani
165c41a99ab6002ef3ba6bd1f9361abf32c077f2Susant Sahani /* dont loop forever :-) */
165c41a99ab6002ef3ba6bd1f9361abf32c077f2Susant Sahani dctx->check_provider = false;
165c41a99ab6002ef3ba6bd1f9361abf32c077f2Susant Sahani
165c41a99ab6002ef3ba6bd1f9361abf32c077f2Susant Sahani /* keep around current data in case backend is offline */
165c41a99ab6002ef3ba6bd1f9361abf32c077f2Susant Sahani /* FIXME - do this by default */
165c41a99ab6002ef3ba6bd1f9361abf32c077f2Susant Sahani#if 0
165c41a99ab6002ef3ba6bd1f9361abf32c077f2Susant Sahani if (dctx->res->count) {
165c41a99ab6002ef3ba6bd1f9361abf32c077f2Susant Sahani dctx->res = talloc_steal(dctx, dctx->res);
165c41a99ab6002ef3ba6bd1f9361abf32c077f2Susant Sahani }
165c41a99ab6002ef3ba6bd1f9361abf32c077f2Susant Sahani#endif
165c41a99ab6002ef3ba6bd1f9361abf32c077f2Susant Sahani
165c41a99ab6002ef3ba6bd1f9361abf32c077f2Susant Sahani req = sss_dp_get_autofs_send(lookup_ctx->cctx, lookup_ctx->rctx,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek lookup_ctx->dctx->domain, true,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek SSS_DP_AUTOFS, lookup_ctx->mapname);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek if (!req) {
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek DEBUG(SSSDBG_CRIT_FAILURE,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek ("Out of memory sending data provider request\n"));
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek ret = ENOMEM;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek goto error;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek }
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek cb_ctx = talloc_zero(lookup_ctx->dctx, struct dp_callback_ctx);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek if(!cb_ctx) {
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek talloc_zfree(req);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek ret = ENOMEM;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek goto error;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek }
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek cb_ctx->callback = lookup_automntmap_cache_updated;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek cb_ctx->ptr = lookup_ctx;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek cb_ctx->cctx = lookup_ctx->dctx->cmd_ctx->cctx;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek cb_ctx->mem_ctx = lookup_ctx->dctx;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek tevent_req_set_callback(req, autofs_dp_send_map_req_done, cb_ctx);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek return EAGAIN;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmekerror:
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek ret = autofs_cmd_send_error(lookup_ctx->dctx->cmd_ctx, ret);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek if (ret != EOK) {
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek DEBUG(SSSDBG_CRIT_FAILURE, ("Fatal error, killing connection!\n"));
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek talloc_free(lookup_ctx->cctx);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek return ret;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek }
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek autofs_cmd_done(lookup_ctx->dctx->cmd_ctx, ret);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek return EOK;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek}
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmekstatic void autofs_dp_send_map_req_done(struct tevent_req *req)
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek{
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek struct dp_callback_ctx *cb_ctx =
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek tevent_req_callback_data(req, struct dp_callback_ctx);
12b42c76672a66c2d4ea7212c14f8f1b5a62b78dTom Gundersen struct setautomntent_lookup_ctx *lookup_ctx =
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek talloc_get_type(cb_ctx->ptr, struct setautomntent_lookup_ctx);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
eac684ef1c29684b1bcd27a89c38c202e568e469Tom Gundersen errno_t ret;
eac684ef1c29684b1bcd27a89c38c202e568e469Tom Gundersen dbus_uint16_t err_maj;
eac684ef1c29684b1bcd27a89c38c202e568e469Tom Gundersen dbus_uint32_t err_min;
eac684ef1c29684b1bcd27a89c38c202e568e469Tom Gundersen char *err_msg;
eac684ef1c29684b1bcd27a89c38c202e568e469Tom Gundersen
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek ret = sss_dp_get_autofs_recv(cb_ctx->mem_ctx, req,
eac684ef1c29684b1bcd27a89c38c202e568e469Tom Gundersen &err_maj, &err_min,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek &err_msg);
12b42c76672a66c2d4ea7212c14f8f1b5a62b78dTom Gundersen talloc_free(req);
eac684ef1c29684b1bcd27a89c38c202e568e469Tom Gundersen if (ret != EOK) {
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek DEBUG(SSSDBG_CRIT_FAILURE, ("Fatal error, killing connection!\n"));
eac684ef1c29684b1bcd27a89c38c202e568e469Tom Gundersen talloc_free(lookup_ctx->cctx);
eac684ef1c29684b1bcd27a89c38c202e568e469Tom Gundersen return;
eac684ef1c29684b1bcd27a89c38c202e568e469Tom Gundersen }
9c8ca3f7a69f82ca181b3cd2d5e1d3e621938abbZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek cb_ctx->callback(err_maj, err_min, err_msg, cb_ctx->ptr);
eac684ef1c29684b1bcd27a89c38c202e568e469Tom Gundersen}
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
12b42c76672a66c2d4ea7212c14f8f1b5a62b78dTom Gundersenstatic void lookup_automntmap_cache_updated(uint16_t err_maj, uint32_t err_min,
f47c5c47d1a7bcfa1842ff7cc52b1f7fc1d86bcfpoma const char *err_msg, void *ptr)
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek{
f47c5c47d1a7bcfa1842ff7cc52b1f7fc1d86bcfpoma struct setautomntent_lookup_ctx *lookup_ctx =
f47c5c47d1a7bcfa1842ff7cc52b1f7fc1d86bcfpoma talloc_get_type(ptr, struct setautomntent_lookup_ctx);
f47c5c47d1a7bcfa1842ff7cc52b1f7fc1d86bcfpoma struct autofs_dom_ctx *dctx = lookup_ctx->dctx;
f47c5c47d1a7bcfa1842ff7cc52b1f7fc1d86bcfpoma errno_t ret;
f47c5c47d1a7bcfa1842ff7cc52b1f7fc1d86bcfpoma
f47c5c47d1a7bcfa1842ff7cc52b1f7fc1d86bcfpoma if (err_maj) {
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek DEBUG(SSSDBG_CRIT_FAILURE,
f47c5c47d1a7bcfa1842ff7cc52b1f7fc1d86bcfpoma ("Unable to get information from Data Provider\n"
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek "Error: %u, %u, %s\n"
12b42c76672a66c2d4ea7212c14f8f1b5a62b78dTom Gundersen "Will try to return what we have in cache\n",
f47c5c47d1a7bcfa1842ff7cc52b1f7fc1d86bcfpoma (unsigned int)err_maj, (unsigned int)err_min, err_msg));
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek /* Loop to the next domain if possible */
f47c5c47d1a7bcfa1842ff7cc52b1f7fc1d86bcfpoma if (dctx->domain->next && dctx->cmd_ctx->check_next) {
f47c5c47d1a7bcfa1842ff7cc52b1f7fc1d86bcfpoma dctx->domain = dctx->domain->next;
f47c5c47d1a7bcfa1842ff7cc52b1f7fc1d86bcfpoma dctx->check_provider = NEED_CHECK_PROVIDER(dctx->domain->provider);
f47c5c47d1a7bcfa1842ff7cc52b1f7fc1d86bcfpoma }
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek }
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
12b42c76672a66c2d4ea7212c14f8f1b5a62b78dTom Gundersen /* ok the backend returned, search to see if we have updated results */
0a8a0fad010018be0f46d1c2e077ade0eb27c7dbTom Gundersen ret = lookup_automntmap_step(lookup_ctx);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek if (ret != EOK) {
0a8a0fad010018be0f46d1c2e077ade0eb27c7dbTom Gundersen if (ret == EAGAIN) {
0a8a0fad010018be0f46d1c2e077ade0eb27c7dbTom Gundersen return;
0a8a0fad010018be0f46d1c2e077ade0eb27c7dbTom Gundersen }
0a8a0fad010018be0f46d1c2e077ade0eb27c7dbTom Gundersen }
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
0a8a0fad010018be0f46d1c2e077ade0eb27c7dbTom Gundersen /* We have results to return */
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek autofs_setent_notify(lookup_ctx->map, ret);
12b42c76672a66c2d4ea7212c14f8f1b5a62b78dTom Gundersen}
0a8a0fad010018be0f46d1c2e077ade0eb27c7dbTom Gundersen
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmekstatic errno_t
0a8a0fad010018be0f46d1c2e077ade0eb27c7dbTom Gundersensetautomntent_recv(struct tevent_req *req)
0a8a0fad010018be0f46d1c2e077ade0eb27c7dbTom Gundersen{
0a8a0fad010018be0f46d1c2e077ade0eb27c7dbTom Gundersen TEVENT_REQ_RETURN_ON_ERROR(req);
0a8a0fad010018be0f46d1c2e077ade0eb27c7dbTom Gundersen return EOK;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek}
0a8a0fad010018be0f46d1c2e077ade0eb27c7dbTom Gundersen
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmekstatic errno_t
12b42c76672a66c2d4ea7212c14f8f1b5a62b78dTom Gundersengetautomntent_process(struct autofs_cmd_ctx *cmdctx,
0a8a0fad010018be0f46d1c2e077ade0eb27c7dbTom Gundersen struct autofs_map_ctx *map,
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek uint32_t cursor);
0a8a0fad010018be0f46d1c2e077ade0eb27c7dbTom Gundersenstatic void
0a8a0fad010018be0f46d1c2e077ade0eb27c7dbTom Gundersengetautomntent_implicit_done(struct tevent_req *req);
0a8a0fad010018be0f46d1c2e077ade0eb27c7dbTom Gundersen
0a8a0fad010018be0f46d1c2e077ade0eb27c7dbTom Gundersenstatic int
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmeksss_autofs_cmd_getautomntent(struct cli_ctx *client)
0a8a0fad010018be0f46d1c2e077ade0eb27c7dbTom Gundersen{
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek struct autofs_cmd_ctx *cmdctx;
12b42c76672a66c2d4ea7212c14f8f1b5a62b78dTom Gundersen struct autofs_map_ctx *map;
0a8a0fad010018be0f46d1c2e077ade0eb27c7dbTom Gundersen struct autofs_ctx *actx;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek uint8_t *body;
0a8a0fad010018be0f46d1c2e077ade0eb27c7dbTom Gundersen size_t blen;
0a8a0fad010018be0f46d1c2e077ade0eb27c7dbTom Gundersen errno_t ret;
0a8a0fad010018be0f46d1c2e077ade0eb27c7dbTom Gundersen uint32_t namelen;
0a8a0fad010018be0f46d1c2e077ade0eb27c7dbTom Gundersen size_t c = 0;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek struct tevent_req *req;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek DEBUG(SSSDBG_TRACE_INTERNAL, ("sss_autofs_cmd_getautomntent\n"));
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek cmdctx = talloc_zero(client, struct autofs_cmd_ctx);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek if (!cmdctx) {
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek return ENOMEM;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek }
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek cmdctx->cctx = client;
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek actx = talloc_get_type(client->rctx->pvt_ctx, struct autofs_ctx);
798d3a524ea57aaf40cb53858aaa45ec702f012dZbigniew Jędrzejewski-Szmek if (!actx) {
eac684ef1c29684b1bcd27a89c38c202e568e469Tom Gundersen DEBUG(SSSDBG_CRIT_FAILURE, ("Missing autofs context\n"));
eac684ef1c29684b1bcd27a89c38c202e568e469Tom Gundersen return EIO;
}
/* get autofs map name and index to query */
sss_packet_get_body(client->creq->in, &body, &blen);
SAFEALIGN_COPY_UINT32_CHECK(&namelen, body+c, blen, &c);
if (namelen == 0) {
ret = EINVAL;
goto done;
}
cmdctx->mapname = (char *) body+c;
/* if not null-terminated fail */
if (cmdctx->mapname[namelen] != '\0') {
ret = EINVAL;
goto done;
}
/* If the name isn't valid UTF-8, fail */
if (!sss_utf8_check((const uint8_t *) cmdctx->mapname, namelen -1)) {
ret = EINVAL;
goto done;
}
SAFEALIGN_COPY_UINT32_CHECK(&cmdctx->cursor, body+c+namelen+1, blen, &c);
DEBUG(SSSDBG_TRACE_FUNC,
("Requested data of map %s cursor %d\n", cmdctx->mapname, cmdctx->cursor));
ret = get_autofs_map(actx, cmdctx->mapname, &map);
if (ret == ENOENT) {
DEBUG(SSSDBG_TRACE_FUNC, ("Performing implicit setautomntent\n"));
req = setautomntent_send(cmdctx, cmdctx->mapname, cmdctx);
if (req == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE, ("setautomntent_send failed\n"));
ret = EIO;
goto done;
}
tevent_req_set_callback(req, getautomntent_implicit_done, cmdctx);
ret = EOK;
goto done;
} else if (ret != EOK) {
DEBUG(SSSDBG_OP_FAILURE,
("An unexpected error occurred: [%d][%s]\n",
ret, strerror(ret)));
goto done;
}
if (map->ready == false) {
DEBUG(SSSDBG_TRACE_FUNC, ("Performing implicit setautomntent\n"));
req = setautomntent_send(cmdctx, cmdctx->mapname, cmdctx);
if (req == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE, ("setautomntent_send failed\n"));
ret = EIO;
goto done;
}
tevent_req_set_callback(req, getautomntent_implicit_done, cmdctx);
ret = EOK;
goto done;
} else if (map->found == false) {
DEBUG(SSSDBG_TRACE_FUNC, ("negative cache hit\n"));
ret = ENOENT;
goto done;
}
DEBUG(SSSDBG_TRACE_INTERNAL,
("returning entries for [%s]\n", map->mapname));
ret = getautomntent_process(cmdctx, map, cmdctx->cursor);
done:
return autofs_cmd_done(cmdctx, ret);
}
static void
getautomntent_implicit_done(struct tevent_req *req)
{
errno_t ret;
struct autofs_map_ctx *map;
struct autofs_cmd_ctx *cmdctx =
tevent_req_callback_data(req, struct autofs_cmd_ctx);
struct autofs_ctx *actx =
talloc_get_type(cmdctx->cctx->rctx->pvt_ctx, struct autofs_ctx);
ret = setautomntent_recv(req);
talloc_zfree(req);
if (ret != EOK) {
if (ret != ENOENT) {
DEBUG(SSSDBG_CRIT_FAILURE, ("setautomntent_recv failed\n"));
} else {
DEBUG(SSSDBG_MINOR_FAILURE, ("No such map\n"));
}
goto done;
}
ret = get_autofs_map(actx, cmdctx->mapname, &map);
if (ret != EOK) {
DEBUG(SSSDBG_CRIT_FAILURE,
("Cannot get map after setautomntent succeeded?\n"));
goto done;
}
if (map->ready == false) {
DEBUG(SSSDBG_CRIT_FAILURE,
("Map not ready after setautomntent succeeded\n"));
goto done;
}
ret = getautomntent_process(cmdctx, map, cmdctx->cursor);
done:
autofs_cmd_done(cmdctx, ret);
return;
}
static errno_t
getautomntent_process(struct autofs_cmd_ctx *cmdctx,
struct autofs_map_ctx *map,
uint32_t cursor)
{
struct cli_ctx *client = cmdctx->cctx;
errno_t ret;
const char *key;
size_t keylen;
const char *value;
size_t valuelen;
struct ldb_message *entry;
size_t len;
uint8_t *body;
size_t blen, rp;
/* create response packet */
ret = sss_packet_new(client->creq, 0,
sss_packet_get_cmd(client->creq->in),
&client->creq->out);
if (ret != EOK) {
return ret;
}
if (!map->map || !map->entries || !map->entries[0] ||
cursor >= map->entry_count) {
DEBUG(SSSDBG_MINOR_FAILURE, ("No entries found\n"));
ret = sss_cmd_empty_packet(client->creq->out);
if (ret != EOK) {
return autofs_cmd_done(cmdctx, ret);
}
goto done;
}
entry = map->entries[cursor];
key = ldb_msg_find_attr_as_string(entry, SYSDB_AUTOFS_ENTRY_KEY, NULL);
value = ldb_msg_find_attr_as_string(entry, SYSDB_AUTOFS_ENTRY_VALUE, NULL);
if (!key || !value) {
ret = EAGAIN;
DEBUG(SSSDBG_MINOR_FAILURE, ("Incomplete entry\n"));
goto done;
}
/* FIXME - split below into a separate function */
keylen = 1 + strlen(key);
valuelen = 1 + strlen(value);
len = sizeof(uint32_t) + sizeof(uint32_t) + keylen + sizeof(uint32_t)+ valuelen;
ret = sss_packet_grow(client->creq->out, len);
if (ret != EOK) {
goto done;
}
sss_packet_get_body(client->creq->out, &body, &blen);
rp = 0;
SAFEALIGN_SET_UINT32(&body[rp], len, &rp);
SAFEALIGN_SET_UINT32(&body[rp], keylen, &rp);
if (keylen == 1) {
body[rp] = '\0';
} else {
memcpy(&body[rp], key, keylen);
}
rp += keylen;
SAFEALIGN_SET_UINT32(&body[rp], valuelen, &rp);
if (valuelen == 1) {
body[rp] = '\0';
} else {
memcpy(&body[rp], value, valuelen);
}
rp += valuelen;
ret = EOK;
done:
sss_packet_set_error(client->creq->out, ret);
sss_cmd_done(client, cmdctx);
return EOK;
}
static errno_t
getautomntbyname_process(struct autofs_cmd_ctx *cmdctx,
struct autofs_map_ctx *map,
const char *key);
static void
getautomntbyname_implicit_done(struct tevent_req *req);
static int
sss_autofs_cmd_getautomntbyname(struct cli_ctx *client)
{
errno_t ret;
struct autofs_cmd_ctx *cmdctx;
struct autofs_map_ctx *map;
struct autofs_ctx *actx;
uint8_t *body;
size_t blen;
uint32_t namelen;
uint32_t keylen;
size_t c = 0;
struct tevent_req *req;
DEBUG(SSSDBG_TRACE_INTERNAL, ("sss_autofs_cmd_getautomntbyname\n"));
cmdctx = talloc_zero(client, struct autofs_cmd_ctx);
if (!cmdctx) {
return ENOMEM;
}
cmdctx->cctx = client;
actx = talloc_get_type(client->rctx->pvt_ctx, struct autofs_ctx);
if (!actx) {
DEBUG(SSSDBG_CRIT_FAILURE, ("Missing autofs context\n"));
return EIO;
}
/* get autofs map name and index to query */
sss_packet_get_body(client->creq->in, &body, &blen);
/* FIXME - split out a function to get string from <len><str>\0 */
SAFEALIGN_COPY_UINT32_CHECK(&namelen, body+c, blen, &c);
if (namelen == 0) {
ret = EINVAL;
goto done;
}
cmdctx->mapname = (char *) body+c;
/* if not null-terminated fail */
if (cmdctx->mapname[namelen] != '\0') {
ret = EINVAL;
goto done;
}
/* If the name isn't valid UTF-8, fail */
if (!sss_utf8_check((const uint8_t *) cmdctx->mapname, namelen -1)) {
ret = EINVAL;
goto done;
}
c += namelen + 1;
/* FIXME - split out a function to get string from <len><str>\0 */
SAFEALIGN_COPY_UINT32_CHECK(&keylen, body+c, blen, &c);
if (keylen == 0) {
ret = EINVAL;
goto done;
}
cmdctx->key = (char *) body+c;
/* if not null-terminated fail */
if (cmdctx->key[keylen] != '\0') {
ret = EINVAL;
goto done;
}
/* If the key isn't valid UTF-8, fail */
if (!sss_utf8_check((const uint8_t *) cmdctx->key, keylen -1)) {
ret = EINVAL;
goto done;
}
DEBUG(SSSDBG_TRACE_FUNC,
("Requested data of map %s key %s\n", cmdctx->mapname, cmdctx->key));
ret = get_autofs_map(actx, cmdctx->mapname, &map);
if (ret == ENOENT) {
DEBUG(SSSDBG_TRACE_FUNC, ("Performing implicit setautomntent\n"));
req = setautomntent_send(cmdctx, cmdctx->mapname, cmdctx);
if (req == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE, ("setautomntent_send failed\n"));
ret = EIO;
goto done;
}
tevent_req_set_callback(req, getautomntbyname_implicit_done, cmdctx);
ret = EOK;
goto done;
} else if (ret != EOK) {
DEBUG(SSSDBG_OP_FAILURE,
("An unexpected error occurred: [%d][%s]\n",
ret, strerror(ret)));
goto done;
}
if (map->ready == false) {
DEBUG(SSSDBG_TRACE_FUNC, ("Performing implicit setautomntent\n"));
req = setautomntent_send(cmdctx, cmdctx->mapname, cmdctx);
if (req == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE, ("setautomntent_send failed\n"));
ret = EIO;
goto done;
}
tevent_req_set_callback(req, getautomntbyname_implicit_done, cmdctx);
ret = EOK;
goto done;
} else if (map->found == false) {
DEBUG(SSSDBG_TRACE_FUNC, ("negative cache hit\n"));
ret = ENOENT;
goto done;
}
DEBUG(SSSDBG_TRACE_INTERNAL,
("Looking up value for [%s] in [%s]\n", cmdctx->key, map->mapname));
ret = getautomntbyname_process(cmdctx, map, cmdctx->key);
done:
return autofs_cmd_done(cmdctx, ret);
}
static void
getautomntbyname_implicit_done(struct tevent_req *req)
{
errno_t ret;
struct autofs_map_ctx *map;
struct autofs_cmd_ctx *cmdctx =
tevent_req_callback_data(req, struct autofs_cmd_ctx);
struct autofs_ctx *actx =
talloc_get_type(cmdctx->cctx->rctx->pvt_ctx, struct autofs_ctx);
ret = setautomntent_recv(req);
talloc_zfree(req);
if (ret != EOK) {
if (ret != ENOENT) {
DEBUG(SSSDBG_CRIT_FAILURE, ("setautomntent_recv failed\n"));
} else {
DEBUG(SSSDBG_MINOR_FAILURE, ("No such map\n"));
}
goto done;
}
ret = get_autofs_map(actx, cmdctx->mapname, &map);
if (ret != EOK) {
DEBUG(SSSDBG_CRIT_FAILURE,
("Cannot get map after setautomntent succeeded?\n"));
goto done;
}
if (map->ready == false) {
DEBUG(SSSDBG_CRIT_FAILURE,
("Map not ready after setautomntent succeeded\n"));
goto done;
}
ret = getautomntbyname_process(cmdctx, map, cmdctx->key);
done:
autofs_cmd_done(cmdctx, ret);
return;
}
static errno_t
getautomntbyname_process(struct autofs_cmd_ctx *cmdctx,
struct autofs_map_ctx *map,
const char *key)
{
struct cli_ctx *client = cmdctx->cctx;
errno_t ret;
size_t i;
const char *k;
const char *value;
size_t valuelen;
size_t len;
uint8_t *body;
size_t blen, rp;
/* create response packet */
ret = sss_packet_new(client->creq, 0,
sss_packet_get_cmd(client->creq->in),
&client->creq->out);
if (ret != EOK) {
return ret;
}
if (!map->map || !map->entries || !map->entries[0]) {
DEBUG(SSSDBG_MINOR_FAILURE, ("No entries found\n"));
ret = sss_cmd_empty_packet(client->creq->out);
if (ret != EOK) {
return autofs_cmd_done(cmdctx, ret);
}
goto done;
}
for (i=0; i < map->entry_count; i++) {
k = ldb_msg_find_attr_as_string(map->entries[i],
SYSDB_AUTOFS_ENTRY_KEY, NULL);
if (!k) {
DEBUG(SSSDBG_MINOR_FAILURE, ("Skipping incomplete entry\n"));
continue;
}
if (strcmp(k, key) == 0) {
DEBUG(SSSDBG_TRACE_INTERNAL, ("Found key [%s]\n", key));
break;
}
}
if (i >= map->entry_count) {
DEBUG(SSSDBG_MINOR_FAILURE, ("No key named [%s] found\n", key));
ret = sss_cmd_empty_packet(client->creq->out);
if (ret != EOK) {
return autofs_cmd_done(cmdctx, ret);
}
goto done;
}
value = ldb_msg_find_attr_as_string(map->entries[i],
SYSDB_AUTOFS_ENTRY_VALUE, NULL);
valuelen = 1 + strlen(value);
len = sizeof(uint32_t) + sizeof(uint32_t) + valuelen;
ret = sss_packet_grow(client->creq->out, len);
if (ret != EOK) {
goto done;
}
sss_packet_get_body(client->creq->out, &body, &blen);
rp = 0;
SAFEALIGN_SET_UINT32(&body[rp], len, &rp);
SAFEALIGN_SET_UINT32(&body[rp], valuelen, &rp);
if (valuelen == 1) {
body[rp] = '\0';
} else {
memcpy(&body[rp], value, valuelen);
}
rp += valuelen;
ret = EOK;
done:
sss_packet_set_error(client->creq->out, ret);
sss_cmd_done(client, cmdctx);
return EOK;
}
static int
sss_autofs_cmd_endautomntent(struct cli_ctx *client)
{
errno_t ret;
DEBUG(SSSDBG_TRACE_FUNC, ("endautomntent called\n"));
/* create response packet */
ret = sss_packet_new(client->creq, 0,
sss_packet_get_cmd(client->creq->in),
&client->creq->out);
if (ret != EOK) {
return ret;
}
sss_cmd_done(client, NULL);
return EOK;
}
struct cli_protocol_version *register_cli_protocol_version(void)
{
static struct cli_protocol_version autofs_cli_protocol_version[] = {
{ SSS_AUTOFS_PROTO_VERSION, NULL, NULL }
};
return autofs_cli_protocol_version;
}
struct sss_cmd_table *get_autofs_cmds(void)
{
static struct sss_cmd_table autofs_cmds[] = {
{ SSS_GET_VERSION, sss_cmd_get_version },
{ SSS_AUTOFS_SETAUTOMNTENT, sss_autofs_cmd_setautomntent },
{ SSS_AUTOFS_GETAUTOMNTENT, sss_autofs_cmd_getautomntent },
{ SSS_AUTOFS_GETAUTOMNTBYNAME, sss_autofs_cmd_getautomntbyname },
{ SSS_AUTOFS_ENDAUTOMNTENT, sss_autofs_cmd_endautomntent },
{ SSS_CLI_NULL, NULL}
};
return autofs_cmds;
}