summaryrefslogtreecommitdiff
path: root/src/libnsss/nsss_switch_getgrouplist.c
blob: 868b4635d33bd49b733abfe8be111212d684e94e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/* ISC license. */

#include <stddef.h>
#include <errno.h>
#include <pthread.h>

#include <skalibs/stralloc.h>

#include <nsss/config.h>
#include <nsss/nsss-switch.h>
#include <nsss/grp-switch.h>
#include "nsss-internal.h"
#include "nsss-switch-internal.h"

int nsss_switch_getgrouplist (char const *user, gid_t gid, gid_t *gids, int *ngids)
{
  stralloc sa = STRALLOC_ZERO ;
  size_t r = 0 ;
  size_t n ;
  int e ;
  if (*ngids < 0) return (errno = EINVAL, -1) ;
  n = *ngids ;
  e = pthread_mutex_lock(&nsss_switch_query_mutex) ;
  if (e) return (errno = e, -1) ; 
  e = errno ;
  if (!nsss_switch_query_start(NSSS_NSSSD_PATH, NSSS_SWITCH_GRP, 30000, 0, 0)
   || !nsss_switch_grp_getlist(&nsss_switch_query, user, gids, n, &r, &sa, 0, 0))
  {
    pthread_mutex_unlock(&nsss_switch_query_mutex) ;
    return -1 ;
  }
  pthread_mutex_unlock(&nsss_switch_query_mutex) ;
  return nsss_grouplist_adjust(n, r, gid, gids, ngids, e) ;
}