]> 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>
Tue, 20 Sep 2022 11:09:25 +0000 (13:09 +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>
NEWS
nss/getent.c

diff --git a/NEWS b/NEWS
index ef274d1a42891be36538d34c494a30f6052454fd..a64d3eff2603127a5edccbaee60b6909fd25d3ef 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -9,7 +9,10 @@ Version 2.37
 
 Major new features:
 
-  [Add new features here]
+* 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.
 
 Deprecated and removed features, and other changes affecting compatibility:
 
index 8178b4b470063f27dc1975c7f186c3fbdb8b9c10..d2d2524b0cbef18b912f4de412e6bb37daa789eb 100644 (file)
@@ -58,6 +58,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 },
   };
 
@@ -79,6 +81,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)
@@ -346,7 +351,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;
 
@@ -905,6 +910,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;
     }