6ca6e8
commit c95ef423d78d9a2ec0a8e4141c78165434685c6f
6ca6e8
Author: Florian Weimer <fweimer@redhat.com>
6ca6e8
Date:   Tue Sep 13 16:10:20 2022 +0200
6ca6e8
6ca6e8
    nss: Implement --no-addrconfig option for getent
6ca6e8
    
6ca6e8
    The ahosts, ahostsv4, ahostsv6 commands unconditionally pass
6ca6e8
    AI_ADDRCONFIG to getaddrinfo, which is not always desired.
6ca6e8
    
6ca6e8
    Reviewed-by: Carlos O'Donell <carlos@redhat.com>
6ca6e8
    (cherry picked from commit a623f13adfac47c8634a7288e08f821a846bc650)
6ca6e8
6ca6e8
diff --git a/nss/getent.c b/nss/getent.c
6ca6e8
index ec48ba4bf1f5f788..0f4d549b05da73ac 100644
6ca6e8
--- a/nss/getent.c
6ca6e8
+++ b/nss/getent.c
6ca6e8
@@ -59,6 +59,8 @@ static const struct argp_option args_options[] =
6ca6e8
   {
6ca6e8
     { "service", 's', N_("CONFIG"), 0, N_("Service configuration to be used") },
6ca6e8
     { "no-idn", 'i', NULL, 0, N_("disable IDN encoding") },
6ca6e8
+    { "no-addrconfig", 'A', NULL, 0,
6ca6e8
+      N_("do not filter out unsupported IPv4/IPv6 addresses (with ahosts*)") },
6ca6e8
     { NULL, 0, NULL, 0, NULL },
6ca6e8
   };
6ca6e8
 
6ca6e8
@@ -80,6 +82,9 @@ static struct argp argp =
6ca6e8
 /* Additional getaddrinfo flags for IDN encoding.  */
6ca6e8
 static int idn_flags = AI_IDN | AI_CANONIDN;
6ca6e8
 
6ca6e8
+/* Set to 0 by --no-addrconfig.  */
6ca6e8
+static int addrconfig_flags = AI_ADDRCONFIG;
6ca6e8
+
6ca6e8
 /* Print the version information.  */
6ca6e8
 static void
6ca6e8
 print_version (FILE *stream, struct argp_state *state)
6ca6e8
@@ -347,7 +352,7 @@ ahosts_keys_int (int af, int xflags, int number, char *key[])
6ca6e8
 
6ca6e8
   struct addrinfo hint;
6ca6e8
   memset (&hint, '\0', sizeof (hint));
6ca6e8
-  hint.ai_flags = (AI_V4MAPPED | AI_ADDRCONFIG | AI_CANONNAME
6ca6e8
+  hint.ai_flags = (AI_V4MAPPED | addrconfig_flags | AI_CANONNAME
6ca6e8
 		   | idn_flags | xflags);
6ca6e8
   hint.ai_family = af;
6ca6e8
 
6ca6e8
@@ -906,6 +911,10 @@ parse_option (int key, char *arg, struct argp_state *state)
6ca6e8
       idn_flags = 0;
6ca6e8
       break;
6ca6e8
 
6ca6e8
+    case 'A':
6ca6e8
+      addrconfig_flags = 0;
6ca6e8
+      break;
6ca6e8
+
6ca6e8
     default:
6ca6e8
       return ARGP_ERR_UNKNOWN;
6ca6e8
     }