summaryrefslogtreecommitdiff
path: root/src/libnsss
diff options
context:
space:
mode:
Diffstat (limited to 'src/libnsss')
-rw-r--r--src/libnsss/deps-lib/nsss9
-rw-r--r--src/libnsss/nsss-switch-internal.h17
-rw-r--r--src/libnsss/nsss_all_getgrent.c4
-rw-r--r--src/libnsss/nsss_all_getgrent_r.c4
-rw-r--r--src/libnsss/nsss_all_getpwent.c4
-rw-r--r--src/libnsss/nsss_all_getpwent_r.c4
-rw-r--r--src/libnsss/nsss_all_getspent.c4
-rw-r--r--src/libnsss/nsss_all_getspent_r.c4
-rw-r--r--src/libnsss/nsss_all_setgrent.c4
-rw-r--r--src/libnsss/nsss_all_setpwent.c4
-rw-r--r--src/libnsss/nsss_all_setspent.c4
-rw-r--r--src/libnsss/nsss_switch_end.c3
-rw-r--r--src/libnsss/nsss_switch_endgrent.c8
-rw-r--r--src/libnsss/nsss_switch_endpwent.c8
-rw-r--r--src/libnsss/nsss_switch_endspent.c8
-rw-r--r--src/libnsss/nsss_switch_enumerator.c9
-rw-r--r--src/libnsss/nsss_switch_getgrent.c4
-rw-r--r--src/libnsss/nsss_switch_getgrent_r.c17
-rw-r--r--src/libnsss/nsss_switch_getgrgid.c13
-rw-r--r--src/libnsss/nsss_switch_getgrgid_r.c21
-rw-r--r--src/libnsss/nsss_switch_getgrnam.c13
-rw-r--r--src/libnsss/nsss_switch_getgrnam_r.c21
-rw-r--r--src/libnsss/nsss_switch_getgrouplist.c16
-rw-r--r--src/libnsss/nsss_switch_getpwent.c4
-rw-r--r--src/libnsss/nsss_switch_getpwent_r.c17
-rw-r--r--src/libnsss/nsss_switch_getpwnam.c12
-rw-r--r--src/libnsss/nsss_switch_getpwnam_r.c21
-rw-r--r--src/libnsss/nsss_switch_getpwuid.c12
-rw-r--r--src/libnsss/nsss_switch_getpwuid_r.c21
-rw-r--r--src/libnsss/nsss_switch_getspent.c4
-rw-r--r--src/libnsss/nsss_switch_getspent_r.c17
-rw-r--r--src/libnsss/nsss_switch_getspnam.c12
-rw-r--r--src/libnsss/nsss_switch_getspnam_r.c21
-rw-r--r--src/libnsss/nsss_switch_grp_get.c5
-rw-r--r--src/libnsss/nsss_switch_grp_getbygid.c5
-rw-r--r--src/libnsss/nsss_switch_grp_getbyname.c5
-rw-r--r--src/libnsss/nsss_switch_grp_getlist.c3
-rw-r--r--src/libnsss/nsss_switch_op.c5
-rw-r--r--src/libnsss/nsss_switch_pwd_get.c5
-rw-r--r--src/libnsss/nsss_switch_pwd_getbyname.c5
-rw-r--r--src/libnsss/nsss_switch_pwd_getbyuid.c5
-rw-r--r--src/libnsss/nsss_switch_query.c (renamed from src/libnsss/nsss_switch_here.c)4
-rw-r--r--src/libnsss/nsss_switch_query_mutex.c7
-rw-r--r--src/libnsss/nsss_switch_query_start.c12
-rw-r--r--src/libnsss/nsss_switch_send.c25
-rw-r--r--src/libnsss/nsss_switch_sendv.c25
-rw-r--r--src/libnsss/nsss_switch_set_timeout.c21
-rw-r--r--src/libnsss/nsss_switch_setgrent.c4
-rw-r--r--src/libnsss/nsss_switch_setpwent.c4
-rw-r--r--src/libnsss/nsss_switch_setspent.c4
-rw-r--r--src/libnsss/nsss_switch_shadow_get.c5
-rw-r--r--src/libnsss/nsss_switch_shadow_getbyname.c5
-rw-r--r--src/libnsss/nsss_switch_start.c3
-rw-r--r--src/libnsss/nsss_switch_startf.c26
54 files changed, 374 insertions, 153 deletions
diff --git a/src/libnsss/deps-lib/nsss b/src/libnsss/deps-lib/nsss
index e00084e..56764bf 100644
--- a/src/libnsss/deps-lib/nsss
+++ b/src/libnsss/deps-lib/nsss
@@ -33,6 +33,7 @@ nsss_switch_end.o
nsss_switch_endgrent.o
nsss_switch_endpwent.o
nsss_switch_endspent.o
+nsss_switch_enumerator.o
nsss_switch_getgrent.o
nsss_switch_getgrent_r.o
nsss_switch_getgrgid.o
@@ -57,7 +58,6 @@ nsss_switch_grp_getbyname.o
nsss_switch_grp_getlist.o
nsss_switch_grp_read.o
nsss_switch_grp_rewind.o
-nsss_switch_here.o
nsss_switch_op.o
nsss_switch_pwd_end.o
nsss_switch_pwd_get.o
@@ -65,6 +65,11 @@ nsss_switch_pwd_getbyname.o
nsss_switch_pwd_getbyuid.o
nsss_switch_pwd_read.o
nsss_switch_pwd_rewind.o
+nsss_switch_query.o
+nsss_switch_query_mutex.o
+nsss_switch_query_start.o
+nsss_switch_send.o
+nsss_switch_sendv.o
nsss_switch_setgrent.o
nsss_switch_setpwent.o
nsss_switch_setspent.o
@@ -73,7 +78,9 @@ nsss_switch_shadow_get.o
nsss_switch_shadow_getbyname.o
nsss_switch_shadow_read.o
nsss_switch_shadow_rewind.o
+nsss_switch_set_timeout.o
nsss_switch_start.o
+nsss_switch_startf.o
nsss_unix_end.o
nsss_unix_endgrent.o
nsss_unix_endpwent.o
diff --git a/src/libnsss/nsss-switch-internal.h b/src/libnsss/nsss-switch-internal.h
index 2b93434..50615d8 100644
--- a/src/libnsss/nsss-switch-internal.h
+++ b/src/libnsss/nsss-switch-internal.h
@@ -3,19 +3,34 @@
#ifndef NSSS_SWITCH_INTERNAL_H
#define NSSS_SWITCH_INTERNAL_H
+#include <stddef.h>
+#include <sys/uio.h>
+#include <pthread.h>
+
#include <skalibs/tai.h>
#include <skalibs/buffer.h>
#include <skalibs/stralloc.h>
#include <skalibs/genalloc.h>
+
#include <nsss/pwd-def.h>
#include <nsss/grp-def.h>
#include <nsss/shadow-def.h>
#include <nsss/nsss-switch.h>
-extern nsss_switch_t nsss_switch_here ;
+extern nsss_switch_t nsss_switch_enumerator ;
+extern pthread_mutex_t nsss_switch_enumerator_mutex ;
+
+extern nsss_switch_t nsss_switch_query ;
+extern pthread_mutex_t nsss_switch_query_mutex ;
+
+extern int nsss_switch_query_start (char const *, unsigned int, unsigned int, tain const *, tain *) ;
+
extern int nsss_switch_op (nsss_switch_t *, char, tain const *, tain *) ;
extern int nsss_switch_pwd_read (buffer *, struct passwd *, stralloc *, tain const *, tain *) ;
extern int nsss_switch_grp_read (buffer *, struct group *, stralloc *, genalloc *, tain const *, tain *) ;
extern int nsss_switch_shadow_read (buffer *, struct spwd *, stralloc *, tain const *, tain *) ;
+extern int nsss_switch_send (nsss_switch_t *, char const *, size_t, tain const *, tain *) ;
+extern int nsss_switch_sendv (nsss_switch_t *, struct iovec const *, unsigned int, tain const *, tain *) ;
+
#endif
diff --git a/src/libnsss/nsss_all_getgrent.c b/src/libnsss/nsss_all_getgrent.c
index 15b5894..d6c5e1a 100644
--- a/src/libnsss/nsss_all_getgrent.c
+++ b/src/libnsss/nsss_all_getgrent.c
@@ -14,10 +14,10 @@ struct group *nsss_all_getgrent (void)
{
int e = errno ;
if (nsss_all_errno) goto fallback ;
- if (!nsss_switch_start(&nsss_switch_here, NSSS_SWITCH_GRP, NSSS_NSSSD_PATH, 0, 0)) goto efallback ;
+ if (!nsss_switch_start(&nsss_switch_enumerator, NSSS_SWITCH_GRP, NSSS_NSSSD_PATH, 0, 0)) goto efallback ;
nsss_grp_sa_here.len = 0 ;
genalloc_setlen(char *, &nsss_grp_ga_here, 0) ;
- if (!nsss_switch_grp_get(&nsss_switch_here, &nsss_grp_here, &nsss_grp_sa_here, &nsss_grp_ga_here, 0, 0)) return 0 ;
+ if (!nsss_switch_grp_get(&nsss_switch_enumerator, &nsss_grp_here, &nsss_grp_sa_here, &nsss_grp_ga_here, 0, 0)) return 0 ;
return &nsss_grp_here ;
efallback:
diff --git a/src/libnsss/nsss_all_getgrent_r.c b/src/libnsss/nsss_all_getgrent_r.c
index 3e0557d..c4e5f7a 100644
--- a/src/libnsss/nsss_all_getgrent_r.c
+++ b/src/libnsss/nsss_all_getgrent_r.c
@@ -18,9 +18,9 @@ int nsss_all_getgrent_r (struct group *gr, char *buf, size_t buflen, struct grou
genalloc ga = GENALLOC_ZERO ;
int e = errno ;
if (nsss_all_errno) goto fallback ;
- if (!nsss_switch_start(&nsss_switch_here, NSSS_SWITCH_GRP, NSSS_NSSSD_PATH, 0, 0)) goto efallback ;
+ if (!nsss_switch_start(&nsss_switch_enumerator, NSSS_SWITCH_GRP, NSSS_NSSSD_PATH, 0, 0)) goto efallback ;
errno = 0 ;
- if (!nsss_switch_grp_get(&nsss_switch_here, &gr2, &sa, &ga, 0, 0))
+ if (!nsss_switch_grp_get(&nsss_switch_enumerator, &gr2, &sa, &ga, 0, 0))
{
*grp = 0 ;
if (!errno) errno = ENOENT ;
diff --git a/src/libnsss/nsss_all_getpwent.c b/src/libnsss/nsss_all_getpwent.c
index b68a4b3..edb8a9f 100644
--- a/src/libnsss/nsss_all_getpwent.c
+++ b/src/libnsss/nsss_all_getpwent.c
@@ -13,9 +13,9 @@ struct passwd *nsss_all_getpwent (void)
{
int e = errno ;
if (nsss_all_errno) goto fallback ;
- if (!nsss_switch_start(&nsss_switch_here, NSSS_SWITCH_PWD, NSSS_NSSSD_PATH, 0, 0)) goto efallback ;
+ if (!nsss_switch_start(&nsss_switch_enumerator, NSSS_SWITCH_PWD, NSSS_NSSSD_PATH, 0, 0)) goto efallback ;
nsss_pwd_sa_here.len = 0 ;
- if (!nsss_switch_pwd_get(&nsss_switch_here, &nsss_pwd_here, &nsss_pwd_sa_here, 0, 0)) return 0 ;
+ if (!nsss_switch_pwd_get(&nsss_switch_enumerator, &nsss_pwd_here, &nsss_pwd_sa_here, 0, 0)) return 0 ;
return &nsss_pwd_here ;
efallback:
diff --git a/src/libnsss/nsss_all_getpwent_r.c b/src/libnsss/nsss_all_getpwent_r.c
index 08e69dc..c08194a 100644
--- a/src/libnsss/nsss_all_getpwent_r.c
+++ b/src/libnsss/nsss_all_getpwent_r.c
@@ -16,9 +16,9 @@ int nsss_all_getpwent_r (struct passwd *pw, char *buf, size_t buflen, struct pas
stralloc sa = STRALLOC_ZERO ;
int e = errno ;
if (nsss_all_errno) goto fallback ;
- if (!nsss_switch_start(&nsss_switch_here, NSSS_SWITCH_PWD, NSSS_NSSSD_PATH, 0, 0)) goto efallback ;
+ if (!nsss_switch_start(&nsss_switch_enumerator, NSSS_SWITCH_PWD, NSSS_NSSSD_PATH, 0, 0)) goto efallback ;
errno = 0 ;
- if (!nsss_switch_pwd_get(&nsss_switch_here, &pw2, &sa, 0, 0))
+ if (!nsss_switch_pwd_get(&nsss_switch_enumerator, &pw2, &sa, 0, 0))
{
*pwp = 0 ;
if (!errno) errno = ENOENT ;
diff --git a/src/libnsss/nsss_all_getspent.c b/src/libnsss/nsss_all_getspent.c
index 7ca5048..57d356b 100644
--- a/src/libnsss/nsss_all_getspent.c
+++ b/src/libnsss/nsss_all_getspent.c
@@ -13,9 +13,9 @@ struct spwd *nsss_all_getspent (void)
{
int e = errno ;
if (nsss_all_errno) goto fallback ;
- if (!nsss_switch_start(&nsss_switch_here, NSSS_SWITCH_SHADOW, NSSS_NSSSD_PATH, 0, 0)) goto efallback ;
+ if (!nsss_switch_start(&nsss_switch_enumerator, NSSS_SWITCH_SHADOW, NSSS_NSSSD_PATH, 0, 0)) goto efallback ;
nsss_shadow_sa_here.len = 0 ;
- if (!nsss_switch_shadow_get(&nsss_switch_here, &nsss_shadow_here, &nsss_shadow_sa_here, 0, 0)) return 0 ;
+ if (!nsss_switch_shadow_get(&nsss_switch_enumerator, &nsss_shadow_here, &nsss_shadow_sa_here, 0, 0)) return 0 ;
return &nsss_shadow_here ;
efallback:
diff --git a/src/libnsss/nsss_all_getspent_r.c b/src/libnsss/nsss_all_getspent_r.c
index ab3e531..e6df40e 100644
--- a/src/libnsss/nsss_all_getspent_r.c
+++ b/src/libnsss/nsss_all_getspent_r.c
@@ -16,9 +16,9 @@ int nsss_all_getspent_r (struct spwd *sp, char *buf, size_t buflen, struct spwd
stralloc sa = STRALLOC_ZERO ;
int e = errno ;
if (nsss_all_errno) goto fallback ;
- if (!nsss_switch_start(&nsss_switch_here, NSSS_SWITCH_SHADOW, NSSS_NSSSD_PATH, 0, 0)) goto efallback ;
+ if (!nsss_switch_start(&nsss_switch_enumerator, NSSS_SWITCH_SHADOW, NSSS_NSSSD_PATH, 0, 0)) goto efallback ;
errno = 0 ;
- if (!nsss_switch_shadow_get(&nsss_switch_here, &sp2, &sa, 0, 0))
+ if (!nsss_switch_shadow_get(&nsss_switch_enumerator, &sp2, &sa, 0, 0))
{
*spp = 0 ;
if (!errno) errno = ENOENT ;
diff --git a/src/libnsss/nsss_all_setgrent.c b/src/libnsss/nsss_all_setgrent.c
index 78fee56..993d2fc 100644
--- a/src/libnsss/nsss_all_setgrent.c
+++ b/src/libnsss/nsss_all_setgrent.c
@@ -11,8 +11,8 @@
void nsss_all_setgrent (void)
{
int e = errno ;
- if (!nsss_switch_start(&nsss_switch_here, NSSS_SWITCH_GRP, NSSS_NSSSD_PATH, 0, 0)) goto fallback ;
- nsss_switch_grp_rewind(&nsss_switch_here, 0, 0) ;
+ if (!nsss_switch_start(&nsss_switch_enumerator, NSSS_SWITCH_GRP, NSSS_NSSSD_PATH, 0, 0)) goto fallback ;
+ nsss_switch_grp_rewind(&nsss_switch_enumerator, 0, 0) ;
return ;
fallback:
diff --git a/src/libnsss/nsss_all_setpwent.c b/src/libnsss/nsss_all_setpwent.c
index e22411a..34f4c7f 100644
--- a/src/libnsss/nsss_all_setpwent.c
+++ b/src/libnsss/nsss_all_setpwent.c
@@ -11,8 +11,8 @@
void nsss_all_setpwent (void)
{
int e = errno ;
- if (!nsss_switch_start(&nsss_switch_here, NSSS_SWITCH_PWD, NSSS_NSSSD_PATH, 0, 0)) goto fallback ;
- nsss_switch_pwd_rewind(&nsss_switch_here, 0, 0) ;
+ if (!nsss_switch_start(&nsss_switch_enumerator, NSSS_SWITCH_PWD, NSSS_NSSSD_PATH, 0, 0)) goto fallback ;
+ nsss_switch_pwd_rewind(&nsss_switch_enumerator, 0, 0) ;
return ;
fallback:
diff --git a/src/libnsss/nsss_all_setspent.c b/src/libnsss/nsss_all_setspent.c
index ab6c456..437ffcc 100644
--- a/src/libnsss/nsss_all_setspent.c
+++ b/src/libnsss/nsss_all_setspent.c
@@ -11,8 +11,8 @@
void nsss_all_setspent (void)
{
int e = errno ;
- if (!nsss_switch_start(&nsss_switch_here, NSSS_SWITCH_SHADOW, NSSS_NSSSD_PATH, 0, 0)) goto fallback ;
- nsss_switch_shadow_rewind(&nsss_switch_here, 0, 0) ;
+ if (!nsss_switch_start(&nsss_switch_enumerator, NSSS_SWITCH_SHADOW, NSSS_NSSSD_PATH, 0, 0)) goto fallback ;
+ nsss_switch_shadow_rewind(&nsss_switch_enumerator, 0, 0) ;
return ;
fallback:
diff --git a/src/libnsss/nsss_switch_end.c b/src/libnsss/nsss_switch_end.c
index 3922721..6895dd6 100644
--- a/src/libnsss/nsss_switch_end.c
+++ b/src/libnsss/nsss_switch_end.c
@@ -8,10 +8,11 @@ static inline void nsss_switch_disconnect (nsss_switch_t *a)
{
fd_close(buffer_fd(&a->b)) ;
a->b.fd = -1 ;
+ a->path = 0 ;
}
void nsss_switch_end (nsss_switch_t *a, unsigned int what)
{
- a->held &= ~(1U << what) ;
+ a->held &= ~(what & 0x7u) ;
if (!a->held) nsss_switch_disconnect(a) ;
}
diff --git a/src/libnsss/nsss_switch_endgrent.c b/src/libnsss/nsss_switch_endgrent.c
index 8ae43ea..0a9e1e4 100644
--- a/src/libnsss/nsss_switch_endgrent.c
+++ b/src/libnsss/nsss_switch_endgrent.c
@@ -1,10 +1,14 @@
/* ISC license. */
+#include <pthread.h>
+
#include <nsss/grp-switch.h>
#include "nsss-switch-internal.h"
void nsss_switch_endgrent (void)
{
- nsss_switch_grp_end(&nsss_switch_here, 0, 0) ;
- nsss_switch_end(&nsss_switch_here, NSSS_SWITCH_GRP) ;
+ pthread_mutex_lock(&nsss_switch_enumerator_mutex) ;
+ nsss_switch_grp_end(&nsss_switch_enumerator, 0, 0) ;
+ nsss_switch_end(&nsss_switch_enumerator, NSSS_SWITCH_GRP) ;
+ pthread_mutex_unlock(&nsss_switch_enumerator_mutex) ;
}
diff --git a/src/libnsss/nsss_switch_endpwent.c b/src/libnsss/nsss_switch_endpwent.c
index 8dbec92..501848f 100644
--- a/src/libnsss/nsss_switch_endpwent.c
+++ b/src/libnsss/nsss_switch_endpwent.c
@@ -1,10 +1,14 @@
/* ISC license. */
+#include <pthread.h>
+
#include <nsss/pwd-switch.h>
#include "nsss-switch-internal.h"
void nsss_switch_endpwent (void)
{
- nsss_switch_pwd_end(&nsss_switch_here, 0, 0) ;
- nsss_switch_end(&nsss_switch_here, NSSS_SWITCH_PWD) ;
+ pthread_mutex_lock(&nsss_switch_enumerator_mutex) ;
+ nsss_switch_pwd_end(&nsss_switch_enumerator, 0, 0) ;
+ nsss_switch_end(&nsss_switch_enumerator, NSSS_SWITCH_PWD) ;
+ pthread_mutex_unlock(&nsss_switch_enumerator_mutex) ;
}
diff --git a/src/libnsss/nsss_switch_endspent.c b/src/libnsss/nsss_switch_endspent.c
index 8527072..0bf5b92 100644
--- a/src/libnsss/nsss_switch_endspent.c
+++ b/src/libnsss/nsss_switch_endspent.c
@@ -1,10 +1,14 @@
/* ISC license. */
+#include <pthread.h>
+
#include <nsss/shadow-switch.h>
#include "nsss-switch-internal.h"
void nsss_switch_endspent (void)
{
- nsss_switch_shadow_end(&nsss_switch_here, 0, 0) ;
- nsss_switch_end(&nsss_switch_here, NSSS_SWITCH_SHADOW) ;
+ pthread_mutex_lock(&nsss_switch_enumerator_mutex) ;
+ nsss_switch_shadow_end(&nsss_switch_enumerator, 0, 0) ;
+ nsss_switch_end(&nsss_switch_enumerator, NSSS_SWITCH_SHADOW) ;
+ pthread_mutex_unlock(&nsss_switch_enumerator_mutex) ;
}
diff --git a/src/libnsss/nsss_switch_enumerator.c b/src/libnsss/nsss_switch_enumerator.c
new file mode 100644
index 0000000..ca7d127
--- /dev/null
+++ b/src/libnsss/nsss_switch_enumerator.c
@@ -0,0 +1,9 @@
+/* ISC license. */
+
+#include <pthread.h>
+
+#include <nsss/nsss-switch.h>
+#include "nsss-switch-internal.h"
+
+nsss_switch_t nsss_switch_enumerator = NSSS_SWITCH_ZERO ;
+pthread_mutex_t nsss_switch_enumerator_mutex = PTHREAD_MUTEX_INITIALIZER ;
diff --git a/src/libnsss/nsss_switch_getgrent.c b/src/libnsss/nsss_switch_getgrent.c
index 6a6c8dc..cedcf8c 100644
--- a/src/libnsss/nsss_switch_getgrent.c
+++ b/src/libnsss/nsss_switch_getgrent.c
@@ -9,9 +9,9 @@
struct group *nsss_switch_getgrent (void)
{
- if (!nsss_switch_start(&nsss_switch_here, NSSS_SWITCH_GRP, NSSS_NSSSD_PATH, 0, 0)) return 0 ;
+ if (!nsss_switch_start(&nsss_switch_enumerator, NSSS_SWITCH_GRP, NSSS_NSSSD_PATH, 0, 0)) return 0 ;
nsss_grp_sa_here.len = 0 ;
genalloc_setlen(char *, &nsss_grp_ga_here, 0) ;
- if (!nsss_switch_grp_get(&nsss_switch_here, &nsss_grp_here, &nsss_grp_sa_here, &nsss_grp_ga_here, 0, 0)) return 0 ;
+ if (!nsss_switch_grp_get(&nsss_switch_enumerator, &nsss_grp_here, &nsss_grp_sa_here, &nsss_grp_ga_here, 0, 0)) return 0 ;
return &nsss_grp_here ;
}
diff --git a/src/libnsss/nsss_switch_getgrent_r.c b/src/libnsss/nsss_switch_getgrent_r.c
index 92a4264..f13445c 100644
--- a/src/libnsss/nsss_switch_getgrent_r.c
+++ b/src/libnsss/nsss_switch_getgrent_r.c
@@ -1,8 +1,11 @@
/* ISC license. */
#include <errno.h>
+#include <pthread.h>
+
#include <skalibs/stralloc.h>
#include <skalibs/genalloc.h>
+
#include <nsss/config.h>
#include <nsss/grp-switch.h>
#include <nsss/nsss-switch.h>
@@ -14,16 +17,18 @@ int nsss_switch_getgrent_r (struct group *gr, char *buf, size_t buflen, struct g
struct group gr2 ;
stralloc sa = STRALLOC_ZERO ;
genalloc ga = GENALLOC_ZERO ;
- int e ;
- if (!nsss_switch_start(&nsss_switch_here, NSSS_SWITCH_GRP, NSSS_NSSSD_PATH, 0, 0)) return errno ;
+ int e = pthread_mutex_lock(&nsss_switch_enumerator_mutex) ;
+ if (e) return e ;
+ if (!nsss_switch_start(&nsss_switch_enumerator, NSSS_SWITCH_GRP, NSSS_NSSSD_PATH, 0, 0)) return errno ;
e = errno ;
errno = 0 ;
- if (!nsss_switch_grp_get(&nsss_switch_here, &gr2, &sa, &ga, 0, 0))
+ if (!nsss_switch_grp_get(&nsss_switch_enumerator, &gr2, &sa, &ga, 0, 0))
{
*grp = 0 ;
if (!errno) errno = ENOENT ;
- return errno ;
+ goto err ;
}
+ pthread_mutex_unlock(&nsss_switch_enumerator_mutex) ;
if (!nsss_grp_copy(gr, buf, buflen, &gr2, sa.s, sa.len, genalloc_s(char *, &ga), genalloc_len(char *, &ga)))
{
genalloc_free(char *, &ga) ;
@@ -35,4 +40,8 @@ int nsss_switch_getgrent_r (struct group *gr, char *buf, size_t buflen, struct g
stralloc_free(&sa) ;
*grp = gr ;
return (errno = e, 0) ;
+
+ err:
+ pthread_mutex_unlock(&nsss_switch_enumerator_mutex) ;
+ return errno ;
}
diff --git a/src/libnsss/nsss_switch_getgrgid.c b/src/libnsss/nsss_switch_getgrgid.c
index 65dbeef..57b71fc 100644
--- a/src/libnsss/nsss_switch_getgrgid.c
+++ b/src/libnsss/nsss_switch_getgrgid.c
@@ -1,22 +1,17 @@
/* ISC license. */
#include <skalibs/genalloc.h>
+
#include <nsss/config.h>
#include <nsss/grp-switch.h>
#include <nsss/nsss-switch.h>
#include "nsss-internal.h"
+#include "nsss-switch-internal.h"
struct group *nsss_switch_getgrgid (gid_t gid)
{
- nsss_switch_t a = NSSS_SWITCH_ZERO ;
- if (!nsss_switch_start(&a, NSSS_SWITCH_GRP, NSSS_NSSSD_PATH, 0, 0)) return 0 ;
+ if (!nsss_switch_query_start(NSSS_NSSSD_PATH, NSSS_SWITCH_GRP, 30000, 0, 0)) return 0 ;
nsss_grp_sa_here.len = 0 ;
genalloc_setlen(char *, &nsss_grp_ga_here, 0) ;
- if (!nsss_switch_grp_getbygid(&a, &nsss_grp_here, &nsss_grp_sa_here, &nsss_grp_ga_here, gid, 0, 0))
- {
- nsss_switch_end(&a, NSSS_SWITCH_GRP) ;
- return 0 ;
- }
- nsss_switch_end(&a, NSSS_SWITCH_GRP) ;
- return &nsss_grp_here ;
+ return nsss_switch_grp_getbygid(&nsss_switch_query, &nsss_grp_here, &nsss_grp_sa_here, &nsss_grp_ga_here, gid, 0, 0) ? &nsss_grp_here : 0 ;
}
diff --git a/src/libnsss/nsss_switch_getgrgid_r.c b/src/libnsss/nsss_switch_getgrgid_r.c
index 2eb4855..4113703 100644
--- a/src/libnsss/nsss_switch_getgrgid_r.c
+++ b/src/libnsss/nsss_switch_getgrgid_r.c
@@ -1,29 +1,38 @@
/* ISC license. */
#include <errno.h>
+#include <pthread.h>
+
#include <skalibs/stralloc.h>
#include <skalibs/genalloc.h>
+
#include <nsss/config.h>
#include <nsss/grp-switch.h>
#include <nsss/nsss-switch.h>
#include "nsss-internal.h"
+#include "nsss-switch-internal.h"
int nsss_switch_getgrgid_r (gid_t gid, struct group *gr, char *buf, size_t buflen, struct group **grp)
{
struct group gr2 ;
stralloc sa = STRALLOC_ZERO ;
genalloc ga = GENALLOC_ZERO ;
- nsss_switch_t a = NSSS_SWITCH_ZERO ;
- int e = errno ;
- if (!nsss_switch_start(&a, NSSS_SWITCH_GRP, NSSS_NSSSD_PATH, 0, 0)) return errno ;
+ int e = pthread_mutex_lock(&nsss_switch_query_mutex) ;
+ if (e) return e ;
+ e = errno ;
+ if (!nsss_switch_query_start(NSSS_NSSSD_PATH, NSSS_SWITCH_GRP, 30000, 0, 0))
+ {
+ pthread_mutex_unlock(&nsss_switch_query_mutex) ;
+ return errno ;
+ }
errno = 0 ;
- if (!nsss_switch_grp_getbygid(&a, &gr2, &sa, &ga, gid, 0, 0))
+ if (!nsss_switch_grp_getbygid(&nsss_switch_query, &gr2, &sa, &ga, gid, 0, 0))
{
- nsss_switch_end(&a, NSSS_SWITCH_GRP) ;
+ pthread_mutex_unlock(&nsss_switch_query_mutex) ;
*grp = 0 ;
return errno ? errno : (errno = e, 0) ;
}
- nsss_switch_end(&a, NSSS_SWITCH_GRP) ;
+ pthread_mutex_unlock(&nsss_switch_query_mutex) ;
if (!nsss_grp_copy(gr, buf, buflen, &gr2, sa.s, sa.len, genalloc_s(char *, &ga), genalloc_len(char *, &ga)))
{
genalloc_free(char *, &ga) ;
diff --git a/src/libnsss/nsss_switch_getgrnam.c b/src/libnsss/nsss_switch_getgrnam.c
index 396f44e..9be1e18 100644
--- a/src/libnsss/nsss_switch_getgrnam.c
+++ b/src/libnsss/nsss_switch_getgrnam.c
@@ -1,22 +1,17 @@
/* ISC license. */
#include <skalibs/genalloc.h>
+
#include <nsss/config.h>
#include <nsss/grp-switch.h>
#include <nsss/nsss-switch.h>
#include "nsss-internal.h"
+#include "nsss-switch-internal.h"
struct group *nsss_switch_getgrnam (char const *name)
{
- nsss_switch_t a = NSSS_SWITCH_ZERO ;
- if (!nsss_switch_start(&a, NSSS_SWITCH_GRP, NSSS_NSSSD_PATH, 0, 0)) return 0 ;
+ if (!nsss_switch_query_start(NSSS_NSSSD_PATH, NSSS_SWITCH_GRP, 30000, 0, 0)) return 0 ;
nsss_grp_sa_here.len = 0 ;
genalloc_setlen(char *, &nsss_grp_ga_here, 0) ;
- if (!nsss_switch_grp_getbyname(&a, &nsss_grp_here, &nsss_grp_sa_here, &nsss_grp_ga_here, name, 0, 0))
- {
- nsss_switch_end(&a, NSSS_SWITCH_GRP) ;
- return 0 ;
- }
- nsss_switch_end(&a, NSSS_SWITCH_GRP) ;
- return &nsss_grp_here ;
+ return nsss_switch_grp_getbyname(&nsss_switch_query, &nsss_grp_here, &nsss_grp_sa_here, &nsss_grp_ga_here, name, 0, 0) ? &nsss_grp_here : 0 ;
}
diff --git a/src/libnsss/nsss_switch_getgrnam_r.c b/src/libnsss/nsss_switch_getgrnam_r.c
index c35b8ef..b09484e 100644
--- a/src/libnsss/nsss_switch_getgrnam_r.c
+++ b/src/libnsss/nsss_switch_getgrnam_r.c
@@ -1,29 +1,38 @@
/* ISC license. */
#include <errno.h>
+#include <pthread.h>
+
#include <skalibs/stralloc.h>
#include <skalibs/genalloc.h>
+
#include <nsss/config.h>
#include <nsss/grp-switch.h>
#include <nsss/nsss-switch.h>
#include "nsss-internal.h"
+#include "nsss-switch-internal.h"
int nsss_switch_getgrnam_r (char const *name, struct group *gr, char *buf, size_t buflen, struct group **grp)
{
struct group gr2 ;
stralloc sa = STRALLOC_ZERO ;
genalloc ga = GENALLOC_ZERO ;
- nsss_switch_t a = NSSS_SWITCH_ZERO ;
- int e = errno ;
- if (!nsss_switch_start(&a, NSSS_SWITCH_GRP, NSSS_NSSSD_PATH, 0, 0)) return errno ;
+ int e = pthread_mutex_lock(&nsss_switch_query_mutex) ;
+ if (e) return (errno = e, 0) ;
+ e = errno ;
+ if (!nsss_switch_query_start(NSSS_NSSSD_PATH, NSSS_SWITCH_GRP, 30000, 0, 0))
+ {
+ pthread_mutex_unlock(&nsss_switch_query_mutex) ;
+ return errno ;
+ }
errno = 0 ;
- if (!nsss_switch_grp_getbyname(&a, &gr2, &sa, &ga, name, 0, 0))
+ if (!nsss_switch_grp_getbyname(&nsss_switch_query, &gr2, &sa, &ga, name, 0, 0))
{
- nsss_switch_end(&a, NSSS_SWITCH_GRP) ;
+ pthread_mutex_unlock(&nsss_switch_query_mutex) ;
*grp = 0 ;
return errno ? errno : (errno = e, 0) ;
}
- nsss_switch_end(&a, NSSS_SWITCH_GRP) ;
+ pthread_mutex_unlock(&nsss_switch_query_mutex) ;
if (!nsss_grp_copy(gr, buf, buflen, &gr2, sa.s, sa.len, genalloc_s(char *, &ga), genalloc_len(char *, &ga)))
{
genalloc_free(char *, &ga) ;
diff --git a/src/libnsss/nsss_switch_getgrouplist.c b/src/libnsss/nsss_switch_getgrouplist.c
index 73d3fe0..868b463 100644
--- a/src/libnsss/nsss_switch_getgrouplist.c
+++ b/src/libnsss/nsss_switch_getgrouplist.c
@@ -2,6 +2,7 @@
#include <stddef.h>
#include <errno.h>
+#include <pthread.h>
#include <skalibs/stralloc.h>
@@ -9,22 +10,25 @@
#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 ;
- int e = errno ;
size_t r = 0 ;
size_t n ;
- nsss_switch_t a = NSSS_SWITCH_ZERO ;
+ int e ;
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))
+ 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))
{
- nsss_switch_end(&a, NSSS_SWITCH_GRP) ;
+ pthread_mutex_unlock(&nsss_switch_query_mutex) ;
return -1 ;
}
- nsss_switch_end(&a, NSSS_SWITCH_GRP) ;
+ pthread_mutex_unlock(&nsss_switch_query_mutex) ;
return nsss_grouplist_adjust(n, r, gid, gids, ngids, e) ;
}
diff --git a/src/libnsss/nsss_switch_getpwent.c b/src/libnsss/nsss_switch_getpwent.c
index 89cabfd..a339716 100644
--- a/src/libnsss/nsss_switch_getpwent.c
+++ b/src/libnsss/nsss_switch_getpwent.c
@@ -8,8 +8,8 @@
struct passwd *nsss_switch_getpwent (void)
{
- if (!nsss_switch_start(&nsss_switch_here, NSSS_SWITCH_PWD, NSSS_NSSSD_PATH, 0, 0)) return 0 ;
+ if (!nsss_switch_start(&nsss_switch_enumerator, NSSS_SWITCH_PWD, NSSS_NSSSD_PATH, 0, 0)) return 0 ;
nsss_pwd_sa_here.len = 0 ;
- if (!nsss_switch_pwd_get(&nsss_switch_here, &nsss_pwd_here, &nsss_pwd_sa_here, 0, 0)) return 0 ;
+ if (!nsss_switch_pwd_get(&nsss_switch_enumerator, &nsss_pwd_here, &nsss_pwd_sa_here, 0, 0)) return 0 ;
return &nsss_pwd_here ;
}
diff --git a/src/libnsss/nsss_switch_getpwent_r.c b/src/libnsss/nsss_switch_getpwent_r.c
index 7795af0..e982f11 100644
--- a/src/libnsss/nsss_switch_getpwent_r.c
+++ b/src/libnsss/nsss_switch_getpwent_r.c
@@ -1,7 +1,10 @@
/* ISC license. */
#include <errno.h>
+#include <pthread.h>
+
#include <skalibs/stralloc.h>
+
#include <nsss/config.h>
#include <nsss/pwd-switch.h>
#include <nsss/nsss-switch.h>
@@ -12,16 +15,18 @@ int nsss_switch_getpwent_r (struct passwd *pw, char *buf, size_t buflen, struct
{
struct passwd pw2 ;
stralloc sa = STRALLOC_ZERO ;
- int e ;
- if (!nsss_switch_start(&nsss_switch_here, NSSS_SWITCH_PWD, NSSS_NSSSD_PATH, 0, 0)) return errno ;
+ int e = pthread_mutex_lock(&nsss_switch_enumerator_mutex) ;
+ if (e) return e ;
+ if (!nsss_switch_start(&nsss_switch_enumerator, NSSS_SWITCH_PWD, NSSS_NSSSD_PATH, 0, 0)) goto err ;
e = errno ;
errno = 0 ;
- if (!nsss_switch_pwd_get(&nsss_switch_here, &pw2, &sa, 0, 0))
+ if (!nsss_switch_pwd_get(&nsss_switch_enumerator, &pw2, &sa, 0, 0))
{
*pwp = 0 ;
if (!errno) errno = ENOENT ;
- return errno ;
+ goto err ;
}
+ pthread_mutex_unlock(&nsss_switch_enumerator_mutex) ;
if (!nsss_pwd_copy(pw, buf, buflen, &pw2, sa.s, sa.len))
{
stralloc_free(&sa) ;
@@ -31,4 +36,8 @@ int nsss_switch_getpwent_r (struct passwd *pw, char *buf, size_t buflen, struct
stralloc_free(&sa) ;
*pwp = pw ;
return (errno = e, 0) ;
+
+ err:
+ pthread_mutex_unlock(&nsss_switch_enumerator_mutex) ;
+ return errno ;
}
diff --git a/src/libnsss/nsss_switch_getpwnam.c b/src/libnsss/nsss_switch_getpwnam.c
index 393503d..722e556 100644
--- a/src/libnsss/nsss_switch_getpwnam.c
+++ b/src/libnsss/nsss_switch_getpwnam.c
@@ -4,17 +4,11 @@
#include <nsss/pwd-switch.h>
#include <nsss/nsss-switch.h>
#include "nsss-internal.h"
+#include "nsss-switch-internal.h"
struct passwd *nsss_switch_getpwnam (char const *name)
{
- nsss_switch_t a = NSSS_SWITCH_ZERO ;
- if (!nsss_switch_start(&a, NSSS_SWITCH_PWD, NSSS_NSSSD_PATH, 0, 0)) return 0 ;
+ if (!nsss_switch_query_start(NSSS_NSSSD_PATH, NSSS_SWITCH_PWD, 30000, 0, 0)) return 0 ;
nsss_pwd_sa_here.len = 0 ;
- if (!nsss_switch_pwd_getbyname(&a, &nsss_pwd_here, &nsss_pwd_sa_here, name, 0, 0))
- {
- nsss_switch_end(&a, NSSS_SWITCH_PWD) ;
- return 0 ;
- }
- nsss_switch_end(&a, NSSS_SWITCH_PWD) ;
- return &nsss_pwd_here ;
+ return nsss_switch_pwd_getbyname(&nsss_switch_query, &nsss_pwd_here, &nsss_pwd_sa_here, name, 0, 0) ? &nsss_pwd_here : 0 ;
}
diff --git a/src/libnsss/nsss_switch_getpwnam_r.c b/src/libnsss/nsss_switch_getpwnam_r.c
index e1c1e71..53ab665 100644
--- a/src/libnsss/nsss_switch_getpwnam_r.c
+++ b/src/libnsss/nsss_switch_getpwnam_r.c
@@ -1,27 +1,36 @@
/* ISC license. */
#include <errno.h>
+#include <pthread.h>
+
#include <skalibs/stralloc.h>
+
#include <nsss/config.h>
#include <nsss/pwd-switch.h>
#include <nsss/nsss-switch.h>
#include "nsss-internal.h"
+#include "nsss-switch-internal.h"
int nsss_switch_getpwnam_r (char const *name, struct passwd *pw, char *buf, size_t buflen, struct passwd **pwp)
{
struct passwd pw2 ;
stralloc sa = STRALLOC_ZERO ;
- nsss_switch_t a = NSSS_SWITCH_ZERO ;
- int e = errno ;
- if (!nsss_switch_start(&a, NSSS_SWITCH_PWD, NSSS_NSSSD_PATH, 0, 0)) return errno ;
+ int e = pthread_mutex_lock(&nsss_switch_query_mutex) ;
+ if (e) return e ;
+ e = errno ;
+ if (!nsss_switch_query_start(NSSS_NSSSD_PATH, NSSS_SWITCH_PWD, 30000, 0, 0))
+ {
+ pthread_mutex_unlock(&nsss_switch_query_mutex) ;
+ return errno ;
+ }
errno = 0 ;
- if (!nsss_switch_pwd_getbyname(&a, &pw2, &sa, name, 0, 0))
+ if (!nsss_switch_pwd_getbyname(&nsss_switch_query, &pw2, &sa, name, 0, 0))
{
- nsss_switch_end(&a, NSSS_SWITCH_PWD) ;
+ pthread_mutex_unlock(&nsss_switch_query_mutex) ;
*pwp = 0 ;
return errno ? errno : (errno = e, 0) ;
}
- nsss_switch_end(&a, NSSS_SWITCH_PWD) ;
+ pthread_mutex_unlock(&nsss_switch_query_mutex) ;
if (!nsss_pwd_copy(pw, buf, buflen, &pw2, sa.s, sa.len))
{
stralloc_free(&sa) ;
diff --git a/src/libnsss/nsss_switch_getpwuid.c b/src/libnsss/nsss_switch_getpwuid.c
index 3d765bf..004e93c 100644
--- a/src/libnsss/nsss_switch_getpwuid.c
+++ b/src/libnsss/nsss_switch_getpwuid.c
@@ -4,17 +4,11 @@
#include <nsss/pwd-switch.h>
#include <nsss/nsss-switch.h>
#include "nsss-internal.h"
+#include "nsss-switch-internal.h"
struct passwd *nsss_switch_getpwuid (uid_t uid)
{
- nsss_switch_t a = NSSS_SWITCH_ZERO ;
- if (!nsss_switch_start(&a, NSSS_SWITCH_PWD, NSSS_NSSSD_PATH, 0, 0)) return 0 ;
+ if (!nsss_switch_query_start(NSSS_NSSSD_PATH, NSSS_SWITCH_PWD, 30000, 0, 0)) return 0 ;
nsss_pwd_sa_here.len = 0 ;
- if (!nsss_switch_pwd_getbyuid(&a, &nsss_pwd_here, &nsss_pwd_sa_here, uid, 0, 0))
- {
- nsss_switch_end(&a, NSSS_SWITCH_PWD) ;
- return 0 ;
- }
- nsss_switch_end(&a, NSSS_SWITCH_PWD) ;
- return &nsss_pwd_here ;
+ return nsss_switch_pwd_getbyuid(&nsss_switch_query, &nsss_pwd_here, &nsss_pwd_sa_here, uid, 0, 0) ? &nsss_pwd_here : 0 ;
}
diff --git a/src/libnsss/nsss_switch_getpwuid_r.c b/src/libnsss/nsss_switch_getpwuid_r.c
index 8e63a75..3eb17a6 100644
--- a/src/libnsss/nsss_switch_getpwuid_r.c
+++ b/src/libnsss/nsss_switch_getpwuid_r.c
@@ -1,27 +1,36 @@
/* ISC license. */
#include <errno.h>
+#include <pthread.h>
+
#include <skalibs/stralloc.h>
+
#include <nsss/config.h>
#include <nsss/pwd-switch.h>
#include <nsss/nsss-switch.h>
#include "nsss-internal.h"
+#include "nsss-switch-internal.h"
int nsss_switch_getpwuid_r (uid_t uid, struct passwd *pw, char *buf, size_t buflen, struct passwd **pwp)
{
struct passwd pw2 ;
stralloc sa = STRALLOC_ZERO ;
- nsss_switch_t a = NSSS_SWITCH_ZERO ;
- int e = errno ;
- if (!nsss_switch_start(&a, NSSS_SWITCH_PWD, NSSS_NSSSD_PATH, 0, 0)) return errno ;
+ int e = pthread_mutex_lock(&nsss_switch_query_mutex) ;
+ if (e) return e ;
+ e = errno ;
+ if (!nsss_switch_query_start(NSSS_NSSSD_PATH, NSSS_SWITCH_PWD, 30000, 0, 0))
+ {
+ pthread_mutex_unlock(&nsss_switch_query_mutex) ;
+ return errno ;
+ }
errno = 0 ;
- if (!nsss_switch_pwd_getbyuid(&a, &pw2, &sa, uid, 0, 0))
+ if (!nsss_switch_pwd_getbyuid(&nsss_switch_query, &pw2, &sa, uid, 0, 0))
{
- nsss_switch_end(&a, NSSS_SWITCH_PWD) ;
+ pthread_mutex_unlock(&nsss_switch_query_mutex) ;
*pwp = 0 ;
return errno ? errno : (errno = e, 0) ;
}
- nsss_switch_end(&a, NSSS_SWITCH_PWD) ;
+ pthread_mutex_unlock(&nsss_switch_query_mutex) ;
if (!nsss_pwd_copy(pw, buf, buflen, &pw2, sa.s, sa.len))
{
stralloc_free(&sa) ;
diff --git a/src/libnsss/nsss_switch_getspent.c b/src/libnsss/nsss_switch_getspent.c
index 65064a1..270737c 100644
--- a/src/libnsss/nsss_switch_getspent.c
+++ b/src/libnsss/nsss_switch_getspent.c
@@ -8,8 +8,8 @@
struct spwd *nsss_switch_getspent (void)
{
- if (!nsss_switch_start(&nsss_switch_here, NSSS_SWITCH_SHADOW, NSSS_NSSSD_PATH, 0, 0)) return 0 ;
+ if (!nsss_switch_start(&nsss_switch_enumerator, NSSS_SWITCH_SHADOW, NSSS_NSSSD_PATH, 0, 0)) return 0 ;
nsss_shadow_sa_here.len = 0 ;
- if (!nsss_switch_shadow_get(&nsss_switch_here, &nsss_shadow_here, &nsss_shadow_sa_here, 0, 0)) return 0 ;
+ if (!nsss_switch_shadow_get(&nsss_switch_enumerator, &nsss_shadow_here, &nsss_shadow_sa_here, 0, 0)) return 0 ;
return &nsss_shadow_here ;
}
diff --git a/src/libnsss/nsss_switch_getspent_r.c b/src/libnsss/nsss_switch_getspent_r.c
index 118e095..25cebae 100644
--- a/src/libnsss/nsss_switch_getspent_r.c
+++ b/src/libnsss/nsss_switch_getspent_r.c
@@ -1,7 +1,10 @@
/* ISC license. */
#include <errno.h>
+#include <pthread.h>
+
#include <skalibs/stralloc.h>
+
#include <nsss/config.h>
#include <nsss/shadow-switch.h>
#include <nsss/nsss-switch.h>
@@ -12,16 +15,18 @@ int nsss_switch_getspent_r (struct spwd *sp, char *buf, size_t buflen, struct sp
{
struct spwd sp2 ;
stralloc sa = STRALLOC_ZERO ;
- int e ;
- if (!nsss_switch_start(&nsss_switch_here, NSSS_SWITCH_SHADOW, NSSS_NSSSD_PATH, 0, 0)) return errno ;
+ int e = pthread_mutex_lock(&nsss_switch_enumerator_mutex) ;
+ if (e) return e ;
+ if (!nsss_switch_start(&nsss_switch_enumerator, NSSS_SWITCH_SHADOW, NSSS_NSSSD_PATH, 0, 0)) goto err ;
e = errno ;
errno = 0 ;
- if (!nsss_switch_shadow_get(&nsss_switch_here, &sp2, &sa, 0, 0))
+ if (!nsss_switch_shadow_get(&nsss_switch_enumerator, &sp2, &sa, 0, 0))
{
*spp = 0 ;
if (!errno) errno = ENOENT ;
- return errno ;
+ goto err ;
}
+ pthread_mutex_unlock(&nsss_switch_enumerator_mutex) ;
if (!nsss_shadow_copy(sp, buf, buflen, &sp2, sa.s, sa.len))
{
stralloc_free(&sa) ;
@@ -31,4 +36,8 @@ int nsss_switch_getspent_r (struct spwd *sp, char *buf, size_t buflen, struct sp
stralloc_free(&sa) ;
*spp = sp ;
return (errno = e, 0) ;
+
+ err:
+ pthread_mutex_unlock(&nsss_switch_enumerator_mutex) ;
+ return errno ;
}
diff --git a/src/libnsss/nsss_switch_getspnam.c b/src/libnsss/nsss_switch_getspnam.c
index 01184ec..af2f8da 100644
--- a/src/libnsss/nsss_switch_getspnam.c
+++ b/src/libnsss/nsss_switch_getspnam.c
@@ -4,17 +4,11 @@
#include <nsss/shadow-switch.h>
#include <nsss/nsss-switch.h>
#include "nsss-internal.h"
+#include "nsss-switch-internal.h"
struct spwd *nsss_switch_getspnam (char const *name)
{
- nsss_switch_t a = NSSS_SWITCH_ZERO ;
- if (!nsss_switch_start(&a, NSSS_SWITCH_SHADOW, NSSS_NSSSD_PATH, 0, 0)) return 0 ;
+ if (!nsss_switch_query_start(NSSS_NSSSD_PATH, NSSS_SWITCH_SHADOW, 30000, 0, 0)) return 0 ;
nsss_shadow_sa_here.len = 0 ;
- if (!nsss_switch_shadow_getbyname(&a, &nsss_shadow_here, &nsss_shadow_sa_here, name, 0, 0))
- {
- nsss_switch_end(&a, NSSS_SWITCH_SHADOW) ;
- return 0 ;
- }
- nsss_switch_end(&a, NSSS_SWITCH_SHADOW) ;
- return &nsss_shadow_here ;
+ return nsss_switch_shadow_getbyname(&nsss_switch_query, &nsss_shadow_here, &nsss_shadow_sa_here, name, 0, 0) ? &nsss_shadow_here : 0 ;
}
diff --git a/src/libnsss/nsss_switch_getspnam_r.c b/src/libnsss/nsss_switch_getspnam_r.c
index 9c6b86f..7652004 100644
--- a/src/libnsss/nsss_switch_getspnam_r.c
+++ b/src/libnsss/nsss_switch_getspnam_r.c
@@ -1,27 +1,36 @@
/* ISC license. */
#include <errno.h>
+#include <pthread.h>
+
#include <skalibs/stralloc.h>
+
#include <nsss/config.h>
#include <nsss/shadow-switch.h>
#include <nsss/nsss-switch.h>
#include "nsss-internal.h"
+#include "nsss-switch-internal.h"
int nsss_switch_getspnam_r (char const *name, struct spwd *sp, char *buf, size_t buflen, struct spwd **spp)
{
struct spwd sp2 ;
stralloc sa = STRALLOC_ZERO ;
- nsss_switch_t a = NSSS_SWITCH_ZERO ;
- int e = errno ;
- if (!nsss_switch_start(&a, NSSS_SWITCH_SHADOW, NSSS_NSSSD_PATH, 0, 0)) return errno ;
+ int e = pthread_mutex_lock(&nsss_switch_query_mutex) ;
+ if (e) return e ;
+ e = errno ;
+ if (!nsss_switch_query_start(NSSS_NSSSD_PATH, NSSS_SWITCH_SHADOW, 30000, 0, 0))
+ {
+ pthread_mutex_unlock(&nsss_switch_query_mutex) ;
+ return errno ;
+ }
errno = 0 ;
- if (!nsss_switch_shadow_getbyname(&a, &sp2, &sa, name, 0, 0))
+ if (!nsss_switch_shadow_getbyname(&nsss_switch_query, &sp2, &sa, name, 0, 0))
{
- nsss_switch_end(&a, NSSS_SWITCH_SHADOW) ;
+ pthread_mutex_unlock(&nsss_switch_query_mutex) ;
*spp = 0 ;
return errno ? errno : (errno = e, 0) ;
}
- nsss_switch_end(&a, NSSS_SWITCH_SHADOW) ;
+ pthread_mutex_unlock(&nsss_switch_query_mutex) ;
if (!nsss_shadow_copy(sp, buf, buflen, &sp2, sa.s, sa.len))
{
stralloc_free(&sa) ;
diff --git a/src/libnsss/nsss_switch_grp_get.c b/src/libnsss/nsss_switch_grp_get.c
index 8ba52b1..d925cd1 100644
--- a/src/libnsss/nsss_switch_grp_get.c
+++ b/src/libnsss/nsss_switch_grp_get.c
@@ -1,15 +1,16 @@
/* ISC license. */
#include <errno.h>
-#include <skalibs/buffer.h>
+
#include <skalibs/unix-timed.h>
+
#include <nsss/nsss-switch.h>
#include "nsss-switch-internal.h"
int nsss_switch_grp_get (nsss_switch_t *a, struct group *gr, stralloc *sa, genalloc *ga, tain const *deadline, tain *stamp)
{
unsigned char c = NSSS_SWITCH_GRP_GET ;
- if (!ipc_timed_send(buffer_fd(&a->b), (char *)&c, 1, deadline, stamp)) return 0 ;
+ if (!nsss_switch_send(a, (char *)&c, 1, deadline, stamp)) return 0 ;
if (!buffer_timed_get(&a->b, (char *)&c, 1, deadline, stamp)) return 0 ;
if (c == 255) return 0 ;
if (c) return (errno = c, 0) ;
diff --git a/src/libnsss/nsss_switch_grp_getbygid.c b/src/libnsss/nsss_switch_grp_getbygid.c
index d40235c..79e95c7 100644
--- a/src/libnsss/nsss_switch_grp_getbygid.c
+++ b/src/libnsss/nsss_switch_grp_getbygid.c
@@ -1,9 +1,10 @@
/* ISC license. */
#include <errno.h>
+
#include <skalibs/uint32.h>
-#include <skalibs/buffer.h>
#include <skalibs/unix-timed.h>
+
#include <nsss/nsss-switch.h>
#include "nsss-switch-internal.h"
@@ -11,7 +12,7 @@ int nsss_switch_grp_getbygid (nsss_switch_t *a, struct group *gr, stralloc *sa,
{
char buf[5] = { NSSS_SWITCH_GRP_GETBYGID } ;
uint32_pack_big(buf + 1, gid) ;
- if (!ipc_timed_send(buffer_fd(&a->b), buf, 5, deadline, stamp)) return 0 ;
+ if (!nsss_switch_send(a, buf, 5, deadline, stamp)) return 0 ;
if (!buffer_timed_get(&a->b, &buf[0], 1, deadline, stamp)) return 0 ;
if ((unsigned char)buf[0] == 255) return 0 ;
if (buf[0]) return (errno = (unsigned char)buf[0], 0) ;
diff --git a/src/libnsss/nsss_switch_grp_getbyname.c b/src/libnsss/nsss_switch_grp_getbyname.c
index 2b7448a..de397ce 100644
--- a/src/libnsss/nsss_switch_grp_getbyname.c
+++ b/src/libnsss/nsss_switch_grp_getbyname.c
@@ -3,9 +3,10 @@
#include <string.h>
#include <sys/uio.h>
#include <errno.h>
+
#include <skalibs/uint32.h>
-#include <skalibs/buffer.h>
#include <skalibs/unix-timed.h>
+
#include <nsss/nsss-switch.h>
#include "nsss-switch-internal.h"
@@ -16,7 +17,7 @@ int nsss_switch_grp_getbyname (nsss_switch_t *a, struct group *gr, stralloc *sa,
struct iovec v[2] = { { .iov_base = buf, .iov_len = 5 }, { .iov_base = (char *)name, .iov_len = len + 1 } } ;
if (len > NSSS_SWITCH_NAME_MAXLEN - 1) return (errno = EINVAL, 0) ;
uint32_pack_big(buf + 1, len + 1) ;
- if (!ipc_timed_sendv(buffer_fd(&a->b), v, 2, deadline, stamp)) return 0 ;
+ if (!nsss_switch_sendv(a, v, 2, deadline, stamp)) return 0 ;
if (!buffer_timed_get(&a->b, &buf[0], 1, deadline, stamp)) return 0 ;
if ((unsigned char)buf[0] == 255) return 0 ;
if (buf[0]) return (errno = (unsigned char)buf[0], 0) ;
diff --git a/src/libnsss/nsss_switch_grp_getlist.c b/src/libnsss/nsss_switch_grp_getlist.c
index 22fb156..f637c0d 100644
--- a/src/libnsss/nsss_switch_grp_getlist.c
+++ b/src/libnsss/nsss_switch_grp_getlist.c
@@ -13,6 +13,7 @@
#include <skalibs/unix-timed.h>
#include <nsss/nsss-switch.h>
+#include "nsss-switch-internal.h"
/*
Expects:
@@ -59,7 +60,7 @@ int nsss_switch_grp_getlist (nsss_switch_t *a, char const *user, gid_t *gids, si
if (len > NSSS_SWITCH_NAME_MAXLEN - 1) return (errno = EINVAL, 0) ;
uint64_pack_big(buf + 1, n) ;
uint32_pack_big(buf + 9, len + 1) ;
- if (!ipc_timed_sendv(buffer_fd(&a->b), v, 2, deadline, stamp)) return 0 ;
+ if (!nsss_switch_sendv(a, v, 2, deadline, stamp)) return 0 ;
if (!buffer_timed_get(&a->b, &buf[0], 1, deadline, stamp)) return 0 ;
if (buf[0]) return (errno = (unsigned char)buf[0], 0) ;
return nsss_switch_grouplist_read(&a->b, n, r, gids, sa, deadline, stamp) ;
diff --git a/src/libnsss/nsss_switch_op.c b/src/libnsss/nsss_switch_op.c
index 7e9c1b3..4753432 100644
--- a/src/libnsss/nsss_switch_op.c
+++ b/src/libnsss/nsss_switch_op.c
@@ -1,15 +1,16 @@
/* ISC license. */
#include <errno.h>
-#include <skalibs/buffer.h>
+
#include <skalibs/unix-timed.h>
+
#include <nsss/nsss-switch.h>
#include "nsss-switch-internal.h"
int nsss_switch_op (nsss_switch_t *a, char op, tain const *deadline, tain *stamp)
{
unsigned char c ;
- if (!ipc_timed_send(buffer_fd(&a->b), &op, 1, deadline, stamp)) return 0 ;
+ if (!nsss_switch_send(a, &op, 1, deadline, stamp)) return 0 ;
if (!buffer_timed_get(&a->b, (char *)&c, 1, deadline, stamp)) return 0 ;
if (c) return (errno = c, 0) ;
return 1 ;
diff --git a/src/libnsss/nsss_switch_pwd_get.c b/src/libnsss/nsss_switch_pwd_get.c
index 146e934..b3c3a34 100644
--- a/src/libnsss/nsss_switch_pwd_get.c
+++ b/src/libnsss/nsss_switch_pwd_get.c
@@ -1,15 +1,16 @@
/* ISC license. */
#include <errno.h>
-#include <skalibs/buffer.h>
+
#include <skalibs/unix-timed.h>
+
#include <nsss/nsss-switch.h>
#include "nsss-switch-internal.h"
int nsss_switch_pwd_get (nsss_switch_t *a, struct passwd *pw, stralloc *sa, tain const *deadline, tain *stamp)
{
unsigned char c = NSSS_SWITCH_PWD_GET ;
- if (!ipc_timed_send(buffer_fd(&a->b), (char *)&c, 1, deadline, stamp)) return 0 ;
+ if (!nsss_switch_send(a, (char *)&c, 1, deadline, stamp)) return 0 ;
if (!buffer_timed_get(&a->b, (char *)&c, 1, deadline, stamp)) return 0 ;
if (c == 255) return 0 ;
if (c) return (errno = c, 0) ;
diff --git a/src/libnsss/nsss_switch_pwd_getbyname.c b/src/libnsss/nsss_switch_pwd_getbyname.c
index eea9923..b360c4e 100644
--- a/src/libnsss/nsss_switch_pwd_getbyname.c
+++ b/src/libnsss/nsss_switch_pwd_getbyname.c
@@ -3,9 +3,10 @@
#include <string.h>
#include <sys/uio.h>
#include <errno.h>
+
#include <skalibs/uint32.h>
-#include <skalibs/buffer.h>
#include <skalibs/unix-timed.h>
+
#include <nsss/nsss-switch.h>
#include "nsss-switch-internal.h"
@@ -16,7 +17,7 @@ int nsss_switch_pwd_getbyname (nsss_switch_t *a, struct passwd *pw, stralloc *sa
struct iovec v[2] = { { .iov_base = buf, .iov_len = 5 }, { .iov_base = (char *)name, .iov_len = len + 1 } } ;
if (len > NSSS_SWITCH_NAME_MAXLEN - 1) return (errno = EINVAL, 0) ;
uint32_pack_big(buf + 1, len + 1) ;
- if (!ipc_timed_sendv(buffer_fd(&a->b), v, 2, deadline, stamp)) return 0 ;
+ if (!nsss_switch_sendv(a, v, 2, deadline, stamp)) return 0 ;
if (!buffer_timed_get(&a->b, &buf[0], 1, deadline, stamp)) return 0 ;
if ((unsigned char)buf[0] == 255) return 0 ;
if (buf[0]) return (errno = (unsigned char)buf[0], 0) ;
diff --git a/src/libnsss/nsss_switch_pwd_getbyuid.c b/src/libnsss/nsss_switch_pwd_getbyuid.c
index e5b5c8a..2b3d52f 100644
--- a/src/libnsss/nsss_switch_pwd_getbyuid.c
+++ b/src/libnsss/nsss_switch_pwd_getbyuid.c
@@ -1,9 +1,10 @@
/* ISC license. */
#include <errno.h>
+
#include <skalibs/uint32.h>
-#include <skalibs/buffer.h>
#include <skalibs/unix-timed.h>
+
#include <nsss/nsss-switch.h>
#include "nsss-switch-internal.h"
@@ -11,7 +12,7 @@ int nsss_switch_pwd_getbyuid (nsss_switch_t *a, struct passwd *pw, stralloc *sa,
{
char buf[5] = { NSSS_SWITCH_PWD_GETBYUID } ;
uint32_pack_big(buf + 1, uid) ;
- if (!ipc_timed_send(buffer_fd(&a->b), buf, 5, deadline, stamp)) return 0 ;
+ if (!nsss_switch_send(a, buf, 5, deadline, stamp)) return 0 ;
if (!buffer_timed_get(&a->b, &buf[0], 1, deadline, stamp)) return 0 ;
if ((unsigned char)buf[0] == 255) return 0 ;
if (buf[0]) return (errno = (unsigned char)buf[0], 0) ;
diff --git a/src/libnsss/nsss_switch_here.c b/src/libnsss/nsss_switch_query.c
index 994974b..523d4ce 100644
--- a/src/libnsss/nsss_switch_here.c
+++ b/src/libnsss/nsss_switch_query.c
@@ -1,6 +1,8 @@
/* ISC license. */
+#include <pthread.h>
+
#include <nsss/nsss-switch.h>
#include "nsss-switch-internal.h"
-nsss_switch_t nsss_switch_here = NSSS_SWITCH_ZERO ;
+nsss_switch_t nsss_switch_query = NSSS_SWITCH_ZERO ;
diff --git a/src/libnsss/nsss_switch_query_mutex.c b/src/libnsss/nsss_switch_query_mutex.c
new file mode 100644
index 0000000..549f42b
--- /dev/null
+++ b/src/libnsss/nsss_switch_query_mutex.c
@@ -0,0 +1,7 @@
+/* ISC license. */
+
+#include <pthread.h>
+
+#include "nsss-switch-internal.h"
+
+pthread_mutex_t nsss_switch_query_mutex = PTHREAD_MUTEX_INITIALIZER ;
diff --git a/src/libnsss/nsss_switch_query_start.c b/src/libnsss/nsss_switch_query_start.c
new file mode 100644
index 0000000..007fa90
--- /dev/null
+++ b/src/libnsss/nsss_switch_query_start.c
@@ -0,0 +1,12 @@
+/* ISC license. */
+
+#include <nsss/nsss-switch.h>
+#include "nsss-switch-internal.h"
+
+int nsss_switch_query_start (char const *path, unsigned int what, unsigned int timeout, tain const *deadline, tain *stamp)
+{
+ unsigned int held = nsss_switch_query.held ;
+ if (!nsss_switch_start(&nsss_switch_query, what, path, deadline, stamp)) return 0 ;
+ if (!held && !nsss_switch_set_timeout(&nsss_switch_query, timeout, deadline, stamp)) return 0 ;
+ return 1 ;
+}
diff --git a/src/libnsss/nsss_switch_send.c b/src/libnsss/nsss_switch_send.c
new file mode 100644
index 0000000..ecef1f4
--- /dev/null
+++ b/src/libnsss/nsss_switch_send.c
@@ -0,0 +1,25 @@
+/* ISC license. */
+
+#include <errno.h>
+
+#include <skalibs/buffer.h>
+#include <skalibs/unix-timed.h>
+
+#include <nsss/nsss-switch.h>
+#include "nsss-switch-internal.h"
+
+int nsss_switch_send (nsss_switch_t *a, char const *s, size_t len, tain const *deadline, tain *stamp)
+{
+ if (!ipc_timed_send(buffer_fd(&a->b), s, len, deadline, stamp))
+ {
+ unsigned int what ;
+ char const *path ;
+ if (errno != ECONNRESET || !a->path) return 0 ;
+ what = a->held ;
+ path = a->path ;
+ nsss_switch_end(a, what) ;
+ if (!nsss_switch_start(a, what, path, deadline, stamp)) return 0 ;
+ if (!ipc_timed_send(buffer_fd(&a->b), s, len, deadline, stamp)) return 0 ;
+ }
+ return 1 ;
+}
diff --git a/src/libnsss/nsss_switch_sendv.c b/src/libnsss/nsss_switch_sendv.c
new file mode 100644
index 0000000..2590686
--- /dev/null
+++ b/src/libnsss/nsss_switch_sendv.c
@@ -0,0 +1,25 @@
+/* ISC license. */
+
+#include <errno.h>
+
+#include <skalibs/buffer.h>
+#include <skalibs/unix-timed.h>
+
+#include <nsss/nsss-switch.h>
+#include "nsss-switch-internal.h"
+
+int nsss_switch_sendv (nsss_switch_t *a, struct iovec const *v, unsigned int n, tain const *deadline, tain *stamp)
+{
+ if (!ipc_timed_sendv(buffer_fd(&a->b), v, n, deadline, stamp))
+ {
+ unsigned int what ;
+ char const *path ;
+ if (errno != ECONNRESET || !a->path) return 0 ;
+ what = a->held ;
+ path = a->path ;
+ nsss_switch_end(a, what) ;
+ if (!nsss_switch_start(a, what, path, deadline, stamp)) return 0 ;
+ if (!ipc_timed_sendv(buffer_fd(&a->b), v, n, deadline, stamp)) return 0 ;
+ }
+ return 1 ;
+}
diff --git a/src/libnsss/nsss_switch_set_timeout.c b/src/libnsss/nsss_switch_set_timeout.c
new file mode 100644
index 0000000..ce037db
--- /dev/null
+++ b/src/libnsss/nsss_switch_set_timeout.c
@@ -0,0 +1,21 @@
+/* ISC license. */
+
+#include <stdint.h>
+#include <errno.h>
+
+#include <skalibs/uint32.h>
+#include <skalibs/unix-timed.h>
+
+#include <nsss/nsss-switch.h>
+#include "nsss-switch-internal.h"
+
+int nsss_switch_set_timeout (nsss_switch_t *a, unsigned int t, tain const *deadline, tain *stamp)
+{
+ char buf[5] = { NSSS_SWITCH_SET_TIMEOUT } ;
+ uint32_pack_big(buf + 1, (uint32_t)t) ;
+ if (!nsss_switch_send(a, buf, 5, deadline, stamp)) return 0 ;
+ if (!buffer_timed_get(&a->b, &buf[0], 1, deadline, stamp)) return 0 ;
+ if ((unsigned char)buf[0] == 255) return 0 ;
+ if (buf[0]) return (errno = (unsigned char)buf[0], 0) ;
+ return 1 ;
+}
diff --git a/src/libnsss/nsss_switch_setgrent.c b/src/libnsss/nsss_switch_setgrent.c
index a930568..81bc35c 100644
--- a/src/libnsss/nsss_switch_setgrent.c
+++ b/src/libnsss/nsss_switch_setgrent.c
@@ -7,6 +7,6 @@
void nsss_switch_setgrent (void)
{
- if (!nsss_switch_start(&nsss_switch_here, NSSS_SWITCH_GRP, NSSS_NSSSD_PATH, 0, 0)) return ;
- nsss_switch_grp_rewind(&nsss_switch_here, 0, 0) ;
+ if (!nsss_switch_start(&nsss_switch_enumerator, NSSS_SWITCH_GRP, NSSS_NSSSD_PATH, 0, 0)) return ;
+ nsss_switch_grp_rewind(&nsss_switch_enumerator, 0, 0) ;
}
diff --git a/src/libnsss/nsss_switch_setpwent.c b/src/libnsss/nsss_switch_setpwent.c
index 371423e..5b21f21 100644
--- a/src/libnsss/nsss_switch_setpwent.c
+++ b/src/libnsss/nsss_switch_setpwent.c
@@ -7,6 +7,6 @@
void nsss_switch_setpwent (void)
{
- if (!nsss_switch_start(&nsss_switch_here, NSSS_SWITCH_PWD, NSSS_NSSSD_PATH, 0, 0)) return ;
- nsss_switch_pwd_rewind(&nsss_switch_here, 0, 0) ;
+ if (!nsss_switch_start(&nsss_switch_enumerator, NSSS_SWITCH_PWD, NSSS_NSSSD_PATH, 0, 0)) return ;
+ nsss_switch_pwd_rewind(&nsss_switch_enumerator, 0, 0) ;
}
diff --git a/src/libnsss/nsss_switch_setspent.c b/src/libnsss/nsss_switch_setspent.c
index 5f5ed8a..fce844c 100644
--- a/src/libnsss/nsss_switch_setspent.c
+++ b/src/libnsss/nsss_switch_setspent.c
@@ -7,6 +7,6 @@
void nsss_switch_setspent (void)
{
- if (!nsss_switch_start(&nsss_switch_here, NSSS_SWITCH_SHADOW, NSSS_NSSSD_PATH, 0, 0)) return ;
- nsss_switch_shadow_rewind(&nsss_switch_here, 0, 0) ;
+ if (!nsss_switch_start(&nsss_switch_enumerator, NSSS_SWITCH_SHADOW, NSSS_NSSSD_PATH, 0, 0)) return ;
+ nsss_switch_shadow_rewind(&nsss_switch_enumerator, 0, 0) ;
}
diff --git a/src/libnsss/nsss_switch_shadow_get.c b/src/libnsss/nsss_switch_shadow_get.c
index a2fc431..4c0a722 100644
--- a/src/libnsss/nsss_switch_shadow_get.c
+++ b/src/libnsss/nsss_switch_shadow_get.c
@@ -1,15 +1,16 @@
/* ISC license. */
#include <errno.h>
-#include <skalibs/buffer.h>
+
#include <skalibs/unix-timed.h>
+
#include <nsss/nsss-switch.h>
#include "nsss-switch-internal.h"
int nsss_switch_shadow_get (nsss_switch_t *a, struct spwd *sp, stralloc *sa, tain const *deadline, tain *stamp)
{
unsigned char c = NSSS_SWITCH_SHADOW_GET ;
- if (!ipc_timed_send(buffer_fd(&a->b), (char *)&c, 1, deadline, stamp)) return 0 ;
+ if (!nsss_switch_send(a, (char *)&c, 1, deadline, stamp)) return 0 ;
if (!buffer_timed_get(&a->b, (char *)&c, 1, deadline, stamp)) return 0 ;
if (c == 255) return 0 ;
if (c) return (errno = c, 0) ;
diff --git a/src/libnsss/nsss_switch_shadow_getbyname.c b/src/libnsss/nsss_switch_shadow_getbyname.c
index d5cf57a..4d2911f 100644
--- a/src/libnsss/nsss_switch_shadow_getbyname.c
+++ b/src/libnsss/nsss_switch_shadow_getbyname.c
@@ -3,9 +3,10 @@
#include <string.h>
#include <sys/uio.h>
#include <errno.h>
+
#include <skalibs/uint32.h>
-#include <skalibs/buffer.h>
#include <skalibs/unix-timed.h>
+
#include <nsss/nsss-switch.h>
#include "nsss-switch-internal.h"
@@ -16,7 +17,7 @@ int nsss_switch_shadow_getbyname (nsss_switch_t *a, struct spwd *sp, stralloc *s
struct iovec v[2] = { { .iov_base = buf, .iov_len = 5 }, { .iov_base = (char *)name, .iov_len = len + 1 } } ;
if (len > NSSS_SWITCH_NAME_MAXLEN - 1) return (errno = EINVAL, 0) ;
uint32_pack_big(buf + 1, len + 1) ;
- if (!ipc_timed_sendv(buffer_fd(&a->b), v, 2, deadline, stamp)) return 0 ;
+ if (!nsss_switch_sendv(a, v, 2, deadline, stamp)) return 0 ;
if (!buffer_timed_get(&a->b, &buf[0], 1, deadline, stamp)) return 0 ;
if ((unsigned char)buf[0] == 255) return 0 ;
if (buf[0]) return (errno = (unsigned char)buf[0], 0) ;
diff --git a/src/libnsss/nsss_switch_start.c b/src/libnsss/nsss_switch_start.c
index 220a7e2..ba014ae 100644
--- a/src/libnsss/nsss_switch_start.c
+++ b/src/libnsss/nsss_switch_start.c
@@ -22,6 +22,7 @@ static inline int nsss_switch_connect (nsss_switch_t *a, char const *path, tain
int nsss_switch_start (nsss_switch_t *a, unsigned int what, char const *path, tain const *deadline, tain *stamp)
{
if (!a->held && !nsss_switch_connect(a, path, deadline, stamp)) return 0 ;
- a->held |= (1U << what) ;
+ a->held |= what & 0x7u ;
+ a->path = path ;
return 1 ;
}
diff --git a/src/libnsss/nsss_switch_startf.c b/src/libnsss/nsss_switch_startf.c
new file mode 100644
index 0000000..faabd1f
--- /dev/null
+++ b/src/libnsss/nsss_switch_startf.c
@@ -0,0 +1,26 @@
+/* ISC license. */
+
+#include <sys/types.h>
+
+#include <skalibs/posixplz.h>
+#include <skalibs/buffer.h>
+#include <skalibs/djbunix.h>
+
+#include <nsss/nsss-switch.h>
+
+static inline pid_t nsss_switch_spawn (nsss_switch_t *a, char const *const *argv, tain const *deadline, tain *stamp)
+{
+ int fd ;
+ pid_t pid = child_spawn1_socket(argv[0], argv, (char const *const *)environ, &fd) ;
+ if (!pid) return 0 ;
+ buffer_init(&a->b, &buffer_read, fd, a->buf, NSSS_SWITCH_BUFSIZE) ;
+ return pid ;
+}
+
+int nsss_switch_startf (nsss_switch_t *a, unsigned int what, char const *const *argv, tain const *deadline, tain *stamp)
+{
+ if (!a->held && !nsss_switch_spawn(a, argv, deadline, stamp)) return 0 ;
+ a->held |= what & 0x7u ;
+ a->path = 0 ;
+ return 1 ;
+}