lists.arthurdejong.org
RSS feed

nss-pam-ldapd commit: r1808 - nss-pam-ldapd/nss

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

nss-pam-ldapd commit: r1808 - nss-pam-ldapd/nss



Author: arthur
Date: Fri Oct 26 13:48:29 2012
New Revision: 1808
URL: http://arthurdejong.org/viewvc/nss-pam-ldapd?revision=1808&view=revision

Log:
introduce ent2str() functions for each database (except ether and netgroup) and 
make buffer handling consistent

Modified:
   nss-pam-ldapd/nss/ethers.c
   nss-pam-ldapd/nss/group.c
   nss-pam-ldapd/nss/hosts.c
   nss-pam-ldapd/nss/netgroup.c
   nss-pam-ldapd/nss/networks.c
   nss-pam-ldapd/nss/passwd.c
   nss-pam-ldapd/nss/protocols.c
   nss-pam-ldapd/nss/rpc.c
   nss-pam-ldapd/nss/services.c
   nss-pam-ldapd/nss/shadow.c

Modified: nss-pam-ldapd/nss/ethers.c
==============================================================================
--- nss-pam-ldapd/nss/ethers.c  Sun Oct 21 16:36:44 2012        (r1807)
+++ nss-pam-ldapd/nss/ethers.c  Fri Oct 26 13:48:29 2012        (r1808)
@@ -102,29 +102,37 @@
 #define NSS_BUFLEN_ETHERS HOST_NAME_MAX
 #endif /* NSS_BUFLEN_ETHERS */
 
