libsemanage: make expand-check a proper boolean option
PATCH v2 1/1 libsemanage: make expand-check a proper boolean option
Make expand-check configuration option accept values 'true' and 'false' for consistency with the rest of the boolean options. Preserve backwards compatibility with old configuration file settings by still accepting the values "1" and "0".
Add missing <stdbool.h> include.
--- libsemanage/src/conf-parse.y | 22 +++++++++++++--------- libsemanage/src/semanage_conf.h | 3 ++- 2 files changed, 15 insertions(+), 10 deletions(-)
libsemanage/src/conf-parse.y +13 -9
@@ -29,6 +29,7 @@ #include <errno.h> #include <unistd.h> +#include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <string.h>
@@ -168,15 +169,18 @@ target_platform: TARGET_PLATFORM '=' ARG { ; expand_check: EXPAND_CHECK '=' ARG { - char *endptr; - long value; - errno = 0; - value = strtol($3, &endptr, 10); - if (*endptr != '\0' || errno != 0 || (value != 0 && value != 1)) - yyerror("expand-check can only be '1' or '0'"); - else - current_conf->expand_check = value; - free($3); + if (strcasecmp($3, "true") == 0) + current_conf->expand_check = true; + else if (strcmp($3, "1") == 0) + current_conf->expand_check = true; + else if (strcasecmp($3, "false") == 0) + current_conf->expand_check = false; + else if (strcmp($3, "0") == 0) + current_conf->expand_check = false; + else { + yyerror("expand-check can only be 'true' or 'false'"); + } + free($3); } ;
libsemanage/src/semanage_conf.h +2 -1
@@ -21,6 +21,7 @@#define SEMANAGE_CONF_H #include <semanage/handle.h> +#include <stdbool.h> #include <sys/types.h> #include <sys/stat.h>
@@ -36,7 +37,7 @@ typedef struct semanage_conf {int server_port;int policyvers;/* version for server generated policies */ int target_platform; -int expand_check; +bool expand_check;int save_previous;int save_linked;int disable_genhomedircon;
Signature · 1 line
2.54.0
Quoted 40 lines · Kalevi Kolttonen
Make expand-check configuration option accept values 'true' and 'false' for consistency with the rest of the boolean options. Preserve backwards compatibility with old configuration file settings by still accepting the values "1" and "0".
Add missing <
stdbool.h> include.Signed-off-by Kalevi Kolttonen <[email protected]>--- libsemanage/src/conf-parse.y | 22 +++++++++++++--------- libsemanage/src/semanage_conf.h | 3 ++- 2 files changed, 15 insertions(+), 10 deletions(-)libsemanage/src/conf-parse.y +1
-9@@ -29,6 +29,7 @@ #include <errno.h> #include <unistd.h> +#include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <string.h>@@ -168,15 +169,18 @@ target_platform: TARGET_PLATFORM '=' ARG { ; expand_check: EXPAND_CHECK '=' ARG { - char *endptr; - long value; - errno = 0; - value = strtol($3, &endptr, 10); - if (*endptr != '\0' || errno != 0 || (value != 0 && value != 1)) - yyerror("expand-check can only be '1' or '0'"); - else - current_conf->expand_check = value; - free($3);
libsemanage/src/conf-parse.y target_platform: TARGET_PLATFORM '=' ARG { · line 181
Quoted 10 lines
libsemanage/src/conf-parse.y +10
-0+ if (strcasecmp($3, "true") == 0) + current_conf->expand_check = true; + else if (strcmp($3, "1") == 0) + current_conf->expand_check = true; + else if (strcasecmp($3, "false") == 0) + current_conf->expand_check = false; + else if (strcmp($3, "0") == 0) + current_conf->expand_check = false; + else { + yyerror("expand-check can only be 'true' or 'false'");
0 and 1 are still acceptable, so the error message should reflect that.
Also, you need to update man/man5/semanage.conf.5 to reflect that true and false are acceptable values (along with 0 and 1).
Thanks,
Jim
Quoted 30 lines
libsemanage/src/conf-parse.y +2
-0+ } + free($3); } ;libsemanage/src/semanage_conf.h +2
-2@@ -21,6 +21,7 @@#define SEMANAGE_CONF_H #include <semanage/handle.h> +#include <stdbool.h> #include <sys/types.h> #include <sys/stat.h> @@ -36,7 +37,7 @@ typedef struct semanage_conf {int server_port;int policyvers;/* version for server generated policies */ int target_platform; -int expand_check; +bool expand_check;int save_previous;int save_linked;int disable_genhomedircon; --2.54.0
Quoted 3 lines · James Carter
Quoted 1 line
+
yyerror("expand-check can only be 'true' or 'false'");0 and 1 are still acceptable, so the error message should reflect that.
Updated.
Quoted 2 lines
Also, you need to update man/man5/semanage.conf.5 to reflect that true and false are acceptable values (along with 0 and 1).
Updated. I will send fixed v3 now.
br,
KK