about summary refs log tree commit diff
path: root/nis/nss_nisplus
diff options
context:
space:
mode:
Diffstat (limited to 'nis/nss_nisplus')
-rw-r--r--nis/nss_nisplus/nisplus-alias.c57
-rw-r--r--nis/nss_nisplus/nisplus-ethers.c40
-rw-r--r--nis/nss_nisplus/nisplus-hosts.c88
-rw-r--r--nis/nss_nisplus/nisplus-netgrp.c10
-rw-r--r--nis/nss_nisplus/nisplus-network.c67
-rw-r--r--nis/nss_nisplus/nisplus-parser.c59
-rw-r--r--nis/nss_nisplus/nisplus-proto.c64
-rw-r--r--nis/nss_nisplus/nisplus-publickey.c35
-rw-r--r--nis/nss_nisplus/nisplus-rpc.c70
-rw-r--r--nis/nss_nisplus/nisplus-service.c78
10 files changed, 296 insertions, 272 deletions
diff --git a/nis/nss_nisplus/nisplus-alias.c b/nis/nss_nisplus/nisplus-alias.c
index d7926e1566..57858721a1 100644
--- a/nis/nss_nisplus/nisplus-alias.c
+++ b/nis/nss_nisplus/nisplus-alias.c
@@ -36,11 +36,11 @@ static u_long next_entry;
 static nis_name tablename_val;
 static size_t tablename_len;
 
-#define NISENTRYVAL(idx,col,res) \
-        ((res)->objects.objects_val[(idx)].EN_data.en_cols.en_cols_val[(col)].ec_value.ec_value_val)
+#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) \
-        ((res)->objects.objects_val[(idx)].EN_data.en_cols.en_cols_val[(col)].ec_value.ec_value_len)
+#define NISENTRYLEN(idx, col, res) \
+        (NIS_RES_OBJECT (res)[idx].EN_data.en_cols.en_cols_val[col].ec_value.ec_value_len)
 
 static enum nss_status
 _nss_create_tablename (int *errnop)