-static nss_status_t read_result(TFILE *fp,void *args,int wantname)
+#ifdef HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN
+static char *etherent2str(struct etherent *result,char *buffer,size_t buflen)
+{
+  int res;
+  res=snprintf(buffer,buflen,"%s 
%s",ether_ntoa(&result->e_addr),result->e_name);
+  if ((res<0)||(res>=buflen))
+    return NULL;
+  return buffer;
+}
+#endif /* HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN */
+
+static nss_status_t read_result(TFILE *fp,nss_XbyY_args_t *args,int wantname)
 {
   struct etherent result;
   char buffer[NSS_BUFLEN_ETHERS];
   nss_status_t retv;
-  int res;
   /* read the result entry from the stream */
-  retv=read_etherent(fp,&result,buffer,sizeof(buffer),&NSS_ARGS(args)->erange);
+  retv=read_etherent(fp,&result,buffer,sizeof(buffer),&args->erange);
   if (retv!=NSS_STATUS_SUCCESS)
     return retv;
 #ifdef HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN
   /* try to return in string format if requested */
-  if ((NSS_ARGS(args)->buf.buffer!=NULL)&&(NSS_ARGS(args)->buf.buflen>0))
+  if ((args->buf.buffer!=NULL)&&(args->buf.buflen>0))
   {
-    res=snprintf(NSS_ARGS(args)->buf.buffer,NSS_ARGS(args)->buf.buflen,
-                 "%s %s",ether_ntoa(&result.e_addr),result.e_name);
-    if ((res<0)||(res>=NSS_ARGS(args)->buf.buflen))
+    if (etherent2str(&result,args->buf.buffer,args->buf.buflen)==NULL)
     {
-      NSS_ARGS(args)->erange=1;
+      args->erange=1;
       return NSS_NOTFOUND;
     }
-    NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.buffer;
-    NSS_ARGS(args)->returnlen=strlen(NSS_ARGS(args)->returnval);
+    args->returnval=args->buf.buffer;
+    args->returnlen=strlen(args->returnval);
     return NSS_SUCCESS;
   }
 #endif /* HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN */
@@ -132,13 +140,13 @@
   if (wantname)
   {
     /* we expect the buffer to have enough room for the name (buflen==0) */
-    strcpy(NSS_ARGS(args)->buf.buffer,result.e_name);
-    NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.buffer;
+    strcpy(args->buf.buffer,result.e_name);
+    args->returnval=args->buf.buffer;
   }
   else /* address */
   {
-    memcpy(NSS_ARGS(args)->buf.result,&result.e_addr,sizeof(result.e_addr));
-    NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.result;
+    memcpy(args->buf.result,&result.e_addr,sizeof(result.e_addr));
+    args->returnval=args->buf.result;
   }
   return NSS_SUCCESS;
 }

Modified: nss-pam-ldapd/nss/group.c
==============================================================================
--- nss-pam-ldapd/nss/group.c   Sun Oct 21 16:36:44 2012        (r1807)
+++ nss-pam-ldapd/nss/group.c   Fri Oct 26 13:48:29 2012        (r1808)
@@ -185,71 +185,76 @@
 #ifdef NSS_FLAVOUR_SOLARIS
 
 #ifdef HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN
+static char *group2str(struct group *result,char *buffer,size_t buflen)
+{
+  int res,i;
+  
res=snprintf(buffer,buflen,"%s:%s:%d:",result->gr_name,result->gr_passwd,(int)result->gr_gid);
+  if ((res<0)||(res>=buflen))
+    return NULL;
+  if (result->gr_mem)
+    for (i=0;result->gr_mem[i];i++)
+    {
+      if (i)
+        strlcat(buffer,",",buflen);
+      strlcat(buffer,result->gr_mem[i],buflen);
+    }
+  /* check if buffer overflowed */
+  if (strlen(buffer)>=buflen-1)
+    return NULL;
+  return buffer;
+}
+#endif /* HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN */
 
-static nss_status_t read_groupstring(TFILE *fp,nss_XbyY_args_t *args)
+static nss_status_t read_result(TFILE *fp,nss_XbyY_args_t *args)
 {
-  struct group result;
   nss_status_t retv;
+#ifdef HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN
+  struct group result;
   char *buffer;
-  int i;
-  /* read the group into a temporary buffer */
-  buffer=(char *)malloc(args->buf.buflen);
-  if (buffer==NULL)
-    return NSS_STATUS_UNAVAIL;
-  retv=read_group(fp,&result,buffer,args->buf.buflen,&NSS_ARGS(args)->erange);
-  if (retv!=NSS_STATUS_SUCCESS)
+  /* try to return in string format if requested */
+  if (args->buf.result==NULL)
   {
+    /* read the entry into a temporary buffer */
+    buffer=(char *)malloc(args->buf.buflen);
+    if (buffer==NULL)
+      return NSS_STATUS_UNAVAIL;
+    retv=read_group(fp,&result,buffer,args->buf.buflen,&args->erange);
+    /* format to string */
+    if (retv==NSS_STATUS_SUCCESS)
+      if (group2str(&result,args->buf.buffer,args->buf.buflen)==NULL)
+      {
+        args->erange=1;
+        retv=NSS_NOTFOUND;
+      }
+    /* clean up and return result */
     free(buffer);
-    return retv;
+    if (retv!=NSS_STATUS_SUCCESS)
+      return retv;
+    args->returnval=args->buf.buffer;
+    args->returnlen=strlen(args->returnval);
+    return NSS_STATUS_SUCCESS;
   }
-  /* make a string representation */
-  snprintf(args->buf.buffer,args->buf.buflen,
-           "%s:%s:%d:",result.gr_name,result.gr_passwd,(int)result.gr_gid);
-  args->buf.buffer[args->buf.buflen-1]='\0';
-  if (result.gr_mem)
-    for (i=0;result.gr_mem[i];i++)
-    {
-      if (i)
-        
strncat(args->buf.buffer,",",args->buf.buflen-strlen(args->buf.buffer)-1);
-      
strncat(args->buf.buffer,result.gr_mem[i],args->buf.buflen-strlen(args->buf.buffer)-1);
-    }
-  free(buffer);
-  /* check if buffer overflowed */
-  if (strlen(args->buf.buffer)>=args->buf.buflen-1)
-    return NSS_STATUS_TRYAGAIN;
-  NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.buffer;
-  NSS_ARGS(args)->returnlen=strlen(NSS_ARGS(args)->buf.buffer);
+#endif /* HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN */
+  /* read the entry */
+  
retv=read_group(fp,args->buf.result,args->buf.buffer,args->buf.buflen,&args->erange);
+  if (retv!=NSS_STATUS_SUCCESS)
+    return retv;
+  args->returnval=args->buf.result;
   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,&NSS_ARGS(args)->erange):
 \
-    read_groupstring(fp,args); \
-  if ((NSS_ARGS(args)->buf.result)&&(retv==NSS_STATUS_SUCCESS)) \
-    NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.result;
-
-#else /* not HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN */
-
-#define READ_RESULT(fp) \
-  read_group(fp,(struct group 
*)NSS_ARGS(args)->buf.result,NSS_ARGS(args)->buf.buffer,NSS_ARGS(args)->buf.buflen,&NSS_ARGS(args)->erange);
 \
-  if (retv==NSS_STATUS_SUCCESS) \
-    NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.result;
-
-#endif /* not HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN */
-
 static nss_status_t group_getgrnam(nss_backend_t UNUSED(*be),void *args)
 {
   NSS_BYNAME(NSLCD_ACTION_GROUP_BYNAME,
              NSS_ARGS(args)->key.name,
-             READ_RESULT(fp));
+             read_result(fp,args));
 }
 
 static nss_status_t group_getgrgid(nss_backend_t UNUSED(*be),void *args)
 {
   NSS_BYTYPE(NSLCD_ACTION_GROUP_BYGID,
              NSS_ARGS(args)->key.gid,gid_t,
-             READ_RESULT(fp));
+             read_result(fp,args));
 }
 
 static nss_status_t group_setgrent(nss_backend_t *be,void UNUSED(*args))
@@ -260,7 +265,7 @@
 static nss_status_t group_getgrent(nss_backend_t *be,void *args)
 {
   NSS_GETENT(LDAP_BE(be)->fp,NSLCD_ACTION_GROUP_ALL,
-             READ_RESULT((LDAP_BE(be)->fp)));
+             read_result(LDAP_BE(be)->fp,args));
 }
 
 static nss_status_t group_endgrent(nss_backend_t *be,void UNUSED(*args))
@@ -268,11 +273,6 @@
   NSS_ENDENT(LDAP_BE(be)->fp);
 }
 
