From: Todd C. Miller Date: Fri, 26 Nov 2004 19:21:08 +0000 (+0000) Subject: Allow tuples that can be used as booleans to be used as boolean TRUE. X-Git-Tag: SUDO_1_7_0~781 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=57ab7279b118cd462506bf9033622a3a38caba35;p=sudo Allow tuples that can be used as booleans to be used as boolean TRUE. In this case the 2nd possible value of the tuple is used for TRUE. --- diff --git a/def_data.in b/def_data.in index 9a0d53f16..81b616f1e 100644 --- a/def_data.in +++ b/def_data.in @@ -6,6 +6,9 @@ # description (or NULL) # array of struct def_values if TYPE == T_TUPLE # +# NOTE: for tuples that can be used in a boolean context the first +# value corresponds to boolean FALSE and the second to TRUE. +# syslog T_LOGFAC|T_BOOL diff --git a/defaults.c b/defaults.c index df8ae5db8..c9bff384b 100644 --- a/defaults.c +++ b/defaults.c @@ -333,12 +333,9 @@ set_default(var, val, op) } break; case T_TUPLE: - if (!val) { - /* Check for bogus boolean usage or lack of a value. */ - if (!ISSET(cur->type, T_BOOL) || op != FALSE) { - warningx("no value specified for `%s'", var); - return(FALSE); - } + if (!val && !ISSET(cur->type, T_BOOL)) { + warningx("no value specified for `%s'", var); + return(FALSE); } if (!store_tuple(val, cur, op)) { warningx("value `%s' is invalid for option `%s'", val, var); @@ -598,16 +595,16 @@ store_tuple(val, def, op) * This does assume that the first entry in the tuple enum will * be the equivalent to a boolean "false". */ - if (op == FALSE) { - def->sd_un.ival = 0; + if (!val) { + def->sd_un.ival = (op == FALSE) ? 0 : 1; } else { - for (v = def->values; v != NULL; v++) { + for (v = def->values; v->sval != NULL; v++) { if (strcmp(v->sval, val) == 0) { def->sd_un.ival = v->ival; break; } } - if (v == NULL) + if (v->sval == NULL) return(FALSE); } if (def->callback)