]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Fix getnetbyaddr implementation.
authorUlrich Drepper <drepper@redhat.com>
Wed, 1 Jul 2009 09:42:59 +0000 (02:42 -0700)
committerPetr Baudis <pasky@suse.cz>
Thu, 16 Jul 2009 15:40:28 +0000 (17:40 +0200)
There were two problems in the getnetbyaddr implementation.  The type
argument is pretty much useless since (almost) no input file contains
this information and the NSS backends make up the value they fill in
for the n_addrtype field.  Therefore we now declare that passing AF_UNSPEC
is always recognized.  Secondly, the files backend didn't compare the network
numbers with the correct endianess.

Also change getent to take advantage of the type parameter change.

(cherry picked from commit 29ba9812bb86bf6da9702f4fbff5cdbb25846401)

ChangeLog
nss/getent.c
nss/nss_files/files-network.c

index 3620d6252b4ead0e4ea9da1dcf635e866aaaa3b7..0e5bcfce752caa7828bb073980b37751876704a1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2009-07-01  Ulrich Drepper  <drepper@redhat.com>
+
+       * nss/nss_files/files-network.c (netbyaddr): If type is AF_UNSPEC,
+       recognize all types.  Fix endianess in comparison of network number.
+       * nss/getent.c (networks_keys): Pass AF_UNSPEC instead of AF_UNIX
+       to getnetbyaddr.
+
 2009-06-24  Andreas Schwab  <aschwab@redhat.com>
 
        * sysdeps/powerpc/powerpc32/power4/fpu/w_sqrtf.S: Fix cfa offset
index ea5608f1e2783edecef56d9b8809f5f8ad20b84b..cda7d78ed47a86d01e9832c023dbe0b571ed6a52 100644 (file)
@@ -469,7 +469,7 @@ networks_keys (int number, char *key[])
   for (i = 0; i < number; ++i)
     {
       if (isdigit (key[i][0]))
-       net = getnetbyaddr (inet_addr (key[i]), AF_UNIX);
+       net = getnetbyaddr (inet_addr (key[i]), AF_UNSPEC);
       else
        net = getnetbyname (key[i]);
 
index 9f4a3e032462fec64b370bc1d455308957b84132..064de5a143516d9f03ee21910d7c02b07660c2b0 100644 (file)
@@ -1,5 +1,5 @@
 /* Networks file parser in nss_files module.
-   Copyright (C) 1996, 1997, 1998, 2000, 2001 Free Software Foundation, Inc.
+   Copyright (C) 1996-1998, 2000, 2001, 2009 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -81,7 +81,8 @@ DB_LOOKUP (netbyname, ,,
 
 DB_LOOKUP (netbyaddr, ,,
           {
-            if (result->n_addrtype == type && result->n_net == net)
+            if ((type == AF_UNSPEC || result->n_addrtype == type)
+                && result->n_net == htonl (net))
               /* Bingo!  */
               break;
           }, uint32_t net, int type)