-/*
-static nss_status_t get_initgroups_dyn(
-        const char *user,gid_t skipgroup,long int *start,
-        gid_t **groupsp,long int limit,int *errnop)
-*/
 static nss_status_t group_getgroupsbymember(nss_backend_t UNUSED(*be),void 
*args)
 {
   struct nss_groupsbymem *argp=(struct nss_groupsbymem *)args;

Modified: nss-pam-ldapd/nss/hosts.c
==============================================================================
--- nss-pam-ldapd/nss/hosts.c   Sun Oct 21 16:36:44 2012        (r1807)
+++ nss-pam-ldapd/nss/hosts.c   Fri Oct 26 13:48:29 2012        (r1808)
@@ -244,60 +244,73 @@
 #ifdef NSS_FLAVOUR_SOLARIS
 
 #ifdef HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN
-static nss_status_t read_hoststring(TFILE *fp,int af,nss_XbyY_args_t *args,int 
erronempty)
+static char *hostent2str(struct hostent *result,char *buffer,size_t buflen)
 {
-  struct hostent result;
-  char buffer[NSS_BUFLEN_HOSTS];
-  int retv;
   int i,j;
-  /* read the result entry */
-  if (erronempty)
-    
retv=read_hostent_erronempty(fp,af,&result,buffer,sizeof(buffer),&args->erange,&args->h_errno);
-  else
-    
retv=read_hostent_nextonempty(fp,af,&result,buffer,sizeof(buffer),&args->erange,&args->h_errno);
-  if (retv!=NSS_STATUS_SUCCESS)
-    return retv;
   /* build the formatted string, one line per address */
-  args->buf.buffer[0]='\0';
-  if (result.h_addr_list!=NULL)
+  buffer[0]='\0';
+  if (result->h_addr_list!=NULL)
   {
-    for (i=0;result.h_addr_list[i];i++)
+    for (i=0;result->h_addr_list[i];i++)
     {
       if (i>0)
-        strlcat(args->buf.buffer,"\n",args->buf.buflen);
-      snprintf(args->buf.buffer,args->buf.buflen-strlen(args->buf.buffer)-1,
-               "%s %s",inet_ntoa(*((struct in_addr 
*)result.h_addr_list[i])),result.h_name);
+        strlcat(buffer,"\n",buflen);
+      /* snprintf writes a terminating \0 on Solaris */
+      snprintf(buffer,buflen-strlen(buffer)-1,
+               "%s %s",inet_ntoa(*((struct in_addr 
*)result->h_addr_list[i])),result->h_name);
       /* add aliases for first line only */
-      if ((i==0)&&(result.h_aliases))
+      if ((i==0)&&(result->h_aliases))
       {
-        for (j=0;result.h_aliases[j];j++)
+        for (j=0;result->h_aliases[j];j++)
         {
-          strlcat(args->buf.buffer," ",args->buf.buflen);
-          strlcat(args->buf.buffer,result.h_aliases[j],args->buf.buflen);
+          strlcat(buffer," ",buflen);
+          strlcat(buffer,result->h_aliases[j],buflen);
         }
       }
     }
   }
-  if (strlen(args->buf.buffer)>=args->buf.buflen-1)
-  {
-    NSS_ARGS(args)->erange=1;
-    return NSS_NOTFOUND;
-  }
-  args->returnval=args->buf.buffer;
-  args->returnlen=strlen(args->returnval);
-  return NSS_STATUS_SUCCESS;
+  if (strlen(buffer)>=buflen-1)
+    return NULL;
+  return buffer;
 }
-#endif /* not HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN */
+#endif /* HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN */
 
 static nss_status_t read_result(TFILE *fp,int af,nss_XbyY_args_t *args,int 
erronempty)
 {
   nss_status_t retv;
 #ifdef HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN
+  struct hostent result;
+  char *buffer;
   /* try to return in string format if requested */
   if (args->buf.result==NULL)
-    return read_hoststring(fp,af,args,erronempty);
-#endif /* not HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN */
-  /* read the hostent */
+  {
+    /* read the entry into a temporary buffer*/
+    buffer=(char *)malloc(args->buf.buflen);
+    if (buffer==NULL)
+      return NSS_STATUS_UNAVAIL;
+    if (erronempty)
+      
retv=read_hostent_erronempty(fp,af,&result,buffer,args->buf.buflen,&args->erange,&args->h_errno);
+    else
+      
retv=read_hostent_nextonempty(fp,af,&result,buffer,args->buf.buflen,&args->erange,&args->h_errno);
+    if (retv!=NSS_STATUS_SUCCESS)
+      return retv;
+    /* format to string */
+    if (retv==NSS_STATUS_SUCCESS)
+      if (hostent2str(&result,args->buf.buffer,args->buf.buflen)==NULL)
+      {
+        args->erange=1;
+        retv=NSS_NOTFOUND;
+      }
+    /* clean up and return result */
+    free(buffer);
+    if (retv!=NSS_STATUS_SUCCESS)
+      return retv;
+    args->returnval=args->buf.buffer;
+    args->returnlen=strlen(args->returnval);
+    return NSS_STATUS_SUCCESS;
+  }
+#endif /* HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN */
+  /* read the entry */
   if (erronempty)
     retv=read_hostent_erronempty(fp,af,
           args->buf.result,args->buf.buffer,args->buf.buflen,

Modified: nss-pam-ldapd/nss/netgroup.c
==============================================================================
--- nss-pam-ldapd/nss/netgroup.c        Sun Oct 21 16:36:44 2012        (r1807)
+++ nss-pam-ldapd/nss/netgroup.c        Fri Oct 26 13:48:29 2012        (r1808)
@@ -217,7 +217,7 @@
           {
             /* no more netgroup */
             found=1; done=1;
-            errno=ENOENT;
+            errno=ENOENT;  /* TODO: probably don't do this */
           }
           else
           {

Modified: nss-pam-ldapd/nss/networks.c
==============================================================================
--- nss-pam-ldapd/nss/networks.c        Sun Oct 21 16:36:44 2012        (r1807)
+++ nss-pam-ldapd/nss/networks.c        Fri Oct 26 13:48:29 2012        (r1808)
@@ -163,56 +163,64 @@
 #ifdef NSS_FLAVOUR_SOLARIS
 
 #ifdef HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN
+static char *netent2str(struct netent *result,char *buffer,size_t buflen)
+{
+  int i,res;
+  struct in_addr priv_in_addr;
+  priv_in_addr.s_addr=result->n_net;
+  res=snprintf(buffer,buflen,"%s %s",result->n_name,inet_ntoa(priv_in_addr));
+  if ((res<0)||(res>=buflen))
+    return NULL;
+  if (result->n_aliases)
+    for (i=0;result->n_aliases[i];i++)
+    {
+      strlcat(buffer," ",buflen);
+      strlcat(buffer,result->n_aliases[i],buflen);
+    }
+  if (strlen(buffer)>=buflen-1)
+    return NULL;
+  return buffer;
+}
+#endif /* HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN */
 
-static nss_status_t read_netentstring(TFILE *fp,nss_XbyY_args_t *args)
+static nss_status_t read_result(TFILE *fp,nss_XbyY_args_t *args)
 {
-  struct netent result;
   nss_status_t retv;
+#ifdef HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN
+  struct netent result;
   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,&NSS_ARGS(args)->erange,&(NSS_ARGS(args)->h_errno));
+  /* try to return in string format if requested */
+  if (args->buf.result==NULL)
+  {
+    /* read the entry into a temporary buffer */
+    buffer=(char *)malloc(args->buf.buflen);
+    if (buffer==NULL)
+      return NSS_STATUS_UNAVAIL;
+    
retv=read_netent(fp,&result,buffer,args->buf.buflen,&args->erange,&args->h_errno);
+    /* format to string */
+    if (retv==NSS_STATUS_SUCCESS)
+      if (netent2str(&result,args->buf.buffer,args->buf.buflen)==NULL)
+      {
+        args->erange=1;
+        retv=NSS_NOTFOUND;
+      }
+    /* clean up and return result */
+    free(buffer);
+    if (retv!=NSS_STATUS_SUCCESS)
+      return retv;
+    args->returnval=args->buf.buffer;
+    args->returnlen=strlen(args->returnval);
+    return NSS_STATUS_SUCCESS;
+  }
+#endif /* HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN */
+  /* read the entry */
+  
retv=read_netent(fp,args->buf.result,args->buf.buffer,args->buf.buflen,&args->erange,&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++)
-    {
-      strcat(buffer," ");
-      strcat(buffer,result.n_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);
+  args->returnval=args->buf.result;
   return NSS_STATUS_SUCCESS;
 }
 
-#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,&NSS_ARGS(args)->erange,&(NSS_ARGS(args)->h_errno)):
 \
-    read_netentstring(fp,args); \
-  if ((NSS_ARGS(args)->buf.result)&&(retv==NSS_STATUS_SUCCESS)) \
-    NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.result;
-
-#else /* not HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN */
-
-#define READ_RESULT(fp) \
-  read_netent(fp,(struct netent 
*)NSS_ARGS(args)->buf.result,NSS_ARGS(args)->buf.buffer,NSS_ARGS(args)->buf.buflen,&NSS_ARGS(args)->erange,&(NSS_ARGS(args)->h_errno));
 \
-  if (retv==NSS_STATUS_SUCCESS) \
-    NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.result;
-
-#endif /* not HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN */
-
 /* more of a dirty hack */
 #define h_errnop (&(NSS_ARGS(args)->h_errno))
 
@@ -220,14 +228,14 @@
 {
   NSS_BYNAME(NSLCD_ACTION_NETWORK_BYNAME,
              NSS_ARGS(args)->key.name,
-             READ_RESULT(fp));
+             read_result(fp,args));
 }
 
 static nss_status_t networks_getnetbyaddr(nss_backend_t UNUSED(*be),void *args)
 {
   NSS_BYGEN(NSLCD_ACTION_NETWORK_BYADDR,
             WRITE_ADDRESS(fp,NSS_ARGS(args)->key.netaddr.net),
-            READ_RESULT(fp));
+            read_result(fp,args));
 }
 
 static nss_status_t networks_setnetent(nss_backend_t *be,void UNUSED(*args))
@@ -238,7 +246,7 @@
 static nss_status_t networks_getnetent(nss_backend_t *be,void *args)
 {
   NSS_GETENT(LDAP_BE(be)->fp,NSLCD_ACTION_NETWORK_ALL,
-             READ_RESULT(LDAP_BE(be)->fp));
+             read_result(LDAP_BE(be)->fp,args));
 }
 
 static nss_status_t networks_endnetent(nss_backend_t *be,void UNUSED(*args))

Modified: nss-pam-ldapd/nss/passwd.c
==============================================================================
--- nss-pam-ldapd/nss/passwd.c  Sun Oct 21 16:36:44 2012        (r1807)
+++ nss-pam-ldapd/nss/passwd.c  Fri Oct 26 13:48:29 2012        (r1808)
@@ -99,42 +99,50 @@
 #ifdef NSS_FLAVOUR_SOLARIS
 
 #ifdef HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN
-static nss_status_t read_passwdstring(TFILE *fp,nss_XbyY_args_t *args)
+static char *passwd2str(struct passwd *result,char *buffer,size_t buflen)
 {
-  struct passwd result;
-  char buffer[NSS_BUFLEN_PASSWD];
-  nss_status_t retv;
   int res;
-  /* read the passwd */
-  retv=read_passwd(fp,&result,buffer,sizeof(buffer),&NSS_ARGS(args)->erange);
-  if (retv!=NSS_STATUS_SUCCESS)
-    return retv;
-  /* build the formatted string */
-  res=snprintf(args->buf.buffer,args->buf.buflen,"%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);
-  if ((res<0)||(res>=NSS_ARGS(args)->buf.buflen))
-  {
-    NSS_ARGS(args)->erange=1;
-    return NSS_NOTFOUND;
-  }
-  /* return the string as a result */
-  args->returnval=args->buf.buffer;
-  args->returnlen=strlen(args->returnval);
-  return NSS_STATUS_SUCCESS;
+  res=snprintf(buffer,buflen,"%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);
+  if ((res<0)||(res>=buflen))
+    return NULL;
+  return buffer;
 }
-#endif /* not HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN */
+#endif /* HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN */
 
 static nss_status_t read_result(TFILE *fp,nss_XbyY_args_t *args)
 {
   nss_status_t retv;
 #ifdef HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN
+  struct passwd result;
+  char *buffer;
   /* try to return in string format if requested */
   if (args->buf.result==NULL)
-    return read_passwdstring(fp,args);
-#endif /* not HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN */
+  {
+    /* read the entry into a temporary buffer */
+    buffer=(char *)malloc(args->buf.buflen);
+    if (buffer==NULL)
+      return NSS_STATUS_UNAVAIL;
+    retv=read_passwd(fp,&result,buffer,args->buf.buflen,&args->erange);
+    /* format to string */
+    if (retv==NSS_STATUS_SUCCESS)
+      if (passwd2str(&result,args->buf.buffer,args->buf.buflen)==NULL)
+      {
+        args->erange=1;
+        retv=NSS_NOTFOUND;
+      }
+    /* clean up and return result */
+    free(buffer);
+    if (retv!=NSS_STATUS_SUCCESS)
+      return retv;
+    args->returnval=args->buf.buffer;
+    args->returnlen=strlen(args->returnval);
+    return NSS_STATUS_SUCCESS;
+  }
+#endif /* HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN */
   /* read the entry */
-  
retv=read_passwd(fp,args->buf.result,args->buf.buffer,args->buf.buflen,&NSS_ARGS(args)->erange);
+  
retv=read_passwd(fp,args->buf.result,args->buf.buffer,args->buf.buflen,&args->erange);
   if (retv!=NSS_STATUS_SUCCESS)
     return retv;
   args->returnval=args->buf.result;

Modified: nss-pam-ldapd/nss/protocols.c
==============================================================================
--- nss-pam-ldapd/nss/protocols.c       Sun Oct 21 16:36:44 2012        (r1807)
+++ nss-pam-ldapd/nss/protocols.c       Fri Oct 26 13:48:29 2012        (r1808)
@@ -95,66 +95,74 @@
 #ifdef NSS_FLAVOUR_SOLARIS
 
 #ifdef HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN
+static char *protoent2str(struct protoent *result,char *buffer,size_t buflen)
+{
+  int res,i;
+  res=snprintf(buffer,buflen,"%s\t\t%d",result->p_name,result->p_proto);
+  if ((res<0)||(res>=buflen))
+    return NULL;
+  if (result->p_aliases)
+    for (i=0;result->p_aliases[i];i++)
+    {
+      strlcat(buffer," ",buflen);
+      strlcat(buffer,result->p_aliases[i],buflen);
+    }
+  if (strlen(buffer)>=buflen-1)
+    return NULL;
+  return buffer;
+}
+#endif /* HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN */
 
-static nss_status_t read_protostring(TFILE *fp,nss_XbyY_args_t *args)
+static nss_status_t read_result(TFILE *fp,nss_XbyY_args_t *args)
 {
-  struct protoent result;
   nss_status_t retv;
+#ifdef HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN
+  struct protoent result;
   char *buffer;
-  size_t buflen;
-  int i;
-  /* read the protoent */
-  
retv=read_protoent(fp,&result,NSS_ARGS(args)->buf.buffer,args->buf.buflen,&NSS_ARGS(args)->erange);
+  /* try to return in string format if requested */
+  if (args->buf.result==NULL)
+  {
+    /* read the entry into a temporary buffer */
+    buffer=(char *)malloc(args->buf.buflen);
+    if (buffer==NULL)
+      return NSS_STATUS_UNAVAIL;
+    retv=read_protoent(fp,&result,buffer,args->buf.buflen,&args->erange);
+    /* format to string */
+    if (retv==NSS_STATUS_SUCCESS)
+      if (protoent2str(&result,args->buf.buffer,args->buf.buflen)==NULL)
+      {
+        args->erange=1;
+        retv=NSS_NOTFOUND;
+      }
+    /* clean up and return result */
+    free(buffer);
+    if (retv!=NSS_STATUS_SUCCESS)
+      return retv;
+    args->returnval=args->buf.buffer;
+    args->returnlen=strlen(args->returnval);
+    return NSS_STATUS_SUCCESS;
+  }
+#endif /* HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN */
+  /* read the entry */
+  
retv=read_protoent(fp,args->buf.result,args->buf.buffer,args->buf.buflen,&args->erange);
   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++)
-    {
-      strcat(buffer," ");
-      strcat(buffer,result.p_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);
+  args->returnval=args->buf.result;
   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,&NSS_ARGS(args)->erange):
 \
-    read_protostring(fp,args); \
-  if ((NSS_ARGS(args)->buf.result)&&(retv==NSS_STATUS_SUCCESS)) \
-    NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.result;
-
-#else /* not HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN */
-
-#define READ_RESULT(fp) \
-  read_protoent(fp,(struct protoent 
*)NSS_ARGS(args)->buf.result,NSS_ARGS(args)->buf.buffer,NSS_ARGS(args)->buf.buflen,&NSS_ARGS(args)->erange);
 \
-  if (retv==NSS_STATUS_SUCCESS) \
-    NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.result;
-
-#endif /* not HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN */
-
 static nss_status_t protocols_getprotobyname(nss_backend_t UNUSED(*be),void 
*args)
 {
   NSS_BYNAME(NSLCD_ACTION_PROTOCOL_BYNAME,
              NSS_ARGS(args)->key.name,
-             READ_RESULT(fp));
+             read_result(fp,args));
 }
 
 static nss_status_t protocols_getprotobynumber(nss_backend_t UNUSED(*be),void 
*args)
 {
   NSS_BYINT32(NSLCD_ACTION_PROTOCOL_BYNUMBER,
               NSS_ARGS(args)->key.number,
-              READ_RESULT(fp));
+              read_result(fp,args));
 }
 
 static nss_status_t protocols_setprotoent(nss_backend_t *be,void UNUSED(*args))
@@ -165,7 +173,7 @@
 static nss_status_t protocols_getprotoent(nss_backend_t *be,void *args)
 {
   NSS_GETENT(LDAP_BE(be)->fp,NSLCD_ACTION_PROTOCOL_ALL,
-             READ_RESULT(LDAP_BE(be)->fp));
+             read_result(LDAP_BE(be)->fp,args));
 }
 
 static nss_status_t protocols_endprotoent(nss_backend_t *be,void UNUSED(*args))

Modified: nss-pam-ldapd/nss/rpc.c
==============================================================================
--- nss-pam-ldapd/nss/rpc.c     Sun Oct 21 16:36:44 2012        (r1807)
+++ nss-pam-ldapd/nss/rpc.c     Fri Oct 26 13:48:29 2012        (r1808)
@@ -95,66 +95,74 @@
 #ifdef NSS_FLAVOUR_SOLARIS
 
 #ifdef HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN
+static char *rpcent2str(struct rpcent *result,char *buffer,size_t buflen)
+{
+  int res,i;
+  res=snprintf(buffer,buflen,"%s %d",result->r_name,result->r_number);
+  if ((res<0)||(res>=buflen))
+    return NULL;
+  if (result->r_aliases)
+    for (i=0;result->r_aliases[i];i++)
+    {
+      strlcat(buffer," ",buflen);
+      strlcat(buffer,result->r_aliases[i],buflen);
+    }
+  if (strlen(buffer)>=buflen-1)
+    return NULL;
+  return buffer;
+}
+#endif /* HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN */
 
-static nss_status_t read_rpcstring(TFILE *fp,nss_XbyY_args_t *args)
+static nss_status_t read_result(TFILE *fp,nss_XbyY_args_t *args)
 {
-  struct rpcent result;
   nss_status_t retv;
+#ifdef HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN
+  struct rpcent result;
   char *buffer;
-  size_t buflen;
-  int i;
-  /* read the rpcent */
-  
retv=read_rpcent(fp,&result,NSS_ARGS(args)->buf.buffer,args->buf.buflen,&NSS_ARGS(args)->erange);
+  /* try to return in string format if requested */
+  if (args->buf.result==NULL)
+  {
+    /* read the entry into a temporary buffer */
+    buffer=(char *)malloc(args->buf.buflen);
+    if (buffer==NULL)
+      return NSS_STATUS_UNAVAIL;
+    retv=read_rpcent(fp,&result,buffer,args->buf.buflen,&args->erange);
+    /* format to string */
+    if (retv==NSS_STATUS_SUCCESS)
+      if (rpcent2str(&result,args->buf.buffer,args->buf.buflen)==NULL)
+      {
+        args->erange=1;
+        retv=NSS_NOTFOUND;
+      }
+    /* clean up and return result */
+    free(buffer);
+    if (retv!=NSS_STATUS_SUCCESS)
+      return retv;
+    args->returnval=args->buf.buffer;
+    args->returnlen=strlen(args->returnval);
+    return NSS_STATUS_SUCCESS;
+  }
+#endif /* HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN */
+  /* read the entry */
+  
retv=read_rpcent(fp,args->buf.result,args->buf.buffer,args->buf.buflen,&args->erange);
   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);
+  args->returnval=args->buf.result;
   return NSS_STATUS_SUCCESS;
 }
 
