lists.arthurdejong.org
RSS feed

nss-pam-ldapd commit: r1236 - in nss-pam-ldapd-solaris: . nss

[Date Prev][Date Next] [Thread Prev][Thread Next]

nss-pam-ldapd commit: r1236 - in nss-pam-ldapd-solaris: . nss



Author: arthur
Date: Sun Oct  3 23:57:11 2010
New Revision: 1236
URL: http://arthurdejong.org/viewvc/nss-pam-ldapd?view=rev&revision=1236

Log:
first attempt to split Solaris and Glibc code more and determine NSS flavour in 
configure script

Deleted:
   nss-pam-ldapd-solaris/nss/ldap-nss.h
Modified:
   nss-pam-ldapd-solaris/configure.ac
   nss-pam-ldapd-solaris/nss/aliases.c
   nss-pam-ldapd-solaris/nss/common.c
   nss-pam-ldapd-solaris/nss/common.h
   nss-pam-ldapd-solaris/nss/ethers.c
   nss-pam-ldapd-solaris/nss/group.c
   nss-pam-ldapd-solaris/nss/hosts.c
   nss-pam-ldapd-solaris/nss/netgroup.c
   nss-pam-ldapd-solaris/nss/networks.c
   nss-pam-ldapd-solaris/nss/passwd.c
   nss-pam-ldapd-solaris/nss/protocols.c
   nss-pam-ldapd-solaris/nss/prototypes.h
   nss-pam-ldapd-solaris/nss/rpc.c
   nss-pam-ldapd-solaris/nss/services.c
   nss-pam-ldapd-solaris/nss/shadow.c

Modified: nss-pam-ldapd-solaris/configure.ac
==============================================================================
--- nss-pam-ldapd-solaris/configure.ac  Sat Oct  2 21:19:00 2010        (r1235)
+++ nss-pam-ldapd-solaris/configure.ac  Sun Oct  3 23:57:11 2010        (r1236)
@@ -217,11 +217,20 @@
 AC_SUBST(PAM_SECLIB_DIR)
 
 # the SONAME to use for the NSS module
+AC_MSG_CHECKING([name of NSS module])
 AC_ARG_WITH(nss-ldap-soname,
             AS_HELP_STRING([--with-nss-ldap-soname=SONAME],
-                           [name of NSS module @<:@libnss_ldap.so.2@:>@]),
+                           [name of NSS module @<:@auto@:>@]),
             [ NSS_LDAP_SONAME="$with_nss_ldap_soname" ],
-            [ NSS_LDAP_SONAME="libnss_ldap.so.2" ])
+            [ NSS_LDAP_SONAME="auto" ])
+if test "x$NSS_LDAP_SONAME" = "xauto"
+then
+  case "$target_os" in
+    solaris*) NSS_LDAP_SONAME="nss_ldap.so.1" ;;
+    *)        NSS_LDAP_SONAME="libnss_ldap.so.2" ;;
+  esac
+fi
+AC_MSG_RESULT($NSS_LDAP_SONAME)
 AC_DEFINE_UNQUOTED(NSS_LDAP_SONAME,"$NSS_LDAP_SONAME",[The SONAME of the NSS 
library module.])
 AC_SUBST(NSS_LDAP_SONAME)
 
@@ -335,15 +344,44 @@
       #include <rpc/rpcent.h>
       #endif])
 
-  # check for a definition of enum nss_status
-  AC_CHECK_TYPES(enum nss_status,,,[
+  # check for a definition of enum nss_status and nss_backend_t
+  AC_CHECK_TYPES([enum nss_status,nss_backend_t],,,[
       #ifdef HAVE_NSS_H
       #include <nss.h>
       #endif
       #ifdef HAVE_NSS_COMMON_H
       #include <nss_common.h>
+      #endif
+      #ifdef HAVE_NSS_DBDEFS_H
+      #include <nss_dbdefs.h>
+      #endif
+      #ifdef HAVE_NSSWITCH_H
+      #include <nsswitch.h>
+      #endif
+      #ifdef HAVE_IRS_NSS_H
+      #include "irs-nss.h"
       #endif])
 
+  # check which NSS flavour to build
+  AC_MSG_CHECKING([which NSS flavour to build])
+  AC_ARG_WITH(nss-flavour,
+              AS_HELP_STRING([--with-nss-flavour=auto|glibc|solaris],
+                             [the libc flavour to build our NSS module for 
@<:@auto@:>@]),,
+              with_nss_flavour=auto)
+  if test "x$with_nss_flavour" = "xauto"
+  then
+    # do the guessing game
+    case "$target_os" in
+      solaris*) with_nss_flavour=solaris ;;
+      *)        with_nss_flavour=glibc ;;
+    esac
+  fi
+  AC_MSG_RESULT($with_nss_flavour)
+  case "$with_nss_flavour" in
+    glibc)   AC_DEFINE(NSS_FLAVOUR_GLIBC,1,[Whether to use the Glibc NSS 
interface flavour.]) ;;
+    solaris) AC_DEFINE(NSS_FLAVOUR_SOLARIS,1,[Whether to use the Solaris NSS 
interface flavour.]) ;;
+  esac
+
   # check which module source files to use
   AC_MSG_CHECKING([which NSS maps to build])
   if test "x$with_nss_ldap_maps" = "xall"
@@ -616,23 +654,19 @@
   fi
   nss_ldap_so_LDFLAGS="-Bdirect -z nodelete -Bdynamic -M 
\$(srcdir)/exports.solaris -G"
   pam_ldap_so_LDFLAGS="-Bdirect -z nodelete -Bdynamic -M 
\$(srcdir)/exports.solaris -G"
-  NSS_LDAP_SONAME="nss_ldap.so.1"
   pam_ldap_so_VERSIONED="pam_ldap.so.1"
   TARGET_OS="SUNOS" ;;
 linux*) nss_ldap_so_LDFLAGS="-shared -Wl,-Bdynamic 
-Wl,--version-script,\$(srcdir)/exports.linux"
   pam_ldap_so_LDFLAGS="-shared -Wl,-Bdynamic 
-Wl,--version-script,\$(srcdir)/exports.linux"
-  NSS_LDAP_SONAME="libnss_ldap.so.2"
   pam_ldap_so_VERSIONED="pam_ldap.so"
   TARGET_OS="LINUX" ;;
 *) nss_ldap_so_LDFLAGS="-shared -Wl,-Bdynamic"
    pam_ldap_so_LDFLAGS="-shared -Wl,-Bdynamic"
-  NSS_LDAP_SONAME="nss_ldap.so.1"
   pam_ldap_so_VERSIONED="pam_ldap.so" ;;
 esac
 
 AC_SUBST(nss_ldap_so_LD)
 AC_SUBST(nss_ldap_so_LDFLAGS)
-AC_SUBST(NSS_LDAP_SONAME)
 
 AC_SUBST(pam_ldap_so_LD)
 AC_SUBST(pam_ldap_so_LDFLAGS)

Modified: nss-pam-ldapd-solaris/nss/aliases.c
==============================================================================
--- nss-pam-ldapd-solaris/nss/aliases.c Sat Oct  2 21:19:00 2010        (r1235)
+++ nss-pam-ldapd-solaris/nss/aliases.c Sun Oct  3 23:57:11 2010        (r1236)
@@ -50,9 +50,10 @@
         const char *name,struct aliasent *result,
         char *buffer,size_t buflen,int *errnop)
 {
-  NSS_BYNAME(NSLCD_ACTION_ALIAS_BYNAME,
+  NSS_BYNAME(NSLCD_ACTION_ALIAS_BYNAME,buffer,buflen,
              name,
              read_aliasent(fp,result,buffer,buflen,errnop));
+  return retv;
 }
 
 /* thread-local file pointer to an ongoing request */
@@ -65,8 +66,9 @@
 
 nss_status_t _nss_ldap_getaliasent_r(struct aliasent *result,char 
*buffer,size_t buflen,int *errnop)
 {
-  NSS_GETENT(aliasentfp,NSLCD_ACTION_ALIAS_ALL,
+  NSS_GETENT(aliasentfp,NSLCD_ACTION_ALIAS_ALL,buffer,buflen,
              read_aliasent(aliasentfp,result,buffer,buflen,errnop));
+  return retv;
 }
 
 nss_status_t _nss_ldap_endaliasent(void)

Modified: nss-pam-ldapd-solaris/nss/common.c
==============================================================================
--- nss-pam-ldapd-solaris/nss/common.c  Sat Oct  2 21:19:00 2010        (r1235)
+++ nss-pam-ldapd-solaris/nss/common.c  Sun Oct  3 23:57:11 2010        (r1236)
@@ -44,29 +44,8 @@
 /* flag used to disable NSS lookups using this module */
 int _nss_ldap_enablelookups=1;
 
-#ifdef HAVE_NSSWITCH_H
+#ifdef NSS_FLAVOUR_SOLARIS
 /* Adapted from PADL */
-/*
- *Default destructor.
- *The entry point for this function is the destructor in the dispatch
- *table for the switch. Thus,it's safe to grab the mutex from this
- *function.
- */
-nss_status_t _nss_ldap_default_destr(nss_backend_t *be,void *args)
-{
-  /* Ditch the backend. */
-  free(be);
-  return NSS_STATUS_SUCCESS;
-}
-
-/*
- *This is the default "constructor" which gets called from each
- *constructor,in the NSS dispatch table.
- */
-nss_status_t _nss_ldap_default_constr(nss_ldap_backend_t *be)
-{
-  return NSS_STATUS_SUCCESS;
-}
 
 /* add a nested netgroup or group to the namelist */
 nss_status_t _nss_ldap_namelist_push(struct name_list **head,const char *name)
@@ -129,4 +108,4 @@
   return found;
 }
 
-#endif /* HAVE_NSSWITCH_H */
+#endif /* NSS_FLAVOUR_SOLARIS */

Modified: nss-pam-ldapd-solaris/nss/common.h
==============================================================================
--- nss-pam-ldapd-solaris/nss/common.h  Sat Oct  2 21:19:00 2010        (r1235)
+++ nss-pam-ldapd-solaris/nss/common.h  Sun Oct  3 23:57:11 2010        (r1236)
@@ -31,18 +31,17 @@
 #include "compat/attrs.h"
 #include "compat/nss_compat.h"
 
-#ifdef HAVE_NSSWITCH_H
-#include "ldap-nss.h"
-#endif /* HAVE_NSSWITCH_H */
-
-#ifdef HAVE_NSSWITCH_H
 /* Adapted from PADL */
 /* Routines for managing namelists */
+struct name_list
+{
+  char *name;
+  struct name_list *next;
+};
 nss_status_t _nss_ldap_namelist_push(struct name_list **head,const char *name);
 void _nss_ldap_namelist_pop(struct name_list **head);
 int _nss_ldap_namelist_find(struct name_list *head,const char *netgroup);
 void _nss_ldap_namelist_destroy(struct name_list **head);
-#endif /* HAVE_NSSWITCH_H */
 
 /* These are macros for handling read and write problems, they are
    NSS specific due to the return code so are defined here. They
@@ -93,7 +92,7 @@
    the result structure, the user buffer with length and the
    errno to return. This macro should be called through some of
    the customized ones below. */
-#define NSS_BYGEN(action,writefn,readfn) \
+#define NSS_BYGEN(action,buffer,buflen,writefn,readfn) \
   TFILE *fp; \
   int32_t tmpint32; \
   nss_status_t retv; \
@@ -112,23 +111,22 @@
   retv=readfn; \
   /* close socket and we're done */ \
   if ((retv==NSS_STATUS_SUCCESS)||(retv==NSS_STATUS_TRYAGAIN)) \
-    (void)tio_close(fp); \
-  return retv;
+    (void)tio_close(fp);
 
 /* This macro can be used to generate a get..byname() function
    body. */
-#define NSS_BYNAME(action,name,readfn) \
-  NSS_BYGEN(action,WRITE_STRING(fp,name),readfn)
+#define NSS_BYNAME(action,buffer,buflen,name,readfn) \
+  NSS_BYGEN(action,buffer,buflen,WRITE_STRING(fp,name),readfn)
 
 /* This macro can be used to generate a get..by..() function
    body where the value that is the key has the specified type. */
-#define NSS_BYTYPE(action,val,type,readfn) \
-  NSS_BYGEN(action,WRITE_TYPE(fp,val,type),readfn)
+#define NSS_BYTYPE(action,buffer,buflen,val,type,readfn) \
+  NSS_BYGEN(action,buffer,buflen,WRITE_TYPE(fp,val,type),readfn)
 
 /* This macro can be used to generate a get..by..() function
    body where the value should be passed as an int32_t. */
-#define NSS_BYINT32(action,val,readfn) \
-  NSS_BYGEN(action,WRITE_INT32(fp,val),readfn)
+#define NSS_BYINT32(action,buffer,buflen,val,readfn) \
+  NSS_BYGEN(action,buffer,buflen,WRITE_INT32(fp,val),readfn)
 
 /* This macro generates a simple setent() function body. This closes any
    open streams so that NSS_GETENT() can open a new file. */
@@ -145,7 +143,7 @@
 /* This macro generates a getent() function body. If the stream is not yet
    open, a new one is opened, a request is written and a check is done for
    a response header. A single entry is read with the readfn() function. */
-#define NSS_GETENT(fp,action,readfn) \
+#define NSS_GETENT(fp,action,buffer,buflen,readfn) \
   int32_t tmpint32; \
   nss_status_t retv; \
   if (!_nss_ldap_enablelookups) \
@@ -188,8 +186,7 @@
     } \
   } \
   else if (retv!=NSS_STATUS_SUCCESS) \
-    fp=NULL; /* file should be closed by now */ \
-  return retv;
+    fp=NULL; /* file should be closed by now */
 
 /* This macro generates a endent() function body. This just closes
    the stream. */

Modified: nss-pam-ldapd-solaris/nss/ethers.c
==============================================================================
--- nss-pam-ldapd-solaris/nss/ethers.c  Sat Oct  2 21:19:00 2010        (r1235)
+++ nss-pam-ldapd-solaris/nss/ethers.c  Sun Oct  3 23:57:11 2010        (r1236)
@@ -41,106 +41,95 @@
   return NSS_STATUS_SUCCESS;
 }
 
+#ifdef NSS_FLAVOUR_GLIBC
+
 /* map a hostname to the corresponding ethernet address */
