From: Dmitry V. Levin Date: Fri, 14 Jul 2023 08:00:00 +0000 (+0000) Subject: userdb: cleanup use of ERRNO_IS_PRIVILEGE() X-Git-Tag: v255-rc1~886^2~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7a0b6d312b42b488b79117066fc3859bea4e8164;p=thirdparty%2Fsystemd.git userdb: cleanup use of ERRNO_IS_PRIVILEGE() Given that ERRNO_IS_PRIVILEGE() also matches positive values, make sure this macro is not called with arguments that do not have errno semantics. In this case the argument passed to ERRNO_IS_PRIVILEGE() is the value returned by json_parse_file() which is not expected to return any positive values, but let's be consistent anyway and move the ERRNO_IS_PRIVILEGE() invocation to the branch where the return value is known to be negative. --- diff --git a/src/shared/userdb-dropin.c b/src/shared/userdb-dropin.c index 5d79f4688a0..309f33b5b5b 100644 --- a/src/shared/userdb-dropin.c +++ b/src/shared/userdb-dropin.c @@ -57,13 +57,14 @@ static int load_user( } r = json_parse_file(NULL, j, JSON_PARSE_SENSITIVE, &privileged_v, NULL, NULL); - if (ERRNO_IS_PRIVILEGE(r)) - have_privileged = false; - else if (r == -ENOENT) - have_privileged = true; /* if the privileged file doesn't exist, we are complete */ - else if (r < 0) - return r; - else { + if (r < 0) { + if (ERRNO_IS_PRIVILEGE(r)) + have_privileged = false; + else if (r == -ENOENT) + have_privileged = true; /* if the privileged file doesn't exist, we are complete */ + else + return r; + } else { r = json_variant_merge(&v, privileged_v); if (r < 0) return r; @@ -201,13 +202,14 @@ static int load_group( } r = json_parse_file(NULL, j, JSON_PARSE_SENSITIVE, &privileged_v, NULL, NULL); - if (ERRNO_IS_PRIVILEGE(r)) - have_privileged = false; - else if (r == -ENOENT) - have_privileged = true; /* if the privileged file doesn't exist, we are complete */ - else if (r < 0) - return r; - else { + if (r < 0) { + if (ERRNO_IS_PRIVILEGE(r)) + have_privileged = false; + else if (r == -ENOENT) + have_privileged = true; /* if the privileged file doesn't exist, we are complete */ + else + return r; + } else { r = json_variant_merge(&v, privileged_v); if (r < 0) return r;