]> granicus.if.org Git - sudo/commitdiff
In print_member_json_int() eliminate the need_newline variable
authorTodd C. Miller <Todd.Miller@sudo.ws>
Thu, 20 Sep 2018 21:15:14 +0000 (15:15 -0600)
committerTodd C. Miller <Todd.Miller@sudo.ws>
Thu, 20 Sep 2018 21:15:14 +0000 (15:15 -0600)
and just move the non-alias expansion printing bits into the
else clause, including the newline and comma printing.

plugins/sudoers/cvtsudoers_json.c

index 901f2b104df14c602ec8d499a0e07f7f03929554..8d57894e3a99b6dae6eb8f3e8d5853af67bcff39 100644 (file)
@@ -338,9 +338,8 @@ print_member_json_int(FILE *fp, struct sudoers_parse_tree *parse_tree,
     const char *typestr = NULL;
     const char *errstr;
     int alias_type = UNSPEC;
-    bool need_newline = true;
     id_t id;
-    debug_decl(print_member_json, SUDOERS_DEBUG_UTIL)
+    debug_decl(print_member_json_int, SUDOERS_DEBUG_UTIL)
 
     /* Most of the time we print a string. */
     value.type = JSON_STRING;
@@ -476,6 +475,7 @@ print_member_json_int(FILE *fp, struct sudoers_parse_tree *parse_tree,
        struct alias *a;
        struct member *m;
 
+       /* Print each member of the alias. */
        if ((a = alias_get(parse_tree, value.u.string, alias_type)) != NULL) {
            TAILQ_FOREACH(m, &a->members, entries) {
                print_member_json_int(fp, parse_tree, m->name, m->type,
@@ -484,23 +484,23 @@ print_member_json_int(FILE *fp, struct sudoers_parse_tree *parse_tree,
                    last_one && TAILQ_NEXT(m, entries) == NULL, indent, true);
            }
            alias_put(a);
-           need_newline = false;
        }
-    } else if (negated) {
-       print_indent(fp, indent);
-       fputs("{\n", fp);
-       indent += 4;
-       print_pair_json(fp, NULL, typestr, &value, ",\n", indent);
-       value.type = JSON_BOOL;
-       value.u.boolean = true;
-       print_pair_json(fp, NULL, "negated", &value, "\n", indent);
-       indent -= 4;
-       print_indent(fp, indent);
-       putc('}', fp);
     } else {
-       print_pair_json(fp, "{ ", typestr, &value, " }", indent);
-    }
-    if (need_newline) {
+       if (negated) {
+           print_indent(fp, indent);
+           fputs("{\n", fp);
+           indent += 4;
+           print_pair_json(fp, NULL, typestr, &value, ",\n", indent);
+           value.type = JSON_BOOL;
+           value.u.boolean = true;
+           print_pair_json(fp, NULL, "negated", &value, "\n", indent);
+           indent -= 4;
+           print_indent(fp, indent);
+           putc('}', fp);
+       } else {
+           print_pair_json(fp, "{ ", typestr, &value, " }", indent);
+       }
+
        if (!last_one)
            putc(',', fp);
        putc('\n', fp);