-#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,&NSS_ARGS(args)->erange):
 \
-    read_rpcstring(fp,args); \
-  if ((NSS_ARGS(args)->buf.result)&&(retv==NSS_STATUS_SUCCESS)) \
-    NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.result;
-
-#else /* not HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN */
-
-#define READ_RESULT(fp) \
-  read_rpcent(fp,(struct rpcent 
*)NSS_ARGS(args)->buf.result,NSS_ARGS(args)->buf.buffer,NSS_ARGS(args)->buf.buflen,&NSS_ARGS(args)->erange);
 \
-  if (retv==NSS_STATUS_SUCCESS) \
-    NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.result;
-
-#endif /* not HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN */
-
 static nss_status_t rpc_getrpcbyname(nss_backend_t UNUSED(*be),void *args)
 {
   NSS_BYNAME(NSLCD_ACTION_RPC_BYNAME,
              NSS_ARGS(args)->key.name,
-             READ_RESULT(fp));
+             read_result(fp,args));
 }
 
 static nss_status_t rpc_getrpcbynumber(nss_backend_t UNUSED(*be),void *args)
 {
   NSS_BYINT32(NSLCD_ACTION_RPC_BYNUMBER,
               NSS_ARGS(args)->key.number,
-              READ_RESULT(fp));
+              read_result(fp,args));
 }
 
 static nss_status_t rpc_setrpcent(nss_backend_t *be,void UNUSED(*args))
