5e6622722e84d594298a8324f3685a1bda2b5868Sumit Bose Extended NSS Responder Interface
5e6622722e84d594298a8324f3685a1bda2b5868Sumit Bose Sumit Bose <sbose@redhat.com>
5e6622722e84d594298a8324f3685a1bda2b5868Sumit Bose Copyright (C) 2017 Red Hat
5e6622722e84d594298a8324f3685a1bda2b5868Sumit Bose This program is free software; you can redistribute it and/or modify
5e6622722e84d594298a8324f3685a1bda2b5868Sumit Bose it under the terms of the GNU General Public License as published by
5e6622722e84d594298a8324f3685a1bda2b5868Sumit Bose the Free Software Foundation; either version 3 of the License, or
5e6622722e84d594298a8324f3685a1bda2b5868Sumit Bose (at your option) any later version.
5e6622722e84d594298a8324f3685a1bda2b5868Sumit Bose This program is distributed in the hope that it will be useful,
5e6622722e84d594298a8324f3685a1bda2b5868Sumit Bose but WITHOUT ANY WARRANTY; without even the implied warranty of
5e6622722e84d594298a8324f3685a1bda2b5868Sumit Bose MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5e6622722e84d594298a8324f3685a1bda2b5868Sumit Bose GNU General Public License for more details.
5e6622722e84d594298a8324f3685a1bda2b5868Sumit Bose You should have received a copy of the GNU General Public License
5e6622722e84d594298a8324f3685a1bda2b5868Sumit Bose along with this program. If not, see <http://www.gnu.org/licenses/>.
5e6622722e84d594298a8324f3685a1bda2b5868Sumit Bose#include "sss_client/idmap/sss_nss_idmap_private.h"
5e6622722e84d594298a8324f3685a1bda2b5868Sumit Bose#define discard_const(ptr) ((void *)((uintptr_t)(ptr)))
cf93f7c2f2031078bbbff095dae01eb4f8deff85Sumit Bose return sss_nss_mc_getpwnam(inp->input.name, strlen(inp->input.name),
cf93f7c2f2031078bbbff095dae01eb4f8deff85Sumit Bose return sss_nss_mc_getgrnam(inp->input.name, strlen(inp->input.name),
cf93f7c2f2031078bbbff095dae01eb4f8deff85Sumit Bose return sss_nss_mc_initgroups_dyn(inp->input.name,
46a4c265629d9b725c41f22849741ce7342bdd85Sumit Bose /* no limit so that needed size can
46a4c265629d9b725c41f22849741ce7342bdd85Sumit Bose * be returned properly */
859bddc2bf51dc426a3dc56bd9f365e9c5722b65Sumit Bosestatic int check_flags(struct nss_input *inp, uint32_t flags,
55f7d8034d783c01789d76a2b9ffc901045e8af8Sumit Bose /* SSS_NSS_EX_FLAG_NO_CACHE and SSS_NSS_EX_FLAG_INVALIDATE_CACHE are
55f7d8034d783c01789d76a2b9ffc901045e8af8Sumit Bose * mutually exclusive */
55f7d8034d783c01789d76a2b9ffc901045e8af8Sumit Bose && (flags & SSS_NSS_EX_FLAG_INVALIDATE_CACHE) != 0) {
859bddc2bf51dc426a3dc56bd9f365e9c5722b65Sumit Bose || (flags & SSS_NSS_EX_FLAG_INVALIDATE_CACHE) != 0) {
859bddc2bf51dc426a3dc56bd9f365e9c5722b65Sumit Bose /* Allow empty buffer with SSS_NSS_EX_FLAG_INVALIDATE_CACHE */
859bddc2bf51dc426a3dc56bd9f365e9c5722b65Sumit Bose if ((flags & SSS_NSS_EX_FLAG_INVALIDATE_CACHE) != 0) {
5e6622722e84d594298a8324f3685a1bda2b5868Sumit Boseint sss_get_ex(struct nss_input *inp, uint32_t flags, unsigned int timeout)
859bddc2bf51dc426a3dc56bd9f365e9c5722b65Sumit Bose ret = check_flags(inp, flags, &skip_mc, &skip_data);
ac6b267ff3df6d0417062a128ec16b184ea2c1b7Sumit Bose /* fall through, we need to actively ask the parent
ac6b267ff3df6d0417062a128ec16b184ea2c1b7Sumit Bose * if no entry is found */
080e1bfb72ed0e8d96e390d83ad35eaba79bd450René Genz /* if using the mmapped cache failed,
ac6b267ff3df6d0417062a128ec16b184ea2c1b7Sumit Bose * fall back to socket based comms */
ac6b267ff3df6d0417062a128ec16b184ea2c1b7Sumit Bose /* previous thread might already initialize entry in mmap cache */
ac6b267ff3df6d0417062a128ec16b184ea2c1b7Sumit Bose /* fall through, we need to actively ask the parent
ac6b267ff3df6d0417062a128ec16b184ea2c1b7Sumit Bose * if no entry is found */
080e1bfb72ed0e8d96e390d83ad35eaba79bd450René Genz /* if using the mmapped cache failed,
ac6b267ff3df6d0417062a128ec16b184ea2c1b7Sumit Bose * fall back to socket based comms */
5e6622722e84d594298a8324f3685a1bda2b5868Sumit Bose ret = sss_nss_make_request_timeout(inp->cmd, &inp->rd, time_left,
5e6622722e84d594298a8324f3685a1bda2b5868Sumit Bose /* Get number of results from repbuf. */
5e6622722e84d594298a8324f3685a1bda2b5868Sumit Bose SAFEALIGN_COPY_UINT32(&num_results, repbuf, NULL);
5e6622722e84d594298a8324f3685a1bda2b5868Sumit Bose /* no results if not found */
859bddc2bf51dc426a3dc56bd9f365e9c5722b65Sumit Bose /* No data requested, just return the return code */
cf93f7c2f2031078bbbff095dae01eb4f8deff85Sumit Bose if (inp->cmd == SSS_NSS_INITGR || inp->cmd == SSS_NSS_INITGR_EX) {
5e6622722e84d594298a8324f3685a1bda2b5868Sumit Bose if ((*(inp->result.initgrrep.ngroups) - *(inp->result.initgrrep.start))
5e6622722e84d594298a8324f3685a1bda2b5868Sumit Bose new_groups = realloc(inp->result.initgrrep.groups,
5e6622722e84d594298a8324f3685a1bda2b5868Sumit Bose for (c = 0; c < num_results; c++) {
5e6622722e84d594298a8324f3685a1bda2b5868Sumit Bose &(inp->result.initgrrep.groups[*(inp->result.initgrrep.start)]),
5e6622722e84d594298a8324f3685a1bda2b5868Sumit Bose /* only 1 result is accepted for this function */
5e6622722e84d594298a8324f3685a1bda2b5868Sumit Bose ret = sss_nss_getpw_readrep(&(inp->result.pwrep), repbuf+8, &len);
5e6622722e84d594298a8324f3685a1bda2b5868Sumit Bose ret = sss_nss_getgr_readrep(&(inp->result.grrep), repbuf+8, &len);
5e6622722e84d594298a8324f3685a1bda2b5868Sumit Bose /* no extra data */
cf93f7c2f2031078bbbff095dae01eb4f8deff85Sumit Bosestatic int make_name_flag_req_data(const char *name, uint32_t flags,
cf93f7c2f2031078bbbff095dae01eb4f8deff85Sumit Bose ret = sss_strnlen(name, SSS_NAME_MAX, &name_len);
cf93f7c2f2031078bbbff095dae01eb4f8deff85Sumit Bose SAFEALIGN_COPY_UINT32(data + name_len, &flags, NULL);
5e6622722e84d594298a8324f3685a1bda2b5868Sumit Boseint sss_nss_getpwnam_timeout(const char *name, struct passwd *pwd,
cf93f7c2f2031078bbbff095dae01eb4f8deff85Sumit Bose ret = make_name_flag_req_data(name, flags, &inp.rd);
5e6622722e84d594298a8324f3685a1bda2b5868Sumit Boseint sss_nss_getpwuid_timeout(uid_t uid, struct passwd *pwd,
cf93f7c2f2031078bbbff095dae01eb4f8deff85Sumit Bose SAFEALIGN_COPY_UINT32(&req_data[1], &flags, NULL);
5e6622722e84d594298a8324f3685a1bda2b5868Sumit Boseint sss_nss_getgrnam_timeout(const char *name, struct group *grp,
5e6622722e84d594298a8324f3685a1bda2b5868Sumit Bose char *buffer, size_t buflen, struct group **result,
cf93f7c2f2031078bbbff095dae01eb4f8deff85Sumit Bose ret = make_name_flag_req_data(name, flags, &inp.rd);
5e6622722e84d594298a8324f3685a1bda2b5868Sumit Boseint sss_nss_getgrgid_timeout(gid_t gid, struct group *grp,
5e6622722e84d594298a8324f3685a1bda2b5868Sumit Bose char *buffer, size_t buflen, struct group **result,
cf93f7c2f2031078bbbff095dae01eb4f8deff85Sumit Bose SAFEALIGN_COPY_UINT32(&req_data[1], &flags, NULL);
5e6622722e84d594298a8324f3685a1bda2b5868Sumit Boseint sss_nss_getgrouplist_timeout(const char *name, gid_t group,
cf93f7c2f2031078bbbff095dae01eb4f8deff85Sumit Bose ret = make_name_flag_req_data(name, flags, &inp.rd);
2c4dc7a4d98c439c69625f12ba4c3c8253f4cc5bSumit Bose inp.result.initgrrep.groups = malloc(new_ngroups * sizeof(gid_t));
2c4dc7a4d98c439c69625f12ba4c3c8253f4cc5bSumit Bose /* inp.result.initgrrep.groups, inp.result.initgrrep.ngroups and
2c4dc7a4d98c439c69625f12ba4c3c8253f4cc5bSumit Bose * inp.result.initgrrep.start might be modified by sss_get_ex() */