nsssrv_netgroup.c revision 0232747f04b650796db56fd7b487aee8a96fab03
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder/*
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder SSSD
df098122ddc81fe1cb033a151f7305c1dda2dc81Christian Maeder
b03274844ecd270f9e9331f51cc4236a33e2e671Christian Maeder nsssrv_netgroup.c
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder
2eeec5240b424984e3ee26296da1eeab6c6d739eChristian Maeder Authors:
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder Stephen Gallagher <sgallagh@redhat.com>
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder Copyright (C) 2010 Red Hat
e6d40133bc9f858308654afb1262b8b483ec5922Till Mossakowski
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
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
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/>.
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maeder*/
74b841a4b332085d5fd79975a13313c2681ae595Christian Maeder
74b841a4b332085d5fd79975a13313c2681ae595Christian Maeder#include <collection.h>
f3faf4e4346b6224a3aaeeac11bac8b5c8932a29Christian Maeder#include "util/util.h"
f3faf4e4346b6224a3aaeeac11bac8b5c8932a29Christian Maeder#include "responder/nss/nsssrv.h"
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder#include "responder/nss/nsssrv_private.h"
43b4c41fbb07705c9df321221ab9cb9832460407Christian Maeder#include "responder/nss/nsssrv_netgroup.h"
ba904a15082557e939db689fcfba0c68c9a4f740Christian Maeder#include "responder/common/negcache.h"
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder#include "confdb/confdb.h"
7bf4436b6f9987b070033a323757b206c898c1beChristian Maeder#include "db/sysdb.h"
e9249d3ecd51a2b6a966a58669953e58d703adc6Till Mossakowski
ba904a15082557e939db689fcfba0c68c9a4f740Christian Maederstatic errno_t get_netgroup_entry(struct nss_ctx *nctx,
410ff490af511ffa09b52e4de631d36a154b9730Christian Maeder char *name,
ba904a15082557e939db689fcfba0c68c9a4f740Christian Maeder struct getent_ctx **netgr)
1842453990fed8a1bd7a5ac792d7982c1d2bfcd5Christian Maeder{
ba904a15082557e939db689fcfba0c68c9a4f740Christian Maeder hash_key_t key;
ba904a15082557e939db689fcfba0c68c9a4f740Christian Maeder hash_value_t value;
ba904a15082557e939db689fcfba0c68c9a4f740Christian Maeder int hret;
f9e0b18852b238ddb649d341194e05d7200d1bbeChristian Maeder
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder key.type = HASH_KEY_STRING;
ad270004874ce1d0697fb30d7309f180553bb315Christian Maeder key.str = name;
ad270004874ce1d0697fb30d7309f180553bb315Christian Maeder
88ece6e49930670e8fd3ee79c89a2e918d2fbd0cChristian Maeder hret = hash_lookup(nctx->netgroups, &key, &value);
6108a4c3e891e85e6b36a658382d7e78ad4ce9e7Christian Maeder if (hret == HASH_SUCCESS) {
89ab08979dc23d72e9e09c8990a8c44847041d6fChristian Maeder *netgr = talloc_get_type(value.ptr, struct getent_ctx);
410ff490af511ffa09b52e4de631d36a154b9730Christian Maeder return EOK;
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder } else if (hret == HASH_ERROR_KEY_NOT_FOUND) {
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder return ENOENT;
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder }
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder DEBUG(1, ("Unexpected error reading from netgroup hash [%d][%s]\n",
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder hret, hash_error_string(hret)));
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder return EIO;
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder}
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maederstatic int netgr_hash_remove (TALLOC_CTX *ctx);
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maederstatic errno_t set_netgroup_entry(struct nss_ctx *nctx,
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder struct getent_ctx *netgr)
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder{
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder hash_key_t key;
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder hash_value_t value;
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder int hret;
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder if (netgr->name == NULL) {
f1b14608f0f3db464c3aded480e49522d73b08e5Christian Maeder DEBUG(1, ("Missing netgroup name.\n"));
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder return EINVAL;
f1b14608f0f3db464c3aded480e49522d73b08e5Christian Maeder }
f1b14608f0f3db464c3aded480e49522d73b08e5Christian Maeder /* Add this entry to the hash table */
f1b14608f0f3db464c3aded480e49522d73b08e5Christian Maeder key.type = HASH_KEY_STRING;
f1b14608f0f3db464c3aded480e49522d73b08e5Christian Maeder key.str = netgr->name;
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder value.type = HASH_VALUE_PTR;
f1b14608f0f3db464c3aded480e49522d73b08e5Christian Maeder value.ptr = netgr;
f1b14608f0f3db464c3aded480e49522d73b08e5Christian Maeder hret = hash_enter(nctx->netgroups, &key, &value);
f1b14608f0f3db464c3aded480e49522d73b08e5Christian Maeder if (hret != EOK) {
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)));
be3f5e3e69900ececafea5b010a8400f26af5362Christian Maeder return EIO;
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder }
be3f5e3e69900ececafea5b010a8400f26af5362Christian Maeder talloc_steal(nctx->netgroups, netgr);
12368e292c1abf7eaf975f20ee30ef7820ac5dd5Christian Maeder talloc_set_destructor((TALLOC_CTX *) netgr, netgr_hash_remove);
12368e292c1abf7eaf975f20ee30ef7820ac5dd5Christian Maeder
12368e292c1abf7eaf975f20ee30ef7820ac5dd5Christian Maeder return EOK;
be3f5e3e69900ececafea5b010a8400f26af5362Christian Maeder}
be3f5e3e69900ececafea5b010a8400f26af5362Christian Maeder
be3f5e3e69900ececafea5b010a8400f26af5362Christian Maederstatic struct tevent_req *setnetgrent_send(TALLOC_CTX *mem_ctx,
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder const char *rawname,
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder struct nss_cmd_ctx *cmdctx);
12368e292c1abf7eaf975f20ee30ef7820ac5dd5Christian Maederstatic void nss_cmd_setnetgrent_done(struct tevent_req *req);
12368e292c1abf7eaf975f20ee30ef7820ac5dd5Christian Maederint nss_cmd_setnetgrent(struct cli_ctx *client)
12368e292c1abf7eaf975f20ee30ef7820ac5dd5Christian Maeder{
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder struct nss_cmd_ctx *cmdctx;
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder struct tevent_req *req;
7688e20f844fe88f75c04016841ebb5e5e3d927fChristian Maeder const char *rawname;
be3f5e3e69900ececafea5b010a8400f26af5362Christian Maeder uint8_t *body;
be3f5e3e69900ececafea5b010a8400f26af5362Christian Maeder size_t blen;
be3f5e3e69900ececafea5b010a8400f26af5362Christian Maeder errno_t ret = EOK;
8528053a6a766c3614276df0f59fb2a2e8ab6d18Christian Maeder
0d0047d6eb457b56ff10987569769a420754a56fChristian Maeder /* Reset the result cursor to zero */
0d0047d6eb457b56ff10987569769a420754a56fChristian Maeder client->netgrent_cur = 0;
0d0047d6eb457b56ff10987569769a420754a56fChristian Maeder
0d0047d6eb457b56ff10987569769a420754a56fChristian Maeder cmdctx = talloc_zero(client, struct nss_cmd_ctx);
12368e292c1abf7eaf975f20ee30ef7820ac5dd5Christian Maeder if (!cmdctx) {
12368e292c1abf7eaf975f20ee30ef7820ac5dd5Christian Maeder return ENOMEM;
0d0047d6eb457b56ff10987569769a420754a56fChristian Maeder }
0d0047d6eb457b56ff10987569769a420754a56fChristian Maeder cmdctx->cctx = client;
0d0047d6eb457b56ff10987569769a420754a56fChristian Maeder
0d0047d6eb457b56ff10987569769a420754a56fChristian Maeder /* get netgroup name to query */
0d0047d6eb457b56ff10987569769a420754a56fChristian Maeder sss_packet_get_body(client->creq->in, &body, &blen);
3fe83d4c932a8266edcf0304a97814c59821d91fChristian Maeder
12368e292c1abf7eaf975f20ee30ef7820ac5dd5Christian Maeder /* if not terminated fail */
0d0047d6eb457b56ff10987569769a420754a56fChristian Maeder if (body[blen -1] != '\0') {
12368e292c1abf7eaf975f20ee30ef7820ac5dd5Christian Maeder ret = EINVAL;
0d0047d6eb457b56ff10987569769a420754a56fChristian Maeder goto done;
0d0047d6eb457b56ff10987569769a420754a56fChristian Maeder }
0d0047d6eb457b56ff10987569769a420754a56fChristian Maeder
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder /* If the body isn't valid UTF-8, fail */
1af66b491a6164e07ac202abfa0d06c6c2462d64Christian Maeder if (!sss_utf8_check(body, blen -1)) {
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder ret = EINVAL;
1af66b491a6164e07ac202abfa0d06c6c2462d64Christian Maeder goto done;
1af66b491a6164e07ac202abfa0d06c6c2462d64Christian Maeder }
1af66b491a6164e07ac202abfa0d06c6c2462d64Christian Maeder
1af66b491a6164e07ac202abfa0d06c6c2462d64Christian Maeder rawname = (const char *)body;
1af66b491a6164e07ac202abfa0d06c6c2462d64Christian Maeder
1af66b491a6164e07ac202abfa0d06c6c2462d64Christian Maeder req = setnetgrent_send(cmdctx, rawname, cmdctx);
1af66b491a6164e07ac202abfa0d06c6c2462d64Christian Maeder if (!req) {
97f7ac06b3cbf4fc22c0a9eef523b68ee34fc164Christian Maeder DEBUG(0, ("Fatal error calling setnetgrent_send\n"));
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder ret = EIO;
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder goto done;
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder }
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder tevent_req_set_callback(req, nss_cmd_setnetgrent_done, cmdctx);
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maederdone:
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder return nss_cmd_done(cmdctx, ret);
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder}
de66af0f4b27f08f81c7ca9c573ef9cdf7ca7a07Christian Maeder
7297175957c5ad3c0498032190b1dee9ec5fb873Christian Maederstatic int netgr_hash_remove (TALLOC_CTX *ctx)
792df0347edab377785d98c63e2be8e2ce0a8bdeChristian Maeder{
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder int hret;
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder hash_key_t key;
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder struct getent_ctx *netgr =
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder talloc_get_type(ctx, struct getent_ctx);
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder key.type = HASH_KEY_STRING;
de66af0f4b27f08f81c7ca9c573ef9cdf7ca7a07Christian Maeder key.str = netgr->name;
c30cfe2a6ab063befdfb47449bc286caee6d8fc3Christian Maeder
c30cfe2a6ab063befdfb47449bc286caee6d8fc3Christian Maeder /* Remove the netgroup result object from the lookup table */
12368e292c1abf7eaf975f20ee30ef7820ac5dd5Christian Maeder hret = hash_delete(netgr->lookup_table, &key);
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder if (hret != HASH_SUCCESS) {
4a8f990902448d0562fbe1a98ce685ddbd531d38Christian Maeder DEBUG(0, ("Could not remove key [%s] from table! [%d][%s]\n",
4a8f990902448d0562fbe1a98ce685ddbd531d38Christian Maeder netgr->name, hret, hash_error_string(hret)));
4a8f990902448d0562fbe1a98ce685ddbd531d38Christian Maeder return -1;
4a8f990902448d0562fbe1a98ce685ddbd531d38Christian Maeder }
4a8f990902448d0562fbe1a98ce685ddbd531d38Christian Maeder return 0;
4a8f990902448d0562fbe1a98ce685ddbd531d38Christian Maeder}
4a8f990902448d0562fbe1a98ce685ddbd531d38Christian Maeder
4a8f990902448d0562fbe1a98ce685ddbd531d38Christian Maederstruct setnetgrent_ctx {
4a8f990902448d0562fbe1a98ce685ddbd531d38Christian Maeder struct nss_ctx *nctx;
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder struct nss_cmd_ctx *cmdctx;
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder struct nss_dom_ctx *dctx;
1af66b491a6164e07ac202abfa0d06c6c2462d64Christian Maeder char *netgr_shortname;
1af66b491a6164e07ac202abfa0d06c6c2462d64Christian Maeder struct getent_ctx *netgr;
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder const char *rawname;
df098122ddc81fe1cb033a151f7305c1dda2dc81Christian Maeder};
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,
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder const char *rawname,
df098122ddc81fe1cb033a151f7305c1dda2dc81Christian Maeder struct nss_cmd_ctx *cmdctx)
1c8c2b04b40b5c054da07b8d059e5ef29d4dbc32Christian Maeder{
df098122ddc81fe1cb033a151f7305c1dda2dc81Christian Maeder char *domname;
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder errno_t ret;
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder struct tevent_req *req;
c0380b947eef252db81ee562246bb732555427f4Till Mossakowski struct setnetgrent_ctx *state;
2afae0880da7ca73c9376fd4d653ab19833fe858Christian Maeder struct nss_dom_ctx *dctx;
63fb549acb4eddfd045bb55da66c1fd4ff5b1ac5Christian Maeder
ff3bc28a09cff76d4d6cbe8914ab53d1e032d009Till Mossakowski struct cli_ctx *client = cmdctx->cctx;
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder struct nss_ctx *nctx =
0d0047d6eb457b56ff10987569769a420754a56fChristian Maeder talloc_get_type(client->rctx->pvt_ctx, struct nss_ctx);
4c7f058cdd19ce67b2b5d4b7f69703d0f8a21e38Christian Maeder
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder req = tevent_req_create(mem_ctx, &state, struct setnetgrent_ctx);
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder if (!req) {
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder DEBUG(0, ("Could not create tevent request for setnetgrent\n"));
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder return NULL;
c0380b947eef252db81ee562246bb732555427f4Till Mossakowski }
2afae0880da7ca73c9376fd4d653ab19833fe858Christian Maeder
63fb549acb4eddfd045bb55da66c1fd4ff5b1ac5Christian Maeder state->nctx = nctx;
b9804822fb178b0fc27ce967a6a8cedc42c5bf90Christian Maeder state->cmdctx = cmdctx;
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder state->rawname = rawname;
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder state->dctx = talloc_zero(state, struct nss_dom_ctx);
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder if (!state->dctx) {
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder ret = ENOMEM;
0d0047d6eb457b56ff10987569769a420754a56fChristian Maeder goto error;
4c7f058cdd19ce67b2b5d4b7f69703d0f8a21e38Christian Maeder }
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder dctx = state->dctx;
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder dctx->cmdctx = state->cmdctx;
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder ret = sss_parse_name_for_domains(state, client->rctx->domains,
4c7f058cdd19ce67b2b5d4b7f69703d0f8a21e38Christian Maeder client->rctx->default_domain, rawname,
4c7f058cdd19ce67b2b5d4b7f69703d0f8a21e38Christian Maeder &domname, &state->netgr_shortname);
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder if (ret != EOK) {
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski DEBUG(2, ("Invalid name received [%s]\n", rawname));
4c7f058cdd19ce67b2b5d4b7f69703d0f8a21e38Christian Maeder goto error;
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski }
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder DEBUG(4, ("Requesting info for netgroup [%s] from [%s]\n",
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder state->netgr_shortname, domname?domname:"<ALL>"));
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski if (domname) {
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder dctx->domain = responder_get_domain(dctx, client->rctx, domname);
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder if (!dctx->domain) {
0d0047d6eb457b56ff10987569769a420754a56fChristian Maeder ret = EINVAL;
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder goto error;
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder }
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder /* Save the netgroup name for getnetgrent */
b9804822fb178b0fc27ce967a6a8cedc42c5bf90Christian Maeder client->netgr_name = talloc_strdup(client, rawname);
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder if (!client->netgr_name) {
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder ret = ENOMEM;
2afae0880da7ca73c9376fd4d653ab19833fe858Christian Maeder goto error;
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder }
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder } else {
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder /* this is a multidomain search */
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder dctx->domain = client->rctx->domains;
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder cmdctx->check_next = true;
b645cf3dc1e449038ed291bbd11fcc6e02b2fc7fChristian Maeder
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski /* Save the netgroup name for getnetgrent */
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder client->netgr_name = talloc_strdup(client, state->netgr_shortname);
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder if (!client->netgr_name) {
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder ret = ENOMEM;
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder goto error;
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder }
b10d6cef708b7a659f2d3b367e8e0db0d03ae3f5Till Mossakowski }
b10d6cef708b7a659f2d3b367e8e0db0d03ae3f5Till Mossakowski
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder ret = setnetgrent_retry(req);
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowski if (ret != EOK) {
6b00a9239fe7c804524099ca3d25f4ffc6079ceeChristian Maeder if (ret == EAGAIN) {
6b00a9239fe7c804524099ca3d25f4ffc6079ceeChristian Maeder /* We need to reenter the mainloop
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder * We may be refreshing the cache
b9804822fb178b0fc27ce967a6a8cedc42c5bf90Christian Maeder */
b9804822fb178b0fc27ce967a6a8cedc42c5bf90Christian Maeder return req;
21dae7237ac384abdb94a81e00b3f099873ec623Till Mossakowski }
b9804822fb178b0fc27ce967a6a8cedc42c5bf90Christian Maeder
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder goto error;
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder }
b645cf3dc1e449038ed291bbd11fcc6e02b2fc7fChristian Maeder
b645cf3dc1e449038ed291bbd11fcc6e02b2fc7fChristian Maeder return req;
283fdbf051a1cbcfe003ffdcb434564495106f13Christian Maeder
63fb549acb4eddfd045bb55da66c1fd4ff5b1ac5Christian Maedererror:
63fb549acb4eddfd045bb55da66c1fd4ff5b1ac5Christian Maeder tevent_req_error(req, ret);
283fdbf051a1cbcfe003ffdcb434564495106f13Christian Maeder tevent_req_post(req, cmdctx->cctx->ev);
283fdbf051a1cbcfe003ffdcb434564495106f13Christian Maeder return req;
63fb549acb4eddfd045bb55da66c1fd4ff5b1ac5Christian Maeder}
63fb549acb4eddfd045bb55da66c1fd4ff5b1ac5Christian Maeder
283fdbf051a1cbcfe003ffdcb434564495106f13Christian Maederstatic errno_t setnetgrent_retry(struct tevent_req *req)
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder{
c0380b947eef252db81ee562246bb732555427f4Till Mossakowski errno_t ret;
c0380b947eef252db81ee562246bb732555427f4Till Mossakowski struct setent_step_ctx *step_ctx;
2d879b474429900e22aec178ed54be734bda5b8aChristian Maeder struct setnetgrent_ctx *state;
e24d81c69aecd41abb2f4969519c9e7126b1d687Christian Maeder struct cli_ctx *client;
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder struct nss_ctx *nctx;
2afae0880da7ca73c9376fd4d653ab19833fe858Christian Maeder struct nss_cmd_ctx *cmdctx;
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder struct nss_dom_ctx *dctx;
b9804822fb178b0fc27ce967a6a8cedc42c5bf90Christian Maeder
9dfa1c020a030abdbcfce17b18000cc4e1f28462Christian Maeder state = tevent_req_data(req, struct setnetgrent_ctx);
2d879b474429900e22aec178ed54be734bda5b8aChristian Maeder dctx = state->dctx;
2d879b474429900e22aec178ed54be734bda5b8aChristian Maeder cmdctx = state->cmdctx;
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder client = cmdctx->cctx;
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder nctx = talloc_get_type(client->rctx->pvt_ctx, struct nss_ctx);
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder
4c7f058cdd19ce67b2b5d4b7f69703d0f8a21e38Christian Maeder dctx->check_provider = NEED_CHECK_PROVIDER(dctx->domain->provider);
2d879b474429900e22aec178ed54be734bda5b8aChristian Maeder
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski /* Is the result context already available?
4c7f058cdd19ce67b2b5d4b7f69703d0f8a21e38Christian Maeder * Check for existing lookups for this netgroup
c0380b947eef252db81ee562246bb732555427f4Till Mossakowski */
12368e292c1abf7eaf975f20ee30ef7820ac5dd5Christian Maeder ret = get_netgroup_entry(nctx, client->netgr_name, &state->netgr);
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder if (ret == EOK) {
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder /* Another process already requested this netgroup
88ece6e49930670e8fd3ee79c89a2e918d2fbd0cChristian Maeder * Check whether it's ready for processing.
89ab08979dc23d72e9e09c8990a8c44847041d6fChristian Maeder */
9dfa1c020a030abdbcfce17b18000cc4e1f28462Christian Maeder if (state->netgr->ready) {
9dfa1c020a030abdbcfce17b18000cc4e1f28462Christian Maeder if (state->netgr->found) {
0d0047d6eb457b56ff10987569769a420754a56fChristian Maeder /* Ready to process results */
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder tevent_req_done(req);
c0380b947eef252db81ee562246bb732555427f4Till Mossakowski } else {
c0380b947eef252db81ee562246bb732555427f4Till Mossakowski tevent_req_error(req, ENOENT);
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder }
37d0b201b8ba5d6056691e3055dd803e7928e163Christian Maeder
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder tevent_req_post(req, nctx->rctx->ev);
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder /* Return EOK, otherwise this will be treated as
c0380b947eef252db81ee562246bb732555427f4Till Mossakowski * an error
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder */
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski return EOK;
2afae0880da7ca73c9376fd4d653ab19833fe858Christian Maeder }
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder /* Result object is still being constructed
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder * Register for notification when it's ready
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder */
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder ret = nss_setent_add_ref(state, state->netgr, req);
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder if (ret != EOK) {
a980a2f16eda9aad70f1f53f9df713595f57cb78Jian Chun Wang goto done;
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder }
0d0047d6eb457b56ff10987569769a420754a56fChristian Maeder /* Will return control below */
0d0047d6eb457b56ff10987569769a420754a56fChristian Maeder } else if (ret == ENOENT) {
0d0047d6eb457b56ff10987569769a420754a56fChristian Maeder /* This is the first attempt to request this netgroup
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder */
7d5f239f3f1c1397e5d80caea12929bdf8abe2d8Christian Maeder state->netgr = talloc_zero(nctx, struct getent_ctx);
7d5f239f3f1c1397e5d80caea12929bdf8abe2d8Christian Maeder if (!state->netgr) {
7d5f239f3f1c1397e5d80caea12929bdf8abe2d8Christian Maeder ret = ENOMEM;
7d5f239f3f1c1397e5d80caea12929bdf8abe2d8Christian Maeder goto done;
7d5f239f3f1c1397e5d80caea12929bdf8abe2d8Christian Maeder }
7d5f239f3f1c1397e5d80caea12929bdf8abe2d8Christian Maeder dctx->netgr = state->netgr;
283fdbf051a1cbcfe003ffdcb434564495106f13Christian Maeder
63fb549acb4eddfd045bb55da66c1fd4ff5b1ac5Christian Maeder /* Save the name used for the lookup table
63fb549acb4eddfd045bb55da66c1fd4ff5b1ac5Christian Maeder * so we can remove it in the destructor
283fdbf051a1cbcfe003ffdcb434564495106f13Christian Maeder */
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowski state->netgr->name = talloc_strdup(state->netgr,
63fb549acb4eddfd045bb55da66c1fd4ff5b1ac5Christian Maeder client->netgr_name);
63fb549acb4eddfd045bb55da66c1fd4ff5b1ac5Christian Maeder if (!state->netgr->name) {
0d0047d6eb457b56ff10987569769a420754a56fChristian Maeder talloc_free(state->netgr);
7d5f239f3f1c1397e5d80caea12929bdf8abe2d8Christian Maeder ret = ENOMEM;
7d5f239f3f1c1397e5d80caea12929bdf8abe2d8Christian Maeder goto done;
2cafc2361fcaccf6b82d81f6a94f59e42af725c7Christian Maeder }
89ab08979dc23d72e9e09c8990a8c44847041d6fChristian Maeder
7d5f239f3f1c1397e5d80caea12929bdf8abe2d8Christian Maeder state->netgr->lookup_table = nctx->netgroups;
7688e20f844fe88f75c04016841ebb5e5e3d927fChristian Maeder
7d5f239f3f1c1397e5d80caea12929bdf8abe2d8Christian Maeder /* Add a reference for ourselves */
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder ret = nss_setent_add_ref(state, state->netgr, req);
7d5f239f3f1c1397e5d80caea12929bdf8abe2d8Christian Maeder if (ret != EOK) {
b9804822fb178b0fc27ce967a6a8cedc42c5bf90Christian Maeder talloc_free(state->netgr);
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder goto done;
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder }
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski ret = set_netgroup_entry(nctx, state->netgr);
2afae0880da7ca73c9376fd4d653ab19833fe858Christian Maeder if (ret != EOK) {
c0380b947eef252db81ee562246bb732555427f4Till Mossakowski DEBUG(1, ("set_netgroup_entry failed.\n"));
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder talloc_free(state->netgr);
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder goto done;
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder }
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder /* Perform lookup */
b9804822fb178b0fc27ce967a6a8cedc42c5bf90Christian Maeder step_ctx = talloc_zero(state->netgr, struct setent_step_ctx);
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder if (!step_ctx) {
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder ret = ENOMEM;
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder goto done;
9d500b1d6d1946f9e6f0c1f9ee548a611b3166b0Christian Maeder }
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder
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.
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder */
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski step_ctx->dctx = talloc_steal(step_ctx, state->dctx);
7d5f239f3f1c1397e5d80caea12929bdf8abe2d8Christian Maeder step_ctx->nctx = state->nctx;
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder step_ctx->getent_ctx = state->netgr;
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder step_ctx->rctx = client->rctx;
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder step_ctx->check_next = cmdctx->check_next;
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder step_ctx->name =
06afcb70f335c6de74007dc5d6bb19a7d06de457Christian Maeder talloc_strdup(step_ctx, state->netgr->name);
06afcb70f335c6de74007dc5d6bb19a7d06de457Christian Maeder if (!step_ctx->name) {
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder ret = ENOMEM;
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder goto done;
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder }
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder ret = lookup_netgr_step(step_ctx);
06afcb70f335c6de74007dc5d6bb19a7d06de457Christian Maeder if (ret != EOK) {
06afcb70f335c6de74007dc5d6bb19a7d06de457Christian Maeder goto done;
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder }
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder tevent_req_done(req);
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder tevent_req_post(req, cmdctx->cctx->ev);
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder /* Will return control below */
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder } else {
06afcb70f335c6de74007dc5d6bb19a7d06de457Christian Maeder /* Unexpected error from hash_lookup */
06afcb70f335c6de74007dc5d6bb19a7d06de457Christian Maeder goto done;
06afcb70f335c6de74007dc5d6bb19a7d06de457Christian Maeder }
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder ret = EOK;
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maederdone:
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder return ret;
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder}
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowskistatic void lookup_netgr_dp_callback(uint16_t err_maj, uint32_t err_min,
e379124f467e5d0ef7d3c0ca238bff0521f70831Till Mossakowski const char *err_msg, void *ptr);
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maederstatic void setnetgrent_result_timeout(struct tevent_context *ev,
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder struct tevent_timer *te,
d210b655b5f93a0fff2eefbb94c072d450cef3b4Till Mossakowski struct timeval current_time,
89ab08979dc23d72e9e09c8990a8c44847041d6fChristian Maeder void *pvt);
89ab08979dc23d72e9e09c8990a8c44847041d6fChristian Maeder
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
ba5c87b3f4a921f0932a08de48a3aedd3ca4d25bTill Mossakowski */
7d5f239f3f1c1397e5d80caea12929bdf8abe2d8Christian Maederstatic void set_netgr_lifetime(uint32_t lifetime,
7d5f239f3f1c1397e5d80caea12929bdf8abe2d8Christian Maeder struct setent_step_ctx *step_ctx,
e3c9174a782e90f965a0b080c22861c3ef5af12dTill Mossakowski struct getent_ctx *netgr)
b645cf3dc1e449038ed291bbd11fcc6e02b2fc7fChristian Maeder{
ba5c87b3f4a921f0932a08de48a3aedd3ca4d25bTill Mossakowski struct timeval tv;
ba5c87b3f4a921f0932a08de48a3aedd3ca4d25bTill Mossakowski struct tevent_timer *te;
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder
b3dca469a9e267d6d71acfdeca7bf284d0581dc7Till Mossakowski tv = tevent_timeval_current_ofs(lifetime, 0);
b3dca469a9e267d6d71acfdeca7bf284d0581dc7Till Mossakowski te = tevent_add_timer(step_ctx->nctx->rctx->ev,
c40822a6238ef14ebd3df830204c2790a68c8076Christian Maeder step_ctx->nctx->gctx, tv,
ba5c87b3f4a921f0932a08de48a3aedd3ca4d25bTill Mossakowski setnetgrent_result_timeout,
be3f5e3e69900ececafea5b010a8400f26af5362Christian Maeder netgr);
c40822a6238ef14ebd3df830204c2790a68c8076Christian Maeder if (!te) {
ba5c87b3f4a921f0932a08de48a3aedd3ca4d25bTill Mossakowski DEBUG(0, ("Could not set up life timer for setnetgrent result object. "
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder "Entries may become stale.\n"));
ba5c87b3f4a921f0932a08de48a3aedd3ca4d25bTill Mossakowski }
c40822a6238ef14ebd3df830204c2790a68c8076Christian Maeder}
ba5c87b3f4a921f0932a08de48a3aedd3ca4d25bTill Mossakowski
c40822a6238ef14ebd3df830204c2790a68c8076Christian Maederstatic errno_t lookup_netgr_step(struct setent_step_ctx *step_ctx)
12368e292c1abf7eaf975f20ee30ef7820ac5dd5Christian Maeder{
12368e292c1abf7eaf975f20ee30ef7820ac5dd5Christian Maeder errno_t ret;
4c7f058cdd19ce67b2b5d4b7f69703d0f8a21e38Christian Maeder struct sss_domain_info *dom = step_ctx->dctx->domain;
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder struct getent_ctx *netgr;
ba5c87b3f4a921f0932a08de48a3aedd3ca4d25bTill Mossakowski struct sysdb_ctx *sysdb;
c30cfe2a6ab063befdfb47449bc286caee6d8fc3Christian Maeder char *name = NULL;
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder uint32_t lifetime;
b3dca469a9e267d6d71acfdeca7bf284d0581dc7Till Mossakowski
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder /* Check each domain for this netgroup name */
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder while (dom) {
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) {
63fb549acb4eddfd045bb55da66c1fd4ff5b1ac5Christian Maeder dom = get_next_domain(dom, false);
63fb549acb4eddfd045bb55da66c1fd4ff5b1ac5Christian Maeder }
63fb549acb4eddfd045bb55da66c1fd4ff5b1ac5Christian Maeder
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder /* No domains left to search */
63fb549acb4eddfd045bb55da66c1fd4ff5b1ac5Christian Maeder if (!dom) break;
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder
63fb549acb4eddfd045bb55da66c1fd4ff5b1ac5Christian Maeder if (dom != step_ctx->dctx->domain) {
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder /* make sure we reset the check_provider flag when we check
8528053a6a766c3614276df0f59fb2a2e8ab6d18Christian Maeder * a new domain */
283fdbf051a1cbcfe003ffdcb434564495106f13Christian Maeder step_ctx->dctx->check_provider =
283fdbf051a1cbcfe003ffdcb434564495106f13Christian Maeder NEED_CHECK_PROVIDER(dom->provider);
7688e20f844fe88f75c04016841ebb5e5e3d927fChristian Maeder }
6108a4c3e891e85e6b36a658382d7e78ad4ce9e7Christian Maeder
7688e20f844fe88f75c04016841ebb5e5e3d927fChristian Maeder /* make sure to update the dctx if we changed domain */
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder step_ctx->dctx->domain = dom;
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder
c40f5b4da5caf568cf9cc6e81c79613450e321aeChristian Maeder talloc_free(name);
6108a4c3e891e85e6b36a658382d7e78ad4ce9e7Christian Maeder name = sss_get_cased_name(step_ctx, step_ctx->name,
8528053a6a766c3614276df0f59fb2a2e8ab6d18Christian Maeder dom->case_sensitive);
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder if (!name) {
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder DEBUG(SSSDBG_CRIT_FAILURE, ("sss_get_cased_name failed\n"));
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder return ENOMEM;
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder }
6108a4c3e891e85e6b36a658382d7e78ad4ce9e7Christian Maeder
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder DEBUG(4, ("Requesting info for [%s@%s]\n",
1805f9816e3414ab184fb8546ab1abc6241f04cdChristian Maeder name, dom->name));
1805f9816e3414ab184fb8546ab1abc6241f04cdChristian Maeder sysdb = dom->sysdb;
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder if (sysdb == NULL) {
627ed7abdbae641636a2d0f2510c0d450f5ee915Christian Maeder DEBUG(0, ("Fatal: Sysdb CTX not found for this domain!\n"));
1805f9816e3414ab184fb8546ab1abc6241f04cdChristian Maeder return EIO;
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder }
2701083ab584807a8dec6f2c8bc03237a25d9809Christian Maeder
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder /* Look up the netgroup in the cache */
2701083ab584807a8dec6f2c8bc03237a25d9809Christian Maeder ret = sysdb_getnetgr(step_ctx->dctx, sysdb, dom, name,
2701083ab584807a8dec6f2c8bc03237a25d9809Christian Maeder &step_ctx->dctx->res);
ecf557c0b4f953106755a239da2c0b168064d3f4Christian Maeder if (ret == ENOENT) {
1805f9816e3414ab184fb8546ab1abc6241f04cdChristian Maeder /* This netgroup was not found in this domain */
1805f9816e3414ab184fb8546ab1abc6241f04cdChristian Maeder if (!step_ctx->dctx->check_provider) {
1805f9816e3414ab184fb8546ab1abc6241f04cdChristian Maeder if (step_ctx->check_next) {
1805f9816e3414ab184fb8546ab1abc6241f04cdChristian Maeder dom = get_next_domain(dom, false);
ecf557c0b4f953106755a239da2c0b168064d3f4Christian Maeder continue;
1805f9816e3414ab184fb8546ab1abc6241f04cdChristian Maeder }
9efe0bf51725355f7a8be26dd44bb6a69212e7beChristian Maeder else break;
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder }
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder ret = EOK;
1805f9816e3414ab184fb8546ab1abc6241f04cdChristian Maeder }
1805f9816e3414ab184fb8546ab1abc6241f04cdChristian Maeder
1805f9816e3414ab184fb8546ab1abc6241f04cdChristian Maeder if (ret != EOK) {
1805f9816e3414ab184fb8546ab1abc6241f04cdChristian Maeder DEBUG(1, ("Failed to make request to our cache!\n"));
1805f9816e3414ab184fb8546ab1abc6241f04cdChristian Maeder return EIO;
1805f9816e3414ab184fb8546ab1abc6241f04cdChristian Maeder }
1805f9816e3414ab184fb8546ab1abc6241f04cdChristian Maeder
ecf557c0b4f953106755a239da2c0b168064d3f4Christian Maeder ret = get_netgroup_entry(step_ctx->nctx, step_ctx->name,
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder &netgr);
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder if (ret != EOK) {
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder /* Something really bad happened! */
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder DEBUG(0, ("Netgroup entry was lost!\n"));
2701083ab584807a8dec6f2c8bc03237a25d9809Christian Maeder return ret;
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder }
2701083ab584807a8dec6f2c8bc03237a25d9809Christian Maeder
627ed7abdbae641636a2d0f2510c0d450f5ee915Christian Maeder /* Convert the result to a list of entries */
2701083ab584807a8dec6f2c8bc03237a25d9809Christian Maeder ret = sysdb_netgr_to_entries(netgr, step_ctx->dctx->res,
2701083ab584807a8dec6f2c8bc03237a25d9809Christian Maeder &netgr->entries);
2701083ab584807a8dec6f2c8bc03237a25d9809Christian Maeder if (ret == ENOENT) {
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder /* This netgroup was not found in this domain */
2701083ab584807a8dec6f2c8bc03237a25d9809Christian Maeder DEBUG(2, ("No results for netgroup %s (domain %s)\n",
52aad0502f0ddd332a28ae3fcd3327fa66d002f7Till Mossakowski name, dom->name));
52aad0502f0ddd332a28ae3fcd3327fa66d002f7Till Mossakowski
52aad0502f0ddd332a28ae3fcd3327fa66d002f7Till Mossakowski if (!step_ctx->dctx->check_provider) {
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder if (step_ctx->check_next) {
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder dom = get_next_domain(dom, false);
52aad0502f0ddd332a28ae3fcd3327fa66d002f7Till Mossakowski continue;
52aad0502f0ddd332a28ae3fcd3327fa66d002f7Till Mossakowski }
52aad0502f0ddd332a28ae3fcd3327fa66d002f7Till Mossakowski else break;
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder }
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder ret = EOK;
52aad0502f0ddd332a28ae3fcd3327fa66d002f7Till Mossakowski }
52aad0502f0ddd332a28ae3fcd3327fa66d002f7Till Mossakowski
52aad0502f0ddd332a28ae3fcd3327fa66d002f7Till Mossakowski if (ret != EOK) {
52aad0502f0ddd332a28ae3fcd3327fa66d002f7Till Mossakowski DEBUG(1, ("Failed to convert results into entries\n"));
52aad0502f0ddd332a28ae3fcd3327fa66d002f7Till Mossakowski netgr->ready = true;
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder netgr->found = false;
52aad0502f0ddd332a28ae3fcd3327fa66d002f7Till Mossakowski set_netgr_lifetime(step_ctx->nctx->neg_timeout, step_ctx, netgr);
2701083ab584807a8dec6f2c8bc03237a25d9809Christian Maeder return EIO;
2701083ab584807a8dec6f2c8bc03237a25d9809Christian Maeder }
52aad0502f0ddd332a28ae3fcd3327fa66d002f7Till Mossakowski
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 */
ff3bc28a09cff76d4d6cbe8914ab53d1e032d009Till Mossakowski if (step_ctx->dctx->check_provider) {
4c7f058cdd19ce67b2b5d4b7f69703d0f8a21e38Christian Maeder ret = check_cache(step_ctx->dctx,
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder step_ctx->nctx,
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder step_ctx->dctx->res,
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder SSS_DP_NETGR,
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder name, 0,
de66af0f4b27f08f81c7ca9c573ef9cdf7ca7a07Christian Maeder lookup_netgr_dp_callback,
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder step_ctx);
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder if (ret != EOK) {
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder /* May return EAGAIN legitimately to indicate that
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder * we need to reenter the mainloop
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder */
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder return ret;
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder }
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder }
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder /* Results found */
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder DEBUG(6, ("Returning info for netgroup [%s@%s]\n",
62607bfd8541a700d18aee4f9cdb037aded5ab0bChristian Maeder name, dom->name));
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder netgr->ready = true;
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder netgr->found = true;
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder if (step_ctx->nctx->cache_refresh_percent) {
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder lifetime = dom->netgroup_timeout *
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder (step_ctx->nctx->cache_refresh_percent / 100.0);
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder } else {
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder lifetime = dom->netgroup_timeout;
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder }
89ab08979dc23d72e9e09c8990a8c44847041d6fChristian Maeder if (lifetime < 10) lifetime = 10;
89ab08979dc23d72e9e09c8990a8c44847041d6fChristian Maeder set_netgr_lifetime(lifetime, step_ctx, netgr);
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder return EOK;
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder }
4c7f058cdd19ce67b2b5d4b7f69703d0f8a21e38Christian Maeder
4c7f058cdd19ce67b2b5d4b7f69703d0f8a21e38Christian Maeder /* If we've gotten here, then no domain contained this netgroup */
de66af0f4b27f08f81c7ca9c573ef9cdf7ca7a07Christian Maeder DEBUG(SSSDBG_MINOR_FAILURE,
de66af0f4b27f08f81c7ca9c573ef9cdf7ca7a07Christian Maeder ("No matching domain found for [%s], fail!\n", step_ctx->name));
12368e292c1abf7eaf975f20ee30ef7820ac5dd5Christian Maeder
12368e292c1abf7eaf975f20ee30ef7820ac5dd5Christian Maeder netgr = talloc_zero(step_ctx->nctx, struct getent_ctx);
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder if (netgr == NULL) {
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder DEBUG(1, ("talloc_zero failed, ignored.\n"));
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder } else {
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder netgr->ready = true;
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder netgr->found = false;
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder netgr->entries = NULL;
37d0b201b8ba5d6056691e3055dd803e7928e163Christian Maeder netgr->lookup_table = step_ctx->nctx->netgroups;
4c7f058cdd19ce67b2b5d4b7f69703d0f8a21e38Christian Maeder netgr->name = talloc_strdup(netgr, step_ctx->name);
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder if (netgr->name == NULL) {
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder DEBUG(1, ("talloc_strdup failed.\n"));
4c7f058cdd19ce67b2b5d4b7f69703d0f8a21e38Christian Maeder talloc_free(netgr);
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder return ENOMEM;
ecf557c0b4f953106755a239da2c0b168064d3f4Christian Maeder }
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder ret = set_netgroup_entry(step_ctx->nctx, netgr);
ecf557c0b4f953106755a239da2c0b168064d3f4Christian Maeder if (ret != EOK) {
ecf557c0b4f953106755a239da2c0b168064d3f4Christian Maeder DEBUG(1, ("set_netgroup_entry failed, ignored.\n"));
7bf4436b6f9987b070033a323757b206c898c1beChristian Maeder }
ecf557c0b4f953106755a239da2c0b168064d3f4Christian Maeder set_netgr_lifetime(step_ctx->nctx->neg_timeout, step_ctx, netgr);
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder }
0c2a90cbfb63865ff485c3fbe20a14589a5914beTill Mossakowski
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder return ENOENT;
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder}
79ee6b8eb396ed31807784a4bb1c9cc2ce094835Till Mossakowski
79ee6b8eb396ed31807784a4bb1c9cc2ce094835Till Mossakowskistatic void lookup_netgr_dp_callback(uint16_t err_maj, uint32_t err_min,
ecf557c0b4f953106755a239da2c0b168064d3f4Christian Maeder const char *err_msg, void *ptr)
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder{
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder struct setent_step_ctx *step_ctx =
ecf557c0b4f953106755a239da2c0b168064d3f4Christian Maeder talloc_get_type(ptr, struct setent_step_ctx);
ecf557c0b4f953106755a239da2c0b168064d3f4Christian Maeder struct nss_dom_ctx *dctx = step_ctx->dctx;
37d0b201b8ba5d6056691e3055dd803e7928e163Christian Maeder struct nss_cmd_ctx *cmdctx = dctx->cmdctx;
37d0b201b8ba5d6056691e3055dd803e7928e163Christian Maeder int ret;
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maeder if (err_maj) {
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 }
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maeder }
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maeder
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maeder /* ok the backend returned, search to see if we have updated results */
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maeder ret = lookup_netgr_step(step_ctx);
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maeder if (ret != EOK) {
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maeder if (ret == EAGAIN) {
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maeder return;
ecf557c0b4f953106755a239da2c0b168064d3f4Christian Maeder }
ecf557c0b4f953106755a239da2c0b168064d3f4Christian Maeder }
ecf557c0b4f953106755a239da2c0b168064d3f4Christian Maeder
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maeder /* We have results to return */
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maeder nss_setent_notify_error(dctx->netgr, ret);
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maeder}
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maeder
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maederstatic void setnetgrent_result_timeout(struct tevent_context *ev,
a89e661aad28f1b39f4fc9f9f9a4d46074234123Christian Maeder struct tevent_timer *te,
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder struct timeval current_time,
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder void *pvt)
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder{
a89e661aad28f1b39f4fc9f9f9a4d46074234123Christian Maeder struct getent_ctx *netgr =
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder talloc_get_type(pvt, struct getent_ctx);
89ab08979dc23d72e9e09c8990a8c44847041d6fChristian Maeder
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 *
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maeder * If additional getnetgrent() requests come in, they
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maeder * will invoke an implicit setnetgrent() call and
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maeder * refresh the result object
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maeder */
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maeder talloc_free(netgr);
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maeder}
f8fe1f095d5b7fd96bde0784289b001446e60d0bChristian Maeder
587fb54160b66128cf17e4c9bca7494a7f2c3c4aChristian Maederstatic errno_t setnetgrent_recv(struct tevent_req *req)
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder{
8528053a6a766c3614276df0f59fb2a2e8ab6d18Christian Maeder TEVENT_REQ_RETURN_ON_ERROR(req);
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder return EOK;
7d5f239f3f1c1397e5d80caea12929bdf8abe2d8Christian Maeder}
89ab08979dc23d72e9e09c8990a8c44847041d6fChristian Maeder
7d5f239f3f1c1397e5d80caea12929bdf8abe2d8Christian Maederstatic void nss_cmd_setnetgrent_done(struct tevent_req *req)
7688e20f844fe88f75c04016841ebb5e5e3d927fChristian Maeder{
7688e20f844fe88f75c04016841ebb5e5e3d927fChristian Maeder errno_t reqret;
b9804822fb178b0fc27ce967a6a8cedc42c5bf90Christian Maeder errno_t ret;
b9804822fb178b0fc27ce967a6a8cedc42c5bf90Christian Maeder struct sss_packet *packet;
b9804822fb178b0fc27ce967a6a8cedc42c5bf90Christian Maeder uint8_t *body;
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski size_t blen;
b9804822fb178b0fc27ce967a6a8cedc42c5bf90Christian Maeder
37d0b201b8ba5d6056691e3055dd803e7928e163Christian Maeder struct nss_cmd_ctx *cmdctx =
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski tevent_req_callback_data(req, struct nss_cmd_ctx);
7d5f239f3f1c1397e5d80caea12929bdf8abe2d8Christian Maeder
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski reqret = setnetgrent_recv(req);
7d5f239f3f1c1397e5d80caea12929bdf8abe2d8Christian Maeder talloc_zfree(req);
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski if (reqret != EOK && reqret != ENOENT) {
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder DEBUG(1, ("setnetgrent failed\n"));
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder nss_cmd_done(cmdctx, reqret);
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder return;
37d0b201b8ba5d6056691e3055dd803e7928e163Christian Maeder }
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski
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 &cmdctx->cctx->creq->out);
89ab08979dc23d72e9e09c8990a8c44847041d6fChristian Maeder if (ret == EOK) {
89ab08979dc23d72e9e09c8990a8c44847041d6fChristian Maeder if (reqret == ENOENT) {
89ab08979dc23d72e9e09c8990a8c44847041d6fChristian Maeder /* Notify the caller that this entry wasn't found */
89ab08979dc23d72e9e09c8990a8c44847041d6fChristian Maeder sss_cmd_empty_packet(cmdctx->cctx->creq->out);
89ab08979dc23d72e9e09c8990a8c44847041d6fChristian Maeder } else {
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder packet = cmdctx->cctx->creq->out;
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder ret = sss_packet_grow(packet, 2*sizeof(uint32_t));
b9804822fb178b0fc27ce967a6a8cedc42c5bf90Christian Maeder if (ret != EOK) {
4c7f058cdd19ce67b2b5d4b7f69703d0f8a21e38Christian Maeder DEBUG(1, ("Couldn't grow the packet\n"));
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski NSS_CMD_FATAL_ERROR(cmdctx);
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski }
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski sss_packet_get_body(packet, &body, &blen);
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski ((uint32_t *)body)[0] = 1; /* Got some results */
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder ((uint32_t *)body)[1] = 0; /* reserved */
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder }
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder sss_cmd_done(cmdctx->cctx, NULL);
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder return;
8528053a6a766c3614276df0f59fb2a2e8ab6d18Christian Maeder }
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder
8528053a6a766c3614276df0f59fb2a2e8ab6d18Christian Maeder DEBUG(1, ("Error creating packet\n"));
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder}
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder
4c7f058cdd19ce67b2b5d4b7f69703d0f8a21e38Christian Maederstatic void setnetgrent_implicit_done(struct tevent_req *req);
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maederstatic errno_t nss_cmd_getnetgrent_process(struct nss_cmd_ctx *cmdctx,
37d0b201b8ba5d6056691e3055dd803e7928e163Christian Maeder struct getent_ctx *netgr);
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowskiint nss_cmd_getnetgrent(struct cli_ctx *client)
7d5f239f3f1c1397e5d80caea12929bdf8abe2d8Christian Maeder{
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski errno_t ret;
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder struct nss_ctx *nctx;
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder struct nss_cmd_ctx *cmdctx;
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski struct getent_ctx *netgr;
64601796d2f62ffe61e9a5340dc569dd41dc2244Christian Maeder struct tevent_req *req;
9d34a8049237647d0188ee2ec88db2dc45f1f848Till Mossakowski
4c7f058cdd19ce67b2b5d4b7f69703d0f8a21e38Christian Maeder DEBUG(4, ("Requesting netgroup data\n"));
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski
4c7f058cdd19ce67b2b5d4b7f69703d0f8a21e38Christian Maeder cmdctx = talloc_zero(client, struct nss_cmd_ctx);
e24d81c69aecd41abb2f4969519c9e7126b1d687Christian Maeder if (!cmdctx) {
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski return ENOMEM;
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski }
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder cmdctx->cctx = client;
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder nctx = talloc_get_type(client->rctx->pvt_ctx, struct nss_ctx);
e24d81c69aecd41abb2f4969519c9e7126b1d687Christian Maeder
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder if (!client->netgr_name) {
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.
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski */
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski return nss_cmd_done(cmdctx, EINVAL);
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder }
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder /* Look up the results from the hash */
a05cad7f2f387b795a71a3aaec543c78e1b89d38Christian Maeder ret = get_netgroup_entry(nctx, client->netgr_name, &netgr);
8528053a6a766c3614276df0f59fb2a2e8ab6d18Christian Maeder if (ret == ENOENT) {
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder /* We need to invoke an implicit setnetgrent() to
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder * wait for the result object to become available.
0d0047d6eb457b56ff10987569769a420754a56fChristian Maeder */
0d0047d6eb457b56ff10987569769a420754a56fChristian Maeder
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder req = setnetgrent_send(cmdctx, client->netgr_name, cmdctx);
8528053a6a766c3614276df0f59fb2a2e8ab6d18Christian Maeder if (!req) {
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder return nss_cmd_done(cmdctx, EIO);
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder }
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder tevent_req_set_callback(req, setnetgrent_implicit_done, cmdctx);
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder return EOK;
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski } else if (ret != EOK) {
a946fa1fe525f04a8b4e2734fa2082bbe5e6ed3fTill Mossakowski DEBUG(1, ("An unexpected error occurred: [%d][%s]\n",
37d0b201b8ba5d6056691e3055dd803e7928e163Christian Maeder ret, strerror(ret)));
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder return nss_cmd_done(cmdctx, ret);
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder }
89ab08979dc23d72e9e09c8990a8c44847041d6fChristian Maeder
89ab08979dc23d72e9e09c8990a8c44847041d6fChristian Maeder /* Hash entry was found. Is it ready? */
7d5f239f3f1c1397e5d80caea12929bdf8abe2d8Christian Maeder if (!netgr->ready) {
7d5f239f3f1c1397e5d80caea12929bdf8abe2d8Christian Maeder /* We need to invoke an implicit setnetgrent() to
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski * wait for the result object to become available.
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski */
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski req = setnetgrent_send(cmdctx, client->netgr_name, cmdctx);
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski if (!req) {
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder return nss_cmd_done(cmdctx, EIO);
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder }
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder tevent_req_set_callback(req, setnetgrent_implicit_done, cmdctx);
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski
0dcb86310998e097d3b15608f980f0a89a11a322Christian Maeder return EOK;
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski } else if (!netgr->found) {
dbbcdfeafa68c87e0b2be0096788844e2be08345Christian Maeder DEBUG(6, ("Results for [%s] not found.\n", client->netgr_name));
410ff490af511ffa09b52e4de631d36a154b9730Christian Maeder return ENOENT;
410ff490af511ffa09b52e4de631d36a154b9730Christian Maeder }
89ab08979dc23d72e9e09c8990a8c44847041d6fChristian Maeder
89ab08979dc23d72e9e09c8990a8c44847041d6fChristian Maeder DEBUG(6, ("Returning results for [%s]\n", client->netgr_name));
89ab08979dc23d72e9e09c8990a8c44847041d6fChristian Maeder
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski /* Read the result strings */
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder ret = nss_cmd_getnetgrent_process(cmdctx, netgr);
88ece6e49930670e8fd3ee79c89a2e918d2fbd0cChristian Maeder if (ret != EOK) {
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder DEBUG(1, ("Failed: [%d][%s]\n", ret, strerror(ret)));
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski }
0dcb86310998e097d3b15608f980f0a89a11a322Christian Maeder return ret;
0dcb86310998e097d3b15608f980f0a89a11a322Christian Maeder}
0dcb86310998e097d3b15608f980f0a89a11a322Christian Maeder
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowskistatic void setnetgrent_implicit_done(struct tevent_req *req)
88ece6e49930670e8fd3ee79c89a2e918d2fbd0cChristian Maeder{
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder errno_t ret;
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski struct getent_ctx *netgr;
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder struct nss_cmd_ctx *cmdctx =
7297175957c5ad3c0498032190b1dee9ec5fb873Christian Maeder tevent_req_callback_data(req, struct nss_cmd_ctx);
7297175957c5ad3c0498032190b1dee9ec5fb873Christian Maeder struct nss_ctx *nctx =
7297175957c5ad3c0498032190b1dee9ec5fb873Christian Maeder talloc_get_type(cmdctx->cctx->rctx->pvt_ctx, struct nss_ctx);
64601796d2f62ffe61e9a5340dc569dd41dc2244Christian Maeder
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder ret = setnetgrent_recv(req);
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder talloc_zfree(req);
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder
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
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder */
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder if (ret != EOK && ret != ENOENT) {
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder DEBUG(0, ("Implicit setnetgrent failed with unexpected error "
88ece6e49930670e8fd3ee79c89a2e918d2fbd0cChristian Maeder "[%d][%s]\n", ret, strerror(ret)));
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski NSS_CMD_FATAL_ERROR(cmdctx);
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski }
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder if (ret == ENOENT) {
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski /* No entries found for this netgroup */
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski nss_cmd_done(cmdctx, ret);
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder return;
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder }
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski
3476beb5baf84bef7cc7d627b130de9d48700399Christian Maeder /* Look up the results from the hash */
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder ret = get_netgroup_entry(nctx, cmdctx->cctx->netgr_name, &netgr);
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder if (ret == ENOENT) {
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 NSS_CMD_FATAL_ERROR(cmdctx);
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder } else if (ret != EOK) {
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski DEBUG(1, ("An unexpected error occurred: [%d][%s]\n",
4c7f058cdd19ce67b2b5d4b7f69703d0f8a21e38Christian Maeder ret, strerror(ret)));
d8220f52119f85832e72228b82543fa638449eecChristian Maeder
3cb09c6460a2262e392c759e363bf645f913a47aChristian Maeder NSS_CMD_FATAL_ERROR(cmdctx);
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder }
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder
88ece6e49930670e8fd3ee79c89a2e918d2fbd0cChristian Maeder if (!netgr->ready) {
88ece6e49930670e8fd3ee79c89a2e918d2fbd0cChristian Maeder /* Critical error. This should never happen */
89ab08979dc23d72e9e09c8990a8c44847041d6fChristian Maeder DEBUG(0, ("Implicit setnetgrent returned success without creating "
89ab08979dc23d72e9e09c8990a8c44847041d6fChristian Maeder "result object.\n"));
89ab08979dc23d72e9e09c8990a8c44847041d6fChristian Maeder NSS_CMD_FATAL_ERROR(cmdctx);
ed373f8356ebc42bd83aaa5ff9b908e07721f2beChristian Maeder }
ed20c3b1e992d174a2cbb2077e61817527f8e061Christian Maeder
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder ret = nss_cmd_getnetgrent_process(cmdctx, netgr);
f9690de9acb57e279b8ad5792d71b48ffbb807e7Christian Maeder if (ret != EOK) {
f9690de9acb57e279b8ad5792d71b48ffbb807e7Christian Maeder DEBUG(0, ("Immediate retrieval failed with unexpected error "
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder "[%d][%s]\n", ret, strerror(ret)));
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder NSS_CMD_FATAL_ERROR(cmdctx);
ed20c3b1e992d174a2cbb2077e61817527f8e061Christian Maeder }
88ece6e49930670e8fd3ee79c89a2e918d2fbd0cChristian Maeder}
89ab08979dc23d72e9e09c8990a8c44847041d6fChristian Maeder
89ab08979dc23d72e9e09c8990a8c44847041d6fChristian Maederstatic errno_t nss_cmd_retnetgrent(struct cli_ctx *client,
89ab08979dc23d72e9e09c8990a8c44847041d6fChristian Maeder struct sysdb_netgroup_ctx **entries,
1bc5dccbf0083a620ae1181c717fea75e4af5e5cChristian Maeder int num);
4c7f058cdd19ce67b2b5d4b7f69703d0f8a21e38Christian Maederstatic errno_t nss_cmd_getnetgrent_process(struct nss_cmd_ctx *cmdctx,
64601796d2f62ffe61e9a5340dc569dd41dc2244Christian Maeder struct getent_ctx *netgr)
58b671de3fe578346fef9642ffa3c5a0a0edb3cbTill Mossakowski{
64601796d2f62ffe61e9a5340dc569dd41dc2244Christian Maeder struct cli_ctx *client = cmdctx->cctx;
64601796d2f62ffe61e9a5340dc569dd41dc2244Christian Maeder uint8_t *body;
7688e20f844fe88f75c04016841ebb5e5e3d927fChristian Maeder size_t blen;
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder uint32_t num;
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder errno_t ret;
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder
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 if (blen != sizeof(uint32_t)) {
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder return EINVAL;
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder }
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder num = *((uint32_t *)body);
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder /* create response packet */
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder ret = sss_packet_new(client->creq, 0,
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder sss_packet_get_cmd(client->creq->in),
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder &client->creq->out);
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder if (ret != EOK) {
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder return ret;
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder }
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder
95c27038582e8a2ce24923bee69ef15931b8b87bChristian Maeder if (!netgr->entries || netgr->entries[0] == NULL) {
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder /* No entries */
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder DEBUG(5, ("No entries found\n"));
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder ret = sss_cmd_empty_packet(client->creq->out);
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder if (ret != EOK) {
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder return nss_cmd_done(cmdctx, ret);
587fb54160b66128cf17e4c9bca7494a7f2c3c4aChristian Maeder }
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder goto done;
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder }
6157bf81d295795067c177aa870fedff83cbe750Christian Maeder
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder ret = nss_cmd_retnetgrent(client, netgr->entries, num);
a80f2865b6b40a922bcccfce0cb0d047edc33e3aChristian Maeder
587fb54160b66128cf17e4c9bca7494a7f2c3c4aChristian Maederdone:
22dd6d9af47163ee081d6c505d0a13dbf40ba87aChristian Maeder sss_packet_set_error(client->creq->out, ret);
7297175957c5ad3c0498032190b1dee9ec5fb873Christian Maeder sss_cmd_done(client, cmdctx);
b03274844ecd270f9e9331f51cc4236a33e2e671Christian Maeder
0d0047d6eb457b56ff10987569769a420754a56fChristian Maeder return EOK;
0d0047d6eb457b56ff10987569769a420754a56fChristian Maeder}
95c3e5d11dcee331dc3876a9bf0c1d6daa38e2caChristian Maeder
4a8f990902448d0562fbe1a98ce685ddbd531d38Christian Maederstatic errno_t nss_cmd_retnetgrent(struct cli_ctx *client,
4a8f990902448d0562fbe1a98ce685ddbd531d38Christian Maeder struct sysdb_netgroup_ctx **entries,
4a8f990902448d0562fbe1a98ce685ddbd531d38Christian Maeder int count)
1af66b491a6164e07ac202abfa0d06c6c2462d64Christian Maeder{
1af66b491a6164e07ac202abfa0d06c6c2462d64Christian Maeder size_t len;
dbbcdfeafa68c87e0b2be0096788844e2be08345Christian Maeder size_t hostlen = 0;
dbbcdfeafa68c87e0b2be0096788844e2be08345Christian Maeder size_t userlen = 0;
dbbcdfeafa68c87e0b2be0096788844e2be08345Christian Maeder size_t domainlen = 0;
1af66b491a6164e07ac202abfa0d06c6c2462d64Christian Maeder size_t grouplen = 0;
1af66b491a6164e07ac202abfa0d06c6c2462d64Christian Maeder uint8_t *body;
1af66b491a6164e07ac202abfa0d06c6c2462d64Christian Maeder size_t blen, rp;
1af66b491a6164e07ac202abfa0d06c6c2462d64Christian Maeder errno_t ret;
1af66b491a6164e07ac202abfa0d06c6c2462d64Christian Maeder struct sss_packet *packet = client->creq->out;
1af66b491a6164e07ac202abfa0d06c6c2462d64Christian Maeder int num, start;
4a8f990902448d0562fbe1a98ce685ddbd531d38Christian Maeder
4a8f990902448d0562fbe1a98ce685ddbd531d38Christian Maeder /* first 2 fields (len and reserved), filled up later */
4a8f990902448d0562fbe1a98ce685ddbd531d38Christian Maeder rp = 2*sizeof(uint32_t);
4a8f990902448d0562fbe1a98ce685ddbd531d38Christian Maeder ret = sss_packet_grow(packet, rp);
6b00a9239fe7c804524099ca3d25f4ffc6079ceeChristian Maeder if (ret != EOK) return ret;
6b00a9239fe7c804524099ca3d25f4ffc6079ceeChristian Maeder
4a8f990902448d0562fbe1a98ce685ddbd531d38Christian Maeder start = client->netgrent_cur;
6b00a9239fe7c804524099ca3d25f4ffc6079ceeChristian Maeder num = 0;
6b00a9239fe7c804524099ca3d25f4ffc6079ceeChristian Maeder while (entries[client->netgrent_cur] &&
6b00a9239fe7c804524099ca3d25f4ffc6079ceeChristian Maeder (client->netgrent_cur - start) < count) {
4a8f990902448d0562fbe1a98ce685ddbd531d38Christian Maeder if (entries[client->netgrent_cur]->type == SYSDB_NETGROUP_TRIPLE_VAL) {
1af66b491a6164e07ac202abfa0d06c6c2462d64Christian Maeder hostlen = 1;
1af66b491a6164e07ac202abfa0d06c6c2462d64Christian Maeder if (entries[client->netgrent_cur]->value.triple.hostname) {
6b00a9239fe7c804524099ca3d25f4ffc6079ceeChristian Maeder hostlen += strlen(entries[client->netgrent_cur]->value.triple.hostname);
1af66b491a6164e07ac202abfa0d06c6c2462d64Christian Maeder }
1af66b491a6164e07ac202abfa0d06c6c2462d64Christian Maeder
1af66b491a6164e07ac202abfa0d06c6c2462d64Christian Maeder userlen = 1;
1af66b491a6164e07ac202abfa0d06c6c2462d64Christian Maeder if (entries[client->netgrent_cur]->value.triple.username) {
1af66b491a6164e07ac202abfa0d06c6c2462d64Christian Maeder userlen += strlen(entries[client->netgrent_cur]->value.triple.username);
1af66b491a6164e07ac202abfa0d06c6c2462d64Christian Maeder }
1af66b491a6164e07ac202abfa0d06c6c2462d64Christian Maeder
1af66b491a6164e07ac202abfa0d06c6c2462d64Christian Maeder domainlen = 1;
1af66b491a6164e07ac202abfa0d06c6c2462d64Christian Maeder if (entries[client->netgrent_cur]->value.triple.domainname) {
6b00a9239fe7c804524099ca3d25f4ffc6079ceeChristian Maeder 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;
}