@@ -165,7 +173,7 @@
 static nss_status_t rpc_getrpcent(nss_backend_t *be,void *args)
 {
   NSS_GETENT(LDAP_BE(be)->fp,NSLCD_ACTION_RPC_ALL,
-             READ_RESULT(LDAP_BE(be)->fp));
+             read_result(LDAP_BE(be)->fp,args));
 }
 
 static nss_status_t rpc_endrpcent(nss_backend_t *be,void UNUSED(*args))

Modified: nss-pam-ldapd/nss/services.c
==============================================================================
--- nss-pam-ldapd/nss/services.c        Sun Oct 21 16:36:44 2012        (r1807)
+++ nss-pam-ldapd/nss/services.c        Fri Oct 26 13:48:29 2012        (r1808)
@@ -99,60 +99,68 @@
 #ifdef NSS_FLAVOUR_SOLARIS
 
 #ifdef HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN
+static char *servent2str(struct servent *result,char *buffer,size_t buflen)
+{
+  int res,i;
+  res=snprintf(buffer,buflen,"%s 
%d/%s",result->s_name,result->s_port,result->s_proto);
+  if ((res<0)||(res>=buflen))
+    return NULL;
+  if (result->s_aliases)
+    for (i=0;result->s_aliases[i];i++)
+    {
+      strlcat(buffer," ",buflen);
+      strlcat(buffer,result->s_aliases[i],buflen);
+    }
+  if (strlen(buffer)>=buflen-1)
+    return NULL;
+  return buffer;
+}
+#endif /* HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN */
 
-static nss_status_t read_servstring(TFILE *fp,nss_XbyY_args_t *args)
+static nss_status_t read_result(TFILE *fp,nss_XbyY_args_t *args)
 {
-  struct servent result;
   nss_status_t retv;
+#ifdef HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN
+  struct servent result;
   char *buffer;
-  size_t buflen;
-  int i;
-  /* read the servent */
-  
retv=read_servent(fp,&result,NSS_ARGS(args)->buf.buffer,args->buf.buflen,&NSS_ARGS(args)->erange);
+  /* try to return in string format if requested */
+  if (args->buf.result==NULL)
+  {
+    /* read the entry into a temporary buffer */
+    buffer=(char *)malloc(args->buf.buflen);
+    if (buffer==NULL)
+      return NSS_STATUS_UNAVAIL;
+    retv=read_servent(fp,&result,buffer,args->buf.buflen,&args->erange);
+    /* format to string */
+    if (retv==NSS_STATUS_SUCCESS)
+      if (servent2str(&result,args->buf.buffer,args->buf.buflen)==NULL)
+      {
+        args->erange=1;
+        retv=NSS_NOTFOUND;
+      }
+    /* clean up and return result */
+    free(buffer);
+    if (retv!=NSS_STATUS_SUCCESS)
+      return retv;
+    args->returnval=args->buf.buffer;
+    args->returnlen=strlen(args->returnval);
+    return NSS_STATUS_SUCCESS;
+  }
+#endif /* HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN */
+  /* read the entry */
+  
retv=read_servent(fp,args->buf.result,args->buf.buffer,args->buf.buflen,&args->erange);
   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);
+  args->returnval=args->buf.result;
   return NSS_STATUS_SUCCESS;
 }
 
