lists.arthurdejong.org
RSS feed

nss-pam-ldapd commit: r1258 - nss-pam-ldapd-solaris/nss

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

nss-pam-ldapd commit: r1258 - nss-pam-ldapd-solaris/nss



Author: arthur
Date: Sun Oct 10 22:21:39 2010
New Revision: 1258
URL: http://arthurdejong.org/viewvc/nss-pam-ldapd?view=rev&revision=1258

Log:
generate Solaris NSS functions using same macros that are used for Glibc, 
splitting functionality to make a string representation into a single function 
per NSS map

Modified:
   nss-pam-ldapd-solaris/nss/aliases.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/rpc.c
   nss-pam-ldapd-solaris/nss/services.c
   nss-pam-ldapd-solaris/nss/shadow.c

Modified: nss-pam-ldapd-solaris/nss/aliases.c
==============================================================================
--- nss-pam-ldapd-solaris/nss/aliases.c Sun Oct 10 22:05:43 2010        (r1257)
+++ nss-pam-ldapd-solaris/nss/aliases.c Sun Oct 10 22:21:39 2010        (r1258)
@@ -52,10 +52,9 @@
         const char *name,struct aliasent *result,
         char *buffer,size_t buflen,int *errnop)
 {
-  NSS_BYNAME(NSLCD_ACTION_ALIAS_BYNAME,buffer,buflen,
+  NSS_BYNAME(NSLCD_ACTION_ALIAS_BYNAME,
              name,
              read_aliasent(fp,result,buffer,buflen,errnop));
-  return retv;
 }
 
 /* thread-local file pointer to an ongoing request */
@@ -72,9 +71,8 @@
         struct aliasent *result,
         char *buffer,size_t buflen,int *errnop)
 {
-  NSS_GETENT(aliasentfp,NSLCD_ACTION_ALIAS_ALL,buffer,buflen,
+  NSS_GETENT(aliasentfp,NSLCD_ACTION_ALIAS_ALL,
              read_aliasent(aliasentfp,result,buffer,buflen,errnop));
-  return retv;
 }
 
 /* close the stream opened with setaliasent() above */

Modified: nss-pam-ldapd-solaris/nss/common.h
==============================================================================
--- nss-pam-ldapd-solaris/nss/common.h  Sun Oct 10 22:05:43 2010        (r1257)
+++ nss-pam-ldapd-solaris/nss/common.h  Sun Oct 10 22:21:39 2010        (r1258)
@@ -79,6 +79,45 @@
   fp=NULL; \
   return NSS_STATUS_NOTFOUND;
 
+/* These are some general macros that are used to build parts of the
+   genral macros below. */
+
+/* check to see if we should answer NSS requests */
+#define NSS_AVAILCHECK \
+  if (!_nss_ldap_enablelookups) \
+    return NSS_STATUS_UNAVAIL;
+
+#ifdef NSS_FLAVOUR_GLIBC
+
+/* extra definitions we need (nothing for Glibc) */
+#define NSS_EXTRA_DEFS ;
+
+/* check validity of passed buffer (Glibc flavour) */
+#define NSS_BUFCHECK \
+  if ((buffer==NULL)||(buflen<=0)) \
+  { \
+      *errnop=EINVAL; \
+      return NSS_STATUS_UNAVAIL; \
+  }
+
+#endif /* NSS_FLAVOUR_GLIBC */
+
+#ifdef NSS_FLAVOUR_SOLARIS
+
+/* extra definitions we need (Solaris NSS functions don't pass errno) */
+#define NSS_EXTRA_DEFS \
+  int *errnop=&(errno);
+
+/* check validity of passed buffer (Solaris flavour) */
+#define NSS_BUFCHECK \
+  if ((NSS_ARGS(args)->buf.buffer==NULL)||(NSS_ARGS(args)->buf.buflen<=0)) \
+  { \
+      NSS_ARGS(args)->erange=1; \
+      return NSS_STATUS_TRYAGAIN; \
+  } \
+
+#endif /* NSS_FLAVOUR_SOLARIS */
+
 /* The following macros to automatically generate get..byname(),
    get..bynumber(), setent(), getent() and endent() function
    bodies. These functions have very common code so this can
@@ -92,18 +131,13 @@
    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,buffer,buflen,writefn,readfn) \
+#define NSS_BYGEN(action,writefn,readfn) \
   TFILE *fp; \
   int32_t tmpint32; \
   nss_status_t retv; \
-  if (!_nss_ldap_enablelookups) \
-    return NSS_STATUS_UNAVAIL; \
-  /* check that we have a valid buffer */ \
-  if ((buffer==NULL)||(buflen<=0)) \
-  { \
-      *errnop=EINVAL; \
-      return NSS_STATUS_UNAVAIL; \
-  } \
+  NSS_EXTRA_DEFS; \
+  NSS_AVAILCHECK; \
+  NSS_BUFCHECK; \
   /* open socket and write request */ \
   NSLCD_REQUEST(fp,action,writefn); \
   /* read response */ \
@@ -111,28 +145,28 @@
   retv=readfn; \
   /* close socket and we're done */ \
   if ((retv==NSS_STATUS_SUCCESS)||(retv==NSS_STATUS_TRYAGAIN)) \
-    (void)tio_close(fp);
+    (void)tio_close(fp); \
+  return retv;
 
 /* This macro can be used to generate a get..byname() function
    body. */
-#define NSS_BYNAME(action,buffer,buflen,name,readfn) \
-  NSS_BYGEN(action,buffer,buflen,WRITE_STRING(fp,name),readfn)
+#define NSS_BYNAME(action,name,readfn) \
+  NSS_BYGEN(action,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,buffer,buflen,val,type,readfn) \
-  NSS_BYGEN(action,buffer,buflen,WRITE_TYPE(fp,val,type),readfn)
+#define NSS_BYTYPE(action,val,type,readfn) \
+  NSS_BYGEN(action,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,buffer,buflen,val,readfn) \
-  NSS_BYGEN(action,buffer,buflen,WRITE_INT32(fp,val),readfn)
+#define NSS_BYINT32(action,val,readfn) \
+  NSS_BYGEN(action,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. */
 #define NSS_SETENT(fp) \
-  if (!_nss_ldap_enablelookups) \
-    return NSS_STATUS_UNAVAIL; \
+  NSS_AVAILCHECK; \
   if (fp!=NULL) \
   { \
     (void)tio_close(fp); \
@@ -143,24 +177,12 @@
 /* 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,buffer,buflen,readfn) \
+#define NSS_GETENT(fp,action,readfn) \
   int32_t tmpint32; \
   nss_status_t retv; \
-  if (!_nss_ldap_enablelookups) \
-    return NSS_STATUS_UNAVAIL; \
-  /* check that we have a valid buffer */ \
-  if ((buffer==NULL)||(buflen<=0)) \
-  { \
-      /* close stream */ \
-      if (fp!=NULL) \
-      { \
-        (void)tio_close(fp); \
-        fp=NULL; \
-      } \
-      /* indicate error */ \
-      *errnop=EINVAL; \
-      return NSS_STATUS_UNAVAIL; \
-  } \
+  NSS_EXTRA_DEFS; \
+  NSS_AVAILCHECK; \
+  NSS_BUFCHECK; \
   /* check that we have a valid file descriptor */ \
   if (fp==NULL) \
   { \
@@ -186,13 +208,13 @@
     } \
   } \
   else if (retv!=NSS_STATUS_SUCCESS) \
-    fp=NULL; /* file should be closed by now */
+    fp=NULL; /* file should be closed by now */ \
+  return retv;
 
 /* This macro generates a endent() function body. This just closes
    the stream. */
 #define NSS_ENDENT(fp) \
-  if (!_nss_ldap_enablelookups) \
-    return NSS_STATUS_UNAVAIL; \
+  NSS_AVAILCHECK; \
   if (fp!=NULL) \
   { \
     (void)tio_close(fp); \

Modified: nss-pam-ldapd-solaris/nss/ethers.c
==============================================================================
--- nss-pam-ldapd-solaris/nss/ethers.c  Sun Oct 10 22:05:43 2010        (r1257)
+++ nss-pam-ldapd-solaris/nss/ethers.c  Sun Oct 10 22:21:39 2010        (r1258)
@@ -49,10 +49,9 @@
         const char *name,struct etherent *result,
         char *buffer,size_t buflen,int *errnop)
 {
-  NSS_BYNAME(NSLCD_ACTION_ETHER_BYNAME,buffer,buflen,
+  NSS_BYNAME(NSLCD_ACTION_ETHER_BYNAME,
              name,
              read_etherent(fp,result,buffer,buflen,errnop));
-  return retv;
 }
 
 /* map an ethernet address to the corresponding hostname */
@@ -60,10 +59,9 @@
         const struct ether_addr *addr,struct etherent *result,
         char *buffer,size_t buflen,int *errnop)
 {
-  NSS_BYTYPE(NSLCD_ACTION_ETHER_BYETHER,buffer,buflen,
+  NSS_BYTYPE(NSLCD_ACTION_ETHER_BYETHER,
              *addr,uint8_t[6],
              read_etherent(fp,result,buffer,buflen,errnop));
-  return retv;
 }
 
 /* thread-local file pointer to an ongoing request */
@@ -80,9 +78,8 @@
         struct etherent *result,
         char *buffer,size_t buflen,int *errnop)
 {
-  NSS_GETENT(etherentfp,NSLCD_ACTION_ETHER_ALL,buffer,buflen,
+  NSS_GETENT(etherentfp,NSLCD_ACTION_ETHER_ALL,
              read_etherent(etherentfp,result,buffer,buflen,errnop));
-  return retv;
 }
 
 /* close the stream opened with setetherent() above */
@@ -99,107 +96,69 @@
 #define NSS_BUFLEN_ETHERS 1024
 #endif /* NSS_BUFLEN_ETHERS */
 
-#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)
+static nss_status_t read_etherstring(TFILE *fp,nss_XbyY_args_t *args)
 {
+  /* TODO: padl uses struct ether, verify */
   struct etherent result;
-  char buffer[NSS_BUFLEN_ETHERS];
-  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.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 retv;
-    }
-    memcpy(NSS_ARGS(args)->buf.result,&result.e_addr,sizeof(result.e_addr));
-    NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.result;
-  }
-  return retv;
+  nss_status_t retv;
+  char *buffer;
+  size_t buflen;
+  /* read the etherent */
+  
retv=read_etherent(fp,&result,NSS_ARGS(args)->buf.buffer,args->buf.buflen,&errno);
+  if (retv!=NSS_STATUS_SUCCESS)
+    return retv;
+  /* allocate a temporary buffer */
+  buflen=args->buf.buflen;
+  buffer=(char *)malloc(buflen);
+  /* build the formatted string */
+  /* FIXME: implement proper buffer size checking */
+  /* TODO: OpenSolaris expects "<macAddress> <host>" */
+  /* This output is handled correctly by NSCD,but not */
+  /* when NSCD is off. Not an issue with NSS_LDAP,but */
+  /* with the frontend. */
+  sprintf(buffer,"%s %s",ether_ntoa(&result.e_addr),result.e_name);
+  /* copy the result back to the result buffer and free the temporary one */
+  strcpy(NSS_ARGS(args)->buf.buffer,buffer);
+  free(buffer);
+  NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.buffer;
+  NSS_ARGS(args)->returnlen=strlen(NSS_ARGS(args)->buf.buffer);
+  return NSS_STATUS_SUCCESS;
 }
 
-/* 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 *)(NSS_ARGS(args)->key.ether);
-  char buffer[NSS_BUFLEN_ETHERS];
-  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)
-    {
-      /* TODO: OpenSolaris expects "<macAddress> <host>" */
-      /* This output is handled correctly by NSCD,but not */
-      /* when NSCD is off. Not an issue with NSS_LDAP,but */
-      /* with the frontend. */
-      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 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); /* ?? */
-  }
-  else
-  {
-    NSS_ARGS(args)->returnval=NULL;
-  }
-  return retv;
-}
+#define READ_RESULT(fp) \
+  NSS_ARGS(args)->buf.result? \
+    read_etherent(fp,(struct etherent 
*)NSS_ARGS(args)->buf.result,NSS_ARGS(args)->buf.buffer,NSS_ARGS(args)->buf.buflen,&errno):
 \
