aboutsummaryrefslogtreecommitdiffstats
path: root/src/libnsss/nsss_all_getgrouplist.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libnsss/nsss_all_getgrouplist.c')
-rw-r--r--src/libnsss/nsss_all_getgrouplist.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/libnsss/nsss_all_getgrouplist.c b/src/libnsss/nsss_all_getgrouplist.c
new file mode 100644
index 0000000..0560ba7
--- /dev/null
+++ b/src/libnsss/nsss_all_getgrouplist.c
@@ -0,0 +1,35 @@
+/* ISC license. */
+
+#include <stddef.h>
+#include <errno.h>
+
+#include <skalibs/stralloc.h>
+
+#include <nsss/config.h>
+#include <nsss/grp-unix.h>
+#include <nsss/nsss-switch.h>
+#include <nsss/grp-all.h>
+#include "nsss-internal.h"
+
+int nsss_all_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)) goto fallback ;
+ 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) ;
+
+ fallback:
+ errno = e ;
+ return nsss_unix_getgrouplist(user, gid, gids, ngids) ;
+}