From b163ab8008fb0280677f55c5e5b6e3fddb2e0254 Mon Sep 17 00:00:00 2001 From: Kai Blin Date: Thu, 14 Jun 2007 06:05:27 +0000 Subject: r23481: As per metze's suggestion, move the nsstest files from torture/ to nsswitch/ (This used to be commit 4e7dc9eae4a30f67a87dbf8ccfda7f6a3ace114d) --- source4/configure.ac | 2 +- source4/nsswitch/config.mk | 12 ++ source4/nsswitch/nsstest.c | 412 ++++++++++++++++++++++++++++++++++++++++++++ source4/nsswitch/nsstest.h | 116 +++++++++++++ source4/nsswitch/nsstest.m4 | 9 + source4/torture/config.mk | 12 -- source4/torture/nsstest.c | 412 -------------------------------------------- source4/torture/nsstest.h | 116 ------------- source4/torture/nsstest.m4 | 9 - 9 files changed, 550 insertions(+), 550 deletions(-) create mode 100644 source4/nsswitch/nsstest.c create mode 100644 source4/nsswitch/nsstest.h create mode 100644 source4/nsswitch/nsstest.m4 delete mode 100644 source4/torture/nsstest.c delete mode 100644 source4/torture/nsstest.h delete mode 100644 source4/torture/nsstest.m4 (limited to 'source4') diff --git a/source4/configure.ac b/source4/configure.ac index 4feb6debd4..c947a1629a 100644 --- a/source4/configure.ac +++ b/source4/configure.ac @@ -25,7 +25,7 @@ m4_include(lib/util/time.m4) m4_include(lib/popt/samba.m4) m4_include(lib/charset/config.m4) m4_include(lib/socket/config.m4) -m4_include(torture/nsstest.m4) +m4_include(nsswitch/nsstest.m4) #SMB_EXT_LIB_FROM_PKGCONFIG(LIBTALLOC, talloc >= 1.0, # [samba_cv_internal_talloc=no], diff --git a/source4/nsswitch/config.mk b/source4/nsswitch/config.mk index 9723964a4b..4123194c23 100644 --- a/source4/nsswitch/config.mk +++ b/source4/nsswitch/config.mk @@ -3,3 +3,15 @@ VERSION = 0.0.1 SO_VERSION = 0 DESCRIPTION = Client library for communicating with winbind OBJ_FILES = wb_common.o + +################################# +# Start BINARY nsstest +[BINARY::nsstest] +INSTALLDIR = BINDIR +OBJ_FILES = \ + nsstest.o +PRIVATE_DEPENDENCIES = \ + LIBSAMBA-UTIL \ + LIBREPLACE_EXT +# End BINARY nsstest +################################# diff --git a/source4/nsswitch/nsstest.c b/source4/nsswitch/nsstest.c new file mode 100644 index 0000000000..5a5af8e356 --- /dev/null +++ b/source4/nsswitch/nsstest.c @@ -0,0 +1,412 @@ +/* + Unix SMB/CIFS implementation. + nss tester for winbindd + Copyright (C) Andrew Tridgell 2001 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +#include "nsswitch/nsstest.h" + +static const char *so_path = "/lib/libnss_winbind.so"; +static const char *nss_name = "winbind"; +static int nss_errno; +static NSS_STATUS last_error; +static int total_errors; + +static void *find_fn(const char *name) +{ + char s[1024]; + static void *h; + void *res; + + snprintf(s,sizeof(s), "_nss_%s_%s", nss_name, name); + + if (!h) { + h = dlopen(so_path, RTLD_LAZY); + } + if (!h) { + printf("Can't open shared library %s\n", so_path); + exit(1); + } + res = dlsym(h, s); + if (!res) { + printf("Can't find function %s\n", s); + return NULL; + } + return res; +} + +static void report_nss_error(const char *who, NSS_STATUS status) +{ + last_error = status; + total_errors++; + printf("ERROR %s: NSS_STATUS=%d %d (nss_errno=%d)\n", + who, status, NSS_STATUS_SUCCESS, nss_errno); +} + +static struct passwd *nss_getpwent(void) +{ + NSS_STATUS (*_nss_getpwent_r)(struct passwd *, char *, + size_t , int *) = find_fn("getpwent_r"); + static struct passwd pwd; + static char buf[1000]; + NSS_STATUS status; + + status = _nss_getpwent_r(&pwd, buf, sizeof(buf), &nss_errno); + if (status == NSS_STATUS_NOTFOUND) { + return NULL; + } + if (status != NSS_STATUS_SUCCESS) { + report_nss_error("getpwent", status); + return NULL; + } + return &pwd; +} + +static struct passwd *nss_getpwnam(const char *name) +{ + NSS_STATUS (*_nss_getpwnam_r)(const char *, struct passwd *, char *, + size_t , int *) = find_fn("getpwnam_r"); + static struct passwd pwd; + static char buf[1000]; + NSS_STATUS status; + + status = _nss_getpwnam_r(name, &pwd, buf, sizeof(buf), &nss_errno); + if (status == NSS_STATUS_NOTFOUND) { + return NULL; + } + if (status != NSS_STATUS_SUCCESS) { + report_nss_error("getpwnam", status); + return NULL; + } + return &pwd; +} + +static struct passwd *nss_getpwuid(uid_t uid) +{ + NSS_STATUS (*_nss_getpwuid_r)(uid_t , struct passwd *, char *, + size_t , int *) = find_fn("getpwuid_r"); + static struct passwd pwd; + static char buf[1000]; + NSS_STATUS status; + + status = _nss_getpwuid_r(uid, &pwd, buf, sizeof(buf), &nss_errno); + if (status == NSS_STATUS_NOTFOUND) { + return NULL; + } + if (status != NSS_STATUS_SUCCESS) { + report_nss_error("getpwuid", status); + return NULL; + } + return &pwd; +} + +static void nss_setpwent(void) +{ + NSS_STATUS (*_nss_setpwent)(void) = find_fn("setpwent"); + NSS_STATUS status; + status = _nss_setpwent(); + if (status != NSS_STATUS_SUCCESS) { + report_nss_error("setpwent", status); + } +} + +static void nss_endpwent(void) +{ + NSS_STATUS (*_nss_endpwent)(void) = find_fn("endpwent"); + NSS_STATUS status; + status = _nss_endpwent(); + if (status != NSS_STATUS_SUCCESS) { + report_nss_error("endpwent", status); + } +} + + +static struct group *nss_getgrent(void) +{ + NSS_STATUS (*_nss_getgrent_r)(struct group *, char *, + size_t , int *) = find_fn("getgrent_r"); + static struct group grp; + static char *buf; + static int buflen = 1024; + NSS_STATUS status; + + if (!buf) buf = malloc(buflen); + +again: + status = _nss_getgrent_r(&grp, buf, buflen, &nss_errno); + if (status == NSS_STATUS_TRYAGAIN) { + buflen *= 2; + buf = realloc(buf, buflen); + goto again; + } + if (status == NSS_STATUS_NOTFOUND) { + return NULL; + } + if (status != NSS_STATUS_SUCCESS) { + report_nss_error("getgrent", status); + return NULL; + } + return &grp; +} + +static struct group *nss_getgrnam(const char *name) +{ + NSS_STATUS (*_nss_getgrnam_r)(const char *, struct group *, char *, + size_t , int *) = find_fn("getgrnam_r"); + static struct group grp; + static char *buf; + static int buflen = 1000; + NSS_STATUS status; + + if (!buf) buf = malloc(buflen); +again: + status = _nss_getgrnam_r(name, &grp, buf, buflen, &nss_errno); + if (status == NSS_STATUS_TRYAGAIN) { + buflen *= 2; + buf = realloc(buf, buflen); + goto again; + } + if (status == NSS_STATUS_NOTFOUND) { + return NULL; + } + if (status != NSS_STATUS_SUCCESS) { + report_nss_error("getgrnam", status); + return NULL; + } + return &grp; +} + +static struct group *nss_getgrgid(gid_t gid) +{ + NSS_STATUS (*_nss_getgrgid_r)(gid_t , struct group *, char *, + size_t , int *) = find_fn("getgrgid_r"); + static struct group grp; + static char *buf; + static int buflen = 1000; + NSS_STATUS status; + + if (!buf) buf = malloc(buflen); +again: + status = _nss_getgrgid_r(gid, &grp, buf, buflen, &nss_errno); + if (status == NSS_STATUS_TRYAGAIN) { + buflen *= 2; + buf = realloc(buf, buflen); + goto again; + } + if (status == NSS_STATUS_NOTFOUND) { + return NULL; + } + if (status != NSS_STATUS_SUCCESS) { + report_nss_error("getgrgid", status); + return NULL; + } + return &grp; +} + +static void nss_setgrent(void) +{ + NSS_STATUS (*_nss_setgrent)(void) = find_fn("setgrent"); + NSS_STATUS status; + status = _nss_setgrent(); + if (status != NSS_STATUS_SUCCESS) { + report_nss_error("setgrent", status); + } +} + +static void nss_endgrent(void) +{ + NSS_STATUS (*_nss_endgrent)(void) = find_fn("endgrent"); + NSS_STATUS status; + status = _nss_endgrent(); + if (status != NSS_STATUS_SUCCESS) { + report_nss_error("endgrent", status); + } +} + +static int nss_initgroups(char *user, gid_t group, gid_t **groups, long int *start, long int *size) +{ + NSS_STATUS (*_nss_initgroups)(char *, gid_t , long int *, + long int *, gid_t **, long int , int *) = + find_fn("initgroups_dyn"); + NSS_STATUS status; + + if (!_nss_initgroups) return NSS_STATUS_UNAVAIL; + + status = _nss_initgroups(user, group, start, size, groups, 0, &nss_errno); + if (status != NSS_STATUS_SUCCESS) { + report_nss_error("initgroups", status); + } + return status; +} + +static void print_passwd(struct passwd *pwd) +{ + printf("%s:%s:%d:%d:%s:%s:%s\n", + pwd->pw_name, + pwd->pw_passwd, + pwd->pw_uid, + pwd->pw_gid, + pwd->pw_gecos, + pwd->pw_dir, + pwd->pw_shell); +} + +static void print_group(struct group *grp) +{ + int i; + printf("%s:%s:%d: ", + grp->gr_name, + grp->gr_passwd, + grp->gr_gid); + + if (!grp->gr_mem[0]) { + printf("\n"); + return; + } + + for (i=0; grp->gr_mem[i+1]; i++) { + printf("%s, ", grp->gr_mem[i]); + } + printf("%s\n", grp->gr_mem[i]); +} + +static void nss_test_initgroups(char *name, gid_t gid) +{ + long int size = 16; + long int start = 1; + gid_t *groups = NULL; + int i; + NSS_STATUS status; + + groups = (gid_t *)malloc_array_p(gid_t, size); + groups[0] = gid; + + status = nss_initgroups(name, gid, &groups, &start, &size); + if (status == NSS_STATUS_UNAVAIL) { + printf("No initgroups fn\n"); + return; + } + + for (i=0; ipw_name); + printf("getpwent: "); print_passwd(pwd); + pwd = nss_getpwuid(pwd->pw_uid); + if (!pwd) { + total_errors++; + printf("ERROR: can't getpwuid\n"); + continue; + } + printf("getpwuid: "); print_passwd(pwd); + pwd = nss_getpwnam(pwd->pw_name); + if (!pwd) { + total_errors++; + printf("ERROR: can't getpwnam\n"); + continue; + } + printf("getpwnam: "); print_passwd(pwd); + printf("initgroups: "); nss_test_initgroups(pwd->pw_name, pwd->pw_gid); + printf("\n"); + } + nss_endpwent(); +} + +static void nss_test_groups(void) +{ + struct group *grp; + + nss_setgrent(); + /* loop over all groups */ + while ((grp = nss_getgrent())) { + printf("Testing group %s\n", grp->gr_name); + printf("getgrent: "); print_group(grp); + grp = nss_getgrnam(grp->gr_name); + if (!grp) { + total_errors++; + printf("ERROR: can't getgrnam\n"); + continue; + } + printf("getgrnam: "); print_group(grp); + grp = nss_getgrgid(grp->gr_gid); + if (!grp) { + total_errors++; + printf("ERROR: can't getgrgid\n"); + continue; + } + printf("getgrgid: "); print_group(grp); + printf("\n"); + } + nss_endgrent(); +} + +static void nss_test_errors(void) +{ + struct passwd *pwd; + struct group *grp; + + pwd = getpwnam("nosuchname"); + if (pwd || last_error != NSS_STATUS_NOTFOUND) { + total_errors++; + printf("ERROR Non existant user gave error %d\n", last_error); + } + + pwd = getpwuid(0xFFF0); + if (pwd || last_error != NSS_STATUS_NOTFOUND) { + total_errors++; + printf("ERROR Non existant uid gave error %d\n", last_error); + } + + grp = getgrnam("nosuchgroup"); + if (grp || last_error != NSS_STATUS_NOTFOUND) { + total_errors++; + printf("ERROR Non existant group gave error %d\n", last_error); + } + + grp = getgrgid(0xFFF0); + if (grp || last_error != NSS_STATUS_NOTFOUND) { + total_errors++; + printf("ERROR Non existant gid gave error %d\n", last_error); + } +} + + int main(int argc, char *argv[]) +{ + if (argc > 1) so_path = argv[1]; + if (argc > 2) nss_name = argv[2]; + + nss_test_users(); + nss_test_groups(); + nss_test_errors(); + + printf("total_errors=%d\n", total_errors); + + return total_errors; +} diff --git a/source4/nsswitch/nsstest.h b/source4/nsswitch/nsstest.h new file mode 100644 index 0000000000..4dddf473fc --- /dev/null +++ b/source4/nsswitch/nsstest.h @@ -0,0 +1,116 @@ +/* + Unix SMB/CIFS implementation. + nss includes for the nss tester + Copyright (C) Kai Blin 2007 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#ifndef _NSSTEST_H +#define _NSSTEST_H + +#include +#include + +#ifdef HAVE_NSS_COMMON_H + +/* + * Sun Solaris + */ + +#include +#include +#include + +typedef nss_status_t NSS_STATUS; + +#define NSS_STATUS_SUCCESS NSS_SUCCESS +#define NSS_STATUS_NOTFOUND NSS_NOTFOUND +#define NSS_STATUS_UNAVAIL NSS_UNAVAIL +#define NSS_STATUS_TRYAGAIN NSS_TRYAGAIN + +#elif HAVE_NSS_H + +/* + * Linux (glibc) + */ + +#include +typedef enum nss_status NSS_STATUS; + +#elif HAVE_NS_API_H + +/* + * SGI IRIX + */ + +#ifdef DATUM +#define _DATUM_DEFINED +#endif + +#include + +typedef enum +{ + NSS_STATUS_SUCCESS=NS_SUCCESS, + NSS_STATUS_NOTFOUND=NS_NOTFOUND, + NSS_STATUS_UNAVAIL=NS_UNAVAIL, + NSS_STATUS_TRYAGAIN=NS_TRYAGAIN +} NSS_STATUS; + +#define NSD_MEM_STATIC 0 +#define NSD_MEM_VOLATILE 1 +#define NSD_MEM_DYNAMIC 2 + +#elif defined(HPUX) && defined(HAVE_NSSWITCH_H) + +/* HP-UX 11 */ + +#include + +#define NSS_STATUS_SUCCESS NSS_SUCCESS +#define NSS_STATUS_NOTFOUND NSS_NOTFOUND +#define NSS_STATUS_UNAVAIL NSS_UNAVAIL +#define NSS_STATUS_TRYAGAIN NSS_TRYAGAIN + +#ifdef HAVE_SYNCH_H +#include +#endif +#ifdef HAVE_PTHREAD_H +#include +#endif + +typedef enum { + NSS_SUCCESS, + NSS_NOTFOUND, + NSS_UNAVAIL, + NSS_TRYAGAIN +} nss_status_t; + +typedef nss_status_t NSS_STATUS; + +#else /* Nothing's defined. Neither solaris nor gnu nor sun nor hp */ + +typedef enum +{ + NSS_STATUS_SUCCESS=0, + NSS_STATUS_NOTFOUND=1, + NSS_STATUS_UNAVAIL=2, + NSS_STATUS_TRYAGAIN=3 +} NSS_STATUS; + +#endif + +#endif /* _NSSTEST_H */ diff --git a/source4/nsswitch/nsstest.m4 b/source4/nsswitch/nsstest.m4 new file mode 100644 index 0000000000..2856f9de15 --- /dev/null +++ b/source4/nsswitch/nsstest.m4 @@ -0,0 +1,9 @@ +case "$host_os" in + *linux*) + SMB_ENABLE(nsstest,YES) + ;; + *) + SMB_ENABLE(nsstest,NO) + ;; +esac + diff --git a/source4/torture/config.mk b/source4/torture/config.mk index 6a825b01a8..42f1d72bb0 100644 --- a/source4/torture/config.mk +++ b/source4/torture/config.mk @@ -358,18 +358,6 @@ MANPAGE = man/locktest.1 # End BINARY locktest ################################# -################################# -# Start BINARY nsstest -[BINARY::nsstest] -INSTALLDIR = BINDIR -OBJ_FILES = \ - nsstest.o -PRIVATE_DEPENDENCIES = \ - LIBSAMBA-UTIL \ - LIBREPLACE_EXT -# End BINARY nsstest -################################# - GCOV_FLAGS = -ftest-coverage -fprofile-arcs GCOV_LIBS = -lgcov diff --git a/source4/torture/nsstest.c b/source4/torture/nsstest.c deleted file mode 100644 index 0fc2baf068..0000000000 --- a/source4/torture/nsstest.c +++ /dev/null @@ -1,412 +0,0 @@ -/* - Unix SMB/CIFS implementation. - nss tester for winbindd - Copyright (C) Andrew Tridgell 2001 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -*/ - -#include "includes.h" - -#include "torture/nsstest.h" - -static const char *so_path = "/lib/libnss_winbind.so"; -static const char *nss_name = "winbind"; -static int nss_errno; -static NSS_STATUS last_error; -static int total_errors; - -static void *find_fn(const char *name) -{ - char s[1024]; - static void *h; - void *res; - - snprintf(s,sizeof(s), "_nss_%s_%s", nss_name, name); - - if (!h) { - h = dlopen(so_path, RTLD_LAZY); - } - if (!h) { - printf("Can't open shared library %s\n", so_path); - exit(1); - } - res = dlsym(h, s); - if (!res) { - printf("Can't find function %s\n", s); - return NULL; - } - return res; -} - -static void report_nss_error(const char *who, NSS_STATUS status) -{ - last_error = status; - total_errors++; - printf("ERROR %s: NSS_STATUS=%d %d (nss_errno=%d)\n", - who, status, NSS_STATUS_SUCCESS, nss_errno); -} - -static struct passwd *nss_getpwent(void) -{ - NSS_STATUS (*_nss_getpwent_r)(struct passwd *, char *, - size_t , int *) = find_fn("getpwent_r"); - static struct passwd pwd; - static char buf[1000]; - NSS_STATUS status; - - status = _nss_getpwent_r(&pwd, buf, sizeof(buf), &nss_errno); - if (status == NSS_STATUS_NOTFOUND) { - return NULL; - } - if (status != NSS_STATUS_SUCCESS) { - report_nss_error("getpwent", status); - return NULL; - } - return &pwd; -} - -static struct passwd *nss_getpwnam(const char *name) -{ - NSS_STATUS (*_nss_getpwnam_r)(const char *, struct passwd *, char *, - size_t , int *) = find_fn("getpwnam_r"); - static struct passwd pwd; - static char buf[1000]; - NSS_STATUS status; - - status = _nss_getpwnam_r(name, &pwd, buf, sizeof(buf), &nss_errno); - if (status == NSS_STATUS_NOTFOUND) { - return NULL; - } - if (status != NSS_STATUS_SUCCESS) { - report_nss_error("getpwnam", status); - return NULL; - } - return &pwd; -} - -static struct passwd *nss_getpwuid(uid_t uid) -{ - NSS_STATUS (*_nss_getpwuid_r)(uid_t , struct passwd *, char *, - size_t , int *) = find_fn("getpwuid_r"); - static struct passwd pwd; - static char buf[1000]; - NSS_STATUS status; - - status = _nss_getpwuid_r(uid, &pwd, buf, sizeof(buf), &nss_errno); - if (status == NSS_STATUS_NOTFOUND) { - return NULL; - } - if (status != NSS_STATUS_SUCCESS) { - report_nss_error("getpwuid", status); - return NULL; - } - return &pwd; -} - -static void nss_setpwent(void) -{ - NSS_STATUS (*_nss_setpwent)(void) = find_fn("setpwent"); - NSS_STATUS status; - status = _nss_setpwent(); - if (status != NSS_STATUS_SUCCESS) { - report_nss_error("setpwent", status); - } -} - -static void nss_endpwent(void) -{ - NSS_STATUS (*_nss_endpwent)(void) = find_fn("endpwent"); - NSS_STATUS status; - status = _nss_endpwent(); - if (status != NSS_STATUS_SUCCESS) { - report_nss_error("endpwent", status); - } -} - - -static struct group *nss_getgrent(void) -{ - NSS_STATUS (*_nss_getgrent_r)(struct group *, char *, - size_t , int *) = find_fn("getgrent_r"); - static struct group grp; - static char *buf; - static int buflen = 1024; - NSS_STATUS status; - - if (!buf) buf = malloc(buflen); - -again: - status = _nss_getgrent_r(&grp, buf, buflen, &nss_errno); - if (status == NSS_STATUS_TRYAGAIN) { - buflen *= 2; - buf = realloc(buf, buflen); - goto again; - } - if (status == NSS_STATUS_NOTFOUND) { - return NULL; - } - if (status != NSS_STATUS_SUCCESS) { - report_nss_error("getgrent", status); - return NULL; - } - return &grp; -} - -static struct group *nss_getgrnam(const char *name) -{ - NSS_STATUS (*_nss_getgrnam_r)(const char *, struct group *, char *, - size_t , int *) = find_fn("getgrnam_r"); - static struct group grp; - static char *buf; - static int buflen = 1000; - NSS_STATUS status; - - if (!buf) buf = malloc(buflen); -again: - status = _nss_getgrnam_r(name, &grp, buf, buflen, &nss_errno); - if (status == NSS_STATUS_TRYAGAIN) { - buflen *= 2; - buf = realloc(buf, buflen); - goto again; - } - if (status == NSS_STATUS_NOTFOUND) { - return NULL; - } - if (status != NSS_STATUS_SUCCESS) { - report_nss_error("getgrnam", status); - return NULL; - } - return &grp; -} - -static struct group *nss_getgrgid(gid_t gid) -{ - NSS_STATUS (*_nss_getgrgid_r)(gid_t , struct group *, char *, - size_t , int *) = find_fn("getgrgid_r"); - static struct group grp; - static char *buf; - static int buflen = 1000; - NSS_STATUS status; - - if (!buf) buf = malloc(buflen); -again: - status = _nss_getgrgid_r(gid, &grp, buf, buflen, &nss_errno); - if (status == NSS_STATUS_TRYAGAIN) { - buflen *= 2; - buf = realloc(buf, buflen); - goto again; - } - if (status == NSS_STATUS_NOTFOUND) { - return NULL; - } - if (status != NSS_STATUS_SUCCESS) { - report_nss_error("getgrgid", status); - return NULL; - } - return &grp; -} - -static void nss_setgrent(void) -{ - NSS_STATUS (*_nss_setgrent)(void) = find_fn("setgrent"); - NSS_STATUS status; - status = _nss_setgrent(); - if (status != NSS_STATUS_SUCCESS) { - report_nss_error("setgrent", status); - } -} - -static void nss_endgrent(void) -{ - NSS_STATUS (*_nss_endgrent)(void) = find_fn("endgrent"); - NSS_STATUS status; - status = _nss_endgrent(); - if (status != NSS_STATUS_SUCCESS) { - report_nss_error("endgrent", status); - } -} - -static int nss_initgroups(char *user, gid_t group, gid_t **groups, long int *start, long int *size) -{ - NSS_STATUS (*_nss_initgroups)(char *, gid_t , long int *, - long int *, gid_t **, long int , int *) = - find_fn("initgroups_dyn"); - NSS_STATUS status; - - if (!_nss_initgroups) return NSS_STATUS_UNAVAIL; - - status = _nss_initgroups(user, group, start, size, groups, 0, &nss_errno); - if (status != NSS_STATUS_SUCCESS) { - report_nss_error("initgroups", status); - } - return status; -} - -static void print_passwd(struct passwd *pwd) -{ - printf("%s:%s:%d:%d:%s:%s:%s\n", - pwd->pw_name, - pwd->pw_passwd, - pwd->pw_uid, - pwd->pw_gid, - pwd->pw_gecos, - pwd->pw_dir, - pwd->pw_shell); -} - -static void print_group(struct group *grp) -{ - int i; - printf("%s:%s:%d: ", - grp->gr_name, - grp->gr_passwd, - grp->gr_gid); - - if (!grp->gr_mem[0]) { - printf("\n"); - return; - } - - for (i=0; grp->gr_mem[i+1]; i++) { - printf("%s, ", grp->gr_mem[i]); - } - printf("%s\n", grp->gr_mem[i]); -} - -static void nss_test_initgroups(char *name, gid_t gid) -{ - long int size = 16; - long int start = 1; - gid_t *groups = NULL; - int i; - NSS_STATUS status; - - groups = (gid_t *)malloc_array_p(gid_t, size); - groups[0] = gid; - - status = nss_initgroups(name, gid, &groups, &start, &size); - if (status == NSS_STATUS_UNAVAIL) { - printf("No initgroups fn\n"); - return; - } - - for (i=0; ipw_name); - printf("getpwent: "); print_passwd(pwd); - pwd = nss_getpwuid(pwd->pw_uid); - if (!pwd) { - total_errors++; - printf("ERROR: can't getpwuid\n"); - continue; - } - printf("getpwuid: "); print_passwd(pwd); - pwd = nss_getpwnam(pwd->pw_name); - if (!pwd) { - total_errors++; - printf("ERROR: can't getpwnam\n"); - continue; - } - printf("getpwnam: "); print_passwd(pwd); - printf("initgroups: "); nss_test_initgroups(pwd->pw_name, pwd->pw_gid); - printf("\n"); - } - nss_endpwent(); -} - -static void nss_test_groups(void) -{ - struct group *grp; - - nss_setgrent(); - /* loop over all groups */ - while ((grp = nss_getgrent())) { - printf("Testing group %s\n", grp->gr_name); - printf("getgrent: "); print_group(grp); - grp = nss_getgrnam(grp->gr_name); - if (!grp) { - total_errors++; - printf("ERROR: can't getgrnam\n"); - continue; - } - printf("getgrnam: "); print_group(grp); - grp = nss_getgrgid(grp->gr_gid); - if (!grp) { - total_errors++; - printf("ERROR: can't getgrgid\n"); - continue; - } - printf("getgrgid: "); print_group(grp); - printf("\n"); - } - nss_endgrent(); -} - -static void nss_test_errors(void) -{ - struct passwd *pwd; - struct group *grp; - - pwd = getpwnam("nosuchname"); - if (pwd || last_error != NSS_STATUS_NOTFOUND) { - total_errors++; - printf("ERROR Non existant user gave error %d\n", last_error); - } - - pwd = getpwuid(0xFFF0); - if (pwd || last_error != NSS_STATUS_NOTFOUND) { - total_errors++; - printf("ERROR Non existant uid gave error %d\n", last_error); - } - - grp = getgrnam("nosuchgroup"); - if (grp || last_error != NSS_STATUS_NOTFOUND) { - total_errors++; - printf("ERROR Non existant group gave error %d\n", last_error); - } - - grp = getgrgid(0xFFF0); - if (grp || last_error != NSS_STATUS_NOTFOUND) { - total_errors++; - printf("ERROR Non existant gid gave error %d\n", last_error); - } -} - - int main(int argc, char *argv[]) -{ - if (argc > 1) so_path = argv[1]; - if (argc > 2) nss_name = argv[2]; - - nss_test_users(); - nss_test_groups(); - nss_test_errors(); - - printf("total_errors=%d\n", total_errors); - - return total_errors; -} diff --git a/source4/torture/nsstest.h b/source4/torture/nsstest.h deleted file mode 100644 index 4dddf473fc..0000000000 --- a/source4/torture/nsstest.h +++ /dev/null @@ -1,116 +0,0 @@ -/* - Unix SMB/CIFS implementation. - nss includes for the nss tester - Copyright (C) Kai Blin 2007 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -*/ - -#ifndef _NSSTEST_H -#define _NSSTEST_H - -#include -#include - -#ifdef HAVE_NSS_COMMON_H - -/* - * Sun Solaris - */ - -#include -#include -#include - -typedef nss_status_t NSS_STATUS; - -#define NSS_STATUS_SUCCESS NSS_SUCCESS -#define NSS_STATUS_NOTFOUND NSS_NOTFOUND -#define NSS_STATUS_UNAVAIL NSS_UNAVAIL -#define NSS_STATUS_TRYAGAIN NSS_TRYAGAIN - -#elif HAVE_NSS_H - -/* - * Linux (glibc) - */ - -#include -typedef enum nss_status NSS_STATUS; - -#elif HAVE_NS_API_H - -/* - * SGI IRIX - */ - -#ifdef DATUM -#define _DATUM_DEFINED -#endif - -#include - -typedef enum -{ - NSS_STATUS_SUCCESS=NS_SUCCESS, - NSS_STATUS_NOTFOUND=NS_NOTFOUND, - NSS_STATUS_UNAVAIL=NS_UNAVAIL, - NSS_STATUS_TRYAGAIN=NS_TRYAGAIN -} NSS_STATUS; - -#define NSD_MEM_STATIC 0 -#define NSD_MEM_VOLATILE 1 -#define NSD_MEM_DYNAMIC 2 - -#elif defined(HPUX) && defined(HAVE_NSSWITCH_H) - -/* HP-UX 11 */ - -#include - -#define NSS_STATUS_SUCCESS NSS_SUCCESS -#define NSS_STATUS_NOTFOUND NSS_NOTFOUND -#define NSS_STATUS_UNAVAIL NSS_UNAVAIL -#define NSS_STATUS_TRYAGAIN NSS_TRYAGAIN - -#ifdef HAVE_SYNCH_H -#include -#endif -#ifdef HAVE_PTHREAD_H -#include -#endif - -typedef enum { - NSS_SUCCESS, - NSS_NOTFOUND, - NSS_UNAVAIL, - NSS_TRYAGAIN -} nss_status_t; - -typedef nss_status_t NSS_STATUS; - -#else /* Nothing's defined. Neither solaris nor gnu nor sun nor hp */ - -typedef enum -{ - NSS_STATUS_SUCCESS=0, - NSS_STATUS_NOTFOUND=1, - NSS_STATUS_UNAVAIL=2, - NSS_STATUS_TRYAGAIN=3 -} NSS_STATUS; - -#endif - -#endif /* _NSSTEST_H */ diff --git a/source4/torture/nsstest.m4 b/source4/torture/nsstest.m4 deleted file mode 100644 index 2856f9de15..0000000000 --- a/source4/torture/nsstest.m4 +++ /dev/null @@ -1,9 +0,0 @@ -case "$host_os" in - *linux*) - SMB_ENABLE(nsstest,YES) - ;; - *) - SMB_ENABLE(nsstest,NO) - ;; -esac - -- cgit