+    read_etherstring(fp,args); \
+  if (NSS_ARGS(args)->buf.result) \
+    NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.result
 
-/* thread-local file pointer to an ongoing request */
-static __thread TFILE *etherentfp;
-
-static nss_status_t _xnss_ldap_setetherent(nss_backend_t UNUSED(*be),void 
UNUSED(*args))
+/* map a hostname to the corresponding ethernet address */
+static nss_status_t get_gethostton(nss_backend_t UNUSED(*be),void *args)
 {
-  NSS_SETENT(etherentfp);
+  NSS_BYNAME(NSLCD_ACTION_ETHER_BYNAME,
+             NSS_ARGS(args)->key.name,
+             READ_RESULT(fp));
 }
 
-static nss_status_t _xnss_ldap_getetherent_r(nss_backend_t UNUSED(*be),void 
*args)
-{
-  /* TODO: padl uses struct ether,verify */
-  struct etherent result;
-  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 retv;
-}
-
-static nss_status_t _xnss_ldap_endetherent(nss_backend_t UNUSED(*be),void 
UNUSED(*args))
+/* map an ethernet address to the corresponding hostname */
+static nss_status_t get_getntohost(nss_backend_t UNUSED(*be),void *args)
 {
-  NSS_ENDENT(etherentfp);
+  struct ether_addr *addr=(struct ether_addr *)(NSS_ARGS(args)->key.ether);
+  NSS_BYTYPE(NSLCD_ACTION_ETHER_BYETHER,
+             *addr,uint8_t[6],
+             READ_RESULT(fp));
 }
 
-static nss_status_t _xnss_ldap_ethers_destr(nss_backend_t *be,void 
UNUSED(*args))
+static nss_status_t destructor(nss_backend_t *be,void UNUSED(*args))
 {
   free(be);
   return NSS_STATUS_SUCCESS;
 }
 
 static nss_backend_op_t ethers_ops[]={
-  _xnss_ldap_ethers_destr,
-  _xnss_ldap_gethostton_r,
-  _xnss_ldap_getntohost_r
+  destructor,
+  get_gethostton,
+  get_getntohost
 };
 
 nss_backend_t *_nss_ldap_ethers_constr(const char UNUSED(*db_name),

Modified: nss-pam-ldapd-solaris/nss/group.c
==============================================================================
--- nss-pam-ldapd-solaris/nss/group.c   Sun Oct 10 22:05:43 2010        (r1257)
+++ nss-pam-ldapd-solaris/nss/group.c   Sun Oct 10 22:21:39 2010        (r1258)
@@ -112,10 +112,9 @@
         const char *name,struct group *result,
         char *buffer,size_t buflen,int *errnop)
 {
-  NSS_BYNAME(NSLCD_ACTION_GROUP_BYNAME,buffer,buflen,
+  NSS_BYNAME(NSLCD_ACTION_GROUP_BYNAME,
              name,
              read_group(fp,result,buffer,buflen,errnop));
-  return retv;
 }
 
 /* get a group entry by numeric gid */
@@ -123,10 +122,9 @@
         gid_t gid,struct group *result,
         char *buffer,size_t buflen,int *errnop)
 {
-  NSS_BYTYPE(NSLCD_ACTION_GROUP_BYGID,buffer,buflen,
+  NSS_BYTYPE(NSLCD_ACTION_GROUP_BYGID,
              gid,gid_t,
              read_group(fp,result,buffer,buflen,errnop));
-  return retv;
 }
 
 /* thread-local file pointer to an ongoing request */
@@ -143,9 +141,8 @@
         struct group *result,
         char *buffer,size_t buflen,int *errnop)
 {
-  NSS_GETENT(grentfp,NSLCD_ACTION_GROUP_ALL,buffer,buflen,
+  NSS_GETENT(grentfp,NSLCD_ACTION_GROUP_ALL,
              read_group(grentfp,result,buffer,buflen,errnop));
-  return retv;
 }
 
 /* close the stream opened with setgrent() above */
@@ -170,227 +167,124 @@
         const char *user,gid_t skipgroup,long int *start,
         long int *size,gid_t **groupsp,long int limit,int *errnop)
 {
-  NSS_BYNAME(NSLCD_ACTION_GROUP_BYMEMBER,groupsp,*size,
+/* 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
+  NSS_BYNAME(NSLCD_ACTION_GROUP_BYMEMBER,
              user,
              read_gids(fp,skipgroup,start,size,groupsp,limit,errnop));
-  return retv;
+#undef buffer
+#undef buflen
 }
 
 #endif /* NSS_FLAVOUR_GLIBC */
 
 #ifdef NSS_FLAVOUR_SOLARIS
 
-static nss_status_t _nss_nslcd_getgrnam_r(
-        const char *name,struct group *result,char *buffer,
-        size_t buflen,int *errnop)
+static nss_status_t read_groupstring(TFILE *fp,nss_XbyY_args_t *args)
 {
-  NSS_BYNAME(NSLCD_ACTION_GROUP_BYNAME,buffer,buflen,
-             name,
-             read_group(fp,result,buffer,buflen,errnop));
-  return retv;
-}
-
-static nss_status_t _xnss_ldap_getgrnam_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;
-  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(NSS_ARGS(args)->key.name,gr,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);
-    sprintf(data_ptr,"%s:%s:%d:",gr->gr_name,gr->gr_passwd,(int) gr->gr_gid);
-    if (gr->gr_mem)
+  struct group result;
+  nss_status_t retv;
+  char *buffer;
+  size_t buflen;
+  int i;
+  /* read the groupent */
+  
retv=read_group(fp,&result,NSS_ARGS(args)->buf.buffer,args->buf.buflen,&errno);
+  if (retv!=NSS_STATUS_SUCCESS)
+    return retv;
+  /* allocate a temporary buffer */
+  buflen=args->buf.buflen;
+  buffer=(char *)malloc(buflen);
+  /* build the formatted string */
+  /* FIXME: implement proper buffer size checking */
+  
sprintf(buffer,"%s:%s:%d:",result.gr_name,result.gr_passwd,(int)result.gr_gid);
+  if (result.gr_mem)
+    for (i=0;result.gr_mem[i];i++)
     {
-      int i;
-      for (i=0; gr->gr_mem[i]; i++)
-      {
-        if (i)
-          strcat(data_ptr,",");
-        strcat(data_ptr,gr->gr_mem[i]);
-      }
+      if (i)
+        strcat(buffer,",");
+      strcat(buffer,result.gr_mem[i]);
     }
-    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
-  { /* result!=NULL */
-    NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.result;
-  }
-  return status;
-}
-
-static nss_status_t _nss_nslcd_getgrgid_r(
-        gid_t gid,struct group *result,char *buffer,
-        size_t buflen,int *errnop)
+  /* copy the result back to the result buffer and free the temporary one */
+  strcpy(NSS_ARGS(args)->buf.buffer,buffer);
+  free(buffer);
+  NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.buffer;
+  NSS_ARGS(args)->returnlen=strlen(NSS_ARGS(args)->buf.buffer);
+  return NSS_STATUS_SUCCESS;
+}
+
+#define READ_RESULT(fp) \
+  NSS_ARGS(args)->buf.result? \
+    read_group(fp,(struct group 
*)NSS_ARGS(args)->buf.result,NSS_ARGS(args)->buf.buffer,NSS_ARGS(args)->buf.buflen,&errno):
 \
+    read_groupstring(fp,args); \
+  if (NSS_ARGS(args)->buf.result) \
+    NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.result
+
+static nss_status_t get_getgrnam_r(nss_backend_t UNUSED(*be),void *args)
 {
-  NSS_BYTYPE(NSLCD_ACTION_GROUP_BYGID,buffer,buflen,
-             gid,gid_t,
-             read_group(fp,result,buffer,buflen,errnop));
-  return retv;
+  NSS_BYNAME(NSLCD_ACTION_GROUP_BYNAME,
+             NSS_ARGS(args)->key.name,
+             READ_RESULT(fp));
 }
 
-static nss_status_t _xnss_ldap_getgrgid_r(nss_backend_t UNUSED(*be),void *args)
+static nss_status_t get_getgrgid_r(nss_backend_t UNUSED(*be),void *args)
 {
-  gid_t gid=NSS_ARGS(args)->key.gid;
-  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_getgrgid_r(gid,gr,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);
-    sprintf(data_ptr,"%s:%s:%d:",gr->gr_name,gr->gr_passwd,(int) gr->gr_gid);
-    if (gr->gr_mem)
-    {
-      int i;
-      for (i=0; gr->gr_mem[i]; i++)
-      {
-        if (i)
-          strcat(data_ptr,",");
-        strcat(data_ptr,gr->gr_mem[i]);
-      }
-    }
-    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
-  { /* result!=NULL */
-    NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.result;
-  }
-  return status;
+  NSS_BYTYPE(NSLCD_ACTION_GROUP_BYGID,
+             NSS_ARGS(args)->key.gid,gid_t,
+             READ_RESULT(fp));
 }
 
 /* thread-local file pointer to an ongoing request */
 static __thread TFILE *grentfp;
 
-static nss_status_t _xnss_ldap_setgrent(nss_backend_t UNUSED(*be),void 
UNUSED(*args))
+static nss_status_t get_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)
+static nss_status_t get_getgrent_r(nss_backend_t UNUSED(*be),void *args)
 {
-  NSS_GETENT(grentfp,NSLCD_ACTION_GROUP_ALL,buffer,buflen,
-             read_group(grentfp,result,buffer,buflen,errnop));
-  return retv;
+  NSS_GETENT(grentfp,NSLCD_ACTION_GROUP_ALL,
+             READ_RESULT(grentfp));
 }
 
-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;
-  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_getgrent_r(gr,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);
-    sprintf(data_ptr,"%s:%s:%d:",gr->gr_name,gr->gr_passwd,(int)gr->gr_gid);
-    if (gr->gr_mem)
-    {
-      int i;
-      for (i=0; gr->gr_mem[i]; i++)
-      {
-        if (i)
-          strcat(data_ptr,",");
-        strcat(data_ptr,gr->gr_mem[i]);
-      }
-    }
-    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
-  { /* result!=NULL */
-    NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.result;
-  }
-  return status;
-}
-
-static nss_status_t _xnss_ldap_endgrent(nss_backend_t UNUSED(*be),void 
UNUSED(*args))
+static nss_status_t get_endgrent(nss_backend_t UNUSED(*be),void UNUSED(*args))
 {
   NSS_ENDENT(grentfp);
 }
 