@@ -79,16 +79,12 @@ _nss_nisplus_parse_aliasent (nis_result *result, unsigned long entry,
     return 0;
 
   if ((result->status != NIS_SUCCESS && result->status != NIS_S_SUCCESS)
-      || __type_of (&result->objects.objects_val[entry]) != NIS_ENTRY_OBJ
-      || strcmp (result->objects.objects_val[entry].EN_data.en_type,
+      || __type_of (&NIS_RES_OBJECT (result)[entry]) != NIS_ENTRY_OBJ
+      || strcmp (NIS_RES_OBJECT (result)[entry].EN_data.en_type,
 		 "mail_aliases") != 0
-      || result->objects.objects_val[entry].EN_data.en_cols.en_cols_len < 2)
+      || NIS_RES_OBJECT (result)[entry].EN_data.en_cols.en_cols_len < 2)
     return 0;
 
-  char *first_unused = buffer + NISENTRYLEN (0, 1, result) + 1;
-  size_t room_left = (buflen - (buflen % __alignof__ (char *))
-		      - NISENTRYLEN (0, 1, result) - 2);
-
   if (NISENTRYLEN (entry, 1, result) >= buflen)
     {
       /* The line is too long for our buffer.  */
@@ -101,13 +97,15 @@ _nss_nisplus_parse_aliasent (nis_result *result, unsigned long entry,
 			NISENTRYLEN (entry, 1, result));
   *cp = '\0';
 
-  if (NISENTRYLEN(entry, 0, result) >= room_left)
-    goto no_more_room;
+  char *first_unused = cp + 1;
+  size_t room_left = buflen - (first_unused - buffer);
 
   alias->alias_local = 0;
   alias->alias_members_len = 0;
-  *first_unused = '\0';
-  ++first_unused;
+
+  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';
@@ -118,11 +116,20 @@ _nss_nisplus_parse_aliasent (nis_result *result, unsigned long entry,
   if (cp != NULL)
     *cp = '\0';
 
-  first_unused += strlen (alias->alias_name) +1;
+  size_t len = strlen (alias->alias_name) + 1;
+  first_unused += len;
+  room_left -= len;
+
   /* Adjust the pointer so it is aligned for
      storing pointers.  */
-  first_unused += __alignof__ (char *) - 1;
-  first_unused -= ((first_unused - (char *) 0) % __alignof__ (char *));
+  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;
@@ -146,8 +153,10 @@ _nss_nisplus_parse_aliasent (nis_result *result, unsigned long entry,
       if (line != alias->alias_members[alias->alias_members_len])
 	{
 	  *line++ = '\0';
-	  alias->alias_members_len++;
+	  ++alias->alias_members_len;
 	}
+      else if (*line == ',')
+	++line;
     }
 
   return alias->alias_members_len == 0 ? 0 : 1;
@@ -304,10 +313,18 @@ _nss_nisplus_getaliasbyname_r (const char *name, struct aliasent *alias,
     }
 
   if (__builtin_expect (niserr2nss (result->status) != NSS_STATUS_SUCCESS, 0))
-    return niserr2nss (result->status);
+    {
+      enum nss_status status = niserr2nss (result->status);
+      nis_freeresult (result);
+      return status;
+    }
 
   parse_res = _nss_nisplus_parse_aliasent (result, 0, alias,
 					   buffer, buflen, errnop);
+
+  /* We do not need the lookup result anymore.  */
+  nis_freeresult (result);
+
   if (__builtin_expect (parse_res < 1, 0))
     {
       __set_errno (olderr);
diff --git a/nis/nss_nisplus/nisplus-ethers.c b/nis/nss_nisplus/nisplus-ethers.c
index ca0a9e2481..2620427243 100644
--- a/nis/nss_nisplus/nisplus-ethers.c
+++ b/nis/nss_nisplus/nisplus-ethers.c
@@ -38,11 +38,11 @@ static nis_name tablename_val;
 static u_long tablename_len;
 
 
-#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 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 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)
+#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)
 
 static int
 _nss_nisplus_parse_etherent (nis_result *result, struct etherent *ether,
@@ -55,7 +55,7 @@ _nss_nisplus_parse_etherent (nis_result *result, struct etherent *ether,
     return 0;
 
   if ((result->status != NIS_SUCCESS && result->status != NIS_S_SUCCESS)
-      || result->objects.objects_len != 1
+      || NIS_RES_NUMOBJ (result) != 1
       || __type_of (NIS_RES_OBJECT (result)) != NIS_ENTRY_OBJ
       || strcmp (NIS_RES_OBJECT (result)->EN_data.en_type,
 		 "ethers_tbl") != 0
@@ -63,13 +63,15 @@ _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;
     }
-  strncpy (p, NISENTRYVAL (0, 0, result), NISENTRYLEN (0, 0, result));
-  room_left -= (NISENTRYLEN (0, 0, result) +1);
+  char *cp = __stpncpy (p, NISENTRYVAL (0, 0, result),
+			NISENTRYLEN (0, 0, result));
+  *cp = '\0';
+  room_left -= NISENTRYLEN (0, 0, result) + 1;
   ether->e_name = p;
 
   struct ether_addr *ea = ether_aton (NISENTRYVAL (0, 1, result));
@@ -261,17 +263,18 @@ _nss_nisplus_gethostton_r (const char *name, struct etherent *eth,
 
   int parse_res = _nss_nisplus_parse_etherent (result, eth, buffer,
 					       buflen, errnop);
+
+  /* We do not need the lookup result anymore.  */
+  nis_freeresult (result);
+
   if (__builtin_expect (parse_res < 1, 0))
     {
       __set_errno (olderr);
 
       if (parse_res == -1)
-	{
-	  nis_freeresult (result);
-	  return NSS_STATUS_TRYAGAIN;
-	}
-      else
-	return NSS_STATUS_NOTFOUND;
+	return NSS_STATUS_TRYAGAIN;
+
+      return NSS_STATUS_NOTFOUND;
     }
 
   return NSS_STATUS_SUCCESS;
@@ -326,13 +329,14 @@ _nss_nisplus_getntohost_r (const struct ether_addr *addr, struct etherent *eth,
 
   int parse_res = _nss_nisplus_parse_etherent (result, eth, buffer,
 					       buflen, errnop);
+
+  /* We do not need the lookup result anymore.  */
+  nis_freeresult (result);
+
   if (__builtin_expect (parse_res < 1, 0))
     {
       if (parse_res == -1)
-	{
-	  nis_freeresult (result);
-	  return NSS_STATUS_TRYAGAIN;
-	}
+	return NSS_STATUS_TRYAGAIN;
 
       return NSS_STATUS_NOTFOUND;
     }
diff --git a/nis/nss_nisplus/nisplus-hosts.c b/nis/nss_nisplus/nisplus-hosts.c
index bf002d6dd7..023e18f93d 100644
--- a/nis/nss_nisplus/nisplus-hosts.c
+++ b/nis/nss_nisplus/nisplus-hosts.c
@@ -36,15 +36,16 @@ static nis_result *result;
 static nis_name tablename_val;
 static u_long tablename_len;
 
-#define NISENTRYVAL(idx,col,res) \
-        ((res)->objects.objects_val[(idx)].EN_data.en_cols.en_cols_val[(col)].ec_value.ec_value_val)
+#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) \
-        ((res)->objects.objects_val[(idx)].EN_data.en_cols.en_cols_val[(col)].ec_value.ec_value_len)
+#define NISENTRYLEN(idx, col, res) \
+        (NIS_RES_OBJECT (res)[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,
@@ -53,27 +54,26 @@ _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 (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)
+      __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)
     return 0;
 
-  if (room_left < NISENTRYLEN (0, 2, result) + 1)
+  char *data = first_unused;
+
+  if (room_left < (af == AF_INET6 || (flags & AI_V4MAPPED) != 0
+		   ? IN6ADDRSZ : INADDRSZ))
     {
     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,51 +99,53 @@ _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 += NISENTRYLEN (0, 0, result) +1;
-  p = first_unused;
-
-  line = p;
-  for (i = 0; i < result->objects.objects_len; ++i)
+  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)
     {
       if (strcmp (NISENTRYVAL (i, 1, result), host->h_name) != 0)
 	{
 	  if (NISENTRYLEN (i, 1, result) + 2 > room_left)
 	    goto no_more_room;
 
-	  *p++ = ' ';
-	  p = __stpncpy (p, NISENTRYVAL (i, 1, result),
-			 NISENTRYLEN (i, 1, result));
-	  *p = '\0';
-	  room_left -= (NISENTRYLEN (i, 1, result) + 1);
+	  *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++ = '\0';
-  first_unused = p;
+  *first_unused++ = '\0';
 
   /* Adjust the pointer so it is aligned for
      storing pointers.  */
-  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 *))
+  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;
+  host->h_addr_list = (char **) first_unused;
 
-  room_left -= (2 * sizeof (char *));
+  room_left -= 3 * 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')
@@ -159,23 +161,21 @@ _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;
-	  ++i;
-	}
-      else
-	host->h_aliases[i+1] = NULL;
+	*line++ = '\0';
     }
+
+  host->h_aliases[i] = NULL;
+
   return 1;
 }
 
+
 static enum nss_status
 _nss_create_tablename (int *errnop)
 {
diff --git a/nis/nss_nisplus/nisplus-netgrp.c b/nis/nss_nisplus/nisplus-netgrp.c
index 31a8cdf097..24303b1474 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 Free Software Foundation, Inc.
+/* Copyright (C) 1997, 2003, 2004, 2005, 2006 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) \
-        ((res)->objects.objects_val[(idx)].EN_data.en_cols.en_cols_val[(col)].ec_value.ec_value_val)
+#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) \
-        ((res)->objects.objects_val[(idx)].EN_data.en_cols.en_cols_val[(col)].ec_value.ec_value_len)
+#define NISENTRYLEN(idx, col, res) \
+        (NIS_RES_OBJECT (res)[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,
diff --git a/nis/nss_nisplus/nisplus-network.c b/nis/nss_nisplus/nisplus-network.c
index 960c0558e9..468520c937 100644
--- a/nis/nss_nisplus/nisplus-network.c
+++ b/nis/nss_nisplus/nisplus-network.c
@@ -36,11 +36,11 @@ static nis_result *result;
 static nis_name tablename_val;
 static u_long tablename_len;
 
-#define NISENTRYVAL(idx,col,res) \
-        ((res)->objects.objects_val[(idx)].EN_data.en_cols.en_cols_val[(col)].ec_value.ec_value_val)
+#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) \
-        ((res)->objects.objects_val[(idx)].EN_data.en_cols.en_cols_val[(col)].ec_value.ec_value_len)
+#define NISENTRYLEN(idx, col, res) \
+        (NIS_RES_OBJECT (res)[idx].EN_data.en_cols.en_cols_val[col].ec_value.ec_value_len)
 
 
 static int
@@ -54,10 +54,10 @@ _nss_nisplus_parse_netent (nis_result *result, struct netent *network,
     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[0].EN_data.en_type,
+      || __type_of (NIS_RES_OBJECT (result)) != NIS_ENTRY_OBJ
+      || strcmp (NIS_RES_OBJECT (result)[0].EN_data.en_type,
 		 "networks_tbl") != 0
-      || result->objects.objects_val[0].EN_data.en_cols.en_cols_len < 3)
+      || NIS_RES_OBJECT (result)[0].EN_data.en_cols.en_cols_len < 3)
     return 0;
 
   if (NISENTRYLEN (0, 0, result) >= room_left)
@@ -72,39 +72,45 @@ _nss_nisplus_parse_netent (nis_result *result, struct netent *network,
            NISENTRYLEN (0, 0, result));
   first_unused[NISENTRYLEN (0, 0, result)] = '\0';
   network->n_name = first_unused;
-  room_left -= (strlen (first_unused) +1);
-  first_unused += strlen (first_unused) +1;
+  size_t len = strlen (first_unused) + 1;
+  room_left -= len;
+  first_unused += len;
+
   network->n_addrtype = 0;
   network->n_net = inet_network (NISENTRYVAL (0, 2, result));
-  char *p = first_unused;
 
-  char *line = p;
-  for (unsigned int i = 0; i < result->objects.objects_len; ++i)
+  /* 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)
     {
       if (strcmp (NISENTRYVAL (i, 1, result), network->n_name) != 0)
         {
           if (NISENTRYLEN (i, 1, result) + 2 > room_left)
 	    goto no_more_room;
 
-	  *p++ = ' ';
-          p = __stpncpy (p, NISENTRYVAL (i, 1, result),
-			 NISENTRYLEN (i, 1, result));
-          *p = '\0';
+	  *first_unused++ = ' ';
+          first_unused = __stpncpy (first_unused, NISENTRYVAL (i, 1, result),
+				    NISENTRYLEN (i, 1, result));
           room_left -= (NISENTRYLEN (i, 1, result) + 1);
         }
     }
-  *p++ = '\0';
-  first_unused = p;
+  *first_unused++ = '\0';
 
   /* Adjust the pointer so it is aligned for
      storing pointers.  */
-  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 *))
+  size_t adjust = ((__alignof__ (char *)
+		    - (first_unused - (char *) 0) % __alignof__ (char *))
+		   % __alignof__ (char *));
+  if (room_left < adjust + sizeof (char *))
     goto no_more_room;
-  room_left -= (2 * sizeof (char *));
-  network->n_aliases[0] = NULL;
+  first_unused += adjust;
+  room_left -= adjust;
+  network->n_aliases = (char **) first_unused;
+
+  /* For the terminating NULL pointer.  */
+  room_left -= sizeof (char *);
 
   unsigned int i = 0;
   while (*line != '\0')
@@ -120,24 +126,20 @@ _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;
-          ++i;
-        }
-      else
-        network->n_aliases[i + 1] = NULL;
+	*line++ = '\0';
     }
+  network->n_aliases[i] = NULL;
 
   return 1;
 }
 
+
 static enum nss_status
 _nss_create_tablename (int *errnop)
 {
@@ -443,6 +445,7 @@ _nss_nisplus_getnetbyaddr_r (uint32_t addr, const int type,
 		   removed (one by one) */
 		buf2[b2len - 2] = '\0';
 		b2len -= 2;
+		nis_freeresult (result);
 		continue;
 	      }
 
diff --git a/nis/nss_nisplus/nisplus-parser.c b/nis/nss_nisplus/nisplus-parser.c
index b61733a628..e41751fff2 100644
--- a/nis/nss_nisplus/nisplus-parser.c
+++ b/nis/nss_nisplus/nisplus-parser.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1997, 1999, 2004 Free Software Foundation, Inc.
+/* Copyright (C) 1997, 1999, 2004, 2006 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1997.
 
@@ -26,10 +26,10 @@
 #include "nisplus-parser.h"
 
 #define NISENTRYVAL(idx,col,res) \
-        ((res)->objects.objects_val[(idx)].EN_data.en_cols.en_cols_val[(col)].ec_value.ec_value_val)
+        (NIS_RES_OBJECT (res)[(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)
+        (NIS_RES_OBJECT (res)[(idx)].EN_data.en_cols.en_cols_val[(col)].ec_value.ec_value_len)
 
 
 int
@@ -44,11 +44,10 @@ _nss_nisplus_parse_pwent (nis_result *result, struct passwd *pw,
     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)
+      || 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;
 
   if (NISENTRYLEN (0, 0, result) >= room_left)
@@ -90,8 +89,6 @@ _nss_nisplus_parse_pwent (nis_result *result, struct passwd *pw,
   if (len == 0) /* If we don't have a uid, it's an invalid shadow entry */
     return 0;
   pw->pw_uid = strtoul (first_unused, NULL, 10);
-  room_left -= (len + 1);
-  first_unused += (len + 1);
 
   if (NISENTRYLEN (0, 3, result) >= room_left)
     goto no_more_room;
@@ -103,8 +100,6 @@ _nss_nisplus_parse_pwent (nis_result *result, struct passwd *pw,
   if (len == 0) /* If we don't have a gid, it's an invalid shadow entry */
     return 0;
   pw->pw_gid = strtoul (first_unused, NULL, 10);
-  room_left -= (len + 1);
-  first_unused += (len + 1);
 
   if (NISENTRYLEN(0, 4, result) >= room_left)
     goto no_more_room;
@@ -143,6 +138,7 @@ _nss_nisplus_parse_pwent (nis_result *result, struct passwd *pw,
 }
 libnss_nisplus_hidden_def (_nss_nisplus_parse_pwent)
 
+
 int
 _nss_nisplus_parse_grent (nis_result *result, u_long entry, struct group *gr,
 			  char *buffer, size_t buflen, int *errnop)
@@ -157,10 +153,10 @@ _nss_nisplus_parse_grent (nis_result *result, u_long entry, struct group *gr,
     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,
+      || __type_of(NIS_RES_OBJECT (result)) != NIS_ENTRY_OBJ
+      || strcmp (NIS_RES_OBJECT (result)[entry].EN_data.en_type,
 		 "group_tbl") != 0
-      || result->objects.objects_val[entry].EN_data.en_cols.en_cols_len < 4)
+      || NIS_RES_OBJECT (result)[entry].EN_data.en_cols.en_cols_len < 4)
     return 0;
 
   if (NISENTRYLEN (entry, 0, result) >= room_left)
@@ -199,11 +195,9 @@ _nss_nisplus_parse_grent (nis_result *result, u_long entry, struct group *gr,
 	   NISENTRYLEN (entry, 2, result));
   first_unused[NISENTRYLEN (entry, 2, result)] = '\0';
   len = strlen (first_unused);
-  if (len == 0) /* We should always have an gid */
+  if (len == 0) /* We should always have a gid */
     return 0;
   gr->gr_gid = strtoul (first_unused, NULL, 10);
-  room_left -= (strlen (first_unused) + 1);
-  first_unused += strlen (first_unused) + 1;
 
   if (NISENTRYLEN (entry, 3, result) >= room_left)
     goto no_more_room;
@@ -217,8 +211,13 @@ _nss_nisplus_parse_grent (nis_result *result, u_long entry, struct group *gr,
   first_unused += (len + 1);
   /* Adjust the pointer so it is aligned for
      storing pointers.  */
-  first_unused += __alignof__ (char *) - 1;
-  first_unused -= ((first_unused - (char *) 0) % __alignof__ (char *));
+  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;
   gr->gr_mem = (char **) first_unused;
 
   count = 0;
@@ -243,12 +242,10 @@ _nss_nisplus_parse_grent (nis_result *result, u_long entry, 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 *))
@@ -260,6 +257,7 @@ _nss_nisplus_parse_grent (nis_result *result, u_long entry, struct group *gr,
 }
 libnss_nisplus_hidden_def (_nss_nisplus_parse_grent)
 
+
 int
 _nss_nisplus_parse_spent (nis_result *result, struct spwd *sp,
 			  char *buffer, size_t buflen, int *errnop)
@@ -272,11 +270,10 @@ _nss_nisplus_parse_spent (nis_result *result, struct spwd *sp,
     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[0].EN_data.en_cols.en_cols_len < 8)
+      || 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)
     return 0;
 
   if (NISENTRYLEN (0, 0, result) >= room_left)
@@ -314,10 +311,8 @@ _nss_nisplus_parse_spent (nis_result *result, struct spwd *sp,
 
   if (NISENTRYLEN (0, 7, result) > 0)
     {
-      char *line, *cp;
-
-      line = NISENTRYVAL (0, 7, result);
-      cp = strchr (line, ':');
+      char *line = NISENTRYVAL (0, 7, result);
+      char *cp = strchr (line, ':');
       if (cp == NULL)
 	return 1;
       *cp++ = '\0';
diff --git a/nis/nss_nisplus/nisplus-proto.c b/nis/nss_nisplus/nisplus-proto.c
index a3370aa85e..0b96153819 100644
--- a/nis/nss_nisplus/nisplus-proto.c
+++ b/nis/nss_nisplus/nisplus-proto.c
@@ -35,20 +35,20 @@ static nis_result *result;
 static nis_name tablename_val;
 static u_long tablename_len;
 
-#define NISENTRYVAL(idx,col,res) \
-        ((res)->objects.objects_val[(idx)].EN_data.en_cols.en_cols_val[(col)].ec_value.ec_value_val)
+#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 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,41 +71,44 @@ _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;
-  room_left -= (strlen (first_unused) +1);
-  first_unused += strlen (first_unused) +1;
+  size_t len = strlen (first_unused) + 1;
+  room_left -= len;
+  first_unused += len;
 
 
-  if (NISENTRYLEN (0, 2, result) + 1 > room_left)
-    goto no_more_room;
   proto->p_proto = atoi (NISENTRYVAL (0, 2, result));
-  p = first_unused;
 
-  line = p;
-  for (i = 0; i < result->objects.objects_len; ++i)
+  /* 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)
     {
       if (strcmp (NISENTRYVAL (i, 1, result), proto->p_name) != 0)
         {
           if (NISENTRYLEN (i, 1, result) + 2 > room_left)
             goto no_more_room;
-	  *p++ = ' ';
-          p = __stpncpy (p, NISENTRYVAL (i, 1, result),
-			 NISENTRYLEN (i, 1, result));
-          *p = '\0';
-          room_left -= (NISENTRYLEN (i, 1, result) + 1);
+	  *first_unused++ = ' ';
+          first_unused = __stpncpy (first_unused, NISENTRYVAL (i, 1, result),
+				    NISENTRYLEN (i, 1, result));
+          room_left -= NISENTRYLEN (i, 1, result) + 1;
         }
     }
-  *p++ = '\0';
-  first_unused = p;
+  *first_unused++ = '\0';
 
   /* Adjust the pointer so it is aligned for
      storing pointers.  */
-  first_unused += __alignof__ (char *) - 1;
-  first_unused -= ((first_unused - (char *) 0) % __alignof__ (char *));
-  proto->p_aliases = (char **) first_unused;
-  if (room_left < sizeof (char *))
+  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;
+  proto->p_aliases = (char **) first_unused;
+
+  /* For the terminating NULL pointer.  */
   room_left -= sizeof (char *);
-  proto->p_aliases[0] = NULL;
 
   i = 0;
   while (*line != '\0')
@@ -120,20 +123,15 @@ _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;
-          ++i;
-        }
-      else
-        proto->p_aliases[i+1] = NULL;
+	*line++ = '\0';
     }
+  proto->p_aliases[i] = NULL;
 
   return 1;
 }
diff --git a/nis/nss_nisplus/nisplus-publickey.c b/nis/nss_nisplus/nisplus-publickey.c
index c24e898137..fe269b2c48 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 Free Software Foundation, Inc.
+/* Copyright (c) 1997,1999,2001,2003,2005,2006 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Thorsten Kukuk <kukuk@suse.de>, 1997.
 
@@ -91,20 +91,20 @@ _nss_nisplus_getpublickey (const char *netname, char *pkey, int *errnop)
       return retval;
     }
 
-  if (res->objects.objects_len > 1)
+  if (NIS_RES_NUMOBJ (res) > 1)
     {
       /*
        * More than one principal with same uid?
        * something wrong with cred table. Should be unique
        * Warn user and continue.
        */
-      printf (_("DES entry for netname %s not unique\n"), netname);
+      syslog (LOG_ERR, _("DES entry for netname %s not unique\n"), netname);
       nis_freeresult (res);
       return NSS_STATUS_SUCCESS;
     }
 
