summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArthur de Jong <arthur@arthurdejong.org>2006-11-28 10:59:23 +0000
committerArthur de Jong <arthur@arthurdejong.org>2006-11-28 10:59:23 +0000
commit742039b6ed98f637228575adb6217821ad3ea707 (patch)
tree576b47718a072a3f5326f7645fa9802a620283eb
parentd524c2cfc47a4d5217957e8e910611de9fb5b0fd (diff)
get as many files from the root directory as possible, moving all server related code to the server directory and moving and splitting the test code to the tests directory
git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/libnss_ldapd@131 ef36b2f9-881f-0410-afb5-c4e39611909c
-rw-r--r--Makefile.am20
-rw-r--r--configure.ac2
-rw-r--r--nslcd-common.h3
-rw-r--r--nss/Makefile.am6
-rw-r--r--nss/exports.linux (renamed from exports.linux)0
-rw-r--r--server/Makefile.am18
-rw-r--r--server/log.c (renamed from log.c)0
-rw-r--r--server/log.h (renamed from log.h)0
-rw-r--r--server/nslcd-server.c (renamed from nslcd-server.c)0
-rw-r--r--server/nslcd-server.h (renamed from nslcd-server.h)0
-rw-r--r--server/nslcd.c (renamed from nslcd.c)0
-rw-r--r--server/xmalloc.c (renamed from xmalloc.c)0
-rw-r--r--server/xmalloc.h (renamed from xmalloc.h)0
-rw-r--r--tests/Makefile.am37
-rw-r--r--tests/test_aliases.c93
-rw-r--r--tests/test_ethers.c98
-rw-r--r--tests/test_group.c119
-rw-r--r--tests/test_hosts.c163
-rw-r--r--tests/test_netgroup.c99
-rw-r--r--tests/test_networks.c113
-rw-r--r--tests/test_passwd.c112
-rw-r--r--tests/test_protocols.c102
-rw-r--r--tests/test_rpc.c102
-rw-r--r--tests/test_services.c104
-rw-r--r--tests/test_shadow.c97
-rw-r--r--tests/testnss.c (renamed from testnss.c)0
26 files changed, 1260 insertions, 28 deletions
diff --git a/Makefile.am b/Makefile.am
index eb65e0f..f697e8d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -19,29 +19,15 @@
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
# MA 02110-1301 USA
-SUBDIRS = nss server
-
-noinst_PROGRAMS = nss_ldap.so nslcd testnss
+SUBDIRS = nss server tests
man_MANS = nss_ldap.5
EXTRA_DIST = ChangeLog \
AUTHORS ANNOUNCE NEWS INSTALL README COPYING \
ldap.conf \
- debian doc exports.linux nss_ldap.5 tests
-
-nss_ldap_so_SOURCES = nslcd.h
-nss_ldap_so_LDADD = nss/libnss.a
-nss_ldap_so_LDFLAGS = @nss_ldap_so_LDFLAGS@
-
-nslcd_SOURCES = nslcd.c nslcd.h \
- nslcd-server.c nslcd-server.h \
- log.c log.h \
- xmalloc.c xmalloc.h
-nslcd_LDADD = server/libserver.a
-
-testnss_SOURCES = testnss.c nslcd.h
-testnss_LDADD = nss/libnss.a
+ debian doc exports.linux nss_ldap.5 tests \
+ nslcd.h nslcd-common.h
NSS_LDAP_PATH_CONF = @NSS_LDAP_PATH_CONF@
NSS_LDAP_PATH_ROOTPASSWD = @NSS_LDAP_PATH_ROOTPASSWD@
diff --git a/configure.ac b/configure.ac
index fbacc4f..b7f3e0a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -371,5 +371,5 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <ldap.h>]], [[ldap_set_rebind_proc(0, 0, 0);]])],[nss_ldap_cv_ldap_set_rebind_proc=3],[nss_ldap_cv_ldap_set_rebind_proc=2]) ])
AC_DEFINE_UNQUOTED(LDAP_SET_REBIND_PROC_ARGS, $nss_ldap_cv_ldap_set_rebind_proc,[Define to the number of arguments to ldap_set_rebindproc.])
-AC_CONFIG_FILES([Makefile nss/Makefile server/Makefile])
+AC_CONFIG_FILES([Makefile nss/Makefile server/Makefile tests/Makefile])
AC_OUTPUT
diff --git a/nslcd-common.h b/nslcd-common.h
index 5daebca..25efd83 100644
--- a/nslcd-common.h
+++ b/nslcd-common.h
@@ -26,9 +26,6 @@
#include <stdio.h>
-#undef DEBUG_PROT
-#undef DEBUG_PROT_DUMP
-
#ifdef DEBUG_PROT
/* define a debugging macro to output logging */
#include <string.h>
diff --git a/nss/Makefile.am b/nss/Makefile.am
index 655e94d..b149a46 100644
--- a/nss/Makefile.am
+++ b/nss/Makefile.am
@@ -19,9 +19,15 @@
# MA 02110-1301 USA
noinst_LIBRARIES = libnss.a
+noinst_PROGRAMS = nss_ldap.so
libnss_a_SOURCES = common.c common.h prototypes.h \
../nslcd.h ../nslcd-common.h \
aliases.c ethers.c group.c hosts.c netgroup.c \
networks.c passwd.c protocols.c rpc.c services.c \
shadow.c
+
+nss_ldap_so_SOURCES = ../nslcd.h
+nss_ldap_so_LDADD = libnss.a
+nss_ldap_so_LDFLAGS = @nss_ldap_so_LDFLAGS@
+
diff --git a/exports.linux b/nss/exports.linux
index f2ecf08..f2ecf08 100644
--- a/exports.linux
+++ b/nss/exports.linux
diff --git a/server/Makefile.am b/server/Makefile.am
index 4534311..c5f5ed0 100644
--- a/server/Makefile.am
+++ b/server/Makefile.am
@@ -18,11 +18,15 @@
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
# MA 02110-1301 USA
-noinst_LIBRARIES = libserver.a
+noinst_PROGRAMS = nslcd
-libserver_a_SOURCES = common.c common.h \
- alias.c ether.c group.c host.c netgroup.c network.c \
- passwd.c protocol.c rpc.c service.c shadow.c \
- dnsconfig.c dnsconfig.h ldap-nss.c ldap-nss.h \
- ldap-schema.c ldap-schema.h pagectrl.c pagectrl.h \
- resolve.c resolve.h util.c util.h
+nslcd_SOURCES = nslcd.c ../nslcd.h ../nslcd-common.h \
+ nslcd-server.c nslcd-server.h \
+ log.c log.h \
+ xmalloc.c xmalloc.h \
+ common.c common.h \
+ alias.c ether.c group.c host.c netgroup.c network.c \
+ passwd.c protocol.c rpc.c service.c shadow.c \
+ dnsconfig.c dnsconfig.h ldap-nss.c ldap-nss.h \
+ ldap-schema.c ldap-schema.h pagectrl.c pagectrl.h \
+ resolve.c resolve.h util.c util.h
diff --git a/log.c b/server/log.c
index 72a28a3..72a28a3 100644
--- a/log.c
+++ b/server/log.c
diff --git a/log.h b/server/log.h
index 0cadbeb..0cadbeb 100644
--- a/log.h
+++ b/server/log.h
diff --git a/nslcd-server.c b/server/nslcd-server.c
index 7f3c10d..7f3c10d 100644
--- a/nslcd-server.c
+++ b/server/nslcd-server.c
diff --git a/nslcd-server.h b/server/nslcd-server.h
index 2b6b80a..2b6b80a 100644
--- a/nslcd-server.h
+++ b/server/nslcd-server.h
diff --git a/nslcd.c b/server/nslcd.c
index 25db64e..25db64e 100644
--- a/nslcd.c
+++ b/server/nslcd.c
diff --git a/xmalloc.c b/server/xmalloc.c
index f316ad8..f316ad8 100644
--- a/xmalloc.c
+++ b/server/xmalloc.c
diff --git a/xmalloc.h b/server/xmalloc.h
index a4a6238..a4a6238 100644
--- a/xmalloc.h
+++ b/server/xmalloc.h
diff --git a/tests/Makefile.am b/tests/Makefile.am
new file mode 100644
index 0000000..4f1683b
--- /dev/null
+++ b/tests/Makefile.am
@@ -0,0 +1,37 @@
+# Makefile.am - use automake to generate Makefile.in
+#
+# Copyright (C) 2006 West consulting
+# Copyright (C) 2006 Arthur de Jong
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Library General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library 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
+# Library General Public License for more details.
+#
+# You should have received a copy of the GNU Library General Public
+# License along with this library; if not, write to the Free
+# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+# MA 02110-1301 USA
+
+noinst_PROGRAMS = test_aliases test_ethers test_group test_hosts \
+ test_netgroup test_networks test_passwd test_protocols \
+ test_rpc test_services test_shadow
+
+AM_CFLAGS=-DDEBUG_PROT -DDEBUG_PROT_DUMP
+
+test_aliases_SOURCES = test_aliases.c ../nss/aliases.c ../nss/common.c ../nslcd.h ../nss/prototypes.h
+test_ethers_SOURCES = test_ethers.c ../nss/ethers.c ../nss/common.c ../nslcd.h ../nss/prototypes.h
+test_group_SOURCES = test_group.c ../nss/group.c ../nss/common.c ../nslcd.h ../nss/prototypes.h
+test_hosts_SOURCES = test_hosts.c ../nss/hosts.c ../nss/common.c ../nslcd.h ../nss/prototypes.h
+test_netgroup_SOURCES = test_netgroup.c ../nss/netgroup.c ../nss/common.c ../nslcd.h ../nss/prototypes.h
+test_networks_SOURCES = test_networks.c ../nss/networks.c ../nss/common.c ../nslcd.h ../nss/prototypes.h
+test_passwd_SOURCES = test_passwd.c ../nss/passwd.c ../nss/common.c ../nslcd.h ../nss/prototypes.h
+test_protocols_SOURCES = test_protocols.c ../nss/protocols.c ../nss/common.c ../nslcd.h ../nss/prototypes.h
+test_rpc_SOURCES = test_rpc.c ../nss/rpc.c ../nss/common.c ../nslcd.h ../nss/prototypes.h
+test_services_SOURCES = test_services.c ../nss/services.c ../nss/common.c ../nslcd.h ../nss/prototypes.h
+test_shadow_SOURCES = test_shadow.c ../nss/shadow.c ../nss/common.c ../nslcd.h ../nss/prototypes.h
diff --git a/tests/test_aliases.c b/tests/test_aliases.c
new file mode 100644
index 0000000..b340cb5
--- /dev/null
+++ b/tests/test_aliases.c
@@ -0,0 +1,93 @@
+/*
+ test_aliases.c - simple tests of developed nss code
+
+ Copyright (C) 2006 West Consulting
+ Copyright (C) 2006 Arthur de Jong
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+*/
+
+#include "config.h"
+
+#include <string.h>
+#include <stdio.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
+
+#include "nss/prototypes.h"
+
+static char *nssstatus(enum nss_status retv)
+{
+ switch(retv)
+ {
+ case NSS_STATUS_TRYAGAIN: return "NSS_STATUS_TRYAGAIN";
+ case NSS_STATUS_UNAVAIL: return "NSS_STATUS_UNAVAIL";
+ case NSS_STATUS_NOTFOUND: return "NSS_STATUS_NOTFOUND";
+ case NSS_STATUS_SUCCESS: return "NSS_STATUS_SUCCESS";
+ case NSS_STATUS_RETURN: return "NSS_STATUS_RETURN";
+ default: return "NSS_STATUS_**ILLEGAL**";
+ }
+}
+
+static void printalias(struct aliasent *alias)
+{
+ int i;
+ printf("struct alias {\n"
+ " alias_name=\"%s\",\n"
+ " alias_members_len=%d,\n",
+ alias->alias_name,(int)alias->alias_members_len);
+ for (i=0;i<(int)alias->alias_members_len;i++)
+ printf(" alias_members[%d]=\"%s\",\n",
+ i,alias->alias_members[i]);
+ printf(" alias_local=%d\n"
+ "}\n",(int)alias->alias_local);
+}
+
+/* the main program... */
+int main(int argc,char *argv[])
+{
+ struct aliasent aliasresult;
+ char buffer[1024];
+ enum nss_status res;
+ int errnocp;
+
+ /* test getaliasbyname() */
+ printf("\nTEST getaliasbyname()\n");
+ res=_nss_ldap_getaliasbyname_r("wij@arthurenhella.demon.nl",&aliasresult,buffer,1024,&errnocp);
+ printf("status=%s\n",nssstatus(res));
+ if (res==NSS_STATUS_SUCCESS)
+ printalias(&aliasresult);
+ else
+ printf("errno=%d:%s\n",(int)errnocp,strerror(errnocp));
+
+ /* test {set,get,end}aliasent() */
+ printf("\nTEST {set,get,end}aliasent()\n");
+ res=_nss_ldap_setaliasent();
+ printf("status=%s\n",nssstatus(res));
+ while ((res=_nss_ldap_getaliasent_r(&aliasresult,buffer,1024,&errnocp))==NSS_STATUS_SUCCESS)
+ {
+ printf("status=%s\n",nssstatus(res));
+ printalias(&aliasresult);
+ }
+ printf("status=%s\n",nssstatus(res));
+ printf("errno=%d:%s\n",(int)errnocp,strerror(errnocp));
+ res=_nss_ldap_endaliasent();
+ printf("status=%s\n",nssstatus(res));
+
+ return 0;
+}
diff --git a/tests/test_ethers.c b/tests/test_ethers.c
new file mode 100644
index 0000000..ef77a99
--- /dev/null
+++ b/tests/test_ethers.c
@@ -0,0 +1,98 @@
+/*
+ test_ethers.c - simple tests of developed nss code
+
+ Copyright (C) 2006 West Consulting
+ Copyright (C) 2006 Arthur de Jong
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+*/
+
+#include "config.h"
+
+#include <string.h>
+#include <stdio.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
+
+#include "nss/prototypes.h"
+
+static char *nssstatus(enum nss_status retv)
+{
+ switch(retv)
+ {
+ case NSS_STATUS_TRYAGAIN: return "NSS_STATUS_TRYAGAIN";
+ case NSS_STATUS_UNAVAIL: return "NSS_STATUS_UNAVAIL";
+ case NSS_STATUS_NOTFOUND: return "NSS_STATUS_NOTFOUND";
+ case NSS_STATUS_SUCCESS: return "NSS_STATUS_SUCCESS";
+ case NSS_STATUS_RETURN: return "NSS_STATUS_RETURN";
+ default: return "NSS_STATUS_**ILLEGAL**";
+ }
+}
+
+static void printether(struct etherent *ether)
+{
+ printf("struct etherent {\n"
+ " e_name=\"%s\",\n"
+ " e_addr=%s\n"
+ "}\n",
+ ether->e_name,ether_ntoa(&(ether->e_addr)));
+}
+
+/* the main program... */
+int main(int argc,char *argv[])
+{
+ struct etherent etherresult;
+ char buffer[1024];
+ enum nss_status res;
+ int errnocp;
+
+ /* test ether_hostton() */
+ printf("\nTEST ether_hostton()\n");
+ res=_nss_ldap_gethostton_r("spiritus",&etherresult,buffer,1024,&errnocp);
+ printf("status=%s\n",nssstatus(res));
+ if (res==NSS_STATUS_SUCCESS)
+ printether(&etherresult);
+ else
+ printf("errno=%d:%s\n",(int)errnocp,strerror(errnocp));
+
+ /* test ether_ntohost() */
+ printf("\nTEST ether_ntohost()\n");
+ res=_nss_ldap_getntohost_r(ether_aton("00:E0:4C:39:D3:6A"),
+ &etherresult,buffer,1024,&errnocp);
+ printf("status=%s\n",nssstatus(res));
+ if (res==NSS_STATUS_SUCCESS)
+ printether(&etherresult);
+ else
+ printf("errno=%d:%s\n",(int)errnocp,strerror(errnocp));
+
+ /* test {set,get,end}etherent() */
+ printf("\nTEST {set,get,end}etherent()\n");
+ res=_nss_ldap_setetherent(1);
+ printf("status=%s\n",nssstatus(res));
+ while ((res=_nss_ldap_getetherent_r(&etherresult,buffer,1024,&errnocp))==NSS_STATUS_SUCCESS)
+ {
+ printf("status=%s\n",nssstatus(res));
+ printether(&etherresult);
+ }
+ printf("status=%s\n",nssstatus(res));
+ printf("errno=%d:%s\n",(int)errnocp,strerror(errnocp));
+ res=_nss_ldap_endetherent();
+ printf("status=%s\n",nssstatus(res));
+
+ return 0;
+}
diff --git a/tests/test_group.c b/tests/test_group.c
new file mode 100644
index 0000000..408b0a9
--- /dev/null
+++ b/tests/test_group.c
@@ -0,0 +1,119 @@
+/*
+ test_group.c - simple tests of developed nss code
+
+ Copyright (C) 2006 West Consulting
+ Copyright (C) 2006 Arthur de Jong
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+*/
+
+#include "config.h"
+
+#include <string.h>
+#include <stdio.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
+
+#include "nss/prototypes.h"
+
+static char *nssstatus(enum nss_status retv)
+{
+ switch(retv)
+ {
+ case NSS_STATUS_TRYAGAIN: return "NSS_STATUS_TRYAGAIN";
+ case NSS_STATUS_UNAVAIL: return "NSS_STATUS_UNAVAIL";
+ case NSS_STATUS_NOTFOUND: return "NSS_STATUS_NOTFOUND";
+ case NSS_STATUS_SUCCESS: return "NSS_STATUS_SUCCESS";
+ case NSS_STATUS_RETURN: return "NSS_STATUS_RETURN";
+ default: return "NSS_STATUS_**ILLEGAL**";
+ }
+}
+
+static void printgroup(struct group *group)
+{
+ int i;
+ printf("struct group {\n"
+ " gr_name=\"%s\",\n"
+ " gr_passwd=\"%s\",\n"
+ " gr_gid=%d,\n",
+ group->gr_name,group->gr_passwd,(int)group->gr_gid);
+ for (i=0;group->gr_mem[i]!=NULL;i++)
+ printf(" gr_mem[%d]=\"%s\",\n",
+ i,group->gr_mem[i]);
+ printf(" gr_mem[%d]=NULL\n"
+ "}\n",i);
+}
+
+/* the main program... */
+int main(int argc,char *argv[])
+{
+ struct group groupresult;
+ char buffer[1024];
+ enum nss_status res;
+ int errnocp;
+ long int start,size=40;
+ gid_t *gidlist=(gid_t *)buffer;
+
+ /* test getgrnam() */
+ printf("\nTEST getgrnam()\n");
+ res=_nss_ldap_getgrnam_r("testgroup",&groupresult,buffer,1024,&errnocp);
+ printf("status=%s\n",nssstatus(res));
+ if (res==NSS_STATUS_SUCCESS)
+ printgroup(&groupresult);
+ else
+ printf("errno=%d:%s\n",(int)errnocp,strerror(errnocp));
+
+ /* test getgrgid() */
+ printf("\nTEST getgrgid()\n");
+ res=_nss_ldap_getgrgid_r(100,&groupresult,buffer,1024,&errnocp);
+ printf("status=%s\n",nssstatus(res));
+ if (res==NSS_STATUS_SUCCESS)
+ printgroup(&groupresult);
+ else
+ printf("errno=%d:%s\n",(int)errnocp,strerror(errnocp));
+
+ /* test initgroups() */
+ printf("\nTEST initgroups()\n");
+ res=_nss_ldap_initgroups_dyn("arthur",10,&start,&size,&gidlist,size,&errnocp);
+ printf("status=%s\n",nssstatus(res));
+ if (res==NSS_STATUS_SUCCESS)
+ {
+ for (size=0;size<start;size++)
+ {
+ printf("gidlist[%d]=%d\n",(int)size,(int)gidlist[size]);
+ }
+ }
+ else
+ printf("errno=%d:%s\n",(int)errnocp,strerror(errnocp));
+
+ /* test {set,get,end}grent() */
+ printf("\nTEST {set,get,end}grent()\n");
+ res=_nss_ldap_setgrent(1);
+ printf("status=%s\n",nssstatus(res));
+ while ((res=_nss_ldap_getgrent_r(&groupresult,buffer,1024,&errnocp))==NSS_STATUS_SUCCESS)
+ {
+ printf("status=%s\n",nssstatus(res));
+ printgroup(&groupresult);
+ }
+ printf("status=%s\n",nssstatus(res));
+ printf("errno=%d:%s\n",(int)errnocp,strerror(errnocp));
+ res=_nss_ldap_endgrent();
+ printf("status=%s\n",nssstatus(res));
+
+ return 0;
+}
diff --git a/tests/test_hosts.c b/tests/test_hosts.c
new file mode 100644
index 0000000..3c77f62
--- /dev/null
+++ b/tests/test_hosts.c
@@ -0,0 +1,163 @@
+/*
+ test_hosts.c - simple tests of developed nss code
+
+ Copyright (C) 2006 West Consulting
+ Copyright (C) 2006 Arthur de Jong
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+*/
+
+#include <string.h>
+#include <stdio.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
+
+#include "nss/prototypes.h"
+
+static char *nssstatus(enum nss_status retv)
+{
+ switch(retv)
+ {
+ case NSS_STATUS_TRYAGAIN: return "NSS_STATUS_TRYAGAIN";
+ case NSS_STATUS_UNAVAIL: return "NSS_STATUS_UNAVAIL";
+ case NSS_STATUS_NOTFOUND: return "NSS_STATUS_NOTFOUND";
+ case NSS_STATUS_SUCCESS: return "NSS_STATUS_SUCCESS";
+ case NSS_STATUS_RETURN: return "NSS_STATUS_RETURN";
+ default: return "NSS_STATUS_**ILLEGAL**";
+ }
+}
+
+static void printhost(struct hostent *host)
+{
+ int i,j;
+ char buffer[1024];
+ printf("struct hostent {\n"
+ " h_name=\"%s\",\n",
+ host->h_name);
+ for (i=0;host->h_aliases[i]!=NULL;i++)
+ printf(" h_aliases[%d]=\"%s\",\n",
+ i,host->h_aliases[i]);
+ printf(" h_aliases[%d]=NULL,\n",i);
+ if (host->h_addrtype==AF_INET)
+ printf(" h_addrtype=AF_INET,\n");
+ else if (host->h_addrtype==AF_INET6)
+ printf(" h_addrtype=AF_INET6,\n");
+ else
+ printf(" h_addrtype=%d,\n",host->h_addrtype);
+ printf(" h_length=%d,\n",host->h_length);
+ for (i=0;host->h_addr_list[i]!=NULL;i++)
+ {
+ if (inet_ntop(host->h_addrtype,host->h_addr_list[i],
+ buffer,1024)!=NULL)
+ {
+ printf(" h_addr_list[%d]=%s,\n",i,buffer);
+ }
+ else
+ {
+ printf(" h_addr_list[%d]=",i);
+ for (j=0;j<host->h_length;j++)
+ printf("%02x",(int)((const uint8_t*)host->h_addr_list[i])[j]);
+ printf(",\n");
+ }
+ }
+ printf(" h_addr_list[%d]=NULL\n"
+ "}\n",i);
+}
+
+/* the main program... */
+int main(int argc,char *argv[])
+{
+ struct hostent hostresult;
+ char buffer[1024];
+ enum nss_status res;
+ int errnocp,h_errnocp;
+ char address[1024];
+
+ /* test gethostbyname2(AF_INET) */
+ printf("\nTEST gethostbyname2(AF_INET)\n");
+ res=_nss_ldap_gethostbyname2_r("oostc",AF_INET,&hostresult,buffer,1024,&errnocp,&h_errnocp);
+ printf("status=%s\n",nssstatus(res));
+ if (res==NSS_STATUS_SUCCESS)
+ printhost(&hostresult);
+ else
+ {
+ printf("errno=%d:%s\n",(int)errnocp,strerror(errnocp));
+ printf("h_errno=%d:%s\n",(int)h_errnocp,hstrerror(h_errnocp));
+ }
+
+ /* test gethostbyname2(AF_INET6) */
+/* this is currently unsupported
+ printf("\nTEST gethostbyname2(AF_INET6)\n");
+ res=_nss_ldap_gethostbyname2_r("appelscha",AF_INET6,&hostresult,buffer,1024,&errnocp,&h_errnocp);
+ printf("status=%s\n",nssstatus(res));
+ if (res==NSS_STATUS_SUCCESS)
+ printhost(&hostresult);
+ else
+ {
+ printf("errno=%d:%s\n",(int)errnocp,strerror(errnocp));
+ printf("h_errno=%d:%s\n",(int)h_errnocp,hstrerror(h_errnocp));
+ }
+*/
+
+ /* test gethostbyaddr(AF_INET) */
+ printf("\nTEST gethostbyaddr(AF_INET)\n");
+ inet_pton(AF_INET,"192.43.210.81",address);
+ res=_nss_ldap_gethostbyaddr_r(address,sizeof(struct in_addr),AF_INET,
+ &hostresult,buffer,1024,&errnocp,&h_errnocp);
+ printf("status=%s\n",nssstatus(res));
+ if (res==NSS_STATUS_SUCCESS)
+ printhost(&hostresult);
+ else
+ {
+ printf("errno=%d:%s\n",(int)errnocp,strerror(errnocp));
+ printf("h_errno=%d:%s\n",(int)h_errnocp,hstrerror(h_errnocp));
+ }
+
+ /* test gethostbyaddr(AF_INET6) */
+/* this is currently unsupported
+ printf("\nTEST gethostbyaddr(AF_INET6)\n");
+ inet_pton(AF_INET6,"2001:200:0:8002:203:47ff:fea5:3085",address);
+ res=_nss_ldap_gethostbyaddr_r(address,sizeof(struct in6_addr),AF_INET6,
+ &hostresult,buffer,1024,&errnocp,&h_errnocp);
+ printf("status=%s\n",nssstatus(res));
+ if (res==NSS_STATUS_SUCCESS)
+ printhost(&hostresult);
+ else
+ {
+ printf("errno=%d:%s\n",(int)errnocp,strerror(errnocp));
+ printf("h_errno=%d:%s\n",(int)h_errnocp,hstrerror(h_errnocp));
+ }
+*/
+
+ /* test {set,get,end}hostent() */
+ printf("\nTEST {set,get,end}hostent()\n");
+ res=_nss_ldap_sethostent(1);
+ printf("status=%s\n",nssstatus(res));
+ while ((res=_nss_ldap_gethostent_r(&hostresult,buffer,1024,&errnocp,&h_errnocp))==NSS_STATUS_SUCCESS)
+ {
+ printf("status=%s\n",nssstatus(res));
+ printhost(&hostresult);
+ }
+ printf("status=%s\n",nssstatus(res));
+ printf("errno=%d:%s\n",(int)errnocp,strerror(errnocp));
+ printf("h_errno=%d:%s\n",(int)h_errnocp,hstrerror(h_errnocp));
+ res=_nss_ldap_endhostent();
+ printf("status=%s\n",nssstatus(res));
+
+ return 0;
+}
diff --git a/tests/test_netgroup.c b/tests/test_netgroup.c
new file mode 100644
index 0000000..3adb2ae
--- /dev/null
+++ b/tests/test_netgroup.c
@@ -0,0 +1,99 @@
+/*
+ test_netgroup.c - simple tests of developed nss code
+
+ Copyright (C) 2006 West Consulting
+ Copyright (C) 2006 Arthur de Jong
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+*/
+
+#include "config.h"
+
+#include <string.h>
+#include <stdio.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
+
+#include "nss/prototypes.h"
+
+static char *nssstatus(enum nss_status retv)
+{
+ switch(retv)
+ {
+ case NSS_STATUS_TRYAGAIN: return "NSS_STATUS_TRYAGAIN";
+ case NSS_STATUS_UNAVAIL: return "NSS_STATUS_UNAVAIL";
+ case NSS_STATUS_NOTFOUND: return "NSS_STATUS_NOTFOUND";
+ case NSS_STATUS_SUCCESS: return "NSS_STATUS_SUCCESS";
+ case NSS_STATUS_RETURN: return "NSS_STATUS_RETURN";
+ default: return "NSS_STATUS_**ILLEGAL**";
+ }
+}
+
+static void printnetgroup(struct __netgrent *netgroup)
+{
+ printf("struct __netgrent {\n");
+ if (netgroup->type==triple_val)
+ {
+ printf(" type=triple_val,\n");
+ if (netgroup->val.triple.host==NULL)
+ printf(" val.triple.host=NULL,\n");
+ else
+ printf(" val.triple.host=\"%s\",\n",netgroup->val.triple.host);
+ if (netgroup->val.triple.user==NULL)
+ printf(" val.triple.user=NULL,\n");
+ else
+ printf(" val.triple.user=\"%s\",\n",netgroup->val.triple.user);
+ if (netgroup->val.triple.domain==NULL)
+ printf(" val.triple.domain=NULL,\n");
+ else
+ printf(" val.triple.domain=\"%s\",\n",netgroup->val.triple.domain);
+ }
+ else
+ {
+ printf(" type=triple_val,\n"
+ " val.group=\"%s\",\n",
+ netgroup->val.group);
+ }
+ printf(" ...\n"
+ "}\n");
+}
+
+/* the main program... */
+int main(int argc,char *argv[])
+{
+ struct __netgrent netgroupresult;
+ char buffer[1024];
+ enum nss_status res;
+ int errnocp;
+
+ /* test {set,get,end}netgrent() */
+ printf("\nTEST {set,get,end}netgrent()\n");
+ res=_nss_ldap_setnetgrent("westcomp",&netgroupresult);
+ printf("status=%s\n",nssstatus(res));
+ while ((_nss_ldap_getnetgrent_r(&netgroupresult,buffer,1024,&errnocp))==NSS_STATUS_SUCCESS)
+ {
+ printf("status=%s\n",nssstatus(res));
+ printnetgroup(&netgroupresult);
+ }
+ printf("status=%s\n",nssstatus(res));
+ printf("errno=%d:%s\n",(int)errnocp,strerror(errnocp));
+ res=_nss_ldap_endnetgrent(&netgroupresult);
+ printf("status=%s\n",nssstatus(res));
+
+ return 0;
+}
diff --git a/tests/test_networks.c b/tests/test_networks.c
new file mode 100644
index 0000000..6cc41b2
--- /dev/null
+++ b/tests/test_networks.c
@@ -0,0 +1,113 @@
+/*
+ test_networks.c - simple tests of developed nss code
+
+ Copyright (C) 2006 West Consulting
+ Copyright (C) 2006 Arthur de Jong
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+*/
+
+#include <string.h>
+#include <stdio.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
+
+#include "nss/prototypes.h"
+
+static char *nssstatus(enum nss_status retv)
+{
+ switch(retv)
+ {
+ case NSS_STATUS_TRYAGAIN: return "NSS_STATUS_TRYAGAIN";
+ case NSS_STATUS_UNAVAIL: return "NSS_STATUS_UNAVAIL";
+ case NSS_STATUS_NOTFOUND: return "NSS_STATUS_NOTFOUND";
+ case NSS_STATUS_SUCCESS: return "NSS_STATUS_SUCCESS";
+ case NSS_STATUS_RETURN: return "NSS_STATUS_RETURN";
+ default: return "NSS_STATUS_**ILLEGAL**";
+ }
+}
+
+static void printnetwork(struct netent *network)
+{
+ int i;
+ printf("struct netent {\n"
+ " n_name=\"%s\",\n",
+ network->n_name);
+ for (i=0;network->n_aliases[i]!=NULL;i++)
+ printf(" n_aliases[%d]=\"%s\",\n",
+ i,network->n_aliases[i]);
+ printf(" n_aliases[%d]=NULL,\n",i);
+ if (network->n_addrtype==AF_INET)
+ printf(" n_addrtype=AF_INET,\n");
+ else if (network->n_addrtype==AF_INET6)
+ printf(" n_addrtype=AF_INET6,\n");
+ else
+ printf(" n_addrtype=%d,\n",network->n_addrtype);
+ printf(" n_net=%s\n"
+ "}\n",inet_ntoa(inet_makeaddr(network->n_net,0)));
+}
+
+/* the main program... */
+int main(int argc,char *argv[])
+{
+ struct netent netresult;
+ char buffer[1024];
+ enum nss_status res;
+ int errnocp,h_errnocp;
+
+ /* test getnetbyname() */
+ printf("\nTEST getnetbyname()\n");
+ res=_nss_ldap_getnetbyname_r("west",&netresult,buffer,1024,&errnocp,&h_errnocp);
+ printf("status=%s\n",nssstatus(res));
+ if (res==NSS_STATUS_SUCCESS)
+ printnetwork(&netresult);
+ else
+ {
+ printf("errno=%d:%s\n",(int)errnocp,strerror(errnocp));
+ printf("h_errno=%d:%s\n",(int)h_errnocp,hstrerror(h_errnocp));
+ }
+
+ /* test getnetbyaddr() */
+ printf("\nTEST getnetbyaddr()\n");
+ res=_nss_ldap_getnetbyaddr_r(inet_network("192.43.210.0"),AF_INET,&netresult,buffer,1024,&errnocp,&h_errnocp);
+ printf("status=%s\n",nssstatus(res));
+ if (res==NSS_STATUS_SUCCESS)
+ printnetwork(&netresult);
+ else
+ {
+ printf("errno=%d:%s\n",(int)errnocp,strerror(errnocp));
+ printf("h_errno=%d:%s\n",(int)h_errnocp,hstrerror(h_errnocp));
+ }
+
+ /* test {set,get,end}netent() */
+ printf("\nTEST {set,get,end}netent()\n");
+ res=_nss_ldap_setnetent(1);
+ printf("status=%s\n",nssstatus(res));
+ while ((res=_nss_ldap_getnetent_r(&netresult,buffer,1024,&errnocp,&h_errnocp))==NSS_STATUS_SUCCESS)
+ {
+ printf("status=%s\n",nssstatus(res));
+ printnetwork(&netresult);
+ }
+ printf("status=%s\n",nssstatus(res));
+ printf("errno=%d:%s\n",(int)errnocp,strerror(errnocp));
+ printf("h_errno=%d:%s\n",(int)h_errnocp,hstrerror(h_errnocp));
+ res=_nss_ldap_endnetent();
+ printf("status=%s\n",nssstatus(res));
+
+ return 0;
+}
diff --git a/tests/test_passwd.c b/tests/test_passwd.c
new file mode 100644
index 0000000..c37e5d6
--- /dev/null
+++ b/tests/test_passwd.c
@@ -0,0 +1,112 @@
+/*
+ test_passwd.c - simple tests of developed nss code
+
+ Copyright (C) 2006 West Consulting
+ Copyright (C) 2006 Arthur de Jong
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+*/
+
+#include "config.h"
+
+#include <string.h>
+#include <stdio.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
+
+#include "nss/prototypes.h"
+
+static char *nssstatus(enum nss_status retv)
+{
+ switch(retv)
+ {
+ case NSS_STATUS_TRYAGAIN: return "NSS_STATUS_TRYAGAIN";
+ case NSS_STATUS_UNAVAIL: return "NSS_STATUS_UNAVAIL";
+ case NSS_STATUS_NOTFOUND: return "NSS_STATUS_NOTFOUND";
+ case NSS_STATUS_SUCCESS: return "NSS_STATUS_SUCCESS";
+ case NSS_STATUS_RETURN: return "NSS_STATUS_RETURN";
+ default: return "NSS_STATUS_**ILLEGAL**";
+ }
+}
+
+static void printpasswd(struct passwd *pw)
+{
+ printf("struct passwd {\n"
+ " pw_name=\"%s\",\n"
+ " pw_passwd=\"%s\",\n"
+ " pw_uid=%d,\n"
+ " pw_gid=%d,\n"
+ " pw_gecos=\"%s\",\n"
+ " pw_dir=\"%s\",\n"
+ " pw_shell=\"%s\"\n"
+ "}\n",pw->pw_name,pw->pw_passwd,
+ (int)(pw->pw_uid),(int)(pw->pw_gid),
+ pw->pw_gecos,pw->pw_dir,pw->pw_shell);
+}
+
+/* the main program... */
+int main(int argc,char *argv[])
+{
+ struct passwd passwdresult;
+ char buffer[1024];
+ enum nss_status res;
+ int errnocp;
+
+ /* test getpwnam() */
+ printf("\nTEST getpwnam()\n");
+ res=_nss_ldap_getpwnam_r("arthur",&passwdresult,buffer,1024,&errnocp);
+ printf("status=%s\n",nssstatus(res));
+ if (res==NSS_STATUS_SUCCESS)
+ printpasswd(&passwdresult);
+ else
+ printf("errno=%d:%s\n",(int)errnocp,strerror(errnocp));
+
+ /* test getpwnam() with non-existing user */
+ printf("\nTEST getpwnam() with non-existing user\n");
+ res=_nss_ldap_getpwnam_r("nonexist",&passwdresult,buffer,1024,&errnocp);
+ printf("status=%s\n",nssstatus(res));
+ if (res==NSS_STATUS_SUCCESS)
+ printpasswd(&passwdresult);
+ else
+ printf("errno=%d:%s\n",(int)errnocp,strerror(errnocp));
+
+ /* test getpwuid() */
+ printf("\nTEST getpwuid()\n");
+ res=_nss_ldap_getpwuid_r(1004,&passwdresult,buffer,1024,&errnocp);
+ printf("status=%s\n",nssstatus(res));
+ if (res==NSS_STATUS_SUCCESS)
+ printpasswd(&passwdresult);
+ else
+ printf("errno=%d:%s\n",(int)errnocp,strerror(errnocp));
+
+ /* test {set,get,end}pwent() */
+ printf("\nTEST {set,get,end}pwent()\n");
+ res=_nss_ldap_setpwent(1);
+ printf("status=%s\n",nssstatus(res));
+ while ((res=_nss_ldap_getpwent_r(&passwdresult,buffer,1024,&errnocp))==NSS_STATUS_SUCCESS)
+ {
+ printf("status=%s\n",nssstatus(res));
+ printpasswd(&passwdresult);
+ }
+ printf("status=%s\n",nssstatus(res));
+ printf("errno=%d:%s\n",(int)errnocp,strerror(errnocp));
+ res=_nss_ldap_endpwent();
+ printf("status=%s\n",nssstatus(res));
+
+ return 0;
+}
diff --git a/tests/test_protocols.c b/tests/test_protocols.c
new file mode 100644
index 0000000..cfcf413
--- /dev/null
+++ b/tests/test_protocols.c
@@ -0,0 +1,102 @@
+/*
+ test_protocols.c - simple tests of developed nss code
+
+ Copyright (C) 2006 West Consulting
+ Copyright (C) 2006 Arthur de Jong
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+*/
+
+#include "config.h"
+
+#include <string.h>
+#include <stdio.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
+
+#include "nss/prototypes.h"
+
+static char *nssstatus(enum nss_status retv)
+{
+ switch(retv)
+ {
+ case NSS_STATUS_TRYAGAIN: return "NSS_STATUS_TRYAGAIN";
+ case NSS_STATUS_UNAVAIL: return "NSS_STATUS_UNAVAIL";
+ case NSS_STATUS_NOTFOUND: return "NSS_STATUS_NOTFOUND";
+ case NSS_STATUS_SUCCESS: return "NSS_STATUS_SUCCESS";
+ case NSS_STATUS_RETURN: return "NSS_STATUS_RETURN";
+ default: return "NSS_STATUS_**ILLEGAL**";
+ }
+}
+
+static void printproto(struct protoent *protocol)
+{
+ int i;
+ printf("struct protoent {\n"
+ " p_name=\"%s\",\n",
+ protocol->p_name);
+ for (i=0;protocol->p_aliases[i]!=NULL;i++)
+ printf(" p_aliases[%d]=\"%s\",\n",
+ i,protocol->p_aliases[i]);
+ printf(" p_aliases[%d]=NULL,\n"
+ " p_proto=%d\n"
+ "}\n",i,(int)(protocol->p_proto));
+}
+
+/* the main program... */
+int main(int argc,char *argv[])
+{
+ struct protoent protoresult;
+ char buffer[1024];
+ enum nss_status res;
+ int errnocp;
+
+ /* test getprotobyname() */
+ printf("\nTEST getprotobyname()\n");
+ res=_nss_ldap_getprotobyname_r("foo",&protoresult,buffer,1024,&errnocp);
+ printf("status=%s\n",nssstatus(res));
+ if (res==NSS_STATUS_SUCCESS)
+ printproto(&protoresult);
+ else
+ printf("errno=%d:%s\n",(int)errnocp,strerror(errnocp));
+
+ /* test getprotobynumber() */
+ printf("\nTEST getprotobynumber()\n");
+ res=_nss_ldap_getprotobynumber_r(10,&protoresult,buffer,1024,&errnocp);
+ printf("status=%s\n",nssstatus(res));
+ if (res==NSS_STATUS_SUCCESS)
+ printproto(&protoresult);
+ else
+ printf("errno=%d:%s\n",(int)errnocp,strerror(errnocp));
+
+ /* test {set,get,end}protoent() */
+ printf("\nTEST {set,get,end}protoent()\n");
+ res=_nss_ldap_setprotoent(1);
+ printf("status=%s\n",nssstatus(res));
+ while ((res=_nss_ldap_getprotoent_r(&protoresult,buffer,1024,&errnocp))==NSS_STATUS_SUCCESS)
+ {
+ printf("status=%s\n",nssstatus(res));
+ printproto(&protoresult);
+ }
+ printf("status=%s\n",nssstatus(res));
+ printf("errno=%d:%s\n",(int)errnocp,strerror(errnocp));
+ res=_nss_ldap_endprotoent();
+ printf("status=%s\n",nssstatus(res));
+
+ return 0;
+}
diff --git a/tests/test_rpc.c b/tests/test_rpc.c
new file mode 100644
index 0000000..85de284
--- /dev/null
+++ b/tests/test_rpc.c
@@ -0,0 +1,102 @@
+/*
+ test_rpc.c - simple tests of developed nss code
+
+ Copyright (C) 2006 West Consulting
+ Copyright (C) 2006 Arthur de Jong
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+*/
+
+#include "config.h"
+
+#include <string.h>
+#include <stdio.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
+
+#include "nss/prototypes.h"
+
+static char *nssstatus(enum nss_status retv)
+{
+ switch(retv)
+ {
+ case NSS_STATUS_TRYAGAIN: return "NSS_STATUS_TRYAGAIN";
+ case NSS_STATUS_UNAVAIL: return "NSS_STATUS_UNAVAIL";
+ case NSS_STATUS_NOTFOUND: return "NSS_STATUS_NOTFOUND";
+ case NSS_STATUS_SUCCESS: return "NSS_STATUS_SUCCESS";
+ case NSS_STATUS_RETURN: return "NSS_STATUS_RETURN";
+ default: return "NSS_STATUS_**ILLEGAL**";
+ }
+}
+
+static void printrpc(struct rpcent *rpc)
+{
+ int i;
+ printf("struct rpcent {\n"
+ " r_name=\"%s\",\n",
+ rpc->r_name);
+ for (i=0;rpc->r_aliases[i]!=NULL;i++)
+ printf(" r_aliases[%d]=\"%s\",\n",
+ i,rpc->r_aliases[i]);
+ printf(" r_aliases[%d]=NULL,\n"
+ " r_number=%d\n"
+ "}\n",i,(int)(rpc->r_number));
+}
+
+/* the main program... */
+int main(int argc,char *argv[])
+{
+ struct rpcent rpcresult;
+ char buffer[1024];
+ enum nss_status res;
+ int errnocp;
+
+ /* test getrpcbyname() */
+ printf("\nTEST getrpcbyname()\n");
+ res=_nss_ldap_getrpcbyname_r("rpcfoo",&rpcresult,buffer,1024,&errnocp);
+ printf("status=%s\n",nssstatus(res));
+ if (res==NSS_STATUS_SUCCESS)
+ printrpc(&rpcresult);
+ else
+ printf("errno=%d:%s\n",(int)errnocp,strerror(errnocp));
+
+ /* test getrpcbynumber() */
+ printf("\nTEST getrpcbynumber()\n");
+ res=_nss_ldap_getrpcbynumber_r(7899,&rpcresult,buffer,1024,&errnocp);
+ printf("status=%s\n",nssstatus(res));
+ if (res==NSS_STATUS_SUCCESS)
+ printrpc(&rpcresult);
+ else
+ printf("errno=%d:%s\n",(int)errnocp,strerror(errnocp));
+
+ /* test {set,get,end}rpcent() */
+ printf("\nTEST {set,get,end}rpcent()\n");
+ res=_nss_ldap_setrpcent(1);
+ printf("status=%s\n",nssstatus(res));
+ while ((res=_nss_ldap_getrpcent_r(&rpcresult,buffer,1024,&errnocp))==NSS_STATUS_SUCCESS)
+ {
+ printf("status=%s\n",nssstatus(res));
+ printrpc(&rpcresult);
+ }
+ printf("status=%s\n",nssstatus(res));
+ printf("errno=%d:%s\n",(int)errnocp,strerror(errnocp));
+ res=_nss_ldap_endrpcent();
+ printf("status=%s\n",nssstatus(res));
+
+ return 0;
+}
diff --git a/tests/test_services.c b/tests/test_services.c
new file mode 100644
index 0000000..75cc612
--- /dev/null
+++ b/tests/test_services.c
@@ -0,0 +1,104 @@
+/*
+ test_services.c - simple tests of developed nss code
+
+ Copyright (C) 2006 West Consulting
+ Copyright (C) 2006 Arthur de Jong
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+*/
+
+#include "config.h"
+
+#include <string.h>
+#include <stdio.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
+
+#include "nss/prototypes.h"
+
+static char *nssstatus(enum nss_status retv)
+{
+ switch(retv)
+ {
+ case NSS_STATUS_TRYAGAIN: return "NSS_STATUS_TRYAGAIN";
+ case NSS_STATUS_UNAVAIL: return "NSS_STATUS_UNAVAIL";
+ case NSS_STATUS_NOTFOUND: return "NSS_STATUS_NOTFOUND";
+ case NSS_STATUS_SUCCESS: return "NSS_STATUS_SUCCESS";
+ case NSS_STATUS_RETURN: return "NSS_STATUS_RETURN";
+ default: return "NSS_STATUS_**ILLEGAL**";
+ }
+}
+
+static void printserv(struct servent *serv)
+{
+ int i;
+ printf("struct servent {\n"
+ " s_name=\"%s\",\n",
+ serv->s_name);
+ for (i=0;serv->s_aliases[i]!=NULL;i++)
+ printf(" s_aliases[%d]=\"%s\",\n",
+ i,serv->s_aliases[i]);
+ printf(" s_aliases[%d]=NULL,\n"
+ " s_port=%d,\n"
+ " s_proto=\"%s\"\n"
+ "}\n",i,(int)(ntohs(serv->s_port)),
+ serv->s_proto);
+}
+
+/* the main program... */
+int main(int argc,char *argv[])
+{
+ struct servent servresult;
+ char buffer[1024];
+ enum nss_status res;
+ int errnocp;
+
+ /* test getservbyname() */
+ printf("\nTEST getservbyname()\n");
+ res=_nss_ldap_getservbyname_r("srvfoo","udp",&servresult,buffer,1024,&errnocp);
+ printf("status=%s\n",nssstatus(res));
+ if (res==NSS_STATUS_SUCCESS)
+ printserv(&servresult);
+ else
+ printf("errno=%d:%s\n",(int)errnocp,strerror(errnocp));
+
+ /* test getservbyport() */
+ printf("\nTEST getservbyport()\n");
+ res=_nss_ldap_getservbyport_r(ntohs(9988),NULL,&servresult,buffer,1024,&errnocp);
+ printf("status=%s\n",nssstatus(res));
+ if (res==NSS_STATUS_SUCCESS)
+ printserv(&servresult);
+ else
+ printf("errno=%d:%s\n",(int)errnocp,strerror(errnocp));
+
+ /* test {set,get,end}servent() */
+ printf("\nTEST {set,get,end}servent()\n");
+ res=_nss_ldap_setservent(1);
+ printf("status=%s\n",nssstatus(res));
+ while ((res=_nss_ldap_getservent_r(&servresult,buffer,1024,&errnocp))==NSS_STATUS_SUCCESS)
+ {
+ printf("status=%s\n",nssstatus(res));
+ printserv(&servresult);
+ }
+ printf("status=%s\n",nssstatus(res));
+ printf("errno=%d:%s\n",(int)errnocp,strerror(errnocp));
+ res=_nss_ldap_endservent();
+ printf("status=%s\n",nssstatus(res));
+
+ return 0;
+}
diff --git a/tests/test_shadow.c b/tests/test_shadow.c
new file mode 100644
index 0000000..88cbba0
--- /dev/null
+++ b/tests/test_shadow.c
@@ -0,0 +1,97 @@
+/*
+ test_shadow.c - simple tests of developed nss code
+
+ Copyright (C) 2006 West Consulting
+ Copyright (C) 2006 Arthur de Jong
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; if not, write to the Free
+ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ MA 02110-1301 USA
+*/
+
+#include "config.h"
+
+#include <string.h>
+#include <stdio.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
+
+#include "nss/prototypes.h"
+
+static char *nssstatus(enum nss_status retv)
+{
+ switch(retv)
+ {
+ case NSS_STATUS_TRYAGAIN: return "NSS_STATUS_TRYAGAIN";
+ case NSS_STATUS_UNAVAIL: return "NSS_STATUS_UNAVAIL";
+ case NSS_STATUS_NOTFOUND: return "NSS_STATUS_NOTFOUND";
+ case NSS_STATUS_SUCCESS: return "NSS_STATUS_SUCCESS";
+ case NSS_STATUS_RETURN: return "NSS_STATUS_RETURN";
+ default: return "NSS_STATUS_**ILLEGAL**";
+ }
+}
+
+static void printshadow(struct spwd *shadow)
+{
+ printf("struct spwd {\n"
+ " sp_namp=\"%s\",\n"
+ " sp_pwdp=\"%s\",\n"
+ " sp_lstchg=%ld,\n"
+ " sp_min=%ld,\n"
+ " sp_max=%ld,\n"
+ " sp_warn=%ld,\n"
+ " sp_inact=%ld,\n"
+ " sp_expire=%ld,\n"
+ " sp_flag=%lu\n"
+ "}\n",
+ shadow->sp_namp,shadow->sp_pwdp,shadow->sp_lstchg,
+ shadow->sp_min,shadow->sp_max,shadow->sp_warn,
+ shadow->sp_inact,shadow->sp_expire,shadow->sp_flag);
+}
+
+/* the main program... */
+int main(int argc,char *argv[])
+{
+ struct spwd shadowresult;
+ char buffer[1024];
+ enum nss_status res;
+ int errnocp;
+
+ /* test getspnam() */
+ printf("\nTEST getspnam()\n");
+ res=_nss_ldap_getspnam_r("arthur",&shadowresult,buffer,1024,&errnocp);
+ printf("status=%s\n",nssstatus(res));
+ if (res==NSS_STATUS_SUCCESS)
+ printshadow(&shadowresult);
+ else
+ printf("errno=%d:%s\n",(int)errnocp,strerror(errnocp));
+
+ /* test {set,get,end}spent() */
+ printf("\nTEST {set,get,end}spent()\n");
+ res=_nss_ldap_setspent(1);
+ printf("status=%s\n",nssstatus(res));
+ while ((res=_nss_ldap_getspent_r(&shadowresult,buffer,1024,&errnocp))==NSS_STATUS_SUCCESS)
+ {
+ printf("status=%s\n",nssstatus(res));
+ printshadow(&shadowresult);
+ }
+ printf("status=%s\n",nssstatus(res));
+ printf("errno=%d:%s\n",(int)errnocp,strerror(errnocp));
+ res=_nss_ldap_endspent();
+ printf("status=%s\n",nssstatus(res));
+
+ return 0;
+}
diff --git a/testnss.c b/tests/testnss.c
index 50b36c8..50b36c8 100644
--- a/testnss.c
+++ b/tests/testnss.c