-/* 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(
+/*
+static nss_status_t get_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)
+*/
+static nss_status_t get_getgroupsbymember_r(nss_backend_t UNUSED(*be),void 
*args)
 {
   struct nss_groupsbymem *argp=(struct nss_groupsbymem *)args;
-  nss_status_t status;
-  long int limit=(long int)argp->maxgids;
   long int start=(long int)argp->numgids;
-  gid_t skipgroup;
-  if (start>0)
-    skipgroup=argp->gid_array[0];
-  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;
+  gid_t skipgroup=(start>0)?argp->gid_array[0]:(gid_t)-1;
+  NSS_BYNAME(NSLCD_ACTION_GROUP_BYMEMBER,
+             argp->username,
+             read_gids(fp,skipgroup,&start,NULL,(gid_t 
**)&argp->gid_array,argp->maxgids,&errno);
+             argp->numgids=(int)start;);
 }
 
-static nss_status_t _xnss_ldap_group_destr(nss_backend_t *be,void 
UNUSED(*args))
+static nss_status_t destructor(nss_backend_t *be,void UNUSED(*args))
 {
   free(be);
   return NSS_STATUS_SUCCESS;
 }
 
 static nss_backend_op_t group_ops[]={
-  _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
+  destructor,
+  get_endgrent,
+  get_setgrent,
+  get_getgrent_r,
+  get_getgrnam_r,
+  get_getgrgid_r,
+  get_getgroupsbymember_r
 };
 
 nss_backend_t *_nss_ldap_group_constr(const char UNUSED(*db_name),

Modified: nss-pam-ldapd-solaris/nss/hosts.c
==============================================================================
--- nss-pam-ldapd-solaris/nss/hosts.c   Sun Oct 10 22:05:43 2010        (r1257)
+++ nss-pam-ldapd-solaris/nss/hosts.c   Sun Oct 10 22:21:39 2010        (r1258)
@@ -184,10 +184,9 @@
         const char *name,int af,struct hostent *result,
         char *buffer,size_t buflen,int *errnop,int *h_errnop)
 {
-  NSS_BYNAME(NSLCD_ACTION_HOST_BYNAME,buffer,buflen,
+  NSS_BYNAME(NSLCD_ACTION_HOST_BYNAME,
              name,
              
read_hostent_erronempty(fp,af,result,buffer,buflen,errnop,h_errnop));
-  return retv;
 }
 
 /* this function just calls the gethostbyname2() variant with the address
@@ -211,10 +210,9 @@
         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,buffer,buflen,
+  NSS_BYGEN(NSLCD_ACTION_HOST_BYADDR,
             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 */
@@ -230,9 +228,8 @@
         struct hostent *result,
         char *buffer,size_t buflen,int *errnop,int *h_errnop)
 {
-  NSS_GETENT(hostentfp,NSLCD_ACTION_HOST_ALL,buffer,buflen,
+  NSS_GETENT(hostentfp,NSLCD_ACTION_HOST_ALL,
              
read_hostent_nextonempty(hostentfp,AF_INET,result,buffer,buflen,errnop,h_errnop));
-  return retv;
 }
 
 /* close the stream opened with sethostent() above */
@@ -245,191 +242,122 @@
 
 #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)
+static nss_status_t read_hoststring(TFILE *fp,nss_XbyY_args_t *args,int 
erronempty)
 {
-  struct hostent priv_host;
-  struct hostent 
*host=NSS_ARGS(args)->buf.result?NSS_ARGS(args)->buf.result:&priv_host;
-  char *data_ptr;
-  
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));
+  struct hostent result;
+  nss_status_t retv;
+  char *buffer;
+  size_t buflen;
+  int i;
+  /* read the hostent */
+  if (erronempty)
+    
retv=read_hostent_erronempty(fp,NSS_ARGS(args)->key.hostaddr.type,&result,NSS_ARGS(args)->buf.buffer,args->buf.buflen,&errno,&(NSS_ARGS(args)->h_errno));
+  else
+    
retv=read_hostent_nextonempty(fp,NSS_ARGS(args)->key.hostaddr.type,&result,NSS_ARGS(args)->buf.buffer,args->buf.buflen,&errno,&(NSS_ARGS(args)->h_errno));
   if (retv!=NSS_STATUS_SUCCESS)
     return retv;
-  if (!NSS_ARGS(args)->buf.result)
+  /* allocate a temporary buffer */
+  buflen=args->buf.buflen;
+  buffer=(char *)malloc(buflen);
+  /* build the formatted string */
+  /* FIXME: implement proper buffer size checking */
+  if (result.h_addr_list)
   {
-    /* result==NULL, return file format */
-    data_ptr=(char *)malloc(NSS_ARGS(args)->buf.buflen);
-    if (host->h_addr_list)
+    struct in_addr in;
+    (void)memcpy(&in.s_addr,result.h_addr_list[0],sizeof(in.s_addr));
+    sprintf(buffer,"%s %s",inet_ntoa(in),result.h_name);
+    if (result.h_aliases)
     {
-      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++)
+      int j;
+      for (j=0;result.h_aliases[j];j++)
       {
-        (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 */
+        strcat(buffer,"  ");
+        strcat(buffer,result.h_aliases[j]);
       }
     }
-    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;
+    for (i=1;result.h_addr_list[i];i++)
+    {
+      (void)memcpy(&in.s_addr,result.h_addr_list[i],sizeof(in.s_addr));
+      strcat(buffer,"\n");
+      strcat(buffer,inet_ntoa(in));
+      strcat(buffer," ");
+      strcat(buffer,result.h_name);
+      /* TODO: aliases only supplied to the first address */
+      /* need review */
+    }
   }
-  return retv;
+  /* copy the result back to the result buffer and free the temporary one */
+  strcpy(NSS_ARGS(args)->buf.buffer,buffer);
+  free(buffer);
+  NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.buffer;
+  NSS_ARGS(args)->returnlen=strlen(NSS_ARGS(args)->buf.buffer);
+  return NSS_STATUS_SUCCESS;
 }
 
-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;
-  char *data_ptr;
-  
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))
+#define READ_RESULT_ERRONEMPTY(fp) \
+  NSS_ARGS(args)->buf.result? \
+    read_hostent_erronempty(fp,NSS_ARGS(args)->key.hostaddr.type,(struct 
hostent 
*)NSS_ARGS(args)->buf.result,NSS_ARGS(args)->buf.buffer,NSS_ARGS(args)->buf.buflen,&errno,&(NSS_ARGS(args)->h_errno)):
 \
+    read_hoststring(fp,args,1); \
+  if (NSS_ARGS(args)->buf.result) \
+    NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.result
+
+#define READ_RESULT_NEXTONEMPTY(fp) \
+  NSS_ARGS(args)->buf.result? \
+    read_hostent_nextonempty(fp,NSS_ARGS(args)->key.hostaddr.type,(struct 
hostent 
*)NSS_ARGS(args)->buf.result,NSS_ARGS(args)->buf.buffer,NSS_ARGS(args)->buf.buflen,&errno,&(NSS_ARGS(args)->h_errno)):
 \