-  len = ENTRY_LEN (res->objects.objects_val, 3);
-  memcpy (pkey, ENTRY_VAL (res->objects.objects_val,3), len);
+  len = ENTRY_LEN (NIS_RES_OBJECT (res), 3);
+  memcpy (pkey, ENTRY_VAL (NIS_RES_OBJECT (res),3), len);
   pkey[len] = 0;
   cptr = strchr (pkey, ':');
   if (cptr)
@@ -114,6 +114,7 @@ _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)
@@ -172,20 +173,20 @@ _nss_nisplus_getsecretkey (const char *netname, char *skey, char *passwd,
       return retval;
     }
 
-  if (res->objects.objects_len > 1)
+  if (NIS_RES_NUMOBJ (res) > 1)
     {
       /*
        * More than one principal with same uid?
        * something wrong with cred table. Should be unique
        * Warn user and continue.
        */
-      printf (_("DES entry for netname %s not unique\n"), netname);
+      syslog (LOG_ERR, _("DES entry for netname %s not unique\n"), netname);
       nis_freeresult (res);
       return NSS_STATUS_SUCCESS;
     }
 
-  len = ENTRY_LEN (res->objects.objects_val, 4);
-  memcpy (buf, ENTRY_VAL (res->objects.objects_val,4), len);
+  len = ENTRY_LEN (NIS_RES_OBJECT (res), 4);
+  memcpy (buf, ENTRY_VAL (NIS_RES_OBJECT (res), 4), len);
   buf[len] = '\0';
   cptr = strchr (buf, ':');
   if (cptr)
