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