nsssrv_netgroup.c revision 7de6e3534fd61c7619ed34a6b1afe7230b5e6504
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher/*
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher SSSD
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher nsssrv_netgroup.c
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher Authors:
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher Stephen Gallagher <sgallagh@redhat.com>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher Copyright (C) 2010 Red Hat
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher This program is free software; you can redistribute it and/or modify
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher it under the terms of the GNU General Public License as published by
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher the Free Software Foundation; either version 3 of the License, or
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher (at your option) any later version.
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher This program is distributed in the hope that it will be useful,
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher but WITHOUT ANY WARRANTY; without even the implied warranty of
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher GNU General Public License for more details.
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher You should have received a copy of the GNU General Public License
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher along with this program. If not, see <http://www.gnu.org/licenses/>.
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher*/
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher#include "util/util.h"
e0404de84c31d2387bb244d018a5cac8d01f8b19Simo Sorce#include "responder/nss/nsssrv.h"
e0404de84c31d2387bb244d018a5cac8d01f8b19Simo Sorce#include "responder/nss/nsssrv_private.h"
e0404de84c31d2387bb244d018a5cac8d01f8b19Simo Sorce#include "responder/nss/nsssrv_netgroup.h"
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher#include "responder/common/negcache.h"
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher#include "confdb/confdb.h"
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher#include "db/sysdb.h"
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagherstatic errno_t get_netgroup_entry(struct nss_ctx *nctx,
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher char *name,
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher struct getent_ctx **netgr)
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher{
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher hash_key_t key;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher hash_value_t value;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher int hret;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov key.type = HASH_KEY_STRING;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher key.str = name;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher hret = hash_lookup(nctx->netgroups, &key, &value);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher if (hret == HASH_SUCCESS) {
e2ac9be4f293b96f3c8992f1171e44bc1da5cfcaMichal Zidek *netgr = talloc_get_type(value.ptr, struct getent_ctx);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher return EOK;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher } else if (hret == HASH_ERROR_KEY_NOT_FOUND) {
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher return ENOENT;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher }
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e0404de84c31d2387bb244d018a5cac8d01f8b19Simo Sorce DEBUG(1, ("Unexpected error reading from netgroup hash [%d][%s]\n",
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher hret, hash_error_string(hret)));
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov return EIO;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher}
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagherstatic int netgr_hash_remove (TALLOC_CTX *ctx);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagherstatic errno_t set_netgroup_entry(struct nss_ctx *nctx,
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher struct getent_ctx *netgr)
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher{
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher hash_key_t key;
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov hash_value_t value;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher int hret;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher if (netgr->name == NULL) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(1, ("Missing netgroup name.\n"));
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher return EINVAL;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher }
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* Add this entry to the hash table */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher key.type = HASH_KEY_STRING;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher key.str = netgr->name;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher value.type = HASH_VALUE_PTR;
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov value.ptr = netgr;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher hret = hash_enter(nctx->netgroups, &key, &value);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher if (hret != EOK) {
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher DEBUG(0, ("Unable to add hash table entry for [%s]", key.str));
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(4, ("Hash error [%d][%s]", hret, hash_error_string(hret)));
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher return EIO;
d115f40c7a3999e3cbe705a2ff9cf0fd493f80fbMichal Zidek }
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher talloc_steal(nctx->netgroups, netgr);
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov talloc_set_destructor((TALLOC_CTX *) netgr, netgr_hash_remove);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher return EOK;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher}
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagherstatic struct tevent_req *setnetgrent_send(TALLOC_CTX *mem_ctx,
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher const char *rawname,
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher struct nss_cmd_ctx *cmdctx);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagherstatic void nss_cmd_setnetgrent_done(struct tevent_req *req);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagherint nss_cmd_setnetgrent(struct cli_ctx *client)
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher{
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher struct nss_cmd_ctx *cmdctx;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher struct tevent_req *req;
e0404de84c31d2387bb244d018a5cac8d01f8b19Simo Sorce const char *rawname;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher uint8_t *body;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher size_t blen;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher errno_t ret = EOK;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* Reset the result cursor to zero */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher client->netgrent_cur = 0;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher cmdctx = talloc_zero(client, struct nss_cmd_ctx);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher if (!cmdctx) {
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher return ENOMEM;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher }
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher cmdctx->cctx = client;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* get netgroup name to query */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher sss_packet_get_body(client->creq->in, &body, &blen);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* if not terminated fail */
e0404de84c31d2387bb244d018a5cac8d01f8b19Simo Sorce if (body[blen -1] != '\0') {
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek ret = EINVAL;
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov goto done;
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek }
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* If the body isn't valid UTF-8, fail */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher if (!sss_utf8_check(body, blen -1)) {
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher ret = EINVAL;
e0404de84c31d2387bb244d018a5cac8d01f8b19Simo Sorce goto done;
e0404de84c31d2387bb244d018a5cac8d01f8b19Simo Sorce }
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov rawname = (const char *)body;
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher req = setnetgrent_send(cmdctx, rawname, cmdctx);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher if (!req) {
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher DEBUG(0, ("Fatal error calling setnetgrent_send\n"));
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher ret = EIO;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher goto done;
e0404de84c31d2387bb244d018a5cac8d01f8b19Simo Sorce }
e0404de84c31d2387bb244d018a5cac8d01f8b19Simo Sorce tevent_req_set_callback(req, nss_cmd_setnetgrent_done, cmdctx);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashovdone:
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov return nss_cmd_done(cmdctx, ret);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher}
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagherstatic int netgr_hash_remove (TALLOC_CTX *ctx)
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher{
e0404de84c31d2387bb244d018a5cac8d01f8b19Simo Sorce int hret;
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek hash_key_t key;
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov struct getent_ctx *netgr =
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek talloc_get_type(ctx, struct getent_ctx);
21d485184df986e1a123f70c689517386e51a5ceMichal Zidek
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher key.type = HASH_KEY_STRING;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher key.str = netgr->name;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* Remove the netgroup result object from the lookup table */
e0404de84c31d2387bb244d018a5cac8d01f8b19Simo Sorce hret = hash_delete(netgr->lookup_table, &key);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher if (hret != HASH_SUCCESS) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(0, ("Could not remove key [%s] from table! [%d][%s]\n",
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher netgr->name, hret, hash_error_string(hret)));
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher return -1;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher }
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher return 0;
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov}
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagherstruct setnetgrent_ctx {
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher struct nss_ctx *nctx;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher struct nss_cmd_ctx *cmdctx;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher struct nss_dom_ctx *dctx;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher char *netgr_shortname;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher struct getent_ctx *netgr;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher const char *rawname;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher};
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagherstatic errno_t setnetgrent_retry(struct tevent_req *req);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagherstatic errno_t lookup_netgr_step(struct setent_step_ctx *step_ctx);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagherstatic struct tevent_req *setnetgrent_send(TALLOC_CTX *mem_ctx,
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher const char *rawname,
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher struct nss_cmd_ctx *cmdctx)
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher{
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov char *domname;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher errno_t ret;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher struct tevent_req *req;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher struct setnetgrent_ctx *state;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher struct nss_dom_ctx *dctx;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher struct cli_ctx *client = cmdctx->cctx;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher struct nss_ctx *nctx =
3d8a87081a6cd197acbd355b5a39111669ec2aa6Jakub Hrozek talloc_get_type(client->rctx->pvt_ctx, struct nss_ctx);
3d8a87081a6cd197acbd355b5a39111669ec2aa6Jakub Hrozek
3d8a87081a6cd197acbd355b5a39111669ec2aa6Jakub Hrozek req = tevent_req_create(mem_ctx, &state, struct setnetgrent_ctx);
3d8a87081a6cd197acbd355b5a39111669ec2aa6Jakub Hrozek if (!req) {
3d8a87081a6cd197acbd355b5a39111669ec2aa6Jakub Hrozek DEBUG(0, ("Could not create tevent request for setnetgrent\n"));
3d8a87081a6cd197acbd355b5a39111669ec2aa6Jakub Hrozek return NULL;
3d8a87081a6cd197acbd355b5a39111669ec2aa6Jakub Hrozek }
3d8a87081a6cd197acbd355b5a39111669ec2aa6Jakub Hrozek
3d8a87081a6cd197acbd355b5a39111669ec2aa6Jakub Hrozek state->nctx = nctx;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher state->cmdctx = cmdctx;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher state->rawname = rawname;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher state->dctx = talloc_zero(state, struct nss_dom_ctx);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher if (!state->dctx) {
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher ret = ENOMEM;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher goto error;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher }
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher dctx = state->dctx;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher dctx->cmdctx = state->cmdctx;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher ret = sss_parse_name_for_domains(state, client->rctx->domains,
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher client->rctx->default_domain, rawname,
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher &domname, &state->netgr_shortname);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher if (ret != EOK) {
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher DEBUG(2, ("Invalid name received [%s]\n", rawname));
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher goto error;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher }
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher DEBUG(4, ("Requesting info for netgroup [%s] from [%s]\n",
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher state->netgr_shortname, domname?domname:"<ALL>"));
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher if (domname) {
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher dctx->domain = responder_get_domain(dctx, client->rctx, domname);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher if (!dctx->domain) {
9f37bb2012faa136ef7c1f9fe93689ce2be85637Ondrej Kos ret = EINVAL;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher goto error;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher }
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* Save the netgroup name for getnetgrent */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher client->netgr_name = talloc_strdup(client, rawname);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher if (!client->netgr_name) {
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher ret = ENOMEM;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher goto error;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher }
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher } else {
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* this is a multidomain search */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher dctx->domain = client->rctx->domains;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher cmdctx->check_next = true;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* Save the netgroup name for getnetgrent */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher client->netgr_name = talloc_strdup(client, state->netgr_shortname);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher if (!client->netgr_name) {
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher ret = ENOMEM;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher goto error;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher }
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher }
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov ret = setnetgrent_retry(req);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher if (ret != EOK) {
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher if (ret == EAGAIN) {
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* We need to reenter the mainloop
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher * We may be refreshing the cache
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher return req;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher }
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov goto error;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher }
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher return req;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallaghererror:
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher tevent_req_error(req, ret);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher tevent_req_post(req, cmdctx->cctx->ev);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher return req;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher}
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagherstatic errno_t setnetgrent_retry(struct tevent_req *req)
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher{
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher errno_t ret;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher struct setent_step_ctx *step_ctx;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher struct setnetgrent_ctx *state;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher struct cli_ctx *client;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher struct nss_ctx *nctx;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher struct nss_cmd_ctx *cmdctx;
03abdaa21ecf562b714f204ca42379ff08626f75Simo Sorce struct nss_dom_ctx *dctx;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher state = tevent_req_data(req, struct setnetgrent_ctx);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher dctx = state->dctx;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher cmdctx = state->cmdctx;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher client = cmdctx->cctx;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher nctx = talloc_get_type(client->rctx->pvt_ctx, struct nss_ctx);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher dctx->check_provider = NEED_CHECK_PROVIDER(dctx->domain->provider);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* Is the result context already available?
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher * Check for existing lookups for this netgroup
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher ret = get_netgroup_entry(nctx, client->netgr_name, &state->netgr);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher if (ret == EOK) {
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* Another process already requested this netgroup
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher * Check whether it's ready for processing.
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher if (state->netgr->ready) {
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher if (state->netgr->found) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov /* Ready to process results */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher tevent_req_done(req);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher } else {
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher tevent_req_error(req, ENOENT);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher }
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher tevent_req_post(req, nctx->rctx->ev);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* Return EOK, otherwise this will be treated as
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher * an error
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher return EOK;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher }
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* Result object is still being constructed
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher * Register for notification when it's ready
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher ret = nss_setent_add_ref(state, state->netgr, req);
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov if (ret != EOK) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov goto done;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher }
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* Will return control below */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher } else if (ret == ENOENT) {
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* This is the first attempt to request this netgroup
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher */
03abdaa21ecf562b714f204ca42379ff08626f75Simo Sorce state->netgr = talloc_zero(nctx, struct getent_ctx);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher if (!state->netgr) {
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher ret = ENOMEM;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher goto done;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher }
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov dctx->netgr = state->netgr;
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* Save the name used for the lookup table
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher * so we can remove it in the destructor
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher state->netgr->name = talloc_strdup(state->netgr,
03abdaa21ecf562b714f204ca42379ff08626f75Simo Sorce client->netgr_name);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher if (!state->netgr->name) {
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher talloc_free(state->netgr);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher ret = ENOMEM;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher goto done;
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov }
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher state->netgr->lookup_table = nctx->netgroups;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* Add a reference for ourselves */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher ret = nss_setent_add_ref(state, state->netgr, req);
03abdaa21ecf562b714f204ca42379ff08626f75Simo Sorce if (ret != EOK) {
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher talloc_free(state->netgr);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher goto done;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher }
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov ret = set_netgroup_entry(nctx, state->netgr);
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov if (ret != EOK) {
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(1, ("set_netgroup_entry failed.\n"));
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher talloc_free(state->netgr);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher goto done;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher }
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
6fb75e297bf7fc83e3db1f5ae8560624656ef319Jan Zeleny /* Perform lookup */
03abdaa21ecf562b714f204ca42379ff08626f75Simo Sorce step_ctx = talloc_zero(state->netgr, struct setent_step_ctx);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher if (!step_ctx) {
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher ret = ENOMEM;
6fb75e297bf7fc83e3db1f5ae8560624656ef319Jan Zeleny goto done;
6fb75e297bf7fc83e3db1f5ae8560624656ef319Jan Zeleny }
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* Steal the dom_ctx onto the step_ctx so it doesn't go out of scope if
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov * this request is canceled while other requests are in-progress.
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov */
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov step_ctx->dctx = talloc_steal(step_ctx, state->dctx);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher step_ctx->nctx = state->nctx;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher step_ctx->getent_ctx = state->netgr;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher step_ctx->rctx = client->rctx;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher step_ctx->check_next = cmdctx->check_next;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher step_ctx->name =
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher talloc_strdup(step_ctx, state->netgr->name);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher if (!step_ctx->name) {
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher ret = ENOMEM;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher goto done;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher }
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher ret = lookup_netgr_step(step_ctx);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher if (ret != EOK) {
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher goto done;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher }
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher tevent_req_done(req);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher tevent_req_post(req, cmdctx->cctx->ev);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* Will return control below */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher } else {
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* Unexpected error from hash_lookup */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher goto done;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher }
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher ret = EOK;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagherdone:
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher return ret;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher}
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagherstatic void lookup_netgr_dp_callback(uint16_t err_maj, uint32_t err_min,
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher const char *err_msg, void *ptr);
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagherstatic void setnetgrent_result_timeout(struct tevent_context *ev,
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher struct tevent_timer *te,
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher struct timeval current_time,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov void *pvt);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher/* Set up a lifetime timer for this result object
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher * We don't want this result object to outlive the
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher * entry cache refresh timeout
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagherstatic void set_netgr_lifetime(uint32_t lifetime,
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher struct setent_step_ctx *step_ctx,
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher struct getent_ctx *netgr)
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher{
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher struct timeval tv;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher struct tevent_timer *te;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher tv = tevent_timeval_current_ofs(lifetime, 0);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher te = tevent_add_timer(step_ctx->nctx->rctx->ev,
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher step_ctx->nctx->gctx, tv,
2ce00e0d3896bb42db169d1e79553a81ca837a22Simo Sorce setnetgrent_result_timeout,
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher netgr);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher if (!te) {
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher DEBUG(0, ("Could not set up life timer for setnetgrent result object. "
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher "Entries may become stale.\n"));
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher }
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher}
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
f5e22261a2ff95f2a61f4f199fffb8de79668110Stephen Gallagherstatic errno_t lookup_netgr_step(struct setent_step_ctx *step_ctx)
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher{
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher errno_t ret;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher struct sss_domain_info *dom = step_ctx->dctx->domain;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher struct getent_ctx *netgr;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher struct sysdb_ctx *sysdb;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher char *name = NULL;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher uint32_t lifetime;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* Check each domain for this netgroup name */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher while (dom) {
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* if it is a domainless search, skip domains that require fully
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher * qualified names instead */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher while (dom && step_ctx->check_next && dom->fqnames) {
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher dom = get_next_domain(dom, false);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher }
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* No domains left to search */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher if (!dom) break;
03abdaa21ecf562b714f204ca42379ff08626f75Simo Sorce
03abdaa21ecf562b714f204ca42379ff08626f75Simo Sorce if (dom != step_ctx->dctx->domain) {
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* make sure we reset the check_provider flag when we check
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher * a new domain */
94a66f84bd3c28fcabffeb84c682dccf89d89c2bSumit Bose step_ctx->dctx->check_provider =
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher NEED_CHECK_PROVIDER(dom->provider);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher }
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* make sure to update the dctx if we changed domain */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher step_ctx->dctx->domain = dom;
1ea2e8bd370e0dc2f2c3fa09232cf67082ef748dStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher talloc_free(name);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher name = sss_get_cased_name(step_ctx, step_ctx->name,
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher dom->case_sensitive);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher if (!name) {
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher DEBUG(SSSDBG_CRIT_FAILURE, ("sss_get_cased_name failed\n"));
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher return ENOMEM;
94a66f84bd3c28fcabffeb84c682dccf89d89c2bSumit Bose }
94a66f84bd3c28fcabffeb84c682dccf89d89c2bSumit Bose
94a66f84bd3c28fcabffeb84c682dccf89d89c2bSumit Bose DEBUG(4, ("Requesting info for [%s@%s]\n",
db18dda869bc6c52a41797b2066cf121cf10f49cPavel Reichl name, dom->name));
94a66f84bd3c28fcabffeb84c682dccf89d89c2bSumit Bose sysdb = dom->sysdb;
db18dda869bc6c52a41797b2066cf121cf10f49cPavel Reichl if (sysdb == NULL) {
94a66f84bd3c28fcabffeb84c682dccf89d89c2bSumit Bose DEBUG(0, ("Fatal: Sysdb CTX not found for this domain!\n"));
94a66f84bd3c28fcabffeb84c682dccf89d89c2bSumit Bose return EIO;
94a66f84bd3c28fcabffeb84c682dccf89d89c2bSumit Bose }
2ce00e0d3896bb42db169d1e79553a81ca837a22Simo Sorce
94a66f84bd3c28fcabffeb84c682dccf89d89c2bSumit Bose /* Look up the netgroup in the cache */
94a66f84bd3c28fcabffeb84c682dccf89d89c2bSumit Bose ret = sysdb_getnetgr(step_ctx->dctx, sysdb, dom, name,
b860f8b6b6b03982c80268e9f6fd35f6455b6b37Simo Sorce &step_ctx->dctx->res);
94a66f84bd3c28fcabffeb84c682dccf89d89c2bSumit Bose if (ret == ENOENT) {
94a66f84bd3c28fcabffeb84c682dccf89d89c2bSumit Bose /* This netgroup was not found in this domain */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher if (!step_ctx->dctx->check_provider) {
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher if (step_ctx->check_next) {
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher dom = get_next_domain(dom, false);
b860f8b6b6b03982c80268e9f6fd35f6455b6b37Simo Sorce continue;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher }
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher else break;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher }
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher ret = EOK;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher }
9b72b00ebcfd6225a4e139619c8e18d44a448f87Stephen Gallagher
9b72b00ebcfd6225a4e139619c8e18d44a448f87Stephen Gallagher if (ret != EOK) {
9b72b00ebcfd6225a4e139619c8e18d44a448f87Stephen Gallagher DEBUG(1, ("Failed to make request to our cache!\n"));
9b72b00ebcfd6225a4e139619c8e18d44a448f87Stephen Gallagher return EIO;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher }
9b72b00ebcfd6225a4e139619c8e18d44a448f87Stephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher ret = get_netgroup_entry(step_ctx->nctx, step_ctx->name,
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher &netgr);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher if (ret != EOK) {
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* Something really bad happened! */
b860f8b6b6b03982c80268e9f6fd35f6455b6b37Simo Sorce DEBUG(0, ("Netgroup entry was lost!\n"));
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher return ret;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher }
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* Convert the result to a list of entries */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher ret = sysdb_netgr_to_entries(netgr, step_ctx->dctx->res,
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher &netgr->entries);
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov if (ret == ENOENT) {
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov /* This netgroup was not found in this domain */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher DEBUG(2, ("No results for netgroup %s (domain %s)\n",
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher name, dom->name));
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher if (!step_ctx->dctx->check_provider) {
b860f8b6b6b03982c80268e9f6fd35f6455b6b37Simo Sorce if (step_ctx->check_next) {
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher dom = get_next_domain(dom, false);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher continue;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher }
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher else break;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher }
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher ret = EOK;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher }
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher if (ret != EOK) {
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher DEBUG(1, ("Failed to convert results into entries\n"));
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher netgr->ready = true;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher netgr->found = false;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher set_netgr_lifetime(step_ctx->nctx->neg_timeout, step_ctx, netgr);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher return EIO;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher }
2ce00e0d3896bb42db169d1e79553a81ca837a22Simo Sorce
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* if this is a caching provider (or if we haven't checked the cache
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher * yet) then verify that the cache is uptodate */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher if (step_ctx->dctx->check_provider) {
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher ret = check_cache(step_ctx->dctx,
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher step_ctx->nctx,
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher step_ctx->dctx->res,
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher SSS_DP_NETGR,
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher name, 0,
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher lookup_netgr_dp_callback,
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher step_ctx);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher if (ret != EOK) {
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* May return EAGAIN legitimately to indicate that
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher * we need to reenter the mainloop
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher return ret;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher }
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher }
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* Results found */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher DEBUG(6, ("Returning info for netgroup [%s@%s]\n",
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher name, dom->name));
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher netgr->ready = true;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher netgr->found = true;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher if (step_ctx->nctx->cache_refresh_percent) {
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher lifetime = dom->netgroup_timeout *
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher (step_ctx->nctx->cache_refresh_percent / 100.0);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher } else {
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher lifetime = dom->netgroup_timeout;
4c08db0fb0dda3d27b1184248ca5c800d7ce23f0Michal Zidek }
4c08db0fb0dda3d27b1184248ca5c800d7ce23f0Michal Zidek if (lifetime < 10) lifetime = 10;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher set_netgr_lifetime(lifetime, step_ctx, netgr);
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov return EOK;
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov }
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* If we've gotten here, then no domain contained this netgroup */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher DEBUG(SSSDBG_MINOR_FAILURE,
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher ("No matching domain found for [%s], fail!\n", step_ctx->name));
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher netgr = talloc_zero(step_ctx->nctx, struct getent_ctx);
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov if (netgr == NULL) {
3d8a87081a6cd197acbd355b5a39111669ec2aa6Jakub Hrozek DEBUG(1, ("talloc_zero failed, ignored.\n"));
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher } else {
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher netgr->ready = true;
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov netgr->found = false;
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov netgr->entries = NULL;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher netgr->lookup_table = step_ctx->nctx->netgroups;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher netgr->name = talloc_strdup(netgr, step_ctx->name);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher if (netgr->name == NULL) {
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher DEBUG(1, ("talloc_strdup failed.\n"));
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher talloc_free(netgr);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher return ENOMEM;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher }
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher ret = set_netgroup_entry(step_ctx->nctx, netgr);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher if (ret != EOK) {
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher DEBUG(1, ("set_netgroup_entry failed, ignored.\n"));
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher }
1243e093fd31c5660adf1bb3dd477d6935a755beJakub Hrozek set_netgr_lifetime(step_ctx->nctx->neg_timeout, step_ctx, netgr);
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov }
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher return ENOENT;
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov}
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagherstatic void lookup_netgr_dp_callback(uint16_t err_maj, uint32_t err_min,
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher const char *err_msg, void *ptr)
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher{
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher struct setent_step_ctx *step_ctx =
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov talloc_get_type(ptr, struct setent_step_ctx);
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov struct nss_dom_ctx *dctx = step_ctx->dctx;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher struct nss_cmd_ctx *cmdctx = dctx->cmdctx;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher int ret;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher if (err_maj) {
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher DEBUG(2, ("Unable to get information from Data Provider\n"
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher "Error: %u, %u, %s\n"
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher "Will try to return what we have in cache\n",
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher (unsigned int)err_maj, (unsigned int)err_min, err_msg));
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* Loop to the next domain if possible */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher if (cmdctx->check_next && get_next_domain(dctx->domain, false)) {
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher dctx->domain = get_next_domain(dctx->domain, false);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher dctx->check_provider = NEED_CHECK_PROVIDER(dctx->domain->provider);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher }
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher }
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* ok the backend returned, search to see if we have updated results */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher ret = lookup_netgr_step(step_ctx);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher if (ret != EOK) {
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher if (ret == EAGAIN) {
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher return;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher }
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher }
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* We have results to return */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher nss_setent_notify_error(dctx->netgr, ret);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher}
f5e22261a2ff95f2a61f4f199fffb8de79668110Stephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagherstatic void setnetgrent_result_timeout(struct tevent_context *ev,
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher struct tevent_timer *te,
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher struct timeval current_time,
f5e22261a2ff95f2a61f4f199fffb8de79668110Stephen Gallagher void *pvt)
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher{
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher struct getent_ctx *netgr =
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher talloc_get_type(pvt, struct getent_ctx);
f5e22261a2ff95f2a61f4f199fffb8de79668110Stephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* Free the netgroup result context
f5e22261a2ff95f2a61f4f199fffb8de79668110Stephen Gallagher * The destructor for the netgroup will remove itself
f5e22261a2ff95f2a61f4f199fffb8de79668110Stephen Gallagher * from the hash table
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher *
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher * If additional getnetgrent() requests come in, they
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher * will invoke an implicit setnetgrent() call and
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher * refresh the result object
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher talloc_free(netgr);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher}
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagherstatic errno_t setnetgrent_recv(struct tevent_req *req)
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher{
f5e22261a2ff95f2a61f4f199fffb8de79668110Stephen Gallagher TEVENT_REQ_RETURN_ON_ERROR(req);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher return EOK;
e2ac9be4f293b96f3c8992f1171e44bc1da5cfcaMichal Zidek}
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagherstatic void nss_cmd_setnetgrent_done(struct tevent_req *req)
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher{
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher errno_t reqret;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher errno_t ret;
f5e22261a2ff95f2a61f4f199fffb8de79668110Stephen Gallagher struct sss_packet *packet;
f5e22261a2ff95f2a61f4f199fffb8de79668110Stephen Gallagher uint8_t *body;
f5e22261a2ff95f2a61f4f199fffb8de79668110Stephen Gallagher size_t blen;
f5e22261a2ff95f2a61f4f199fffb8de79668110Stephen Gallagher
f5e22261a2ff95f2a61f4f199fffb8de79668110Stephen Gallagher struct nss_cmd_ctx *cmdctx =
f5e22261a2ff95f2a61f4f199fffb8de79668110Stephen Gallagher tevent_req_callback_data(req, struct nss_cmd_ctx);
f5e22261a2ff95f2a61f4f199fffb8de79668110Stephen Gallagher
f5e22261a2ff95f2a61f4f199fffb8de79668110Stephen Gallagher reqret = setnetgrent_recv(req);
f5e22261a2ff95f2a61f4f199fffb8de79668110Stephen Gallagher talloc_zfree(req);
f5e22261a2ff95f2a61f4f199fffb8de79668110Stephen Gallagher if (reqret != EOK && reqret != ENOENT) {
3d8a87081a6cd197acbd355b5a39111669ec2aa6Jakub Hrozek DEBUG(1, ("setnetgrent failed\n"));
f5e22261a2ff95f2a61f4f199fffb8de79668110Stephen Gallagher nss_cmd_done(cmdctx, reqret);
f5e22261a2ff95f2a61f4f199fffb8de79668110Stephen Gallagher return;
f5e22261a2ff95f2a61f4f199fffb8de79668110Stephen Gallagher }
f5e22261a2ff95f2a61f4f199fffb8de79668110Stephen Gallagher
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov /* Either we succeeded or no domains were eligible */
f5e22261a2ff95f2a61f4f199fffb8de79668110Stephen Gallagher ret = sss_packet_new(cmdctx->cctx->creq, 0,
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher sss_packet_get_cmd(cmdctx->cctx->creq->in),
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher &cmdctx->cctx->creq->out);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher if (ret == EOK) {
f5e22261a2ff95f2a61f4f199fffb8de79668110Stephen Gallagher if (reqret == ENOENT) {
f5e22261a2ff95f2a61f4f199fffb8de79668110Stephen Gallagher /* Notify the caller that this entry wasn't found */
f5e22261a2ff95f2a61f4f199fffb8de79668110Stephen Gallagher sss_cmd_empty_packet(cmdctx->cctx->creq->out);
f5e22261a2ff95f2a61f4f199fffb8de79668110Stephen Gallagher } else {
f5e22261a2ff95f2a61f4f199fffb8de79668110Stephen Gallagher packet = cmdctx->cctx->creq->out;
f5e22261a2ff95f2a61f4f199fffb8de79668110Stephen Gallagher ret = sss_packet_grow(packet, 2*sizeof(uint32_t));
3d8a87081a6cd197acbd355b5a39111669ec2aa6Jakub Hrozek if (ret != EOK) {
c3d09c0095a45de1973f320ce2045ac74d4e4f83Jakub Hrozek DEBUG(1, ("Couldn't grow the packet\n"));
f5e22261a2ff95f2a61f4f199fffb8de79668110Stephen Gallagher NSS_CMD_FATAL_ERROR(cmdctx);
f5e22261a2ff95f2a61f4f199fffb8de79668110Stephen Gallagher }
f5e22261a2ff95f2a61f4f199fffb8de79668110Stephen Gallagher
f5e22261a2ff95f2a61f4f199fffb8de79668110Stephen Gallagher sss_packet_get_body(packet, &body, &blen);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher ((uint32_t *)body)[0] = 1; /* Got some results */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher ((uint32_t *)body)[1] = 0; /* reserved */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher }
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher sss_cmd_done(cmdctx->cctx, NULL);
f5e22261a2ff95f2a61f4f199fffb8de79668110Stephen Gallagher return;
f5e22261a2ff95f2a61f4f199fffb8de79668110Stephen Gallagher }
f5e22261a2ff95f2a61f4f199fffb8de79668110Stephen Gallagher
f5e22261a2ff95f2a61f4f199fffb8de79668110Stephen Gallagher DEBUG(1, ("Error creating packet\n"));
1243e093fd31c5660adf1bb3dd477d6935a755beJakub Hrozek}
f5e22261a2ff95f2a61f4f199fffb8de79668110Stephen Gallagher
1243e093fd31c5660adf1bb3dd477d6935a755beJakub Hrozekstatic void setnetgrent_implicit_done(struct tevent_req *req);
f5e22261a2ff95f2a61f4f199fffb8de79668110Stephen Gallagherstatic errno_t nss_cmd_getnetgrent_process(struct nss_cmd_ctx *cmdctx,
f5e22261a2ff95f2a61f4f199fffb8de79668110Stephen Gallagher struct getent_ctx *netgr);
f5e22261a2ff95f2a61f4f199fffb8de79668110Stephen Gallagherint nss_cmd_getnetgrent(struct cli_ctx *client)
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher{
f5e22261a2ff95f2a61f4f199fffb8de79668110Stephen Gallagher errno_t ret;
f5e22261a2ff95f2a61f4f199fffb8de79668110Stephen Gallagher struct nss_ctx *nctx;
f5e22261a2ff95f2a61f4f199fffb8de79668110Stephen Gallagher struct nss_cmd_ctx *cmdctx;
f5e22261a2ff95f2a61f4f199fffb8de79668110Stephen Gallagher struct getent_ctx *netgr;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher struct tevent_req *req;
f5e22261a2ff95f2a61f4f199fffb8de79668110Stephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher DEBUG(4, ("Requesting netgroup data\n"));
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher cmdctx = talloc_zero(client, struct nss_cmd_ctx);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher if (!cmdctx) {
f5e22261a2ff95f2a61f4f199fffb8de79668110Stephen Gallagher return ENOMEM;
f5e22261a2ff95f2a61f4f199fffb8de79668110Stephen Gallagher }
f5e22261a2ff95f2a61f4f199fffb8de79668110Stephen Gallagher cmdctx->cctx = client;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher nctx = talloc_get_type(client->rctx->pvt_ctx, struct nss_ctx);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher if (!client->netgr_name) {
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* Tried to run getnetgrent without a preceding
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher * setnetgrent. There is no way to determine which
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher * netgroup is being requested.
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher return nss_cmd_done(cmdctx, EINVAL);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher }
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* Look up the results from the hash */
c1fcc832ccfc237caac8b99be238cf2d598f908cStephen Gallagher ret = get_netgroup_entry(nctx, client->netgr_name, &netgr);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher if (ret == ENOENT) {
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* We need to invoke an implicit setnetgrent() to
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher * wait for the result object to become available.
c1fcc832ccfc237caac8b99be238cf2d598f908cStephen Gallagher */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
c1fcc832ccfc237caac8b99be238cf2d598f908cStephen Gallagher req = setnetgrent_send(cmdctx, client->netgr_name, cmdctx);
c1fcc832ccfc237caac8b99be238cf2d598f908cStephen Gallagher if (!req) {
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher return nss_cmd_done(cmdctx, EIO);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher }
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher tevent_req_set_callback(req, setnetgrent_implicit_done, cmdctx);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher return EOK;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher } else if (ret != EOK) {
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher DEBUG(1, ("An unexpected error occurred: [%d][%s]\n",
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher ret, strerror(ret)));
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher return nss_cmd_done(cmdctx, ret);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher }
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
9b72b00ebcfd6225a4e139619c8e18d44a448f87Stephen Gallagher /* Hash entry was found. Is it ready? */
9b72b00ebcfd6225a4e139619c8e18d44a448f87Stephen Gallagher if (!netgr->ready) {
9b72b00ebcfd6225a4e139619c8e18d44a448f87Stephen Gallagher /* We need to invoke an implicit setnetgrent() to
9b72b00ebcfd6225a4e139619c8e18d44a448f87Stephen Gallagher * wait for the result object to become available.
3d8a87081a6cd197acbd355b5a39111669ec2aa6Jakub Hrozek */
9b72b00ebcfd6225a4e139619c8e18d44a448f87Stephen Gallagher req = setnetgrent_send(cmdctx, client->netgr_name, cmdctx);
9b72b00ebcfd6225a4e139619c8e18d44a448f87Stephen Gallagher if (!req) {
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher return nss_cmd_done(cmdctx, EIO);
e2ac9be4f293b96f3c8992f1171e44bc1da5cfcaMichal Zidek }
c1fcc832ccfc237caac8b99be238cf2d598f908cStephen Gallagher tevent_req_set_callback(req, setnetgrent_implicit_done, cmdctx);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher return EOK;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher } else if (!netgr->found) {
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher DEBUG(6, ("Results for [%s] not found.\n", client->netgr_name));
c1fcc832ccfc237caac8b99be238cf2d598f908cStephen Gallagher return ENOENT;
c1fcc832ccfc237caac8b99be238cf2d598f908cStephen Gallagher }
c1fcc832ccfc237caac8b99be238cf2d598f908cStephen Gallagher
c1fcc832ccfc237caac8b99be238cf2d598f908cStephen Gallagher DEBUG(6, ("Returning results for [%s]\n", client->netgr_name));
c1fcc832ccfc237caac8b99be238cf2d598f908cStephen Gallagher
c1fcc832ccfc237caac8b99be238cf2d598f908cStephen Gallagher /* Read the result strings */
c1fcc832ccfc237caac8b99be238cf2d598f908cStephen Gallagher ret = nss_cmd_getnetgrent_process(cmdctx, netgr);
c1fcc832ccfc237caac8b99be238cf2d598f908cStephen Gallagher if (ret != EOK) {
c1fcc832ccfc237caac8b99be238cf2d598f908cStephen Gallagher DEBUG(1, ("Failed: [%d][%s]\n", ret, strerror(ret)));
c1fcc832ccfc237caac8b99be238cf2d598f908cStephen Gallagher }
3d8a87081a6cd197acbd355b5a39111669ec2aa6Jakub Hrozek return ret;
c1fcc832ccfc237caac8b99be238cf2d598f908cStephen Gallagher}
c1fcc832ccfc237caac8b99be238cf2d598f908cStephen Gallagher
c1fcc832ccfc237caac8b99be238cf2d598f908cStephen Gallagherstatic void setnetgrent_implicit_done(struct tevent_req *req)
c1fcc832ccfc237caac8b99be238cf2d598f908cStephen Gallagher{
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov errno_t ret;
c1fcc832ccfc237caac8b99be238cf2d598f908cStephen Gallagher struct getent_ctx *netgr;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher struct nss_cmd_ctx *cmdctx =
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher tevent_req_callback_data(req, struct nss_cmd_ctx);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher struct nss_ctx *nctx =
c1fcc832ccfc237caac8b99be238cf2d598f908cStephen Gallagher talloc_get_type(cmdctx->cctx->rctx->pvt_ctx, struct nss_ctx);
c1fcc832ccfc237caac8b99be238cf2d598f908cStephen Gallagher
c1fcc832ccfc237caac8b99be238cf2d598f908cStephen Gallagher ret = setnetgrent_recv(req);
c1fcc832ccfc237caac8b99be238cf2d598f908cStephen Gallagher talloc_zfree(req);
c1fcc832ccfc237caac8b99be238cf2d598f908cStephen Gallagher
c1fcc832ccfc237caac8b99be238cf2d598f908cStephen Gallagher /* ENOENT is acceptable, it just means there were no values
3d8a87081a6cd197acbd355b5a39111669ec2aa6Jakub Hrozek * to be returned. This will be handled gracefully in
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher * nss_cmd_retnetgrent later
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher if (ret != EOK && ret != ENOENT) {
c1fcc832ccfc237caac8b99be238cf2d598f908cStephen Gallagher DEBUG(0, ("Implicit setnetgrent failed with unexpected error "
c1fcc832ccfc237caac8b99be238cf2d598f908cStephen Gallagher "[%d][%s]\n", ret, strerror(ret)));
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher NSS_CMD_FATAL_ERROR(cmdctx);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher }
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher if (ret == ENOENT) {
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* No entries found for this netgroup */
c1fcc832ccfc237caac8b99be238cf2d598f908cStephen Gallagher nss_cmd_done(cmdctx, ret);
c1fcc832ccfc237caac8b99be238cf2d598f908cStephen Gallagher return;
c1fcc832ccfc237caac8b99be238cf2d598f908cStephen Gallagher }
c1fcc832ccfc237caac8b99be238cf2d598f908cStephen Gallagher
1243e093fd31c5660adf1bb3dd477d6935a755beJakub Hrozek /* Look up the results from the hash */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher ret = get_netgroup_entry(nctx, cmdctx->cctx->netgr_name, &netgr);
1243e093fd31c5660adf1bb3dd477d6935a755beJakub Hrozek if (ret == ENOENT) {
c1fcc832ccfc237caac8b99be238cf2d598f908cStephen Gallagher /* Critical error. This should never happen */
c1fcc832ccfc237caac8b99be238cf2d598f908cStephen Gallagher DEBUG(0, ("Implicit setnetgrent returned success without creating "
c1fcc832ccfc237caac8b99be238cf2d598f908cStephen Gallagher "result object.\n"));
c1fcc832ccfc237caac8b99be238cf2d598f908cStephen Gallagher NSS_CMD_FATAL_ERROR(cmdctx);
c1fcc832ccfc237caac8b99be238cf2d598f908cStephen Gallagher } else if (ret != EOK) {
c1fcc832ccfc237caac8b99be238cf2d598f908cStephen Gallagher DEBUG(1, ("An unexpected error occurred: [%d][%s]\n",
c1fcc832ccfc237caac8b99be238cf2d598f908cStephen Gallagher ret, strerror(ret)));
c1fcc832ccfc237caac8b99be238cf2d598f908cStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher NSS_CMD_FATAL_ERROR(cmdctx);
c1fcc832ccfc237caac8b99be238cf2d598f908cStephen Gallagher }
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher if (!netgr->ready) {
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* Critical error. This should never happen */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher DEBUG(0, ("Implicit setnetgrent returned success without creating "
9b72b00ebcfd6225a4e139619c8e18d44a448f87Stephen Gallagher "result object.\n"));
9b72b00ebcfd6225a4e139619c8e18d44a448f87Stephen Gallagher NSS_CMD_FATAL_ERROR(cmdctx);
9b72b00ebcfd6225a4e139619c8e18d44a448f87Stephen Gallagher }
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher ret = nss_cmd_getnetgrent_process(cmdctx, netgr);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher if (ret != EOK) {
DEBUG(0, ("Immediate retrieval failed with unexpected error "
"[%d][%s]\n", ret, strerror(ret)));
NSS_CMD_FATAL_ERROR(cmdctx);
}
}
static errno_t nss_cmd_retnetgrent(struct cli_ctx *client,
struct sysdb_netgroup_ctx **entries,
int num);
static errno_t nss_cmd_getnetgrent_process(struct nss_cmd_ctx *cmdctx,
struct getent_ctx *netgr)
{
struct cli_ctx *client = cmdctx->cctx;
uint8_t *body;
size_t blen;
uint32_t num;
errno_t ret;
/* get max num of entries to return in one call */
sss_packet_get_body(client->creq->in, &body, &blen);
if (blen != sizeof(uint32_t)) {
return EINVAL;
}
num = *((uint32_t *)body);
/* create response packet */
ret = sss_packet_new(client->creq, 0,
sss_packet_get_cmd(client->creq->in),
&client->creq->out);
if (ret != EOK) {
return ret;
}
if (!netgr->entries || netgr->entries[0] == NULL) {
/* No entries */
DEBUG(5, ("No entries found\n"));
ret = sss_cmd_empty_packet(client->creq->out);
if (ret != EOK) {
return nss_cmd_done(cmdctx, ret);
}
goto done;
}
ret = nss_cmd_retnetgrent(client, netgr->entries, num);
done:
sss_packet_set_error(client->creq->out, ret);
sss_cmd_done(client, cmdctx);
return EOK;
}
static errno_t nss_cmd_retnetgrent(struct cli_ctx *client,
struct sysdb_netgroup_ctx **entries,
int count)
{
size_t len;
size_t hostlen = 0;
size_t userlen = 0;
size_t domainlen = 0;
size_t grouplen = 0;
uint8_t *body;
size_t blen, rp;
errno_t ret;
struct sss_packet *packet = client->creq->out;
int num, start;
/* first 2 fields (len and reserved), filled up later */
rp = 2*sizeof(uint32_t);
ret = sss_packet_grow(packet, rp);
if (ret != EOK) return ret;
start = client->netgrent_cur;
num = 0;
while (entries[client->netgrent_cur] &&
(client->netgrent_cur - start) < count) {
if (entries[client->netgrent_cur]->type == SYSDB_NETGROUP_TRIPLE_VAL) {
hostlen = 1;
if (entries[client->netgrent_cur]->value.triple.hostname) {
hostlen += strlen(entries[client->netgrent_cur]->value.triple.hostname);
}
userlen = 1;
if (entries[client->netgrent_cur]->value.triple.username) {
userlen += strlen(entries[client->netgrent_cur]->value.triple.username);
}
domainlen = 1;
if (entries[client->netgrent_cur]->value.triple.domainname) {
domainlen += strlen(entries[client->netgrent_cur]->value.triple.domainname);
}
len = sizeof(uint32_t) + hostlen + userlen + domainlen;
ret = sss_packet_grow(packet, len);
if (ret != EOK) {
return ret;
}
sss_packet_get_body(packet, &body, &blen);
SAFEALIGN_SET_UINT32(&body[rp], SSS_NETGR_REP_TRIPLE, &rp);
if (hostlen == 1) {
body[rp] = '\0';
} else {
memcpy(&body[rp],
entries[client->netgrent_cur]->value.triple.hostname,
hostlen);
}
rp += hostlen;
if (userlen == 1) {
body[rp] = '\0';
} else {
memcpy(&body[rp],
entries[client->netgrent_cur]->value.triple.username,
userlen);
}
rp += userlen;
if (domainlen == 1) {
body[rp] = '\0';
} else {
memcpy(&body[rp],
entries[client->netgrent_cur]->value.triple.domainname,
domainlen);
}
rp += domainlen;
} else if (entries[client->netgrent_cur]->type == SYSDB_NETGROUP_GROUP_VAL) {
if (entries[client->netgrent_cur]->value.groupname == NULL ||
entries[client->netgrent_cur]->value.groupname[0] == '\0') {
DEBUG(1, ("Empty netgroup member. Please check your cache.\n"));
continue;
}
grouplen = 1 + strlen(entries[client->netgrent_cur]->value.groupname);
len = sizeof(uint32_t) + grouplen;
ret = sss_packet_grow(packet, len);
if (ret != EOK) {
return ret;
}
sss_packet_get_body(packet, &body, &blen);
SAFEALIGN_SET_UINT32(&body[rp], SSS_NETGR_REP_GROUP, &rp);
memcpy(&body[rp],
entries[client->netgrent_cur]->value.groupname,
grouplen);
rp += grouplen;
} else {
DEBUG(1, ("Unexpected value type for netgroup entry. "
"Please check your cache.\n"));
continue;
}
num++;
client->netgrent_cur++;
}
sss_packet_get_body(packet, &body, &blen);
((uint32_t *)body)[0] = num; /* num results */
((uint32_t *)body)[1] = 0; /* reserved */
return EOK;
}
int nss_cmd_endnetgrent(struct cli_ctx *client)
{
errno_t ret;
/* create response packet */
ret = sss_packet_new(client->creq, 0,
sss_packet_get_cmd(client->creq->in),
&client->creq->out);
if (ret != EOK) {
return ret;
}
/* Reset the indices so that subsequent requests start at zero */
client->netgrent_cur = 0;
talloc_zfree(client->netgr_name);
sss_cmd_done(client, NULL);
return EOK;
}