aboutsummaryrefslogtreecommitdiffstats
path: root/src/libnsss/nsss_switch_getgrouplist.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2019-09-21 21:17:34 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2019-09-21 21:17:34 +0000
commit426039bdd70a5502d56fbc2a9dcde5817b145c1c (patch)
treed796c9013d131297819b9d7637bea628d9c117d7 /src/libnsss/nsss_switch_getgrouplist.c
parentce150eb99b4af0f509e86c0e077abb5203253049 (diff)
downloadnsss-426039bdd70a5502d56fbc2a9dcde5817b145c1c.tar.gz
Add getgrouplist() support (stubbed in nsssd-nslcd)
Diffstat (limited to 'src/libnsss/nsss_switch_getgrouplist.c')
-rw-r--r--src/libnsss/nsss_switch_getgrouplist.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/libnsss/nsss_switch_getgrouplist.c b/src/libnsss/nsss_switch_getgrouplist.c
new file mode 100644
index 0000000..73d3fe0
--- /dev/null
+++ b/src/libnsss/nsss_switch_getgrouplist.c
@@ -0,0 +1,30 @@
+/* ISC license. */
+
+#include <stddef.h>
+#include <errno.h>
+
+#include <skalibs/stralloc.h>
+
+#include <nsss/config.h>
+#include <nsss/nsss-switch.h>
+#include <nsss/grp-switch.h>
+#include "nsss-internal.h"
+
+int nsss_switch_getgrouplist (char const *user, gid_t gid, gid_t *gids, int *ngids)
+{
+ stralloc sa = STRALLOC_ZERO ;
+ int e = errno ;
+ size_t r = 0 ;
+ size_t n ;
+ nsss_switch_t a = NSSS_SWITCH_ZERO ;
+ if (*ngids < 0) return (errno = EINVAL, -1) ;
+ n = *ngids ;
+ if (!nsss_switch_start(&a, NSSS_SWITCH_GRP, NSSS_NSSSD_PATH, 0, 0)) return -1 ;
+ if (!nsss_switch_grp_getlist(&a, user, gids, n, &r, &sa, 0, 0))
+ {
+ nsss_switch_end(&a, NSSS_SWITCH_GRP) ;
+ return -1 ;
+ }
+ nsss_switch_end(&a, NSSS_SWITCH_GRP) ;
+ return nsss_grouplist_adjust(n, r, gid, gids, ngids, e) ;
+}