@@ -204,6 +205,7 @@ _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
@@ -305,7 +307,7 @@ _nss_nisplus_netname2user (char netname[MAXNETNAMELEN + 1], uid_t *uidp,
       return NSS_STATUS_UNAVAIL;
     }
 
-  if (res->objects.objects_len > 1)
+  if (NIS_RES_NUMOBJ (res) > 1)
     /*
      * A netname belonging to more than one principal?
      * Something wrong with cred table. should be unique.
@@ -315,8 +317,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 (res->objects.objects_val, 0);
-  strncpy (principal, ENTRY_VAL (res->objects.objects_val, 0), len);
+  len = ENTRY_LEN (NIS_RES_OBJECT (res), 0);
+  strncpy (principal, ENTRY_VAL (NIS_RES_OBJECT (res), 0), len);
   principal[len] = '\0';
   nis_freeresult (res);
 
@@ -328,7 +330,7 @@ _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);
@@ -379,7 +381,7 @@ _nss_nisplus_netname2user (char netname[MAXNETNAMELEN + 1], uid_t *uidp,
       return NSS_STATUS_UNAVAIL;
     }
 
-  if (res->objects.objects_len > 1)
+  if (NIS_RES_NUMOBJ (res) > 1)
     /*
      * A principal can have more than one LOCAL entry?
      * Something wrong with cred table.
@@ -389,15 +391,16 @@ _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 (res->objects.objects_val, 2), NULL, 10);
+  *uidp = strtoul (ENTRY_VAL (NIS_RES_OBJECT (res), 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 (res->objects.objects_val, 3),
+  parse_grp_str (ENTRY_VAL (NIS_RES_OBJECT (res), 3),
 		 gidp, gidlenp, gidlist, errnop);
 
   nis_freeresult (res);
diff --git a/nis/nss_nisplus/nisplus-rpc.c b/nis/nss_nisplus/nisplus-rpc.c
index f6ab3fbd87..1c3faa7dc0 100644
--- a/nis/nss_nisplus/nisplus-rpc.c
+++ b/nis/nss_nisplus/nisplus-rpc.c
@@ -35,11 +35,12 @@ static nis_result *result;
 static nis_name tablename_val;
 static u_long tablename_len;
 
-#define NISENTRYVAL(idx,col,res) \
-        ((res)->objects.objects_val[(idx)].EN_data.en_cols.en_cols_val[(col)].ec_value.ec_value_val)
+#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 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,
@@ -48,17 +49,16 @@ _nss_nisplus_parse_rpcent (nis_result *result, struct rpcent *rpc,
   char *first_unused = buffer;
   size_t room_left = buflen;
   unsigned int i;
-  char *p, *line;
+  char *line;
 
 
   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[0].EN_data.en_type,
-		 "rpc_tbl") != 0
-      || result->objects.objects_val[0].EN_data.en_cols.en_cols_len < 3)
+      || __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)
     return 0;
 
   if (NISENTRYLEN (0, 0, result) >= room_left)
@@ -71,37 +71,43 @@ _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;
-  room_left -= (strlen (first_unused) + 1);
-  first_unused += strlen (first_unused) + 1;
+  size_t len = strlen (first_unused) + 1;
+  room_left -= len;
+  first_unused += len;
+
   rpc->r_number = atoi (NISENTRYVAL (0, 2, result));
-  p = first_unused;
 
-  line = p;
-  for (i = 0; i < result->objects.objects_len; ++i)
+  /* 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)
     {
       if (strcmp (NISENTRYVAL (i, 1, result), rpc->r_name) != 0)
         {
           if (NISENTRYLEN (i, 1, result) + 2 > room_left)
 	    goto no_more_room;
-	  *p++ = ' ';
-          p = __stpncpy (p, NISENTRYVAL (i, 1, result),
-			 NISENTRYLEN (i, 1, result));
-          *p = '\0';
-          room_left -= (NISENTRYLEN (i, 1, result) + 1);
+	  *first_unused++ = ' ';
+          first_unused = __stpncpy (first_unused, NISENTRYVAL (i, 1, result),
+				    NISENTRYLEN (i, 1, result));
+          room_left -= NISENTRYLEN (i, 1, result) + 1;
         }
     }
-  ++p;
-  first_unused = p;
+  *first_unused++ = '\0';
 
   /* Adjust the pointer so it is aligned for
      storing pointers.  */