-#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,&NSS_ARGS(args)->erange):
 \
-    read_servstring(fp,args); \
-  if ((NSS_ARGS(args)->buf.result)&&(retv==NSS_STATUS_SUCCESS)) \
-    NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.result;
-
-#else /* not HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN */
-
-#define READ_RESULT(fp) \
-  read_servent(fp,(struct servent 
*)NSS_ARGS(args)->buf.result,NSS_ARGS(args)->buf.buffer,NSS_ARGS(args)->buf.buflen,&NSS_ARGS(args)->erange);
 \
-  if (retv==NSS_STATUS_SUCCESS) \
-    NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.result;
-
-#endif /* not HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN */
-
 static nss_status_t services_getservbyname(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));
+            read_result(fp,args));
 }
 
 static nss_status_t services_getservbyport(nss_backend_t UNUSED(*be),void 
*args)
@@ -160,7 +168,7 @@
   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));
+            read_result(fp,args));
 }
 
 static nss_status_t services_setservent(nss_backend_t *be,void UNUSED(*args))
@@ -171,7 +179,7 @@
 static nss_status_t services_getservent(nss_backend_t *be,void *args)
 {
   NSS_GETENT(LDAP_BE(be)->fp,NSLCD_ACTION_SERVICE_ALL,
-             READ_RESULT(LDAP_BE(be)->fp));
+             read_result(LDAP_BE(be)->fp,args));
 }
 
 static nss_status_t services_endservent(nss_backend_t *be,void UNUSED(*args))