+    read_hoststring(fp,args,0); \
+  if (NSS_ARGS(args)->buf.result) \
+    NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.result
 
 
-  if (retv!=NSS_STATUS_SUCCESS)
-    return retv;
-  if (!NSS_ARGS(args)->buf.result)
-  {
-    /* 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;
+/* hack to set the correct errno and h_errno */
+#define h_errnop &(NSS_ARGS(args)->h_errno)
+
+static nss_status_t get_gethostbyname(nss_backend_t UNUSED(*be),void *args)
+{
+  NSS_BYNAME(NSLCD_ACTION_HOST_BYNAME,
+             NSS_ARGS(args)->key.name,
+             READ_RESULT_ERRONEMPTY(fp));
+}
+
+static nss_status_t get_gethostbyaddr(nss_backend_t UNUSED(*be),void *args)
+{
+  NSS_BYGEN(NSLCD_ACTION_HOST_BYADDR,
+            
WRITE_ADDRESS(fp,NSS_ARGS(args)->key.hostaddr.type,NSS_ARGS(args)->key.hostaddr.len,NSS_ARGS(args)->key.hostaddr.addr),
+            READ_RESULT_ERRONEMPTY(fp));
 }
 
 /* thread-local file pointer to an ongoing request */
 static __thread TFILE *hostentfp;
 
-static nss_status_t _xnss_ldap_sethostent(nss_backend_t UNUSED(*be),void 
UNUSED(*args))
+static nss_status_t get_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)
+static nss_status_t get_gethostent(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(NSS_ARGS(args)->buf.buflen);
-    if (host->h_addr_list)
-    {
-      int i;
-      sprintf(data_ptr,"%s %s",host->h_addr_list[0],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++)
-      {
-        strcat(data_ptr,"\n");
-        strcat(data_ptr,host->h_addr_list[i]);
-        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;
+  NSS_GETENT(hostentfp,NSLCD_ACTION_HOST_ALL,
+             READ_RESULT_NEXTONEMPTY(hostentfp));
 }
 
-static nss_status_t _xnss_ldap_endhostent(nss_backend_t UNUSED(*be),void 
UNUSED(*args))
+static nss_status_t get_endhostent(nss_backend_t UNUSED(*be),void 
UNUSED(*args))
 {
   NSS_ENDENT(hostentfp);
 }
 
-static nss_status_t _xnss_ldap_hosts_destr(nss_backend_t *be,void 
UNUSED(*args))
+static nss_status_t destructor(nss_backend_t *be,void UNUSED(*args))
 {
   free(be);
   return NSS_STATUS_SUCCESS;
 }
 
 static nss_backend_op_t host_ops[]={
-  _xnss_ldap_hosts_destr,
-  _xnss_ldap_endhostent,
-  _xnss_ldap_sethostent,
-  _xnss_ldap_gethostent_r,
-  _xnss_ldap_gethostbyname_r,
-  _xnss_ldap_gethostbyaddr_r
+  destructor,
+  get_endhostent,
+  get_sethostent,
+  get_gethostent,
+  get_gethostbyname,
+  get_gethostbyaddr
 };
 
 nss_backend_t *_nss_ldap_hosts_constr(const char UNUSED(*db_name),

Modified: nss-pam-ldapd-solaris/nss/netgroup.c
==============================================================================
--- nss-pam-ldapd-solaris/nss/netgroup.c        Sun Oct 10 22:05:43 2010        
(r1257)
+++ nss-pam-ldapd-solaris/nss/netgroup.c        Sun Oct 10 22:21:39 2010        
(r1258)
@@ -117,9 +117,8 @@
         struct __netgrent *result,
         char *buffer,size_t buflen,int *errnop)
 {
-  NSS_GETENT(netgrentfp,NSLCD_ACTION_NETGROUP_BYNAME,buffer,buflen,
+  NSS_GETENT(netgrentfp,NSLCD_ACTION_NETGROUP_BYNAME,
              read_netgrent(netgrentfp,result,buffer,buflen,errnop));
-  return retv;
 }
 
 /* close the stream opened with setnetgrent() above */
@@ -192,13 +191,6 @@
 /* thread-local file pointer to an ongoing request */
 static __thread TFILE *netgrentfp;
 
-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
@@ -206,8 +198,7 @@
   int32_t tmpint32;
   int errnocp;
   int *errnop;
-  if (!_nss_ldap_enablelookups)
-    return NSS_STATUS_UNAVAIL;
+  NSS_AVAILCHECK;
   errnop=&errnocp;
   /* check parameter */
   if ((group==NULL)||(group[0]=='\0'))
@@ -217,6 +208,12 @@
   return NSS_STATUS_SUCCESS;
 }
 
+static nss_status_t _nss_nslcd_getnetgrent_r(struct __netgrent *result,char 
*buffer,size_t buflen,void *args)
+{
+  NSS_GETENT(netgrentfp,NSLCD_ACTION_NETGROUP_BYNAME,
+             read_netgrent(netgrentfp,result,buffer,buflen,errnop));
+}
+
 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;
@@ -224,15 +221,14 @@
   struct __netgrent result;
   char *group=NULL;
   int done=0;
-  int err;
   nss_status_t status,rc;
   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,args);
     if (status!=NSS_STATUS_SUCCESS)
     {
-      if (err==ENOENT)
+      if (errno==ENOENT)
       {
         /* done with the current netgroup */
         /* explore nested netgroup,if any */
@@ -298,7 +294,7 @@
   NSS_ENDENT(netgrentfp);
 }
 
-static nss_status_t _xnss_ldap_netgroup_destr(nss_backend_t *be,void 
UNUSED(*args))
+static nss_status_t destructor(nss_backend_t *be,void UNUSED(*args))
 {
   nss_ldap_netgr_backend_t *ngbe=(nss_ldap_netgr_backend_t *)be;
   /* free list of nested netgroups */
@@ -311,7 +307,7 @@
 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 */
+  destructor,          /* NSS_DBOP_DESTRUCTOR */
   _xnss_ldap_endnetgrent,             /* NSS_DBOP_ENDENT */
   _xnss_ldap_setnetgrent,             /* NSS_DBOP_SETNET */
   _xnss_ldap_getnetgrent_r,           /* NSS_DBOP_GETENT */
@@ -325,7 +321,6 @@
   struct nss_setnetgrent_args *args;
   nss_ldap_netgr_backend_t *ngbe;
   struct __netgrent result;
-  char *group=NULL;
   args=(struct nss_setnetgrent_args *)_args;
   args->iterator=NULL;        /* initialize */
   ngbe=(nss_ldap_netgr_backend_t *)malloc(sizeof(*ngbe));
@@ -336,18 +331,17 @@
   ngbe->state=NULL;
   ngbe->known_groups=NULL;
   ngbe->needed_groups=NULL;
-  group=(char *)args->netgroup;
-  stat=_nss_nslcd_setnetgrent(group,&result);
+  stat=_nss_nslcd_setnetgrent(args->netgroup,&result);
   if (stat!=NSS_STATUS_SUCCESS)
   {
     free(be);
     return stat;
   }
   /* place the group name in known list */
-  stat=_nss_ldap_namelist_push(&ngbe->known_groups,group);
+  stat=_nss_ldap_namelist_push(&ngbe->known_groups,args->netgroup);
   if (stat!=NSS_STATUS_SUCCESS)
   {
-    _xnss_ldap_netgroup_destr((nss_backend_t *)ngbe,NULL);
+    destructor((nss_backend_t *)ngbe,NULL);
     return stat;
   }
   args->iterator=(nss_backend_t *)ngbe;

Modified: nss-pam-ldapd-solaris/nss/networks.c
==============================================================================
--- nss-pam-ldapd-solaris/nss/networks.c        Sun Oct 10 22:05:43 2010        
(r1257)
+++ nss-pam-ldapd-solaris/nss/networks.c        Sun Oct 10 22:21:39 2010        
(r1258)
@@ -118,10 +118,9 @@
         const char *name,struct netent *result,
         char *buffer,size_t buflen,int *errnop,int *h_errnop)
 {
-  NSS_BYNAME(NSLCD_ACTION_NETWORK_BYNAME,buffer,buflen,
+  NSS_BYNAME(NSLCD_ACTION_NETWORK_BYNAME,
              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 */
@@ -130,10 +129,9 @@
         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,
+  NSS_BYGEN(NSLCD_ACTION_NETWORK_BYADDR,
             WRITE_ADDRESS(fp,addr),
             read_netent(fp,result,buffer,buflen,errnop,h_errnop))
-  return retv;
 }
 
 /* thread-local file pointer to an ongoing request */
@@ -150,9 +148,8 @@
         struct netent *result,
         char *buffer,size_t buflen,int *errnop,int *h_errnop)
 {
-  NSS_GETENT(netentfp,NSLCD_ACTION_NETWORK_ALL,buffer,buflen,
+  NSS_GETENT(netentfp,NSLCD_ACTION_NETWORK_ALL,
              read_netent(netentfp,result,buffer,buflen,errnop,h_errnop));
-  return retv;
 }
 
 /* close the stream opened by setnetent() above */
@@ -165,132 +162,61 @@
 
 #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)
+static nss_status_t read_netentstring(TFILE *fp,nss_XbyY_args_t *args)
 {
-  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;
-  char *name=(char *)NSS_ARGS(args)->key.name;
-  int af=NSS_ARGS(args)->key.netaddr.type;
-  char *buffer=NSS_ARGS(args)->buf.buffer;
-  size_t buflen=NSS_ARGS(args)->buf.buflen;
-  int h_errno;
-  char *data_ptr;
-  nss_status_t status;
-  if (NSS_ARGS(args)->buf.buflen<0)
-  {
-    NSS_ARGS(args)->erange=1;
-    return NSS_STATUS_TRYAGAIN;
-  }
-  status=_nss_nslcd_getnetbyname_r(name,network,buffer,
-                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 */
-    struct in_addr priv_in_addr;
-    priv_in_addr.s_addr = network->n_net;
-    data_ptr=(char *)malloc(buflen);
-    sprintf(data_ptr,"%s %s",name,inet_ntoa(priv_in_addr)); /* ipNetworkNumber 
*/
-    if (network->n_aliases)
+  struct netent result;
+  nss_status_t retv;
+  char *buffer;
+  size_t buflen;
+  int i;
+  struct in_addr priv_in_addr;
+  /* read the netent */
+  
retv=read_netent(fp,&result,NSS_ARGS(args)->buf.buffer,args->buf.buflen,&errno,&(NSS_ARGS(args)->h_errno));
+  if (retv!=NSS_STATUS_SUCCESS)
+    return retv;
+  /* allocate a temporary buffer */
+  buflen=args->buf.buflen;
+  buffer=(char *)malloc(buflen);
+  /* build the formatted string */
+  /* FIXME: implement proper buffer size checking */
+  priv_in_addr.s_addr = result.n_net;
+  sprintf(buffer,"%s %s",result.n_name,inet_ntoa(priv_in_addr)); /* 
ipNetworkNumber */
+  if (result.n_aliases)
+    for (i=0;result.n_aliases[i];i++)
     {
-      int i;
-      for (i=0; network->n_aliases[i]; i++)
-      {
-        strcat(data_ptr," ");
-        strcat(data_ptr,network->n_aliases[i]);
-      }
+      strcat(buffer," ");
+      strcat(buffer,result.n_aliases[i]);
     }
-    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)->returnval=NSS_ARGS(args)->buf.result;
-  }
-  NSS_ARGS(args)->h_errno=h_errno;
-  return status;
+  /* copy the result back to the result buffer and free the temporary one */
+  strcpy(NSS_ARGS(args)->buf.buffer,buffer);
+  free(buffer);
+  NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.buffer;
+  NSS_ARGS(args)->returnlen=strlen(NSS_ARGS(args)->buf.buffer);
+  return NSS_STATUS_SUCCESS;
 }
 
-/* Note: the af parameter is ignored and is assumed to be AF_INET */
-/* TODO: implement handling of af parameter */
-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)
+#define READ_RESULT(fp) \
+  NSS_ARGS(args)->buf.result? \
+    read_netent(fp,(struct netent 
*)NSS_ARGS(args)->buf.result,NSS_ARGS(args)->buf.buffer,NSS_ARGS(args)->buf.buflen,&errno,&(NSS_ARGS(args)->h_errno)):
 \
+    read_netentstring(fp,args); \
+  if (NSS_ARGS(args)->buf.result) \
+    NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.result
+
+/* more of a dirty hack */
+#define h_errnop (&(NSS_ARGS(args)->h_errno))
+
+static nss_status_t _xnss_ldap_getnetbyname_r(nss_backend_t UNUSED(*be),void 
*args)
 {
-  NSS_BYGEN(NSLCD_ACTION_NETWORK_BYADDR,buffer,buflen,
-            WRITE_ADDRESS(fp,addr),
-            read_netent(fp,result,buffer,buflen,errnop,h_errnop))
-  return retv;
+  NSS_BYNAME(NSLCD_ACTION_NETWORK_BYNAME,
+             NSS_ARGS(args)->key.name,
+             READ_RESULT(fp));
 }
 
-/* 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; /* 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;
-  int h_errno;
-  char *data_ptr;
-  struct in_addr in_addr;
-  nss_status_t status;
-  if (NSS_ARGS(args)->buf.buflen<0)
-  {
-    NSS_ARGS(args)->erange=1;
-    return NSS_STATUS_TRYAGAIN;
-  }
-  
status=_nss_nslcd_getnetbyaddr_r(addr,af,network,buffer,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 */
-    (void)memcpy(&in_addr.s_addr,addr,sizeof(in_addr.s_addr));
-    data_ptr=(char *)malloc(buflen);
-    sprintf(data_ptr,"%s %s",network->n_name,
-        inet_ntoa(in_addr)); /* ipNetworkNumber */
-    if (network->n_aliases)
-    {
-      int i;
-      for (i=0; network->n_aliases[i]; i++)
-      {
-        strcat(data_ptr," ");
-        strcat(data_ptr,network->n_aliases[i]);
-      }
-    }
-    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)->returnval=NSS_ARGS(args)->buf.result;
-  }
-  NSS_ARGS(args)->h_errno=h_errno;
-  return status;
+  NSS_BYGEN(NSLCD_ACTION_NETWORK_BYADDR,
+            WRITE_ADDRESS(fp,NSS_ARGS(args)->key.netaddr.net),
+            READ_RESULT(fp));
 }
 
 /* thread-local file pointer to an ongoing request */
@@ -301,60 +227,10 @@
   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;
-  char *buffer=NSS_ARGS(args)->buf.buffer;
-  size_t buflen=NSS_ARGS(args)->buf.buflen;
-  int h_errno;
-  char *data_ptr;
-  nss_status_t status;
-  if (NSS_ARGS(args)->buf.buflen<0)
-  {
-    NSS_ARGS(args)->erange=1;
-    return NSS_STATUS_TRYAGAIN;
-  }
-  status=_nss_nslcd_getnetent_r(network,buffer,buflen,&errno,&h_errno);
-  if (status!=NSS_STATUS_SUCCESS)
-    return status;
-  if (!NSS_ARGS(args)->buf.result)
-  {
-    /* result==NULL, return file format */
-    struct in_addr priv_in_addr;
-    priv_in_addr.s_addr = network->n_net;
-    data_ptr=(char *)malloc(buflen);
-    sprintf(data_ptr,"%s %s",network->n_name,
-                inet_ntoa(priv_in_addr)); /* ipNetworkNumber */
-    if (network->n_aliases)
-    {
-      int i;
-      for (i=0; network->n_aliases[i]; i++)
-      {
-        strcat(data_ptr," ");
-        strcat(data_ptr,network->n_aliases[i]);
-      }
-    }
-    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)->returnval=NSS_ARGS(args)->buf.result;
-  }
-  NSS_ARGS(args)->h_errno=h_errno;
-  return status;
+  NSS_GETENT(netentfp,NSLCD_ACTION_NETWORK_ALL,
+             READ_RESULT(netentfp));
 }
 
 static nss_status_t _xnss_ldap_endnetent(nss_backend_t UNUSED(*be),void 
UNUSED(*args))
@@ -362,14 +238,14 @@
   NSS_ENDENT(netentfp);
 }
 
