public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] getaddrinfo does not work without nscd
@ 2004-09-16 12:24 Thorsten Kukuk
  2004-09-16 22:45 ` Ulrich Drepper
  0 siblings, 1 reply; 2+ messages in thread
From: Thorsten Kukuk @ 2004-09-16 12:24 UTC (permalink / raw)
  To: libc-hacker

[-- Attachment #1: Type: text/plain, Size: 697 bytes --]


Hi,

the latest getaddrinfo changes don't work, if no nscd is running.
__nscd_getai will return -1 in this case, which means gaih_inet will
bail out with an error and not fall back to the old code.

I have added a check for the __nss_not_use_nscd_hosts variable, if
nscd should be used or not. And for the first call, I also check in
the error case, if this variable is set or not.

Patch attached.

  Thorsten

-- 
Thorsten Kukuk       http://www.suse.de/~kukuk/        kukuk@suse.de
SuSE Linux AG        Maxfeldstr. 5                 D-90409 Nuernberg
--------------------------------------------------------------------    
Key fingerprint = A368 676B 5E1B 3E46 CFCE  2D97 F8FD 4E23 56C6 FB4B

[-- Attachment #2: glibc-2.3.3-getaddrinfo-nscd.diff --]
[-- Type: text/plain, Size: 4360 bytes --]

2004-09-16  Thorsten Kukuk  <kukuk@suse.de>

	* sysdeps/posix/getaddrinfo.c(gaih_inet): Check
	__nss_not_use_nscd_hosts variable if nscd should be used or not.

--- sysdeps/posix/getaddrinfo.c	2004-09-15 12:17:03.000000000 +0200
+++ sysdeps/posix/getaddrinfo.c	2004-09-16 14:11:52.022452106 +0200
@@ -55,6 +55,7 @@
 #include <nsswitch.h>
 #include <not-cancel.h>
 #include <nscd/nscd-client.h>
+#include <nscd/nscd_proto.h>
 
 #ifdef HAVE_LIBIDN
 extern int __idna_to_ascii_lz (const char *input, char **output, int flags);
@@ -672,69 +673,78 @@
 	    }
 
 #ifdef USE_NSCD
-	  /* Try to use nscd.  */
-	  struct nscd_ai_result *air = NULL;
-	  int herrno;
-	  int err = __nscd_getai (name, &air, &herrno);
-	  if (air != NULL)
-	    {
-	      /* Transform into gaih_addrtuple list.  */
-	      bool added_canon = (req->ai_flags & AI_CANONNAME) == 0;
-	      char *addrs = air->addrs;
+#define NSS_NSCD_RETRY      100
+
+	  if (__nss_not_use_nscd_hosts > 0 &&
+	      ++__nss_not_use_nscd_hosts > NSS_NSCD_RETRY)
+	    __nss_not_use_nscd_hosts = 0;
 
-	      for (int i = 0; i < air->naddrs; ++i)
+	  if (!__nss_not_use_nscd_hosts)
+	    {
+	      /* Try to use nscd.  */
+	      struct nscd_ai_result *air = NULL;
+	      int herrno;
+	      int err = __nscd_getai (name, &air, &herrno);
+	      if (air != NULL)
 		{
-		  socklen_t size = (air->family[i] == AF_INET
-				    ? INADDRSZ : IN6ADDRSZ);
-		  if (*pat == NULL)
-		    {
-		      *pat = __alloca (sizeof (struct gaih_addrtuple));
-		      (*pat)->scopeid = 0;
-		    }
-		  uint32_t *pataddr = (*pat)->addr;
-		  (*pat)->next = NULL;
-		  if (added_canon || air->canon == NULL)
-		    (*pat)->name = NULL;
-		  else
-		    canon = (*pat)->name = strdupa (air->canon);
+		  /* Transform into gaih_addrtuple list.  */
+		  bool added_canon = (req->ai_flags & AI_CANONNAME) == 0;
+		  char *addrs = air->addrs;
 
-		  if (air->family[i] == AF_INET
-		      && req->ai_family == AF_INET6
-		      && (req->ai_flags & AI_V4MAPPED))
+		  for (int i = 0; i < air->naddrs; ++i)
 		    {
-		      (*pat)->family = AF_INET6;
-		      pataddr[3] = *(uint32_t *) addrs;
-		      pataddr[2] = htonl (0xffff);
-		      pataddr[1] = 0;
-		      pataddr[0] = 0;
-		      pat = &((*pat)->next);
-		      added_canon = true;
-		    }
-		  else if (req->ai_family == AF_UNSPEC
-			   || air->family[i] == req->ai_family)
-		    {
-		      (*pat)->family = air->family[i];
-		      memcpy (pataddr, addrs, size);
-		      pat = &((*pat)->next);
-		      added_canon = true;
-		      if (air->family[i] == AF_INET6)
-			got_ipv6 = true;
+		      socklen_t size = (air->family[i] == AF_INET
+					? INADDRSZ : IN6ADDRSZ);
+		      if (*pat == NULL)
+			{
+			  *pat = __alloca (sizeof (struct gaih_addrtuple));
+			  (*pat)->scopeid = 0;
+			}
+		      uint32_t *pataddr = (*pat)->addr;
+		      (*pat)->next = NULL;
+		      if (added_canon || air->canon == NULL)
+			(*pat)->name = NULL;
+		      else
+			canon = (*pat)->name = strdupa (air->canon);
+
+		      if (air->family[i] == AF_INET
+			  && req->ai_family == AF_INET6
+			  && (req->ai_flags & AI_V4MAPPED))
+			{
+			  (*pat)->family = AF_INET6;
+			  pataddr[3] = *(uint32_t *) addrs;
+			  pataddr[2] = htonl (0xffff);
+			  pataddr[1] = 0;
+			  pataddr[0] = 0;
+			  pat = &((*pat)->next);
+			  added_canon = true;
+			}
+		      else if (req->ai_family == AF_UNSPEC
+			       || air->family[i] == req->ai_family)
+			{
+			  (*pat)->family = air->family[i];
+			  memcpy (pataddr, addrs, size);
+			  pat = &((*pat)->next);
+			  added_canon = true;
+			  if (air->family[i] == AF_INET6)
+			    got_ipv6 = true;
+			}
+		      addrs += size;
 		    }
-		  addrs += size;
-		}
 
-	      if (at->family == AF_UNSPEC)
-		return (GAIH_OKIFUNSPEC | -EAI_NONAME);
+		  if (at->family == AF_UNSPEC)
+		    return (GAIH_OKIFUNSPEC | -EAI_NONAME);
 
-	      goto process_list;
-	    }
-	  else if (err != 0)
-	    {
-	      if (herrno == NETDB_INTERNAL && errno == ENOMEM)
-		return -EAI_MEMORY;
-	      if (herrno == TRY_AGAIN)
-		return -EAI_AGAIN;
-	      return -EAI_SYSTEM;
+		  goto process_list;
+		}
+	      else if (err != 0 && __nss_not_use_nscd_hosts == 0)
+		{
+		  if (herrno == NETDB_INTERNAL && errno == ENOMEM)
+		    return -EAI_MEMORY;
+		  if (herrno == TRY_AGAIN)
+		    return -EAI_AGAIN;
+		  return -EAI_SYSTEM;
+		}
 	    }
 #endif
 

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] getaddrinfo does not work without nscd
  2004-09-16 12:24 [PATCH] getaddrinfo does not work without nscd Thorsten Kukuk
@ 2004-09-16 22:45 ` Ulrich Drepper
  0 siblings, 0 replies; 2+ messages in thread
From: Ulrich Drepper @ 2004-09-16 22:45 UTC (permalink / raw)
  To: Thorsten Kukuk; +Cc: libc-hacker

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Applied after cleanup.

- --
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)

iD8DBQFBShdu2ijCOnn/RHQRAsHXAJ0XuSL7NIcg784Cg8vO+Y2ogrDoGgCgnCZe
DOZCGfkYPOCEx0iuqlSEobQ=
=87K5
-----END PGP SIGNATURE-----

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2004-09-16 22:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-09-16 12:24 [PATCH] getaddrinfo does not work without nscd Thorsten Kukuk
2004-09-16 22:45 ` Ulrich Drepper

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).