-  first_unused += __alignof__ (char *) - 1;
-  first_unused -= ((first_unused - (char *) 0) % __alignof__ (char *));
-  rpc->r_aliases = (char **) first_unused;
-  if (room_left < sizeof (char *))
+  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;
+  rpc->r_aliases = (char **) first_unused;
+
+  /* For the terminating NULL pointer.  */
   room_left -= sizeof (char *);
-  rpc->r_aliases[0] = NULL;
 
   i = 0;
   while (*line != '\0')
@@ -117,24 +123,20 @@ _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;
-          ++i;
-        }
-      else
-        rpc->r_aliases[i+1] = NULL;
+	*line++ = '\0';
     }
+  rpc->r_aliases[i] = NULL;
 
   return 1;
 }
 
+
 static enum nss_status
 _nss_create_tablename (int *errnop)
 {
diff --git a/nis/nss_nisplus/nisplus-service.c b/nis/nss_nisplus/nisplus-service.c
index c47dc09a06..3dd9f4dde6 100644
--- a/nis/nss_nisplus/nisplus-service.c
+++ b/nis/nss_nisplus/nisplus-service.c
@@ -35,11 +35,12 @@ static nis_result *result;
 static nis_name tablename_val;
 static u_long tablename_len;
 
-#define NISENTRYVAL(idx,col,res) \
-  ((res)->objects.objects_val[(idx)].EN_data.en_cols.en_cols_val[(col)].ec_value.ec_value_val)
+#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 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,
@@ -52,10 +53,9 @@ _nss_nisplus_parse_servent (nis_result *result, struct servent *serv,
     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->EN_data.en_type,
-		 "services_tbl") != 0
-      || result->objects.objects_val->EN_data.en_cols.en_cols_len < 4)
+      || __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)
     return 0;
 
   if (NISENTRYLEN (0, 0, result) >= room_left)