-static nss_status_t _xnss_ldap_networks_destr(nss_backend_t *be,void 
UNUSED(*args))
+static nss_status_t destructor(nss_backend_t *be,void UNUSED(*args))
 {
   free(be);
   return NSS_STATUS_SUCCESS;
 }
 
 static nss_backend_op_t net_ops[]={
-  _xnss_ldap_networks_destr,
+  destructor,
   _xnss_ldap_endnetent,
   _xnss_ldap_setnetent,
   _xnss_ldap_getnetent_r,

Modified: nss-pam-ldapd-solaris/nss/passwd.c
==============================================================================
--- nss-pam-ldapd-solaris/nss/passwd.c  Sun Oct 10 22:05:43 2010        (r1257)
+++ nss-pam-ldapd-solaris/nss/passwd.c  Sun Oct 10 22:21:39 2010        (r1258)
@@ -54,10 +54,9 @@
         const char *name,struct passwd *result,
         char *buffer,size_t buflen,int *errnop)
 {
-  NSS_BYNAME(NSLCD_ACTION_PASSWD_BYNAME,buffer,buflen,
+  NSS_BYNAME(NSLCD_ACTION_PASSWD_BYNAME,
              name,
              read_passwd(fp,result,buffer,buflen,errnop));
-  return retv;
 }
 
 /* get a single passwd entry by uid */
@@ -65,10 +64,9 @@
         uid_t uid,struct passwd *result,
         char *buffer,size_t buflen,int *errnop)
 {
-  NSS_BYTYPE(NSLCD_ACTION_PASSWD_BYUID,buffer,buflen,
+  NSS_BYTYPE(NSLCD_ACTION_PASSWD_BYUID,
              uid,uid_t,
              read_passwd(fp,result,buffer,buflen,errnop));
-  return retv;
 }
 
 /* thread-local file pointer to an ongoing request */
@@ -85,9 +83,8 @@
         struct passwd *result,
         char *buffer,size_t buflen,int *errnop)
 {
-  NSS_GETENT(pwentfp,NSLCD_ACTION_PASSWD_ALL,buffer,buflen,
+  NSS_GETENT(pwentfp,NSLCD_ACTION_PASSWD_ALL,
              read_passwd(pwentfp,result,buffer,buflen,errnop));
-  return retv;
 }
 
 /* close the stream opened with setpwent() above */
@@ -100,167 +97,88 @@
 
 #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)
+static nss_status_t read_passwdstring(TFILE *fp,nss_XbyY_args_t *args)
 {
-  NSS_BYNAME(NSLCD_ACTION_PASSWD_BYNAME,buffer,buflen,
-             name,
-             read_passwd(fp,result,buffer,buflen,errnop));
-  return retv;
+  struct passwd result;
+  nss_status_t retv;
+  char *buffer;
+  size_t buflen;
+  /* read the passwd */
+  
retv=read_passwd(fp,&result,NSS_ARGS(args)->buf.buffer,args->buf.buflen,&errno);
+  if (retv!=NSS_STATUS_SUCCESS)
+    return retv;
+  /* allocate a temporary buffer */
+  buflen=args->buf.buflen;
+  buffer=(char *)malloc(buflen);
+  /* build the formatted string */
+  /* FIXME: implement proper buffer size checking */
+   sprintf(buffer,"%s:%s:%d:%d:%s:%s:%s",
+     
result.pw_name,result.pw_passwd,(int)result.pw_uid,(int)result.pw_gid,result.pw_gecos,
+     result.pw_dir,result.pw_shell);
+  /* copy the result back to the result buffer and free the temporary one */
+  strcpy(NSS_ARGS(args)->buf.buffer,buffer);
+  free(buffer);
+  NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.buffer;
+  NSS_ARGS(args)->returnlen=strlen(NSS_ARGS(args)->buf.buffer);
+  return NSS_STATUS_SUCCESS;
 }
 
-static nss_status_t _xnss_ldap_getpwnam_r(nss_backend_t UNUSED(*be),void *args)
+#define READ_RESULT(fp) \
+  NSS_ARGS(args)->buf.result? \
+    read_passwd(fp,(struct passwd 
*)NSS_ARGS(args)->buf.result,NSS_ARGS(args)->buf.buffer,NSS_ARGS(args)->buf.buflen,&errno):
 \
+    read_passwdstring(fp,args); \
+  if (NSS_ARGS(args)->buf.result) \
+    NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.result
+
+static nss_status_t get_getpwnam(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 *data_ptr;
-  nss_status_t status;
-  if (NSS_ARGS(args)->buf.buflen<0)
-  {
-    NSS_ARGS(args)->erange=1;
-    status=NSS_STATUS_TRYAGAIN;
-    return status;
-  }
-  
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)
-  {
-     /* result==NULL, return file format */
-     data_ptr=(char *)malloc(buflen);
-     sprintf(data_ptr,"%s:%s:%d:%d:%s:%s:%s",
-       pw->pw_name,"x",(int) pw->pw_uid,(int) pw->pw_gid,pw->pw_gecos,
-       pw->pw_dir,pw->pw_shell);
-     /* copy file-format data to buffer provided by front-end */
-     strcpy(buffer,data_ptr);
-     if (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)->returnval=NSS_ARGS(args)->buf.result;
-  }
-  return status;
-}
-
-static nss_status_t _nss_nslcd_getpwuid_r(
-        uid_t uid,struct passwd *result,char *buffer,
-        size_t buflen,int *errnop)
+  NSS_BYNAME(NSLCD_ACTION_PASSWD_BYNAME,
+             NSS_ARGS(args)->key.name,
+             READ_RESULT(fp));
+}
+
+static nss_status_t get_getpwuid(nss_backend_t UNUSED(*be),void *args)
 {
-  NSS_BYTYPE(NSLCD_ACTION_PASSWD_BYUID,buffer,buflen,
-             uid,uid_t,
-             read_passwd(fp,result,buffer,buflen,errnop));
-  return retv;
+  NSS_BYTYPE(NSLCD_ACTION_PASSWD_BYUID,
+             NSS_ARGS(args)->key.uid,uid_t,
+             READ_RESULT(fp));
 }
 
 /* thread-local file pointer to an ongoing request */
 static __thread TFILE *pwentfp;
 
 /* 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))
+static nss_status_t get_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)
+static nss_status_t get_getpwent(nss_backend_t UNUSED(*be),void *args)
 {
-  NSS_GETENT(pwentfp,NSLCD_ACTION_PASSWD_ALL,buffer,buflen,
-             read_passwd(pwentfp,result,buffer,buflen,errnop));
-  return retv;
+  NSS_GETENT(pwentfp,NSLCD_ACTION_PASSWD_ALL,
+             READ_RESULT(pwentfp));
 }
 
 /* close the stream opened with setpwent() above */
-static nss_status_t _xnss_ldap_endpwent(nss_backend_t UNUSED(*be),void 
UNUSED(*args))
+static nss_status_t get_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 ?
-                NSS_ARGS(args)->buf.result : &priv_pw;
-  uid_t uid=NSS_ARGS(args)->key.uid;
-  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_getpwuid_r(uid,pw,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((size_t) buflen);
-    sprintf(data_ptr,"%s:%s:%d:%d:%s:%s:%s",
-            pw->pw_name,"x",(int) pw->pw_uid,(int) pw->pw_gid,pw->pw_gecos,
-            pw->pw_dir,pw->pw_shell);
-    /* copy file-format data to buffer provided by front-end */
-    strcpy(buffer,data_ptr);
-    if (data_ptr)
-      free((void *)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)->returnval=NSS_ARGS(args)->buf.result;
-  }
-  return status;
-}
-
-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;
-  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_getpwent_r(pw,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);
-     sprintf(data_ptr,"%s:%s:%d:%d:%s:%s:%s",
-       pw->pw_name,"x",(int) pw->pw_uid,(int) pw->pw_gid,pw->pw_gecos,
-       pw->pw_dir,pw->pw_shell);
-     /* copy file-format data to buffer provided by front-end */
-     strcpy(buffer,data_ptr);
-     if (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)->returnval=NSS_ARGS(args)->buf.result;
-  }
-  return status;
-}
-
-static nss_status_t _xnss_ldap_passwd_destr(nss_backend_t *be,void 
UNUSED(*args))
+static nss_status_t destructor(nss_backend_t *be,void UNUSED(*args))
 {
   free(be);
   return NSS_STATUS_SUCCESS;
 }
 
 static nss_backend_op_t passwd_ops[]={
-  _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 */
+  destructor,
+  get_endpwent,       /* NSS_DBOP_ENDENT */
+  get_setpwent,       /* NSS_DBOP_SETENT */
+  get_getpwent,       /* NSS_DBOP_GETENT */
+  get_getpwnam,       /* NSS_DBOP_PASSWD_BYNAME */
+  get_getpwuid        /* NSS_DBOP_PASSWD_BYUID */
 };
 
 nss_backend_t *_nss_ldap_passwd_constr(const char UNUSED(*db_name),

Modified: nss-pam-ldapd-solaris/nss/protocols.c
==============================================================================
--- nss-pam-ldapd-solaris/nss/protocols.c       Sun Oct 10 22:05:43 2010        
(r1257)
+++ nss-pam-ldapd-solaris/nss/protocols.c       Sun Oct 10 22:21:39 2010        
(r1258)
@@ -50,10 +50,9 @@
         const char *name,struct protoent *result,
         char *buffer,size_t buflen,int *errnop)
 {
-  NSS_BYNAME(NSLCD_ACTION_PROTOCOL_BYNAME,buffer,buflen,
+  NSS_BYNAME(NSLCD_ACTION_PROTOCOL_BYNAME,
              name,
              read_protoent(fp,result,buffer,buflen,errnop));
-  return retv;
 }
 
 /* get a protocol entry by number */
@@ -61,10 +60,9 @@
         int number,struct protoent *result,
         char *buffer,size_t buflen,int *errnop)
 {
-  NSS_BYINT32(NSLCD_ACTION_PROTOCOL_BYNUMBER,buffer,buflen,
+  NSS_BYINT32(NSLCD_ACTION_PROTOCOL_BYNUMBER,
               number,
               read_protoent(fp,result,buffer,buflen,errnop));
-  return retv;
 }
 
 /* thread-local file pointer to an ongoing request */
@@ -81,9 +79,8 @@
         struct protoent *result,
         char *buffer,size_t buflen,int *errnop)
 {
-  NSS_GETENT(protoentfp,NSLCD_ACTION_PROTOCOL_ALL,buffer,buflen,
+  NSS_GETENT(protoentfp,NSLCD_ACTION_PROTOCOL_ALL,
              read_protoent(protoentfp,result,buffer,buflen,errnop));
-  return retv;
 }
 
 /* close the stream opened by setprotoent() above */
@@ -96,196 +93,98 @@
 
 #ifdef NSS_FLAVOUR_SOLARIS
 
-static nss_status_t _nss_nslcd_getprotobyname_r(
-        const char *name,struct protoent *result,char *buffer,
-        size_t buflen,int *errnop)
+static nss_status_t read_protostring(TFILE *fp,nss_XbyY_args_t *args)
 {
-  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 *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)
-  {
-    NSS_ARGS(args)->erange=1;
-    return NSS_STATUS_TRYAGAIN;
-  }
-  
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)
+  struct protoent result;
+  nss_status_t retv;
+  char *buffer;
+  size_t buflen;
+  int i;
+  /* read the protoent */
+  
retv=read_protoent(fp,&result,NSS_ARGS(args)->buf.buffer,args->buf.buflen,&errno);
+  if (retv!=NSS_STATUS_SUCCESS)
+    return retv;
+  /* allocate a temporary buffer */
+  buflen=args->buf.buflen;
+  buffer=(char *)malloc(buflen);
+  /* build the formatted string */
+  /* FIXME: implement proper buffer size checking */
+  sprintf(buffer,"%s\t\t%d",result.p_name,result.p_proto);
+  if (result.p_aliases)
+    for (i=0; result.p_aliases[i]; i++)
     {
-      int i;
-      for (i=0; proto->p_aliases[i]; i++)
-      {
-        strcat(data_ptr," ");
-        strcat(data_ptr,proto->p_aliases[i]);
-      }
+      strcat(buffer," ");
+      strcat(buffer,result.p_aliases[i]);
     }
