Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorArthur de Jong <arthur@arthurdejong.org>2006-10-11 15:34:15 +0200
committerArthur de Jong <arthur@arthurdejong.org>2006-10-11 15:34:15 +0200
commit6f17403298cf33747a45fb5ecbe78bf7632531f9 (patch)
treea5fc4cfdc3b091a0ee86f3c5c8d5e0ea8fc2c564 /tests
import release 251 of nss-ldap
git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/nss_ldap-251@1 ef36b2f9-881f-0410-afb5-c4e39611909c
Diffstat (limited to 'tests')
-rw-r--r--tests/ldaptest.pl101
-rw-r--r--tests/nsswitch.test40
-rw-r--r--tests/testd.c41
-rw-r--r--tests/testgr.c71
-rw-r--r--tests/testpw.c151
-rw-r--r--tests/testpw3.c48
-rw-r--r--tests/testpw4.c77
-rw-r--r--tests/testpw5.c127
-rw-r--r--tests/testpw6.c187
9 files changed, 843 insertions, 0 deletions
diff --git a/tests/ldaptest.pl b/tests/ldaptest.pl
new file mode 100644
index 0000000..615e6b3
--- /dev/null
+++ b/tests/ldaptest.pl
@@ -0,0 +1,101 @@
+#!/usr/bin/perl
+
+#
+# $Header: /home/project/cvs/nss_ldap/tests/ldaptest.pl,v 1.2 2001/01/09 00:21:21 lukeh Exp $
+#
+
+
+sub printarr {
+ foreach (@_) {
+ print $_." ";
+ }
+ print "\n";
+}
+sub printhost {
+ foreach (@_) {
+ if ($_ !~ /^[\w\.\d]+$/) {
+ @addr = unpack('C4',$_);
+ print $addr[0].".".$addr[1].".".$addr[2].".".$addr[3]." ";
+ } else {
+ print $_." ";
+ }
+ }
+ print "\n";
+}
+
+
+print "*** getpwnam ***\n";
+printarr(getpwnam("root"));
+print "*** getpwuid ***\n";
+printarr(getpwuid(0));
+print "*** setpwent ***\n";
+setpwent();
+print "*** getpwent ***\n";
+while(@ent = getpwent()) {
+ printarr(@ent);
+}
+print "*** endpwent ***\n";
+endpwent();
+print "*** getgrnam ***\n";
+printarr(getgrnam("wheel"));
+print "*** getgrgid ***\n";
+printarr(getgrgid(10));
+print "*** setgrent ***\n";
+setgrent();
+print "*** getgrent ***\n";
+while(@ent = getgrent()) {
+ printarr(@ent);
+}
+print "*** endgrent ***\n";
+endgrent();
+print "*** gethostbyname ***\n";
+printhost(gethostbyname("localhost"));
+print "*** gethostbyaddr ***\n";
+printhost(gethostbyaddr(pack(C4,(127,0,0,1)),2));
+print "*** sethostent ***\n";
+sethostent(0);
+print "*** gethostent ***\n";
+while(@ent = gethostent()) {
+ printhost(@ent);
+}
+print "*** endhostent ***\n";
+endhostent();
+# I dont appear to have networks. but we'll try anyway.
+print "*** getnetbyname ***\n";
+printhost(getnetbyname("localnet"));
+print "*** getnetbyaddr ***\n";
+# this may not be the right call. who uses 'networks' anyways!?
+printhost(getnetbyaddr(127,2));
+print "*** setnetent ***\n";
+setnetent(0);
+print "*** getnetent ***\n";
+while(@ent = getnetent()) {
+ printhost(@ent);
+}
+print "*** endnetent ***\n";
+endnetent();
+print "*** getservbyname ***\n";
+printarr(getservbyname("telnet","tcp"));
+print "*** getservbyport ***\n";
+printarr(getservbyport(23,"tcp"));
+print "*** setservent ***\n";
+setservent(0);
+print "*** getservent ***\n";
+while(@ent = getservent()) {
+ printarr(@ent);
+}
+print "*** endservent ***\n";
+endservent();
+print "*** getprotobyname ***\n";
+printarr(getprotobyname("icmp"));
+print "*** getprotobynumber ***\n";
+printarr(getprotobynumber(1));
+print "*** setprotoent ***\n";
+setprotoent(0);
+print "*** getprotoent ***\n";
+while(@ent = getprotoent()) {
+ printarr(@ent);
+}
+print "*** endprotoent ***\n";
+endprotoent();
+
diff --git a/tests/nsswitch.test b/tests/nsswitch.test
new file mode 100644
index 0000000..9240353
--- /dev/null
+++ b/tests/nsswitch.test
@@ -0,0 +1,40 @@
+#ident $Id: nsswitch.test,v 1.2 2001/01/09 00:21:22 lukeh Exp $
+#
+# An example file that could be copied over to /etc/nsswitch.conf; it
+# uses LDAP conjunction with files.
+#
+# "hosts:" and "services:" in this file are used only if the
+# /etc/netconfig file has a "-" for nametoaddr_libs of "inet" transports.
+
+# the following two lines obviate the "+" entry in /etc/passwd and /etc/group.
+passwd: ldap
+group: ldap
+
+# consult DNS first, we will need it to resolve the LDAP host. (If we
+# can't resolve it, we're in infinite recursion, because libldap calls
+# gethostbyname(). Careful!)
+hosts: files ldap
+
+# LDAP is nominally authoritative for the following maps.
+services: ldap
+networks: ldap
+protocols: ldap
+rpc: ldap
+ethers: ldap
+
+# no support for netmasks, bootparams, publickey yet.
+netmasks: files
+bootparams: files
+publickey: files
+automount: files
+
+# I'm pretty sure nsswitch.conf is consulted directly by sendmail,
+# here, so we can't do much here. Instead, use bbense's LDAP
+# rules ofr sendmail.
+aliases: files
+sendmailvars: files
+
+# No one has written the LDAP support for netgroups yet, so we'll
+# have to stick with NIS.
+netgroup: files nis
+
diff --git a/tests/testd.c b/tests/testd.c
new file mode 100644
index 0000000..f47081a
--- /dev/null
+++ b/tests/testd.c
@@ -0,0 +1,41 @@
+
+#import <lber.h>
+#import <ldap.h>
+#import "ldap-nss.h"
+#import "util.h"
+#import "dnsconfig.h"
+
+void
+printcf (ldap_config_t * cf)
+{
+ printf ("host %s\n", cf->ldc_host);
+ printf ("port %d\n", cf->ldc_port);
+ printf ("base %s\n", cf->ldc_base);
+#if 0
+ char *ldc_host;
+ int ldc_port;
+ char *ldc_base;
+ int ldc_scope;
+ char *ldc_binddn;
+ char *ldc_bindpw;
+ struct ldap_config *ldc_next;
+#endif
+}
+
+void
+main (void)
+{
+/*
+ NSS_STATUS _nss_ldap_readconfigfromdns(
+ ldap_config_t *result,
+ char *buf,
+ size_t buflen
+ */
+ ldap_config_t cf;
+ char buf[1024];
+
+ _nss_ldap_readconfigfromdns (&cf, buf, sizeof (buf));
+ printcf (&cf);
+ printcf (cf.ldc_next);
+ exit (0);
+}
diff --git a/tests/testgr.c b/tests/testgr.c
new file mode 100644
index 0000000..4907238
--- /dev/null
+++ b/tests/testgr.c
@@ -0,0 +1,71 @@
+#include <stdio.h>
+#include <grp.h>
+#include <signal.h>
+
+void
+main (int argc, char **argv)
+{
+#if 0
+ struct group
+ { /* see getgrent(3) */
+ char *gr_name;
+ char *gr_passwd;
+ gid_t gr_gid;
+ char **gr_mem;
+ };
+#endif
+
+ scan_group ();
+ exit (0);
+}
+
+void
+dump (struct group *g)
+{
+ char mem[2048];
+ char **p;
+
+ int doit = (g->gr_mem && *(g->gr_mem));
+ p = g->gr_mem;
+ strcpy (mem, "");
+ while (doit)
+ {
+ if (p != g->gr_mem)
+ strcat (mem, ",");
+ strcat (mem, *p);
+ if (*(++p) == NULL)
+ break;
+ }
+ printf ("%s:%s:%d:%s\n", g->gr_name, g->gr_passwd, g->gr_gid, mem);
+
+}
+
+scan_group ()
+{
+ struct group *g;
+
+ signal(SIGPIPE, SIG_IGN);
+
+ setgrent ();
+
+ while ((g = getgrent ()) != NULL)
+ {
+ dump (g);
+ }
+
+ endgrent ();
+
+ sleep(10);
+
+ printf ("==> getgrnam(qmail)\n");
+ g = getgrnam ("qmail");
+ if (g != NULL)
+ dump (g);
+#if 0
+ printf ("==> getgrnam(testgroup)\n");
+ g = getgrnam ("testgroup");
+ if (g != NULL)
+ dump (g);
+#endif
+
+}
diff --git a/tests/testpw.c b/tests/testpw.c
new file mode 100644
index 0000000..e65f986
--- /dev/null
+++ b/tests/testpw.c
@@ -0,0 +1,151 @@
+
+/* $Id: testpw.c,v 1.2 2001/01/09 00:21:22 lukeh Exp $ */
+
+/* This program just tests getpwent/getpwnam. You want to have nss_ldap
+ * plugged in, so to speak, to test anything useful.
+ */
+
+#include "config.h"
+
+#ifdef _REENTRANT
+#ifdef HAVE_PTHREAD_H
+#include <pthread.h>
+#else
+#include <thread.h>
+#endif /* _REENTRANT */
+
+#endif /* HAVE_PTHREAD_H */
+#include <stdio.h>
+#include <pwd.h>
+#include <sys/types.h>
+
+#if NeXT
+#define uid_t int
+#else
+#include <dlfcn.h> /* why? */
+#endif
+
+void test_passwd (void);
+void scan_passwd (void);
+
+int ARGC;
+char **ARGV;
+
+#define MAX_THREADS 16
+
+void
+main (int argc, char **argv)
+{
+#ifdef _REENTRANT
+ int i;
+#endif
+ ARGC = argc;
+ ARGV = argv;
+
+#ifdef _REENTRANT
+ for (i = 0; i < MAX_THREADS; i++)
+ {
+#ifdef HAVE_PTHREAD_H
+ pthread_t tid;
+ pthread_create (NULL, 0, test_passwd, NULL, 0, &tid);
+ pthread_continue (tid);
+#else
+ thread_t tid;
+ thr_create (NULL, 0, test_passwd, NULL, 0, &tid);
+ thr_continue (tid);
+#endif /* HAVE_PTHREAD_H */
+ }
+ while (thr_join (NULL, NULL, NULL) == 0);
+#else
+ test_passwd ();
+#endif
+ exit (0);
+}
+
+#ifdef _REENTRANT
+static void
+ret (int status)
+{
+ thr_exit (&status);
+}
+#else
+#define ret exit
+#endif
+
+void
+test_passwd (void)
+{
+ struct passwd *pw;
+ uid_t uid;
+#ifdef _REENTRANT
+ char buf[1024];
+ struct passwd pbuf;
+#endif
+
+ printf (">>>>>> getpwnam(\"%s\")\n", ARGC > 1 ? ARGV[1] : "root");
+#ifdef _REENTRANT
+ pw = getpwnam_r (ARGC > 1 ? ARGV[1] : "root", &pbuf, buf, sizeof (buf));
+#else
+ pw = getpwnam (ARGC > 1 ? ARGV[1] : "root");
+#endif
+
+ if (!pw)
+ ret (1);
+
+ printf ("%s:%s:%d:%d:%s:%s:%s\n", pw->pw_name, pw->pw_passwd, pw->pw_uid,
+ pw->pw_gid, pw->pw_gecos, pw->pw_dir, pw->pw_shell);
+ uid = pw->pw_uid;
+
+ printf (">>>>>> getpwuid(%d)\n", uid);
+
+#ifdef _REENTRANT
+ pw = getpwuid_r (uid, &pbuf, buf, sizeof (buf));
+#else
+ pw = getpwuid (uid);
+#endif
+
+ if (!pw)
+ ret (1);
+
+ printf ("%s:%s:%d:%d:%s:%s:%s\n", pw->pw_name, pw->pw_passwd, pw->pw_uid,
+ pw->pw_gid, pw->pw_gecos, pw->pw_dir, pw->pw_shell);
+
+ if (ARGC > 2 && !strcmp (ARGV[2], "no"))
+ {
+ printf (">>>>>> Enumeration skipped.\n");
+ }
+ else
+ {
+ printf (">>>>>> setpwent()\n");
+ setpwent ();
+
+ printf (">>>>>> getpwent()\n");
+ scan_passwd ();
+
+ printf (">>>>>> endpwent()\n");
+ endpwent ();
+ }
+
+ ret (0);
+}
+
+void
+scan_passwd (void)
+{
+ int i = 1;
+ struct passwd *p;
+#ifdef _REENTRANT
+ char buf[1024];
+ struct passwd pbuf;
+ while ((p = getpwent_r (&pbuf, buf, sizeof (buf))) != NULL)
+#else
+ while ((p = getpwent ()) != NULL)
+#endif
+ {
+ printf ("%s:%s:%d:%d:%s:%s:%s\n",
+ p->pw_name,
+ p->pw_passwd,
+ p->pw_uid, p->pw_gid, p->pw_gecos, p->pw_dir, p->pw_shell);
+ i++;
+ }
+}
diff --git a/tests/testpw3.c b/tests/testpw3.c
new file mode 100644
index 0000000..35cc855
--- /dev/null
+++ b/tests/testpw3.c
@@ -0,0 +1,48 @@
+#include <stdio.h>
+#include <pwd.h>
+
+void
+main (int argc, char **argv)
+{
+ scan_passwd ();
+
+ exit (0);
+}
+scan_passwd ()
+{
+ struct passwd p;
+ char buf[1024];
+ int i = 1;
+
+#ifdef WEIRD_GETPWENT
+ FILE *fp = NULL;
+#endif
+ memset (buf, 0xFF, sizeof (buf));
+
+#ifdef WEIRD_GETPWENT
+ setpwent_r (&fp);
+#else
+ setpwent_r ();
+#endif
+
+#ifdef WEIRD_GETPWENT
+ while (getpwent_r (&p, buf, (int) sizeof (buf), &fp) == 0)
+#else
+ while (getpwent_r (&p, buf, (int) sizeof (buf)) == 0)
+#endif
+ {
+ printf ("%s:%s:%d:%d:%s:%s:%s\n",
+ p.pw_name,
+ p.pw_passwd,
+ p.pw_uid, p.pw_gid, p.pw_gecos, p.pw_dir, p.pw_shell);
+ i++;
+ }
+
+#ifdef WEIRD_GETPWENT
+ endpwent_r (&fp);
+#else
+ endpwent_r ();
+#endif
+ fprintf (stderr, ">>>>>>> %d\n", i);
+
+}
diff --git a/tests/testpw4.c b/tests/testpw4.c
new file mode 100644
index 0000000..bf6f234
--- /dev/null
+++ b/tests/testpw4.c
@@ -0,0 +1,77 @@
+/* test IRS, independently of getpwnam et al. */
+
+#include <stdio.h>
+#include <pwd.h>
+#include <bsd/netdb.h>
+#include <netinet/in.h>
+#include <sys/socket.h>
+#include "irs-nss.h"
+
+static const char *testhost = "davinci.eng.sun.com";
+static char rcsid[] = "$Id: testpw4.c,v 1.2 2001/01/09 00:21:22 lukeh Exp $";
+
+void
+main (void)
+{
+
+ struct irs_pw *irs;
+ struct irs_ho *irs2;
+ struct passwd *pwd;
+ struct hostent *h;
+
+ int i;
+
+ i = 0;
+
+ printf ("Testing irs_pw enumeration...\n");
+
+ /* test users */
+ irs = irs_ldap_pw (NULL);
+
+ (irs->rewind) (irs);
+ while ((pwd = (irs->next) (irs)))
+ {
+ 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);
+ i++;
+ }
+ (irs->close) (irs);
+ free (irs);
+
+ fprintf (stderr, ">>>>>>> %d entries\n", i);
+
+ /* test hosts */
+
+ printf ("Testing irs_ho enumeration...\n");
+
+ irs2 = irs_ldap_ho (NULL);
+ i = 0;
+
+ (irs2->rewind) (irs2);
+ while ((h = (irs2->next) (irs2)))
+ {
+ struct in_addr addr;
+ bcopy (h->h_addr, &addr.s_addr, h->h_length);
+ printf ("%s\t%s\n", (char *) inet_ntoa (addr), h->h_name);
+ i++;
+ }
+ (irs2->close) (irs2);
+ fprintf (stderr, ">>>>>>> %d entries\n", i);
+
+ printf ("Testing irs_ho byname...\n");
+
+ h = (irs2->byname) (irs2, testhost);
+ if (h != NULL)
+ {
+ struct in_addr addr;
+ bcopy (h->h_addr, &addr.s_addr, h->h_length);
+ printf ("%s\t%s\n", (char *) inet_ntoa (addr), h->h_name);
+ }
+
+ free (irs);
+
+ exit (0);
+}
diff --git a/tests/testpw5.c b/tests/testpw5.c
new file mode 100644
index 0000000..8daaca8
--- /dev/null
+++ b/tests/testpw5.c
@@ -0,0 +1,127 @@
+
+/* $Id: testpw5.c,v 1.2 2001/01/09 00:21:22 lukeh Exp $ */
+
+/* This program just tests getpwent/getpwnam. You want to have nss_ldap
+ * plugged in, so to speak, to test anything useful.
+ */
+
+#include "config.h"
+
+#ifdef _REENTRANT
+#ifdef HAVE_THREAD_H
+#include <thread.h>
+#else
+#include <pthread.h>
+#endif
+#endif
+#include <stdio.h>
+#include <pwd.h>
+#include <stdlib.h>
+
+#if NeXT
+#define uid_t int
+#else
+#include <dlfcn.h> /* why? */
+#endif
+
+void test_passwd (void);
+
+int ARGC;
+char **ARGV;
+
+#define MAX_THREADS 16
+
+void
+main (int argc, char **argv)
+{
+#ifdef _REENTRANT
+ int i;
+#endif
+ ARGC = argc;
+ ARGV = argv;
+
+#ifdef _REENTRANT
+ for (i = 0; i < MAX_THREADS; i++)
+ {
+ thread_t tid;
+ thr_create (NULL, 0, test_passwd, NULL, 0, &tid);
+ thr_continue (tid);
+ }
+ while (thr_join (NULL, NULL, NULL) == 0);
+#else
+ test_passwd ();
+#endif
+ exit (0);
+}
+
+#ifdef _REENTRANT
+static void
+ret (int status)
+{
+ thr_exit (&status);
+}
+#else
+#define ret exit
+#endif
+
+void
+test_passwd (void)
+{
+ struct passwd *pw;
+ uid_t uid;
+#ifdef _REENTRANT
+ char buf[1024];
+ struct passwd pbuf;
+#endif
+
+
+
+ printf (">>>>>> setpwent()\n");
+ setpwent ();
+
+ printf (">>>>>> getpwent()\n");
+ scan_passwd ();
+
+ printf (">>>>>> endpwent()\n");
+ endpwent ();
+
+ ret (0);
+}
+
+scan_passwd ()
+{
+ int i = 1;
+ struct passwd *p;
+#ifdef _REENTRANT
+ char buf[1024];
+ struct passwd pbuf;
+ while ((p = getpwent_r (&pbuf, buf, sizeof (buf))) != NULL)
+#else
+ while ((p = getpwent ()) != NULL)
+#endif
+ {
+ printf ("%s:%s:%d:%d:%s:%s:%s\n",
+ p->pw_name,
+ p->pw_passwd,
+ p->pw_uid, p->pw_gid, p->pw_gecos, p->pw_dir, p->pw_shell);
+
+ if (p == NULL)
+ ret (1);
+
+#ifdef _REENTRANT
+ p = getpwnam_r (p->pw_name, &pbuf, buf, sizeof (buf));
+#else
+ p = getpwnam (p->pw_name);
+#endif
+
+ if (p == NULL)
+ ret (2);
+
+ printf ("%s:%s:%d:%d:%s:%s:%s\n",
+ p->pw_name,
+ p->pw_passwd,
+ p->pw_uid, p->pw_gid, p->pw_gecos, p->pw_dir, p->pw_shell);
+
+ i++;
+ }
+}
diff --git a/tests/testpw6.c b/tests/testpw6.c
new file mode 100644
index 0000000..f3a1596
--- /dev/null
+++ b/tests/testpw6.c
@@ -0,0 +1,187 @@
+
+/* $Id: testpw6.c,v 1.2 2006/01/10 18:06:39 lukeh Exp $ */
+
+/* This program just tests getpwent/getpwnam. You want to have nss_ldap
+ * plugged in, so to speak, to test anything useful.
+ */
+
+#include "config.h"
+
+#ifdef _REENTRANT
+#ifdef HAVE_PTHREAD_H
+#include <pthread.h>
+#else
+#include <thread.h>
+#endif /* _REENTRANT */
+
+#endif /* HAVE_PTHREAD_H */
+#include <stdio.h>
+#include <pwd.h>
+#include <sys/types.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+void test_passwd (void);
+void scan_passwd (void);
+
+int ARGC;
+char **ARGV;
+
+#define MAX_THREADS 8
+
+void
+main (int argc, char **argv)
+{
+#ifdef _REENTRANT
+ int i;
+#ifdef HAVE_PTHREAD_H
+ pthread_t tids[MAX_THREADS];
+#endif
+#endif
+ pid_t pid;
+ ARGC = argc;
+ ARGV = argv;
+
+ /* PRIME */
+ scan_passwd();
+
+ pid = fork();
+ if (pid == 0) {
+ printf("IN CHILD\n");
+ } else {
+ printf("IN PARENT\n");
+ }
+
+#ifdef _REENTRANT
+ for (i = 0; i < MAX_THREADS; i++)
+ {
+#ifdef HAVE_PTHREAD_H
+ pthread_create(&tids[i], NULL, test_passwd, NULL);
+#else
+ thread_t tid;
+ thr_create (NULL, 0, test_passwd, NULL, 0, &tid);
+ thr_continue (tid);
+#endif /* HAVE_PTHREAD_H */
+ }
+#ifdef HAVE_PTHREAD_H
+ for (i = 0; i < MAX_THREADS; i++) pthread_join(tids[i], NULL);
+#else
+ while (thr_join (NULL, NULL, NULL) == 0);
+#endif
+#else
+ test_passwd ();
+#endif
+ exit (0);
+}
+
+#ifdef _REENTRANT
+static void
+ret (int status)
+{
+#ifdef HAVE_PTHREAD_H
+ pthread_exit(&status);
+#else
+ thr_exit (&status);
+#endif
+}
+#else
+#define ret exit
+#endif
+
+void
+test_passwd (void)
+{
+ struct passwd *pw;
+ uid_t uid;
+#ifdef _REENTRANT
+ char buf[1024];
+ struct passwd pbuf;
+#endif
+ int pid;
+
+ printf (">>>>>> getpwnam(\"%s\")\n", ARGC > 1 ? ARGV[1] : "testuser");
+#ifdef _REENTRANT
+#if GETHOSTBYNAME_R_ARGS == 6
+ if (getpwnam_r (ARGC > 1 ? ARGV[1] : "testuser", &pbuf, buf, sizeof (buf), &pw) != 0) pw = NULL;
+#else
+ pw = getpwnam_r (ARGC > 1 ? ARGV[1] : "testuser", &pbuf, buf, sizeof (buf));
+#endif
+#else
+ pw = getpwnam (ARGC > 1 ? ARGV[1] : "testuser");
+#endif
+
+ if (!pw)
+ ret (1);
+
+ printf ("%s:%s:%d:%d:%s:%s:%s\n", pw->pw_name, pw->pw_passwd, pw->pw_uid,
+ pw->pw_gid, pw->pw_gecos, pw->pw_dir, pw->pw_shell);
+ uid = pw->pw_uid;
+
+
+ printf (">>>>>> getpwuid(%d)\n", uid);
+
+#ifdef _REENTRANT
+#if GETHOSTBYNAME_R_ARGS == 6
+ if (getpwuid_r (uid, &pbuf, buf, sizeof(buf), &pw) != 0) pw = NULL;
+#else
+ pw = getpwuid_r (uid, &pbuf, buf, sizeof (buf));
+#endif
+#else
+ pw = getpwuid (uid);
+#endif
+
+ if (!pw)
+ ret (1);
+
+
+ printf ("%s:%s:%d:%d:%s:%s:%s\n", pw->pw_name, pw->pw_passwd, pw->pw_uid,
+ pw->pw_gid, pw->pw_gecos, pw->pw_dir, pw->pw_shell);
+
+ if (ARGC > 2 && !strcmp (ARGV[2], "no"))
+ {
+ printf (">>>>>> Enumeration skipped.\n");
+ }
+ else
+ {
+ printf (">>>>>> setpwent()\n");
+ setpwent ();
+
+ printf (">>>>>> getpwent()\n");
+ scan_passwd ();
+
+ printf (">>>>>> endpwent()\n");
+ endpwent ();
+ }
+
+ ret (0);
+}
+
+void
+scan_passwd (void)
+{
+ int i = 1;
+ struct passwd *p;
+#ifdef _REENTRANT
+ char buf[1024];
+ struct passwd pbuf;
+#endif
+
+
+#ifdef _REENTRANT
+#if GETHOSTBYNAME_R_ARGS == 6
+ while (getpwent_r (&pbuf, buf, sizeof (buf), &p) == 0 && p != NULL)
+#else
+ while ((p = getpwent_r (&pbuf, buf, sizeof (buf))) != NULL)
+#endif
+#else
+ while ((p = getpwent ()) != NULL)
+#endif
+ {
+ printf ("%s:%s:%d:%d:%s:%s:%s\n",
+ p->pw_name,
+ p->pw_passwd,
+ p->pw_uid, p->pw_gid, p->pw_gecos, p->pw_dir, p->pw_shell);
+ i++;
+ }
+}