@@ -68,8 +68,9 @@ _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;
-  room_left -= (strlen (first_unused) +1);
-  first_unused += strlen (first_unused) +1;
+  size_t len = strlen (first_unused) + 1;
+  room_left -= len;
+  first_unused += len;
 
   if (NISENTRYLEN (0, 2, result) >= room_left)
     goto no_more_room;
@@ -77,38 +78,43 @@ _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;
-  room_left -= strlen (first_unused) + 1;
-  first_unused += strlen (first_unused) + 1;
+  len = strlen (first_unused) + 1;
+  room_left -= len;
+  first_unused += len;
 
   serv->s_port = htons (atoi (NISENTRYVAL (0, 3, result)));
-  char *p = first_unused;
 
-  char *line = p;
-  for (unsigned int i = 0; i < result->objects.objects_len; ++i)
+  /* 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)
     {
       if (strcmp (NISENTRYVAL (i, 1, result), serv->s_name) != 0)
         {
           if (NISENTRYLEN (i, 1, result) + 2 > room_left)
             goto no_more_room;
-	  *p++ = ' ';
-          p = __stpncpy (p, NISENTRYVAL (i, 1, result),
-			 NISENTRYLEN (i, 1, result));
-          *p = '\0';
-          room_left -= (NISENTRYLEN (i, 1, result) + 1);
+	  *first_unused++ = ' ';
+          first_unused = __stpncpy (first_unused, NISENTRYVAL (i, 1, result),
+				    NISENTRYLEN (i, 1, result));
+          room_left -= NISENTRYLEN (i, 1, result) + 1;
         }
     }
-  *p++ = '\0';
-  first_unused = p;
+  *first_unused++ = '\0';
 
   /* Adjust the pointer so it is aligned for
      storing pointers.  */
