Skip to content

Commit

Permalink
* nis/nis_subr.c (nis_getnames): Fix the implementation to better
Browse files Browse the repository at this point in the history
	match what Solaris does.

	* string/bug-envz1.c: New file.
  • Loading branch information
Ulrich Drepper committed Jun 16, 2006
1 parent c26ca5e commit 02f366b
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 20 deletions.
7 changes: 6 additions & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2006-06-16 Ulrich Drepper <drepper@redhat.com>

* nis/nis_subr.c (nis_getnames): Fix the implementation to better
match what Solaris does.

2006-06-04 Ulrich Drepper <drepper@redhat.com>

* sysdeps/posix/spawni.c (__spawni): Use local_seteuid and
Expand All @@ -8,7 +13,7 @@
* sysdeps/posix/spawni.c (__spawni): Use non-cancelable interfaces.

* string/Makefile (tests): Add bug-envz1.
* string/bug-enz1.c: New file.
* string/bug-envz1.c: New file.

2006-06-02 Jakub Jelinek <jakub@redhat.com>

Expand Down
73 changes: 54 additions & 19 deletions nis/nis_subr.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 1997, 1999, 2000, 2004, 2005 Free Software Foundation, Inc.
/* Copyright (c) 1997,1999,2000,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.
Expand Down Expand Up @@ -107,25 +107,23 @@ count_dots (const_nis_name str)
nis_name *
nis_getnames (const_nis_name name)
{
nis_name *getnames = NULL;
char local_domain[NIS_MAXNAMELEN + 1];
const char *local_domain = nis_local_directory ();
size_t local_domain_len = strlen (local_domain);
size_t name_len = strlen (name);
char *path;
char *cp;
int count;
int pos = 0;
int have_point;
char *saveptr;
int have_point;
const char *cp;
const char *cp2;

strncpy (local_domain, nis_local_directory (), NIS_MAXNAMELEN);
local_domain[NIS_MAXNAMELEN] = '\0';

count = 1;
getnames = malloc ((count + 1) * sizeof (char *));
int count = 2;
nis_name *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[strlen (name) - 1] == '.')
if (name[name_len - 1] == '.')
{
if ((getnames[0] = strdup (name)) == NULL)
{
Expand All @@ -141,24 +139,62 @@ 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)
path = strdupa ("$");
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)
{
char *cptr = local_domain;
const char *cptr = local_domain;
char *tmp;

while ((have_point && *cptr != '\0') || (count_dots (cptr) >= 2))
while (*cptr != '\0' && count_dots (cptr) >= 2)
{
if (pos >= count)
{
Expand All @@ -169,8 +205,7 @@ nis_getnames (const_nis_name name)
goto free_null;
getnames = newp;
}
tmp = malloc (strlen (cptr) + strlen (local_domain) +
strlen (name) + 2);
tmp = malloc (strlen (cptr) + local_domain_len + name_len + 2);
if (__builtin_expect (tmp == NULL, 0))
goto free_null;

Expand Down Expand Up @@ -200,7 +235,7 @@ nis_getnames (const_nis_name name)
{
char *p;

tmp = malloc (cplen + strlen (local_domain) + strlen (name) + 2);
tmp = malloc (cplen + local_domain_len + name_len + 2);
if (__builtin_expect (tmp == NULL, 0))
goto free_null;

Expand All @@ -216,7 +251,7 @@ nis_getnames (const_nis_name name)
{
char *p;

tmp = malloc (cplen + strlen (name) + 2);
tmp = malloc (cplen + name_len + 2);
if (__builtin_expect (tmp == NULL, 0))
goto free_null;

Expand Down

0 comments on commit 02f366b

Please sign in to comment.