[BZ,#14799] Allow to disable options in RES_OPTIONS

Message ID 20141126001713.GA27914@domone
State Superseded
Headers

Commit Message

Ondrej Bilka Nov. 26, 2014, 12:17 a.m. UTC
  Hi, this bug ticket ask to make posible to disable ip6 and other options
by RES_OPTIONS environment variable. Rather to add them manually I added
a check so no-option will do opposite of option.

OK to commit?

	[BZ #14799]
	* resolv/res_init.c (res_setoptions): Detect no- prefix to
	disable option.
  

Comments

Andreas Schwab Nov. 26, 2014, 10:06 a.m. UTC | #1
Ondřej Bílka <neleai@seznam.cz> writes:

> +		  int invert = 0;
> +		  if (strncmp (cp, "no-", 3))
> +		    {
> +		      cp += 3;
> +		      invert = 1;
> +		    }
> +
>  		  for (i = 0; i < noptions; ++i)
>  		    if (strncmp (cp, options[i].str, options[i].len) == 0)
>  		      {
> -			if (options[i].clear)
> -			  statp->options &= options[i].flag;
> +			if (options[i].clear ^ invert)
> +			  statp->options &= options[i].flag ^ invert;
>  			else
> -			  statp->options |= options[i].flag;
> +			  statp->options |= options[i].flag ^ invert;

That doesn't work.

Andreas.
  

Patch

diff --git a/resolv/res_init.c b/resolv/res_init.c
index ea133f8..9ea43e9 100644
--- a/resolv/res_init.c
+++ b/resolv/res_init.c
@@ -533,26 +533,32 @@  res_setoptions(res_state statp, const char *options, const char *source) {
 #define STRnLEN(str) str, sizeof (str) - 1
 		    { STRnLEN ("inet6"), 0, RES_USE_INET6 },
 		    { STRnLEN ("ip6-bytestring"), 0, RES_USEBSTRING },
-		    { STRnLEN ("no-ip6-dotint"), 0, RES_NOIP6DOTINT },
 		    { STRnLEN ("ip6-dotint"), 1, ~RES_NOIP6DOTINT },
 		    { STRnLEN ("rotate"), 0, RES_ROTATE },
-		    { STRnLEN ("no-check-names"), 0, RES_NOCHECKNAME },
+		    { STRnLEN ("check-names"), 1, ~RES_NOCHECKNAME },
 		    { STRnLEN ("edns0"), 0, RES_USE_EDNS0 },
 		    { STRnLEN ("single-request-reopen"), 0, RES_SNGLKUPREOP },
 		    { STRnLEN ("single-request"), 0, RES_SNGLKUP },
 		    { STRnLEN ("no_tld_query"), 0, RES_NOTLDQUERY },
-		    { STRnLEN ("no-tld-query"), 0, RES_NOTLDQUERY },
+		    { STRnLEN ("tld-query"), 1, ~RES_NOTLDQUERY },
 		    { STRnLEN ("use-vc"), 0, RES_USEVC }
 		  };
 #define noptions (sizeof (options) / sizeof (options[0]))
 		  int i;
+		  int invert = 0;
+		  if (strncmp (cp, "no-", 3))
+		    {
+		      cp += 3;
+		      invert = 1;
+		    }
+
 		  for (i = 0; i < noptions; ++i)
 		    if (strncmp (cp, options[i].str, options[i].len) == 0)
 		      {
-			if (options[i].clear)
-			  statp->options &= options[i].flag;
+			if (options[i].clear ^ invert)
+			  statp->options &= options[i].flag ^ invert;
 			else
-			  statp->options |= options[i].flag;
+			  statp->options |= options[i].flag ^ invert;
 			break;
 		      }
 		  if (i == noptions) {