summaryrefslogtreecommitdiff
path: root/nis/nss_nisplus
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2006-04-15 18:07:00 +0000
committerUlrich Drepper <drepper@redhat.com>2006-04-15 18:07:00 +0000
commit47ad422ffe8d3fd4e77edbe8c218d7faa59b4fda (patch)
treec31e25e18aa0ffe4b80b8daa6aa8201094ce6af7 /nis/nss_nisplus
parent0944b9e1f09dafaa86d431f4f2497436fd48781b (diff)
downloadglibc-47ad422ffe8d3fd4e77edbe8c218d7faa59b4fda.tar.gz
* nis/nss_nisplus/nisplus-service.c (_nss_nisplus_parse_servent):
* nis/nss_nisplus/nisplus-rpc.c (_nss_nisplus_parse_rpcent): Likewise.
Diffstat (limited to 'nis/nss_nisplus')
-rw-r--r--nis/nss_nisplus/nisplus-service.c78
1 files changed, 40 insertions, 38 deletions
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