]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
nss: Implement --no-addrconfig option for getent
authorFlorian Weimer <fweimer@redhat.com>
Tue, 13 Sep 2022 14:10:20 +0000 (16:10 +0200)
committerFlorian Weimer <fweimer@redhat.com>
Thu, 13 Oct 2022 13:45:25 +0000 (15:45 +0200)
The ahosts, ahostsv4, ahostsv6 commands unconditionally pass
AI_ADDRCONFIG to getaddrinfo, which is not always desired.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
(cherry picked from commit a623f13adfac47c8634a7288e08f821a846bc650)

NEWS
nss/getent.c

diff --git a/NEWS b/NEWS
index 865157146427eff9819386eb5237900b0a6260be..60dcd893da259133c5b9d78a79426bc38be1120f 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -12,6 +12,11 @@ Major new features:
 * The audit libraries will avoid unnecessary slowdown if it is not required
   PLT tracking (by not implementing the la_pltenter or la_pltexit callbacks).
 
+* The getent tool now supports the --no-addrconfig option. The output of
+  getent with --no-addrconfig may contain addresses of families not
+  configured on the current host i.e. as-if you had not passed
+  AI_ADDRCONFIG to getaddrinfo calls.
+
 Changes to build and runtime requirements:
 
 * The audit module interface version LAV_CURRENT is increased to enable
index ec48ba4bf1f5f788ad6bca0071150b4a736b3a1b..0f4d549b05da73ac1872934ce0874e5400c4e515 100644 (file)
@@ -59,6 +59,8 @@ static const struct argp_option args_options[] =
   {
     { "service", 's', N_("CONFIG"), 0, N_("Service configuration to be used") },
     { "no-idn", 'i', NULL, 0, N_("disable IDN encoding") },
+    { "no-addrconfig", 'A', NULL, 0,
+      N_("do not filter out unsupported IPv4/IPv6 addresses (with ahosts*)") },
     { NULL, 0, NULL, 0, NULL },
   };
 
@@ -80,6 +82,9 @@ static struct argp argp =
 /* Additional getaddrinfo flags for IDN encoding.  */
 static int idn_flags = AI_IDN | AI_CANONIDN;
 
+/* Set to 0 by --no-addrconfig.  */
+static int addrconfig_flags = AI_ADDRCONFIG;
+
 /* Print the version information.  */
 static void
 print_version (FILE *stream, struct argp_state *state)
@@ -347,7 +352,7 @@ ahosts_keys_int (int af, int xflags, int number, char *key[])
 
   struct addrinfo hint;
   memset (&hint, '\0', sizeof (hint));
-  hint.ai_flags = (AI_V4MAPPED | AI_ADDRCONFIG | AI_CANONNAME
+  hint.ai_flags = (AI_V4MAPPED | addrconfig_flags | AI_CANONNAME
                   | idn_flags | xflags);
   hint.ai_family = af;
 
@@ -906,6 +911,10 @@ parse_option (int key, char *arg, struct argp_state *state)
       idn_flags = 0;
       break;
 
+    case 'A':
+      addrconfig_flags = 0;
+      break;
+
     default:
       return ARGP_ERR_UNKNOWN;
     }