-    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)->returnval=NSS_ARGS(args)->buf.result;
-  }
-  return status;
-}
-
-static nss_status_t _nss_nslcd_getprotobynumber_r(
-        int number,struct protoent *result,char *buffer,
-        size_t buflen,int *errnop)
+  /* copy the result back to the result buffer and free the temporary one */
+  strcpy(NSS_ARGS(args)->buf.buffer,buffer);
+  free(buffer);
+  NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.buffer;
+  NSS_ARGS(args)->returnlen=strlen(NSS_ARGS(args)->buf.buffer);
+  return NSS_STATUS_SUCCESS;
+}
+
+#define READ_RESULT(fp) \
+  NSS_ARGS(args)->buf.result? \
+    read_protoent(fp,(struct protoent 
*)NSS_ARGS(args)->buf.result,NSS_ARGS(args)->buf.buffer,NSS_ARGS(args)->buf.buflen,&errno):
 \
+    read_protostring(fp,args); \
+  if (NSS_ARGS(args)->buf.result) \
+    NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.result
+
+static nss_status_t get_getprotobyname(nss_backend_t UNUSED(*be),void *args)
 {
-  NSS_BYINT32(NSLCD_ACTION_PROTOCOL_BYNUMBER,buffer,buflen,
-              number,
-              read_protoent(fp,result,buffer,buflen,errnop));
-  return retv;
+  NSS_BYNAME(NSLCD_ACTION_PROTOCOL_BYNAME,
+             NSS_ARGS(args)->key.name,
+             READ_RESULT(fp));
 }
 
-static nss_status_t _xnss_ldap_getprotobynumber_r(nss_backend_t 
UNUSED(*be),void *args)
+static nss_status_t get_getprotobynumber(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;
-  int number=NSS_ARGS(args)->key.number;
-  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)
-  {
-    NSS_ARGS(args)->erange=1;
-    return NSS_STATUS_TRYAGAIN;
-  }
-  status=_nss_nslcd_getprotobynumber_r(number,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);
-    sprintf(data_ptr,"%s\t\t%d",proto->p_name,proto->p_proto);
-    if (proto->p_aliases)
-    {
-      int i;
-      for (i=0; proto->p_aliases[i]; i++)
-      {
-        strcat(data_ptr," ");
-        strcat(data_ptr,proto->p_aliases[i]);
-      }
-    }
-    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)->returnval=NSS_ARGS(args)->buf.result;
-  }
-  return status;
+  NSS_BYINT32(NSLCD_ACTION_PROTOCOL_BYNUMBER,
+              NSS_ARGS(args)->key.number,
+              READ_RESULT(fp));
 }
 
 /* thread-local file pointer to an ongoing request */
 static __thread TFILE *protoentfp;
 
-static nss_status_t _xnss_ldap_setprotoent(nss_backend_t UNUSED(*be),void 
UNUSED(*args))
+static nss_status_t get_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)
+static nss_status_t get_getprotoent(nss_backend_t UNUSED(*be),void *args)
 {
-  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;
-  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)
-  {
-    NSS_ARGS(args)->erange=1;
-    return NSS_STATUS_TRYAGAIN;
-  }
-  status=_nss_nslcd_getprotoent_r(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);
-    sprintf(data_ptr,"%s\t\t%d",proto->p_name,proto->p_proto);
-    if (proto->p_aliases)
-    {
-      int i;
-      for (i=0; proto->p_aliases[i]; i++)
-      {
-        strcat(data_ptr," ");
-        strcat(data_ptr,proto->p_aliases[i]);
-      }
-    }
-    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)->returnval=NSS_ARGS(args)->buf.result;
-  }
-  return status;
+  NSS_GETENT(protoentfp,NSLCD_ACTION_PROTOCOL_ALL,
+             READ_RESULT(protoentfp));
 }
 
