1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce/*
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce * System Security Services Daemon. NSS client interface
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce *
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce * Copyright (C) Simo Sorce 2011
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce *
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce * This program is free software; you can redistribute it and/or modify
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce * it under the terms of the GNU Lesser General Public License as
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce * published by the Free Software Foundation; either version 2.1 of the
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce * License, or (at your option) any later version.
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce *
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce * This program is distributed in the hope that it will be useful,
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce * but WITHOUT ANY WARRANTY; without even the implied warranty of
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce * GNU Lesser General Public License for more details.
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo 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/>.
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce */
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce/* PASSWD database NSS interface using mmap cache */
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce#include <errno.h>
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce#include <stdio.h>
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce#include <string.h>
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce#include <stdlib.h>
8a5931bcc8e9034e4beb92fc9addf3f7fcf83fd6Michal Zidek#include <stddef.h>
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce#include <sys/mman.h>
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce#include <time.h>
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce#include "nss_mc.h"
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce
6a60e29468fc6b4043a4dc52d3aab73e8465db70Lukas Slebodnikstruct sss_cli_mc_ctx pw_mc_ctx = { UNINITIALIZED, -1, 0, NULL, 0, NULL, 0,
6a60e29468fc6b4043a4dc52d3aab73e8465db70Lukas Slebodnik NULL, 0, 0 };
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorcestatic errno_t sss_nss_mc_parse_result(struct sss_mc_rec *rec,
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce struct passwd *result,
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce char *buffer, size_t buflen)
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce{
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce struct sss_mc_pwd_data *data;
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce time_t expire;
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce void *cookie;
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce int ret;
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce /* additional checks before filling result*/
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce expire = rec->expire;
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce if (expire < time(NULL)) {
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce /* entry is now invalid */
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce return EINVAL;
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce }
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce data = (struct sss_mc_pwd_data *)rec->data;
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce if (data->strs_len > buflen) {
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce return ERANGE;
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce }
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce /* fill in glibc provided structs */
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce /* copy in buffer */
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce memcpy(buffer, data->strs, data->strs_len);
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce /* fill in passwd */
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce result->pw_uid = data->uid;
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce result->pw_gid = data->gid;
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce cookie = NULL;
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce ret = sss_nss_str_ptr_from_buffer(&result->pw_name, &cookie,
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce buffer, data->strs_len);
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce if (ret) {
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce return ret;
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce }
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce ret = sss_nss_str_ptr_from_buffer(&result->pw_passwd, &cookie,
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce buffer, data->strs_len);
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce if (ret) {
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce return ret;
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce }
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce ret = sss_nss_str_ptr_from_buffer(&result->pw_gecos, &cookie,
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce buffer, data->strs_len);
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce if (ret) {
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce return ret;
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce }
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce ret = sss_nss_str_ptr_from_buffer(&result->pw_dir, &cookie,
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce buffer, data->strs_len);
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce if (ret) {
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce return ret;
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce }
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce ret = sss_nss_str_ptr_from_buffer(&result->pw_shell, &cookie,
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce buffer, data->strs_len);
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce if (ret) {
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce return ret;
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce }
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce if (cookie != NULL) {
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce return EINVAL;
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce }
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce return 0;
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce}
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorceerrno_t sss_nss_mc_getpwnam(const char *name, size_t name_len,
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce struct passwd *result,
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce char *buffer, size_t buflen)
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce{
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce struct sss_mc_rec *rec = NULL;
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce struct sss_mc_pwd_data *data;
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce char *rec_name;
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce uint32_t hash;
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce uint32_t slot;
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce int ret;
ba847347cade817ee927397d82c952b51b0dcb2bLukas Slebodnik const size_t strs_offset = offsetof(struct sss_mc_pwd_data, strs);
ba847347cade817ee927397d82c952b51b0dcb2bLukas Slebodnik size_t data_size;
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce ret = sss_nss_mc_get_ctx("passwd", &pw_mc_ctx);
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce if (ret) {
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce return ret;
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce }
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce
ba847347cade817ee927397d82c952b51b0dcb2bLukas Slebodnik /* Get max size of data table. */
ba847347cade817ee927397d82c952b51b0dcb2bLukas Slebodnik data_size = pw_mc_ctx.dt_size;
8a5931bcc8e9034e4beb92fc9addf3f7fcf83fd6Michal Zidek
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce /* hashes are calculated including the NULL terminator */
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce hash = sss_nss_mc_hash(&pw_mc_ctx, name, name_len + 1);
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce slot = pw_mc_ctx.hash_table[hash];
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo 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
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce ret = sss_nss_mc_get_record(&pw_mc_ctx, slot, &rec);
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce if (ret) {
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce goto done;
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce }
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce /* check record matches what we are searching for */
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce if (hash != rec->hash1) {
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce /* if name hash does not match we can skip this immediately */
581de96fc30b7fe44070f17a8a73f3374d38d6ffLukas Slebodnik slot = sss_nss_mc_next_slot_with_hash(rec, hash);
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce continue;
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce }
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce data = (struct sss_mc_pwd_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 > pw_mc_ctx.data_table + data_size) {
8a5931bcc8e9034e4beb92fc9addf3f7fcf83fd6Michal Zidek ret = ENOENT;
8a5931bcc8e9034e4beb92fc9addf3f7fcf83fd6Michal Zidek goto done;
8a5931bcc8e9034e4beb92fc9addf3f7fcf83fd6Michal Zidek }
8a5931bcc8e9034e4beb92fc9addf3f7fcf83fd6Michal Zidek
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce if (strcmp(name, rec_name) == 0) {
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce break;
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce }
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce
581de96fc30b7fe44070f17a8a73f3374d38d6ffLukas Slebodnik slot = sss_nss_mc_next_slot_with_hash(rec, hash);
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce }
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce
ba847347cade817ee927397d82c952b51b0dcb2bLukas Slebodnik if (!MC_SLOT_WITHIN_BOUNDS(slot, data_size)) {
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce ret = ENOENT;
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce goto done;
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce }
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce ret = sss_nss_mc_parse_result(rec, result, buffer, buflen);
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorcedone:
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce free(rec);
6a60e29468fc6b4043a4dc52d3aab73e8465db70Lukas Slebodnik __sync_sub_and_fetch(&pw_mc_ctx.active_threads, 1);
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce return ret;
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce}
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorceerrno_t sss_nss_mc_getpwuid(uid_t uid,
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce struct passwd *result,
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce char *buffer, size_t buflen)
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce{
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce struct sss_mc_rec *rec = NULL;
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce struct sss_mc_pwd_data *data;
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce char uidstr[11];
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce uint32_t hash;
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce uint32_t slot;
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce int len;
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce int ret;
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce ret = sss_nss_mc_get_ctx("passwd", &pw_mc_ctx);
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce if (ret) {
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce return ret;
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce }
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce len = snprintf(uidstr, 11, "%ld", (long)uid);
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce if (len > 10) {
6a60e29468fc6b4043a4dc52d3aab73e8465db70Lukas Slebodnik ret = EINVAL;
6a60e29468fc6b4043a4dc52d3aab73e8465db70Lukas Slebodnik goto done;
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce }
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce /* hashes are calculated including the NULL terminator */
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce hash = sss_nss_mc_hash(&pw_mc_ctx, uidstr, len+1);
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce slot = pw_mc_ctx.hash_table[hash];
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo 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, pw_mc_ctx.dt_size)) {
9d876108620931e0941a115adf60bfd8d67459d9Lukas Slebodnik /* free record from previous iteration */
9d876108620931e0941a115adf60bfd8d67459d9Lukas Slebodnik free(rec);
9d876108620931e0941a115adf60bfd8d67459d9Lukas Slebodnik rec = NULL;
9d876108620931e0941a115adf60bfd8d67459d9Lukas Slebodnik
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce ret = sss_nss_mc_get_record(&pw_mc_ctx, slot, &rec);
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce if (ret) {
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce goto done;
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce }
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce /* check record matches what we are searching for */
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce if (hash != rec->hash2) {
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce /* if uid hash does not match we can skip this immediately */
581de96fc30b7fe44070f17a8a73f3374d38d6ffLukas Slebodnik slot = sss_nss_mc_next_slot_with_hash(rec, hash);
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce continue;
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce }
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce data = (struct sss_mc_pwd_data *)rec->data;
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce if (uid == data->uid) {
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce break;
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce }
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce
581de96fc30b7fe44070f17a8a73f3374d38d6ffLukas Slebodnik slot = sss_nss_mc_next_slot_with_hash(rec, hash);
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce }
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce
13df7b9e400211c717284fb841c849ba034ed348Michal Zidek if (!MC_SLOT_WITHIN_BOUNDS(slot, pw_mc_ctx.dt_size)) {
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce ret = ENOENT;
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce goto done;
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce }
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce ret = sss_nss_mc_parse_result(rec, result, buffer, buflen);
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorcedone:
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce free(rec);
6a60e29468fc6b4043a4dc52d3aab73e8465db70Lukas Slebodnik __sync_sub_and_fetch(&pw_mc_ctx.active_threads, 1);
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce return ret;
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce}
1171986bdc3011555c5b62a9d9ee9f7481f48cdcSimo Sorce