9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek/*
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek Authors:
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek Jakub Hrozek <jhrozek@redhat.com>
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek Copyright (C) 2012 Red Hat
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek Autofs responder: commands
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek This program is free software; you can redistribute it and/or modify
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek it under the terms of the GNU General Public License as published by
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek the Free Software Foundation; either version 3 of the License, or
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek (at your option) any later version.
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek This program is distributed in the hope that it will be useful,
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek but WITHOUT ANY WARRANTY; without even the implied warranty of
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek GNU General Public License for more details.
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek You should have received a copy of the GNU General Public License
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek along with this program. If not, see <http://www.gnu.org/licenses/>.
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek*/
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek#include <talloc.h>
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek#include "util/util.h"
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek#include "responder/common/responder.h"
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek#include "responder/common/responder_packet.h"
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek#include "responder/autofs/autofs_private.h"
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek#include "db/sysdb.h"
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek#include "db/sysdb_autofs.h"
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek#include "confdb/confdb.h"
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozekstatic int autofs_cmd_send_error(struct autofs_cmd_ctx *cmdctx, int err)
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek{
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return sss_cmd_send_error(cmdctx->cctx, err);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek}
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozekstatic int
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozekautofs_cmd_send_empty(struct autofs_cmd_ctx *cmdctx)
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek{
0713b92ec9f10b6dd913dc56cbc7845d1b025ccbPavel Březina return sss_cmd_send_empty(cmdctx->cctx);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek}
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozekstatic int
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozekautofs_cmd_done(struct autofs_cmd_ctx *cmdctx, int ret)
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek{
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek switch (ret) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek case EOK:
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek /* all fine, just return here */
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek break;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek case ENOENT:
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek ret = autofs_cmd_send_empty(cmdctx);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (ret) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return EFAULT;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
0713b92ec9f10b6dd913dc56cbc7845d1b025ccbPavel Březina sss_cmd_done(cmdctx->cctx, cmdctx);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek break;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek case EAGAIN:
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek /* async processing, just return here */
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek break;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek case EFAULT:
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek /* very bad error */
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return EFAULT;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek default:
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek ret = autofs_cmd_send_error(cmdctx, ret);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (ret) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return EFAULT;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek sss_cmd_done(cmdctx->cctx, cmdctx);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek break;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return EOK;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek}
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozekstatic errno_t
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozekautofs_setent_add_ref(TALLOC_CTX *memctx,
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek struct autofs_map_ctx *map_ctx,
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek struct tevent_req *req)
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek{
e4b147ed01c8476d36ce356ee53899870d84351dPavel Březina return setent_add_ref(memctx, &map_ctx->reqs, req);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek}
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozekstatic void
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozekautofs_setent_notify(struct autofs_map_ctx *map_ctx, errno_t ret)
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek{
2cba1c86f48db866fc72738a32eecbbdcdf3dbdbJakub Hrozek setent_notify(&map_ctx->reqs, ret);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek}
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
1bcb68cc3069a6bd539289e68a87a0815aa2a1beJakub Hrozekerrno_t
1bcb68cc3069a6bd539289e68a87a0815aa2a1beJakub Hrozekautofs_orphan_maps(struct autofs_ctx *actx)
1bcb68cc3069a6bd539289e68a87a0815aa2a1beJakub Hrozek{
1bcb68cc3069a6bd539289e68a87a0815aa2a1beJakub Hrozek int hret;
1bcb68cc3069a6bd539289e68a87a0815aa2a1beJakub Hrozek unsigned long mcount;
1bcb68cc3069a6bd539289e68a87a0815aa2a1beJakub Hrozek unsigned long i;
1bcb68cc3069a6bd539289e68a87a0815aa2a1beJakub Hrozek hash_key_t *maps;
1bcb68cc3069a6bd539289e68a87a0815aa2a1beJakub Hrozek
1bcb68cc3069a6bd539289e68a87a0815aa2a1beJakub Hrozek if (!actx || !actx->maps) {
1bcb68cc3069a6bd539289e68a87a0815aa2a1beJakub Hrozek return EINVAL;
1bcb68cc3069a6bd539289e68a87a0815aa2a1beJakub Hrozek }
1bcb68cc3069a6bd539289e68a87a0815aa2a1beJakub Hrozek
1bcb68cc3069a6bd539289e68a87a0815aa2a1beJakub Hrozek hret = hash_keys(actx->maps, &mcount, &maps);
1bcb68cc3069a6bd539289e68a87a0815aa2a1beJakub Hrozek if (hret != HASH_SUCCESS) {
1bcb68cc3069a6bd539289e68a87a0815aa2a1beJakub Hrozek return EIO;
1bcb68cc3069a6bd539289e68a87a0815aa2a1beJakub Hrozek }
1bcb68cc3069a6bd539289e68a87a0815aa2a1beJakub Hrozek
1bcb68cc3069a6bd539289e68a87a0815aa2a1beJakub Hrozek for (i = 0; i < mcount; i++) {
1bcb68cc3069a6bd539289e68a87a0815aa2a1beJakub Hrozek hret = hash_delete(actx->maps, &maps[i]);
1bcb68cc3069a6bd539289e68a87a0815aa2a1beJakub Hrozek if (hret != HASH_SUCCESS) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "Could not delete key from hash\n");
1bcb68cc3069a6bd539289e68a87a0815aa2a1beJakub Hrozek continue;
1bcb68cc3069a6bd539289e68a87a0815aa2a1beJakub Hrozek }
1bcb68cc3069a6bd539289e68a87a0815aa2a1beJakub Hrozek }
1bcb68cc3069a6bd539289e68a87a0815aa2a1beJakub Hrozek
1bcb68cc3069a6bd539289e68a87a0815aa2a1beJakub Hrozek return EOK;
1bcb68cc3069a6bd539289e68a87a0815aa2a1beJakub Hrozek}
1bcb68cc3069a6bd539289e68a87a0815aa2a1beJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozekstatic errno_t
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozekget_autofs_map(struct autofs_ctx *actx,
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek char *mapname,
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek struct autofs_map_ctx **map)
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek{
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek hash_key_t key;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek hash_value_t value;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek int hret;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek key.type = HASH_KEY_STRING;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek key.str = mapname;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek hret = hash_lookup(actx->maps, &key, &value);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (hret == HASH_SUCCESS) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek *map = talloc_get_type(value.ptr, struct autofs_map_ctx);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return EOK;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek } else if (hret == HASH_ERROR_KEY_NOT_FOUND) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return ENOENT;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Unexpected error reading from autofs map hash [%d][%s]\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov hret, hash_error_string(hret));
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return EIO;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek}
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozekstatic int autofs_map_hash_remove (TALLOC_CTX *ctx);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
08c72b84d85d482f030a30cf74786695f097e91cJakub Hrozekvoid
08c72b84d85d482f030a30cf74786695f097e91cJakub Hrozekautofs_map_hash_delete_cb(hash_entry_t *item,
08c72b84d85d482f030a30cf74786695f097e91cJakub Hrozek hash_destroy_enum deltype, void *pvt)
08c72b84d85d482f030a30cf74786695f097e91cJakub Hrozek{
08c72b84d85d482f030a30cf74786695f097e91cJakub Hrozek struct autofs_map_ctx *map;
08c72b84d85d482f030a30cf74786695f097e91cJakub Hrozek
08c72b84d85d482f030a30cf74786695f097e91cJakub Hrozek if (deltype != HASH_ENTRY_DESTROY) {
08c72b84d85d482f030a30cf74786695f097e91cJakub Hrozek return;
08c72b84d85d482f030a30cf74786695f097e91cJakub Hrozek }
08c72b84d85d482f030a30cf74786695f097e91cJakub Hrozek
08c72b84d85d482f030a30cf74786695f097e91cJakub Hrozek map = talloc_get_type(item->value.ptr, struct autofs_map_ctx);
08c72b84d85d482f030a30cf74786695f097e91cJakub Hrozek if (!map) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Invalid autofs map\n");
08c72b84d85d482f030a30cf74786695f097e91cJakub Hrozek return;
08c72b84d85d482f030a30cf74786695f097e91cJakub Hrozek }
08c72b84d85d482f030a30cf74786695f097e91cJakub Hrozek
08c72b84d85d482f030a30cf74786695f097e91cJakub Hrozek /* So that the destructor wouldn't attempt to remove the map from hash
08c72b84d85d482f030a30cf74786695f097e91cJakub Hrozek * table */
08c72b84d85d482f030a30cf74786695f097e91cJakub Hrozek map->map_table = NULL;
08c72b84d85d482f030a30cf74786695f097e91cJakub Hrozek}
08c72b84d85d482f030a30cf74786695f097e91cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozekstatic errno_t
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozekset_autofs_map(struct autofs_ctx *actx,
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek struct autofs_map_ctx *map)
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek{
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek hash_key_t key;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek hash_value_t value;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek int hret;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (map->mapname == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Missing autofs map name.\n");
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return EINVAL;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek /* Add this entry to the hash table */
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek key.type = HASH_KEY_STRING;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek key.str = map->mapname;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek value.type = HASH_VALUE_PTR;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek value.ptr = map;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek hret = hash_enter(actx->maps, &key, &value);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (hret != EOK) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE,
87f8bee53ee1b4ca87b602ff8536bc5fd5b5b595Lukas Slebodnik "Unable to add hash table entry for [%s]\n", key.str);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek DEBUG(SSSDBG_MINOR_FAILURE,
87f8bee53ee1b4ca87b602ff8536bc5fd5b5b595Lukas Slebodnik "Hash error [%d][%s]\n", hret, hash_error_string(hret));
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return EIO;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek talloc_steal(actx->maps, map);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek talloc_set_destructor((TALLOC_CTX *) map, autofs_map_hash_remove);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return EOK;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek}
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozekstatic int
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozekautofs_map_hash_remove(TALLOC_CTX *ctx)
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek{
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek int hret;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek hash_key_t key;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek struct autofs_map_ctx *map =
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek talloc_get_type(ctx, struct autofs_map_ctx);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
08c72b84d85d482f030a30cf74786695f097e91cJakub Hrozek if (map->map_table == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_LIBS, "autofs map [%s] was already removed\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov map->mapname);
08c72b84d85d482f030a30cf74786695f097e91cJakub Hrozek return 0;
08c72b84d85d482f030a30cf74786695f097e91cJakub Hrozek }
08c72b84d85d482f030a30cf74786695f097e91cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek key.type = HASH_KEY_STRING;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek key.str = map->mapname;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek /* Remove the autofs map result object from the lookup table */
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek hret = hash_delete(map->map_table, &key);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (hret != HASH_SUCCESS) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Could not remove key from table! [%d][%s]\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov hret, hash_error_string(hret));
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return -1;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return 0;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek}
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozekstatic struct tevent_req *
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozeksetautomntent_send(TALLOC_CTX *mem_ctx,
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek const char *rawname,
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek struct autofs_cmd_ctx *cmdctx);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozekstatic errno_t setautomntent_recv(struct tevent_req *req);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozekstatic void sss_autofs_cmd_setautomntent_done(struct tevent_req *req);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek/* FIXME - file a ticket to have per-responder private
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek * data instead of growing the cli_ctx structure */
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozekstatic int
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozeksss_autofs_cmd_setautomntent(struct cli_ctx *client)
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek{
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek struct autofs_cmd_ctx *cmdctx;
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce struct cli_protocol *pctx;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek uint8_t *body;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek size_t blen;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek errno_t ret = EOK;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek const char *rawname;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek struct tevent_req *req;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_INTERNAL, "sss_autofs_cmd_setautomntent\n");
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek cmdctx = talloc_zero(client, struct autofs_cmd_ctx);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (!cmdctx) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return ENOMEM;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek cmdctx->cctx = client;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce pctx = talloc_get_type(cmdctx->cctx->protocol_ctx, struct cli_protocol);
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce sss_packet_get_body(pctx->creq->in, &body, &blen);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek /* if not terminated fail */
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (body[blen -1] != '\0') {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek ret = EINVAL;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek goto done;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek /* If the body isn't valid UTF-8, fail */
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (!sss_utf8_check(body, blen -1)) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek ret = EINVAL;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek goto done;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek rawname = (const char *)body;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek DEBUG(SSSDBG_TRACE_FUNC,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Got request for automount map named %s\n", rawname);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek req = setautomntent_send(cmdctx, rawname, cmdctx);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (!req) {
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Fatal error calling setautomntent_send\n");
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek ret = EIO;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek goto done;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek tevent_req_set_callback(req, sss_autofs_cmd_setautomntent_done, cmdctx);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek ret = EOK;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozekdone:
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return autofs_cmd_done(cmdctx, ret);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek}
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozekstatic void sss_autofs_cmd_setautomntent_done(struct tevent_req *req)
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek{
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek struct autofs_cmd_ctx *cmdctx =
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek tevent_req_callback_data(req, struct autofs_cmd_ctx);
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce struct cli_protocol *pctx;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek errno_t ret;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek errno_t reqret;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek uint8_t *body;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek size_t blen;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_INTERNAL, "setautomntent done\n");
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek reqret = setautomntent_recv(req);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek talloc_zfree(req);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (reqret != EOK && reqret != ENOENT) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "setautomntent_recv failed\n");
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek autofs_cmd_done(cmdctx, reqret);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce pctx = talloc_get_type(cmdctx->cctx->protocol_ctx, struct cli_protocol);
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek /* Either we succeeded or no domains were eligible */
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce ret = sss_packet_new(pctx->creq, 0,
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce sss_packet_get_cmd(pctx->creq->in),
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce &pctx->creq->out);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (ret == EOK) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (reqret == ENOENT) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "setautomntent did not find requested map\n");
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek /* Notify the caller that this entry wasn't found */
51ce94d00a61f205ba727a3849835c269e568c41Fabiano Fidêncio ret = sss_cmd_empty_packet(pctx->creq->out);
51ce94d00a61f205ba727a3849835c269e568c41Fabiano Fidêncio if (ret != EOK) {
51ce94d00a61f205ba727a3849835c269e568c41Fabiano Fidêncio DEBUG(SSSDBG_TRACE_INTERNAL,
51ce94d00a61f205ba727a3849835c269e568c41Fabiano Fidêncio "sss_cmd_empty_packet() failed: %s [%d]\n",
51ce94d00a61f205ba727a3849835c269e568c41Fabiano Fidêncio sss_strerror(ret), ret);
51ce94d00a61f205ba727a3849835c269e568c41Fabiano Fidêncio }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek } else {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "setautomntent found data\n");
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce ret = sss_packet_grow(pctx->creq->out, 2*sizeof(uint32_t));
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Couldn't grow the packet\n");
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek talloc_free(cmdctx);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce sss_packet_get_body(pctx->creq->out, &body, &blen);
d8057ec487e452038f0106042021fa612bbb8555Michal Zidek
d8057ec487e452038f0106042021fa612bbb8555Michal Zidek /* Got some results */
d8057ec487e452038f0106042021fa612bbb8555Michal Zidek SAFEALIGN_SETMEM_UINT32(body, 1, NULL);
d8057ec487e452038f0106042021fa612bbb8555Michal Zidek
d8057ec487e452038f0106042021fa612bbb8555Michal Zidek /* Reserved padding */
d8057ec487e452038f0106042021fa612bbb8555Michal Zidek SAFEALIGN_SETMEM_UINT32(body + sizeof(uint32_t), 0, NULL);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek sss_cmd_done(cmdctx->cctx, NULL);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Error creating packet\n");
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek}
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozekstruct setautomntent_state {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek struct autofs_cmd_ctx *cmdctx;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek struct autofs_dom_ctx *dctx;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek char *mapname;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek struct autofs_map_ctx *map;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek};
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozekstruct setautomntent_lookup_ctx {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek struct autofs_ctx *actx;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek struct autofs_dom_ctx *dctx;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek struct resp_ctx *rctx;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek struct cli_ctx *cctx;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek bool returned_to_mainloop;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek char *mapname;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek struct autofs_map_ctx *map;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek};
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozekstatic errno_t
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozeklookup_automntmap_step(struct setautomntent_lookup_ctx *lookup_ctx);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozekstatic void
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozekautofs_map_result_timeout(struct tevent_context *ev,
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek struct tevent_timer *te,
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek struct timeval current_time,
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek void *pvt)
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek{
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek struct autofs_map_ctx *map =
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek talloc_get_type(pvt, struct autofs_map_ctx);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek /* Free the autofs map result context
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek * The destructor for the autofs map will remove itself
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek * from the hash table
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek */
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek talloc_free(map);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek}
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozekstatic void
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozekset_autofs_map_lifetime(uint32_t lifetime,
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek struct setautomntent_lookup_ctx *lookup_ctx,
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek struct autofs_map_ctx *map)
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek{
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek struct timeval tv;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek struct tevent_timer *te;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek tv = tevent_timeval_current_ofs(lifetime, 0);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek te = tevent_add_timer(lookup_ctx->rctx->ev,
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek lookup_ctx->rctx, tv,
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek autofs_map_result_timeout,
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek map);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (!te) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Could not set up life timer for autofs maps. "
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Entries may become stale.\n");
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek}
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
1bcb68cc3069a6bd539289e68a87a0815aa2a1beJakub Hrozekstatic errno_t
1bcb68cc3069a6bd539289e68a87a0815aa2a1beJakub Hrozeksetautomntent_get_autofs_map(struct autofs_ctx *actx,
1bcb68cc3069a6bd539289e68a87a0815aa2a1beJakub Hrozek char *mapname,
1bcb68cc3069a6bd539289e68a87a0815aa2a1beJakub Hrozek struct autofs_map_ctx **map);
1bcb68cc3069a6bd539289e68a87a0815aa2a1beJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozekstatic struct tevent_req *
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozeksetautomntent_send(TALLOC_CTX *mem_ctx,
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek const char *rawname,
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek struct autofs_cmd_ctx *cmdctx)
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek{
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek char *domname;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek errno_t ret;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek struct tevent_req *req;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek struct setautomntent_state *state;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek struct cli_ctx *client = cmdctx->cctx;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek struct autofs_dom_ctx *dctx;
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce struct autofs_ctx *actx;
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce struct autofs_state_ctx *state_ctx;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek struct setautomntent_lookup_ctx *lookup_ctx;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce actx = talloc_get_type(client->rctx->pvt_ctx, struct autofs_ctx);
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce state_ctx = talloc_get_type(client->state_ctx, struct autofs_state_ctx);
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek req = tevent_req_create(mem_ctx, &state, struct setautomntent_state);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (!req) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek DEBUG(SSSDBG_FATAL_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Could not create tevent request for setautomntent\n");
5f93f452e4a80d6b0243eaf3c583d0caf9981ca0Jakub Hrozek return NULL;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek state->cmdctx = cmdctx;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek dctx = talloc_zero(state, struct autofs_dom_ctx);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (!dctx) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_FATAL_FAILURE, "Out of memory\n");
5f93f452e4a80d6b0243eaf3c583d0caf9981ca0Jakub Hrozek ret = ENOMEM;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek goto fail;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek dctx->cmd_ctx = state->cmdctx;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek state->dctx = dctx;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
1542b85f13d72329685bdd97aa879c36d11f81beSumit Bose ret = sss_parse_name_for_domains(state, client->rctx->domains,
620cbbcadd42627e55210045cac66c66df4f1243Aron Parsons NULL, rawname,
3c60433641ce2e86b9b04778c8f8652ef0d097e4Stef Walter &domname, &state->mapname);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (ret != EOK) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek DEBUG(SSSDBG_FATAL_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Invalid name received [%s]\n", rawname);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek goto fail;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek DEBUG(SSSDBG_TRACE_FUNC,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Requesting info for automount map [%s] from [%s]\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov state->mapname, domname?domname:"<ALL>");
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (domname) {
4668b4765530cf37289235e483f301100cc1ae21Sumit Bose dctx->domain = responder_get_domain(client->rctx, domname);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (!dctx->domain) {
5f93f452e4a80d6b0243eaf3c583d0caf9981ca0Jakub Hrozek ret = EINVAL;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek goto fail;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce state_ctx->automntmap_name = talloc_strdup(client, rawname);
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce if (!state_ctx->automntmap_name) {
5f93f452e4a80d6b0243eaf3c583d0caf9981ca0Jakub Hrozek ret = ENOMEM;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek goto fail;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek } else {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek /* this is a multidomain search */
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek dctx->domain = client->rctx->domains;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek cmdctx->check_next = true;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce state_ctx->automntmap_name = talloc_strdup(client, state->mapname);
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce if (!state_ctx->automntmap_name) {
5f93f452e4a80d6b0243eaf3c583d0caf9981ca0Jakub Hrozek ret = ENOMEM;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek goto fail;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek dctx->check_provider = NEED_CHECK_PROVIDER(dctx->domain->provider);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek /* Is the result context already available?
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek * Check for existing lookups for this map
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek */
1bcb68cc3069a6bd539289e68a87a0815aa2a1beJakub Hrozek ret = setautomntent_get_autofs_map(actx, state->mapname, &state->map);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (ret == EOK) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek /* Another process already requested this map
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek * Check whether it's ready for processing.
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek */
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (state->map->ready) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (state->map->found) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek DEBUG(SSSDBG_TRACE_LIBS,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Map %s is ready to be processed\n", state->mapname);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek tevent_req_done(req);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek tevent_req_post(req, actx->rctx->ev);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return req;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek } else {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek DEBUG(SSSDBG_TRACE_LIBS,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Map %s was marked as nonexistent\n", state->mapname);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek tevent_req_error(req, ENOENT);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek tevent_req_post(req, actx->rctx->ev);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return req;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek /* Result object is still being constructed
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek * Register for notification when it's ready
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek */
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek DEBUG(SSSDBG_TRACE_LIBS,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Map %s is being looked up, registering for notification\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov state->mapname);
129310e872a0a70e721ba59363e518176ef406d6Jakub Hrozek ret = autofs_setent_add_ref(state, state->map, req);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (ret != EOK) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek goto fail;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek /* Will return control below */
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek } else if (ret == ENOENT) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek DEBUG(SSSDBG_TRACE_LIBS,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Map %s needs to be looked up\n", state->mapname);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek state->map = talloc_zero(actx, struct autofs_map_ctx);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (!state->map) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek ret = ENOMEM;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek goto fail;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek dctx->map_ctx = state->map;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek state->map->mapname = talloc_strdup(state->map, state->mapname);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (!state->map->mapname) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek talloc_free(state->map);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek ret = ENOMEM;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek goto fail;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek state->map->map_table = actx->maps;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
129310e872a0a70e721ba59363e518176ef406d6Jakub Hrozek ret = autofs_setent_add_ref(state, state->map, req);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (ret != EOK) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek talloc_free(state->map);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek goto fail;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek ret = set_autofs_map(actx, state->map);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (ret != EOK) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek talloc_free(state->map);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek goto fail;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek /* Perform lookup */
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek lookup_ctx = talloc_zero(state->map, struct setautomntent_lookup_ctx);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (!lookup_ctx) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek talloc_free(state->map);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek ret = ENOMEM;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek goto fail;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek /* Steal the dom_ctx onto the lookup_ctx so it doesn't go out of scope if
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek * this request is canceled while other requests are in-progress.
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek */
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek lookup_ctx->dctx = talloc_steal(lookup_ctx, state->dctx);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek lookup_ctx->actx = actx;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek lookup_ctx->map = state->map;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek lookup_ctx->rctx = client->rctx;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek lookup_ctx->mapname =
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek talloc_strdup(lookup_ctx, state->mapname);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (!lookup_ctx->mapname) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek talloc_free(state->map);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek ret = ENOMEM;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek goto fail;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek ret = lookup_automntmap_step(lookup_ctx);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (ret == EAGAIN) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_INTERNAL, "lookup_automntmap_step "
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "is refreshing the cache, re-entering the mainloop\n");
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return req;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek } else if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Could not get data from cache\n");
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek talloc_free(state->map);
5f93f452e4a80d6b0243eaf3c583d0caf9981ca0Jakub Hrozek ret = ENOMEM;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek goto fail;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek tevent_req_done(req);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek tevent_req_post(req, cmdctx->cctx->ev);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return req;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek } else {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Unexpected error from get_autofs_map [%d]: %s\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret, strerror(ret));
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek goto fail;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return req;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozekfail:
5f93f452e4a80d6b0243eaf3c583d0caf9981ca0Jakub Hrozek tevent_req_error(req, ret);
5f93f452e4a80d6b0243eaf3c583d0caf9981ca0Jakub Hrozek tevent_req_post(req, actx->rctx->ev);
5f93f452e4a80d6b0243eaf3c583d0caf9981ca0Jakub Hrozek return req;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek}
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
1bcb68cc3069a6bd539289e68a87a0815aa2a1beJakub Hrozekstatic errno_t
1bcb68cc3069a6bd539289e68a87a0815aa2a1beJakub Hrozeksetautomntent_get_autofs_map(struct autofs_ctx *actx,
1bcb68cc3069a6bd539289e68a87a0815aa2a1beJakub Hrozek char *mapname,
1bcb68cc3069a6bd539289e68a87a0815aa2a1beJakub Hrozek struct autofs_map_ctx **map)
1bcb68cc3069a6bd539289e68a87a0815aa2a1beJakub Hrozek{
1bcb68cc3069a6bd539289e68a87a0815aa2a1beJakub Hrozek errno_t ret;
1bcb68cc3069a6bd539289e68a87a0815aa2a1beJakub Hrozek
1bcb68cc3069a6bd539289e68a87a0815aa2a1beJakub Hrozek if (strcmp(mapname, "auto.master") == 0) {
1bcb68cc3069a6bd539289e68a87a0815aa2a1beJakub Hrozek /* Iterate over the hash and remove all maps */
1bcb68cc3069a6bd539289e68a87a0815aa2a1beJakub Hrozek ret = autofs_orphan_maps(actx);
1bcb68cc3069a6bd539289e68a87a0815aa2a1beJakub Hrozek if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "Could not remove existing maps from hash\n");
1bcb68cc3069a6bd539289e68a87a0815aa2a1beJakub Hrozek }
1bcb68cc3069a6bd539289e68a87a0815aa2a1beJakub Hrozek return ENOENT;
1bcb68cc3069a6bd539289e68a87a0815aa2a1beJakub Hrozek }
1bcb68cc3069a6bd539289e68a87a0815aa2a1beJakub Hrozek
1bcb68cc3069a6bd539289e68a87a0815aa2a1beJakub Hrozek return get_autofs_map(actx, mapname, map);
1bcb68cc3069a6bd539289e68a87a0815aa2a1beJakub Hrozek}
1bcb68cc3069a6bd539289e68a87a0815aa2a1beJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozekstatic errno_t
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozeklookup_automntmap_update_cache(struct setautomntent_lookup_ctx *lookup_ctx);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozekstatic errno_t
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozeklookup_automntmap_step(struct setautomntent_lookup_ctx *lookup_ctx)
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek{
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek errno_t ret;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek struct sss_domain_info *dom = lookup_ctx->dctx->domain;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek struct autofs_dom_ctx *dctx = lookup_ctx->dctx;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek struct sysdb_ctx *sysdb;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek struct autofs_map_ctx *map;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek /* Check each domain for this map name */
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek while (dom) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (dom != dctx->domain) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek /* make sure we reset the check_provider flag when we check
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek * a new domain */
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek dctx->check_provider =
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek NEED_CHECK_PROVIDER(dom->provider);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek /* make sure to update the dctx if we changed domain */
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek dctx->domain = dom;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "Requesting info for [%s@%s]\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov lookup_ctx->mapname, dom->name);
b7b50b21d2254a079b1b1c299909483d23db1512Sumit Bose sysdb = dom->sysdb;
b7b50b21d2254a079b1b1c299909483d23db1512Sumit Bose if (sysdb == NULL) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek DEBUG(SSSDBG_FATAL_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Fatal: Sysdb CTX not found for this domain!\n");
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return EIO;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek /* Look into the cache */
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek talloc_free(dctx->map);
e7d1cd14ce1a427007b1a7e9789dcb7e9619f84fJakub Hrozek ret = sysdb_get_map_byname(dctx, dom, lookup_ctx->mapname,
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek &dctx->map);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (ret != EOK && ret != ENOENT) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Could not check cache\n");
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return ret;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek } else if (ret == ENOENT) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek DEBUG(SSSDBG_MINOR_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "No automount map [%s] in cache for domain [%s]\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov lookup_ctx->mapname, dom->name);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (!dctx->check_provider) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (dctx->cmd_ctx->check_next) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_INTERNAL, "Moving on to next domain\n");
877b92e80bde510d5cd9f03dbf01e2bcf73ab072Michal Židek dom = get_next_domain(dom, 0);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek continue;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek else break;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek ret = get_autofs_map(lookup_ctx->actx, lookup_ctx->mapname, &map);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (ret != EOK) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek /* Something really bad happened! */
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Autofs map entry was lost!\n");
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return ret;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (dctx->map == NULL && !dctx->check_provider) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek DEBUG(SSSDBG_MINOR_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Autofs map not found, setting negative cache\n");
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek map->ready = true;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek map->found = false;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek set_autofs_map_lifetime(lookup_ctx->actx->neg_timeout, lookup_ctx, map);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return ENOENT;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (dctx->check_provider) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek ret = lookup_automntmap_update_cache(lookup_ctx);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (ret == EAGAIN) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek DEBUG(SSSDBG_TRACE_INTERNAL,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Looking up automount maps from the DP\n");
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return EAGAIN;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek } else if (ret != EOK) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Error looking up automount maps [%d]: %s\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret, strerror(ret));
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return ret;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek /* OK, the map is in cache and valid.
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek * Let's get all members and return it
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek */
e7d1cd14ce1a427007b1a7e9789dcb7e9619f84fJakub Hrozek ret = sysdb_autofs_entries_by_map(map, dom, map->mapname,
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek &map->entry_count,
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek &map->entries);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (ret != EOK && ret != ENOENT) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Error looking automount map entries [%d]: %s\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret, strerror(ret));
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek map->ready = true;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek map->found = false;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek set_autofs_map_lifetime(lookup_ctx->actx->neg_timeout, lookup_ctx, map);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return EIO;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek map->map = talloc_steal(map, dctx->map);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek DEBUG(SSSDBG_TRACE_FUNC,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "setautomntent done for map %s\n", lookup_ctx->mapname);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek map->ready = true;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek map->found = true;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek set_autofs_map_lifetime(dom->autofsmap_timeout, lookup_ctx, map);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return EOK;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek map = talloc_zero(lookup_ctx->actx, struct autofs_map_ctx);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (!map) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return ENOMEM;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek map->ready = true;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek map->found = false;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek map->map_table = lookup_ctx->actx->maps;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek map->mapname = talloc_strdup(map, lookup_ctx->mapname);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (!map->mapname) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek talloc_free(map);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return ENOMEM;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek ret = set_autofs_map(lookup_ctx->actx, map);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (ret != EOK) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek talloc_free(map);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return ENOMEM;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek set_autofs_map_lifetime(lookup_ctx->actx->neg_timeout, lookup_ctx, map);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek /* If we've gotten here, then no domain contained this map */
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return ENOENT;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek}
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozekstatic void lookup_automntmap_cache_updated(uint16_t err_maj, uint32_t err_min,
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek const char *err_msg, void *ptr);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozekstatic void autofs_dp_send_map_req_done(struct tevent_req *req);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozekstatic errno_t
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozeklookup_automntmap_update_cache(struct setautomntent_lookup_ctx *lookup_ctx)
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek{
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek errno_t ret;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek uint64_t cache_expire = 0;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek struct autofs_dom_ctx *dctx = lookup_ctx->dctx;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek struct tevent_req *req = NULL;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek struct dp_callback_ctx *cb_ctx = NULL;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (dctx->map != NULL) {
1bcb68cc3069a6bd539289e68a87a0815aa2a1beJakub Hrozek if (strcmp(lookup_ctx->mapname, "auto.master") != 0) {
1bcb68cc3069a6bd539289e68a87a0815aa2a1beJakub Hrozek cache_expire = ldb_msg_find_attr_as_uint64(dctx->map,
1bcb68cc3069a6bd539289e68a87a0815aa2a1beJakub Hrozek SYSDB_CACHE_EXPIRE, 0);
1bcb68cc3069a6bd539289e68a87a0815aa2a1beJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek /* if we have any reply let's check cache validity */
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek ret = sss_cmd_check_cache(dctx->map, 0, cache_expire);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (ret == EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "Cached entry is valid, returning..\n");
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return EOK;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek } else if (ret != EAGAIN && ret != ENOENT) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Error checking cache: %d\n", ret);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek goto error;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek /* dont loop forever :-) */
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek dctx->check_provider = false;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek /* keep around current data in case backend is offline */
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek /* FIXME - do this by default */
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek#if 0
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (dctx->res->count) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek dctx->res = talloc_steal(dctx, dctx->res);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek#endif
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek req = sss_dp_get_autofs_send(lookup_ctx->cctx, lookup_ctx->rctx,
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek lookup_ctx->dctx->domain, true,
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek SSS_DP_AUTOFS, lookup_ctx->mapname);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (!req) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Out of memory sending data provider request\n");
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek ret = ENOMEM;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek goto error;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek cb_ctx = talloc_zero(lookup_ctx->dctx, struct dp_callback_ctx);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if(!cb_ctx) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek talloc_zfree(req);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek ret = ENOMEM;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek goto error;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek cb_ctx->callback = lookup_automntmap_cache_updated;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek cb_ctx->ptr = lookup_ctx;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek cb_ctx->cctx = lookup_ctx->dctx->cmd_ctx->cctx;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek cb_ctx->mem_ctx = lookup_ctx->dctx;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek tevent_req_set_callback(req, autofs_dp_send_map_req_done, cb_ctx);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return EAGAIN;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozekerror:
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek ret = autofs_cmd_send_error(lookup_ctx->dctx->cmd_ctx, ret);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Fatal error, killing connection!\n");
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek talloc_free(lookup_ctx->cctx);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return ret;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek autofs_cmd_done(lookup_ctx->dctx->cmd_ctx, ret);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return EOK;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek}
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozekstatic void autofs_dp_send_map_req_done(struct tevent_req *req)
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek{
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek struct dp_callback_ctx *cb_ctx =
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek tevent_req_callback_data(req, struct dp_callback_ctx);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek struct setautomntent_lookup_ctx *lookup_ctx =
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek talloc_get_type(cb_ctx->ptr, struct setautomntent_lookup_ctx);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek errno_t ret;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek dbus_uint16_t err_maj;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek dbus_uint32_t err_min;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek char *err_msg;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek ret = sss_dp_get_autofs_recv(cb_ctx->mem_ctx, req,
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek &err_maj, &err_min,
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek &err_msg);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek talloc_free(req);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Fatal error, killing connection!\n");
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek talloc_free(lookup_ctx->cctx);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek cb_ctx->callback(err_maj, err_min, err_msg, cb_ctx->ptr);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek}
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozekstatic void lookup_automntmap_cache_updated(uint16_t err_maj, uint32_t err_min,
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek const char *err_msg, void *ptr)
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek{
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek struct setautomntent_lookup_ctx *lookup_ctx =
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek talloc_get_type(ptr, struct setautomntent_lookup_ctx);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek struct autofs_dom_ctx *dctx = lookup_ctx->dctx;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek errno_t ret;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (err_maj) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Unable to get information from Data Provider\n"
b9e155da725e711ab306ca8a96e3ba6fbda41a3aJakub Hrozek "Error: %u, %u, %s\n"
b9e155da725e711ab306ca8a96e3ba6fbda41a3aJakub Hrozek "Will try to return what we have in cache\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov (unsigned int)err_maj, (unsigned int)err_min, err_msg);
b9e155da725e711ab306ca8a96e3ba6fbda41a3aJakub Hrozek
b9e155da725e711ab306ca8a96e3ba6fbda41a3aJakub Hrozek /* Try to fall back to cache */
b9e155da725e711ab306ca8a96e3ba6fbda41a3aJakub Hrozek ret = lookup_automntmap_step(lookup_ctx);
b9e155da725e711ab306ca8a96e3ba6fbda41a3aJakub Hrozek if (ret == EOK) {
b9e155da725e711ab306ca8a96e3ba6fbda41a3aJakub Hrozek /* We have cached results to return */
b9e155da725e711ab306ca8a96e3ba6fbda41a3aJakub Hrozek autofs_setent_notify(lookup_ctx->map, ret);
b9e155da725e711ab306ca8a96e3ba6fbda41a3aJakub Hrozek return;
b9e155da725e711ab306ca8a96e3ba6fbda41a3aJakub Hrozek }
b9e155da725e711ab306ca8a96e3ba6fbda41a3aJakub Hrozek
b9e155da725e711ab306ca8a96e3ba6fbda41a3aJakub Hrozek /* Otherwise try the next domain */
e563de9203be581acc30c7794f568ae40d22bee0Michal Židek if (dctx->cmd_ctx->check_next
e563de9203be581acc30c7794f568ae40d22bee0Michal Židek && (dctx->domain = get_next_domain(dctx->domain, 0))) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek dctx->check_provider = NEED_CHECK_PROVIDER(dctx->domain->provider);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek ret = lookup_automntmap_step(lookup_ctx);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (ret != EOK) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (ret == EAGAIN) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek /* We have results to return */
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek autofs_setent_notify(lookup_ctx->map, ret);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek}
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozekstatic errno_t
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozeksetautomntent_recv(struct tevent_req *req)
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek{
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek TEVENT_REQ_RETURN_ON_ERROR(req);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return EOK;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek}
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozekstatic errno_t
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozekgetautomntent_process(struct autofs_cmd_ctx *cmdctx,
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek struct autofs_map_ctx *map,
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozek uint32_t cursor, uint32_t max_entries);
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozekstatic void
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozekgetautomntent_implicit_done(struct tevent_req *req);
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozekstatic errno_t
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozekfill_autofs_entry(struct ldb_message *entry, struct sss_packet *packet, size_t *rp);
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozekstatic int
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozeksss_autofs_cmd_getautomntent(struct cli_ctx *client)
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek{
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek struct autofs_cmd_ctx *cmdctx;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek struct autofs_map_ctx *map;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek struct autofs_ctx *actx;
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce struct cli_protocol *pctx;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek uint8_t *body;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek size_t blen;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek errno_t ret;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek uint32_t namelen;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek size_t c = 0;
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek struct tevent_req *req;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_INTERNAL, "sss_autofs_cmd_getautomntent\n");
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek cmdctx = talloc_zero(client, struct autofs_cmd_ctx);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (!cmdctx) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return ENOMEM;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek cmdctx->cctx = client;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek actx = talloc_get_type(client->rctx->pvt_ctx, struct autofs_ctx);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (!actx) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Missing autofs context\n");
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return EIO;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce pctx = talloc_get_type(cmdctx->cctx->protocol_ctx, struct cli_protocol);
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek /* get autofs map name and index to query */
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce sss_packet_get_body(pctx->creq->in, &body, &blen);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek SAFEALIGN_COPY_UINT32_CHECK(&namelen, body+c, blen, &c);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
2bd514cfde1938b1e245af11c9b548d58d49b325Jan Cholasta if (namelen == 0 || namelen > blen - c) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek ret = EINVAL;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek goto done;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek cmdctx->mapname = (char *) body+c;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek /* if not null-terminated fail */
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek if (cmdctx->mapname[namelen] != '\0') {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek ret = EINVAL;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek goto done;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek /* If the name isn't valid UTF-8, fail */
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek if (!sss_utf8_check((const uint8_t *) cmdctx->mapname, namelen -1)) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek ret = EINVAL;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek goto done;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek SAFEALIGN_COPY_UINT32_CHECK(&cmdctx->cursor, body+c+namelen+1, blen, &c);
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozek SAFEALIGN_COPY_UINT32_CHECK(&cmdctx->max_entries, body+c+namelen+1, blen, &c);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek DEBUG(SSSDBG_TRACE_FUNC,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Requested data of map %s cursor %d max entries %d\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov cmdctx->mapname, cmdctx->cursor, cmdctx->max_entries);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek ret = get_autofs_map(actx, cmdctx->mapname, &map);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (ret == ENOENT) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "Performing implicit setautomntent\n");
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek req = setautomntent_send(cmdctx, cmdctx->mapname, cmdctx);
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek if (req == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "setautomntent_send failed\n");
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek ret = EIO;
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek goto done;
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek }
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek tevent_req_set_callback(req, getautomntent_implicit_done, cmdctx);
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek ret = EOK;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek goto done;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek } else if (ret != EOK) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "An unexpected error occurred: [%d][%s]\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret, strerror(ret));
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek goto done;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (map->ready == false) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "Performing implicit setautomntent\n");
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek req = setautomntent_send(cmdctx, cmdctx->mapname, cmdctx);
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek if (req == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "setautomntent_send failed\n");
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek ret = EIO;
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek goto done;
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek }
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek tevent_req_set_callback(req, getautomntent_implicit_done, cmdctx);
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek ret = EOK;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek goto done;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek } else if (map->found == false) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "negative cache hit\n");
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek ret = ENOENT;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek goto done;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek DEBUG(SSSDBG_TRACE_INTERNAL,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "returning entries for [%s]\n", map->mapname);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozek ret = getautomntent_process(cmdctx, map, cmdctx->cursor, cmdctx->max_entries);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozekdone:
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return autofs_cmd_done(cmdctx, ret);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek}
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozekstatic void
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozekgetautomntent_implicit_done(struct tevent_req *req)
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek{
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek errno_t ret;
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek struct autofs_map_ctx *map;
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek struct autofs_cmd_ctx *cmdctx =
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek tevent_req_callback_data(req, struct autofs_cmd_ctx);
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek struct autofs_ctx *actx =
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek talloc_get_type(cmdctx->cctx->rctx->pvt_ctx, struct autofs_ctx);
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek ret = setautomntent_recv(req);
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek talloc_zfree(req);
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek if (ret != EOK) {
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek if (ret != ENOENT) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "setautomntent_recv failed\n");
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek } else {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "No such map\n");
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek }
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek goto done;
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek }
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek ret = get_autofs_map(actx, cmdctx->mapname, &map);
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek if (ret != EOK) {
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Cannot get map after setautomntent succeeded?\n");
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek goto done;
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek }
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek if (map->ready == false) {
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Map not ready after setautomntent succeeded\n");
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek goto done;
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek }
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozek ret = getautomntent_process(cmdctx, map,
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozek cmdctx->cursor, cmdctx->max_entries);
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozekdone:
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek autofs_cmd_done(cmdctx, ret);
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek return;
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek}
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozekstatic errno_t
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozekgetautomntent_process(struct autofs_cmd_ctx *cmdctx,
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek struct autofs_map_ctx *map,
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozek uint32_t cursor, uint32_t max_entries)
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek{
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce struct cli_protocol *pctx;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek errno_t ret;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek struct ldb_message *entry;
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozek size_t rp;
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozek uint32_t i, stop, left, nentries;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek uint8_t *body;
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozek size_t blen;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce pctx = talloc_get_type(cmdctx->cctx->protocol_ctx, struct cli_protocol);
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek /* create response packet */
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce ret = sss_packet_new(pctx->creq, 0,
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce sss_packet_get_cmd(pctx->creq->in),
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce &pctx->creq->out);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (ret != EOK) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return ret;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (!map->map || !map->entries || !map->entries[0] ||
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek cursor >= map->entry_count) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "No entries found\n");
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce ret = sss_cmd_empty_packet(pctx->creq->out);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (ret != EOK) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return autofs_cmd_done(cmdctx, ret);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek goto done;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozek
cd2327153a9ac55f3cf470c294691506096bd1ebPavel Březina /* allocate memory for number of entries in the packet */
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce ret = sss_packet_grow(pctx->creq->out, sizeof(uint32_t));
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozek if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Cannot grow packet\n");
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozek goto done;
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozek }
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozek
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozek rp = sizeof(uint32_t); /* We'll write the number of entries here */
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozek
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozek left = map->entry_count - cursor;
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozek stop = max_entries < left ? max_entries : left;
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozek
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozek nentries = 0;
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozek for (i=0; i < stop; i++) {
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozek entry = map->entries[cursor];
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozek cursor++;
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozek
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce ret = fill_autofs_entry(entry, pctx->creq->out, &rp);
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozek if (ret != EOK) {
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozek DEBUG(SSSDBG_MINOR_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Cannot fill entry %d/%d, skipping\n", i, stop);
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozek continue;
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozek }
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozek nentries++;
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozek }
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozek
cd2327153a9ac55f3cf470c294691506096bd1ebPavel Březina /* packet grows in fill_autofs_entry, body pointer may change,
cd2327153a9ac55f3cf470c294691506096bd1ebPavel Březina * thus we have to obtain it here */
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce sss_packet_get_body(pctx->creq->out, &body, &blen);
cd2327153a9ac55f3cf470c294691506096bd1ebPavel Březina
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozek rp = 0;
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozek SAFEALIGN_SET_UINT32(&body[rp], nentries, &rp);
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozek
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozek ret = EOK;
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozekdone:
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce sss_packet_set_error(pctx->creq->out, ret);
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce sss_cmd_done(cmdctx->cctx, cmdctx);
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozek
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozek return EOK;
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozek}
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozek
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozekstatic errno_t
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozekfill_autofs_entry(struct ldb_message *entry, struct sss_packet *packet, size_t *rp)
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozek{
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozek errno_t ret;
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozek const char *key;
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozek size_t keylen;
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozek const char *value;
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozek size_t valuelen;
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozek uint8_t *body;
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozek size_t blen;
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozek size_t len;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek key = ldb_msg_find_attr_as_string(entry, SYSDB_AUTOFS_ENTRY_KEY, NULL);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek value = ldb_msg_find_attr_as_string(entry, SYSDB_AUTOFS_ENTRY_VALUE, NULL);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (!key || !value) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "Incomplete entry\n");
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozek return EINVAL;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek keylen = 1 + strlen(key);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek valuelen = 1 + strlen(value);
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozek len = sizeof(uint32_t) + sizeof(uint32_t) + keylen + sizeof(uint32_t) + valuelen;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozek ret = sss_packet_grow(packet, len);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_OP_FAILURE, "Cannot grow packet\n");
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozek return ret;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozek sss_packet_get_body(packet, &body, &blen);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozek SAFEALIGN_SET_UINT32(&body[*rp], len, rp);
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozek SAFEALIGN_SET_UINT32(&body[*rp], keylen, rp);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (keylen == 1) {
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozek body[*rp] = '\0';
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek } else {
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozek memcpy(&body[*rp], key, keylen);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozek *rp += keylen;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozek SAFEALIGN_SET_UINT32(&body[*rp], valuelen, rp);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (valuelen == 1) {
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozek body[*rp] = '\0';
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek } else {
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozek memcpy(&body[*rp], value, valuelen);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
c83ebdbc0629313ef6594215ed1674b9a783cfddJakub Hrozek *rp += valuelen;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return EOK;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek}
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozekstatic errno_t
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozekgetautomntbyname_process(struct autofs_cmd_ctx *cmdctx,
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek struct autofs_map_ctx *map,
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek const char *key);
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozekstatic void
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozekgetautomntbyname_implicit_done(struct tevent_req *req);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozekstatic int
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozeksss_autofs_cmd_getautomntbyname(struct cli_ctx *client)
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek{
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek errno_t ret;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek struct autofs_cmd_ctx *cmdctx;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek struct autofs_map_ctx *map;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek struct autofs_ctx *actx;
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce struct cli_protocol *pctx;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek uint8_t *body;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek size_t blen;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek uint32_t namelen;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek uint32_t keylen;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek size_t c = 0;
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek struct tevent_req *req;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_INTERNAL, "sss_autofs_cmd_getautomntbyname\n");
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek cmdctx = talloc_zero(client, struct autofs_cmd_ctx);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (!cmdctx) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return ENOMEM;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek cmdctx->cctx = client;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek actx = talloc_get_type(client->rctx->pvt_ctx, struct autofs_ctx);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (!actx) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "Missing autofs context\n");
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return EIO;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce pctx = talloc_get_type(cmdctx->cctx->protocol_ctx, struct cli_protocol);
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek /* get autofs map name and index to query */
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce sss_packet_get_body(pctx->creq->in, &body, &blen);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek /* FIXME - split out a function to get string from <len><str>\0 */
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek SAFEALIGN_COPY_UINT32_CHECK(&namelen, body+c, blen, &c);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
2bd514cfde1938b1e245af11c9b548d58d49b325Jan Cholasta if (namelen == 0 || namelen > blen - c) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek ret = EINVAL;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek goto done;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek cmdctx->mapname = (char *) body+c;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek /* if not null-terminated fail */
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek if (cmdctx->mapname[namelen] != '\0') {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek ret = EINVAL;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek goto done;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek /* If the name isn't valid UTF-8, fail */
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek if (!sss_utf8_check((const uint8_t *) cmdctx->mapname, namelen -1)) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek ret = EINVAL;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek goto done;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek c += namelen + 1;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek /* FIXME - split out a function to get string from <len><str>\0 */
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek SAFEALIGN_COPY_UINT32_CHECK(&keylen, body+c, blen, &c);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
2bd514cfde1938b1e245af11c9b548d58d49b325Jan Cholasta if (keylen == 0 || keylen > blen - c) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek ret = EINVAL;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek goto done;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek cmdctx->key = (char *) body+c;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek /* if not null-terminated fail */
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek if (cmdctx->key[keylen] != '\0') {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek ret = EINVAL;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek goto done;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek /* If the key isn't valid UTF-8, fail */
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek if (!sss_utf8_check((const uint8_t *) cmdctx->key, keylen -1)) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek ret = EINVAL;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek goto done;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek DEBUG(SSSDBG_TRACE_FUNC,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Requested data of map %s key %s\n", cmdctx->mapname, cmdctx->key);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek ret = get_autofs_map(actx, cmdctx->mapname, &map);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (ret == ENOENT) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "Performing implicit setautomntent\n");
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek req = setautomntent_send(cmdctx, cmdctx->mapname, cmdctx);
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek if (req == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "setautomntent_send failed\n");
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek ret = EIO;
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek goto done;
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek }
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek tevent_req_set_callback(req, getautomntbyname_implicit_done, cmdctx);
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek ret = EOK;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek goto done;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek } else if (ret != EOK) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek DEBUG(SSSDBG_OP_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "An unexpected error occurred: [%d][%s]\n",
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov ret, strerror(ret));
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek goto done;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (map->ready == false) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "Performing implicit setautomntent\n");
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek req = setautomntent_send(cmdctx, cmdctx->mapname, cmdctx);
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek if (req == NULL) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "setautomntent_send failed\n");
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek ret = EIO;
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek goto done;
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek }
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek tevent_req_set_callback(req, getautomntbyname_implicit_done, cmdctx);
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek ret = EOK;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek goto done;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek } else if (map->found == false) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "negative cache hit\n");
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek ret = ENOENT;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek goto done;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek DEBUG(SSSDBG_TRACE_INTERNAL,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Looking up value for [%s] in [%s]\n", cmdctx->key, map->mapname);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek ret = getautomntbyname_process(cmdctx, map, cmdctx->key);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozekdone:
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return autofs_cmd_done(cmdctx, ret);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek}
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozekstatic void
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozekgetautomntbyname_implicit_done(struct tevent_req *req)
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek{
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek errno_t ret;
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek struct autofs_map_ctx *map;
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek struct autofs_cmd_ctx *cmdctx =
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek tevent_req_callback_data(req, struct autofs_cmd_ctx);
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek struct autofs_ctx *actx =
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek talloc_get_type(cmdctx->cctx->rctx->pvt_ctx, struct autofs_ctx);
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek ret = setautomntent_recv(req);
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek talloc_zfree(req);
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek if (ret != EOK) {
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek if (ret != ENOENT) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_CRIT_FAILURE, "setautomntent_recv failed\n");
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek } else {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "No such map\n");
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek }
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek goto done;
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek }
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek ret = get_autofs_map(actx, cmdctx->mapname, &map);
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek if (ret != EOK) {
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Cannot get map after setautomntent succeeded?\n");
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek goto done;
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek }
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek if (map->ready == false) {
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek DEBUG(SSSDBG_CRIT_FAILURE,
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov "Map not ready after setautomntent succeeded\n");
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek goto done;
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek }
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek ret = getautomntbyname_process(cmdctx, map, cmdctx->key);
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozekdone:
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek autofs_cmd_done(cmdctx, ret);
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek return;
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek}
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozekstatic errno_t
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozekgetautomntbyname_process(struct autofs_cmd_ctx *cmdctx,
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek struct autofs_map_ctx *map,
5dfb1257f62839eea1c31669cf3bbcb114c22183Jakub Hrozek const char *key)
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek{
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce struct cli_protocol *pctx;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek errno_t ret;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek size_t i;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek const char *k;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek const char *value;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek size_t valuelen;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek size_t len;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek uint8_t *body;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek size_t blen, rp;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce pctx = talloc_get_type(cmdctx->cctx->protocol_ctx, struct cli_protocol);
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek /* create response packet */
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce ret = sss_packet_new(pctx->creq, 0,
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce sss_packet_get_cmd(pctx->creq->in),
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce &pctx->creq->out);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (ret != EOK) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return ret;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (!map->map || !map->entries || !map->entries[0]) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "No entries found\n");
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce ret = sss_cmd_empty_packet(pctx->creq->out);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (ret != EOK) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return autofs_cmd_done(cmdctx, ret);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek goto done;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek for (i=0; i < map->entry_count; i++) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek k = ldb_msg_find_attr_as_string(map->entries[i],
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek SYSDB_AUTOFS_ENTRY_KEY, NULL);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (!k) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "Skipping incomplete entry\n");
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek continue;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (strcmp(k, key) == 0) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_INTERNAL, "Found key [%s]\n", key);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek break;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (i >= map->entry_count) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_MINOR_FAILURE, "No key named [%s] found\n", key);
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce ret = sss_cmd_empty_packet(pctx->creq->out);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (ret != EOK) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return autofs_cmd_done(cmdctx, ret);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek goto done;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek value = ldb_msg_find_attr_as_string(map->entries[i],
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek SYSDB_AUTOFS_ENTRY_VALUE, NULL);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek valuelen = 1 + strlen(value);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek len = sizeof(uint32_t) + sizeof(uint32_t) + valuelen;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce ret = sss_packet_grow(pctx->creq->out, len);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (ret != EOK) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek goto done;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce sss_packet_get_body(pctx->creq->out, &body, &blen);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek rp = 0;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek SAFEALIGN_SET_UINT32(&body[rp], len, &rp);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek SAFEALIGN_SET_UINT32(&body[rp], valuelen, &rp);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (valuelen == 1) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek body[rp] = '\0';
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek } else {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek memcpy(&body[rp], value, valuelen);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek rp += valuelen;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek ret = EOK;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozekdone:
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce sss_packet_set_error(pctx->creq->out, ret);
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce sss_cmd_done(cmdctx->cctx, cmdctx);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return EOK;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek}
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozekstatic int
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozeksss_autofs_cmd_endautomntent(struct cli_ctx *client)
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek{
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce struct cli_protocol *pctx;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek errno_t ret;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(SSSDBG_TRACE_FUNC, "endautomntent called\n");
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce pctx = talloc_get_type(client->protocol_ctx, struct cli_protocol);
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek /* create response packet */
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce ret = sss_packet_new(pctx->creq, 0,
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce sss_packet_get_cmd(pctx->creq->in),
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce &pctx->creq->out);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek if (ret != EOK) {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return ret;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek sss_cmd_done(client, NULL);
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return EOK;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek}
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozekstruct cli_protocol_version *register_cli_protocol_version(void)
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek{
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek static struct cli_protocol_version autofs_cli_protocol_version[] = {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek { SSS_AUTOFS_PROTO_VERSION, NULL, NULL }
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek };
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return autofs_cli_protocol_version;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek}
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozekstruct sss_cmd_table *get_autofs_cmds(void)
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek{
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek static struct sss_cmd_table autofs_cmds[] = {
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek { SSS_GET_VERSION, sss_cmd_get_version },
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek { SSS_AUTOFS_SETAUTOMNTENT, sss_autofs_cmd_setautomntent },
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek { SSS_AUTOFS_GETAUTOMNTENT, sss_autofs_cmd_getautomntent },
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek { SSS_AUTOFS_GETAUTOMNTBYNAME, sss_autofs_cmd_getautomntbyname },
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek { SSS_AUTOFS_ENDAUTOMNTENT, sss_autofs_cmd_endautomntent },
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek { SSS_CLI_NULL, NULL}
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek };
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek return autofs_cmds;
9e80079370ff3b943832adc3c5ef430e64be0a0cJakub Hrozek}
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorceint autofs_connection_setup(struct cli_ctx *cctx)
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce{
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce int ret;
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce ret = sss_connection_setup(cctx);
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce if (ret != EOK) return ret;
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce cctx->state_ctx = talloc_zero(cctx, struct autofs_state_ctx);
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce if (!cctx->state_ctx) {
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce return ENOMEM;
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce }
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce return EOK;
4f3a9d837a55b49448eca3c713c85a406207e523Simo Sorce}