-static nss_status_t _xnss_ldap_endprotoent(nss_backend_t UNUSED(*be),void 
UNUSED(*args))
+static nss_status_t get_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))
+static nss_status_t destructor(nss_backend_t *be,void UNUSED(*args))
 {
   free(be);
   return NSS_STATUS_SUCCESS;
 }
 
 static nss_backend_op_t proto_ops[]={
-  _xnss_ldap_protocols_destr,
-  _xnss_ldap_endprotoent,
-  _xnss_ldap_setprotoent,
-  _xnss_ldap_getprotoent_r,
-  _xnss_ldap_getprotobyname_r,
-  _xnss_ldap_getprotobynumber_r
+  destructor,
+  get_endprotoent,
+  get_setprotoent,
+  get_getprotoent,
+  get_getprotobyname,
+  get_getprotobynumber
 };
 
 nss_backend_t *_nss_ldap_protocols_constr(const char UNUSED(*db_name),
-                            const char UNUSED(*src_name),const char 
UNUSED(*cfg_args))
+        const char UNUSED(*src_name),const char UNUSED(*cfg_args))
 {
   nss_backend_t *be;
-  if (!(be=(nss_backend_t *)malloc(sizeof(*be))))
+  be=(nss_backend_t *)malloc(sizeof(*be));
+  if (be==NULL)
     return NULL;
   be->ops=proto_ops;
   be->n_ops=sizeof(proto_ops)/sizeof(nss_backend_op_t);

Modified: nss-pam-ldapd-solaris/nss/rpc.c
==============================================================================
--- nss-pam-ldapd-solaris/nss/rpc.c     Sun Oct 10 22:05:43 2010        (r1257)
+++ nss-pam-ldapd-solaris/nss/rpc.c     Sun Oct 10 22:21:39 2010        (r1258)
@@ -50,10 +50,9 @@
         const char *name,struct rpcent *result,
         char *buffer,size_t buflen,int *errnop)
 {
-  NSS_BYNAME(NSLCD_ACTION_RPC_BYNAME,buffer,buflen,
+  NSS_BYNAME(NSLCD_ACTION_RPC_BYNAME,
              name,
              read_rpcent(fp,result,buffer,buflen,errnop));
-  return retv;
 }
 
 /* get a rpc entry by number */
@@ -61,10 +60,9 @@
         int number,struct rpcent *result,
         char *buffer,size_t buflen,int *errnop)
 {
-  NSS_BYINT32(NSLCD_ACTION_RPC_BYNUMBER,buffer,buflen,
+  NSS_BYINT32(NSLCD_ACTION_RPC_BYNUMBER,
               number,
               read_rpcent(fp,result,buffer,buflen,errnop));
-  return retv;
 }
 
 /* thread-local file pointer to an ongoing request */
@@ -81,9 +79,8 @@
         struct rpcent *result,
         char *buffer,size_t buflen,int *errnop)
 {
-  NSS_GETENT(rpcentfp,NSLCD_ACTION_RPC_ALL,buffer,buflen,
+  NSS_GETENT(rpcentfp,NSLCD_ACTION_RPC_ALL,
              read_rpcent(rpcentfp,result,buffer,buflen,errnop));
-  return retv;
 }
 
 /* close the stream opened by setrpcent() above */
@@ -96,187 +93,90 @@
 
 #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)
+static nss_status_t read_rpcstring(TFILE *fp,nss_XbyY_args_t *args)
 {
-  NSS_BYNAME(NSLCD_ACTION_RPC_BYNAME,buffer,buflen,
-             name,
-             read_rpcent(fp,result,buffer,buflen,errnop));
-  return retv;
+  struct rpcent result;
+  nss_status_t retv;
+  char *buffer;
+  size_t buflen;
+  int i;
+  /* read the rpcent */
+  
retv=read_rpcent(fp,&result,NSS_ARGS(args)->buf.buffer,args->buf.buflen,&errno);
+  if (retv!=NSS_STATUS_SUCCESS)
+    return retv;
+  /* allocate a temporary buffer */
+  buflen=args->buf.buflen;
+  buffer=(char *)malloc(buflen);
+  /* build the formatted string */
+  /* FIXME: implement proper buffer size checking */
+  sprintf(buffer,"%s %d",result.r_name,result.r_number);
+  if (result.r_aliases)
+    for (i=0; result.r_aliases[i]; i++)
+    {
+      strcat(buffer," ");
+      strcat(buffer,result.r_aliases[i]);
+    }
+  /* copy the result back to the result buffer and free the temporary one */
+  strcpy(NSS_ARGS(args)->buf.buffer,buffer);
+  free(buffer);
+  NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.buffer;
+  NSS_ARGS(args)->returnlen=strlen(NSS_ARGS(args)->buf.buffer);
+  return NSS_STATUS_SUCCESS;
 }
 
-static nss_status_t _nss_nslcd_getrpcbynumber_r(
-        int number,struct rpcent *result,char *buffer,
-        size_t buflen,int *errnop)
+#define READ_RESULT(fp) \
+  NSS_ARGS(args)->buf.result? \
+    read_rpcent(fp,(struct rpcent 
*)NSS_ARGS(args)->buf.result,NSS_ARGS(args)->buf.buffer,NSS_ARGS(args)->buf.buflen,&errno):
 \
+    read_rpcstring(fp,args); \
+  if (NSS_ARGS(args)->buf.result) \
+    NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.result
+
+static nss_status_t get_getrpcbyname_r(nss_backend_t UNUSED(*be),void *args)
 {
-  NSS_BYINT32(NSLCD_ACTION_RPC_BYNUMBER,buffer,buflen,
-              number,
-              read_rpcent(fp,result,buffer,buflen,errnop));
-  return retv;
+  NSS_BYNAME(NSLCD_ACTION_RPC_BYNAME,
+             NSS_ARGS(args)->key.name,
+             READ_RESULT(fp));
+}
+
+static nss_status_t get_getrpcbynumber_r(nss_backend_t UNUSED(*be),void *args)
+{
+  NSS_BYINT32(NSLCD_ACTION_RPC_BYNUMBER,
+              NSS_ARGS(args)->key.number,
+              READ_RESULT(fp));
 }
 
 /* thread-local file pointer to an ongoing request */
 static __thread TFILE *rpcentfp;
 
-static nss_status_t _xnss_ldap_setrpcent(nss_backend_t UNUSED(*be),void 
UNUSED(*args))
+static nss_status_t get_setrpcent(nss_backend_t UNUSED(*be),void UNUSED(*args))
 {
   NSS_SETENT(rpcentfp);
 }
 
-static nss_status_t _nss_nslcd_getrpcent_r(
-        struct rpcent *result,char *buffer,size_t buflen,int *errnop)
+static nss_status_t get_getrpcent_r(nss_backend_t UNUSED(*be),void *args)
 {
-  NSS_GETENT(rpcentfp,NSLCD_ACTION_RPC_ALL,buffer,buflen,
-             read_rpcent(rpcentfp,result,buffer,buflen,errnop));
-  return retv;
+  NSS_GETENT(rpcentfp,NSLCD_ACTION_RPC_ALL,
+             READ_RESULT(rpcentfp));
 }
 
-static nss_status_t _xnss_ldap_endrpcent(nss_backend_t UNUSED(*be),void 
UNUSED(*args))
+static nss_status_t get_endrpcent(nss_backend_t UNUSED(*be),void UNUSED(*args))
 {
   NSS_ENDENT(rpcentfp);
 }
 
-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 *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)
-  {
-    NSS_ARGS(args)->erange=1;
-    return NSS_STATUS_TRYAGAIN;
-  }
-  
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)
-  {
-    /* result==NULL, return file format */
-    data_ptr=(char *)malloc(buflen);
-    sprintf(data_ptr,"%s %d",rpc->r_name,rpc->r_number);
-    if (rpc->r_aliases)
-    {
-      int i;
-      for (i=0; rpc->r_aliases[i]; i++)
-      {
-        strcat(data_ptr," ");
-        strcat(data_ptr,rpc->r_aliases[i]);
-      }
-    }
-    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)->returnval=NSS_ARGS(args)->buf.result;
-  }
-  return status;
-}
-
-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;
-  int number=NSS_ARGS(args)->key.number;
-  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)
-  {
-    NSS_ARGS(args)->erange=1;
-    return NSS_STATUS_TRYAGAIN;
-  }
-  status=_nss_nslcd_getrpcbynumber_r(number,rpc,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);
-    sprintf(data_ptr,"%s %d",rpc->r_name,rpc->r_number);
-    if (rpc->r_aliases)
-    {
-      int i;
-      for (i=0; rpc->r_aliases[i]; i++)
-      {
-        strcat(data_ptr," ");
-        strcat(data_ptr,rpc->r_aliases[i]);
-      }
-    }
-    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)->returnval=NSS_ARGS(args)->buf.result;
-  }
-  return status;
-}
-
-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;
-  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)
-  {
-    NSS_ARGS(args)->erange=1;
-    return NSS_STATUS_TRYAGAIN;
-  }
-  status=_nss_nslcd_getrpcent_r(rpc,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);
-    sprintf(data_ptr,"%s %d",rpc->r_name,rpc->r_number);
-    if (rpc->r_aliases)
-    {
-      int i;
-      for (i=0; rpc->r_aliases[i]; i++)
-      {
-        strcat(data_ptr," ");
-        strcat(data_ptr,rpc->r_aliases[i]);
-      }
-    }
-    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)->returnval=NSS_ARGS(args)->buf.result;
-  }
-  return status;
-}
-
-static nss_status_t _xnss_ldap_rpc_destr(nss_backend_t *be,void UNUSED(*args))
+static nss_status_t destructor(nss_backend_t *be,void UNUSED(*args))
 {
   free(be);
   return NSS_STATUS_SUCCESS;
 }
 
 static nss_backend_op_t rpc_ops[]={
-  _xnss_ldap_rpc_destr,
-  _xnss_ldap_endrpcent,
-  _xnss_ldap_setrpcent,
-  _xnss_ldap_getrpcent_r,
-  _xnss_ldap_getrpcbyname_r,
-  _xnss_ldap_getrpcbynumber_r
+  destructor,
+  get_endrpcent,
+  get_setrpcent,
+  get_getrpcent_r,
+  get_getrpcbyname_r,
+  get_getrpcbynumber_r
 };
 
 nss_backend_t *_nss_ldap_rpc_constr(const char UNUSED(*db_name),

Modified: nss-pam-ldapd-solaris/nss/services.c
==============================================================================
--- nss-pam-ldapd-solaris/nss/services.c        Sun Oct 10 22:05:43 2010        
(r1257)
+++ nss-pam-ldapd-solaris/nss/services.c        Sun Oct 10 22:21:39 2010        
(r1258)
@@ -54,10 +54,9 @@
         const char *name,const char *protocol,struct servent *result,
         char *buffer,size_t buflen,int *errnop)
 {
-  NSS_BYGEN(NSLCD_ACTION_SERVICE_BYNAME,buffer,buflen,
+  NSS_BYGEN(NSLCD_ACTION_SERVICE_BYNAME,
             WRITE_STRING(fp,name);WRITE_STRING(fp,protocol),
             read_servent(fp,result,buffer,buflen,errnop));
-  return retv;
 }
 
 /* get a service entry by port and protocol */
@@ -65,10 +64,9 @@
         int port,const char *protocol,struct servent *result,
         char *buffer,size_t buflen,int *errnop)
 {
-  NSS_BYGEN(NSLCD_ACTION_SERVICE_BYNUMBER,buffer,buflen,
+  NSS_BYGEN(NSLCD_ACTION_SERVICE_BYNUMBER,
             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 */
@@ -85,9 +83,8 @@
         struct servent *result,
         char *buffer,size_t buflen,int *errnop)
 {
-  NSS_GETENT(serventfp,NSLCD_ACTION_SERVICE_ALL,buffer,buflen,
+  NSS_GETENT(serventfp,NSLCD_ACTION_SERVICE_ALL,
              read_servent(serventfp,result,buffer,buflen,errnop));
-  return retv;
 }
 
 /* close the stream opened by setservent() above */
@@ -100,176 +97,92 @@
 
 #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)
+static nss_status_t read_servstring(TFILE *fp,nss_XbyY_args_t *args)
 {
-  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;
+  struct servent result;
+  nss_status_t retv;
+  char *buffer;
+  size_t buflen;
+  int i;
+  /* read the servent */
+  
retv=read_servent(fp,&result,NSS_ARGS(args)->buf.buffer,args->buf.buflen,&errno);
+  if (retv!=NSS_STATUS_SUCCESS)
+    return retv;
+  /* allocate a temporary buffer */
+  buflen=args->buf.buflen;
+  buffer=(char *)malloc(buflen);
+  /* build the formatted string */
+  /* FIXME: implement proper buffer size checking */
+  sprintf(buffer,"%s %d/%s",result.s_name,result.s_port,result.s_proto);
+  if (result.s_aliases)
+    for (i=0;result.s_aliases[i];i++)
+    {
+      strcat(buffer," ");
+      strcat(buffer,result.s_aliases[i]);
+    }
+  /* copy the result back to the result buffer and free the temporary one */
+  strcpy(NSS_ARGS(args)->buf.buffer,buffer);
+  free(buffer);
+  NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.buffer;
+  NSS_ARGS(args)->returnlen=strlen(NSS_ARGS(args)->buf.buffer);
+  return NSS_STATUS_SUCCESS;
 }
 
-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;
+#define READ_RESULT(fp) \
+  NSS_ARGS(args)->buf.result? \
+    read_servent(fp,(struct servent 
*)NSS_ARGS(args)->buf.result,NSS_ARGS(args)->buf.buffer,NSS_ARGS(args)->buf.buflen,&errno):
 \
+    read_servstring(fp,args); \
+  if (NSS_ARGS(args)->buf.result) \
+    NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.result
+
+static nss_status_t get_getservbyname_r(nss_backend_t UNUSED(*be),void *args)
+{
+  NSS_BYGEN(NSLCD_ACTION_SERVICE_BYNAME,
+            WRITE_STRING(fp,NSS_ARGS(args)->key.serv.serv.name);
+            WRITE_STRING(fp,NSS_ARGS(args)->key.serv.proto),
+            READ_RESULT(fp));
+}
+
+static nss_status_t get_getservbyport_r(nss_backend_t UNUSED(*be),void *args)
+{
+  NSS_BYGEN(NSLCD_ACTION_SERVICE_BYNUMBER,
+            WRITE_INT32(fp,ntohs(NSS_ARGS(args)->key.serv.serv.port));
+            WRITE_STRING(fp,NSS_ARGS(args)->key.serv.proto),
+            READ_RESULT(fp));
 }
 
 /* thread-local file pointer to an ongoing request */
 static __thread TFILE *serventfp;
 
-static nss_status_t _xnss_ldap_setservent(nss_backend_t UNUSED(*be),void 
UNUSED(*args))
+static nss_status_t get_setservent(nss_backend_t UNUSED(*be),void 
UNUSED(*args))
 {
   NSS_SETENT(serventfp);
 }
 
-static nss_status_t _nss_nslcd_getservent_r(
-        struct servent *result,char *buffer,size_t buflen,int *errnop)
+static nss_status_t get_getservent_r(nss_backend_t UNUSED(*be),void *args)
 {
-  NSS_GETENT(serventfp,NSLCD_ACTION_SERVICE_ALL,buffer,buflen,
-             read_servent(serventfp,result,buffer,buflen,errnop));
-  return retv;
+  NSS_GETENT(serventfp,NSLCD_ACTION_SERVICE_ALL,
+             READ_RESULT(serventfp));
 }
 
-static nss_status_t _xnss_ldap_endservent(nss_backend_t UNUSED(*be),void 
UNUSED(*args))
+static nss_status_t get_endservent(nss_backend_t UNUSED(*be),void 
UNUSED(*args))
 {
   NSS_ENDENT(serventfp);
 }
 
-static nss_status_t _xnss_ldap_getservbyname_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;
-  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(NSS_ARGS(args)->key.serv.serv.name,NSS_ARGS(args)->key.serv.proto,service,
-                                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);
-    sprintf(data_ptr,"%s %d/%s",service->s_name,service->s_port,
-            service->s_proto);
-    if (service->s_aliases)
-    {
-      int i;
-      for (i=0; service->s_aliases[i]; i++)
-      {
-        strcat(data_ptr," ");
-        strcat(data_ptr,service->s_aliases[i]);
-      }
-    }
-    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)->returnval=NSS_ARGS(args)->buf.result;
-  }
-  return status;
-}
-
-static nss_status_t _xnss_ldap_getservbyport_r(nss_backend_t UNUSED(*be),void 
*args)
-{
-  int port=NSS_ARGS(args)->key.serv.serv.port;
-  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,NSS_ARGS(args)->key.serv.proto,service,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);
-    sprintf(data_ptr,"%s %d/%s",service->s_name,port,
-            service->s_proto);
-    if (service->s_aliases)
-    {
-      int i;
-      for (i=0; service->s_aliases[i]; i++)
-      {
-        strcat(data_ptr," ");
-        strcat(data_ptr,service->s_aliases[i]);
-      }
-    }
-    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)->returnval=NSS_ARGS(args)->buf.result;
-  }
-  return status;
-}
-
-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;
-  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_getservent_r(service,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);
-    sprintf(data_ptr,"%s %d/%s",service->s_name,service->s_port,
-            service->s_proto);
-    if (service->s_aliases)
-    {
-      int i;
-      for (i=0; service->s_aliases[i]; i++)
-      {
-        strcat(data_ptr," ");
-        strcat(data_ptr,service->s_aliases[i]);
-      }
-    }
-    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)->returnval=NSS_ARGS(args)->buf.result;
-  }
-  return status;
-}
-
-static nss_status_t _xnss_ldap_services_destr(nss_backend_t *be,void 
UNUSED(*args))
+static nss_status_t destructor(nss_backend_t *be,void UNUSED(*args))
 {
   free(be);
   return NSS_STATUS_SUCCESS;
 }
 
 static nss_backend_op_t services_ops[]={
-  _xnss_ldap_services_destr,
-  _xnss_ldap_endservent,
-  _xnss_ldap_setservent,
-  _xnss_ldap_getservent_r,
-  _xnss_ldap_getservbyname_r,
-  _xnss_ldap_getservbyport_r
+  destructor,
+  get_endservent,
+  get_setservent,
+  get_getservent_r,
+  get_getservbyname_r,
+  get_getservbyport_r
 };
 
 nss_backend_t *_nss_ldap_services_constr(const char UNUSED(*db_name),

Modified: nss-pam-ldapd-solaris/nss/shadow.c
==============================================================================
--- nss-pam-ldapd-solaris/nss/shadow.c  Sun Oct 10 22:05:43 2010        (r1257)
+++ nss-pam-ldapd-solaris/nss/shadow.c  Sun Oct 10 22:21:39 2010        (r1258)
@@ -56,10 +56,9 @@
         const char *name,struct spwd *result,
         char *buffer,size_t buflen,int *errnop)
 {
-  NSS_BYNAME(NSLCD_ACTION_SHADOW_BYNAME,buffer,buflen,
+  NSS_BYNAME(NSLCD_ACTION_SHADOW_BYNAME,
              name,
              read_spwd(fp,result,buffer,buflen,errnop));
-  return retv;
 }
 
 /* thread-local file pointer to an ongoing request */
@@ -76,9 +75,8 @@
         struct spwd *result,
         char *buffer,size_t buflen,int *errnop)
 {
-  NSS_GETENT(spentfp,NSLCD_ACTION_SHADOW_ALL,buffer,buflen,
+  NSS_GETENT(spentfp,NSLCD_ACTION_SHADOW_ALL,
              read_spwd(spentfp,result,buffer,buflen,errnop));
-  return retv;
 }
 
 /* close the stream opened by setspent() above */
@@ -91,187 +89,111 @@
 
 #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)
+static nss_status_t read_spwdstring(TFILE *fp,nss_XbyY_args_t *args)
 {
-  NSS_BYNAME(NSLCD_ACTION_SHADOW_BYNAME,buffer,buflen,
-             name,
-             read_spwd(fp,result,buffer,buflen,errnop));
-  return retv;
+  struct spwd result;
+  nss_status_t retv;
+  char *buffer;
+  char field_buf[128];
+  size_t buflen;
+  /* read the spwd */
+  
retv=read_spwd(fp,&result,NSS_ARGS(args)->buf.buffer,args->buf.buflen,&errno);
+  if (retv!=NSS_STATUS_SUCCESS)
+    return retv;
+  /* allocate a temporary buffer */
+  buflen=args->buf.buflen;
+  buffer=(char *)malloc(buflen);
+  /* build the formatted string */
+  /* FIXME: implement proper buffer size checking */
+  sprintf(buffer,"%s:%s:",result.sp_namp,result.sp_pwdp);
+  if (result.sp_lstchg >= 0)
+    sprintf(field_buf,"%d:",result.sp_lstchg);
+  else
+    sprintf(field_buf,":");
+  strcat(buffer,field_buf);
+  if (result.sp_min >= 0)
+    sprintf(field_buf,"%d:",result.sp_min);
+  else
+    sprintf(field_buf,":");
+  strcat(buffer,field_buf);
+  if (result.sp_max >= 0)
+    sprintf(field_buf,"%d:",result.sp_max);
+  else
+    sprintf(field_buf,":");
+  strcat(buffer,field_buf);
+  if (result.sp_warn >= 0)
+    sprintf(field_buf,"%d:",result.sp_warn);
+  else
+    sprintf(field_buf,":");
+  strcat(buffer,field_buf);
+  if (result.sp_inact >= 0)
+    sprintf(field_buf,"%d:",result.sp_inact);
+  else
+    sprintf(field_buf,":");
+  strcat(buffer,field_buf);
+  if (result.sp_expire >= 0)
+    sprintf(field_buf,"%d:",result.sp_expire);
+  else
+    sprintf(field_buf,":");
+  strcat(buffer,field_buf);
+  if (result.sp_flag >= 0)
+    sprintf(field_buf,"%x",result.sp_flag);
+  else
+    sprintf(field_buf,":");
+  strcat(buffer,field_buf);
+  /* copy the result back to the result buffer and free the temporary one */
+  strcpy(NSS_ARGS(args)->buf.buffer,buffer);
+  free(buffer);
+  NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.buffer;
+  NSS_ARGS(args)->returnlen=strlen(NSS_ARGS(args)->buf.buffer);
+  return NSS_STATUS_SUCCESS;
 }
 
-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 *data_ptr;
-  char field_buf[128];
-  nss_status_t status;
-  if (NSS_ARGS(args)->buf.buflen<0)
-  {
-    NSS_ARGS(args)->erange=1;
-    return NSS_STATUS_TRYAGAIN;
-  }
-  
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)
-  {
-    /* result==NULL, return file format */
-    data_ptr=(char *)malloc(buflen);
-    sprintf(data_ptr,"%s:%s:",sp->sp_namp,sp->sp_pwdp);
-    if (sp->sp_lstchg >= 0)
-      sprintf(field_buf,"%d:",sp->sp_lstchg);
-    else
-      sprintf(field_buf,":");
-    strcat(data_ptr,field_buf);
-    if (sp->sp_min >= 0)
-      sprintf(field_buf,"%d:",sp->sp_min);
-    else
-      sprintf(field_buf,":");
-    strcat(data_ptr,field_buf);
-    if (sp->sp_max >= 0)
-      sprintf(field_buf,"%d:",sp->sp_max);
-    else
-      sprintf(field_buf,":");
-    strcat(data_ptr,field_buf);
-    if (sp->sp_warn >= 0)
-      sprintf(field_buf,"%d:",sp->sp_warn);
-    else
-      sprintf(field_buf,":");
-    strcat(data_ptr,field_buf);
-    if (sp->sp_inact >= 0)
-      sprintf(field_buf,"%d:",sp->sp_inact);
-    else
-      sprintf(field_buf,":");
-    strcat(data_ptr,field_buf);
-    if (sp->sp_expire >= 0)
-      sprintf(field_buf,"%d:",sp->sp_expire);
-    else
-      sprintf(field_buf,":");
-    strcat(data_ptr,field_buf);
-    if (sp->sp_flag >= 0)
-      sprintf(field_buf,"%x",sp->sp_flag);
-    else
-      sprintf(field_buf,":");
-    strcat(data_ptr,field_buf);
-    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)->returnval=NSS_ARGS(args)->buf.result;
-  }
-  return status;
+#define READ_RESULT(fp) \
+  NSS_ARGS(args)->buf.result? \
+    read_spwd(fp,(struct spwd 
*)NSS_ARGS(args)->buf.result,NSS_ARGS(args)->buf.buffer,NSS_ARGS(args)->buf.buflen,&errno):
 \
