10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce/*
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce * System Security Services Daemon. NSS client interface
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce *
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce * Copyright (C) Simo Sorce 2011
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce *
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce * This program is free software; you can redistribute it and/or modify
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce * it under the terms of the GNU Lesser General Public License as
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce * published by the Free Software Foundation; either version 2.1 of the
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce * License, or (at your option) any later version.
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce *
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce * This program is distributed in the hope that it will be useful,
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce * but WITHOUT ANY WARRANTY; without even the implied warranty of
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce * GNU Lesser General Public License for more details.
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce *
287e76479d68db4134274d4a4fca5fe0fbc9a605Jan Cholasta * You should have received a copy of the GNU Lesser General Public License
287e76479d68db4134274d4a4fca5fe0fbc9a605Jan Cholasta * along with this program. If not, see <http://www.gnu.org/licenses/>.
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce */
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce/* GROUP database NSS interface using mmap cache */
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce#include <errno.h>
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce#include <stdio.h>
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce#include <string.h>
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce#include <stdlib.h>
8a5931bcc8e9034e4beb92fc9addf3f7fcf83fd6Michal Zidek#include <stddef.h>
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce#include <sys/mman.h>
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce#include <time.h>
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce#include "nss_mc.h"
3996e391054a1c02ab62e1541ae21a8204bd5d0aAmitKumar#include "shared/safealign.h"
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce
6a60e29468fc6b4043a4dc52d3aab73e8465db70Lukas Slebodnikstruct sss_cli_mc_ctx gr_mc_ctx = { UNINITIALIZED, -1, 0, NULL, 0, NULL, 0,
6a60e29468fc6b4043a4dc52d3aab73e8465db70Lukas Slebodnik NULL, 0, 0 };
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorcestatic errno_t sss_nss_mc_parse_result(struct sss_mc_rec *rec,
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce struct group *result,
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce char *buffer, size_t buflen)
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce{
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce struct sss_mc_grp_data *data;
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce time_t expire;
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce void *cookie;
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce char *membuf;
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce size_t memsize;
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce int ret;
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce int i;
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce /* additional checks before filling result*/
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce expire = rec->expire;
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce if (expire < time(NULL)) {
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce /* entry is now invalid */
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce return EINVAL;
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce }
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce data = (struct sss_mc_grp_data *)rec->data;
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce memsize = (data->members + 1) * sizeof(char *);
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce if (data->strs_len + memsize > buflen) {
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce return ERANGE;
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce }
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce /* fill in glibc provided structs */
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce /* copy in buffer */
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce membuf = buffer + memsize;
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce memcpy(membuf, data->strs, data->strs_len);
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce /* fill in group */
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce result->gr_gid = data->gid;
8bf65dbab8703697c85b033beb5c189fce17b036Michal Zidek
8bf65dbab8703697c85b033beb5c189fce17b036Michal Zidek /* The address &buffer[0] must be aligned to sizeof(char *) */
8bf65dbab8703697c85b033beb5c189fce17b036Michal Zidek if (!IS_ALIGNED(buffer, char *)) {
8bf65dbab8703697c85b033beb5c189fce17b036Michal Zidek /* The buffer is not properly aligned. */
8bf65dbab8703697c85b033beb5c189fce17b036Michal Zidek return EFAULT;
8bf65dbab8703697c85b033beb5c189fce17b036Michal Zidek }
8bf65dbab8703697c85b033beb5c189fce17b036Michal Zidek
90ac46f71068d131391492360a8553bdd005b5a7Michal Zidek result->gr_mem = DISCARD_ALIGN(buffer, char **);
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce result->gr_mem[data->members] = NULL;
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce cookie = NULL;
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce ret = sss_nss_str_ptr_from_buffer(&result->gr_name, &cookie,
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce membuf, data->strs_len);
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce if (ret) {
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce return ret;
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce }
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce ret = sss_nss_str_ptr_from_buffer(&result->gr_passwd, &cookie,
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce membuf, data->strs_len);
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce if (ret) {
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce return ret;
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce }
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce for (i = 0; i < data->members; i++) {
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce ret = sss_nss_str_ptr_from_buffer(&result->gr_mem[i], &cookie,
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce membuf, data->strs_len);
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce if (ret) {
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce return ret;
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce }
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce }
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce if (cookie != NULL) {
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce return EINVAL;
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce }
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce return 0;
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce}
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorceerrno_t sss_nss_mc_getgrnam(const char *name, size_t name_len,
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce struct group *result,
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce char *buffer, size_t buflen)
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce{
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce struct sss_mc_rec *rec = NULL;
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce struct sss_mc_grp_data *data;
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce char *rec_name;
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce uint32_t hash;
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce uint32_t slot;
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce int ret;
ba847347cade817ee927397d82c952b51b0dcb2bLukas Slebodnik const size_t strs_offset = offsetof(struct sss_mc_grp_data, strs);
ba847347cade817ee927397d82c952b51b0dcb2bLukas Slebodnik size_t data_size;
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce ret = sss_nss_mc_get_ctx("group", &gr_mc_ctx);
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce if (ret) {
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce return ret;
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce }
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce
ba847347cade817ee927397d82c952b51b0dcb2bLukas Slebodnik /* Get max size of data table. */
ba847347cade817ee927397d82c952b51b0dcb2bLukas Slebodnik data_size = gr_mc_ctx.dt_size;
8a5931bcc8e9034e4beb92fc9addf3f7fcf83fd6Michal Zidek
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce /* hashes are calculated including the NULL terminator */
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce hash = sss_nss_mc_hash(&gr_mc_ctx, name, name_len + 1);
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce slot = gr_mc_ctx.hash_table[hash];
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce
080e1bfb72ed0e8d96e390d83ad35eaba79bd450René Genz /* If slot is not within the bounds of mmapped region and
e61044d99ce1e68057fda236f04a731f1f3f299aMichal Zidek * it's value is not MC_INVALID_VAL, then the cache is
080e1bfb72ed0e8d96e390d83ad35eaba79bd450René Genz * probably corrupted. */
ba847347cade817ee927397d82c952b51b0dcb2bLukas Slebodnik while (MC_SLOT_WITHIN_BOUNDS(slot, data_size)) {
9d876108620931e0941a115adf60bfd8d67459d9Lukas Slebodnik /* free record from previous iteration */
9d876108620931e0941a115adf60bfd8d67459d9Lukas Slebodnik free(rec);
9d876108620931e0941a115adf60bfd8d67459d9Lukas Slebodnik rec = NULL;
9d876108620931e0941a115adf60bfd8d67459d9Lukas Slebodnik
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce ret = sss_nss_mc_get_record(&gr_mc_ctx, slot, &rec);
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce if (ret) {
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce goto done;
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce }
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce /* check record matches what we are searching for */
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce if (hash != rec->hash1) {
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce /* if name hash does not match we can skip this immediately */
581de96fc30b7fe44070f17a8a73f3374d38d6ffLukas Slebodnik slot = sss_nss_mc_next_slot_with_hash(rec, hash);
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce continue;
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce }
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce data = (struct sss_mc_grp_data *)rec->data;
4382047490dd4f80b407cc1e618da048f13e5f8fSumit Bose rec_name = (char *)data + data->name;
8a5931bcc8e9034e4beb92fc9addf3f7fcf83fd6Michal Zidek /* Integrity check
8a5931bcc8e9034e4beb92fc9addf3f7fcf83fd6Michal Zidek * - data->name cannot point outside strings
ba847347cade817ee927397d82c952b51b0dcb2bLukas Slebodnik * - all strings must be within copy of record
4382047490dd4f80b407cc1e618da048f13e5f8fSumit Bose * - record must not end outside data table
4382047490dd4f80b407cc1e618da048f13e5f8fSumit Bose * - rec_name is a zero-terminated string */
4382047490dd4f80b407cc1e618da048f13e5f8fSumit Bose if (data->name < strs_offset
4382047490dd4f80b407cc1e618da048f13e5f8fSumit Bose || data->name >= strs_offset + data->strs_len
ba847347cade817ee927397d82c952b51b0dcb2bLukas Slebodnik || data->strs_len > rec->len
fd17e0925dbcafedb878ddf828a37743c115c9ddLukas Slebodnik || (uint8_t *) rec + rec->len > gr_mc_ctx.data_table + data_size) {
8a5931bcc8e9034e4beb92fc9addf3f7fcf83fd6Michal Zidek ret = ENOENT;
8a5931bcc8e9034e4beb92fc9addf3f7fcf83fd6Michal Zidek goto done;
8a5931bcc8e9034e4beb92fc9addf3f7fcf83fd6Michal Zidek }
8a5931bcc8e9034e4beb92fc9addf3f7fcf83fd6Michal Zidek
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce if (strcmp(name, rec_name) == 0) {
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce break;
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce }
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce
581de96fc30b7fe44070f17a8a73f3374d38d6ffLukas Slebodnik slot = sss_nss_mc_next_slot_with_hash(rec, hash);
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce }
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce
ba847347cade817ee927397d82c952b51b0dcb2bLukas Slebodnik if (!MC_SLOT_WITHIN_BOUNDS(slot, data_size)) {
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce ret = ENOENT;
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce goto done;
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce }
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce ret = sss_nss_mc_parse_result(rec, result, buffer, buflen);
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorcedone:
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce free(rec);
6a60e29468fc6b4043a4dc52d3aab73e8465db70Lukas Slebodnik __sync_sub_and_fetch(&gr_mc_ctx.active_threads, 1);
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce return ret;
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce}
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorceerrno_t sss_nss_mc_getgrgid(gid_t gid,
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce struct group *result,
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce char *buffer, size_t buflen)
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce{
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce struct sss_mc_rec *rec = NULL;
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce struct sss_mc_grp_data *data;
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce char gidstr[11];
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce uint32_t hash;
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce uint32_t slot;
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce int len;
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce int ret;
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce ret = sss_nss_mc_get_ctx("group", &gr_mc_ctx);
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce if (ret) {
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce return ret;
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce }
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce len = snprintf(gidstr, 11, "%ld", (long)gid);
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce if (len > 10) {
6a60e29468fc6b4043a4dc52d3aab73e8465db70Lukas Slebodnik ret = EINVAL;
6a60e29468fc6b4043a4dc52d3aab73e8465db70Lukas Slebodnik goto done;
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce }
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce /* hashes are calculated including the NULL terminator */
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce hash = sss_nss_mc_hash(&gr_mc_ctx, gidstr, len+1);
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce slot = gr_mc_ctx.hash_table[hash];
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce
080e1bfb72ed0e8d96e390d83ad35eaba79bd450René Genz /* If slot is not within the bounds of mmapped region and
e61044d99ce1e68057fda236f04a731f1f3f299aMichal Zidek * it's value is not MC_INVALID_VAL, then the cache is
080e1bfb72ed0e8d96e390d83ad35eaba79bd450René Genz * probably corrupted. */
13df7b9e400211c717284fb841c849ba034ed348Michal Zidek while (MC_SLOT_WITHIN_BOUNDS(slot, gr_mc_ctx.dt_size)) {
9d876108620931e0941a115adf60bfd8d67459d9Lukas Slebodnik /* free record from previous iteration */
9d876108620931e0941a115adf60bfd8d67459d9Lukas Slebodnik free(rec);
9d876108620931e0941a115adf60bfd8d67459d9Lukas Slebodnik rec = NULL;
9d876108620931e0941a115adf60bfd8d67459d9Lukas Slebodnik
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce ret = sss_nss_mc_get_record(&gr_mc_ctx, slot, &rec);
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce if (ret) {
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce goto done;
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce }
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce /* check record matches what we are searching for */
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce if (hash != rec->hash2) {
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce /* if uid hash does not match we can skip this immediately */
581de96fc30b7fe44070f17a8a73f3374d38d6ffLukas Slebodnik slot = sss_nss_mc_next_slot_with_hash(rec, hash);
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce continue;
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce }
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce data = (struct sss_mc_grp_data *)rec->data;
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce if (gid == data->gid) {
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce break;
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce }
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce
581de96fc30b7fe44070f17a8a73f3374d38d6ffLukas Slebodnik slot = sss_nss_mc_next_slot_with_hash(rec, hash);
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce }
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce
13df7b9e400211c717284fb841c849ba034ed348Michal Zidek if (!MC_SLOT_WITHIN_BOUNDS(slot, gr_mc_ctx.dt_size)) {
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce ret = ENOENT;
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce goto done;
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce }
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce ret = sss_nss_mc_parse_result(rec, result, buffer, buflen);
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorcedone:
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce free(rec);
6a60e29468fc6b4043a4dc52d3aab73e8465db70Lukas Slebodnik __sync_sub_and_fetch(&gr_mc_ctx.active_threads, 1);
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce return ret;
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce}
10eae23e2483733d4ca3c21f15b5bdb3f04c9839Simo Sorce