]> granicus.if.org Git - sudo/commitdiff
Allow tuples that can be used as booleans to be used as boolean TRUE.
authorTodd C. Miller <Todd.Miller@courtesan.com>
Fri, 26 Nov 2004 19:21:08 +0000 (19:21 +0000)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Fri, 26 Nov 2004 19:21:08 +0000 (19:21 +0000)
In this case the 2nd possible value of the tuple is used for TRUE.

def_data.in
defaults.c

index 9a0d53f1605e39e7c4b8b2737b901a708ad7ba49..81b616f1e715fca0f145c5ee7ac891922d9f6364 100644 (file)
@@ -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
index df8ae5db89003da9042201ea53d6c2bdc1d634d7..c9bff384bd9bc52b44409f4fd423f0c5a6361eb5 100644 (file)
@@ -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)