2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose/*
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose SSSD
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose NSS Responder Interface for ID-SID mappings
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose Authors:
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose Sumit Bose <sbose@redhat.com>
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose Copyright (C) 2013 Red Hat
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose This program is free software; you can redistribute it and/or modify
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose it under the terms of the GNU General Public License as published by
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose the Free Software Foundation; either version 3 of the License, or
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose (at your option) any later version.
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose This program is distributed in the hope that it will be useful,
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose but WITHOUT ANY WARRANTY; without even the implied warranty of
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose GNU General Public License for more details.
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose You should have received a copy of the GNU General Public License
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose along with this program. If not, see <http://www.gnu.org/licenses/>.
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose*/
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose#include <stdlib.h>
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose#include <errno.h>
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose#include <nss.h>
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose#include "sss_client/sss_cli.h"
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose#include "sss_client/idmap/sss_nss_idmap.h"
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Bose#include "sss_client/idmap/sss_nss_idmap_private.h"
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose#include "util/strtonum.h"
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose#define DATA_START (3 * sizeof(uint32_t))
440797cba931aa491bf418035f55935943e22b4bSumit Bose#define LIST_START (2 * sizeof(uint32_t))
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Bose#define NO_TIMEOUT ((unsigned int) -1)
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Bose
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Boseunion input {
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose const char *str;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose uint32_t id;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose};
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bosestruct output {
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose enum sss_id_type type;
440797cba931aa491bf418035f55935943e22b4bSumit Bose enum sss_id_type *types;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose union {
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose char *str;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose uint32_t id;
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose struct sss_nss_kv *kv_list;
440797cba931aa491bf418035f55935943e22b4bSumit Bose char **names;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose } d;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose};
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Boseint nss_status_to_errno(enum nss_status nret) {
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose switch (nret) {
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose case NSS_STATUS_TRYAGAIN:
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose return EAGAIN;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose case NSS_STATUS_SUCCESS:
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose return EOK;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose case NSS_STATUS_UNAVAIL:
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose default:
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose return ENOENT;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose }
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose return EINVAL;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose}
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bosevoid sss_nss_free_kv(struct sss_nss_kv *kv_list)
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose{
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose size_t c;
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose if (kv_list != NULL) {
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose for (c = 0; kv_list[c].key != NULL; c++) {
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose free(kv_list[c].key);
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose free(kv_list[c].value);
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose }
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose free(kv_list);
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose }
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose}
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose
440797cba931aa491bf418035f55935943e22b4bSumit Bosevoid sss_nss_free_list(char **l)
440797cba931aa491bf418035f55935943e22b4bSumit Bose{
440797cba931aa491bf418035f55935943e22b4bSumit Bose size_t c;
440797cba931aa491bf418035f55935943e22b4bSumit Bose
440797cba931aa491bf418035f55935943e22b4bSumit Bose if (l != NULL) {
440797cba931aa491bf418035f55935943e22b4bSumit Bose for (c = 0; l[c] != NULL; c++) {
440797cba931aa491bf418035f55935943e22b4bSumit Bose free(l[c]);
440797cba931aa491bf418035f55935943e22b4bSumit Bose }
440797cba931aa491bf418035f55935943e22b4bSumit Bose free(l);
440797cba931aa491bf418035f55935943e22b4bSumit Bose }
440797cba931aa491bf418035f55935943e22b4bSumit Bose}
440797cba931aa491bf418035f55935943e22b4bSumit Bose
440797cba931aa491bf418035f55935943e22b4bSumit Bosestatic int buf_to_name_type_list(uint8_t *buf, size_t buf_len, uint32_t num,
440797cba931aa491bf418035f55935943e22b4bSumit Bose char ***names, enum sss_id_type **types)
440797cba931aa491bf418035f55935943e22b4bSumit Bose{
440797cba931aa491bf418035f55935943e22b4bSumit Bose int ret;
440797cba931aa491bf418035f55935943e22b4bSumit Bose size_t c;
440797cba931aa491bf418035f55935943e22b4bSumit Bose char **n = NULL;
440797cba931aa491bf418035f55935943e22b4bSumit Bose enum sss_id_type *t = NULL;
440797cba931aa491bf418035f55935943e22b4bSumit Bose size_t rp = 0;
440797cba931aa491bf418035f55935943e22b4bSumit Bose
440797cba931aa491bf418035f55935943e22b4bSumit Bose n = calloc(num + 1, sizeof(char *));
440797cba931aa491bf418035f55935943e22b4bSumit Bose if (n == NULL) {
440797cba931aa491bf418035f55935943e22b4bSumit Bose ret = ENOMEM;
440797cba931aa491bf418035f55935943e22b4bSumit Bose goto done;
440797cba931aa491bf418035f55935943e22b4bSumit Bose }
440797cba931aa491bf418035f55935943e22b4bSumit Bose
440797cba931aa491bf418035f55935943e22b4bSumit Bose t = calloc(num + 1, sizeof(enum sss_id_type));
440797cba931aa491bf418035f55935943e22b4bSumit Bose if (t == NULL) {
440797cba931aa491bf418035f55935943e22b4bSumit Bose ret = ENOMEM;
440797cba931aa491bf418035f55935943e22b4bSumit Bose goto done;
440797cba931aa491bf418035f55935943e22b4bSumit Bose }
440797cba931aa491bf418035f55935943e22b4bSumit Bose
440797cba931aa491bf418035f55935943e22b4bSumit Bose for (c = 0; c < num; c++) {
440797cba931aa491bf418035f55935943e22b4bSumit Bose SAFEALIGN_COPY_UINT32(&(t[c]), buf + rp, &rp);
440797cba931aa491bf418035f55935943e22b4bSumit Bose n[c] = strdup((char *) buf + rp);
440797cba931aa491bf418035f55935943e22b4bSumit Bose if (n[c] == NULL) {
440797cba931aa491bf418035f55935943e22b4bSumit Bose ret = ENOMEM;
440797cba931aa491bf418035f55935943e22b4bSumit Bose goto done;
440797cba931aa491bf418035f55935943e22b4bSumit Bose }
440797cba931aa491bf418035f55935943e22b4bSumit Bose rp += strlen(n[c]) + 1;
440797cba931aa491bf418035f55935943e22b4bSumit Bose }
440797cba931aa491bf418035f55935943e22b4bSumit Bose
440797cba931aa491bf418035f55935943e22b4bSumit Bose ret = EOK;
440797cba931aa491bf418035f55935943e22b4bSumit Bose
440797cba931aa491bf418035f55935943e22b4bSumit Bosedone:
440797cba931aa491bf418035f55935943e22b4bSumit Bose if (ret != EOK) {
440797cba931aa491bf418035f55935943e22b4bSumit Bose sss_nss_free_list(n);
440797cba931aa491bf418035f55935943e22b4bSumit Bose free(t);
440797cba931aa491bf418035f55935943e22b4bSumit Bose } else {
440797cba931aa491bf418035f55935943e22b4bSumit Bose *names = n;
440797cba931aa491bf418035f55935943e22b4bSumit Bose *types = t;
440797cba931aa491bf418035f55935943e22b4bSumit Bose }
440797cba931aa491bf418035f55935943e22b4bSumit Bose
440797cba931aa491bf418035f55935943e22b4bSumit Bose return ret;
440797cba931aa491bf418035f55935943e22b4bSumit Bose}
440797cba931aa491bf418035f55935943e22b4bSumit Bose
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bosestatic int buf_to_kv_list(uint8_t *buf, size_t buf_len,
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose struct sss_nss_kv **kv_list)
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose{
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose size_t c;
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose size_t count = 0;
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose struct sss_nss_kv *list;
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose uint8_t *p;
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose int ret;
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose for (c = 0; c < buf_len; c++) {
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose if (buf[c] == '\0') {
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose count++;
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose }
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose }
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose if ((count % 2) != 0) {
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose return EINVAL;
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose }
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose count /= 2;
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose list = calloc((count + 1), sizeof(struct sss_nss_kv));
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose if (list == NULL) {
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose return ENOMEM;
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose }
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose p = buf;
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose for (c = 0; c < count; c++) {
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose list[c].key = strdup((char *) p);
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose if (list[c].key == NULL) {
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose ret = ENOMEM;
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose goto done;
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose }
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose p = memchr(p, '\0', buf_len - (p - buf));
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose if (p == NULL) {
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose ret = EINVAL;
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose goto done;
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose }
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose p++;
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose list[c].value = strdup((char *) p);
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose if (list[c].value == NULL) {
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose ret = ENOMEM;
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose goto done;
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose }
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose p = memchr(p, '\0', buf_len - (p - buf));
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose if (p == NULL) {
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose ret = EINVAL;
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose goto done;
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose }
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose p++;
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose }
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose *kv_list = list;
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose ret = EOK;
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bosedone:
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose if (ret != EOK) {
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose sss_nss_free_kv(list);
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose }
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose return ret;
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose}
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Bosestatic int sss_nss_getyyybyxxx(union input inp, enum sss_cli_command cmd,
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Bose unsigned int timeout, struct output *out)
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose{
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose int ret;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose size_t inp_len;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose struct sss_cli_req_data rd;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose uint8_t *repbuf = NULL;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose size_t replen;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose int errnop;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose enum nss_status nret;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose uint32_t num_results;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose char *str = NULL;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose size_t data_len;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose uint32_t c;
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose struct sss_nss_kv *kv_list;
440797cba931aa491bf418035f55935943e22b4bSumit Bose char **names;
440797cba931aa491bf418035f55935943e22b4bSumit Bose enum sss_id_type *types;
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Bose int time_left = SSS_CLI_SOCKET_TIMEOUT;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose switch (cmd) {
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose case SSS_NSS_GETSIDBYNAME:
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose case SSS_NSS_GETNAMEBYSID:
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose case SSS_NSS_GETIDBYSID:
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose case SSS_NSS_GETORIGBYNAME:
9c88f837ffacf6548c13825589b327de1a5525f3Sumit Bose ret = sss_strnlen(inp.str, 2048, &inp_len);
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose if (ret != EOK) {
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose return EINVAL;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose }
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose rd.len = inp_len + 1;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose rd.data = inp.str;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose
440797cba931aa491bf418035f55935943e22b4bSumit Bose break;
440797cba931aa491bf418035f55935943e22b4bSumit Bose case SSS_NSS_GETNAMEBYCERT:
440797cba931aa491bf418035f55935943e22b4bSumit Bose case SSS_NSS_GETLISTBYCERT:
440797cba931aa491bf418035f55935943e22b4bSumit Bose ret = sss_strnlen(inp.str, 10 * 1024 , &inp_len);
440797cba931aa491bf418035f55935943e22b4bSumit Bose if (ret != EOK) {
440797cba931aa491bf418035f55935943e22b4bSumit Bose return EINVAL;
440797cba931aa491bf418035f55935943e22b4bSumit Bose }
440797cba931aa491bf418035f55935943e22b4bSumit Bose
440797cba931aa491bf418035f55935943e22b4bSumit Bose rd.len = inp_len + 1;
440797cba931aa491bf418035f55935943e22b4bSumit Bose rd.data = inp.str;
440797cba931aa491bf418035f55935943e22b4bSumit Bose
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose break;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose case SSS_NSS_GETSIDBYID:
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose rd.len = sizeof(uint32_t);
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose rd.data = &inp.id;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose break;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose default:
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose return EINVAL;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose }
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Bose if (timeout == NO_TIMEOUT) {
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Bose sss_nss_lock();
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Bose } else {
3e32cb2ad36a9dd2654c7f63469dc595f1bb8593Sumit Bose ret = sss_nss_timedlock(timeout, &time_left);
3e32cb2ad36a9dd2654c7f63469dc595f1bb8593Sumit Bose if (ret != 0) {
3e32cb2ad36a9dd2654c7f63469dc595f1bb8593Sumit Bose return ret;
3e32cb2ad36a9dd2654c7f63469dc595f1bb8593Sumit Bose }
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Bose }
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Bose nret = sss_nss_make_request_timeout(cmd, &rd, time_left, &repbuf, &replen,
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Bose &errnop);
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose if (nret != NSS_STATUS_SUCCESS) {
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose ret = nss_status_to_errno(nret);
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose goto done;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose }
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose if (replen < 8) {
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose ret = EBADMSG;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose goto done;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose }
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose
a171d77f40aa92e240e91aa4bafe5a392a98b5a2Michal Zidek SAFEALIGN_COPY_UINT32(&num_results, repbuf, NULL);
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose if (num_results == 0) {
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose ret = ENOENT;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose goto done;
440797cba931aa491bf418035f55935943e22b4bSumit Bose } else if (num_results > 1 && cmd != SSS_NSS_GETLISTBYCERT) {
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose ret = EBADMSG;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose goto done;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose }
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose
a171d77f40aa92e240e91aa4bafe5a392a98b5a2Michal Zidek /* Skip first two 32 bit values (number of results and
a171d77f40aa92e240e91aa4bafe5a392a98b5a2Michal Zidek * reserved padding) */
a171d77f40aa92e240e91aa4bafe5a392a98b5a2Michal Zidek SAFEALIGN_COPY_UINT32(&out->type, repbuf + 2 * sizeof(uint32_t), NULL);
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose data_len = replen - DATA_START;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose switch(cmd) {
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose case SSS_NSS_GETSIDBYID:
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose case SSS_NSS_GETSIDBYNAME:
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose case SSS_NSS_GETNAMEBYSID:
9c88f837ffacf6548c13825589b327de1a5525f3Sumit Bose case SSS_NSS_GETNAMEBYCERT:
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose if (data_len <= 1 || repbuf[replen - 1] != '\0') {
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose ret = EBADMSG;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose goto done;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose }
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose str = malloc(sizeof(char) * data_len);
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose if (str == NULL) {
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose ret = ENOMEM;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose goto done;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose }
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose strncpy(str, (char *) repbuf + DATA_START, data_len);
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose out->d.str = str;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose break;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose case SSS_NSS_GETIDBYSID:
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose if (data_len != sizeof(uint32_t)) {
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose ret = EBADMSG;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose goto done;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose }
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose SAFEALIGN_COPY_UINT32(&c, repbuf + DATA_START, NULL);
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose out->d.id = c;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose
440797cba931aa491bf418035f55935943e22b4bSumit Bose break;
440797cba931aa491bf418035f55935943e22b4bSumit Bose case SSS_NSS_GETLISTBYCERT:
440797cba931aa491bf418035f55935943e22b4bSumit Bose ret = buf_to_name_type_list(repbuf + LIST_START, replen - LIST_START,
440797cba931aa491bf418035f55935943e22b4bSumit Bose num_results,
440797cba931aa491bf418035f55935943e22b4bSumit Bose &names, &types);
440797cba931aa491bf418035f55935943e22b4bSumit Bose if (ret != EOK) {
440797cba931aa491bf418035f55935943e22b4bSumit Bose goto done;
440797cba931aa491bf418035f55935943e22b4bSumit Bose }
440797cba931aa491bf418035f55935943e22b4bSumit Bose
440797cba931aa491bf418035f55935943e22b4bSumit Bose out->types = types;
440797cba931aa491bf418035f55935943e22b4bSumit Bose out->d.names = names;
440797cba931aa491bf418035f55935943e22b4bSumit Bose
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose break;
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose case SSS_NSS_GETORIGBYNAME:
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose ret = buf_to_kv_list(repbuf + DATA_START, data_len, &kv_list);
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose if (ret != EOK) {
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose goto done;
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose }
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose out->d.kv_list = kv_list;
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose break;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose default:
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose ret = EINVAL;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose goto done;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose }
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose ret = EOK;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bosedone:
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose sss_nss_unlock();
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose free(repbuf);
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose if (ret != EOK) {
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose free(str);
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose }
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose return ret;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose}
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Boseint sss_nss_getsidbyname_timeout(const char *fq_name, unsigned int timeout,
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Bose char **sid, enum sss_id_type *type)
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose{
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose int ret;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose union input inp;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose struct output out;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose if (sid == NULL || fq_name == NULL || *fq_name == '\0') {
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose return EINVAL;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose }
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose inp.str = fq_name;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Bose ret = sss_nss_getyyybyxxx(inp, SSS_NSS_GETSIDBYNAME, timeout, &out);
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose if (ret == EOK) {
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose *sid = out.d.str;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose *type = out.type;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose }
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose return ret;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose}
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Boseint sss_nss_getsidbyname(const char *fq_name, char **sid,
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Bose enum sss_id_type *type)
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Bose{
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Bose return sss_nss_getsidbyname_timeout(fq_name, NO_TIMEOUT, sid, type);
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Bose}
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Bose
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Boseint sss_nss_getsidbyid_timeout(uint32_t id, unsigned int timeout,
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Bose char **sid, enum sss_id_type *type)
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose{
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose int ret;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose union input inp;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose struct output out;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose if (sid == NULL) {
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose return EINVAL;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose }
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose inp.id = id;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Bose ret = sss_nss_getyyybyxxx(inp, SSS_NSS_GETSIDBYID, timeout, &out);
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose if (ret == EOK) {
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose *sid = out.d.str;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose *type = out.type;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose }
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose return ret;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose}
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Boseint sss_nss_getsidbyid(uint32_t id, char **sid, enum sss_id_type *type)
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Bose{
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Bose return sss_nss_getsidbyid_timeout(id, NO_TIMEOUT, sid, type);
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Bose}
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Bose
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Boseint sss_nss_getnamebysid_timeout(const char *sid, unsigned int timeout,
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Bose char **fq_name, enum sss_id_type *type)
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose{
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose int ret;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose union input inp;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose struct output out;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose if (fq_name == NULL || sid == NULL || *sid == '\0') {
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose return EINVAL;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose }
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose inp.str = sid;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Bose ret = sss_nss_getyyybyxxx(inp, SSS_NSS_GETNAMEBYSID, timeout, &out);
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose if (ret == EOK) {
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose *fq_name = out.d.str;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose *type = out.type;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose }
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose return ret;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose}
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Boseint sss_nss_getnamebysid(const char *sid, char **fq_name,
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Bose enum sss_id_type *type)
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Bose{
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Bose return sss_nss_getnamebysid_timeout(sid, NO_TIMEOUT, fq_name, type);
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Bose}
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Bose
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Boseint sss_nss_getidbysid_timeout(const char *sid, unsigned int timeout,
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Bose uint32_t *id, enum sss_id_type *id_type)
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose{
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose int ret;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose union input inp;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose struct output out;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose if (id == NULL || id_type == NULL || sid == NULL || *sid == '\0') {
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose return EINVAL;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose }
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose inp.str = sid;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Bose ret = sss_nss_getyyybyxxx(inp, SSS_NSS_GETIDBYSID, timeout, &out);
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose if (ret == EOK) {
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose *id = out.d.id;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose *id_type = out.type;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose }
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose return ret;
2a9af1f71887f02935e2fb6ad5023afba5b6d43eSumit Bose}
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Boseint sss_nss_getidbysid(const char *sid, uint32_t *id, enum sss_id_type *id_type)
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Bose{
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Bose return sss_nss_getidbysid_timeout(sid, NO_TIMEOUT, id, id_type);
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Bose}
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Bose
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Boseint sss_nss_getorigbyname_timeout(const char *fq_name, unsigned int timeout,
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Bose struct sss_nss_kv **kv_list,
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Bose enum sss_id_type *type)
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose{
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose int ret;
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose union input inp;
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose struct output out;
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose if (kv_list == NULL || fq_name == NULL || *fq_name == '\0') {
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose return EINVAL;
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose }
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose inp.str = fq_name;
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Bose ret = sss_nss_getyyybyxxx(inp, SSS_NSS_GETORIGBYNAME, timeout, &out);
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose if (ret == EOK) {
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose *kv_list = out.d.kv_list;
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose *type = out.type;
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose }
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose return ret;
0d01e4f6cc21d8ca0e4fafe59c7cbfa1459fa47eSumit Bose}
9c88f837ffacf6548c13825589b327de1a5525f3Sumit Bose
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Boseint sss_nss_getorigbyname(const char *fq_name, struct sss_nss_kv **kv_list,
9c88f837ffacf6548c13825589b327de1a5525f3Sumit Bose enum sss_id_type *type)
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Bose{
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Bose return sss_nss_getorigbyname_timeout(fq_name, NO_TIMEOUT, kv_list, type);
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Bose}
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Bose
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Boseint sss_nss_getnamebycert_timeout(const char *cert, unsigned int timeout,
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Bose char **fq_name, enum sss_id_type *type)
9c88f837ffacf6548c13825589b327de1a5525f3Sumit Bose{
9c88f837ffacf6548c13825589b327de1a5525f3Sumit Bose int ret;
9c88f837ffacf6548c13825589b327de1a5525f3Sumit Bose union input inp;
9c88f837ffacf6548c13825589b327de1a5525f3Sumit Bose struct output out;
9c88f837ffacf6548c13825589b327de1a5525f3Sumit Bose
9c88f837ffacf6548c13825589b327de1a5525f3Sumit Bose if (fq_name == NULL || cert == NULL || *cert == '\0') {
9c88f837ffacf6548c13825589b327de1a5525f3Sumit Bose return EINVAL;
9c88f837ffacf6548c13825589b327de1a5525f3Sumit Bose }
9c88f837ffacf6548c13825589b327de1a5525f3Sumit Bose
9c88f837ffacf6548c13825589b327de1a5525f3Sumit Bose inp.str = cert;
9c88f837ffacf6548c13825589b327de1a5525f3Sumit Bose
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Bose ret = sss_nss_getyyybyxxx(inp, SSS_NSS_GETNAMEBYCERT, timeout, &out);
9c88f837ffacf6548c13825589b327de1a5525f3Sumit Bose if (ret == EOK) {
9c88f837ffacf6548c13825589b327de1a5525f3Sumit Bose *fq_name = out.d.str;
9c88f837ffacf6548c13825589b327de1a5525f3Sumit Bose *type = out.type;
9c88f837ffacf6548c13825589b327de1a5525f3Sumit Bose }
9c88f837ffacf6548c13825589b327de1a5525f3Sumit Bose
9c88f837ffacf6548c13825589b327de1a5525f3Sumit Bose return ret;
9c88f837ffacf6548c13825589b327de1a5525f3Sumit Bose}
440797cba931aa491bf418035f55935943e22b4bSumit Bose
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Boseint sss_nss_getnamebycert(const char *cert, char **fq_name,
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Bose enum sss_id_type *type)
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Bose{
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Bose return sss_nss_getnamebycert_timeout(cert, NO_TIMEOUT, fq_name, type);
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Bose}
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Bose
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Boseint sss_nss_getlistbycert_timeout(const char *cert, unsigned int timeout,
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Bose char ***fq_name, enum sss_id_type **type)
440797cba931aa491bf418035f55935943e22b4bSumit Bose{
440797cba931aa491bf418035f55935943e22b4bSumit Bose int ret;
440797cba931aa491bf418035f55935943e22b4bSumit Bose union input inp;
440797cba931aa491bf418035f55935943e22b4bSumit Bose struct output out;
440797cba931aa491bf418035f55935943e22b4bSumit Bose
440797cba931aa491bf418035f55935943e22b4bSumit Bose if (fq_name == NULL || cert == NULL || *cert == '\0') {
440797cba931aa491bf418035f55935943e22b4bSumit Bose return EINVAL;
440797cba931aa491bf418035f55935943e22b4bSumit Bose }
440797cba931aa491bf418035f55935943e22b4bSumit Bose
440797cba931aa491bf418035f55935943e22b4bSumit Bose inp.str = cert;
440797cba931aa491bf418035f55935943e22b4bSumit Bose
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Bose ret = sss_nss_getyyybyxxx(inp, SSS_NSS_GETLISTBYCERT, timeout, &out);
440797cba931aa491bf418035f55935943e22b4bSumit Bose if (ret == EOK) {
440797cba931aa491bf418035f55935943e22b4bSumit Bose *fq_name = out.d.names;
440797cba931aa491bf418035f55935943e22b4bSumit Bose *type = out.types;
440797cba931aa491bf418035f55935943e22b4bSumit Bose }
440797cba931aa491bf418035f55935943e22b4bSumit Bose
440797cba931aa491bf418035f55935943e22b4bSumit Bose return ret;
440797cba931aa491bf418035f55935943e22b4bSumit Bose}
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Bose
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Boseint sss_nss_getlistbycert(const char *cert, char ***fq_name,
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Bose enum sss_id_type **type)
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Bose{
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Bose return sss_nss_getlistbycert_timeout(cert, NO_TIMEOUT, fq_name, type);
e54db68cbb9c12d8a6867f2c7766fb2115ab0997Sumit Bose}