nsssrv_netgroup.c revision 7de6e3534fd61c7619ed34a6b1afe7230b5e6504
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher Stephen Gallagher <sgallagh@redhat.com>
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher Copyright (C) 2010 Red Hat
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 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 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 Gallagherstatic errno_t get_netgroup_entry(struct nss_ctx *nctx,
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher hret = hash_lookup(nctx->netgroups, &key, &value);
e2ac9be4f293b96f3c8992f1171e44bc1da5cfcaMichal Zidek *netgr = talloc_get_type(value.ptr, struct getent_ctx);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher } else if (hret == HASH_ERROR_KEY_NOT_FOUND) {
e0404de84c31d2387bb244d018a5cac8d01f8b19Simo Sorce DEBUG(1, ("Unexpected error reading from netgroup hash [%d][%s]\n",
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagherstatic int netgr_hash_remove (TALLOC_CTX *ctx);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagherstatic errno_t set_netgroup_entry(struct nss_ctx *nctx,
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* Add this entry to the hash table */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher hret = hash_enter(nctx->netgroups, &key, &value);
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)));
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov talloc_set_destructor((TALLOC_CTX *) netgr, netgr_hash_remove);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagherstatic struct tevent_req *setnetgrent_send(TALLOC_CTX *mem_ctx,
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagherstatic void nss_cmd_setnetgrent_done(struct tevent_req *req);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagherint nss_cmd_setnetgrent(struct cli_ctx *client)
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* Reset the result cursor to zero */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher cmdctx = talloc_zero(client, struct nss_cmd_ctx);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* get netgroup name to query */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher sss_packet_get_body(client->creq->in, &body, &blen);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* if not terminated fail */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* If the body isn't valid UTF-8, fail */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher req = setnetgrent_send(cmdctx, rawname, cmdctx);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher DEBUG(0, ("Fatal error calling setnetgrent_send\n"));
e0404de84c31d2387bb244d018a5cac8d01f8b19Simo Sorce tevent_req_set_callback(req, nss_cmd_setnetgrent_done, cmdctx);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagherstatic int netgr_hash_remove (TALLOC_CTX *ctx)
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* Remove the netgroup result object from the lookup table */
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov DEBUG(0, ("Could not remove key [%s] from table! [%d][%s]\n",
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher netgr->name, hret, hash_error_string(hret)));
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,
3d8a87081a6cd197acbd355b5a39111669ec2aa6Jakub Hrozek talloc_get_type(client->rctx->pvt_ctx, struct nss_ctx);
3d8a87081a6cd197acbd355b5a39111669ec2aa6Jakub Hrozek req = tevent_req_create(mem_ctx, &state, struct setnetgrent_ctx);
3d8a87081a6cd197acbd355b5a39111669ec2aa6Jakub Hrozek DEBUG(0, ("Could not create tevent request for setnetgrent\n"));
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher state->dctx = talloc_zero(state, struct nss_dom_ctx);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher ret = sss_parse_name_for_domains(state, client->rctx->domains,
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher DEBUG(2, ("Invalid name received [%s]\n", rawname));
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher DEBUG(4, ("Requesting info for netgroup [%s] from [%s]\n",
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher state->netgr_shortname, domname?domname:"<ALL>"));
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher dctx->domain = responder_get_domain(dctx, client->rctx, domname);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* Save the netgroup name for getnetgrent */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher client->netgr_name = talloc_strdup(client, rawname);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* this is a multidomain search */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* Save the netgroup name for getnetgrent */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher client->netgr_name = talloc_strdup(client, state->netgr_shortname);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* We need to reenter the mainloop
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher * We may be refreshing the cache
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagherstatic errno_t setnetgrent_retry(struct tevent_req *req)
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher state = tevent_req_data(req, struct setnetgrent_ctx);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher nctx = talloc_get_type(client->rctx->pvt_ctx, struct nss_ctx);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher dctx->check_provider = NEED_CHECK_PROVIDER(dctx->domain->provider);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* Is the result context already available?
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher * Check for existing lookups for this netgroup
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher ret = get_netgroup_entry(nctx, client->netgr_name, &state->netgr);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* Another process already requested this netgroup
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher * Check whether it's ready for processing.
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov /* Ready to process results */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* Return EOK, otherwise this will be treated as
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* Result object is still being constructed
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher * Register for notification when it's ready
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher ret = nss_setent_add_ref(state, state->netgr, req);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* Will return control below */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* This is the first attempt to request this netgroup
03abdaa21ecf562b714f204ca42379ff08626f75Simo Sorce state->netgr = talloc_zero(nctx, struct getent_ctx);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* Save the name used for the lookup table
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher * so we can remove it in the destructor
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher state->netgr->name = talloc_strdup(state->netgr,
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher state->netgr->lookup_table = nctx->netgroups;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* Add a reference for ourselves */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher ret = nss_setent_add_ref(state, state->netgr, req);
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov ret = set_netgroup_entry(nctx, state->netgr);
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov DEBUG(1, ("set_netgroup_entry failed.\n"));
6fb75e297bf7fc83e3db1f5ae8560624656ef319Jan Zeleny /* Perform lookup */
03abdaa21ecf562b714f204ca42379ff08626f75Simo Sorce step_ctx = talloc_zero(state->netgr, struct setent_step_ctx);
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.
a3c8390d19593b1e5277d95bfb4ab206d4785150Nikolai Kondrashov step_ctx->dctx = talloc_steal(step_ctx, state->dctx);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher step_ctx->check_next = cmdctx->check_next;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher talloc_strdup(step_ctx, state->netgr->name);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* Will return control below */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* Unexpected error from hash_lookup */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagherstatic void lookup_netgr_dp_callback(uint16_t err_maj, uint32_t err_min,
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagherstatic void setnetgrent_result_timeout(struct tevent_context *ev,
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 Gallagherstatic void set_netgr_lifetime(uint32_t lifetime,
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher tv = tevent_timeval_current_ofs(lifetime, 0);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher te = tevent_add_timer(step_ctx->nctx->rctx->ev,
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher DEBUG(0, ("Could not set up life timer for setnetgrent result object. "
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher "Entries may become stale.\n"));
f5e22261a2ff95f2a61f4f199fffb8de79668110Stephen Gallagherstatic errno_t lookup_netgr_step(struct setent_step_ctx *step_ctx)
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher struct sss_domain_info *dom = step_ctx->dctx->domain;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* Check each domain for this netgroup name */
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 /* No domains left to search */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* make sure we reset the check_provider flag when we check
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher * a new domain */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* make sure to update the dctx if we changed domain */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher name = sss_get_cased_name(step_ctx, step_ctx->name,
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher DEBUG(SSSDBG_CRIT_FAILURE, ("sss_get_cased_name failed\n"));
94a66f84bd3c28fcabffeb84c682dccf89d89c2bSumit Bose DEBUG(0, ("Fatal: Sysdb CTX not found for this domain!\n"));
94a66f84bd3c28fcabffeb84c682dccf89d89c2bSumit Bose /* Look up the netgroup in the cache */
94a66f84bd3c28fcabffeb84c682dccf89d89c2bSumit Bose ret = sysdb_getnetgr(step_ctx->dctx, sysdb, dom, name,
94a66f84bd3c28fcabffeb84c682dccf89d89c2bSumit Bose /* This netgroup was not found in this domain */
9b72b00ebcfd6225a4e139619c8e18d44a448f87Stephen Gallagher DEBUG(1, ("Failed to make request to our cache!\n"));
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher ret = get_netgroup_entry(step_ctx->nctx, step_ctx->name,
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* Something really bad happened! */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* Convert the result to a list of entries */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher ret = sysdb_netgr_to_entries(netgr, step_ctx->dctx->res,
83bf46f4066e3d5e838a32357c201de9bd6ecdfdNikolai Kondrashov /* This netgroup was not found in this domain */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher DEBUG(2, ("No results for netgroup %s (domain %s)\n",
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher DEBUG(1, ("Failed to convert results into entries\n"));
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher set_netgr_lifetime(step_ctx->nctx->neg_timeout, step_ctx, netgr);
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 /* May return EAGAIN legitimately to indicate that
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher * we need to reenter the mainloop
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* Results found */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher DEBUG(6, ("Returning info for netgroup [%s@%s]\n",
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher if (step_ctx->nctx->cache_refresh_percent) {
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher (step_ctx->nctx->cache_refresh_percent / 100.0);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher set_netgr_lifetime(lifetime, step_ctx, netgr);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* If we've gotten here, then no domain contained this netgroup */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher ("No matching domain found for [%s], fail!\n", step_ctx->name));
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher netgr = talloc_zero(step_ctx->nctx, struct getent_ctx);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher netgr->lookup_table = step_ctx->nctx->netgroups;
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher netgr->name = talloc_strdup(netgr, step_ctx->name);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher ret = set_netgroup_entry(step_ctx->nctx, netgr);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher DEBUG(1, ("set_netgroup_entry failed, ignored.\n"));
1243e093fd31c5660adf1bb3dd477d6935a755beJakub Hrozek set_netgr_lifetime(step_ctx->nctx->neg_timeout, step_ctx, netgr);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagherstatic void lookup_netgr_dp_callback(uint16_t err_maj, uint32_t err_min,
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 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 /* ok the backend returned, search to see if we have updated results */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* We have results to return */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher nss_setent_notify_error(dctx->netgr, ret);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagherstatic void setnetgrent_result_timeout(struct tevent_context *ev,
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 * If additional getnetgrent() requests come in, they
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher * will invoke an implicit setnetgrent() call and
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher * refresh the result object
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagherstatic errno_t setnetgrent_recv(struct tevent_req *req)
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagherstatic void nss_cmd_setnetgrent_done(struct tevent_req *req)
f5e22261a2ff95f2a61f4f199fffb8de79668110Stephen Gallagher tevent_req_callback_data(req, struct nss_cmd_ctx);
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),
f5e22261a2ff95f2a61f4f199fffb8de79668110Stephen Gallagher /* Notify the caller that this entry wasn't found */
f5e22261a2ff95f2a61f4f199fffb8de79668110Stephen Gallagher sss_cmd_empty_packet(cmdctx->cctx->creq->out);
f5e22261a2ff95f2a61f4f199fffb8de79668110Stephen Gallagher ret = sss_packet_grow(packet, 2*sizeof(uint32_t));
f5e22261a2ff95f2a61f4f199fffb8de79668110Stephen Gallagher sss_packet_get_body(packet, &body, &blen);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher ((uint32_t *)body)[0] = 1; /* Got some results */
1243e093fd31c5660adf1bb3dd477d6935a755beJakub Hrozekstatic void setnetgrent_implicit_done(struct tevent_req *req);
f5e22261a2ff95f2a61f4f199fffb8de79668110Stephen Gallagherstatic errno_t nss_cmd_getnetgrent_process(struct nss_cmd_ctx *cmdctx,
f5e22261a2ff95f2a61f4f199fffb8de79668110Stephen Gallagherint nss_cmd_getnetgrent(struct cli_ctx *client)
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher cmdctx = talloc_zero(client, struct nss_cmd_ctx);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher nctx = talloc_get_type(client->rctx->pvt_ctx, struct nss_ctx);
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 /* Look up the results from the hash */
c1fcc832ccfc237caac8b99be238cf2d598f908cStephen Gallagher ret = get_netgroup_entry(nctx, client->netgr_name, &netgr);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* We need to invoke an implicit setnetgrent() to
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher * wait for the result object to become available.
c1fcc832ccfc237caac8b99be238cf2d598f908cStephen Gallagher req = setnetgrent_send(cmdctx, client->netgr_name, cmdctx);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher tevent_req_set_callback(req, setnetgrent_implicit_done, cmdctx);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher DEBUG(1, ("An unexpected error occurred: [%d][%s]\n",
9b72b00ebcfd6225a4e139619c8e18d44a448f87Stephen Gallagher /* Hash entry was found. Is it ready? */
9b72b00ebcfd6225a4e139619c8e18d44a448f87Stephen Gallagher /* We need to invoke an implicit setnetgrent() to
9b72b00ebcfd6225a4e139619c8e18d44a448f87Stephen Gallagher * wait for the result object to become available.
9b72b00ebcfd6225a4e139619c8e18d44a448f87Stephen Gallagher req = setnetgrent_send(cmdctx, client->netgr_name, cmdctx);
c1fcc832ccfc237caac8b99be238cf2d598f908cStephen Gallagher tevent_req_set_callback(req, setnetgrent_implicit_done, cmdctx);
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher DEBUG(6, ("Results for [%s] not found.\n", client->netgr_name));
c1fcc832ccfc237caac8b99be238cf2d598f908cStephen Gallagher DEBUG(6, ("Returning results for [%s]\n", client->netgr_name));
c1fcc832ccfc237caac8b99be238cf2d598f908cStephen Gallagher /* Read the result strings */
c1fcc832ccfc237caac8b99be238cf2d598f908cStephen Gallagher ret = nss_cmd_getnetgrent_process(cmdctx, netgr);
c1fcc832ccfc237caac8b99be238cf2d598f908cStephen Gallagher DEBUG(1, ("Failed: [%d][%s]\n", ret, strerror(ret)));
c1fcc832ccfc237caac8b99be238cf2d598f908cStephen Gallagherstatic void setnetgrent_implicit_done(struct tevent_req *req)
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher tevent_req_callback_data(req, struct nss_cmd_ctx);
c1fcc832ccfc237caac8b99be238cf2d598f908cStephen Gallagher talloc_get_type(cmdctx->cctx->rctx->pvt_ctx, struct nss_ctx);
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
c1fcc832ccfc237caac8b99be238cf2d598f908cStephen Gallagher DEBUG(0, ("Implicit setnetgrent failed with unexpected error "
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* No entries found for this netgroup */
1243e093fd31c5660adf1bb3dd477d6935a755beJakub Hrozek /* Look up the results from the hash */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher ret = get_netgroup_entry(nctx, cmdctx->cctx->netgr_name, &netgr);
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 DEBUG(1, ("An unexpected error occurred: [%d][%s]\n",
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher /* Critical error. This should never happen */
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher DEBUG(0, ("Implicit setnetgrent returned success without creating "
9b72b00ebcfd6225a4e139619c8e18d44a448f87Stephen Gallagher "result object.\n"));
e134a6af42102c8d865e82bf89e0b8c5a40fb5faStephen Gallagher ret = nss_cmd_getnetgrent_process(cmdctx, netgr);
int num);
return EINVAL;
return ret;
goto done;
done:
return EOK;
int count)
num = 0;
return ret;
hostlen);
userlen);
return ret;
grouplen);
num++;
return EOK;
return ret;
return EOK;