aboutsummaryrefslogtreecommitdiff
path: root/nis/nis_lookup.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2004-12-22 20:10:10 +0000
committerUlrich Drepper <drepper@redhat.com>2004-12-22 20:10:10 +0000
commita334319f6530564d22e775935d9c91663623a1b4 (patch)
treeb5877475619e4c938e98757d518bb1e9cbead751 /nis/nis_lookup.c
parent0ecb606cb6cf65de1d9fc8a919bceb4be476c602 (diff)
downloadglibc-a334319f6530564d22e775935d9c91663623a1b4.zip
glibc-a334319f6530564d22e775935d9c91663623a1b4.tar.gz
glibc-a334319f6530564d22e775935d9c91663623a1b4.tar.bz2
(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
Diffstat (limited to 'nis/nis_lookup.c')
-rw-r--r--nis/nis_lookup.c109
1 files changed, 57 insertions, 52 deletions
diff --git a/nis/nis_lookup.c b/nis/nis_lookup.c
index 9677b4d..0b97e67 100644
--- a/nis/nis_lookup.c
+++ b/nis/nis_lookup.c
@@ -1,5 +1,4 @@
-/* Copyright (C) 1997-1999, 2004, 2005, 2006, 2007
- Free Software Foundation, Inc.
+/* Copyright (C) 1997, 1998, 1999, 2004 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@uni-paderborn.de>, 1997.
@@ -22,8 +21,6 @@
#include <rpcsvc/nis.h>
#include "nis_xdr.h"
#include "nis_intern.h"
-#include <libnsl.h>
-
nis_result *
nis_lookup (const_nis_name name, const unsigned int flags)
@@ -64,16 +61,36 @@ nis_lookup (const_nis_name name, const unsigned int flags)
req.ns_object.ns_object_len = 0;
req.ns_object.ns_object_val = NULL;
- status = __prepare_niscall (req.ns_name, &dir, &bptr, flags);
- if (__builtin_expect (status != NIS_SUCCESS, 0))
+ status = __nisfind_server (req.ns_name, &dir);
+ if (status != NIS_SUCCESS)
{
NIS_RES_STATUS (res) = status;
- goto out;
+ return res;
+ }
+
+ status = __nisbind_create (&bptr, dir->do_servers.do_servers_val,
+ dir->do_servers.do_servers_len, flags);
+ if (status != NIS_SUCCESS)
+ {
+ NIS_RES_STATUS (res) = status;
+ nis_free_directory (dir);
+ return res;
+ }
+
+ while (__nisbind_connect (&bptr) != NIS_SUCCESS)
+ {
+ if (__nisbind_next (&bptr) != NIS_SUCCESS)
+ {
+ __nisbind_destroy (&bptr);
+ nis_free_directory (dir);
+ NIS_RES_STATUS (res) = NIS_NAMEUNREACHABLE;
+ return res;
+ }
}
do
{
- static const struct timeval RPCTIMEOUT = {10, 0};
+ static struct timeval RPCTIMEOUT = {10, 0};
enum clnt_stat result;
again:
@@ -90,9 +107,11 @@ nis_lookup (const_nis_name name, const unsigned int flags)
if (NIS_RES_STATUS (res) == NIS_SUCCESS)
{
- if (__type_of (NIS_RES_OBJECT (res)) == NIS_LINK_OBJ
- && (flags & FOLLOW_LINKS)) /* We are following links */
+ if (__type_of(NIS_RES_OBJECT (res)) == NIS_LINK_OBJ &&
+ flags & FOLLOW_LINKS) /* We are following links */
{
+ if (count_links)
+ free (req.ns_name);
/* if we hit the link limit, bail */
if (count_links > NIS_MAXLINKS)
{
@@ -101,68 +120,55 @@ nis_lookup (const_nis_name name, const unsigned int flags)
}
++count_links;
req.ns_name =
- strdupa (NIS_RES_OBJECT (res)->LI_data.li_name);
+ strdup (NIS_RES_OBJECT (res)->LI_data.li_name);
+ if (req.ns_name == NULL)
+ return NULL;
- /* 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. */
- xdr_free ((xdrproc_t) _xdr_nis_result, (char *) res);
- memset (res, '\0', sizeof (*res));
+ nis_freeresult (res);
+ res = calloc (1, sizeof (nis_result));
+ if (res == NULL)
+ {
+ __nisbind_destroy (&bptr);
+ return NULL;
+ }
link_first_try = 1; /* Try at first the old binding */
goto again;
}
}
else
- if (NIS_RES_STATUS (res) == NIS_SYSTEMERROR
- || NIS_RES_STATUS (res) == NIS_NOSUCHNAME
- || NIS_RES_STATUS (res) == NIS_NOT_ME)
+ if ((NIS_RES_STATUS (res) == NIS_SYSTEMERROR) ||
+ (NIS_RES_STATUS (res) == NIS_NOSUCHNAME) ||
+ (NIS_RES_STATUS (res) == NIS_NOT_ME))
{
if (link_first_try)
{
__nisbind_destroy (&bptr);
nis_free_directory (dir);
- /* Otherwise __nisfind_server will not do anything. */
- dir = NULL;
- if (__nisfind_server (req.ns_name, 1, &dir, &bptr,
- flags & ~MASTER_ONLY)
- != NIS_SUCCESS)
- goto out;
+ if (__nisfind_server (req.ns_name, &dir) != NIS_SUCCESS)
+ return res;
+
+ if (__nisbind_create (&bptr,
+ dir->do_servers.do_servers_val,
+ dir->do_servers.do_servers_len,
+ flags) != NIS_SUCCESS)
+ {
+ nis_free_directory (dir);
+ return res;
+ }
}
else
if (__nisbind_next (&bptr) != NIS_SUCCESS)
- {
- /* No more servers to search. Try parent. */
- const char *ndomain = __nis_domain_of (req.ns_name);
- req.ns_name = strdupa (ndomain);
- if (strcmp (req.ns_name, ".") == 0)
- {
- NIS_RES_STATUS (res) = NIS_NAMEUNREACHABLE;
- goto out;
- }
-
- __nisbind_destroy (&bptr);
- nis_free_directory (dir);
- dir = NULL;
- status = __prepare_niscall (req.ns_name, &dir,
- &bptr, flags);
- if (__builtin_expect (status != NIS_SUCCESS, 0))
- {
- NIS_RES_STATUS (res) = status;
- goto out;
- }
- goto again;
- }
+ break; /* No more servers to search */
while (__nisbind_connect (&bptr) != NIS_SUCCESS)
{
if (__nisbind_next (&bptr) != NIS_SUCCESS)
{
+ __nisbind_destroy (&bptr);
nis_free_directory (dir);
- goto out;
+ return res;
}
}
goto again;
@@ -179,7 +185,7 @@ nis_lookup (const_nis_name name, const unsigned int flags)
if (status != NIS_SUCCESS)
{
NIS_RES_STATUS (res) = status;
- goto out;
+ return res;
}
switch (NIS_RES_STATUS (res))
@@ -211,7 +217,6 @@ nis_lookup (const_nis_name name, const unsigned int flags)
}
}
- out:
if (names != namebuf)
nis_freenames (names);