Modified: nss-pam-ldapd/nss/shadow.c
==============================================================================
--- nss-pam-ldapd/nss/shadow.c  Sun Oct 21 16:36:44 2012        (r1807)
+++ nss-pam-ldapd/nss/shadow.c  Fri Oct 26 13:48:29 2012        (r1808)
@@ -91,88 +91,79 @@
 #ifdef NSS_FLAVOUR_SOLARIS
 
 #ifdef HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN
+static char *spwd2str(struct spwd *result,char *buffer,size_t buflen)
+{
+  /* snprintf writes a terminating \0 on Solaris */
+  snprintf(buffer,buflen,"%s:%s:",result->sp_namp,result->sp_pwdp);
+  if (result->sp_lstchg>=0)
+    snprintf(buffer,buflen-strlen(buffer)-1,"%d:",result->sp_lstchg);
+  strlcat(buffer,":",buflen);
+  if (result->sp_min>=0)
+    snprintf(buffer,buflen-strlen(buffer)-1,"%d:",result->sp_min);
+  strlcat(buffer,":",buflen);
+  if (result->sp_max>=0)
+    snprintf(buffer,buflen-strlen(buffer)-1,"%d:",result->sp_max);
+  strlcat(buffer,":",buflen);
+  if (result->sp_warn>=0)
+    snprintf(buffer,buflen-strlen(buffer)-1,"%d:",result->sp_warn);
+  strlcat(buffer,":",buflen);
+  if (result->sp_inact>=0)
+    snprintf(buffer,buflen-strlen(buffer)-1,"%d:",result->sp_inact);
+  strlcat(buffer,":",buflen);
+  if (result->sp_expire>=0)
+    snprintf(buffer,buflen-strlen(buffer)-1,"%d:",result->sp_expire);
+  strlcat(buffer,":",buflen);
+  if (result->sp_flag>=0)
+    snprintf(buffer,buflen-strlen(buffer)-1,"%x",result->sp_flag);
+  if (strlen(buffer)>=buflen-1)
+    return NULL;
+  return buffer;
+}
+#endif /* HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN */
 
