nsssrv_netgroup.c revision 0232747f04b650796db56fd7b487aee8a96fab03
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder Stephen Gallagher <sgallagh@redhat.com>
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder Copyright (C) 2010 Red Hat
679d3f541f7a9ede4079e045f7758873bb901872Till Mossakowski This program is free software; you can redistribute it and/or modify
679d3f541f7a9ede4079e045f7758873bb901872Till Mossakowski it under the terms of the GNU General Public License as published by
1bb1684c83317dfd1692ab53415027b67d8f2faeTill Mossakowski the Free Software Foundation; either version 3 of the License, or
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder (at your option) any later version.
f3faf4e4346b6224a3aaeeac11bac8b5c8932a29Christian Maeder This program is distributed in the hope that it will be useful,
4a8f990902448d0562fbe1a98ce685ddbd531d38Christian Maeder but WITHOUT ANY WARRANTY; without even the implied warranty of
4a8f990902448d0562fbe1a98ce685ddbd531d38Christian Maeder MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f3faf4e4346b6224a3aaeeac11bac8b5c8932a29Christian Maeder GNU General Public License for more details.
f3faf4e4346b6224a3aaeeac11bac8b5c8932a29Christian Maeder You should have received a copy of the GNU General Public License
f3faf4e4346b6224a3aaeeac11bac8b5c8932a29Christian Maeder along with this program. If not, see <http://www.gnu.org/licenses/>.
ba904a15082557e939db689fcfba0c68c9a4f740Christian Maederstatic errno_t get_netgroup_entry(struct nss_ctx *nctx,
88ece6e49930670e8fd3ee79c89a2e918d2fbd0cChristian Maeder hret = hash_lookup(nctx->netgroups, &key, &value);
89ab08979dc23d72e9e09c8990a8c44847041d6fChristian Maeder *netgr = talloc_get_type(value.ptr, struct getent_ctx);
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder } else if (hret == HASH_ERROR_KEY_NOT_FOUND) {
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder DEBUG(1, ("Unexpected error reading from netgroup hash [%d][%s]\n",
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maederstatic int netgr_hash_remove (TALLOC_CTX *ctx);
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maederstatic errno_t set_netgroup_entry(struct nss_ctx *nctx,
f1b14608f0f3db464c3aded480e49522d73b08e5Christian Maeder /* Add this entry to the hash table */
f1b14608f0f3db464c3aded480e49522d73b08e5Christian Maeder hret = hash_enter(nctx->netgroups, &key, &value);
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder DEBUG(0, ("Unable to add hash table entry for [%s]", key.str));
7688e20f844fe88f75c04016841ebb5e5e3d927fChristian Maeder DEBUG(4, ("Hash error [%d][%s]", hret, hash_error_string(hret)));
12368e292c1abf7eaf975f20ee30ef7820ac5dd5Christian Maeder talloc_set_destructor((TALLOC_CTX *) netgr, netgr_hash_remove);
be3f5e3e69900ececafea5b010a8400f26af5362Christian Maederstatic struct tevent_req *setnetgrent_send(TALLOC_CTX *mem_ctx,
12368e292c1abf7eaf975f20ee30ef7820ac5dd5Christian Maederstatic void nss_cmd_setnetgrent_done(struct tevent_req *req);
12368e292c1abf7eaf975f20ee30ef7820ac5dd5Christian Maederint nss_cmd_setnetgrent(struct cli_ctx *client)
0d0047d6eb457b56ff10987569769a420754a56fChristian Maeder /* Reset the result cursor to zero */
0d0047d6eb457b56ff10987569769a420754a56fChristian Maeder cmdctx = talloc_zero(client, struct nss_cmd_ctx);
0d0047d6eb457b56ff10987569769a420754a56fChristian Maeder /* get netgroup name to query */
0d0047d6eb457b56ff10987569769a420754a56fChristian Maeder sss_packet_get_body(client->creq->in, &body, &blen);
12368e292c1abf7eaf975f20ee30ef7820ac5dd5Christian Maeder /* if not terminated fail */
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder /* If the body isn't valid UTF-8, fail */
1af66b491a6164e07ac202abfa0d06c6c2462d64Christian Maeder req = setnetgrent_send(cmdctx, rawname, cmdctx);
97f7ac06b3cbf4fc22c0a9eef523b68ee34fc164Christian Maeder DEBUG(0, ("Fatal error calling setnetgrent_send\n"));
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder tevent_req_set_callback(req, nss_cmd_setnetgrent_done, cmdctx);
7297175957c5ad3c0498032190b1dee9ec5fb873Christian Maederstatic int netgr_hash_remove (TALLOC_CTX *ctx)
c30cfe2a6ab063befdfb47449bc286caee6d8fc3Christian Maeder /* Remove the netgroup result object from the lookup table */
12368e292c1abf7eaf975f20ee30ef7820ac5dd5Christian Maeder hret = hash_delete(netgr->lookup_table, &key);
4a8f990902448d0562fbe1a98ce685ddbd531d38Christian Maeder DEBUG(0, ("Could not remove key [%s] from table! [%d][%s]\n",
4a8f990902448d0562fbe1a98ce685ddbd531d38Christian Maeder netgr->name, hret, hash_error_string(hret)));
df098122ddc81fe1cb033a151f7305c1dda2dc81Christian Maederstatic errno_t setnetgrent_retry(struct tevent_req *req);
df098122ddc81fe1cb033a151f7305c1dda2dc81Christian Maederstatic errno_t lookup_netgr_step(struct setent_step_ctx *step_ctx);
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maederstatic struct tevent_req *setnetgrent_send(TALLOC_CTX *mem_ctx,
0d0047d6eb457b56ff10987569769a420754a56fChristian Maeder talloc_get_type(client->rctx->pvt_ctx, struct nss_ctx);
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder req = tevent_req_create(mem_ctx, &state, struct setnetgrent_ctx);
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder DEBUG(0, ("Could not create tevent request for setnetgrent\n"));
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder state->dctx = talloc_zero(state, struct nss_dom_ctx);
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder ret = sss_parse_name_for_domains(state, client->rctx->domains,
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski DEBUG(2, ("Invalid name received [%s]\n", rawname));
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder DEBUG(4, ("Requesting info for netgroup [%s] from [%s]\n",
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder state->netgr_shortname, domname?domname:"<ALL>"));
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder dctx->domain = responder_get_domain(dctx, client->rctx, domname);
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder /* Save the netgroup name for getnetgrent */
b9804822fb178b0fc27ce967a6a8cedc42c5bf90Christian Maeder client->netgr_name = talloc_strdup(client, rawname);
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder /* this is a multidomain search */
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski /* Save the netgroup name for getnetgrent */
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder client->netgr_name = talloc_strdup(client, state->netgr_shortname);
6b00a9239fe7c804524099ca3d25f4ffc6079ceeChristian Maeder /* We need to reenter the mainloop
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder * We may be refreshing the cache
283fdbf051a1cbcfe003ffdcb434564495106f13Christian Maederstatic errno_t setnetgrent_retry(struct tevent_req *req)
9dfa1c020a030abdbcfce17b18000cc4e1f28462Christian Maeder state = tevent_req_data(req, struct setnetgrent_ctx);
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder nctx = talloc_get_type(client->rctx->pvt_ctx, struct nss_ctx);
4c7f058cdd19ce67b2b5d4b7f69703d0f8a21e38Christian Maeder dctx->check_provider = NEED_CHECK_PROVIDER(dctx->domain->provider);
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski /* Is the result context already available?
4c7f058cdd19ce67b2b5d4b7f69703d0f8a21e38Christian Maeder * Check for existing lookups for this netgroup
12368e292c1abf7eaf975f20ee30ef7820ac5dd5Christian Maeder ret = get_netgroup_entry(nctx, client->netgr_name, &state->netgr);
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder /* Another process already requested this netgroup
88ece6e49930670e8fd3ee79c89a2e918d2fbd0cChristian Maeder * Check whether it's ready for processing.
0d0047d6eb457b56ff10987569769a420754a56fChristian Maeder /* Ready to process results */
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder /* Return EOK, otherwise this will be treated as
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder /* Result object is still being constructed
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder * Register for notification when it's ready
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder ret = nss_setent_add_ref(state, state->netgr, req);
0d0047d6eb457b56ff10987569769a420754a56fChristian Maeder /* Will return control below */
0d0047d6eb457b56ff10987569769a420754a56fChristian Maeder /* This is the first attempt to request this netgroup
7d5f239f3f1c1397e5d80caea12929bdf8abe2d8Christian Maeder state->netgr = talloc_zero(nctx, struct getent_ctx);
63fb549acb4eddfd045bb55da66c1fd4ff5b1ac5Christian Maeder /* Save the name used for the lookup table
63fb549acb4eddfd045bb55da66c1fd4ff5b1ac5Christian Maeder * so we can remove it in the destructor
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowski state->netgr->name = talloc_strdup(state->netgr,
7d5f239f3f1c1397e5d80caea12929bdf8abe2d8Christian Maeder state->netgr->lookup_table = nctx->netgroups;
7d5f239f3f1c1397e5d80caea12929bdf8abe2d8Christian Maeder /* Add a reference for ourselves */
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder ret = nss_setent_add_ref(state, state->netgr, req);
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski ret = set_netgroup_entry(nctx, state->netgr);
c0380b947eef252db81ee562246bb732555427f4Till Mossakowski DEBUG(1, ("set_netgroup_entry failed.\n"));
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder /* Perform lookup */
b9804822fb178b0fc27ce967a6a8cedc42c5bf90Christian Maeder step_ctx = talloc_zero(state->netgr, struct setent_step_ctx);
1c8c2b04b40b5c054da07b8d059e5ef29d4dbc32Christian Maeder /* Steal the dom_ctx onto the step_ctx so it doesn't go out of scope if
0d0047d6eb457b56ff10987569769a420754a56fChristian Maeder * this request is canceled while other requests are in-progress.
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski step_ctx->dctx = talloc_steal(step_ctx, state->dctx);
06afcb70f335c6de74007dc5d6bb19a7d06de457Christian Maeder talloc_strdup(step_ctx, state->netgr->name);
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder /* Will return control below */
06afcb70f335c6de74007dc5d6bb19a7d06de457Christian Maeder /* Unexpected error from hash_lookup */
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowskistatic void lookup_netgr_dp_callback(uint16_t err_maj, uint32_t err_min,
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maederstatic void setnetgrent_result_timeout(struct tevent_context *ev,
7d5f239f3f1c1397e5d80caea12929bdf8abe2d8Christian Maeder/* Set up a lifetime timer for this result object
7d5f239f3f1c1397e5d80caea12929bdf8abe2d8Christian Maeder * We don't want this result object to outlive the
ba5c87b3f4a921f0932a08de48a3aedd3ca4d25bTill Mossakowski * entry cache refresh timeout
7d5f239f3f1c1397e5d80caea12929bdf8abe2d8Christian Maederstatic void set_netgr_lifetime(uint32_t lifetime,
b3dca469a9e267d6d71acfdeca7bf284d0581dc7Till Mossakowski tv = tevent_timeval_current_ofs(lifetime, 0);
b3dca469a9e267d6d71acfdeca7bf284d0581dc7Till Mossakowski te = tevent_add_timer(step_ctx->nctx->rctx->ev,
ba5c87b3f4a921f0932a08de48a3aedd3ca4d25bTill Mossakowski DEBUG(0, ("Could not set up life timer for setnetgrent result object. "
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder "Entries may become stale.\n"));
c40822a6238ef14ebd3df830204c2790a68c8076Christian Maederstatic errno_t lookup_netgr_step(struct setent_step_ctx *step_ctx)
4c7f058cdd19ce67b2b5d4b7f69703d0f8a21e38Christian Maeder struct sss_domain_info *dom = step_ctx->dctx->domain;
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder /* Check each domain for this netgroup name */
0d0047d6eb457b56ff10987569769a420754a56fChristian Maeder /* if it is a domainless search, skip domains that require fully
5b1394673f35f4d23cfe08175841ab414a39678eMarkus Roggenbach * qualified names instead */
63fb549acb4eddfd045bb55da66c1fd4ff5b1ac5Christian Maeder while (dom && step_ctx->check_next && dom->fqnames) {
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder /* No domains left to search */
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder /* make sure we reset the check_provider flag when we check
8528053a6a766c3614276df0f59fb2a2e8ab6d18Christian Maeder * a new domain */
7688e20f844fe88f75c04016841ebb5e5e3d927fChristian Maeder /* make sure to update the dctx if we changed domain */
6108a4c3e891e85e6b36a658382d7e78ad4ce9e7Christian Maeder name = sss_get_cased_name(step_ctx, step_ctx->name,
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder DEBUG(SSSDBG_CRIT_FAILURE, ("sss_get_cased_name failed\n"));
627ed7abdbae641636a2d0f2510c0d450f5ee915Christian Maeder DEBUG(0, ("Fatal: Sysdb CTX not found for this domain!\n"));
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder /* Look up the netgroup in the cache */
2701083ab584807a8dec6f2c8bc03237a25d9809Christian Maeder ret = sysdb_getnetgr(step_ctx->dctx, sysdb, dom, name,
1805f9816e3414ab184fb8546ab1abc6241f04cdChristian Maeder /* This netgroup was not found in this domain */
1805f9816e3414ab184fb8546ab1abc6241f04cdChristian Maeder DEBUG(1, ("Failed to make request to our cache!\n"));
ecf557c0b4f953106755a239da2c0b168064d3f4Christian Maeder ret = get_netgroup_entry(step_ctx->nctx, step_ctx->name,
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder /* Something really bad happened! */
627ed7abdbae641636a2d0f2510c0d450f5ee915Christian Maeder /* Convert the result to a list of entries */
2701083ab584807a8dec6f2c8bc03237a25d9809Christian Maeder ret = sysdb_netgr_to_entries(netgr, step_ctx->dctx->res,
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder /* This netgroup was not found in this domain */
2701083ab584807a8dec6f2c8bc03237a25d9809Christian Maeder DEBUG(2, ("No results for netgroup %s (domain %s)\n",
52aad0502f0ddd332a28ae3fcd3327fa66d002f7Till Mossakowski DEBUG(1, ("Failed to convert results into entries\n"));
52aad0502f0ddd332a28ae3fcd3327fa66d002f7Till Mossakowski set_netgr_lifetime(step_ctx->nctx->neg_timeout, step_ctx, netgr);
ff3bc28a09cff76d4d6cbe8914ab53d1e032d009Till Mossakowski /* if this is a caching provider (or if we haven't checked the cache
b645cf3dc1e449038ed291bbd11fcc6e02b2fc7fChristian Maeder * yet) then verify that the cache is uptodate */
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder /* May return EAGAIN legitimately to indicate that
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder * we need to reenter the mainloop
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder /* Results found */
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder DEBUG(6, ("Returning info for netgroup [%s@%s]\n",
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder if (step_ctx->nctx->cache_refresh_percent) {
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder (step_ctx->nctx->cache_refresh_percent / 100.0);
89ab08979dc23d72e9e09c8990a8c44847041d6fChristian Maeder set_netgr_lifetime(lifetime, step_ctx, netgr);
4c7f058cdd19ce67b2b5d4b7f69703d0f8a21e38Christian Maeder /* If we've gotten here, then no domain contained this netgroup */
de66af0f4b27f08f81c7ca9c573ef9cdf7ca7a07Christian Maeder ("No matching domain found for [%s], fail!\n", step_ctx->name));
12368e292c1abf7eaf975f20ee30ef7820ac5dd5Christian Maeder netgr = talloc_zero(step_ctx->nctx, struct getent_ctx);
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder DEBUG(1, ("talloc_zero failed, ignored.\n"));
37d0b201b8ba5d6056691e3055dd803e7928e163Christian Maeder netgr->lookup_table = step_ctx->nctx->netgroups;
4c7f058cdd19ce67b2b5d4b7f69703d0f8a21e38Christian Maeder netgr->name = talloc_strdup(netgr, step_ctx->name);
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder ret = set_netgroup_entry(step_ctx->nctx, netgr);
ecf557c0b4f953106755a239da2c0b168064d3f4Christian Maeder DEBUG(1, ("set_netgroup_entry failed, ignored.\n"));
ecf557c0b4f953106755a239da2c0b168064d3f4Christian Maeder set_netgr_lifetime(step_ctx->nctx->neg_timeout, step_ctx, netgr);
79ee6b8eb396ed31807784a4bb1c9cc2ce094835Till Mossakowskistatic void lookup_netgr_dp_callback(uint16_t err_maj, uint32_t err_min,
ecf557c0b4f953106755a239da2c0b168064d3f4Christian Maeder talloc_get_type(ptr, struct setent_step_ctx);
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maeder DEBUG(2, ("Unable to get information from Data Provider\n"
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder "Error: %u, %u, %s\n"
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder "Will try to return what we have in cache\n",
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maeder (unsigned int)err_maj, (unsigned int)err_min, err_msg));
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maeder /* Loop to the next domain if possible */
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maeder if (cmdctx->check_next && get_next_domain(dctx->domain, false)) {
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maeder dctx->domain = get_next_domain(dctx->domain, false);
ecf557c0b4f953106755a239da2c0b168064d3f4Christian Maeder dctx->check_provider = NEED_CHECK_PROVIDER(dctx->domain->provider);
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maeder /* ok the backend returned, search to see if we have updated results */
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maeder /* We have results to return */
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maederstatic void setnetgrent_result_timeout(struct tevent_context *ev,
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder /* Free the netgroup result context
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder * The destructor for the netgroup will remove itself
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maeder * from the hash table
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maeder * If additional getnetgrent() requests come in, they
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maeder * will invoke an implicit setnetgrent() call and
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maeder * refresh the result object
587fb54160b66128cf17e4c9bca7494a7f2c3c4aChristian Maederstatic errno_t setnetgrent_recv(struct tevent_req *req)
7d5f239f3f1c1397e5d80caea12929bdf8abe2d8Christian Maederstatic void nss_cmd_setnetgrent_done(struct tevent_req *req)
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski tevent_req_callback_data(req, struct nss_cmd_ctx);
b9804822fb178b0fc27ce967a6a8cedc42c5bf90Christian Maeder /* Either we succeeded or no domains were eligible */
b9804822fb178b0fc27ce967a6a8cedc42c5bf90Christian Maeder ret = sss_packet_new(cmdctx->cctx->creq, 0,
4cb77926a2d85ce3bb32ac0938f0100c8c528dc2Till Mossakowski sss_packet_get_cmd(cmdctx->cctx->creq->in),
89ab08979dc23d72e9e09c8990a8c44847041d6fChristian Maeder /* Notify the caller that this entry wasn't found */
89ab08979dc23d72e9e09c8990a8c44847041d6fChristian Maeder sss_cmd_empty_packet(cmdctx->cctx->creq->out);
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder ret = sss_packet_grow(packet, 2*sizeof(uint32_t));
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski ((uint32_t *)body)[0] = 1; /* Got some results */
4c7f058cdd19ce67b2b5d4b7f69703d0f8a21e38Christian Maederstatic void setnetgrent_implicit_done(struct tevent_req *req);
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maederstatic errno_t nss_cmd_getnetgrent_process(struct nss_cmd_ctx *cmdctx,
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowskiint nss_cmd_getnetgrent(struct cli_ctx *client)
4c7f058cdd19ce67b2b5d4b7f69703d0f8a21e38Christian Maeder cmdctx = talloc_zero(client, struct nss_cmd_ctx);
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder nctx = talloc_get_type(client->rctx->pvt_ctx, struct nss_ctx);
7bf4436b6f9987b070033a323757b206c898c1beChristian Maeder /* Tried to run getnetgrent without a preceding
4c7f058cdd19ce67b2b5d4b7f69703d0f8a21e38Christian Maeder * setnetgrent. There is no way to determine which
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski * netgroup is being requested.
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder /* Look up the results from the hash */
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder ret = get_netgroup_entry(nctx, client->netgr_name, &netgr);
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder /* We need to invoke an implicit setnetgrent() to
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder * wait for the result object to become available.
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder req = setnetgrent_send(cmdctx, client->netgr_name, cmdctx);
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder tevent_req_set_callback(req, setnetgrent_implicit_done, cmdctx);
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski DEBUG(1, ("An unexpected error occurred: [%d][%s]\n",
89ab08979dc23d72e9e09c8990a8c44847041d6fChristian Maeder /* Hash entry was found. Is it ready? */
7d5f239f3f1c1397e5d80caea12929bdf8abe2d8Christian Maeder /* We need to invoke an implicit setnetgrent() to
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski * wait for the result object to become available.
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski req = setnetgrent_send(cmdctx, client->netgr_name, cmdctx);
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder tevent_req_set_callback(req, setnetgrent_implicit_done, cmdctx);
dbbcdfeafa68c87e0b2be0096788844e2be08345Christian Maeder DEBUG(6, ("Results for [%s] not found.\n", client->netgr_name));
89ab08979dc23d72e9e09c8990a8c44847041d6fChristian Maeder DEBUG(6, ("Returning results for [%s]\n", client->netgr_name));
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski /* Read the result strings */
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder ret = nss_cmd_getnetgrent_process(cmdctx, netgr);
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder DEBUG(1, ("Failed: [%d][%s]\n", ret, strerror(ret)));
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowskistatic void setnetgrent_implicit_done(struct tevent_req *req)
7297175957c5ad3c0498032190b1dee9ec5fb873Christian Maeder tevent_req_callback_data(req, struct nss_cmd_ctx);
7297175957c5ad3c0498032190b1dee9ec5fb873Christian Maeder talloc_get_type(cmdctx->cctx->rctx->pvt_ctx, struct nss_ctx);
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder /* ENOENT is acceptable, it just means there were no values
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder * to be returned. This will be handled gracefully in
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder * nss_cmd_retnetgrent later
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder DEBUG(0, ("Implicit setnetgrent failed with unexpected error "
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski /* No entries found for this netgroup */
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder /* Look up the results from the hash */
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder ret = get_netgroup_entry(nctx, cmdctx->cctx->netgr_name, &netgr);
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder /* Critical error. This should never happen */
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder DEBUG(0, ("Implicit setnetgrent returned success without creating "
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski "result object.\n"));
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski DEBUG(1, ("An unexpected error occurred: [%d][%s]\n",
88ece6e49930670e8fd3ee79c89a2e918d2fbd0cChristian Maeder /* Critical error. This should never happen */
89ab08979dc23d72e9e09c8990a8c44847041d6fChristian Maeder DEBUG(0, ("Implicit setnetgrent returned success without creating "
89ab08979dc23d72e9e09c8990a8c44847041d6fChristian Maeder "result object.\n"));
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder ret = nss_cmd_getnetgrent_process(cmdctx, netgr);
f9690de9acb57e279b8ad5792d71b48ffbb807e7Christian Maeder DEBUG(0, ("Immediate retrieval failed with unexpected error "
89ab08979dc23d72e9e09c8990a8c44847041d6fChristian Maederstatic errno_t nss_cmd_retnetgrent(struct cli_ctx *client,
4c7f058cdd19ce67b2b5d4b7f69703d0f8a21e38Christian Maederstatic errno_t nss_cmd_getnetgrent_process(struct nss_cmd_ctx *cmdctx,
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder /* get max num of entries to return in one call */
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder sss_packet_get_body(client->creq->in, &body, &blen);
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder /* create response packet */
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder if (!netgr->entries || netgr->entries[0] == NULL) {
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder /* No entries */
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder ret = sss_cmd_empty_packet(client->creq->out);
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder ret = nss_cmd_retnetgrent(client, netgr->entries, num);
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder sss_packet_set_error(client->creq->out, ret);
4a8f990902448d0562fbe1a98ce685ddbd531d38Christian Maederstatic errno_t nss_cmd_retnetgrent(struct cli_ctx *client,
1af66b491a6164e07ac202abfa0d06c6c2462d64Christian Maeder struct sss_packet *packet = client->creq->out;
4a8f990902448d0562fbe1a98ce685ddbd531d38Christian Maeder /* first 2 fields (len and reserved), filled up later */
4a8f990902448d0562fbe1a98ce685ddbd531d38Christian Maeder if (entries[client->netgrent_cur]->type == SYSDB_NETGROUP_TRIPLE_VAL) {
1af66b491a6164e07ac202abfa0d06c6c2462d64Christian Maeder if (entries[client->netgrent_cur]->value.triple.hostname) {
6b00a9239fe7c804524099ca3d25f4ffc6079ceeChristian Maeder hostlen += strlen(entries[client->netgrent_cur]->value.triple.hostname);
1af66b491a6164e07ac202abfa0d06c6c2462d64Christian Maeder if (entries[client->netgrent_cur]->value.triple.username) {
1af66b491a6164e07ac202abfa0d06c6c2462d64Christian Maeder userlen += strlen(entries[client->netgrent_cur]->value.triple.username);
1af66b491a6164e07ac202abfa0d06c6c2462d64Christian Maeder if (entries[client->netgrent_cur]->value.triple.domainname) {
6b00a9239fe7c804524099ca3d25f4ffc6079ceeChristian Maeder domainlen += strlen(entries[client->netgrent_cur]->value.triple.domainname);
return ret;
hostlen);
userlen);
return ret;
grouplen);
num++;
return EOK;
return ret;
return EOK;