-#ifdef HAVE_NSSWITCH_H
-nss_status_t _nss_nslcd_gethostton_r(
-#else /* not HAVE_NSSWITCH_H */
 nss_status_t _nss_ldap_gethostton_r(
-#endif /* HAVE_NSSWITCH_H */
         const char *name,struct etherent *result,
         char *buffer,size_t buflen,int *errnop)
 {
-  NSS_BYNAME(NSLCD_ACTION_ETHER_BYNAME,
+  NSS_BYNAME(NSLCD_ACTION_ETHER_BYNAME,buffer,buflen,
              name,
              read_etherent(fp,result,buffer,buflen,errnop));
+  return retv;
 }
 
 /* map an ethernet address to the corresponding hostname */
-#ifdef HAVE_NSSWITCH_H
-nss_status_t _nss_nslcd_getntohost_r(
-#else /* not HAVE_NSSWITCH_H */
 nss_status_t _nss_ldap_getntohost_r(
-#endif /* HAVE_NSSWITCH_H */
         const struct ether_addr *addr,struct etherent *result,
         char *buffer,size_t buflen,int *errnop)
 {
-  NSS_BYTYPE(NSLCD_ACTION_ETHER_BYETHER,
+  NSS_BYTYPE(NSLCD_ACTION_ETHER_BYETHER,buffer,buflen,
              *addr,uint8_t[6],
              read_etherent(fp,result,buffer,buflen,errnop));
+  return retv;
 }
 
 /* thread-local file pointer to an ongoing request */
 static __thread TFILE *etherentfp;
 
-#ifdef HAVE_NSSWITCH_H
-static nss_status_t _nss_ldap_setetherent(
-        nss_backend_t *be,void *args)
-#else /* not HAVE_NSSWITCH_H */
 nss_status_t _nss_ldap_setetherent(int UNUSED(stayopen))
-#endif /* HAVE_NSSWITCH_H */
 {
   NSS_SETENT(etherentfp);
 }
 
-#ifdef HAVE_NSSWITCH_H
-nss_status_t _nss_nslcd_getetherent_r(
-#else /* not HAVE_NSSWITCH_H */
 nss_status_t _nss_ldap_getetherent_r(
-#endif /* HAVE_NSSWITCH_H */
         struct etherent *result,
         char *buffer,size_t buflen,int *errnop)
 {
-  NSS_GETENT(etherentfp,NSLCD_ACTION_ETHER_ALL,
+  NSS_GETENT(etherentfp,NSLCD_ACTION_ETHER_ALL,buffer,buflen,
              read_etherent(etherentfp,result,buffer,buflen,errnop));
+  return retv;
 }
 
-#ifdef HAVE_NSSWITCH_H
-nss_status_t _nss_ldap_endetherent(nss_backend_t *be,void *args)
-#else /* not HAVE_NSSWITCH_H */
 nss_status_t _nss_ldap_endetherent(void)
-#endif /* HAVE_NSSWITCH_H */
 {
   NSS_ENDENT(etherentfp);
 }
 
-#ifdef HAVE_NSSWITCH_H
+#endif /* NSS_FLAVOUR_GLIBC */
+
+#ifdef NSS_FLAVOUR_SOLARIS
+
+#define NSS_BUFLEN_ETHERS 1024
 
-/* Solaris wrapper around _nss_nslcd_gethsotton_r */
-static nss_status_t _nss_ldap_gethostton_r(nss_backend_t *be,void *args)
+#define errnop &errno
+
+/* map a hostname to the corresponding ethernet address */
+static nss_status_t _xnss_ldap_gethostton_r(nss_backend_t *UNUSED(be),void 
*args)
 {
   struct etherent result;
   char buffer[NSS_BUFLEN_ETHERS];
-  nss_status_t status;
-  char *name=(char *)(NSS_ARGS(args)->key.name);
-  status=_nss_nslcd_gethostton_r(name,&result,buffer,sizeof(buffer),&errno);
-  if (status==NSS_STATUS_SUCCESS)
+  const char *name=(NSS_ARGS(args)->key.name);
+  NSS_BYNAME(NSLCD_ACTION_ETHER_BYNAME,buffer,sizeof(buffer),
+             name,
+             read_etherent(fp,&result,buffer,sizeof(buffer),&errno));
+  if (retv==NSS_STATUS_SUCCESS)
   {
-   /*  if (NSS_ARGS(args)->buf.buffer!=NULL) { */
     if (NSS_ARGS(args)->buf.result==NULL)
     {
       strcpy(NSS_ARGS(args)->buf.buffer,ether_ntoa(&result.e_addr));
       NSS_ARGS(args)->buf.buflen=strlen(NSS_ARGS(args)->buf.buffer);
       NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.buffer;
       NSS_ARGS(args)->returnlen=strlen(NSS_ARGS(args)->buf.buffer);
-      return status;
+      return retv;
     }
     memcpy(NSS_ARGS(args)->buf.result,&result.e_addr,sizeof(result.e_addr));
     NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.result;
   }
-  return status;
+  return retv;
 }
 
-/* Solaris wrapper around _nss_nslcd_getntohost_r */
-static nss_status_t _nss_ldap_getntohost_r(nss_backend_t *be,void *args)
+/* map an ethernet address to the corresponding hostname */
+static nss_status_t _xnss_ldap_getntohost_r(nss_backend_t *UNUSED(be),void 
*args)
 {
   struct etherent result;
-  struct ether_addr *addr;
+  struct ether_addr *addr=(struct ether_addr *)(NSS_ARGS(args)->key.ether);
   char buffer[NSS_BUFLEN_ETHERS];
-  size_t buflen=sizeof(buffer);
-  nss_status_t status;
-  addr=(struct ether_addr *)(NSS_ARGS(args)->key.ether);
-  status=_nss_nslcd_getntohost_r(addr,&result,buffer,buflen,&errno);
-  if (status==NSS_STATUS_SUCCESS)
+  NSS_BYTYPE(NSLCD_ACTION_ETHER_BYETHER,buffer,sizeof(buffer),
+             *addr,uint8_t[6],
+             read_etherent(fp,&result,buffer,sizeof(buffer),&errno));
+  if (retv==NSS_STATUS_SUCCESS)
   {
     if (NSS_ARGS(args)->buf.buffer!=NULL)
     {
@@ -151,61 +140,68 @@
       sprintf(NSS_ARGS(args)->buf.buffer,"%s 
%s",ether_ntoa(addr),result.e_name);
       NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.buffer;
       NSS_ARGS(args)->returnlen=strlen(NSS_ARGS(args)->buf.buffer);
-      return status;
+      return retv;
     }
     memcpy(NSS_ARGS(args)->buf.buffer,result.e_name,strlen(result.e_name)+1);
     
NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.result=NSS_ARGS(args)->buf.buffer;
-    NSS_ARGS(args)->buf.buflen=strlen(result.e_name);
+    NSS_ARGS(args)->buf.buflen=strlen(result.e_name); /* ?? */
   }
   else
   {
     NSS_ARGS(args)->returnval=NULL;
   }
-  return status;
+  return retv;
+}
+
+static nss_status_t _xnss_ldap_setetherent(nss_backend_t *UNUSED(be),void 
*UNUSED(args))
+{
+  NSS_SETENT(etherentfp);
 }
 
-static nss_status_t _nss_ldap_getetherent_r(nss_backend_t *be,void *args)
+static nss_status_t _xnss_ldap_getetherent_r(nss_backend_t *UNUSED(be),void 
*args)
 {
   /* TODO: cns3 uses struct ether,verify */
   struct etherent result;
-  char *buffer;
-  size_t buflen;
-  int errnop;
-  nss_status_t status;
-  buffer=NSS_ARGS(args)->buf.buffer;
-  buflen=NSS_ARGS(args)->buf.buflen;
-  status=_nss_nslcd_getetherent_r(&result,buffer,buflen,&errnop);
-  if (status==NSS_STATUS_SUCCESS)
+  char *buffer=NSS_ARGS(args)->buf.buffer;
+  size_t buflen=NSS_ARGS(args)->buf.buflen;
+  NSS_GETENT(etherentfp,NSLCD_ACTION_ETHER_ALL,buffer,buflen,
+             read_etherent(etherentfp,&result,buffer,buflen,&errno));
+  if (retv==NSS_STATUS_SUCCESS)
   {
     memcpy(NSS_ARGS(args)->buf.result,&result.e_addr,sizeof(result.e_addr));
     NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.result;
   }
   else
     NSS_ARGS(args)->returnval=NULL;
-  return status;
+  return retv;
 }
 
-static nss_status_t _nss_ldap_ethers_destr(nss_backend_t *ether_context,void 
*args)
+static nss_status_t _xnss_ldap_endetherent(nss_backend_t *UNUSED(be),void 
*UNUSED(args))
 {
-  return _nss_ldap_default_destr(ether_context,args);
+  NSS_ENDENT(etherentfp);
+}
+
+static nss_status_t _xnss_ldap_ethers_destr(nss_backend_t *be,void 
*UNUSED(args))
+{
+  free(be);
+  return NSS_STATUS_SUCCESS;
 }
 
 static nss_backend_op_t ethers_ops[]={
-  _nss_ldap_ethers_destr,
-  _nss_ldap_gethostton_r,
-  _nss_ldap_getntohost_r
+  _xnss_ldap_ethers_destr,
+  _xnss_ldap_gethostton_r,
+  _xnss_ldap_getntohost_r
 };
 
-nss_backend_t *_nss_ldap_ethers_constr(const char *db_name,const char 
*src_name,const char *cfg_args)
+nss_backend_t *_nss_ldap_ethers_constr(const char *UNUSED(db_name),
+      const char *UNUSED(src_name),const char *UNUSED(cfg_args))
 {
-  nss_ldap_backend_t *be;
-  if (!(be=(nss_ldap_backend_t *)malloc(sizeof(*be))))
+  nss_backend_t *be;
+  if (!(be=(nss_backend_t *)malloc(sizeof(*be))))
     return NULL;
   be->ops=ethers_ops;
   be->n_ops=sizeof(ethers_ops)/sizeof(nss_backend_op_t);
-  if (_nss_ldap_default_constr(be)!=NSS_STATUS_SUCCESS)
-    return NULL;
-  return (nss_backend_t *)be;
+  return be;
 }
 
-#endif /* HAVE_NSSWITCH_H */
+#endif /* NSS_FLAVOUR_SOLARIS */

Modified: nss-pam-ldapd-solaris/nss/group.c
==============================================================================
--- nss-pam-ldapd-solaris/nss/group.c   Sat Oct  2 21:19:00 2010        (r1235)
+++ nss-pam-ldapd-solaris/nss/group.c   Sun Oct  3 23:57:11 2010        (r1236)
@@ -48,9 +48,7 @@
    gids of these groups to the list */
 static nss_status_t read_gids(
         TFILE *fp,gid_t skipgroup,long int *start,
-#ifndef HAVE_NSSWITCH_H
         long int *size,
-#endif /* HAVE_NSSWITCH_H */
         gid_t **groupsp,long int limit,int *errnop)
 {
   int32_t res=(int32_t)NSLCD_RESULT_BEGIN;
@@ -76,7 +74,7 @@
       if ( (limit>0) && (*start>=limit) )
         return NSS_STATUS_TRYAGAIN;
       /* check if our buffer is large enough */
-#ifndef HAVE_NSSWITCH_H
+#ifdef NSS_FLAVOUR_GLIBC
       if ((*start)>=(*size))
       {
         /* for some reason Glibc expects us to grow the array (completely
@@ -92,8 +90,8 @@
         *groupsp=newgroups;
         *size=newsize;
       }
+#endif /* NSS_FLAVOUR_GLIBC */
       /* add gid to list */
-#endif /* HAVE_NSSWITCH_H */
       (*groupsp)[(*start)++]=gid;
     }
     /* read next response code
@@ -105,30 +103,47 @@
   return NSS_STATUS_SUCCESS;
 }
 
-#ifdef HAVE_NSSWITCH_H
-nss_status_t _nss_nslcd_getgrnam_r(
-#else /* not HAVE_NSSWITCH_H */
+#ifdef NSS_FLAVOUR_GLIBC
+
 nss_status_t _nss_ldap_getgrnam_r(
-#endif /* HAVE_NSSWITCH_H */
         const char *name,struct group *result,char *buffer,
         size_t buflen,int *errnop)
 {
-  NSS_BYNAME(NSLCD_ACTION_GROUP_BYNAME,
+  NSS_BYNAME(NSLCD_ACTION_GROUP_BYNAME,buffer,buflen,
              name,
              read_group(fp,result,buffer,buflen,errnop));
+  return retv;
 }
 
-#ifdef HAVE_NSSWITCH_H
-nss_status_t _nss_nslcd_getgrgid_r(
-#else /* not HAVE_NSSWITCH_H */
 nss_status_t _nss_ldap_getgrgid_r(
-#endif /* HAVE_NSSWITCH_H */
         gid_t gid,struct group *result,char *buffer,
         size_t buflen,int *errnop)
 {
-  NSS_BYTYPE(NSLCD_ACTION_GROUP_BYGID,
+  NSS_BYTYPE(NSLCD_ACTION_GROUP_BYGID,buffer,buflen,
              gid,gid_t,
              read_group(fp,result,buffer,buflen,errnop));
+  return retv;
+}
+
+/* thread-local file pointer to an ongoing request */
+static __thread TFILE *grentfp;
+
+nss_status_t _nss_ldap_setgrent(int UNUSED(stayopen))
+{
+  NSS_SETENT(grentfp);
+}
+
+nss_status_t _nss_ldap_getgrent_r(
+        struct group *result,char *buffer,size_t buflen,int *errnop)
+{
+  NSS_GETENT(grentfp,NSLCD_ACTION_GROUP_ALL,buffer,buflen,
+             read_group(grentfp,result,buffer,buflen,errnop));
+  return retv;
+}
+
+nss_status_t _nss_ldap_endgrent(void)
+{
+  NSS_ENDENT(grentfp);
 }
 
 /* this function returns a list of groups, documentation for the
@@ -145,77 +160,38 @@
 */
 nss_status_t _nss_ldap_initgroups_dyn(
         const char *user,gid_t skipgroup,long int *start,
-#ifndef HAVE_NSSWITCH_H
         long int *size,
-#endif /* HAVE_NSSWITCH_H */
         gid_t **groupsp,long int limit,int *errnop)
 {
-#ifdef HAVE_NSSWITCH_H
-   long int buffer_size=limit;
-   long int *size=&buffer_size;
-#endif /* HAVE_NSSWITCH_H */
-/* temporarily map the buffer and buflen names so the check in NSS_BYNAME
-   for validity of the buffer works (renaming the parameters may cause
-   confusion) */
-#define buffer groupsp
-#define buflen *size
-#ifdef HAVE_NSSWITCH_H
-  NSS_BYNAME(NSLCD_ACTION_GROUP_BYMEMBER,
-             user,
-             read_gids(fp,skipgroup,start,groupsp,limit,errnop));
-#else  /* not HAVE_NSSWITCH_H */
-  NSS_BYNAME(NSLCD_ACTION_GROUP_BYMEMBER,
+  NSS_BYNAME(NSLCD_ACTION_GROUP_BYMEMBER,groupsp,*size,
              user,
              read_gids(fp,skipgroup,start,size,groupsp,limit,errnop));
-#endif /* not HAVE_NSSWITCH_H */
-#undef buffer
-#undef buflen
+  return retv;
 }
 
-/* thread-local file pointer to an ongoing request */
-static __thread TFILE *grentfp;
-
-#ifdef HAVE_NSSWITCH_H
-nss_status_t _nss_ldap_setgrent(nss_backend_t *gr_context,void *args)
-#else /* not HAVE_NSSWITCH_H */
-nss_status_t _nss_ldap_setgrent(int UNUSED(stayopen))
-#endif /* HAVE_NSSWITCH_H */
-{
-  NSS_SETENT(grentfp);
-}
+#endif /* NSS_FLAVOUR_GLIBC */
 
-#ifdef HAVE_NSSWITCH_H
-nss_status_t _nss_nslcd_getgrent_r(
-#else /* not HAVE_NSSWITCH_H */
-nss_status_t _nss_ldap_getgrent_r(
-#endif /* HAVE_NSSWITCH_H */
-        struct group *result,char *buffer,size_t buflen,int *errnop)
-{
-  NSS_GETENT(grentfp,NSLCD_ACTION_GROUP_ALL,
-             read_group(grentfp,result,buffer,buflen,errnop));
-}
+#ifdef NSS_FLAVOUR_SOLARIS
 
-#ifdef HAVE_NSSWITCH_H
-nss_status_t _nss_ldap_endgrent(nss_backend_t *gr_context,void *args)
-#else /* not HAVE_NSSWITCH_H */
-nss_status_t _nss_ldap_endgrent(void)
-#endif /* HAVE_NSSWITCH_H */
+static nss_status_t _nss_nslcd_getgrnam_r(
+        const char *name,struct group *result,char *buffer,
+        size_t buflen,int *errnop)
 {
-  NSS_ENDENT(grentfp);
+  NSS_BYNAME(NSLCD_ACTION_GROUP_BYNAME,buffer,buflen,
+             name,
+             read_group(fp,result,buffer,buflen,errnop));
+  return retv;
 }
 
-#ifdef HAVE_NSSWITCH_H
-
-static nss_status_t _nss_ldap_getgrnam_r(nss_backend_t *be,void *args)
+static nss_status_t _xnss_ldap_getgrnam_r(nss_backend_t *UNUSED(be),void *args)
 {
-  char *name=(char *)NSS_ARGS(args)->key.name;
   struct group priv_gr;
   struct group *gr=NSS_ARGS(args)->buf.result?(struct group 
*)NSS_ARGS(args)->buf.result:&priv_gr;
   char *data_ptr;
   char *buffer=NSS_ARGS(args)->buf.buffer;
   size_t buflen=NSS_ARGS(args)->buf.buflen;
   nss_status_t status;
-  status=_nss_nslcd_getgrnam_r(name,gr,buffer,buflen,&errno);
+  
status=_nss_nslcd_getgrnam_r(NSS_ARGS(args)->key.name,gr,buffer,buflen,&errno);
   if (status!=NSS_STATUS_SUCCESS)
     return status;
   if (!NSS_ARGS(args)->buf.result)
@@ -245,7 +221,17 @@
   return status;
 }
 
-static nss_status_t _nss_ldap_getgrgid_r(nss_backend_t *be,void *args)
+static nss_status_t _nss_nslcd_getgrgid_r(
+        gid_t gid,struct group *result,char *buffer,
+        size_t buflen,int *errnop)
+{
+  NSS_BYTYPE(NSLCD_ACTION_GROUP_BYGID,buffer,buflen,
+             gid,gid_t,
+             read_group(fp,result,buffer,buflen,errnop));
+  return retv;
+}
+
+static nss_status_t _xnss_ldap_getgrgid_r(nss_backend_t *UNUSED(be),void *args)
 {
   gid_t gid=NSS_ARGS(args)->key.gid;
   struct group priv_gr;
@@ -284,7 +270,20 @@
   return status;
 }
 
-static nss_status_t _nss_ldap_getgrent_r(nss_backend_t *gr_context,void *args)
+static nss_status_t _xnss_ldap_setgrent(nss_backend_t *UNUSED(be),void 
*UNUSED(args))
+{
+  NSS_SETENT(grentfp);
+}
+
+static nss_status_t _nss_nslcd_getgrent_r(
+        struct group *result,char *buffer,size_t buflen,int *errnop)
+{
+  NSS_GETENT(grentfp,NSLCD_ACTION_GROUP_ALL,buffer,buflen,
+             read_group(grentfp,result,buffer,buflen,errnop));
+  return retv;
+}
+
+static nss_status_t _xnss_ldap_getgrent_r(nss_backend_t *UNUSED(be),void *args)
 {
   struct group priv_gr;
   struct group *gr=NSS_ARGS(args)->buf.result?(struct group 
*)NSS_ARGS(args)->buf.result:&priv_gr;
@@ -292,12 +291,9 @@
   char *buffer=NSS_ARGS(args)->buf.buffer;
   size_t buflen=NSS_ARGS(args)->buf.buflen;
   nss_status_t status;
-
   status=_nss_nslcd_getgrent_r(gr,buffer,buflen,&errno);
-
   if (status!=NSS_STATUS_SUCCESS)
     return status;
-
   if (!NSS_ARGS(args)->buf.result)
   {
     /* result==NULL, return file format */
@@ -315,7 +311,6 @@
     }
     strcpy(NSS_ARGS(args)->buf.buffer,data_ptr);
     free(data_ptr);
-
     NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.buffer;
     NSS_ARGS(args)->returnlen=strlen(NSS_ARGS(args)->buf.buffer);
   }
@@ -326,58 +321,77 @@
   return status;
 }
 
-static nss_status_t _nss_ldap_group_destr(nss_backend_t *gr_context,void *args)
+static nss_status_t _xnss_ldap_endgrent(nss_backend_t *UNUSED(be),void 
*UNUSED(args))
 {
-  return _nss_ldap_default_destr(gr_context,args);
+  NSS_ENDENT(grentfp);
 }
 
-static nss_status_t _nss_ldap_getgroupsbymember_r(nss_backend_t 
*gr_context,void *args)
+/* this function returns a list of groups, documentation for the
+   interface is scarce (any pointers are welcome) but this is
+   what is assumed the parameters mean:
+
+   user      IN     - the user name to find groups for
+   skipgroup IN     - a group to not include in the list
+   *start    IN/OUT - where to write in the array, is incremented
+   **groupsp IN/OUT - pointer to the array of returned groupids
+   limit     IN     - the maxium size of the array
+   *errnop   OUT    - for returning errno
+*/
+static nss_status_t _xnss_ldap_initgroups_dyn(
+        const char *user,gid_t skipgroup,long int *start,
+        gid_t **groupsp,long int limit,int *errnop)
+{
+  NSS_BYNAME(NSLCD_ACTION_GROUP_BYMEMBER,groupsp,limit,
+             user,
+             read_gids(fp,skipgroup,start,&limit,groupsp,limit,errnop));
+  return retv;
+}
+
+static nss_status_t _xnss_ldap_getgroupsbymember_r(nss_backend_t 
*UNUSED(be),void *args)
 {
   struct nss_groupsbymem *argp=(struct nss_groupsbymem *)args;
-  char *user=(char *)argp->username;
   nss_status_t status;
-  long int limit=(long int) argp->maxgids;
-  long int start=(long int) argp->numgids;
+  long int limit=(long int)argp->maxgids;
+  long int start=(long int)argp->numgids;
   gid_t skipgroup;
-  int i;
-
-  if (start > 0)
+  if (start>0)
     skipgroup=argp->gid_array[0];
-
-  status=_nss_ldap_initgroups_dyn(
-                user,
-                (start > 0)?skipgroup:-1,
+  status=_xnss_ldap_initgroups_dyn(
+                argp->username,
+                (start>0)?skipgroup:(gid_t)-1,
                 &start,
                 (gid_t **)&argp->gid_array,
                 limit,
                 &errno);
   argp->numgids=(int)start;
-
   return status;
 }
 
+static nss_status_t _xnss_ldap_group_destr(nss_backend_t *be,void 
*UNUSED(args))
+{
+  free(be);
+  return NSS_STATUS_SUCCESS;
+}
+
 static nss_backend_op_t group_ops[]={
-  _nss_ldap_group_destr,
-  _nss_ldap_endgrent,
-  _nss_ldap_setgrent,
-  _nss_ldap_getgrent_r,
-  _nss_ldap_getgrnam_r,
-  _nss_ldap_getgrgid_r,
-  _nss_ldap_getgroupsbymember_r
+  _xnss_ldap_group_destr,
+  _xnss_ldap_endgrent,
+  _xnss_ldap_setgrent,
+  _xnss_ldap_getgrent_r,
+  _xnss_ldap_getgrnam_r,
+  _xnss_ldap_getgrgid_r,
+  _xnss_ldap_getgroupsbymember_r
 };
 
-nss_backend_t *_nss_ldap_group_constr(const char *db_name,
-                        const char *src_name,const char *cfg_args)
+nss_backend_t *_nss_ldap_group_constr(const char *UNUSED(db_name),
+                        const char *UNUSED(src_name),const char 
*UNUSED(cfg_args))
 {
-  nss_ldap_backend_t *be;
-  if (!(be=(nss_ldap_backend_t *)malloc(sizeof(*be))))
+  nss_backend_t *be;
+  if (!(be=(nss_backend_t *)malloc(sizeof(*be))))
     return NULL;
   be->ops=group_ops;
   be->n_ops=sizeof(group_ops)/sizeof(nss_backend_op_t);
-  /* a NOOP at the moment */
-  if (_nss_ldap_default_constr(be)!=NSS_STATUS_SUCCESS)
-    return NULL;
   return (nss_backend_t *)be;
 }
 
-#endif /* HAVE_NSSWITCH_H */
+#endif /* NSS_FLAVOUR_SOLARIS */

Modified: nss-pam-ldapd-solaris/nss/hosts.c
==============================================================================
--- nss-pam-ldapd-solaris/nss/hosts.c   Sat Oct  2 21:19:00 2010        (r1235)
+++ nss-pam-ldapd-solaris/nss/hosts.c   Sun Oct  3 23:57:11 2010        (r1236)
@@ -25,6 +25,9 @@
 
 #include <string.h>
 #include <errno.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
 
 #include "prototypes.h"
 #include "common.h"
@@ -162,6 +165,14 @@
   return NSS_STATUS_SUCCESS;
 }
 
+/* write an address value */
+#define WRITE_ADDRESS(fp,af,len,addr) \
+  WRITE_INT32(fp,af); \
+  WRITE_INT32(fp,len); \
+  WRITE(fp,addr,len);
+
+#ifdef NSS_FLAVOUR_GLIBC
+
 /* this function looks up a single host entry and returns all the addresses
    associated with the host in a single address familiy
    name            - IN  - hostname to lookup
@@ -173,93 +184,20 @@
         const char *name,int af,struct hostent *result,
         char *buffer,size_t buflen,int *errnop,int *h_errnop)
 {
-  NSS_BYNAME(NSLCD_ACTION_HOST_BYNAME,
+  NSS_BYNAME(NSLCD_ACTION_HOST_BYNAME,buffer,buflen,
              name,
              
read_hostent_erronempty(fp,af,result,buffer,buflen,errnop,h_errnop));
+  return retv;
 }
 
 /* this function just calls the gethostbyname2() variant with the address
    familiy set */
-#ifdef HAVE_NSSWITCH_H
-static nss_status_t _nss_ldap_gethostbyname_r(nss_backend_t *be,void *args)
-{
-  struct hostent priv_host;
-  struct hostent 
*host=NSS_ARGS(args)->buf.result?NSS_ARGS(args)->buf.result:&priv_host;
-  char *data_ptr;
-  char *buffer=NSS_ARGS(args)->buf.buffer;
-  size_t buflen=NSS_ARGS(args)->buf.buflen;
-  int h_errno;
-  nss_status_t status;
-  status=_nss_ldap_gethostbyname2_r(
-                NSS_ARGS(args)->key.name,
-                AF_INET,
-                host,
-                NSS_ARGS(args)->buf.buffer,
-                NSS_ARGS(args)->buf.buflen,
-                &errno,&h_errno);
-
-  if (status!=NSS_STATUS_SUCCESS)
-  {
-    NSS_ARGS(args)->h_errno=h_errno;
-    return status;
-  }
-
-  if (!NSS_ARGS(args)->buf.result)
-  {
-    /* result==NULL, return file format */
-    data_ptr=(char *)malloc(buflen);
-    if (host->h_addr_list)
-    {
-      int i;
-      struct in_addr in;
-      (void)memcpy(&in.s_addr,host->h_addr_list[0],sizeof(in.s_addr));
-      sprintf(data_ptr,"%s %s",inet_ntoa(in),host->h_name);
-      if (host->h_aliases)
-      {
-        int j;
-        for (j=0; host->h_aliases[j]; j++)
-        {
-          strcat(data_ptr,"  ");
-          strcat(data_ptr,host->h_aliases[j]);
-        }
-      }
-      for (i=1; host->h_addr_list[i]; i++)
-      {
-        (void) memcpy(&in.s_addr,host->h_addr_list[i],sizeof(in.s_addr));
-        strcat(data_ptr,"\n");
-        strcat(data_ptr,inet_ntoa(in));
-        strcat(data_ptr," ");
-        strcat(data_ptr,host->h_name);
-        /* TODO: aliases only supplied to the first address */
-        /* need review */
-      }
-    }
-    strcpy(buffer,data_ptr);
-    free(data_ptr);
-    NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.buffer;
-    NSS_ARGS(args)->returnlen=strlen(NSS_ARGS(args)->buf.buffer);
-  }
-  else
-  { /* NSS_ARGS(args)->buf.result!=NULL */
-    NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.result;
-  }
-  NSS_ARGS(args)->h_errno=h_errno;
-  return status;
-}
-#else /* not HAVE_NSSWITCH_H */
 nss_status_t _nss_ldap_gethostbyname_r(
         const char *name,struct hostent *result,
         char *buffer,size_t buflen,int *errnop,int *h_errnop)
 {
   return 
_nss_ldap_gethostbyname2_r(name,AF_INET,result,buffer,buflen,errnop,h_errnop);
 }
-#endif /* HAVE_NSSWITCH_H */
-
-/* write an address value */
-#define WRITE_ADDRESS(fp,af,len,addr) \
-  WRITE_INT32(fp,af); \
-  WRITE_INT32(fp,len); \
-  WRITE(fp,addr,len);
 
 /* this function looks up a single host entry and returns all the addresses
    associated with the host in a single address familiy
@@ -269,88 +207,66 @@
    result          - OUT - entry found
    buffer,buflen   - OUT - buffer to store allocated stuff on
    errnop,h_errnop - OUT - for reporting errors */
-#ifdef HAVE_NSSWITCH_H
-nss_status_t _nss_nslcd_gethostbyaddr_r(
-#else /* not HAVE_NSSWITCH_H */
 nss_status_t _nss_ldap_gethostbyaddr_r(
-#endif /* HAVE_NSSWITCH_H */
         const void *addr,socklen_t len,int af,struct hostent *result,
         char *buffer,size_t buflen,int *errnop,int *h_errnop)
 {
-  NSS_BYGEN(NSLCD_ACTION_HOST_BYADDR,
+  NSS_BYGEN(NSLCD_ACTION_HOST_BYADDR,buffer,buflen,
             WRITE_ADDRESS(fp,af,len,addr),
             
read_hostent_erronempty(fp,af,result,buffer,buflen,errnop,h_errnop))
+  return retv;
 }
 
 /* thread-local file pointer to an ongoing request */
 static __thread TFILE *hostentfp;
 
-#ifdef HAVE_NSSWITCH_H
-nss_status_t _nss_ldap_sethostent(nss_backend_t *hosts_context,void *fakeargs)
-#else /* not HAVE_NSSWITCH_H */
 nss_status_t _nss_ldap_sethostent(int UNUSED(stayopen))
-#endif /* HAVE_NSSWITCH_H */
 {
   NSS_SETENT(hostentfp);
 }
 
 /* this function only returns addresses of the AF_INET address family */
-#ifdef HAVE_NSSWITCH_H
-nss_status_t _nss_nslcd_gethostent_r(
-#else /* not HAVE_NSSWITCH_H */
 nss_status_t _nss_ldap_gethostent_r(
-#endif /* HAVE_NSSWITCH_H */
         struct hostent *result,
         char *buffer,size_t buflen,int *errnop,int *h_errnop)
 {
-  NSS_GETENT(hostentfp,NSLCD_ACTION_HOST_ALL,
+  NSS_GETENT(hostentfp,NSLCD_ACTION_HOST_ALL,buffer,buflen,
              
read_hostent_nextonempty(hostentfp,AF_INET,result,buffer,buflen,errnop,h_errnop));
+  return retv;
 }
 
-#ifdef HAVE_NSSWITCH_H
-nss_status_t _nss_ldap_endhostent(nss_backend_t *hosts_context,void *fakeargs )
-#else /* not HAVE_NSSWITCH_H */
 nss_status_t _nss_ldap_endhostent(void)
-#endif /* HAVE_NSSWITCH_H */
 {
   NSS_ENDENT(hostentfp);
 }
 
-#ifdef HAVE_NSSWITCH_H
+#endif /* NSS_FLAVOUR_GLIBC */
 
-static nss_status_t _nss_ldap_gethostbyaddr_r(nss_backend_t *be,void *args)
+#ifdef NSS_FLAVOUR_SOLARIS
+
+/* hack to set the correct errno and h_errno */
+#define errnop &errno
+#define h_errnop &(NSS_ARGS(args)->h_errno)
+
+static nss_status_t _xnss_ldap_gethostbyname_r(nss_backend_t *UNUSED(be),void 
*args)
 {
-  struct in_addr iaddr;
-  int type;
   struct hostent priv_host;
   struct hostent 
*host=NSS_ARGS(args)->buf.result?NSS_ARGS(args)->buf.result:&priv_host;
   char *data_ptr;
-  char *buffer=NSS_ARGS(args)->buf.buffer;
-  size_t buflen=NSS_ARGS(args)->buf.buflen;
-  int h_errno;
-  nss_status_t status;
-  status=_nss_nslcd_gethostbyaddr_r(
-        NSS_ARGS(args)->key.hostaddr.addr,
-        NSS_ARGS(args)->key.hostaddr.len,
-        NSS_ARGS(args)->key.hostaddr.type,
-        host,
-        NSS_ARGS(args)->buf.buffer,
-        NSS_ARGS(args)->buf.buflen,
-        &errno,&h_errno);
-  if (status!=NSS_STATUS_SUCCESS)
-  {
-    NSS_ARGS(args)->h_errno=h_errno;
-    return status;
-  }
+  
NSS_BYNAME(NSLCD_ACTION_HOST_BYNAME,NSS_ARGS(args)->buf.buffer,NSS_ARGS(args)->buf.buflen,
+             NSS_ARGS(args)->key.name,
+             
read_hostent_erronempty(fp,AF_INET,host,NSS_ARGS(args)->buf.buffer,NSS_ARGS(args)->buf.buflen,&errno,h_errnop));
+  if (retv!=NSS_STATUS_SUCCESS)
+    return retv;
   if (!NSS_ARGS(args)->buf.result)
   {
     /* result==NULL, return file format */
-    data_ptr=(char *)malloc(buflen);
+    data_ptr=(char *)malloc(NSS_ARGS(args)->buf.buflen);
     if (host->h_addr_list)
     {
       int i;
       struct in_addr in;
-      (void) memcpy(&in.s_addr,host->h_addr_list[0],sizeof(in.s_addr));
+      (void)memcpy(&in.s_addr,host->h_addr_list[0],sizeof(in.s_addr));
       sprintf(data_ptr,"%s %s",inet_ntoa(in),host->h_name);
       if (host->h_aliases)
       {
@@ -372,7 +288,7 @@
         /* need review */
       }
     }
-    strcpy(buffer,data_ptr);
+    strcpy(NSS_ARGS(args)->buf.buffer,data_ptr);
     free(data_ptr);
     NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.buffer;
     NSS_ARGS(args)->returnlen=strlen(NSS_ARGS(args)->buf.buffer);
@@ -381,31 +297,83 @@
   { /* NSS_ARGS(args)->buf.result!=NULL */
     NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.result;
   }
-  NSS_ARGS(args)->h_errno=h_errno;
-  return status;
+  return retv;
 }
 
-/* this function only returns addresses of the AF_INET address family */
-static nss_status_t _nss_ldap_gethostent_r(nss_backend_t *hosts_context,void 
*args)
+static nss_status_t _xnss_ldap_gethostbyaddr_r(nss_backend_t *UNUSED(be),void 
*args)
 {
   struct hostent priv_host;
-  struct hostent *host=NSS_ARGS(args)->buf.result ?
-                        NSS_ARGS(args)->buf.result : &priv_host;
+  struct hostent 
*host=NSS_ARGS(args)->buf.result?NSS_ARGS(args)->buf.result:&priv_host;
   char *data_ptr;
-  char *buffer=NSS_ARGS(args)->buf.buffer;
-  size_t buflen=NSS_ARGS(args)->buf.buflen;
-  int h_errno;
-  nss_status_t status;
-  status=_nss_nslcd_gethostent_r(host,buffer,buflen,&errno,&h_errno);
-  if (status!=NSS_STATUS_SUCCESS)
+  
NSS_BYGEN(NSLCD_ACTION_HOST_BYADDR,NSS_ARGS(args)->buf.buffer,NSS_ARGS(args)->buf.buflen,
+            
WRITE_ADDRESS(fp,NSS_ARGS(args)->key.hostaddr.type,NSS_ARGS(args)->key.hostaddr.len,NSS_ARGS(args)->key.hostaddr.addr),
+            
read_hostent_erronempty(fp,NSS_ARGS(args)->key.hostaddr.type,host,NSS_ARGS(args)->buf.buffer,NSS_ARGS(args)->buf.buflen,&errno,h_errnop))
+
+
+  if (retv!=NSS_STATUS_SUCCESS)
+    return retv;
+  if (!NSS_ARGS(args)->buf.result)
   {
-    NSS_ARGS(args)->h_errno=h_errno;
-    return status;
+    /* result==NULL, return file format */
+    data_ptr=(char *)malloc(NSS_ARGS(args)->buf.buflen);
+    if (host->h_addr_list)
+    {
+      int i;
+      struct in_addr in;
+      (void)memcpy(&in.s_addr,host->h_addr_list[0],sizeof(in.s_addr));
+      sprintf(data_ptr,"%s %s",inet_ntoa(in),host->h_name);
+      if (host->h_aliases)
+      {
+        int j;
+        for (j=0;host->h_aliases[j];j++)
+        {
+          strcat(data_ptr,"  ");
+          strcat(data_ptr,host->h_aliases[j]);
+        }
+      }
+      for (i=1;host->h_addr_list[i];i++)
+      {
+        (void)memcpy(&in.s_addr,host->h_addr_list[i],sizeof(in.s_addr));
+        strcat(data_ptr,"\n");
+        strcat(data_ptr,inet_ntoa(in));
+        strcat(data_ptr," ");
+        strcat(data_ptr,host->h_name);
+        /* TODO: aliases only supplied to the first address */
+        /* need review */
+      }
+    }
+    strcpy(NSS_ARGS(args)->buf.buffer,data_ptr);
+    free(data_ptr);
+    NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.buffer;
+    NSS_ARGS(args)->returnlen=strlen(NSS_ARGS(args)->buf.buffer);
+  }
+  else
+  { /* NSS_ARGS(args)->buf.result!=NULL */
+    NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.result;
   }
+  return retv;
+}
+
+
+static nss_status_t _xnss_ldap_sethostent(nss_backend_t *UNUSED(be),void 
*UNUSED(args))
+{
+  NSS_SETENT(hostentfp);
+}
+
+/* this function only returns addresses of the AF_INET address family */
+static nss_status_t _xnss_ldap_gethostent_r(nss_backend_t *UNUSED(be),void 
*args)
+{
+  struct hostent priv_host;
+  struct hostent 
*host=NSS_ARGS(args)->buf.result?NSS_ARGS(args)->buf.result:&priv_host;
+  char *data_ptr;
+  
NSS_GETENT(hostentfp,NSLCD_ACTION_HOST_ALL,NSS_ARGS(args)->buf.buffer,NSS_ARGS(args)->buf.buflen,
+             
read_hostent_nextonempty(hostentfp,AF_INET,host,NSS_ARGS(args)->buf.buffer,NSS_ARGS(args)->buf.buflen,&errno,h_errnop));
+  if (retv!=NSS_STATUS_SUCCESS)
+    return retv;
   if (!NSS_ARGS(args)->buf.result)
   {
     /* result==NULL, return file format */
-    data_ptr=(char *)malloc(buflen);
+    data_ptr=(char *)malloc(NSS_ARGS(args)->buf.buflen);
     if (host->h_addr_list)
     {
       int i;
@@ -429,7 +397,7 @@
         /* need review */
       }
     }
-    strcpy(buffer,data_ptr);
+    strcpy(NSS_ARGS(args)->buf.buffer,data_ptr);
     free(data_ptr);
     NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.buffer;
     NSS_ARGS(args)->returnlen=strlen(NSS_ARGS(args)->buf.buffer);
@@ -438,35 +406,38 @@
   { /* NSS_ARGS(args)->buf.result!=NULL */
     NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.result;
   }
-  NSS_ARGS(args)->h_errno=h_errno;
-  return status;
+  return retv;
 }
 
-static nss_status_t _nss_ldap_hosts_destr(nss_backend_t *hosts_context,void 
*args)
+static nss_status_t _xnss_ldap_endhostent(nss_backend_t *UNUSED(be),void 
*UNUSED(args))
 {
-  return _nss_ldap_default_destr(hosts_context,args);
+  NSS_ENDENT(hostentfp);
+}
+
+static nss_status_t _xnss_ldap_hosts_destr(nss_backend_t *be,void 
*UNUSED(args))
+{
+  free(be);
+  return NSS_STATUS_SUCCESS;
 }
 
 static nss_backend_op_t host_ops[]={
-  _nss_ldap_hosts_destr,
-  _nss_ldap_endhostent,
-  _nss_ldap_sethostent,
-  _nss_ldap_gethostent_r,
-  _nss_ldap_gethostbyname_r,
-  _nss_ldap_gethostbyaddr_r
+  _xnss_ldap_hosts_destr,
+  _xnss_ldap_endhostent,
+  _xnss_ldap_sethostent,
+  _xnss_ldap_gethostent_r,
+  _xnss_ldap_gethostbyname_r,
+  _xnss_ldap_gethostbyaddr_r
 };
 
-nss_backend_t *_nss_ldap_hosts_constr(const char *db_name,
-                        const char *src_name,const char *cfg_args)
+nss_backend_t *_nss_ldap_hosts_constr(const char *UNUSED(db_name),
+                        const char *UNUSED(src_name),const char 
*UNUSED(cfg_args))
 {
-  nss_ldap_backend_t *be;
-  if (!(be=(nss_ldap_backend_t *)malloc(sizeof(*be))))
+  nss_backend_t *be;
+  if (!(be=(nss_backend_t *)malloc(sizeof(*be))))
     return NULL;
   be->ops=host_ops;
   be->n_ops=sizeof(host_ops)/sizeof(nss_backend_op_t);
-  if (_nss_ldap_default_constr(be)!=NSS_STATUS_SUCCESS)
-    return NULL;
   return (nss_backend_t *)be;
 }
 
-#endif /* HAVE_NSSWITCH_H */
+#endif /* NSS_FLAVOUR_SOLARIS */

Modified: nss-pam-ldapd-solaris/nss/netgroup.c
==============================================================================
--- nss-pam-ldapd-solaris/nss/netgroup.c        Sat Oct  2 21:19:00 2010        
(r1235)
+++ nss-pam-ldapd-solaris/nss/netgroup.c        Sun Oct  3 23:57:11 2010        
(r1236)
@@ -31,51 +31,6 @@
 #include "common.h"
 #include "compat/attrs.h"
 
-#ifdef HAVE_NSSWITCH_H
-#include <nss_common.h>
-#include <nss_dbdefs.h>
-#include <nsswitch.h>
-#endif /* HAVE_NSSWITCH_H */
-
-
-#ifdef HAVE_NSSWITCH_H
-
-static nss_backend_op_t netgroup_ops[];
-static nss_status_t _nss_ldap_netgroup_destr(nss_backend_t *_ngbe,void *args);
-
-/* find a netgroup that has not been traversed */
-static char *_nss_ldap_chase_netgroup(nss_ldap_netgr_backend_t *ngbe)
-{
-  nss_status_t status;
-  char *group=NULL;
-  int found=0;
-  if (!ngbe->needed_groups)
-  {
-   /* exhausted all netgroups */
-   return NULL;
-  }
-  while (ngbe->needed_groups&&!found)
-  {
-    if (_nss_ldap_namelist_find(ngbe->known_groups,
-                                ngbe->needed_groups->name))
-    {
-       /* netgroup seen before,ignore it */
-       _nss_ldap_namelist_pop(&ngbe->needed_groups);
-    }
-    else
-      found=1;
-  }
-  if (found)
-  {
-    group=strdup(ngbe->needed_groups->name);
-    status=_nss_ldap_namelist_push(&ngbe->known_groups,
-                                   ngbe->needed_groups->name);
-    _nss_ldap_namelist_pop(&ngbe->needed_groups);
-  }
-  return group;
-}
-#endif /* HAVE_NSSWITCH_H */
-
 /* we redefine this here because we need to return NSS_STATUS_RETURN
    instead of NSS_STATUS_NOTFOUND */
 #undef ERROR_OUT_NOSUCCESS
@@ -132,22 +87,12 @@
   return NSS_STATUS_SUCCESS;
 }
 
+#ifdef NSS_FLAVOUR_GLIBC
+
 /* thread-local file pointer to an ongoing request */
 static __thread TFILE *netgrentfp;
 
-#ifdef HAVE_NSSWITCH_H
-nss_status_t _nss_ldap_setnetgrent(nss_backend_t *be,void *_args)
-{
-  return NSS_STATUS_SUCCESS;
-}
-#endif /* HAVE_NSSWITCH_H */
-
-#ifdef HAVE_NSSWITCH_H
-nss_status_t _nss_nslcd_setnetgrent(
-#else /* not HAVE_NSSWITCH_H */
-nss_status_t _nss_ldap_setnetgrent(
-#endif /* HAVE_NSSWITCH_H */
-        const char *group,struct __netgrent UNUSED(* result))
+nss_status_t _nss_ldap_setnetgrent(const char *group,struct __netgrent 
UNUSED(* result))
 {
   /* we cannot use NSS_SETENT() here because we have a parameter that is only
      available in this function */
@@ -165,29 +110,105 @@
   return NSS_STATUS_SUCCESS;
 }
 
-#ifdef HAVE_NSSWITCH_H
-nss_status_t _nss_nslcd_getnetgrent_r(
-#else /* not HAVE_NSSWITCH_H */
-nss_status_t _nss_ldap_getnetgrent_r(
-#endif /* HAVE_NSSWITCH_H */
-        struct __netgrent *result,char *buffer,size_t buflen,int *errnop)
+nss_status_t _nss_ldap_getnetgrent_r(struct __netgrent *result,char 
*buffer,size_t buflen,int *errnop)
 {
-  NSS_GETENT(netgrentfp,NSLCD_ACTION_NETGROUP_BYNAME,
+  NSS_GETENT(netgrentfp,NSLCD_ACTION_NETGROUP_BYNAME,buffer,buflen,
              read_netgrent(netgrentfp,result,buffer,buflen,errnop));
+  return retv;
 }
 
-#ifdef HAVE_NSSWITCH_H
-nss_status_t _nss_ldap_endnetgrent(nss_backend_t *be,void *args)
-#else /* not HAVE_NSSWITCH_H */
 nss_status_t _nss_ldap_endnetgrent(struct __netgrent UNUSED(* result))
-#endif /* HAVE_NSSWITCH_H */
 {
   NSS_ENDENT(netgrentfp);
 }
 
-#ifdef HAVE_NSSWITCH_H
+#endif /* NSS_FLAVOUR_GLIBC */
+
+#ifdef NSS_FLAVOUR_SOLARIS
+
+/*
+ *thread specific context: result chain,and state data
+ */
+struct ent_context
+{
+   void *first_entry;
+   void *curr_entry;
+};
+typedef struct ent_context ent_context_t;
+
+struct nss_ldap_netgr_backend
+{
+  nss_backend_op_t *ops;
+  int n_ops;
+  ent_context_t *state;
+  struct name_list *known_groups; /* netgroups seen, for loop detection */
+  struct name_list *needed_groups; /* nested netgroups to chase */
+};
+typedef struct nss_ldap_netgr_backend nss_ldap_netgr_backend_t;
+
+static nss_status_t _xnss_ldap_setnetgrent(nss_backend_t *UNUSED(be),void 
*UNUSED(args))
+{
+  return NSS_STATUS_SUCCESS;
+}
+
+/* find a netgroup that has not been traversed */
+static char *_nss_ldap_chase_netgroup(nss_ldap_netgr_backend_t *ngbe)
+{
+  nss_status_t status;
+  char *group=NULL;
+  int found=0;
+  if (!ngbe->needed_groups)
+  {
+   /* exhausted all netgroups */
+   return NULL;
+  }
+  while (ngbe->needed_groups&&!found)
+  {
+    if (_nss_ldap_namelist_find(ngbe->known_groups,
+                                ngbe->needed_groups->name))
+    {
+       /* netgroup seen before,ignore it */
+       _nss_ldap_namelist_pop(&ngbe->needed_groups);
+    }
+    else
+      found=1;
+  }
+  if (found)
+  {
+    group=strdup(ngbe->needed_groups->name);
+    status=_nss_ldap_namelist_push(&ngbe->known_groups,
+                                   ngbe->needed_groups->name);
+    _nss_ldap_namelist_pop(&ngbe->needed_groups);
+  }
+  return group;
+}
+
+static nss_status_t _nss_nslcd_getnetgrent_r(struct __netgrent *result,char 
*buffer,size_t buflen,int *errnop)
+{
+  NSS_GETENT(netgrentfp,NSLCD_ACTION_NETGROUP_BYNAME,buffer,buflen,
+             read_netgrent(netgrentfp,result,buffer,buflen,errnop));
+  return retv;
+}
+
+static nss_status_t _nss_nslcd_setnetgrent(const char *group,struct __netgrent 
UNUSED(* result))
+{
+  /* we cannot use NSS_SETENT() here because we have a parameter that is only
+     available in this function */
+  int32_t tmpint32;
+  int errnocp;
+  int *errnop;
+  if (!_nss_ldap_enablelookups)
+    return NSS_STATUS_UNAVAIL;
+  errnop=&errnocp;
+  /* check parameter */
+  if ((group==NULL)||(group[0]=='\0'))
+    return NSS_STATUS_UNAVAIL;
+  /* open a new stream and write the request */
+  
NSLCD_REQUEST(netgrentfp,NSLCD_ACTION_NETGROUP_BYNAME,WRITE_STRING(netgrentfp,group));
+  return NSS_STATUS_SUCCESS;
+}
 
-nss_status_t _nss_ldap_getnetgrent_r(nss_backend_t *_be,void *_args)
+static nss_status_t _xnss_ldap_getnetgrent_r(nss_backend_t *_be,void *_args)
 {
   nss_ldap_netgr_backend_t *ngbe=(nss_ldap_netgr_backend_t *)_be;
   struct nss_getnetgrent_args *args=(struct nss_getnetgrent_args *)_args;
@@ -199,8 +220,7 @@
   args->status=NSS_NETGR_NO;
   while (!done)
   {
-    status=_nss_nslcd_getnetgrent_r(&result,args->buffer,args->buflen,
-                &err);
+    status=_nss_nslcd_getnetgrent_r(&result,args->buffer,args->buflen,&err);
     if (status!=NSS_STATUS_SUCCESS)
     {
       if (err==ENOENT)
@@ -264,7 +284,33 @@
   return status;
 }
 
-static nss_status_t _nss_ldap_netgr_set(nss_backend_t *be,void *_args)
+static nss_status_t _xnss_ldap_endnetgrent(nss_backend_t *UNUSED(be),void 
*UNUSED(args))
+{
+  NSS_ENDENT(netgrentfp);
+}
+
+static nss_status_t _xnss_ldap_netgroup_destr(nss_backend_t *be,void 
*UNUSED(args))
+{
+  nss_ldap_netgr_backend_t *ngbe=(nss_ldap_netgr_backend_t *)be;
+  /* free list of nested netgroups */
+  _nss_ldap_namelist_destroy(&ngbe->known_groups);
+  _nss_ldap_namelist_destroy(&ngbe->needed_groups);
+  free(ngbe);
+  return NSS_STATUS_SUCCESS;
+}
+
+static nss_status_t _xnss_ldap_netgr_set(nss_backend_t *be,void *_args);
+
+static nss_backend_op_t netgroup_ops[]={
+  _xnss_ldap_netgroup_destr,          /* NSS_DBOP_DESTRUCTOR */
+  _xnss_ldap_endnetgrent,             /* NSS_DBOP_ENDENT */
+  _xnss_ldap_setnetgrent,             /* NSS_DBOP_SETNET */
+  _xnss_ldap_getnetgrent_r,           /* NSS_DBOP_GETENT */
+  NULL,/* TODO:_nss_ldap_netgr_in,*/ /* NSS_DBOP_NETGROUP_IN */
+  _xnss_ldap_netgr_set                /* NSS_DBOP_NETGROUP_SET */
+};
+
+static nss_status_t _xnss_ldap_netgr_set(nss_backend_t *be,void *_args)
 {
   nss_status_t stat;
   struct nss_setnetgrent_args *args;
@@ -281,50 +327,26 @@
   ngbe->state=NULL;
   ngbe->known_groups=NULL;
   ngbe->needed_groups=NULL;
-  stat=_nss_ldap_default_constr((nss_ldap_backend_t *)ngbe);
-  if (stat!=NSS_STATUS_SUCCESS)
-  {
-    free(ngbe);
-    return stat;
-  }
   group=(char *)args->netgroup;
   stat=_nss_nslcd_setnetgrent(group,&result);
   if (stat!=NSS_STATUS_SUCCESS)
   {
-    _nss_ldap_default_destr((nss_backend_t *)ngbe,NULL);
+    free(be);
     return stat;
   }
   /* place the group name in known list */
   stat=_nss_ldap_namelist_push(&ngbe->known_groups,group);
   if (stat!=NSS_STATUS_SUCCESS)
   {
-    _nss_ldap_netgroup_destr((nss_backend_t *)ngbe,NULL);
+    _xnss_ldap_netgroup_destr((nss_backend_t *)ngbe,NULL);
     return stat;
   }
   args->iterator=(nss_backend_t *)ngbe;
   return stat;
 }
 
-static nss_status_t _nss_ldap_netgroup_destr(nss_backend_t *_ngbe,void *args)
-{
-  nss_ldap_netgr_backend_t *ngbe=(nss_ldap_netgr_backend_t *)_ngbe;
-  /* free list of nested netgroups */
-  _nss_ldap_namelist_destroy(&ngbe->known_groups);
-  _nss_ldap_namelist_destroy(&ngbe->needed_groups);
-  return _nss_ldap_default_destr(_ngbe,args);
-}
-
-static nss_backend_op_t netgroup_ops[]={
-  _nss_ldap_netgroup_destr,          /* NSS_DBOP_DESTRUCTOR */
-  _nss_ldap_endnetgrent,             /* NSS_DBOP_ENDENT */
-  _nss_ldap_setnetgrent,             /* NSS_DBOP_SETNET */
-  _nss_ldap_getnetgrent_r,           /* NSS_DBOP_GETENT */
-  NULL,/* TODO:_nss_ldap_netgr_in,*/ /* NSS_DBOP_NETGROUP_IN */
-  _nss_ldap_netgr_set                /* NSS_DBOP_NETGROUP_SET */
-};
-
-nss_backend_t *_nss_ldap_netgroup_constr(const char *db_name,
-                           const char *src_name,const char *cfg_args)
+nss_backend_t *_nss_ldap_netgroup_constr(const char *UNUSED(db_name),
+                           const char *UNUSED(src_name),const char 
*UNUSED(cfg_args))
 {
   nss_ldap_netgr_backend_t *be;
   if (!(be=(nss_ldap_netgr_backend_t *)malloc(sizeof(*be))))
@@ -333,12 +355,7 @@
   be->n_ops=sizeof(netgroup_ops)/sizeof(nss_backend_op_t);
   be->known_groups=NULL;
   be->needed_groups=NULL;
-  if (_nss_ldap_default_constr((nss_ldap_backend_t *)be)!=NSS_STATUS_SUCCESS)
-  {
-    free(be);
-    return NULL;
-  }
   return (nss_backend_t *)be;
 }
 
-#endif /* HAVE_NSSWITCH_H */
+#endif /* NSS_FLAVOUR_SOLARIS */

Modified: nss-pam-ldapd-solaris/nss/networks.c
==============================================================================
--- nss-pam-ldapd-solaris/nss/networks.c        Sat Oct  2 21:19:00 2010        
(r1235)
+++ nss-pam-ldapd-solaris/nss/networks.c        Sun Oct  3 23:57:11 2010        
(r1236)
@@ -25,6 +25,9 @@
 
 #include <string.h>
 #include <errno.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
 
 #include "prototypes.h"
 #include "common.h"
@@ -100,19 +103,6 @@
   return retv;
 }
 
-#ifdef HAVE_NSSWITCH_H
-nss_status_t _nss_nslcd_getnetbyname_r(
-#else /* not HAVE_NSSWITCH_H */
-nss_status_t _nss_ldap_getnetbyname_r(
-#endif /* HAVE_NSSWITCH_H */
-        const char *name,struct netent *result,char *buffer,
-        size_t buflen,int *errnop,int *h_errnop)
-{
-  NSS_BYNAME(NSLCD_ACTION_NETWORK_BYNAME,
-             name,
-             read_netent(fp,result,buffer,buflen,errnop,h_errnop));
-}
-
 /* write an address value */
 /* version 2.10 of glibc changed the address from network to host order
    (changelog entry 2009-07-01) */
@@ -121,56 +111,67 @@
   WRITE_INT32(fp,4); \
   WRITE_INT32(fp,htonl(addr));
 
+#ifdef NSS_FLAVOUR_GLIBC
+
+nss_status_t _nss_ldap_getnetbyname_r(
+        const char *name,struct netent *result,char *buffer,
+        size_t buflen,int *errnop,int *h_errnop)
+{
+  NSS_BYNAME(NSLCD_ACTION_NETWORK_BYNAME,buffer,buflen,
+             name,
+             read_netent(fp,result,buffer,buflen,errnop,h_errnop));
+  return retv;
+}
+
 /* Note: the af parameter is ignored and is assumed to be AF_INET */
 /* TODO: implement handling of af parameter */
-#ifdef HAVE_NSSWITCH_H
-nss_status_t _nss_nslcd_getnetbyaddr_r(
-#else /* not HAVE_NSSWITCH_H */
 nss_status_t _nss_ldap_getnetbyaddr_r(
-#endif /* HAVE_NSSWITCH_H */
         uint32_t addr,int UNUSED(af),struct netent *result,
         char *buffer,size_t buflen,int *errnop,int *h_errnop)
 {
-  NSS_BYGEN(NSLCD_ACTION_NETWORK_BYADDR,
+  NSS_BYGEN(NSLCD_ACTION_NETWORK_BYADDR,buffer,buflen,
             WRITE_ADDRESS(fp,addr),
             read_netent(fp,result,buffer,buflen,errnop,h_errnop))
+  return retv;
 }
 
 /* thread-local file pointer to an ongoing request */
 static __thread TFILE *netentfp;
 
-#ifdef HAVE_NSSWITCH_H
-nss_status_t _nss_ldap_setnetent(nss_backend_t *net_context,void *fakeargs)
-#else /* not HAVE_NSSWITCH_H */
 nss_status_t _nss_ldap_setnetent(int UNUSED(stayopen))
-#endif /* HAVE_NSSWITCH_H */
 {
   NSS_SETENT(netentfp);
 }
 
-#ifdef HAVE_NSSWITCH_H
-nss_status_t _nss_nslcd_getnetent_r(
-#else /* not HAVE_NSSWITCH_H */
 nss_status_t _nss_ldap_getnetent_r(
-#endif /* HAVE_NSSWITCH_H */
         struct netent *result,char *buffer,size_t buflen,
         int *errnop,int *h_errnop)
 {
-  NSS_GETENT(netentfp,NSLCD_ACTION_NETWORK_ALL,
+  NSS_GETENT(netentfp,NSLCD_ACTION_NETWORK_ALL,buffer,buflen,
              read_netent(netentfp,result,buffer,buflen,errnop,h_errnop));
+  return retv;
 }
 
-#ifdef HAVE_NSSWITCH_H
-nss_status_t _nss_ldap_endnetent(nss_backend_t *net_context,void *fakeargs)
-#else /* not HAVE_NSSWITCH_H */
 nss_status_t _nss_ldap_endnetent(void)
-#endif /* HAVE_NSSWITCH_H */
 {
   NSS_ENDENT(netentfp);
 }
 
-#ifdef HAVE_NSSWITCH_H
-static nss_status_t _nss_ldap_getnetbyname_r(nss_backend_t *be,void *args)
+#endif /* NSS_FLAVOUR_GLIBC */
+
+#ifdef NSS_FLAVOUR_SOLARIS
+
+static nss_status_t _nss_nslcd_getnetbyname_r(
+        const char *name,struct netent *result,char *buffer,
+        size_t buflen,int *errnop,int *h_errnop)
+{
+  NSS_BYNAME(NSLCD_ACTION_NETWORK_BYNAME,buffer,buflen,
+             name,
+             read_netent(fp,result,buffer,buflen,errnop,h_errnop));
+  return retv;
+}
+
+static nss_status_t _xnss_ldap_getnetbyname_r(nss_backend_t *UNUSED(be),void 
*args)
 {
   struct netent priv_network;
   struct netent *network=NSS_ARGS(args)->buf.result?(struct netent 
*)NSS_ARGS(args)->buf.result:&priv_network;
@@ -181,7 +182,7 @@
   int h_errno;
   char *data_ptr;
   nss_status_t status;
-  if (NSS_ARGS(args)->buf.buflen < 0)
+  if (NSS_ARGS(args)->buf.buflen<0)
   {
     NSS_ARGS(args)->erange=1;
     return NSS_STATUS_TRYAGAIN;
@@ -219,16 +220,26 @@
   NSS_ARGS(args)->h_errno=h_errno;
   return status;
 }
-#endif /* HAVE_NSSWITCH_H */
 
 /* Note: the af parameter is ignored and is assumed to be AF_INET */
 /* TODO: implement handling of af parameter */
-#ifdef HAVE_NSSWITCH_H
-static nss_status_t _nss_ldap_getnetbyaddr_r(nss_backend_t *be,void *args)
+static nss_status_t _nss_nslcd_getnetbyaddr_r(
+        uint32_t addr,int UNUSED(af),struct netent *result,
+        char *buffer,size_t buflen,int *errnop,int *h_errnop)
+{
+  NSS_BYGEN(NSLCD_ACTION_NETWORK_BYADDR,buffer,buflen,
+            WRITE_ADDRESS(fp,addr),
+            read_netent(fp,result,buffer,buflen,errnop,h_errnop))
+  return retv;
+}
+
+/* Note: the af parameter is ignored and is assumed to be AF_INET */
+/* TODO: implement handling of af parameter */
+static nss_status_t _xnss_ldap_getnetbyaddr_r(nss_backend_t *UNUSED(be),void 
*args)
 {
   struct netent priv_network;
   struct netent *network=NSS_ARGS(args)->buf.result?(struct netent 
*)NSS_ARGS(args)->buf.result:&priv_network;
-  int addr=NSS_ARGS(args)->key.netaddr.net;
+  int addr=NSS_ARGS(args)->key.netaddr.net; /* is an addr an int? */
   int af=NSS_ARGS(args)->key.netaddr.type;
   char *buffer=NSS_ARGS(args)->buf.buffer;
   size_t buflen=NSS_ARGS(args)->buf.buflen;
@@ -236,7 +247,7 @@
   char *data_ptr;
   struct in_addr in_addr;
   nss_status_t status;
-  if (NSS_ARGS(args)->buf.buflen < 0)
+  if (NSS_ARGS(args)->buf.buflen<0)
   {
     NSS_ARGS(args)->erange=1;
     return NSS_STATUS_TRYAGAIN;
@@ -276,7 +287,21 @@
   return status;
 }
 
-static nss_status_t _nss_ldap_getnetent_r(nss_backend_t *net_context,void 
*args)
+static nss_status_t _xnss_ldap_setnetent(nss_backend_t *UNUSED(be),void 
*UNUSED(args))
+{
+  NSS_SETENT(netentfp);
+}
+
+static nss_status_t _nss_nslcd_getnetent_r(
+        struct netent *result,char *buffer,size_t buflen,
+        int *errnop,int *h_errnop)
+{
+  NSS_GETENT(netentfp,NSLCD_ACTION_NETWORK_ALL,buffer,buflen,
+             read_netent(netentfp,result,buffer,buflen,errnop,h_errnop));
+  return retv;
+}
+
+static nss_status_t _xnss_ldap_getnetent_r(nss_backend_t *UNUSED(be),void 
*args)
 {
   struct netent priv_network;
   struct netent *network=NSS_ARGS(args)->buf.result?(struct netent 
*)NSS_ARGS(args)->buf.result:&priv_network;
@@ -285,7 +310,7 @@
   int h_errno;
   char *data_ptr;
   nss_status_t status;
-  if (NSS_ARGS(args)->buf.buflen < 0)
+  if (NSS_ARGS(args)->buf.buflen<0)
   {
     NSS_ARGS(args)->erange=1;
     return NSS_STATUS_TRYAGAIN;
@@ -321,31 +346,35 @@
   return status;
 }
 
-static nss_status_t _nss_ldap_networks_destr(nss_backend_t *net_context,void 
*args)
+static nss_status_t _xnss_ldap_endnetent(nss_backend_t *UNUSED(be),void 
*UNUSED(args))
 {
-  return _nss_ldap_default_destr(net_context,args);
+  NSS_ENDENT(netentfp);
+}
+
+static nss_status_t _xnss_ldap_networks_destr(nss_backend_t *be,void 
*UNUSED(args))
+{
+  free(be);
+  return NSS_STATUS_SUCCESS;
 }
 
 static nss_backend_op_t net_ops[]={
-  _nss_ldap_networks_destr,
-  _nss_ldap_endnetent,
-  _nss_ldap_setnetent,
-  _nss_ldap_getnetent_r,
-  _nss_ldap_getnetbyname_r,
-  _nss_ldap_getnetbyaddr_r
+  _xnss_ldap_networks_destr,
+  _xnss_ldap_endnetent,
+  _xnss_ldap_setnetent,
+  _xnss_ldap_getnetent_r,
+  _xnss_ldap_getnetbyname_r,
+  _xnss_ldap_getnetbyaddr_r
 };
 
-nss_backend_t *_nss_ldap_networks_constr(const char *db_name,
-                           const char *src_name,const char *cfg_args)
+nss_backend_t *_nss_ldap_networks_constr(const char *UNUSED(db_name),
+                           const char *UNUSED(src_name),const char 
*UNUSED(cfg_args))
 {
-  nss_ldap_backend_t *be;
-  if (!(be=(nss_ldap_backend_t *)malloc(sizeof(*be))))
+  nss_backend_t *be;
+  if (!(be=(nss_backend_t *)malloc(sizeof(*be))))
     return NULL;
   be->ops=net_ops;
   be->n_ops=sizeof(net_ops)/sizeof(nss_backend_op_t);
-  if (_nss_ldap_default_constr(be)!=NSS_STATUS_SUCCESS)
-    return NULL;
   return (nss_backend_t *)be;
 }
 
-#endif /* HAVE_NSSWITCH_H */
+#endif /* NSS_FLAVOUR_SOLARIS */

Modified: nss-pam-ldapd-solaris/nss/passwd.c
==============================================================================
--- nss-pam-ldapd-solaris/nss/passwd.c  Sat Oct  2 21:19:00 2010        (r1235)
+++ nss-pam-ldapd-solaris/nss/passwd.c  Sun Oct  3 23:57:11 2010        (r1236)
@@ -46,84 +46,81 @@
   return NSS_STATUS_SUCCESS;
 }
 
-#ifdef HAVE_NSSWITCH_H
-nss_status_t _nss_nslcd_getpwnam_r(
-#else /* not HAVE_NSSWITCH_H */
+#ifdef NSS_FLAVOUR_GLIBC
+
 nss_status_t _nss_ldap_getpwnam_r(
-#endif /* HAVE_NSSWITCH_H */
         const char *name,struct passwd *result,char *buffer,size_t buflen,
         int *errnop)
 {
-  NSS_BYNAME(NSLCD_ACTION_PASSWD_BYNAME,
+  NSS_BYNAME(NSLCD_ACTION_PASSWD_BYNAME,buffer,buflen,
              name,
              read_passwd(fp,result,buffer,buflen,errnop));
+  return retv;
 }
 
-#ifdef HAVE_NSSWITCH_H
-nss_status_t _nss_nslcd_getpwuid_r(
-#else /* not HAVE_NSSWITCH_H */
 nss_status_t _nss_ldap_getpwuid_r(
-#endif /* HAVE_NSSWITCH_H */
         uid_t uid,struct passwd *result,char *buffer,
         size_t buflen,int *errnop)
 {
-  NSS_BYTYPE(NSLCD_ACTION_PASSWD_BYUID,
+  NSS_BYTYPE(NSLCD_ACTION_PASSWD_BYUID,buffer,buflen,
              uid,uid_t,
              read_passwd(fp,result,buffer,buflen,errnop));
+  return retv;
 }
 
 /* thread-local file pointer to an ongoing request */
 static __thread TFILE *pwentfp;
 
 /* open a connection to the nslcd and write the request */
-#ifdef HAVE_NSSWITCH_H
-nss_status_t _nss_ldap_setpwent(nss_backend_t *be,void *args)
-#else /* not HAVE_NSSWITCH_H */
 nss_status_t _nss_ldap_setpwent(int UNUSED(stayopen))
-#endif /* HAVE_NSSWITCH_H */
 {
   NSS_SETENT(pwentfp);
 }
 
 /* read password data from an opened stream */
-#ifdef HAVE_NSSWITCH_H
-nss_status_t _nss_nslcd_getpwent_r(
-#else /* not HAVE_NSSWITCH_H */
 nss_status_t _nss_ldap_getpwent_r(
-#endif /* HAVE_NSSWITCH_H */
         struct passwd *result,char *buffer,size_t buflen,int *errnop)
 {
-  NSS_GETENT(pwentfp,NSLCD_ACTION_PASSWD_ALL,
+  NSS_GETENT(pwentfp,NSLCD_ACTION_PASSWD_ALL,buffer,buflen,
              read_passwd(pwentfp,result,buffer,buflen,errnop));
+  return retv;
 }
 
 /* close the stream opened with setpwent() above */
-#ifdef HAVE_NSSWITCH_H
-nss_status_t _nss_ldap_endpwent(nss_backend_t *be,void *args)
-#else /* not HAVE_NSSWITCH_H */
 nss_status_t _nss_ldap_endpwent(void)
-#endif /* HAVE_NSSWITCH_H */
 {
   NSS_ENDENT(pwentfp);
 }
 
-#ifdef HAVE_NSSWITCH_H
-static nss_status_t _nss_ldap_getpwnam_r(nss_backend_t *be,void *args)
+#endif /* NSS_FLAVOUR_GLIBC */
+
+#ifdef NSS_FLAVOUR_SOLARIS
+
+static nss_status_t _nss_nslcd_getpwnam_r(
+        const char *name,struct passwd *result,char *buffer,size_t buflen,
+        int *errnop)
+{
+  NSS_BYNAME(NSLCD_ACTION_PASSWD_BYNAME,buffer,buflen,
+             name,
+             read_passwd(fp,result,buffer,buflen,errnop));
+  return retv;
+}
+
+static nss_status_t _xnss_ldap_getpwnam_r(nss_backend_t *UNUSED(be),void *args)
 {
   struct passwd priv_pw;
   struct passwd *pw=NSS_ARGS(args)->buf.result?(struct passwd 
*)NSS_ARGS(args)->buf.result:&priv_pw;
   char *buffer=NSS_ARGS(args)->buf.buffer;
   size_t buflen=NSS_ARGS(args)->buf.buflen;
-  char *name=(char *)NSS_ARGS(args)->key.name;
   char *data_ptr;
   nss_status_t status;
-  if (NSS_ARGS(args)->buf.buflen < 0)
+  if (NSS_ARGS(args)->buf.buflen<0)
   {
     NSS_ARGS(args)->erange=1;
     status=NSS_STATUS_TRYAGAIN;
     return status;
   }
-  status=_nss_nslcd_getpwnam_r(name,pw,buffer,buflen,&errno);
+  
status=_nss_nslcd_getpwnam_r(NSS_ARGS(args)->key.name,pw,buffer,buflen,&errno);
   if (status!=NSS_STATUS_SUCCESS)
     return status;
   if (!NSS_ARGS(args)->buf.result)
@@ -147,7 +144,38 @@
   return status;
 }
 
-static nss_status_t _nss_ldap_getpwuid_r(nss_backend_t *be,void *args)
+static nss_status_t _nss_nslcd_getpwuid_r(
+        uid_t uid,struct passwd *result,char *buffer,
+        size_t buflen,int *errnop)
+{
+  NSS_BYTYPE(NSLCD_ACTION_PASSWD_BYUID,buffer,buflen,
+             uid,uid_t,
+             read_passwd(fp,result,buffer,buflen,errnop));
+  return retv;
+}
+
+/* open a connection to the nslcd and write the request */
+static nss_status_t _xnss_ldap_setpwent(nss_backend_t *UNUSED(be),void 
*UNUSED(args))
+{
+  NSS_SETENT(pwentfp);
+}
+
+/* read password data from an opened stream */
+static nss_status_t _nss_nslcd_getpwent_r(
+        struct passwd *result,char *buffer,size_t buflen,int *errnop)
+{
+  NSS_GETENT(pwentfp,NSLCD_ACTION_PASSWD_ALL,buffer,buflen,
+             read_passwd(pwentfp,result,buffer,buflen,errnop));
+  return retv;
+}
+
+/* close the stream opened with setpwent() above */
+static nss_status_t _xnss_ldap_endpwent(nss_backend_t *UNUSED(be),void 
*UNUSED(args))
+{
+  NSS_ENDENT(pwentfp);
+}
+
+static nss_status_t _xnss_ldap_getpwuid_r(nss_backend_t *UNUSED(be),void *args)
 {
   struct passwd priv_pw;
   struct passwd *pw=NSS_ARGS(args)->buf.result ?
@@ -181,7 +209,7 @@
   return status;
 }
 
-static nss_status_t _nss_ldap_getpwent_r(nss_backend_t *be,void *args)
+static nss_status_t _xnss_ldap_getpwent_r(nss_backend_t *UNUSED(be),void *args)
 {
   struct passwd priv_pw;
   struct passwd *pw=NSS_ARGS(args)->buf.result?(struct passwd 
*)NSS_ARGS(args)->buf.result:&priv_pw;
@@ -213,31 +241,30 @@
   return status;
 }
 
-static nss_status_t _nss_ldap_passwd_destr(nss_backend_t *pw_context,void 
*args)
+static nss_status_t _xnss_ldap_passwd_destr(nss_backend_t *be,void 
*UNUSED(args))
 {
-  return _nss_ldap_default_destr(pw_context,args);
+  free(be);
+  return NSS_STATUS_SUCCESS;
 }
 
 static nss_backend_op_t passwd_ops[]={
-  _nss_ldap_passwd_destr,
-  _nss_ldap_endpwent,         /* NSS_DBOP_ENDENT */
-  _nss_ldap_setpwent,         /* NSS_DBOP_SETENT */
-  _nss_ldap_getpwent_r,       /* NSS_DBOP_GETENT */
-  _nss_ldap_getpwnam_r,       /* NSS_DBOP_PASSWD_BYNAME */
-  _nss_ldap_getpwuid_r        /* NSS_DBOP_PASSWD_BYUID */
+  _xnss_ldap_passwd_destr,
+  _xnss_ldap_endpwent,         /* NSS_DBOP_ENDENT */
+  _xnss_ldap_setpwent,         /* NSS_DBOP_SETENT */
+  _xnss_ldap_getpwent_r,       /* NSS_DBOP_GETENT */
+  _xnss_ldap_getpwnam_r,       /* NSS_DBOP_PASSWD_BYNAME */
+  _xnss_ldap_getpwuid_r        /* NSS_DBOP_PASSWD_BYUID */
 };
 
-nss_backend_t *_nss_ldap_passwd_constr(const char *db_name,
-                         const char *src_name,const char *cfg_args)
+nss_backend_t *_nss_ldap_passwd_constr(const char *UNUSED(db_name),
+                         const char *UNUSED(src_name),const char 
*UNUSED(cfg_args))
 {
-  nss_ldap_backend_t *be;
-  if (!(be=(nss_ldap_backend_t *)malloc(sizeof(*be))))
+  nss_backend_t *be;
+  if (!(be=(nss_backend_t *)malloc(sizeof(*be))))
     return NULL;
   be->ops=passwd_ops;
   be->n_ops=sizeof(passwd_ops)/sizeof(nss_backend_op_t);
-  if (_nss_ldap_default_constr(be)!=NSS_STATUS_SUCCESS)
-    return NULL;
   return (nss_backend_t *)be;
 }
 
-#endif /* HAVE_NSSWITCH_H */
+#endif /* NSS_FLAVOUR_SOLARIS */

Modified: nss-pam-ldapd-solaris/nss/protocols.c
==============================================================================
--- nss-pam-ldapd-solaris/nss/protocols.c       Sat Oct  2 21:19:00 2010        
(r1235)
+++ nss-pam-ldapd-solaris/nss/protocols.c       Sun Oct  3 23:57:11 2010        
(r1236)
@@ -42,88 +42,85 @@
   return NSS_STATUS_SUCCESS;
 }
 
-#ifdef HAVE_NSSWITCH_H
-nss_status_t _nss_nslcd_getprotobyname_r(
-#else /* not HAVE_NSSWITCH_H */
+#ifdef NSS_FLAVOUR_GLIBC
+
 nss_status_t _nss_ldap_getprotobyname_r(
-#endif /* HAVE_NSSWITCH_H */
         const char *name,struct protoent *result,char *buffer,
         size_t buflen,int *errnop)
 {
-  NSS_BYNAME(NSLCD_ACTION_PROTOCOL_BYNAME,
+  NSS_BYNAME(NSLCD_ACTION_PROTOCOL_BYNAME,buffer,buflen,
              name,
              read_protoent(fp,result,buffer,buflen,errnop));
+  return retv;
 }
 
-#ifdef HAVE_NSSWITCH_H
-nss_status_t _nss_nslcd_getprotobynumber_r(
-#else /* not HAVE_NSSWITCH_H */
 nss_status_t _nss_ldap_getprotobynumber_r(
-#endif /* HAVE_NSSWITCH_H */
         int number,struct protoent *result,char *buffer,
         size_t buflen,int *errnop)
 {
-  NSS_BYINT32(NSLCD_ACTION_PROTOCOL_BYNUMBER,
+  NSS_BYINT32(NSLCD_ACTION_PROTOCOL_BYNUMBER,buffer,buflen,
               number,
               read_protoent(fp,result,buffer,buflen,errnop));
+  return retv;
 }
 
 /* thread-local file pointer to an ongoing request */
 static __thread TFILE *protoentfp;
 
-#ifdef HAVE_NSSWITCH_H
-nss_status_t _nss_ldap_setprotoent(nss_backend_t *proto_context,void *fakeargs)
-#else /* not HAVE_NSSWITCH_H */
 nss_status_t _nss_ldap_setprotoent(int UNUSED(stayopen))
-#endif /* HAVE_NSSWITCH_H */
 {
   NSS_SETENT(protoentfp);
 }
 
-#ifdef HAVE_NSSWITCH_H
-nss_status_t _nss_nslcd_getprotoent_r(
-#else /* not HAVE_NSSWITCH_H */
 nss_status_t _nss_ldap_getprotoent_r(
-#endif /* HAVE_NSSWITCH_H */
         struct protoent *result,char *buffer,size_t buflen,int *errnop)
 {
-  NSS_GETENT(protoentfp,NSLCD_ACTION_PROTOCOL_ALL,
+  NSS_GETENT(protoentfp,NSLCD_ACTION_PROTOCOL_ALL,buffer,buflen,
              read_protoent(protoentfp,result,buffer,buflen,errnop));
+  return retv;
 }
 
-#ifdef HAVE_NSSWITCH_H
-nss_status_t _nss_ldap_endprotoent(nss_backend_t *proto_context,void *fakeargs)
-#else /* not HAVE_NSSWITCH_H */
 nss_status_t _nss_ldap_endprotoent(void)
-#endif /* HAVE_NSSWITCH_H */
-
 {
   NSS_ENDENT(protoentfp);
 }
 
-#ifdef HAVE_NSSWITCH_H
+#endif /* NSS_FLAVOUR_GLIBC */
+
+#ifdef NSS_FLAVOUR_SOLARIS
 
-static nss_status_t _nss_ldap_getprotobyname_r(nss_backend_t *be,void *args)
+static nss_status_t _nss_nslcd_getprotobyname_r(
+        const char *name,struct protoent *result,char *buffer,
+        size_t buflen,int *errnop)
+{
+  NSS_BYNAME(NSLCD_ACTION_PROTOCOL_BYNAME,buffer,buflen,
+             name,
+             read_protoent(fp,result,buffer,buflen,errnop));
+  return retv;
+}
+
+static nss_status_t _xnss_ldap_getprotobyname_r(nss_backend_t *UNUSED(be),void 
*args)
 {
   struct protoent priv_proto;
   struct protoent *proto=NSS_ARGS(args)->buf.result?(struct protoent 
*)NSS_ARGS(args)->buf.result:&priv_proto;
-  char *name=(char *)NSS_ARGS(args)->key.name;
   char *buffer=NSS_ARGS(args)->buf.buffer;
   size_t buflen=NSS_ARGS(args)->buf.buflen;
   char *data_ptr;
   nss_status_t status;
-  if (NSS_ARGS(args)->buf.buflen < 0)
+  if (NSS_ARGS(args)->buf.buflen<0)
   {
     NSS_ARGS(args)->erange=1;
     return NSS_STATUS_TRYAGAIN;
   }
-  status=_nss_nslcd_getprotobyname_r(name,proto ,buffer,buflen,&errno);
+  
status=_nss_nslcd_getprotobyname_r(NSS_ARGS(args)->key.name,proto,buffer,buflen,&errno);
   if (status!=NSS_STATUS_SUCCESS)
     return status;
   if (!NSS_ARGS(args)->buf.result)
   {
     /* result==NULL, return file format */
     data_ptr=(char *)malloc(buflen);
+    /* FIXME: shouldn't there be some range checks here to see if it actually
+              fits inside the buffer? */
     sprintf(data_ptr,"%s\t\t%d",proto->p_name,proto->p_proto);
     if (proto->p_aliases)
     {
@@ -146,7 +143,17 @@
   return status;
 }
 
-static nss_status_t _nss_ldap_getprotobynumber_r(nss_backend_t *be,void *args)
+static nss_status_t _nss_nslcd_getprotobynumber_r(
+        int number,struct protoent *result,char *buffer,
+        size_t buflen,int *errnop)
+{
+  NSS_BYINT32(NSLCD_ACTION_PROTOCOL_BYNUMBER,buffer,buflen,
+              number,
+              read_protoent(fp,result,buffer,buflen,errnop));
+  return retv;
+}
+
+static nss_status_t _xnss_ldap_getprotobynumber_r(nss_backend_t 
*UNUSED(be),void *args)
 {
   struct protoent priv_proto;
   struct protoent *proto=NSS_ARGS(args)->buf.result?(struct protoent 
*)NSS_ARGS(args)->buf.result:&priv_proto;
@@ -189,7 +196,20 @@
   return status;
 }
 
-static nss_status_t _nss_ldap_getprotoent_r(nss_backend_t *proto_context,void 
*args)
+static nss_status_t _xnss_ldap_setprotoent(nss_backend_t *UNUSED(be),void 
*UNUSED(args))
+{
+  NSS_SETENT(protoentfp);
+}
+
+static nss_status_t _nss_nslcd_getprotoent_r(
+        struct protoent *result,char *buffer,size_t buflen,int *errnop)
+{
+  NSS_GETENT(protoentfp,NSLCD_ACTION_PROTOCOL_ALL,buffer,buflen,
+             read_protoent(protoentfp,result,buffer,buflen,errnop));
+  return retv;
+}
+
+static nss_status_t _xnss_ldap_getprotoent_r(nss_backend_t *UNUSED(be),void 
*args)
 {
   struct protoent priv_proto;
   struct protoent *proto=NSS_ARGS(args)->buf.result?(struct protoent 
*)NSS_ARGS(args)->buf.result:&priv_proto;
@@ -197,7 +217,7 @@
   size_t buflen=NSS_ARGS(args)->buf.buflen;
   char *data_ptr;
   nss_status_t status;
-  if (NSS_ARGS(args)->buf.buflen < 0)
+  if (NSS_ARGS(args)->buf.buflen<0)
   {
     NSS_ARGS(args)->erange=1;
     return NSS_STATUS_TRYAGAIN;
@@ -231,31 +251,35 @@
   return status;
 }
 
-static nss_status_t _nss_ldap_protocols_destr(nss_backend_t 
*proto_context,void *args)
+static nss_status_t _xnss_ldap_endprotoent(nss_backend_t *UNUSED(be),void 
*UNUSED(args))
+{
+  NSS_ENDENT(protoentfp);
+}
+
+static nss_status_t _xnss_ldap_protocols_destr(nss_backend_t *be,void 
*UNUSED(args))
 {
-  return _nss_ldap_default_destr(proto_context,args);
+  free(be);
+  return NSS_STATUS_SUCCESS;
 }
 
 static nss_backend_op_t proto_ops[]={
-  _nss_ldap_protocols_destr,
-  _nss_ldap_endprotoent,
-  _nss_ldap_setprotoent,
-  _nss_ldap_getprotoent_r,
-  _nss_ldap_getprotobyname_r,
-  _nss_ldap_getprotobynumber_r
+  _xnss_ldap_protocols_destr,
+  _xnss_ldap_endprotoent,
+  _xnss_ldap_setprotoent,
+  _xnss_ldap_getprotoent_r,
+  _xnss_ldap_getprotobyname_r,
+  _xnss_ldap_getprotobynumber_r
 };
 
-nss_backend_t *_nss_ldap_protocols_constr(const char *db_name,
-                            const char *src_name,const char *cfg_args)
+nss_backend_t *_nss_ldap_protocols_constr(const char *UNUSED(db_name),
+                            const char *UNUSED(src_name),const char 
*UNUSED(cfg_args))
 {
-  nss_ldap_backend_t *be;
-  if (!(be=(nss_ldap_backend_t *)malloc(sizeof(*be))))
+  nss_backend_t *be;
+  if (!(be=(nss_backend_t *)malloc(sizeof(*be))))
     return NULL;
   be->ops=proto_ops;
   be->n_ops=sizeof(proto_ops)/sizeof(nss_backend_op_t);
-  if (_nss_ldap_default_constr(be)!=NSS_STATUS_SUCCESS)
-    return NULL;
   return (nss_backend_t *)be;
 }
 
-#endif /* HAVE_NSSWITCH_H */
+#endif /* NSS_FLAVOUR_SOLARIS */

Modified: nss-pam-ldapd-solaris/nss/prototypes.h
==============================================================================
--- nss-pam-ldapd-solaris/nss/prototypes.h      Sat Oct  2 21:19:00 2010        
(r1235)
+++ nss-pam-ldapd-solaris/nss/prototypes.h      Sun Oct  3 23:57:11 2010        
(r1236)
@@ -25,6 +25,12 @@
 
 #include "compat/nss_compat.h"
 
+/* flag to gloabally disable lookups (all _nss_ldap_*() functions will return
+   NSS_STATUS_UNAVAIL */
+extern int _nss_ldap_enablelookups;
+
+#ifdef NSS_FLAVOUR_GLIBC
+
 /*
    These are prototypes for functions exported from the ldap NSS module.
    For more complete definitions of these functions check the GLIBC
@@ -38,105 +44,99 @@
    http://www.gnu.org/software/libc/manual/html_node/Name-Service-Switch.html
 */
 
-/* flag to gloabally disable lookups (all _nss_ldap_*() functions will return
-   NSS_STATUS_UNAVAIL */
-extern int _nss_ldap_enablelookups;
-
 /* aliases - mail aliases */
-#ifdef HAVE_ALIASES_H
 nss_status_t _nss_ldap_getaliasbyname_r(const char *name,struct aliasent 
*result,char *buffer,size_t buflen,int *errnop);
 nss_status_t _nss_ldap_setaliasent(void);
 nss_status_t _nss_ldap_getaliasent_r(struct aliasent *result,char 
*buffer,size_t buflen,int *errnop);
 nss_status_t _nss_ldap_endaliasent(void);
-#endif /* HAVE_ALIASES_H */
 
 /* ethers - ethernet numbers */
-#ifndef HAVE_NSSWITCH_H
 nss_status_t _nss_ldap_gethostton_r(const char *name,struct etherent 
*result,char *buffer,size_t buflen,int *errnop);
 nss_status_t _nss_ldap_getntohost_r(const struct ether_addr *addr,struct 
etherent *result,char *buffer,size_t buflen,int *errnop);
 nss_status_t _nss_ldap_setetherent(int stayopen);
 nss_status_t _nss_ldap_getetherent_r(struct etherent *result,char 
*buffer,size_t buflen,int *errnop);
 nss_status_t _nss_ldap_endetherent(void);
-#endif /* not HAVE_NSSWITCH_H */
 
 /* group - groups of users */
-#ifndef HAVE_NSSWITCH_H
 nss_status_t _nss_ldap_getgrnam_r(const char *name,struct group *result,char 
*buffer,size_t buflen,int *errnop);
 nss_status_t _nss_ldap_getgrgid_r(gid_t gid,struct group *result,char 
*buffer,size_t buflen,int *errnop);
 nss_status_t _nss_ldap_initgroups_dyn(const char *user,gid_t group,long int 
*start,long int *size,gid_t **groupsp,long int limit,int *errnop);
 nss_status_t _nss_ldap_setgrent(int stayopen);
 nss_status_t _nss_ldap_getgrent_r(struct group *result,char *buffer,size_t 
buflen,int *errnop);
 nss_status_t _nss_ldap_endgrent(void);
-#endif /* not HAVE_NSSWITCH_H */
 
 /* hosts - host names and numbers */
-#ifndef HAVE_NSSWITCH_H
 nss_status_t _nss_ldap_gethostbyname_r(const char *name,struct hostent 
*result,char *buffer,size_t buflen,int *errnop,int *h_errnop);
 nss_status_t _nss_ldap_gethostbyname2_r(const char *name,int af,struct hostent 
*result,char *buffer,size_t buflen,int *errnop,int *h_errnop);
 nss_status_t _nss_ldap_gethostbyaddr_r(const void *addr,socklen_t len,int 
af,struct hostent *result,char *buffer,size_t buflen,int *errnop,int *h_errnop);
 nss_status_t _nss_ldap_sethostent(int stayopen);
 nss_status_t _nss_ldap_gethostent_r(struct hostent *result,char *buffer,size_t 
buflen,int *errnop,int *h_errnop);
 nss_status_t _nss_ldap_endhostent(void);
-#endif /* not HAVE_NSSWITCH_H */
 
 /* netgroup - list of host and users */
-#ifndef HAVE_NSSWITCH_H
 nss_status_t _nss_ldap_setnetgrent(const char *group,struct __netgrent 
*result);
 nss_status_t _nss_ldap_getnetgrent_r(struct __netgrent *result,char 
*buffer,size_t buflen,int *errnop);
 nss_status_t _nss_ldap_endnetgrent(struct __netgrent *result);
-#endif /* not HAVE_NSSWITCH_H */
 
 /* networks - network names and numbers */
-#ifndef HAVE_NSSWITCH_H
 nss_status_t _nss_ldap_getnetbyname_r(const char *name,struct netent 
*result,char *buffer,size_t buflen,int *errnop,int *h_errnop);
 nss_status_t _nss_ldap_getnetbyaddr_r(uint32_t addr,int af,struct netent 
*result,char *buffer,size_t buflen,int *errnop,int *h_errnop);
 nss_status_t _nss_ldap_setnetent(int stayopen);
 nss_status_t _nss_ldap_getnetent_r(struct netent *result,char *buffer,size_t 
buflen,int *errnop,int *h_errnop);
 nss_status_t _nss_ldap_endnetent(void);
-#endif /* not HAVE_NSSWITCH_H */
 
 /* passwd - user database and passwords */
-#ifndef HAVE_NSSWITCH_H
 nss_status_t _nss_ldap_getpwnam_r(const char *name,struct passwd *result,char 
*buffer,size_t buflen,int *errnop);
 nss_status_t _nss_ldap_getpwuid_r(uid_t uid,struct passwd *result,char 
*buffer,size_t buflen,int *errnop);
 nss_status_t _nss_ldap_setpwent(int stayopen);
 nss_status_t _nss_ldap_getpwent_r(struct passwd *result,char *buffer,size_t 
buflen,int *errnop);
 nss_status_t _nss_ldap_endpwent(void);
-#endif /* not HAVE_NSSWITCH_H */
 
 /* protocols - network protocols */
-#ifndef HAVE_NSSWITCH_H
 nss_status_t _nss_ldap_getprotobyname_r(const char *name,struct protoent 
*result,char *buffer,size_t buflen,int *errnop);
 nss_status_t _nss_ldap_getprotobynumber_r(int number,struct protoent 
*result,char *buffer,size_t buflen,int *errnop);
 nss_status_t _nss_ldap_setprotoent(int stayopen);
 nss_status_t _nss_ldap_getprotoent_r(struct protoent *result,char 
*buffer,size_t buflen,int *errnop);
 nss_status_t _nss_ldap_endprotoent(void);
-#endif /* not HAVE_NSSWITCH_H */
 
 /* rpc - remote procedure call names and numbers */
-#ifndef HAVE_NSSWITCH_H
 nss_status_t _nss_ldap_getrpcbyname_r(const char *name,struct rpcent 
*result,char *buffer,size_t buflen,int *errnop);
 nss_status_t _nss_ldap_getrpcbynumber_r(int number,struct rpcent *result,char 
*buffer,size_t buflen,int *errnop);
 nss_status_t _nss_ldap_setrpcent(int stayopen);
 nss_status_t _nss_ldap_getrpcent_r(struct rpcent *result,char *buffer,size_t 
buflen,int *errnop);
 nss_status_t _nss_ldap_endrpcent(void);
-#endif /* not HAVE_NSSWITCH_H */
 
 /* services - network services */
-#ifndef HAVE_NSSWITCH_H
 nss_status_t _nss_ldap_getservbyname_r(const char *name,const char 
*protocol,struct servent *result,char *buffer,size_t buflen,int *errnop);
 nss_status_t _nss_ldap_getservbyport_r(int port,const char *protocol,struct 
servent *result,char *buffer,size_t buflen,int *errnop);
 nss_status_t _nss_ldap_setservent(int stayopen);
 nss_status_t _nss_ldap_getservent_r(struct servent *result,char *buffer,size_t 
buflen,int *errnop);
 nss_status_t _nss_ldap_endservent(void);
-#endif /* not HAVE_NSSWITCH_H */
 
 /* shadow - extended user information */
-#ifndef HAVE_NSSWITCH_H
 nss_status_t _nss_ldap_getspnam_r(const char *name,struct spwd *result,char 
*buffer,size_t buflen,int *errnop);
 nss_status_t _nss_ldap_setspent(int stayopen);
 nss_status_t _nss_ldap_getspent_r(struct spwd *result,char *buffer,size_t 
buflen,int *errnop);
 nss_status_t _nss_ldap_endspent(void);
-#endif /* not HAVE_NSSWITCH_H */
+
+#endif /* NSS_FLAVOUR_GLIBC */
+
+#ifdef NSS_FLAVOUR_SOLARIS
+
+#define NSS_ARGS(args) ((nss_XbyY_args_t *)args)
+
+/* these are the constructors we provide */
+nss_backend_t *_nss_ldap_ethers_constr(const char *db_name,const char 
*src_name,const char *cfg_args);
+nss_backend_t *_nss_ldap_group_constr(const char *db_name,const char 
*src_name,const char *cfg_args);
+nss_backend_t *_nss_ldap_hosts_constr(const char *db_name,const char 
*src_name,const char *cfg_args);
+nss_backend_t *_nss_ldap_netgroup_constr(const char *db_name,const char 
*src_name,const char *cfg_args);
+nss_backend_t *_nss_ldap_networks_constr(const char *db_name,const char 
*src_name,const char *cfg_args);
+nss_backend_t *_nss_ldap_passwd_constr(const char *db_name,const char 
*src_name,const char *cfg_args);
+nss_backend_t *_nss_ldap_protocols_constr(const char *db_name,const char 
*src_name,const char *cfg_args);
+nss_backend_t *_nss_ldap_rpc_constr(const char *db_name,const char 
*src_name,const char *cfg_args);
+nss_backend_t *_nss_ldap_services_constr(const char *db_name,const char 
*src_name,const char *cfg_args);
+nss_backend_t *_nss_ldap_shadow_constr(const char *db_name,const char 
*src_name,const char *cfg_args);
+
+#endif /* NSS_FLAVOUR_SOLARIS */
 
 #endif /* not NSS__PROTOTYPES_H */

Modified: nss-pam-ldapd-solaris/nss/rpc.c
==============================================================================
--- nss-pam-ldapd-solaris/nss/rpc.c     Sat Oct  2 21:19:00 2010        (r1235)
+++ nss-pam-ldapd-solaris/nss/rpc.c     Sun Oct  3 23:57:11 2010        (r1236)
@@ -42,81 +42,105 @@
   return NSS_STATUS_SUCCESS;
 }
 
-#ifdef HAVE_NSSWITCH_H
-nss_status_t _nss_nslcd_getrpcbyname_r(
-#else /* not HAVE_NSSWITCH_H */
+#ifdef NSS_FLAVOUR_GLIBC
+
 nss_status_t _nss_ldap_getrpcbyname_r(
-#endif /* HAVE_NSSWITCH_H */
         const char *name,struct rpcent *result,char *buffer,
         size_t buflen,int *errnop)
 {
-  NSS_BYNAME(NSLCD_ACTION_RPC_BYNAME,
+  NSS_BYNAME(NSLCD_ACTION_RPC_BYNAME,buffer,buflen,
              name,
              read_rpcent(fp,result,buffer,buflen,errnop));
+  return retv;
 }
 
-#ifdef HAVE_NSSWITCH_H
-nss_status_t _nss_nslcd_getrpcbynumber_r(
-#else /* not HAVE_NSSWITCH_H */
 nss_status_t _nss_ldap_getrpcbynumber_r(
-#endif /* HAVE_NSSWITCH_H */
         int number,struct rpcent *result,char *buffer,
         size_t buflen,int *errnop)
 {
-  NSS_BYINT32(NSLCD_ACTION_RPC_BYNUMBER,
+  NSS_BYINT32(NSLCD_ACTION_RPC_BYNUMBER,buffer,buflen,
               number,
               read_rpcent(fp,result,buffer,buflen,errnop));
+  return retv;
 }
 
 /* thread-local file pointer to an ongoing request */
 static __thread TFILE *protoentfp;
 
-#ifdef HAVE_NSSWITCH_H
-nss_status_t _nss_ldap_setrpcent(nss_backend_t *rpc_context,void *args)
-#else /* not HAVE_NSSWITCH_H */
 nss_status_t _nss_ldap_setrpcent(int UNUSED(stayopen))
-#endif /* HAVE_NSSWITCH_H */
 {
   NSS_SETENT(protoentfp);
 }
 
-#ifdef HAVE_NSSWITCH_H
-nss_status_t _nss_nslcd_getrpcent_r(
-#else /* not HAVE_NSSWITCH_H */
 nss_status_t _nss_ldap_getrpcent_r(
-#endif /* HAVE_NSSWITCH_H */
         struct rpcent *result,char *buffer,size_t buflen,int *errnop)
 {
-  NSS_GETENT(protoentfp,NSLCD_ACTION_RPC_ALL,
+  NSS_GETENT(protoentfp,NSLCD_ACTION_RPC_ALL,buffer,buflen,
              read_rpcent(protoentfp,result,buffer,buflen,errnop));
+  return retv;
 }
 
-#ifdef HAVE_NSSWITCH_H
-nss_status_t _nss_ldap_endrpcent(nss_backend_t *rpc_context,void *args)
-#else /* not HAVE_NSSWITCH_H */
 nss_status_t _nss_ldap_endrpcent(void)
-#endif /* HAVE_NSSWITCH_H */
 {
   NSS_ENDENT(protoentfp);
 }
 
-#ifdef HAVE_NSSWITCH_H
+#endif /* NSS_FLAVOUR_GLIBC */
+
+#ifdef NSS_FLAVOUR_SOLARIS
+
+static nss_status_t _nss_nslcd_getrpcbyname_r(
+        const char *name,struct rpcent *result,char *buffer,
+        size_t buflen,int *errnop)
+{
+  NSS_BYNAME(NSLCD_ACTION_RPC_BYNAME,buffer,buflen,
+             name,
+             read_rpcent(fp,result,buffer,buflen,errnop));
+  return retv;
+}
+
+static nss_status_t _nss_nslcd_getrpcbynumber_r(
+        int number,struct rpcent *result,char *buffer,
+        size_t buflen,int *errnop)
+{
+  NSS_BYINT32(NSLCD_ACTION_RPC_BYNUMBER,buffer,buflen,
+              number,
+              read_rpcent(fp,result,buffer,buflen,errnop));
+  return retv;
+}
 
-static nss_status_t _nss_ldap_getrpcbyname_r(nss_backend_t *be,void *args)
+static nss_status_t _xnss_ldap_setrpcent(nss_backend_t *UNUSED(be),void 
*UNUSED(args))
+{
+  NSS_SETENT(protoentfp);
+}
+
+static nss_status_t _nss_nslcd_getrpcent_r(
+        struct rpcent *result,char *buffer,size_t buflen,int *errnop)
+{
+  NSS_GETENT(protoentfp,NSLCD_ACTION_RPC_ALL,buffer,buflen,
+             read_rpcent(protoentfp,result,buffer,buflen,errnop));
+  return retv;
+}
+
+static nss_status_t _xnss_ldap_endrpcent(nss_backend_t *UNUSED(be),void 
*UNUSED(args))
+{
+  NSS_ENDENT(protoentfp);
+}
+
+static nss_status_t _xnss_ldap_getrpcbyname_r(nss_backend_t *UNUSED(be),void 
*args)
 {
   struct rpcent priv_rpc;
   struct rpcent *rpc=NSS_ARGS(args)->buf.result?(struct rpcent 
*)NSS_ARGS(args)->buf.result:&priv_rpc;
-  char *name=NSS_ARGS(args)->key.name;
   char *buffer=NSS_ARGS(args)->buf.buffer;
   size_t buflen=NSS_ARGS(args)->buf.buflen;
   char *data_ptr;
   nss_status_t status;
-  if (NSS_ARGS(args)->buf.buflen < 0)
+  if (NSS_ARGS(args)->buf.buflen<0)
   {
     NSS_ARGS(args)->erange=1;
     return NSS_STATUS_TRYAGAIN;
   }
-  status=_nss_nslcd_getrpcbyname_r(name,rpc,buffer,buflen,&errno);
+  
status=_nss_nslcd_getrpcbyname_r(NSS_ARGS(args)->key.name,rpc,buffer,buflen,&errno);
   if (status!=NSS_STATUS_SUCCESS)
     return status;
   if (!NSS_ARGS(args)->buf.result)
@@ -145,7 +169,7 @@
   return status;
 }
 
-static nss_status_t _nss_ldap_getrpcbynumber_r(nss_backend_t *be,void *args)
+static nss_status_t _xnss_ldap_getrpcbynumber_r(nss_backend_t *UNUSED(be),void 
*args)
 {
   struct rpcent priv_rpc;
   struct rpcent *rpc=NSS_ARGS(args)->buf.result?(struct rpcent 
*)NSS_ARGS(args)->buf.result:&priv_rpc;
@@ -154,7 +178,7 @@
   size_t buflen=NSS_ARGS(args)->buf.buflen;
   char *data_ptr;
   nss_status_t status;
-  if (NSS_ARGS(args)->buf.buflen < 0)
+  if (NSS_ARGS(args)->buf.buflen<0)
   {
     NSS_ARGS(args)->erange=1;
     return NSS_STATUS_TRYAGAIN;
@@ -188,7 +212,7 @@
   return status;
 }
 
-static nss_status_t _nss_ldap_getrpcent_r(nss_backend_t *rpc_context,void 
*args)
+static nss_status_t _xnss_ldap_getrpcent_r(nss_backend_t *UNUSED(be),void 
*args)
 {
   struct rpcent priv_rpc;
   struct rpcent *rpc=NSS_ARGS(args)->buf.result?(struct rpcent 
*)NSS_ARGS(args)->buf.result:&priv_rpc;
@@ -196,7 +220,7 @@
   size_t buflen=NSS_ARGS(args)->buf.buflen;
   char *data_ptr;
   nss_status_t status;
-  if (NSS_ARGS(args)->buf.buflen < 0)
+  if (NSS_ARGS(args)->buf.buflen<0)
   {
     NSS_ARGS(args)->erange=1;
     return NSS_STATUS_TRYAGAIN;
@@ -230,31 +254,30 @@
   return status;
 }
 
-static nss_status_t _nss_ldap_rpc_destr(nss_backend_t *rpc_context,void *args)
+static nss_status_t _xnss_ldap_rpc_destr(nss_backend_t *be,void *UNUSED(args))
 {
-  return _nss_ldap_default_destr(rpc_context,args);
+  free(be);
+  return NSS_STATUS_SUCCESS;
 }
 
 static nss_backend_op_t rpc_ops[]={
-  _nss_ldap_rpc_destr,
-  _nss_ldap_endrpcent,
-  _nss_ldap_setrpcent,
-  _nss_ldap_getrpcent_r,
-  _nss_ldap_getrpcbyname_r,
-  _nss_ldap_getrpcbynumber_r
+  _xnss_ldap_rpc_destr,
+  _xnss_ldap_endrpcent,
+  _xnss_ldap_setrpcent,
+  _xnss_ldap_getrpcent_r,
+  _xnss_ldap_getrpcbyname_r,
+  _xnss_ldap_getrpcbynumber_r
 };
 
-nss_backend_t *_nss_ldap_rpc_constr(const char *db_name,
-                      const char *src_name,const char *cfg_args)
+nss_backend_t *_nss_ldap_rpc_constr(const char *UNUSED(db_name),
+                      const char *UNUSED(src_name),const char 
*UNUSED(cfg_args))
 {
-  nss_ldap_backend_t *be;
-  if (!(be=(nss_ldap_backend_t *)malloc(sizeof(*be))))
+  nss_backend_t *be;
+  if (!(be=(nss_backend_t *)malloc(sizeof(*be))))
     return NULL;
   be->ops=rpc_ops;
   be->n_ops=sizeof(rpc_ops)/sizeof(nss_backend_op_t);
-  if (_nss_ldap_default_constr(be)!=NSS_STATUS_SUCCESS)
-    return NULL;
   return (nss_backend_t *)be;
 }
 
-#endif /* HAVE_NSSWITCH_H */
+#endif /* NSS_FLAVOUR_SOLARIS */

Modified: nss-pam-ldapd-solaris/nss/services.c
==============================================================================
--- nss-pam-ldapd-solaris/nss/services.c        Sat Oct  2 21:19:00 2010        
(r1235)
+++ nss-pam-ldapd-solaris/nss/services.c        Sun Oct  3 23:57:11 2010        
(r1236)
@@ -45,78 +45,100 @@
   return NSS_STATUS_SUCCESS;
 }
 
-#ifdef HAVE_NSSWITCH_H
-nss_status_t _nss_nslcd_getservbyname_r(
-#else /* not HAVE_NSSWITCH_H */
+#ifdef NSS_FLAVOUR_GLIBC
+
 nss_status_t _nss_ldap_getservbyname_r(
-#endif /* HAVE_NSSWITCH_H */
         const char *name,const char *protocol,struct servent *result,
         char *buffer,size_t buflen,int *errnop)
 {
-  NSS_BYGEN(NSLCD_ACTION_SERVICE_BYNAME,
+  NSS_BYGEN(NSLCD_ACTION_SERVICE_BYNAME,buffer,buflen,
             WRITE_STRING(fp,name);WRITE_STRING(fp,protocol),
             read_servent(fp,result,buffer,buflen,errnop));
-
+  return retv;
 }
 
-#ifdef HAVE_NSSWITCH_H
-nss_status_t _nss_nslcd_getservbyport_r(
-#else /* not HAVE_NSSWITCH_H */
 nss_status_t _nss_ldap_getservbyport_r(
-#endif /* HAVE_NSSWITCH_H */
         int port,const char *protocol,struct servent *result,
         char *buffer,size_t buflen,int *errnop)
 {
-  NSS_BYGEN(NSLCD_ACTION_SERVICE_BYNUMBER,
+  NSS_BYGEN(NSLCD_ACTION_SERVICE_BYNUMBER,buffer,buflen,
             WRITE_INT32(fp,ntohs(port));WRITE_STRING(fp,protocol),
             read_servent(fp,result,buffer,buflen,errnop));
+  return retv;
 }
 
 /* thread-local file pointer to an ongoing request */
 static __thread TFILE *protoentfp;
 
-#ifdef HAVE_NSSWITCH_H
-nss_status_t _nss_ldap_setservent(nss_backend_t *serv_context,void *args)
-#else /* not HAVE_NSSWITCH_H */
 nss_status_t _nss_ldap_setservent(int UNUSED(stayopen))
-#endif /* HAVE_NSSWITCH_H */
 {
   NSS_SETENT(protoentfp);
 }
 
-#ifdef HAVE_NSSWITCH_H
-nss_status_t _nss_nslcd_getservent_r(
-#else /* not HAVE_NSSWITCH_H */
 nss_status_t _nss_ldap_getservent_r(
-#endif /* HAVE_NSSWITCH_H */
         struct servent *result,char *buffer,size_t buflen,int *errnop)
 {
-  NSS_GETENT(protoentfp,NSLCD_ACTION_SERVICE_ALL,
+  NSS_GETENT(protoentfp,NSLCD_ACTION_SERVICE_ALL,buffer,buflen,
              read_servent(protoentfp,result,buffer,buflen,errnop));
+  return retv;
 }
 
-#ifdef HAVE_NSSWITCH_H
-nss_status_t _nss_ldap_endservent(nss_backend_t *serv_context,void *args)
-#else /* not HAVE_NSSWITCH_H */
 nss_status_t _nss_ldap_endservent(void)
-#endif /* HAVE_NSSWITCH_H */
 {
   NSS_ENDENT(protoentfp);
 }
 
-#ifdef HAVE_NSSWITCH_H
+#endif /* NSS_FLAVOUR_GLIBC */
+
+#ifdef NSS_FLAVOUR_SOLARIS
+
+static nss_status_t _nss_nslcd_getservbyname_r(
+        const char *name,const char *protocol,struct servent *result,
+        char *buffer,size_t buflen,int *errnop)
+{
+  NSS_BYGEN(NSLCD_ACTION_SERVICE_BYNAME,buffer,buflen,
+            WRITE_STRING(fp,name);WRITE_STRING(fp,protocol),
+            read_servent(fp,result,buffer,buflen,errnop));
+  return retv;
+}
+
+static nss_status_t _nss_nslcd_getservbyport_r(
+        int port,const char *protocol,struct servent *result,
+        char *buffer,size_t buflen,int *errnop)
+{
+  NSS_BYGEN(NSLCD_ACTION_SERVICE_BYNUMBER,buffer,buflen,
+            WRITE_INT32(fp,ntohs(port));WRITE_STRING(fp,protocol),
+            read_servent(fp,result,buffer,buflen,errnop));
+  return retv;
+}
 
-static nss_status_t _nss_ldap_getservbyname_r(nss_backend_t *be,void *args)
+static nss_status_t _xnss_ldap_setservent(nss_backend_t *UNUSED(be),void 
*UNUSED(args))
+{
+  NSS_SETENT(protoentfp);
+}
+
+static nss_status_t _nss_nslcd_getservent_r(
+        struct servent *result,char *buffer,size_t buflen,int *errnop)
+{
+  NSS_GETENT(protoentfp,NSLCD_ACTION_SERVICE_ALL,buffer,buflen,
+             read_servent(protoentfp,result,buffer,buflen,errnop));
+  return retv;
+}
+
+static nss_status_t _xnss_ldap_endservent(nss_backend_t *UNUSED(be),void 
*UNUSED(args))
+{
+  NSS_ENDENT(protoentfp);
+}
+
+static nss_status_t _xnss_ldap_getservbyname_r(nss_backend_t *UNUSED(be),void 
*args)
 {
-  char *name=(char *)NSS_ARGS(args)->key.serv.serv.name;
-  char *protocol=NSS_ARGS(args)->key.serv.proto?(char 
*)NSS_ARGS(args)->key.serv.proto:"";
   struct servent priv_service;
   struct servent *service=NSS_ARGS(args)->buf.result?(struct servent 
*)NSS_ARGS(args)->buf.result:&priv_service;
   char *buffer=NSS_ARGS(args)->buf.buffer;
   size_t buflen=NSS_ARGS(args)->buf.buflen;
   char *data_ptr;
   nss_status_t status;
-  status=_nss_nslcd_getservbyname_r(name,protocol,service,
+  
status=_nss_nslcd_getservbyname_r(NSS_ARGS(args)->key.serv.serv.name,NSS_ARGS(args)->key.serv.proto,service,
                                 buffer,buflen,&errno);
   if (status!=NSS_STATUS_SUCCESS)
     return status;
@@ -124,7 +146,7 @@
   {
     /* result==NULL, return file format */
     data_ptr=(char *)malloc(buflen);
-    sprintf(data_ptr,"%s %d/%s",name,service->s_port,
+    sprintf(data_ptr,"%s %d/%s",service->s_name,service->s_port,
             service->s_proto);
     if (service->s_aliases)
     {
@@ -147,17 +169,16 @@
   return status;
 }
 
-static nss_status_t _nss_ldap_getservbyport_r(nss_backend_t *be,void *args)
+static nss_status_t _xnss_ldap_getservbyport_r(nss_backend_t *UNUSED(be),void 
*args)
 {
   int port=NSS_ARGS(args)->key.serv.serv.port;
-  char *protocol=(char *)NSS_ARGS(args)->key.serv.proto;
   struct servent priv_service;
   struct servent *service=NSS_ARGS(args)->buf.result?(struct servent 
*)NSS_ARGS(args)->buf.result:&priv_service;
   char *buffer=NSS_ARGS(args)->buf.buffer;
   size_t buflen=NSS_ARGS(args)->buf.buflen;
   char *data_ptr;
   nss_status_t status;
-  
status=_nss_nslcd_getservbyport_r(port,protocol,service,buffer,buflen,&errno);
+  
status=_nss_nslcd_getservbyport_r(port,NSS_ARGS(args)->key.serv.proto,service,buffer,buflen,&errno);
   if (status!=NSS_STATUS_SUCCESS)
     return status;
   if (!NSS_ARGS(args)->buf.result)
@@ -187,7 +208,7 @@
   return status;
 }
 
-static nss_status_t _nss_ldap_getservent_r(nss_backend_t *serv_context,void 
*args)
+static nss_status_t _xnss_ldap_getservent_r(nss_backend_t *UNUSED(be),void 
*args)
 {
   struct servent priv_service;
   struct servent *service=NSS_ARGS(args)->buf.result?(struct servent 
*)NSS_ARGS(args)->buf.result:&priv_service;
@@ -225,31 +246,30 @@
   return status;
 }
 
-static nss_status_t _nss_ldap_services_destr(nss_backend_t *serv_context,void 
*args)
+static nss_status_t _xnss_ldap_services_destr(nss_backend_t *be,void 
*UNUSED(args))
 {
-  return _nss_ldap_default_destr(serv_context,args);
+  free(be);
+  return NSS_STATUS_SUCCESS;
 }
 
 static nss_backend_op_t services_ops[]={
-  _nss_ldap_services_destr,
-  _nss_ldap_endservent,
-  _nss_ldap_setservent,
-  _nss_ldap_getservent_r,
-  _nss_ldap_getservbyname_r,
-  _nss_ldap_getservbyport_r
+  _xnss_ldap_services_destr,
+  _xnss_ldap_endservent,
+  _xnss_ldap_setservent,
+  _xnss_ldap_getservent_r,
+  _xnss_ldap_getservbyname_r,
+  _xnss_ldap_getservbyport_r
 };
 
-nss_backend_t *_nss_ldap_services_constr(const char *db_name,
-                           const char *src_name,const char *cfg_args)
+nss_backend_t *_nss_ldap_services_constr(const char *UNUSED(db_name),
+                           const char *UNUSED(src_name),const char 
*UNUSED(cfg_args))
 {
-  nss_ldap_backend_t *be;
-  if (!(be=(nss_ldap_backend_t *)malloc(sizeof(*be))))
+  nss_backend_t *be;
+  if (!(be=(nss_backend_t *)malloc(sizeof(*be))))
     return NULL;
   be->ops=services_ops;
   be->n_ops=sizeof(services_ops)/sizeof(nss_backend_op_t);
-  if (_nss_ldap_default_constr(be)!=NSS_STATUS_SUCCESS)
-    return NULL;
   return (nss_backend_t *)be;
 }
 
-#endif /* HAVE_NSSWITCH_H */
+#endif /* NSS_FLAVOUR_SOLARIS */

Modified: nss-pam-ldapd-solaris/nss/shadow.c
==============================================================================
--- nss-pam-ldapd-solaris/nss/shadow.c  Sat Oct  2 21:19:00 2010        (r1235)
+++ nss-pam-ldapd-solaris/nss/shadow.c  Sun Oct  3 23:57:11 2010        (r1236)
@@ -48,67 +48,67 @@
   return NSS_STATUS_SUCCESS;
 }
 
-#ifdef HAVE_NSSWITCH_H
-nss_status_t _nss_nslcd_getspnam_r(
-#else /* not HAVE_NSSWITCH_H */
+#ifdef NSS_FLAVOUR_GLIBC
+
 nss_status_t _nss_ldap_getspnam_r(
-#endif /* HAVE_NSSWITCH_H */
         const char *name,struct spwd *result,char *buffer,
         size_t buflen,int *errnop)
 {
-  NSS_BYNAME(NSLCD_ACTION_SHADOW_BYNAME,
+  NSS_BYNAME(NSLCD_ACTION_SHADOW_BYNAME,buffer,buflen,
              name,
              read_spwd(fp,result,buffer,buflen,errnop));
+  return retv;
 }
 
 /* thread-local file pointer to an ongoing request */
 static __thread TFILE *spentfp;
 
-#ifdef HAVE_NSSWITCH_H
-nss_status_t _nss_ldap_setspent(nss_backend_t *be,void *args)
-#else /* not HAVE_NSSWITCH_H */
 nss_status_t _nss_ldap_setspent(int UNUSED(stayopen))
-#endif /* HAVE_NSSWITCH_H */
 {
   NSS_SETENT(spentfp);
 }
 
-#ifdef HAVE_NSSWITCH_H
-nss_status_t _nss_nslcd_getspent_r(
-#else /* not HAVE_NSSWITCH_H */
 nss_status_t _nss_ldap_getspent_r(
-#endif /* HAVE_NSSWITCH_H */
         struct spwd *result,char *buffer,size_t buflen,int *errnop)
 {
-  NSS_GETENT(spentfp,NSLCD_ACTION_SHADOW_ALL,
+  NSS_GETENT(spentfp,NSLCD_ACTION_SHADOW_ALL,buffer,buflen,
              read_spwd(spentfp,result,buffer,buflen,errnop));
+  return retv;
 }
 
-#ifdef HAVE_NSSWITCH_H
-nss_status_t _nss_ldap_endspent(nss_backend_t *sp_context,void *args)
-#else /* not HAVE_NSSWITCH_H */
 nss_status_t _nss_ldap_endspent(void)
-#endif /* HAVE_NSSWITCH_H */
 {
   NSS_ENDENT(spentfp);
 }
 
-#ifdef HAVE_NSSWITCH_H
-static nss_status_t _nss_ldap_getspnam_r(nss_backend_t *be,void *args)
+#endif /* NSS_FLAVOUR_GLIBC */
+
+#ifdef NSS_FLAVOUR_SOLARIS
+
+static nss_status_t _nss_nslcd_getspnam_r(
+        const char *name,struct spwd *result,char *buffer,
+        size_t buflen,int *errnop)
+{
+  NSS_BYNAME(NSLCD_ACTION_SHADOW_BYNAME,buffer,buflen,
+             name,
+             read_spwd(fp,result,buffer,buflen,errnop));
+  return retv;
+}
+
+static nss_status_t _xnss_ldap_getspnam_r(nss_backend_t *UNUSED(be),void *args)
 {
   struct spwd priv_spwd;
   struct spwd *sp=NSS_ARGS(args)->buf.result?(struct spwd 
*)NSS_ARGS(args)->buf.result:&priv_spwd;
   char *buffer=NSS_ARGS(args)->buf.buffer;
   size_t buflen=NSS_ARGS(args)->buf.buflen;
-  char *name=(char *)NSS_ARGS(args)->key.name;
   char *data_ptr;
   nss_status_t status;
-  if (NSS_ARGS(args)->buf.buflen < 0)
+  if (NSS_ARGS(args)->buf.buflen<0)
   {
     NSS_ARGS(args)->erange=1;
     return NSS_STATUS_TRYAGAIN;
   }
-  status=_nss_nslcd_getspnam_r(name,sp,buffer,buflen,&errno);
+  
status=_nss_nslcd_getspnam_r(NSS_ARGS(args)->key.name,sp,buffer,buflen,&errno);
   if (status!=NSS_STATUS_SUCCESS)
     return status;
   if (!NSS_ARGS(args)->buf.result)
@@ -164,7 +164,20 @@
   return status;
 }
 
-static nss_status_t _nss_ldap_getspent_r(nss_backend_t *sp_context,void *args)
+static nss_status_t _xnss_ldap_setspent(nss_backend_t *UNUSED(be),void 
*UNUSED(args))
+{
+  NSS_SETENT(spentfp);
+}
+
+static nss_status_t _nss_nslcd_getspent_r(
+        struct spwd *result,char *buffer,size_t buflen,int *errnop)
+{
+  NSS_GETENT(spentfp,NSLCD_ACTION_SHADOW_ALL,buffer,buflen,
+             read_spwd(spentfp,result,buffer,buflen,errnop));
+  return retv;
+}
+
+static nss_status_t _xnss_ldap_getspent_r(nss_backend_t *UNUSED(be),void *args)
 {
   struct spwd priv_spwd;
   struct spwd *sp=NSS_ARGS(args)->buf.result?(struct spwd 
*)NSS_ARGS(args)->buf.result:&priv_spwd;
@@ -172,7 +185,7 @@
   size_t buflen=NSS_ARGS(args)->buf.buflen;
   char *data_ptr;
   nss_status_t status;
-  if (NSS_ARGS(args)->buf.buflen < 0)
+  if (NSS_ARGS(args)->buf.buflen<0)
   {
     NSS_ARGS(args)->erange=1;
     return NSS_STATUS_TRYAGAIN;
@@ -233,30 +246,34 @@
   return status;
 }
 
-static nss_status_t _nss_ldap_shadow_destr(nss_backend_t *sp_context,void 
*args)
+static nss_status_t _xnss_ldap_endspent(nss_backend_t *UNUSED(be),void 
*UNUSED(args))
 {
-  return _nss_ldap_default_destr(sp_context,args);
+  NSS_ENDENT(spentfp);
+}
+
+static nss_status_t _xnss_ldap_shadow_destr(nss_backend_t *be,void 
*UNUSED(args))
+{
+  free(be);
+  return NSS_STATUS_SUCCESS;
 }
 
 static nss_backend_op_t shadow_ops[]={
-  _nss_ldap_shadow_destr,
-  _nss_ldap_endspent,         /* NSS_DBOP_ENDENT */
-  _nss_ldap_setspent,         /* NSS_DBOP_SETENT */
-  _nss_ldap_getspent_r,       /* NSS_DBOP_GETENT */
-  _nss_ldap_getspnam_r        /* NSS_DBOP_SHADOW_BYNAME */
+  _xnss_ldap_shadow_destr,
+  _xnss_ldap_endspent,         /* NSS_DBOP_ENDENT */
+  _xnss_ldap_setspent,         /* NSS_DBOP_SETENT */
+  _xnss_ldap_getspent_r,       /* NSS_DBOP_GETENT */
+  _xnss_ldap_getspnam_r        /* NSS_DBOP_SHADOW_BYNAME */
 };
 
-nss_backend_t *_nss_ldap_shadow_constr(const char *db_name,
-                         const char *src_name,const char *cfg_args)
+nss_backend_t *_nss_ldap_shadow_constr(const char *UNUSED(db_name),
+                         const char *UNUSED(src_name),const char 
*UNUSED(cfg_args))
 {
-  nss_ldap_backend_t *be;
-  if (!(be=(nss_ldap_backend_t *)malloc(sizeof(*be))))
+  nss_backend_t *be;
+  if (!(be=(nss_backend_t *)malloc(sizeof(*be))))
     return NULL;
   be->ops=shadow_ops;
   be->n_ops=sizeof(shadow_ops)/sizeof(nss_backend_op_t);
-  if (_nss_ldap_default_constr(be)!=NSS_STATUS_SUCCESS)
-    return NULL;
   return (nss_backend_t *)be;
 }
 
-#endif /* HAVE_NSSWITCH_H */
+#endif /* NSS_FLAVOUR_SOLARIS */
--
To unsubscribe send an email to
nss-pam-ldapd-commits-unsubscribe@lists.arthurdejong.org or see
http://lists.arthurdejong.org/nss-pam-ldapd-commits