summaryrefslogtreecommitdiff
path: root/nis/nss_nisplus
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2006-05-20 19:22:30 +0000
committerUlrich Drepper <drepper@redhat.com>2006-05-20 19:22:30 +0000
commita17fa6100dd400cd0c64aab1803c2047c95bfd5b (patch)
tree3f1c005d18d338defaeaa489fd34c2c6e4fd7690 /nis/nss_nisplus
parent1d4f062ab84f24cab893a9211e3e72b2f1f470ce (diff)
downloadglibc-a17fa6100dd400cd0c64aab1803c2047c95bfd5b.tar.gz
* nis/nis_call.c (__prepare_niscall): New function. Split outcvs/fedora-glibc-20060521T2153
from __do_niscall. * nis/nis_table.c (__create_ib_request): Renamed from create_ib_request and exported. (__follow_path): New function. Split out from nis_list. * nis/nis_xdr.h: Add libnsl_hidden_proto for _xdr_ib_request and _xdr_nis_result. * nis/nis_xdr.c: Add libnsl_hidden_def for _xdr_ib_request and _xdr_nis_result. * nis/libnsl.h: Declare __prepare_niscall, __create_ib_request, and __follow_path. * nis/Versions: Export __prepare_niscall, __create_ib_request, __follow_path, __do_niscall3, _xdr_ib_request, and _xdr_nis_result from libnsl for version GLIBC_PRIVATE. * nis/nisplus-parser.h: Remove _nss_nisplus_parse_pwent_chk. Remove entry parameter from _nss_nisplus_parse_pwent and _nss_nisplus_parse_grent. * nis/nss_nisplus/nisplus-parser.c: Likewise. * nis/nss_nisplus/nisplus-pwd.c: Remove support for SETENT_BATCH_READ again. Rewrite getpwent handling to not use nis_first_entry and nis_next_entry. Roll out own niscall handling. * nis/nss_nisplus/nisplus-grp.c: Likewise. * sunrpc/xdr_rec.c: Fix typo in comment. 2006-05-18 David Woodhouse <dwmw2@redhat.com>
Diffstat (limited to 'nis/nss_nisplus')
-rw-r--r--nis/nss_nisplus/nisplus-grp.c202
-rw-r--r--nis/nss_nisplus/nisplus-parser.c108
-rw-r--r--nis/nss_nisplus/nisplus-pwd.c258
3 files changed, 325 insertions, 243 deletions
diff --git a/nis/nss_nisplus/nisplus-grp.c b/nis/nss_nisplus/nisplus-grp.c
index 624b20610a..c1adc98aee 100644
--- a/nis/nss_nisplus/nisplus-grp.c
+++ b/nis/nss_nisplus/nisplus-grp.c
@@ -29,12 +29,23 @@
#include "nss-nisplus.h"
#include "nisplus-parser.h"
+#include <libnsl.h>
+#include <nis_intern.h>
+#include <nis_xdr.h>
__libc_lock_define_initialized (static, lock);
-static nis_result *result;
-static unsigned long next_entry;
+/* Connection information. */
+static ib_request *ibreq;
+static directory_obj *dir;
+static dir_binding bptr;
+static char *tablepath;
+static char *tableptr;
+/* Cursor. */
+static netobj cursor;
+
+
static nis_name tablename_val;
static size_t tablename_len;
@@ -66,43 +77,57 @@ _nss_create_tablename (int *errnop)
return NSS_STATUS_SUCCESS;
}
-static enum nss_status
-internal_setgrent (void)
+
+static void
+internal_endgrent (void)
{
- enum nss_status status;
+ __nisbind_destroy (&bptr);
+ memset (&bptr, '\0', sizeof (bptr));
- if (result != NULL)
- {
- nis_freeresult (result);
- result = NULL;
- }
- next_entry = 0;
+ nis_free_directory (dir);
+ dir = NULL;
+
+ nis_free_request (ibreq);
+ ibreq = NULL;
+
+ xdr_free ((xdrproc_t) xdr_netobj, (char *) &cursor);
+ memset (&cursor, '\0', sizeof (cursor));
+
+ free (tablepath);
+ tableptr = tablepath = NULL;
+}
+
+
+static enum nss_status
+internal_setgrent (int *errnop)
+{
+ enum nss_status status = NSS_STATUS_SUCCESS;
if (tablename_val == NULL)
- {
- int err;
- if (_nss_create_tablename (&err) != NSS_STATUS_SUCCESS)
- return NSS_STATUS_UNAVAIL;
- }
+ status = _nss_create_tablename (errnop);
- result = nis_list (tablename_val, FOLLOW_LINKS | FOLLOW_PATH, NULL, NULL);
- if (result == NULL)
+ if (status == NSS_STATUS_SUCCESS)
{
- status = NSS_STATUS_TRYAGAIN;
- __set_errno (ENOMEM);
- }
- else
- {
- status = niserr2nss (result->status);
- if (status != NSS_STATUS_SUCCESS)
+ ibreq = __create_ib_request (tablename_val, 0);
+ if (ibreq == NULL)
{
- nis_freeresult (result);
- result = NULL;
+ *errnop = errno;
+ return NSS_STATUS_TRYAGAIN;
+ }
+
+ nis_error retcode = __prepare_niscall (tablename_val, &dir, &bptr, 0);
+ if (retcode != NIS_SUCCESS)
+ {
+ nis_free_request (ibreq);
+ ibreq = NULL;
+ status = niserr2nss (retcode);
}
}
+
return status;
}
+
enum nss_status
_nss_nisplus_setgrent (int stayopen)
{
@@ -110,60 +135,133 @@ _nss_nisplus_setgrent (int stayopen)
__libc_lock_lock (lock);
- status = internal_setgrent ();
+ internal_endgrent ();
+
+ // XXX We need to be able to set errno. Pass in new parameter.
+ int err;
+ status = internal_setgrent (&err);
__libc_lock_unlock (lock);
return status;
}
+
enum nss_status
_nss_nisplus_endgrent (void)
{
__libc_lock_lock (lock);
- if (result != NULL)
- {
- nis_freeresult (result);
- result = NULL;
- }
+ internal_endgrent ();
__libc_lock_unlock (lock);
return NSS_STATUS_SUCCESS;
}
+
static enum nss_status
internal_nisplus_getgrent_r (struct group *gr, char *buffer, size_t buflen,
int *errnop)
{
- int parse_res;
-
- if (result == NULL)
- {
- enum nss_status status;
-
- status = internal_setgrent ();
- if (result == NULL || status != NSS_STATUS_SUCCESS)
- return status;
- }
+ int parse_res = -1;
+ enum nss_status retval = NSS_STATUS_SUCCESS;
/* Get the next entry until we found a correct one. */
do
{
- if (next_entry >= result->objects.objects_len)
- return NSS_STATUS_NOTFOUND;
+ nis_error status;
+ nis_result result;
+ memset (&result, '\0', sizeof (result));
- parse_res = _nss_nisplus_parse_grent (result, next_entry, gr,
+ if (cursor.n_bytes == NULL)
+ {
+ if (ibreq == NULL)
+ {
+ retval = internal_setgrent (errnop);
+ if (retval != NSS_STATUS_SUCCESS)
+ return retval;
+ }
+
+ status = __do_niscall3 (&bptr, NIS_IBFIRST,
+ (xdrproc_t) _xdr_ib_request,
+ (caddr_t) ibreq,
+ (xdrproc_t) _xdr_nis_result,
+ (caddr_t) &result,
+ 0, NULL);
+ }
+ else
+ {
+ ibreq->ibr_cookie.n_bytes = cursor.n_bytes;
+ ibreq->ibr_cookie.n_len = cursor.n_len;
+
+ status = __do_niscall3 (&bptr, NIS_IBNEXT,
+ (xdrproc_t) _xdr_ib_request,
+ (caddr_t) ibreq,
+ (xdrproc_t) _xdr_nis_result,
+ (caddr_t) &result,
+ 0, NULL);
+
+ ibreq->ibr_cookie.n_bytes = NULL;
+ ibreq->ibr_cookie.n_len = 0;
+ }
+
+ if (status != NIS_SUCCESS)
+ return niserr2nss (status);
+
+ if (NIS_RES_STATUS (&result) == NIS_NOTFOUND)
+ {
+ /* No more entries on this server. This means we have to go
+ to the next server on the path. */
+ status = __follow_path (&tablepath, &tableptr, ibreq, &bptr);
+ if (status != NIS_SUCCESS)
+ return niserr2nss (status);
+
+ directory_obj *newdir = NULL;
+ dir_binding newbptr;
+ status = __prepare_niscall (ibreq->ibr_name, &newdir, &newbptr, 0);
+ if (status != NIS_SUCCESS)
+ return niserr2nss (status);
+
+ nis_free_directory (dir);
+ dir = newdir;
+ __nisbind_destroy (&bptr);
+ bptr = newbptr;
+
+ xdr_free ((xdrproc_t) xdr_netobj, (char *) &result.cookie);
+ result.cookie.n_bytes = NULL;
+ result.cookie.n_len = 0;
+ parse_res = 0;
+ goto next;
+ }
+ else if (NIS_RES_STATUS (&result) != NIS_SUCCESS)
+ return niserr2nss (NIS_RES_STATUS (&result));
+
+ parse_res = _nss_nisplus_parse_grent (&result, gr,
buffer, buflen, errnop);
- if (parse_res == -1)
- return NSS_STATUS_TRYAGAIN;
+ if (__builtin_expect (parse_res == -1, 0))
+ {
+ *errnop = ERANGE;
+ retval = NSS_STATUS_TRYAGAIN;
+ goto freeres;
+ }
- ++next_entry;
+ next:
+ /* Free the old cursor. */
+ xdr_free ((xdrproc_t) xdr_netobj, (char *) &cursor);
+ /* Remember the new one. */
+ cursor.n_bytes = result.cookie.n_bytes;
+ cursor.n_len = result.cookie.n_len;
+ /* Free the result structure. NB: we do not remove the cookie. */
+ result.cookie.n_bytes = NULL;
+ result.cookie.n_len = 0;
+ freeres:
+ xdr_free ((xdrproc_t) _xdr_nis_result, (char *) &result);
+ memset (&result, '\0', sizeof (result));
}
while (!parse_res);
- return NSS_STATUS_SUCCESS;
+ return retval;
}
enum nss_status
@@ -227,7 +325,7 @@ _nss_nisplus_getgrnam_r (const char *name, struct group *gr,
return status;
}
- parse_res = _nss_nisplus_parse_grent (result, 0, gr, buffer, buflen, errnop);
+ parse_res = _nss_nisplus_parse_grent (result, gr, buffer, buflen, errnop);
nis_freeresult (result);
if (__builtin_expect (parse_res < 1, 0))
{
@@ -288,7 +386,7 @@ _nss_nisplus_getgrgid_r (const gid_t gid, struct group *gr,
return status;
}
- parse_res = _nss_nisplus_parse_grent (result, 0, gr, buffer, buflen, errnop);
+ parse_res = _nss_nisplus_parse_grent (result, gr, buffer, buflen, errnop);
nis_freeresult (result);
if (__builtin_expect (parse_res < 1, 0))
diff --git a/nis/nss_nisplus/nisplus-parser.c b/nis/nss_nisplus/nisplus-parser.c
index 5ed07d86d9..1e1a343d52 100644
--- a/nis/nss_nisplus/nisplus-parser.c
+++ b/nis/nss_nisplus/nisplus-parser.c
@@ -31,10 +31,16 @@
#define NISENTRYLEN(idx, col, res) \
(NIS_RES_OBJECT (res)[idx].EN_data.en_cols.en_cols_val[col].ec_value.ec_value_len)
+#define NISOBJVAL(col, obj) \
+ ((obj)->EN_data.en_cols.en_cols_val[col].ec_value.ec_value_val)
+
+#define NISOBJLEN(col, obj) \
+ ((obj)->EN_data.en_cols.en_cols_val[col].ec_value.ec_value_len)
+
int
-_nss_nisplus_parse_pwent_chk (nis_result *result, struct passwd *pw,
- char *buffer, size_t buflen, int *errnop)
+_nss_nisplus_parse_pwent (nis_result *result, struct passwd *pw,
+ char *buffer, size_t buflen, int *errnop)
{
if ((result->status != NIS_SUCCESS && result->status != NIS_S_SUCCESS)
|| NIS_RES_NUMOBJ (result) != 1
@@ -43,19 +49,12 @@ _nss_nisplus_parse_pwent_chk (nis_result *result, struct passwd *pw,
|| NIS_RES_OBJECT (result)->EN_data.en_cols.en_cols_len < 7)
return 0;
- return _nss_nisplus_parse_pwent (result, 0, pw, buffer, buflen, errnop);
-}
-
-
-int
-_nss_nisplus_parse_pwent (nis_result *result, size_t entry, struct passwd *pw,
- char *buffer, size_t buflen, int *errnop)
-{
+ nis_object *obj = NIS_RES_OBJECT (result);
char *first_unused = buffer;
size_t room_left = buflen;
size_t len;
- if (NISENTRYLEN (entry, 0, result) >= room_left)
+ if (NISOBJLEN (0, obj) >= room_left)
{
/* The line is too long for our buffer. */
no_more_room:
@@ -63,9 +62,8 @@ _nss_nisplus_parse_pwent (nis_result *result, size_t entry, struct passwd *pw,
return -1;
}
- strncpy (first_unused, NISENTRYVAL (entry, 0, result),
- NISENTRYLEN (entry, 0, result));
- first_unused[NISENTRYLEN (entry, 0, result)] = '\0';
+ strncpy (first_unused, NISOBJVAL (0, obj), NISOBJLEN (0, obj));
+ first_unused[NISOBJLEN (0, obj)] = '\0';
len = strlen (first_unused);
if (len == 0) /* No name ? Should never happen, database is corrupt */
return 0;
@@ -73,19 +71,18 @@ _nss_nisplus_parse_pwent (nis_result *result, size_t entry, struct passwd *pw,
room_left -= len + 1;
first_unused += len + 1;
- if (NISENTRYLEN (entry, 1, result) >= room_left)
+ if (NISOBJLEN (1, obj) >= room_left)
goto no_more_room;
- strncpy (first_unused, NISENTRYVAL (entry, 1, result),
- NISENTRYLEN (entry, 1, result));
- first_unused[NISENTRYLEN (entry, 1, result)] = '\0';
+ strncpy (first_unused, NISOBJVAL (1, obj), NISOBJLEN (1, obj));
+ first_unused[NISOBJLEN (1, obj)] = '\0';
pw->pw_passwd = first_unused;
len = strlen (first_unused);
room_left -= len + 1;
first_unused += len + 1;
- char *numstr = NISENTRYVAL (entry, 2, result);
- len = NISENTRYLEN (entry, 2, result);
+ char *numstr = NISOBJVAL (2, obj);
+ len = NISOBJLEN (2, obj);
if (len == 0 && numstr[len - 1] != '\0')
{
if (len >= room_left)
@@ -100,8 +97,8 @@ _nss_nisplus_parse_pwent (nis_result *result, size_t entry, struct passwd *pw,
return 0;
pw->pw_uid = strtoul (numstr, NULL, 10);
- numstr = NISENTRYVAL (entry, 3, result);
- len = NISENTRYLEN (entry, 3, result);
+ numstr = NISOBJVAL (3, obj);
+ len = NISOBJLEN (3, obj);
if (len == 0 && numstr[len - 1] != '\0')
{
if (len >= room_left)
@@ -116,34 +113,31 @@ _nss_nisplus_parse_pwent (nis_result *result, size_t entry, struct passwd *pw,
return 0;
pw->pw_gid = strtoul (numstr, NULL, 10);
- if (NISENTRYLEN(entry, 4, result) >= room_left)
+ if (NISOBJLEN(4, obj) >= room_left)
goto no_more_room;
- strncpy (first_unused, NISENTRYVAL (entry, 4, result),
- NISENTRYLEN (entry, 4, result));
- first_unused[NISENTRYLEN (entry, 4, result)] = '\0';
+ strncpy (first_unused, NISOBJVAL (4, obj), NISOBJLEN (4, obj));
+ first_unused[NISOBJLEN (4, obj)] = '\0';
pw->pw_gecos = first_unused;
len = strlen (first_unused);
room_left -= len + 1;
first_unused += len + 1;
- if (NISENTRYLEN (entry, 5, result) >= room_left)
+ if (NISOBJLEN (5, obj) >= room_left)
goto no_more_room;
- strncpy (first_unused, NISENTRYVAL (entry, 5, result),
- NISENTRYLEN (entry, 5, result));
- first_unused[NISENTRYLEN (entry, 5, result)] = '\0';
+ strncpy (first_unused, NISOBJVAL (5, obj), NISOBJLEN (5, obj));
+ first_unused[NISOBJLEN (5, obj)] = '\0';
pw->pw_dir = first_unused;
len = strlen (first_unused);
room_left -= len + 1;
first_unused += len + 1;
- if (NISENTRYLEN (entry, 6, result) >= room_left)
+ if (NISOBJLEN (6, obj) >= room_left)
goto no_more_room;
- strncpy (first_unused, NISENTRYVAL (entry, 6, result),
- NISENTRYLEN (entry, 6, result));
- first_unused[NISENTRYLEN (entry, 6, result)] = '\0';
+ strncpy (first_unused, NISOBJVAL (6, obj), NISOBJLEN (6, obj));
+ first_unused[NISOBJLEN (6, obj)] = '\0';
pw->pw_shell = first_unused;
len = strlen (first_unused);
room_left -= len + 1;
@@ -154,26 +148,23 @@ _nss_nisplus_parse_pwent (nis_result *result, size_t entry, struct passwd *pw,
int
-_nss_nisplus_parse_grent (nis_result *result, u_long entry, struct group *gr,
+_nss_nisplus_parse_grent (nis_result *result, struct group *gr,
char *buffer, size_t buflen, int *errnop)
{
+ if ((result->status != NIS_SUCCESS && result->status != NIS_S_SUCCESS)
+ || __type_of(NIS_RES_OBJECT (result)) != NIS_ENTRY_OBJ
+ || strcmp (NIS_RES_OBJECT (result)[0].EN_data.en_type, "group_tbl") != 0
+ || NIS_RES_OBJECT (result)[0].EN_data.en_cols.en_cols_len < 4)
+ return 0;
+
+ nis_object *obj = NIS_RES_OBJECT (result);
char *first_unused = buffer;
size_t room_left = buflen;
char *line;
int count;
size_t len;
- if (result == NULL)
- return 0;
-
- if ((result->status != NIS_SUCCESS && result->status != NIS_S_SUCCESS)
- || __type_of(NIS_RES_OBJECT (result)) != NIS_ENTRY_OBJ
- || strcmp (NIS_RES_OBJECT (result)[entry].EN_data.en_type,
- "group_tbl") != 0
- || NIS_RES_OBJECT (result)[entry].EN_data.en_cols.en_cols_len < 4)
- return 0;
-
- if (NISENTRYLEN (entry, 0, result) >= room_left)
+ if (NISOBJLEN (0, obj) >= room_left)
{
/* The line is too long for our buffer. */
no_more_room:
@@ -181,9 +172,8 @@ _nss_nisplus_parse_grent (nis_result *result, u_long entry, struct group *gr,
return -1;
}
- strncpy (first_unused, NISENTRYVAL (entry, 0, result),
- NISENTRYLEN (entry, 0, result));
- first_unused[NISENTRYLEN (entry, 0, result)] = '\0';
+ strncpy (first_unused, NISOBJVAL (0, obj), NISOBJLEN (0, obj));
+ first_unused[NISOBJLEN (0, obj)] = '\0';
len = strlen (first_unused);
if (len == 0) /* group table is corrupt */
return 0;
@@ -191,20 +181,19 @@ _nss_nisplus_parse_grent (nis_result *result, u_long entry, struct group *gr,
room_left -= len + 1;
first_unused += len + 1;
- if (NISENTRYLEN (entry, 1, result) >= room_left)
+ if (NISOBJLEN (1, obj) >= room_left)
goto no_more_room;
- strncpy (first_unused, NISENTRYVAL (entry, 1, result),
- NISENTRYLEN (entry, 1, result));
- first_unused[NISENTRYLEN (entry, 1, result)] = '\0';
+ strncpy (first_unused, NISOBJVAL (1, obj), NISOBJLEN (1, obj));
+ first_unused[NISOBJLEN (1, obj)] = '\0';
gr->gr_passwd = first_unused;
len = strlen (first_unused);
room_left -= len + 1;
first_unused += len + 1;
- char *numstr = NISENTRYVAL (entry, 2, result);
- len = NISENTRYLEN (entry, 2, result);
- if (len == 0 && numstr[len - 1] != '\0')
+ char *numstr = NISOBJVAL (2, obj);
+ len = NISOBJLEN (2, obj);
+ if (len == 0 || numstr[len - 1] != '\0')
{
if (len >= room_left)
goto no_more_room;
@@ -218,12 +207,11 @@ _nss_nisplus_parse_grent (nis_result *result, u_long entry, struct group *gr,
return 0;
gr->gr_gid = strtoul (numstr, NULL, 10);
- if (NISENTRYLEN (entry, 3, result) >= room_left)
+ if (NISOBJLEN (3, obj) >= room_left)
goto no_more_room;
- strncpy (first_unused, NISENTRYVAL (entry, 3, result),
- NISENTRYLEN (entry, 3, result));
- first_unused[NISENTRYLEN (entry, 3, result)] = '\0';
+ strncpy (first_unused, NISOBJVAL (3, obj), NISOBJLEN (3, obj));
+ first_unused[NISOBJLEN (3, obj)] = '\0';
line = first_unused;
len = strlen (line);
room_left -= len + 1;
diff --git a/nis/nss_nisplus/nisplus-pwd.c b/nis/nss_nisplus/nisplus-pwd.c
index 7957e6a27d..93e37dddab 100644
--- a/nis/nss_nisplus/nisplus-pwd.c
+++ b/nis/nss_nisplus/nisplus-pwd.c
@@ -29,16 +29,21 @@
#include "nss-nisplus.h"
#include "nisplus-parser.h"
#include <libnsl.h>
+#include <nis_intern.h>
+#include <nis_xdr.h>
__libc_lock_define_initialized (static, lock)
-/* Previous result of iteration. */
-static nis_result *result;
+/* Connection information. */
+static ib_request *ibreq;
+static directory_obj *dir;
+static dir_binding bptr;
+static char *tablepath;
+static char *tableptr;
+/* Cursor. */
+static netobj cursor;
-/* All results of batch table load. */
-static nis_result *cached_results;
-static size_t cached_results_iter;
nis_name pwd_tablename_val attribute_hidden;
size_t pwd_tablename_len attribute_hidden;
@@ -80,50 +85,48 @@ _nss_pwd_create_tablename (int *errnop)
static void
internal_nisplus_endpwent (void)
{
- if (cached_results != NULL)
- {
- nis_freeresult (cached_results);
- cached_results = NULL;
- cached_results_iter = 0;
- }
+ __nisbind_destroy (&bptr);
+ memset (&bptr, '\0', sizeof (bptr));
- if (result != NULL)
- {
- nis_freeresult (result);
- result = NULL;
- }
+ nis_free_directory (dir);
+ dir = NULL;
+
+ nis_free_request (ibreq);
+ ibreq = NULL;
+
+ xdr_free ((xdrproc_t) xdr_netobj, (char *) &cursor);
+ memset (&cursor, '\0', sizeof (cursor));
+
+ free (tablepath);
+ tableptr = tablepath = NULL;
}
static enum nss_status
internal_nisplus_setpwent (int *errnop)
{
- enum nss_status status;
+ enum nss_status status = NSS_STATUS_SUCCESS;
- cached_results = nis_list (pwd_tablename_val, FOLLOW_PATH | FOLLOW_LINKS,
- NULL, NULL);
+ if (pwd_tablename_val == NULL)
+ status = _nss_pwd_create_tablename (errnop);
- if (cached_results == NULL)
- {
- *errnop = errno;
- status = NSS_STATUS_TRYAGAIN;
- }
- else if (__builtin_expect ((status = niserr2nss (cached_results->status))
- != NSS_STATUS_SUCCESS, 0))
- {
- nis_freeresult (cached_results);
- cached_results = NULL;
- }
- else if (__builtin_expect (__type_of (NIS_RES_OBJECT (cached_results))
- != NIS_ENTRY_OBJ
- || strcmp (NIS_RES_OBJECT (cached_results)->EN_data.en_type,
- "passwd_tbl") != 0
- || NIS_RES_OBJECT (cached_results)->EN_data.en_cols.en_cols_len < 7,
- 0))
+ if (status == NSS_STATUS_SUCCESS)
{
- nis_freeresult (cached_results);
- cached_results = NULL;
- status = NSS_STATUS_NOTFOUND;
+ ibreq = __create_ib_request (pwd_tablename_val, 0);
+ if (ibreq == NULL)
+ {
+ *errnop = errno;
+ return NSS_STATUS_TRYAGAIN;
+ }
+
+ nis_error retcode = __prepare_niscall (pwd_tablename_val, &dir,
+ &bptr, 0);
+ if (retcode != NIS_SUCCESS)
+ {
+ nis_free_request (ibreq);
+ ibreq = NULL;
+ status = niserr2nss (retcode);
+ }
}
return status;
@@ -133,26 +136,15 @@ internal_nisplus_setpwent (int *errnop)
enum nss_status
_nss_nisplus_setpwent (int stayopen)
{
- enum nss_status status = NSS_STATUS_SUCCESS;
+ enum nss_status status;
__libc_lock_lock (lock);
internal_nisplus_endpwent ();
- if (pwd_tablename_val == NULL)
- {
- // XXX We need to be able to set errno. Pass in new parameter.
- int err;
- status = _nss_pwd_create_tablename (&err);
- }
-
- if (status == NSS_STATUS_SUCCESS
- && (_nsl_default_nss () & NSS_FLAG_SETENT_BATCH_READ))
- {
- // XXX We need to be able to set errno. Pass in new parameter.
- int err;
- status = internal_nisplus_setpwent (&err);
- }
+ // XXX We need to be able to set errno. Pass in new parameter.
+ int err;
+ status = internal_nisplus_setpwent (&err);
__libc_lock_unlock (lock);
@@ -178,98 +170,104 @@ internal_nisplus_getpwent_r (struct passwd *pw, char *buffer, size_t buflen,
int *errnop)
{
int parse_res = -1;
- nis_result *saved_res = NULL;
+ enum nss_status retval = NSS_STATUS_SUCCESS;
/* Get the next entry until we found a correct one. */
do
{
- if (cached_results != NULL)
+ nis_error status;
+ nis_result result;
+ memset (&result, '\0', sizeof (result));
+
+ if (cursor.n_bytes == NULL)
{
- handle_batch_read:
- /* See whether we reported the last problem. */
- if (cached_results_iter >= NIS_RES_NUMOBJ (cached_results))
- return NSS_STATUS_NOTFOUND;
-
- parse_res = _nss_nisplus_parse_pwent (cached_results,
- cached_results_iter, pw,
- buffer, buflen, errnop);
+ if (ibreq == NULL)
+ {
+ retval = internal_nisplus_setpwent (errnop);
+ if (retval != NSS_STATUS_SUCCESS)
+ return retval;
+ }
+
+ status = __do_niscall3 (&bptr, NIS_IBFIRST,
+ (xdrproc_t) _xdr_ib_request,
+ (caddr_t) ibreq,
+ (xdrproc_t) _xdr_nis_result,
+ (caddr_t) &result,
+ 0, NULL);
}
else
{
- if (result == NULL)
- {
- if (pwd_tablename_val == NULL)
- {
- enum nss_status status = _nss_pwd_create_tablename (errnop);
-
- if (status != NSS_STATUS_SUCCESS)
- return status;
- }
-
- /* Determine whether we should instead read all entries at
- once. */
- if (_nsl_default_nss () & NSS_FLAG_SETENT_BATCH_READ)
- {
- enum nss_status status = internal_nisplus_setpwent (errnop);
-
- if (status == NSS_STATUS_SUCCESS && cached_results != NULL)
- goto handle_batch_read;
- }
-
- saved_res = NULL;
-
- result = nis_first_entry (pwd_tablename_val);
- if (result == NULL)
- {
- *errnop = errno;
- return NSS_STATUS_TRYAGAIN;
- }
- if (niserr2nss (result->status) != NSS_STATUS_SUCCESS)
- return niserr2nss (result->status);
- }
- else
- {
- saved_res = result;
- result = nis_next_entry (pwd_tablename_val, &result->cookie);
- if (result == NULL)
- {
- *errnop = errno;
- return NSS_STATUS_TRYAGAIN;
- }
- if (niserr2nss (result->status) != NSS_STATUS_SUCCESS)
- {
- nis_freeresult (saved_res);
- return niserr2nss (result->status);
- }
- }
+ ibreq->ibr_cookie.n_bytes = cursor.n_bytes;
+ ibreq->ibr_cookie.n_len = cursor.n_len;
+
+ status = __do_niscall3 (&bptr, NIS_IBNEXT,
+ (xdrproc_t) _xdr_ib_request,
+ (caddr_t) ibreq,
+ (xdrproc_t) _xdr_nis_result,
+ (caddr_t) &result,
+ 0, NULL);
+
+ ibreq->ibr_cookie.n_bytes = NULL;
+ ibreq->ibr_cookie.n_len = 0;
+ }
- parse_res = _nss_nisplus_parse_pwent_chk (result, pw, buffer,
- buflen, errnop);
+ if (status != NIS_SUCCESS)
+ return niserr2nss (status);
+
+ if (NIS_RES_STATUS (&result) == NIS_NOTFOUND)
+ {
+ /* No more entries on this server. This means we have to go
+ to the next server on the path. */
+ status = __follow_path (&tablepath, &tableptr, ibreq, &bptr);
+ if (status != NIS_SUCCESS)
+ return niserr2nss (status);
+
+ directory_obj *newdir = NULL;
+ dir_binding newbptr;
+ status = __prepare_niscall (ibreq->ibr_name, &newdir, &newbptr, 0);
+ if (status != NIS_SUCCESS)
+ return niserr2nss (status);
+
+ nis_free_directory (dir);
+ dir = newdir;
+ __nisbind_destroy (&bptr);
+ bptr = newbptr;
+
+ xdr_free ((xdrproc_t) xdr_netobj, (char *) &result.cookie);
+ result.cookie.n_bytes = NULL;
+ result.cookie.n_len = 0;
+ parse_res = 0;
+ goto next;
}
+ else if (NIS_RES_STATUS (&result) != NIS_SUCCESS)
+ return niserr2nss (NIS_RES_STATUS (&result));
+
+ parse_res = _nss_nisplus_parse_pwent (&result, pw, buffer,
+ buflen, errnop);
if (__builtin_expect (parse_res == -1, 0))
{
- if (cached_results == NULL)
- {
- nis_freeresult (result);
- result = saved_res;
- }
*errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
+ retval = NSS_STATUS_TRYAGAIN;
+ goto freeres;
}
- if (cached_results != NULL)
- ++cached_results_iter;
- else
- if (saved_res)
- {
- nis_freeresult (saved_res);
- saved_res = NULL;
- }
+ next:
+ /* Free the old cursor. */
+ xdr_free ((xdrproc_t) xdr_netobj, (char *) &cursor);
+ /* Remember the new one. */
+ cursor.n_bytes = result.cookie.n_bytes;
+ cursor.n_len = result.cookie.n_len;
+ /* Free the result structure. NB: we do not remove the cookie. */
+ result.cookie.n_bytes = NULL;
+ result.cookie.n_len = 0;
+ freeres:
+ xdr_free ((xdrproc_t) _xdr_nis_result, (char *) &result);
+ memset (&result, '\0', sizeof (result));
}
while (!parse_res);
- return NSS_STATUS_SUCCESS;
+ return retval;
}
enum nss_status
@@ -331,8 +329,7 @@ _nss_nisplus_getpwnam_r (const char *name, struct passwd *pw,
return status;
}
- parse_res = _nss_nisplus_parse_pwent_chk (result, pw, buffer, buflen,
- errnop);
+ parse_res = _nss_nisplus_parse_pwent (result, pw, buffer, buflen, errnop);
nis_freeresult (result);
@@ -391,8 +388,7 @@ _nss_nisplus_getpwuid_r (const uid_t uid, struct passwd *pw,
return status;
}
- parse_res = _nss_nisplus_parse_pwent_chk (result, pw, buffer, buflen,
- errnop);
+ parse_res = _nss_nisplus_parse_pwent (result, pw, buffer, buflen, errnop);
nis_freeresult (result);