responder_cmd.c revision ae526063fcbc4b4c440e35e01e4eca35358c2906
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen SSS Client Responder, command parser
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen Copyright (C) Simo Sorce <ssorce@redhat.com> 2008
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen This program is free software; you can redistribute it and/or modify
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen it under the terms of the GNU General Public License as published by
09060303d565e15d54e42b4ef722f9d3c26f5336Timo Sirainen the Free Software Foundation; either version 3 of the License, or
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen (at your option) any later version.
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen This program is distributed in the hope that it will be useful,
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen but WITHOUT ANY WARRANTY; without even the implied warranty of
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen GNU General Public License for more details.
4fda77c9e9fc68feb292c4dacae1fac49dd08165Timo Sirainen You should have received a copy of the GNU General Public License
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen along with this program. If not, see <http://www.gnu.org/licenses/>.
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenint sss_cmd_send_error(struct cli_ctx *cctx, int err)
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen /* create response packet */
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen DEBUG(SSSDBG_CRIT_FAILURE, ("Cannot create new packet: %d\n", ret));
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenint sss_cmd_empty_packet(struct sss_packet *packet)
09060303d565e15d54e42b4ef722f9d3c26f5336Timo Sirainen ret = sss_packet_grow(packet, 2*sizeof(uint32_t));
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainenint sss_cmd_send_empty(struct cli_ctx *cctx, TALLOC_CTX *freectx)
8b16d3b00f051401c97568697ccdbba48663759aTimo Sirainen /* create response packet */
8b16d3b00f051401c97568697ccdbba48663759aTimo Sirainenvoid sss_cmd_done(struct cli_ctx *cctx, void *freectx)
8b16d3b00f051401c97568697ccdbba48663759aTimo Sirainen /* now that the packet is in place, unlock queue
8b16d3b00f051401c97568697ccdbba48663759aTimo Sirainen * making the event writable */
8b16d3b00f051401c97568697ccdbba48663759aTimo Sirainen /* free all request related data through the talloc hierarchy */
ad404d294fedf792619aed432ed8de5174e9ce7cTimo Sirainen static struct cli_protocol_version *cli_protocol_version = NULL;
ad404d294fedf792619aed432ed8de5174e9ce7cTimo Sirainen cli_protocol_version = register_cli_protocol_version();
ad404d294fedf792619aed432ed8de5174e9ce7cTimo Sirainen cctx->cli_protocol_version = &cli_protocol_version[0];
ad404d294fedf792619aed432ed8de5174e9ce7cTimo Sirainen sss_packet_get_body(cctx->creq->in, &req_body, &req_blen);
ad404d294fedf792619aed432ed8de5174e9ce7cTimo Sirainen memcpy(&client_version, req_body, sizeof(uint32_t));
ad404d294fedf792619aed432ed8de5174e9ce7cTimo Sirainen DEBUG(5, ("Received client version [%d].\n", client_version));
ad404d294fedf792619aed432ed8de5174e9ce7cTimo Sirainen if (cli_protocol_version[i].version == client_version) {
ad404d294fedf792619aed432ed8de5174e9ce7cTimo Sirainen cctx->cli_protocol_version = &cli_protocol_version[i];
ad404d294fedf792619aed432ed8de5174e9ce7cTimo Sirainen /* create response packet */
ad404d294fedf792619aed432ed8de5174e9ce7cTimo Sirainen ret = sss_packet_new(cctx->creq, sizeof(uint32_t),
ad404d294fedf792619aed432ed8de5174e9ce7cTimo Sirainen sss_packet_get_body(cctx->creq->out, &body, &blen);
ad404d294fedf792619aed432ed8de5174e9ce7cTimo Sirainen ((uint32_t *)body)[0] = cctx->cli_protocol_version!=NULL ?
ad404d294fedf792619aed432ed8de5174e9ce7cTimo Sirainen DEBUG(5, ("Offered version [%d].\n", ((uint32_t *)body)[0]));
ad404d294fedf792619aed432ed8de5174e9ce7cTimo Sirainenint sss_cmd_execute(struct cli_ctx *cctx, struct sss_cmd_table *sss_cmds)
ad404d294fedf792619aed432ed8de5174e9ce7cTimo Sirainen for (i = 0; sss_cmds[i].cmd != SSS_CLI_NULL; i++) {
4fda77c9e9fc68feb292c4dacae1fac49dd08165Timo Sirainen /* Need to modify the list from a talloc destructor */
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen entry = talloc_zero(memctx, struct setent_req_list);
e4194f4703eeec32b432371ae30fc8f25ab720d8Timo Sirainen DLIST_ADD_END(*list, entry, struct setent_req_list *);
009217abb57a24a4076092e8e4e165545747839eStephan Bosch talloc_set_destructor((TALLOC_CTX *)entry, setent_remove_ref);
009217abb57a24a4076092e8e4e165545747839eStephan Boschvoid setent_notify(struct setent_req_list **list, errno_t err)
e4194f4703eeec32b432371ae30fc8f25ab720d8Timo Sirainen /* Notify the waiting clients */
e4194f4703eeec32b432371ae30fc8f25ab720d8Timo Sirainen /* Each tevent_req_done() call will free
e4194f4703eeec32b432371ae30fc8f25ab720d8Timo Sirainen * the request, removing it from the list.
e4194f4703eeec32b432371ae30fc8f25ab720d8Timo Sirainen /* The consumer failed to free the
e4194f4703eeec32b432371ae30fc8f25ab720d8Timo Sirainen * request. Log a bug and continue.
e4194f4703eeec32b432371ae30fc8f25ab720d8Timo Sirainen ("BUG: a callback did not free its request. "
e4194f4703eeec32b432371ae30fc8f25ab720d8Timo Sirainen "May leak memory\n"));
49ec317299dedfbc27be79ab97d5b7a8ba7a4eacTimo Sirainen /* Skip to the next since a memory leak is non-fatal */
e4194f4703eeec32b432371ae30fc8f25ab720d8Timo Sirainenvoid setent_notify_done(struct setent_req_list **list)
e4194f4703eeec32b432371ae30fc8f25ab720d8Timo Sirainen * Return values:
e2a88d59c0d47d63ce1ad5b1fd95e487124a3fd4Timo Sirainen * EOK - cache hit
e4194f4703eeec32b432371ae30fc8f25ab720d8Timo Sirainen * EAGAIN - cache hit, but schedule off band update
3c3001681da75afc68578a180ec8f8b2d6dfacfaTimo Sirainen * ENOENT - cache miss
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen lastUpdate = ldb_msg_find_attr_as_uint64(msg, SYSDB_LAST_UPDATE, 0);
09060303d565e15d54e42b4ef722f9d3c26f5336Timo Sirainen (cache_expire - lastUpdate)*cache_refresh_percent/100;
09060303d565e15d54e42b4ef722f9d3c26f5336Timo Sirainen /* If the percentage results in an expiration
09060303d565e15d54e42b4ef722f9d3c26f5336Timo Sirainen * less than ten seconds after the lastUpdate time,
09060303d565e15d54e42b4ef722f9d3c26f5336Timo Sirainen * that's too often we will simply set it to 10s
8ae72ad7d0c69e972cfa65d1e2ce4e3e9a8b765cTimo Sirainen /* cache still valid */
3c3001681da75afc68578a180ec8f8b2d6dfacfaTimo Sirainen if (midpoint_refresh && midpoint_refresh < now) {
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen /* We're past the cache refresh timeout
cf9d67e4a9bfee31cf3be05244555d51a3d1b9feTimo Sirainen * We'll return the value from the cache, but we'll also
a4502a71879d6018bd2c64f13614bb619911dd9fTimo Sirainen * queue the cache entry for update out-of-band.
a4502a71879d6018bd2c64f13614bb619911dd9fTimo Sirainen /* Cache is still valid. */
28789c7ce1aa66ab21798bfb73ec64308b9a4de8Timo Sirainen /* Cache needs to be updated */