Skip to content

Commit

Permalink
Fix getnetbyaddr implementation.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Ulrich Drepper committed Jul 1, 2009
1 parent e6bd12d commit 29ba981
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
7 changes: 7 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -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-26 H.J. Lu <hongjiu.lu@intel.com>

* sysdeps/x86_64/multiarch/ifunc-defines.sym (FAMILIY_OFFSET): Define.
Expand Down
2 changes: 1 addition & 1 deletion nss/getent.c
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,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]);

Expand Down
5 changes: 3 additions & 2 deletions nss/nss_files/files-network.c
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)

0 comments on commit 29ba981

Please sign in to comment.