summaryrefslogtreecommitdiff
path: root/nis
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2006-05-11 14:01:43 +0000
committerJakub Jelinek <jakub@redhat.com>2006-05-11 14:01:43 +0000
commit3ec0d26c76d6905501034692d05bddbabae64e76 (patch)
tree191efcdfd934a0369cdef723fe4f650fe2f3dcfc /nis
parent262cf6b3df91d5bb7cbdcae2390333b21e8008d5 (diff)
Updated to fedora-glibc-20060511T1325cvs/fedora-glibc-2_4_90-7
Diffstat (limited to 'nis')
-rw-r--r--nis/nis_creategroup.c4
-rw-r--r--nis/nis_defaults.c125
-rw-r--r--nis/nis_lookup.c35
-rw-r--r--nis/nss-nis.h4
-rw-r--r--nis/nss-nisplus.h6
-rw-r--r--nis/nss_nis/nis-service.c29
6 files changed, 92 insertions, 111 deletions
diff --git a/nis/nis_creategroup.c b/nis/nis_creategroup.c
index a7808abf4b..0e9e13d5e5 100644
--- a/nis/nis_creategroup.c
+++ b/nis/nis_creategroup.c
@@ -52,8 +52,8 @@ nis_creategroup (const_nis_name group, unsigned int flags)
obj->zo_oid.ctime = obj->zo_oid.mtime = time (NULL);
obj->zo_name = strdup (leafbuf);
- obj->zo_owner = strdup (__nis_default_owner (NULL));
- obj->zo_group = strdup (__nis_default_group (NULL));
+ obj->zo_owner = __nis_default_owner (NULL);
+ obj->zo_group = __nis_default_group (NULL);
obj->zo_domain = strdup (domainbuf);
if (obj->zo_name == NULL || obj->zo_owner == NULL
|| obj->zo_group == NULL || obj->zo_domain == NULL)
diff --git a/nis/nis_defaults.c b/nis/nis_defaults.c
index f13578635a..59fbbe4b26 100644
--- a/nis/nis_defaults.c
+++ b/nis/nis_defaults.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 1997, 1998, 2004 Free Software Foundation, Inc.
+/* Copyright (c) 1997, 1998, 2004, 2006 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 <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -30,45 +31,36 @@
** Some functions for parsing the -D param and NIS_DEFAULTS Environ
*/
static nis_name
-searchgroup (char *str)
+searchXYX (char *str, const char *what)
{
- char *cptr;
- int i;
+ assert (strlen (what) == 6);
+ assert (strncmp (str, what, 6) == 0);
+ str += 6; /* Points to the begin of the parameters. */
+
+ int i = 0;
+ while (str[i] != '\0' && str[i] != ':')
+ ++i;
+ if (i == 0) /* only "<WHAT>=" ? */
+ return strdup ("");
- cptr = strstr (str, "group=");
- if (cptr == NULL)
- return NULL;
+ return strndup (str, i);
+}
- cptr += 6; /* points to the begin of the group string */
- i = 0;
- while (cptr[i] != '\0' && cptr[i] != ':')
- i++;
- if (i == 0) /* only "group=" ? */
- return (nis_name) "";
- return strndup (cptr, i);
+static nis_name
+searchgroup (char *str)
+{
+ return searchXYX (str, "group=");
}
+
static nis_name
searchowner (char *str)
{
- char *cptr;
- int i;
-
- cptr = strstr (str, "owner=");
- if (cptr == NULL)
- return NULL;
-
- cptr += 6; /* points to the begin of the owner string */
- i = 0;
- while (cptr[i] != '\0' && cptr[i] != ':')
- i++;
- if (i == 0) /* only "owner=" ? */
- return strdup ("");
-
- return strndup (cptr, i);
+ return searchXYX (str, "owner=");
}
+
static uint32_t
searchttl (char *str)
{
@@ -358,86 +350,61 @@ searchaccess (char *str, unsigned int access)
return result;
}
+
nis_name
__nis_default_owner (char *defaults)
{
- char default_owner[NIS_MAXNAMELEN + 1];
- char *cptr, *dptr;
+ char *default_owner = NULL;
- strcpy (default_owner, nis_local_principal ());
+ char *cptr = defaults;
+ if (cptr == NULL)
+ cptr = getenv ("NIS_DEFAULTS");
- if (defaults != NULL)
+ if (cptr != NULL)
{
- dptr = strstr (defaults, "owner=");
+ char *dptr = strstr (cptr, "owner=");
if (dptr != NULL)
{
- char *p = searchowner (defaults);
- if (strlen (p) <= NIS_MAXNAMELEN)
- strcpy (default_owner, p);
+ char *p = searchowner (dptr);
+ if (p == NULL)
+ return NULL;
+ default_owner = strdupa (p);
free (p);
}
}
- else
- {
- cptr = getenv ("NIS_DEFAULTS");
- if (cptr != NULL)
- {
- dptr = strstr (cptr, "owner=");
- if (dptr != NULL)
- {
- char *p = searchowner (cptr);
- if (strlen (p) <= NIS_MAXNAMELEN)
- strcpy (default_owner, p);
- free (p);
- }
- }
- }
- return strdup (default_owner);
+ return strdup (default_owner ?: nis_local_principal ());
}
libnsl_hidden_def (__nis_default_owner)
+
nis_name
__nis_default_group (char *defaults)
{
- char default_group[NIS_MAXNAMELEN + 1];
- char *cptr, *dptr;
+ char *default_group = NULL;
- strcpy (default_group, nis_local_group ());
+ char *cptr = defaults;
+ if (cptr == NULL)
+ cptr = getenv ("NIS_DEFAULTS");
- if (defaults != NULL)
+ if (cptr != NULL)
{
- dptr = strstr (defaults, "group=");
+ char *dptr = strstr (cptr, "group=");
if (dptr != NULL)
{
- char *p = searchgroup (defaults);
-
- if (strlen (p) <= NIS_MAXNAMELEN)
- strcpy (default_group, p);
+ char *p = searchgroup (dptr);
+ if (p == NULL)
+ return NULL;
+ default_group = strdupa (p);
free (p);
}
}
- else
- {
- cptr = getenv ("NIS_DEFAULTS");
- if (cptr != NULL)
- {
- dptr = strstr (cptr, "group=");
- if (dptr != NULL)
- {
- char *p = searchgroup (cptr);
-
- if (strlen (p) <= NIS_MAXNAMELEN)
- strcpy (default_group, p);
- free (p);
- }
- }
- }
- return strdup (default_group);
+ return strdup (default_group ?: nis_local_group ());
}
libnsl_hidden_def (__nis_default_group)
+
uint32_t
__nis_default_ttl (char *defaults)
{
diff --git a/nis/nis_lookup.c b/nis/nis_lookup.c
index 4cb34dd1a8..821b9bce73 100644
--- a/nis/nis_lookup.c
+++ b/nis/nis_lookup.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997, 1998, 1999, 2004, 2005 Free Software Foundation, Inc.
+/* Copyright (C) 1997-1999, 2004, 2005, 2006 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@uni-paderborn.de>, 1997.
@@ -65,7 +65,7 @@ nis_lookup (const_nis_name name, const unsigned int flags)
if (status != NIS_SUCCESS)
{
NIS_RES_STATUS (res) = status;
- return res;
+ goto out;
}
status = __nisbind_create (&bptr, dir->do_servers.do_servers_val,
@@ -74,7 +74,7 @@ nis_lookup (const_nis_name name, const unsigned int flags)
{
NIS_RES_STATUS (res) = status;
nis_free_directory (dir);
- return res;
+ goto out;;
}
while (__nisbind_connect (&bptr) != NIS_SUCCESS)
@@ -83,7 +83,7 @@ nis_lookup (const_nis_name name, const unsigned int flags)
{
nis_free_directory (dir);
NIS_RES_STATUS (res) = NIS_NAMEUNREACHABLE;
- return res;
+ goto out;
}
}
@@ -121,8 +121,21 @@ nis_lookup (const_nis_name name, const unsigned int flags)
req.ns_name =
strdup (NIS_RES_OBJECT (res)->LI_data.li_name);
if (req.ns_name == NULL)
- return NULL;
+ {
+ nis_free_directory (dir);
+ res = NULL;
+ goto out;
+ }
+ /* 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)
@@ -130,6 +143,7 @@ nis_lookup (const_nis_name name, const unsigned int flags)
__nisbind_destroy (&bptr);
return NULL;
}
+#endif
link_first_try = 1; /* Try at first the old binding */
goto again;
@@ -144,10 +158,12 @@ nis_lookup (const_nis_name name, const unsigned int flags)
{
__nisbind_destroy (&bptr);
nis_free_directory (dir);
+ /* Otherwise __nisfind_server will not do anything. */
+ dir = NULL;
if (__nisfind_server (req.ns_name, &dir)
!= NIS_SUCCESS)
- return res;
+ goto out;
if (__nisbind_create (&bptr,
dir->do_servers.do_servers_val,
@@ -155,7 +171,7 @@ nis_lookup (const_nis_name name, const unsigned int flags)
flags) != NIS_SUCCESS)
{
nis_free_directory (dir);
- return res;
+ goto out;
}
}
else
@@ -167,7 +183,7 @@ nis_lookup (const_nis_name name, const unsigned int flags)
if (__nisbind_next (&bptr) != NIS_SUCCESS)
{
nis_free_directory (dir);
- return res;
+ goto out;
}
}
goto again;
@@ -184,7 +200,7 @@ nis_lookup (const_nis_name name, const unsigned int flags)
if (status != NIS_SUCCESS)
{
NIS_RES_STATUS (res) = status;
- return res;
+ goto out;
}
switch (NIS_RES_STATUS (res))
@@ -216,6 +232,7 @@ nis_lookup (const_nis_name name, const unsigned int flags)
}
}
+ out:
if (names != namebuf)
nis_freenames (names);
diff --git a/nis/nss-nis.h b/nis/nss-nis.h
index 5ac968e28e..a02583d14c 100644
--- a/nis/nss-nis.h
+++ b/nis/nss-nis.h
@@ -25,8 +25,8 @@
/* Convert YP error number to NSS error number. */
-extern const enum nss_status __yperr2nss_tab[];
-extern const unsigned int __yperr2nss_count;
+extern const enum nss_status __yperr2nss_tab[] attribute_hidden;
+extern const unsigned int __yperr2nss_count attribute_hidden;
static inline enum nss_status
yperr2nss (int errval)
diff --git a/nis/nss-nisplus.h b/nis/nss-nisplus.h
index 7235c355b0..ad7f444440 100644
--- a/nis/nss-nisplus.h
+++ b/nis/nss-nisplus.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997 Free Software Foundation, Inc.
+/* Copyright (C) 1997, 2006 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@uni-paderborn.de>, 1997.
@@ -26,8 +26,8 @@
/* Convert NIS+ error number to NSS error number. */
-extern const enum nss_status __niserr2nss_tab[];
-extern const unsigned int __niserr2nss_count;
+extern const enum nss_status __niserr2nss_tab[] attribute_hidden;
+extern const unsigned int __niserr2nss_count attribute_hidden;
static inline enum nss_status
niserr2nss (int errval)
diff --git a/nis/nss_nis/nis-service.c b/nis/nss_nis/nis-service.c
index cb728335f9..c0e064d9a4 100644
--- a/nis/nss_nis/nis-service.c
+++ b/nis/nss_nis/nis-service.c
@@ -280,14 +280,13 @@ _nss_nis_getservbyname_r (const char *name, const char *protocol,
char *result;
int int_len;
- enum nss_status status = yperr2nss (yp_match (domain,
- "services.byservicename", key,
- keylen, &result, &int_len));
+ int status = yp_match (domain, "services.byservicename", key,
+ keylen, &result, &int_len);
size_t len = int_len;
/* If we found the key, it's ok and parse the result. If not,
fall through and parse the complete table. */
- if (__builtin_expect (status == NSS_STATUS_SUCCESS, 1))
+ if (__builtin_expect (status == YPERR_SUCCESS, 1))
{
if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
{
@@ -317,7 +316,7 @@ _nss_nis_getservbyname_r (const char *name, const char *protocol,
/* Check if it is safe to rely on services.byservicename. */
if (_nsl_default_nss () & NSS_FLAG_SERVICES_AUTHORITATIVE)
- return status;
+ return yperr2nss (status);
struct ypall_callback ypcb;
struct search_t req;
@@ -332,10 +331,10 @@ _nss_nis_getservbyname_r (const char *name, const char *protocol,
req.buflen = buflen;
req.errnop = errnop;
req.status = NSS_STATUS_NOTFOUND;
- status = yperr2nss (yp_all (domain, "services.byname", &ypcb));
+ status = yp_all (domain, "services.byname", &ypcb);
- if (status != NSS_STATUS_SUCCESS)
- return status;
+ if (__builtin_expect (status != YPERR_SUCCESS, 0))
+ return yperr2nss (status);
return req.status;
}
@@ -362,14 +361,13 @@ _nss_nis_getservbyport_r (int port, const char *protocol,
char *result;
int int_len;
- enum nss_status status = yperr2nss (yp_match (domain, "services.byname",
- key, keylen, &result,
- &int_len));
+ int status = yp_match (domain, "services.byname", key, keylen, &result,
+ &int_len);
size_t len = int_len;
/* If we found the key, it's ok and parse the result. If not,
fall through and parse the complete table. */
- if (status == NSS_STATUS_SUCCESS)
+ if (__builtin_expect (status == YPERR_SUCCESS, 1))
{
if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
{
@@ -414,11 +412,10 @@ _nss_nis_getservbyport_r (int port, const char *protocol,
req.buflen = buflen;
req.errnop = errnop;
req.status = NSS_STATUS_NOTFOUND;
- enum nss_status status = yperr2nss (yp_all (domain, "services.byname",
- &ypcb));
+ int status = yp_all (domain, "services.byname", &ypcb);
- if (status != NSS_STATUS_SUCCESS)
- return status;
+ if (__builtin_expect (status != YPERR_SUCCESS, 0))
+ return yperr2nss (status);
return req.status;
}