-static nss_status_t read_spwdstring(TFILE *fp,nss_XbyY_args_t *args)
+static nss_status_t read_result(TFILE *fp,nss_XbyY_args_t *args)
 {
-  struct spwd result;
   nss_status_t retv;
+#ifdef HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN
+  struct spwd result;
   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,&NSS_ARGS(args)->erange);
+  /* try to return in string format if requested */
+  if (args->buf.result==NULL)
+  {
+    /* read the entry into a temporary buffer */
+    buffer=(char *)malloc(args->buf.buflen);
+    if (buffer==NULL)
+      return NSS_STATUS_UNAVAIL;
+    retv=read_spwd(fp,&result,buffer,args->buf.buflen,&args->erange);
+    /* format to string */
+    if (retv==NSS_STATUS_SUCCESS)
+      if (spwd2str(&result,args->buf.buffer,args->buf.buflen)==NULL)
+      {
+        args->erange=1;
+        retv=NSS_NOTFOUND;
+      }
+    /* clean up and return result */
+    free(buffer);
+    if (retv!=NSS_STATUS_SUCCESS)
+      return retv;
+    args->returnval=args->buf.buffer;
+    args->returnlen=strlen(args->returnval);
+    return NSS_STATUS_SUCCESS;
+  }
+#endif /* HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN */
+  /* read the entry */
+  
retv=read_spwd(fp,args->buf.result,args->buf.buffer,args->buf.buflen,&args->erange);
   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);
+  args->returnval=args->buf.result;
   return NSS_STATUS_SUCCESS;
 }
 
-#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,&NSS_ARGS(args)->erange):
 \
-    read_spwdstring(fp,args); \
-  if ((NSS_ARGS(args)->buf.result)&&(retv==NSS_STATUS_SUCCESS)) \
-    NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.result;
-
-#else /* not HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN */
-
-#define READ_RESULT(fp) \
-  read_spwd(fp,(struct spwd 
*)NSS_ARGS(args)->buf.result,NSS_ARGS(args)->buf.buffer,NSS_ARGS(args)->buf.buflen,&NSS_ARGS(args)->erange);
 \
-  if (retv==NSS_STATUS_SUCCESS) \
-    NSS_ARGS(args)->returnval=NSS_ARGS(args)->buf.result;
-
-#endif /* not HAVE_STRUCT_NSS_XBYY_ARGS_RETURNLEN */
-
 static nss_status_t shadow_getspnam(nss_backend_t UNUSED(*be),void *args)
 {
   NSS_BYNAME(NSLCD_ACTION_SHADOW_BYNAME,
              NSS_ARGS(args)->key.name,
-             READ_RESULT(fp));
+             read_result(fp,args));
 }
 
 static nss_status_t shadow_setspent(nss_backend_t *be,void UNUSED(*args))
@@ -183,7 +174,7 @@
 static nss_status_t shadow_getspent(nss_backend_t *be,void *args)
 {
   NSS_GETENT(LDAP_BE(be)->fp,NSLCD_ACTION_SHADOW_ALL,
-             READ_RESULT(LDAP_BE(be)->fp));
+             read_result(LDAP_BE(be)->fp,args));
 }
 
 static nss_status_t shadow_endspent(nss_backend_t *be,void UNUSED(*args))
-- 
To unsubscribe send an email to
nss-pam-ldapd-commits-unsubscribe@lists.arthurdejong.org or see
http://lists.arthurdejong.org/nss-pam-ldapd-commits/