autofssrv_cmd.c revision d8057ec487e452038f0106042021fa612bbb8555
/*
Authors:
Jakub Hrozek <jhrozek@redhat.com>
Copyright (C) 2012 Red Hat
Autofs responder: commands
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <talloc.h>
#include "responder/common/responder.h"
#include "responder/common/responder_packet.h"
#include "responder/autofs/autofs_private.h"
#include "db/sysdb_autofs.h"
{
}
static int
{
}
static int
{
switch (ret) {
case EOK:
/* all fine, just return here */
break;
case ENOENT:
if (ret) {
return EFAULT;
}
break;
case EAGAIN:
/* async processing, just return here */
break;
case EFAULT:
/* very bad error */
return EFAULT;
default:
if (ret) {
return EFAULT;
}
break;
}
return EOK;
}
static errno_t
struct autofs_map_ctx *map_ctx,
struct tevent_req *req)
{
}
static void
{
}
{
int hret;
unsigned long mcount;
unsigned long i;
return EINVAL;
}
if (hret != HASH_SUCCESS) {
return EIO;
}
for (i = 0; i < mcount; i++) {
if (hret != HASH_SUCCESS) {
continue;
}
}
return EOK;
}
static errno_t
char *mapname,
struct autofs_map_ctx **map)
{
int hret;
if (hret == HASH_SUCCESS) {
return EOK;
} else if (hret == HASH_ERROR_KEY_NOT_FOUND) {
return ENOENT;
}
("Unexpected error reading from autofs map hash [%d][%s]\n",
return EIO;
}
void
{
struct autofs_map_ctx *map;
if (deltype != HASH_ENTRY_DESTROY) {
return;
}
if (!map) {
return;
}
/* So that the destructor wouldn't attempt to remove the map from hash
* table */
}
static errno_t
struct autofs_map_ctx *map)
{
int hret;
return EINVAL;
}
/* Add this entry to the hash table */
return EIO;
}
return EOK;
}
static int
{
int hret;
struct autofs_map_ctx *map =
return 0;
}
/* Remove the autofs map result object from the lookup table */
if (hret != HASH_SUCCESS) {
("Could not remove key from table! [%d][%s]\n",
return -1;
}
return 0;
}
static struct tevent_req *
const char *rawname,
struct autofs_cmd_ctx *cmdctx);
/* FIXME - file a ticket to have per-responder private
* data instead of growing the cli_ctx structure */
static int
{
struct autofs_cmd_ctx *cmdctx;
const char *rawname;
struct tevent_req *req;
if (!cmdctx) {
return ENOMEM;
}
/* if not terminated fail */
goto done;
}
/* If the body isn't valid UTF-8, fail */
goto done;
}
("Got request for automount map named %s\n", rawname));
if (!req) {
("Fatal error calling setautomntent_send\n"));
goto done;
}
done:
}
{
struct autofs_cmd_ctx *cmdctx =
struct sss_packet *packet;
return;
}
/* Either we succeeded or no domains were eligible */
/* Notify the caller that this entry wasn't found */
} else {
return;
}
/* Got some results */
/* Reserved padding */
}
return;
}
return;
}
struct setautomntent_state {
struct autofs_cmd_ctx *cmdctx;
struct autofs_dom_ctx *dctx;
char *mapname;
struct autofs_map_ctx *map;
};
struct setautomntent_lookup_ctx {
struct autofs_ctx *actx;
struct autofs_dom_ctx *dctx;
bool returned_to_mainloop;
char *mapname;
struct autofs_map_ctx *map;
};
static errno_t
static void
struct tevent_timer *te,
struct timeval current_time,
void *pvt)
{
struct autofs_map_ctx *map =
/* Free the autofs map result context
* The destructor for the autofs map will remove itself
* from the hash table
*/
}
static void
struct setautomntent_lookup_ctx *lookup_ctx,
struct autofs_map_ctx *map)
{
struct tevent_timer *te;
map);
if (!te) {
("Could not set up life timer for autofs maps. "
"Entries may become stale.\n"));
}
}
static errno_t
char *mapname,
struct autofs_map_ctx **map);
static struct tevent_req *
const char *rawname,
struct autofs_cmd_ctx *cmdctx)
{
char *domname;
struct tevent_req *req;
struct setautomntent_state *state;
struct autofs_dom_ctx *dctx;
struct autofs_ctx *actx =
struct setautomntent_lookup_ctx *lookup_ctx;
if (!req) {
("Could not create tevent request for setautomntent\n"));
return NULL;
}
if (!dctx) {
goto fail;
}
("Invalid name received [%s]\n", rawname));
goto fail;
}
("Requesting info for automount map [%s] from [%s]\n",
if (domname) {
goto fail;
}
if (!client->automntmap_name) {
goto fail;
}
} else {
/* this is a multidomain search */
cmdctx->check_next = true;
if (!client->automntmap_name) {
goto fail;
}
}
/* Is the result context already available?
* Check for existing lookups for this map
*/
/* Another process already requested this map
* Check whether it's ready for processing.
*/
return req;
} else {
return req;
}
}
/* Result object is still being constructed
* Register for notification when it's ready
*/
("Map %s is being looked up, registering for notification\n",
goto fail;
}
/* Will return control below */
goto fail;
}
goto fail;
}
goto fail;
}
goto fail;
}
/* Perform lookup */
if (!lookup_ctx) {
goto fail;
}
/* Steal the dom_ctx onto the lookup_ctx so it doesn't go out of scope if
* this request is canceled while other requests are in-progress.
*/
if (!lookup_ctx->mapname) {
goto fail;
}
"is refreshing the cache, re-entering the mainloop\n"));
return req;
goto fail;
}
return req;
} else {
("Unexpected error from get_autofs_map [%d]: %s\n",
goto fail;
}
return req;
fail:
return req;
}
static errno_t
char *mapname,
struct autofs_map_ctx **map)
{
/* Iterate over the hash and remove all maps */
}
return ENOENT;
}
}
static errno_t
static errno_t
{
struct autofs_map_ctx *map;
/* Check each domain for this map name */
while (dom) {
/* if it is a domainless search, skip domains that require fully
* qualified names instead */
}
/* No domains left to search */
if (!dom) break;
/* make sure we reset the check_provider flag when we check
* a new domain */
}
/* make sure to update the dctx if we changed domain */
("Fatal: Sysdb CTX not found for this domain!\n"));
return EIO;
}
/* Look into the cache */
return ret;
("No automount map [%s] in cache for domain [%s]\n",
if (!dctx->check_provider) {
continue;
}
else break;
}
}
/* Something really bad happened! */
return ret;
}
("Autofs map not found, setting negative cache\n"));
return ENOENT;
}
if (dctx->check_provider) {
("Looking up automount maps from the DP\n"));
return EAGAIN;
("Error looking up automount maps [%d]: %s\n",
return ret;
}
}
/* OK, the map is in cache and valid.
* Let's get all members and return it
*/
&map->entry_count,
("Error looking automount map entries [%d]: %s\n",
return EIO;
}
return EOK;
}
if (!map) {
return ENOMEM;
}
return ENOMEM;
}
return ENOMEM;
}
/* If we've gotten here, then no domain contained this map */
return ENOENT;
}
static errno_t
{
uint64_t cache_expire = 0;
SYSDB_CACHE_EXPIRE, 0);
}
/* if we have any reply let's check cache validity */
return EOK;
goto error;
}
}
/* dont loop forever :-) */
dctx->check_provider = false;
/* keep around current data in case backend is offline */
/* FIXME - do this by default */
#if 0
}
#endif
if (!req) {
("Out of memory sending data provider request\n"));
goto error;
}
if(!cb_ctx) {
goto error;
}
return EAGAIN;
return ret;
}
return EOK;
}
{
struct dp_callback_ctx *cb_ctx =
struct setautomntent_lookup_ctx *lookup_ctx =
char *err_msg;
&err_msg);
return;
}
}
{
struct setautomntent_lookup_ctx *lookup_ctx =
if (err_maj) {
("Unable to get information from Data Provider\n"
"Error: %u, %u, %s\n"
"Will try to return what we have in cache\n",
/* Loop to the next domain if possible */
}
}
/* ok the backend returned, search to see if we have updated results */
return;
}
}
/* We have results to return */
}
static errno_t
{
return EOK;
}
static errno_t
struct autofs_map_ctx *map,
static void
static errno_t
static int
{
struct autofs_cmd_ctx *cmdctx;
struct autofs_map_ctx *map;
struct autofs_ctx *actx;
size_t c = 0;
struct tevent_req *req;
if (!cmdctx) {
return ENOMEM;
}
if (!actx) {
return EIO;
}
/* get autofs map name and index to query */
goto done;
}
/* if not null-terminated fail */
goto done;
}
/* If the name isn't valid UTF-8, fail */
goto done;
}
("Requested data of map %s cursor %d max entries %d\n",
goto done;
}
goto done;
("An unexpected error occurred: [%d][%s]\n",
goto done;
}
goto done;
}
goto done;
goto done;
}
done:
}
static void
{
struct autofs_map_ctx *map;
struct autofs_cmd_ctx *cmdctx =
struct autofs_ctx *actx =
} else {
}
goto done;
}
("Cannot get map after setautomntent succeeded?\n"));
goto done;
}
("Map not ready after setautomntent succeeded\n"));
goto done;
}
done:
return;
}
static errno_t
struct autofs_map_ctx *map,
{
struct ldb_message *entry;
/* create response packet */
return ret;
}
}
goto done;
}
/* allocate memory for number of entries in the packet */
goto done;
}
nentries = 0;
for (i=0; i < stop; i++) {
cursor++;
("Cannot fill entry %d/%d, skipping\n", i, stop));
continue;
}
nentries++;
}
/* packet grows in fill_autofs_entry, body pointer may change,
* thus we have to obtain it here */
rp = 0;
done:
return EOK;
}
static errno_t
{
const char *key;
const char *value;
return EINVAL;
}
return ret;
}
if (keylen == 1) {
} else {
}
if (valuelen == 1) {
} else {
}
return EOK;
}
static errno_t
struct autofs_map_ctx *map,
const char *key);
static void
static int
{
struct autofs_cmd_ctx *cmdctx;
struct autofs_map_ctx *map;
struct autofs_ctx *actx;
size_t c = 0;
struct tevent_req *req;
if (!cmdctx) {
return ENOMEM;
}
if (!actx) {
return EIO;
}
/* get autofs map name and index to query */
/* FIXME - split out a function to get string from <len><str>\0 */
goto done;
}
/* if not null-terminated fail */
goto done;
}
/* If the name isn't valid UTF-8, fail */
goto done;
}
c += namelen + 1;
/* FIXME - split out a function to get string from <len><str>\0 */
goto done;
}
/* if not null-terminated fail */
goto done;
}
/* If the key isn't valid UTF-8, fail */
goto done;
}
goto done;
}
goto done;
("An unexpected error occurred: [%d][%s]\n",
goto done;
}
goto done;
}
goto done;
goto done;
}
done:
}
static void
{
struct autofs_map_ctx *map;
struct autofs_cmd_ctx *cmdctx =
struct autofs_ctx *actx =
} else {
}
goto done;
}
("Cannot get map after setautomntent succeeded?\n"));
goto done;
}
("Map not ready after setautomntent succeeded\n"));
goto done;
}
done:
return;
}
static errno_t
struct autofs_map_ctx *map,
const char *key)
{
size_t i;
const char *k;
const char *value;
/* create response packet */
return ret;
}
}
goto done;
}
for (i=0; i < map->entry_count; i++) {
if (!k) {
continue;
}
break;
}
}
if (i >= map->entry_count) {
}
goto done;
}
goto done;
}
rp = 0;
if (valuelen == 1) {
} else {
}
done:
return EOK;
}
static int
{
/* create response packet */
return ret;
}
return EOK;
}
struct cli_protocol_version *register_cli_protocol_version(void)
{
static struct cli_protocol_version autofs_cli_protocol_version[] = {
};
return autofs_cli_protocol_version;
}
struct sss_cmd_table *get_autofs_cmds(void)
{
static struct sss_cmd_table autofs_cmds[] = {
{ SSS_CLI_NULL, NULL}
};
return autofs_cmds;
}