This one time, at band camp, Raphael Hertzog said:
> On Sun, 27 May 2007, Guido Guenther wrote:
> > Yes it does, but that doesn't seem to be sufficient. If you look at
> > nss/files-XXX.c you see:
> 
> Where's that from?

glibc.

> > Note that the group stays 112 until the buffer is large enough to fit
> > the "huge" group 10000 into it. This is something that must be handled
> > by the nss modul internally. So the pgsql module should IMHO do
> > somehting like:
> > 
> >     res = fetch("group");
> >         if (PQresultStatus(res)==PGRES_TUPLES_OK) {
> >                 status = res2grp(res, result, buffer, buflen, errnop);
> >                 if(status == NSS_STATUS_TRYAGAIN && *errnop = ERANGE)
>                                                             ^^
>                                                    should probably be ==
> >                         move("group", backwards)
> >         } else
> >                 status = NSS_STATUS_UNAVAIL;
> > 
> > Where move() just moves the cursor one row back. So I'll reassign to
> > libnss-pgsql1, if you agree?
> 
> Sure, however it's not the latest upstream version in Debian and it might
> not be completely relevant in that case.

The logic is the same in both the version in Debian, and the new
upstream version.

This patch for the current version seems to fix it:

diff -Nru /tmp/hty0RmSdM8/libnss-pgsql-1.3.2/src/backend.c 
/tmp/61pmwYpjZQ/libnss-pgsql-1.3.3/src/backend.c
--- /tmp/hty0RmSdM8/libnss-pgsql-1.3.2/src/backend.c    2006-09-27 
01:02:37.000000000 +0000
+++ /tmp/61pmwYpjZQ/libnss-pgsql-1.3.3/src/backend.c    2007-05-27 
23:32:20.000000000 +0000
@@ -522,6 +522,28 @@
 }
 
 /*
+ * Back the cursor up - needed whe returning NSS_STATUS_TRYAGAIN and ERANGE
+ */
+PGresult *move(char *what)
+{
+    char *stmt;
+    PGresult *res;
+
+    asprintf(&stmt, "MOVE BACKWARD 1 IN nss_pgsql_internal_%s_curs", what);
+    if(_conn == NULL) {
+        D("Did a fetch with the database closed!");
+    }
+    if(PQstatus(_conn) != CONNECTION_OK) {
+         D("oops! die connection is futsch");
+         return NULL;
+    }
+    res = PQexec(_conn, stmt);
+    free(stmt);
+
+    return res;
+}
+
+/*
  * get a group entry from cursor
  */
 enum nss_status backend_getgrent(struct group *result,
@@ -533,8 +555,11 @@
    enum nss_status status = NSS_STATUS_NOTFOUND;
 
    res = fetch("group");
-   if (PQresultStatus(res)==PGRES_TUPLES_OK)
+   if (PQresultStatus(res)==PGRES_TUPLES_OK) {
        status = res2grp(res, result, buffer, buflen, errnop);
+       if (status == NSS_STATUS_TRYAGAIN && *errnop == ERANGE)
+            move("group");
+   }
    else
        status = NSS_STATUS_UNAVAIL;
 
@@ -554,8 +579,11 @@
    enum nss_status status = NSS_STATUS_NOTFOUND;
 
    res = fetch("passwd");
-   if (PQresultStatus(res)==PGRES_TUPLES_OK)
+   if (PQresultStatus(res)==PGRES_TUPLES_OK) {
        status = res2pwd(res, result, buffer, buflen, errnop);
+       if (status == NSS_STATUS_TRYAGAIN && *errnop == ERANGE)
+             move("passwd");
+   }
    else
        status = NSS_STATUS_UNAVAIL;
 

With this patch, I get output that looks correct:

gid_t: 10800 starting
Enlarging buffer from 496 to 992
gid_t: 10800 starting
Enlarging buffer from 992 to 1984
gid_t: 10800 starting
Enlarging buffer from 1984 to 3968
gid_t: 10800 starting
Enlarging buffer from 3968 to 7936
gid_t: 10800 starting
Enlarging buffer from 7936 to 15872
gid_t: 10800 starting
Enlarging buffer from 15872 to 31744
gid_t: 10800 starting
gid_t: 10800 done

buxy: I've installed a version with this patch on alioth.  I am going to
revert the patched version of nss-updatedb in the morning, unless you
have any objections.
-- 
 -----------------------------------------------------------------
|   ,''`.                                            Stephen Gran |
|  : :' :                                        [EMAIL PROTECTED] |
|  `. `'                        Debian user, admin, and developer |
|    `-                                     http://www.debian.org |
 -----------------------------------------------------------------

Attachment: signature.asc
Description: Digital signature

Reply via email to