aboutsummaryrefslogtreecommitdiff
path: root/nis
diff options
context:
space:
mode:
Diffstat (limited to 'nis')
-rw-r--r--nis/Makefile6
-rw-r--r--nis/Versions9
-rw-r--r--nis/libnsl.h40
-rw-r--r--nis/nis_addmember.c30
-rw-r--r--nis/nis_call.c566
-rw-r--r--nis/nis_callback.c65
-rw-r--r--nis/nis_checkpoint.c5
-rw-r--r--nis/nis_clone_dir.c27
-rw-r--r--nis/nis_clone_obj.c6
-rw-r--r--nis/nis_clone_res.c29
-rw-r--r--nis/nis_creategroup.c18
-rw-r--r--nis/nis_defaults.c127
-rw-r--r--nis/nis_domain_of.c16
-rw-r--r--nis/nis_domain_of_r.c9
-rw-r--r--nis/nis_error.c97
-rw-r--r--nis/nis_error.h48
-rw-r--r--nis/nis_file.c93
-rw-r--r--nis/nis_getservlist.c57
-rw-r--r--nis/nis_intern.h3
-rw-r--r--nis/nis_ismember.c5
-rw-r--r--nis/nis_local_names.c6
-rw-r--r--nis/nis_lookup.c109
-rw-r--r--nis/nis_ping.c11
-rw-r--r--nis/nis_print_group_entry.c14
-rw-r--r--nis/nis_removemember.c74
-rw-r--r--nis/nis_subr.c105
-rw-r--r--nis/nis_table.c380
-rw-r--r--nis/nis_xdr.c524
-rw-r--r--nis/nis_xdr.h35
-rw-r--r--nis/nisplus-parser.h18
-rw-r--r--nis/nss12
-rw-r--r--nis/nss-default.c127
-rw-r--r--nis/nss-nis.c87
-rw-r--r--nis/nss-nis.h32
-rw-r--r--nis/nss-nisplus.h6
-rw-r--r--nis/nss_compat/compat-grp.c48
-rw-r--r--nis/nss_compat/compat-initgroups.c6
-rw-r--r--nis/nss_compat/compat-pwd.c83
-rw-r--r--nis/nss_compat/compat-spwd.c73
-rw-r--r--nis/nss_nis/nis-alias.c76
-rw-r--r--nis/nss_nis/nis-ethers.c75
-rw-r--r--nis/nss_nis/nis-grp.c256
-rw-r--r--nis/nss_nis/nis-hosts.c136
-rw-r--r--nis/nss_nis/nis-initgroups.c121
-rw-r--r--nis/nss_nis/nis-netgrp.c30
-rw-r--r--nis/nss_nis/nis-network.c115
-rw-r--r--nis/nss_nis/nis-proto.c60
-rw-r--r--nis/nss_nis/nis-publickey.c106
-rw-r--r--nis/nss_nis/nis-pwd.c350
-rw-r--r--nis/nss_nis/nis-rpc.c169
-rw-r--r--nis/nss_nis/nis-service.c254
-rw-r--r--nis/nss_nis/nis-spwd.c66
-rw-r--r--nis/nss_nisplus/nisplus-alias.c257
-rw-r--r--nis/nss_nisplus/nisplus-ethers.c251
-rw-r--r--nis/nss_nisplus/nisplus-grp.c380
-rw-r--r--nis/nss_nisplus/nisplus-hosts.c371
-rw-r--r--nis/nss_nisplus/nisplus-initgroups.c150
-rw-r--r--nis/nss_nisplus/nisplus-netgrp.c30
-rw-r--r--nis/nss_nisplus/nisplus-network.c318
-rw-r--r--nis/nss_nisplus/nisplus-parser.c252
-rw-r--r--nis/nss_nisplus/nisplus-proto.c323
-rw-r--r--nis/nss_nisplus/nisplus-publickey.c62
-rw-r--r--nis/nss_nisplus/nisplus-pwd.c388
-rw-r--r--nis/nss_nisplus/nisplus-rpc.c336
-rw-r--r--nis/nss_nisplus/nisplus-service.c341
-rw-r--r--nis/nss_nisplus/nisplus-spwd.c151
-rw-r--r--nis/rpcsvc/nislib.h8
-rw-r--r--nis/yp_xdr.c8
-rw-r--r--nis/ypclnt.c311
-rw-r--r--nis/ypupdate_xdr.c2
70 files changed, 3666 insertions, 5093 deletions
diff --git a/nis/Makefile b/nis/Makefile
index 8083ee8044..fa5c4dfd30 100644
--- a/nis/Makefile
+++ b/nis/Makefile
@@ -1,4 +1,4 @@
-# Copyright (C) 1996,1997,1998,2001,2004,2006 Free Software Foundation, Inc.
+# Copyright (C) 1996, 1997, 1998, 2001, 2004 Free Software Foundation, Inc.
# This file is part of the GNU C Library.
# The GNU C Library is free software; you can redistribute it and/or
@@ -54,7 +54,7 @@ libnsl-routines = yp_xdr ypclnt ypupdate_xdr \
nis_print_group_entry nis_domain_of nis_domain_of_r\
nis_modify nis_remove nis_add nis_defaults\
nis_findserv nis_callback nis_clone_dir nis_clone_obj\
- nis_clone_res nss-default
+ nis_clone_res
libnss_compat-routines := $(addprefix compat-,grp pwd spwd initgroups)
libnss_compat-inhibit-o = $(filter-out .os,$(object-suffixes))
@@ -64,7 +64,7 @@ libnss_nis-routines := $(addprefix nis-,$(databases)) nis-initgroups \
libnss_nis-inhibit-o = $(filter-out .os,$(object-suffixes))
libnss_nisplus-routines := $(addprefix nisplus-,$(databases)) nisplus-parser \
- nss-nisplus nisplus-initgroups
+ nss-nisplus
libnss_nisplus-inhibit-o = $(filter-out .os,$(object-suffixes))
include ../Rules
diff --git a/nis/Versions b/nis/Versions
index be4453e285..d6b6a972f6 100644
--- a/nis/Versions
+++ b/nis/Versions
@@ -57,10 +57,6 @@ libnsl {
GLIBC_2.2 {
xdr_ypall;
}
- GLIBC_PRIVATE {
- _nsl_default_nss; __prepare_niscall; __follow_path; __do_niscall3;
- __create_ib_request; _xdr_ib_request; _xdr_nis_result;
- }
}
libnss_compat {
@@ -121,10 +117,11 @@ libnss_nisplus {
_nss_nisplus_getservbyname_r; _nss_nisplus_getservbynumber_r;
_nss_nisplus_getservent_r; _nss_nisplus_getspent_r;
_nss_nisplus_getspnam_r; _nss_nisplus_netname2user;
- _nss_nisplus_setaliasent;
+ _nss_nisplus_parse_grent; _nss_nisplus_parse_pwent;
+ _nss_nisplus_parse_spent; _nss_nisplus_setaliasent;
_nss_nisplus_setetherent; _nss_nisplus_setgrent; _nss_nisplus_sethostent;
_nss_nisplus_setnetent; _nss_nisplus_setnetgrent; _nss_nisplus_setprotoent;
_nss_nisplus_setpwent; _nss_nisplus_setrpcent; _nss_nisplus_setservent;
- _nss_nisplus_setspent; _nss_nisplus_initgroups_dyn;
+ _nss_nisplus_setspent;
}
}
diff --git a/nis/libnsl.h b/nis/libnsl.h
deleted file mode 100644
index c6ceb321d7..0000000000
--- a/nis/libnsl.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/* Copyright (C) 2005, 2006 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
-
- The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- The GNU C Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with the GNU C Library; if not, write to the Free
- Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
- 02111-1307 USA. */
-
-#include <rpcsvc/nis.h>
-
-#define NSS_FLAG_NETID_AUTHORITATIVE 1
-#define NSS_FLAG_SERVICES_AUTHORITATIVE 2
-#define NSS_FLAG_SETENT_BATCH_READ 4
-
-
-/* Get current set of default flags. */
-extern int _nsl_default_nss (void);
-
-/* Set up everything for a call to __do_niscall3. */
-extern nis_error __prepare_niscall (const_nis_name name, directory_obj **dirp,
- dir_binding *bptrp, unsigned int flags);
-libnsl_hidden_proto (__prepare_niscall)
-
-extern struct ib_request *__create_ib_request (const_nis_name name,
- unsigned int flags);
-libnsl_hidden_proto (__create_ib_request)
-
-extern nis_error __follow_path (char **tablepath, char **tableptr,
- struct ib_request *ibreq, dir_binding *bptr);
-libnsl_hidden_proto (__follow_path)
diff --git a/nis/nis_addmember.c b/nis/nis_addmember.c
index 5e342ad0d0..bbe1c23977 100644
--- a/nis/nis_addmember.c
+++ b/nis/nis_addmember.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 1997, 1998, 1999, 2004, 2006 Free Software Foundation, Inc.
+/* Copyright (c) 1997, 1998, 1999, 2004 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
@@ -28,12 +28,13 @@ nis_addmember (const_nis_name member, const_nis_name group)
{
size_t grouplen = strlen (group);
char buf[grouplen + 14 + NIS_MAXNAMELEN];
+ char leafbuf[grouplen + 2];
char domainbuf[grouplen + 2];
nis_result *res, *res2;
nis_error status;
char *cp, *cp2;
- cp = rawmemchr (nis_leaf_of_r (group, buf, sizeof (buf) - 1), '\0');
+ cp = stpcpy (buf, nis_leaf_of_r (group, leafbuf, sizeof (leafbuf) - 1));
cp = stpcpy (cp, ".groups_dir");
cp2 = nis_domain_of_r (group, domainbuf, sizeof (domainbuf) - 1);
if (cp2 != NULL && cp2[0] != '\0')
@@ -41,35 +42,30 @@ nis_addmember (const_nis_name member, const_nis_name group)
*cp++ = '.';
stpcpy (cp, cp2);
}
- res = nis_lookup (buf, FOLLOW_LINKS | EXPAND_NAME);
+ res = nis_lookup (buf, FOLLOW_LINKS|EXPAND_NAME);
if (NIS_RES_STATUS (res) != NIS_SUCCESS)
{
status = NIS_RES_STATUS (res);
nis_freeresult (res);
return status;
}
- if (NIS_RES_NUMOBJ (res) != 1
- || __type_of (NIS_RES_OBJECT (res)) != NIS_GROUP_OBJ)
+ if ((NIS_RES_NUMOBJ (res) != 1) ||
+ (__type_of (NIS_RES_OBJECT (res)) != NIS_GROUP_OBJ))
{
nis_freeresult (res);
return NIS_INVALIDOBJ;
}
- u_int gr_members_len
- = NIS_RES_OBJECT(res)->GR_data.gr_members.gr_members_len;
-
- nis_name *new_gr_members_val
+ NIS_RES_OBJECT (res)->GR_data.gr_members.gr_members_val
= realloc (NIS_RES_OBJECT (res)->GR_data.gr_members.gr_members_val,
- (gr_members_len + 1) * sizeof (nis_name));
- if (new_gr_members_val == NULL)
+ (NIS_RES_OBJECT(res)->GR_data.gr_members.gr_members_len + 1)
+ * sizeof (char *));
+ if (NIS_RES_OBJECT (res)->GR_data.gr_members.gr_members_val == NULL)
goto nomem_out;
-
- NIS_RES_OBJECT (res)->GR_data.gr_members.gr_members_val
- = new_gr_members_val;
-
- new_gr_members_val[gr_members_len] = strdup (member);
- if (new_gr_members_val[gr_members_len] == NULL)
+ NIS_RES_OBJECT (res)->GR_data.gr_members.gr_members_val[NIS_RES_OBJECT (res)->GR_data.gr_members.gr_members_len] = strdup (member);
+ if (NIS_RES_OBJECT (res)->GR_data.gr_members.gr_members_val[NIS_RES_OBJECT (res)->GR_data.gr_members.gr_members_len] == NULL)
{
+ free (NIS_RES_OBJECT (res)->GR_data.gr_members.gr_members_val);
nomem_out:
nis_freeresult (res);
return NIS_NOMEMORY;
diff --git a/nis/nis_call.c b/nis/nis_call.c
index c571e8f367..14041a160c 100644
--- a/nis/nis_call.c
+++ b/nis/nis_call.c
@@ -1,5 +1,4 @@
-/* Copyright (C) 1997, 1998, 2001, 2004, 2005, 2006, 2007
- Free Software Foundation, Inc.
+/* Copyright (C) 1997, 1998, 2001, 2004 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
@@ -26,15 +25,11 @@
#include <rpc/auth.h>
#include <rpcsvc/nis.h>
#include <sys/socket.h>
-#include <sys/stat.h>
-#include <unistd.h>
#include <netinet/in.h>
#include <arpa/inet.h>
-#include <bits/libc-lock.h>
#include "nis_xdr.h"
#include "nis_intern.h"
-#include <libnsl.h>
static const struct timeval RPCTIMEOUT = {10, 0};
static const struct timeval UDPTIMEOUT = {5, 0};
@@ -42,19 +37,28 @@ static const struct timeval UDPTIMEOUT = {5, 0};
extern u_short __pmap_getnisport (struct sockaddr_in *address, u_long program,
u_long version, u_int protocol);
-unsigned long int
+unsigned long
inetstr2int (const char *str)
{
- size_t j = 0;
- for (size_t i = 0; str[i] != '\0'; ++i)
- if (str[i] == '.' && __builtin_expect (++j == 4, 0))
+ 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] == '.')
{
- char buffer[i + 1];
- buffer[i] = '\0';
- return inet_addr (memcpy (buffer, str, i));
+ ++j;
+ if (j == 4)
+ {
+ buffer[i] = '\0';
+ break;
+ }
}
- return inet_addr (str);
+ return inet_addr (buffer);
}
void
@@ -72,6 +76,8 @@ libnsl_hidden_def (__nisbind_destroy)
nis_error
__nisbind_next (dir_binding *bind)
{
+ u_int j;
+
if (bind->clnt != NULL)
{
if (bind->use_auth)
@@ -83,7 +89,7 @@ __nisbind_next (dir_binding *bind)
if (bind->trys >= bind->server_len)
return NIS_FAIL;
- for (u_int j = bind->current_ep + 1;
+ for (j = bind->current_ep + 1;
j < bind->server_val[bind->server_used].ep.ep_len; ++j)
if (strcmp (bind->server_val[bind->server_used].ep.ep_val[j].family,
"inet") == 0)
@@ -98,7 +104,7 @@ __nisbind_next (dir_binding *bind)
if (bind->server_used >= bind->server_len)
bind->server_used = 0;
- for (u_int j = 0; j < bind->server_val[bind->server_used].ep.ep_len; ++j)
+ for (j = 0; j < bind->server_val[bind->server_used].ep.ep_len; ++j)
if (strcmp (bind->server_val[bind->server_used].ep.ep_val[j].family,
"inet") == 0)
if (bind->server_val[bind->server_used].ep.ep_val[j].proto[0] == '-')
@@ -111,79 +117,10 @@ __nisbind_next (dir_binding *bind)
}
libnsl_hidden_def (__nisbind_next)
-static struct ckey_cache_entry
-{
- struct in_addr inaddr;
- in_port_t port;
- unsigned int protocol;
- des_block ckey;
-} *ckey_cache;
-static size_t ckey_cache_size;
-static size_t ckey_cache_allocated;
-static pid_t ckey_cache_pid;
-static uid_t ckey_cache_euid;
-__libc_lock_define_initialized (static, ckey_cache_lock)
-
-static bool_t
-get_ckey (des_block *ckey, struct sockaddr_in *addr, unsigned int protocol)
-{
- size_t i;
- pid_t pid = getpid ();
- uid_t euid = geteuid ();
- bool_t ret = FALSE;
-
- __libc_lock_lock (ckey_cache_lock);
-
- if (ckey_cache_pid != pid || ckey_cache_euid != euid)
- {
- ckey_cache_size = 0;
- ckey_cache_pid = pid;
- ckey_cache_euid = euid;
- }
-
- for (i = 0; i < ckey_cache_size; ++i)
- if (ckey_cache[i].port == addr->sin_port
- && ckey_cache[i].protocol == protocol
- && memcmp (&ckey_cache[i].inaddr, &addr->sin_addr,
- sizeof (addr->sin_addr)) == 0)
- {
- *ckey = ckey_cache[i].ckey;
- ret = TRUE;
- break;
- }
-
- if (!ret && key_gendes (ckey) >= 0)
- {
- ret = TRUE;
- /* Don't grow the cache indefinitely. */
- if (ckey_cache_size == 256)
- ckey_cache_size = 0;
- if (ckey_cache_size == ckey_cache_allocated)
- {
- size_t size = ckey_cache_allocated ? ckey_cache_allocated * 2 : 16;
- struct ckey_cache_entry *new_cache
- = realloc (ckey_cache, size * sizeof (*ckey_cache));
- if (new_cache != NULL)
- {
- ckey_cache = new_cache;
- ckey_cache_allocated = size;
- }
- }
- ckey_cache[ckey_cache_size].inaddr = addr->sin_addr;
- ckey_cache[ckey_cache_size].port = addr->sin_port;
- ckey_cache[ckey_cache_size].protocol = protocol;
- ckey_cache[ckey_cache_size++].ckey = *ckey;
- }
-
- __libc_lock_unlock (ckey_cache_lock);
- return ret;
-}
-
nis_error
__nisbind_connect (dir_binding *dbp)
{
nis_server *serv;
- u_short port;
if (dbp == NULL)
return NIS_FAIL;
@@ -196,17 +133,14 @@ __nisbind_connect (dir_binding *dbp)
dbp->addr.sin_addr.s_addr =
inetstr2int (serv->ep.ep_val[dbp->current_ep].uaddr);
- if (dbp->addr.sin_addr.s_addr == INADDR_NONE)
+ if (dbp->addr.sin_addr.s_addr == 0)
return NIS_FAIL;
/* Check, if the host is online and rpc.nisd is running. Much faster
then the clnt*_create functions: */
- port = __pmap_getnisport (&dbp->addr, NIS_PROG, NIS_VERSION,
- dbp->use_udp ? IPPROTO_UDP : IPPROTO_TCP);
- if (port == 0)
+ if (__pmap_getnisport (&dbp->addr, NIS_PROG, NIS_VERSION, IPPROTO_UDP) == 0)
return NIS_RPCERROR;
- dbp->addr.sin_port = htons (port);
dbp->socket = RPC_ANYSOCK;
if (dbp->use_udp)
dbp->clnt = clntudp_create (&dbp->addr, NIS_PROG, NIS_VERSION,
@@ -229,21 +163,23 @@ __nisbind_connect (dir_binding *dbp)
{
char netname[MAXNETNAMELEN + 1];
char *p;
- des_block ckey;
- p = stpcpy (netname, "unix@");
+ p = stpcpy (netname, "unix.");
strncpy (p, serv->name, MAXNETNAMELEN - 5);
netname[MAXNETNAMELEN] = '\0';
- dbp->clnt->cl_auth = NULL;
- if (get_ckey (&ckey, &dbp->addr,
- dbp->use_udp ? IPPROTO_UDP : IPPROTO_TCP))
- dbp->clnt->cl_auth =
- authdes_pk_create (netname, &serv->pkey, 300, NULL, &ckey);
+ // XXX What is this supposed to do? If we really want to replace
+ // XXX the first dot, then we might as well use unix@ as the
+ // XXX prefix string. --drepper
+ p = strchr (netname, '.');
+ *p = '@';
+ dbp->clnt->cl_auth =
+ authdes_pk_create (netname, &serv->pkey, 300, NULL, NULL);
if (!dbp->clnt->cl_auth)
dbp->clnt->cl_auth = authunix_create_default ();
}
else
dbp->clnt->cl_auth = authunix_create_default ();
+ dbp->use_auth = TRUE;
}
return NIS_SUCCESS;
@@ -252,8 +188,7 @@ libnsl_hidden_def (__nisbind_connect)
nis_error
__nisbind_create (dir_binding *dbp, const nis_server *serv_val,
- unsigned int serv_len, unsigned int server_used,
- unsigned int current_ep, unsigned int flags)
+ unsigned int serv_len, unsigned int flags)
{
dbp->clnt = NULL;
@@ -279,15 +214,10 @@ __nisbind_create (dir_binding *dbp, const nis_server *serv_val,
dbp->trys = 1;
dbp->class = -1;
- if (server_used == ~0)
- {
- if (__nis_findfastest (dbp) < 1)
- return NIS_NAMEUNREACHABLE;
- }
- else
+ if (__nis_findfastest (dbp) < 1)
{
- dbp->server_used = server_used;
- dbp->current_ep = current_ep;
+ __nisbind_destroy (dbp);
+ return NIS_NAMEUNREACHABLE;
}
return NIS_SUCCESS;
@@ -339,7 +269,6 @@ __do_niscall3 (dir_binding *dbp, u_long prog, xdrproc_t xargs, caddr_t req,
|| ((nis_result *)resp)->status == NIS_NOSUCHNAME
|| ((nis_result *)resp)->status == NIS_NOT_ME)
{
- next_server:
if (__nisbind_next (dbp) == NIS_SUCCESS)
{
while (__nisbind_connect (dbp) != NIS_SUCCESS)
@@ -357,14 +286,38 @@ __do_niscall3 (dir_binding *dbp, u_long prog, xdrproc_t xargs, caddr_t req,
if (((fd_result *)resp)->status == NIS_SYSTEMERROR
|| ((fd_result *)resp)->status == NIS_NOSUCHNAME
|| ((fd_result *)resp)->status == NIS_NOT_ME)
- goto next_server;
+ {
+ if (__nisbind_next (dbp) == NIS_SUCCESS)
+ {
+ while (__nisbind_connect (dbp) != NIS_SUCCESS)
+ {
+ if (__nisbind_next (dbp) != NIS_SUCCESS)
+ return NIS_SUCCESS;
+ }
+ }
+ else
+ break; /* No more servers to search in */
+ goto again;
+ }
break;
case NIS_DUMPLOG: /* log_result */
case NIS_DUMP:
if (((log_result *)resp)->lr_status == NIS_SYSTEMERROR
|| ((log_result *)resp)->lr_status == NIS_NOSUCHNAME
|| ((log_result *)resp)->lr_status == NIS_NOT_ME)
- goto next_server;
+ {
+ if (__nisbind_next (dbp) == NIS_SUCCESS)
+ {
+ while (__nisbind_connect (dbp) != NIS_SUCCESS)
+ {
+ if (__nisbind_next (dbp) != NIS_SUCCESS)
+ return NIS_SUCCESS;
+ }
+ }
+ else
+ break; /* No more servers to search in */
+ goto again;
+ }
break;
default:
break;
@@ -376,8 +329,6 @@ __do_niscall3 (dir_binding *dbp, u_long prog, xdrproc_t xargs, caddr_t req,
return retcode;
}
-libnsl_hidden_def (__do_niscall3)
-
nis_error
__do_niscall2 (const nis_server *server, u_int server_len, u_long prog,
@@ -390,7 +341,7 @@ __do_niscall2 (const nis_server *server, u_int server_len, u_long prog,
if (flags & MASTER_ONLY)
server_len = 1;
- status = __nisbind_create (&dbp, server, server_len, ~0, ~0, flags);
+ status = __nisbind_create (&dbp, server, server_len, flags);
if (status != NIS_SUCCESS)
return status;
@@ -422,18 +373,14 @@ rec_dirsearch (const_nis_name name, directory_obj *dir, nis_error *status)
case HIGHER_NAME:
{ /* We need data from a parent domain */
directory_obj *obj;
- const char *ndomain = __nis_domain_of (dir->do_name);
+ char ndomain [strlen (name) + 3];
+
+ nis_domain_of_r (dir->do_name, ndomain, sizeof (ndomain));
/* The root server of our domain is a replica of the parent
domain ! (Now I understand why a root server must be a
replica of the parent domain) */
fd_res = __nis_finddirectory (dir, ndomain);
- if (fd_res == NULL)
- {
- nis_free_directory (dir);
- *status = NIS_NOMEMORY;
- return NULL;
- }
*status = fd_res->status;
if (fd_res->status != NIS_SUCCESS)
{
@@ -441,33 +388,36 @@ rec_dirsearch (const_nis_name name, directory_obj *dir, nis_error *status)
__free_fdresult (fd_res);
return dir;
}
- nis_free_directory (dir);
obj = calloc (1, sizeof (directory_obj));
- if (obj == NULL)
- {
- __free_fdresult (fd_res);
- *status = NIS_NOMEMORY;
- return NULL;
- }
xdrmem_create (&xdrs, fd_res->dir_data.dir_data_val,
fd_res->dir_data.dir_data_len, XDR_DECODE);
_xdr_directory_obj (&xdrs, obj);
xdr_destroy (&xdrs);
__free_fdresult (fd_res);
-
- /* We have found a NIS+ server serving ndomain, now
- let us search for "name" */
- return rec_dirsearch (name, obj, status);
+ if (obj != NULL)
+ {
+ /* We have found a NIS+ server serving ndomain, now
+ let us search for "name" */
+ nis_free_directory (dir);
+ return rec_dirsearch (name, obj, status);
+ }
+ else
+ {
+ /* Ups, very bad. Are we already the root server ? */
+ nis_free_directory (dir);
+ return NULL;
+ }
}
- break;
+ break;
case LOWER_NAME:
{
directory_obj *obj;
size_t namelen = strlen (name);
char leaf[namelen + 3];
char domain[namelen + 3];
- const char *ndomain;
+ char ndomain[namelen + 3];
char *cp;
+ u_int run = 0;
strcpy (domain, name);
@@ -479,22 +429,23 @@ rec_dirsearch (const_nis_name name, directory_obj *dir, nis_error *status)
return NULL;
}
nis_leaf_of_r (domain, leaf, sizeof (leaf));
- ndomain = __nis_domain_of (domain);
- memmove (domain, ndomain, strlen (ndomain) + 1);
+ nis_domain_of_r (domain, ndomain, sizeof (ndomain));
+ strcpy (domain, ndomain);
+ ++run;
}
while (nis_dir_cmp (domain, dir->do_name) != SAME_NAME);
- cp = rawmemchr (leaf, '\0');
+ if (run == 1)
+ {
+ /* We have found the directory above. Use it. */
+ return dir;
+ }
+
+ cp = strchr (leaf, '\0');
*cp++ = '.';
strcpy (cp, domain);
fd_res = __nis_finddirectory (dir, leaf);
- if (fd_res == NULL)
- {
- nis_free_directory (dir);
- *status = NIS_NOMEMORY;
- return NULL;
- }
*status = fd_res->status;
if (fd_res->status != NIS_SUCCESS)
{
@@ -502,24 +453,21 @@ rec_dirsearch (const_nis_name name, directory_obj *dir, nis_error *status)
__free_fdresult (fd_res);
return dir;
}
- nis_free_directory (dir);
- obj = calloc (1, sizeof(directory_obj));
- if (obj == NULL)
+ obj = calloc(1, sizeof(directory_obj));
+ xdrmem_create(&xdrs, fd_res->dir_data.dir_data_val,
+ fd_res->dir_data.dir_data_len, XDR_DECODE);
+ _xdr_directory_obj(&xdrs, obj);
+ xdr_destroy(&xdrs);
+ __free_fdresult (fd_res);
+ if (obj != NULL)
{
- __free_fdresult (fd_res);
- *status = NIS_NOMEMORY;
- return NULL;
+ /* We have found a NIS+ server serving ndomain, now
+ let us search for "name" */
+ nis_free_directory (dir);
+ return rec_dirsearch (name, obj, status);
}
- xdrmem_create (&xdrs, fd_res->dir_data.dir_data_val,
- fd_res->dir_data.dir_data_len, XDR_DECODE);
- _xdr_directory_obj (&xdrs, obj);
- xdr_destroy (&xdrs);
- __free_fdresult (fd_res);
- /* We have found a NIS+ server serving ndomain, now
- let us search for "name" */
- return rec_dirsearch (name, obj, status);
}
- break;
+ break;
case BAD_NAME:
nis_free_directory (dir);
*status = NIS_BADNAME;
@@ -538,26 +486,24 @@ first_shoot (const_nis_name name, directory_obj *dir)
directory_obj *obj = NULL;
fd_result *fd_res;
XDR xdrs;
+ char domain[strlen (name) + 3];
if (nis_dir_cmp (name, dir->do_name) == SAME_NAME)
return dir;
- fd_res = __nis_finddirectory (dir, name);
- if (fd_res == NULL)
- return NULL;
+ nis_domain_of_r (name, domain, sizeof (domain));
+
+ if (nis_dir_cmp (domain, dir->do_name) == SAME_NAME)
+ return dir;
+
+ fd_res = __nis_finddirectory (dir, domain);
if (fd_res->status == NIS_SUCCESS
&& (obj = calloc (1, sizeof (directory_obj))) != NULL)
{
- xdrmem_create (&xdrs, fd_res->dir_data.dir_data_val,
- fd_res->dir_data.dir_data_len, XDR_DECODE);
+ xdrmem_create(&xdrs, fd_res->dir_data.dir_data_val,
+ fd_res->dir_data.dir_data_len, XDR_DECODE);
_xdr_directory_obj (&xdrs, obj);
xdr_destroy (&xdrs);
-
- if (strcmp (dir->do_name, obj->do_name) != 0)
- {
- nis_free_directory (obj);
- obj = NULL;
- }
}
__free_fdresult (fd_res);
@@ -568,272 +514,88 @@ first_shoot (const_nis_name name, directory_obj *dir)
return obj;
}
-static struct nis_server_cache
-{
- int search_parent;
- int uses;
- unsigned int size;
- unsigned int server_used;
- unsigned int current_ep;
- time_t expires;
- char name[];
-} *nis_server_cache[16];
-static time_t nis_cold_start_mtime;
-__libc_lock_define_initialized (static, nis_server_cache_lock)
-
-static directory_obj *
-nis_server_cache_search (const_nis_name name, int search_parent,
- unsigned int *server_used, unsigned int *current_ep,
- struct timeval *now)
-{
- directory_obj *ret = NULL;
- int i;
- char *addr;
- XDR xdrs;
- struct stat64 st;
-
- if (stat64 ("/var/nis/NIS_COLD_START", &st) < 0)
- st.st_mtime = nis_cold_start_mtime + 1;
-
- __libc_lock_lock (nis_server_cache_lock);
-
- for (i = 0; i < 16; ++i)
- if (nis_server_cache[i] == NULL)
- continue;
- else if (st.st_mtime != nis_cold_start_mtime
- || now->tv_sec > nis_server_cache[i]->expires)
- {
- free (nis_server_cache[i]);
- nis_server_cache[i] = NULL;
- }
- else if (nis_server_cache[i]->search_parent == search_parent
- && strcmp (nis_server_cache[i]->name, name) == 0)
- {
- ret = calloc (1, sizeof (directory_obj));
- if (ret == NULL)
- break;
-
- addr = rawmemchr (nis_server_cache[i]->name, '\0') + 8;
- addr = (char *) ((uintptr_t) addr & ~(uintptr_t) 7);
- xdrmem_create (&xdrs, addr, nis_server_cache[i]->size, XDR_DECODE);
- if (!_xdr_directory_obj (&xdrs, ret))
- {
- xdr_destroy (&xdrs);
- free (ret);
- ret = NULL;
- free (nis_server_cache[i]);
- nis_server_cache[i] = NULL;
- break;
- }
- xdr_destroy (&xdrs);
- *server_used = nis_server_cache[i]->server_used;
- *current_ep = nis_server_cache[i]->current_ep;
- break;
- }
-
- nis_cold_start_mtime = st.st_mtime;
-
- __libc_lock_unlock (nis_server_cache_lock);
- return ret;
-}
-
-static void
-nis_server_cache_add (const_nis_name name, int search_parent,
- directory_obj *dir, unsigned int server_used,
- unsigned int current_ep, struct timeval *now)
-{
- struct nis_server_cache **loc;
- struct nis_server_cache *new;
- struct nis_server_cache *old;
- int i;
- char *addr;
- unsigned int size;
- XDR xdrs;
-
- if (dir == NULL)
- return;
-
- size = xdr_sizeof ((xdrproc_t) _xdr_directory_obj, (char *) dir);
- new = calloc (1, sizeof (*new) + strlen (name) + 8 + size);
- if (new == NULL)
- return;
- new->search_parent = search_parent;
- new->uses = 1;
- new->expires = now->tv_sec + dir->do_ttl;
- new->size = size;
- new->server_used = server_used;
- new->current_ep = current_ep;
- addr = stpcpy (new->name, name) + 8;
- addr = (char *) ((uintptr_t) addr & ~(uintptr_t) 7);
-
- xdrmem_create(&xdrs, addr, size, XDR_ENCODE);
- if (!_xdr_directory_obj (&xdrs, dir))
- {
- xdr_destroy (&xdrs);
- free (new);
- return;
- }
- xdr_destroy (&xdrs);
-
- __libc_lock_lock (nis_server_cache_lock);
-
- /* Choose which entry should be evicted from the cache. */
- loc = &nis_server_cache[0];
- if (*loc != NULL)
- for (i = 1; i < 16; ++i)
- if (nis_server_cache[i] == NULL)
- {
- loc = &nis_server_cache[i];
- break;
- }
- else if ((*loc)->uses > nis_server_cache[i]->uses
- || ((*loc)->uses == nis_server_cache[i]->uses
- && (*loc)->expires > nis_server_cache[i]->expires))
- loc = &nis_server_cache[i];
- old = *loc;
- *loc = new;
-
- __libc_lock_unlock (nis_server_cache_lock);
- free (old);
-}
-
nis_error
-__nisfind_server (const_nis_name name, int search_parent,
- directory_obj **dir, dir_binding *dbp, unsigned int flags)
+__nisfind_server (const_nis_name name, directory_obj **dir)
{
- nis_error result = NIS_SUCCESS;
- nis_error status;
- directory_obj *obj;
- struct timeval now;
- unsigned int server_used = ~0;
- unsigned int current_ep = ~0;
-
if (name == NULL)
return NIS_BADNAME;
- if (*dir != NULL)
- return NIS_SUCCESS;
-
- (void) gettimeofday (&now, NULL);
-
- if ((flags & NO_CACHE) == 0)
- *dir = nis_server_cache_search (name, search_parent, &server_used,
- &current_ep, &now);
- if (*dir != NULL)
- {
- unsigned int server_len = (*dir)->do_servers.do_servers_len;
- if (flags & MASTER_ONLY)
- {
- server_len = 1;
- if (server_used != 0)
- {
- server_used = ~0;
- current_ep = ~0;
- }
- }
- result = __nisbind_create (dbp, (*dir)->do_servers.do_servers_val,
- server_len, server_used, current_ep, flags);
- if (result != NIS_SUCCESS)
- {
- nis_free_directory (*dir);
- *dir = NULL;
- }
- return result;
- }
+#if 0
+ /* Search in local cache. In the moment, we ignore the fastest server */
+ if (!(flags & NO_CACHE))
+ dir = __nis_cache_search (name, flags, &cinfo);
+#endif
- *dir = readColdStartFile ();
if (*dir == NULL)
- /* No /var/nis/NIS_COLD_START->no NIS+ installed. */
- return NIS_UNAVAIL;
-
- /* Try at first, if servers in "dir" know our object */
- const char *search_name = name;
- if (search_parent)
- search_name = __nis_domain_of (name);
- obj = first_shoot (search_name, *dir);
- if (obj == NULL)
{
- obj = rec_dirsearch (search_name, *dir, &status);
- if (obj == NULL)
- result = status;
- }
+ nis_error status;
+ directory_obj *obj;
- if (result == NIS_SUCCESS)
- {
- unsigned int server_len = obj->do_servers.do_servers_len;
- if (flags & MASTER_ONLY)
- server_len = 1;
- result = __nisbind_create (dbp, obj->do_servers.do_servers_val,
- server_len, ~0, ~0, flags);
- if (result == NIS_SUCCESS)
+ *dir = readColdStartFile ();
+ if (*dir == NULL) /* No /var/nis/NIS_COLD_START->no NIS+ installed */
+ return NIS_UNAVAIL;
+
+ /* Try at first, if servers in "dir" know our object */
+ obj = first_shoot (name, *dir);
+ if (obj == NULL)
{
- if ((flags & MASTER_ONLY) == 0
- || obj->do_servers.do_servers_len == 1)
- {
- server_used = dbp->server_used;
- current_ep = dbp->current_ep;
- }
- if ((flags & NO_CACHE) == 0)
- nis_server_cache_add (name, search_parent, obj,
- server_used, current_ep, &now);
+ *dir = rec_dirsearch (name, *dir, &status);
+ if (*dir == NULL)
+ return status;
}
else
- {
- nis_free_directory (obj);
- obj = NULL;
- }
+ *dir = obj;
}
- *dir = obj;
-
- return result;
-}
-
-
-nis_error
-__prepare_niscall (const_nis_name name, directory_obj **dirp,
- dir_binding *bptrp, unsigned int flags)
-{
- nis_error retcode = __nisfind_server (name, 1, dirp, bptrp, flags);
- if (__builtin_expect (retcode != NIS_SUCCESS, 0))
- return retcode;
-
- do
- if (__nisbind_connect (bptrp) == NIS_SUCCESS)
- return NIS_SUCCESS;
- while (__nisbind_next (bptrp) == NIS_SUCCESS);
-
- __nisbind_destroy (bptrp);
- memset (bptrp, '\0', sizeof (*bptrp));
-
- retcode = NIS_NAMEUNREACHABLE;
- nis_free_directory (*dirp);
- *dirp = NULL;
-
- return retcode;
+ return NIS_SUCCESS;
}
-libnsl_hidden_def (__prepare_niscall)
-
nis_error
__do_niscall (const_nis_name name, u_long prog, xdrproc_t xargs,
caddr_t req, xdrproc_t xres, caddr_t resp, unsigned int flags,
nis_cb *cb)
{
+ nis_error retcode;
dir_binding bptr;
directory_obj *dir = NULL;
+ nis_server *server;
+ u_int server_len;
int saved_errno = errno;
- nis_error retcode = __prepare_niscall (name, &dir, &bptr, flags);
+ retcode = __nisfind_server (name, &dir);
+ if (retcode != NIS_SUCCESS)
+ return retcode;
+
+ if (flags & MASTER_ONLY)
+ {
+ server = dir->do_servers.do_servers_val;
+ server_len = 1;
+ }
+ else
+ {
+ server = dir->do_servers.do_servers_val;
+ server_len = dir->do_servers.do_servers_len;
+ }
+
+ retcode = __nisbind_create (&bptr, server, server_len, flags);
if (retcode == NIS_SUCCESS)
{
+ while (__nisbind_connect (&bptr) != NIS_SUCCESS)
+ {
+ if (__nisbind_next (&bptr) != NIS_SUCCESS)
+ {
+ nis_free_directory (dir);
+ __nisbind_destroy (&bptr);
+ return NIS_NAMEUNREACHABLE;
+ }
+ }
retcode = __do_niscall3 (&bptr, prog, xargs, req, xres, resp, flags, cb);
__nisbind_destroy (&bptr);
-
- nis_free_directory (dir);
}
+ nis_free_directory (dir);
+
__set_errno (saved_errno);
return retcode;
diff --git a/nis/nis_callback.c b/nis/nis_callback.c
index e0acd9683a..b867b39ab7 100644
--- a/nis/nis_callback.c
+++ b/nis/nis_callback.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997,1998,1999,2000,2005,2006 Free Software Foundation, Inc.
+/* Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@suse.de>, 1997.
@@ -197,18 +197,22 @@ internal_nis_do_callback (struct dir_binding *bptr, netobj *cookie,
struct nis_cb *cb)
{
struct timeval TIMEOUT = {25, 0};
- bool_t cb_is_running;
+ bool_t cb_is_running = FALSE;
data = cb;
for (;;)
{
- struct pollfd my_pollfd[svc_max_pollfd];
+ struct pollfd *my_pollfd;
int i;
if (svc_max_pollfd == 0 && svc_pollfd == NULL)
return NIS_CBERROR;
+ my_pollfd = malloc (sizeof (struct pollfd) * svc_max_pollfd);
+ if (__builtin_expect (my_pollfd == NULL, 0))
+ return NIS_NOMEMORY;
+
for (i = 0; i < svc_max_pollfd; ++i)
{
my_pollfd[i].fd = svc_pollfd[i].fd;
@@ -216,17 +220,20 @@ internal_nis_do_callback (struct dir_binding *bptr, netobj *cookie,
my_pollfd[i].revents = 0;
}
- switch (i = TEMP_FAILURE_RETRY (__poll (my_pollfd, svc_max_pollfd,
- 25*1000)))
+ switch (i = __poll (my_pollfd, svc_max_pollfd, 25*1000))
{
case -1:
+ free (my_pollfd);
+ if (errno == EINTR)
+ continue;
return NIS_CBERROR;
case 0:
+ free (my_pollfd);
/* See if callback 'thread' in the server is still alive. */
- cb_is_running = FALSE;
+ memset ((char *) &cb_is_running, 0, sizeof (cb_is_running));
if (clnt_call (bptr->clnt, NIS_CALLBACK, (xdrproc_t) xdr_netobj,
(caddr_t) cookie, (xdrproc_t) xdr_bool,
- (caddr_t) &cb_is_running, TIMEOUT) != RPC_SUCCESS)
+ (caddr_t) & cb_is_running, TIMEOUT) != RPC_SUCCESS)
cb_is_running = FALSE;
if (cb_is_running == FALSE)
@@ -237,6 +244,7 @@ internal_nis_do_callback (struct dir_binding *bptr, netobj *cookie,
break;
default:
svc_getreq_poll (my_pollfd, i);
+ free (my_pollfd);
if (data->nomore)
return data->result;
}
@@ -266,15 +274,16 @@ __nis_create_callback (int (*callback) (const_nis_name, const nis_object *,
struct nis_cb *cb;
int sock = RPC_ANYSOCK;
struct sockaddr_in sin;
- socklen_t len = sizeof (struct sockaddr_in);
+ int len = sizeof (struct sockaddr_in);
+ char addr[NIS_MAXNAMELEN + 1];
unsigned short port;
- int nomsg = 0;
- cb = (struct nis_cb *) calloc (1,
- sizeof (struct nis_cb) + sizeof (nis_server));
+ cb = (struct nis_cb *) calloc (1, sizeof (struct nis_cb));
if (__builtin_expect (cb == NULL, 0))
goto failed;
- cb->serv = (nis_server *) (cb + 1);
+ cb->serv = (nis_server *) calloc (1, sizeof (nis_server));
+ if (__builtin_expect (cb->serv == NULL, 0))
+ goto failed;
cb->serv->name = strdup (nis_local_principal ());
if (__builtin_expect (cb->serv->name == NULL, 0))
goto failed;
@@ -317,20 +326,15 @@ __nis_create_callback (int (*callback) (const_nis_name, const nis_object *,
cb->serv->ep.ep_val[0].proto = strdup ((flags & USE_DGRAM) ? "udp" : "tcp");
if (__builtin_expect (cb->serv->ep.ep_val[0].proto == NULL, 0))
goto failed;
- cb->xprt = ((flags & USE_DGRAM)
- ? svcudp_bufcreate (sock, 100, 8192)
- : svctcp_create (sock, 100, 8192));
- if (cb->xprt == NULL)
- {
- nomsg = 1;
- goto failed;
- }
+ cb->xprt = (flags & USE_DGRAM) ? svcudp_bufcreate (sock, 100, 8192) :
+ svctcp_create (sock, 100, 8192);
cb->sock = cb->xprt->xp_sock;
if (!svc_register (cb->xprt, CB_PROG, CB_VERS, cb_prog_1, 0))
{
xprt_unregister (cb->xprt);
svc_destroy (cb->xprt);
xdr_free ((xdrproc_t) _xdr_nis_server, (char *) cb->serv);
+ free (cb->serv);
free (cb);
syslog (LOG_ERR, "NIS+: failed to register callback dispatcher");
return NULL;
@@ -341,30 +345,30 @@ __nis_create_callback (int (*callback) (const_nis_name, const nis_object *,
xprt_unregister (cb->xprt);
svc_destroy (cb->xprt);
xdr_free ((xdrproc_t) _xdr_nis_server, (char *) cb->serv);
+ free (cb->serv);
free (cb);
syslog (LOG_ERR, "NIS+: failed to read local socket info");
return NULL;
}
port = ntohs (sin.sin_port);
get_myaddress (&sin);
-
- if (asprintf (&cb->serv->ep.ep_val[0].uaddr, "%s.%d.%d",
- inet_ntoa (sin.sin_addr), (port & 0xFF00) >> 8, port & 0x00FF)
- < 0)
- goto failed;
+ snprintf (addr, sizeof (addr), "%s.%d.%d", inet_ntoa (sin.sin_addr),
+ (port & 0xFF00) >> 8, port & 0x00FF);
+ cb->serv->ep.ep_val[0].uaddr = strdup (addr);
return cb;
failed:
if (cb)
{
- if (cb->xprt)
- svc_destroy (cb->xprt);
- xdr_free ((xdrproc_t) _xdr_nis_server, (char *) cb->serv);
+ if (cb->serv)
+ {
+ xdr_free ((xdrproc_t) _xdr_nis_server, (char *) cb->serv);
+ free (cb->serv);
+ }
free (cb);
}
- if (!nomsg)
- syslog (LOG_ERR, "NIS+: out of memory allocating callback");
+ syslog (LOG_ERR, "NIS+: out of memory allocating callback");
return NULL;
}
@@ -375,6 +379,7 @@ __nis_destroy_callback (struct nis_cb *cb)
svc_destroy (cb->xprt);
close (cb->sock);
xdr_free ((xdrproc_t) _xdr_nis_server, (char *) cb->serv);
+ free (cb->serv);
free (cb);
return NIS_SUCCESS;
diff --git a/nis/nis_checkpoint.c b/nis/nis_checkpoint.c
index 23c4707b6f..0146d53054 100644
--- a/nis/nis_checkpoint.c
+++ b/nis/nis_checkpoint.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 1997, 1998, 1999, 2006 Free Software Foundation, Inc.
+/* Copyright (c) 1997, 1998, 1999 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
@@ -24,7 +24,7 @@
#include "nis_intern.h"
nis_result *
-nis_checkpoint (const_nis_name dirname)
+nis_checkpoint(const_nis_name dirname)
{
nis_result *res;
@@ -48,6 +48,7 @@ nis_checkpoint (const_nis_name dirname)
if (__type_of (NIS_RES_OBJECT (res2)) != NIS_DIRECTORY_OBJ)
{
nis_freeresult (res2);
+ nis_freeresult (res);
NIS_RES_STATUS (res) = NIS_INVALIDOBJ;
return res;
}
diff --git a/nis/nis_clone_dir.c b/nis/nis_clone_dir.c
index f94a1eeb74..0271db1790 100644
--- a/nis/nis_clone_dir.c
+++ b/nis/nis_clone_dir.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 1997, 1998, 2005, 2006 Free Software Foundation, Inc.
+/* Copyright (c) 1997, 1998 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
@@ -26,27 +26,18 @@
directory_obj *
nis_clone_directory (const directory_obj *src, directory_obj *dest)
{
- char *addr;
+ unsigned char *addr;
unsigned int size;
XDR xdrs;
+ directory_obj *res;
if (src == NULL)
- return NULL;
+ return (NULL);
size = xdr_sizeof ((xdrproc_t)_xdr_directory_obj, (char *)src);
if ((addr = calloc(1, size)) == NULL)
return NULL;
- xdrmem_create(&xdrs, addr, size, XDR_ENCODE);
- if (!_xdr_directory_obj (&xdrs, (directory_obj *)src))
- {
- xdr_destroy (&xdrs);
- free (addr);
- return NULL;
- }
- xdr_destroy (&xdrs);
-
- directory_obj *res;
if (dest == NULL)
{
if ((res = calloc (1, sizeof (directory_obj))) == NULL)
@@ -58,12 +49,18 @@ nis_clone_directory (const directory_obj *src, directory_obj *dest)
else
res = dest;
+ xdrmem_create(&xdrs, addr, size, XDR_ENCODE);
+ if (!_xdr_directory_obj (&xdrs, (directory_obj *)src))
+ {
+ xdr_destroy (&xdrs);
+ free (addr);
+ return NULL;
+ }
+ xdr_destroy (&xdrs);
xdrmem_create (&xdrs, addr, size, XDR_DECODE);
if (!_xdr_directory_obj (&xdrs, res))
{
xdr_destroy (&xdrs);
- if (res != dest)
- free (res);
free (addr);
return NULL;
}
diff --git a/nis/nis_clone_obj.c b/nis/nis_clone_obj.c
index 4d88200284..0b163fe662 100644
--- a/nis/nis_clone_obj.c
+++ b/nis/nis_clone_obj.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 1997, 1998, 2004, 2005 Free Software Foundation, Inc.
+/* Copyright (c) 1997, 1998, 2004 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
@@ -26,8 +26,8 @@
nis_object *
nis_clone_object (const nis_object *src, nis_object *dest)
{
- char *addr;
- unsigned int size;
+ unsigned char *addr;
+ unsigned long size;
XDR xdrs;
nis_object *res = NULL;
diff --git a/nis/nis_clone_res.c b/nis/nis_clone_res.c
index 021f7cb4f4..135f397911 100644
--- a/nis/nis_clone_res.c
+++ b/nis/nis_clone_res.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 1997, 1998, 2005, 2006 Free Software Foundation, Inc.
+/* Copyright (c) 1997, 1998 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
@@ -26,9 +26,10 @@
nis_result *
nis_clone_result (const nis_result *src, nis_result *dest)
{
- char *addr;
+ unsigned char *addr;
unsigned int size;
XDR xdrs;
+ nis_result *res;
if (src == NULL)
return (NULL);
@@ -37,16 +38,6 @@ nis_clone_result (const nis_result *src, nis_result *dest)
if ((addr = calloc(1, size)) == NULL)
return NULL;
- xdrmem_create (&xdrs, addr, size, XDR_ENCODE);
- if (!_xdr_nis_result (&xdrs, (nis_result *)src))
- {
- xdr_destroy (&xdrs);
- free (addr);
- return NULL;
- }
- xdr_destroy (&xdrs);
-
- nis_result *res;
if (dest == NULL)
{
if ((res = calloc (1, sizeof (nis_result))) == NULL)
@@ -58,12 +49,18 @@ nis_clone_result (const nis_result *src, nis_result *dest)
else
res = dest;
- xdrmem_create (&xdrs, addr, size, XDR_DECODE);
- if (!_xdr_nis_result (&xdrs, res))
+ xdrmem_create(&xdrs, addr, size, XDR_ENCODE);
+ if (!_xdr_nis_result (&xdrs, (nis_result *)src))
+ {
+ xdr_destroy (&xdrs);
+ free (addr);
+ return NULL;
+ }
+ xdr_destroy (&xdrs);
+ xdrmem_create(&xdrs, addr, size, XDR_DECODE);
+ if (!_xdr_nis_result(&xdrs, res))
{
xdr_destroy (&xdrs);
- if (res != dest)
- free (res);
free (addr);
return NULL;
}
diff --git a/nis/nis_creategroup.c b/nis/nis_creategroup.c
index 0e9e13d5e5..3786461d64 100644
--- a/nis/nis_creategroup.c
+++ b/nis/nis_creategroup.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 1997, 1998, 1999, 2000, 2006 Free Software Foundation, Inc.
+/* Copyright (c) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@suse.de>, 1997.
@@ -46,24 +46,18 @@ nis_creategroup (const_nis_name group, unsigned int flags)
else
return NIS_BADNAME;
- obj = calloc (1, sizeof (nis_object));
+ obj = malloc (sizeof (nis_object));
if (__builtin_expect (obj == NULL, 0))
return NIS_NOMEMORY;
obj->zo_oid.ctime = obj->zo_oid.mtime = time (NULL);
obj->zo_name = strdup (leafbuf);
- obj->zo_owner = __nis_default_owner (NULL);
- obj->zo_group = __nis_default_group (NULL);
+ obj->zo_owner = strdup (__nis_default_owner (NULL));
+ obj->zo_group = strdup (__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)
- {
- free (obj->zo_group);
- free (obj->zo_owner);
- free (obj->zo_name);
- free (obj);
- return NIS_NOMEMORY;
- }
+ return NIS_NOMEMORY;
obj->zo_access = __nis_default_access (NULL, 0);
obj->zo_ttl = 60 * 60;
obj->zo_data.zo_type = NIS_GROUP_OBJ;
@@ -72,11 +66,11 @@ nis_creategroup (const_nis_name group, unsigned int flags)
obj->zo_data.objdata_u.gr_data.gr_members.gr_members_val = NULL;
res = nis_add (buf, obj);
- nis_free_object (obj);
if (res == NULL)
return NIS_NOMEMORY;
status = NIS_RES_STATUS (res);
nis_freeresult (res);
+ nis_free_object (obj);
return status;
}
diff --git a/nis/nis_defaults.c b/nis/nis_defaults.c
index ed79b59ec6..f13578635a 100644
--- a/nis/nis_defaults.c
+++ b/nis/nis_defaults.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 1997, 1998, 2004, 2006 Free Software Foundation, Inc.
+/* Copyright (c) 1997, 1998, 2004 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
@@ -17,7 +17,6 @@
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>
@@ -31,35 +30,44 @@
** Some functions for parsing the -D param and NIS_DEFAULTS Environ
*/
static nis_name
-searchXYX (char *str, const char *what)
+searchgroup (char *str)
{
- 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 ("");
+ char *cptr;
+ int i;
- return strndup (str, i);
-}
+ cptr = strstr (str, "group=");
+ if (cptr == NULL)
+ return NULL;
+ 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) "";
-static nis_name
-searchgroup (char *str)
-{
- return searchXYX (str, "group=");
+ return strndup (cptr, i);
}
-
static nis_name
searchowner (char *str)
{
- return searchXYX (str, "owner=");
-}
+ 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);
+}
static uint32_t
searchttl (char *str)
@@ -350,61 +358,86 @@ searchaccess (char *str, unsigned int access)
return result;
}
-
nis_name
__nis_default_owner (char *defaults)
{
- char *default_owner = NULL;
+ char default_owner[NIS_MAXNAMELEN + 1];
+ char *cptr, *dptr;
- char *cptr = defaults;
- if (cptr == NULL)
- cptr = getenv ("NIS_DEFAULTS");
+ strcpy (default_owner, nis_local_principal ());
- if (cptr != NULL)
+ if (defaults != NULL)
{
- char *dptr = strstr (cptr, "owner=");
+ dptr = strstr (defaults, "owner=");
if (dptr != NULL)
{
- char *p = searchowner (dptr);
- if (p == NULL)
- return NULL;
- default_owner = strdupa (p);
+ char *p = searchowner (defaults);
+ if (strlen (p) <= NIS_MAXNAMELEN)
+ strcpy (default_owner, 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 ?: nis_local_principal ());
+ return strdup (default_owner);
}
libnsl_hidden_def (__nis_default_owner)
-
nis_name
__nis_default_group (char *defaults)
{
- char *default_group = NULL;
+ char default_group[NIS_MAXNAMELEN + 1];
+ char *cptr, *dptr;
- char *cptr = defaults;
- if (cptr == NULL)
- cptr = getenv ("NIS_DEFAULTS");
+ strcpy (default_group, nis_local_group ());
- if (cptr != NULL)
+ if (defaults != NULL)
{
- char *dptr = strstr (cptr, "group=");
+ dptr = strstr (defaults, "group=");
if (dptr != NULL)
{
- char *p = searchgroup (dptr);
- if (p == NULL)
- return NULL;
- default_group = strdupa (p);
+ char *p = searchgroup (defaults);
+
+ if (strlen (p) <= NIS_MAXNAMELEN)
+ strcpy (default_group, 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 ?: nis_local_group ());
+ return strdup (default_group);
}
libnsl_hidden_def (__nis_default_group)
-
uint32_t
__nis_default_ttl (char *defaults)
{
@@ -447,7 +480,7 @@ __nis_default_access (char *param, unsigned int defaults)
{
cptr = getenv ("NIS_DEFAULTS");
if (cptr != NULL && strstr (cptr, "access=") != NULL)
- result = searchaccess (cptr, result);
+ result = searchaccess (getenv ("NIS_DEFAULTS"), result);
}
return result;
diff --git a/nis/nis_domain_of.c b/nis/nis_domain_of.c
index 4d6b48640e..eca2066aa3 100644
--- a/nis/nis_domain_of.c
+++ b/nis/nis_domain_of.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 1997, 2007 Free Software Foundation, Inc.
+/* Copyright (c) 1997 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
@@ -26,17 +26,3 @@ nis_domain_of (const_nis_name name)
return nis_domain_of_r (name, result, NIS_MAXNAMELEN);
}
-
-const_nis_name
-__nis_domain_of (const_nis_name name)
-{
- const_nis_name cptr = strchr (name, '.');
-
- if (cptr++ == NULL)
- return "";
-
- if (*cptr == '\0')
- return ".";
-
- return cptr;
-}
diff --git a/nis/nis_domain_of_r.c b/nis/nis_domain_of_r.c
index e2db146038..1fedcfe074 100644
--- a/nis/nis_domain_of_r.c
+++ b/nis/nis_domain_of_r.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 1997, 2004, 2006 Free Software Foundation, Inc.
+/* Copyright (c) 1997, 2004 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
@@ -29,7 +29,6 @@ nis_domain_of_r (const_nis_name name, char *buffer, size_t buflen)
if (buffer == NULL)
{
- erange:
__set_errno (ERANGE);
return NULL;
}
@@ -45,11 +44,7 @@ nis_domain_of_r (const_nis_name name, char *buffer, size_t buflen)
cptr_len = strlen (cptr);
if (cptr_len == 0)
- {
- if (buflen < 2)
- goto erange;
- return strcpy (buffer, ".");
- }
+ return strcpy (buffer, ".");
if (__builtin_expect (cptr_len >= buflen, 0))
{
diff --git a/nis/nis_error.c b/nis/nis_error.c
index d92ad03604..147f88ce15 100644
--- a/nis/nis_error.c
+++ b/nis/nis_error.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 1997,1998,1999,2004,2005,2006 Free Software Foundation, Inc.
+/* Copyright (c) 1997, 1998, 1999, 2004 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
@@ -24,41 +24,65 @@
#include <rpcsvc/nis.h>
-#define MF(line) MF1 (line)
-#define MF1(line) str##line
-static const union msgstr_t
+static const char *nis_errlist[] =
{
- struct
- {
-#define S(s) char MF(__LINE__)[sizeof (s)];
-#include "nis_error.h"
-#undef S
- };
- char str[0];
-} msgstr =
- {
- {
-#define S(s) s,
-#include "nis_error.h"
-#undef S
- }
- };
-
-static const unsigned short int msgidx[] =
- {
-#define S(s) offsetof (union msgstr_t, MF (__LINE__)),
-#include "nis_error.h"
-#undef S
- };
-
+ N_("Success"),
+ N_("Probable success"),
+ N_("Not found"),
+ N_("Probably not found"),
+ N_("Cache expired"),
+ N_("NIS+ servers unreachable"),
+ N_("Unknown object"),
+ N_("Server busy, try again"),
+ N_("Generic system error"),
+ N_("First/next chain broken"),
+ N_("Permission denied"),
+ N_("Not owner"),
+ N_("Name not served by this server"),
+ N_("Server out of memory"),
+ N_("Object with same name exists"),
+ N_("Not master server for this domain"),
+ N_("Invalid object for operation"),
+ N_("Malformed name, or illegal name"),
+ N_("Unable to create callback"),
+ N_("Results sent to callback proc"),
+ N_("Not found, no such name"),
+ N_("Name/entry isn't unique"),
+ N_("Modification failed"),
+ N_("Database for table does not exist"),
+ N_("Entry/table type mismatch"),
+ N_("Link points to illegal name"),
+ N_("Partial success"),
+ N_("Too many attributes"),
+ N_("Error in RPC subsystem"),
+ N_("Missing or malformed attribute"),
+ N_("Named object is not searchable"),
+ N_("Error while talking to callback proc"),
+ N_("Non NIS+ namespace encountered"),
+ N_("Illegal object type for operation"),
+ N_("Passed object is not the same object on server"),
+ N_("Modify operation failed"),
+ N_("Query illegal for named table"),
+ N_("Attempt to remove a non-empty table"),
+ N_("Error in accessing NIS+ cold start file. Is NIS+ installed?"),
+ N_("Full resync required for directory"),
+ N_("NIS+ operation failed"),
+ N_("NIS+ service is unavailable or not installed"),
+ N_("Yes, 42 is the meaning of life"),
+ N_("Unable to authenticate NIS+ server"),
+ N_("Unable to authenticate NIS+ client"),
+ N_("No file space on server"),
+ N_("Unable to create process on server"),
+ N_("Master server busy, full dump rescheduled.")
+};
const char *
nis_sperrno (const nis_error status)
{
- if (status >= sizeof (msgidx) / sizeof (msgidx[0]))
+ if (status >= (sizeof (nis_errlist) / sizeof (nis_errlist[0])))
return "???";
else
- return gettext (msgstr.str + msgidx[status]);
+ return gettext (nis_errlist[status]);
}
libnsl_hidden_def (nis_sperrno)
@@ -78,21 +102,26 @@ char *
nis_sperror_r (const nis_error status, const char *label,
char *buffer, size_t buflen)
{
- if (snprintf (buffer, buflen, "%s: %s", label, nis_sperrno (status))
- >= buflen)
+ const char *cptr;
+
+ cptr = nis_sperrno (status);
+
+ if ((strlen (cptr) + strlen (label) + 3) > buflen)
{
- __set_errno (ERANGE);
+ errno = ERANGE;
return NULL;
}
- return buffer;
+ sprintf (buffer, "%s: %s", label, cptr);
+
+ 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_error.h b/nis/nis_error.h
deleted file mode 100644
index add1316d9f..0000000000
--- a/nis/nis_error.h
+++ /dev/null
@@ -1,48 +0,0 @@
-S(N_("Success"))
-S(N_("Probable success"))
-S(N_("Not found"))
-S(N_("Probably not found"))
-S(N_("Cache expired"))
-S(N_("NIS+ servers unreachable"))
-S(N_("Unknown object"))
-S(N_("Server busy, try again"))
-S(N_("Generic system error"))
-S(N_("First/next chain broken"))
-S(N_("Permission denied"))
-S(N_("Not owner"))
-S(N_("Name not served by this server"))
-S(N_("Server out of memory"))
-S(N_("Object with same name exists"))
-S(N_("Not master server for this domain"))
-S(N_("Invalid object for operation"))
-S(N_("Malformed name, or illegal name"))
-S(N_("Unable to create callback"))
-S(N_("Results sent to callback proc"))
-S(N_("Not found, no such name"))
-S(N_("Name/entry isn't unique"))
-S(N_("Modification failed"))
-S(N_("Database for table does not exist"))
-S(N_("Entry/table type mismatch"))
-S(N_("Link points to illegal name"))
-S(N_("Partial success"))
-S(N_("Too many attributes"))
-S(N_("Error in RPC subsystem"))
-S(N_("Missing or malformed attribute"))
-S(N_("Named object is not searchable"))
-S(N_("Error while talking to callback proc"))
-S(N_("Non NIS+ namespace encountered"))
-S(N_("Illegal object type for operation"))
-S(N_("Passed object is not the same object on server"))
-S(N_("Modify operation failed"))
-S(N_("Query illegal for named table"))
-S(N_("Attempt to remove a non-empty table"))
-S(N_("Error in accessing NIS+ cold start file. Is NIS+ installed?"))
-S(N_("Full resync required for directory"))
-S(N_("NIS+ operation failed"))
-S(N_("NIS+ service is unavailable or not installed"))
-S(N_("Yes, 42 is the meaning of life"))
-S(N_("Unable to authenticate NIS+ server"))
-S(N_("Unable to authenticate NIS+ client"))
-S(N_("No file space on server"))
-S(N_("Unable to create process on server"))
-S(N_("Master server busy, full dump rescheduled."))
diff --git a/nis/nis_file.c b/nis/nis_file.c
index 566f30c48c..1f2295787c 100644
--- a/nis/nis_file.c
+++ b/nis/nis_file.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 1997, 1998, 1999, 2004, 2005 Free Software Foundation, Inc.
+/* Copyright (c) 1997, 1998, 1999, 2004 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@suse.de>, 1997.
@@ -23,30 +23,27 @@
#include <rpcsvc/nis.h>
#include "nis_xdr.h"
-typedef bool_t (*iofct_t) (XDR *, void *);
-typedef void (*freefct_t) (void *);
-
+static const char cold_start_file[] = "/var/nis/NIS_COLD_START";
-static void *
-read_nis_obj (const char *name, iofct_t readfct, freefct_t freefct,
- size_t objsize)
+directory_obj *
+readColdStartFile (void)
{
- FILE *in = fopen (name, "rc");
+ FILE *in = fopen (cold_start_file, "rc");
if (in == NULL)
return NULL;
- void *obj = calloc (1, objsize);
+ directory_obj *obj = calloc (1, sizeof (directory_obj));
if (obj != NULL)
{
XDR xdrs;
xdrstdio_create (&xdrs, in, XDR_DECODE);
- bool_t status = readfct (&xdrs, obj);
+ bool_t status = _xdr_directory_obj (&xdrs, obj);
xdr_destroy (&xdrs);
if (!status)
{
- freefct (obj);
+ nis_free_directory (obj);
obj = NULL;
}
}
@@ -55,49 +52,75 @@ read_nis_obj (const char *name, iofct_t readfct, freefct_t freefct,
return obj;
}
+libnsl_hidden_def (readColdStartFile)
-static bool_t
-write_nis_obj (const char *name, const void *obj, iofct_t writefct)
+bool_t
+writeColdStartFile (const directory_obj *obj)
{
- FILE *out = fopen (name, "w");
+ XDR xdrs;
+ FILE *out;
+ bool_t status;
+
+ out = fopen (cold_start_file, "wb");
if (out == NULL)
return FALSE;
- XDR xdrs;
xdrstdio_create (&xdrs, out, XDR_ENCODE);
- bool_t status = writefct (&xdrs, (void *) obj);
+ status = _xdr_directory_obj (&xdrs, (directory_obj *) obj);
xdr_destroy (&xdrs);
fclose (out);
return status;
}
+nis_object *
+nis_read_obj (const char *name)
+{
+ XDR xdrs;
+ FILE *in;
+ bool_t status;
+ nis_object *obj;
-static const char cold_start_file[] = "/var/nis/NIS_COLD_START";
+ in = fopen (name, "rb");
+ if (in == NULL)
+ return NULL;
-directory_obj *
-readColdStartFile (void)
-{
- return read_nis_obj (cold_start_file, (iofct_t) _xdr_directory_obj,
- (freefct_t) nis_free_directory, sizeof (directory_obj));
-}
-libnsl_hidden_def (readColdStartFile)
+ obj = calloc (1, sizeof (nis_object));
+ if (obj == NULL)
+ {
+ fclose (in);
+ return NULL;
+ }
-bool_t
-writeColdStartFile (const directory_obj *obj)
-{
- return write_nis_obj (cold_start_file, obj, (iofct_t) _xdr_directory_obj);
-}
+ xdrstdio_create (&xdrs, in, XDR_DECODE);
+ status =_xdr_nis_object (&xdrs, obj);
+ xdr_destroy (&xdrs);
+ fclose (in);
-nis_object *
-nis_read_obj (const char *name)
-{
- return read_nis_obj (name, (iofct_t) _xdr_nis_object,
- (freefct_t) nis_free_object, sizeof (nis_object));
+ if (status)
+ return obj;
+ else
+ {
+ nis_free_object (obj);
+ return NULL;
+ }
}
bool_t
nis_write_obj (const char *name, const nis_object *obj)
{
- return write_nis_obj (name, obj, (iofct_t) _xdr_nis_object);
+ XDR xdrs;
+ FILE *out;
+ bool_t status;
+
+ out = fopen (name, "wb");
+ if (out == NULL)
+ return FALSE;
+
+ xdrstdio_create (&xdrs, out, XDR_ENCODE);
+ status = _xdr_nis_object (&xdrs, (nis_object *) obj);
+ xdr_destroy (&xdrs);
+ fclose (out);
+
+ return status;
}
diff --git a/nis/nis_getservlist.c b/nis/nis_getservlist.c
index e57649d526..315960c8e8 100644
--- a/nis/nis_getservlist.c
+++ b/nis/nis_getservlist.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 1997, 1998, 1999, 2000, 2006 Free Software Foundation, Inc.
+/* Copyright (c) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
@@ -40,10 +40,7 @@ nis_getservlist (const_nis_name dir)
malloc (sizeof (nis_server *) *
(NIS_RES_OBJECT (res)->DI_data.do_servers.do_servers_len + 1));
if (__builtin_expect (serv == NULL, 0))
- {
- nis_freeresult (res);
- return NULL;
- }
+ return NULL;
for (i = 0; i < NIS_RES_OBJECT (res)->DI_data.do_servers.do_servers_len;
++i)
@@ -52,41 +49,13 @@ nis_getservlist (const_nis_name dir)
&NIS_RES_OBJECT (res)->DI_data.do_servers.do_servers_val[i];
serv[i] = calloc (1, sizeof (nis_server));
if (__builtin_expect (serv[i] == NULL, 0))
- {
- free_all:
- while (i-- > 0)
- {
- free (serv[i]->pkey.n_bytes);
- if (serv[i]->ep.ep_val != NULL)
- {
- unsigned long int j;
- for (j = 0; j < serv[i]->ep.ep_len; ++j)
- {
- free (serv[i]->ep.ep_val[j].proto);
- free (serv[i]->ep.ep_val[j].family);
- free (serv[i]->ep.ep_val[j].uaddr);
- }
- free (serv[i]->ep.ep_val);
- }
- free (serv[i]->name);
- free (serv[i]);
- }
-
- free (serv);
-
- nis_freeresult (res);
-
- return NULL;
- }
+ return NULL;
if (server->name != NULL)
{
serv[i]->name = strdup (server->name);
if (__builtin_expect (serv[i]->name == NULL, 0))
- {
- ++i;
- goto free_all;
- }
+ return NULL;
}
serv[i]->ep.ep_len = server->ep.ep_len;
@@ -97,10 +66,7 @@ nis_getservlist (const_nis_name dir)
serv[i]->ep.ep_val =
malloc (server->ep.ep_len * sizeof (endpoint));
if (__builtin_expect (serv[i]->ep.ep_val == NULL, 0))
- {
- ++i;
- goto free_all;
- }
+ return NULL;
for (j = 0; j < serv[i]->ep.ep_len; ++j)
{
@@ -121,20 +87,20 @@ nis_getservlist (const_nis_name dir)
serv[i]->ep.ep_val[j].proto = NULL;
}
}
-
+ else
+ serv[i]->ep.ep_val = NULL;
serv[i]->key_type = server->key_type;
serv[i]->pkey.n_len = server->pkey.n_len;
if (server->pkey.n_len > 0)
{
serv[i]->pkey.n_bytes = malloc (server->pkey.n_len);
if (__builtin_expect (serv[i]->pkey.n_bytes == NULL, 0))
- {
- ++i;
- goto free_all;
- }
+ return NULL;
memcpy (serv[i]->pkey.n_bytes, server->pkey.n_bytes,
server->pkey.n_len);
}
+ else
+ serv[i]->pkey.n_bytes = NULL;
}
serv[i] = NULL;
}
@@ -145,7 +111,8 @@ nis_getservlist (const_nis_name dir)
serv[0] = NULL;
}
- nis_freeresult (res);
+ if (res != NULL)
+ nis_freeresult (res);
return serv;
}
diff --git a/nis/nis_intern.h b/nis/nis_intern.h
index c805920aec..29a80a9188 100644
--- a/nis/nis_intern.h
+++ b/nis/nis_intern.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 1997,1998,1999,2000,2001,2006 Free Software Foundation, Inc.
+/* Copyright (c) 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@suse.de>, 1997.
@@ -66,7 +66,6 @@ extern nis_error __do_niscall3 (dir_binding *dbp, u_long prog,
xdrproc_t xargs, caddr_t req,
xdrproc_t xres, caddr_t resp,
unsigned int flags, nis_cb *cb);
-libnsl_hidden_proto (__do_niscall3)
extern u_short __pmap_getnisport (struct sockaddr_in *address, u_long program,
u_long version, u_int protocol);
diff --git a/nis/nis_ismember.c b/nis/nis_ismember.c
index 178b4890ef..f3f9bc9540 100644
--- a/nis/nis_ismember.c
+++ b/nis/nis_ismember.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 1997, 1998, 1999, 2006 Free Software Foundation, Inc.
+/* Copyright (c) 1997, 1998, 1999 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@suse.de>, 1997.
@@ -47,7 +47,8 @@ internal_ismember (const_nis_name principal, const_nis_name group)
res = nis_lookup (buf, EXPAND_NAME|FOLLOW_LINKS);
if (res == NULL || NIS_RES_STATUS (res) != NIS_SUCCESS)
{
- nis_freeresult (res);
+ if (res)
+ nis_freeresult (res);
return 0;
}
diff --git a/nis/nis_local_names.c b/nis/nis_local_names.c
index e9aea12a86..30fd208b75 100644
--- a/nis/nis_local_names.c
+++ b/nis/nis_local_names.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 1997, 1998, 2004, 2006 Free Software Foundation, Inc.
+/* Copyright (c) 1997, 1998, 2004 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
@@ -63,7 +63,7 @@ nis_local_directory (void)
__nisdomainname[0] = '\0';
else
{
- char *cp = rawmemchr (__nisdomainname, '\0');
+ char *cp = strchr (__nisdomainname, '\0');
/* Missing trailing dot? */
if (cp[-1] != '.')
@@ -154,7 +154,7 @@ nis_local_host (void)
__nishostname[0] = '\0';
else
{
- char *cp = rawmemchr (__nishostname, '\0');
+ char *cp = strchr (__nishostname, '\0');
int len = cp - __nishostname;
/* Hostname already fully qualified? */
diff --git a/nis/nis_lookup.c b/nis/nis_lookup.c
index 9677b4d3d1..0b97e67a61 100644
--- a/nis/nis_lookup.c
+++ b/nis/nis_lookup.c
@@ -1,5 +1,4 @@
-/* Copyright (C) 1997-1999, 2004, 2005, 2006, 2007
- Free Software Foundation, Inc.
+/* Copyright (C) 1997, 1998, 1999, 2004 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@uni-paderborn.de>, 1997.
@@ -22,8 +21,6 @@
#include <rpcsvc/nis.h>
#include "nis_xdr.h"
#include "nis_intern.h"
-#include <libnsl.h>
-
nis_result *
nis_lookup (const_nis_name name, const unsigned int flags)
@@ -64,16 +61,36 @@ nis_lookup (const_nis_name name, const unsigned int flags)
req.ns_object.ns_object_len = 0;
req.ns_object.ns_object_val = NULL;
- status = __prepare_niscall (req.ns_name, &dir, &bptr, flags);
- if (__builtin_expect (status != NIS_SUCCESS, 0))
+ status = __nisfind_server (req.ns_name, &dir);
+ if (status != NIS_SUCCESS)
{
NIS_RES_STATUS (res) = status;
- goto out;
+ return res;
+ }
+
+ status = __nisbind_create (&bptr, dir->do_servers.do_servers_val,
+ dir->do_servers.do_servers_len, flags);
+ if (status != NIS_SUCCESS)
+ {
+ NIS_RES_STATUS (res) = status;
+ nis_free_directory (dir);
+ return res;
+ }
+
+ while (__nisbind_connect (&bptr) != NIS_SUCCESS)
+ {
+ if (__nisbind_next (&bptr) != NIS_SUCCESS)
+ {
+ __nisbind_destroy (&bptr);
+ nis_free_directory (dir);
+ NIS_RES_STATUS (res) = NIS_NAMEUNREACHABLE;
+ return res;
+ }
}
do
{
- static const struct timeval RPCTIMEOUT = {10, 0};
+ static struct timeval RPCTIMEOUT = {10, 0};
enum clnt_stat result;
again:
@@ -90,9 +107,11 @@ nis_lookup (const_nis_name name, const unsigned int flags)
if (NIS_RES_STATUS (res) == NIS_SUCCESS)
{
- if (__type_of (NIS_RES_OBJECT (res)) == NIS_LINK_OBJ
- && (flags & FOLLOW_LINKS)) /* We are following links */
+ if (__type_of(NIS_RES_OBJECT (res)) == NIS_LINK_OBJ &&
+ flags & FOLLOW_LINKS) /* We are following links */
{
+ if (count_links)
+ free (req.ns_name);
/* if we hit the link limit, bail */
if (count_links > NIS_MAXLINKS)
{
@@ -101,68 +120,55 @@ nis_lookup (const_nis_name name, const unsigned int flags)
}
++count_links;
req.ns_name =
- strdupa (NIS_RES_OBJECT (res)->LI_data.li_name);
+ strdup (NIS_RES_OBJECT (res)->LI_data.li_name);
+ if (req.ns_name == NULL)
+ return NULL;
- /* The following is a non-obvious optimization. A
- nis_freeresult call would call xdr_free as the
- following code. But it also would unnecessarily
- free the result structure. We avoid this here
- along with the necessary tests. */
- xdr_free ((xdrproc_t) _xdr_nis_result, (char *) res);
- memset (res, '\0', sizeof (*res));
+ nis_freeresult (res);
+ res = calloc (1, sizeof (nis_result));
+ if (res == NULL)
+ {
+ __nisbind_destroy (&bptr);
+ return NULL;
+ }
link_first_try = 1; /* Try at first the old binding */
goto again;
}
}
else
- if (NIS_RES_STATUS (res) == NIS_SYSTEMERROR
- || NIS_RES_STATUS (res) == NIS_NOSUCHNAME
- || NIS_RES_STATUS (res) == NIS_NOT_ME)
+ if ((NIS_RES_STATUS (res) == NIS_SYSTEMERROR) ||
+ (NIS_RES_STATUS (res) == NIS_NOSUCHNAME) ||
+ (NIS_RES_STATUS (res) == NIS_NOT_ME))
{
if (link_first_try)
{
__nisbind_destroy (&bptr);
nis_free_directory (dir);
- /* Otherwise __nisfind_server will not do anything. */
- dir = NULL;
- if (__nisfind_server (req.ns_name, 1, &dir, &bptr,
- flags & ~MASTER_ONLY)
- != NIS_SUCCESS)
- goto out;
+ if (__nisfind_server (req.ns_name, &dir) != NIS_SUCCESS)
+ return res;
+
+ if (__nisbind_create (&bptr,
+ dir->do_servers.do_servers_val,
+ dir->do_servers.do_servers_len,
+ flags) != NIS_SUCCESS)
+ {
+ nis_free_directory (dir);
+ return res;
+ }
}
else
if (__nisbind_next (&bptr) != NIS_SUCCESS)
- {
- /* No more servers to search. Try parent. */
- const char *ndomain = __nis_domain_of (req.ns_name);
- req.ns_name = strdupa (ndomain);
- if (strcmp (req.ns_name, ".") == 0)
- {
- NIS_RES_STATUS (res) = NIS_NAMEUNREACHABLE;
- goto out;
- }
-
- __nisbind_destroy (&bptr);
- nis_free_directory (dir);
- dir = NULL;
- status = __prepare_niscall (req.ns_name, &dir,
- &bptr, flags);
- if (__builtin_expect (status != NIS_SUCCESS, 0))
- {
- NIS_RES_STATUS (res) = status;
- goto out;
- }
- goto again;
- }
+ break; /* No more servers to search */
while (__nisbind_connect (&bptr) != NIS_SUCCESS)
{
if (__nisbind_next (&bptr) != NIS_SUCCESS)
{
+ __nisbind_destroy (&bptr);
nis_free_directory (dir);
- goto out;
+ return res;
}
}
goto again;
@@ -179,7 +185,7 @@ nis_lookup (const_nis_name name, const unsigned int flags)
if (status != NIS_SUCCESS)
{
NIS_RES_STATUS (res) = status;
- goto out;
+ return res;
}
switch (NIS_RES_STATUS (res))
@@ -211,7 +217,6 @@ nis_lookup (const_nis_name name, const unsigned int flags)
}
}
- out:
if (names != namebuf)
nis_freenames (names);
diff --git a/nis/nis_ping.c b/nis/nis_ping.c
index 81afc5e8e3..d9924f9279 100644
--- a/nis/nis_ping.c
+++ b/nis/nis_ping.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 1997, 1998, 1999, 2006 Free Software Foundation, Inc.
+/* Copyright (c) 1997, 1998, 1999 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@suse.de>, 1997.
@@ -39,7 +39,8 @@ nis_ping (const_nis_name dirname, unsigned int utime,
res = nis_lookup (dirname, MASTER_ONLY);
if (res == NULL || NIS_RES_STATUS (res) != NIS_SUCCESS)
{
- nis_freeresult (res);
+ if (res)
+ nis_freeresult (res);
return;
}
obj = res->objects.objects_val;
@@ -50,7 +51,8 @@ nis_ping (const_nis_name dirname, unsigned int utime,
/* Check if obj is really a diryectory object */
if (__type_of (obj) != NIS_DIRECTORY_OBJ)
{
- nis_freeresult (res);
+ if (res != NULL)
+ nis_freeresult (res);
return;
}
@@ -66,5 +68,6 @@ nis_ping (const_nis_name dirname, unsigned int utime,
NIS_PING, (xdrproc_t) _xdr_ping_args,
(caddr_t) &args, (xdrproc_t) xdr_void,
(caddr_t) NULL, 0, NULL);
- nis_freeresult (res);
+ if (res)
+ nis_freeresult (res);
}
diff --git a/nis/nis_print_group_entry.c b/nis/nis_print_group_entry.c
index 91e6399b90..6f0ba8fbd4 100644
--- a/nis/nis_print_group_entry.c
+++ b/nis/nis_print_group_entry.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
+/* Copyright (c) 1997, 1998, 2000, 2004 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
@@ -45,16 +45,12 @@ nis_print_group_entry (const_nis_name group)
}
res = nis_lookup (buf, FOLLOW_LINKS | EXPAND_NAME);
- if (res == NULL)
+ if (NIS_RES_STATUS(res) != NIS_SUCCESS)
return;
- if (NIS_RES_STATUS (res) != NIS_SUCCESS
- || NIS_RES_NUMOBJ (res) != 1
- || __type_of (NIS_RES_OBJECT (res)) != NIS_GROUP_OBJ)
- {
- nis_freeresult (res);
- return;
- }
+ if ((NIS_RES_NUMOBJ (res) != 1) ||
+ (__type_of (NIS_RES_OBJECT (res)) != NIS_GROUP_OBJ))
+ return;
char *mem_exp[NIS_RES_NUMOBJ (res)];
char *mem_imp[NIS_RES_NUMOBJ (res)];
diff --git a/nis/nis_removemember.c b/nis/nis_removemember.c
index 2e45b4fb79..b9e27ab48c 100644
--- a/nis/nis_removemember.c
+++ b/nis/nis_removemember.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 1997,1998,1999,2004,2005,2006 Free Software Foundation, Inc.
+/* Copyright (c) 1997, 1998, 1999, 2004 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
@@ -28,12 +28,15 @@ nis_removemember (const_nis_name member, const_nis_name group)
{
size_t grouplen = strlen (group);
char buf[grouplen + 14 + NIS_MAXNAMELEN];
+ char leafbuf[grouplen + 2];
char domainbuf[grouplen + 2];
+ nis_name *newmem;
nis_result *res, *res2;
nis_error status;
char *cp, *cp2;
+ unsigned long int i, j, k;
- cp = rawmemchr (nis_leaf_of_r (group, buf, sizeof (buf) - 1), '\0');
+ cp = stpcpy (buf, nis_leaf_of_r (group, leafbuf, sizeof (leafbuf) - 1));
cp = stpcpy (cp, ".groups_dir");
cp2 = nis_domain_of_r (group, domainbuf, sizeof (domainbuf) - 1);
if (cp2 != NULL && cp2[0] != '\0')
@@ -41,41 +44,60 @@ nis_removemember (const_nis_name member, const_nis_name group)
cp = stpcpy (cp, ".");
stpcpy (cp, cp2);
}
- res = nis_lookup (buf, FOLLOW_LINKS | EXPAND_NAME);
- if (res == NULL)
- return NIS_NOMEMORY;
- if (NIS_RES_STATUS (res) != NIS_SUCCESS)
+ res = nis_lookup (buf, FOLLOW_LINKS|EXPAND_NAME);
+ if (res == NULL || NIS_RES_STATUS (res) != NIS_SUCCESS)
{
- status = NIS_RES_STATUS (res);
- nis_freeresult (res);
+ if (res)
+ {
+ status = NIS_RES_STATUS (res);
+ nis_freeresult (res);
+ }
+ else
+ return NIS_NOMEMORY;
return status;
}
- if (NIS_RES_NUMOBJ (res) != 1
- || __type_of (NIS_RES_OBJECT (res)) != NIS_GROUP_OBJ)
+ if ((res->objects.objects_len != 1) ||
+ (__type_of (NIS_RES_OBJECT (res)) != NIS_GROUP_OBJ))
{
nis_freeresult (res);
return NIS_INVALIDOBJ;
}
- nis_name *gr_members_val
- = NIS_RES_OBJECT(res)->GR_data.gr_members.gr_members_val;
- u_int gr_members_len
- = NIS_RES_OBJECT(res)->GR_data.gr_members.gr_members_len;
+ newmem =
+ calloc (NIS_RES_OBJECT(res)->GR_data.gr_members.gr_members_len,
+ sizeof (char *));
+ if (newmem == NULL)
+ return NIS_NOMEMORY;
- u_int j = 0;
- for (u_int i = 0; i < gr_members_len; ++i)
- if (strcmp (gr_members_val[i], member) != 0)
- gr_members_val[j++] = gr_members_val[i];
- else
- free (gr_members_val[i]);
+ k = NIS_RES_OBJECT (res)[0].GR_data.gr_members.gr_members_len;
+ j = 0;
+ for (i = 0; i < NIS_RES_OBJECT(res)->GR_data.gr_members.gr_members_len;
+ ++i)
+ {
+ if (strcmp (NIS_RES_OBJECT(res)->GR_data.gr_members.gr_members_val[i],
+ member) != 0)
+ {
+ newmem[j] = NIS_RES_OBJECT(res)->GR_data.gr_members.gr_members_val[i];
+ ++j;
+ }
+ else
+ {
+ free (NIS_RES_OBJECT(res)->GR_data.gr_members.gr_members_val[i]);
+ --k;
+ }
+ }
+ free (NIS_RES_OBJECT (res)->GR_data.gr_members.gr_members_val);
+ assert (k <= NIS_RES_OBJECT(res)->GR_data.gr_members.gr_members_len);
+ /* This realloc() call always decreases the size. This cannot
+ fail. We still have the test but do not recover memory
+ (i.e., we overwrite the input pointer). */
+ newmem = realloc (newmem, k * sizeof (char*));
+ if (newmem == NULL)
+ return NIS_NOMEMORY;
- /* There is no need to reallocate the gr_members_val array. We
- just adjust the size to match the number of strings still in
- it. Yes, xdr_array will use mem_free with a size parameter
- but this is mapped to a simple free call which determines the
- size of the block by itself. */
- NIS_RES_OBJECT (res)->GR_data.gr_members.gr_members_len = j;
+ NIS_RES_OBJECT (res)->GR_data.gr_members.gr_members_val = newmem;
+ NIS_RES_OBJECT (res)->GR_data.gr_members.gr_members_len = k;
cp = stpcpy (buf, NIS_RES_OBJECT (res)->zo_name);
*cp++ = '.';
diff --git a/nis/nis_subr.c b/nis/nis_subr.c
index c68189e541..4c4ef8b5b4 100644
--- a/nis/nis_subr.c
+++ b/nis/nis_subr.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 1997,1999,2000,2004,2005,2006 Free Software Foundation, Inc.
+/* Copyright (c) 1997, 1999, 2000, 2004 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
@@ -39,13 +39,22 @@ nis_leaf_of_r (const_nis_name name, char *buffer, size_t buflen)
while (name[i] != '.' && name[i] != '\0')
i++;
- if (__builtin_expect (i >= buflen, 0))
+ if (i > buflen - 1)
{
__set_errno (ERANGE);
return NULL;
}
- *((char *) __mempcpy (buffer, name, i)) = '\0';
+ if (i > 0)
+ {
+ if ((size_t)i >= buflen)
+ {
+ __set_errno (ERANGE);
+ return NULL;
+ }
+
+ *((char *) __mempcpy (buffer, name, i)) = '\0';
+ }
return buffer;
}
@@ -89,12 +98,13 @@ nis_name_of_r (const_nis_name name, char *buffer, size_t buflen)
}
libnsl_hidden_def (nis_name_of_r)
-static int __always_inline
+static int
count_dots (const_nis_name str)
{
int count = 0;
+ size_t l = strlen (str);
- for (size_t i = 0; str[i] != '\0'; ++i)
+ for (size_t i = 0; i < l; ++i)
if (str[i] == '.')
++count;
@@ -107,23 +117,25 @@ count_dots (const_nis_name str)
nis_name *
nis_getnames (const_nis_name name)
{
- const char *local_domain = nis_local_directory ();
- size_t local_domain_len = strlen (local_domain);
- size_t name_len = strlen (name);
+ nis_name *getnames = NULL;
+ char local_domain[NIS_MAXNAMELEN + 1];
char *path;
+ char *cp;
+ int count;
int pos = 0;
- char *saveptr;
int have_point;
- const char *cp;
- const char *cp2;
+ char *saveptr;
- int count = 2;
- nis_name *getnames = malloc ((count + 1) * sizeof (char *));
+ strncpy (local_domain, nis_local_directory (), NIS_MAXNAMELEN);
+ local_domain[NIS_MAXNAMELEN] = '\0';
+
+ count = 1;
+ getnames = malloc ((count + 1) * sizeof (char *));
if (__builtin_expect (getnames == NULL, 0))
return NULL;
/* Do we have a fully qualified NIS+ name ? If yes, give it back */
- if (name[name_len - 1] == '.')
+ if (name[strlen (name) - 1] == '.')
{
if ((getnames[0] = strdup (name)) == NULL)
{
@@ -139,44 +151,6 @@ nis_getnames (const_nis_name name)
return getnames;
}
- /* If the passed NAME is shared a suffix (the latter of course with
- a final dot) with each other we pass back NAME with a final
- dot. */
- if (local_domain_len > 2)
- {
- have_point = 0;
- cp = &local_domain[local_domain_len - 2];
- cp2 = &name[name_len - 1];
-
- while (*cp == *cp2)
- {
- if (*cp == '.')
- have_point = 1;
- --cp;
- --cp2;
- if (cp < local_domain)
- {
- have_point = cp2 < name || *cp2 == '.';
- break;
- }
- if (cp2 < name)
- {
- have_point = *cp == '.';
- break;
- }
- }
-
- if (have_point)
- {
- getnames[0] = malloc (name_len + 2);
- if (getnames[0] == NULL)
- goto free_null;
-
- strcpy (stpcpy (getnames[0], name), ".");
- ++pos;
- }
- }
-
/* Get the search path, where we have to search "name" */
path = getenv ("NIS_PATH");
if (path == NULL)
@@ -184,17 +158,17 @@ nis_getnames (const_nis_name name)
else
path = strdupa (path);
- have_point = strchr (name, '.') != NULL;
+ have_point = (strchr (name, '.') != NULL);
cp = __strtok_r (path, ":", &saveptr);
while (cp)
{
if (strcmp (cp, "$") == 0)
{
- const char *cptr = local_domain;
+ char *cptr = local_domain;
char *tmp;
- while (*cptr != '\0' && count_dots (cptr) >= 2)
+ while ((have_point && *cptr != '\0') || (count_dots (cptr) >= 2))
{
if (pos >= count)
{
@@ -205,7 +179,8 @@ nis_getnames (const_nis_name name)
goto free_null;
getnames = newp;
}
- tmp = malloc (strlen (cptr) + local_domain_len + name_len + 2);
+ tmp = malloc (strlen (cptr) + strlen (local_domain) +
+ strlen (name) + 2);
if (__builtin_expect (tmp == NULL, 0))
goto free_null;
@@ -235,7 +210,7 @@ nis_getnames (const_nis_name name)
{
char *p;
- tmp = malloc (cplen + local_domain_len + name_len + 2);
+ tmp = malloc (cplen + strlen (local_domain) + strlen (name) + 2);
if (__builtin_expect (tmp == NULL, 0))
goto free_null;
@@ -251,16 +226,13 @@ nis_getnames (const_nis_name name)
{
char *p;
- tmp = malloc (cplen + name_len + 3);
+ tmp = malloc (cplen + strlen (name) + 2);
if (__builtin_expect (tmp == NULL, 0))
goto free_null;
- p = __mempcpy (tmp, name, name_len);
+ p = __stpcpy (tmp, name);
*p++ = '.';
- p = __mempcpy (p, cp, cplen);
- if (p[-1] != '.')
- *p++ = '.';
- *p = '\0';
+ memcpy (p, cp, cplen + 1);
}
if (pos >= count)
@@ -278,13 +250,6 @@ nis_getnames (const_nis_name name)
cp = __strtok_r (NULL, ":", &saveptr);
}
- if (pos == 0
- && __asprintf (&getnames[pos++], "%s%s%s%s",
- name, name[name_len - 1] == '.' ? "" : ".",
- local_domain,
- local_domain[local_domain_len - 1] == '.' ? "" : ".") < 0)
- goto free_null;
-
getnames[pos] = NULL;
return getnames;
diff --git a/nis/nis_table.c b/nis/nis_table.c
index 70b4701419..13acdfdf50 100644
--- a/nis/nis_table.c
+++ b/nis/nis_table.c
@@ -1,5 +1,4 @@
-/* Copyright (c) 1997-1999, 2003, 2004, 2005, 2006, 2007
- Free Software Foundation, Inc.
+/* Copyright (c) 1997, 1998, 1999, 2003, 2004 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@suse.de>, 1997.
@@ -18,21 +17,21 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
-#include <assert.h>
#include <string.h>
#include <rpcsvc/nis.h>
#include "nis_xdr.h"
#include "nis_intern.h"
-#include "libnsl.h"
-struct ib_request *
+static struct ib_request *
__create_ib_request (const_nis_name name, unsigned int flags)
{
- struct ib_request *ibreq = calloc (1, sizeof (struct ib_request));
+ struct ib_request *ibreq = calloc (1, sizeof (ib_request));
+ char buf[strlen (name) + 1];
nis_attr *search_val = NULL;
size_t search_len = 0;
+ char *cptr;
size_t size = 0;
if (ibreq == NULL)
@@ -40,26 +39,18 @@ __create_ib_request (const_nis_name name, unsigned int flags)
ibreq->ibr_flags = flags;
- char *cptr = strdupa (name);
+ cptr = strcpy (buf, name);
/* Not of "[key=value,key=value,...],foo.." format? */
if (cptr[0] != '[')
- {
- ibreq->ibr_name = strdup (cptr);
- if (ibreq->ibr_name == NULL)
- {
- free (ibreq);
- return NULL;
- }
- return ibreq;
- }
+ return (ibreq->ibr_name = strdup (cptr)) == NULL ? NULL : ibreq;
/* "[key=value,...],foo" format */
ibreq->ibr_name = strchr (cptr, ']');
if (ibreq->ibr_name == NULL || ibreq->ibr_name[1] != ',')
{
- /* The object has not really been built yet so we use free. */
- free (ibreq);
+ ibreq->ibr_name = NULL; /* Or the xdr_* functions will dump */
+ nis_free_request (ibreq);
return NULL;
}
@@ -94,22 +85,21 @@ __create_ib_request (const_nis_name name, unsigned int flags)
if (cptr != NULL)
*cptr++ = '\0';
- if (__builtin_expect (val == NULL, 0))
+ if (!val)
{
nis_free_request (ibreq);
return NULL;
}
*val++ = '\0';
- if (search_len + 1 >= size)
+ if ((search_len + 1) >= size)
{
size += 1;
- nis_attr *newp = realloc (search_val, size * sizeof (nis_attr));
- if (newp == NULL)
+ search_val = realloc (search_val, size * sizeof (nis_attr));
+ if (search_val == NULL)
goto free_null;
- search_val = newp;
}
search_val[search_len].zattr_ndx = strdup (key);
- if (search_val[search_len].zattr_ndx == NULL)
+ if ((search_val[search_len].zattr_ndx) == NULL)
goto free_null;
search_val[search_len].zattr_val.zattr_val_len = strlen (val) + 1;
@@ -128,18 +118,18 @@ __create_ib_request (const_nis_name name, unsigned int flags)
return ibreq;
}
-libnsl_hidden_def (__create_ib_request)
-static const struct timeval RPCTIMEOUT = {10, 0};
+static struct timeval RPCTIMEOUT = {10, 0};
static char *
-get_tablepath (char *name, dir_binding *bptr)
+__get_tablepath (char *name, dir_binding *bptr)
{
enum clnt_stat result;
- nis_result res;
+ nis_result *res = calloc (1, sizeof (nis_result));
struct ns_request req;
- memset (&res, '\0', sizeof (res));
+ if (res == NULL)
+ return NULL;
req.ns_name = name;
req.ns_object.ns_object_len = 0;
@@ -147,54 +137,21 @@ 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);
- 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;
+ 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;
+ }
else
- cptr = "";
-
- char *str = strdup (cptr);
-
- if (result == RPC_SUCCESS)
- xdr_free ((xdrproc_t) _xdr_nis_result, (char *) &res);
-
- return str;
-}
-
-
-nis_error
-__follow_path (char **tablepath, char **tableptr, struct ib_request *ibreq,
- dir_binding *bptr)
-{
- if (*tablepath == NULL)
{
- *tablepath = get_tablepath (ibreq->ibr_name, bptr);
- if (*tablepath == NULL)
- return NIS_NOMEMORY;
-
- *tableptr = *tablepath;
+ nis_freeresult (res);
+ return strdup ("");
}
- if (*tableptr == NULL)
- return NIS_NOTFOUND;
-
- char *newname = strsep (tableptr, ":");
- if (newname[0] == '\0')
- return NIS_NOTFOUND;
-
- newname = strdup (newname);
- if (newname == NULL)
- return NIS_NOMEMORY;
-
- free (ibreq->ibr_name);
- ibreq->ibr_name = newname;
-
- return NIS_SUCCESS;
}
-libnsl_hidden_def (__follow_path)
-
nis_result *
nis_list (const_nis_name name, unsigned int flags,
@@ -203,7 +160,7 @@ nis_list (const_nis_name name, unsigned int flags,
const void *userdata),
const void *userdata)
{
- nis_result *res = malloc (sizeof (nis_result));
+ nis_result *res = calloc (1, sizeof (nis_result));
ib_request *ibreq;
int status;
enum clnt_stat clnt_status;
@@ -213,29 +170,23 @@ 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;
- char *tablepath = NULL;
+ char *tableptr, *tablepath = NULL;
+ int have_tablepath = 0;
int first_try = 0; /* Do we try the old binding at first ? */
- nis_result *allres = NULL;
if (res == NULL)
return NULL;
if (name == NULL)
{
- status = NIS_BADNAME;
- err_out:
- nis_freeresult (allres);
- memset (res, '\0', sizeof (nis_result));
- NIS_RES_STATUS (res) = status;
+ NIS_RES_STATUS (res) = NIS_BADNAME;
return res;
}
- ibreq = __create_ib_request (name, flags);
- if (ibreq == NULL)
+ if ((ibreq = __create_ib_request (name, flags)) == NULL)
{
- status = NIS_BADNAME;
- goto err_out;
+ NIS_RES_STATUS (res) = NIS_BADNAME;
+ return res;
}
if ((flags & EXPAND_NAME)
@@ -247,16 +198,15 @@ nis_list (const_nis_name name, unsigned int flags,
if (names == NULL)
{
nis_free_request (ibreq);
- status = NIS_BADNAME;
- goto err_out;
+ NIS_RES_STATUS (res) = NIS_BADNAME;
+ return res;
}
ibreq->ibr_name = strdup (names[name_nr]);
if (ibreq->ibr_name == NULL)
{
- nis_freenames (names);
nis_free_request (ibreq);
- status = NIS_NOMEMORY;
- goto err_out;
+ NIS_RES_STATUS (res) = NIS_NOMEMORY;
+ return res;
}
}
else
@@ -274,25 +224,36 @@ nis_list (const_nis_name name, unsigned int flags,
memset (res, '\0', sizeof (nis_result));
- status = __nisfind_server (ibreq->ibr_name,
- ibreq->ibr_srch.ibr_srch_val != NULL,
- &dir, &bptr, flags & ~MASTER_ONLY);
+ status = __nisfind_server (ibreq->ibr_name, &dir);
if (status != NIS_SUCCESS)
- {
+ {
+ nis_free_request (ibreq);
NIS_RES_STATUS (res) = status;
- goto fail3;
- }
+ return res;
+ }
+
+ status = __nisbind_create (&bptr, dir->do_servers.do_servers_val,
+ 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;
+ }
while (__nisbind_connect (&bptr) != NIS_SUCCESS)
- if (__builtin_expect (__nisbind_next (&bptr) != NIS_SUCCESS, 0))
+ if (__nisbind_next (&bptr) != NIS_SUCCESS)
{
+ __nisbind_destroy (&bptr);
+ nis_free_directory (dir);
+ nis_free_request (ibreq);
NIS_RES_STATUS (res) = NIS_NAMEUNREACHABLE;
- goto fail;
+ return res;
}
if (callback != NULL)
{
- assert (cb == NULL);
cb = __nis_create_callback (callback, userdata, flags);
ibreq->ibr_cbhost.ibr_cbhost_len = 1;
ibreq->ibr_cbhost.ibr_cbhost_val = cb->serv;
@@ -304,7 +265,7 @@ nis_list (const_nis_name name, unsigned int flags,
(xdrproc_t) _xdr_nis_result,
(caddr_t) res, RPCTIMEOUT);
- if (__builtin_expect (clnt_status != RPC_SUCCESS, 0))
+ if (clnt_status != RPC_SUCCESS)
NIS_RES_STATUS (res) = NIS_RPCERROR;
else
switch (NIS_RES_STATUS (res))
@@ -312,13 +273,13 @@ 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;
/* If we hit the link limit, bail. */
- if (__builtin_expect (count_links > NIS_MAXLINKS, 0))
+ if (count_links > NIS_MAXLINKS)
{
NIS_RES_STATUS (res) = NIS_LINKNAMEERROR;
++done;
@@ -329,22 +290,8 @@ nis_list (const_nis_name name, unsigned int flags,
strdup (NIS_RES_OBJECT (res)->LI_data.li_name);
if (ibreq->ibr_name == NULL)
{
- NIS_RES_STATUS (res) = NIS_NOMEMORY;
- fail:
- __nisbind_destroy (&bptr);
- 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);
- nis_freeresult (allres);
+ NIS_RES_STATUS (res) = NIS_NOMEMORY;
return res;
}
if (NIS_RES_OBJECT (res)->LI_data.li_attrs.li_attrs_len)
@@ -355,88 +302,63 @@ 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. */
- xdr_free ((xdrproc_t) _xdr_nis_result, (char *)res);
- memset (res, '\0', sizeof (*res));
+ nis_freeresult (res);
+ res = calloc (1, sizeof (nis_result));
+ if (res == NULL)
+ {
+ if (have_tablepath)
+ free (tablepath);
+ __nisbind_destroy (&bptr);
+ nis_free_directory (dir);
+ return NULL;
+ }
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)
{
- clnt_status = __follow_path (&tablepath, &tableptr, ibreq,
- &bptr);
- if (clnt_status != NIS_SUCCESS)
+ if (!have_tablepath)
{
- NIS_RES_STATUS (res) = clnt_status;
- ++done;
+ tablepath = __get_tablepath (ibreq->ibr_name, &bptr);
+ tableptr = tablepath;
+ have_tablepath = 1;
}
- else
+ if (tableptr == NULL)
{
- /* The following is a non-obvious optimization. A
- nis_freeresult call would call xdr_free as the
- following code. But it also would unnecessarily
- free the result structure. We avoid this here
- along with the necessary tests. */
- xdr_free ((xdrproc_t) _xdr_nis_result, (char *) res);
- memset (res, '\0', sizeof (*res));
- first_try = 1;
- goto again;
+ ++done;
+ break;
}
- }
- else if ((flags & (FOLLOW_PATH | ALL_RESULTS))
- == (FOLLOW_PATH | ALL_RESULTS))
- {
- if (allres == NULL)
+ free (ibreq->ibr_name);
+ ibreq->ibr_name = strsep (&tableptr, ":");
+ if (ibreq->ibr_name == NULL || ibreq->ibr_name[0] == '\0')
{
- allres = res;
- res = malloc (sizeof (nis_result));
- if (res == NULL)
+ ibreq->ibr_name = strdup ("");
+ if (ibreq->ibr_name == NULL)
{
- res = allres;
- allres = NULL;
+ nis_free_request (ibreq);
NIS_RES_STATUS (res) = NIS_NOMEMORY;
- goto fail;
+ return res;
}
- NIS_RES_STATUS (res) = NIS_RES_STATUS (allres);
+ ++done;
}
else
{
- nis_object *objects_val
- = realloc (NIS_RES_OBJECT (allres),
- (NIS_RES_NUMOBJ (allres)
- + NIS_RES_NUMOBJ (res))
- * sizeof (nis_object));
- if (objects_val == NULL)
+ ibreq->ibr_name = strdup (ibreq->ibr_name);
+ nis_freeresult (res);
+ res = calloc (1, sizeof (nis_result));
+ if (res == NULL || ibreq->ibr_name == NULL)
{
- NIS_RES_STATUS (res) = NIS_NOMEMORY;
- goto fail;
+ free (res);
+ nis_free_request (ibreq);
+ if (have_tablepath)
+ free (tablepath);
+ __nisbind_destroy (&bptr);
+ nis_free_directory (dir);
+ return NULL;
}
- NIS_RES_OBJECT (allres) = objects_val;
- memcpy (NIS_RES_OBJECT (allres) + NIS_RES_NUMOBJ (allres),
- NIS_RES_OBJECT (res),
- NIS_RES_NUMOBJ (res) * sizeof (nis_object));
- NIS_RES_NUMOBJ (allres) += NIS_RES_NUMOBJ (res);
- NIS_RES_NUMOBJ (res) = 0;
- free (NIS_RES_OBJECT (res));
- NIS_RES_OBJECT (res) = NULL;
- NIS_RES_STATUS (allres) = NIS_RES_STATUS (res);
- xdr_free ((xdrproc_t) _xdr_nis_result, (char *) res);
- }
- clnt_status = __follow_path (&tablepath, &tableptr, ibreq,
- &bptr);
- if (clnt_status != NIS_SUCCESS)
- {
- /* Prepare for the nis_freeresult call. */
- memset (res, '\0', sizeof (*res));
-
- if (clnt_status == NIS_NOMEMORY)
- NIS_RES_STATUS (allres) = clnt_status;
- ++done;
+ first_try = 1;
+ goto again;
}
}
else
@@ -452,10 +374,32 @@ nis_list (const_nis_name name, unsigned int flags,
++done;
else
{
- NIS_RES_STATUS (res)
- = __follow_path (&tablepath, &tableptr, ibreq, &bptr);
- if (NIS_RES_STATUS (res) != NIS_SUCCESS)
- ++done;
+ if (!have_tablepath)
+ {
+ tablepath = __get_tablepath (ibreq->ibr_name, &bptr);
+ tableptr = tablepath;
+ have_tablepath = 1;
+ }
+ if (tableptr == NULL)
+ {
+ ++done;
+ break;
+ }
+ free (ibreq->ibr_name);
+ ibreq->ibr_name = strsep (&tableptr, ":");
+ if (ibreq->ibr_name == NULL || ibreq->ibr_name[0] == '\0')
+ {
+ ibreq->ibr_name = strdup ("");
+ ++done;
+ }
+ else
+ ibreq->ibr_name = strdup (ibreq->ibr_name);
+ if (ibreq->ibr_name == NULL)
+ {
+ nis_free_request (ibreq);
+ NIS_RES_STATUS (res) = NIS_NOMEMORY;
+ return res;
+ }
}
}
break;
@@ -488,7 +432,7 @@ nis_list (const_nis_name name, unsigned int flags,
/* Try the next domainname if we don't follow a link. */
free (ibreq->ibr_name);
ibreq->ibr_name = NULL;
- if (__builtin_expect (count_links, 0))
+ if (count_links)
{
NIS_RES_STATUS (res) = NIS_LINKNAMEERROR;
++done;
@@ -503,8 +447,9 @@ 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;
- goto fail;
+ return res;
}
first_try = 1; /* Try old binding at first */
goto again;
@@ -518,26 +463,17 @@ 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);
nis_free_request (ibreq);
- if (allres)
- {
- nis_freeresult (res);
- return allres;
- }
-
return res;
}
libnsl_hidden_def (nis_list)
@@ -545,7 +481,15 @@ libnsl_hidden_def (nis_list)
nis_result *
nis_add_entry (const_nis_name name, const nis_object *obj2, unsigned int flags)
{
- nis_result *res = calloc (1, sizeof (nis_result));
+ nis_object obj;
+ nis_result *res;
+ nis_error status;
+ ib_request *ibreq;
+ size_t namelen = strlen (name);
+ char buf1[namelen + 20];
+ char buf4[namelen + 20];
+
+ res = calloc (1, sizeof (nis_result));
if (res == NULL)
return NULL;
@@ -555,20 +499,14 @@ nis_add_entry (const_nis_name name, const nis_object *obj2, unsigned int flags)
return res;
}
- ib_request *ibreq = __create_ib_request (name, flags);
- if (ibreq == NULL)
+ if ((ibreq = __create_ib_request (name, flags)) == NULL)
{
NIS_RES_STATUS (res) = NIS_BADNAME;
return res;
}
- nis_object obj;
memcpy (&obj, obj2, sizeof (nis_object));
- size_t namelen = strlen (name);
- char buf1[namelen + 20];
- char buf4[namelen + 20];
-
if (obj.zo_name == NULL || strlen (obj.zo_name) == 0)
obj.zo_name = nis_leaf_of_r (name, buf1, sizeof (buf1));
@@ -589,12 +527,11 @@ nis_add_entry (const_nis_name name, const nis_object *obj2, unsigned int flags)
}
ibreq->ibr_obj.ibr_obj_len = 1;
- nis_error status = __do_niscall (ibreq->ibr_name, NIS_IBADD,
- (xdrproc_t) _xdr_ib_request,
- (caddr_t) ibreq,
- (xdrproc_t) _xdr_nis_result,
- (caddr_t) res, 0, NULL);
- if (__builtin_expect (status != NIS_SUCCESS, 0))
+ if ((status = __do_niscall (ibreq->ibr_name, NIS_IBADD,
+ (xdrproc_t) _xdr_ib_request,
+ (caddr_t) ibreq,
+ (xdrproc_t) _xdr_nis_result,
+ (caddr_t) res, 0, NULL)) != NIS_SUCCESS)
NIS_RES_STATUS (res) = status;
nis_free_request (ibreq);
@@ -618,8 +555,7 @@ nis_modify_entry (const_nis_name name, const nis_object *obj2,
if (res == NULL)
return NULL;
- ibreq = __create_ib_request (name, flags);
- if (ibreq == NULL)
+ if (( ibreq =__create_ib_request (name, flags)) == NULL)
{
NIS_RES_STATUS (res) = NIS_BADNAME;
return res;
@@ -647,11 +583,10 @@ nis_modify_entry (const_nis_name name, const nis_object *obj2,
}
ibreq->ibr_obj.ibr_obj_len = 1;
- status = __do_niscall (ibreq->ibr_name, NIS_IBMODIFY,
- (xdrproc_t) _xdr_ib_request,
- (caddr_t) ibreq, (xdrproc_t) _xdr_nis_result,
- (caddr_t) res, 0, NULL);
- if (__builtin_expect (status != NIS_SUCCESS, 0))
+ if ((status = __do_niscall (ibreq->ibr_name, NIS_IBMODIFY,
+ (xdrproc_t) _xdr_ib_request,
+ (caddr_t) ibreq, (xdrproc_t) _xdr_nis_result,
+ (caddr_t) res, 0, NULL)) != NIS_SUCCESS)
NIS_RES_STATUS (res) = status;
nis_free_request (ibreq);
@@ -677,8 +612,7 @@ nis_remove_entry (const_nis_name name, const nis_object *obj,
return res;
}
- ibreq = __create_ib_request (name, flags);
- if (ibreq == NULL)
+ if ((ibreq =__create_ib_request (name, flags)) == NULL)
{
NIS_RES_STATUS (res) = NIS_BADNAME;
return res;
@@ -736,7 +670,7 @@ nis_first_entry (const_nis_name name)
(caddr_t) ibreq, (xdrproc_t) _xdr_nis_result,
(caddr_t) res, 0, NULL);
- if (__builtin_expect (status != NIS_SUCCESS, 0))
+ if (status != NIS_SUCCESS)
NIS_RES_STATUS (res) = status;
nis_free_request (ibreq);
@@ -779,7 +713,7 @@ nis_next_entry (const_nis_name name, const netobj *cookie)
(caddr_t) ibreq, (xdrproc_t) _xdr_nis_result,
(caddr_t) res, 0, NULL);
- if (__builtin_expect (status != NIS_SUCCESS, 0))
+ if (status != NIS_SUCCESS)
NIS_RES_STATUS (res) = status;
if (cookie != NULL)
diff --git a/nis/nis_xdr.c b/nis/nis_xdr.c
index 0c6452a6a7..2a75505b31 100644
--- a/nis/nis_xdr.c
+++ b/nis/nis_xdr.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 1997, 1998, 2005, 2006 Free Software Foundation, Inc.
+/* Copyright (c) 1997, 1998 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
@@ -28,415 +28,383 @@
static bool_t
xdr_nis_attr (XDR *xdrs, nis_attr *objp)
{
- bool_t res = xdr_string (xdrs, &objp->zattr_ndx, ~0);
- if (__builtin_expect (res, TRUE))
- res = xdr_bytes (xdrs, (char **) &objp->zattr_val.zattr_val_val,
- &objp->zattr_val.zattr_val_len, ~0);
- return res;
-}
-
-static __always_inline bool_t
-xdr_nis_name (XDR *xdrs, nis_name *objp)
-{
- return xdr_string (xdrs, objp, ~0);
+ if (!xdr_string (xdrs, &objp->zattr_ndx, ~0))
+ return FALSE;
+ if (!xdr_bytes (xdrs, (char **) &objp->zattr_val.zattr_val_val,
+ (u_int *) & objp->zattr_val.zattr_val_len, ~0))
+ return FALSE;
+ return TRUE;
}
bool_t
_xdr_nis_name (XDR *xdrs, nis_name *objp)
{
- return xdr_nis_name (xdrs, objp);
+ if (!xdr_string (xdrs, objp, ~0))
+ return FALSE;
+ return TRUE;
}
-static __always_inline bool_t
+static bool_t
xdr_zotypes (XDR *xdrs, zotypes *objp)
{
- return xdr_enum (xdrs, (enum_t *) objp);
+ if (!xdr_enum (xdrs, (enum_t *) objp))
+ return FALSE;
+ return TRUE;
}
-static __always_inline bool_t
+static bool_t
xdr_nstype (XDR *xdrs, nstype *objp)
{
- return xdr_enum (xdrs, (enum_t *) objp);
+ if (!xdr_enum (xdrs, (enum_t *) objp))
+ return FALSE;
+ return TRUE;
}
static bool_t
xdr_oar_mask (XDR *xdrs, oar_mask *objp)
{
- bool_t res = xdr_u_int (xdrs, &objp->oa_rights);
- if (__builtin_expect (res, TRUE))
- res = xdr_zotypes (xdrs, &objp->oa_otype);
- return res;
+ if (!xdr_u_int (xdrs, &objp->oa_rights))
+ return FALSE;
+ if (!xdr_zotypes (xdrs, &objp->oa_otype))
+ return FALSE;
+ return TRUE;
}
static bool_t
xdr_endpoint (XDR *xdrs, endpoint *objp)
{
- bool_t res = xdr_string (xdrs, &objp->uaddr, ~0);
- if (__builtin_expect (res, TRUE))
- {
- res = xdr_string (xdrs, &objp->family, ~0);
- if (__builtin_expect (res, 1))
- res = xdr_string (xdrs, &objp->proto, ~0);
- }
- return res;
+ if (!xdr_string (xdrs, &objp->uaddr, ~0))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->family, ~0))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->proto, ~0))
+ return FALSE;
+ return TRUE;
}
bool_t
_xdr_nis_server (XDR *xdrs, nis_server *objp)
{
- bool_t res = xdr_nis_name (xdrs, &objp->name);
- if (__builtin_expect (res, TRUE))
- {
- res = xdr_array (xdrs, (char **) &objp->ep.ep_val, &objp->ep.ep_len,
- ~0, sizeof (endpoint), (xdrproc_t) xdr_endpoint);
- if (__builtin_expect (res, TRUE))
- {
- res = xdr_u_int (xdrs, &objp->key_type);
- if (__builtin_expect (res, TRUE))
- res = xdr_netobj (xdrs, &objp->pkey);
- }
- }
- return res;
+ if (!_xdr_nis_name (xdrs, &objp->name))
+ return FALSE;
+ if (!xdr_array (xdrs, (char **) &objp->ep.ep_val, (u_int *) &objp->ep.ep_len,
+ ~0, sizeof (endpoint), (xdrproc_t) xdr_endpoint))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->key_type))
+ return FALSE;
+ if (!xdr_netobj (xdrs, &objp->pkey))
+ return FALSE;
+ return TRUE;
}
bool_t
_xdr_directory_obj (XDR *xdrs, directory_obj *objp)
{
- bool_t res = xdr_nis_name (xdrs, &objp->do_name);
- if (__builtin_expect (res, TRUE))
- {
- res = xdr_nstype (xdrs, &objp->do_type);
- if (__builtin_expect (res, TRUE))
- {
- res = xdr_array (xdrs, (char **) &objp->do_servers.do_servers_val,
- &objp->do_servers.do_servers_len, ~0,
- sizeof (nis_server), (xdrproc_t) _xdr_nis_server);
- if (__builtin_expect (res, TRUE))
- {
- res = xdr_uint32_t (xdrs, &objp->do_ttl);
- if (__builtin_expect (res, TRUE))
- res = xdr_array (xdrs,
- (char **) &objp->do_armask.do_armask_val,
- &objp->do_armask.do_armask_len, ~0,
- sizeof (oar_mask), (xdrproc_t) xdr_oar_mask);
- }
- }
- }
- return res;
+ if (!_xdr_nis_name (xdrs, &objp->do_name))
+ return FALSE;
+ if (!xdr_nstype (xdrs, &objp->do_type))
+ return FALSE;
+ if (!xdr_array (xdrs, (char **) &objp->do_servers.do_servers_val,
+ (u_int *) & objp->do_servers.do_servers_len, ~0,
+ sizeof (nis_server), (xdrproc_t) _xdr_nis_server))
+ return FALSE;
+
+ if (!xdr_uint32_t (xdrs, &objp->do_ttl))
+ return FALSE;
+ if (!xdr_array (xdrs, (char **) &objp->do_armask.do_armask_val,
+ (u_int *) & objp->do_armask.do_armask_len, ~0,
+ sizeof (oar_mask), (xdrproc_t) xdr_oar_mask))
+ return FALSE;
+ return TRUE;
}
static bool_t
xdr_entry_col (XDR *xdrs, entry_col *objp)
{
- bool_t res = xdr_u_int (xdrs, &objp->ec_flags);
- if (__builtin_expect (res, TRUE))
- res = xdr_bytes (xdrs, (char **) &objp->ec_value.ec_value_val,
- &objp->ec_value.ec_value_len, ~0);
- return res;
+ if (!xdr_u_int (xdrs, &objp->ec_flags))
+ return FALSE;
+ if (!xdr_bytes (xdrs, (char **) &objp->ec_value.ec_value_val,
+ (u_int *) &objp->ec_value.ec_value_len, ~0))
+ return FALSE;
+ return TRUE;
}
static bool_t
xdr_entry_obj (XDR *xdrs, entry_obj *objp)
{
- bool_t res = xdr_string (xdrs, &objp->en_type, ~0);
- if (__builtin_expect (res, TRUE))
- res = xdr_array (xdrs, (char **) &objp->en_cols.en_cols_val,
- &objp->en_cols.en_cols_len, ~0,
- sizeof (entry_col), (xdrproc_t) xdr_entry_col);
- return res;
+ if (!xdr_string (xdrs, &objp->en_type, ~0))
+ return FALSE;
+ if (!xdr_array (xdrs, (char **) &objp->en_cols.en_cols_val,
+ (u_int *) &objp->en_cols.en_cols_len, ~0,
+ sizeof (entry_col), (xdrproc_t) xdr_entry_col))
+ return FALSE;
+ return TRUE;
}
static bool_t
xdr_group_obj (XDR *xdrs, group_obj *objp)
{
- bool_t res = xdr_u_int (xdrs, &objp->gr_flags);
- if (__builtin_expect (res, TRUE))
- res = xdr_array (xdrs, (char **) &objp->gr_members.gr_members_val,
- &objp->gr_members.gr_members_len, ~0,
- sizeof (nis_name), (xdrproc_t) _xdr_nis_name);
- return res;
+ if (!xdr_u_int (xdrs, &objp->gr_flags))
+ return FALSE;
+ if (!xdr_array (xdrs, (char **) &objp->gr_members.gr_members_val,
+ (u_int *) &objp->gr_members.gr_members_len, ~0,
+ sizeof (nis_name), (xdrproc_t) _xdr_nis_name))
+ return FALSE;
+ return TRUE;
}
static bool_t
xdr_link_obj (XDR *xdrs, link_obj *objp)
{
- bool_t res = xdr_zotypes (xdrs, &objp->li_rtype);
- if (__builtin_expect (res, TRUE))
- {
- res = xdr_array (xdrs, (char **) &objp->li_attrs.li_attrs_val,
- &objp->li_attrs.li_attrs_len, ~0,
- sizeof (nis_attr), (xdrproc_t) xdr_nis_attr);
- if (__builtin_expect (res, TRUE))
- res = xdr_nis_name (xdrs, &objp->li_name);
- }
- return res;
+ if (!xdr_zotypes (xdrs, &objp->li_rtype))
+ return FALSE;
+ if (!xdr_array (xdrs, (char **) &objp->li_attrs.li_attrs_val,
+ (u_int *) &objp->li_attrs.li_attrs_len, ~0,
+ sizeof (nis_attr), (xdrproc_t) xdr_nis_attr))
+ return FALSE;
+ if (!_xdr_nis_name (xdrs, &objp->li_name))
+ return FALSE;
+ return TRUE;
}
static bool_t
xdr_table_col (XDR *xdrs, table_col *objp)
{
- bool_t res = xdr_string (xdrs, &objp->tc_name, 64);
- if (__builtin_expect (res, TRUE))
- {
- res = xdr_u_int (xdrs, &objp->tc_flags);
- if (__builtin_expect (res, TRUE))
- res = xdr_u_int (xdrs, &objp->tc_rights);
- }
- return res;
+ if (!xdr_string (xdrs, &objp->tc_name, 64))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->tc_flags))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->tc_rights))
+ return FALSE;
+ return TRUE;
}
static bool_t
xdr_table_obj (XDR *xdrs, table_obj *objp)
{
- bool_t res = xdr_string (xdrs, &objp->ta_type, 64);
- if (__builtin_expect (res, TRUE))
- {
- res = xdr_int (xdrs, &objp->ta_maxcol);
- if (__builtin_expect (res, TRUE))
- {
- res = xdr_u_char (xdrs, &objp->ta_sep);
- if (__builtin_expect (res, TRUE))
- {
- res = xdr_array (xdrs, (char **) &objp->ta_cols.ta_cols_val,
- &objp->ta_cols.ta_cols_len, ~0,
- sizeof (table_col), (xdrproc_t) xdr_table_col);
- if (__builtin_expect (res, TRUE))
- res = xdr_string (xdrs, &objp->ta_path, ~0);
- }
- }
- }
- return res;
+ if (!xdr_string (xdrs, &objp->ta_type, 64))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->ta_maxcol))
+ return FALSE;
+ if (!xdr_u_char (xdrs, &objp->ta_sep))
+ return FALSE;
+ if (!xdr_array (xdrs, (char **) &objp->ta_cols.ta_cols_val,
+ (u_int *) &objp->ta_cols.ta_cols_len, ~0,
+ sizeof (table_col), (xdrproc_t) xdr_table_col))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->ta_path, ~0))
+ return FALSE;
+ return TRUE;
}
static bool_t
xdr_objdata (XDR *xdrs, objdata *objp)
{
- bool_t res = xdr_zotypes (xdrs, &objp->zo_type);
- if (!__builtin_expect (res, TRUE))
- return res;
+ if (!xdr_zotypes (xdrs, &objp->zo_type))
+ return FALSE;
switch (objp->zo_type)
{
case NIS_DIRECTORY_OBJ:
- return _xdr_directory_obj (xdrs, &objp->objdata_u.di_data);
+ if (!_xdr_directory_obj (xdrs, &objp->objdata_u.di_data))
+ return FALSE;
+ break;
case NIS_GROUP_OBJ:
- return xdr_group_obj (xdrs, &objp->objdata_u.gr_data);
+ if (!xdr_group_obj (xdrs, &objp->objdata_u.gr_data))
+ return FALSE;
+ break;
case NIS_TABLE_OBJ:
- return xdr_table_obj (xdrs, &objp->objdata_u.ta_data);
+ if (!xdr_table_obj (xdrs, &objp->objdata_u.ta_data))
+ return FALSE;
+ break;
case NIS_ENTRY_OBJ:
- return xdr_entry_obj (xdrs, &objp->objdata_u.en_data);
+ if (!xdr_entry_obj (xdrs, &objp->objdata_u.en_data))
+ return FALSE;
+ break;
case NIS_LINK_OBJ:
- return xdr_link_obj (xdrs, &objp->objdata_u.li_data);
+ if (!xdr_link_obj (xdrs, &objp->objdata_u.li_data))
+ return FALSE;
+ break;
case NIS_PRIVATE_OBJ:
- return xdr_bytes (xdrs, &objp->objdata_u.po_data.po_data_val,
- &objp->objdata_u.po_data.po_data_len, ~0);
+ if (!xdr_bytes (xdrs, (char **) &objp->objdata_u.po_data.po_data_val,
+ (u_int *) & objp->objdata_u.po_data.po_data_len, ~0))
+ return FALSE;
+ break;
case NIS_NO_OBJ:
+ break;
case NIS_BOGUS_OBJ:
+ break;
default:
- return TRUE;
+ break;
}
+ return TRUE;
}
static bool_t
xdr_nis_oid (XDR *xdrs, nis_oid *objp)
{
- bool_t res = xdr_uint32_t (xdrs, &objp->ctime);
- if (__builtin_expect (res, TRUE))
- res = xdr_uint32_t (xdrs, &objp->mtime);
- return res;
+ if (!xdr_uint32_t (xdrs, &objp->ctime))
+ return FALSE;
+ if (!xdr_uint32_t (xdrs, &objp->mtime))
+ return FALSE;
+ return TRUE;
}
bool_t
_xdr_nis_object (XDR *xdrs, nis_object *objp)
{
- bool_t res = xdr_nis_oid (xdrs, &objp->zo_oid);
- if (__builtin_expect (res, TRUE))
- {
- res = xdr_nis_name (xdrs, &objp->zo_name);
- if (__builtin_expect (res, TRUE))
- {
- res = xdr_nis_name (xdrs, &objp->zo_owner);
- if (__builtin_expect (res, TRUE))
- {
- res = xdr_nis_name (xdrs, &objp->zo_group);
- if (__builtin_expect (res, TRUE))
- {
- res = xdr_nis_name (xdrs, &objp->zo_domain);
- if (__builtin_expect (res, TRUE))
- {
- res = xdr_u_int (xdrs, &objp->zo_access);
- if (__builtin_expect (res, TRUE))
- {
- res = xdr_uint32_t (xdrs, &objp->zo_ttl);
- if (__builtin_expect (res, TRUE))
- res = xdr_objdata (xdrs, &objp->zo_data);
- }
- }
- }
- }
- }
- }
- return res;
-}
-
-static __always_inline bool_t
-xdr_nis_error (XDR *xdrs, nis_error *objp)
-{
- return xdr_enum (xdrs, (enum_t *) objp);
+ if (!xdr_nis_oid (xdrs, &objp->zo_oid))
+ return FALSE;
+ if (!_xdr_nis_name (xdrs, &objp->zo_name))
+ return FALSE;
+ if (!_xdr_nis_name (xdrs, &objp->zo_owner))
+ return FALSE;
+ if (!_xdr_nis_name (xdrs, &objp->zo_group))
+ return FALSE;
+ if (!_xdr_nis_name (xdrs, &objp->zo_domain))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->zo_access))
+ return FALSE;
+ if (!xdr_uint32_t (xdrs, &objp->zo_ttl))
+ return FALSE;
+ if (!xdr_objdata (xdrs, &objp->zo_data))
+ return FALSE;
+ return TRUE;
}
bool_t
_xdr_nis_error (XDR *xdrs, nis_error *objp)
{
- return xdr_nis_error (xdrs, objp);
+ if (!xdr_enum (xdrs, (enum_t *) objp))
+ return FALSE;
+ return TRUE;
}
bool_t
_xdr_nis_result (XDR *xdrs, nis_result *objp)
{
- bool_t res = xdr_nis_error (xdrs, &objp->status);
- if (__builtin_expect (res, TRUE))
- {
- res = xdr_array (xdrs, (char **) &objp->objects.objects_val,
- &objp->objects.objects_len, ~0,
- sizeof (nis_object), (xdrproc_t) _xdr_nis_object);
- if (__builtin_expect (res, TRUE))
- {
- res = xdr_netobj (xdrs, &objp->cookie);
- if (__builtin_expect (res, TRUE))
- {
- res = xdr_uint32_t (xdrs, &objp->zticks);
- if (__builtin_expect (res, TRUE))
- {
- res = xdr_uint32_t (xdrs, &objp->dticks);
- if (__builtin_expect (res, TRUE))
- {
- res = xdr_uint32_t (xdrs, &objp->aticks);
- if (__builtin_expect (res, TRUE))
- res = xdr_uint32_t (xdrs, &objp->cticks);
- }
- }
- }
- }
- }
- return res;
+ if (!_xdr_nis_error (xdrs, &objp->status))
+ return FALSE;
+ if (!xdr_array (xdrs, (char **) &objp->objects.objects_val,
+ (u_int *) &objp->objects.objects_len, ~0,
+ sizeof (nis_object), (xdrproc_t) _xdr_nis_object))
+ return FALSE;
+ if (!xdr_netobj (xdrs, &objp->cookie))
+ return FALSE;
+ if (!xdr_uint32_t (xdrs, &objp->zticks))
+ return FALSE;
+ if (!xdr_uint32_t (xdrs, &objp->dticks))
+ return FALSE;
+ if (!xdr_uint32_t (xdrs, &objp->aticks))
+ return FALSE;
+ if (!xdr_uint32_t (xdrs, &objp->cticks))
+ return FALSE;
+ return TRUE;
}
-libnsl_hidden_def (_xdr_nis_result)
bool_t
_xdr_ns_request (XDR *xdrs, ns_request *objp)
{
- bool_t res = xdr_nis_name (xdrs, &objp->ns_name);
- if (__builtin_expect (res, TRUE))
- res = xdr_array (xdrs, (char **) &objp->ns_object.ns_object_val,
- &objp->ns_object.ns_object_len, 1,
- sizeof (nis_object), (xdrproc_t) _xdr_nis_object);
- return res;
+ if (!_xdr_nis_name (xdrs, &objp->ns_name))
+ return FALSE;
+ if (!xdr_array (xdrs, (char **) &objp->ns_object.ns_object_val,
+ (u_int *) &objp->ns_object.ns_object_len, 1,
+ sizeof (nis_object), (xdrproc_t) _xdr_nis_object))
+ return FALSE;
+ return TRUE;
}
bool_t
_xdr_ib_request (XDR *xdrs, ib_request *objp)
{
- bool_t res = xdr_nis_name (xdrs, &objp->ibr_name);
- if (__builtin_expect (res, TRUE))
- {
- res = xdr_array (xdrs, (char **) &objp->ibr_srch.ibr_srch_val,
- &objp->ibr_srch.ibr_srch_len, ~0,
- sizeof (nis_attr), (xdrproc_t) xdr_nis_attr);
- if (__builtin_expect (res, TRUE))
- {
- res = xdr_u_int (xdrs, &objp->ibr_flags);
- if (__builtin_expect (res, TRUE))
- {
- res = xdr_array (xdrs, (char **) &objp->ibr_obj.ibr_obj_val,
- &objp->ibr_obj.ibr_obj_len, 1,
- sizeof (nis_object),
- (xdrproc_t) _xdr_nis_object);
- if (__builtin_expect (res, TRUE))
- {
- res = xdr_array (xdrs,
- (char **) &objp->ibr_cbhost.ibr_cbhost_val,
- &objp->ibr_cbhost.ibr_cbhost_len, 1,
- sizeof (nis_server),
- (xdrproc_t) _xdr_nis_server);
- if (__builtin_expect (res, TRUE))
- {
- res = xdr_u_int (xdrs, &objp->ibr_bufsize);
- if (__builtin_expect (res, TRUE))
- res = xdr_netobj (xdrs, &objp->ibr_cookie);
- }
- }
- }
- }
- }
- return res;
+ if (!_xdr_nis_name (xdrs, &objp->ibr_name))
+ return FALSE;
+ if (!xdr_array (xdrs, (char **) &objp->ibr_srch.ibr_srch_val,
+ (u_int *) &objp->ibr_srch.ibr_srch_len, ~0,
+ sizeof (nis_attr), (xdrproc_t) xdr_nis_attr))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->ibr_flags))
+ return FALSE;
+ if (!xdr_array (xdrs, (char **) &objp->ibr_obj.ibr_obj_val,
+ (u_int *) &objp->ibr_obj.ibr_obj_len, 1,
+ sizeof (nis_object), (xdrproc_t) _xdr_nis_object))
+ return FALSE;
+ if (!xdr_array (xdrs, (char **) &objp->ibr_cbhost.ibr_cbhost_val,
+ (u_int *) &objp->ibr_cbhost.ibr_cbhost_len, 1,
+ sizeof (nis_server), (xdrproc_t) _xdr_nis_server))
+ return FALSE;
+ if (!xdr_u_int (xdrs, &objp->ibr_bufsize))
+ return FALSE;
+ if (!xdr_netobj (xdrs, &objp->ibr_cookie))
+ return FALSE;
+ return TRUE;
}
-libnsl_hidden_def (_xdr_ib_request)
bool_t
_xdr_ping_args (XDR *xdrs, ping_args *objp)
{
- bool_t res = xdr_nis_name (xdrs, &objp->dir);
- if (__builtin_expect (res, TRUE))
- res = xdr_uint32_t (xdrs, &objp->stamp);
- return res;
+ if (!_xdr_nis_name (xdrs, &objp->dir))
+ return FALSE;
+ if (!xdr_uint32_t (xdrs, &objp->stamp))
+ return FALSE;
+ return TRUE;
}
bool_t
_xdr_cp_result (XDR *xdrs, cp_result *objp)
{
- bool_t res = xdr_nis_error (xdrs, &objp->cp_status);
- if (__builtin_expect (res, TRUE))
- {
- res = xdr_uint32_t (xdrs, &objp->cp_zticks);
- if (__builtin_expect (res, TRUE))
- res = xdr_uint32_t (xdrs, &objp->cp_dticks);
- }
- return res;
+ if (!_xdr_nis_error (xdrs, &objp->cp_status))
+ return FALSE;
+ if (!xdr_uint32_t (xdrs, &objp->cp_zticks))
+ return FALSE;
+ if (!xdr_uint32_t (xdrs, &objp->cp_dticks))
+ return FALSE;
+ return TRUE;
}
bool_t
_xdr_nis_tag (XDR *xdrs, nis_tag *objp)
{
- bool_t res = xdr_u_int (xdrs, &objp->tag_type);
- if (__builtin_expect (res, TRUE))
- res = xdr_string (xdrs, &objp->tag_val, ~0);
- return res;
+ if (!xdr_u_int (xdrs, &objp->tag_type))
+ return FALSE;
+ if (!xdr_string (xdrs, &objp->tag_val, ~0))
+ return FALSE;
+ return TRUE;
}
bool_t
_xdr_nis_taglist (XDR *xdrs, nis_taglist *objp)
{
- return xdr_array (xdrs, (char **) &objp->tags.tags_val,
- &objp->tags.tags_len, ~0, sizeof (nis_tag),
- (xdrproc_t) _xdr_nis_tag);
+ if (!xdr_array (xdrs, (char **) &objp->tags.tags_val,
+ (u_int *) &objp->tags.tags_len, ~0, sizeof (nis_tag),
+ (xdrproc_t) _xdr_nis_tag))
+ return FALSE;
+ return TRUE;
}
bool_t
_xdr_fd_args (XDR *xdrs, fd_args *objp)
{
- bool_t res = xdr_nis_name (xdrs, &objp->dir_name);
- if (__builtin_expect (res, TRUE))
- res = xdr_nis_name (xdrs, &objp->requester);
- return res;
+ if (!_xdr_nis_name (xdrs, &objp->dir_name))
+ return FALSE;
+ if (!_xdr_nis_name (xdrs, &objp->requester))
+ return FALSE;
+ return TRUE;
}
bool_t
_xdr_fd_result (XDR *xdrs, fd_result *objp)
{
- bool_t res = xdr_nis_error (xdrs, &objp->status);
- if (__builtin_expect (res, TRUE))
- {
- res = xdr_nis_name (xdrs, &objp->source);
- if (__builtin_expect (res, TRUE))
- {
- res = xdr_bytes (xdrs, (char **) &objp->dir_data.dir_data_val,
- &objp->dir_data.dir_data_len, ~0);
- if (__builtin_expect (res, TRUE))
- res = xdr_bytes (xdrs, (char **) &objp->signature.signature_val,
- &objp->signature.signature_len, ~0);
- }
- }
- return res;
+ if (!_xdr_nis_error (xdrs, &objp->status))
+ return FALSE;
+ if (!_xdr_nis_name (xdrs, &objp->source))
+ return FALSE;
+ if (!xdr_bytes (xdrs, (char **) &objp->dir_data.dir_data_val,
+ (u_int *) &objp->dir_data.dir_data_len, ~0))
+ return FALSE;
+ if (!xdr_bytes (xdrs, (char **) &objp->signature.signature_val,
+ (u_int *) &objp->signature.signature_len, ~0))
+ return FALSE;
+ return TRUE;
}
/* The following functions have prototypes in nis_callback.h. So
@@ -444,16 +412,18 @@ _xdr_fd_result (XDR *xdrs, fd_result *objp)
bool_t
xdr_obj_p (XDR *xdrs, obj_p *objp)
{
- return xdr_pointer (xdrs, (char **)objp, sizeof (nis_object),
- (xdrproc_t)_xdr_nis_object);
+ if (!xdr_pointer (xdrs, (char **)objp, sizeof (nis_object),
+ (xdrproc_t)_xdr_nis_object))
+ return FALSE;
+ return TRUE;
}
-libnsl_hidden_def (xdr_obj_p)
bool_t
xdr_cback_data (XDR *xdrs, cback_data *objp)
{
- return xdr_array (xdrs, (char **)&objp->entries.entries_val,
- &objp->entries.entries_len, ~0,
- sizeof (obj_p), (xdrproc_t) xdr_obj_p);
+ if (!xdr_array (xdrs, (char **)&objp->entries.entries_val,
+ (u_int *) &objp->entries.entries_len, ~0,
+ sizeof (obj_p), (xdrproc_t) xdr_obj_p))
+ return FALSE;
+ return TRUE;
}
-libnsl_hidden_def (xdr_cback_data)
diff --git a/nis/nis_xdr.h b/nis/nis_xdr.h
index a59362c78f..2f1a179e0a 100644
--- a/nis/nis_xdr.h
+++ b/nis/nis_xdr.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 1998, 1999, 2006 Free Software Foundation, Inc.
+/* Copyright (c) 1998, 1999 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@suse.de>, 1998.
@@ -22,23 +22,24 @@
#include <features.h>
-extern bool_t _xdr_nis_attr (XDR *, nis_attr*) attribute_hidden;
-extern bool_t _xdr_nis_name (XDR *, nis_name*) attribute_hidden;
-extern bool_t _xdr_nis_server (XDR *, nis_server*) attribute_hidden;
-extern bool_t _xdr_directory_obj (XDR *, directory_obj*) attribute_hidden;
-extern bool_t _xdr_nis_object (XDR *, nis_object*) attribute_hidden;
-extern bool_t _xdr_nis_error (XDR *, nis_error*) attribute_hidden;
-extern bool_t _xdr_ns_request (XDR *, ns_request*) attribute_hidden;
-extern bool_t _xdr_ping_args (XDR *, ping_args*) attribute_hidden;
-extern bool_t _xdr_cp_result (XDR *, cp_result*) attribute_hidden;
-extern bool_t _xdr_nis_tag (XDR *, nis_tag*) attribute_hidden;
-extern bool_t _xdr_nis_taglist (XDR *, nis_taglist*) attribute_hidden;
-extern bool_t _xdr_fd_args (XDR *, fd_args*) attribute_hidden;
-extern bool_t _xdr_fd_result (XDR *, fd_result*) attribute_hidden;
+__BEGIN_DECLS
-extern bool_t _xdr_ib_request (XDR *, ib_request*);
-libnsl_hidden_proto (_xdr_ib_request)
+extern bool_t _xdr_nis_attr (XDR *, nis_attr*);
+extern bool_t _xdr_nis_name (XDR *, nis_name*);
+extern bool_t _xdr_nis_server (XDR *, nis_server*);
+extern bool_t _xdr_directory_obj (XDR *, directory_obj*);
+extern bool_t _xdr_nis_object (XDR *, nis_object*);
+extern bool_t _xdr_nis_error (XDR *, nis_error*);
extern bool_t _xdr_nis_result (XDR *, nis_result*);
-libnsl_hidden_proto (_xdr_nis_result)
+extern bool_t _xdr_ns_request (XDR *, ns_request*);
+extern bool_t _xdr_ib_request (XDR *, ib_request*);
+extern bool_t _xdr_ping_args (XDR *, ping_args*);
+extern bool_t _xdr_cp_result (XDR *, cp_result*);
+extern bool_t _xdr_nis_tag (XDR *, nis_tag*);
+extern bool_t _xdr_nis_taglist (XDR *, nis_taglist*);
+extern bool_t _xdr_fd_args (XDR *, fd_args*);
+extern bool_t _xdr_fd_result (XDR *, fd_result*);
+
+__END_DECLS
#endif
diff --git a/nis/nisplus-parser.h b/nis/nisplus-parser.h
index 4dc8db8c9f..f4b8d49596 100644
--- a/nis/nisplus-parser.h
+++ b/nis/nisplus-parser.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997, 2004, 2006 Free Software Foundation, Inc.
+/* Copyright (C) 1997, 2004 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
@@ -24,13 +24,15 @@
#include <grp.h>
#include <shadow.h>
-extern int _nss_nisplus_parse_pwent (nis_result *result, struct passwd *pw,
- char *buffer, size_t buflen, int *errnop);
+extern int _nss_nisplus_parse_pwent (nis_result *, struct passwd *,
+ char *, size_t, int *);
+extern int _nss_nisplus_parse_grent (nis_result *, u_long, struct group *,
+ char *, size_t, int *);
+extern int _nss_nisplus_parse_spent (nis_result *, struct spwd *,
+ char *, size_t, int *);
-extern int _nss_nisplus_parse_grent (nis_result *result, struct group *gr,
- char *buffer, size_t buflen, int *errnop);
-
-extern int _nss_nisplus_parse_spent (nis_result *result, struct spwd *sp,
- char *buffer, size_t buflen, int *errnop);
+libnss_nisplus_hidden_proto (_nss_nisplus_parse_pwent)
+libnss_nisplus_hidden_proto (_nss_nisplus_parse_grent)
+libnss_nisplus_hidden_proto (_nss_nisplus_parse_spent)
#endif
diff --git a/nis/nss b/nis/nss
index b7007a6bd4..4f65f81120 100644
--- a/nis/nss
+++ b/nis/nss
@@ -1,7 +1,7 @@
# /etc/default/nss
# This file can theoretically contain a bunch of customization variables
-# for Name Service Switch in the GNU C library. For now there are only
-# three variables:
+# for Name Service Switch in the GNU C library. For now there are only two
+# variables:
#
# NETID_AUTHORITATIVE
# If set to TRUE, the initgroups() function will accept the information
@@ -18,11 +18,3 @@
# primary service names and service aliases. The system administrator
# has to make sure it is correctly generated.
#SERVICES_AUTHORITATIVE=TRUE
-#
-# SETENT_BATCH_READ
-# If set to TRUE, various setXXent() functions will read the entire
-# database at once and then hand out the requests one by one from
-# memory with every getXXent() call. Otherwise each getXXent() call
-# might result into a network communication with the server to get
-# the next entry.
-SETENT_BATCH_READ=TRUE
diff --git a/nis/nss-default.c b/nis/nss-default.c
deleted file mode 100644
index 046ddfee8d..0000000000
--- a/nis/nss-default.c
+++ /dev/null
@@ -1,127 +0,0 @@
-/* Copyright (C) 1996, 2001, 2004, 2006, 2007 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
-
- The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- The GNU C Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with the GNU C Library; if not, write to the Free
- Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
- 02111-1307 USA. */
-
-#include <ctype.h>
-#include <errno.h>
-#include <stdio.h>
-#include <stdio_ext.h>
-#include <stdlib.h>
-#include <string.h>
-#include <bits/libc-lock.h>
-
-#include <libnsl.h>
-
-
-/* Path of the file. */
-static const char default_nss[] = "/etc/default/nss";
-
-/* Flags once read from the file. */
-static int default_nss_flags;
-
-/* Code to make sure we call 'init' once. */
-__libc_once_define (static, once);
-
-/* Table of the recognized variables. */
-static const struct
-{
- char name[23];
- unsigned int len;
- int flag;
-} vars[] =
- {
-#define STRNLEN(s) s, sizeof (s) - 1
- { STRNLEN ("NETID_AUTHORITATIVE"), NSS_FLAG_NETID_AUTHORITATIVE },
- { STRNLEN ("SERVICES_AUTHORITATIVE"), NSS_FLAG_SERVICES_AUTHORITATIVE },
- { STRNLEN ("SETENT_BATCH_READ"), NSS_FLAG_SETENT_BATCH_READ }
- };
-#define nvars (sizeof (vars) / sizeof (vars[0]))
-
-
-static void
-init (void)
-{
- int saved_errno = errno;
- FILE *fp = fopen (default_nss, "rc");
- if (fp != NULL)
- {
- char *line = NULL;
- size_t linelen = 0;
-
- __fsetlocking (fp, FSETLOCKING_BYCALLER);
-
- while (!feof_unlocked (fp))
- {
- ssize_t n = getline (&line, &linelen, fp);
- if (n <= 0)
- break;
-
- /* Recognize only
-
- <THE-VARIABLE> = TRUE
-
- with arbitrary white spaces. */
- char *cp = line;
- while (isspace (*cp))
- ++cp;
-
- /* Recognize comment lines. */
- if (*cp == '#')
- continue;
-
- int idx;
- for (idx = 0; idx < nvars; ++idx)
- if (strncmp (cp, vars[idx].name, vars[idx].len) == 0)
- break;
- if (idx == nvars)
- continue;
-
- cp += vars[idx].len;
- while (isspace (*cp))
- ++cp;
- if (*cp++ != '=')
- continue;
- while (isspace (*cp))
- ++cp;
-
- if (strncmp (cp, "TRUE", 4) != 0)
- continue;
- cp += 4;
-
- while (isspace (*cp))
- ++cp;
-
- if (*cp == '\0')
- default_nss_flags |= vars[idx].flag;
- }
-
- free (line);
-
- fclose (fp);
- }
- __set_errno (saved_errno);
-}
-
-
-int
-_nsl_default_nss (void)
-{
- /* If we have not yet read the file yet do it now. */
- __libc_once (once, init);
-
- return default_nss_flags;
-}
diff --git a/nis/nss-nis.c b/nis/nss-nis.c
index cff1e765bb..40370bae3b 100644
--- a/nis/nss-nis.c
+++ b/nis/nss-nis.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996, 2001, 2004, 2006 Free Software Foundation, Inc.
+/* Copyright (C) 1996, 2001, 2004 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -16,6 +16,13 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
+#include <ctype.h>
+#include <stdio.h>
+#include <stdio_ext.h>
+#include <stdlib.h>
+#include <string.h>
+#include <rpcsvc/ypclnt.h>
+
#include "nss-nis.h"
#include "nsswitch.h"
@@ -43,3 +50,81 @@ const enum nss_status __yperr2nss_tab[] =
};
const unsigned int __yperr2nss_count = (sizeof (__yperr2nss_tab)
/ sizeof (__yperr2nss_tab[0]));
+
+int _nis_default_nss_flags;
+
+static const char default_nss[] = "/etc/default/nss";
+
+int
+_nis_check_default_nss (void)
+{
+ FILE *fp = fopen (default_nss, "rc");
+ int flags = NSS_FLAG_SET;
+ if (fp != NULL)
+ {
+ char *line = NULL;
+ size_t linelen = 0;
+
+ __fsetlocking (fp, FSETLOCKING_BYCALLER);
+
+ while (!feof_unlocked (fp))
+ {
+ ssize_t n = getline (&line, &linelen, fp);
+ if (n <= 0)
+ break;
+
+ /* There currently are only two variables we expect, so
+ simplify the parsing. Recognize only
+
+ NETID_AUTHORITATIVE = TRUE
+ SERVICES_AUTHORITATIVE = TRUE
+
+ with arbitrary white spaces. */
+ char *cp = line;
+ while (isspace (*cp))
+ ++cp;
+
+ /* Recognize comment lines. */
+ if (*cp == '#')
+ continue;
+
+ static const char netid_authoritative[] = "NETID_AUTHORITATIVE";
+ static const char services_authoritative[]
+ = "SERVICES_AUTHORITATIVE";
+ size_t flag_len;
+ if (strncmp (cp, netid_authoritative,
+ flag_len = sizeof (netid_authoritative) - 1) != 0
+ && strncmp (cp, services_authoritative,
+ flag_len = sizeof (services_authoritative) - 1)
+ != 0)
+ continue;
+
+ cp += flag_len;
+ while (isspace (*cp))
+ ++cp;
+ if (*cp++ != '=')
+ continue;
+ while (isspace (*cp))
+ ++cp;
+
+ if (strncmp (cp, "TRUE", 4) != 0)
+ continue;
+ cp += 4;
+
+ while (isspace (*cp))
+ ++cp;
+
+ if (*cp == '\0')
+ flags |= flag_len == sizeof (netid_authoritative) - 1
+ ? NSS_FLAG_NETID_AUTHORITATIVE
+ : NSS_FLAG_SERVICES_AUTHORITATIVE;
+ }
+
+ free (line);
+
+ fclose (fp);
+ }
+
+ _nis_default_nss_flags = flags;
+ return flags;
+}
diff --git a/nis/nss-nis.h b/nis/nss-nis.h
index a02583d14c..659b3a14aa 100644
--- a/nis/nss-nis.h
+++ b/nis/nss-nis.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996, 2004, 2006 Free Software Foundation, Inc.
+/* Copyright (C) 1996, 2004 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -25,8 +25,8 @@
/* Convert YP error number to NSS error number. */
-extern const enum nss_status __yperr2nss_tab[] attribute_hidden;
-extern const unsigned int __yperr2nss_count attribute_hidden;
+extern const enum nss_status __yperr2nss_tab[];
+extern const unsigned int __yperr2nss_count;
static inline enum nss_status
yperr2nss (int errval)
@@ -36,24 +36,16 @@ yperr2nss (int errval)
return __yperr2nss_tab[(unsigned int) errval];
}
+#define NSS_FLAG_SET 1
+#define NSS_FLAG_NETID_AUTHORITATIVE 2
+#define NSS_FLAG_SERVICES_AUTHORITATIVE 4
+extern int _nis_default_nss_flags attribute_hidden;
+extern int _nis_check_default_nss (void) attribute_hidden;
-struct response_t
+extern inline __attribute__((always_inline)) int
+_nis_default_nss (void)
{
- struct response_t *next;
- size_t size;
- char mem[0];
-};
-
-typedef struct intern_t
-{
- struct response_t *start;
- struct response_t *next;
- size_t offset;
-} intern_t;
-
-
-extern int _nis_saveit (int instatus, char *inkey, int inkeylen, char *inval,
- int invallen, char *indata) attribute_hidden;
-
+ return _nis_default_nss_flags ?: _nis_check_default_nss ();
+}
#endif /* nis/nss-nis.h */
diff --git a/nis/nss-nisplus.h b/nis/nss-nisplus.h
index ad7f444440..7235c355b0 100644
--- a/nis/nss-nisplus.h
+++ b/nis/nss-nisplus.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997, 2006 Free Software Foundation, Inc.
+/* Copyright (C) 1997 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[] attribute_hidden;
-extern const unsigned int __niserr2nss_count attribute_hidden;
+extern const enum nss_status __niserr2nss_tab[];
+extern const unsigned int __niserr2nss_count;
static inline enum nss_status
niserr2nss (int errval)
diff --git a/nis/nss_compat/compat-grp.c b/nis/nss_compat/compat-grp.c
index 236c84a20f..08bf5d2f80 100644
--- a/nis/nss_compat/compat-grp.c
+++ b/nis/nss_compat/compat-grp.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-1999,2001-2005,2006 Free Software Foundation, Inc.
+/* Copyright (C) 1996-1999,2001,2002,2003,2004 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@suse.de>, 1996.
@@ -59,13 +59,12 @@ struct blacklist_t
struct ent_t
{
bool_t files;
- enum nss_status setent_status;
FILE *stream;
struct blacklist_t blacklist;
};
typedef struct ent_t ent_t;
-static ent_t ext_ent = { TRUE, NSS_STATUS_SUCCESS, NULL, { NULL, 0, 0 }};
+static ent_t ext_ent = {TRUE, NULL, {NULL, 0, 0}};
/* Protect global state against multiple changers. */
__libc_lock_define_initialized (static, lock)
@@ -90,7 +89,7 @@ init_nss_interface (void)
}
static enum nss_status
-internal_setgrent (ent_t *ent, int stayopen, int needent)
+internal_setgrent (ent_t *ent, int stayopen)
{
enum nss_status status = NSS_STATUS_SUCCESS;
@@ -138,8 +137,8 @@ internal_setgrent (ent_t *ent, int stayopen, int needent)
else
rewind (ent->stream);
- if (needent && status == NSS_STATUS_SUCCESS && nss_setgrent)
- ent->setent_status = nss_setgrent (stayopen);
+ if (status == NSS_STATUS_SUCCESS && nss_setgrent)
+ return nss_setgrent (stayopen);
return status;
}
@@ -155,7 +154,7 @@ _nss_compat_setgrent (int stayopen)
if (ni == NULL)
init_nss_interface ();
- result = internal_setgrent (&ext_ent, stayopen, 1);
+ result = internal_setgrent (&ext_ent, stayopen);
__libc_lock_unlock (lock);
@@ -209,10 +208,6 @@ getgrent_next_nss (struct group *result, ent_t *ent, char *buffer,
if (!nss_getgrent_r)
return NSS_STATUS_UNAVAIL;
- /* If the setgrent call failed, say so. */
- if (ent->setent_status != NSS_STATUS_SUCCESS)
- return ent->setent_status;
-
do
{
enum nss_status status;
@@ -234,10 +229,9 @@ getgrnam_plusgroup (const char *name, struct group *result, ent_t *ent,
if (!nss_getgrnam_r)
return NSS_STATUS_UNAVAIL;
- enum nss_status status = nss_getgrnam_r (name, result, buffer, buflen,
- errnop);
- if (status != NSS_STATUS_SUCCESS)
- return status;
+ if (nss_getgrnam_r (name, result, buffer, buflen, errnop) !=
+ NSS_STATUS_SUCCESS)
+ return NSS_STATUS_NOTFOUND;
if (in_blacklist (result->gr_name, strlen (result->gr_name), ent))
return NSS_STATUS_NOTFOUND;
@@ -364,7 +358,7 @@ _nss_compat_getgrent_r (struct group *grp, char *buffer, size_t buflen,
init_nss_interface ();
if (ext_ent.stream == NULL)
- result = internal_setgrent (&ext_ent, 1, 1);
+ result = internal_setgrent (&ext_ent, 1);
if (result == NSS_STATUS_SUCCESS)
{
@@ -486,7 +480,7 @@ enum nss_status
_nss_compat_getgrnam_r (const char *name, struct group *grp,
char *buffer, size_t buflen, int *errnop)
{
- ent_t ent = { TRUE, NSS_STATUS_SUCCESS, NULL, { NULL, 0, 0 }};
+ ent_t ent = {TRUE, NULL, {NULL, 0, 0}};
enum nss_status result;
if (name[0] == '-' || name[0] == '+')
@@ -499,7 +493,7 @@ _nss_compat_getgrnam_r (const char *name, struct group *grp,
__libc_lock_unlock (lock);
- result = internal_setgrent (&ent, 0, 0);
+ result = internal_setgrent (&ent, 0);
if (result == NSS_STATUS_SUCCESS)
result = internal_getgrnam_r (name, grp, &ent, buffer, buflen, errnop);
@@ -557,7 +551,7 @@ internal_getgrgid_r (gid_t gid, struct group *result, ent_t *ent,
!(parse_res = _nss_files_parse_grent (p, result, data, buflen,
errnop)));
- if (__builtin_expect (parse_res == -1, 0))
+ if (parse_res == -1)
/* The parser ran out of space. */
goto erange_reset;
@@ -580,17 +574,13 @@ internal_getgrgid_r (gid_t gid, struct group *result, ent_t *ent,
/* +group */
if (result->gr_name[0] == '+' && result->gr_name[1] != '\0')
{
- /* Yes, no +1, see the memcpy call below. */
- size_t len = strlen (result->gr_name);
- char buf[len];
enum nss_status status;
/* Store the group in the blacklist for the "+" at the end of
/etc/group */
- memcpy (buf, &result->gr_name[1], len);
+ blacklist_store_name (&result->gr_name[1], ent);
status = getgrnam_plusgroup (&result->gr_name[1], result, ent,
buffer, buflen, errnop);
- blacklist_store_name (buf, ent);
if (status == NSS_STATUS_SUCCESS && result->gr_gid == gid)
break;
else
@@ -599,11 +589,9 @@ internal_getgrgid_r (gid_t gid, struct group *result, ent_t *ent,
/* +:... */
if (result->gr_name[0] == '+' && result->gr_name[1] == '\0')
{
- if (!nss_getgrgid_r)
- return NSS_STATUS_UNAVAIL;
+ enum nss_status status;
- enum nss_status status = nss_getgrgid_r (gid, result, buffer, buflen,
- errnop);
+ status = nss_getgrgid_r (gid, result, buffer, buflen, errnop);
if (status == NSS_STATUS_RETURN) /* We couldn't parse the entry */
return NSS_STATUS_NOTFOUND;
else
@@ -618,7 +606,7 @@ enum nss_status
_nss_compat_getgrgid_r (gid_t gid, struct group *grp,
char *buffer, size_t buflen, int *errnop)
{
- ent_t ent = { TRUE, NSS_STATUS_SUCCESS, NULL, { NULL, 0, 0 }};
+ ent_t ent = {TRUE, NULL, {NULL, 0, 0}};
enum nss_status result;
__libc_lock_lock (lock);
@@ -628,7 +616,7 @@ _nss_compat_getgrgid_r (gid_t gid, struct group *grp,
__libc_lock_unlock (lock);
- result = internal_setgrent (&ent, 0, 0);
+ result = internal_setgrent (&ent, 0);
if (result == NSS_STATUS_SUCCESS)
result = internal_getgrgid_r (gid, grp, &ent, buffer, buflen, errnop);
diff --git a/nis/nss_compat/compat-initgroups.c b/nis/nss_compat/compat-initgroups.c
index 70403a0785..9574ea7c0b 100644
--- a/nis/nss_compat/compat-initgroups.c
+++ b/nis/nss_compat/compat-initgroups.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1998-2003, 2004, 2006 Free Software Foundation, Inc.
+/* Copyright (C) 1998-2003, 2004 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@suse.de>, 1998.
@@ -36,6 +36,7 @@ static service_user *ni;
static enum nss_status (*nss_initgroups_dyn) (const char *, gid_t,
long int *, long int *,
gid_t **, long int, int *);
+static enum nss_status (*nss_setgrent) (int stayopen);
static enum nss_status (*nss_getgrnam_r) (const char *name,
struct group * grp, char *buffer,
size_t buflen, int *errnop);
@@ -44,6 +45,7 @@ static enum nss_status (*nss_getgrgid_r) (gid_t gid, struct group * grp,
int *errnop);
static enum nss_status (*nss_getgrent_r) (struct group * grp, char *buffer,
size_t buflen, int *errnop);
+static enum nss_status (*nss_endgrent) (void);
/* Protect global state against multiple changers. */
__libc_lock_define_initialized (static, lock)
@@ -90,9 +92,11 @@ init_nss_interface (void)
&& __nss_database_lookup ("group_compat", NULL, "nis", &ni) >= 0)
{
nss_initgroups_dyn = __nss_lookup_function (ni, "initgroups_dyn");
+ nss_setgrent = __nss_lookup_function (ni, "setgrent");
nss_getgrnam_r = __nss_lookup_function (ni, "getgrnam_r");
nss_getgrgid_r = __nss_lookup_function (ni, "getgrgid_r");
nss_getgrent_r = __nss_lookup_function (ni, "getgrent_r");
+ nss_endgrent = __nss_lookup_function (ni, "endgrent");
}
__libc_lock_unlock (lock);
diff --git a/nis/nss_compat/compat-pwd.c b/nis/nss_compat/compat-pwd.c
index ac132046da..89a6a7013e 100644
--- a/nis/nss_compat/compat-pwd.c
+++ b/nis/nss_compat/compat-pwd.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-1999,2001-2005,2006 Free Software Foundation, Inc.
+/* Copyright (C) 1996-1999,2001,2002,2003,2004 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1996.
@@ -62,10 +62,9 @@ struct blacklist_t
struct ent_t
{
- bool netgroup;
- bool first;
- bool files;
- enum nss_status setent_status;
+ bool_t netgroup;
+ bool_t first;
+ bool_t files;
FILE *stream;
struct blacklist_t blacklist;
struct passwd pwd;
@@ -73,9 +72,8 @@ struct ent_t
};
typedef struct ent_t ent_t;
-static ent_t ext_ent = { false, false, true, NSS_STATUS_SUCCESS, NULL,
- { NULL, 0, 0 },
- { NULL, NULL, 0, 0, NULL, NULL, NULL }};
+static ent_t ext_ent = {0, 0, TRUE, NULL, {NULL, 0, 0},
+ {NULL, NULL, 0, 0, NULL, NULL, NULL}};
/* Protect global state against multiple changers. */
__libc_lock_define_initialized (static, lock)
@@ -204,13 +202,12 @@ copy_pwd_changes (struct passwd *dest, struct passwd *src,
}
static enum nss_status
-internal_setpwent (ent_t *ent, int stayopen, int needent)
+internal_setpwent (ent_t *ent, int stayopen)
{
enum nss_status status = NSS_STATUS_SUCCESS;
- ent->first = ent->netgroup = false;
- ent->files = true;
- ent->setent_status = NSS_STATUS_SUCCESS;
+ ent->first = ent->netgroup = FALSE;
+ ent->files = TRUE;
/* If something was left over free it. */
if (ent->netgroup)
@@ -260,8 +257,8 @@ internal_setpwent (ent_t *ent, int stayopen, int needent)
give_pwd_free (&ent->pwd);
- if (needent && status == NSS_STATUS_SUCCESS && nss_setpwent)
- ent->setent_status = nss_setpwent (stayopen);
+ if (status == NSS_STATUS_SUCCESS && nss_setpwent)
+ return nss_setpwent (stayopen);
return status;
}
@@ -277,7 +274,7 @@ _nss_compat_setpwent (int stayopen)
if (ni == NULL)
init_nss_interface ();
- result = internal_setpwent (&ext_ent, stayopen, 1);
+ result = internal_setpwent (&ext_ent, stayopen);
__libc_lock_unlock (lock);
@@ -300,7 +297,7 @@ internal_endpwent (ent_t *ent)
if (ent->netgroup)
__internal_endnetgrent (&ent->netgrdata);
- ent->first = ent->netgroup = false;
+ ent->first = ent->netgroup = FALSE;
if (ent->blacklist.data != NULL)
{
@@ -347,17 +344,17 @@ getpwent_next_nss_netgr (const char *name, struct passwd *result, ent_t *ent,
if (yp_get_default_domain (&curdomain) != YPERR_SUCCESS)
{
- ent->netgroup = false;
- ent->first = false;
+ ent->netgroup = FALSE;
+ ent->first = FALSE;
give_pwd_free (&ent->pwd);
return NSS_STATUS_UNAVAIL;
}
- if (ent->first == true)
+ if (ent->first == TRUE)
{
memset (&ent->netgrdata, 0, sizeof (struct __netgrent));
__internal_setnetgrent (group, &ent->netgrdata);
- ent->first = false;
+ ent->first = FALSE;
}
while (1)
@@ -426,10 +423,6 @@ getpwent_next_nss (struct passwd *result, ent_t *ent, char *buffer,
if (!nss_getpwent_r)
return NSS_STATUS_UNAVAIL;
- /* If the setpwent call failed, say so. */
- if (ent->setent_status != NSS_STATUS_SUCCESS)
- return ent->setent_status;
-
p2len = pwd_need_buflen (&ent->pwd);
if (p2len > buflen)
{
@@ -440,7 +433,7 @@ getpwent_next_nss (struct passwd *result, ent_t *ent, char *buffer,
buflen -= p2len;
if (ent->first)
- ent->first = false;
+ ent->first = FALSE;
do
{
@@ -460,27 +453,29 @@ static enum nss_status
getpwnam_plususer (const char *name, struct passwd *result, ent_t *ent,
char *buffer, size_t buflen, int *errnop)
{
+ struct passwd pwd;
+ char *p;
+ size_t plen;
+
if (!nss_getpwnam_r)
return NSS_STATUS_UNAVAIL;
- struct passwd pwd;
memset (&pwd, '\0', sizeof (struct passwd));
copy_pwd_changes (&pwd, result, NULL, 0);
- size_t plen = pwd_need_buflen (&pwd);
+ plen = pwd_need_buflen (&pwd);
if (plen > buflen)
{
*errnop = ERANGE;
return NSS_STATUS_TRYAGAIN;
}
- char *p = buffer + (buflen - plen);
+ p = buffer + (buflen - plen);
buflen -= plen;
- enum nss_status status = nss_getpwnam_r (name, result, buffer, buflen,
- errnop);
- if (status != NSS_STATUS_SUCCESS)
- return status;
+ if (nss_getpwnam_r (name, result, buffer, buflen, errnop) !=
+ NSS_STATUS_SUCCESS)
+ return NSS_STATUS_NOTFOUND;
if (in_blacklist (result->pw_name, strlen (result->pw_name), ent))
return NSS_STATUS_NOTFOUND;
@@ -573,8 +568,8 @@ getpwent_next_file (struct passwd *result, ent_t *ent,
{
enum nss_status status;
- ent->netgroup = true;
- ent->first = true;
+ ent->netgroup = TRUE;
+ ent->first = TRUE;
copy_pwd_changes (&ent->pwd, result, NULL, 0);
status = getpwent_next_nss_netgr (NULL, result, ent,
@@ -629,8 +624,8 @@ getpwent_next_file (struct passwd *result, ent_t *ent,
/* +:... */
if (result->pw_name[0] == '+' && result->pw_name[1] == '\0')
{
- ent->files = false;
- ent->first = true;
+ ent->files = FALSE;
+ ent->first = TRUE;
copy_pwd_changes (&ent->pwd, result, NULL, 0);
return getpwent_next_nss (result, ent, buffer, buflen, errnop);
@@ -678,7 +673,7 @@ _nss_compat_getpwent_r (struct passwd *pwd, char *buffer, size_t buflen,
init_nss_interface ();
if (ext_ent.stream == NULL)
- result = internal_setpwent (&ext_ent, 1, 1);
+ result = internal_setpwent (&ext_ent, 1);
if (result == NSS_STATUS_SUCCESS)
result = internal_getpwent_r (pwd, &ext_ent, buffer, buflen, errnop);
@@ -830,8 +825,8 @@ _nss_compat_getpwnam_r (const char *name, struct passwd *pwd,
char *buffer, size_t buflen, int *errnop)
{
enum nss_status result;
- ent_t ent = { false, false, true, NSS_STATUS_SUCCESS, NULL, { NULL, 0, 0 },
- { NULL, NULL, 0, 0, NULL, NULL, NULL }};
+ ent_t ent = {0, 0, TRUE, NULL, {NULL, 0, 0},
+ {NULL, NULL, 0, 0, NULL, NULL, NULL}};
if (name[0] == '-' || name[0] == '+')
return NSS_STATUS_NOTFOUND;
@@ -843,7 +838,7 @@ _nss_compat_getpwnam_r (const char *name, struct passwd *pwd,
__libc_lock_unlock (lock);
- result = internal_setpwent (&ent, 0, 0);
+ result = internal_setpwent (&ent, 0);
if (result == NSS_STATUS_SUCCESS)
result = internal_getpwnam_r (name, pwd, &ent, buffer, buflen, errnop);
@@ -1072,8 +1067,8 @@ _nss_compat_getpwuid_r (uid_t uid, struct passwd *pwd,
char *buffer, size_t buflen, int *errnop)
{
enum nss_status result;
- ent_t ent = { false, false, true, NSS_STATUS_SUCCESS, NULL, { NULL, 0, 0 },
- { NULL, NULL, 0, 0, NULL, NULL, NULL }};
+ ent_t ent = {0, 0, TRUE, NULL, {NULL, 0, 0},
+ {NULL, NULL, 0, 0, NULL, NULL, NULL}};
__libc_lock_lock (lock);
@@ -1082,7 +1077,7 @@ _nss_compat_getpwuid_r (uid_t uid, struct passwd *pwd,
__libc_lock_unlock (lock);
- result = internal_setpwent (&ent, 0, 0);
+ result = internal_setpwent (&ent, 0);
if (result == NSS_STATUS_SUCCESS)
result = internal_getpwuid_r (uid, pwd, &ent, buffer, buflen, errnop);
@@ -1139,7 +1134,7 @@ blacklist_store_name (const char *name, ent_t *ent)
return;
}
-/* Returns TRUE if ent->blacklist contains name, else FALSE. */
+/* returns TRUE if ent->blacklist contains name, else FALSE */
static bool_t
in_blacklist (const char *name, int namelen, ent_t *ent)
{
diff --git a/nis/nss_compat/compat-spwd.c b/nis/nss_compat/compat-spwd.c
index d1de3f75b0..4ca6368139 100644
--- a/nis/nss_compat/compat-spwd.c
+++ b/nis/nss_compat/compat-spwd.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-1999,2001-2005,2006 Free Software Foundation, Inc.
+/* Copyright (C) 1996-1999,2001,2002,2003,2004 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1996.
@@ -59,10 +59,9 @@ struct blacklist_t
struct ent_t
{
- bool netgroup;
- bool files;
- bool first;
- enum nss_status setent_status;
+ bool_t netgroup;
+ bool_t files;
+ bool_t first;
FILE *stream;
struct blacklist_t blacklist;
struct spwd pwd;
@@ -70,9 +69,8 @@ struct ent_t
};
typedef struct ent_t ent_t;
-static ent_t ext_ent = { false, true, false, NSS_STATUS_SUCCESS, NULL,
- { NULL, 0, 0},
- { NULL, NULL, 0, 0, 0, 0, 0, 0, 0}};
+static ent_t ext_ent = {0, TRUE, 0, NULL, {NULL, 0, 0},
+ {NULL, NULL, 0, 0, 0, 0, 0, 0, 0}};
/* Protect global state against multiple changers. */
__libc_lock_define_initialized (static, lock)
@@ -163,7 +161,7 @@ internal_setspent (ent_t *ent, int stayopen)
enum nss_status status = NSS_STATUS_SUCCESS;
ent->first = ent->netgroup = 0;
- ent->files = true;
+ ent->files = TRUE;
/* If something was left over free it. */
if (ent->netgroup)
@@ -214,7 +212,7 @@ internal_setspent (ent_t *ent, int stayopen)
give_spwd_free (&ent->pwd);
if (status == NSS_STATUS_SUCCESS && nss_setspent)
- ent->setent_status = nss_setspent (stayopen);
+ return nss_setspent (stayopen);
return status;
}
@@ -253,8 +251,8 @@ internal_endspent (ent_t *ent)
if (ent->netgroup)
__internal_endnetgrent (&ent->netgrdata);
- ent->first = ent->netgroup = false;
- ent->files = true;
+ ent->first = ent->netgroup = FALSE;
+ ent->files = TRUE;
if (ent->blacklist.data != NULL)
{
@@ -296,23 +294,19 @@ getspent_next_nss_netgr (const char *name, struct spwd *result, ent_t *ent,
if (!nss_getspnam_r)
return NSS_STATUS_UNAVAIL;
- /* If the setpwent call failed, say so. */
- if (ent->setent_status != NSS_STATUS_SUCCESS)
- return ent->setent_status;
-
if (yp_get_default_domain (&curdomain) != YPERR_SUCCESS)
{
- ent->netgroup = false;
- ent->first = false;
+ ent->netgroup = FALSE;
+ ent->first = FALSE;
give_spwd_free (&ent->pwd);
return NSS_STATUS_UNAVAIL;
}
- if (ent->first == true)
+ if (ent->first == TRUE)
{
memset (&ent->netgrdata, 0, sizeof (struct __netgrent));
__internal_setnetgrent (group, &ent->netgrdata);
- ent->first = false;
+ ent->first = FALSE;
}
while (1)
@@ -327,7 +321,7 @@ getspent_next_nss_netgr (const char *name, struct spwd *result, ent_t *ent,
if (status != 1)
{
__internal_endnetgrent (&ent->netgrdata);
- ent->netgroup = false;
+ ent->netgroup = FALSE;
give_spwd_free (&ent->pwd);
return NSS_STATUS_RETURN;
}
@@ -402,16 +396,18 @@ getspent_next_nss (struct spwd *result, ent_t *ent,
return NSS_STATUS_SUCCESS;
}
-
/* This function handle the +user entrys in /etc/shadow */
static enum nss_status
getspnam_plususer (const char *name, struct spwd *result, ent_t *ent,
char *buffer, size_t buflen, int *errnop)
{
+ struct spwd pwd;
+ char *p;
+ size_t plen;
+
if (!nss_getspnam_r)
return NSS_STATUS_UNAVAIL;
- struct spwd pwd;
memset (&pwd, '\0', sizeof (struct spwd));
pwd.sp_warn = -1;
pwd.sp_inact = -1;
@@ -420,19 +416,18 @@ getspnam_plususer (const char *name, struct spwd *result, ent_t *ent,
copy_spwd_changes (&pwd, result, NULL, 0);
- size_t plen = spwd_need_buflen (&pwd);
+ plen = spwd_need_buflen (&pwd);
if (plen > buflen)
{
*errnop = ERANGE;
return NSS_STATUS_TRYAGAIN;
}
- char *p = buffer + (buflen - plen);
+ p = buffer + (buflen - plen);
buflen -= plen;
- enum nss_status status = nss_getspnam_r (name, result, buffer, buflen,
- errnop);
- if (status != NSS_STATUS_SUCCESS)
- return status;
+ if (nss_getspnam_r (name, result, buffer, buflen, errnop) !=
+ NSS_STATUS_SUCCESS)
+ return NSS_STATUS_NOTFOUND;
if (in_blacklist (result->sp_namp, strlen (result->sp_namp), ent))
return NSS_STATUS_NOTFOUND;
@@ -443,7 +438,6 @@ getspnam_plususer (const char *name, struct spwd *result, ent_t *ent,
return NSS_STATUS_SUCCESS;
}
-
static enum nss_status
getspent_next_file (struct spwd *result, ent_t *ent,
char *buffer, size_t buflen, int *errnop)
@@ -524,8 +518,8 @@ getspent_next_file (struct spwd *result, ent_t *ent,
{
int status;
- ent->netgroup = true;
- ent->first = true;
+ ent->netgroup = TRUE;
+ ent->first = TRUE;
copy_spwd_changes (&ent->pwd, result, NULL, 0);
status = getspent_next_nss_netgr (NULL, result, ent,
@@ -581,8 +575,8 @@ getspent_next_file (struct spwd *result, ent_t *ent,
/* +:... */
if (result->sp_namp[0] == '+' && result->sp_namp[1] == '\0')
{
- ent->files = false;
- ent->first = true;
+ ent->files = FALSE;
+ ent->first = TRUE;
copy_spwd_changes (&ent->pwd, result, NULL, 0);
return getspent_next_nss (result, ent, buffer, buflen, errnop);
@@ -617,7 +611,6 @@ internal_getspent_r (struct spwd *pw, ent_t *ent,
return getspent_next_nss (pw, ent, buffer, buflen, errnop);
}
-
enum nss_status
_nss_compat_getspent_r (struct spwd *pwd, char *buffer, size_t buflen,
int *errnop)
@@ -641,7 +634,6 @@ _nss_compat_getspent_r (struct spwd *pwd, char *buffer, size_t buflen,
return result;
}
-
/* Searches in /etc/passwd and the NIS/NIS+ map for a special user */
static enum nss_status
internal_getspnam_r (const char *name, struct spwd *result, ent_t *ent,
@@ -784,14 +776,13 @@ internal_getspnam_r (const char *name, struct spwd *result, ent_t *ent,
return NSS_STATUS_SUCCESS;
}
-
enum nss_status
_nss_compat_getspnam_r (const char *name, struct spwd *pwd,
char *buffer, size_t buflen, int *errnop)
{
enum nss_status result;
- ent_t ent = { false, true, false, NSS_STATUS_SUCCESS, NULL, { NULL, 0, 0},
- { NULL, NULL, 0, 0, 0, 0, 0, 0, 0}};
+ ent_t ent = {0, TRUE, 0, NULL, {NULL, 0, 0},
+ {NULL, NULL, 0, 0, 0, 0, 0, 0, 0}};
if (name[0] == '-' || name[0] == '+')
return NSS_STATUS_NOTFOUND;
@@ -813,7 +804,6 @@ _nss_compat_getspnam_r (const char *name, struct spwd *pwd,
return result;
}
-
/* Support routines for remembering -@netgroup and -user entries.
The names are stored in a single string with `|' as separator. */
static void
@@ -860,7 +850,6 @@ blacklist_store_name (const char *name, ent_t *ent)
return;
}
-
/* Returns TRUE if ent->blacklist contains name, else FALSE. */
static bool_t
in_blacklist (const char *name, int namelen, ent_t *ent)
@@ -869,7 +858,7 @@ in_blacklist (const char *name, int namelen, ent_t *ent)
char *cp;
if (ent->blacklist.data == NULL)
- return false;
+ return FALSE;
buf[0] = '|';
cp = stpcpy (&buf[1], name);
diff --git a/nis/nss_nis/nis-alias.c b/nis/nss_nis/nis-alias.c
index 9286e36ba6..3b0887be04 100644
--- a/nis/nss_nis/nis-alias.c
+++ b/nis/nss_nis/nis-alias.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-2002, 2003, 2006 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2002, 2003 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1996.
@@ -125,53 +125,52 @@ internal_nis_getaliasent_r (struct aliasent *alias, char *buffer,
size_t buflen, int *errnop)
{
char *domain;
+ char *result;
+ int len;
+ char *outkey;
+ int keylen;
+ char *p;
+ int parse_res;
- if (__builtin_expect (yp_get_default_domain (&domain), 0))
+ if (yp_get_default_domain (&domain))
return NSS_STATUS_UNAVAIL;
alias->alias_local = 0;
/* Get the next entry until we found a correct one. */
- int parse_res;
do
{
- char *result;
- int len;
- char *outkey;
- int keylen;
- int yperr;
+ enum nss_status retval;
if (new_start)
- yperr = yp_first (domain, "mail.aliases", &outkey, &keylen, &result,
- &len);
+ retval = yperr2nss (yp_first (domain, "mail.aliases",
+ &outkey, &keylen, &result, &len));
else
- yperr = yp_next (domain, "mail.aliases", oldkey, oldkeylen, &outkey,
- &keylen, &result, &len);
-
- if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
+ retval = yperr2nss ( yp_next (domain, "mail.aliases", oldkey,
+ oldkeylen, &outkey, &keylen,
+ &result, &len));
+ if (retval != NSS_STATUS_SUCCESS)
{
- enum nss_status retval = yperr2nss (yperr);
-
if (retval == NSS_STATUS_TRYAGAIN)
*errnop = errno;
return retval;
}
- if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
+ if ((size_t) (len + 1) > buflen)
{
free (result);
*errnop = ERANGE;
return NSS_STATUS_TRYAGAIN;
}
- char *p = strncpy (buffer, result, len);
+ p = strncpy (buffer, result, len);
buffer[len] = '\0';
while (isspace (*p))
++p;
free (result);
- parse_res = _nss_nis_parse_aliasent (outkey, p, alias, buffer,
- buflen, errnop);
- if (__builtin_expect (parse_res == -1, 0))
+ parse_res = _nss_nis_parse_aliasent (outkey, p, alias, buffer, buflen,
+ errnop);
+ if (parse_res == -1)
{
free (outkey);
*errnop = ERANGE;
@@ -207,55 +206,56 @@ enum nss_status
_nss_nis_getaliasbyname_r (const char *name, struct aliasent *alias,
char *buffer, size_t buflen, int *errnop)
{
+ enum nss_status retval;
+ int parse_res;
+ char *domain;
+ char *result;
+ int len;
+ char *p;
+ size_t namlen = strlen (name);
+ char name2[namlen + 1];
+ size_t i;
+
if (name == NULL)
{
*errnop = EINVAL;
return NSS_STATUS_UNAVAIL;
}
- size_t namlen = strlen (name);
- char name2[namlen + 1];
-
- char *domain;
- if (__builtin_expect (yp_get_default_domain (&domain), 0))
+ if (yp_get_default_domain (&domain))
return NSS_STATUS_UNAVAIL;
/* Convert name to lowercase. */
- size_t i;
for (i = 0; i < namlen; ++i)
name2[i] = _tolower (name[i]);
name2[i] = '\0';
- char *result;
- int len;
- int yperr = yp_match (domain, "mail.aliases", name2, namlen, &result, &len);
+ retval = yperr2nss (yp_match (domain, "mail.aliases", name2, namlen,
+ &result, &len));
- if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
+ if (retval != NSS_STATUS_SUCCESS)
{
- enum nss_status retval = yperr2nss (yperr);
-
if (retval == NSS_STATUS_TRYAGAIN)
*errnop = errno;
return retval;
}
- if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
+ if ((size_t) (len + 1) > buflen)
{
free (result);
*errnop = ERANGE;
return NSS_STATUS_TRYAGAIN;
}
- char *p = strncpy (buffer, result, len);
+ p = strncpy (buffer, result, len);
buffer[len] = '\0';
while (isspace (*p))
++p;
free (result);
alias->alias_local = 0;
- int parse_res = _nss_nis_parse_aliasent (name, p, alias, buffer, buflen,
- errnop);
- if (__builtin_expect (parse_res < 1, 0))
+ parse_res = _nss_nis_parse_aliasent (name, p, alias, buffer, buflen, errnop);
+ if (parse_res < 1)
{
if (parse_res == -1)
return NSS_STATUS_TRYAGAIN;
diff --git a/nis/nss_nis/nis-ethers.c b/nis/nss_nis/nis-ethers.c
index a3064282ab..def4c22510 100644
--- a/nis/nss_nis/nis-ethers.c
+++ b/nis/nss_nis/nis-ethers.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-2003, 2004, 2006 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2003, 2004 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@suse.de>, 1996.
@@ -182,46 +182,45 @@ enum nss_status
_nss_nis_gethostton_r (const char *name, struct etherent *eth,
char *buffer, size_t buflen, int *errnop)
{
+ struct parser_data *data = (void *) buffer;
+ enum nss_status retval;
+ char *domain, *result, *p;
+ int len, parse_res;
+
if (name == NULL)
{
*errnop = EINVAL;
return NSS_STATUS_UNAVAIL;
}
- char *domain;
- if (__builtin_expect (yp_get_default_domain (&domain), 0))
+ if (yp_get_default_domain (&domain))
return NSS_STATUS_UNAVAIL;
- char *result;
- int len;
- int yperr = yp_match (domain, "ethers.byname", name, strlen (name), &result,
- &len);
+ retval = yperr2nss (yp_match (domain, "ethers.byname", name,
+ strlen (name), &result, &len));
- if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
+ if (retval != NSS_STATUS_SUCCESS)
{
- enum nss_status retval = yperr2nss (yperr);
-
if (retval == NSS_STATUS_TRYAGAIN)
*errnop = errno;
return retval;
}
- if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
+ if ((size_t) (len + 1) > buflen)
{
free (result);
*errnop = ERANGE;
return NSS_STATUS_TRYAGAIN;
}
- char *p = strncpy (buffer, result, len);
+ p = strncpy (buffer, result, len);
buffer[len] = '\0';
while (isspace (*p))
++p;
free (result);
- int parse_res = _nss_files_parse_etherent (p, eth, (void *) buffer, buflen,
- errnop);
- if (__builtin_expect (parse_res < 1, 0))
+ parse_res = _nss_files_parse_etherent (p, eth, data, buflen, errnop);
+ if (parse_res < 1)
{
if (parse_res == -1)
return NSS_STATUS_TRYAGAIN;
@@ -235,54 +234,54 @@ enum nss_status
_nss_nis_getntohost_r (const struct ether_addr *addr, struct etherent *eth,
char *buffer, size_t buflen, int *errnop)
{
+ struct parser_data *data = (void *) buffer;
+ enum nss_status retval;
+ char *domain, *result, *p;
+ int len, nlen, parse_res;
+ char buf[33];
+
if (addr == NULL)
{
*errnop = EINVAL;
return NSS_STATUS_UNAVAIL;
}
- char *domain;
- if (__builtin_expect (yp_get_default_domain (&domain), 0))
+ if (yp_get_default_domain (&domain))
return NSS_STATUS_UNAVAIL;
- char buf[33];
- int nlen = snprintf (buf, sizeof (buf), "%x:%x:%x:%x:%x:%x",
- (int) addr->ether_addr_octet[0],
- (int) addr->ether_addr_octet[1],
- (int) addr->ether_addr_octet[2],
- (int) addr->ether_addr_octet[3],
- (int) addr->ether_addr_octet[4],
- (int) addr->ether_addr_octet[5]);
-
- char *result;
- int len;
- int yperr = yp_match (domain, "ethers.byaddr", buf, nlen, &result, &len);
-
- if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
- {
- enum nss_status retval = yperr2nss (yperr);
+ nlen = sprintf (buf, "%x:%x:%x:%x:%x:%x",
+ (int) addr->ether_addr_octet[0],
+ (int) addr->ether_addr_octet[1],
+ (int) addr->ether_addr_octet[2],
+ (int) addr->ether_addr_octet[3],
+ (int) addr->ether_addr_octet[4],
+ (int) addr->ether_addr_octet[5]);
+ retval = yperr2nss (yp_match (domain, "ethers.byaddr", buf,
+ nlen, &result, &len));
+
+ if (retval != NSS_STATUS_SUCCESS)
+ {
if (retval == NSS_STATUS_TRYAGAIN)
*errnop = errno;
return retval;
}
- if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
+ if ((size_t) (len + 1) > buflen)
{
free (result);
*errnop = ERANGE;
return NSS_STATUS_TRYAGAIN;
}
- char *p = strncpy (buffer, result, len);
+ p = strncpy (buffer, result, len);
buffer[len] = '\0';
while (isspace (*p))
++p;
free (result);
- int parse_res = _nss_files_parse_etherent (p, eth, (void *) buffer, buflen,
- errnop);
- if (__builtin_expect (parse_res < 1, 0))
+ parse_res = _nss_files_parse_etherent (p, eth, data, buflen, errnop);
+ if (parse_res < 1)
{
if (parse_res == -1)
return NSS_STATUS_TRYAGAIN;
diff --git a/nis/nss_nis/nis-grp.c b/nis/nss_nis/nis-grp.c
index 6e36cf828f..8be7332515 100644
--- a/nis/nss_nis/nis-grp.c
+++ b/nis/nss_nis/nis-grp.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-1999, 2001-2004, 2006 Free Software Foundation, Inc.
+/* Copyright (C) 1996-1999, 2001-2003, 2004 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@suse.de>, 1996.
@@ -17,17 +17,20 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
+#include <nss.h>
+/* The following is an ugly trick to avoid a prototype declaration for
+ _nss_nis_endgrent. */
+#define _nss_nis_endgrent _nss_nis_endgrent_XXX
+#include <grp.h>
+#undef _nss_nis_endgrent
#include <ctype.h>
#include <errno.h>
-#include <grp.h>
-#include <nss.h>
#include <string.h>
#include <bits/libc-lock.h>
#include <rpcsvc/yp.h>
#include <rpcsvc/ypclnt.h>
#include "nss-nis.h"
-#include <libnsl.h>
/* Get the declaration of the parser function. */
#define ENTNAME grent
@@ -41,12 +44,12 @@ __libc_lock_define_initialized (static, lock)
static bool_t new_start = 1;
static char *oldkey;
static int oldkeylen;
-static intern_t intern;
-
-static void
-internal_nis_endgrent (void)
+enum nss_status
+_nss_nis_setgrent (int stayopen)
{
+ __libc_lock_lock (lock);
+
new_start = 1;
if (oldkey != NULL)
{
@@ -55,186 +58,72 @@ internal_nis_endgrent (void)
oldkeylen = 0;
}
- struct response_t *curr = intern.next;
-
- while (curr != NULL)
- {
- struct response_t *last = curr;
- curr = curr->next;
- free (last);
- }
-
- intern.next = intern.start = NULL;
-}
-
-
-enum nss_status
-_nss_nis_endgrent (void)
-{
- __libc_lock_lock (lock);
-
- internal_nis_endgrent ();
-
__libc_lock_unlock (lock);
return NSS_STATUS_SUCCESS;
}
-
-
-enum nss_status
-internal_nis_setgrent (void)
-{
- /* We have to read all the data now. */
- char *domain;
- if (__builtin_expect (yp_get_default_domain (&domain), 0))
- return NSS_STATUS_UNAVAIL;
-
- struct ypall_callback ypcb;
-
- ypcb.foreach = _nis_saveit;
- ypcb.data = (char *) &intern;
- enum nss_status status = yperr2nss (yp_all (domain, "group.byname", &ypcb));
-
-
- /* Mark the last buffer as full. */
- if (intern.next != NULL)
- intern.next->size = intern.offset;
-
- intern.next = intern.start;
- intern.offset = 0;
-
- return status;
-}
-
-
-enum nss_status
-_nss_nis_setgrent (int stayopen)
-{
- enum nss_status result = NSS_STATUS_SUCCESS;
-
- __libc_lock_lock (lock);
-
- internal_nis_endgrent ();
-
- if (_nsl_default_nss () & NSS_FLAG_SETENT_BATCH_READ)
- result = internal_nis_setgrent ();
-
- __libc_lock_unlock (lock);
-
- return result;
-}
-
+/* Make _nss_nis_endgrent an alias of _nss_nis_setgrent. We do this
+ even though the prototypes don't match. The argument of setgrent
+ is not used so this makes no difference. */
+strong_alias (_nss_nis_setgrent, _nss_nis_endgrent)
static enum nss_status
internal_nis_getgrent_r (struct group *grp, char *buffer, size_t buflen,
int *errnop)
{
- /* If we read the entire database at setpwent time we just iterate
- over the data we have in memory. */
- bool batch_read = intern.start != NULL;
+ struct parser_data *data = (void *) buffer;
+ char *domain, *result, *outkey;
+ int len, keylen, parse_res;
- char *domain = NULL;
- if (!batch_read && __builtin_expect (yp_get_default_domain (&domain), 0))
+ if (yp_get_default_domain (&domain))
return NSS_STATUS_UNAVAIL;
/* Get the next entry until we found a correct one. */
- int parse_res;
do
{
- char *result;
- char *outkey;
- int len;
- int keylen;
-
- if (batch_read)
- {
- struct response_t *bucket;
-
- handle_batch_read:
- bucket = intern.next;
-
- if (__builtin_expect (intern.offset >= bucket->size, 0))
- {
- if (bucket->next == NULL)
- return NSS_STATUS_NOTFOUND;
-
- /* We look at all the content in the current bucket. Go on
- to the next. */
- bucket = intern.next = bucket->next;
- intern.offset = 0;
- }
-
- for (result = &bucket->mem[intern.offset]; isspace (*result);
- ++result)
- ++intern.offset;
+ enum nss_status retval;
+ char *p;
- len = strlen (result);
- }
+ if (new_start)
+ retval = yperr2nss (yp_first (domain, "group.byname",
+ &outkey, &keylen, &result, &len));
else
- {
- int yperr;
-
- if (new_start)
- {
- /* Maybe we should read the database in one piece. */
- if ((_nsl_default_nss () & NSS_FLAG_SETENT_BATCH_READ)
- && internal_nis_setgrent () == NSS_STATUS_SUCCESS
- && intern.start != NULL)
- {
- batch_read = true;
- goto handle_batch_read;
- }
-
- yperr = yp_first (domain, "group.byname", &outkey, &keylen,
- &result, &len);
- }
- else
- yperr = yp_next (domain, "group.byname", oldkey, oldkeylen,
- &outkey, &keylen, &result, &len);
-
- if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
- {
- enum nss_status retval = yperr2nss (yperr);
-
- if (retval == NSS_STATUS_TRYAGAIN)
- *errnop = errno;
- return retval;
- }
- }
+ retval = yperr2nss ( yp_next (domain, "group.byname",
+ oldkey, oldkeylen,
+ &outkey, &keylen, &result, &len));
- if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
+ if (retval != NSS_STATUS_SUCCESS)
+ {
+ if (retval == NSS_STATUS_TRYAGAIN)
+ *errnop = errno;
+ return retval;
+ }
+
+ if ((size_t) (len + 1) > buflen)
{
free (result);
*errnop = ERANGE;
return NSS_STATUS_TRYAGAIN;
}
- char *p = strncpy (buffer, result, len);
+ p = strncpy (buffer, result, len);
buffer[len] = '\0';
while (isspace (*p))
++p;
- if (!batch_read)
- free (result);
+ free (result);
- parse_res = _nss_files_parse_grent (p, grp, (void *) buffer, buflen,
- errnop);
- if (__builtin_expect (parse_res == -1, 0))
+ parse_res = _nss_files_parse_grent (p, grp, data, buflen, errnop);
+ if (parse_res == -1)
{
- if (!batch_read)
- free (outkey);
+ free (outkey);
*errnop = ERANGE;
return NSS_STATUS_TRYAGAIN;
}
- if (batch_read)
- intern.offset += len + 1;
- else
- {
- free (oldkey);
- oldkey = outkey;
- oldkeylen = keylen;
- new_start = 0;
- }
+ free (oldkey);
+ oldkey = outkey;
+ oldkeylen = keylen;
+ new_start = 0;
}
while (parse_res < 1);
@@ -260,46 +149,45 @@ enum nss_status
_nss_nis_getgrnam_r (const char *name, struct group *grp,
char *buffer, size_t buflen, int *errnop)
{
+ struct parser_data *data = (void *) buffer;
+ enum nss_status retval;
+ char *domain, *result, *p;
+ int len, parse_res;
+
if (name == NULL)
{
*errnop = EINVAL;
return NSS_STATUS_UNAVAIL;
}
- char *domain;
- if (__builtin_expect (yp_get_default_domain (&domain), 0))
+ if (yp_get_default_domain (&domain))
return NSS_STATUS_UNAVAIL;
- char *result;
- int len;
- int yperr = yp_match (domain, "group.byname", name, strlen (name), &result,
- &len);
+ retval = yperr2nss (yp_match (domain, "group.byname", name,
+ strlen (name), &result, &len));
- if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
+ if (retval != NSS_STATUS_SUCCESS)
{
- enum nss_status retval = yperr2nss (yperr);
-
if (retval == NSS_STATUS_TRYAGAIN)
*errnop = errno;
return retval;
}
- if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
+ if ((size_t) (len + 1) > buflen)
{
free (result);
*errnop = ERANGE;
return NSS_STATUS_TRYAGAIN;
}
- char *p = strncpy (buffer, result, len);
+ p = strncpy (buffer, result, len);
buffer[len] = '\0';
while (isspace (*p))
++p;
free (result);
- int parse_res = _nss_files_parse_grent (p, grp, (void *) buffer, buflen,
- errnop);
- if (__builtin_expect (parse_res < 1, 0))
+ parse_res = _nss_files_parse_grent (p, grp, data, buflen, errnop);
+ if (parse_res < 1)
{
if (parse_res == -1)
return NSS_STATUS_TRYAGAIN;
@@ -313,42 +201,42 @@ enum nss_status
_nss_nis_getgrgid_r (gid_t gid, struct group *grp,
char *buffer, size_t buflen, int *errnop)
{
- char *domain;
- if (__builtin_expect (yp_get_default_domain (&domain), 0))
+ struct parser_data *data = (void *) buffer;
+ enum nss_status retval;
+ char *domain, *result, *p;
+ int len, nlen, parse_res;
+ char buf[32];
+
+ if (yp_get_default_domain (&domain))
return NSS_STATUS_UNAVAIL;
- char buf[32];
- int nlen = sprintf (buf, "%lu", (unsigned long int) gid);
+ nlen = sprintf (buf, "%lu", (unsigned long int) gid);
- char *result;
- int len;
- int yperr = yp_match (domain, "group.bygid", buf, nlen, &result, &len);
+ retval = yperr2nss (yp_match (domain, "group.bygid", buf,
+ nlen, &result, &len));
- if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
+ if (retval != NSS_STATUS_SUCCESS)
{
- enum nss_status retval = yperr2nss (yperr);
-
if (retval == NSS_STATUS_TRYAGAIN)
*errnop = errno;
return retval;
}
- if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
+ if ((size_t) (len + 1) > buflen)
{
free (result);
*errnop = ERANGE;
return NSS_STATUS_TRYAGAIN;
}
- char *p = strncpy (buffer, result, len);
+ p = strncpy (buffer, result, len);
buffer[len] = '\0';
while (isspace (*p))
++p;
free (result);
- int parse_res = _nss_files_parse_grent (p, grp, (void *) buffer, buflen,
- errnop);
- if (__builtin_expect (parse_res < 1, 0))
+ parse_res = _nss_files_parse_grent (p, grp, data, buflen, errnop);
+ if (parse_res < 1)
{
if (parse_res == -1)
return NSS_STATUS_TRYAGAIN;
diff --git a/nis/nss_nis/nis-hosts.c b/nis/nss_nis/nis-hosts.c
index bde0a3291f..58a9064f14 100644
--- a/nis/nss_nis/nis-hosts.c
+++ b/nis/nss_nis/nis-hosts.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-2000, 2002, 2003, 2006, 2007 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2000, 2002, 2003 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@suse.de>, 1996.
@@ -131,42 +131,39 @@ internal_nis_gethostent_r (struct hostent *host, char *buffer,
int af, int flags)
{
char *domain;
- if (__builtin_expect (yp_get_default_domain (&domain), 0))
- return NSS_STATUS_UNAVAIL;
+ char *result;
+ int len, parse_res;
+ char *outkey;
+ int keylen;
+ struct parser_data *data = (void *) buffer;
+ size_t linebuflen = buffer + buflen - data->linebuffer;
- uintptr_t pad = -(uintptr_t) buffer % __alignof__ (struct parser_data);
- buffer += pad;
+ if (yp_get_default_domain (&domain))
+ return NSS_STATUS_UNAVAIL;
- struct parser_data *data = (void *) buffer;
- if (__builtin_expect (buflen < sizeof *data + 1 + pad, 0))
+ if (buflen < sizeof *data + 1)
{
*errnop = ERANGE;
*h_errnop = NETDB_INTERNAL;
return NSS_STATUS_TRYAGAIN;
}
- buflen -= pad;
/* Get the next entry until we found a correct one. */
- const size_t linebuflen = buffer + buflen - data->linebuffer;
- int parse_res;
do
{
- char *result;
- int len;
- char *outkey;
- int keylen;
- int yperr;
+ enum nss_status retval;
+ char *p;
+
if (new_start)
- yperr = yp_first (domain, "hosts.byname", &outkey, &keylen, &result,
- &len);
+ retval = yperr2nss (yp_first (domain, "hosts.byname",
+ &outkey, &keylen, &result, &len));
else
- yperr = yp_next (domain, "hosts.byname", oldkey, oldkeylen, &outkey,
- &keylen, &result, &len);
+ retval = yperr2nss ( yp_next (domain, "hosts.byname",
+ oldkey, oldkeylen,
+ &outkey, &keylen, &result, &len));
- if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
+ if (retval != NSS_STATUS_SUCCESS)
{
- enum nss_status retval = yperr2nss (yperr);
-
switch (retval)
{
case NSS_STATUS_TRYAGAIN:
@@ -183,7 +180,7 @@ internal_nis_gethostent_r (struct hostent *host, char *buffer,
return retval;
}
- if (__builtin_expect ((size_t) (len + 1) > linebuflen, 0))
+ if ((size_t) (len + 1) > linebuflen)
{
free (result);
*h_errnop = NETDB_INTERNAL;
@@ -191,14 +188,14 @@ internal_nis_gethostent_r (struct hostent *host, char *buffer,
return NSS_STATUS_TRYAGAIN;
}
- char *p = strncpy (data->linebuffer, result, len);
+ p = strncpy (data->linebuffer, result, len);
data->linebuffer[len] = '\0';
while (isspace (*p))
++p;
free (result);
parse_res = parse_line (p, host, data, buflen, errnop, af, flags);
- if (__builtin_expect (parse_res == -1, 0))
+ if (parse_res == -1)
{
free (outkey);
*h_errnop = NETDB_INTERNAL;
@@ -238,10 +235,11 @@ internal_gethostbyname2_r (const char *name, int af, struct hostent *host,
char *buffer, size_t buflen, int *errnop,
int *h_errnop, int flags)
{
- uintptr_t pad = -(uintptr_t) buffer % __alignof__ (struct parser_data);
- buffer += pad;
-
+ enum nss_status retval;
+ char *domain, *result, *p;
+ int len, parse_res;
struct parser_data *data = (void *) buffer;
+ size_t linebuflen = buffer + buflen - data->linebuffer;
if (name == NULL)
{
@@ -249,35 +247,33 @@ internal_gethostbyname2_r (const char *name, int af, struct hostent *host,
return NSS_STATUS_UNAVAIL;
}
- char *domain;
if (yp_get_default_domain (&domain))
return NSS_STATUS_UNAVAIL;
- if (buflen < sizeof *data + 1 + pad)
+ if (buflen < sizeof *data + 1)
{
*h_errnop = NETDB_INTERNAL;
*errnop = ERANGE;
return NSS_STATUS_TRYAGAIN;
}
- buflen -= pad;
+ else
+ {
+ /* Convert name to lowercase. */
+ size_t namlen = strlen (name);
+ char name2[namlen + 1];
+ size_t i;
- /* Convert name to lowercase. */
- size_t namlen = strlen (name);
- char name2[namlen + 1];
- size_t i;
+ for (i = 0; i < namlen; ++i)
+ name2[i] = tolower (name[i]);
+ name2[i] = '\0';
- for (i = 0; i < namlen; ++i)
- name2[i] = tolower (name[i]);
- name2[i] = '\0';
+ retval = yperr2nss (yp_match (domain, "hosts.byname", name2,
+ namlen, &result, &len));
- char *result;
- int len;
- int yperr = yp_match (domain, "hosts.byname", name2, namlen, &result, &len);
+ }
- if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
+ if (retval != NSS_STATUS_SUCCESS)
{
- enum nss_status retval = yperr2nss (yperr);
-
if (retval == NSS_STATUS_TRYAGAIN)
{
*h_errnop = TRY_AGAIN;
@@ -288,8 +284,7 @@ internal_gethostbyname2_r (const char *name, int af, struct hostent *host,
return retval;
}
- const size_t linebuflen = buffer + buflen - data->linebuffer;
- if (__builtin_expect ((size_t) (len + 1) > linebuflen, 0))
+ if ((size_t) (len + 1) > linebuflen)
{
free (result);
*h_errnop = NETDB_INTERNAL;
@@ -297,15 +292,15 @@ internal_gethostbyname2_r (const char *name, int af, struct hostent *host,
return NSS_STATUS_TRYAGAIN;
}
- char *p = strncpy (data->linebuffer, result, len);
+ p = strncpy (data->linebuffer, result, len);
data->linebuffer[len] = '\0';
while (isspace (*p))
++p;
free (result);
- int parse_res = parse_line (p, host, data, buflen, errnop, af, flags);
+ parse_res = parse_line (p, host, data, buflen, errnop, af, flags);
- if (__builtin_expect (parse_res < 1 || host->h_addrtype != af, 0))
+ if (parse_res < 1 || host->h_addrtype != af)
{
if (parse_res == -1)
{
@@ -356,46 +351,42 @@ _nss_nis_gethostbyaddr_r (const void *addr, socklen_t addrlen, int af,
struct hostent *host, char *buffer, size_t buflen,
int *errnop, int *h_errnop)
{
- char *domain;
- if (__builtin_expect (yp_get_default_domain (&domain), 0))
- return NSS_STATUS_UNAVAIL;
+ enum nss_status retval;
+ char *domain, *result, *p;
+ int len, parse_res;
+ char *buf;
+ struct parser_data *data = (void *) buffer;
+ size_t linebuflen = buffer + buflen - data->linebuffer;
- uintptr_t pad = -(uintptr_t) buffer % __alignof__ (struct parser_data);
- buffer += pad;
+ if (yp_get_default_domain (&domain))
+ return NSS_STATUS_UNAVAIL;
- struct parser_data *data = (void *) buffer;
- if (__builtin_expect (buflen < sizeof *data + 1 + pad, 0))
+ if (buflen < sizeof *data + 1)
{
*errnop = ERANGE;
*h_errnop = NETDB_INTERNAL;
return NSS_STATUS_TRYAGAIN;
}
- buflen -= pad;
- char *buf = inet_ntoa (*(const struct in_addr *) addr);
+ buf = inet_ntoa (*(const struct in_addr *) addr);
- char *result;
- int len;
- int yperr = yp_match (domain, "hosts.byaddr", buf, strlen (buf), &result,
- &len);
+ retval = yperr2nss (yp_match (domain, "hosts.byaddr", buf,
+ strlen (buf), &result, &len));
- if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
+ if (retval != NSS_STATUS_SUCCESS)
{
- enum nss_status retval = yperr2nss (yperr);
-
if (retval == NSS_STATUS_TRYAGAIN)
{
*h_errnop = TRY_AGAIN;
*errnop = errno;
}
- else if (retval == NSS_STATUS_NOTFOUND)
+ if (retval == NSS_STATUS_NOTFOUND)
*h_errnop = HOST_NOT_FOUND;
return retval;
}
- const size_t linebuflen = buffer + buflen - data->linebuffer;
- if (__builtin_expect ((size_t) (len + 1) > linebuflen, 0))
+ if ((size_t) (len + 1) > linebuflen)
{
free (result);
*errnop = ERANGE;
@@ -403,16 +394,15 @@ _nss_nis_gethostbyaddr_r (const void *addr, socklen_t addrlen, int af,
return NSS_STATUS_TRYAGAIN;
}
- char *p = strncpy (data->linebuffer, result, len);
+ p = strncpy (data->linebuffer, result, len);
data->linebuffer[len] = '\0';
while (isspace (*p))
++p;
free (result);
- int parse_res = parse_line (p, host, data, buflen, errnop, af,
- ((_res.options & RES_USE_INET6)
- ? AI_V4MAPPED : 0));
- if (__builtin_expect (parse_res < 1, 0))
+ parse_res = parse_line (p, host, data, buflen, errnop, af,
+ ((_res.options & RES_USE_INET6) ? AI_V4MAPPED : 0));
+ if (parse_res < 1)
{
if (parse_res == -1)
{
diff --git a/nis/nss_nis/nis-initgroups.c b/nis/nss_nis/nis-initgroups.c
index a5a3ba6144..33a9662b4c 100644
--- a/nis/nss_nis/nis-initgroups.c
+++ b/nis/nss_nis/nis-initgroups.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1998-2000,2002,2003,2004,2006 Free Software Foundation, Inc.
+/* Copyright (C) 1998-2000, 2002, 2003, 2004 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@suse.de>, 1998.
@@ -30,7 +30,6 @@
#include <sys/param.h>
#include "nss-nis.h"
-#include <libnsl.h>
/* Get the declaration of the parser function. */
#define ENTNAME grent
@@ -38,6 +37,47 @@
#define EXTERN_PARSER
#include <nss/nss_files/files-parse.c>
+struct response_t
+{
+ struct response_t *next;
+ char val[0];
+};
+
+struct intern_t
+{
+ struct response_t *start;
+ struct response_t *next;
+};
+typedef struct intern_t intern_t;
+
+static int
+saveit (int instatus, char *inkey, int inkeylen, char *inval,
+ int invallen, char *indata)
+{
+ intern_t *intern = (intern_t *) indata;
+
+ if (instatus != YP_TRUE)
+ return 1;
+
+ if (inkey && inkeylen > 0 && inval && invallen > 0)
+ {
+ struct response_t *newp = malloc (sizeof (struct response_t)
+ + invallen + 1);
+ if (newp == NULL)
+ return 1; /* We have no error code for out of memory */
+
+ if (intern->start == NULL)
+ intern->start = newp;
+ else
+ intern->next->next = newp;
+ intern->next = newp;
+
+ newp->next = NULL;
+ *((char *) mempcpy (newp->val, inval, invallen)) = '\0';
+ }
+
+ return 0;
+}
static enum nss_status
internal_setgrent (char *domainname, intern_t *intern)
@@ -45,72 +85,41 @@ internal_setgrent (char *domainname, intern_t *intern)
struct ypall_callback ypcb;
enum nss_status status;
- ypcb.foreach = _nis_saveit;
+ intern->start = NULL;
+
+ ypcb.foreach = saveit;
ypcb.data = (char *) intern;
status = yperr2nss (yp_all (domainname, "group.byname", &ypcb));
-
- /* Mark the last buffer as full. */
- if (intern->next != NULL)
- intern->next->size = intern->offset;
-
intern->next = intern->start;
- intern->offset = 0;
return status;
}
-
static enum nss_status
internal_getgrent_r (struct group *grp, char *buffer, size_t buflen,
int *errnop, intern_t *intern)
{
+ struct parser_data *data = (void *) buffer;
+ int parse_res;
+ char *p;
+
if (intern->start == NULL)
return NSS_STATUS_NOTFOUND;
/* Get the next entry until we found a correct one. */
- int parse_res;
do
{
- struct response_t *bucket = intern->next;
-
- if (__builtin_expect (intern->offset >= bucket->size, 0))
- {
- if (bucket->next == NULL)
- return NSS_STATUS_NOTFOUND;
-
- /* We look at all the content in the current bucket. Go on
- to the next. */
- bucket = intern->next = bucket->next;
- intern->offset = 0;
- }
-
- char *p;
- for (p = &bucket->mem[intern->offset]; isspace (*p); ++p)
- ++intern->offset;
+ if (intern->next == NULL)
+ return NSS_STATUS_NOTFOUND;
- size_t len = strlen (p) + 1;
- if (__builtin_expect (len > buflen, 0))
- {
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
- }
+ p = strncpy (buffer, intern->next->val, buflen);
+ while (isspace (*p))
+ ++p;
- /* We unfortunately have to copy the data in the user-provided
- buffer because that buffer might be around for a very long
- time and the servent structure must remain valid. If we would
- rely on the BUCKET memory the next 'setservent' or 'endservent'
- call would destroy it.
-
- The important thing is that it is a single NUL-terminated
- string. This is what the parsing routine expects. */
- p = memcpy (buffer, &bucket->mem[intern->offset], len);
-
- parse_res = _nss_files_parse_grent (p, grp, (void *) buffer, buflen,
- errnop);
- if (__builtin_expect (parse_res == -1, 0))
+ parse_res = _nss_files_parse_grent (p, grp, data, buflen, errnop);
+ if (parse_res == -1)
return NSS_STATUS_TRYAGAIN;
-
- intern->offset += len;
+ intern->next = intern->next->next;
}
while (!parse_res);
@@ -157,12 +166,13 @@ initgroups_netid (uid_t uid, gid_t group, long int *start, long int *size,
ssize_t keylen = snprintf (key, sizeof (key), "unix.%lu@%s",
(unsigned long int) uid, domainname);
+ enum nss_status retval;
char *result;
int reslen;
- int yperr = yp_match (domainname, "netid.byname", key, keylen, &result,
- &reslen);
- if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
- return yperr2nss (yperr);
+ retval = yperr2nss (yp_match (domainname, "netid.byname", key, keylen,
+ &result, &reslen));
+ if (retval != NSS_STATUS_SUCCESS)
+ return retval;
/* Parse the result: following the colon is a comma separated list of
group IDs. */
@@ -197,6 +207,7 @@ initgroups_netid (uid_t uid, gid_t group, long int *start, long int *size,
if (*start == *size)
{
/* Need a bigger buffer. */
+ gid_t *newgroups;
long int newsize;
if (limit > 0 && *size == limit)
@@ -208,7 +219,7 @@ initgroups_netid (uid_t uid, gid_t group, long int *start, long int *size,
else
newsize = MIN (limit, 2 * *size);
- gid_t *newgroups = realloc (groups, newsize * sizeof (*groups));
+ newgroups = realloc (groups, newsize * sizeof (*groups));
if (newgroups == NULL)
goto errout;
*groupsp = groups = newgroups;
@@ -236,7 +247,7 @@ _nss_nis_initgroups_dyn (const char *user, gid_t group, long int *start,
return NSS_STATUS_UNAVAIL;
/* Check whether we are supposed to use the netid.byname map. */
- if (_nsl_default_nss () & NSS_FLAG_NETID_AUTHORITATIVE)
+ if (_nis_default_nss () & NSS_FLAG_NETID_AUTHORITATIVE)
{
/* We need the user ID. */
uid_t uid;
@@ -251,7 +262,7 @@ _nss_nis_initgroups_dyn (const char *user, gid_t group, long int *start,
size_t buflen = sysconf (_SC_GETPW_R_SIZE_MAX);
char *tmpbuf;
enum nss_status status;
- intern_t intern = { NULL, NULL, 0 };
+ intern_t intern = { NULL, NULL };
gid_t *groups = *groupsp;
status = internal_setgrent (domainname, &intern);
diff --git a/nis/nss_nis/nis-netgrp.c b/nis/nss_nis/nis-netgrp.c
index 5a88b72d9c..d339dd5097 100644
--- a/nis/nss_nis/nis-netgrp.c
+++ b/nis/nss_nis/nis-netgrp.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996,1997,1999,2000,2002,2003,2004,2005,2006
+/* Copyright (C) 1996,1997,1999,2000,2002,2003,2004
Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@suse.de>, 1996.
@@ -41,37 +41,41 @@ _nss_netgroup_parseline (char **cursor, struct __netgrent *netgrp,
static void
internal_nis_endnetgrent (struct __netgrent *netgrp)
{
- free (netgrp->data);
- netgrp->data = NULL;
- netgrp->data_size = 0;
- netgrp->cursor = NULL;
+ if (netgrp->data != NULL)
+ {
+ free (netgrp->data);
+ netgrp->data = NULL;
+ netgrp->data_size = 0;
+ netgrp->cursor = NULL;
+ }
}
-
enum nss_status
_nss_nis_setnetgrent (const char *group, struct __netgrent *netgrp)
{
+ char *domain;
int len;
enum nss_status status;
status = NSS_STATUS_SUCCESS;
- if (__builtin_expect (group == NULL || group[0] == '\0', 0))
+ if (group == NULL || group[0] == '\0')
return NSS_STATUS_UNAVAIL;
- char *domain;
- if (__builtin_expect (yp_get_default_domain (&domain), 0))
+ if (yp_get_default_domain (&domain))
return NSS_STATUS_UNAVAIL;
+ internal_nis_endnetgrent (netgrp);
+
status = yperr2nss (yp_match (domain, "netgroup", group, strlen (group),
&netgrp->data, &len));
- if (__builtin_expect (status == NSS_STATUS_SUCCESS, 1))
+ if (status == NSS_STATUS_SUCCESS)
{
/* Our implementation of yp_match already allocates a buffer
which is one byte larger than the value in LEN specifies
and the last byte is filled with NUL. So we can simply
use that buffer. */
- assert (len >= 0);
+ assert (len > 0);
assert (malloc_usable_size (netgrp->data) >= len + 1);
assert (netgrp->data[len] == '\0');
@@ -91,11 +95,13 @@ _nss_nis_endnetgrent (struct __netgrent *netgrp)
return NSS_STATUS_SUCCESS;
}
-
enum nss_status
_nss_nis_getnetgrent_r (struct __netgrent *result, char *buffer, size_t buflen,
int *errnop)
{
+ if (result->cursor == NULL)
+ return NSS_STATUS_NOTFOUND;
+
return _nss_netgroup_parseline (&result->cursor, result, buffer, buflen,
errnop);
}
diff --git a/nis/nss_nis/nis-network.c b/nis/nss_nis/nis-network.c
index 9b02302e0b..ed8439c814 100644
--- a/nis/nss_nis/nis-network.c
+++ b/nis/nss_nis/nis-network.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-2003, 2006 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2000, 2001, 2002, 2003 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1996.
@@ -73,32 +73,28 @@ internal_nis_getnetent_r (struct netent *net, char *buffer, size_t buflen,
int *errnop, int *herrnop)
{
struct parser_data *data = (void *) buffer;
+ char *domain, *result, *outkey;
+ int len, keylen, parse_res;
- char *domain;
- if (__builtin_expect (yp_get_default_domain (&domain), 0))
+ if (yp_get_default_domain (&domain))
return NSS_STATUS_UNAVAIL;
/* Get the next entry until we found a correct one. */
- int parse_res;
do
{
- char *result;
- char *outkey;
- int len;
- int keylen;
- int yperr;
+ enum nss_status retval;
+ char *p;
if (new_start)
- yperr = yp_first (domain, "networks.byname", &outkey, &keylen, &result,
- &len);
+ retval = yperr2nss (yp_first (domain, "networks.byname",
+ &outkey, &keylen, &result, &len));
else
- yperr = yp_next (domain, "networks.byname", oldkey, oldkeylen, &outkey,
- &keylen, &result, &len);
+ retval = yperr2nss ( yp_next (domain, "networks.byname",
+ oldkey, oldkeylen,
+ &outkey, &keylen, &result, &len));
- if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
+ if (retval != NSS_STATUS_SUCCESS)
{
- enum nss_status retval = yperr2nss (yperr);
-
if (retval == NSS_STATUS_TRYAGAIN)
{
*herrnop = NETDB_INTERNAL;
@@ -107,7 +103,7 @@ internal_nis_getnetent_r (struct netent *net, char *buffer, size_t buflen,
return retval;
}
- if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
+ if ((size_t) (len + 1) > buflen)
{
free (result);
*errnop = ERANGE;
@@ -115,14 +111,14 @@ internal_nis_getnetent_r (struct netent *net, char *buffer, size_t buflen,
return NSS_STATUS_TRYAGAIN;
}
- char *p = strncpy (buffer, result, len);
+ p = strncpy (buffer, result, len);
buffer[len] = '\0';
while (isspace (*p))
++p;
free (result);
parse_res = _nss_files_parse_netent (p, net, data, buflen, errnop);
- if (__builtin_expect (parse_res == -1, 0))
+ if (parse_res == -1)
{
free (outkey);
*herrnop = NETDB_INTERNAL;
@@ -159,6 +155,11 @@ enum nss_status
_nss_nis_getnetbyname_r (const char *name, struct netent *net, char *buffer,
size_t buflen, int *errnop, int *herrnop)
{
+ enum nss_status retval;
+ struct parser_data *data = (void *) buffer;
+ char *domain, *result, *p;
+ int len, parse_res;
+
if (name == NULL)
{
*errnop = EINVAL;
@@ -166,36 +167,33 @@ _nss_nis_getnetbyname_r (const char *name, struct netent *net, char *buffer,
return NSS_STATUS_UNAVAIL;
}
- char *domain;
- if (__builtin_expect (yp_get_default_domain (&domain), 0))
+ if (yp_get_default_domain (&domain))
return NSS_STATUS_UNAVAIL;
- struct parser_data *data = (void *) buffer;
if (buflen < sizeof *data + 1)
{
*herrnop = NETDB_INTERNAL;
*errnop = ERANGE;
return NSS_STATUS_TRYAGAIN;
}
+ else
+ {
+ /* Convert name to lowercase. */
+ size_t namlen = strlen (name);
+ char name2[namlen + 1];
+ size_t i;
- /* Convert name to lowercase. */
- size_t namlen = strlen (name);
- char name2[namlen + 1];
- size_t i;
+ for (i = 0; i < namlen; ++i)
+ name2[i] = _tolower (name[i]);
+ name2[i] = '\0';
- for (i = 0; i < namlen; ++i)
- name2[i] = _tolower (name[i]);
- name2[i] = '\0';
+ retval = yperr2nss (yp_match (domain, "networks.byname", name2,
+ namlen, &result, &len));
+ }
- char *result;
- int len;
- int yperr = yp_match (domain, "networks.byname", name2, namlen, &result,
- &len);
- if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
+ if (retval != NSS_STATUS_SUCCESS)
{
- enum nss_status retval = yperr2nss (yperr);
-
if (retval == NSS_STATUS_TRYAGAIN)
{
*errnop = errno;
@@ -204,7 +202,7 @@ _nss_nis_getnetbyname_r (const char *name, struct netent *net, char *buffer,
return retval;
}
- if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
+ if ((size_t) (len + 1) > buflen)
{
free (result);
*errnop = ERANGE;
@@ -212,15 +210,15 @@ _nss_nis_getnetbyname_r (const char *name, struct netent *net, char *buffer,
return NSS_STATUS_TRYAGAIN;
}
- char *p = strncpy (buffer, result, len);
+ p = strncpy (buffer, result, len);
buffer[len] = '\0';
while (isspace (*p))
++p;
free (result);
- int parse_res = _nss_files_parse_netent (p, net, data, buflen, errnop);
+ parse_res = _nss_files_parse_netent (p, net, data, buflen, errnop);
- if (__builtin_expect (parse_res < 1, 0))
+ if (parse_res < 1)
{
*herrnop = NETDB_INTERNAL;
if (parse_res == -1)
@@ -237,26 +235,32 @@ _nss_nis_getnetbyaddr_r (uint32_t addr, int type, struct netent *net,
char *buffer, size_t buflen, int *errnop,
int *herrnop)
{
+ struct parser_data *data = (void *) buffer;
char *domain;
- if (__builtin_expect (yp_get_default_domain (&domain), 0))
+ char *result;
+ int len;
+ char buf[256];
+ int blen;
+ struct in_addr in;
+ char *p;
+
+ if (yp_get_default_domain (&domain))
return NSS_STATUS_UNAVAIL;
- struct in_addr in = inet_makeaddr (addr, 0);
- char *buf = inet_ntoa (in);
- size_t blen = strlen (buf);
+ in = inet_makeaddr (addr, 0);
+ strcpy (buf, inet_ntoa (in));
+ blen = strlen (buf);
while (1)
{
- char *result;
- int len;
+ enum nss_status retval;
+ int parse_res;
- int yperr = yp_match (domain, "networks.byaddr", buf, blen, &result,
- &len);
+ retval = yperr2nss (yp_match (domain, "networks.byaddr", buf,
+ strlen (buf), &result, &len));
- if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
+ if (retval != NSS_STATUS_SUCCESS)
{
- enum nss_status retval = yperr2nss (yperr);
-
if (retval == NSS_STATUS_NOTFOUND)
{
if (buf[blen - 2] == '.' && buf[blen - 1] == '0')
@@ -278,7 +282,7 @@ _nss_nis_getnetbyaddr_r (uint32_t addr, int type, struct netent *net,
}
}
- if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
+ if ((size_t) (len + 1) > buflen)
{
free (result);
*errnop = ERANGE;
@@ -286,16 +290,15 @@ _nss_nis_getnetbyaddr_r (uint32_t addr, int type, struct netent *net,
return NSS_STATUS_TRYAGAIN;
}
- char *p = strncpy (buffer, result, len);
+ p = strncpy (buffer, result, len);
buffer[len] = '\0';
while (isspace (*p))
++p;
free (result);
- int parse_res = _nss_files_parse_netent (p, net, (void *) buffer,
- buflen, errnop);
+ parse_res = _nss_files_parse_netent (p, net, data, buflen, errnop);
- if (__builtin_expect (parse_res < 1, 0))
+ if (parse_res < 1)
{
*herrnop = NETDB_INTERNAL;
if (parse_res == -1)
diff --git a/nis/nss_nis/nis-proto.c b/nis/nss_nis/nis-proto.c
index 1480a928b5..f1069283ab 100644
--- a/nis/nss_nis/nis-proto.c
+++ b/nis/nss_nis/nis-proto.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-1998, 2000-2004, 2006 Free Software Foundation, Inc.
+/* Copyright (C) 1996-1998, 2000-2003, 2004 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@suse.de>, 1996.
@@ -179,46 +179,45 @@ enum nss_status
_nss_nis_getprotobyname_r (const char *name, struct protoent *proto,
char *buffer, size_t buflen, int *errnop)
{
+ struct parser_data *data = (void *) buffer;
+ enum nss_status retval;
+ char *domain, *result, *p;
+ int len, parse_res;
+
if (name == NULL)
{
*errnop = EINVAL;
return NSS_STATUS_UNAVAIL;
}
- char *domain;
- if (__builtin_expect (yp_get_default_domain (&domain), 0))
+ if (yp_get_default_domain (&domain))
return NSS_STATUS_UNAVAIL;
- char *result;
- int len;
- int yperr = yp_match (domain, "protocols.byname", name, strlen (name),
- &result, &len);
+ retval = yperr2nss (yp_match (domain, "protocols.byname", name,
+ strlen (name), &result, &len));
- if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
+ if (retval != NSS_STATUS_SUCCESS)
{
- enum nss_status retval = yperr2nss (yperr);
-
if (retval == NSS_STATUS_TRYAGAIN)
*errnop = errno;
return retval;
}
- if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
+ if ((size_t) (len + 1) > buflen)
{
free (result);
*errnop = ERANGE;
return NSS_STATUS_TRYAGAIN;
}
- char *p = strncpy (buffer, result, len);
+ p = strncpy (buffer, result, len);
buffer[len] = '\0';
while (isspace (*p))
++p;
free (result);
- int parse_res = _nss_files_parse_protoent (p, proto, (void *) buffer, buflen,
- errnop);
- if (__builtin_expect (parse_res < 1, 0))
+ parse_res = _nss_files_parse_protoent (p, proto, data, buflen, errnop);
+ if (parse_res < 1)
{
if (parse_res == -1)
return NSS_STATUS_TRYAGAIN;
@@ -232,43 +231,42 @@ enum nss_status
_nss_nis_getprotobynumber_r (int number, struct protoent *proto,
char *buffer, size_t buflen, int *errnop)
{
- char *domain;
- if (__builtin_expect (yp_get_default_domain (&domain), 0))
+ struct parser_data *data = (void *) buffer;
+ enum nss_status retval;
+ char *domain, *result, *p;
+ int len, nlen, parse_res;
+ char buf[32];
+
+ if (yp_get_default_domain (&domain))
return NSS_STATUS_UNAVAIL;
- char buf[32];
- int nlen = snprintf (buf, sizeof (buf), "%d", number);
+ nlen = sprintf (buf, "%d", number);
- char *result;
- int len;
- int yperr = yp_match (domain, "protocols.bynumber", buf, nlen, &result,
- &len);
+ retval = yperr2nss (yp_match (domain, "protocols.bynumber", buf,
+ nlen, &result, &len));
- if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
+ if (retval != NSS_STATUS_SUCCESS)
{
- enum nss_status retval = yperr2nss (yperr);
-
if (retval == NSS_STATUS_TRYAGAIN)
*errnop = errno;
return retval;
}
- if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
+ if ((size_t) (len + 1) > buflen)
{
free (result);
*errnop = ERANGE;
return NSS_STATUS_TRYAGAIN;
}
- char *p = strncpy (buffer, result, len);
+ p = strncpy (buffer, result, len);
buffer[len] = '\0';
while (isspace (*p))
++p;
free (result);
- int parse_res = _nss_files_parse_protoent (p, proto, (void *) buffer, buflen,
- errnop);
- if (__builtin_expect (parse_res < 1, 0))
+ parse_res = _nss_files_parse_protoent (p, proto, data, buflen, errnop);
+ if (parse_res < 1)
{
if (parse_res == -1)
return NSS_STATUS_TRYAGAIN;
diff --git a/nis/nss_nis/nis-publickey.c b/nis/nss_nis/nis-publickey.c
index f58eb154ad..6e92112d11 100644
--- a/nis/nss_nis/nis-publickey.c
+++ b/nis/nss_nis/nis-publickey.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-1999,2001,2002,2005,2006 Free Software Foundation, Inc.
+/* Copyright (C) 1996,1997,1998,1999,2001,2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@suse.de>, 1996.
@@ -36,6 +36,10 @@ extern int xdecrypt (char *, char *);
enum nss_status
_nss_nis_getpublickey (const char *netname, char *pkey, int *errnop)
{
+ enum nss_status retval;
+ char *domain, *result;
+ int len;
+
pkey[0] = 0;
if (netname == NULL)
@@ -44,23 +48,19 @@ _nss_nis_getpublickey (const char *netname, char *pkey, int *errnop)
return NSS_STATUS_UNAVAIL;
}
- char *domain = strchr (netname, '@');
- if (domain == NULL)
+ domain = strchr (netname, '@');
+ if (!domain)
{
*errnop = EINVAL;
return NSS_STATUS_UNAVAIL;
}
++domain;
- char *result;
- int len;
- int yperr = yp_match (domain, "publickey.byname", netname, strlen (netname),
- &result, &len);
+ retval = yperr2nss (yp_match (domain, "publickey.byname", netname,
+ strlen (netname), &result, &len));
- if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
+ if (retval != NSS_STATUS_SUCCESS)
{
- enum nss_status retval = yperr2nss (yperr);
-
if (retval == NSS_STATUS_TRYAGAIN)
*errnop = errno;
return retval;
@@ -73,7 +73,6 @@ _nss_nis_getpublickey (const char *netname, char *pkey, int *errnop)
*p = 0;
strncpy (pkey, result, HEXKEYBYTES + 1);
pkey[HEXKEYBYTES] = '\0';
- free (result);
}
return NSS_STATUS_SUCCESS;
}
@@ -82,6 +81,11 @@ enum nss_status
_nss_nis_getsecretkey (const char *netname, char *skey, char *passwd,
int *errnop)
{
+ enum nss_status retval;
+ char buf[2 * (HEXKEYBYTES + 1)];
+ char *domain, *result;
+ int len;
+
skey[0] = 0;
if (netname == NULL || passwd == NULL)
@@ -90,23 +94,19 @@ _nss_nis_getsecretkey (const char *netname, char *skey, char *passwd,
return NSS_STATUS_UNAVAIL;
}
- char *domain = strchr (netname, '@');
- if (domain == NULL)
+ domain = strchr (netname, '@');
+ if (!domain)
{
*errnop = EINVAL;
return NSS_STATUS_UNAVAIL;
}
++domain;
- char *result;
- int len;
- int yperr = yp_match (domain, "publickey.byname", netname, strlen (netname),
- &result, &len);
+ retval = yperr2nss (yp_match (domain, "publickey.byname", netname,
+ strlen (netname), &result, &len));
- if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
+ if (retval != NSS_STATUS_SUCCESS)
{
- enum nss_status retval = yperr2nss (yperr);
-
if (retval == NSS_STATUS_TRYAGAIN)
*errnop = errno;
return retval;
@@ -115,22 +115,20 @@ _nss_nis_getsecretkey (const char *netname, char *skey, char *passwd,
if (result != NULL)
{
char *p = strchr (result, ':');
- if (p != NULL)
- {
- char buf[2 * (HEXKEYBYTES + 1)];
-
- ++p;
- strncpy (buf, p, 2 * (HEXKEYBYTES + 1));
- buf[2 * HEXKEYBYTES + 1] = '\0';
- if (xdecrypt (buf, passwd)
- && memcmp (buf, &(buf[HEXKEYBYTES]), KEYCHECKSUMSIZE) == 0)
- {
- buf[HEXKEYBYTES] = '\0';
- strcpy (skey, buf);
- }
- }
-
- free (result);
+ if (p == NULL)
+ return NSS_STATUS_SUCCESS;
+
+ ++p;
+ strncpy (buf, p, 2 * (HEXKEYBYTES + 1));
+ buf[2 * (HEXKEYBYTES + 1)] = '\0';
+ if (!xdecrypt (buf, passwd))
+ return NSS_STATUS_SUCCESS;
+
+ if (memcmp (buf, &(buf[HEXKEYBYTES]), KEYCHECKSUMSIZE) != 0)
+ return NSS_STATUS_SUCCESS;
+
+ buf[HEXKEYBYTES] = '\0';
+ strcpy (skey, buf);
}
return NSS_STATUS_SUCCESS;
}
@@ -196,8 +194,13 @@ enum nss_status
_nss_nis_netname2user (char netname[MAXNETNAMELEN + 1], uid_t *uidp,
gid_t *gidp, int *gidlenp, gid_t *gidlist, int *errnop)
{
- char *domain = strchr (netname, '@');
- if (domain == NULL)
+ char *domain;
+ int yperr;
+ char *lookup;
+ int len;
+
+ domain = strchr (netname, '@');
+ if (!domain)
{
*errnop = EINVAL;
return NSS_STATUS_UNAVAIL;
@@ -205,10 +208,9 @@ _nss_nis_netname2user (char netname[MAXNETNAMELEN + 1], uid_t *uidp,
/* Point past the '@' character */
++domain;
- char *lookup = NULL;
- int len;
- int yperr = yp_match (domain, "netid.byname", netname, strlen (netname),
- &lookup, &len);
+ lookup = NULL;
+ yperr = yp_match (domain, "netid.byname", netname, strlen (netname),
+ &lookup, &len);
switch (yperr)
{
case YPERR_SUCCESS:
@@ -221,15 +223,17 @@ _nss_nis_netname2user (char netname[MAXNETNAMELEN + 1], uid_t *uidp,
return NSS_STATUS_UNAVAIL;
}
- if (lookup == NULL)
- return NSS_STATUS_NOTFOUND;
-
-
- lookup[len] = '\0';
-
- enum nss_status err = parse_netid_str (lookup, uidp, gidp, gidlenp, gidlist);
+ if (lookup)
+ {
+ enum nss_status err;
- free (lookup);
+ lookup[len] = '\0';
+ err = parse_netid_str (lookup, uidp, gidp, gidlenp, gidlist);
+ free (lookup);
+ return err;
+ }
+ else
+ return NSS_STATUS_NOTFOUND;
- return err;
+ return NSS_STATUS_SUCCESS;
}
diff --git a/nis/nss_nis/nis-pwd.c b/nis/nss_nis/nis-pwd.c
index 1b5206ad6d..0f56ced014 100644
--- a/nis/nss_nis/nis-pwd.c
+++ b/nis/nss_nis/nis-pwd.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-1998,2001,2002,2003,2006 Free Software Foundation, Inc.
+/* Copyright (C) 1996-1998, 2001, 2002, 2003 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1996.
@@ -17,18 +17,20 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
-#include <assert.h>
-#include <ctype.h>
-#include <errno.h>
#include <nss.h>
+/* The following is an ugly trick to avoid a prototype declaration for
+ _nss_nis_endpwent. */
+#define _nss_nis_endpwent _nss_nis_endpwent_XXX
#include <pwd.h>
+#undef _nss_nis_endpwent
+#include <ctype.h>
+#include <errno.h>
#include <string.h>
#include <bits/libc-lock.h>
#include <rpcsvc/yp.h>
#include <rpcsvc/ypclnt.h>
#include "nss-nis.h"
-#include <libnsl.h>
/* Get the declaration of the parser function. */
#define ENTNAME pwent
@@ -42,72 +44,12 @@ __libc_lock_define_initialized (static, lock)
static bool_t new_start = 1;
static char *oldkey;
static int oldkeylen;
-static intern_t intern;
-
-int
-_nis_saveit (int instatus, char *inkey, int inkeylen, char *inval,
- int invallen, char *indata)
+enum nss_status
+_nss_nis_setpwent (int stayopen)
{
- intern_t *intern = (intern_t *) indata;
-
- if (instatus != YP_TRUE)
- return 1;
-
- if (inkey && inkeylen > 0 && inval && invallen > 0)
- {
- struct response_t *bucket = intern->next;
-
- if (__builtin_expect (bucket == NULL, 0))
- {
-#define MINSIZE 4096 - 4 * sizeof (void *)
- const size_t minsize = MAX (MINSIZE, 2 * (invallen + 1));
- bucket = malloc (sizeof (struct response_t) + minsize);
- if (bucket == NULL)
- /* We have no error code for out of memory. */
- return 1;
-
- bucket->next = NULL;
- bucket->size = minsize;
- intern->start = intern->next = bucket;
- intern->offset = 0;
- }
- else if (__builtin_expect (invallen + 1 > bucket->size - intern->offset,
- 0))
- {
- /* We need a new (larger) buffer. */
- const size_t newsize = 2 * MAX (bucket->size, invallen + 1);
- struct response_t *newp = malloc (sizeof (struct response_t)
- + newsize);
- if (newp == NULL)
- /* We have no error code for out of memory. */
- return 1;
-
- /* Mark the old bucket as full. */
- bucket->size = intern->offset;
-
- newp->next = NULL;
- newp->size = newsize;
- bucket = intern->next = bucket->next = newp;
- intern->offset = 0;
- }
-
- char *p = mempcpy (&bucket->mem[intern->offset], inval, invallen);
- if (__builtin_expect (p[-1] != '\0', 0))
- {
- *p = '\0';
- ++invallen;
- }
- intern->offset += invallen;
- }
-
- return 0;
-}
-
+ __libc_lock_lock (lock);
-static void
-internal_nis_endpwent (void)
-{
new_start = 1;
if (oldkey != NULL)
{
@@ -116,159 +58,52 @@ internal_nis_endpwent (void)
oldkeylen = 0;
}
- struct response_t *curr = intern.next;
-
- while (curr != NULL)
- {
- struct response_t *last = curr;
- curr = curr->next;
- free (last);
- }
-
- intern.next = intern.start = NULL;
-}
-
-
-enum nss_status
-_nss_nis_endpwent (void)
-{
- __libc_lock_lock (lock);
-
- internal_nis_endpwent ();
-
__libc_lock_unlock (lock);
return NSS_STATUS_SUCCESS;
}
-
-
-enum nss_status
-internal_nis_setpwent (void)
-{
- /* We have to read all the data now. */
- char *domain;
- if (__builtin_expect (yp_get_default_domain (&domain), 0))
- return NSS_STATUS_UNAVAIL;
-
- struct ypall_callback ypcb;
-
- ypcb.foreach = _nis_saveit;
- ypcb.data = (char *) &intern;
- enum nss_status status = yperr2nss (yp_all (domain, "passwd.byname", &ypcb));
-
-
- /* Mark the last buffer as full. */
- if (intern.next != NULL)
- intern.next->size = intern.offset;
-
- intern.next = intern.start;
- intern.offset = 0;
-
- return status;
-}
-
-
-enum nss_status
-_nss_nis_setpwent (int stayopen)
-{
- enum nss_status result = NSS_STATUS_SUCCESS;
-
- __libc_lock_lock (lock);
-
- internal_nis_endpwent ();
-
- if (_nsl_default_nss () & NSS_FLAG_SETENT_BATCH_READ)
- result = internal_nis_setpwent ();
-
- __libc_lock_unlock (lock);
-
- return result;
-}
-
+/* Make _nss_nis_endpwent an alias of _nss_nis_setpwent. We do this
+ even though the prototypes don't match. The argument of setpwent
+ is not used so this makes no difference. */
+strong_alias (_nss_nis_setpwent, _nss_nis_endpwent)
static enum nss_status
internal_nis_getpwent_r (struct passwd *pwd, char *buffer, size_t buflen,
int *errnop)
{
- /* If we read the entire database at setpwent time we just iterate
- over the data we have in memory. */
- bool batch_read = intern.start != NULL;
+ struct parser_data *data = (void *) buffer;
+ char *domain;
+ int parse_res;
- char *domain = NULL;
- if (!batch_read && __builtin_expect (yp_get_default_domain (&domain), 0))
+ if (yp_get_default_domain (&domain))
return NSS_STATUS_UNAVAIL;
/* Get the next entry until we found a correct one. */
- int parse_res;
do
{
- char *result;
- char *outkey;
- int len;
- int keylen;
-
- if (batch_read)
- {
- struct response_t *bucket;
-
- handle_batch_read:
- bucket = intern.next;
-
- if (__builtin_expect (intern.offset >= bucket->size, 0))
- {
- if (bucket->next == NULL)
- return NSS_STATUS_NOTFOUND;
-
- /* We look at all the content in the current bucket. Go on
- to the next. */
- bucket = intern.next = bucket->next;
- intern.offset = 0;
- }
-
- for (result = &bucket->mem[intern.offset]; isspace (*result);
- ++result)
- ++intern.offset;
+ enum nss_status retval;
+ char *result, *outkey, *result2, *p;
+ int len, keylen, len2;
+ size_t namelen;
- len = strlen (result);
- }
+ if (new_start)
+ retval = yperr2nss (yp_first (domain, "passwd.byname",
+ &outkey, &keylen, &result, &len));
else
- {
- int yperr;
+ retval = yperr2nss ( yp_next (domain, "passwd.byname",
+ oldkey, oldkeylen,
+ &outkey, &keylen, &result, &len));
- if (new_start)
- {
- /* Maybe we should read the database in one piece. */
- if ((_nsl_default_nss () & NSS_FLAG_SETENT_BATCH_READ)
- && internal_nis_setpwent () == NSS_STATUS_SUCCESS
- && intern.start != NULL)
- {
- batch_read = true;
- goto handle_batch_read;
- }
-
- yperr = yp_first (domain, "passwd.byname", &outkey, &keylen,
- &result, &len);
- }
- else
- yperr = yp_next (domain, "passwd.byname", oldkey, oldkeylen,
- &outkey, &keylen, &result, &len);
-
- if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
- {
- enum nss_status retval = yperr2nss (yperr);
-
- if (retval == NSS_STATUS_TRYAGAIN)
- *errnop = errno;
- return retval;
- }
- }
+ if (retval != NSS_STATUS_SUCCESS)
+ {
+ if (retval == NSS_STATUS_TRYAGAIN)
+ *errnop = errno;
+ return retval;
+ }
/* Check for adjunct style secret passwords. They can be
recognized by a password starting with "##". */
- char *p = strchr (result, ':');
- size_t namelen;
- char *result2;
- int len2;
+ p = strchr (result, ':');
if (p != NULL /* This better should be true in all cases. */
&& p[1] == '#' && p[2] == '#'
&& (namelen = p - result,
@@ -293,8 +128,7 @@ internal_nis_getpwent_r (struct passwd *pwd, char *buffer, size_t buflen,
}
restlen = len - (p - result);
- if (__builtin_expect ((size_t) (namelen + (endp - encrypted)
- + restlen + 2) > buflen, 0))
+ if ((size_t) (namelen + (endp - encrypted) + restlen + 2) > buflen)
{
free (result2);
free (result);
@@ -302,10 +136,10 @@ internal_nis_getpwent_r (struct passwd *pwd, char *buffer, size_t buflen,
return NSS_STATUS_TRYAGAIN;
}
- mempcpy (mempcpy (mempcpy (mempcpy (buffer, result, namelen),
- ":", 1),
- encrypted, endp - encrypted),
- p, restlen + 1);
+ __mempcpy (__mempcpy (__mempcpy (__mempcpy (buffer, result, namelen),
+ ":", 1),
+ encrypted, endp - encrypted),
+ p, restlen + 1);
p = buffer;
free (result2);
@@ -313,41 +147,33 @@ internal_nis_getpwent_r (struct passwd *pwd, char *buffer, size_t buflen,
else
{
non_adjunct:
- if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
+ if ((size_t) (len + 1) > buflen)
{
free (result);
*errnop = ERANGE;
return NSS_STATUS_TRYAGAIN;
}
- p = buffer;
- *((char *) mempcpy (buffer, result, len)) = '\0';
+ p = strncpy (buffer, result, len);
+ buffer[len] = '\0';
}
while (isspace (*p))
++p;
- if (!batch_read)
- free (result);
+ free (result);
- parse_res = _nss_files_parse_pwent (p, pwd, (void *) buffer, buflen,
- errnop);
- if (__builtin_expect (parse_res == -1, 0))
+ parse_res = _nss_files_parse_pwent (p, pwd, data, buflen, errnop);
+ if (parse_res == -1)
{
- if (!batch_read)
- free (outkey);
+ free (outkey);
*errnop = ERANGE;
return NSS_STATUS_TRYAGAIN;
}
- if (batch_read)
- intern.offset += len + 1;
- else
- {
- free (oldkey);
- oldkey = outkey;
- oldkeylen = keylen;
- new_start = 0;
- }
+ free (oldkey);
+ oldkey = outkey;
+ oldkeylen = keylen;
+ new_start = 0;
}
while (parse_res < 1);
@@ -373,26 +199,28 @@ enum nss_status
_nss_nis_getpwnam_r (const char *name, struct passwd *pwd,
char *buffer, size_t buflen, int *errnop)
{
+ struct parser_data *data = (void *) buffer;
+ enum nss_status retval;
+ char *domain, *result, *result2, *p;
+ int len, len2, parse_res;
+ size_t namelen;
+
if (name == NULL)
{
*errnop = EINVAL;
return NSS_STATUS_UNAVAIL;
}
- char *domain;
- if (__builtin_expect (yp_get_default_domain (&domain), 0))
+ if (yp_get_default_domain (&domain))
return NSS_STATUS_UNAVAIL;
- size_t namelen = strlen (name);
+ namelen = strlen (name);
- char *result;
- int len;
- int yperr = yp_match (domain, "passwd.byname", name, namelen, &result, &len);
+ retval = yperr2nss (yp_match (domain, "passwd.byname", name,
+ namelen, &result, &len));
- if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
+ if (retval != NSS_STATUS_SUCCESS)
{
- enum nss_status retval = yperr2nss (yperr);
-
if (retval == NSS_STATUS_TRYAGAIN)
*errnop = errno;
return retval;
@@ -400,9 +228,7 @@ _nss_nis_getpwnam_r (const char *name, struct passwd *pwd,
/* Check for adjunct style secret passwords. They can be recognized
by a password starting with "##". */
- char *result2;
- int len2;
- char *p = strchr (result, ':');
+ p = strchr (result, ':');
if (p != NULL /* This better should be true in all cases. */
&& p[1] == '#' && p[2] == '#'
&& yp_match (domain, "passwd.adjunct.byname", name, namelen,
@@ -412,6 +238,7 @@ _nss_nis_getpwnam_r (const char *name, struct passwd *pwd,
therein into original result. */
char *encrypted = strchr (result2, ':');
char *endp;
+ size_t restlen;
if (encrypted == NULL
|| (endp = strchr (++encrypted, ':')) == NULL
@@ -424,9 +251,8 @@ _nss_nis_getpwnam_r (const char *name, struct passwd *pwd,
goto non_adjunct;
}
- size_t restlen = len - (p - result);
- if (__builtin_expect ((size_t) (namelen + (endp - encrypted)
- + restlen + 2) > buflen, 0))
+ restlen = len - (p - result);
+ if ((size_t) (namelen + (endp - encrypted) + restlen + 2) > buflen)
{
free (result2);
free (result);
@@ -445,7 +271,7 @@ _nss_nis_getpwnam_r (const char *name, struct passwd *pwd,
else
{
non_adjunct:
- if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
+ if ((size_t) (len + 1) > buflen)
{
free (result);
*errnop = ERANGE;
@@ -460,9 +286,8 @@ _nss_nis_getpwnam_r (const char *name, struct passwd *pwd,
++p;
free (result);
- int parse_res = _nss_files_parse_pwent (p, pwd, (void *) buffer, buflen,
- errnop);
- if (__builtin_expect (parse_res < 1, 0))
+ parse_res = _nss_files_parse_pwent (p, pwd, data, buflen, errnop);
+ if (parse_res < 1)
{
if (parse_res == -1)
return NSS_STATUS_TRYAGAIN;
@@ -477,21 +302,23 @@ enum nss_status
_nss_nis_getpwuid_r (uid_t uid, struct passwd *pwd,
char *buffer, size_t buflen, int *errnop)
{
- char *domain;
- if (__builtin_expect (yp_get_default_domain (&domain), 0))
+ struct parser_data *data = (void *) buffer;
+ enum nss_status retval;
+ char *domain, *result, *p, *result2;
+ int len, nlen, parse_res, len2;
+ char buf[32];
+ size_t namelen;
+
+ if (yp_get_default_domain (&domain))
return NSS_STATUS_UNAVAIL;
- char buf[32];
- int nlen = snprintf (buf, sizeof (buf), "%lu", (unsigned long int) uid);
+ nlen = sprintf (buf, "%lu", (unsigned long int) uid);
- char *result;
- int len;
- int yperr = yp_match (domain, "passwd.byuid", buf, nlen, &result, &len);
+ retval = yperr2nss (yp_match (domain, "passwd.byuid", buf,
+ nlen, &result, &len));
- if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
+ if (retval != NSS_STATUS_SUCCESS)
{
- enum nss_status retval = yperr2nss (yperr);
-
if (retval == NSS_STATUS_TRYAGAIN)
*errnop = errno;
return retval;
@@ -499,10 +326,7 @@ _nss_nis_getpwuid_r (uid_t uid, struct passwd *pwd,
/* Check for adjunct style secret passwords. They can be recognized
by a password starting with "##". */
- char *result2;
- int len2;
- size_t namelen;
- char *p = strchr (result, ':');
+ p = strchr (result, ':');
if (p != NULL /* This better should be true in all cases. */
&& p[1] == '#' && p[2] == '#'
&& (namelen = p - result,
@@ -527,8 +351,7 @@ _nss_nis_getpwuid_r (uid_t uid, struct passwd *pwd,
}
restlen = len - (p - result);
- if (__builtin_expect ((size_t) (namelen + (endp - encrypted)
- + restlen + 2) > buflen, 0))
+ if ((size_t) (namelen + (endp - encrypted) + restlen + 2) > buflen)
{
free (result2);
free (result);
@@ -547,7 +370,7 @@ _nss_nis_getpwuid_r (uid_t uid, struct passwd *pwd,
else
{
non_adjunct:
- if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
+ if ((size_t) (len + 1) > buflen)
{
free (result);
*errnop = ERANGE;
@@ -562,9 +385,8 @@ _nss_nis_getpwuid_r (uid_t uid, struct passwd *pwd,
++p;
free (result);
- int parse_res = _nss_files_parse_pwent (p, pwd, (void *) buffer, buflen,
- errnop);
- if (__builtin_expect (parse_res < 1, 0))
+ parse_res = _nss_files_parse_pwent (p, pwd, data, buflen, errnop);
+ if (parse_res < 1)
{
if (parse_res == -1)
return NSS_STATUS_TRYAGAIN;
diff --git a/nis/nss_nis/nis-rpc.c b/nis/nss_nis/nis-rpc.c
index 2fdb16ddde..d1ab94371a 100644
--- a/nis/nss_nis/nis-rpc.c
+++ b/nis/nss_nis/nis-rpc.c
@@ -1,5 +1,4 @@
-/* Copyright (C) 1996-1998,2000,2002,2003,2004,2006
- Free Software Foundation, Inc.
+/* Copyright (C) 1996-1998,2000,2002,2003,2004 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@suse.de>, 1996.
@@ -36,22 +35,59 @@
__libc_lock_define_initialized (static, lock)
-static intern_t intern;
+struct response_t
+{
+ struct response_t *next;
+ char val[0];
+};
+struct intern_t
+{
+ struct response_t *start;
+ struct response_t *next;
+};
+typedef struct intern_t intern_t;
-static void
-internal_nis_endrpcent (intern_t *intern)
+static intern_t intern = {NULL, NULL};
+
+static int
+saveit (int instatus, char *inkey, int inkeylen, char *inval,
+ int invallen, char *indata)
{
- struct response_t *curr = intern->next;
+ intern_t *intern = (intern_t *)indata;
+
+ if (instatus != YP_TRUE)
+ return 1;
- while (curr != NULL)
+ if (inkey && inkeylen > 0 && inval && invallen > 0)
{
- struct response_t *last = curr;
- curr = curr->next;
- free (last);
+ struct response_t *newp = malloc (sizeof (struct response_t)
+ + invallen + 1);
+ if (newp == NULL)
+ return 1; /* We have no error code for out of memory */
+
+ if (intern->start == NULL)
+ intern->start = newp;
+ else
+ intern->next->next = newp;
+ intern->next = newp;
+
+ newp->next = NULL;
+ *((char *) mempcpy (newp->val, inval, invallen)) = '\0';
}
- intern->next = intern->start = NULL;
+ return 0;
+}
+
+static void
+internal_nis_endrpcent (intern_t *intern)
+{
+ while (intern->start != NULL)
+ {
+ intern->next = intern->start;
+ intern->start = intern->start->next;
+ free (intern->next);
+ }
}
static enum nss_status
@@ -66,16 +102,10 @@ internal_nis_setrpcent (intern_t *intern)
internal_nis_endrpcent (intern);
- ypcb.foreach = _nis_saveit;
- ypcb.data = (char *) intern;
- status = yperr2nss (yp_all (domainname, "rpc.bynumber", &ypcb));
-
- /* Mark the last buffer as full. */
- if (intern->next != NULL)
- intern->next->size = intern->offset;
-
+ ypcb.foreach = saveit;
+ ypcb.data = (char *)intern;
+ status = yperr2nss (yp_all(domainname, "rpc.bynumber", &ypcb));
intern->next = intern->start;
- intern->offset = 0;
return status;
}
@@ -108,60 +138,29 @@ _nss_nis_endrpcent (void)
static enum nss_status
internal_nis_getrpcent_r (struct rpcent *rpc, char *buffer, size_t buflen,
- int *errnop, intern_t *intern)
+ int *errnop, intern_t *data)
{
struct parser_data *pdata = (void *) buffer;
int parse_res;
char *p;
- if (intern->start == NULL)
- internal_nis_setrpcent (intern);
-
- if (intern->next == NULL)
- /* Not one entry in the map. */
- return NSS_STATUS_NOTFOUND;
+ if (data->start == NULL)
+ internal_nis_setrpcent (data);
/* Get the next entry until we found a correct one. */
do
{
- struct response_t *bucket = intern->next;
-
- if (__builtin_expect (intern->offset >= bucket->size, 0))
- {
- if (bucket->next == NULL)
- return NSS_STATUS_NOTFOUND;
-
- /* We look at all the content in the current bucket. Go on
- to the next. */
- bucket = intern->next = bucket->next;
- intern->offset = 0;
- }
-
- for (p = &bucket->mem[intern->offset]; isspace (*p); ++p)
- ++intern->offset;
-
- size_t len = strlen (p) + 1;
- if (__builtin_expect (len > buflen, 0))
- {
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
- }
-
- /* We unfortunately have to copy the data in the user-provided
- buffer because that buffer might be around for a very long
- time and the servent structure must remain valid. If we would
- rely on the BUCKET memory the next 'setservent' or 'endservent'
- call would destroy it.
+ if (data->next == NULL)
+ return NSS_STATUS_NOTFOUND;
- The important thing is that it is a single NUL-terminated
- string. This is what the parsing routine expects. */
- p = memcpy (buffer, &bucket->mem[intern->offset], len);
+ p = strncpy (buffer, data->next->val, buflen);
+ while (isspace (*p))
+ ++p;
parse_res = _nss_files_parse_rpcent (p, rpc, pdata, buflen, errnop);
- if (__builtin_expect (parse_res == -1, 0))
+ if (parse_res == -1)
return NSS_STATUS_TRYAGAIN;
-
- intern->offset += len;
+ data->next = data->next->next;
}
while (!parse_res);
@@ -187,18 +186,21 @@ enum nss_status
_nss_nis_getrpcbyname_r (const char *name, struct rpcent *rpc,
char *buffer, size_t buflen, int *errnop)
{
+ intern_t data = {NULL, NULL};
+ enum nss_status status;
+ int found;
+
if (name == NULL)
{
*errnop = EINVAL;
return NSS_STATUS_UNAVAIL;
}
- intern_t data = { NULL, NULL, 0 };
- enum nss_status status = internal_nis_setrpcent (&data);
- if (__builtin_expect (status != NSS_STATUS_SUCCESS, 0))
+ status = internal_nis_setrpcent (&data);
+ if (status != NSS_STATUS_SUCCESS)
return status;
- int found = 0;
+ found = 0;
while (!found &&
((status = internal_nis_getrpcent_r (rpc, buffer, buflen, errnop,
&data)) == NSS_STATUS_SUCCESS))
@@ -224,52 +226,53 @@ _nss_nis_getrpcbyname_r (const char *name, struct rpcent *rpc,
internal_nis_endrpcent (&data);
- if (__builtin_expect (!found && status == NSS_STATUS_SUCCESS, 0))
+ if (!found && status == NSS_STATUS_SUCCESS)
return NSS_STATUS_NOTFOUND;
-
- return status;
+ else
+ return status;
}
enum nss_status
_nss_nis_getrpcbynumber_r (int number, struct rpcent *rpc,
char *buffer, size_t buflen, int *errnop)
{
- char *domain;
- if (__builtin_expect (yp_get_default_domain (&domain), 0))
+ struct parser_data *data = (void *) buffer;
+ enum nss_status retval;
+ char *domain, *result, *p;
+ int len, nlen, parse_res;
+ char buf[32];
+
+ if (yp_get_default_domain (&domain))
return NSS_STATUS_UNAVAIL;
- char buf[32];
- int nlen = snprintf (buf, sizeof (buf), "%d", number);
+ nlen = sprintf (buf, "%d", number);
- char *result;
- int len;
- int yperr = yp_match (domain, "rpc.bynumber", buf, nlen, &result, &len);
+ retval = yperr2nss (yp_match (domain, "rpc.bynumber", buf,
+ nlen, &result, &len));
- if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
+ if (retval != NSS_STATUS_SUCCESS)
{
- enum nss_status retval = yperr2nss (yperr);
-
if (retval == NSS_STATUS_TRYAGAIN)
*errnop = errno;
return retval;
}
- if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
+ if ((size_t) (len + 1) > buflen)
{
free (result);
*errnop = ERANGE;
return NSS_STATUS_TRYAGAIN;
}
- char *p = strncpy (buffer, result, len);
+ p = strncpy (buffer, result, len);
buffer[len] = '\0';
while (isspace (*p))
++p;
free (result);
- int parse_res = _nss_files_parse_rpcent (p, rpc, (void *) buffer, buflen,
- errnop);
- if (__builtin_expect (parse_res < 1, 0))
+ parse_res = _nss_files_parse_rpcent (p, rpc, data, buflen, errnop);
+
+ if (parse_res < 1)
{
if (parse_res == -1)
return NSS_STATUS_TRYAGAIN;
diff --git a/nis/nss_nis/nis-service.c b/nis/nss_nis/nis-service.c
index 59a598f296..1e879d04e3 100644
--- a/nis/nss_nis/nis-service.c
+++ b/nis/nss_nis/nis-service.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-2004, 2006 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2001, 2002, 2003, 2004 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@suse.de>, 1996.
@@ -27,7 +27,6 @@
#include <rpcsvc/ypclnt.h>
#include "nss-nis.h"
-#include <libnsl.h>
/* Get the declaration of the parser function. */
@@ -37,7 +36,20 @@
__libc_lock_define_initialized (static, lock)
-static intern_t intern;
+struct response_t
+{
+ struct response_t *next;
+ char val[0];
+};
+
+struct intern_t
+{
+ struct response_t *start;
+ struct response_t *next;
+};
+typedef struct intern_t intern_t;
+
+static intern_t intern = { NULL, NULL };
struct search_t
{
@@ -52,31 +64,63 @@ struct search_t
};
static int
+saveit (int instatus, char *inkey, int inkeylen, char *inval,
+ int invallen, char *indata)
+{
+ intern_t *intern = (intern_t *) indata;
+
+ if (instatus != YP_TRUE)
+ return 1;
+
+ if (inkey && inkeylen > 0 && inval && invallen > 0)
+ {
+ struct response_t *newp = malloc (sizeof (struct response_t)
+ + invallen + 1);
+ if (newp == NULL)
+ return 1; /* We have no error code for out of memory */
+
+ if (intern->start == NULL)
+ intern->start = newp;
+ else
+ intern->next->next = newp;
+ intern->next = newp;
+
+ newp->next = NULL;
+ *((char *) mempcpy (newp->val, inval, invallen)) = '\0';
+ }
+
+ return 0;
+}
+
+static int
dosearch (int instatus, char *inkey, int inkeylen, char *inval,
int invallen, char *indata)
{
struct search_t *req = (struct search_t *) indata;
- if (__builtin_expect (instatus != YP_TRUE, 0))
+ if (instatus != YP_TRUE)
return 1;
if (inkey && inkeylen > 0 && inval && invallen > 0)
{
- if (__builtin_expect ((size_t) (invallen + 1) > req->buflen, 0))
+ struct parser_data *pdata = (void *) req->buffer;
+ int parse_res;
+ char *p;
+
+ if ((size_t) (invallen + 1) > req->buflen)
{
*req->errnop = ERANGE;
req->status = NSS_STATUS_TRYAGAIN;
return 1;
}
- char *p = strncpy (req->buffer, inval, invallen);
+ p = strncpy (req->buffer, inval, invallen);
req->buffer[invallen] = '\0';
while (isspace (*p))
++p;
- int parse_res = _nss_files_parse_servent (p, req->serv,
- (void *) req->buffer,
- req->buflen, req->errnop);
+ parse_res = _nss_files_parse_servent (p, req->serv, pdata, req->buflen,
+ req->errnop);
if (parse_res == -1)
{
req->status = NSS_STATUS_TRYAGAIN;
@@ -110,35 +154,35 @@ dosearch (int instatus, char *inkey, int inkeylen, char *inval,
return 0;
}
-static void
-internal_nis_endservent (void)
+static enum nss_status
+internal_nis_endservent (intern_t * intern)
{
- struct response_t *curr = intern.next;
-
- while (curr != NULL)
+ while (intern->start != NULL)
{
- struct response_t *last = curr;
- curr = curr->next;
- free (last);
+ intern->next = intern->start;
+ intern->start = intern->start->next;
+ free (intern->next);
}
- intern.next = intern.start = NULL;
+ return NSS_STATUS_SUCCESS;
}
enum nss_status
_nss_nis_endservent (void)
{
+ enum nss_status status;
+
__libc_lock_lock (lock);
- internal_nis_endservent ();
+ status = internal_nis_endservent (&intern);
__libc_lock_unlock (lock);
- return NSS_STATUS_SUCCESS;
+ return status;
}
static enum nss_status
-internal_nis_setservent (void)
+internal_nis_setservent (intern_t *intern)
{
char *domainname;
struct ypall_callback ypcb;
@@ -147,18 +191,12 @@ internal_nis_setservent (void)
if (yp_get_default_domain (&domainname))
return NSS_STATUS_UNAVAIL;
- internal_nis_endservent ();
+ (void) internal_nis_endservent (intern);
- ypcb.foreach = _nis_saveit;
- ypcb.data = (char *) &intern;
+ ypcb.foreach = saveit;
+ ypcb.data = (char *) intern;
status = yperr2nss (yp_all (domainname, "services.byname", &ypcb));
-
- /* Mark the last buffer as full. */
- if (intern.next != NULL)
- intern.next->size = intern.offset;
-
- intern.next = intern.start;
- intern.offset = 0;
+ intern->next = intern->start;
return status;
}
@@ -170,7 +208,7 @@ _nss_nis_setservent (int stayopen)
__libc_lock_lock (lock);
- status = internal_nis_setservent ();
+ status = internal_nis_setservent (&intern);
__libc_lock_unlock (lock);
@@ -179,60 +217,29 @@ _nss_nis_setservent (int stayopen)
static enum nss_status
internal_nis_getservent_r (struct servent *serv, char *buffer,
- size_t buflen, int *errnop)
+ size_t buflen, int *errnop, intern_t *data)
{
struct parser_data *pdata = (void *) buffer;
int parse_res;
char *p;
- if (intern.start == NULL)
- internal_nis_setservent ();
+ if (data->start == NULL)
+ internal_nis_setservent (data);
- if (intern.next == NULL)
- /* Not one entry in the map. */
- return NSS_STATUS_NOTFOUND;
-
- /* Get the next entry until we found a correct one. */
+ /* Get the next entry until we found a correct one. */
do
{
- struct response_t *bucket = intern.next;
+ if (data->next == NULL)
+ return NSS_STATUS_NOTFOUND;
- if (__builtin_expect (intern.offset >= bucket->size, 0))
- {
- if (bucket->next == NULL)
- return NSS_STATUS_NOTFOUND;
-
- /* We look at all the content in the current bucket. Go on
- to the next. */
- bucket = intern.next = bucket->next;
- intern.offset = 0;
- }
-
- for (p = &bucket->mem[intern.offset]; isspace (*p); ++p)
- ++intern.offset;
-
- size_t len = strlen (p) + 1;
- if (__builtin_expect (len > buflen, 0))
- {
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
- }
-
- /* We unfortunately have to copy the data in the user-provided
- buffer because that buffer might be around for a very long
- time and the servent structure must remain valid. If we would
- rely on the BUCKET memory the next 'setservent' or 'endservent'
- call would destroy it.
-
- The important thing is that it is a single NUL-terminated
- string. This is what the parsing routine expects. */
- p = memcpy (buffer, &bucket->mem[intern.offset], len);
+ p = strncpy (buffer, data->next->val, buflen);
+ while (isspace (*p))
+ ++p;
parse_res = _nss_files_parse_servent (p, serv, pdata, buflen, errnop);
- if (__builtin_expect (parse_res == -1, 0))
+ if (parse_res == -1)
return NSS_STATUS_TRYAGAIN;
-
- intern.offset += len;
+ data->next = data->next->next;
}
while (!parse_res);
@@ -247,7 +254,7 @@ _nss_nis_getservent_r (struct servent *serv, char *buffer, size_t buflen,
__libc_lock_lock (lock);
- status = internal_nis_getservent_r (serv, buffer, buflen, errnop);
+ status = internal_nis_getservent_r (serv, buffer, buflen, errnop, &intern);
__libc_lock_unlock (lock);
@@ -259,55 +266,60 @@ _nss_nis_getservbyname_r (const char *name, const char *protocol,
struct servent *serv, char *buffer, size_t buflen,
int *errnop)
{
+ enum nss_status status;
+ char *domain;
+
if (name == NULL)
{
*errnop = EINVAL;
return NSS_STATUS_UNAVAIL;
}
- char *domain;
- if (__builtin_expect (yp_get_default_domain (&domain), 0))
+ if (yp_get_default_domain (&domain))
return NSS_STATUS_UNAVAIL;
/* If the protocol is given, we could try if our NIS server knows
about services.byservicename map. If yes, we only need one query. */
- size_t keylen = strlen (name) + (protocol ? 1 + strlen (protocol) : 0);
- char key[keylen + 1];
+ char key[strlen (name) + (protocol ? strlen (protocol) : 0) + 2];
+ char *cp, *result;
+ size_t keylen, len;
+ int int_len;
/* key is: "name/proto" */
- char *cp = stpcpy (key, name);
- if (protocol != NULL)
+ cp = stpcpy (key, name);
+ if (protocol)
{
*cp++ = '/';
strcpy (cp, protocol);
}
-
- char *result;
- int int_len;
- int status = yp_match (domain, "services.byservicename", key,
- keylen, &result, &int_len);
- size_t len = int_len;
+ keylen = strlen (key);
+ status = yperr2nss (yp_match (domain, "services.byservicename", key,
+ keylen, &result, &int_len));
+ 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 == YPERR_SUCCESS, 1))
+ if (status == NSS_STATUS_SUCCESS)
{
- if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
+ struct parser_data *pdata = (void *) buffer;
+ int parse_res;
+ char *p;
+
+ if ((size_t) (len + 1) > buflen)
{
free (result);
*errnop = ERANGE;
return NSS_STATUS_TRYAGAIN;
}
- char *p = strncpy (buffer, result, len);
+ p = strncpy (buffer, result, len);
buffer[len] = '\0';
while (isspace (*p))
++p;
free (result);
-
- int parse_res = _nss_files_parse_servent (p, serv, (void *) buffer,
- buflen, errnop);
- if (__builtin_expect (parse_res < 0, 0))
+ parse_res = _nss_files_parse_servent (p, serv, pdata,
+ buflen, errnop);
+ if (parse_res < 0)
{
if (parse_res == -1)
return NSS_STATUS_TRYAGAIN;
@@ -319,8 +331,8 @@ _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 yperr2nss (status);
+ if (_nis_default_nss () & NSS_FLAG_SERVICES_AUTHORITATIVE)
+ return status;
struct ypall_callback ypcb;
struct search_t req;
@@ -335,10 +347,10 @@ _nss_nis_getservbyname_r (const char *name, const char *protocol,
req.buflen = buflen;
req.errnop = errnop;
req.status = NSS_STATUS_NOTFOUND;
- status = yp_all (domain, "services.byname", &ypcb);
+ status = yperr2nss (yp_all (domain, "services.byname", &ypcb));
- if (__builtin_expect (status != YPERR_SUCCESS, 0))
- return yperr2nss (status);
+ if (status != NSS_STATUS_SUCCESS)
+ return status;
return req.status;
}
@@ -348,8 +360,10 @@ _nss_nis_getservbyport_r (int port, const char *protocol,
struct servent *serv, char *buffer,
size_t buflen, int *errnop)
{
+ enum nss_status status;
char *domain;
- if (__builtin_expect (yp_get_default_domain (&domain), 0))
+
+ if (yp_get_default_domain (&domain))
return NSS_STATUS_UNAVAIL;
/* If the protocol is given, we only need one query.
@@ -358,44 +372,48 @@ _nss_nis_getservbyport_r (int port, const char *protocol,
const char *proto = protocol != NULL ? protocol : "tcp";
do
{
- /* key is: "port/proto" */
char key[sizeof (int) * 3 + strlen (proto) + 2];
- size_t keylen = snprintf (key, sizeof (key), "%d/%s", ntohs (port),
- proto);
-
char *result;
+ size_t keylen, len;
int int_len;
- int status = yp_match (domain, "services.byname", key, keylen, &result,
- &int_len);
- size_t len = int_len;
+
+ /* key is: "port/proto" */
+ keylen = snprintf (key, sizeof (key), "%d/%s", ntohs (port), proto);
+ status = yperr2nss (yp_match (domain, "services.byname", key,
+ keylen, &result, &int_len));
+ 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 == YPERR_SUCCESS, 1))
+ if (status == NSS_STATUS_SUCCESS)
{
- if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
+ struct parser_data *pdata = (void *) buffer;
+ int parse_res;
+ char *p;
+
+ if ((size_t) (len + 1) > buflen)
{
free (result);
*errnop = ERANGE;
return NSS_STATUS_TRYAGAIN;
}
- char *p = strncpy (buffer, result, len);
+ p = strncpy (buffer, result, len);
buffer[len] = '\0';
while (isspace (*p))
++p;
free (result);
- int parse_res = _nss_files_parse_servent (p, serv, (void *) buffer,
- buflen, errnop);
- if (__builtin_expect (parse_res < 0, 0))
+ parse_res = _nss_files_parse_servent (p, serv, pdata,
+ buflen, errnop);
+ if (parse_res < 0)
{
if (parse_res == -1)
return NSS_STATUS_TRYAGAIN;
else
return NSS_STATUS_NOTFOUND;
}
-
- return NSS_STATUS_SUCCESS;
+ else
+ return NSS_STATUS_SUCCESS;
}
}
while (protocol == NULL && (proto[0] == 't' ? (proto = "udp") : NULL));
@@ -416,10 +434,10 @@ _nss_nis_getservbyport_r (int port, const char *protocol,
req.buflen = buflen;
req.errnop = errnop;
req.status = NSS_STATUS_NOTFOUND;
- int status = yp_all (domain, "services.byname", &ypcb);
+ status = yperr2nss (yp_all (domain, "services.byname", &ypcb));
- if (__builtin_expect (status != YPERR_SUCCESS, 0))
- return yperr2nss (status);
+ if (status != NSS_STATUS_SUCCESS)
+ return status;
return req.status;
}
diff --git a/nis/nss_nis/nis-spwd.c b/nis/nss_nis/nis-spwd.c
index 0fc4e17c42..99a9ed5f48 100644
--- a/nis/nss_nis/nis-spwd.c
+++ b/nis/nss_nis/nis-spwd.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-1998,2001,2002,2003,2006 Free Software Foundation, Inc.
+/* Copyright (C) 1996-1998, 2001, 2002, 2003 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1996.
@@ -68,52 +68,49 @@ static enum nss_status
internal_nis_getspent_r (struct spwd *sp, char *buffer, size_t buflen,
int *errnop)
{
- char *domain;
- if (__builtin_expect (yp_get_default_domain (&domain), 0))
+ struct parser_data *data = (void *) buffer;
+ char *domain, *result, *outkey;
+ int len, keylen, parse_res;
+
+ if (yp_get_default_domain (&domain))
return NSS_STATUS_UNAVAIL;
/* Get the next entry until we found a correct one. */
- int parse_res;
do
{
- char *result;
- char *outkey;
- int len;
- int keylen;
- int yperr;
+ enum nss_status retval;
+ char *p;
if (new_start)
- yperr = yp_first (domain, "shadow.byname", &outkey, &keylen, &result,
- &len);
+ retval = yperr2nss (yp_first (domain, "shadow.byname",
+ &outkey, &keylen, &result, &len));
else
- yperr = yp_next (domain, "shadow.byname", oldkey, oldkeylen, &outkey,
- &keylen, &result, &len);
+ retval = yperr2nss ( yp_next (domain, "shadow.byname",
+ oldkey, oldkeylen,
+ &outkey, &keylen, &result, &len));
- if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
+ if (retval != NSS_STATUS_SUCCESS)
{
- enum nss_status retval = yperr2nss (yperr);
-
if (retval == NSS_STATUS_TRYAGAIN)
*errnop = errno;
return retval;
}
- if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
+ if ((size_t) (len + 1) > buflen)
{
free (result);
*errnop = ERANGE;
return NSS_STATUS_TRYAGAIN;
}
- char *p = strncpy (buffer, result, len);
+ p = strncpy (buffer, result, len);
buffer[len] = '\0';
while (isspace (*p))
++p;
free (result);
- parse_res = _nss_files_parse_spent (p, sp, (void *) buffer, buflen,
- errnop);
- if (__builtin_expect (parse_res == -1, 0))
+ parse_res = _nss_files_parse_spent (p, sp, data, buflen, errnop);
+ if (parse_res == -1)
{
free (outkey);
*errnop = ERANGE;
@@ -149,46 +146,45 @@ enum nss_status
_nss_nis_getspnam_r (const char *name, struct spwd *sp,
char *buffer, size_t buflen, int *errnop)
{
+ struct parser_data *data = (void *) buffer;
+ enum nss_status retval;
+ char *domain, *result, *p;
+ int len, parse_res;
+
if (name == NULL)
{
*errnop = EINVAL;
return NSS_STATUS_UNAVAIL;
}
- char *domain;
- if (__builtin_expect (yp_get_default_domain (&domain), 0))
+ if (yp_get_default_domain (&domain))
return NSS_STATUS_UNAVAIL;
- char *result;
- int len;
- int yperr = yp_match (domain, "shadow.byname", name, strlen (name), &result,
- &len);
+ retval = yperr2nss (yp_match (domain, "shadow.byname", name,
+ strlen (name), &result, &len));
- if (__builtin_expect (yperr != YPERR_SUCCESS, 0))
+ if (retval != NSS_STATUS_SUCCESS)
{
- enum nss_status retval = yperr2nss (yperr);
-
if (retval == NSS_STATUS_TRYAGAIN)
*errnop = errno;
return retval;
}
- if (__builtin_expect ((size_t) (len + 1) > buflen, 0))
+ if ((size_t) (len + 1) > buflen)
{
free (result);
*errnop = ERANGE;
return NSS_STATUS_TRYAGAIN;
}
- char *p = strncpy (buffer, result, len);
+ p = strncpy (buffer, result, len);
buffer[len] = '\0';
while (isspace (*p))
++p;
free (result);
- int parse_res = _nss_files_parse_spent (p, sp, (void *) buffer, buflen,
- errnop);
- if (__builtin_expect (parse_res < 1, 0))
+ parse_res = _nss_files_parse_spent (p, sp, data, buflen, errnop);
+ if (parse_res < 1)
{
if (parse_res == -1)
return NSS_STATUS_TRYAGAIN;
diff --git a/nis/nss_nisplus/nisplus-alias.c b/nis/nss_nisplus/nisplus-alias.c
index 57858721a1..152e5fc3fc 100644
--- a/nis/nss_nisplus/nisplus-alias.c
+++ b/nis/nss_nisplus/nisplus-alias.c
@@ -1,5 +1,4 @@
-/* Copyright (C) 1997, 1998, 2001, 2002, 2003, 2005, 2006
- Free Software Foundation, Inc.
+/* Copyright (C) 1997, 1998, 2001, 2002, 2003 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
@@ -18,7 +17,6 @@
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>
@@ -34,39 +32,32 @@ __libc_lock_define_initialized (static, lock)
static nis_result *result;
static u_long next_entry;
static nis_name tablename_val;
-static size_t tablename_len;
+static u_long tablename_len;
-#define NISENTRYVAL(idx, col, res) \
- (NIS_RES_OBJECT (res)[idx].EN_data.en_cols.en_cols_val[col].ec_value.ec_value_val)
+#define NISENTRYVAL(idx,col,res) \
+ ((res)->objects.objects_val[(idx)].EN_data.en_cols.en_cols_val[(col)].ec_value.ec_value_val)
-#define NISENTRYLEN(idx, col, res) \
- (NIS_RES_OBJECT (res)[idx].EN_data.en_cols.en_cols_val[col].ec_value.ec_value_len)
+#define NISENTRYLEN(idx,col,res) \
+ ((res)->objects.objects_val[(idx)].EN_data.en_cols.en_cols_val[(col)].ec_value.ec_value_len)
static enum nss_status
_nss_create_tablename (int *errnop)
{
if (tablename_val == NULL)
{
- const char *local_dir = nis_local_directory ();
- size_t local_dir_len = strlen (local_dir);
- static const char prefix[] = "mail_aliases.org_dir.";
+ char buf [40 + strlen (nis_local_directory ())];
+ char *p;
- char *p = malloc (sizeof (prefix) + local_dir_len);
- if (p == NULL)
+ p = __stpcpy (buf, "mail_aliases.org_dir.");
+ p = __stpcpy (p, nis_local_directory ());
+ tablename_val = __strdup (buf);
+ if (tablename_val == NULL)
{
*errnop = errno;
return NSS_STATUS_TRYAGAIN;
}
-
- memcpy (__stpcpy (p, prefix), local_dir, local_dir_len + 1);
-
- tablename_len = sizeof (prefix) - 1 + local_dir_len;
-
- atomic_write_barrier ();
-
- tablename_val = p;
+ tablename_len = strlen (tablename_val);
}
-
return NSS_STATUS_SUCCESS;
}
@@ -79,87 +70,86 @@ _nss_nisplus_parse_aliasent (nis_result *result, unsigned long entry,
return 0;
if ((result->status != NIS_SUCCESS && result->status != NIS_S_SUCCESS)
- || __type_of (&NIS_RES_OBJECT (result)[entry]) != NIS_ENTRY_OBJ
- || strcmp (NIS_RES_OBJECT (result)[entry].EN_data.en_type,
+ || __type_of (&result->objects.objects_val[entry]) != NIS_ENTRY_OBJ
+ || strcmp (result->objects.objects_val[entry].EN_data.en_type,
"mail_aliases") != 0
- || NIS_RES_OBJECT (result)[entry].EN_data.en_cols.en_cols_len < 2)
+ || result->objects.objects_val[entry].EN_data.en_cols.en_cols_len < 2)
return 0;
-
- if (NISENTRYLEN (entry, 1, result) >= buflen)
- {
- /* 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';
-
- char *first_unused = cp + 1;
- size_t room_left = buflen - (first_unused - buffer);
-
- alias->alias_local = 0;
- alias->alias_members_len = 0;
-
- if (NISENTRYLEN (entry, 0, result) >= room_left)
- goto no_more_room;
-
- 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';
-
- size_t len = strlen (alias->alias_name) + 1;
- first_unused += len;
- room_left -= len;
-
- /* Adjust the pointer so it is aligned for
- storing pointers. */
- size_t adjust = ((__alignof__ (char *)
- - (first_unused - (char *) 0) % __alignof__ (char *))
- % __alignof__ (char *));
- if (room_left < adjust)
- goto no_more_room;
- first_unused += adjust;
- room_left -= adjust;
-
- alias->alias_members = (char **) first_unused;
-
- char *line = buffer;
- while (*line != '\0')
+ else
{
- /* Skip leading blanks. */
- while (isspace (*line))
- ++line;
-
- if (*line == '\0')
- break;
+ 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';
+ }
- if (room_left < sizeof (char *))
+ if (NISENTRYLEN(entry, 0, result) >= room_left)
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])
+ 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')
{
- *line++ = '\0';
- ++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++;
+ }
}
- else if (*line == ',')
- ++line;
- }
- return alias->alias_members_len == 0 ? 0 : 1;
+ return alias->alias_members_len == 0 ? 0 : 1;
+ }
}
static enum nss_status
@@ -168,11 +158,9 @@ internal_setaliasent (void)
enum nss_status status;
int err;
- if (result != NULL)
- {
- nis_freeresult (result);
- result = NULL;
- }
+ if (result)
+ nis_freeresult (result);
+ result = NULL;
if (_nss_create_tablename (&err) != NSS_STATUS_SUCCESS)
return NSS_STATUS_UNAVAIL;
@@ -215,11 +203,9 @@ _nss_nisplus_endaliasent (void)
{
__libc_lock_lock (lock);
- if (result != NULL)
- {
- nis_freeresult (result);
- result = NULL;
- }
+ if (result)
+ nis_freeresult (result);
+ result = NULL;
next_entry = 0;
__libc_lock_unlock (lock);
@@ -254,8 +240,7 @@ internal_nisplus_getaliasent_r (struct aliasent *alias,
return NSS_STATUS_TRYAGAIN;
++next_entry;
- }
- while (!parse_res);
+ } while (!parse_res);
return NSS_STATUS_SUCCESS;
}
@@ -283,12 +268,7 @@ _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;
}
@@ -298,42 +278,35 @@ _nss_nisplus_getaliasbyname_r (const char *name, struct aliasent *alias,
*errnop = EINVAL;
return NSS_STATUS_UNAVAIL;
}
-
- char buf[strlen (name) + 9 + tablename_len];
- int olderr = errno;
-
- 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)
+ else
{
- *errnop = ENOMEM;
- return NSS_STATUS_TRYAGAIN;
- }
+ nis_result *result;
+ char buf[strlen (name) + 30 + tablename_len];
+ int olderr = errno;
- if (__builtin_expect (niserr2nss (result->status) != NSS_STATUS_SUCCESS, 0))
- {
- enum nss_status status = niserr2nss (result->status);
- nis_freeresult (result);
- return status;
- }
+ sprintf (buf, "[name=%s],%s", name, tablename_val);
- parse_res = _nss_nisplus_parse_aliasent (result, 0, alias,
- buffer, buflen, errnop);
+ result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL);
- /* We do not need the lookup result anymore. */
- nis_freeresult (result);
+ if (result == NULL)
+ {
+ *errnop = ENOMEM;
+ return NSS_STATUS_TRYAGAIN;
+ }
+ if (niserr2nss (result->status) != NSS_STATUS_SUCCESS)
+ return niserr2nss (result->status);
- if (__builtin_expect (parse_res < 1, 0))
- {
- __set_errno (olderr);
+ parse_res = _nss_nisplus_parse_aliasent (result, 0, alias,
+ buffer, buflen, errnop);
+ if (parse_res < 1)
+ {
+ __set_errno (olderr);
- if (parse_res == -1)
- return NSS_STATUS_TRYAGAIN;
- else
- return NSS_STATUS_NOTFOUND;
+ if (parse_res == -1)
+ return NSS_STATUS_TRYAGAIN;
+ else
+ return NSS_STATUS_NOTFOUND;
+ }
+ return NSS_STATUS_SUCCESS;
}
-
- return NSS_STATUS_SUCCESS;
}
diff --git a/nis/nss_nisplus/nisplus-ethers.c b/nis/nss_nisplus/nisplus-ethers.c
index 298869f931..028309c841 100644
--- a/nis/nss_nisplus/nisplus-ethers.c
+++ b/nis/nss_nisplus/nisplus-ethers.c
@@ -1,5 +1,4 @@
-/* Copyright (C) 1997,1998,2000-2003,2005,2006,2007
- Free Software Foundation, Inc.
+/* Copyright (C) 1997,1998,2000,2001,2002,2003 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@suse.de>, 1997.
@@ -18,17 +17,15 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
-#include <atomic.h>
-#include <ctype.h>
-#include <errno.h>
-#include <inttypes.h>
-#include <netdb.h>
#include <nss.h>
+#include <errno.h>
+#include <ctype.h>
#include <string.h>
+#include <bits/libc-lock.h>
+#include <netdb.h>
#include <netinet/ether.h>
-#include <netinet/if_ether.h>
#include <rpcsvc/nis.h>
-#include <bits/libc-lock.h>
+#include <netinet/if_ether.h>
#include "nss-nisplus.h"
@@ -39,11 +36,11 @@ static nis_name tablename_val;
static u_long tablename_len;
-#define NISENTRYVAL(idx, col, res) \
- (NIS_RES_OBJECT (res)[idx].zo_data.objdata_u.en_data.en_cols.en_cols_val[col].ec_value.ec_value_val)
+#define NISENTRYVAL(idx,col,res) \
+ ((res)->objects.objects_val[(idx)].zo_data.objdata_u.en_data.en_cols.en_cols_val[(col)].ec_value.ec_value_val)
-#define NISENTRYLEN(idx, col, res) \
- (NIS_RES_OBJECT (res)[idx].zo_data.objdata_u.en_data.en_cols.en_cols_val[col].ec_value.ec_value_len)
+#define NISENTRYLEN(idx,col,res) \
+ ((res)->objects.objects_val[(idx)].zo_data.objdata_u.en_data.en_cols.en_cols_val[(col)].ec_value.ec_value_len)
static int
_nss_nisplus_parse_etherent (nis_result *result, struct etherent *ether,
@@ -56,7 +53,7 @@ _nss_nisplus_parse_etherent (nis_result *result, struct etherent *ether,
return 0;
if ((result->status != NIS_SUCCESS && result->status != NIS_S_SUCCESS)
- || NIS_RES_NUMOBJ (result) != 1
+ || result->objects.objects_len != 1
|| __type_of (NIS_RES_OBJECT (result)) != NIS_ENTRY_OBJ
|| strcmp (NIS_RES_OBJECT (result)->EN_data.en_type,
"ethers_tbl") != 0
@@ -64,25 +61,16 @@ _nss_nisplus_parse_etherent (nis_result *result, struct etherent *ether,
return 0;
/* Generate the ether entry format and use the normal parser */
- if (NISENTRYLEN (0, 0, result) + 1 > room_left)
+ if (NISENTRYLEN (0, 0, result) +1 > room_left)
{
*errnop = ERANGE;
return -1;
}
- char *cp = __stpncpy (p, NISENTRYVAL (0, 0, result),
- NISENTRYLEN (0, 0, result));
- *cp = '\0';
- room_left -= NISENTRYLEN (0, 0, result) + 1;
+ strncpy (p, NISENTRYVAL (0, 0, result), NISENTRYLEN (0, 0, result));
+ room_left -= (NISENTRYLEN (0, 0, result) +1);
ether->e_name = p;
- struct ether_addr *ea = ether_aton (NISENTRYVAL (0, 1, result));
- if (ea == NULL)
- {
- *errnop = EINVAL;
- return -2;
- }
-
- ether->e_addr = *ea;
+ ether->e_addr = *ether_aton (NISENTRYVAL (0, 1, result));
return 1;
}
@@ -92,24 +80,18 @@ _nss_create_tablename (int *errnop)
{
if (tablename_val == NULL)
{
- const char *local_dir = nis_local_directory ();
- size_t local_dir_len = strlen (local_dir);
- static const char prefix[] = "ethers.org_dir.";
+ char buf [40 + strlen (nis_local_directory ())];
+ char *p;
- char *p = malloc (sizeof (prefix) + local_dir_len);
- if (p == NULL)
+ p = __stpcpy (buf, "ethers.org_dir.");
+ p = __stpcpy (p, nis_local_directory ());
+ tablename_val = __strdup (buf);
+ if (tablename_val == NULL)
{
*errnop = errno;
return NSS_STATUS_TRYAGAIN;
}
-
- memcpy (__stpcpy (p, prefix), local_dir, local_dir_len + 1);
-
- tablename_len = sizeof (prefix) - 1 + local_dir_len;
-
- atomic_write_barrier ();
-
- tablename_val = p;
+ tablename_len = strlen (tablename_val);
}
return NSS_STATUS_SUCCESS;
}
@@ -125,11 +107,9 @@ _nss_nisplus_setetherent (int stayopen)
__libc_lock_lock (lock);
- if (result != NULL)
- {
- nis_freeresult (result);
- result = NULL;
- }
+ if (result)
+ nis_freeresult (result);
+ result = NULL;
if (_nss_create_tablename (&err) != NSS_STATUS_SUCCESS)
status = NSS_STATUS_UNAVAIL;
@@ -144,11 +124,9 @@ _nss_nisplus_endetherent (void)
{
__libc_lock_lock (lock);
- if (result != NULL)
- {
- nis_freeresult (result);
- result = NULL;
- }
+ if (result)
+ nis_freeresult (result);
+ result = NULL;
__libc_lock_unlock (lock);
@@ -159,6 +137,8 @@ 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);
@@ -168,7 +148,6 @@ 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;
@@ -177,23 +156,16 @@ internal_nisplus_getetherent_r (struct etherent *ether, char *buffer,
{
saved_result = NULL;
result = nis_first_entry (tablename_val);
- if (result == NULL)
- {
- *errnop = errno;
- return NSS_STATUS_TRYAGAIN;
- }
if (niserr2nss (result->status) != NSS_STATUS_SUCCESS)
return niserr2nss (result->status);
}
else
{
+ nis_result *res2;
+
+ res2 = nis_next_entry(tablename_val, &result->cookie);
saved_result = result;
- result = nis_next_entry (tablename_val, &result->cookie);
- if (result == NULL)
- {
- *errnop = errno;
- return NSS_STATUS_TRYAGAIN;
- }
+ result = res2;
if (niserr2nss (result->status) != NSS_STATUS_SUCCESS)
{
nis_freeresult (saved_result);
@@ -206,15 +178,17 @@ 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);
+ }
- if (saved_result != NULL)
- nis_freeresult (saved_result);
-
- }
- while (!parse_res);
+ } while (!parse_res);
return NSS_STATUS_SUCCESS;
}
@@ -238,6 +212,8 @@ 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);
@@ -251,59 +227,56 @@ _nss_nisplus_gethostton_r (const char *name, struct etherent *eth,
*errnop = EINVAL;
return NSS_STATUS_UNAVAIL;
}
-
- char buf[strlen (name) + 9 + tablename_len];
- int olderr = errno;
-
- snprintf (buf, sizeof (buf), "[name=%s],%s", name, tablename_val);
-
- nis_result *result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS | USE_DGRAM,
- NULL, NULL);
-
- if (result == NULL)
+ else
{
- *errnop = ENOMEM;
- return NSS_STATUS_TRYAGAIN;
- }
+ nis_result *result;
+ char buf[strlen (name) + 40 + tablename_len];
+ int olderr = errno;
- if (__builtin_expect (niserr2nss (result->status) != NSS_STATUS_SUCCESS, 0))
- {
- enum nss_status status = niserr2nss (result->status);
- nis_freeresult (result);
- return status;
- }
+ sprintf (buf, "[name=%s],%s", name, tablename_val);
- int parse_res = _nss_nisplus_parse_etherent (result, eth, buffer,
- buflen, errnop);
+ result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL);
- /* We do not need the lookup result anymore. */
- nis_freeresult (result);
-
- if (__builtin_expect (parse_res < 1, 0))
- {
- __set_errno (olderr);
+ 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;
+ }
- if (parse_res == -1)
- return NSS_STATUS_TRYAGAIN;
+ parse_res = _nss_nisplus_parse_etherent (result, eth, buffer,
+ buflen, errnop);
+ if (parse_res < 1)
+ {
+ __set_errno (olderr);
- return NSS_STATUS_NOTFOUND;
+ if (parse_res == -1)
+ {
+ nis_freeresult (result);
+ *errnop = ERANGE;
+ return NSS_STATUS_TRYAGAIN;
+ }
+ else
+ return NSS_STATUS_NOTFOUND;
+ }
+ return NSS_STATUS_SUCCESS;
}
-
- 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;
}
@@ -313,46 +286,44 @@ _nss_nisplus_getntohost_r (const struct ether_addr *addr, struct etherent *eth,
*errnop = EINVAL;
return NSS_STATUS_UNAVAIL;
}
-
- char buf[26 + tablename_len];
-
- 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);
-
- nis_result *result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS | USE_DGRAM,
- NULL, NULL);
-
- if (result == NULL)
- {
- *errnop = ENOMEM;
- return NSS_STATUS_TRYAGAIN;
- }
-
- if (__builtin_expect (niserr2nss (result->status) != NSS_STATUS_SUCCESS, 0))
+ else
{
- enum nss_status status = niserr2nss (result->status);
- nis_freeresult (result);
- return status;
- }
+ int parse_res;
+ nis_result *result;
+ char buf[255 + tablename_len];
- int parse_res = _nss_nisplus_parse_etherent (result, eth, buffer,
- buflen, errnop);
+ 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]);
- /* We do not need the lookup result anymore. */
- nis_freeresult (result);
+ result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL);
- if (__builtin_expect (parse_res < 1, 0))
- {
- if (parse_res == -1)
- return NSS_STATUS_TRYAGAIN;
+ 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;
+ }
- return NSS_STATUS_NOTFOUND;
+ parse_res = _nss_nisplus_parse_etherent (result, eth, buffer,
+ buflen, errnop);
+ if (parse_res < 1)
+ {
+ if (parse_res == -1)
+ {
+ nis_freeresult (result);
+ *errnop = ERANGE;
+ return NSS_STATUS_TRYAGAIN;
+ }
+ else
+ return NSS_STATUS_NOTFOUND;
+ }
+ return NSS_STATUS_SUCCESS;
}
-
- return NSS_STATUS_SUCCESS;
}
diff --git a/nis/nss_nisplus/nisplus-grp.c b/nis/nss_nisplus/nisplus-grp.c
index 7cc762fea9..daca94fc87 100644
--- a/nis/nss_nisplus/nisplus-grp.c
+++ b/nis/nss_nisplus/nisplus-grp.c
@@ -1,5 +1,4 @@
-/* Copyright (C) 1997, 2001, 2002, 2003, 2005, 2006
- Free Software Foundation, Inc.
+/* Copyright (C) 1997, 2001, 2002, 2003 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
@@ -18,7 +17,6 @@
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>
@@ -29,110 +27,68 @@
#include "nss-nisplus.h"
#include "nisplus-parser.h"
-#include <libnsl.h>
-#include <nis_intern.h>
-#include <nis_xdr.h>
-
__libc_lock_define_initialized (static, lock);
-/* Connection information. */
-static ib_request *ibreq;
-static directory_obj *dir;
-static dir_binding bptr;
-static char *tablepath;
-static char *tableptr;
-/* Cursor. */
-static netobj cursor;
-
+static nis_result *result;
+static unsigned long next_entry;
+static nis_name tablename_val;
+static u_long tablename_len;
-nis_name grp_tablename_val attribute_hidden;
-size_t grp_tablename_len attribute_hidden;
-
-enum nss_status
-_nss_grp_create_tablename (int *errnop)
+static enum nss_status
+_nss_create_tablename (int *errnop)
{
- if (grp_tablename_val == NULL)
+ if (tablename_val == NULL)
{
- const char *local_dir = nis_local_directory ();
- size_t local_dir_len = strlen (local_dir);
- static const char prefix[] = "group.org_dir.";
+ char buf [40 + strlen (nis_local_directory ())];
+ char *p;
- char *p = malloc (sizeof (prefix) + local_dir_len);
- if (p == NULL)
+ p = __stpcpy (buf, "group.org_dir.");
+ p = __stpcpy (p, nis_local_directory ());
+ tablename_val = __strdup (buf);
+ if (tablename_val == NULL)
{
*errnop = errno;
return NSS_STATUS_TRYAGAIN;
}
-
- memcpy (__stpcpy (p, prefix), local_dir, local_dir_len + 1);
-
- grp_tablename_len = sizeof (prefix) - 1 + local_dir_len;
-
- atomic_write_barrier ();
-
- if (atomic_compare_and_exchange_bool_acq (&grp_tablename_val, p, NULL))
- {
- /* Another thread already installed the value. */
- free (p);
- grp_tablename_len = strlen (grp_tablename_val);
- }
+ tablename_len = strlen (tablename_val);
}
-
return NSS_STATUS_SUCCESS;
}
-
-static void
-internal_endgrent (void)
-{
- __nisbind_destroy (&bptr);
- memset (&bptr, '\0', sizeof (bptr));
-
- nis_free_directory (dir);
- dir = NULL;
-
- nis_free_request (ibreq);
- ibreq = NULL;
-
- xdr_free ((xdrproc_t) xdr_netobj, (char *) &cursor);
- memset (&cursor, '\0', sizeof (cursor));
-
- free (tablepath);
- tableptr = tablepath = NULL;
-}
-
-
static enum nss_status
-internal_setgrent (int *errnop)
+internal_setgrent (void)
{
- enum nss_status status = NSS_STATUS_SUCCESS;
+ enum nss_status status;
+ int err;
- if (grp_tablename_val == NULL)
- status = _nss_grp_create_tablename (errnop);
+ if (result)
+ nis_freeresult (result);
+ result = NULL;
+ next_entry = 0;
- if (status == NSS_STATUS_SUCCESS)
- {
- ibreq = __create_ib_request (grp_tablename_val, 0);
- if (ibreq == NULL)
- {
- *errnop = errno;
- return NSS_STATUS_TRYAGAIN;
- }
+ if (tablename_val == NULL)
+ if (_nss_create_tablename (&err) != NSS_STATUS_SUCCESS)
+ return NSS_STATUS_UNAVAIL;
- nis_error retcode = __prepare_niscall (grp_tablename_val, &dir, &bptr, 0);
- if (retcode != NIS_SUCCESS)
+ result = nis_list (tablename_val, FOLLOW_LINKS | FOLLOW_PATH, NULL, NULL);
+ if (result == NULL)
+ {
+ status = NSS_STATUS_TRYAGAIN;
+ __set_errno (ENOMEM);
+ }
+ else
+ {
+ status = niserr2nss (result->status);
+ if (status != NSS_STATUS_SUCCESS)
{
- nis_free_request (ibreq);
- ibreq = NULL;
- status = niserr2nss (retcode);
+ nis_freeresult (result);
+ result = NULL;
}
}
-
return status;
}
-
enum nss_status
_nss_nisplus_setgrent (int stayopen)
{
@@ -140,133 +96,58 @@ _nss_nisplus_setgrent (int stayopen)
__libc_lock_lock (lock);
- internal_endgrent ();
-
- // XXX We need to be able to set errno. Pass in new parameter.
- int err;
- status = internal_setgrent (&err);
+ status = internal_setgrent ();
__libc_lock_unlock (lock);
return status;
}
-
enum nss_status
_nss_nisplus_endgrent (void)
{
__libc_lock_lock (lock);
- internal_endgrent ();
+ if (result)
+ nis_freeresult (result);
+ result = NULL;
__libc_lock_unlock (lock);
return NSS_STATUS_SUCCESS;
}
-
static enum nss_status
internal_nisplus_getgrent_r (struct group *gr, char *buffer, size_t buflen,
int *errnop)
{
- int parse_res = -1;
- enum nss_status retval = NSS_STATUS_SUCCESS;
+ int parse_res;
- /* Get the next entry until we found a correct one. */
- do
+ if (result == NULL)
{
- nis_error status;
- nis_result result;
- memset (&result, '\0', sizeof (result));
+ enum nss_status status;
- if (cursor.n_bytes == NULL)
- {
- if (ibreq == NULL)
- {
- retval = internal_setgrent (errnop);
- if (retval != NSS_STATUS_SUCCESS)
- return retval;
- }
-
- status = __do_niscall3 (&bptr, NIS_IBFIRST,
- (xdrproc_t) _xdr_ib_request,
- (caddr_t) ibreq,
- (xdrproc_t) _xdr_nis_result,
- (caddr_t) &result,
- 0, NULL);
- }
- else
- {
- ibreq->ibr_cookie.n_bytes = cursor.n_bytes;
- ibreq->ibr_cookie.n_len = cursor.n_len;
-
- status = __do_niscall3 (&bptr, NIS_IBNEXT,
- (xdrproc_t) _xdr_ib_request,
- (caddr_t) ibreq,
- (xdrproc_t) _xdr_nis_result,
- (caddr_t) &result,
- 0, NULL);
-
- ibreq->ibr_cookie.n_bytes = NULL;
- ibreq->ibr_cookie.n_len = 0;
- }
-
- if (status != NIS_SUCCESS)
- return niserr2nss (status);
+ status = internal_setgrent ();
+ if (result == NULL || status != NSS_STATUS_SUCCESS)
+ return status;
+ }
- if (NIS_RES_STATUS (&result) == NIS_NOTFOUND)
- {
- /* No more entries on this server. This means we have to go
- to the next server on the path. */
- status = __follow_path (&tablepath, &tableptr, ibreq, &bptr);
- if (status != NIS_SUCCESS)
- return niserr2nss (status);
-
- directory_obj *newdir = NULL;
- dir_binding newbptr;
- status = __prepare_niscall (ibreq->ibr_name, &newdir, &newbptr, 0);
- if (status != NIS_SUCCESS)
- return niserr2nss (status);
-
- nis_free_directory (dir);
- dir = newdir;
- __nisbind_destroy (&bptr);
- bptr = newbptr;
-
- xdr_free ((xdrproc_t) xdr_netobj, (char *) &result.cookie);
- result.cookie.n_bytes = NULL;
- result.cookie.n_len = 0;
- parse_res = 0;
- goto next;
- }
- else if (NIS_RES_STATUS (&result) != NIS_SUCCESS)
- return niserr2nss (NIS_RES_STATUS (&result));
+ /* Get the next entry until we found a correct one. */
+ do
+ {
+ if (next_entry >= result->objects.objects_len)
+ return NSS_STATUS_NOTFOUND;
- parse_res = _nss_nisplus_parse_grent (&result, gr,
+ parse_res = _nss_nisplus_parse_grent (result, next_entry, gr,
buffer, buflen, errnop);
- if (__builtin_expect (parse_res == -1, 0))
- {
- *errnop = ERANGE;
- retval = NSS_STATUS_TRYAGAIN;
- goto freeres;
- }
+ if (parse_res == -1)
+ return NSS_STATUS_TRYAGAIN;
- next:
- /* Free the old cursor. */
- xdr_free ((xdrproc_t) xdr_netobj, (char *) &cursor);
- /* Remember the new one. */
- cursor.n_bytes = result.cookie.n_bytes;
- cursor.n_len = result.cookie.n_len;
- /* Free the result structure. NB: we do not remove the cookie. */
- result.cookie.n_bytes = NULL;
- result.cookie.n_len = 0;
- freeres:
- xdr_free ((xdrproc_t) _xdr_nis_result, (char *) &result);
- memset (&result, '\0', sizeof (result));
+ ++next_entry;
}
while (!parse_res);
- return retval;
+ return NSS_STATUS_SUCCESS;
}
enum nss_status
@@ -290,9 +171,9 @@ _nss_nisplus_getgrnam_r (const char *name, struct group *gr,
{
int parse_res;
- if (grp_tablename_val == NULL)
+ if (tablename_val == NULL)
{
- enum nss_status status = _nss_grp_create_tablename (errnop);
+ enum nss_status status = _nss_create_tablename (errnop);
if (status != NSS_STATUS_SUCCESS)
return status;
@@ -303,101 +184,102 @@ _nss_nisplus_getgrnam_r (const char *name, struct group *gr,
*errnop = EINVAL;
return NSS_STATUS_NOTFOUND;
}
-
- nis_result *result;
- char buf[strlen (name) + 9 + grp_tablename_len];
- int olderr = errno;
-
- snprintf (buf, sizeof (buf), "[name=%s],%s", name, grp_tablename_val);
-
- result = nis_list (buf, FOLLOW_LINKS | FOLLOW_PATH, NULL, NULL);
-
- if (result == NULL)
+ else
{
- *errnop = ENOMEM;
- return NSS_STATUS_TRYAGAIN;
- }
+ nis_result *result;
+ char buf[strlen (name) + 24 + tablename_len];
+ int olderr = errno;
- if (__builtin_expect (niserr2nss (result->status) != NSS_STATUS_SUCCESS, 0))
- {
- enum nss_status status = niserr2nss (result->status);
+ sprintf (buf, "[name=%s],%s", name, tablename_val);
- nis_freeresult (result);
- return status;
- }
+ result = nis_list (buf, FOLLOW_LINKS | FOLLOW_PATH, NULL, NULL);
- parse_res = _nss_nisplus_parse_grent (result, gr, buffer, buflen, errnop);
- nis_freeresult (result);
- if (__builtin_expect (parse_res < 1, 0))
- {
- if (parse_res == -1)
+ if (result == NULL)
{
- *errnop = ERANGE;
+ *errnop = ENOMEM;
return NSS_STATUS_TRYAGAIN;
}
- else
+ if (niserr2nss (result->status) != NSS_STATUS_SUCCESS)
{
- __set_errno (olderr);
- return NSS_STATUS_NOTFOUND;
+ enum nss_status status = niserr2nss (result->status);
+
+ nis_freeresult (result);
+ return status;
}
- }
- return NSS_STATUS_SUCCESS;
+ parse_res = _nss_nisplus_parse_grent (result, 0, gr, 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;
+ }
}
enum nss_status
_nss_nisplus_getgrgid_r (const gid_t gid, struct group *gr,
char *buffer, size_t buflen, int *errnop)
{
- if (grp_tablename_val == NULL)
+ if (tablename_val == NULL)
{
- enum nss_status status = _nss_grp_create_tablename (errnop);
+ enum nss_status status = _nss_create_tablename (errnop);
if (status != NSS_STATUS_SUCCESS)
return status;
}
- int parse_res;
- nis_result *result;
- char buf[8 + 3 * sizeof (unsigned long int) + grp_tablename_len];
- int olderr = errno;
-
- snprintf (buf, sizeof (buf), "[gid=%lu],%s",
- (unsigned long int) gid, grp_tablename_val);
+ {
+ int parse_res;
+ nis_result *result;
+ char buf[36 + tablename_len];
+ int olderr = errno;
- result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL);
+ sprintf (buf, "[gid=%lu],%s", (unsigned long int) gid, tablename_val);
- if (result == NULL)
- {
- *errnop = ENOMEM;
- return NSS_STATUS_TRYAGAIN;
- }
+ result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL);
- if (__builtin_expect (niserr2nss (result->status) != NSS_STATUS_SUCCESS, 0))
- {
- enum nss_status status = niserr2nss (result->status);
+ if (result == NULL)
+ {
+ *errnop = ENOMEM;
+ return NSS_STATUS_TRYAGAIN;
+ }
+ if (niserr2nss (result->status) != NSS_STATUS_SUCCESS)
+ {
+ enum nss_status status = niserr2nss (result->status);
- __set_errno (olderr);
-
- nis_freeresult (result);
- return status;
- }
+ __set_errno (olderr);
- parse_res = _nss_nisplus_parse_grent (result, 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;
+ 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;
+ }
}
diff --git a/nis/nss_nisplus/nisplus-hosts.c b/nis/nss_nisplus/nisplus-hosts.c
index f5f0ac96da..540469894e 100644
--- a/nis/nss_nisplus/nisplus-hosts.c
+++ b/nis/nss_nisplus/nisplus-hosts.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997-2002, 2003, 2005, 2006 Free Software Foundation, Inc.
+/* Copyright (C) 1997-2002, 2003 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@suse.de>, 1997.
@@ -17,16 +17,15 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
-#include <atomic.h>
-#include <ctype.h>
-#include <errno.h>
-#include <netdb.h>
#include <nss.h>
+#include <netdb.h>
+#include <errno.h>
+#include <ctype.h>
#include <string.h>
-#include <arpa/inet.h>
#include <netinet/in.h>
-#include <rpcsvc/nis.h>
+#include <arpa/inet.h>
#include <bits/libc-lock.h>
+#include <rpcsvc/nis.h>
#include "nss-nisplus.h"
@@ -36,16 +35,15 @@ static nis_result *result;
static nis_name tablename_val;
static u_long tablename_len;
-#define NISENTRYVAL(idx, col, res) \
- (NIS_RES_OBJECT (res)[idx].EN_data.en_cols.en_cols_val[col].ec_value.ec_value_val)
+#define NISENTRYVAL(idx,col,res) \
+ ((res)->objects.objects_val[(idx)].EN_data.en_cols.en_cols_val[(col)].ec_value.ec_value_val)
-#define NISENTRYLEN(idx, col, res) \
- (NIS_RES_OBJECT (res)[idx].EN_data.en_cols.en_cols_val[col].ec_value.ec_value_len)
+#define NISENTRYLEN(idx,col,res) \
+ ((res)->objects.objects_val[(idx)].EN_data.en_cols.en_cols_val[(col)].ec_value.ec_value_len)
/* Get implementation for some internal functions. */
#include <resolv/mapv4v6addr.h>
-
static int
_nss_nisplus_parse_hostent (nis_result *result, int af, struct hostent *host,
char *buffer, size_t buflen, int *errnop,
@@ -54,26 +52,27 @@ _nss_nisplus_parse_hostent (nis_result *result, int af, struct hostent *host,
unsigned int i;
char *first_unused = buffer;
size_t room_left = buflen;
+ char *data, *p, *line;
if (result == NULL)
return 0;
if ((result->status != NIS_SUCCESS && result->status != NIS_S_SUCCESS) ||
- __type_of (NIS_RES_OBJECT (result)) != NIS_ENTRY_OBJ ||
- strcmp(NIS_RES_OBJECT (result)[0].EN_data.en_type, "hosts_tbl") != 0 ||
- NIS_RES_OBJECT (result)[0].EN_data.en_cols.en_cols_len < 4)
+ __type_of (result->objects.objects_val) != NIS_ENTRY_OBJ ||
+ strcmp(result->objects.objects_val[0].EN_data.en_type,
+ "hosts_tbl") != 0 ||
+ result->objects.objects_val[0].EN_data.en_cols.en_cols_len < 4)
return 0;
- char *data = first_unused;
-
- if (room_left < (af == AF_INET6 || (flags & AI_V4MAPPED) != 0
- ? IN6ADDRSZ : INADDRSZ))
+ if (room_left < NISENTRYLEN (0, 2, result) + 1)
{
no_more_room:
*errnop = ERANGE;
return -1;
}
+ data = first_unused;
+
/* Parse address. */
if (af == AF_INET && inet_pton (af, NISENTRYVAL (0, 2, result), data) > 0)
{
@@ -99,53 +98,51 @@ _nss_nisplus_parse_hostent (nis_result *result, int af, struct hostent *host,
/* Illegal address: ignore line. */
return 0;
- first_unused += host->h_length;
- room_left -= host->h_length;
+ first_unused+=host->h_length;
+ room_left-=host->h_length;
if (NISENTRYLEN (0, 0, result) + 1 > room_left)
goto no_more_room;
+ p = __stpncpy (first_unused, NISENTRYVAL (0, 0, result),
+ NISENTRYLEN (0, 0, result));
+ *p = '\0';
+ room_left -= (NISENTRYLEN (0, 0, result) + 1);
host->h_name = first_unused;
- first_unused = __stpncpy (first_unused, NISENTRYVAL (0, 0, result),
- NISENTRYLEN (0, 0, result));
- *first_unused++ = '\0';
- room_left -= NISENTRYLEN (0, 0, result) + 1;
-
- /* XXX Rewrite at some point to allocate the array first and then
- copy the strings. It wasteful to first concatenate the strings
- to just split them again later. */
- char *line = first_unused;
- for (i = 0; i < NIS_RES_NUMOBJ (result); ++i)
+ first_unused += NISENTRYLEN (0, 0, result) +1;
+ p = first_unused;
+
+ line = p;
+ for (i = 0; i < result->objects.objects_len; ++i)
{
if (strcmp (NISENTRYVAL (i, 1, result), host->h_name) != 0)
{
if (NISENTRYLEN (i, 1, result) + 2 > room_left)
goto no_more_room;
- *first_unused++ = ' ';
- first_unused = __stpncpy (first_unused, NISENTRYVAL (i, 1, result),
- NISENTRYLEN (i, 1, result));
- *first_unused = '\0';
- room_left -= NISENTRYLEN (i, 1, result) + 1;
+ *p++ = ' ';
+ p = __stpncpy (p, NISENTRYVAL (i, 1, result),
+ NISENTRYLEN (i, 1, result));
+ *p = '\0';
+ room_left -= (NISENTRYLEN (i, 1, result) + 1);
}
}
- *first_unused++ = '\0';
+ *p++ = '\0';
+ first_unused = p;
/* Adjust the pointer so it is aligned for
storing pointers. */
- size_t adjust = ((__alignof__ (char *)
- - (first_unused - (char *) 0) % __alignof__ (char *))
- % __alignof__ (char *));
- if (room_left < adjust + 3 * sizeof (char *))
- goto no_more_room;
- first_unused += adjust;
- room_left -= adjust;
+ first_unused += __alignof__ (char *) - 1;
+ first_unused -= ((first_unused - (char *) 0) % __alignof__ (char *));
host->h_addr_list = (char **) first_unused;
+ if (room_left < 2 * sizeof (char *))
+ goto no_more_room;
- room_left -= 3 * sizeof (char *);
+ room_left -= (2 * sizeof (char *));
host->h_addr_list[0] = data;
host->h_addr_list[1] = NULL;
host->h_aliases = &host->h_addr_list[2];
+ host->h_aliases[0] = NULL;
i = 0;
while (*line != '\0')
@@ -161,46 +158,41 @@ _nss_nisplus_parse_hostent (nis_result *result, int af, struct hostent *host,
goto no_more_room;
room_left -= sizeof (char *);
- host->h_aliases[i++] = line;
+ host->h_aliases[i] = line;
while (*line != '\0' && *line != ' ')
++line;
if (*line == ' ')
- *line++ = '\0';
+ {
+ *line = '\0';
+ ++line;
+ ++i;
+ }
+ else
+ host->h_aliases[i+1] = NULL;
}
-
- host->h_aliases[i] = NULL;
-
return 1;
}
-
static enum nss_status
_nss_create_tablename (int *errnop)
{
if (tablename_val == NULL)
{
- const char *local_dir = nis_local_directory ();
- size_t local_dir_len = strlen (local_dir);
- static const char prefix[] = "hosts.org_dir.";
+ char buf [40 + strlen (nis_local_directory ())];
+ char *p;
- char *p = malloc (sizeof (prefix) + local_dir_len);
- if (p == NULL)
+ p = __stpcpy (buf, "hosts.org_dir.");
+ p = __stpcpy (p, nis_local_directory ());
+ tablename_val = __strdup (buf);
+ if (tablename_val == NULL)
{
*errnop = errno;
return NSS_STATUS_TRYAGAIN;
}
-
- memcpy (__stpcpy (p, prefix), local_dir, local_dir_len + 1);
-
- tablename_len = sizeof (prefix) - 1 + local_dir_len;
-
- atomic_write_barrier ();
-
- tablename_val = p;
+ tablename_len = strlen (tablename_val);
}
-
return NSS_STATUS_SUCCESS;
}
@@ -212,11 +204,9 @@ _nss_nisplus_sethostent (int stayopen)
__libc_lock_lock (lock);
- if (result != NULL)
- {
- nis_freeresult (result);
- result = NULL;
- }
+ if (result)
+ nis_freeresult (result);
+ result = NULL;
if (tablename_val == NULL)
status = _nss_create_tablename (&err);
@@ -231,11 +221,9 @@ _nss_nisplus_endhostent (void)
{
__libc_lock_lock (lock);
- if (result != NULL)
- {
- nis_freeresult (result);
- result = NULL;
- }
+ if (result)
+ nis_freeresult (result);
+ result = NULL;
__libc_lock_unlock (lock);
@@ -265,11 +253,6 @@ internal_nisplus_gethostent_r (struct hostent *host, char *buffer,
}
result = nis_first_entry (tablename_val);
- if (result == NULL)
- {
- *errnop = errno;
- return NSS_STATUS_TRYAGAIN;
- }
if (niserr2nss (result->status) != NSS_STATUS_SUCCESS)
{
enum nss_status retval = niserr2nss (result->status);
@@ -284,13 +267,11 @@ internal_nisplus_gethostent_r (struct hostent *host, char *buffer,
}
else
{
+ nis_result *res2;
+
saved_res = result;
- result = nis_next_entry (tablename_val, &result->cookie);
- if (result == NULL)
- {
- *errnop = errno;
- return NSS_STATUS_TRYAGAIN;
- }
+ res2 = nis_next_entry(tablename_val, &result->cookie);
+ result = res2;
if (niserr2nss (result->status) != NSS_STATUS_SUCCESS)
{
enum nss_status retval= niserr2nss (result->status);
@@ -354,12 +335,8 @@ 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;
@@ -373,81 +350,75 @@ 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;
- nis_result *result;
- char buf[strlen (name) + 10 + 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);
- /* 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 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);
- 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
+ nis_freeresult (result);
+ result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL);
+ }
+
+ if (result == NULL)
{
- /* 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);
+ *errnop = 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;
+ }
+
+ 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 (result == NULL)
- {
- *errnop = ENOMEM;
- return NSS_STATUS_TRYAGAIN;
- }
+ if (parse_res > 0)
+ return NSS_STATUS_SUCCESS;
- retval = niserr2nss (result->status);
- if (__builtin_expect (retval != NSS_STATUS_SUCCESS, 0))
- {
- if (retval == NSS_STATUS_TRYAGAIN)
+ *herrnop = NETDB_INTERNAL;
+ if (parse_res == -1)
{
- *errnop = errno;
- *herrnop = NETDB_INTERNAL;
+ *errnop = ERANGE;
+ return NSS_STATUS_TRYAGAIN;
}
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);
-
- 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;
+ }
}
-
- __set_errno (olderr);
- return NSS_STATUS_NOTFOUND;
}
enum nss_status
@@ -460,6 +431,17 @@ _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,
@@ -487,63 +469,62 @@ _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;
-
- char buf[24 + tablename_len];
- int retval, parse_res;
- int olderr = errno;
-
- 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 (result == NULL)
+ else
{
- __set_errno (ENOMEM);
- return NSS_STATUS_TRYAGAIN;
- }
+ nis_result *result;
+ char buf[255 + tablename_len];
+ int retval, parse_res;
+ int olderr = errno;
- retval = niserr2nss (result->status);
- if (__builtin_expect (retval != NSS_STATUS_SUCCESS, 0))
- {
- if (retval == NSS_STATUS_TRYAGAIN)
+ 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)
{
- *errnop = errno;
- *herrnop = NETDB_INTERNAL;
+ __set_errno (ENOMEM);
+ return NSS_STATUS_TRYAGAIN;
}
- else
- __set_errno (olderr);
- nis_freeresult (result);
- return retval;
- }
+ 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,
- ((_res.options & RES_USE_INET6)
- ? AI_V4MAPPED : 0));
- nis_freeresult (result);
+ 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;
+ if (parse_res > 0)
+ return NSS_STATUS_SUCCESS;
- *herrnop = NETDB_INTERNAL;
- if (parse_res == -1)
- {
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
+ *herrnop = NETDB_INTERNAL;
+ 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;
}
diff --git a/nis/nss_nisplus/nisplus-initgroups.c b/nis/nss_nisplus/nisplus-initgroups.c
deleted file mode 100644
index 6588ec2533..0000000000
--- a/nis/nss_nisplus/nisplus-initgroups.c
+++ /dev/null
@@ -1,150 +0,0 @@
-/* Copyright (C) 1997, 2001, 2002, 2003, 2005, 2006
- Free Software Foundation, Inc.
- This file is part of the GNU C Library.
-
- The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- The GNU C Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with the GNU C Library; if not, write to the Free
- 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>
-#include <errno.h>
-#include <string.h>
-#include <bits/libc-lock.h>
-#include <rpcsvc/nis.h>
-
-#include "nss-nisplus.h"
-#include "nisplus-parser.h"
-#include <libnsl.h>
-#include <nis_intern.h>
-#include <nis_xdr.h>
-
-#define NISOBJVAL(col, obj) \
- ((obj)->EN_data.en_cols.en_cols_val[col].ec_value.ec_value_val)
-
-#define NISOBJLEN(col, obj) \
- ((obj)->EN_data.en_cols.en_cols_val[col].ec_value.ec_value_len)
-
-extern nis_name grp_tablename_val attribute_hidden;
-extern size_t grp_tablename_len attribute_hidden;
-extern enum nss_status _nss_grp_create_tablename (int *errnop);
-
-
-enum nss_status
-_nss_nisplus_initgroups_dyn (const char *user, gid_t group, long int *start,
- long int *size, gid_t **groupsp, long int limit,
- int *errnop)
-{
- if (grp_tablename_val == NULL)
- {
- enum nss_status status = _nss_grp_create_tablename (errnop);
-
- if (status != NSS_STATUS_SUCCESS)
- return status;
- }
-
- nis_result *result;
- char buf[strlen (user) + 12 + grp_tablename_len];
-
- snprintf (buf, sizeof (buf), "[members=%s],%s", user, grp_tablename_val);
-
- result = nis_list (buf, FOLLOW_LINKS | FOLLOW_PATH | ALL_RESULTS, 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);
-
- nis_freeresult (result);
- return status;
- }
-
- if (NIS_RES_NUMOBJ (result) == 0)
- {
- errout:
- nis_freeresult (result);
- return NSS_STATUS_NOTFOUND;
- }
-
- gid_t *groups = *groupsp;
- nis_object *obj = NIS_RES_OBJECT (result);
- for (unsigned int cnt = 0; cnt < NIS_RES_NUMOBJ (result); ++cnt, ++obj)
- {
- if (__type_of (obj) != NIS_ENTRY_OBJ
- || strcmp (obj->EN_data.en_type, "group_tbl") != 0
- || obj->EN_data.en_cols.en_cols_len < 4)
- continue;
-
- char *numstr = NISOBJVAL (2, obj);
- size_t len = NISOBJLEN (2, obj);
- if (len == 0 || numstr[0] == '\0')
- continue;
-
- gid_t gid;
- char *endp;
- if (__builtin_expect (numstr[len - 1] != '\0', 0))
- {
- char numstrbuf[len + 1];
- memcpy (numstrbuf, numstr, len);
- numstrbuf[len] = '\0';
- gid = strtoul (numstrbuf, &endp, 10);
- if (*endp)
- continue;
- }
- else
- {
- gid = strtoul (numstr, &endp, 10);
- if (*endp)
- continue;
- }
-
- if (gid == group)
- continue;
-
- /* Insert this group. */
- if (*start == *size)
- {
- /* Need a bigger buffer. */
- long int newsize;
-
- if (limit > 0 && *size == limit)
- /* We reached the maximum. */
- break;
-
- if (limit <= 0)
- newsize = 2 * *size;
- else
- newsize = MIN (limit, 2 * *size);
-
- gid_t *newgroups = realloc (groups, newsize * sizeof (*groups));
- if (newgroups == NULL)
- goto errout;
- *groupsp = groups = newgroups;
- *size = newsize;
- }
-
- groups[*start] = gid;
- *start += 1;
- }
-
- nis_freeresult (result);
- return NSS_STATUS_SUCCESS;
-}
diff --git a/nis/nss_nisplus/nisplus-netgrp.c b/nis/nss_nisplus/nisplus-netgrp.c
index 24303b1474..607bc2c1ca 100644
--- a/nis/nss_nisplus/nisplus-netgrp.c
+++ b/nis/nss_nisplus/nisplus-netgrp.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
+/* Copyright (C) 1997, 2003, 2004 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
@@ -27,11 +27,11 @@
#include "nss-nisplus.h"
-#define NISENTRYVAL(idx, col, res) \
- (NIS_RES_OBJECT (res)[idx].EN_data.en_cols.en_cols_val[col].ec_value.ec_value_val)
+#define NISENTRYVAL(idx,col,res) \
+ ((res)->objects.objects_val[(idx)].EN_data.en_cols.en_cols_val[(col)].ec_value.ec_value_val)
-#define NISENTRYLEN(idx, col, res) \
- (NIS_RES_OBJECT (res)[idx].EN_data.en_cols.en_cols_val[col].ec_value.ec_value_len)
+#define NISENTRYLEN(idx,col,res) \
+ ((res)->objects.objects_val[(idx)].EN_data.en_cols.en_cols_val[(col)].ec_value.ec_value_len)
enum nss_status
_nss_nisplus_getnetgrent_r (struct __netgrent *result, char *buffer,
@@ -141,23 +141,29 @@ _nss_nisplus_getnetgrent_r (struct __netgrent *result, char *buffer,
static void
internal_endnetgrent (struct __netgrent *netgrp)
{
- nis_freeresult ((nis_result *) netgrp->data);
- netgrp->data = NULL;
- netgrp->data_size = 0;
- netgrp->position = 0;
+ if (netgrp->data != NULL)
+ {
+ nis_freeresult ((nis_result *) netgrp->data);
+ netgrp->data = NULL;
+ netgrp->data_size = 0;
+ netgrp->position = 0;
+ }
}
enum nss_status
_nss_nisplus_setnetgrent (const char *group, struct __netgrent *netgrp)
{
- char buf[strlen (group) + 25];
+ enum nss_status status;
+ char buf[strlen (group) + 30];
if (group == NULL || group[0] == '\0')
return NSS_STATUS_UNAVAIL;
- enum nss_status status = NSS_STATUS_SUCCESS;
+ status = NSS_STATUS_SUCCESS;
+
+ internal_endnetgrent (netgrp);
- snprintf (buf, sizeof (buf), "[name=%s],netgroup.org_dir", group);
+ sprintf (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 1cf652f071..422b02b82a 100644
--- a/nis/nss_nisplus/nisplus-network.c
+++ b/nis/nss_nisplus/nisplus-network.c
@@ -1,5 +1,4 @@
-/* Copyright (C) 1997,1998,2000-2003,2005,2006,2007
- Free Software Foundation, Inc.
+/* Copyright (C) 1997,1998,2000,2001,2002,2003 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
@@ -18,16 +17,15 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
-#include <atomic.h>
-#include <ctype.h>
-#include <errno.h>
-#include <netdb.h>
#include <nss.h>
+#include <netdb.h>
+#include <errno.h>
+#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <arpa/inet.h>
-#include <rpcsvc/nis.h>
#include <bits/libc-lock.h>
+#include <rpcsvc/nis.h>
#include "nss-nisplus.h"
@@ -37,31 +35,33 @@ static nis_result *result;
static nis_name tablename_val;
static u_long tablename_len;
-#define NISENTRYVAL(idx, col, res) \
- (NIS_RES_OBJECT (res)[idx].EN_data.en_cols.en_cols_val[col].ec_value.ec_value_val)
+#define NISENTRYVAL(idx,col,res) \
+ ((res)->objects.objects_val[(idx)].EN_data.en_cols.en_cols_val[(col)].ec_value.ec_value_val)
-#define NISENTRYLEN(idx, col, res) \
- (NIS_RES_OBJECT (res)[idx].EN_data.en_cols.en_cols_val[col].ec_value.ec_value_len)
+#define NISENTRYLEN(idx,col,res) \
+ ((res)->objects.objects_val[(idx)].EN_data.en_cols.en_cols_val[(col)].ec_value.ec_value_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;
if ((result->status != NIS_SUCCESS && result->status != NIS_S_SUCCESS)
- || __type_of (NIS_RES_OBJECT (result)) != NIS_ENTRY_OBJ
- || strcmp (NIS_RES_OBJECT (result)[0].EN_data.en_type,
+ || __type_of (result->objects.objects_val) != NIS_ENTRY_OBJ
+ || strcmp (result->objects.objects_val[0].EN_data.en_type,
"networks_tbl") != 0
- || NIS_RES_OBJECT (result)[0].EN_data.en_cols.en_cols_len < 3)
+ || 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,56 +69,50 @@ _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;
- size_t len = strlen (first_unused) + 1;
- room_left -= len;
- first_unused += len;
-
+ room_left -= (strlen (first_unused) +1);
+ first_unused += strlen (first_unused) +1;
network->n_addrtype = 0;
network->n_net = inet_network (NISENTRYVAL (0, 2, result));
+ p = first_unused;
- /* XXX Rewrite at some point to allocate the array first and then
- copy the strings. It wasteful to first concatenate the strings
- to just split them again later. */
- char *line = first_unused;
- for (unsigned int i = 0; i < NIS_RES_NUMOBJ (result); ++i)
+ line = p;
+ for (i = 0; i < result->objects.objects_len; ++i)
{
if (strcmp (NISENTRYVAL (i, 1, result), network->n_name) != 0)
{
if (NISENTRYLEN (i, 1, result) + 2 > room_left)
goto no_more_room;
- *first_unused++ = ' ';
- first_unused = __stpncpy (first_unused, NISENTRYVAL (i, 1, result),
- NISENTRYLEN (i, 1, result));
+ *p++ = ' ';
+ p = __stpncpy (p, NISENTRYVAL (i, 1, result),
+ NISENTRYLEN (i, 1, result));
+ *p = '\0';
room_left -= (NISENTRYLEN (i, 1, result) + 1);
}
}
- *first_unused++ = '\0';
+ *p++ = '\0';
+ first_unused = p;
/* Adjust the pointer so it is aligned for
storing pointers. */
- size_t adjust = ((__alignof__ (char *)
- - (first_unused - (char *) 0) % __alignof__ (char *))
- % __alignof__ (char *));
- if (room_left < adjust + sizeof (char *))
- goto no_more_room;
- first_unused += adjust;
- room_left -= adjust;
+ first_unused += __alignof__ (char *) - 1;
+ first_unused -= ((first_unused - (char *) 0) % __alignof__ (char *));
network->n_aliases = (char **) first_unused;
+ if (room_left < 2 * sizeof (char *))
+ goto no_more_room;
+ room_left -= (2 * sizeof (char *));
+ network->n_aliases[0] = NULL;
- /* For the terminating NULL pointer. */
- room_left -= sizeof (char *);
-
- unsigned int i = 0;
+ i = 0;
while (*line != '\0')
{
/* Skip leading blanks. */
while (isspace (*line))
- ++line;
+ line++;
if (*line == '\0')
break;
@@ -127,45 +121,42 @@ _nss_nisplus_parse_netent (nis_result *result, struct netent *network,
goto no_more_room;
room_left -= sizeof (char *);
- network->n_aliases[i++] = line;
+ network->n_aliases[i] = line;
while (*line != '\0' && *line != ' ')
++line;
if (*line == ' ')
- *line++ = '\0';
+ {
+ *line = '\0';
+ ++line;
+ ++i;
+ }
+ else
+ network->n_aliases[i+1] = NULL;
}
- network->n_aliases[i] = NULL;
return 1;
}
-
static enum nss_status
_nss_create_tablename (int *errnop)
{
if (tablename_val == NULL)
{
- const char *local_dir = nis_local_directory ();
- size_t local_dir_len = strlen (local_dir);
- static const char prefix[] = "networks.org_dir.";
+ char buf [40 + strlen (nis_local_directory ())];
+ char *p;
- char *p = malloc (sizeof (prefix) + local_dir_len);
- if (p == NULL)
+ p = __stpcpy (buf, "networks.org_dir.");
+ p = __stpcpy (p, nis_local_directory ());
+ tablename_val = __strdup (buf);
+ if (tablename_val == NULL)
{
*errnop = errno;
return NSS_STATUS_TRYAGAIN;
}
-
- memcpy (__stpcpy (p, prefix), local_dir, local_dir_len + 1);
-
- tablename_len = sizeof (prefix) - 1 + local_dir_len;
-
- atomic_write_barrier ();
-
- tablename_val = p;
+ tablename_len = strlen (tablename_val);
}
-
return NSS_STATUS_SUCCESS;
}
@@ -173,20 +164,16 @@ enum nss_status
_nss_nisplus_setnetent (int stayopen)
{
enum nss_status status = NSS_STATUS_SUCCESS;
+ int err;
__libc_lock_lock (lock);
- if (result != NULL)
- {
- nis_freeresult (result);
- result = NULL;
- }
+ if (result)
+ nis_freeresult (result);
+ result = NULL;
if (tablename_val == NULL)
- {
- int err;
- status = _nss_create_tablename (&err);
- }
+ status = _nss_create_tablename (&err);
__libc_lock_unlock (lock);
@@ -198,11 +185,9 @@ _nss_nisplus_endnetent (void)
{
__libc_lock_lock (lock);
- if (result != NULL)
- {
- nis_freeresult (result);
- result = NULL;
- }
+ if (result)
+ nis_freeresult (result);
+ result = NULL;
__libc_lock_unlock (lock);
@@ -233,14 +218,11 @@ internal_nisplus_getnetent_r (struct netent *network, char *buffer,
}
result = nis_first_entry (tablename_val);
- if (result == NULL)
- {
- *errnop = errno;
- return NSS_STATUS_TRYAGAIN;
- }
if (niserr2nss (result->status) != NSS_STATUS_SUCCESS)
{
- int retval = niserr2nss (result->status);
+ int retval;
+
+ retval = niserr2nss (result->status);
nis_freeresult (result);
result = NULL;
if (retval == NSS_STATUS_TRYAGAIN)
@@ -255,16 +237,16 @@ internal_nisplus_getnetent_r (struct netent *network, char *buffer,
}
else
{
+ nis_result *res;
+
+ res = nis_next_entry (tablename_val, &result->cookie);
saved_res = result;
- result = nis_next_entry (tablename_val, &result->cookie);
- if (result == NULL)
- {
- *errnop = errno;
- return NSS_STATUS_TRYAGAIN;
- }
+ result = res;
if (niserr2nss (result->status) != NSS_STATUS_SUCCESS)
{
- int retval = niserr2nss (result->status);
+ int retval;
+
+ retval = niserr2nss (result->status);
nis_freeresult (result);
result = saved_res;
if (retval == NSS_STATUS_TRYAGAIN)
@@ -284,8 +266,7 @@ internal_nisplus_getnetent_r (struct netent *network, char *buffer,
return NSS_STATUS_TRYAGAIN;
}
- }
- while (!parse_res);
+ } while (!parse_res);
return NSS_STATUS_SUCCESS;
}
@@ -315,12 +296,8 @@ _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;
}
@@ -331,83 +308,76 @@ _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;
- nis_result *result;
- char buf[strlen (name) + 10 + 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);
- /* 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 | USE_DGRAM, 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[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);
+ }
- 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 (result == NULL)
+ {
+ __set_errno (ENOMEM);
+ return NSS_STATUS_TRYAGAIN;
+ }
+ retval = niserr2nss (result->status);
+ if (retval != NSS_STATUS_SUCCESS)
{
- /* 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 (retval == NSS_STATUS_TRYAGAIN)
+ {
+ *errnop = errno;
+ *herrnop = NETDB_INTERNAL;
+ }
+ else
+ __set_errno (olderr);
+ nis_freeresult (result);
+ return retval;
}
+ parse_res = _nss_nisplus_parse_netent (result, network, buffer, buflen,
+ errnop);
+
nis_freeresult (result);
- result = nis_list (bufptr, FOLLOW_LINKS | FOLLOW_PATH | USE_DGRAM,
- NULL, NULL);
- }
- if (result == NULL)
- {
- __set_errno (ENOMEM);
- return NSS_STATUS_TRYAGAIN;
- }
+ if (parse_res > 0)
+ return NSS_STATUS_SUCCESS;
- retval = niserr2nss (result->status);
- if (__builtin_expect (retval != NSS_STATUS_SUCCESS, 0))
- {
- if (retval == NSS_STATUS_TRYAGAIN)
+ *herrnop = NETDB_INTERNAL;
+ if (parse_res == -1)
{
- *errnop = errno;
- *herrnop = NETDB_INTERNAL;
+ *errnop = ERANGE;
+ return NSS_STATUS_TRYAGAIN;
}
else
- __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;
+ }
}
-
- __set_errno (olderr);
- return NSS_STATUS_NOTFOUND;
}
/* XXX type is ignored, SUN's NIS+ table doesn't support it */
@@ -418,48 +388,48 @@ _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;
}
{
- char buf[27 + tablename_len];
- char buf2[18];
+ int parse_res, retval;
+ nis_result *result;
+ char buf[1024 + tablename_len];
+ struct in_addr in;
+ char buf2[256];
+ int b2len;
int olderr = errno;
- struct in_addr in = inet_makeaddr (addr, 0);
+ in = inet_makeaddr (addr, 0);
strcpy (buf2, inet_ntoa (in));
- size_t b2len = strlen (buf2);
+ b2len = strlen (buf2);
while (1)
{
- snprintf (buf, sizeof (buf), "[addr=%s],%s", buf2, tablename_val);
- nis_result *result = nis_list (buf, EXPAND_NAME | USE_DGRAM,
- NULL, NULL);
+ sprintf (buf, "[addr=%s],%s", buf2, tablename_val);
+ result = nis_list (buf, EXPAND_NAME, NULL, NULL);
if (result == NULL)
{
__set_errno (ENOMEM);
return NSS_STATUS_TRYAGAIN;
}
- enum nss_status retval = niserr2nss (result->status);
- if (__builtin_expect (retval != NSS_STATUS_SUCCESS, 0))
+ retval = niserr2nss (result->status);
+ if (retval != NSS_STATUS_SUCCESS)
{
- if (b2len > 2 && buf2[b2len - 2] == '.' && buf2[b2len - 1] == '0')
+ if (buf2[b2len -2] == '.' && buf2[b2len -1] == '0')
{
/* Try again, but with trailing dot(s)
removed (one by one) */
buf2[b2len - 2] = '\0';
b2len -= 2;
- nis_freeresult (result);
continue;
}
+ else
+ return NSS_STATUS_NOTFOUND;
if (retval == NSS_STATUS_TRYAGAIN)
{
@@ -472,8 +442,8 @@ _nss_nisplus_getnetbyaddr_r (uint32_t addr, const int type,
return retval;
}
- int parse_res = _nss_nisplus_parse_netent (result, network, buffer,
- buflen, errnop);
+ parse_res = _nss_nisplus_parse_netent (result, network, buffer,
+ buflen, errnop);
nis_freeresult (result);
diff --git a/nis/nss_nisplus/nisplus-parser.c b/nis/nss_nisplus/nisplus-parser.c
index 1e1a343d52..b61733a628 100644
--- a/nis/nss_nisplus/nisplus-parser.c
+++ b/nis/nss_nisplus/nisplus-parser.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997, 1999, 2004, 2006 Free Software Foundation, Inc.
+/* Copyright (C) 1997, 1999, 2004 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
@@ -25,36 +25,33 @@
#include "nisplus-parser.h"
-#define NISENTRYVAL(idx, col, res) \
- (NIS_RES_OBJECT (res)[idx].EN_data.en_cols.en_cols_val[col].ec_value.ec_value_val)
+#define NISENTRYVAL(idx,col,res) \
+ ((res)->objects.objects_val[(idx)].EN_data.en_cols.en_cols_val[(col)].ec_value.ec_value_val)
-#define NISENTRYLEN(idx, col, res) \
- (NIS_RES_OBJECT (res)[idx].EN_data.en_cols.en_cols_val[col].ec_value.ec_value_len)
-
-#define NISOBJVAL(col, obj) \
- ((obj)->EN_data.en_cols.en_cols_val[col].ec_value.ec_value_val)
-
-#define NISOBJLEN(col, obj) \
- ((obj)->EN_data.en_cols.en_cols_val[col].ec_value.ec_value_len)
+#define NISENTRYLEN(idx,col,res) \
+ ((res)->objects.objects_val[(idx)].EN_data.en_cols.en_cols_val[(col)].ec_value.ec_value_len)
int
_nss_nisplus_parse_pwent (nis_result *result, struct passwd *pw,
char *buffer, size_t buflen, int *errnop)
{
- if ((result->status != NIS_SUCCESS && result->status != NIS_S_SUCCESS)
- || NIS_RES_NUMOBJ (result) != 1
- || __type_of (NIS_RES_OBJECT (result)) != NIS_ENTRY_OBJ
- || strcmp (NIS_RES_OBJECT (result)->EN_data.en_type, "passwd_tbl") != 0
- || NIS_RES_OBJECT (result)->EN_data.en_cols.en_cols_len < 7)
- return 0;
-
- nis_object *obj = NIS_RES_OBJECT (result);
char *first_unused = buffer;
size_t room_left = buflen;
size_t len;
- if (NISOBJLEN (0, obj) >= room_left)
+ if (result == NULL)
+ return 0;
+
+ if ((result->status != NIS_SUCCESS && result->status != NIS_S_SUCCESS)
+ || result->objects.objects_len != 1
+ || __type_of (result->objects.objects_val) != NIS_ENTRY_OBJ
+ || strcmp (result->objects.objects_val->EN_data.en_type,
+ "passwd_tbl") != 0
+ || result->objects.objects_val->EN_data.en_cols.en_cols_len < 7)
+ return 0;
+
+ if (NISENTRYLEN (0, 0, result) >= room_left)
{
/* The line is too long for our buffer. */
no_more_room:
@@ -62,109 +59,111 @@ _nss_nisplus_parse_pwent (nis_result *result, struct passwd *pw,
return -1;
}
- strncpy (first_unused, NISOBJVAL (0, obj), NISOBJLEN (0, obj));
- first_unused[NISOBJLEN (0, obj)] = '\0';
+ strncpy (first_unused, NISENTRYVAL (0, 0, result),
+ NISENTRYLEN (0, 0, result));
+ first_unused[NISENTRYLEN (0, 0, result)] = '\0';
len = strlen (first_unused);
if (len == 0) /* No name ? Should never happen, database is corrupt */
return 0;
pw->pw_name = first_unused;
- room_left -= len + 1;
- first_unused += len + 1;
+ room_left -= (len + 1);
+ first_unused += (len + 1);
- if (NISOBJLEN (1, obj) >= room_left)
+ if (NISENTRYLEN (0, 1, result) >= room_left)
goto no_more_room;
- strncpy (first_unused, NISOBJVAL (1, obj), NISOBJLEN (1, obj));
- first_unused[NISOBJLEN (1, obj)] = '\0';
+ strncpy (first_unused, NISENTRYVAL (0, 1, result),
+ NISENTRYLEN (0, 1, result));
+ first_unused[NISENTRYLEN (0, 1, result)] = '\0';
pw->pw_passwd = first_unused;
len = strlen (first_unused);
- room_left -= len + 1;
- first_unused += len + 1;
+ room_left -= (len + 1);
+ first_unused += (len + 1);
- char *numstr = NISOBJVAL (2, obj);
- len = NISOBJLEN (2, obj);
- if (len == 0 && numstr[len - 1] != '\0')
- {
- if (len >= room_left)
- goto no_more_room;
+ if (NISENTRYLEN(0, 2, result) >= room_left)
+ goto no_more_room;
- strncpy (first_unused, numstr, len);
- first_unused[len] = '\0';
- numstr = first_unused;
- }
- if (numstr[0] == '\0')
- /* If we don't have a uid, it's an invalid shadow entry. */
+ strncpy (first_unused, NISENTRYVAL (0, 2, result),
+ NISENTRYLEN (0, 2, result));
+ first_unused[NISENTRYLEN (0, 2, result)] = '\0';
+ len = strlen (first_unused);
+ if (len == 0) /* If we don't have a uid, it's an invalid shadow entry */
return 0;
- pw->pw_uid = strtoul (numstr, NULL, 10);
+ pw->pw_uid = strtoul (first_unused, NULL, 10);
+ room_left -= (len + 1);
+ first_unused += (len + 1);
- numstr = NISOBJVAL (3, obj);
- len = NISOBJLEN (3, obj);
- if (len == 0 && numstr[len - 1] != '\0')
- {
- if (len >= room_left)
- goto no_more_room;
+ if (NISENTRYLEN (0, 3, result) >= room_left)
+ goto no_more_room;
- strncpy (first_unused, numstr, len);
- first_unused[len] = '\0';
- numstr = first_unused;
- }
- if (numstr[0] == '\0')
- /* If we don't have a gid, it's an invalid shadow entry. */
+ strncpy (first_unused, NISENTRYVAL (0, 3, result),
+ NISENTRYLEN (0, 3, result));
+ first_unused[NISENTRYLEN (0, 3, result)] = '\0';
+ len = strlen (first_unused);
+ if (len == 0) /* If we don't have a gid, it's an invalid shadow entry */
return 0;
- pw->pw_gid = strtoul (numstr, NULL, 10);
+ pw->pw_gid = strtoul (first_unused, NULL, 10);
+ room_left -= (len + 1);
+ first_unused += (len + 1);
- if (NISOBJLEN(4, obj) >= room_left)
+ if (NISENTRYLEN(0, 4, result) >= room_left)
goto no_more_room;
- strncpy (first_unused, NISOBJVAL (4, obj), NISOBJLEN (4, obj));
- first_unused[NISOBJLEN (4, obj)] = '\0';
+ strncpy (first_unused, NISENTRYVAL (0, 4, result),
+ NISENTRYLEN (0, 4, result));
+ first_unused[NISENTRYLEN (0, 4, result)] = '\0';
pw->pw_gecos = first_unused;
len = strlen (first_unused);
- room_left -= len + 1;
- first_unused += len + 1;
+ room_left -= (len + 1);
+ first_unused += (len + 1);
- if (NISOBJLEN (5, obj) >= room_left)
+ if (NISENTRYLEN (0, 5, result) >= room_left)
goto no_more_room;
- strncpy (first_unused, NISOBJVAL (5, obj), NISOBJLEN (5, obj));
- first_unused[NISOBJLEN (5, obj)] = '\0';
+ strncpy (first_unused, NISENTRYVAL (0, 5, result),
+ NISENTRYLEN (0, 5, result));
+ first_unused[NISENTRYLEN (0, 5, result)] = '\0';
pw->pw_dir = first_unused;
len = strlen (first_unused);
- room_left -= len + 1;
- first_unused += len + 1;
+ room_left -= (len + 1);
+ first_unused += (len + 1);
- if (NISOBJLEN (6, obj) >= room_left)
+ if (NISENTRYLEN (0, 6, result) >= room_left)
goto no_more_room;
- strncpy (first_unused, NISOBJVAL (6, obj), NISOBJLEN (6, obj));
- first_unused[NISOBJLEN (6, obj)] = '\0';
+ strncpy (first_unused, NISENTRYVAL (0, 6, result),
+ NISENTRYLEN (0, 6, result));
+ first_unused[NISENTRYLEN (0, 6, result)] = '\0';
pw->pw_shell = first_unused;
len = strlen (first_unused);
- room_left -= len + 1;
- first_unused += len + 1;
+ room_left -= (len + 1);
+ first_unused += (len + 1);
return 1;
}
-
+libnss_nisplus_hidden_def (_nss_nisplus_parse_pwent)
int
-_nss_nisplus_parse_grent (nis_result *result, struct group *gr,
+_nss_nisplus_parse_grent (nis_result *result, u_long entry, struct group *gr,
char *buffer, size_t buflen, int *errnop)
{
- if ((result->status != NIS_SUCCESS && result->status != NIS_S_SUCCESS)
- || __type_of(NIS_RES_OBJECT (result)) != NIS_ENTRY_OBJ
- || strcmp (NIS_RES_OBJECT (result)[0].EN_data.en_type, "group_tbl") != 0
- || NIS_RES_OBJECT (result)[0].EN_data.en_cols.en_cols_len < 4)
- return 0;
-
- nis_object *obj = NIS_RES_OBJECT (result);
char *first_unused = buffer;
size_t room_left = buflen;
char *line;
int count;
size_t len;
- if (NISOBJLEN (0, obj) >= room_left)
+ if (result == NULL)
+ return 0;
+
+ if ((result->status != NIS_SUCCESS && result->status != NIS_S_SUCCESS)
+ || __type_of(result->objects.objects_val) != NIS_ENTRY_OBJ
+ || strcmp (result->objects.objects_val[entry].EN_data.en_type,
+ "group_tbl") != 0
+ || result->objects.objects_val[entry].EN_data.en_cols.en_cols_len < 4)
+ return 0;
+
+ if (NISENTRYLEN (entry, 0, result) >= room_left)
{
/* The line is too long for our buffer. */
no_more_room:
@@ -172,59 +171,54 @@ _nss_nisplus_parse_grent (nis_result *result, struct group *gr,
return -1;
}
- strncpy (first_unused, NISOBJVAL (0, obj), NISOBJLEN (0, obj));
- first_unused[NISOBJLEN (0, obj)] = '\0';
+ strncpy (first_unused, NISENTRYVAL (entry, 0, result),
+ NISENTRYLEN (entry, 0, result));
+ first_unused[NISENTRYLEN (entry, 0, result)] = '\0';
len = strlen (first_unused);
if (len == 0) /* group table is corrupt */
return 0;
gr->gr_name = first_unused;
- room_left -= len + 1;
- first_unused += len + 1;
+ room_left -= (len + 1);
+ first_unused += (len + 1);
- if (NISOBJLEN (1, obj) >= room_left)
+ if (NISENTRYLEN (entry, 1, result) >= room_left)
goto no_more_room;
- strncpy (first_unused, NISOBJVAL (1, obj), NISOBJLEN (1, obj));
- first_unused[NISOBJLEN (1, obj)] = '\0';
+ strncpy (first_unused, NISENTRYVAL (entry, 1, result),
+ NISENTRYLEN (entry, 1, result));
+ first_unused[NISENTRYLEN (entry, 1, result)] = '\0';
gr->gr_passwd = first_unused;
len = strlen (first_unused);
- room_left -= len + 1;
- first_unused += len + 1;
+ room_left -= (len + 1);
+ first_unused += (len + 1);
- char *numstr = NISOBJVAL (2, obj);
- len = NISOBJLEN (2, obj);
- if (len == 0 || numstr[len - 1] != '\0')
- {
- if (len >= room_left)
- goto no_more_room;
+ if (NISENTRYLEN (entry, 2, result) >= room_left)
+ goto no_more_room;
- strncpy (first_unused, numstr, len);
- first_unused[len] = '\0';
- numstr = first_unused;
- }
- if (numstr[0] == '\0')
- /* We should always have a gid. */
+ strncpy (first_unused, NISENTRYVAL (entry, 2, result),
+ NISENTRYLEN (entry, 2, result));
+ first_unused[NISENTRYLEN (entry, 2, result)] = '\0';
+ len = strlen (first_unused);
+ if (len == 0) /* We should always have an gid */
return 0;
- gr->gr_gid = strtoul (numstr, NULL, 10);
+ gr->gr_gid = strtoul (first_unused, NULL, 10);
+ room_left -= (strlen (first_unused) + 1);
+ first_unused += strlen (first_unused) + 1;
- if (NISOBJLEN (3, obj) >= room_left)
+ if (NISENTRYLEN (entry, 3, result) >= room_left)
goto no_more_room;
- strncpy (first_unused, NISOBJVAL (3, obj), NISOBJLEN (3, obj));
- first_unused[NISOBJLEN (3, obj)] = '\0';
+ strncpy (first_unused, NISENTRYVAL (entry, 3, result),
+ NISENTRYLEN (entry, 3, result));
+ first_unused[NISENTRYLEN (entry, 3, result)] = '\0';
line = first_unused;
len = strlen (line);
- room_left -= len + 1;
- first_unused += len + 1;
+ room_left -= (len + 1);
+ first_unused += (len + 1);
/* Adjust the pointer so it is aligned for
storing pointers. */
- size_t adjust = ((__alignof__ (char *)
- - (first_unused - (char *) 0) % __alignof__ (char *))
- % __alignof__ (char *));
- if (room_left < adjust)
- goto no_more_room;
- first_unused += adjust;
- room_left -= adjust;
+ first_unused += __alignof__ (char *) - 1;
+ first_unused -= ((first_unused - (char *) 0) % __alignof__ (char *));
gr->gr_mem = (char **) first_unused;
count = 0;
@@ -249,10 +243,12 @@ _nss_nisplus_parse_grent (nis_result *result, struct group *gr,
{
int is = isspace (*line);
- *line++ = '\0';
+ *line = '\0';
if (is)
while (*line != '\0' && (*line == ',' || isspace (*line)))
++line;
+ else
+ ++line;
}
}
if (room_left < sizeof (char *))
@@ -262,7 +258,7 @@ _nss_nisplus_parse_grent (nis_result *result, struct group *gr,
return 1;
}
-
+libnss_nisplus_hidden_def (_nss_nisplus_parse_grent)
int
_nss_nisplus_parse_spent (nis_result *result, struct spwd *sp,
@@ -276,10 +272,11 @@ _nss_nisplus_parse_spent (nis_result *result, struct spwd *sp,
return 0;
if ((result->status != NIS_SUCCESS && result->status != NIS_S_SUCCESS)
- || NIS_RES_NUMOBJ (result) != 1
- || __type_of(NIS_RES_OBJECT (result)) != NIS_ENTRY_OBJ
- || strcmp (NIS_RES_OBJECT (result)->EN_data.en_type, "passwd_tbl") != 0
- || NIS_RES_OBJECT (result)->EN_data.en_cols.en_cols_len < 8)
+ || result->objects.objects_len != 1
+ || __type_of(result->objects.objects_val) != NIS_ENTRY_OBJ
+ || strcmp (result->objects.objects_val->EN_data.en_type,
+ "passwd_tbl") != 0
+ || result->objects.objects_val[0].EN_data.en_cols.en_cols_len < 8)
return 0;
if (NISENTRYLEN (0, 0, result) >= room_left)
@@ -297,8 +294,8 @@ _nss_nisplus_parse_spent (nis_result *result, struct spwd *sp,
if (len == 0)
return 0;
sp->sp_namp = first_unused;
- room_left -= len + 1;
- first_unused += len + 1;
+ room_left -= (len + 1);
+ first_unused += (len + 1);
if (NISENTRYLEN (0, 1, result) >= room_left)
goto no_more_room;
@@ -308,8 +305,8 @@ _nss_nisplus_parse_spent (nis_result *result, struct spwd *sp,
first_unused[NISENTRYLEN (0, 1, result)] = '\0';
sp->sp_pwdp = first_unused;
len = strlen (first_unused);
- room_left -= len + 1;
- first_unused += len + 1;
+ room_left -= (len + 1);
+ first_unused += (len + 1);
sp->sp_lstchg = sp->sp_min = sp->sp_max = sp->sp_warn = sp->sp_inact =
sp->sp_expire = -1;
@@ -317,8 +314,10 @@ _nss_nisplus_parse_spent (nis_result *result, struct spwd *sp,
if (NISENTRYLEN (0, 7, result) > 0)
{
- char *line = NISENTRYVAL (0, 7, result);
- char *cp = strchr (line, ':');
+ char *line, *cp;
+
+ line = NISENTRYVAL (0, 7, result);
+ cp = strchr (line, ':');
if (cp == NULL)
return 1;
*cp++ = '\0';
@@ -374,3 +373,4 @@ _nss_nisplus_parse_spent (nis_result *result, struct spwd *sp,
return 1;
}
+libnss_nisplus_hidden_def (_nss_nisplus_parse_spent)
diff --git a/nis/nss_nisplus/nisplus-proto.c b/nis/nss_nisplus/nisplus-proto.c
index 42a2d088da..83456cae64 100644
--- a/nis/nss_nisplus/nisplus-proto.c
+++ b/nis/nss_nisplus/nisplus-proto.c
@@ -1,5 +1,4 @@
-/* Copyright (C) 1997, 1998, 2001, 2002, 2003, 2005, 2006
- Free Software Foundation, Inc.
+/* Copyright (C) 1997, 1998, 2001, 2002, 2003 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
@@ -18,14 +17,13 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
-#include <atomic.h>
-#include <ctype.h>
+#include <nss.h>
#include <errno.h>
+#include <ctype.h>
#include <netdb.h>
-#include <nss.h>
#include <string.h>
-#include <rpcsvc/nis.h>
#include <bits/libc-lock.h>
+#include <rpcsvc/nis.h>
#include "nss-nisplus.h"
@@ -35,20 +33,20 @@ static nis_result *result;
static nis_name tablename_val;
static u_long tablename_len;
-#define NISENTRYVAL(idx, col, res) \
- (NIS_RES_OBJECT (res)[idx].EN_data.en_cols.en_cols_val[col].ec_value.ec_value_val)
-
-#define NISENTRYLEN(idx, col, res) \
- (NIS_RES_OBJECT (res)[idx].EN_data.en_cols.en_cols_val[col].ec_value.ec_value_len)
+#define NISENTRYVAL(idx,col,res) \
+ ((res)->objects.objects_val[(idx)].EN_data.en_cols.en_cols_val[(col)].ec_value.ec_value_val)
+#define NISENTRYLEN(idx,col,res) \
+ ((res)->objects.objects_val[(idx)].EN_data.en_cols.en_cols_val[(col)].ec_value.ec_value_len)
static int
-_nss_nisplus_parse_protoent (nis_result *result, struct protoent *proto,
+_nss_nisplus_parse_protoent (nis_result * result, struct protoent *proto,
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;
@@ -71,44 +69,41 @@ _nss_nisplus_parse_protoent (nis_result *result, struct protoent *proto,
NISENTRYLEN (0, 0, result));
first_unused[NISENTRYLEN (0, 0, result)] = '\0';
proto->p_name = first_unused;
- size_t len = strlen (first_unused) + 1;
- room_left -= len;
- first_unused += len;
+ room_left -= (strlen (first_unused) +1);
+ first_unused += strlen (first_unused) +1;
+ if (NISENTRYLEN (0, 2, result) + 1 > room_left)
+ goto no_more_room;
proto->p_proto = atoi (NISENTRYVAL (0, 2, result));
+ p = first_unused;
- /* XXX Rewrite at some point to allocate the array first and then
- copy the strings. It wasteful to first concatenate the strings
- to just split them again later. */
- char *line = first_unused;
- for (i = 0; i < NIS_RES_NUMOBJ (result); ++i)
+ line = p;
+ for (i = 0; i < result->objects.objects_len; ++i)
{
if (strcmp (NISENTRYVAL (i, 1, result), proto->p_name) != 0)
{
if (NISENTRYLEN (i, 1, result) + 2 > room_left)
goto no_more_room;
- *first_unused++ = ' ';
- first_unused = __stpncpy (first_unused, NISENTRYVAL (i, 1, result),
- NISENTRYLEN (i, 1, result));
- room_left -= NISENTRYLEN (i, 1, result) + 1;
+ *p++ = ' ';
+ p = __stpncpy (p, NISENTRYVAL (i, 1, result),
+ NISENTRYLEN (i, 1, result));
+ *p = '\0';
+ room_left -= (NISENTRYLEN (i, 1, result) + 1);
}
}
- *first_unused++ = '\0';
+ *p++ = '\0';
+ first_unused = p;
/* Adjust the pointer so it is aligned for
storing pointers. */
- size_t adjust = ((__alignof__ (char *)
- - (first_unused - (char *) 0) % __alignof__ (char *))
- % __alignof__ (char *));
- if (room_left < adjust + sizeof (char *))
- goto no_more_room;
- first_unused += adjust;
- room_left -= adjust;
+ first_unused += __alignof__ (char *) - 1;
+ first_unused -= ((first_unused - (char *) 0) % __alignof__ (char *));
proto->p_aliases = (char **) first_unused;
-
- /* For the terminating NULL pointer. */
+ if (room_left < sizeof (char *))
+ goto no_more_room;
room_left -= sizeof (char *);
+ proto->p_aliases[0] = NULL;
i = 0;
while (*line != '\0')
@@ -123,15 +118,20 @@ _nss_nisplus_parse_protoent (nis_result *result, struct protoent *proto,
goto no_more_room;
room_left -= sizeof (char *);
- proto->p_aliases[i++] = line;
+ proto->p_aliases[i] = line;
while (*line != '\0' && *line != ' ')
++line;
if (*line == ' ')
- *line++ = '\0';
+ {
+ *line = '\0';
+ ++line;
+ ++i;
+ }
+ else
+ proto->p_aliases[i+1] = NULL;
}
- proto->p_aliases[i] = NULL;
return 1;
}
@@ -141,26 +141,19 @@ _nss_create_tablename (int *errnop)
{
if (tablename_val == NULL)
{
- const char *local_dir = nis_local_directory ();
- size_t local_dir_len = strlen (local_dir);
- static const char prefix[] = "protocols.org_dir.";
+ char buf [40 + strlen (nis_local_directory ())];
+ char *p;
- char *p = malloc (sizeof (prefix) + local_dir_len);
- if (p == NULL)
+ p = __stpcpy (buf, "protocols.org_dir.");
+ p = __stpcpy (p, nis_local_directory ());
+ tablename_val = __strdup (buf);
+ if (tablename_val == NULL)
{
*errnop = errno;
return NSS_STATUS_TRYAGAIN;
}
-
- memcpy (__stpcpy (p, prefix), local_dir, local_dir_len + 1);
-
- tablename_len = sizeof (prefix) - 1 + local_dir_len;
-
- atomic_write_barrier ();
-
- tablename_val = p;
+ tablename_len = strlen (tablename_val);
}
-
return NSS_STATUS_SUCCESS;
}
@@ -171,11 +164,9 @@ _nss_nisplus_setprotoent (int stayopen)
__libc_lock_lock (lock);
- if (result != NULL)
- {
- nis_freeresult (result);
- result = NULL;
- }
+ if (result)
+ nis_freeresult (result);
+ result = NULL;
if (tablename_val == NULL)
{
@@ -193,11 +184,9 @@ _nss_nisplus_endprotoent (void)
{
__libc_lock_lock (lock);
- if (result != NULL)
- {
- nis_freeresult (result);
- result = NULL;
- }
+ if (result)
+ nis_freeresult (result);
+ result = NULL;
__libc_lock_unlock (lock);
@@ -227,23 +216,17 @@ internal_nisplus_getprotoent_r (struct protoent *proto, char *buffer,
}
result = nis_first_entry (tablename_val);
- if (result == NULL)
- {
- *errnop = errno;
- return NSS_STATUS_TRYAGAIN;
- }
if (niserr2nss (result->status) != NSS_STATUS_SUCCESS)
return niserr2nss (result->status);
}
else
{
+ nis_result *res;
+
saved_res = result;
- result = nis_next_entry (tablename_val, &result->cookie);
- if (result == NULL)
- {
- *errnop = errno;
- return NSS_STATUS_TRYAGAIN;
- }
+ res = nis_next_entry (tablename_val, &result->cookie);
+ result = res;
+
if (niserr2nss (result->status) != NSS_STATUS_SUCCESS)
{
nis_freeresult (saved_res);
@@ -294,91 +277,79 @@ _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;
- char buf[strlen (name) + 10 + tablename_len];
- int olderr = errno;
-
- /* 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);
+ /* 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)
- {
- 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
+ if (result != NULL)
{
- /* 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 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);
+
+ nis_freeresult (result);
+ result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL);
}
- nis_freeresult (result);
- result = nis_list (bufptr, FOLLOW_PATH | FOLLOW_LINKS, 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;
+ }
- __set_errno (olderr);
+ parse_res = _nss_nisplus_parse_protoent (result, proto, buffer, buflen,
+ errnop);
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
+ if (parse_res < 1)
{
- __set_errno (olderr);
- return NSS_STATUS_NOTFOUND;
+ if (parse_res == -1)
+ {
+ *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
@@ -387,57 +358,55 @@ _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;
}
- char buf[12 + 3 * sizeof (number) + tablename_len];
- int olderr = errno;
+ {
+ int parse_res;
+ nis_result *result;
+ char buf[46 + tablename_len];
+ int olderr = errno;
- snprintf (buf, sizeof (buf), "[number=%d],%s", number, tablename_val);
+ sprintf (buf, "[number=%d],%s", number, tablename_val);
- nis_result *result = nis_list (buf, FOLLOW_LINKS | FOLLOW_PATH, NULL, NULL);
+ result = nis_list (buf, FOLLOW_LINKS | FOLLOW_PATH, NULL, NULL);
- if (result == NULL)
- {
- __set_errno (ENOMEM);
- return NSS_STATUS_TRYAGAIN;
- }
+ 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 (__builtin_expect (niserr2nss (result->status) != NSS_STATUS_SUCCESS, 0))
- {
- enum nss_status status = niserr2nss (result->status);
+ __set_errno (olderr);
- __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;
+ 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;
+ }
}
diff --git a/nis/nss_nisplus/nisplus-publickey.c b/nis/nss_nisplus/nisplus-publickey.c
index f6b32f8827..58ae7012af 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,2005,2006 Free Software Foundation, Inc.
+/* Copyright (c) 1997, 1999, 2001, 2003 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;
@@ -91,20 +91,20 @@ _nss_nisplus_getpublickey (const char *netname, char *pkey, int *errnop)
return retval;
}
- if (NIS_RES_NUMOBJ (res) > 1)
+ if (res->objects.objects_len > 1)
{
/*
* More than one principal with same uid?
* something wrong with cred table. Should be unique
* Warn user and continue.
*/
- syslog (LOG_ERR, _("DES entry for netname %s not unique\n"), netname);
+ printf (_("DES entry for netname %s not unique\n"), netname);
nis_freeresult (res);
return NSS_STATUS_SUCCESS;
}
- len = ENTRY_LEN (NIS_RES_OBJECT (res), 3);
- memcpy (pkey, ENTRY_VAL (NIS_RES_OBJECT (res),3), len);
+ len = ENTRY_LEN (res->objects.objects_val, 3);
+ memcpy (pkey, ENTRY_VAL (res->objects.objects_val,3), len);
pkey[len] = 0;
cptr = strchr (pkey, ':');
if (cptr)
@@ -114,14 +114,13 @@ _nss_nisplus_getpublickey (const char *netname, char *pkey, int *errnop)
return NSS_STATUS_SUCCESS;
}
-
enum nss_status
_nss_nisplus_getsecretkey (const char *netname, char *skey, char *passwd,
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;
@@ -155,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)
@@ -173,20 +172,20 @@ _nss_nisplus_getsecretkey (const char *netname, char *skey, char *passwd,
return retval;
}
- if (NIS_RES_NUMOBJ (res) > 1)
+ if (res->objects.objects_len > 1)
{
/*
* More than one principal with same uid?
* something wrong with cred table. Should be unique
* Warn user and continue.
*/
- syslog (LOG_ERR, _("DES entry for netname %s not unique\n"), netname);
+ printf (_("DES entry for netname %s not unique\n"), netname);
nis_freeresult (res);
return NSS_STATUS_SUCCESS;
}
- len = ENTRY_LEN (NIS_RES_OBJECT (res), 4);
- memcpy (buf, ENTRY_VAL (NIS_RES_OBJECT (res), 4), len);
+ len = ENTRY_LEN (res->objects.objects_val, 4);
+ memcpy (buf, ENTRY_VAL (res->objects.objects_val,4), len);
buf[len] = '\0';
cptr = strchr (buf, ':');
if (cptr)
@@ -205,7 +204,6 @@ _nss_nisplus_getsecretkey (const char *netname, char *skey, char *passwd,
return NSS_STATUS_SUCCESS;
}
-
/* Parse information from the passed string.
The format of the string passed is gid,grp,grp, ... */
static enum nss_status
@@ -226,12 +224,8 @@ parse_grp_str (const char *s, gid_t *gidp, int *gidlenp, gid_t *gidlist,
gidlen = 0;
/* After strtoul() ep should point to the marker ',', which means
- here starts a new value.
-
- The Sun man pages show that GIDLIST should contain at least NGRPS
- elements. Limiting the number written by this value is the best
- we can do. */
- while (ep != NULL && *ep == ',' && gidlen < NGRPS)
+ here starts a new value. */
+ while (ep != NULL && *ep == ',')
{
ep++;
s = ep;
@@ -248,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. */
@@ -261,6 +255,10 @@ _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);
@@ -311,7 +309,7 @@ _nss_nisplus_netname2user (char netname[MAXNETNAMELEN + 1], uid_t *uidp,
return NSS_STATUS_UNAVAIL;
}
- if (NIS_RES_NUMOBJ (res) > 1)
+ if (res->objects.objects_len > 1)
/*
* A netname belonging to more than one principal?
* Something wrong with cred table. should be unique.
@@ -321,8 +319,8 @@ _nss_nisplus_netname2user (char netname[MAXNETNAMELEN + 1], uid_t *uidp,
_("netname2user: DES entry for %s in directory %s not unique"),
netname, domain);
- len = ENTRY_LEN (NIS_RES_OBJECT (res), 0);
- strncpy (principal, ENTRY_VAL (NIS_RES_OBJECT (res), 0), len);
+ len = ENTRY_LEN (res->objects.objects_val, 0);
+ strncpy (principal, ENTRY_VAL (res->objects.objects_val, 0), len);
principal[len] = '\0';
nis_freeresult (res);
@@ -334,16 +332,15 @@ _nss_nisplus_netname2user (char netname[MAXNETNAMELEN + 1], uid_t *uidp,
* LOCAL entry in **local** cred table.
*/
domain = nis_local_directory ();
- if (strlen (principal) + strlen (domain) + 45 > (size_t) NIS_MAXNAMELEN)
+ if ((strlen (principal) + strlen (domain) + 45) > (size_t) NIS_MAXNAMELEN)
{
syslog (LOG_ERR, _("netname2user: principal name `%s' too long"),
principal);
return NSS_STATUS_UNAVAIL;
}
- slen = snprintf (sname, sizeof (sname),
- "[cname=%s,auth_type=LOCAL],cred.org_dir.%s",
- principal, domain);
+ slen = sprintf (sname, "[cname=%s,auth_type=LOCAL],cred.org_dir.%s",
+ principal, domain);
if (sname[slen - 1] != '.')
{
@@ -385,7 +382,7 @@ _nss_nisplus_netname2user (char netname[MAXNETNAMELEN + 1], uid_t *uidp,
return NSS_STATUS_UNAVAIL;
}
- if (NIS_RES_NUMOBJ (res) > 1)
+ if (res->objects.objects_len > 1)
/*
* A principal can have more than one LOCAL entry?
* Something wrong with cred table.
@@ -395,16 +392,15 @@ _nss_nisplus_netname2user (char netname[MAXNETNAMELEN + 1], uid_t *uidp,
_("netname2user: LOCAL entry for %s in directory %s not unique"),
netname, domain);
/* Fetch the uid */
- *uidp = strtoul (ENTRY_VAL (NIS_RES_OBJECT (res), 2), NULL, 10);
+ *uidp = strtoul (ENTRY_VAL (res->objects.objects_val, 2), NULL, 10);
if (*uidp == 0)
{
syslog (LOG_ERR, _("netname2user: should not have uid 0"));
- nis_freeresult (res);
return NSS_STATUS_NOTFOUND;
}
- parse_grp_str (ENTRY_VAL (NIS_RES_OBJECT (res), 3),
+ parse_grp_str (ENTRY_VAL (res->objects.objects_val, 3),
gidp, gidlenp, gidlist, errnop);
nis_freeresult (res);
diff --git a/nis/nss_nisplus/nisplus-pwd.c b/nis/nss_nisplus/nisplus-pwd.c
index cd33aebbcc..8f3bc997b3 100644
--- a/nis/nss_nisplus/nisplus-pwd.c
+++ b/nis/nss_nisplus/nisplus-pwd.c
@@ -1,5 +1,4 @@
-/* Copyright (C) 1997, 1999, 2001, 2002, 2003, 2005, 2006, 2007
- Free Software Foundation, Inc.
+/* Copyright (C) 1997, 1999, 2001, 2002, 2003 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
@@ -18,7 +17,6 @@
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>
@@ -28,246 +26,126 @@
#include "nss-nisplus.h"
#include "nisplus-parser.h"
-#include <libnsl.h>
-#include <nis_intern.h>
-#include <nis_xdr.h>
-
__libc_lock_define_initialized (static, lock)
-/* Connection information. */
-static ib_request *ibreq;
-static directory_obj *dir;
-static dir_binding bptr;
-static char *tablepath;
-static char *tableptr;
-/* Cursor. */
-static netobj cursor;
-
+static nis_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;
-
-enum nss_status
-_nss_pwd_create_tablename (int *errnop)
+static enum nss_status
+_nss_create_tablename (int *errnop)
{
- if (pwd_tablename_val == NULL)
+ if (tablename_val == NULL)
{
- const char *local_dir = nis_local_directory ();
- size_t local_dir_len = strlen (local_dir);
- static const char prefix[] = "passwd.org_dir.";
+ char buf [40 + strlen (nis_local_directory ())];
+ char *p;
- char *p = malloc (sizeof (prefix) + local_dir_len);
- if (p == NULL)
+ 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;
}
-
- 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);
- }
+ tablename_len = strlen (tablename_val);
}
-
return NSS_STATUS_SUCCESS;
}
-static void
-internal_nisplus_endpwent (void)
-{
- __nisbind_destroy (&bptr);
- memset (&bptr, '\0', sizeof (bptr));
-
- nis_free_directory (dir);
- dir = NULL;
-
- nis_free_request (ibreq);
- ibreq = NULL;
-
- xdr_free ((xdrproc_t) xdr_netobj, (char *) &cursor);
- memset (&cursor, '\0', sizeof (cursor));
-
- free (tablepath);
- tableptr = tablepath = NULL;
-}
-
-
-static enum nss_status
-internal_nisplus_setpwent (int *errnop)
-{
- enum nss_status status = NSS_STATUS_SUCCESS;
-
- if (pwd_tablename_val == NULL)
- status = _nss_pwd_create_tablename (errnop);
-
- if (status == NSS_STATUS_SUCCESS)
- {
- ibreq = __create_ib_request (pwd_tablename_val, 0);
- if (ibreq == NULL)
- {
- *errnop = errno;
- return NSS_STATUS_TRYAGAIN;
- }
-
- nis_error retcode = __prepare_niscall (pwd_tablename_val, &dir,
- &bptr, 0);
- if (retcode != NIS_SUCCESS)
- {
- nis_free_request (ibreq);
- ibreq = NULL;
- status = niserr2nss (retcode);
- }
- }
-
- return status;
-}
-
-
enum nss_status
_nss_nisplus_setpwent (int stayopen)
{
- enum nss_status status;
+ enum nss_status status = NSS_STATUS_SUCCESS;
+ int err;
__libc_lock_lock (lock);
- internal_nisplus_endpwent ();
+ if (result)
+ nis_freeresult (result);
+ result = NULL;
- // XXX We need to be able to set errno. Pass in new parameter.
- int err;
- status = internal_nisplus_setpwent (&err);
+ if (tablename_val == NULL)
+ status = _nss_create_tablename (&err);
__libc_lock_unlock (lock);
return status;
}
-
enum nss_status
_nss_nisplus_endpwent (void)
{
__libc_lock_lock (lock);
- internal_nisplus_endpwent ();
+ if (result)
+ nis_freeresult (result);
+ result = NULL;
__libc_lock_unlock (lock);
return NSS_STATUS_SUCCESS;
}
-
static enum nss_status
internal_nisplus_getpwent_r (struct passwd *pw, char *buffer, size_t buflen,
int *errnop)
{
- int parse_res = -1;
- enum nss_status retval = NSS_STATUS_SUCCESS;
+ int parse_res;
/* Get the next entry until we found a correct one. */
do
{
- nis_error status;
- nis_result result;
- memset (&result, '\0', sizeof (result));
+ nis_result *saved_res;
- if (cursor.n_bytes == NULL)
+ if (result == NULL)
{
- if (ibreq == NULL)
+ saved_res = NULL;
+ if (tablename_val == NULL)
{
- retval = internal_nisplus_setpwent (errnop);
- if (retval != NSS_STATUS_SUCCESS)
- return retval;
+ enum nss_status status = _nss_create_tablename (errnop);
+
+ if (status != NSS_STATUS_SUCCESS)
+ return status;
}
- status = __do_niscall3 (&bptr, NIS_IBFIRST,
- (xdrproc_t) _xdr_ib_request,
- (caddr_t) ibreq,
- (xdrproc_t) _xdr_nis_result,
- (caddr_t) &result,
- 0, NULL);
+ result = nis_first_entry (tablename_val);
+ if (niserr2nss (result->status) != NSS_STATUS_SUCCESS)
+ return niserr2nss (result->status);
}
else
{
- ibreq->ibr_cookie.n_bytes = cursor.n_bytes;
- ibreq->ibr_cookie.n_len = cursor.n_len;
-
- status = __do_niscall3 (&bptr, NIS_IBNEXT,
- (xdrproc_t) _xdr_ib_request,
- (caddr_t) ibreq,
- (xdrproc_t) _xdr_nis_result,
- (caddr_t) &result,
- 0, NULL);
-
- ibreq->ibr_cookie.n_bytes = NULL;
- ibreq->ibr_cookie.n_len = 0;
- }
-
- if (status != NIS_SUCCESS)
- return niserr2nss (status);
+ nis_result *res;
- if (NIS_RES_STATUS (&result) == NIS_NOTFOUND)
- {
- /* No more entries on this server. This means we have to go
- to the next server on the path. */
- status = __follow_path (&tablepath, &tableptr, ibreq, &bptr);
- if (status != NIS_SUCCESS)
- return niserr2nss (status);
-
- directory_obj *newdir = NULL;
- dir_binding newbptr;
- status = __prepare_niscall (ibreq->ibr_name, &newdir, &newbptr, 0);
- if (status != NIS_SUCCESS)
- return niserr2nss (status);
-
- nis_free_directory (dir);
- dir = newdir;
- __nisbind_destroy (&bptr);
- bptr = newbptr;
-
- xdr_free ((xdrproc_t) xdr_netobj, (char *) &result.cookie);
- result.cookie.n_bytes = NULL;
- result.cookie.n_len = 0;
- parse_res = 0;
- goto next;
+ saved_res = result;
+ res = nis_next_entry (tablename_val, &result->cookie);
+ result = res;
+ if (niserr2nss (result->status) != NSS_STATUS_SUCCESS)
+ {
+ nis_freeresult (saved_res);
+ return niserr2nss (result->status);
+ }
}
- else if (NIS_RES_STATUS (&result) != NIS_SUCCESS)
- return niserr2nss (NIS_RES_STATUS (&result));
- parse_res = _nss_nisplus_parse_pwent (&result, pw, buffer,
+ parse_res = _nss_nisplus_parse_pwent (result, pw, buffer,
buflen, errnop);
-
- if (__builtin_expect (parse_res == -1, 0))
+ if (parse_res == -1)
{
+ nis_freeresult (result);
+ result = saved_res;
*errnop = ERANGE;
- retval = NSS_STATUS_TRYAGAIN;
- goto freeres;
+ return NSS_STATUS_TRYAGAIN;
}
+ else
+ {
+ if (saved_res)
+ nis_freeresult (saved_res);
+ }
+ } while (!parse_res);
- next:
- /* Free the old cursor. */
- xdr_free ((xdrproc_t) xdr_netobj, (char *) &cursor);
- /* Remember the new one. */
- cursor.n_bytes = result.cookie.n_bytes;
- cursor.n_len = result.cookie.n_len;
- /* Free the result structure. NB: we do not remove the cookie. */
- result.cookie.n_bytes = NULL;
- result.cookie.n_len = 0;
- freeres:
- xdr_free ((xdrproc_t) _xdr_nis_result, (char *) &result);
- memset (&result, '\0', sizeof (result));
- }
- while (!parse_res);
-
- return retval;
+ return NSS_STATUS_SUCCESS;
}
enum nss_status
@@ -291,9 +169,9 @@ _nss_nisplus_getpwnam_r (const char *name, struct passwd *pw,
{
int parse_res;
- if (pwd_tablename_val == NULL)
+ if (tablename_val == NULL)
{
- enum nss_status status = _nss_pwd_create_tablename (errnop);
+ enum nss_status status = _nss_create_tablename (errnop);
if (status != NSS_STATUS_SUCCESS)
return status;
@@ -304,107 +182,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;
- nis_result *result;
- char buf[strlen (name) + 9 + pwd_tablename_len];
- int olderr = errno;
+ sprintf (buf, "[name=%s],%s", name, tablename_val);
- snprintf (buf, sizeof (buf), "[name=%s],%s", name, pwd_tablename_val);
+ result = nis_list(buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL);
- result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS | USE_DGRAM, 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;
+ }
- __set_errno (olderr);
+ parse_res = _nss_nisplus_parse_pwent (result, pw, buffer, buflen,
+ errnop);
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
+ if (parse_res < 1)
{
- __set_errno (olderr);
- return NSS_STATUS_NOTFOUND;
+ if (parse_res == -1)
+ {
+ *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 (pwd_tablename_val == NULL)
+ if (tablename_val == NULL)
{
- enum nss_status status = _nss_pwd_create_tablename (errnop);
+ enum nss_status status = _nss_create_tablename (errnop);
if (status != NSS_STATUS_SUCCESS)
return status;
}
- int parse_res;
- nis_result *result;
- char buf[8 + 3 * sizeof (unsigned long int) + pwd_tablename_len];
- int olderr = errno;
-
- snprintf (buf, sizeof (buf), "[uid=%lu],%s",
- (unsigned long int) uid, pwd_tablename_val);
-
- result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS | USE_DGRAM, 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);
+ {
+ int parse_res;
+ nis_result *result;
+ char buf[100 + tablename_len];
+ int olderr = errno;
- __set_errno (olderr);
+ sprintf (buf, "[uid=%lu],%s", (unsigned long int) uid, tablename_val);
- nis_freeresult (result);
- return status;
- }
+ result = nis_list(buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL);
- parse_res = _nss_nisplus_parse_pwent (result, pw, buffer, buflen, errnop);
+ 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);
+ __set_errno (olderr);
- 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;
+ 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;
+ }
}
diff --git a/nis/nss_nisplus/nisplus-rpc.c b/nis/nss_nisplus/nisplus-rpc.c
index 711c6bc273..31d48d17a3 100644
--- a/nis/nss_nisplus/nisplus-rpc.c
+++ b/nis/nss_nisplus/nisplus-rpc.c
@@ -1,5 +1,4 @@
-/* Copyright (C) 1997, 1998, 2001, 2002, 2003, 2005, 2006, 2007
- Free Software Foundation, Inc.
+/* Copyright (C) 1997, 1998, 2001, 2002, 2003 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
@@ -18,14 +17,13 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
-#include <atomic.h>
-#include <ctype.h>
-#include <errno.h>
#include <nss.h>
+#include <errno.h>
+#include <ctype.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"
@@ -35,12 +33,11 @@ static nis_result *result;
static nis_name tablename_val;
static u_long tablename_len;
-#define NISENTRYVAL(idx, col, res) \
- (NIS_RES_OBJECT (res)[idx].EN_data.en_cols.en_cols_val[col].ec_value.ec_value_val)
-
-#define NISENTRYLEN(idx, col, res) \
- (NIS_RES_OBJECT (res)[idx].EN_data.en_cols.en_cols_val[col].ec_value.ec_value_len)
+#define NISENTRYVAL(idx,col,res) \
+ ((res)->objects.objects_val[(idx)].EN_data.en_cols.en_cols_val[(col)].ec_value.ec_value_val)
+#define NISENTRYLEN(idx,col,res) \
+ ((res)->objects.objects_val[(idx)].EN_data.en_cols.en_cols_val[(col)].ec_value.ec_value_len)
static int
_nss_nisplus_parse_rpcent (nis_result *result, struct rpcent *rpc,
@@ -49,16 +46,17 @@ _nss_nisplus_parse_rpcent (nis_result *result, struct rpcent *rpc,
char *first_unused = buffer;
size_t room_left = buflen;
unsigned int i;
- char *line;
+ char *p, *line;
if (result == NULL)
return 0;
if ((result->status != NIS_SUCCESS && result->status != NIS_S_SUCCESS)
- || __type_of (NIS_RES_OBJECT (result)) != NIS_ENTRY_OBJ
- || strcmp (NIS_RES_OBJECT (result)[0].EN_data.en_type, "rpc_tbl") != 0
- || NIS_RES_OBJECT (result)[0].EN_data.en_cols.en_cols_len < 3)
+ || __type_of (result->objects.objects_val) != NIS_ENTRY_OBJ
+ || strcmp (result->objects.objects_val[0].EN_data.en_type,
+ "rpc_tbl") != 0
+ || result->objects.objects_val[0].EN_data.en_cols.en_cols_len < 3)
return 0;
if (NISENTRYLEN (0, 0, result) >= room_left)
@@ -71,43 +69,37 @@ _nss_nisplus_parse_rpcent (nis_result *result, struct rpcent *rpc,
NISENTRYLEN (0, 0, result));
first_unused[NISENTRYLEN (0, 0, result)] = '\0';
rpc->r_name = first_unused;
- size_t len = strlen (first_unused) + 1;
- room_left -= len;
- first_unused += len;
-
+ room_left -= (strlen (first_unused) + 1);
+ first_unused += strlen (first_unused) + 1;
rpc->r_number = atoi (NISENTRYVAL (0, 2, result));
+ p = first_unused;
- /* XXX Rewrite at some point to allocate the array first and then
- copy the strings. It wasteful to first concatenate the strings
- to just split them again later. */
- line = first_unused;
- for (i = 0; i < NIS_RES_NUMOBJ (result); ++i)
+ line = p;
+ for (i = 0; i < result->objects.objects_len; ++i)
{
if (strcmp (NISENTRYVAL (i, 1, result), rpc->r_name) != 0)
{
if (NISENTRYLEN (i, 1, result) + 2 > room_left)
goto no_more_room;
- *first_unused++ = ' ';
- first_unused = __stpncpy (first_unused, NISENTRYVAL (i, 1, result),
- NISENTRYLEN (i, 1, result));
- room_left -= NISENTRYLEN (i, 1, result) + 1;
+ *p++ = ' ';
+ p = __stpncpy (p, NISENTRYVAL (i, 1, result),
+ NISENTRYLEN (i, 1, result));
+ *p = '\0';
+ room_left -= (NISENTRYLEN (i, 1, result) + 1);
}
}
- *first_unused++ = '\0';
+ ++p;
+ first_unused = p;
/* Adjust the pointer so it is aligned for
storing pointers. */
- size_t adjust = ((__alignof__ (char *)
- - (first_unused - (char *) 0) % __alignof__ (char *))
- % __alignof__ (char *));
- if (room_left < adjust + sizeof (char *))
- goto no_more_room;
- first_unused += adjust;
- room_left -= adjust;
+ first_unused += __alignof__ (char *) - 1;
+ first_unused -= ((first_unused - (char *) 0) % __alignof__ (char *));
rpc->r_aliases = (char **) first_unused;
-
- /* For the terminating NULL pointer. */
+ if (room_left < sizeof (char *))
+ goto no_more_room;
room_left -= sizeof (char *);
+ rpc->r_aliases[0] = NULL;
i = 0;
while (*line != '\0')
@@ -123,45 +115,42 @@ _nss_nisplus_parse_rpcent (nis_result *result, struct rpcent *rpc,
goto no_more_room;
room_left -= sizeof (char *);
- rpc->r_aliases[i++] = line;
+ rpc->r_aliases[i] = line;
while (*line != '\0' && *line != ' ')
++line;
if (*line == ' ')
- *line++ = '\0';
+ {
+ *line = '\0';
+ ++line;
+ ++i;
+ }
+ else
+ rpc->r_aliases[i+1] = NULL;
}
- rpc->r_aliases[i] = NULL;
return 1;
}
-
static enum nss_status
_nss_create_tablename (int *errnop)
{
if (tablename_val == NULL)
{
- const char *local_dir = nis_local_directory ();
- size_t local_dir_len = strlen (local_dir);
- static const char prefix[] = "rpc.org_dir.";
+ char buf [40 + strlen (nis_local_directory ())];
+ char *p;
- char *p = malloc (sizeof (prefix) + local_dir_len);
- if (p == NULL)
+ p = __stpcpy (buf, "rpc.org_dir.");
+ p = __stpcpy (p, nis_local_directory ());
+ tablename_val = __strdup (buf);
+ if (tablename_val == NULL)
{
*errnop = errno;
return NSS_STATUS_TRYAGAIN;
}
-
- memcpy (__stpcpy (p, prefix), local_dir, local_dir_len + 1);
-
- tablename_len = sizeof (prefix) - 1 + local_dir_len;
-
- atomic_write_barrier ();
-
- tablename_val = p;
+ tablename_len = strlen (tablename_val);
}
-
return NSS_STATUS_SUCCESS;
}
@@ -170,20 +159,16 @@ enum nss_status
_nss_nisplus_setrpcent (int stayopen)
{
enum nss_status status = NSS_STATUS_SUCCESS;
+ int err;
__libc_lock_lock (lock);
- if (result != NULL)
- {
- nis_freeresult (result);
- result = NULL;
- }
+ if (result)
+ nis_freeresult (result);
+ result = NULL;
if (tablename_val == NULL)
- {
- int err;
- status = _nss_create_tablename (&err);
- }
+ status = _nss_create_tablename (&err);
__libc_lock_unlock (lock);
@@ -195,11 +180,9 @@ _nss_nisplus_endrpcent (void)
{
__libc_lock_lock (lock);
- if (result != NULL)
- {
- nis_freeresult (result);
- result = NULL;
- }
+ if (result)
+ nis_freeresult (result);
+ result = NULL;
__libc_lock_unlock (lock);
@@ -229,23 +212,16 @@ internal_nisplus_getrpcent_r (struct rpcent *rpc, char *buffer,
}
result = nis_first_entry (tablename_val);
- if (result == NULL)
- {
- *errnop = errno;
- return NSS_STATUS_TRYAGAIN;
- }
if (niserr2nss (result->status) != NSS_STATUS_SUCCESS)
return niserr2nss (result->status);
}
else
{
+ nis_result *res;
+
saved_res = result;
- result = nis_next_entry (tablename_val, &result->cookie);
- if (result == NULL)
- {
- *errnop = errno;
- return NSS_STATUS_TRYAGAIN;
- }
+ res = nis_next_entry (tablename_val, &result->cookie);
+ result = res;
if (niserr2nss (result->status) != NSS_STATUS_SUCCESS)
{
nis_freeresult (saved_res);
@@ -267,8 +243,7 @@ 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;
}
@@ -296,91 +271,77 @@ _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;
- char buf[strlen (name) + 10 + tablename_len];
- int olderr = errno;
-
- /* 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 | USE_DGRAM,
- NULL, NULL);
+ /* 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)
- {
- 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
+ if (result != NULL)
{
- /* 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);
- }
-
- nis_freeresult (result);
- result = nis_list (bufptr, FOLLOW_PATH | FOLLOW_LINKS | USE_DGRAM,
- NULL, 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);
- if (result == NULL)
- {
- *errnop = ENOMEM;
- return NSS_STATUS_TRYAGAIN;
- }
+ nis_freeresult (result);
+ result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS , NULL, NULL);
+ }
- if (__builtin_expect (niserr2nss (result->status) != NSS_STATUS_SUCCESS, 0))
- {
- enum nss_status status = niserr2nss (result->status);
+ if (result == NULL)
+ {
+ *errnop = ENOMEM;
+ return NSS_STATUS_TRYAGAIN;
+ }
+ if (niserr2nss (result->status) != NSS_STATUS_SUCCESS)
+ {
+ enum nss_status status = niserr2nss (result->status);
- __set_errno (olderr);
+ __set_errno (olderr);
- nis_freeresult (result);
- return status;
- }
+ nis_freeresult (result);
+ return status;
+ }
- parse_res = _nss_nisplus_parse_rpcent (result, rpc, buffer, buflen,
+ parse_res = _nss_nisplus_parse_rpcent (result, rpc, buffer, buflen,
errnop);
- nis_freeresult (result);
+ nis_freeresult (result);
- if (parse_res < 1)
- {
- if (parse_res == -1)
+ if (parse_res < 1)
{
- *errnop = ERANGE;
- return NSS_STATUS_TRYAGAIN;
- }
+ if (parse_res == -1)
+ {
+ *errnop = ERANGE;
+ return NSS_STATUS_TRYAGAIN;
+ }
- __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
@@ -389,58 +350,55 @@ _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;
}
- char buf[12 + 3 * sizeof (number) + tablename_len];
- int olderr = errno;
+ {
+ int parse_res;
+ nis_result *result;
+ char buf[100 + tablename_len];
+ int olderr = errno;
- snprintf (buf, sizeof (buf), "[number=%d],%s", number, tablename_val);
+ sprintf (buf, "[number=%d],%s", number, tablename_val);
- nis_result *result = nis_list (buf, FOLLOW_LINKS | FOLLOW_PATH | USE_DGRAM,
- NULL, NULL);
+ result = nis_list(buf, FOLLOW_LINKS | FOLLOW_PATH, NULL, NULL);
- if (result == NULL)
- {
- *errnop = ENOMEM;
- return NSS_STATUS_TRYAGAIN;
- }
+ if (result == NULL)
+ {
+ *errnop = ENOMEM;
+ return NSS_STATUS_TRYAGAIN;
+ }
+ if (niserr2nss (result->status) != NSS_STATUS_SUCCESS)
+ {
+ enum nss_status status = niserr2nss (result->status);
- 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;
- }
-
- int 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;
- }
- }
+ __set_errno (olderr);
- return NSS_STATUS_SUCCESS;
+ 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;
+ }
}
diff --git a/nis/nss_nisplus/nisplus-service.c b/nis/nss_nisplus/nisplus-service.c
index 607ce80b01..fbb6987e9e 100644
--- a/nis/nss_nisplus/nisplus-service.c
+++ b/nis/nss_nisplus/nisplus-service.c
@@ -1,5 +1,4 @@
-/* Copyright (C) 1997, 1998, 1999, 2001, 2002, 2003, 2005, 2006, 2007
- Free Software Foundation, Inc.
+/* Copyright (C) 1997,1998,1999,2001,2002,2003 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@suse.de>, 1997.
@@ -18,14 +17,13 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
-#include <atomic.h>
-#include <ctype.h>
+#include <nss.h>
#include <errno.h>
+#include <ctype.h>
#include <netdb.h>
-#include <nss.h>
#include <string.h>
-#include <rpcsvc/nis.h>
#include <bits/libc-lock.h>
+#include <rpcsvc/nis.h>
#include "nss-nisplus.h"
@@ -35,12 +33,11 @@ static nis_result *result;
static nis_name tablename_val;
static u_long tablename_len;
-#define NISENTRYVAL(idx, col, res) \
- (NIS_RES_OBJECT (res)[idx].EN_data.en_cols.en_cols_val[col].ec_value.ec_value_val)
-
-#define NISENTRYLEN(idx, col, res) \
- (NIS_RES_OBJECT (res)[idx].EN_data.en_cols.en_cols_val[col].ec_value.ec_value_len)
+#define NISENTRYVAL(idx,col,res) \
+ ((res)->objects.objects_val[(idx)].EN_data.en_cols.en_cols_val[(col)].ec_value.ec_value_val)
+#define NISENTRYLEN(idx,col,res) \
+ ((res)->objects.objects_val[(idx)].EN_data.en_cols.en_cols_val[(col)].ec_value.ec_value_len)
static int
_nss_nisplus_parse_servent (nis_result *result, struct servent *serv,
@@ -48,14 +45,17 @@ _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;
if ((result->status != NIS_SUCCESS && result->status != NIS_S_SUCCESS)
- || __type_of (NIS_RES_OBJECT (result)) != NIS_ENTRY_OBJ
- || strcmp (NIS_RES_OBJECT (result)->EN_data.en_type, "services_tbl") != 0
- || NIS_RES_OBJECT (result)->EN_data.en_cols.en_cols_len < 4)
+ || __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)
return 0;
if (NISENTRYLEN (0, 0, result) >= room_left)
@@ -68,9 +68,8 @@ _nss_nisplus_parse_servent (nis_result *result, struct servent *serv,
NISENTRYLEN (0, 0, result));
first_unused[NISENTRYLEN (0, 0, result)] = '\0';
serv->s_name = first_unused;
- size_t len = strlen (first_unused) + 1;
- room_left -= len;
- first_unused += len;
+ room_left -= (strlen (first_unused) +1);
+ first_unused += strlen (first_unused) +1;
if (NISENTRYLEN (0, 2, result) >= room_left)
goto no_more_room;
@@ -78,45 +77,40 @@ _nss_nisplus_parse_servent (nis_result *result, struct servent *serv,
NISENTRYLEN (0, 2, result));
first_unused[NISENTRYLEN (0, 2, result)] = '\0';
serv->s_proto = first_unused;
- len = strlen (first_unused) + 1;
- room_left -= len;
- first_unused += len;
+ room_left -= strlen (first_unused) + 1;
+ first_unused += strlen (first_unused) + 1;
serv->s_port = htons (atoi (NISENTRYVAL (0, 3, result)));
+ p = first_unused;
- /* XXX Rewrite at some point to allocate the array first and then
- copy the strings. It wasteful to first concatenate the strings
- to just split them again later. */
- char *line = first_unused;
- for (unsigned int i = 0; i < NIS_RES_NUMOBJ (result); ++i)
+ line = p;
+ for (i = 0; i < result->objects.objects_len; ++i)
{
if (strcmp (NISENTRYVAL (i, 1, result), serv->s_name) != 0)
{
if (NISENTRYLEN (i, 1, result) + 2 > room_left)
goto no_more_room;
- *first_unused++ = ' ';
- first_unused = __stpncpy (first_unused, NISENTRYVAL (i, 1, result),
- NISENTRYLEN (i, 1, result));
- room_left -= NISENTRYLEN (i, 1, result) + 1;
+ *p++ = ' ';
+ p = __stpncpy (p, NISENTRYVAL (i, 1, result),
+ NISENTRYLEN (i, 1, result));
+ *p = '\0';
+ room_left -= (NISENTRYLEN (i, 1, result) + 1);
}
}
- *first_unused++ = '\0';
+ *p++ = '\0';
+ first_unused = p;
/* Adjust the pointer so it is aligned for
storing pointers. */
- size_t adjust = ((__alignof__ (char *)
- - (first_unused - (char *) 0) % __alignof__ (char *))
- % __alignof__ (char *));
- if (room_left < adjust + sizeof (char *))
- goto no_more_room;
- first_unused += adjust;
- room_left -= adjust;
+ first_unused += __alignof__ (char *) - 1;
+ first_unused -= ((first_unused - (char *) 0) % __alignof__ (char *));
serv->s_aliases = (char **) first_unused;
-
- /* For the terminating NULL pointer. */
+ if (room_left < sizeof (char *))
+ goto no_more_room;
room_left -= (sizeof (char *));
+ serv->s_aliases[0] = NULL;
- unsigned int i = 0;
+ i = 0;
while (*line != '\0')
{
/* Skip leading blanks. */
@@ -130,45 +124,42 @@ _nss_nisplus_parse_servent (nis_result *result, struct servent *serv,
goto no_more_room;
room_left -= sizeof (char *);
- serv->s_aliases[i++] = line;
+ serv->s_aliases[i] = line;
while (*line != '\0' && *line != ' ')
++line;
if (*line == ' ')
- *line++ = '\0';
+ {
+ *line = '\0';
+ ++line;
+ ++i;
+ }
+ else
+ serv->s_aliases[i+1] = NULL;
}
- serv->s_aliases[i] = NULL;
return 1;
}
-
static enum nss_status
_nss_create_tablename (int *errnop)
{
if (tablename_val == NULL)
{
- const char *local_dir = nis_local_directory ();
- size_t local_dir_len = strlen (local_dir);
- static const char prefix[] = "services.org_dir.";
+ char buf [40 + strlen (nis_local_directory ())];
+ char *p;
- char *p = malloc (sizeof (prefix) + local_dir_len);
- if (p == NULL)
+ p = __stpcpy (buf, "services.org_dir.");
+ p = __stpcpy (p, nis_local_directory ());
+ tablename_val = __strdup (buf);
+ if (tablename_val == NULL)
{
*errnop = errno;
return NSS_STATUS_TRYAGAIN;
}
-
- memcpy (__stpcpy (p, prefix), local_dir, local_dir_len + 1);
-
- tablename_len = sizeof (prefix) - 1 + local_dir_len;
-
- atomic_write_barrier ();
-
- tablename_val = p;
+ tablename_len = strlen (tablename_val);
}
-
return NSS_STATUS_SUCCESS;
}
@@ -181,11 +172,9 @@ _nss_nisplus_setservent (int stayopen)
__libc_lock_lock (lock);
- if (result != NULL)
- {
- nis_freeresult (result);
- result = NULL;
- }
+ if (result)
+ nis_freeresult (result);
+ result = NULL;
if (tablename_val == NULL)
status = _nss_create_tablename (&err);
@@ -200,11 +189,9 @@ _nss_nisplus_endservent (void)
{
__libc_lock_lock (lock);
- if (result != NULL)
- {
- nis_freeresult (result);
- result = NULL;
- }
+ if (result)
+ nis_freeresult (result);
+ result = NULL;
__libc_lock_unlock (lock);
@@ -234,23 +221,16 @@ internal_nisplus_getservent_r (struct servent *serv, char *buffer,
}
result = nis_first_entry (tablename_val);
- if (result == NULL)
- {
- *errnop = errno;
- return NSS_STATUS_TRYAGAIN;
- }
if (niserr2nss (result->status) != NSS_STATUS_SUCCESS)
return niserr2nss (result->status);
}
else
{
+ nis_result *res;
+
saved_res = result;
- result = nis_next_entry (tablename_val, &result->cookie);
- if (result == NULL)
- {
- *errnop = errno;
- return NSS_STATUS_TRYAGAIN;
- }
+ res = nis_next_entry (tablename_val, &result->cookie);
+ result = res;
if (niserr2nss (result->status) != NSS_STATUS_SUCCESS)
{
nis_freeresult (saved_res);
@@ -260,7 +240,7 @@ internal_nisplus_getservent_r (struct servent *serv, char *buffer,
parse_res = _nss_nisplus_parse_servent (result, serv, buffer,
buflen, errnop);
- if (__builtin_expect (parse_res == -1, 0))
+ if (parse_res == -1)
{
nis_freeresult (result);
result = saved_res;
@@ -282,9 +262,11 @@ enum nss_status
_nss_nisplus_getservent_r (struct servent *result, char *buffer,
size_t buflen, int *errnop)
{
+ int status;
+
__libc_lock_lock (lock);
- int status = internal_nisplus_getservent_r (result, buffer, buflen, errnop);
+ status = internal_nisplus_getservent_r (result, buffer, buflen, errnop);
__libc_lock_unlock (lock);
@@ -296,14 +278,12 @@ _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;
}
@@ -313,84 +293,72 @@ _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;
- size_t protocol_len = strlen (protocol);
- char buf[strlen (name) + protocol_len + 17 + tablename_len];
- int olderr = errno;
-
- /* 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 | USE_DGRAM,
- NULL, NULL);
+ /* 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);
- 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 (NIS_RES_OBJECT (result)) != NIS_ENTRY_OBJ
- || strcmp (NIS_RES_OBJECT (result)->EN_data.en_type,
- "services_tbl") != 0
- || NIS_RES_OBJECT (result)->EN_data.en_cols.en_cols_len < 4)
- snprintf (buf, sizeof (buf), "[cname=%s,proto=%s],%s", name, protocol,
- tablename_val);
- else
+ if (result != NULL)
{
- /* 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 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 (bufptr, FOLLOW_PATH | FOLLOW_LINKS | USE_DGRAM,
- NULL, NULL);
- }
-
- if (result == NULL)
- {
- *errnop = ENOMEM;
- return NSS_STATUS_TRYAGAIN;
- }
+ nis_freeresult (result);
+ result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL);
+ }
- if (__builtin_expect (niserr2nss (result->status) != NSS_STATUS_SUCCESS, 0))
- {
- enum nss_status status = niserr2nss (result->status);
+ if (result == NULL)
+ {
+ *errnop = ENOMEM;
+ return NSS_STATUS_TRYAGAIN;
+ }
+ if (niserr2nss (result->status) != NSS_STATUS_SUCCESS)
+ {
+ enum nss_status status = niserr2nss (result->status);
- __set_errno (olderr);
+ __set_errno (olderr);
- nis_freeresult (result);
- return status;
- }
+ nis_freeresult (result);
+ return status;
+ }
- int parse_res = _nss_nisplus_parse_servent (result, serv, buffer, buflen,
+ parse_res = _nss_nisplus_parse_servent (result, serv, buffer, buflen,
errnop);
- nis_freeresult (result);
+ 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;
+ if (parse_res == -1)
+ {
+ *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
@@ -400,12 +368,8 @@ _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;
}
@@ -415,49 +379,50 @@ _nss_nisplus_getservbyport_r (const int number, const char *protocol,
*errnop = EINVAL;
return NSS_STATUS_NOTFOUND;
}
-
- char buf[17 + 3 * sizeof (int) + strlen (protocol) + tablename_len];
- int olderr = errno;
-
- snprintf (buf, sizeof (buf), "[port=%d,proto=%s],%s",
- number, protocol, tablename_val);
-
- nis_result *result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS | USE_DGRAM,
- NULL, NULL);
-
- if (result == NULL)
- {
- *errnop = ENOMEM;
- return NSS_STATUS_TRYAGAIN;
- }
-
- if (__builtin_expect (niserr2nss (result->status) != NSS_STATUS_SUCCESS, 0))
+ else
{
- enum nss_status status = niserr2nss (result->status);
+ int parse_res;
+ nis_result *result;
+ char buf[60 + strlen (protocol) + tablename_len];
+ int olderr = errno;
- __set_errno (olderr);
+ sprintf (buf, "[port=%d,proto=%s],%s",
+ number, protocol, tablename_val);
- nis_freeresult (result);
- return status;
- }
-
- int parse_res = _nss_nisplus_parse_servent (result, serv, buffer, buflen,
- errnop);
- nis_freeresult (result);
+ result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL);
- if (__builtin_expect (parse_res < 1, 0))
- {
- if (parse_res == -1)
+ if (result == NULL)
{
- *errnop = ERANGE;
+ *errnop = ENOMEM;
return NSS_STATUS_TRYAGAIN;
}
- else
+ if (niserr2nss (result->status) != NSS_STATUS_SUCCESS)
{
+ enum nss_status status = niserr2nss (result->status);
+
__set_errno (olderr);
- return NSS_STATUS_NOTFOUND;
+
+ nis_freeresult (result);
+ return status;
}
- }
- return NSS_STATUS_SUCCESS;
+ parse_res = _nss_nisplus_parse_servent (result, serv, 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-spwd.c b/nis/nss_nisplus/nisplus-spwd.c
index f256f3eb90..c317469137 100644
--- a/nis/nss_nisplus/nisplus-spwd.c
+++ b/nis/nss_nisplus/nisplus-spwd.c
@@ -1,5 +1,4 @@
-/* Copyright (C) 1997, 2001, 2002, 2003, 2005, 2007
- Free Software Foundation, Inc.
+/* Copyright (C) 1997, 2001, 2002, 2003 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
@@ -31,12 +30,29 @@
__libc_lock_define_initialized (static, lock)
static nis_result *result;
+static nis_name tablename_val;
+static u_long tablename_len;
-/* 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);
+static enum nss_status
+_nss_create_tablename (int *errnop)
+{
+ if (tablename_val == NULL)
+ {
+ char buf [40 + strlen (nis_local_directory ())];
+ char *p;
+ 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)
@@ -46,14 +62,12 @@ _nss_nisplus_setspent (int stayopen)
__libc_lock_lock (lock);
- if (result != NULL)
- {
- nis_freeresult (result);
- result = NULL;
- }
+ if (result)
+ nis_freeresult (result);
+ result = NULL;
- if (pwd_tablename_val == NULL)
- status = _nss_pwd_create_tablename (&err);
+ if (tablename_val == NULL)
+ status = _nss_create_tablename (&err);
__libc_lock_unlock (lock);
@@ -65,11 +79,9 @@ _nss_nisplus_endspent (void)
{
__libc_lock_lock (lock);
- if (result != NULL)
- {
- nis_freeresult (result);
- result = NULL;
- }
+ if (result)
+ nis_freeresult (result);
+ result = NULL;
__libc_lock_unlock (lock);
@@ -91,32 +103,25 @@ internal_nisplus_getspent_r (struct spwd *sp, char *buffer, size_t buflen,
{
saved_res = NULL;
- if (pwd_tablename_val == NULL)
+ if (tablename_val == NULL)
{
- enum nss_status status = _nss_pwd_create_tablename (errnop);
+ enum nss_status status = _nss_create_tablename (errnop);
if (status != NSS_STATUS_SUCCESS)
return status;
}
- result = nis_first_entry (pwd_tablename_val);
- if (result == NULL)
- {
- *errnop = errno;
- return NSS_STATUS_TRYAGAIN;
- }
+ result = nis_first_entry (tablename_val);
if (niserr2nss (result->status) != NSS_STATUS_SUCCESS)
return niserr2nss (result->status);
}
else
{
+ nis_result *res;
+
saved_res = result;
- result = nis_next_entry (pwd_tablename_val, &result->cookie);
- if (result == NULL)
- {
- *errnop = errno;
- return NSS_STATUS_TRYAGAIN;
- }
+ res = nis_next_entry (tablename_val, &result->cookie);
+ result = res;
if (niserr2nss (result->status) != NSS_STATUS_SUCCESS)
{
nis_freeresult (saved_res);
@@ -126,18 +131,19 @@ internal_nisplus_getspent_r (struct spwd *sp, char *buffer, size_t buflen,
parse_res = _nss_nisplus_parse_spent (result, sp, buffer,
buflen, errnop);
- if (__builtin_expect (parse_res == -1, 0))
+ if (parse_res == -1)
{
nis_freeresult (result);
result = saved_res;
*errnop = ERANGE;
return NSS_STATUS_TRYAGAIN;
}
-
- if (saved_res != NULL)
- nis_freeresult (saved_res);
- }
- while (!parse_res);
+ else
+ {
+ if (saved_res)
+ nis_freeresult (saved_res);
+ }
+ } while (!parse_res);
return NSS_STATUS_SUCCESS;
}
@@ -163,9 +169,9 @@ _nss_nisplus_getspnam_r (const char *name, struct spwd *sp,
{
int parse_res;
- if (pwd_tablename_val == NULL)
+ if (tablename_val == NULL)
{
- enum nss_status status = _nss_pwd_create_tablename (errnop);
+ enum nss_status status = _nss_create_tablename (errnop);
if (status != NSS_STATUS_SUCCESS)
return status;
@@ -176,47 +182,48 @@ _nss_nisplus_getspnam_r (const char *name, struct spwd *sp,
*errnop = EINVAL;
return NSS_STATUS_NOTFOUND;
}
-
- nis_result *result;
- char buf[strlen (name) + 9 + pwd_tablename_len];
- int olderr = errno;
-
- snprintf (buf, sizeof (buf), "[name=%s],%s", name, pwd_tablename_val);
-
- result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS | USE_DGRAM, NULL, NULL);
-
- if (result == NULL)
- {
- *errnop = ENOMEM;
- return NSS_STATUS_TRYAGAIN;
- }
-
- if (__builtin_expect (niserr2nss (result->status) != NSS_STATUS_SUCCESS, 0))
+ else
{
- enum nss_status status = niserr2nss (result->status);
+ nis_result *result;
+ char buf[strlen (name) + 24 + tablename_len];
+ int olderr = errno;
- __set_errno (olderr);
+ sprintf (buf, "[name=%s],%s", name, tablename_val);
- nis_freeresult (result);
- return status;
- }
+ result = nis_list (buf, FOLLOW_PATH | FOLLOW_LINKS, NULL, NULL);
- 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 (result == NULL)
{
- *errnop = ERANGE;
+ *errnop = ENOMEM;
return NSS_STATUS_TRYAGAIN;
}
- else
+ if (niserr2nss (result->status) != NSS_STATUS_SUCCESS)
{
+ enum nss_status status = niserr2nss (result->status);
+
__set_errno (olderr);
- return NSS_STATUS_NOTFOUND;
+
+ nis_freeresult (result);
+ return status;
}
- }
- return NSS_STATUS_SUCCESS;
+ parse_res = _nss_nisplus_parse_spent (result, sp, 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/rpcsvc/nislib.h b/nis/rpcsvc/nislib.h
index c8927ece17..a55de61830 100644
--- a/nis/rpcsvc/nislib.h
+++ b/nis/rpcsvc/nislib.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997, 1998, 1999, 2006, 2007 Free Software Foundation, Inc.
+/* Copyright (C) 1997, 1998, 1999 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@suse.de>, 1997.
@@ -272,13 +272,11 @@ struct dir_binding
typedef struct dir_binding dir_binding;
extern nis_error __nisbind_create (dir_binding *, const nis_server *,
- unsigned int, unsigned int, unsigned int,
- unsigned int) __THROW;
+ unsigned int, unsigned int) __THROW;
extern nis_error __nisbind_connect (dir_binding *) __THROW;
extern nis_error __nisbind_next (dir_binding *) __THROW;
extern void __nisbind_destroy (dir_binding *) __THROW;
-extern nis_error __nisfind_server (const_nis_name, int, directory_obj **,
- dir_binding *, unsigned int) __THROW;
+extern nis_error __nisfind_server (const_nis_name, directory_obj **) __THROW;
#endif
diff --git a/nis/yp_xdr.c b/nis/yp_xdr.c
index b87ee06151..0ee80126e8 100644
--- a/nis/yp_xdr.c
+++ b/nis/yp_xdr.c
@@ -103,7 +103,6 @@ xdr_ypreq_key (XDR *xdrs, ypreq_key *objp)
return FALSE;
return xdr_keydat (xdrs, &objp->key);
}
-libnsl_hidden_def (xdr_ypreq_key)
bool_t
xdr_ypreq_nokey (XDR *xdrs, ypreq_nokey *objp)
@@ -112,7 +111,6 @@ xdr_ypreq_nokey (XDR *xdrs, ypreq_nokey *objp)
return FALSE;
return xdr_mapname (xdrs, &objp->map);
}
-libnsl_hidden_def (xdr_ypreq_nokey)
bool_t
xdr_ypreq_xfr (XDR *xdrs, ypreq_xfr *objp)
@@ -133,7 +131,6 @@ xdr_ypresp_val (XDR *xdrs, ypresp_val *objp)
return FALSE;
return xdr_valdat (xdrs, &objp->val);
}
-libnsl_hidden_def (xdr_ypresp_val)
bool_t
xdr_ypresp_key_val (XDR *xdrs, ypresp_key_val *objp)
@@ -153,7 +150,6 @@ xdr_ypresp_master (XDR *xdrs, ypresp_master *objp)
return FALSE;
return xdr_peername (xdrs, &objp->peer);
}
-libnsl_hidden_def (xdr_ypresp_master)
bool_t
xdr_ypresp_order (XDR *xdrs, ypresp_order *objp)
@@ -162,7 +158,6 @@ xdr_ypresp_order (XDR *xdrs, ypresp_order *objp)
return FALSE;
return xdr_u_int (xdrs, &objp->ordernum);
}
-libnsl_hidden_def (xdr_ypresp_order)
bool_t
xdr_ypresp_all (XDR *xdrs, ypresp_all *objp)
@@ -198,7 +193,6 @@ xdr_ypmaplist (XDR *xdrs, ypmaplist *objp)
return xdr_pointer (xdrs, (char **) &objp->next, sizeof (ypmaplist),
(xdrproc_t) xdr_ypmaplist);
}
-libnsl_hidden_def (xdr_ypmaplist)
bool_t
xdr_ypresp_maplist (XDR *xdrs, ypresp_maplist *objp)
@@ -208,7 +202,6 @@ xdr_ypresp_maplist (XDR *xdrs, ypresp_maplist *objp)
return xdr_pointer (xdrs, (char **) &objp->maps, sizeof (ypmaplist),
(xdrproc_t) xdr_ypmaplist);
}
-libnsl_hidden_def (xdr_ypresp_maplist)
bool_t
xdr_yppush_status (XDR *xdrs, yppush_status *objp)
@@ -255,7 +248,6 @@ xdr_ypbind_resp (XDR *xdrs, ypbind_resp *objp)
}
return FALSE;
}
-libnsl_hidden_def (xdr_ypbind_resp)
bool_t
xdr_ypbind_setdom (XDR *xdrs, ypbind_setdom *objp)
diff --git a/nis/ypclnt.c b/nis/ypclnt.c
index ae04ee9212..85292b62d9 100644
--- a/nis/ypclnt.c
+++ b/nis/ypclnt.c
@@ -1,5 +1,4 @@
-/* Copyright (C) 1996-2001, 2002, 2003, 2004, 2005, 2006
- Free Software Foundation, Inc.
+/* Copyright (C) 1996-2001, 2002, 2003, 2004 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Thorsten Kukuk <kukuk@suse.de>, 1996.
@@ -46,12 +45,12 @@ struct dom_binding
};
typedef struct dom_binding dom_binding;
-static const struct timeval RPCTIMEOUT = {25, 0};
-static const struct timeval UDPTIMEOUT = {5, 0};
+static struct timeval RPCTIMEOUT = {25, 0};
+static struct timeval UDPTIMEOUT = {5, 0};
static int const MAXTRIES = 2;
-static char ypdomainname[NIS_MAXNAMELEN + 1];
+static char __ypdomainname[NIS_MAXNAMELEN + 1] = "\0";
__libc_lock_define_initialized (static, ypbindlist_lock)
-static dom_binding *ypbindlist = NULL;
+static dom_binding *__ypbindlist = NULL;
static void
@@ -111,8 +110,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 +141,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 +224,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 +238,7 @@ yp_unbind_locked (const char *indomain)
dom_binding *ydbptr, *ydbptr2;
ydbptr2 = NULL;
- ydbptr = ypbindlist;
+ ydbptr = __ypbindlist;
while (ydbptr != NULL)
{
@@ -249,7 +248,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 +305,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 +348,7 @@ do_ypcall (const char *domain, u_long prog, xdrproc_t xargs,
if (status != YPERR_SUCCESS)
{
ydb = calloc (1, sizeof (dom_binding));
- if (ydb != NULL && yp_bind_ypbindprog (domain, ydb) == YPERR_SUCCESS)
+ if (yp_bind_ypbindprog (domain, ydb) == YPERR_SUCCESS)
{
status = __ypclnt_call (domain, prog, xargs, req, xres,
resp, &ydb, 1);
@@ -365,21 +364,6 @@ 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)
@@ -391,21 +375,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);
@@ -418,14 +402,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;
}
@@ -452,26 +436,25 @@ yp_match (const char *indomain, const char *inmap, const char *inkey,
*outvallen = 0;
memset (&resp, '\0', sizeof (resp));
- result = do_ypcall_tr (indomain, YPPROC_MATCH, (xdrproc_t) xdr_ypreq_key,
- (caddr_t) &req, (xdrproc_t) xdr_ypresp_val,
- (caddr_t) &resp);
+ result = do_ypcall (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);
- int status = YPERR_RESRC;
- if (__builtin_expect (*outval != NULL, 1))
- {
- memcpy (*outval, resp.val.valdat_val, *outvallen);
- (*outval)[*outvallen] = '\0';
- status = YPERR_SUCCESS;
- }
+ if (__builtin_expect (*outval == NULL, 0))
+ return YPERR_RESRC;
+ memcpy (*outval, resp.val.valdat_val, *outvallen);
+ (*outval)[*outvallen] = '\0';
xdr_free ((xdrproc_t) xdr_ypresp_val, (char *) &resp);
- return status;
+ return YPERR_SUCCESS;
}
int
@@ -494,38 +477,30 @@ 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);
- 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;
- }
+ *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';
xdr_free ((xdrproc_t) xdr_ypresp_key_val, (char *) &resp);
- return status;
+ return YPERR_SUCCESS;
}
int
@@ -551,37 +526,31 @@ yp_next (const char *indomain, const char *inmap, const char *inkey,
*outkeylen = *outvallen = 0;
memset (&resp, '\0', sizeof (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);
+ result = do_ypcall (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);
- 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;
- }
+ *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';
xdr_free ((xdrproc_t) xdr_ypresp_key_val, (char *) &resp);
- return status;
+ return YPERR_SUCCESS;
}
int
@@ -600,12 +569,13 @@ yp_master (const char *indomain, const char *inmap, char **outname)
memset (&resp, '\0', sizeof (ypresp_master));
- result = do_ypcall_tr (indomain, YPPROC_MASTER, (xdrproc_t) xdr_ypreq_nokey,
- (caddr_t) &req, (xdrproc_t) xdr_ypresp_master,
- (caddr_t) &resp);
+ result = do_ypcall (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);
@@ -622,7 +592,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] == '\0')
+ inmap == NULL || inmap == '\0')
return YPERR_BADARGS;
req.domain = (char *) indomain;
@@ -630,17 +600,18 @@ yp_order (const char *indomain, const char *inmap, unsigned int *outorder)
memset (&resp, '\0', sizeof (resp));
- result = do_ypcall_tr (indomain, YPPROC_ORDER, (xdrproc_t) xdr_ypreq_nokey,
- (caddr_t) &req, (xdrproc_t) xdr_ypresp_order,
- (caddr_t) &resp);
+ result = do_ypcall (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 result;
+ return YPERR_SUCCESS;
}
struct ypresp_all_data
@@ -686,10 +657,10 @@ __xdr_ypresp_all (XDR *xdrs, struct ypresp_all_data *objp)
if we don't modify the length. So add an extra NUL
character to avoid trouble with broken code. */
objp->status = YP_TRUE;
- *((char *) __mempcpy (key, resp.ypresp_all_u.val.key.keydat_val,
- keylen)) = '\0';
- *((char *) __mempcpy (val, resp.ypresp_all_u.val.val.valdat_val,
- vallen)) = '\0';
+ memcpy (key, resp.ypresp_all_u.val.key.keydat_val, keylen);
+ key[keylen] = '\0';
+ memcpy (val, resp.ypresp_all_u.val.val.valdat_val, vallen);
+ val[vallen] = '\0';
xdr_free ((xdrproc_t) xdr_ypresp_all, (char *) &resp);
if ((*objp->foreach) (objp->status, key, keylen,
val, vallen, objp->data))
@@ -700,7 +671,7 @@ __xdr_ypresp_all (XDR *xdrs, struct ypresp_all_data *objp)
objp->status = resp.ypresp_all_u.val.stat;
xdr_free ((xdrproc_t) xdr_ypresp_all, (char *) &resp);
/* Sun says we don't need to make this call, but must return
- immediately. Since Solaris makes this call, we will call
+ immediatly. Since Solaris makes this call, we will call
the callback function, too. */
(*objp->foreach) (objp->status, NULL, 0, NULL, 0, objp->data);
return TRUE;
@@ -722,8 +693,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] == '\0')
+ if (indomain == NULL || indomain[0] == '\0' ||
+ inmap == NULL || inmap == '\0')
return YPERR_BADARGS;
try = 0;
@@ -761,9 +732,9 @@ yp_all (const char *indomain, const char *inmap,
(caddr_t) &req, (xdrproc_t) __xdr_ypresp_all,
(caddr_t) &data, RPCTIMEOUT);
- if (__builtin_expect (result != RPC_SUCCESS, 0))
+ if (result != RPC_SUCCESS)
{
- /* 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;
@@ -787,7 +758,6 @@ yp_all (const char *indomain, const char *inmap,
}
int
-
yp_maplist (const char *indomain, struct ypmaplist **outmaplist)
{
struct ypresp_maplist resp;
@@ -798,92 +768,67 @@ yp_maplist (const char *indomain, struct ypmaplist **outmaplist)
memset (&resp, '\0', sizeof (resp));
- result = do_ypcall_tr (indomain, YPPROC_MAPLIST, (xdrproc_t) xdr_domainname,
- (caddr_t) &indomain, (xdrproc_t) xdr_ypresp_maplist,
- (caddr_t) &resp);
+ result = do_ypcall (indomain, YPPROC_MAPLIST, (xdrproc_t) xdr_domainname,
+ (caddr_t) & indomain, (xdrproc_t) xdr_ypresp_maplist, (caddr_t) & 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); */
- }
+ if (result != YPERR_SUCCESS)
+ return result;
+ if (resp.stat != YP_TRUE)
+ return ypprot_err (resp.stat);
- return result;
+ *outmaplist = resp.maps;
+ /* We give the list not free, this will be done by ypserv
+ xdr_free((xdrproc_t)xdr_ypresp_maplist, (char *)&resp); */
+
+ return YPERR_SUCCESS;
}
const char *
yperr_string (const int error)
{
- const char *str;
switch (error)
{
case YPERR_SUCCESS:
- str = N_("Success");
- break;
+ return _("Success");
case YPERR_BADARGS:
- str = N_("Request arguments bad");
- break;
+ return _("Request arguments bad");
case YPERR_RPC:
- str = N_("RPC failure on NIS operation");
- break;
+ return _("RPC failure on NIS operation");
case YPERR_DOMAIN:
- str = N_("Can't bind to server which serves this domain");
- break;
+ return _("Can't bind to server which serves this domain");
case YPERR_MAP:
- str = N_("No such map in server's domain");
- break;
+ return _("No such map in server's domain");
case YPERR_KEY:
- str = N_("No such key in map");
- break;
+ return _("No such key in map");
case YPERR_YPERR:
- str = N_("Internal NIS error");
- break;
+ return _("Internal NIS error");
case YPERR_RESRC:
- str = N_("Local resource allocation failure");
- break;
+ return _("Local resource allocation failure");
case YPERR_NOMORE:
- str = N_("No more records in map database");
- break;
+ return _("No more records in map database");
case YPERR_PMAP:
- str = N_("Can't communicate with portmapper");
- break;
+ return _("Can't communicate with portmapper");
case YPERR_YPBIND:
- str = N_("Can't communicate with ypbind");
- break;
+ return _("Can't communicate with ypbind");
case YPERR_YPSERV:
- str = N_("Can't communicate with ypserv");
- break;
+ return _("Can't communicate with ypserv");
case YPERR_NODOM:
- str = N_("Local domain name not set");
- break;
+ return _("Local domain name not set");
case YPERR_BADDB:
- str = N_("NIS map database is bad");
- break;
+ return _("NIS map database is bad");
case YPERR_VERS:
- str = N_("NIS client/server version mismatch - can't supply service");
- break;
+ return _("NIS client/server version mismatch - can't supply service");
case YPERR_ACCESS:
- str = N_("Permission denied");
- break;
+ return _("Permission denied");
case YPERR_BUSY:
- str = N_("Database is busy");
- break;
- default:
- str = N_("Unknown NIS error code");
- break;
+ return _("Database is busy");
}
- return _(str);
+ return _("Unknown NIS error code");
}
static const int8_t yp_2_yperr[] =
{
#define YP2YPERR(yp, yperr) [YP_##yp - YP_VERS] = YPERR_##yperr
- YP2YPERR (TRUE, SUCCESS),
- YP2YPERR (NOMORE, NOMORE),
- YP2YPERR (FALSE, YPERR),
- YP2YPERR (NOMAP, MAP),
- YP2YPERR (NODOM, DOMAIN),
YP2YPERR (NOKEY, KEY),
YP2YPERR (BADOP, YPERR),
YP2YPERR (BADDB, BADDB),
@@ -894,7 +839,7 @@ static const int8_t yp_2_yperr[] =
int
ypprot_err (const int code)
{
- if (code < YP_VERS || code > YP_NOMORE)
+ if (code < YP_VERS || code > YP_NOKEY)
return YPERR_YPERR;
return yp_2_yperr[code - YP_VERS];
}
@@ -903,26 +848,19 @@ libnsl_hidden_def (ypprot_err)
const char *
ypbinderr_string (const int error)
{
- const char *str;
switch (error)
{
case 0:
- str = N_("Success");
- break;
+ return _("Success");
case YPBIND_ERR_ERR:
- str = N_("Internal ypbind error");
- break;
+ return _("Internal ypbind error");
case YPBIND_ERR_NOSERV:
- str = N_("Domain not bound");
- break;
+ return _("Domain not bound");
case YPBIND_ERR_RESC:
- str = N_("System resource allocation failure");
- break;
+ return _("System resource allocation failure");
default:
- str = N_("Unknown ypbind error");
- break;
+ return _("Unknown ypbind error");
}
- return _(str);
}
libnsl_hidden_def (ypbinderr_string)
@@ -955,22 +893,16 @@ yp_update (char *domain, char *map, unsigned ypop,
args.update_args.datum.yp_buf_len = datalen;
args.update_args.datum.yp_buf_val = data;
- if ((r = yp_master (domain, map, &master)) != YPERR_SUCCESS)
+ if ((r = yp_master (domain, map, &master)) != 0)
return r;
if (!host2netname (servername, master, domain))
{
fputs (_("yp_update: cannot convert host to netname\n"), stderr);
- free (master);
return YPERR_YPERR;
}
- clnt = clnt_create (master, YPU_PROG, YPU_VERS, "tcp");
-
- /* We do not need the string anymore. */
- free (master);
-
- if (clnt == NULL)
+ if ((clnt = clnt_create (master, YPU_PROG, YPU_VERS, "tcp")) == NULL)
{
clnt_pcreateerror ("yp_update: clnt_create");
return YPERR_RPC;
@@ -1010,7 +942,6 @@ again:
{
if (clnt->cl_auth->ah_cred.oa_flavor == AUTH_DES)
{
- auth_destroy (clnt->cl_auth);
clnt->cl_auth = authunix_create_default ();
goto again;
}
diff --git a/nis/ypupdate_xdr.c b/nis/ypupdate_xdr.c
index 0f5469fa23..4789e47c3e 100644
--- a/nis/ypupdate_xdr.c
+++ b/nis/ypupdate_xdr.c
@@ -50,7 +50,6 @@ xdr_ypupdate_args (XDR *xdrs, ypupdate_args *objp)
return FALSE;
return xdr_yp_buf (xdrs, &objp->datum);
}
-libnsl_hidden_def (xdr_ypupdate_args)
bool_t
xdr_ypdelete_args (XDR *xdrs, ypdelete_args *objp)
@@ -59,4 +58,3 @@ xdr_ypdelete_args (XDR *xdrs, ypdelete_args *objp)
return FALSE;
return xdr_yp_buf (xdrs, &objp->key);
}
-libnsl_hidden_def (xdr_ypdelete_args)