[SCM] NSS Wrapper Repository - branch master updated
Andreas Schneider
asn at samba.org
Wed May 31 13:34:25 UTC 2017
The branch, master has been updated
via 7523b05 testsuite: Add compatibility for musl-libc 1.1
via 09bb07c nwrap: Add compatibility for musl-libc 1.1
via bba5eec nwrap: Add a comment to the pthread_atfork() call
via 2b80c4c nwrap: Use a constructor to initialize pthread and nwrap
via 52490af cmake: Check for contructor attribute support
via 4b7e685 nwrap: Add NULL checks for destructor
from d66ce39 nss_wrapper: Use perl via "env"
https://git.samba.org/?p=nss_wrapper.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit 7523b05f0e84e8d9a1c27c06805d0ba72ec33373
Author: Dennis Schridde <dennis.schridde at uni-heidelberg.de>
Date: Wed Jan 25 22:25:24 2017 +0100
testsuite: Add compatibility for musl-libc 1.1
The major difference is that getpwent_r and getgrent_r do not exist in
musl-libc. The testsuite was adapted to skip these tests if the
functions themselves are missing.
Signed-Off-By: Dennis Schridde <dennis.schridde at uni-heidelberg.de>
Reviewed-by: Andreas Schneider <asn at samba.org>
Reviewed-by: Michael Adam <obnox at samba.org>
commit 09bb07c4aec3da9d555d0a608b2c98dde46ff886
Author: Dennis Schridde <dennis.schridde at uni-heidelberg.de>
Date: Mon Mar 27 16:26:11 2017 +0200
nwrap: Add compatibility for musl-libc 1.1
The major difference is that getpwent_r and getgrent_r do not exist in
musl-libc. Hence it is sufficient to compile the wrappers for those only
conditionally.
Tested with musl-libc 1.1.15-r5 on Alpine Linux 3.5. Also confirmed to
not break with GNU libc 2.24-8 on Debian "Stretch" / 9.
Signed-Off-By: Dennis Schridde <dennis.schridde at uni-heidelberg.de>
Reviewed-by: Andreas Schneider <asn at samba.org>
Reviewed-by: Michael Adam <obnox at samba.org>
commit bba5eecf377b2617dfa25f78bcc11a240c3f5266
Author: Andreas Schneider <asn at samba.org>
Date: Wed May 31 15:25:30 2017 +0200
nwrap: Add a comment to the pthread_atfork() call
Signed-off-by: Andreas Schneider <asn at samba.org>
Reviewed-by: Michael Adam <obnox at samba.org>
commit 2b80c4ce0be8a43fb6ea6abcd4f97105982e239a
Author: Andreas Schneider <asn at samba.org>
Date: Mon Mar 27 16:23:08 2017 +0200
nwrap: Use a constructor to initialize pthread and nwrap
Signed-off-by: Andreas Schneider <asn at samba.org>
Reviewed-by: Michael Adam <obnox at samba.org>
commit 52490af39c319a107fc04c99ee35ddd80a82ce67
Author: Andreas Schneider <asn at samba.org>
Date: Mon Mar 27 16:22:45 2017 +0200
cmake: Check for contructor attribute support
Signed-off-by: Andreas Schneider <asn at samba.org>
Reviewed-by: Michael Adam <obnox at samba.org>
commit 4b7e685ef79d3a993ac4da20b1cca328c9354ee8
Author: Andreas Schneider <asn at samba.org>
Date: Mon Mar 27 16:38:53 2017 +0200
nwrap: Add NULL checks for destructor
If we call init early and leave early they are not filled.
Signed-off-by: Andreas Schneider <asn at samba.org>
Reviewed-by: Michael Adam <obnox at samba.org>
-----------------------------------------------------------------------
Summary of changes:
ConfigureChecks.cmake | 12 ++++++
config.h.cmake | 1 +
src/nss_wrapper.c | 115 +++++++++++++++++++++++++++++++++-----------------
tests/testsuite.c | 18 +++++---
4 files changed, 102 insertions(+), 44 deletions(-)
Changeset truncated at 500 lines:
diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake
index 462b166..6f760e6 100644
--- a/ConfigureChecks.cmake
+++ b/ConfigureChecks.cmake
@@ -235,6 +235,18 @@ int main(void) {
}" HAVE_ATTRIBUTE_PRINTF_FORMAT)
check_c_source_compiles("
+void test_constructor_attribute(void) __attribute__ ((constructor));
+
+void test_constructor_attribute(void)
+{
+ return;
+}
+
+int main(void) {
+ return 0;
+}" HAVE_CONSTRUCTOR_ATTRIBUTE)
+
+check_c_source_compiles("
void test_destructor_attribute(void) __attribute__ ((destructor));
void test_destructor_attribute(void)
diff --git a/config.h.cmake b/config.h.cmake
index 75c92ed..b18dff2 100644
--- a/config.h.cmake
+++ b/config.h.cmake
@@ -93,6 +93,7 @@
#cmakedefine HAVE_IPV6 1
#cmakedefine HAVE_ATTRIBUTE_PRINTF_FORMAT 1
+#cmakedefine HAVE_CONSTRUCTOR_ATTRIBUTE 1
#cmakedefine HAVE_DESTRUCTOR_ATTRIBUTE 1
/*************************** ENDIAN *****************************/
diff --git a/src/nss_wrapper.c b/src/nss_wrapper.c
index 82581b1..70a5989 100644
--- a/src/nss_wrapper.c
+++ b/src/nss_wrapper.c
@@ -142,6 +142,12 @@ typedef nss_status_t NSS_STATUS;
#define PRINTF_ATTRIBUTE(a,b)
#endif /* HAVE_ATTRIBUTE_PRINTF_FORMAT */
+#ifdef HAVE_CONSTRUCTOR_ATTRIBUTE
+#define CONSTRUCTOR_ATTRIBUTE __attribute__ ((constructor))
+#else
+#define CONSTRUCTOR_ATTRIBUTE
+#endif /* HAVE_CONSTRUCTOR_ATTRIBUTE */
+
#ifdef HAVE_DESTRUCTOR_ATTRIBUTE
#define DESTRUCTOR_ATTRIBUTE __attribute__ ((destructor))
#else
@@ -292,11 +298,13 @@ struct nwrap_libc_fns {
int (*_libc_getpwuid_r)(uid_t uid, struct passwd *pwd, char *buf, size_t buflen, struct passwd **result);
void (*_libc_setpwent)(void);
struct passwd *(*_libc_getpwent)(void);
-#ifdef HAVE_SOLARIS_GETPWENT_R
+#ifdef HAVE_GETPWENT_R
+# ifdef HAVE_SOLARIS_GETPWENT_R
struct passwd *(*_libc_getpwent_r)(struct passwd *pwbuf, char *buf, size_t buflen);
-#else
+# else /* HAVE_SOLARIS_GETPWENT_R */
int (*_libc_getpwent_r)(struct passwd *pwbuf, char *buf, size_t buflen, struct passwd **pwbufp);
-#endif
+# endif /* HAVE_SOLARIS_GETPWENT_R */
+#endif /* HAVE_GETPWENT_R */
void (*_libc_endpwent)(void);
int (*_libc_initgroups)(const char *user, gid_t gid);
struct group *(*_libc_getgrnam)(const char *name);
@@ -305,11 +313,13 @@ struct nwrap_libc_fns {
int (*_libc_getgrgid_r)(gid_t gid, struct group *grp, char *buf, size_t buflen, struct group **result);
void (*_libc_setgrent)(void);
struct group *(*_libc_getgrent)(void);
-#ifdef HAVE_SOLARIS_GETGRENT_R
+#ifdef HAVE_GETGRENT_R
+# ifdef HAVE_SOLARIS_GETGRENT_R
struct group *(*_libc_getgrent_r)(struct group *group, char *buf, size_t buflen);
-#else
+# else /* HAVE_SOLARIS_GETGRENT_R */
int (*_libc_getgrent_r)(struct group *group, char *buf, size_t buflen, struct group **result);
-#endif
+# endif /* HAVE_SOLARIS_GETGRENT_R */
+#endif /* HAVE_GETGRENT_R */
void (*_libc_endgrent)(void);
int (*_libc_getgrouplist)(const char *user, gid_t group, gid_t *groups, int *ngroups);
@@ -796,6 +806,7 @@ static struct nwrap_he nwrap_he_global;
static void nwrap_init(void);
static bool nwrap_gr_parse_line(struct nwrap_cache *nwrap, char *line);
static void nwrap_gr_unload(struct nwrap_cache *nwrap);
+void nwrap_constructor(void) CONSTRUCTOR_ATTRIBUTE;
void nwrap_destructor(void) DESTRUCTOR_ATTRIBUTE;
/*********************************************************
@@ -1066,7 +1077,8 @@ static struct passwd *libc_getpwent(void)
return nwrap_main_global->libc->fns->_libc_getpwent();
}
-#ifdef HAVE_SOLARIS_GETPWENT_R
+#ifdef HAVE_GETPWENT_R
+# ifdef HAVE_SOLARIS_GETPWENT_R
static struct passwd *libc_getpwent_r(struct passwd *pwdst,
char *buf,
int buflen)
@@ -1077,7 +1089,7 @@ static struct passwd *libc_getpwent_r(struct passwd *pwdst,
buf,
buflen);
}
-#else /* HAVE_SOLARIS_GETPWENT_R */
+# else /* HAVE_SOLARIS_GETPWENT_R */
static int libc_getpwent_r(struct passwd *pwdst,
char *buf,
size_t buflen,
@@ -1090,7 +1102,8 @@ static int libc_getpwent_r(struct passwd *pwdst,
buflen,
pwdstp);
}
-#endif /* HAVE_SOLARIS_GETPWENT_R */
+# endif /* HAVE_SOLARIS_GETPWENT_R */
+#endif /* HAVE_GETPWENT_R */
static void libc_endpwent(void)
{
@@ -1183,7 +1196,7 @@ static struct group *libc_getgrent(void)
}
#ifdef HAVE_GETGRENT_R
-#ifdef HAVE_SOLARIS_GETGRENT_R
+# ifdef HAVE_SOLARIS_GETGRENT_R
static struct group *libc_getgrent_r(struct group *group,
char *buf,
size_t buflen)
@@ -1194,7 +1207,7 @@ static struct group *libc_getgrent_r(struct group *group,
buf,
buflen);
}
-#else /* !HAVE_SOLARIS_GETGRENT_R */
+# else /* HAVE_SOLARIS_GETGRENT_R */
static int libc_getgrent_r(struct group *group,
char *buf,
size_t buflen,
@@ -1207,7 +1220,7 @@ static int libc_getgrent_r(struct group *group,
buflen,
result);
}
-#endif /* HAVE_SOLARIS_GETGRENT_R */
+# endif /* HAVE_SOLARIS_GETGRENT_R */
#endif /* HAVE_GETGRENT_R */
static void libc_endgrent(void)
@@ -1561,10 +1574,6 @@ static void nwrap_init(void)
nwrap_initialized = true;
- /* Initialize pthread_atfork handlers */
- pthread_atfork(&nwrap_thread_prepare, &nwrap_thread_parent,
- &nwrap_thread_child);
-
env = getenv("NSS_WRAPPER_MAX_HOSTENTS");
if (env != NULL) {
max_hostents_tmp = (size_t)strtol(env, &endptr, 10);
@@ -4420,6 +4429,7 @@ struct passwd *getpwent(void)
* GETPWENT_R
***************************************************************************/
+#ifdef HAVE_GETPWENT_R
static int nwrap_getpwent_r(struct passwd *pwdst, char *buf,
size_t buflen, struct passwd **pwdstp)
{
@@ -4437,7 +4447,7 @@ static int nwrap_getpwent_r(struct passwd *pwdst, char *buf,
return ENOENT;
}
-#ifdef HAVE_SOLARIS_GETPWENT_R
+# ifdef HAVE_SOLARIS_GETPWENT_R
struct passwd *getpwent_r(struct passwd *pwdst, char *buf, int buflen)
{
struct passwd *pwdstp = NULL;
@@ -4453,7 +4463,7 @@ struct passwd *getpwent_r(struct passwd *pwdst, char *buf, int buflen)
return pwdstp;
}
-#else /* HAVE_SOLARIS_GETPWENT_R */
+# else /* HAVE_SOLARIS_GETPWENT_R */
int getpwent_r(struct passwd *pwdst, char *buf,
size_t buflen, struct passwd **pwdstp)
{
@@ -4463,7 +4473,8 @@ int getpwent_r(struct passwd *pwdst, char *buf,
return nwrap_getpwent_r(pwdst, buf, buflen, pwdstp);
}
-#endif /* HAVE_SOLARIS_GETPWENT_R */
+# endif /* HAVE_SOLARIS_GETPWENT_R */
+#endif /* HAVE_GETPWENT_R */
/****************************************************************************
* ENDPWENT
@@ -4726,6 +4737,7 @@ struct group *getgrent(void)
* GETGRENT_R
***************************************************************************/
+#ifdef HAVE_GETGRENT_R
static int nwrap_getgrent_r(struct group *grdst, char *buf,
size_t buflen, struct group **grdstp)
{
@@ -4743,7 +4755,7 @@ static int nwrap_getgrent_r(struct group *grdst, char *buf,
return ENOENT;
}
-#ifdef HAVE_SOLARIS_GETGRENT_R
+# ifdef HAVE_SOLARIS_GETGRENT_R
struct group *getgrent_r(struct group *src, char *buf, int buflen)
{
struct group *grdstp = NULL;
@@ -4760,7 +4772,7 @@ struct group *getgrent_r(struct group *src, char *buf, int buflen)
return grdstp;
}
-#else /* HAVE_SOLARIS_GETGRENT_R */
+# else /* HAVE_SOLARIS_GETGRENT_R */
int getgrent_r(struct group *src, char *buf,
size_t buflen, struct group **grdstp)
{
@@ -4770,7 +4782,8 @@ int getgrent_r(struct group *src, char *buf,
return nwrap_getgrent_r(src, buf, buflen, grdstp);
}
-#endif /* HAVE_SOLARIS_GETGRENT_R */
+# endif /* HAVE_SOLARIS_GETGRENT_R */
+#endif /* HAVE_GETGRENT_R */
/****************************************************************************
* ENDGRENT
@@ -5530,6 +5543,28 @@ int gethostname(char *name, size_t len)
}
/****************************
+ * CONSTRUCTOR
+ ***************************/
+void nwrap_constructor(void)
+{
+ /*
+ * If we hold a lock and the application forks, then the child
+ * is not able to unlock the mutex and we are in a deadlock.
+ *
+ * Setting these handlers should prevent such deadlocks.
+ */
+ pthread_atfork(&nwrap_thread_prepare,
+ &nwrap_thread_parent,
+ &nwrap_thread_child);
+
+ /*
+ * Here is safe place to call nwrap_init() and initialize data
+ * for the main process.
+ */
+ nwrap_init();
+}
+
+/****************************
* DESTRUCTOR
***************************/
@@ -5546,28 +5581,32 @@ void nwrap_destructor(void)
struct nwrap_main *m = nwrap_main_global;
/* libc */
- SAFE_FREE(m->libc->fns);
- if (m->libc->handle != NULL) {
- dlclose(m->libc->handle);
- }
- if (m->libc->nsl_handle != NULL) {
- dlclose(m->libc->nsl_handle);
- }
- if (m->libc->sock_handle != NULL) {
- dlclose(m->libc->sock_handle);
+ if (m->libc != NULL) {
+ SAFE_FREE(m->libc->fns);
+ if (m->libc->handle != NULL) {
+ dlclose(m->libc->handle);
+ }
+ if (m->libc->nsl_handle != NULL) {
+ dlclose(m->libc->nsl_handle);
+ }
+ if (m->libc->sock_handle != NULL) {
+ dlclose(m->libc->sock_handle);
+ }
+ SAFE_FREE(m->libc);
}
- SAFE_FREE(m->libc);
/* backends */
- for (i = 0; i < m->num_backends; i++) {
- struct nwrap_backend *b = &(m->backends[i]);
+ if (m->backends != NULL) {
+ for (i = 0; i < m->num_backends; i++) {
+ struct nwrap_backend *b = &(m->backends[i]);
- if (b->so_handle != NULL) {
- dlclose(b->so_handle);
+ if (b->so_handle != NULL) {
+ dlclose(b->so_handle);
+ }
+ SAFE_FREE(b->fns);
}
- SAFE_FREE(b->fns);
+ SAFE_FREE(m->backends);
}
- SAFE_FREE(m->backends);
}
if (nwrap_pw_global.cache != NULL) {
diff --git a/tests/testsuite.c b/tests/testsuite.c
index dccdb97..6a9f4d1 100644
--- a/tests/testsuite.c
+++ b/tests/testsuite.c
@@ -433,9 +433,11 @@ static bool test_nwrap_enum_passwd(struct passwd **pwd_array_p,
static bool test_nwrap_enum_r_passwd(struct passwd **pwd_array_p,
size_t *num_pwd_p)
{
- struct passwd pwd, *pwdp;
struct passwd *pwd_array = NULL;
size_t num_pwd = 0;
+/* Skip these tests if the platform does not provide getpwent_r() */
+#ifdef HAVE_GETPWENT_R
+ struct passwd pwd, *pwdp;
char buffer[4096];
int ret;
@@ -450,7 +452,7 @@ static bool test_nwrap_enum_r_passwd(struct passwd **pwd_array_p,
if (pwdp == NULL) {
break;
}
-#else
+#else /* HAVE_SOLARIS_GETPWENT_R */
ret = getpwent_r(&pwd, buffer, sizeof(buffer), &pwdp);
if (ret != 0) {
if (ret != ENOENT) {
@@ -458,7 +460,7 @@ static bool test_nwrap_enum_r_passwd(struct passwd **pwd_array_p,
}
break;
}
-#endif
+#endif /* HAVE_SOLARIS_GETPWENT_R */
print_passwd(&pwd);
if (pwd_array_p && num_pwd_p) {
pwd_array = realloc(pwd_array, sizeof(struct passwd) * (num_pwd + 1));
@@ -470,6 +472,7 @@ static bool test_nwrap_enum_r_passwd(struct passwd **pwd_array_p,
DEBUG("Testing endpwent\n");
endpwent();
+#endif /* HAVE_GETPWENT_R */
if (pwd_array_p) {
*pwd_array_p = pwd_array;
@@ -598,9 +601,11 @@ static bool test_nwrap_enum_group(struct group **grp_array_p,
static bool test_nwrap_enum_r_group(struct group **grp_array_p,
size_t *num_grp_p)
{
- struct group grp, *grpp;
struct group *grp_array = NULL;
size_t num_grp = 0;
+/* Skip these tests if the platform does not provide getgrent_r() */
+#ifdef HAVE_GETGRENT_R
+ struct group grp, *grpp;
char buffer[4096];
int ret;
@@ -615,7 +620,7 @@ static bool test_nwrap_enum_r_group(struct group **grp_array_p,
if (grpp == NULL) {
break;
}
-#else
+#else /* HAVE_SOLARIS_GETGRENT_R */
ret = getgrent_r(&grp, buffer, sizeof(buffer), &grpp);
if (ret != 0) {
if (ret != ENOENT) {
@@ -623,7 +628,7 @@ static bool test_nwrap_enum_r_group(struct group **grp_array_p,
}
break;
}
-#endif
+#endif /* HAVE_SOLARIS_GETGRENT_R */
print_group(&grp);
if (grp_array_p && num_grp_p) {
grp_array = realloc(grp_array, sizeof(struct group) * (num_grp + 1));
@@ -635,6 +640,7 @@ static bool test_nwrap_enum_r_group(struct group **grp_array_p,
DEBUG("Testing endgrent\n");
endgrent();
+#endif /* HAVE_GETGRENT_R */
if (grp_array_p) {
*grp_array_p = grp_array;
--
NSS Wrapper Repository
More information about the samba-cvs
mailing list