2747922
diff -up nss-pam-ldapd-0.7.17/common/tio.c.epipe nss-pam-ldapd-0.7.17/common/tio.c
2747922
--- nss-pam-ldapd-0.7.17/common/tio.c.epipe	2012-09-09 19:59:27.189069033 +0200
2747922
+++ nss-pam-ldapd-0.7.17/common/tio.c	2012-09-09 20:00:34.378229054 +0200
2747922
@@ -312,10 +312,39 @@ int tio_read(TFILE *fp, void *buf, size_
0ae6295
   }
0ae6295
 }
0ae6295
 
0ae6295
-/* Read and discard the specified number of bytes from the stream. */
0ae6295
+/* Read and discard the specified number of bytes from the stream.
0ae6295
+   If count is 0 reads and discards any data that can be read and empties
0ae6295
+   the read buffer. */
0ae6295
 int tio_skip(TFILE *fp, size_t count)
0ae6295
 {
0ae6295
-  return tio_read(fp,NULL,count);
0ae6295
+  int rv;
0ae6295
+  size_t len;
0ae6295
+  /* for simple cases just read */
0ae6295
+  if (count>0)
0ae6295
+  {
0ae6295
+    return tio_read(fp,NULL,count);
0ae6295
+  }
0ae6295
+  /* clear the read buffer */
0ae6295
+  fp->readbuffer.start=0;
0ae6295
+  fp->readbuffer.len=0;
0ae6295
+  fp->read_resettable=0;
0ae6295
+  /* read until we can't read no more */
0ae6295
+  len=fp->readbuffer.size;
0ae6295
+#ifdef SSIZE_MAX
0ae6295
+  if (len>SSIZE_MAX)
0ae6295
+    len=SSIZE_MAX;
0ae6295
+#endif /* SSIZE_MAX */
0ae6295
+  while (1)
0ae6295
+  {
0ae6295
+    rv=read(fp->fd,fp->readbuffer.buffer,len);
0ae6295
+    /* check for errors */
0ae6295
+    if (rv==0)
0ae6295
+      return 0; /* end-of-file */
0ae6295
+    if ((rv<0)&&(errno==EWOULDBLOCK))
0ae6295
+      return 0; /* we've ready everything we can without blocking */
0ae6295
+    if ((rv<0)&&(errno!=EINTR)&&(errno!=EAGAIN))
0ae6295
+      return -1; /* something went wrong with the read */
0ae6295
+  }
0ae6295
 }
0ae6295
 
0ae6295
 /* the caller has assured us that we can write to the file descriptor
2747922
diff -up nss-pam-ldapd-0.7.17/common/tio.h.epipe nss-pam-ldapd-0.7.17/common/tio.h
2747922
--- nss-pam-ldapd-0.7.17/common/tio.h.epipe	2012-09-09 20:00:55.145969422 +0200
2747922
+++ nss-pam-ldapd-0.7.17/common/tio.h	2012-09-09 20:01:48.294304972 +0200
0ae6295
@@ -2,7 +2,7 @@
0ae6295
    tio.h - timed io functions
0ae6295
    This file is part of the nss-pam-ldapd library.
0ae6295
 
0ae6295
-   Copyright (C) 2007, 2008 Arthur de Jong
0ae6295
+   Copyright (C) 2007, 2008, 2010, 2012 Arthur de Jong
0ae6295
 
0ae6295
    This library is free software; you can redistribute it and/or
0ae6295
    modify it under the terms of the GNU Lesser General Public
0ae6295
@@ -56,7 +56,9 @@ TFILE *tio_fdopen(int fd,struct timeval
0ae6295
 /* Read the specified number of bytes from the stream. */
0ae6295
 int tio_read(TFILE *fp,void *buf,size_t count);
0ae6295
 
0ae6295
-/* Read and discard the specified number of bytes from the stream. */
0ae6295
+/* Read and discard the specified number of bytes from the stream.
0ae6295
+   If count is 0 reads and discards any data that can be read and empties
0ae6295
+   the read buffer. */
0ae6295
 int tio_skip(TFILE *fp,size_t count);
0ae6295
 
0ae6295
 /* Write the specified buffer to the stream. */
2747922
diff -up nss-pam-ldapd-0.7.17/nss/common.h.epipe nss-pam-ldapd-0.7.17/nss/common.h
2747922
--- nss-pam-ldapd-0.7.17/nss/common.h.epipe	2012-09-09 20:02:18.855922903 +0200
2747922
+++ nss-pam-ldapd-0.7.17/nss/common.h	2012-09-09 20:03:52.188756077 +0200
0ae6295
@@ -2,7 +2,7 @@
0ae6295
    common.h - common functions for NSS lookups
0ae6295
 
0ae6295
    Copyright (C) 2006 West Consulting
0ae6295
-   Copyright (C) 2006, 2007, 2008, 2009, 2010 Arthur de Jong
0ae6295
+   Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012 Arthur de Jong
0ae6295
 
0ae6295
    This library is free software; you can redistribute it and/or
0ae6295
    modify it under the terms of the GNU Lesser General Public
1e1125a
@@ -97,8 +97,10 @@
1e1125a
   READ_RESPONSE_CODE(fp); \
0ae6295
   retv=readfn; \
0ae6295
   /* close socket and we're done */ \
1e1125a
-  if ((retv==NSS_STATUS_SUCCESS)||(retv==NSS_STATUS_TRYAGAIN)) \
1e1125a
+  if ((retv==NSS_STATUS_SUCCESS)||(retv==NSS_STATUS_TRYAGAIN)) { \
0ae6295
+    (void)tio_skip(fp,0); /* read any buffered data */ \
0ae6295
     (void)tio_close(fp); \
1e1125a
+  } \
0ae6295
   return retv;
0ae6295
 
1e1125a
 /* This macro can be used to generate a get..byname() function
2747922
@@ -123,6 +125,7 @@
0ae6295
     return NSS_STATUS_UNAVAIL; \
0ae6295
   if (fp!=NULL) \
0ae6295
   { \
0ae6295
+    (void)tio_skip(fp,0); /* read any buffered data */ \
0ae6295
     (void)tio_close(fp); \
0ae6295
     fp=NULL; \
0ae6295
   } \