summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2019-09-21 06:14:58 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2019-09-21 06:14:58 +0000
commit49d66bcce5aa57acc5fb71efe93f531cae9d7402 (patch)
tree63505224b6579ad8de2559e3f1519c6590649c4a /src
parent711f816b22c09fc9fb0947c041e6a95a933930d4 (diff)
downloadnsss-49d66bcce5aa57acc5fb71efe93f531cae9d7402.tar.xz
Remove tainnow dependency in configure too
Diffstat (limited to 'src')
-rw-r--r--src/include/grp.h1
-rw-r--r--src/include/nsss/grp-all.h1
-rw-r--r--src/include/nsss/grp-switch.h1
-rw-r--r--src/include/nsss/grp-unix.h1
-rw-r--r--src/include/nsss/grp.h12
-rw-r--r--src/include/nsss/nsss-switch.h3
-rw-r--r--src/include/nsss/nsss-unix.h2
-rw-r--r--src/libnsss/deps-lib/nsss1
-rw-r--r--src/libnsss/nsss_unix_getgrouplist.c43
-rw-r--r--src/libnsss/nsss_unix_grp_getlist.c54
-rw-r--r--src/tests/deps-exe/test-all-fallback2
-rw-r--r--src/tests/deps-exe/test-switch2
12 files changed, 120 insertions, 3 deletions
diff --git a/src/include/grp.h b/src/include/grp.h
index 4516a19..a30fe79 100644
--- a/src/include/grp.h
+++ b/src/include/grp.h
@@ -12,7 +12,6 @@
#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
#include <sys/types.h>
-extern int getgrouplist (char const *, gid_t, gid_t *, int *) ;
extern int setgroups (size_t, gid_t const *) ;
extern int initgroups (char const *, gid_t) ;
#endif
diff --git a/src/include/nsss/grp-all.h b/src/include/nsss/grp-all.h
index 54ea213..9f45310 100644
--- a/src/include/nsss/grp-all.h
+++ b/src/include/nsss/grp-all.h
@@ -16,5 +16,6 @@ extern struct group *nsss_all_getgrgid (gid_t) ;
extern struct group *nsss_all_getgrnam (char const *) ;
extern int nsss_all_getgrgid_r (gid_t, struct group *, char *, size_t, struct group **) ;
extern int nsss_all_getgrnam_r (char const *, struct group *, char *, size_t, struct group **) ;
+extern int nsss_all_getgrouplist (char const *, gid_t, gid_t *, int *) ;
#endif
diff --git a/src/include/nsss/grp-switch.h b/src/include/nsss/grp-switch.h
index 6a9ba10..429ee48 100644
--- a/src/include/nsss/grp-switch.h
+++ b/src/include/nsss/grp-switch.h
@@ -16,5 +16,6 @@ extern struct group *nsss_switch_getgrgid (gid_t) ;
extern struct group *nsss_switch_getgrnam (char const *) ;
extern int nsss_switch_getgrgid_r (gid_t, struct group *, char *, size_t, struct group **) ;
extern int nsss_switch_getgrnam_r (char const *, struct group *, char *, size_t, struct group **) ;
+extern int nsss_switch_getgrouplist (char const *, gid_t, gid_t *, int *) ;
#endif
diff --git a/src/include/nsss/grp-unix.h b/src/include/nsss/grp-unix.h
index fe089f1..3b198c0 100644
--- a/src/include/nsss/grp-unix.h
+++ b/src/include/nsss/grp-unix.h
@@ -16,5 +16,6 @@ extern struct group *nsss_unix_getgrgid (gid_t) ;
extern struct group *nsss_unix_getgrnam (char const *) ;
extern int nsss_unix_getgrgid_r (gid_t, struct group *, char *, size_t, struct group **) ;
extern int nsss_unix_getgrnam_r (char const *, struct group *, char *, size_t, struct group **) ;
+extern int nsss_unix_getgrouplist (char const *, gid_t, gid_t *, int *) ;
#endif
diff --git a/src/include/nsss/grp.h b/src/include/nsss/grp.h
index ea963b6..0d56cbd 100644
--- a/src/include/nsss/grp.h
+++ b/src/include/nsss/grp.h
@@ -20,6 +20,10 @@ extern "C" {
#define getgrnam nsss_unix_getgrnam
#define getgrnam_r nsss_unix_getgrnam_r
+#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
+# define getgrouplist nsss_unix_getgrouplist
+#endif
+
#else
#ifdef NSSS_DISABLE_UNIX
@@ -34,6 +38,10 @@ extern "C" {
#define getgrnam nsss_switch_getgrnam
#define getgrnam_r nsss_switch_getgrnam_r
+#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
+# define getgrouplist nsss_switch_getgrouplist
+#endif
+
#else
#include <nsss/grp-all.h>
@@ -47,6 +55,10 @@ extern "C" {
#define getgrnam nsss_all_getgrnam
#define getgrnam_r nsss_all_getgrnam_r
+#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
+# define getgrouplist nsss_all_getgrouplist
+#endif
+
#endif
#endif
diff --git a/src/include/nsss/nsss-switch.h b/src/include/nsss/nsss-switch.h
index 8ee428e..9e1a850 100644
--- a/src/include/nsss/nsss-switch.h
+++ b/src/include/nsss/nsss-switch.h
@@ -67,6 +67,7 @@ extern int nsss_switch_pwd_getbyuid (nsss_switch_t *, struct passwd *, stralloc
#define NSSS_SWITCH_GRP_GET '\022'
#define NSSS_SWITCH_GRP_GETBYNAME '\023'
#define NSSS_SWITCH_GRP_GETBYGID '\024'
+#define NSSS_SWITCH_GRP_GETLIST '\025'
extern int nsss_switch_grp_end (nsss_switch_t *, tain_t const *, tain_t *) ;
#define nsss_switch_grp_end_g(a, deadline) nsss_switch_grp_end(a, (deadline), &STAMP)
@@ -78,6 +79,8 @@ extern int nsss_switch_grp_getbyname (nsss_switch_t *, struct group *, stralloc
#define nsss_switch_grp_getbyname_g(a, b, sa, ga, name, deadline) nsss_switch_grp_getbyname(a, b, sa, ga, name, (deadline), &STAMP)
extern int nsss_switch_grp_getbygid (nsss_switch_t *, struct group *, stralloc *, genalloc *, gid_t, tain_t const *, tain_t *) ;
#define nsss_switch_grp_getbygid_g(a, b, sa, ga, g, deadline) nsss_switch_grp_getbygid(a, b, sa, ga, g, (deadline), &STAMP)
+extern int nsss_switch_grp_getlist (nsss_switch_t *, char const *, gid_t, genalloc *, tain_t const *, tain_t *) ;
+#define nsss_switch_grp_getlist_g(a, user, g, ga, deadline) nsss_switch_grp_getlist(a, user, g, ga, (deadline), &STAMP)
/* Shadow */
diff --git a/src/include/nsss/nsss-unix.h b/src/include/nsss/nsss-unix.h
index 786bf88..dfb0bde 100644
--- a/src/include/nsss/nsss-unix.h
+++ b/src/include/nsss/nsss-unix.h
@@ -4,6 +4,7 @@
#define NSSS_UNIX_H
#include <sys/types.h>
+
#include <skalibs/buffer.h>
#include <skalibs/stralloc.h>
#include <skalibs/genalloc.h>
@@ -47,6 +48,7 @@ extern int nsss_unix_pwd_getbyuid (nsss_unix_t *, struct passwd *, stralloc *, u
extern int nsss_unix_grp_get (nsss_unix_t *, struct group *, stralloc *, genalloc *) ;
extern int nsss_unix_grp_getbyname (nsss_unix_t *, struct group *, stralloc *, genalloc *, char const *) ;
extern int nsss_unix_grp_getbygid (nsss_unix_t *, struct group *, stralloc *, genalloc *, gid_t) ;
+extern int nsss_unix_grp_getlist (nsss_unix_t *, gid_t *, size_t, size_t *, stralloc *, genalloc *, char const *) ;
/* Shadow */
diff --git a/src/libnsss/deps-lib/nsss b/src/libnsss/deps-lib/nsss
index 5c2630c..97f3518 100644
--- a/src/libnsss/deps-lib/nsss
+++ b/src/libnsss/deps-lib/nsss
@@ -91,6 +91,7 @@ nsss_unix_getspent.o
nsss_unix_getspent_r.o
nsss_unix_getspnam.o
nsss_unix_getspnam_r.o
+nsss_unix_getgrouplist.o
nsss_unix_grp_get.o
nsss_unix_grp_getbygid.o
nsss_unix_grp_getbyname.o
diff --git a/src/libnsss/nsss_unix_getgrouplist.c b/src/libnsss/nsss_unix_getgrouplist.c
new file mode 100644
index 0000000..e9a11ab
--- /dev/null
+++ b/src/libnsss/nsss_unix_getgrouplist.c
@@ -0,0 +1,43 @@
+/* ISC license. */
+
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+#include <limits.h>
+
+#include <skalibs/stralloc.h>
+#include <skalibs/genalloc.h>
+#include <skalibs/skamisc.h>
+
+#include <nsss/grp-def.h>
+#include <nsss/grp-unix.h>
+#include <nsss/nsss-unix.h>
+#include "nsss-unix-internal.h"
+
+int nsss_unix_getgrouplist (char const *user, gid_t gid, gid_t *gids, int *ngids)
+{
+ nsss_unix_t a = NSSS_UNIX_ZERO ;
+ stralloc sa = STRALLOC_ZERO ;
+ genalloc ga = GENALLOC_ZERO ; /* char * */
+ int e = errno ;
+ size_t r = 0 ;
+ size_t n ;
+ if (*ngids < 0) return (errno = EINVAL, -1) ;
+ n = *ngids ;
+ if (!nsss_unix_grp_start(&a)) return -1 ;
+ if (!nsss_unix_grp_getlist(&a, gids, n, &r, &sa, &ga, user)) return -1 ;
+ nsss_unix_grp_end(&a) ;
+ if (r > INT_MAX) return (errno = EMSGSIZE, -1) ;
+ if (r > n) return (*ngids = (int)r, errno = ENOBUFS, -1) ;
+ for (size_t i = 0 ; i < r ; i++)
+ if (gid == gids[i]) goto ok ;
+ r++ ;
+ if (r > INT_MAX) return (errno = EMSGSIZE, -1) ;
+ if (r > n) return (*ngids = (int)r, errno = ENOBUFS, -1) ;
+ memmove(gids + 1, gids, (r-1) * sizeof(gid_t)) ;
+ gids[0] = gid ;
+ ok:
+ *ngids = (int)r ;
+ errno = e ;
+ return (int)n ;
+}
diff --git a/src/libnsss/nsss_unix_grp_getlist.c b/src/libnsss/nsss_unix_grp_getlist.c
new file mode 100644
index 0000000..9885a03
--- /dev/null
+++ b/src/libnsss/nsss_unix_grp_getlist.c
@@ -0,0 +1,54 @@
+/* ISC license. */
+
+#include <string.h>
+#include <errno.h>
+
+#include <skalibs/stralloc.h>
+#include <skalibs/genalloc.h>
+
+#include <nsss/grp-unix.h>
+#include <nsss/nsss-unix.h>
+
+int nsss_unix_grp_getlist (nsss_unix_t *a, gid_t *gids, size_t n, size_t *r, stralloc *sa, genalloc *ga, char const *user)
+{
+ int e = errno ;
+ int sawasnull = !sa->s ;
+ int gawasnull = !genalloc_s(char *, ga) ;
+ size_t sabase = sa->len ;
+ size_t gabase = genalloc_len(char *, ga) ;
+ size_t m = 0 ;
+
+ for (;;)
+ {
+ struct group *gr ;
+ sa->len = sabase ;
+ genalloc_setlen(char *, ga, gabase) ;
+ errno = 0 ;
+ if (!nsss_unix_grp_get(a, gr, sa, ga))
+ {
+ if (errno) goto err ;
+ else break ;
+ }
+ for (char **p = gr->gr_mem ; *p ; p++)
+ if (!strcmp(user, *p))
+ {
+ if (m < n) gids[m] = gr->gr_gid ;
+ m++ ;
+ break ;
+ }
+ }
+
+ if (gawasnull) genalloc_free(char *, &ga) ;
+ else genalloc_setlen(char *, ga, gabase) ;
+ if (sawasnull) stralloc_free(&sa) ;
+ else sa->len = sabase ;
+ *r = m ;
+ return 1 ;
+
+ err:
+ if (gawasnull) genalloc_free(char *, &ga) ;
+ else genalloc_setlen(char *, ga, gabase) ;
+ if (sawasnull) stralloc_free(&sa) ;
+ else sa->len = sabase ;
+ return 0 ;
+}
diff --git a/src/tests/deps-exe/test-all-fallback b/src/tests/deps-exe/test-all-fallback
index 704fc90..dcf68b8 100644
--- a/src/tests/deps-exe/test-all-fallback
+++ b/src/tests/deps-exe/test-all-fallback
@@ -1,4 +1,4 @@
${LIBNSSS}
-lskarnet
${SOCKET_LIB}
-${TAINNOW_LIB}
+${SYSCLOCK_LIB}
diff --git a/src/tests/deps-exe/test-switch b/src/tests/deps-exe/test-switch
index 704fc90..dcf68b8 100644
--- a/src/tests/deps-exe/test-switch
+++ b/src/tests/deps-exe/test-switch
@@ -1,4 +1,4 @@
${LIBNSSS}
-lskarnet
${SOCKET_LIB}
-${TAINNOW_LIB}
+${SYSCLOCK_LIB}