public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
From: Thorsten Kukuk <kukuk@suse.de>
To: libc-hacker@sources.redhat.com
Subject: [PATCH] getaddrinfo does not work without nscd
Date: Thu, 16 Sep 2004 12:24:00 -0000	[thread overview]
Message-ID: <20040916122311.GA29768@suse.de> (raw)

[-- 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
 

             reply	other threads:[~2004-09-16 12:24 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-09-16 12:24 Thorsten Kukuk [this message]
2004-09-16 22:45 ` Ulrich Drepper

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040916122311.GA29768@suse.de \
    --to=kukuk@suse.de \
    --cc=libc-hacker@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).