summaryrefslogtreecommitdiff
path: root/nis
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2005-12-19 12:11:38 +0000
committerJakub Jelinek <jakub@redhat.com>2005-12-19 12:11:38 +0000
commit2c6cfe6853a30deb4af842aacc924fa298d0521a (patch)
tree7fcc409e499bb8e3d96522f7fc2393fc10e53db2 /nis
parent3ccb96cd41b38d0159bdf8aad229c3599864c65d (diff)
Updated to fedora-glibc-20051219T1003cvs/fedora-glibc-2_3_90-19
Diffstat (limited to 'nis')
-rw-r--r--nis/nis_call.c32
-rw-r--r--nis/nis_error.c15
-rw-r--r--nis/nis_lookup.c19
-rw-r--r--nis/nis_table.c143
-rw-r--r--nis/nss_nisplus/nisplus-alias.c225
-rw-r--r--nis/nss_nisplus/nisplus-ethers.c210
-rw-r--r--nis/nss_nisplus/nisplus-grp.c194
-rw-r--r--nis/nss_nisplus/nisplus-hosts.c266
-rw-r--r--nis/nss_nisplus/nisplus-netgrp.c7
-rw-r--r--nis/nss_nisplus/nisplus-network.c243
-rw-r--r--nis/nss_nisplus/nisplus-proto.c245
-rw-r--r--nis/nss_nisplus/nisplus-publickey.c21
-rw-r--r--nis/nss_nisplus/nisplus-pwd.c239
-rw-r--r--nis/nss_nisplus/nisplus-rpc.c250
-rw-r--r--nis/nss_nisplus/nisplus-service.c259
-rw-r--r--nis/nss_nisplus/nisplus-spwd.c140
-rw-r--r--nis/ypclnt.c281
17 files changed, 1486 insertions, 1303 deletions
diff --git a/nis/nis_call.c b/nis/nis_call.c
index 14041a160c..5b432b7981 100644
--- a/nis/nis_call.c
+++ b/nis/nis_call.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997, 1998, 2001, 2004 Free Software Foundation, Inc.
+/* Copyright (C) 1997, 1998, 2001, 2004, 2005 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
@@ -40,25 +40,16 @@ extern u_short __pmap_getnisport (struct sockaddr_in *address, u_long program,
unsigned long
inetstr2int (const char *str)
{
- char buffer[strlen (str) + 3];
- size_t buflen;
- size_t i, j;
-
- buflen = stpcpy (buffer, str) - buffer;
-
- j = 0;
- for (i = 0; i < buflen; ++i)
- if (buffer[i] == '.')
+ size_t j = 0;
+ for (size_t i = 0; str[i] != '\0'; ++i)
+ if (str[i] == '.' && ++j == 4)
{
- ++j;
- if (j == 4)
- {
- buffer[i] = '\0';
- break;
- }
+ char buffer[i + 1];
+ buffer[i] = '\0';
+ return inet_addr (memcpy (buffer, str, i));
}
- return inet_addr (buffer);
+ return inet_addr (str);
}
void
@@ -179,7 +170,6 @@ __nisbind_connect (dir_binding *dbp)
}
else
dbp->clnt->cl_auth = authunix_create_default ();
- dbp->use_auth = TRUE;
}
return NIS_SUCCESS;
@@ -215,10 +205,7 @@ __nisbind_create (dir_binding *dbp, const nis_server *serv_val,
dbp->class = -1;
if (__nis_findfastest (dbp) < 1)
- {
- __nisbind_destroy (dbp);
- return NIS_NAMEUNREACHABLE;
- }
+ return NIS_NAMEUNREACHABLE;
return NIS_SUCCESS;
}
@@ -585,7 +572,6 @@ __do_niscall (const_nis_name name, u_long prog, xdrproc_t xargs,
if (__nisbind_next (&bptr) != NIS_SUCCESS)
{
nis_free_directory (dir);
- __nisbind_destroy (&bptr);
return NIS_NAMEUNREACHABLE;
}
}
diff --git a/nis/nis_error.c b/nis/nis_error.c
index 147f88ce15..7db885ef93 100644
--- a/nis/nis_error.c
+++ b/nis/nis_error.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 1997, 1998, 1999, 2004 Free Software Foundation, Inc.
+/* Copyright (c) 1997, 1998, 1999, 2004, 2005 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
@@ -102,26 +102,21 @@ char *
nis_sperror_r (const nis_error status, const char *label,
char *buffer, size_t buflen)
{
- const char *cptr;
-
- cptr = nis_sperrno (status);
-
- if ((strlen (cptr) + strlen (label) + 3) > buflen)
+ if (snprintf (buffer, buflen, "%s: %s", label, nis_sperrno (status))
+ >= buflen)
{
errno = ERANGE;
return NULL;
}
- sprintf (buffer, "%s: %s", label, cptr);
-
- return buffer;
+ return buffer;
}
libnsl_hidden_def (nis_sperror_r)
char *
nis_sperror (const nis_error status, const char *label)
{
- static char buffer[NIS_MAXNAMELEN +1];
+ static char buffer[NIS_MAXNAMELEN + 1];
return nis_sperror_r (status, label, buffer, sizeof (buffer));
}
diff --git a/nis/nis_lookup.c b/nis/nis_lookup.c
index 0b97e67a61..4cb34dd1a8 100644
--- a/nis/nis_lookup.c
+++ b/nis/nis_lookup.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997, 1998, 1999, 2004 Free Software Foundation, Inc.
+/* Copyright (C) 1997, 1998, 1999, 2004, 2005 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@uni-paderborn.de>, 1997.
@@ -81,7 +81,6 @@ nis_lookup (const_nis_name name, const unsigned int flags)
{
if (__nisbind_next (&bptr) != NIS_SUCCESS)
{
- __nisbind_destroy (&bptr);
nis_free_directory (dir);
NIS_RES_STATUS (res) = NIS_NAMEUNREACHABLE;
return res;
@@ -90,7 +89,7 @@ nis_lookup (const_nis_name name, const unsigned int flags)
do
{
- static struct timeval RPCTIMEOUT = {10, 0};
+ static const struct timeval RPCTIMEOUT = {10, 0};
enum clnt_stat result;
again:
@@ -107,8 +106,8 @@ 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);
@@ -137,16 +136,17 @@ nis_lookup (const_nis_name name, const unsigned int flags)
}
}
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);
- if (__nisfind_server (req.ns_name, &dir) != NIS_SUCCESS)
+ if (__nisfind_server (req.ns_name, &dir)
+ != NIS_SUCCESS)
return res;
if (__nisbind_create (&bptr,
@@ -166,7 +166,6 @@ nis_lookup (const_nis_name name, const unsigned int flags)
{
if (__nisbind_next (&bptr) != NIS_SUCCESS)
{
- __nisbind_destroy (&bptr);
nis_free_directory (dir);
return res;
}
diff --git a/nis/nis_table.c b/nis/nis_table.c
index 2531a3fbc5..2ef28ac59b 100644
--- a/nis/nis_table.c
+++ b/nis/nis_table.c
@@ -27,11 +27,9 @@
static struct ib_request *
__create_ib_request (const_nis_name name, unsigned int flags)
{
- struct ib_request *ibreq = calloc (1, sizeof (ib_request));
- char buf[strlen (name) + 1];
+ struct ib_request *ibreq = calloc (1, sizeof (struct ib_request));
nis_attr *search_val = NULL;
size_t search_len = 0;
- char *cptr;
size_t size = 0;
if (ibreq == NULL)
@@ -39,7 +37,7 @@ __create_ib_request (const_nis_name name, unsigned int flags)
ibreq->ibr_flags = flags;
- cptr = strcpy (buf, name);
+ char *cptr = strdupa (name);
/* Not of "[key=value,key=value,...],foo.." format? */
if (cptr[0] != '[')
@@ -49,8 +47,8 @@ __create_ib_request (const_nis_name name, unsigned int flags)
ibreq->ibr_name = strchr (cptr, ']');
if (ibreq->ibr_name == NULL || ibreq->ibr_name[1] != ',')
{
- ibreq->ibr_name = NULL; /* Or the xdr_* functions will dump */
- nis_free_request (ibreq);
+ /* The object has not really been built yet so we use free. */
+ free (ibreq);
return NULL;
}
@@ -120,17 +118,16 @@ __create_ib_request (const_nis_name name, unsigned int flags)
return ibreq;
}
-static struct timeval RPCTIMEOUT = {10, 0};
+static const struct timeval RPCTIMEOUT = {10, 0};
static char *
__get_tablepath (char *name, dir_binding *bptr)
{
enum clnt_stat result;
- nis_result *res = calloc (1, sizeof (nis_result));
+ nis_result res;
struct ns_request req;
- if (res == NULL)
- return NULL;
+ memset (&res, '\0', sizeof (res));
req.ns_name = name;
req.ns_object.ns_object_len = 0;
@@ -138,20 +135,16 @@ __get_tablepath (char *name, dir_binding *bptr)
result = clnt_call (bptr->clnt, NIS_LOOKUP, (xdrproc_t) _xdr_ns_request,
(caddr_t) &req, (xdrproc_t) _xdr_nis_result,
- (caddr_t) res, RPCTIMEOUT);
+ (caddr_t) &res, RPCTIMEOUT);
- if (result == RPC_SUCCESS && NIS_RES_STATUS (res) == NIS_SUCCESS &&
- __type_of (NIS_RES_OBJECT (res)) == NIS_TABLE_OBJ)
- {
- char *cptr = strdup (NIS_RES_OBJECT (res)->TA_data.ta_path);
- nis_freeresult (res);
- return cptr;
- }
+ const char *cptr;
+ if (result == RPC_SUCCESS && NIS_RES_STATUS (&res) == NIS_SUCCESS
+ && __type_of (NIS_RES_OBJECT (&res)) == NIS_TABLE_OBJ)
+ cptr = NIS_RES_OBJECT (&res)->TA_data.ta_path;
else
- {
- nis_freeresult (res);
- return strdup ("");
- }
+ cptr = "";
+
+ return strdup (cptr);
}
nis_result *
@@ -171,8 +164,8 @@ nis_list (const_nis_name name, unsigned int flags,
nis_name namebuf[2] = {NULL, NULL};
int name_nr = 0;
nis_cb *cb = NULL;
- char *tableptr, *tablepath = NULL;
- int have_tablepath = 0;
+ char *tableptr;
+ char *tablepath = NULL;
int first_try = 0; /* Do we try the old binding at first ? */
if (res == NULL)
@@ -205,6 +198,7 @@ nis_list (const_nis_name name, unsigned int flags,
ibreq->ibr_name = strdup (names[name_nr]);
if (ibreq->ibr_name == NULL)
{
+ nis_freenames (names);
nis_free_request (ibreq);
NIS_RES_STATUS (res) = NIS_NOMEMORY;
return res;
@@ -227,30 +221,24 @@ nis_list (const_nis_name name, unsigned int flags,
status = __nisfind_server (ibreq->ibr_name, &dir);
if (status != NIS_SUCCESS)
- {
- nis_free_request (ibreq);
+ {
NIS_RES_STATUS (res) = status;
- return res;
- }
+ goto fail3;
+ }
status = __nisbind_create (&bptr, dir->do_servers.do_servers_val,
- dir->do_servers.do_servers_len, flags);
+ dir->do_servers.do_servers_len, flags);
if (status != NIS_SUCCESS)
{
- nis_free_request (ibreq);
NIS_RES_STATUS (res) = status;
- nis_free_directory (dir);
- return res;
+ goto fail2;
}
while (__nisbind_connect (&bptr) != NIS_SUCCESS)
if (__nisbind_next (&bptr) != NIS_SUCCESS)
{
- __nisbind_destroy (&bptr);
- nis_free_directory (dir);
- nis_free_request (ibreq);
NIS_RES_STATUS (res) = NIS_NAMEUNREACHABLE;
- return res;
+ goto fail;
}
if (callback != NULL)
@@ -274,8 +262,8 @@ nis_list (const_nis_name name, unsigned int flags,
case NIS_PARTIAL:
case NIS_SUCCESS:
case NIS_S_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. */
{
free (ibreq->ibr_name);
ibreq->ibr_name = NULL;
@@ -291,8 +279,22 @@ nis_list (const_nis_name name, unsigned int flags,
strdup (NIS_RES_OBJECT (res)->LI_data.li_name);
if (ibreq->ibr_name == NULL)
{
- nis_free_request (ibreq);
NIS_RES_STATUS (res) = NIS_NOMEMORY;
+ fail:
+ __nisbind_destroy (&bptr);
+ fail2:
+ nis_free_directory (dir);
+ fail3:
+ free (tablepath);
+ if (cb)
+ {
+ __nis_destroy_callback (cb);
+ ibreq->ibr_cbhost.ibr_cbhost_len = 0;
+ ibreq->ibr_cbhost.ibr_cbhost_val = NULL;
+ }
+ if (names != namebuf)
+ nis_freenames (names);
+ nis_free_request (ibreq);
return res;
}
if (NIS_RES_OBJECT (res)->LI_data.li_attrs.li_attrs_len)
@@ -303,27 +305,30 @@ nis_list (const_nis_name name, unsigned int flags,
ibreq->ibr_srch.ibr_srch_val =
NIS_RES_OBJECT (res)->LI_data.li_attrs.li_attrs_val;
}
+ /* 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);
+ memset (res, '\0', sizeof (*res));
+#else
nis_freeresult (res);
res = calloc (1, sizeof (nis_result));
if (res == NULL)
- {
- if (have_tablepath)
- free (tablepath);
- __nisbind_destroy (&bptr);
- nis_free_directory (dir);
- return 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)
+ else if ((flags & FOLLOW_PATH)
+ && NIS_RES_STATUS (res) == NIS_PARTIAL)
{
- if (!have_tablepath)
+ if (tablepath == NULL)
{
tablepath = __get_tablepath (ibreq->ibr_name, &bptr);
tableptr = tablepath;
- have_tablepath = 1;
}
if (tableptr == NULL)
{
@@ -337,27 +342,37 @@ nis_list (const_nis_name name, unsigned int flags,
ibreq->ibr_name = strdup ("");
if (ibreq->ibr_name == NULL)
{
- nis_free_request (ibreq);
NIS_RES_STATUS (res) = NIS_NOMEMORY;
- return res;
+ goto fail;
}
++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);
+ 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);
- nis_free_request (ibreq);
- if (have_tablepath)
- free (tablepath);
- __nisbind_destroy (&bptr);
- nis_free_directory (dir);
- return NULL;
+ res = NULL;
+ goto fail;
}
+#endif
first_try = 1;
goto again;
}
@@ -375,11 +390,10 @@ nis_list (const_nis_name name, unsigned int flags,
++done;
else
{
- if (!have_tablepath)
+ if (tablepath == NULL)
{
tablepath = __get_tablepath (ibreq->ibr_name, &bptr);
tableptr = tablepath;
- have_tablepath = 1;
}
if (tableptr == NULL)
{
@@ -397,9 +411,8 @@ nis_list (const_nis_name name, unsigned int flags,
ibreq->ibr_name = strdup (ibreq->ibr_name);
if (ibreq->ibr_name == NULL)
{
- nis_free_request (ibreq);
NIS_RES_STATUS (res) = NIS_NOMEMORY;
- return res;
+ goto fail;
}
}
}
@@ -448,9 +461,8 @@ nis_list (const_nis_name name, unsigned int flags,
ibreq->ibr_name = strdup (names[name_nr]);
if (ibreq->ibr_name == NULL)
{
- nis_free_request (ibreq);
NIS_RES_STATUS (res) = NIS_NOMEMORY;
- return res;
+ goto fail;
}
first_try = 1; /* Try old binding at first */
goto again;
@@ -464,12 +476,15 @@ nis_list (const_nis_name name, unsigned int flags,
__nis_destroy_callback (cb);
ibreq->ibr_cbhost.ibr_cbhost_len = 0;
ibreq->ibr_cbhost.ibr_cbhost_val = NULL;
+ cb = NULL;
}
__nisbind_destroy (&bptr);
nis_free_directory (dir);
}
+ free (tablepath);
+
if (names != namebuf)
nis_freenames (names);
diff --git a/nis/nss_nisplus/nisplus-alias.c b/nis/nss_nisplus/nisplus-alias.c
index 152e5fc3fc..6aa93ab3bc 100644
--- a/nis/nss_nisplus/nisplus-alias.c
+++ b/nis/nss_nisplus/nisplus-alias.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997, 1998, 2001, 2002, 2003 Free Software Foundation, Inc.
+/* Copyright (C) 1997,1998,2001,2002,2003,2005 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
@@ -17,6 +17,7 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
+#include <atomic.h>
#include <nss.h>
#include <errno.h>
#include <ctype.h>
@@ -32,7 +33,7 @@ __libc_lock_define_initialized (static, lock)
static nis_result *result;
static u_long next_entry;
static nis_name tablename_val;
-static u_long tablename_len;
+static size_t tablename_len;
#define NISENTRYVAL(idx,col,res) \
((res)->objects.objects_val[(idx)].EN_data.en_cols.en_cols_val[(col)].ec_value.ec_value_val)
@@ -45,19 +46,26 @@ _nss_create_tablename (int *errnop)
{
if (tablename_val == NULL)
{
- char buf [40 + strlen (nis_local_directory ())];
- char *p;
+ const char *local_dir = nis_local_directory ();
+ size_t local_dir_len = strlen (local_dir);
+ static const char prefix[] = "mail_aliases.org_dir.";
- p = __stpcpy (buf, "mail_aliases.org_dir.");
- p = __stpcpy (p, nis_local_directory ());
- tablename_val = __strdup (buf);
+ char *p = malloc (sizeof (prefix) + local_dir_len);
if (tablename_val == NULL)
{
*errnop = errno;
return NSS_STATUS_TRYAGAIN;
}
- tablename_len = strlen (tablename_val);
+
+ memcpy (__stpcpy (p, prefix), local_dir, local_dir_len + 1);
+
+ tablename_len = sizeof (prefix) - 1 + local_dir_len;
+
+ atomic_write_barrier ();
+
+ tablename_val = p;
}
+
return NSS_STATUS_SUCCESS;
}
@@ -75,81 +83,73 @@ _nss_nisplus_parse_aliasent (nis_result *result, unsigned long entry,
"mail_aliases") != 0
|| result->objects.objects_val[entry].EN_data.en_cols.en_cols_len < 2)
return 0;
- else
+
+ char *first_unused = buffer + NISENTRYLEN (0, 1, result) + 1;
+ size_t room_left = (buflen - (buflen % __alignof__ (char *))
+ - NISENTRYLEN (0, 1, result) - 2);
+
+ if (NISENTRYLEN (entry, 1, result) >= buflen)
{
- char *first_unused = buffer + NISENTRYLEN (0, 1, result) + 1;
- size_t room_left =
- buflen - (buflen % __alignof__ (char *)) -
- NISENTRYLEN (0, 1, result) - 2;
- char *line;
- char *cp;
-
- if (NISENTRYLEN (entry, 1, result) >= buflen)
- {
- /* The line is too long for our buffer. */
- no_more_room:
- *errnop = ERANGE;
- return -1;
- }
- else
- {
- cp = __stpncpy (buffer, NISENTRYVAL (entry, 1, result),
- NISENTRYLEN (entry, 1, result));
- *cp = '\0';
- }
+ /* The line is too long for our buffer. */
+ no_more_room:
+ *errnop = ERANGE;
+ return -1;
+ }
+
+ char *cp = __stpncpy (buffer, NISENTRYVAL (entry, 1, result),
+ NISENTRYLEN (entry, 1, result));
+ *cp = '\0';
+
+ if (NISENTRYLEN(entry, 0, result) >= room_left)
+ goto no_more_room;
+
+ alias->alias_local = 0;
+ alias->alias_members_len = 0;
+ *first_unused = '\0';
+ ++first_unused;
+ cp = __stpncpy (first_unused, NISENTRYVAL (entry, 0, result),
+ NISENTRYLEN (entry, 0, result));
+ *cp = '\0';
+ alias->alias_name = first_unused;
+
+ /* Terminate the line for any case. */
+ cp = strpbrk (alias->alias_name, "#\n");
+ if (cp != NULL)
+ *cp = '\0';
+
+ first_unused += strlen (alias->alias_name) +1;
+ /* Adjust the pointer so it is aligned for
+ storing pointers. */
+ first_unused += __alignof__ (char *) - 1;
+ first_unused -= ((first_unused - (char *) 0) % __alignof__ (char *));
+ alias->alias_members = (char **) first_unused;
+
+ char *line = buffer;
+ while (*line != '\0')
+ {
+ /* Skip leading blanks. */
+ while (isspace (*line))
+ ++line;
+
+ if (*line == '\0')
+ break;
- if (NISENTRYLEN(entry, 0, result) >= room_left)
+ if (room_left < sizeof (char *))
goto no_more_room;
+ room_left -= sizeof (char *);
+ alias->alias_members[alias->alias_members_len] = line;
+
+ while (*line != '\0' && *line != ',')
+ ++line;
- alias->alias_local = 0;
- alias->alias_members_len = 0;
- *first_unused = '\0';
- ++first_unused;
- cp = __stpncpy (first_unused, NISENTRYVAL (entry, 0, result),
- NISENTRYLEN (entry, 0, result));
- *cp = '\0';
- alias->alias_name = first_unused;
-
- /* Terminate the line for any case. */
- cp = strpbrk (alias->alias_name, "#\n");
- if (cp != NULL)
- *cp = '\0';
-
- first_unused += strlen (alias->alias_name) +1;
- /* Adjust the pointer so it is aligned for
- storing pointers. */
- first_unused += __alignof__ (char *) - 1;
- first_unused -= ((first_unused - (char *) 0) % __alignof__ (char *));
- alias->alias_members = (char **) first_unused;
-
- line = buffer;
-
- while (*line != '\0')
+ if (line != alias->alias_members[alias->alias_members_len])
{
- /* Skip leading blanks. */
- while (isspace (*line))
- ++line;
-
- if (*line == '\0')
- break;
-
- if (room_left < sizeof (char *))
- goto no_more_room;
- room_left -= sizeof (char *);
- alias->alias_members[alias->alias_members_len] = line;
-
- while (*line != '\0' && *line != ',')
- ++line;
-
- if (line != alias->alias_members[alias->alias_members_len])
- {
- *line++ = '\0';
- alias->alias_members_len++;
- }
+ *line++ = '\0';
+ alias->alias_members_len++;
}
-
- return alias->alias_members_len == 0 ? 0 : 1;
}
+
+ return alias->alias_members_len == 0 ? 0 : 1;
}
static enum nss_status
@@ -158,9 +158,11 @@ internal_setaliasent (void)
enum nss_status status;
int err;
- if (result)
- nis_freeresult (result);
- result = NULL;
+ if (result != NULL)
+ {
+ nis_freeresult (result);
+ result = NULL;
+ }
if (_nss_create_tablename (&err) != NSS_STATUS_SUCCESS)
return NSS_STATUS_UNAVAIL;
@@ -203,9 +205,11 @@ _nss_nisplus_endaliasent (void)
{
__libc_lock_lock (lock);
- if (result)
- nis_freeresult (result);
- result = NULL;
+ if (result != NULL)
+ {
+ nis_freeresult (result);
+ result = NULL;
+ }
next_entry = 0;
__libc_lock_unlock (lock);
@@ -240,7 +244,8 @@ internal_nisplus_getaliasent_r (struct aliasent *alias,
return NSS_STATUS_TRYAGAIN;
++next_entry;
- } while (!parse_res);
+ }
+ while (!parse_res);
return NSS_STATUS_SUCCESS;
}
@@ -268,7 +273,12 @@ _nss_nisplus_getaliasbyname_r (const char *name, struct aliasent *alias,
if (tablename_val == NULL)
{
+ __libc_lock_lock (lock);
+
enum nss_status status = _nss_create_tablename (errnop);
+
+ __libc_lock_unlock (lock);
+
if (status != NSS_STATUS_SUCCESS)
return status;
}
@@ -278,35 +288,34 @@ _nss_nisplus_getaliasbyname_r (const char *name, struct aliasent *alias,
*errnop = EINVAL;
return NSS_STATUS_UNAVAIL;
}
- else
- {
- nis_result *result;
- char buf[strlen (name) + 30 + tablename_len];
- int olderr = errno;
- sprintf (buf, "[name=%s],%s", name, tablename_val);
+ char buf[strlen (name) + 9 + tablename_len];
+ int olderr = errno;
- result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL);
+ snprintf (buf, sizeof (buf), "[name=%s],%s", name, tablename_val);
- if (result == NULL)
- {
- *errnop = ENOMEM;
- return NSS_STATUS_TRYAGAIN;
- }
- if (niserr2nss (result->status) != NSS_STATUS_SUCCESS)
- return niserr2nss (result->status);
+ nis_result *result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL);
- parse_res = _nss_nisplus_parse_aliasent (result, 0, alias,
- buffer, buflen, errnop);
- if (parse_res < 1)
- {
- __set_errno (olderr);
+ if (result == NULL)
+ {
+ *errnop = ENOMEM;
+ return NSS_STATUS_TRYAGAIN;
+ }
- if (parse_res == -1)
- return NSS_STATUS_TRYAGAIN;
- else
- return NSS_STATUS_NOTFOUND;
- }
- return NSS_STATUS_SUCCESS;
+ if (__builtin_expect (niserr2nss (result->status) != NSS_STATUS_SUCCESS, 0))
+ return niserr2nss (result->status);
+
+ parse_res = _nss_nisplus_parse_aliasent (result, 0, alias,
+ buffer, buflen, errnop);
+ if (__builtin_expect (parse_res < 1, 0))
+ {
+ __set_errno (olderr);
+
+ if (parse_res == -1)
+ return NSS_STATUS_TRYAGAIN;
+ else
+ return NSS_STATUS_NOTFOUND;
}
+
+ return NSS_STATUS_SUCCESS;
}
diff --git a/nis/nss_nisplus/nisplus-ethers.c b/nis/nss_nisplus/nisplus-ethers.c
index 028309c841..fcc550e743 100644
--- a/nis/nss_nisplus/nisplus-ethers.c
+++ b/nis/nss_nisplus/nisplus-ethers.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997,1998,2000,2001,2002,2003 Free Software Foundation, Inc.
+/* Copyright (C) 1997,1998,2000-2003,2005 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@suse.de>, 1997.
@@ -17,15 +17,17 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
-#include <nss.h>
-#include <errno.h>
+#include <atomic.h>
#include <ctype.h>
-#include <string.h>
-#include <bits/libc-lock.h>
+#include <errno.h>
+#include <inttypes.h>
#include <netdb.h>
+#include <nss.h>
+#include <string.h>
#include <netinet/ether.h>
-#include <rpcsvc/nis.h>
#include <netinet/if_ether.h>
+#include <rpcsvc/nis.h>
+#include <bits/libc-lock.h>
#include "nss-nisplus.h"
@@ -70,7 +72,14 @@ _nss_nisplus_parse_etherent (nis_result *result, struct etherent *ether,
room_left -= (NISENTRYLEN (0, 0, result) +1);
ether->e_name = p;
- ether->e_addr = *ether_aton (NISENTRYVAL (0, 1, result));
+ struct ether_addr *ea = ether_aton (NISENTRYVAL (0, 1, result));
+ if (ea == NULL)
+ {
+ *errnop = EINVAL;
+ return -2;
+ }
+
+ ether->e_addr = *ea;
return 1;
}
@@ -80,18 +89,24 @@ _nss_create_tablename (int *errnop)
{
if (tablename_val == NULL)
{
- char buf [40 + strlen (nis_local_directory ())];
- char *p;
+ const char *local_dir = nis_local_directory ();
+ size_t local_dir_len = strlen (local_dir);
+ static const char prefix[] = "ethers.org_dir.";
- p = __stpcpy (buf, "ethers.org_dir.");
- p = __stpcpy (p, nis_local_directory ());
- tablename_val = __strdup (buf);
+ char *p = malloc (sizeof (prefix) + local_dir_len);
if (tablename_val == NULL)
{
*errnop = errno;
return NSS_STATUS_TRYAGAIN;
}
- tablename_len = strlen (tablename_val);
+
+ memcpy (__stpcpy (p, prefix), local_dir, local_dir_len + 1);
+
+ tablename_len = sizeof (prefix) - 1 + local_dir_len;
+
+ atomic_write_barrier ();
+
+ tablename_val = p;
}
return NSS_STATUS_SUCCESS;
}
@@ -107,9 +122,11 @@ _nss_nisplus_setetherent (int stayopen)
__libc_lock_lock (lock);
- if (result)
- nis_freeresult (result);
- result = NULL;
+ if (result != NULL)
+ {
+ nis_freeresult (result);
+ result = NULL;
+ }
if (_nss_create_tablename (&err) != NSS_STATUS_SUCCESS)
status = NSS_STATUS_UNAVAIL;
@@ -124,9 +141,11 @@ _nss_nisplus_endetherent (void)
{
__libc_lock_lock (lock);
- if (result)
- nis_freeresult (result);
- result = NULL;
+ if (result != NULL)
+ {
+ nis_freeresult (result);
+ result = NULL;
+ }
__libc_lock_unlock (lock);
@@ -137,8 +156,6 @@ static enum nss_status
internal_nisplus_getetherent_r (struct etherent *ether, char *buffer,
size_t buflen, int *errnop)
{
- int parse_res;
-
if (tablename_val == NULL)
{
enum nss_status status = _nss_create_tablename (errnop);
@@ -148,6 +165,7 @@ internal_nisplus_getetherent_r (struct etherent *ether, char *buffer,
}
/* Get the next entry until we found a correct one. */
+ int parse_res;
do
{
nis_result *saved_result;
@@ -161,11 +179,8 @@ internal_nisplus_getetherent_r (struct etherent *ether, char *buffer,
}
else
{
- nis_result *res2;
-
- res2 = nis_next_entry(tablename_val, &result->cookie);
saved_result = result;
- result = res2;
+ result = nis_next_entry (tablename_val, &result->cookie);
if (niserr2nss (result->status) != NSS_STATUS_SUCCESS)
{
nis_freeresult (saved_result);
@@ -178,17 +193,15 @@ internal_nisplus_getetherent_r (struct etherent *ether, char *buffer,
if (parse_res == -1)
{
nis_freeresult (result);
- *errnop = ERANGE;
result = saved_result;
return NSS_STATUS_TRYAGAIN;
}
- else
- {
- if (saved_result != NULL)
- nis_freeresult (saved_result);
- }
- } while (!parse_res);
+ if (saved_result != NULL)
+ nis_freeresult (saved_result);
+
+ }
+ while (!parse_res);
return NSS_STATUS_SUCCESS;
}
@@ -212,8 +225,6 @@ enum nss_status
_nss_nisplus_gethostton_r (const char *name, struct etherent *eth,
char *buffer, size_t buflen, int *errnop)
{
- int parse_res;
-
if (tablename_val == NULL)
{
enum nss_status status = _nss_create_tablename (errnop);
@@ -227,56 +238,57 @@ _nss_nisplus_gethostton_r (const char *name, struct etherent *eth,
*errnop = EINVAL;
return NSS_STATUS_UNAVAIL;
}
- else
- {
- nis_result *result;
- char buf[strlen (name) + 40 + tablename_len];
- int olderr = errno;
- sprintf (buf, "[name=%s],%s", name, tablename_val);
+ char buf[strlen (name) + 9 + tablename_len];
+ int olderr = errno;
- result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL);
+ snprintf (buf, sizeof (buf), "[name=%s],%s", name, tablename_val);
- if (result == NULL)
- {
- *errnop = ENOMEM;
- return NSS_STATUS_TRYAGAIN;
- }
- if (niserr2nss (result->status) != NSS_STATUS_SUCCESS)
- {
- enum nss_status status = niserr2nss (result->status);
- nis_freeresult (result);
- return status;
- }
+ nis_result *result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL);
- parse_res = _nss_nisplus_parse_etherent (result, eth, buffer,
+ if (result == NULL)
+ {
+ *errnop = ENOMEM;
+ return NSS_STATUS_TRYAGAIN;
+ }
+
+ if (__builtin_expect (niserr2nss (result->status) != NSS_STATUS_SUCCESS, 0))
+ {
+ enum nss_status status = niserr2nss (result->status);
+ nis_freeresult (result);
+ return status;
+ }
+
+ int parse_res = _nss_nisplus_parse_etherent (result, eth, buffer,
buflen, errnop);
- if (parse_res < 1)
- {
- __set_errno (olderr);
+ if (__builtin_expect (parse_res < 1, 0))
+ {
+ __set_errno (olderr);
- if (parse_res == -1)
- {
- nis_freeresult (result);
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
- }
- else
- return NSS_STATUS_NOTFOUND;
+ if (parse_res == -1)
+ {
+ nis_freeresult (result);
+ return NSS_STATUS_TRYAGAIN;
}
- return NSS_STATUS_SUCCESS;
+ else
+ return NSS_STATUS_NOTFOUND;
}
+
+ return NSS_STATUS_SUCCESS;
}
enum nss_status
-_nss_nisplus_getntohost_r (const struct ether_addr *addr,
- struct etherent *eth,
+_nss_nisplus_getntohost_r (const struct ether_addr *addr, struct etherent *eth,
char *buffer, size_t buflen, int *errnop)
{
if (tablename_val == NULL)
{
+ __libc_lock_lock (lock);
+
enum nss_status status = _nss_create_tablename (errnop);
+ __libc_lock_unlock (lock);
+
if (status != NSS_STATUS_SUCCESS)
return status;
}
@@ -286,44 +298,44 @@ _nss_nisplus_getntohost_r (const struct ether_addr *addr,
*errnop = EINVAL;
return NSS_STATUS_UNAVAIL;
}
- else
- {
- int parse_res;
- nis_result *result;
- char buf[255 + tablename_len];
- sprintf (buf, "[addr=%x:%x:%x:%x:%x:%x],ethers.org_dir",
- addr->ether_addr_octet[0], addr->ether_addr_octet[1],
- addr->ether_addr_octet[2], addr->ether_addr_octet[3],
- addr->ether_addr_octet[4], addr->ether_addr_octet[5]);
+ char buf[26 + tablename_len];
- result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL);
+ snprintf (buf, sizeof (buf),
+ "[addr=%" PRIx8 ":%" PRIx8 ":%" PRIx8 ":%" PRIx8 ":%" PRIx8
+ ":%" PRIx8 "],%s",
+ addr->ether_addr_octet[0], addr->ether_addr_octet[1],
+ addr->ether_addr_octet[2], addr->ether_addr_octet[3],
+ addr->ether_addr_octet[4], addr->ether_addr_octet[5],
+ tablename_val);
- if (result == NULL)
- {
- *errnop = ENOMEM;
- return NSS_STATUS_TRYAGAIN;
- }
- if (niserr2nss (result->status) != NSS_STATUS_SUCCESS)
- {
- enum nss_status status = niserr2nss (result->status);
- nis_freeresult (result);
- return status;
- }
+ nis_result *result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL);
- parse_res = _nss_nisplus_parse_etherent (result, eth, buffer,
+ if (result == NULL)
+ {
+ *errnop = ENOMEM;
+ return NSS_STATUS_TRYAGAIN;
+ }
+
+ if (__builtin_expect (niserr2nss (result->status) != NSS_STATUS_SUCCESS, 0))
+ {
+ enum nss_status status = niserr2nss (result->status);
+ nis_freeresult (result);
+ return status;
+ }
+
+ int parse_res = _nss_nisplus_parse_etherent (result, eth, buffer,
buflen, errnop);
- if (parse_res < 1)
+ if (__builtin_expect (parse_res < 1, 0))
+ {
+ if (parse_res == -1)
{
- if (parse_res == -1)
- {
- nis_freeresult (result);
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
- }
- else
- return NSS_STATUS_NOTFOUND;
+ nis_freeresult (result);
+ return NSS_STATUS_TRYAGAIN;
}
- return NSS_STATUS_SUCCESS;
+
+ return NSS_STATUS_NOTFOUND;
}
+
+ return NSS_STATUS_SUCCESS;
}
diff --git a/nis/nss_nisplus/nisplus-grp.c b/nis/nss_nisplus/nisplus-grp.c
index daca94fc87..423f7e7291 100644
--- a/nis/nss_nisplus/nisplus-grp.c
+++ b/nis/nss_nisplus/nisplus-grp.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997, 2001, 2002, 2003 Free Software Foundation, Inc.
+/* Copyright (C) 1997, 2001, 2002, 2003, 2005 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
@@ -17,6 +17,7 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
+#include <atomic.h>
#include <nss.h>
#include <grp.h>
#include <ctype.h>
@@ -28,31 +29,39 @@
#include "nss-nisplus.h"
#include "nisplus-parser.h"
+
__libc_lock_define_initialized (static, lock);
static nis_result *result;
static unsigned long next_entry;
static nis_name tablename_val;
-static u_long tablename_len;
+static size_t tablename_len;
static enum nss_status
_nss_create_tablename (int *errnop)
{
if (tablename_val == NULL)
{
- char buf [40 + strlen (nis_local_directory ())];
- char *p;
+ const char *local_dir = nis_local_directory ();
+ size_t local_dir_len = strlen (local_dir);
+ static const char prefix[] = "group.org_dir.";
- p = __stpcpy (buf, "group.org_dir.");
- p = __stpcpy (p, nis_local_directory ());
- tablename_val = __strdup (buf);
+ char *p = malloc (sizeof (prefix) + local_dir_len);
if (tablename_val == NULL)
{
*errnop = errno;
return NSS_STATUS_TRYAGAIN;
}
- tablename_len = strlen (tablename_val);
+
+ memcpy (__stpcpy (p, prefix), local_dir, local_dir_len + 1);
+
+ tablename_len = sizeof (prefix) - 1 + local_dir_len;
+
+ atomic_write_barrier ();
+
+ tablename_val = p;
}
+
return NSS_STATUS_SUCCESS;
}
@@ -60,16 +69,20 @@ static enum nss_status
internal_setgrent (void)
{
enum nss_status status;
- int err;
- if (result)
- nis_freeresult (result);
- result = NULL;
+ if (result != NULL)
+ {
+ nis_freeresult (result);
+ result = NULL;
+ }
next_entry = 0;
if (tablename_val == NULL)
- if (_nss_create_tablename (&err) != NSS_STATUS_SUCCESS)
- return NSS_STATUS_UNAVAIL;
+ {
+ int err;
+ if (_nss_create_tablename (&err) != NSS_STATUS_SUCCESS)
+ return NSS_STATUS_UNAVAIL;
+ }
result = nis_list (tablename_val, FOLLOW_LINKS | FOLLOW_PATH, NULL, NULL);
if (result == NULL)
@@ -108,9 +121,11 @@ _nss_nisplus_endgrent (void)
{
__libc_lock_lock (lock);
- if (result)
- nis_freeresult (result);
- result = NULL;
+ if (result != NULL)
+ {
+ nis_freeresult (result);
+ result = NULL;
+ }
__libc_lock_unlock (lock);
@@ -173,8 +188,12 @@ _nss_nisplus_getgrnam_r (const char *name, struct group *gr,
if (tablename_val == NULL)
{
+ __libc_lock_lock (lock);
+
enum nss_status status = _nss_create_tablename (errnop);
+ __libc_lock_unlock (lock);
+
if (status != NSS_STATUS_SUCCESS)
return status;
}
@@ -184,47 +203,46 @@ _nss_nisplus_getgrnam_r (const char *name, struct group *gr,
*errnop = EINVAL;
return NSS_STATUS_NOTFOUND;
}
- else
+
+ nis_result *result;
+ char buf[strlen (name) + 9 + tablename_len];
+ int olderr = errno;
+
+ snprintf (buf, sizeof (buf), "[name=%s],%s", name, tablename_val);
+
+ result = nis_list (buf, FOLLOW_LINKS | FOLLOW_PATH, NULL, NULL);
+
+ if (result == NULL)
{
- nis_result *result;
- char buf[strlen (name) + 24 + tablename_len];
- int olderr = errno;
+ *errnop = ENOMEM;
+ return NSS_STATUS_TRYAGAIN;
+ }
- sprintf (buf, "[name=%s],%s", name, tablename_val);
+ if (__builtin_expect (niserr2nss (result->status) != NSS_STATUS_SUCCESS, 0))
+ {
+ enum nss_status status = niserr2nss (result->status);
- result = nis_list (buf, FOLLOW_LINKS | FOLLOW_PATH, NULL, NULL);
+ nis_freeresult (result);
+ return status;
+ }
- if (result == NULL)
+ parse_res = _nss_nisplus_parse_grent (result, 0, gr, buffer, buflen, errnop);
+ nis_freeresult (result);
+ if (__builtin_expect (parse_res < 1, 0))
+ {
+ if (parse_res == -1)
{
- *errnop = ENOMEM;
+ *errnop = ERANGE;
return NSS_STATUS_TRYAGAIN;
}
- if (niserr2nss (result->status) != NSS_STATUS_SUCCESS)
- {
- enum nss_status status = niserr2nss (result->status);
-
- nis_freeresult (result);
- return status;
- }
-
- parse_res = _nss_nisplus_parse_grent (result, 0, gr, buffer, buflen,
- errnop);
- nis_freeresult (result);
- if (parse_res < 1)
+ else
{
- if (parse_res == -1)
- {
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
- }
- else
- {
- __set_errno (olderr);
- return NSS_STATUS_NOTFOUND;
- }
+ __set_errno (olderr);
+ return NSS_STATUS_NOTFOUND;
}
- return NSS_STATUS_SUCCESS;
}
+
+ return NSS_STATUS_SUCCESS;
}
enum nss_status
@@ -233,53 +251,57 @@ _nss_nisplus_getgrgid_r (const gid_t gid, struct group *gr,
{
if (tablename_val == NULL)
{
+ __libc_lock_lock (lock);
+
enum nss_status status = _nss_create_tablename (errnop);
+ __libc_lock_unlock (lock);
+
if (status != NSS_STATUS_SUCCESS)
return status;
}
- {
- int parse_res;
- nis_result *result;
- char buf[36 + tablename_len];
- int olderr = errno;
+ int parse_res;
+ nis_result *result;
+ char buf[8 + 3 * sizeof (unsigned long int) + tablename_len];
+ int olderr = errno;
- sprintf (buf, "[gid=%lu],%s", (unsigned long int) gid, tablename_val);
+ snprintf (buf, sizeof (buf), "[gid=%lu],%s",
+ (unsigned long int) gid, tablename_val);
- result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL);
+ result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL);
- if (result == NULL)
- {
- *errnop = ENOMEM;
- return NSS_STATUS_TRYAGAIN;
- }
- if (niserr2nss (result->status) != NSS_STATUS_SUCCESS)
- {
- enum nss_status status = niserr2nss (result->status);
+ if (result == NULL)
+ {
+ *errnop = ENOMEM;
+ return NSS_STATUS_TRYAGAIN;
+ }
- __set_errno (olderr);
+ if (__builtin_expect (niserr2nss (result->status) != NSS_STATUS_SUCCESS, 0))
+ {
+ enum nss_status status = niserr2nss (result->status);
- nis_freeresult (result);
- return status;
- }
-
- parse_res = _nss_nisplus_parse_grent (result, 0, gr, buffer, buflen,
- errnop);
-
- nis_freeresult (result);
- if (parse_res < 1)
- {
- __set_errno (olderr);
-
- if (parse_res == -1)
- {
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
- }
- else
- return NSS_STATUS_NOTFOUND;
- }
- return NSS_STATUS_SUCCESS;
- }
+ __set_errno (olderr);
+
+ nis_freeresult (result);
+ return status;
+ }
+
+ parse_res = _nss_nisplus_parse_grent (result, 0, gr, buffer, buflen, errnop);
+
+ nis_freeresult (result);
+ if (__builtin_expect (parse_res < 1, 0))
+ {
+ __set_errno (olderr);
+
+ if (parse_res == -1)
+ {
+ *errnop = ERANGE;
+ return NSS_STATUS_TRYAGAIN;
+ }
+ else
+ return NSS_STATUS_NOTFOUND;
+ }
+
+ return NSS_STATUS_SUCCESS;
}
diff --git a/nis/nss_nisplus/nisplus-hosts.c b/nis/nss_nisplus/nisplus-hosts.c
index 540469894e..81f8a984dc 100644
--- a/nis/nss_nisplus/nisplus-hosts.c
+++ b/nis/nss_nisplus/nisplus-hosts.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997-2002, 2003 Free Software Foundation, Inc.
+/* Copyright (C) 1997-2002, 2003, 2005 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@suse.de>, 1997.
@@ -17,15 +17,16 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
-#include <nss.h>
-#include <netdb.h>
-#include <errno.h>
+#include <atomic.h>
#include <ctype.h>
+#include <errno.h>
+#include <netdb.h>
+#include <nss.h>
#include <string.h>
-#include <netinet/in.h>
#include <arpa/inet.h>
-#include <bits/libc-lock.h>
+#include <netinet/in.h>
#include <rpcsvc/nis.h>
+#include <bits/libc-lock.h>
#include "nss-nisplus.h"
@@ -180,19 +181,26 @@ _nss_create_tablename (int *errnop)
{
if (tablename_val == NULL)
{
- char buf [40 + strlen (nis_local_directory ())];
- char *p;
+ const char *local_dir = nis_local_directory ();
+ size_t local_dir_len = strlen (local_dir);
+ static const char prefix[] = "hosts.org_dir.";
- p = __stpcpy (buf, "hosts.org_dir.");
- p = __stpcpy (p, nis_local_directory ());
- tablename_val = __strdup (buf);
+ char *p = malloc (sizeof (prefix) + local_dir_len);
if (tablename_val == NULL)
{
*errnop = errno;
return NSS_STATUS_TRYAGAIN;
}
- tablename_len = strlen (tablename_val);
+
+ memcpy (__stpcpy (p, prefix), local_dir, local_dir_len + 1);
+
+ tablename_len = sizeof (prefix) - 1 + local_dir_len;
+
+ atomic_write_barrier ();
+
+ tablename_val = p;
}
+
return NSS_STATUS_SUCCESS;
}
@@ -204,9 +212,11 @@ _nss_nisplus_sethostent (int stayopen)
__libc_lock_lock (lock);
- if (result)
- nis_freeresult (result);
- result = NULL;
+ if (result != NULL)
+ {
+ nis_freeresult (result);
+ result = NULL;
+ }
if (tablename_val == NULL)
status = _nss_create_tablename (&err);
@@ -221,9 +231,11 @@ _nss_nisplus_endhostent (void)
{
__libc_lock_lock (lock);
- if (result)
- nis_freeresult (result);
- result = NULL;
+ if (result != NULL)
+ {
+ nis_freeresult (result);
+ result = NULL;
+ }
__libc_lock_unlock (lock);
@@ -335,8 +347,12 @@ internal_gethostbyname2_r (const char *name, int af, struct hostent *host,
if (tablename_val == NULL)
{
+ __libc_lock_lock (lock);
+
enum nss_status status = _nss_create_tablename (errnop);
+ __libc_lock_unlock (lock);
+
if (status != NSS_STATUS_SUCCESS)
{
*herrnop = NETDB_INTERNAL;
@@ -350,75 +366,81 @@ internal_gethostbyname2_r (const char *name, int af, struct hostent *host,
*herrnop = NETDB_INTERNAL;
return NSS_STATUS_NOTFOUND;
}
- else
- {
- nis_result *result;
- char buf[strlen (name) + 255 + tablename_len];
- int olderr = errno;
- /* Search at first in the alias list, and use the correct name
- for the next search */
- sprintf (buf, "[name=%s],%s", name, tablename_val);
- result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL);
+ nis_result *result;
+ char buf[strlen (name) + 10 + tablename_len];
+ int olderr = errno;
- if (result != NULL)
- {
- /* If we do not find it, try it as original name. But if the
- database is correct, we should find it in the first case, too */
- if ((result->status != NIS_SUCCESS
- && result->status != NIS_S_SUCCESS)
- || __type_of (result->objects.objects_val) != NIS_ENTRY_OBJ
- || strcmp (result->objects.objects_val->EN_data.en_type,
- "hosts_tbl") != 0
- || result->objects.objects_val->EN_data.en_cols.en_cols_len < 3)
- sprintf (buf, "[cname=%s],%s", name, tablename_val);
- else
- sprintf (buf, "[cname=%s],%s", NISENTRYVAL(0, 0, result),
- tablename_val);
-
- nis_freeresult (result);
- result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL);
- }
+ /* Search at first in the alias list, and use the correct name
+ for the next search. */
+ snprintf (buf, sizeof (buf), "[name=%s],%s", name, tablename_val);
+ result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL);
- if (result == NULL)
+ if (result != NULL)
+ {
+ char *bufptr = buf;
+
+ /* If we did not find it, try it as original name. But if the
+ database is correct, we should find it in the first case, too. */
+ if ((result->status != NIS_SUCCESS
+ && result->status != NIS_S_SUCCESS)
+ || __type_of (result->objects.objects_val) != NIS_ENTRY_OBJ
+ || strcmp (result->objects.objects_val->EN_data.en_type,
+ "hosts_tbl") != 0
+ || result->objects.objects_val->EN_data.en_cols.en_cols_len < 3)
+ snprintf (buf, sizeof (buf), "[cname=%s],%s", name, tablename_val);
+ else
{
- *errnop = ENOMEM;
- return NSS_STATUS_TRYAGAIN;
+ /* We need to allocate a new buffer since there is no
+ guarantee the returned name has a length limit. */
+ const char *entryval = NISENTRYVAL(0, 0, result);
+ size_t buflen = strlen (entryval) + 10 + tablename_len;
+ bufptr = alloca (buflen);
+ snprintf (bufptr, buflen, "[cname=%s],%s",
+ entryval, tablename_val);
}
- retval = niserr2nss (result->status);
- if (retval != NSS_STATUS_SUCCESS)
- {
- if (retval == NSS_STATUS_TRYAGAIN)
- {
- *errnop = errno;
- *herrnop = NETDB_INTERNAL;
- }
- else
- __set_errno (olderr);
- nis_freeresult (result);
- return retval;
- }
-
- parse_res = _nss_nisplus_parse_hostent (result, af, host, buffer,
- buflen, errnop, flags);
nis_freeresult (result);
+ result = nis_list (bufptr, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL);
+ }
- if (parse_res > 0)
- return NSS_STATUS_SUCCESS;
+ if (result == NULL)
+ {
+ *errnop = ENOMEM;
+ return NSS_STATUS_TRYAGAIN;
+ }
- *herrnop = NETDB_INTERNAL;
- if (parse_res == -1)
+ retval = niserr2nss (result->status);
+ if (__builtin_expect (retval != NSS_STATUS_SUCCESS, 0))
+ {
+ if (retval == NSS_STATUS_TRYAGAIN)
{
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
+ *errnop = errno;
+ *herrnop = NETDB_INTERNAL;
}
else
- {
- __set_errno (olderr);
- return NSS_STATUS_NOTFOUND;
- }
+ __set_errno (olderr);
+ nis_freeresult (result);
+ return retval;
}
+
+ parse_res = _nss_nisplus_parse_hostent (result, af, host, buffer,
+ buflen, errnop, flags);
+
+ nis_freeresult (result);
+
+ if (parse_res > 0)
+ return NSS_STATUS_SUCCESS;
+
+ *herrnop = NETDB_INTERNAL;
+ if (parse_res == -1)
+ {
+ *errnop = ERANGE;
+ return NSS_STATUS_TRYAGAIN;
+ }
+
+ __set_errno (olderr);
+ return NSS_STATUS_NOTFOUND;
}
enum nss_status
@@ -431,17 +453,6 @@ _nss_nisplus_gethostbyname2_r (const char *name, int af, struct hostent *host,
((_res.options & RES_USE_INET6) ? AI_V4MAPPED : 0));
}
-#if 0
-enum nss_status
-_nss_nisplus_getipnodebyname_r (const char *name, int af, int flags,
- struct hostent *result, char *buffer,
- size_t buflen, int *errnop, int *herrnop)
-{
- return internal_gethostbyname2_r (name, af, result, buffer, buflen,
- errnop, herrnop, flags);
-}
-#endif
-
enum nss_status
_nss_nisplus_gethostbyname_r (const char *name, struct hostent *host,
char *buffer, size_t buflen, int *errnop,
@@ -469,62 +480,63 @@ _nss_nisplus_gethostbyaddr_r (const void *addr, socklen_t addrlen, int af,
{
if (tablename_val == NULL)
{
+ __libc_lock_lock (lock);
+
enum nss_status status = _nss_create_tablename (errnop);
+ __libc_lock_unlock (lock);
+
if (status != NSS_STATUS_SUCCESS)
return status;
}
if (addr == NULL)
return NSS_STATUS_NOTFOUND;
- else
- {
- nis_result *result;
- char buf[255 + tablename_len];
- int retval, parse_res;
- int olderr = errno;
- sprintf (buf, "[addr=%s],%s",
- inet_ntoa (*(const struct in_addr *) addr), tablename_val);
- result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL);
-
- if (result == NULL)
- {
- __set_errno (ENOMEM);
- return NSS_STATUS_TRYAGAIN;
- }
- retval = niserr2nss (result->status);
- if (retval != NSS_STATUS_SUCCESS)
- {
- if (retval == NSS_STATUS_TRYAGAIN)
- {
- *errnop = errno;
- *herrnop = NETDB_INTERNAL;
- }
- else
- __set_errno (olderr);
- nis_freeresult (result);
- return retval;
- }
+ char buf[24 + tablename_len];
+ int retval, parse_res;
+ int olderr = errno;
- parse_res = _nss_nisplus_parse_hostent (result, af, host,
- buffer, buflen, errnop,
- ((_res.options & RES_USE_INET6) ? AI_V4MAPPED : 0));
- nis_freeresult (result);
+ snprintf (buf, sizeof (buf), "[addr=%s],%s",
+ inet_ntoa (*(const struct in_addr *) addr), tablename_val);
+ nis_result *result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL);
- if (parse_res > 0)
- return NSS_STATUS_SUCCESS;
+ if (result == NULL)
+ {
+ __set_errno (ENOMEM);
+ return NSS_STATUS_TRYAGAIN;
+ }
- *herrnop = NETDB_INTERNAL;
- if (parse_res == -1)
+ retval = niserr2nss (result->status);
+ if (__builtin_expect (retval != NSS_STATUS_SUCCESS, 0))
+ {
+ if (retval == NSS_STATUS_TRYAGAIN)
{
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
+ *errnop = errno;
+ *herrnop = NETDB_INTERNAL;
}
else
- {
- __set_errno (olderr);
- return NSS_STATUS_NOTFOUND;
- }
+ __set_errno (olderr);
+ nis_freeresult (result);
+ return retval;
+ }
+
+ parse_res = _nss_nisplus_parse_hostent (result, af, host,
+ buffer, buflen, errnop,
+ ((_res.options & RES_USE_INET6)
+ ? AI_V4MAPPED : 0));
+ nis_freeresult (result);
+
+ if (parse_res > 0)
+ return NSS_STATUS_SUCCESS;
+
+ *herrnop = NETDB_INTERNAL;
+ if (parse_res == -1)
+ {
+ *errnop = ERANGE;
+ return NSS_STATUS_TRYAGAIN;
}
+
+ __set_errno (olderr);
+ return NSS_STATUS_NOTFOUND;
}
diff --git a/nis/nss_nisplus/nisplus-netgrp.c b/nis/nss_nisplus/nisplus-netgrp.c
index 344d65f4c4..31a8cdf097 100644
--- a/nis/nss_nisplus/nisplus-netgrp.c
+++ b/nis/nss_nisplus/nisplus-netgrp.c
@@ -150,15 +150,14 @@ internal_endnetgrent (struct __netgrent *netgrp)
enum nss_status
_nss_nisplus_setnetgrent (const char *group, struct __netgrent *netgrp)
{
- enum nss_status status;
- char buf[strlen (group) + 30];
+ char buf[strlen (group) + 25];
if (group == NULL || group[0] == '\0')
return NSS_STATUS_UNAVAIL;
- status = NSS_STATUS_SUCCESS;
+ enum nss_status status = NSS_STATUS_SUCCESS;
- sprintf (buf, "[name=%s],netgroup.org_dir", group);
+ snprintf (buf, sizeof (buf), "[name=%s],netgroup.org_dir", group);
netgrp->data = (char *) nis_list (buf, EXPAND_NAME, NULL, NULL);
diff --git a/nis/nss_nisplus/nisplus-network.c b/nis/nss_nisplus/nisplus-network.c
index 422b02b82a..dc6b99e505 100644
--- a/nis/nss_nisplus/nisplus-network.c
+++ b/nis/nss_nisplus/nisplus-network.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997,1998,2000,2001,2002,2003 Free Software Foundation, Inc.
+/* Copyright (C) 1997,1998,2000-2003,2005 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
@@ -17,15 +17,16 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
-#include <nss.h>
-#include <netdb.h>
-#include <errno.h>
+#include <atomic.h>
#include <ctype.h>
+#include <errno.h>
+#include <netdb.h>
+#include <nss.h>
#include <stdint.h>
#include <string.h>
#include <arpa/inet.h>
-#include <bits/libc-lock.h>
#include <rpcsvc/nis.h>
+#include <bits/libc-lock.h>
#include "nss-nisplus.h"
@@ -44,12 +45,10 @@ static u_long tablename_len;
static int
_nss_nisplus_parse_netent (nis_result *result, struct netent *network,
- char *buffer, size_t buflen, int *errnop)
+ char *buffer, size_t buflen, int *errnop)
{
char *first_unused = buffer;
size_t room_left = buflen;
- unsigned int i;
- char *p, *line;
if (result == NULL)
return 0;
@@ -61,7 +60,7 @@ _nss_nisplus_parse_netent (nis_result *result, struct netent *network,
|| result->objects.objects_val[0].EN_data.en_cols.en_cols_len < 3)
return 0;
- if (NISENTRYLEN(0, 0, result) >= room_left)
+ if (NISENTRYLEN (0, 0, result) >= room_left)
{
/* The line is too long for our buffer. */
no_more_room:
@@ -69,7 +68,7 @@ _nss_nisplus_parse_netent (nis_result *result, struct netent *network,
return -1;
}
- strncpy (first_unused, NISENTRYVAL(0, 0, result),
+ strncpy (first_unused, NISENTRYVAL (0, 0, result),
NISENTRYLEN (0, 0, result));
first_unused[NISENTRYLEN (0, 0, result)] = '\0';
network->n_name = first_unused;
@@ -77,10 +76,10 @@ _nss_nisplus_parse_netent (nis_result *result, struct netent *network,
first_unused += strlen (first_unused) +1;
network->n_addrtype = 0;
network->n_net = inet_network (NISENTRYVAL (0, 2, result));
- p = first_unused;
+ char *p = first_unused;
- line = p;
- for (i = 0; i < result->objects.objects_len; ++i)
+ char *line = p;
+ for (unsigned int i = 0; i < result->objects.objects_len; ++i)
{
if (strcmp (NISENTRYVAL (i, 1, result), network->n_name) != 0)
{
@@ -107,12 +106,12 @@ _nss_nisplus_parse_netent (nis_result *result, struct netent *network,
room_left -= (2 * sizeof (char *));
network->n_aliases[0] = NULL;
- i = 0;
+ unsigned int i = 0;
while (*line != '\0')
{
/* Skip leading blanks. */
while (isspace (*line))
- line++;
+ ++line;
if (*line == '\0')
break;
@@ -133,7 +132,7 @@ _nss_nisplus_parse_netent (nis_result *result, struct netent *network,
++i;
}
else
- network->n_aliases[i+1] = NULL;
+ network->n_aliases[i + 1] = NULL;
}
return 1;
@@ -144,19 +143,26 @@ _nss_create_tablename (int *errnop)
{
if (tablename_val == NULL)
{
- char buf [40 + strlen (nis_local_directory ())];
- char *p;
+ const char *local_dir = nis_local_directory ();
+ size_t local_dir_len = strlen (local_dir);
+ static const char prefix[] = "networks.org_dir.";
- p = __stpcpy (buf, "networks.org_dir.");
- p = __stpcpy (p, nis_local_directory ());
- tablename_val = __strdup (buf);
+ char *p = malloc (sizeof (prefix) + local_dir_len);
if (tablename_val == NULL)
{
*errnop = errno;
return NSS_STATUS_TRYAGAIN;
}
- tablename_len = strlen (tablename_val);
+
+ memcpy (__stpcpy (p, prefix), local_dir, local_dir_len + 1);
+
+ tablename_len = sizeof (prefix) - 1 + local_dir_len;
+
+ atomic_write_barrier ();
+
+ tablename_val = p;
}
+
return NSS_STATUS_SUCCESS;
}
@@ -164,16 +170,20 @@ enum nss_status
_nss_nisplus_setnetent (int stayopen)
{
enum nss_status status = NSS_STATUS_SUCCESS;
- int err;
__libc_lock_lock (lock);
- if (result)
- nis_freeresult (result);
- result = NULL;
+ if (result != NULL)
+ {
+ nis_freeresult (result);
+ result = NULL;
+ }
if (tablename_val == NULL)
- status = _nss_create_tablename (&err);
+ {
+ int err;
+ status = _nss_create_tablename (&err);
+ }
__libc_lock_unlock (lock);
@@ -185,9 +195,11 @@ _nss_nisplus_endnetent (void)
{
__libc_lock_lock (lock);
- if (result)
- nis_freeresult (result);
- result = NULL;
+ if (result != NULL)
+ {
+ nis_freeresult (result);
+ result = NULL;
+ }
__libc_lock_unlock (lock);
@@ -220,9 +232,7 @@ internal_nisplus_getnetent_r (struct netent *network, char *buffer,
result = nis_first_entry (tablename_val);
if (niserr2nss (result->status) != NSS_STATUS_SUCCESS)
{
- int retval;
-
- retval = niserr2nss (result->status);
+ int retval = niserr2nss (result->status);
nis_freeresult (result);
result = NULL;
if (retval == NSS_STATUS_TRYAGAIN)
@@ -237,16 +247,12 @@ internal_nisplus_getnetent_r (struct netent *network, char *buffer,
}
else
{
- nis_result *res;
-
- res = nis_next_entry (tablename_val, &result->cookie);
+ nis_result *res = nis_next_entry (tablename_val, &result->cookie);
saved_res = result;
result = res;
if (niserr2nss (result->status) != NSS_STATUS_SUCCESS)
{
- int retval;
-
- retval = niserr2nss (result->status);
+ int retval = niserr2nss (result->status);
nis_freeresult (result);
result = saved_res;
if (retval == NSS_STATUS_TRYAGAIN)
@@ -266,7 +272,8 @@ internal_nisplus_getnetent_r (struct netent *network, char *buffer,
return NSS_STATUS_TRYAGAIN;
}
- } while (!parse_res);
+ }
+ while (!parse_res);
return NSS_STATUS_SUCCESS;
}
@@ -296,8 +303,12 @@ _nss_nisplus_getnetbyname_r (const char *name, struct netent *network,
if (tablename_val == NULL)
{
+ __libc_lock_lock (lock);
+
enum nss_status status = _nss_create_tablename (errnop);
+ __libc_lock_unlock (lock);
+
if (status != NSS_STATUS_SUCCESS)
return status;
}
@@ -308,76 +319,82 @@ _nss_nisplus_getnetbyname_r (const char *name, struct netent *network,
*herrnop = NETDB_INTERNAL;
return NSS_STATUS_UNAVAIL;
}
- else
- {
- nis_result *result;
- char buf[strlen (name) + 255 + tablename_len];
- int olderr = errno;
- /* Search at first in the alias list, and use the correct name
- for the next search */
- sprintf (buf, "[name=%s],%s", name, tablename_val);
- result = nis_list (buf, FOLLOW_LINKS | FOLLOW_PATH, NULL, NULL);
+ nis_result *result;
+ char buf[strlen (name) + 10 + tablename_len];
+ int olderr = errno;
- if (result != NULL)
- {
- /* If we do not find it, try it as original name. But if the
- database is correct, we should find it in the first case, too */
- if ((result->status != NIS_SUCCESS
- && result->status != NIS_S_SUCCESS)
- || __type_of (result->objects.objects_val) != NIS_ENTRY_OBJ
- || strcmp (result->objects.objects_val[0].EN_data.en_type,
- "networks_tbl") != 0
- || (result->objects.objects_val[0].EN_data.en_cols.en_cols_len
- < 3))
- sprintf (buf, "[cname=%s],%s", name, tablename_val);
- else
- sprintf (buf, "[cname=%s],%s", NISENTRYVAL (0, 0, result),
- tablename_val);
-
- nis_freeresult (result);
- result = nis_list (buf, FOLLOW_LINKS | FOLLOW_PATH, NULL, NULL);
- }
+ /* Search at first in the alias list, and use the correct name
+ for the next search */
+ snprintf (buf, sizeof (buf), "[name=%s],%s", name, tablename_val);
+ result = nis_list (buf, FOLLOW_LINKS | FOLLOW_PATH, NULL, NULL);
- if (result == NULL)
- {
- __set_errno (ENOMEM);
- return NSS_STATUS_TRYAGAIN;
- }
- retval = niserr2nss (result->status);
- if (retval != NSS_STATUS_SUCCESS)
+ if (result != NULL)
+ {
+ char *bufptr = buf;
+
+ /* If we do not find it, try it as original name. But if the
+ database is correct, we should find it in the first case, too */
+ if ((result->status != NIS_SUCCESS
+ && result->status != NIS_S_SUCCESS)
+ || __type_of (result->objects.objects_val) != NIS_ENTRY_OBJ
+ || strcmp (result->objects.objects_val[0].EN_data.en_type,
+ "networks_tbl") != 0
+ || (result->objects.objects_val[0].EN_data.en_cols.en_cols_len
+ < 3))
+ snprintf (buf, sizeof (buf), "[cname=%s],%s", name, tablename_val);
+ else
{
- if (retval == NSS_STATUS_TRYAGAIN)
- {
- *errnop = errno;
- *herrnop = NETDB_INTERNAL;
- }
- else
- __set_errno (olderr);
- nis_freeresult (result);
- return retval;
+ /* We need to allocate a new buffer since there is no
+ guarantee the returned name has a length limit. */
+ const char *entryval = NISENTRYVAL (0, 0, result);
+ size_t buflen = strlen (entryval) + 10 + tablename_len;
+ bufptr = alloca (buflen);
+ snprintf (bufptr, buflen, "[cname=%s],%s",
+ entryval, tablename_val);
}
- parse_res = _nss_nisplus_parse_netent (result, network, buffer, buflen,
- errnop);
-
nis_freeresult (result);
+ result = nis_list (bufptr, FOLLOW_LINKS | FOLLOW_PATH, NULL, NULL);
+ }
- if (parse_res > 0)
- return NSS_STATUS_SUCCESS;
+ if (result == NULL)
+ {
+ __set_errno (ENOMEM);
+ return NSS_STATUS_TRYAGAIN;
+ }
- *herrnop = NETDB_INTERNAL;
- if (parse_res == -1)
+ retval = niserr2nss (result->status);
+ if (__builtin_expect (retval != NSS_STATUS_SUCCESS, 0))
+ {
+ if (retval == NSS_STATUS_TRYAGAIN)
{
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
+ *errnop = errno;
+ *herrnop = NETDB_INTERNAL;
}
else
- {
- __set_errno (olderr);
- return NSS_STATUS_NOTFOUND;
- }
+ __set_errno (olderr);
+ nis_freeresult (result);
+ return retval;
+ }
+
+ parse_res = _nss_nisplus_parse_netent (result, network, buffer, buflen,
+ errnop);
+
+ nis_freeresult (result);
+
+ if (parse_res > 0)
+ return NSS_STATUS_SUCCESS;
+
+ *herrnop = NETDB_INTERNAL;
+ if (parse_res == -1)
+ {
+ *errnop = ERANGE;
+ return NSS_STATUS_TRYAGAIN;
}
+
+ __set_errno (olderr);
+ return NSS_STATUS_NOTFOUND;
}
/* XXX type is ignored, SUN's NIS+ table doesn't support it */
@@ -388,39 +405,39 @@ _nss_nisplus_getnetbyaddr_r (uint32_t addr, const int type,
{
if (tablename_val == NULL)
{
+ __libc_lock_lock (lock);
+
enum nss_status status = _nss_create_tablename (errnop);
+ __libc_lock_unlock (lock);
+
if (status != NSS_STATUS_SUCCESS)
return status;
}
{
- int parse_res, retval;
- nis_result *result;
- char buf[1024 + tablename_len];
- struct in_addr in;
- char buf2[256];
- int b2len;
+ char buf[27 + tablename_len];
+ char buf2[18];
int olderr = errno;
- in = inet_makeaddr (addr, 0);
+ struct in_addr in = inet_makeaddr (addr, 0);
strcpy (buf2, inet_ntoa (in));
- b2len = strlen (buf2);
+ size_t b2len = strlen (buf2);
while (1)
{
- sprintf (buf, "[addr=%s],%s", buf2, tablename_val);
- result = nis_list (buf, EXPAND_NAME, NULL, NULL);
+ snprintf (buf, sizeof (buf), "[addr=%s],%s", buf2, tablename_val);
+ nis_result *result = nis_list (buf, EXPAND_NAME, NULL, NULL);
if (result == NULL)
{
__set_errno (ENOMEM);
return NSS_STATUS_TRYAGAIN;
}
- retval = niserr2nss (result->status);
- if (retval != NSS_STATUS_SUCCESS)
+ enum nss_status retval = niserr2nss (result->status);
+ if (__builtin_expect (retval != NSS_STATUS_SUCCESS, 0))
{
- if (buf2[b2len -2] == '.' && buf2[b2len -1] == '0')
+ if (b2len > 2 && buf2[b2len - 2] == '.' && buf2[b2len - 1] == '0')
{
/* Try again, but with trailing dot(s)
removed (one by one) */
@@ -428,8 +445,6 @@ _nss_nisplus_getnetbyaddr_r (uint32_t addr, const int type,
b2len -= 2;
continue;
}
- else
- return NSS_STATUS_NOTFOUND;
if (retval == NSS_STATUS_TRYAGAIN)
{
@@ -442,8 +457,8 @@ _nss_nisplus_getnetbyaddr_r (uint32_t addr, const int type,
return retval;
}
- parse_res = _nss_nisplus_parse_netent (result, network, buffer,
- buflen, errnop);
+ int parse_res = _nss_nisplus_parse_netent (result, network, buffer,
+ buflen, errnop);
nis_freeresult (result);
diff --git a/nis/nss_nisplus/nisplus-proto.c b/nis/nss_nisplus/nisplus-proto.c
index 83456cae64..585a4844ad 100644
--- a/nis/nss_nisplus/nisplus-proto.c
+++ b/nis/nss_nisplus/nisplus-proto.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997, 1998, 2001, 2002, 2003 Free Software Foundation, Inc.
+/* Copyright (C) 1997,1998,2001,2002,2003,2005 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
@@ -17,13 +17,14 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
-#include <nss.h>
-#include <errno.h>
+#include <atomic.h>
#include <ctype.h>
+#include <errno.h>
#include <netdb.h>
+#include <nss.h>
#include <string.h>
-#include <bits/libc-lock.h>
#include <rpcsvc/nis.h>
+#include <bits/libc-lock.h>
#include "nss-nisplus.h"
@@ -141,19 +142,26 @@ _nss_create_tablename (int *errnop)
{
if (tablename_val == NULL)
{
- char buf [40 + strlen (nis_local_directory ())];
- char *p;
+ const char *local_dir = nis_local_directory ();
+ size_t local_dir_len = strlen (local_dir);
+ static const char prefix[] = "protocols.org_dir.";
- p = __stpcpy (buf, "protocols.org_dir.");
- p = __stpcpy (p, nis_local_directory ());
- tablename_val = __strdup (buf);
+ char *p = malloc (sizeof (prefix) + local_dir_len);
if (tablename_val == NULL)
{
*errnop = errno;
return NSS_STATUS_TRYAGAIN;
}
- tablename_len = strlen (tablename_val);
+
+ memcpy (__stpcpy (p, prefix), local_dir, local_dir_len + 1);
+
+ tablename_len = sizeof (prefix) - 1 + local_dir_len;
+
+ atomic_write_barrier ();
+
+ tablename_val = p;
}
+
return NSS_STATUS_SUCCESS;
}
@@ -164,9 +172,11 @@ _nss_nisplus_setprotoent (int stayopen)
__libc_lock_lock (lock);
- if (result)
- nis_freeresult (result);
- result = NULL;
+ if (result != NULL)
+ {
+ nis_freeresult (result);
+ result = NULL;
+ }
if (tablename_val == NULL)
{
@@ -184,9 +194,11 @@ _nss_nisplus_endprotoent (void)
{
__libc_lock_lock (lock);
- if (result)
- nis_freeresult (result);
- result = NULL;
+ if (result != NULL)
+ {
+ nis_freeresult (result);
+ result = NULL;
+ }
__libc_lock_unlock (lock);
@@ -221,11 +233,8 @@ internal_nisplus_getprotoent_r (struct protoent *proto, char *buffer,
}
else
{
- nis_result *res;
-
saved_res = result;
- res = nis_next_entry (tablename_val, &result->cookie);
- result = res;
+ result = nis_next_entry (tablename_val, &result->cookie);
if (niserr2nss (result->status) != NSS_STATUS_SUCCESS)
{
@@ -277,79 +286,91 @@ _nss_nisplus_getprotobyname_r (const char *name, struct protoent *proto,
if (tablename_val == NULL)
{
+ __libc_lock_lock (lock);
+
enum nss_status status = _nss_create_tablename (errnop);
+ __libc_lock_unlock (lock);
+
if (status != NSS_STATUS_SUCCESS)
return status;
}
if (name == NULL)
return NSS_STATUS_NOTFOUND;
- else
- {
- nis_result *result;
- char buf[strlen (name) + 255 + tablename_len];
- int olderr = errno;
-
- /* Search at first in the alias list, and use the correct name
- for the next search */
- sprintf (buf, "[name=%s],%s", name, tablename_val);
- result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL);
- if (result != NULL)
- {
- /* If we do not find it, try it as original name. But if the
- database is correct, we should find it in the first case, too */
- if ((result->status != NIS_SUCCESS
- && result->status != NIS_S_SUCCESS)
- || __type_of (result->objects.objects_val) != NIS_ENTRY_OBJ
- || strcmp (result->objects.objects_val->EN_data.en_type,
- "protocols_tbl") != 0
- || result->objects.objects_val->EN_data.en_cols.en_cols_len < 3)
- sprintf (buf, "[cname=%s],%s", name, tablename_val);
- else
- sprintf (buf, "[cname=%s],%s", NISENTRYVAL (0, 0, result),
- tablename_val);
+ char buf[strlen (name) + 10 + tablename_len];
+ int olderr = errno;
- nis_freeresult (result);
- result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL);
- }
+ /* Search at first in the alias list, and use the correct name
+ for the next search */
+ snprintf (buf, sizeof (buf), "[name=%s],%s", name, tablename_val);
+ nis_result *result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL);
- if (result == NULL)
+ if (result != NULL)
+ {
+ char *bufptr = buf;
+
+ /* If we did not find it, try it as original name. But if the
+ database is correct, we should find it in the first case, too */
+ if ((result->status != NIS_SUCCESS
+ && result->status != NIS_S_SUCCESS)
+ || __type_of (result->objects.objects_val) != NIS_ENTRY_OBJ
+ || strcmp (result->objects.objects_val->EN_data.en_type,
+ "protocols_tbl") != 0
+ || result->objects.objects_val->EN_data.en_cols.en_cols_len < 3)
+ snprintf (buf, sizeof (buf), "[cname=%s],%s", name, tablename_val);
+ else
{
- __set_errno (ENOMEM);
- return NSS_STATUS_TRYAGAIN;
+ /* We need to allocate a new buffer since there is no
+ guarantee the returned name has a length limit. */
+ const char *entryval = NISENTRYVAL (0, 0, result);
+ size_t buflen = strlen (entryval) + 10 + tablename_len;
+ bufptr = alloca (buflen);
+ snprintf (bufptr, buflen, "[cname=%s],%s",
+ entryval, tablename_val);
}
- if (niserr2nss (result->status) != NSS_STATUS_SUCCESS)
- {
- enum nss_status status = niserr2nss (result->status);
- __set_errno (olderr);
+ nis_freeresult (result);
+ result = nis_list (bufptr, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL);
+ }
- nis_freeresult (result);
- return status;
- }
+ if (result == NULL)
+ {
+ __set_errno (ENOMEM);
+ return NSS_STATUS_TRYAGAIN;
+ }
- parse_res = _nss_nisplus_parse_protoent (result, proto, buffer, buflen,
- errnop);
+ if (__builtin_expect (niserr2nss (result->status) != NSS_STATUS_SUCCESS, 0))
+ {
+ enum nss_status status = niserr2nss (result->status);
+
+ __set_errno (olderr);
nis_freeresult (result);
+ return status;
+ }
- if (parse_res < 1)
+ parse_res = _nss_nisplus_parse_protoent (result, proto, buffer, buflen,
+ errnop);
+
+ nis_freeresult (result);
+
+ if (parse_res < 1)
+ {
+ if (parse_res == -1)
{
- if (parse_res == -1)
- {
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
- }
- else
- {
- __set_errno (olderr);
- return NSS_STATUS_NOTFOUND;
- }
+ *errnop = ERANGE;
+ return NSS_STATUS_TRYAGAIN;
+ }
+ else
+ {
+ __set_errno (olderr);
+ return NSS_STATUS_NOTFOUND;
}
- return NSS_STATUS_SUCCESS;
}
+
+ return NSS_STATUS_SUCCESS;
}
enum nss_status
@@ -358,55 +379,57 @@ _nss_nisplus_getprotobynumber_r (const int number, struct protoent *proto,
{
if (tablename_val == NULL)
{
+ __libc_lock_lock (lock);
+
enum nss_status status = _nss_create_tablename (errnop);
+ __libc_lock_unlock (lock);
+
if (status != NSS_STATUS_SUCCESS)
return status;
}
- {
- int parse_res;
- nis_result *result;
- char buf[46 + tablename_len];
- int olderr = errno;
+ char buf[12 + 3 * sizeof (number) + tablename_len];
+ int olderr = errno;
- sprintf (buf, "[number=%d],%s", number, tablename_val);
+ snprintf (buf, sizeof (buf), "[number=%d],%s", number, tablename_val);
- result = nis_list (buf, FOLLOW_LINKS | FOLLOW_PATH, NULL, NULL);
+ nis_result *result = nis_list (buf, FOLLOW_LINKS | FOLLOW_PATH, NULL, NULL);
- if (result == NULL)
- {
- __set_errno (ENOMEM);
- return NSS_STATUS_TRYAGAIN;
- }
- if (niserr2nss (result->status) != NSS_STATUS_SUCCESS)
- {
- enum nss_status status = niserr2nss (result->status);
+ if (result == NULL)
+ {
+ __set_errno (ENOMEM);
+ return NSS_STATUS_TRYAGAIN;
+ }
- __set_errno (olderr);
+ if (__builtin_expect (niserr2nss (result->status) != NSS_STATUS_SUCCESS, 0))
+ {
+ enum nss_status status = niserr2nss (result->status);
- nis_freeresult (result);
- return status;
- }
-
- parse_res = _nss_nisplus_parse_protoent (result, proto, buffer, buflen,
- errnop);
-
- nis_freeresult (result);
-
- if (parse_res < 1)
- {
- if (parse_res == -1)
- {
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
- }
- else
- {
- __set_errno (olderr);
- return NSS_STATUS_NOTFOUND;
- }
- }
- return NSS_STATUS_SUCCESS;
- }
+ __set_errno (olderr);
+
+ nis_freeresult (result);
+ return status;
+ }
+
+ int parse_res = _nss_nisplus_parse_protoent (result, proto, buffer, buflen,
+ errnop);
+
+ nis_freeresult (result);
+
+ if (parse_res < 1)
+ {
+ if (parse_res == -1)
+ {
+ *errnop = ERANGE;
+ return NSS_STATUS_TRYAGAIN;
+ }
+ else
+ {
+ __set_errno (olderr);
+ return NSS_STATUS_NOTFOUND;
+ }
+ }
+
+ return NSS_STATUS_SUCCESS;
}
diff --git a/nis/nss_nisplus/nisplus-publickey.c b/nis/nss_nisplus/nisplus-publickey.c
index 58ae7012af..c24e898137 100644
--- a/nis/nss_nisplus/nisplus-publickey.c
+++ b/nis/nss_nisplus/nisplus-publickey.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 1997, 1999, 2001, 2003 Free Software Foundation, Inc.
+/* Copyright (c) 1997, 1999, 2001, 2003, 2005 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@suse.de>, 1997.
@@ -37,7 +37,7 @@ _nss_nisplus_getpublickey (const char *netname, char *pkey, int *errnop)
{
nis_result *res;
enum nss_status retval;
- char buf[NIS_MAXNAMELEN+2];
+ char buf[NIS_MAXNAMELEN + 2];
size_t slen;
char *domain, *cptr;
int len;
@@ -120,7 +120,7 @@ _nss_nisplus_getsecretkey (const char *netname, char *skey, char *passwd,
{
nis_result *res;
enum nss_status retval;
- char buf[NIS_MAXNAMELEN+2];
+ char buf[NIS_MAXNAMELEN + 2];
size_t slen;
char *domain, *cptr;
int len;
@@ -154,7 +154,7 @@ _nss_nisplus_getsecretkey (const char *netname, char *skey, char *passwd,
buf[slen] = '\0';
}
- res = nis_list (buf, USE_DGRAM+NO_AUTHINFO+FOLLOW_LINKS+FOLLOW_PATH,
+ res = nis_list (buf, USE_DGRAM | NO_AUTHINFO | FOLLOW_LINKS | FOLLOW_PATH,
NULL, NULL);
if (res == NULL)
@@ -242,9 +242,9 @@ _nss_nisplus_netname2user (char netname[MAXNETNAMELEN + 1], uid_t *uidp,
{
char *domain;
nis_result *res;
- char sname[NIS_MAXNAMELEN+2]; /* search criteria + table name */
+ char sname[NIS_MAXNAMELEN + 2]; /* search criteria + table name */
size_t slen;
- char principal[NIS_MAXNAMELEN+1];
+ char principal[NIS_MAXNAMELEN + 1];
int len;
/* 1. Get home domain of user. */
@@ -255,10 +255,6 @@ _nss_nisplus_netname2user (char netname[MAXNETNAMELEN + 1], uid_t *uidp,
++domain; /* skip '@' */
/* 2. Get user's nisplus principal name. */
- if ((strlen (netname) + strlen (domain)+45) >
- (size_t) NIS_MAXNAMELEN)
- return NSS_STATUS_UNAVAIL;
-
slen = snprintf (sname, NIS_MAXNAMELEN,
"[auth_name=%s,auth_type=DES],cred.org_dir.%s",
netname, domain);
@@ -339,8 +335,9 @@ _nss_nisplus_netname2user (char netname[MAXNETNAMELEN + 1], uid_t *uidp,
return NSS_STATUS_UNAVAIL;
}
- slen = sprintf (sname, "[cname=%s,auth_type=LOCAL],cred.org_dir.%s",
- principal, domain);
+ slen = snprintf (sname, sizeof (sname),
+ "[cname=%s,auth_type=LOCAL],cred.org_dir.%s",
+ principal, domain);
if (sname[slen - 1] != '.')
{
diff --git a/nis/nss_nisplus/nisplus-pwd.c b/nis/nss_nisplus/nisplus-pwd.c
index 8f3bc997b3..97679dd349 100644
--- a/nis/nss_nisplus/nisplus-pwd.c
+++ b/nis/nss_nisplus/nisplus-pwd.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997, 1999, 2001, 2002, 2003 Free Software Foundation, Inc.
+/* Copyright (C) 1997,1999,2001,2002,2003,2005 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
@@ -17,6 +17,7 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
+#include <atomic.h>
#include <nss.h>
#include <errno.h>
#include <pwd.h>
@@ -30,27 +31,39 @@
__libc_lock_define_initialized (static, lock)
static nis_result *result;
-static nis_name tablename_val;
-static u_long tablename_len;
+nis_name pwd_tablename_val attribute_hidden;
+size_t pwd_tablename_len attribute_hidden;
-static enum nss_status
-_nss_create_tablename (int *errnop)
+enum nss_status
+_nss_pwd_create_tablename (int *errnop)
{
- if (tablename_val == NULL)
+ if (pwd_tablename_val == NULL)
{
- char buf [40 + strlen (nis_local_directory ())];
- char *p;
+ const char *local_dir = nis_local_directory ();
+ size_t local_dir_len = strlen (local_dir);
+ static const char prefix[] = "passwd.org_dir.";
- p = __stpcpy (buf, "passwd.org_dir.");
- p = __stpcpy (p, nis_local_directory ());
- tablename_val = __strdup (buf);
- if (tablename_val == NULL)
+ char *p = malloc (sizeof (prefix) + local_dir_len);
+ if (pwd_tablename_val == NULL)
{
*errnop = errno;
return NSS_STATUS_TRYAGAIN;
}
- tablename_len = strlen (tablename_val);
+
+ memcpy (__stpcpy (p, prefix), local_dir, local_dir_len + 1);
+
+ pwd_tablename_len = sizeof (prefix) - 1 + local_dir_len;
+
+ atomic_write_barrier ();
+
+ if (atomic_compare_and_exchange_bool_acq (&pwd_tablename_val, p, NULL))
+ {
+ /* Another thread already installed the value. */
+ free (p);
+ pwd_tablename_len = strlen (pwd_tablename_val);
+ }
}
+
return NSS_STATUS_SUCCESS;
}
@@ -59,16 +72,20 @@ enum nss_status
_nss_nisplus_setpwent (int stayopen)
{
enum nss_status status = NSS_STATUS_SUCCESS;
- int err;
__libc_lock_lock (lock);
- if (result)
- nis_freeresult (result);
- result = NULL;
+ if (result != NULL)
+ {
+ nis_freeresult (result);
+ result = NULL;
+ }
- if (tablename_val == NULL)
- status = _nss_create_tablename (&err);
+ if (pwd_tablename_val == NULL)
+ {
+ int err;
+ status = _nss_pwd_create_tablename (&err);
+ }
__libc_lock_unlock (lock);
@@ -80,9 +97,11 @@ _nss_nisplus_endpwent (void)
{
__libc_lock_lock (lock);
- if (result)
- nis_freeresult (result);
- result = NULL;
+ if (result != NULL)
+ {
+ nis_freeresult (result);
+ result = NULL;
+ }
__libc_lock_unlock (lock);
@@ -103,25 +122,22 @@ internal_nisplus_getpwent_r (struct passwd *pw, char *buffer, size_t buflen,
if (result == NULL)
{
saved_res = NULL;
- if (tablename_val == NULL)
+ if (pwd_tablename_val == NULL)
{
- enum nss_status status = _nss_create_tablename (errnop);
+ enum nss_status status = _nss_pwd_create_tablename (errnop);
if (status != NSS_STATUS_SUCCESS)
return status;
}
- result = nis_first_entry (tablename_val);
+ result = nis_first_entry (pwd_tablename_val);
if (niserr2nss (result->status) != NSS_STATUS_SUCCESS)
return niserr2nss (result->status);
}
else
{
- nis_result *res;
-
saved_res = result;
- res = nis_next_entry (tablename_val, &result->cookie);
- result = res;
+ result = nis_next_entry (pwd_tablename_val, &result->cookie);
if (niserr2nss (result->status) != NSS_STATUS_SUCCESS)
{
nis_freeresult (saved_res);
@@ -131,19 +147,18 @@ internal_nisplus_getpwent_r (struct passwd *pw, char *buffer, size_t buflen,
parse_res = _nss_nisplus_parse_pwent (result, pw, buffer,
buflen, errnop);
- if (parse_res == -1)
+ if (__builtin_expect (parse_res == -1, 0))
{
nis_freeresult (result);
result = saved_res;
*errnop = ERANGE;
return NSS_STATUS_TRYAGAIN;
}
- else
- {
- if (saved_res)
- nis_freeresult (saved_res);
- }
- } while (!parse_res);
+
+ if (saved_res)
+ nis_freeresult (saved_res);
+ }
+ while (!parse_res);
return NSS_STATUS_SUCCESS;
}
@@ -169,9 +184,9 @@ _nss_nisplus_getpwnam_r (const char *name, struct passwd *pw,
{
int parse_res;
- if (tablename_val == NULL)
+ if (pwd_tablename_val == NULL)
{
- enum nss_status status = _nss_create_tablename (errnop);
+ enum nss_status status = _nss_pwd_create_tablename (errnop);
if (status != NSS_STATUS_SUCCESS)
return status;
@@ -182,107 +197,107 @@ _nss_nisplus_getpwnam_r (const char *name, struct passwd *pw,
*errnop = EINVAL;
return NSS_STATUS_UNAVAIL;
}
- else
- {
- nis_result *result;
- char buf[strlen (name) + 24 + tablename_len];
- int olderr = errno;
- sprintf (buf, "[name=%s],%s", name, tablename_val);
+ nis_result *result;
+ char buf[strlen (name) + 9 + pwd_tablename_len];
+ int olderr = errno;
- result = nis_list(buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL);
+ snprintf (buf, sizeof (buf), "[name=%s],%s", name, pwd_tablename_val);
- if (result == NULL)
- {
- *errnop = ENOMEM;
- return NSS_STATUS_TRYAGAIN;
- }
- if (niserr2nss (result->status) != NSS_STATUS_SUCCESS)
- {
- enum nss_status status = niserr2nss (result->status);
+ result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL);
- __set_errno (olderr);
+ if (result == NULL)
+ {
+ *errnop = ENOMEM;
+ return NSS_STATUS_TRYAGAIN;
+ }
- nis_freeresult (result);
- return status;
- }
+ if (__builtin_expect (niserr2nss (result->status) != NSS_STATUS_SUCCESS, 0))
+ {
+ enum nss_status status = niserr2nss (result->status);
- parse_res = _nss_nisplus_parse_pwent (result, pw, buffer, buflen,
- errnop);
+ __set_errno (olderr);
nis_freeresult (result);
+ return status;
+ }
+
+ parse_res = _nss_nisplus_parse_pwent (result, pw, buffer, buflen, errnop);
+
+ nis_freeresult (result);
- if (parse_res < 1)
+ if (__builtin_expect (parse_res < 1, 0))
+ {
+ if (parse_res == -1)
{
- if (parse_res == -1)
- {
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
- }
- else
- {
- __set_errno (olderr);
- return NSS_STATUS_NOTFOUND;
- }
+ *errnop = ERANGE;
+ return NSS_STATUS_TRYAGAIN;
+ }
+ else
+ {
+ __set_errno (olderr);
+ return NSS_STATUS_NOTFOUND;
}
- return NSS_STATUS_SUCCESS;
}
+
+ return NSS_STATUS_SUCCESS;
}
enum nss_status
_nss_nisplus_getpwuid_r (const uid_t uid, struct passwd *pw,
char *buffer, size_t buflen, int *errnop)
{
- if (tablename_val == NULL)
+ if (pwd_tablename_val == NULL)
{
- enum nss_status status = _nss_create_tablename (errnop);
+ enum nss_status status = _nss_pwd_create_tablename (errnop);
if (status != NSS_STATUS_SUCCESS)
return status;
}
- {
- int parse_res;
- nis_result *result;
- char buf[100 + tablename_len];
- int olderr = errno;
+ int parse_res;
+ nis_result *result;
+ char buf[8 + 3 * sizeof (unsigned long int) + pwd_tablename_len];
+ int olderr = errno;
- sprintf (buf, "[uid=%lu],%s", (unsigned long int) uid, tablename_val);
+ snprintf (buf, sizeof (buf), "[uid=%lu],%s",
+ (unsigned long int) uid, pwd_tablename_val);
- result = nis_list(buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL);
+ result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL);
- if (result == NULL)
- {
- *errnop = ENOMEM;
- return NSS_STATUS_TRYAGAIN;
- }
- if (niserr2nss (result->status) != NSS_STATUS_SUCCESS)
- {
- enum nss_status status = niserr2nss (result->status);
+ if (result == NULL)
+ {
+ *errnop = ENOMEM;
+ return NSS_STATUS_TRYAGAIN;
+ }
- __set_errno (olderr);
+ if (__builtin_expect (niserr2nss (result->status) != NSS_STATUS_SUCCESS, 0))
+ {
+ enum nss_status status = niserr2nss (result->status);
- nis_freeresult (result);
- return status;
- }
-
- parse_res = _nss_nisplus_parse_pwent (result, pw, buffer, buflen, errnop);
-
- nis_freeresult (result);
-
- if (parse_res < 1)
- {
- if (parse_res == -1)
- {
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
- }
- else
- {
- __set_errno (olderr);
- return NSS_STATUS_NOTFOUND;
- }
- }
- return NSS_STATUS_SUCCESS;
- }
+ __set_errno (olderr);
+
+ nis_freeresult (result);
+ return status;
+ }
+
+ parse_res = _nss_nisplus_parse_pwent (result, pw, buffer, buflen, errnop);
+
+ nis_freeresult (result);
+
+ if (__builtin_expect (parse_res < 1, 0))
+ {
+ if (parse_res == -1)
+ {
+ *errnop = ERANGE;
+ return NSS_STATUS_TRYAGAIN;
+ }
+ else
+ {
+ __set_errno (olderr);
+ return NSS_STATUS_NOTFOUND;
+ }
+ }
+
+ return NSS_STATUS_SUCCESS;
}
diff --git a/nis/nss_nisplus/nisplus-rpc.c b/nis/nss_nisplus/nisplus-rpc.c
index 31d48d17a3..98baa5f7fc 100644
--- a/nis/nss_nisplus/nisplus-rpc.c
+++ b/nis/nss_nisplus/nisplus-rpc.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997, 1998, 2001, 2002, 2003 Free Software Foundation, Inc.
+/* Copyright (C) 1997,1998,2001,2002,2003,2005 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
@@ -17,13 +17,14 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
-#include <nss.h>
-#include <errno.h>
+#include <atomic.h>
#include <ctype.h>
+#include <errno.h>
+#include <nss.h>
#include <string.h>
-#include <bits/libc-lock.h>
#include <rpc/netdb.h>
#include <rpcsvc/nis.h>
+#include <bits/libc-lock.h>
#include "nss-nisplus.h"
@@ -138,19 +139,26 @@ _nss_create_tablename (int *errnop)
{
if (tablename_val == NULL)
{
- char buf [40 + strlen (nis_local_directory ())];
- char *p;
+ const char *local_dir = nis_local_directory ();
+ size_t local_dir_len = strlen (local_dir);
+ static const char prefix[] = "rpc.org_dir.";
- p = __stpcpy (buf, "rpc.org_dir.");
- p = __stpcpy (p, nis_local_directory ());
- tablename_val = __strdup (buf);
+ char *p = malloc (sizeof (prefix) + local_dir_len);
if (tablename_val == NULL)
{
*errnop = errno;
return NSS_STATUS_TRYAGAIN;
}
- tablename_len = strlen (tablename_val);
+
+ memcpy (__stpcpy (p, prefix), local_dir, local_dir_len + 1);
+
+ tablename_len = sizeof (prefix) - 1 + local_dir_len;
+
+ atomic_write_barrier ();
+
+ tablename_val = p;
}
+
return NSS_STATUS_SUCCESS;
}
@@ -159,16 +167,20 @@ enum nss_status
_nss_nisplus_setrpcent (int stayopen)
{
enum nss_status status = NSS_STATUS_SUCCESS;
- int err;
__libc_lock_lock (lock);
- if (result)
- nis_freeresult (result);
- result = NULL;
+ if (result != NULL)
+ {
+ nis_freeresult (result);
+ result = NULL;
+ }
if (tablename_val == NULL)
- status = _nss_create_tablename (&err);
+ {
+ int err;
+ status = _nss_create_tablename (&err);
+ }
__libc_lock_unlock (lock);
@@ -180,9 +192,11 @@ _nss_nisplus_endrpcent (void)
{
__libc_lock_lock (lock);
- if (result)
- nis_freeresult (result);
- result = NULL;
+ if (result != NULL)
+ {
+ nis_freeresult (result);
+ result = NULL;
+ }
__libc_lock_unlock (lock);
@@ -217,11 +231,8 @@ internal_nisplus_getrpcent_r (struct rpcent *rpc, char *buffer,
}
else
{
- nis_result *res;
-
saved_res = result;
- res = nis_next_entry (tablename_val, &result->cookie);
- result = res;
+ result = nis_next_entry (tablename_val, &result->cookie);
if (niserr2nss (result->status) != NSS_STATUS_SUCCESS)
{
nis_freeresult (saved_res);
@@ -243,7 +254,8 @@ internal_nisplus_getrpcent_r (struct rpcent *rpc, char *buffer,
if (saved_res)
nis_freeresult (saved_res);
}
- } while (!parse_res);
+ }
+ while (!parse_res);
return NSS_STATUS_SUCCESS;
}
@@ -271,77 +283,89 @@ _nss_nisplus_getrpcbyname_r (const char *name, struct rpcent *rpc,
if (tablename_val == NULL)
{
+ __libc_lock_lock (lock);
+
enum nss_status status = _nss_create_tablename (errnop);
+ __libc_lock_unlock (lock);
+
if (status != NSS_STATUS_SUCCESS)
return status;
}
if (name == NULL)
return NSS_STATUS_NOTFOUND;
- else
- {
- nis_result *result;
- char buf[strlen (name) + 255 + tablename_len];
- int olderr = errno;
-
- /* Search at first in the alias list, and use the correct name
- for the next search */
- sprintf (buf, "[name=%s],%s", name, tablename_val);
- result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL);
- if (result != NULL)
- {
- /* If we do not find it, try it as original name. But if the
- database is correct, we should find it in the first case, too */
- if ((result->status != NIS_SUCCESS
- && result->status != NIS_S_SUCCESS)
- || __type_of (result->objects.objects_val) != NIS_ENTRY_OBJ
- || strcmp (result->objects.objects_val->EN_data.en_type,
- "rpc_tbl") != 0
- || result->objects.objects_val->EN_data.en_cols.en_cols_len < 3)
- sprintf (buf, "[cname=%s],%s", name, tablename_val);
- else
- sprintf (buf, "[cname=%s],%s", NISENTRYVAL (0, 0, result),
- tablename_val);
+ char buf[strlen (name) + 10 + tablename_len];
+ int olderr = errno;
- nis_freeresult (result);
- result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS , NULL, NULL);
- }
+ /* Search at first in the alias list, and use the correct name
+ for the next search */
+ snprintf (buf, sizeof (buf), "[name=%s],%s", name, tablename_val);
+ nis_result *result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL);
- if (result == NULL)
+ if (result != NULL)
+ {
+ char *bufptr = buf;
+
+ /* If we did not find it, try it as original name. But if the
+ database is correct, we should find it in the first case, too */
+ if ((result->status != NIS_SUCCESS
+ && result->status != NIS_S_SUCCESS)
+ || __type_of (result->objects.objects_val) != NIS_ENTRY_OBJ
+ || strcmp (result->objects.objects_val->EN_data.en_type,
+ "rpc_tbl") != 0
+ || result->objects.objects_val->EN_data.en_cols.en_cols_len < 3)
+ snprintf (buf, sizeof (buf), "[cname=%s],%s", name, tablename_val);
+ else
{
- *errnop = ENOMEM;
- return NSS_STATUS_TRYAGAIN;
+ /* We need to allocate a new buffer since there is no
+ guarantee the returned name has a length limit. */
+ const char *entryval = NISENTRYVAL (0, 0, result);
+ size_t buflen = strlen (entryval) + 10 + tablename_len;
+ bufptr = alloca (buflen);
+ snprintf (bufptr, buflen, "[cname=%s],%s",
+ entryval, tablename_val);
}
- if (niserr2nss (result->status) != NSS_STATUS_SUCCESS)
- {
- enum nss_status status = niserr2nss (result->status);
- __set_errno (olderr);
+ nis_freeresult (result);
+ result = nis_list (bufptr, FOLLOW_PATH | FOLLOW_LINKS , NULL, NULL);
+ }
- nis_freeresult (result);
- return status;
- }
+ if (result == NULL)
+ {
+ *errnop = ENOMEM;
+ return NSS_STATUS_TRYAGAIN;
+ }
- parse_res = _nss_nisplus_parse_rpcent (result, rpc, buffer, buflen,
- errnop);
+ if (__builtin_expect (niserr2nss (result->status) != NSS_STATUS_SUCCESS, 0))
+ {
+ enum nss_status status = niserr2nss (result->status);
+
+ __set_errno (olderr);
nis_freeresult (result);
+ return status;
+ }
- if (parse_res < 1)
- {
- if (parse_res == -1)
- {
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
- }
+ parse_res = _nss_nisplus_parse_rpcent (result, rpc, buffer, buflen,
+ errnop);
- __set_errno (olderr);
- return NSS_STATUS_NOTFOUND;
+ nis_freeresult (result);
+
+ if (parse_res < 1)
+ {
+ if (parse_res == -1)
+ {
+ *errnop = ERANGE;
+ return NSS_STATUS_TRYAGAIN;
}
- return NSS_STATUS_SUCCESS;
+
+ __set_errno (olderr);
+ return NSS_STATUS_NOTFOUND;
}
+
+ return NSS_STATUS_SUCCESS;
}
enum nss_status
@@ -350,55 +374,57 @@ _nss_nisplus_getrpcbynumber_r (const int number, struct rpcent *rpc,
{
if (tablename_val == NULL)
{
+ __libc_lock_lock (lock);
+
enum nss_status status = _nss_create_tablename (errnop);
+ __libc_lock_unlock (lock);
+
if (status != NSS_STATUS_SUCCESS)
return status;
}
- {
- int parse_res;
- nis_result *result;
- char buf[100 + tablename_len];
- int olderr = errno;
+ char buf[12 + 3 * sizeof (number) + tablename_len];
+ int olderr = errno;
+
+ snprintf (buf, sizeof (buf), "[number=%d],%s", number, tablename_val);
+
+ nis_result *result = nis_list (buf, FOLLOW_LINKS | FOLLOW_PATH, NULL, NULL);
+
+ if (result == NULL)
+ {
+ *errnop = ENOMEM;
+ return NSS_STATUS_TRYAGAIN;
+ }
+
+ if (__builtin_expect (niserr2nss (result->status) != NSS_STATUS_SUCCESS, 0))
+ {
+ enum nss_status status = niserr2nss (result->status);
- sprintf (buf, "[number=%d],%s", number, tablename_val);
+ __set_errno (olderr);
- result = nis_list(buf, FOLLOW_LINKS | FOLLOW_PATH, NULL, NULL);
+ nis_freeresult (result);
+ return status;
+ }
- if (result == NULL)
- {
- *errnop = ENOMEM;
- return NSS_STATUS_TRYAGAIN;
- }
- if (niserr2nss (result->status) != NSS_STATUS_SUCCESS)
- {
- enum nss_status status = niserr2nss (result->status);
+ int parse_res = _nss_nisplus_parse_rpcent (result, rpc, buffer, buflen,
+ errnop);
- __set_errno (olderr);
+ nis_freeresult (result);
- nis_freeresult (result);
- return status;
- }
-
- parse_res = _nss_nisplus_parse_rpcent (result, rpc, buffer, buflen,
- errnop);
-
- nis_freeresult (result);
-
- if (parse_res < 1)
- {
- if (parse_res == -1)
- {
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
- }
- else
- {
- __set_errno (olderr);
- return NSS_STATUS_NOTFOUND;
- }
- }
- return NSS_STATUS_SUCCESS;
- }
+ if (parse_res < 1)
+ {
+ if (parse_res == -1)
+ {
+ *errnop = ERANGE;
+ return NSS_STATUS_TRYAGAIN;
+ }
+ else
+ {
+ __set_errno (olderr);
+ return NSS_STATUS_NOTFOUND;
+ }
+ }
+
+ return NSS_STATUS_SUCCESS;
}
diff --git a/nis/nss_nisplus/nisplus-service.c b/nis/nss_nisplus/nisplus-service.c
index fbb6987e9e..848e5f4dd8 100644
--- a/nis/nss_nisplus/nisplus-service.c
+++ b/nis/nss_nisplus/nisplus-service.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997,1998,1999,2001,2002,2003 Free Software Foundation, Inc.
+/* Copyright (C) 1997-1999,2001,2002,2003,2005 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@suse.de>, 1997.
@@ -17,13 +17,14 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
-#include <nss.h>
-#include <errno.h>
+#include <atomic.h>
#include <ctype.h>
+#include <errno.h>
#include <netdb.h>
+#include <nss.h>
#include <string.h>
-#include <bits/libc-lock.h>
#include <rpcsvc/nis.h>
+#include <bits/libc-lock.h>
#include "nss-nisplus.h"
@@ -45,8 +46,6 @@ _nss_nisplus_parse_servent (nis_result *result, struct servent *serv,
{
char *first_unused = buffer;
size_t room_left = buflen;
- unsigned int i;
- char *p, *line;
if (result == NULL)
return 0;
@@ -81,10 +80,10 @@ _nss_nisplus_parse_servent (nis_result *result, struct servent *serv,
first_unused += strlen (first_unused) + 1;
serv->s_port = htons (atoi (NISENTRYVAL (0, 3, result)));
- p = first_unused;
+ char *p = first_unused;
- line = p;
- for (i = 0; i < result->objects.objects_len; ++i)
+ char *line = p;
+ for (unsigned int i = 0; i < result->objects.objects_len; ++i)
{
if (strcmp (NISENTRYVAL (i, 1, result), serv->s_name) != 0)
{
@@ -110,7 +109,7 @@ _nss_nisplus_parse_servent (nis_result *result, struct servent *serv,
room_left -= (sizeof (char *));
serv->s_aliases[0] = NULL;
- i = 0;
+ unsigned int i = 0;
while (*line != '\0')
{
/* Skip leading blanks. */
@@ -147,19 +146,26 @@ _nss_create_tablename (int *errnop)
{
if (tablename_val == NULL)
{
- char buf [40 + strlen (nis_local_directory ())];
- char *p;
+ const char *local_dir = nis_local_directory ();
+ size_t local_dir_len = strlen (local_dir);
+ static const char prefix[] = "services.org_dir.";
- p = __stpcpy (buf, "services.org_dir.");
- p = __stpcpy (p, nis_local_directory ());
- tablename_val = __strdup (buf);
+ char *p = malloc (sizeof (prefix) + local_dir_len);
if (tablename_val == NULL)
{
*errnop = errno;
return NSS_STATUS_TRYAGAIN;
}
- tablename_len = strlen (tablename_val);
+
+ memcpy (__stpcpy (p, prefix), local_dir, local_dir_len + 1);
+
+ tablename_len = sizeof (prefix) - 1 + local_dir_len;
+
+ atomic_write_barrier ();
+
+ tablename_val = p;
}
+
return NSS_STATUS_SUCCESS;
}
@@ -172,9 +178,11 @@ _nss_nisplus_setservent (int stayopen)
__libc_lock_lock (lock);
- if (result)
- nis_freeresult (result);
- result = NULL;
+ if (result != NULL)
+ {
+ nis_freeresult (result);
+ result = NULL;
+ }
if (tablename_val == NULL)
status = _nss_create_tablename (&err);
@@ -189,9 +197,11 @@ _nss_nisplus_endservent (void)
{
__libc_lock_lock (lock);
- if (result)
- nis_freeresult (result);
- result = NULL;
+ if (result != NULL)
+ {
+ nis_freeresult (result);
+ result = NULL;
+ }
__libc_lock_unlock (lock);
@@ -226,11 +236,8 @@ internal_nisplus_getservent_r (struct servent *serv, char *buffer,
}
else
{
- nis_result *res;
-
saved_res = result;
- res = nis_next_entry (tablename_val, &result->cookie);
- result = res;
+ result = nis_next_entry (tablename_val, &result->cookie);
if (niserr2nss (result->status) != NSS_STATUS_SUCCESS)
{
nis_freeresult (saved_res);
@@ -240,7 +247,7 @@ internal_nisplus_getservent_r (struct servent *serv, char *buffer,
parse_res = _nss_nisplus_parse_servent (result, serv, buffer,
buflen, errnop);
- if (parse_res == -1)
+ if (__builtin_expect (parse_res == -1, 0))
{
nis_freeresult (result);
result = saved_res;
@@ -262,11 +269,9 @@ enum nss_status
_nss_nisplus_getservent_r (struct servent *result, char *buffer,
size_t buflen, int *errnop)
{
- int status;
-
__libc_lock_lock (lock);
- status = internal_nisplus_getservent_r (result, buffer, buflen, errnop);
+ int status = internal_nisplus_getservent_r (result, buffer, buflen, errnop);
__libc_lock_unlock (lock);
@@ -278,12 +283,14 @@ _nss_nisplus_getservbyname_r (const char *name, const char *protocol,
struct servent *serv,
char *buffer, size_t buflen, int *errnop)
{
- int parse_res;
-
if (tablename_val == NULL)
{
+ __libc_lock_lock (lock);
+
enum nss_status status = _nss_create_tablename (errnop);
+ __libc_lock_unlock (lock);
+
if (status != NSS_STATUS_SUCCESS)
return status;
}
@@ -293,72 +300,82 @@ _nss_nisplus_getservbyname_r (const char *name, const char *protocol,
*errnop = EINVAL;
return NSS_STATUS_NOTFOUND;
}
- else
- {
- nis_result *result;
- char buf[strlen (name) + 255 + tablename_len];
- int olderr = errno;
- /* Search at first in the alias list, and use the correct name
- for the next search */
- sprintf (buf, "[name=%s,proto=%s],%s", name, protocol,
- tablename_val);
- result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL);
+ size_t protocol_len = strlen (protocol);
+ char buf[strlen (name) + protocol_len + 17 + tablename_len];
+ int olderr = errno;
- if (result != NULL)
- {
- /* If we do not find it, try it as original name. But if the
- database is correct, we should find it in the first case, too */
- if ((result->status != NIS_SUCCESS
- && result->status != NIS_S_SUCCESS)
- || __type_of (result->objects.objects_val) != NIS_ENTRY_OBJ
- || strcmp (result->objects.objects_val->EN_data.en_type,
- "services_tbl") != 0
- || result->objects.objects_val->EN_data.en_cols.en_cols_len < 4)
- sprintf (buf, "[cname=%s,proto=%s],%s", name, protocol,
- tablename_val);
- else
- sprintf (buf, "[cname=%s,proto=%s],%s",
- NISENTRYVAL (0, 0, result), protocol, tablename_val);
-
- nis_freeresult (result);
- result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL);
- }
+ /* Search at first in the alias list, and use the correct name
+ for the next search */
+ snprintf (buf, sizeof (buf), "[name=%s,proto=%s],%s", name, protocol,
+ tablename_val);
+ nis_result *result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL);
- if (result == NULL)
+ if (result != NULL)
+ {
+ char *bufptr = buf;
+
+ /* If we did not find it, try it as original name. But if the
+ database is correct, we should find it in the first case, too */
+ if ((result->status != NIS_SUCCESS
+ && result->status != NIS_S_SUCCESS)
+ || __type_of (result->objects.objects_val) != NIS_ENTRY_OBJ
+ || strcmp (result->objects.objects_val->EN_data.en_type,
+ "services_tbl") != 0
+ || result->objects.objects_val->EN_data.en_cols.en_cols_len < 4)
+ snprintf (buf, sizeof (buf), "[cname=%s,proto=%s],%s", name, protocol,
+ tablename_val);
+ else
{
- *errnop = ENOMEM;
- return NSS_STATUS_TRYAGAIN;
+ /* We need to allocate a new buffer since there is no
+ guarantee the returned name has a length limit. */
+ const char *entryval = NISENTRYVAL(0, 0, result);
+ size_t buflen = (strlen (entryval) + protocol_len + 17
+ + tablename_len);
+ bufptr = alloca (buflen);
+ snprintf (bufptr, buflen, "[cname=%s,proto=%s],%s",
+ entryval, protocol, tablename_val);
}
- if (niserr2nss (result->status) != NSS_STATUS_SUCCESS)
- {
- enum nss_status status = niserr2nss (result->status);
- __set_errno (olderr);
+ nis_freeresult (result);
+ result = nis_list (bufptr, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL);
+ }
- nis_freeresult (result);
- return status;
- }
+ if (result == NULL)
+ {
+ *errnop = ENOMEM;
+ return NSS_STATUS_TRYAGAIN;
+ }
+
+ if (__builtin_expect (niserr2nss (result->status) != NSS_STATUS_SUCCESS, 0))
+ {
+ enum nss_status status = niserr2nss (result->status);
+
+ __set_errno (olderr);
- parse_res = _nss_nisplus_parse_servent (result, serv, buffer, buflen,
- errnop);
nis_freeresult (result);
+ return status;
+ }
+
+ int parse_res = _nss_nisplus_parse_servent (result, serv, buffer, buflen,
+ errnop);
+ nis_freeresult (result);
- if (parse_res < 1)
+ if (__builtin_expect (parse_res < 1, 0))
+ {
+ if (parse_res == -1)
{
- if (parse_res == -1)
- {
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
- }
- else
- {
- __set_errno (olderr);
- return NSS_STATUS_NOTFOUND;
- }
+ *errnop = ERANGE;
+ return NSS_STATUS_TRYAGAIN;
+ }
+ else
+ {
+ __set_errno (olderr);
+ return NSS_STATUS_NOTFOUND;
}
- return NSS_STATUS_SUCCESS;
}
+
+ return NSS_STATUS_SUCCESS;
}
enum nss_status
@@ -368,8 +385,12 @@ _nss_nisplus_getservbyport_r (const int number, const char *protocol,
{
if (tablename_val == NULL)
{
+ __libc_lock_lock (lock);
+
enum nss_status status = _nss_create_tablename (errnop);
+ __libc_lock_unlock (lock);
+
if (status != NSS_STATUS_SUCCESS)
return status;
}
@@ -379,50 +400,48 @@ _nss_nisplus_getservbyport_r (const int number, const char *protocol,
*errnop = EINVAL;
return NSS_STATUS_NOTFOUND;
}
- else
- {
- int parse_res;
- nis_result *result;
- char buf[60 + strlen (protocol) + tablename_len];
- int olderr = errno;
- sprintf (buf, "[port=%d,proto=%s],%s",
- number, protocol, tablename_val);
+ char buf[17 + 3 * sizeof (int) + strlen (protocol) + tablename_len];
+ int olderr = errno;
- result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL);
+ snprintf (buf, sizeof (buf), "[port=%d,proto=%s],%s",
+ number, protocol, tablename_val);
- if (result == NULL)
- {
- *errnop = ENOMEM;
- return NSS_STATUS_TRYAGAIN;
- }
- if (niserr2nss (result->status) != NSS_STATUS_SUCCESS)
- {
- enum nss_status status = niserr2nss (result->status);
+ nis_result *result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL);
- __set_errno (olderr);
+ if (result == NULL)
+ {
+ *errnop = ENOMEM;
+ return NSS_STATUS_TRYAGAIN;
+ }
- nis_freeresult (result);
- return status;
- }
+ if (__builtin_expect (niserr2nss (result->status) != NSS_STATUS_SUCCESS, 0))
+ {
+ enum nss_status status = niserr2nss (result->status);
+
+ __set_errno (olderr);
- parse_res = _nss_nisplus_parse_servent (result, serv, buffer, buflen,
- errnop);
nis_freeresult (result);
+ return status;
+ }
+
+ int parse_res = _nss_nisplus_parse_servent (result, serv, buffer, buflen,
+ errnop);
+ nis_freeresult (result);
- if (parse_res < 1)
+ if (__builtin_expect (parse_res < 1, 0))
+ {
+ if (parse_res == -1)
{
- if (parse_res == -1)
- {
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
- }
- else
- {
- __set_errno (olderr);
- return NSS_STATUS_NOTFOUND;
- }
+ *errnop = ERANGE;
+ return NSS_STATUS_TRYAGAIN;
+ }
+ else
+ {
+ __set_errno (olderr);
+ return NSS_STATUS_NOTFOUND;
}
- return NSS_STATUS_SUCCESS;
}
+
+ return NSS_STATUS_SUCCESS;
}
diff --git a/nis/nss_nisplus/nisplus-spwd.c b/nis/nss_nisplus/nisplus-spwd.c
index c317469137..8584300698 100644
--- a/nis/nss_nisplus/nisplus-spwd.c
+++ b/nis/nss_nisplus/nisplus-spwd.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997, 2001, 2002, 2003 Free Software Foundation, Inc.
+/* Copyright (C) 1997, 2001, 2002, 2003, 2005 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
@@ -30,29 +30,12 @@
__libc_lock_define_initialized (static, lock)
static nis_result *result;
-static nis_name tablename_val;
-static u_long tablename_len;
-static enum nss_status
-_nss_create_tablename (int *errnop)
-{
- if (tablename_val == NULL)
- {
- char buf [40 + strlen (nis_local_directory ())];
- char *p;
+/* Defined in nisplus-pwd.c. */
+extern nis_name pwd_tablename_val attribute_hidden;
+extern size_t pwd_tablename_len attribute_hidden;
+extern enum nss_status _nss_pwd_create_tablename (int *errnop);
- p = __stpcpy (buf, "passwd.org_dir.");
- p = __stpcpy (p, nis_local_directory ());
- tablename_val = __strdup (buf);
- if (tablename_val == NULL)
- {
- *errnop = errno;
- return NSS_STATUS_TRYAGAIN;
- }
- tablename_len = strlen (tablename_val);
- }
- return NSS_STATUS_SUCCESS;
-}
enum nss_status
_nss_nisplus_setspent (int stayopen)
@@ -62,12 +45,14 @@ _nss_nisplus_setspent (int stayopen)
__libc_lock_lock (lock);
- if (result)
- nis_freeresult (result);
- result = NULL;
+ if (result != NULL)
+ {
+ nis_freeresult (result);
+ result = NULL;
+ }
- if (tablename_val == NULL)
- status = _nss_create_tablename (&err);
+ if (pwd_tablename_val == NULL)
+ status = _nss_pwd_create_tablename (&err);
__libc_lock_unlock (lock);
@@ -79,9 +64,11 @@ _nss_nisplus_endspent (void)
{
__libc_lock_lock (lock);
- if (result)
- nis_freeresult (result);
- result = NULL;
+ if (result != NULL)
+ {
+ nis_freeresult (result);
+ result = NULL;
+ }
__libc_lock_unlock (lock);
@@ -103,25 +90,22 @@ internal_nisplus_getspent_r (struct spwd *sp, char *buffer, size_t buflen,
{
saved_res = NULL;
- if (tablename_val == NULL)
+ if (pwd_tablename_val == NULL)
{
- enum nss_status status = _nss_create_tablename (errnop);
+ enum nss_status status = _nss_pwd_create_tablename (errnop);
if (status != NSS_STATUS_SUCCESS)
return status;
}
- result = nis_first_entry (tablename_val);
+ result = nis_first_entry (pwd_tablename_val);
if (niserr2nss (result->status) != NSS_STATUS_SUCCESS)
return niserr2nss (result->status);
}
else
{
- nis_result *res;
-
saved_res = result;
- res = nis_next_entry (tablename_val, &result->cookie);
- result = res;
+ result = nis_next_entry (pwd_tablename_val, &result->cookie);
if (niserr2nss (result->status) != NSS_STATUS_SUCCESS)
{
nis_freeresult (saved_res);
@@ -131,19 +115,18 @@ internal_nisplus_getspent_r (struct spwd *sp, char *buffer, size_t buflen,
parse_res = _nss_nisplus_parse_spent (result, sp, buffer,
buflen, errnop);
- if (parse_res == -1)
+ if (__builtin_expect (parse_res == -1, 0))
{
nis_freeresult (result);
result = saved_res;
*errnop = ERANGE;
return NSS_STATUS_TRYAGAIN;
}
- else
- {
- if (saved_res)
- nis_freeresult (saved_res);
- }
- } while (!parse_res);
+
+ if (saved_res != NULL)
+ nis_freeresult (saved_res);
+ }
+ while (!parse_res);
return NSS_STATUS_SUCCESS;
}
@@ -169,9 +152,9 @@ _nss_nisplus_getspnam_r (const char *name, struct spwd *sp,
{
int parse_res;
- if (tablename_val == NULL)
+ if (pwd_tablename_val == NULL)
{
- enum nss_status status = _nss_create_tablename (errnop);
+ enum nss_status status = _nss_pwd_create_tablename (errnop);
if (status != NSS_STATUS_SUCCESS)
return status;
@@ -182,48 +165,47 @@ _nss_nisplus_getspnam_r (const char *name, struct spwd *sp,
*errnop = EINVAL;
return NSS_STATUS_NOTFOUND;
}
- else
- {
- nis_result *result;
- char buf[strlen (name) + 24 + tablename_len];
- int olderr = errno;
- sprintf (buf, "[name=%s],%s", name, tablename_val);
+ nis_result *result;
+ char buf[strlen (name) + 9 + pwd_tablename_len];
+ int olderr = errno;
- result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL);
+ snprintf (buf, sizeof (buf), "[name=%s],%s", name, pwd_tablename_val);
- if (result == NULL)
- {
- *errnop = ENOMEM;
- return NSS_STATUS_TRYAGAIN;
- }
- if (niserr2nss (result->status) != NSS_STATUS_SUCCESS)
- {
- enum nss_status status = niserr2nss (result->status);
+ result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL);
- __set_errno (olderr);
+ if (result == NULL)
+ {
+ *errnop = ENOMEM;
+ return NSS_STATUS_TRYAGAIN;
+ }
- nis_freeresult (result);
- return status;
- }
+ if (__builtin_expect (niserr2nss (result->status) != NSS_STATUS_SUCCESS, 0))
+ {
+ enum nss_status status = niserr2nss (result->status);
+
+ __set_errno (olderr);
- parse_res = _nss_nisplus_parse_spent (result, sp, buffer, buflen,
- errnop);
nis_freeresult (result);
+ return status;
+ }
- if (parse_res < 1)
+ parse_res = _nss_nisplus_parse_spent (result, sp, buffer, buflen, errnop);
+ nis_freeresult (result);
+
+ if (__builtin_expect (parse_res < 1, 0))
+ {
+ if (parse_res == -1)
{
- if (parse_res == -1)
- {
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
- }
- else
- {
- __set_errno (olderr);
- return NSS_STATUS_NOTFOUND;
- }
+ *errnop = ERANGE;
+ return NSS_STATUS_TRYAGAIN;
+ }
+ else
+ {
+ __set_errno (olderr);
+ return NSS_STATUS_NOTFOUND;
}
- return NSS_STATUS_SUCCESS;
}
+
+ return NSS_STATUS_SUCCESS;
}
diff --git a/nis/ypclnt.c b/nis/ypclnt.c
index 6230cb84dc..66095667c6 100644
--- a/nis/ypclnt.c
+++ b/nis/ypclnt.c
@@ -46,12 +46,12 @@ struct dom_binding
};
typedef struct dom_binding dom_binding;
-static struct timeval RPCTIMEOUT = {25, 0};
-static struct timeval UDPTIMEOUT = {5, 0};
+static const struct timeval RPCTIMEOUT = {25, 0};
+static const struct timeval UDPTIMEOUT = {5, 0};
static int const MAXTRIES = 2;
-static char __ypdomainname[NIS_MAXNAMELEN + 1] = "\0";
+static char ypdomainname[NIS_MAXNAMELEN + 1];
__libc_lock_define_initialized (static, ypbindlist_lock)
-static dom_binding *__ypbindlist = NULL;
+static dom_binding *ypbindlist = NULL;
static void
@@ -111,8 +111,8 @@ yp_bind_ypbindprog (const char *domain, dom_binding *ysd)
int clnt_sock;
CLIENT *client;
- memset (&clnt_saddr, '\0', sizeof clnt_saddr);
clnt_saddr.sin_family = AF_INET;
+ clnt_saddr.sin_port = 0;
clnt_saddr.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
clnt_sock = RPC_ANYSOCK;
client = clnttcp_create (&clnt_saddr, YPBINDPROG, YPBINDVERS,
@@ -142,7 +142,7 @@ yp_bind_ypbindprog (const char *domain, dom_binding *ysd)
if (ypbr.ypbind_status != YPBIND_SUCC_VAL)
{
- fprintf (stderr, _("YPBINDPROC_DOMAIN: %s\n"),
+ fprintf (stderr, "YPBINDPROC_DOMAIN: %s\n",
ypbinderr_string (ypbr.ypbind_resp_u.ypbind_error));
return YPERR_DOMAIN;
}
@@ -225,7 +225,7 @@ yp_bind (const char *indomain)
__libc_lock_lock (ypbindlist_lock);
- status = __yp_bind (indomain, &__ypbindlist);
+ status = __yp_bind (indomain, &ypbindlist);
__libc_lock_unlock (ypbindlist_lock);
@@ -239,7 +239,7 @@ yp_unbind_locked (const char *indomain)
dom_binding *ydbptr, *ydbptr2;
ydbptr2 = NULL;
- ydbptr = __ypbindlist;
+ ydbptr = ypbindlist;
while (ydbptr != NULL)
{
@@ -249,7 +249,7 @@ yp_unbind_locked (const char *indomain)
work = ydbptr;
if (ydbptr2 == NULL)
- __ypbindlist = __ypbindlist->dom_pnext;
+ ypbindlist = ypbindlist->dom_pnext;
else
ydbptr2 = ydbptr->dom_pnext;
__yp_unbind (work);
@@ -306,7 +306,7 @@ do_ypcall (const char *domain, u_long prog, xdrproc_t xargs,
status = YPERR_YPERR;
__libc_lock_lock (ypbindlist_lock);
- ydb = __ypbindlist;
+ ydb = ypbindlist;
while (ydb != NULL)
{
if (strcmp (domain, ydb->dom_domain) == 0)
@@ -349,7 +349,7 @@ do_ypcall (const char *domain, u_long prog, xdrproc_t xargs,
if (status != YPERR_SUCCESS)
{
ydb = calloc (1, sizeof (dom_binding));
- if (yp_bind_ypbindprog (domain, ydb) == YPERR_SUCCESS)
+ if (ydb != NULL && yp_bind_ypbindprog (domain, ydb) == YPERR_SUCCESS)
{
status = __ypclnt_call (domain, prog, xargs, req, xres,
resp, &ydb, 1);
@@ -365,6 +365,21 @@ do_ypcall (const char *domain, u_long prog, xdrproc_t xargs,
return status;
}
+/* Like do_ypcall, but translate the status value if necessary. */
+static int
+do_ypcall_tr (const char *domain, u_long prog, xdrproc_t xargs,
+ caddr_t req, xdrproc_t xres, caddr_t resp)
+{
+ int status = do_ypcall (domain, prog, xargs, req, xres, resp);
+ if (status == YPERR_SUCCESS)
+ /* We cast to ypresp_val although the pointer could also be of
+ type ypresp_key_val or ypresp_master or ypresp_order or
+ ypresp_maplist. But the stat element is in a common prefix so
+ this does not matter. */
+ status = ypprot_err (((struct ypresp_val *) resp)->stat);
+ return status;
+}
+
__libc_lock_define_initialized (static, domainname_lock)
@@ -376,21 +391,21 @@ yp_get_default_domain (char **outdomain)
__libc_lock_lock (domainname_lock);
- if (__ypdomainname[0] == '\0')
+ if (ypdomainname[0] == '\0')
{
- if (getdomainname (__ypdomainname, NIS_MAXNAMELEN))
+ if (getdomainname (ypdomainname, NIS_MAXNAMELEN))
result = YPERR_NODOM;
- else if (strcmp (__ypdomainname, "(none)") == 0)
+ else if (strcmp (ypdomainname, "(none)") == 0)
{
/* If domainname is not set, some systems will return "(none)" */
- __ypdomainname[0] = '\0';
+ ypdomainname[0] = '\0';
result = YPERR_NODOM;
}
else
- *outdomain = __ypdomainname;
+ *outdomain = ypdomainname;
}
else
- *outdomain = __ypdomainname;
+ *outdomain = ypdomainname;
__libc_lock_unlock (domainname_lock);
@@ -403,14 +418,14 @@ __yp_check (char **domain)
{
char *unused;
- if (__ypdomainname[0] == '\0')
+ if (ypdomainname[0] == '\0')
if (yp_get_default_domain (&unused))
return 0;
if (domain)
- *domain = __ypdomainname;
+ *domain = ypdomainname;
- if (yp_bind (__ypdomainname) == 0)
+ if (yp_bind (ypdomainname) == 0)
return 1;
return 0;
}
@@ -437,25 +452,26 @@ yp_match (const char *indomain, const char *inmap, const char *inkey,
*outvallen = 0;
memset (&resp, '\0', sizeof (resp));
- result = do_ypcall (indomain, YPPROC_MATCH, (xdrproc_t) xdr_ypreq_key,
- (caddr_t) & req, (xdrproc_t) xdr_ypresp_val,
- (caddr_t) & resp);
+ result = do_ypcall_tr (indomain, YPPROC_MATCH, (xdrproc_t) xdr_ypreq_key,
+ (caddr_t) &req, (xdrproc_t) xdr_ypresp_val,
+ (caddr_t) &resp);
if (result != YPERR_SUCCESS)
return result;
- if (resp.stat != YP_TRUE)
- return ypprot_err (resp.stat);
*outvallen = resp.val.valdat_len;
*outval = malloc (*outvallen + 1);
- if (__builtin_expect (*outval == NULL, 0))
- return YPERR_RESRC;
- memcpy (*outval, resp.val.valdat_val, *outvallen);
- (*outval)[*outvallen] = '\0';
+ int status = YPERR_RESRC;
+ if (__builtin_expect (*outval != NULL, 1))
+ {
+ memcpy (*outval, resp.val.valdat_val, *outvallen);
+ (*outval)[*outvallen] = '\0';
+ status = YPERR_SUCCESS;
+ }
xdr_free ((xdrproc_t) xdr_ypresp_val, (char *) &resp);
- return YPERR_SUCCESS;
+ return status;
}
int
@@ -478,30 +494,38 @@ yp_first (const char *indomain, const char *inmap, char **outkey,
memset (&resp, '\0', sizeof (resp));
result = do_ypcall (indomain, YPPROC_FIRST, (xdrproc_t) xdr_ypreq_nokey,
- (caddr_t) & req, (xdrproc_t) xdr_ypresp_key_val,
- (caddr_t) & resp);
+ (caddr_t) &req, (xdrproc_t) xdr_ypresp_key_val,
+ (caddr_t) &resp);
if (result != RPC_SUCCESS)
return YPERR_RPC;
if (resp.stat != YP_TRUE)
return ypprot_err (resp.stat);
- *outkeylen = resp.key.keydat_len;
- *outkey = malloc (*outkeylen + 1);
- if (__builtin_expect (*outkey == NULL, 0))
- return YPERR_RESRC;
- memcpy (*outkey, resp.key.keydat_val, *outkeylen);
- (*outkey)[*outkeylen] = '\0';
- *outvallen = resp.val.valdat_len;
- *outval = malloc (*outvallen + 1);
- if (__builtin_expect (*outval == NULL, 0))
- return YPERR_RESRC;
- memcpy (*outval, resp.val.valdat_val, *outvallen);
- (*outval)[*outvallen] = '\0';
+ int status;
+ if (__builtin_expect ((*outkey = malloc (resp.key.keydat_len + 1)) != NULL
+ && (*outval = malloc (resp.val.valdat_len
+ + 1)) != NULL, 1))
+ {
+ *outkeylen = resp.key.keydat_len;
+ memcpy (*outkey, resp.key.keydat_val, *outkeylen);
+ (*outkey)[*outkeylen] = '\0';
+
+ *outvallen = resp.val.valdat_len;
+ memcpy (*outval, resp.val.valdat_val, *outvallen);
+ (*outval)[*outvallen] = '\0';
+
+ status = YPERR_SUCCESS;
+ }
+ else
+ {
+ free (*outkey);
+ status = YPERR_RESRC;
+ }
xdr_free ((xdrproc_t) xdr_ypresp_key_val, (char *) &resp);
- return YPERR_SUCCESS;
+ return status;
}
int
@@ -527,31 +551,37 @@ yp_next (const char *indomain, const char *inmap, const char *inkey,
*outkeylen = *outvallen = 0;
memset (&resp, '\0', sizeof (resp));
- result = do_ypcall (indomain, YPPROC_NEXT, (xdrproc_t) xdr_ypreq_key,
- (caddr_t) & req, (xdrproc_t) xdr_ypresp_key_val,
- (caddr_t) & resp);
+ result = do_ypcall_tr (indomain, YPPROC_NEXT, (xdrproc_t) xdr_ypreq_key,
+ (caddr_t) &req, (xdrproc_t) xdr_ypresp_key_val,
+ (caddr_t) &resp);
if (result != YPERR_SUCCESS)
return result;
- if (resp.stat != YP_TRUE)
- return ypprot_err (resp.stat);
- *outkeylen = resp.key.keydat_len;
- *outkey = malloc (*outkeylen + 1);
- if (__builtin_expect (*outkey == NULL, 0))
- return YPERR_RESRC;
- memcpy (*outkey, resp.key.keydat_val, *outkeylen);
- (*outkey)[*outkeylen] = '\0';
- *outvallen = resp.val.valdat_len;
- *outval = malloc (*outvallen + 1);
- if (__builtin_expect (*outval == NULL, 0))
- return YPERR_RESRC;
- memcpy (*outval, resp.val.valdat_val, *outvallen);
- (*outval)[*outvallen] = '\0';
+ int status;
+ if (__builtin_expect ((*outkey = malloc (resp.key.keydat_len + 1)) != NULL
+ && (*outval = malloc (resp.val.valdat_len
+ + 1)) != NULL, 1))
+ {
+ *outkeylen = resp.key.keydat_len;
+ memcpy (*outkey, resp.key.keydat_val, *outkeylen);
+ (*outkey)[*outkeylen] = '\0';
+
+ *outvallen = resp.val.valdat_len;
+ memcpy (*outval, resp.val.valdat_val, *outvallen);
+ (*outval)[*outvallen] = '\0';
+
+ status = YPERR_SUCCESS;
+ }
+ else
+ {
+ free (*outkey);
+ status = YPERR_RESRC;
+ }
xdr_free ((xdrproc_t) xdr_ypresp_key_val, (char *) &resp);
- return YPERR_SUCCESS;
+ return status;
}
int
@@ -570,13 +600,12 @@ yp_master (const char *indomain, const char *inmap, char **outname)
memset (&resp, '\0', sizeof (ypresp_master));
- result = do_ypcall (indomain, YPPROC_MASTER, (xdrproc_t) xdr_ypreq_nokey,
- (caddr_t) & req, (xdrproc_t) xdr_ypresp_master, (caddr_t) & resp);
+ result = do_ypcall_tr (indomain, YPPROC_MASTER, (xdrproc_t) xdr_ypreq_nokey,
+ (caddr_t) &req, (xdrproc_t) xdr_ypresp_master,
+ (caddr_t) &resp);
if (result != YPERR_SUCCESS)
return result;
- if (resp.stat != YP_TRUE)
- return ypprot_err (resp.stat);
*outname = strdup (resp.peer);
xdr_free ((xdrproc_t) xdr_ypresp_master, (char *) &resp);
@@ -593,7 +622,7 @@ yp_order (const char *indomain, const char *inmap, unsigned int *outorder)
enum clnt_stat result;
if (indomain == NULL || indomain[0] == '\0' ||
- inmap == NULL || inmap == '\0')
+ inmap == NULL || inmap[0] == '\0')
return YPERR_BADARGS;
req.domain = (char *) indomain;
@@ -601,18 +630,17 @@ yp_order (const char *indomain, const char *inmap, unsigned int *outorder)
memset (&resp, '\0', sizeof (resp));
- result = do_ypcall (indomain, YPPROC_ORDER, (xdrproc_t) xdr_ypreq_nokey,
- (caddr_t) & req, (xdrproc_t) xdr_ypresp_order, (caddr_t) & resp);
+ result = do_ypcall_tr (indomain, YPPROC_ORDER, (xdrproc_t) xdr_ypreq_nokey,
+ (caddr_t) &req, (xdrproc_t) xdr_ypresp_order,
+ (caddr_t) &resp);
- if (result != YPERR_SUCCESS)
+ if (result == YPERR_SUCCESS)
return result;
- if (resp.stat != YP_TRUE)
- return ypprot_err (resp.stat);
*outorder = resp.ordernum;
xdr_free ((xdrproc_t) xdr_ypresp_order, (char *) &resp);
- return YPERR_SUCCESS;
+ return result;
}
struct ypresp_all_data
@@ -694,8 +722,8 @@ yp_all (const char *indomain, const char *inmap,
int clnt_sock;
int saved_errno = errno;
- if (indomain == NULL || indomain[0] == '\0' ||
- inmap == NULL || inmap == '\0')
+ if (indomain == NULL || indomain[0] == '\0'
+ || inmap == NULL || inmap[0] == '\0')
return YPERR_BADARGS;
try = 0;
@@ -733,9 +761,9 @@ yp_all (const char *indomain, const char *inmap,
(caddr_t) &req, (xdrproc_t) __xdr_ypresp_all,
(caddr_t) &data, RPCTIMEOUT);
- if (result != RPC_SUCCESS)
+ if (__builtin_expect (result != RPC_SUCCESS, 0))
{
- /* Print the error message only on the last try */
+ /* Print the error message only on the last try. */
if (try == MAXTRIES - 1)
clnt_perror (clnt, "yp_all: clnt_call");
res = YPERR_RPC;
@@ -759,6 +787,7 @@ yp_all (const char *indomain, const char *inmap,
}
int
+
yp_maplist (const char *indomain, struct ypmaplist **outmaplist)
{
struct ypresp_maplist resp;
@@ -769,62 +798,82 @@ yp_maplist (const char *indomain, struct ypmaplist **outmaplist)
memset (&resp, '\0', sizeof (resp));
- result = do_ypcall (indomain, YPPROC_MAPLIST, (xdrproc_t) xdr_domainname,
- (caddr_t) & indomain, (xdrproc_t) xdr_ypresp_maplist, (caddr_t) & resp);
-
- if (result != YPERR_SUCCESS)
- return result;
- if (resp.stat != YP_TRUE)
- return ypprot_err (resp.stat);
+ result = do_ypcall_tr (indomain, YPPROC_MAPLIST, (xdrproc_t) xdr_domainname,
+ (caddr_t) &indomain, (xdrproc_t) xdr_ypresp_maplist,
+ (caddr_t) &resp);
- *outmaplist = resp.maps;
- /* We give the list not free, this will be done by ypserv
- xdr_free((xdrproc_t)xdr_ypresp_maplist, (char *)&resp); */
+ if (__builtin_expect (result == YPERR_SUCCESS, 1))
+ {
+ *outmaplist = resp.maps;
+ /* We don't free the list, this will be done by ypserv
+ xdr_free((xdrproc_t)xdr_ypresp_maplist, (char *)&resp); */
+ }
- return YPERR_SUCCESS;
+ return result;
}
const char *
yperr_string (const int error)
{
+ const char *str;
switch (error)
{
case YPERR_SUCCESS:
- return _("Success");
+ str = "Success";
+ break;
case YPERR_BADARGS:
- return _("Request arguments bad");
+ str = "Request arguments bad";
+ break;
case YPERR_RPC:
- return _("RPC failure on NIS operation");
+ str = "RPC failure on NIS operation";
+ break;
case YPERR_DOMAIN:
- return _("Can't bind to server which serves this domain");
+ str = "Can't bind to server which serves this domain";
+ break;
case YPERR_MAP:
- return _("No such map in server's domain");
+ str = "No such map in server's domain";
+ break;
case YPERR_KEY:
- return _("No such key in map");
+ str = "No such key in map";
+ break;
case YPERR_YPERR:
- return _("Internal NIS error");
+ str = "Internal NIS error";
+ break;
case YPERR_RESRC:
- return _("Local resource allocation failure");
+ str = "Local resource allocation failure";
+ break;
case YPERR_NOMORE:
- return _("No more records in map database");
+ str = "No more records in map database";
+ break;
case YPERR_PMAP:
- return _("Can't communicate with portmapper");
+ str = "Can't communicate with portmapper";
+ break;
case YPERR_YPBIND:
- return _("Can't communicate with ypbind");
+ str = "Can't communicate with ypbind";
+ break;
case YPERR_YPSERV:
- return _("Can't communicate with ypserv");
+ str = "Can't communicate with ypserv";
+ break;
case YPERR_NODOM:
- return _("Local domain name not set");
+ str = "Local domain name not set";
+ break;
case YPERR_BADDB:
- return _("NIS map database is bad");
+ str = "NIS map database is bad";
+ break;
case YPERR_VERS:
- return _("NIS client/server version mismatch - can't supply service");
+ str = "NIS client/server version mismatch - can't supply service";
+ break;
case YPERR_ACCESS:
- return _("Permission denied");
+ str = "Permission denied";
+ break;
case YPERR_BUSY:
- return _("Database is busy");
+ str = "Database is busy";
+ break;
+ default:
+ str = "Unknown NIS error code";
+ break;
}
- return _("Unknown NIS error code");
+ return _(str);
}
static const int8_t yp_2_yperr[] =
@@ -854,19 +903,26 @@ libnsl_hidden_def (ypprot_err)
const char *
ypbinderr_string (const int error)
{
+ const char *str;
switch (error)
{
case 0:
- return _("Success");
+ str = "Success";
+ break;
case YPBIND_ERR_ERR:
- return _("Internal ypbind error");
+ str = "Internal ypbind error";
+ break;
case YPBIND_ERR_NOSERV:
- return _("Domain not bound");
+ str = "Domain not bound";
+ break;
case YPBIND_ERR_RESC:
- return _("System resource allocation failure");
+ str = "System resource allocation failure";
+ break;
default:
- return _("Unknown ypbind error");
+ str = "Unknown ypbind error";
+ break;
}
+ return _(str);
}
libnsl_hidden_def (ypbinderr_string)
@@ -948,6 +1004,7 @@ again:
{
if (clnt->cl_auth->ah_cred.oa_flavor == AUTH_DES)
{
+ auth_destroy (clnt->cl_auth);
clnt->cl_auth = authunix_create_default ();
goto again;
}