mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-21 20:40:05 +00:00
* nis/nis_call.c (__prepare_niscall): New function. Split out
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>
This commit is contained in:
parent
1d4f062ab8
commit
a17fa6100d
29
ChangeLog
29
ChangeLog
@ -1,3 +1,30 @@
|
||||
2006-05-20 Ulrich Drepper <drepper@redhat.com>
|
||||
|
||||
* nis/nis_call.c (__prepare_niscall): New function. Split out
|
||||
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-19 Ulrich Drepper <drepper@redhat.com>
|
||||
|
||||
* nis/nis_call.c (__do_niscall3): Avoid code duplication in error
|
||||
@ -30,7 +57,7 @@
|
||||
cb->serv together. Remove now obsolete free calls.
|
||||
(__nis_destroy_callback): Remove now obsolete free call.
|
||||
|
||||
2006-05-18 David Woodhouse <dwmw2@infradead.org>
|
||||
2006-05-18 David Woodhouse <dwmw2@redhat.com>
|
||||
|
||||
* sysdeps/posix/getaddrinfo.c: Add unique labels to the default
|
||||
RFC3484 precedence table for fec0::/10 and fc00::/7 (site-local
|
||||
|
@ -58,7 +58,8 @@ libnsl {
|
||||
xdr_ypall;
|
||||
}
|
||||
GLIBC_PRIVATE {
|
||||
_nsl_default_nss;
|
||||
_nsl_default_nss; __prepare_niscall; __follow_path; __do_niscall3;
|
||||
__create_ib_request; _xdr_ib_request; _xdr_nis_result;
|
||||
}
|
||||
}
|
||||
|
||||
|
14
nis/libnsl.h
14
nis/libnsl.h
@ -16,6 +16,8 @@
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
02111-1307 USA. */
|
||||
|
||||
#include <rpcsvc/nis.h>
|
||||
|
||||
#define NSS_FLAG_NETID_AUTHORITATIVE 1
|
||||
#define NSS_FLAG_SERVICES_AUTHORITATIVE 2
|
||||
#define NSS_FLAG_SETENT_BATCH_READ 4
|
||||
@ -23,3 +25,15 @@
|
||||
|
||||
/* Get current set of default flags. */
|
||||
extern int _nsl_default_nss (void);
|
||||
|
||||
/* Set up everything for a call to __do_niscall3. */
|
||||
extern nis_error __prepare_niscall (const_nis_name name, directory_obj **dirp,
|
||||
dir_binding *bptrp, unsigned int flags);
|
||||
|
||||
extern struct ib_request *__create_ib_request (const_nis_name name,
|
||||
unsigned int flags);
|
||||
libnsl_hidden_proto (__create_ib_request)
|
||||
|
||||
extern nis_error __follow_path (char **tablepath, char **tableptr,
|
||||
struct ib_request *ibreq, dir_binding *bptr);
|
||||
libnsl_hidden_proto (__follow_path)
|
||||
|
@ -531,50 +531,68 @@ __nisfind_server (const_nis_name name, directory_obj **dir)
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
nis_error
|
||||
__prepare_niscall (const_nis_name name, directory_obj **dirp,
|
||||
dir_binding *bptrp, unsigned int flags)
|
||||
{
|
||||
nis_error retcode = __nisfind_server (name, dirp);
|
||||
if (__builtin_expect (retcode != NIS_SUCCESS, 0))
|
||||
return retcode;
|
||||
|
||||
nis_server *server;
|
||||
u_int server_len;
|
||||
|
||||
if (flags & MASTER_ONLY)
|
||||
{
|
||||
server = (*dirp)->do_servers.do_servers_val;
|
||||
server_len = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
server = (*dirp)->do_servers.do_servers_val;
|
||||
server_len = (*dirp)->do_servers.do_servers_len;
|
||||
}
|
||||
|
||||
retcode = __nisbind_create (bptrp, server, server_len, flags);
|
||||
if (retcode == NIS_SUCCESS)
|
||||
{
|
||||
do
|
||||
if (__nisbind_connect (bptrp) == NIS_SUCCESS)
|
||||
return NIS_SUCCESS;
|
||||
while (__nisbind_next (bptrp) == NIS_SUCCESS);
|
||||
|
||||
__nisbind_destroy (bptrp);
|
||||
memset (bptrp, '\0', sizeof (*bptrp));
|
||||
|
||||
retcode = NIS_NAMEUNREACHABLE;
|
||||
}
|
||||
|
||||
nis_free_directory (*dirp);
|
||||
*dirp = NULL;
|
||||
|
||||
return retcode;
|
||||
}
|
||||
|
||||
|
||||
nis_error
|
||||
__do_niscall (const_nis_name name, u_long prog, xdrproc_t xargs,
|
||||
caddr_t req, xdrproc_t xres, caddr_t resp, unsigned int flags,
|
||||
nis_cb *cb)
|
||||
{
|
||||
nis_error retcode;
|
||||
dir_binding bptr;
|
||||
directory_obj *dir = NULL;
|
||||
nis_server *server;
|
||||
u_int server_len;
|
||||
int saved_errno = errno;
|
||||
|
||||
retcode = __nisfind_server (name, &dir);
|
||||
if (retcode != NIS_SUCCESS)
|
||||
return retcode;
|
||||
|
||||
if (flags & MASTER_ONLY)
|
||||
{
|
||||
server = dir->do_servers.do_servers_val;
|
||||
server_len = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
server = dir->do_servers.do_servers_val;
|
||||
server_len = dir->do_servers.do_servers_len;
|
||||
}
|
||||
|
||||
retcode = __nisbind_create (&bptr, server, server_len, flags);
|
||||
nis_error retcode = __prepare_niscall (name, &dir, &bptr, flags);
|
||||
if (retcode == NIS_SUCCESS)
|
||||
{
|
||||
while (__nisbind_connect (&bptr) != NIS_SUCCESS)
|
||||
{
|
||||
if (__nisbind_next (&bptr) != NIS_SUCCESS)
|
||||
{
|
||||
nis_free_directory (dir);
|
||||
return NIS_NAMEUNREACHABLE;
|
||||
}
|
||||
}
|
||||
retcode = __do_niscall3 (&bptr, prog, xargs, req, xres, resp, flags, cb);
|
||||
|
||||
__nisbind_destroy (&bptr);
|
||||
}
|
||||
|
||||
nis_free_directory (dir);
|
||||
}
|
||||
|
||||
__set_errno (saved_errno);
|
||||
|
||||
|
127
nis/nis_table.c
127
nis/nis_table.c
@ -17,15 +17,17 @@
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
02111-1307 USA. */
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <rpcsvc/nis.h>
|
||||
|
||||
#include "nis_xdr.h"
|
||||
#include "nis_intern.h"
|
||||
#include "libnsl.h"
|
||||
|
||||
|
||||
static struct ib_request *
|
||||
create_ib_request (const_nis_name name, unsigned int flags)
|
||||
struct ib_request *
|
||||
__create_ib_request (const_nis_name name, unsigned int flags)
|
||||
{
|
||||
struct ib_request *ibreq = calloc (1, sizeof (struct ib_request));
|
||||
nis_attr *search_val = NULL;
|
||||
@ -125,6 +127,7 @@ create_ib_request (const_nis_name name, unsigned int flags)
|
||||
|
||||
return ibreq;
|
||||
}
|
||||
libnsl_hidden_def (__create_ib_request)
|
||||
|
||||
static const struct timeval RPCTIMEOUT = {10, 0};
|
||||
|
||||
@ -160,6 +163,38 @@ get_tablepath (char *name, dir_binding *bptr)
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
nis_error
|
||||
__follow_path (char **tablepath, char **tableptr, struct ib_request *ibreq,
|
||||
dir_binding *bptr)
|
||||
{
|
||||
if (*tablepath == NULL)
|
||||
{
|
||||
*tablepath = get_tablepath (ibreq->ibr_name, bptr);
|
||||
if (*tablepath == NULL)
|
||||
return NIS_NOMEMORY;
|
||||
|
||||
*tableptr = *tablepath;
|
||||
}
|
||||
if (*tableptr == NULL)
|
||||
return NIS_NOTFOUND;
|
||||
|
||||
char *newname = strsep (tableptr, ":");
|
||||
if (newname[0] == '\0')
|
||||
return NIS_NOTFOUND;
|
||||
|
||||
newname = strdup (newname);
|
||||
if (newname == NULL)
|
||||
return NIS_NOMEMORY;
|
||||
|
||||
free (ibreq->ibr_name);
|
||||
ibreq->ibr_name = newname;
|
||||
|
||||
return NIS_SUCCESS;
|
||||
}
|
||||
libnsl_hidden_def (__follow_path)
|
||||
|
||||
|
||||
nis_result *
|
||||
nis_list (const_nis_name name, unsigned int flags,
|
||||
int (*callback) (const_nis_name name,
|
||||
@ -193,7 +228,7 @@ nis_list (const_nis_name name, unsigned int flags,
|
||||
return res;
|
||||
}
|
||||
|
||||
ibreq = create_ib_request (name, flags);
|
||||
ibreq = __create_ib_request (name, flags);
|
||||
if (ibreq == NULL)
|
||||
{
|
||||
status = NIS_BADNAME;
|
||||
@ -260,6 +295,7 @@ nis_list (const_nis_name name, unsigned int flags,
|
||||
|
||||
if (callback != NULL)
|
||||
{
|
||||
assert (cb == NULL);
|
||||
cb = __nis_create_callback (callback, userdata, flags);
|
||||
ibreq->ibr_cbhost.ibr_cbhost_len = 1;
|
||||
ibreq->ibr_cbhost.ibr_cbhost_val = cb->serv;
|
||||
@ -327,69 +363,30 @@ nis_list (const_nis_name name, unsigned int flags,
|
||||
following code. But it also would unnecessarily
|
||||
free the result structure. We avoid this here
|
||||
along with the necessary tests. */
|
||||
#if 1
|
||||
xdr_free ((xdrproc_t) _xdr_nis_result, (char *)res);
|
||||
memset (res, '\0', sizeof (*res));
|
||||
#else
|
||||
nis_freeresult (res);
|
||||
res = calloc (1, sizeof (nis_result));
|
||||
if (res == NULL)
|
||||
goto fail;
|
||||
#endif
|
||||
first_try = 1; /* Try at first the old binding */
|
||||
goto again;
|
||||
}
|
||||
else if ((flags & FOLLOW_PATH)
|
||||
&& NIS_RES_STATUS (res) == NIS_PARTIAL)
|
||||
{
|
||||
if (tablepath == NULL)
|
||||
clnt_status = __follow_path (&tablepath, &tableptr, ibreq,
|
||||
&bptr);
|
||||
if (clnt_status != NIS_SUCCESS)
|
||||
{
|
||||
tablepath = get_tablepath (ibreq->ibr_name, &bptr);
|
||||
tableptr = tablepath;
|
||||
}
|
||||
if (tableptr == NULL)
|
||||
{
|
||||
++done;
|
||||
break;
|
||||
}
|
||||
free (ibreq->ibr_name);
|
||||
ibreq->ibr_name = strsep (&tableptr, ":");
|
||||
if (ibreq->ibr_name == NULL || ibreq->ibr_name[0] == '\0')
|
||||
{
|
||||
ibreq->ibr_name = strdup ("");
|
||||
if (ibreq->ibr_name == NULL)
|
||||
{
|
||||
NIS_RES_STATUS (res) = NIS_NOMEMORY;
|
||||
goto fail;
|
||||
}
|
||||
NIS_RES_STATUS (res) = clnt_status;
|
||||
++done;
|
||||
}
|
||||
else
|
||||
{
|
||||
ibreq->ibr_name = strdup (ibreq->ibr_name);
|
||||
/* The following is a non-obvious optimization. A
|
||||
nis_freeresult call would call xdr_free as the
|
||||
following code. But it also would unnecessarily
|
||||
free the result structure. We avoid this here
|
||||
along with the necessary tests. */
|
||||
#if 1
|
||||
xdr_free ((xdrproc_t) _xdr_nis_result, (char *)res);
|
||||
xdr_free ((xdrproc_t) _xdr_nis_result, (char *) res);
|
||||
memset (res, '\0', sizeof (*res));
|
||||
if (ibreq->ibr_name == NULL)
|
||||
{
|
||||
NIS_RES_STATUS (res) = NIS_NOMEMORY;
|
||||
goto fail;
|
||||
}
|
||||
#else
|
||||
nis_freeresult (res);
|
||||
res = calloc (1, sizeof (nis_result));
|
||||
if (res == NULL || ibreq->ibr_name == NULL)
|
||||
{
|
||||
free (res);
|
||||
res = NULL;
|
||||
goto fail;
|
||||
}
|
||||
#endif
|
||||
first_try = 1;
|
||||
goto again;
|
||||
}
|
||||
@ -407,30 +404,10 @@ nis_list (const_nis_name name, unsigned int flags,
|
||||
++done;
|
||||
else
|
||||
{
|
||||
if (tablepath == NULL)
|
||||
{
|
||||
tablepath = get_tablepath (ibreq->ibr_name, &bptr);
|
||||
tableptr = tablepath;
|
||||
}
|
||||
if (tableptr == NULL)
|
||||
{
|
||||
NIS_RES_STATUS (res)
|
||||
= __follow_path (&tablepath, &tableptr, ibreq, &bptr);
|
||||
if (NIS_RES_STATUS (res) != NIS_SUCCESS)
|
||||
++done;
|
||||
break;
|
||||
}
|
||||
free (ibreq->ibr_name);
|
||||
ibreq->ibr_name = strsep (&tableptr, ":");
|
||||
if (ibreq->ibr_name == NULL || ibreq->ibr_name[0] == '\0')
|
||||
{
|
||||
ibreq->ibr_name = strdup ("");
|
||||
++done;
|
||||
}
|
||||
else
|
||||
ibreq->ibr_name = strdup (ibreq->ibr_name);
|
||||
if (ibreq->ibr_name == NULL)
|
||||
{
|
||||
NIS_RES_STATUS (res) = NIS_NOMEMORY;
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -524,7 +501,7 @@ nis_add_entry (const_nis_name name, const nis_object *obj2, unsigned int flags)
|
||||
return res;
|
||||
}
|
||||
|
||||
ib_request *ibreq = create_ib_request (name, flags);
|
||||
ib_request *ibreq = __create_ib_request (name, flags);
|
||||
if (ibreq == NULL)
|
||||
{
|
||||
NIS_RES_STATUS (res) = NIS_BADNAME;
|
||||
@ -587,7 +564,7 @@ nis_modify_entry (const_nis_name name, const nis_object *obj2,
|
||||
if (res == NULL)
|
||||
return NULL;
|
||||
|
||||
ibreq = create_ib_request (name, flags);
|
||||
ibreq = __create_ib_request (name, flags);
|
||||
if (ibreq == NULL)
|
||||
{
|
||||
NIS_RES_STATUS (res) = NIS_BADNAME;
|
||||
@ -646,7 +623,7 @@ nis_remove_entry (const_nis_name name, const nis_object *obj,
|
||||
return res;
|
||||
}
|
||||
|
||||
ibreq = create_ib_request (name, flags);
|
||||
ibreq = __create_ib_request (name, flags);
|
||||
if (ibreq == NULL)
|
||||
{
|
||||
NIS_RES_STATUS (res) = NIS_BADNAME;
|
||||
@ -693,7 +670,7 @@ nis_first_entry (const_nis_name name)
|
||||
return res;
|
||||
}
|
||||
|
||||
ibreq = create_ib_request (name, 0);
|
||||
ibreq = __create_ib_request (name, 0);
|
||||
if (ibreq == NULL)
|
||||
{
|
||||
NIS_RES_STATUS (res) = NIS_BADNAME;
|
||||
@ -730,7 +707,7 @@ nis_next_entry (const_nis_name name, const netobj *cookie)
|
||||
return res;
|
||||
}
|
||||
|
||||
ibreq = create_ib_request (name, 0);
|
||||
ibreq = __create_ib_request (name, 0);
|
||||
if (ibreq == NULL)
|
||||
{
|
||||
NIS_RES_STATUS (res) = NIS_BADNAME;
|
||||
|
@ -308,6 +308,7 @@ _xdr_nis_result (XDR *xdrs, nis_result *objp)
|
||||
}
|
||||
return res;
|
||||
}
|
||||
libnsl_hidden_def (_xdr_nis_result)
|
||||
|
||||
bool_t
|
||||
_xdr_ns_request (XDR *xdrs, ns_request *objp)
|
||||
@ -357,6 +358,7 @@ _xdr_ib_request (XDR *xdrs, ib_request *objp)
|
||||
}
|
||||
return res;
|
||||
}
|
||||
libnsl_hidden_def (_xdr_ib_request)
|
||||
|
||||
bool_t
|
||||
_xdr_ping_args (XDR *xdrs, ping_args *objp)
|
||||
|
@ -28,9 +28,7 @@ extern bool_t _xdr_nis_server (XDR *, nis_server*) attribute_hidden;
|
||||
extern bool_t _xdr_directory_obj (XDR *, directory_obj*) attribute_hidden;
|
||||
extern bool_t _xdr_nis_object (XDR *, nis_object*) attribute_hidden;
|
||||
extern bool_t _xdr_nis_error (XDR *, nis_error*) attribute_hidden;
|
||||
extern bool_t _xdr_nis_result (XDR *, nis_result*) attribute_hidden;
|
||||
extern bool_t _xdr_ns_request (XDR *, ns_request*) attribute_hidden;
|
||||
extern bool_t _xdr_ib_request (XDR *, ib_request*) attribute_hidden;
|
||||
extern bool_t _xdr_ping_args (XDR *, ping_args*) attribute_hidden;
|
||||
extern bool_t _xdr_cp_result (XDR *, cp_result*) attribute_hidden;
|
||||
extern bool_t _xdr_nis_tag (XDR *, nis_tag*) attribute_hidden;
|
||||
@ -38,4 +36,9 @@ extern bool_t _xdr_nis_taglist (XDR *, nis_taglist*) attribute_hidden;
|
||||
extern bool_t _xdr_fd_args (XDR *, fd_args*) attribute_hidden;
|
||||
extern bool_t _xdr_fd_result (XDR *, fd_result*) attribute_hidden;
|
||||
|
||||
extern bool_t _xdr_ib_request (XDR *, ib_request*);
|
||||
libnsl_hidden_proto (_xdr_ib_request)
|
||||
extern bool_t _xdr_nis_result (XDR *, nis_result*);
|
||||
libnsl_hidden_proto (_xdr_nis_result)
|
||||
|
||||
#endif
|
||||
|
@ -24,15 +24,12 @@
|
||||
#include <grp.h>
|
||||
#include <shadow.h>
|
||||
|
||||
extern int _nss_nisplus_parse_pwent (nis_result *result, size_t entry,
|
||||
struct passwd *pw, char *buffer,
|
||||
size_t buflen, int *errnop);
|
||||
extern int _nss_nisplus_parse_pwent_chk (nis_result *result, struct passwd *pw,
|
||||
char *buffer, size_t buflen,
|
||||
int *errnop);
|
||||
extern int _nss_nisplus_parse_grent (nis_result *result, u_long entry,
|
||||
struct group *gr, char *buffer,
|
||||
size_t buflen, int *errnop);
|
||||
extern int _nss_nisplus_parse_pwent (nis_result *result, struct passwd *pw,
|
||||
char *buffer, size_t buflen, int *errnop);
|
||||
|
||||
extern int _nss_nisplus_parse_grent (nis_result *result, struct group *gr,
|
||||
char *buffer, size_t buflen, int *errnop);
|
||||
|
||||
extern int _nss_nisplus_parse_spent (nis_result *result, struct spwd *sp,
|
||||
char *buffer, size_t buflen, int *errnop);
|
||||
|
||||
|
@ -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)
|
||||
{
|
||||
enum nss_status status;
|
||||
|
||||
if (result != NULL)
|
||||
{
|
||||
nis_freeresult (result);
|
||||
result = NULL;
|
||||
}
|
||||
next_entry = 0;
|
||||
static void
|
||||
internal_endgrent (void)
|
||||
{
|
||||
__nisbind_destroy (&bptr);
|
||||
memset (&bptr, '\0', sizeof (bptr));
|
||||
|
||||
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)
|
||||
status = _nss_create_tablename (errnop);
|
||||
|
||||
if (status == NSS_STATUS_SUCCESS)
|
||||
{
|
||||
int err;
|
||||
if (_nss_create_tablename (&err) != NSS_STATUS_SUCCESS)
|
||||
return NSS_STATUS_UNAVAIL;
|
||||
ibreq = __create_ib_request (tablename_val, 0);
|
||||
if (ibreq == NULL)
|
||||
{
|
||||
*errnop = errno;
|
||||
return NSS_STATUS_TRYAGAIN;
|
||||
}
|
||||
|
||||
result = nis_list (tablename_val, FOLLOW_LINKS | FOLLOW_PATH, NULL, NULL);
|
||||
if (result == NULL)
|
||||
nis_error retcode = __prepare_niscall (tablename_val, &dir, &bptr, 0);
|
||||
if (retcode != NIS_SUCCESS)
|
||||
{
|
||||
status = NSS_STATUS_TRYAGAIN;
|
||||
__set_errno (ENOMEM);
|
||||
}
|
||||
else
|
||||
{
|
||||
status = niserr2nss (result->status);
|
||||
if (status != NSS_STATUS_SUCCESS)
|
||||
{
|
||||
nis_freeresult (result);
|
||||
result = NULL;
|
||||
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))
|
||||
|
@ -31,9 +31,15 @@
|
||||
#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,
|
||||
_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)
|
||||
@ -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;
|
||||
|
@ -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)
|
||||
if (status == NSS_STATUS_SUCCESS)
|
||||
{
|
||||
ibreq = __create_ib_request (pwd_tablename_val, 0);
|
||||
if (ibreq == NULL)
|
||||
{
|
||||
*errnop = errno;
|
||||
status = NSS_STATUS_TRYAGAIN;
|
||||
return NSS_STATUS_TRYAGAIN;
|
||||
}
|
||||
else if (__builtin_expect ((status = niserr2nss (cached_results->status))
|
||||
!= NSS_STATUS_SUCCESS, 0))
|
||||
|
||||
nis_error retcode = __prepare_niscall (pwd_tablename_val, &dir,
|
||||
&bptr, 0);
|
||||
if (retcode != NIS_SUCCESS)
|
||||
{
|
||||
nis_freeresult (cached_results);
|
||||
cached_results = NULL;
|
||||
nis_free_request (ibreq);
|
||||
ibreq = NULL;
|
||||
status = niserr2nss (retcode);
|
||||
}
|
||||
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))
|
||||
{
|
||||
nis_freeresult (cached_results);
|
||||
cached_results = NULL;
|
||||
status = NSS_STATUS_NOTFOUND;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
__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)
|
||||
{
|
||||
handle_batch_read:
|
||||
/* See whether we reported the last problem. */
|
||||
if (cached_results_iter >= NIS_RES_NUMOBJ (cached_results))
|
||||
return NSS_STATUS_NOTFOUND;
|
||||
nis_error status;
|
||||
nis_result result;
|
||||
memset (&result, '\0', sizeof (result));
|
||||
|
||||
parse_res = _nss_nisplus_parse_pwent (cached_results,
|
||||
cached_results_iter, pw,
|
||||
buffer, buflen, errnop);
|
||||
if (cursor.n_bytes == NULL)
|
||||
{
|
||||
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);
|
||||
ibreq->ibr_cookie.n_bytes = cursor.n_bytes;
|
||||
ibreq->ibr_cookie.n_len = cursor.n_len;
|
||||
|
||||
if (status != NSS_STATUS_SUCCESS)
|
||||
return status;
|
||||
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;
|
||||
}
|
||||
|
||||
/* 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 != NIS_SUCCESS)
|
||||
return niserr2nss (status);
|
||||
|
||||
if (status == NSS_STATUS_SUCCESS && cached_results != NULL)
|
||||
goto handle_batch_read;
|
||||
}
|
||||
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);
|
||||
|
||||
saved_res = NULL;
|
||||
directory_obj *newdir = NULL;
|
||||
dir_binding newbptr;
|
||||
status = __prepare_niscall (ibreq->ibr_name, &newdir, &newbptr, 0);
|
||||
if (status != NIS_SUCCESS)
|
||||
return niserr2nss (status);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
nis_free_directory (dir);
|
||||
dir = newdir;
|
||||
__nisbind_destroy (&bptr);
|
||||
bptr = newbptr;
|
||||
|
||||
parse_res = _nss_nisplus_parse_pwent_chk (result, pw, buffer,
|
||||
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);
|
||||
|
||||
|
@ -176,7 +176,7 @@ xdrrec_create (XDR *xdrs, u_int sendsize,
|
||||
/*
|
||||
* now the rest ...
|
||||
*/
|
||||
/* We have to add the const since the `struct xdr_ops' in `struct XDR'
|
||||
/* We have to add the cast since the `struct xdr_ops' in `struct XDR'
|
||||
is not `const'. */
|
||||
xdrs->x_ops = (struct xdr_ops *) &xdrrec_ops;
|
||||
xdrs->x_private = (caddr_t) rstrm;
|
||||
|
Loading…
Reference in New Issue
Block a user