-  first_unused += __alignof__ (char *) - 1;
-  first_unused -= ((first_unused - (char *) 0) % __alignof__ (char *));
-  serv->s_aliases = (char **) first_unused;
-  if (room_left < sizeof (char *))
+  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;
+  serv->s_aliases = (char **) first_unused;
+
+  /* For the terminating NULL pointer.  */
   room_left -= (sizeof (char *));
-  serv->s_aliases[0] = NULL;
 
   unsigned int i = 0;
   while (*line != '\0')
@@ -124,24 +130,20 @@ _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;
-          ++i;
-	}
-      else
-        serv->s_aliases[i+1] = NULL;
+	*line++ = '\0';
     }
+  serv->s_aliases[i] = NULL;
 
   return 1;
 }
 
+
 static enum nss_status
 _nss_create_tablename (int *errnop)
 {
@@ -320,10 +322,10 @@ _nss_nisplus_getservbyname_r (const char *name, const char *protocol,
 	 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,
+	  || __type_of (NIS_RES_OBJECT (result)) != NIS_ENTRY_OBJ
+	  || strcmp (NIS_RES_OBJECT (result)->EN_data.en_type,
 		     "services_tbl") != 0
-	  || result->objects.objects_val->EN_data.en_cols.en_cols_len < 4)
+	  || 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