+    read_spwdstring(fp,args); \
+  if (NSS_ARGS(args)->buf.result) \
+    NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.result
+
+static nss_status_t get_getspnam_r(nss_backend_t UNUSED(*be),void *args)
+{
+  NSS_BYNAME(NSLCD_ACTION_SHADOW_BYNAME,
+             NSS_ARGS(args)->key.name,
+             READ_RESULT(fp));
 }
 
 /* thread-local file pointer to an ongoing request */
 static __thread TFILE *spentfp;
 
-static nss_status_t _xnss_ldap_setspent(nss_backend_t UNUSED(*be),void 
UNUSED(*args))
+static nss_status_t get_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)
+static nss_status_t get_getspent_r(nss_backend_t UNUSED(*be),void *args)
 {
-  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;
-  char *buffer=NSS_ARGS(args)->buf.buffer;
-  size_t buflen=NSS_ARGS(args)->buf.buflen;
-  char *data_ptr;
-  char field_buf[128];
-  nss_status_t status;
-  if (NSS_ARGS(args)->buf.buflen<0)
-  {
-    NSS_ARGS(args)->erange=1;
-    return NSS_STATUS_TRYAGAIN;
-  }
-  status=_nss_nslcd_getspent_r(sp,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);
-    sprintf(data_ptr,"%s:%s:",sp->sp_namp,sp->sp_pwdp);
-    if (sp->sp_lstchg >= 0)
-      sprintf(field_buf,"%d:",sp->sp_lstchg);
-    else
-      sprintf(field_buf,":");
-    strcat(data_ptr,field_buf);
-    if (sp->sp_min >= 0)
-      sprintf(field_buf,"%d:",sp->sp_min);
-    else
-      sprintf(field_buf,":");
-    strcat(data_ptr,field_buf);
-    if (sp->sp_max >= 0)
-      sprintf(field_buf,"%d:",sp->sp_max);
-    else
-      sprintf(field_buf,":");
-    strcat(data_ptr,field_buf);
-    if (sp->sp_warn >= 0)
-      sprintf(field_buf,"%d:",sp->sp_warn);
-    else
-      sprintf(field_buf,":");
-    strcat(data_ptr,field_buf);
-    if (sp->sp_inact >= 0)
-      sprintf(field_buf,"%d:",sp->sp_inact);
-    else
-      sprintf(field_buf,":");
-    strcat(data_ptr,field_buf);
-    if (sp->sp_expire >= 0)
-      sprintf(field_buf,"%d:",sp->sp_expire);
-    else
-      sprintf(field_buf,":");
-    strcat(data_ptr,field_buf);
-    if (sp->sp_flag >= 0)
-      sprintf(field_buf,"%x",sp->sp_flag);
-    else
-      sprintf(field_buf,":");
-    strcat(data_ptr,field_buf);
-    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)->returnval=NSS_ARGS(args)->buf.result;
-  }
-  return status;
+  NSS_GETENT(spentfp,NSLCD_ACTION_SHADOW_ALL,
+             READ_RESULT(spentfp));
 }
 
-static nss_status_t _xnss_ldap_endspent(nss_backend_t UNUSED(*be),void 
UNUSED(*args))
+static nss_status_t get_endspent(nss_backend_t UNUSED(*be),void UNUSED(*args))
 {
   NSS_ENDENT(spentfp);
 }
 
-static nss_status_t _xnss_ldap_shadow_destr(nss_backend_t *be,void 
UNUSED(*args))
+static nss_status_t destructor(nss_backend_t *be,void UNUSED(*args))
 {
   free(be);
   return NSS_STATUS_SUCCESS;
 }
 
 static nss_backend_op_t shadow_ops[]={
-  _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 */
+  destructor,
+  get_endspent,         /* NSS_DBOP_ENDENT */
+  get_setspent,         /* NSS_DBOP_SETENT */
+  get_getspent_r,       /* NSS_DBOP_GETENT */
+  get_getspnam_r        /* NSS_DBOP_SHADOW_BYNAME */
 };
 
 nss_backend_t *_nss_ldap_shadow_constr(const char UNUSED(*db_name),
--
To unsubscribe send an email to
nss-pam-ldapd-commits-unsubscribe@lists.arthurdejong.org or see
http://lists.arthurdejong.org/nss-pam-ldapd-commits