From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTP id 83E0E5A0082 for ; Mon, 13 Feb 2023 05:23:12 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676262191; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dR67PRjcyCKWhsfn8dI5sHHxgG68q5X2op4xRrUPeLM=; b=Qk/c8yIyERk7RbfzLPOxe8zicC/Tu7Uo7N6KJ2rVTw69X1vPfrL1Ctue/eTmJP6xmXTIYb UB+fxiLaNxjLS4CoOWUSALtZ0sqd7/NOOzZOpW9Fh/tveSJbwP8YAqKkylMafgCDM6jtcg JJaL1oeOhjgAy/meFaijr7/WqwcdaHQ= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-231-XE4sEk8yPJqbx6fDfDerIA-1; Sun, 12 Feb 2023 23:23:10 -0500 X-MC-Unique: XE4sEk8yPJqbx6fDfDerIA-1 Received: by mail-qk1-f199.google.com with SMTP id bp30-20020a05620a459e00b00738e1fe2470so6860596qkb.23 for ; Sun, 12 Feb 2023 20:23:10 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:organization:from:references :to:content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=dR67PRjcyCKWhsfn8dI5sHHxgG68q5X2op4xRrUPeLM=; b=FLtFOvK/TjztQluoYtDzg1o/BfPV+IjTUFLTUHRfb/Vgpt5FTLX+yyl86t52VVgLKE aO7vDskKLVucZarR65qlNwFrXF5sA/WzmUubY1R5ELFymegzKaCgOVTJIPo6KtXEUICC R3MthC7DsIOKbTMR98UqdhVjWMDqGQ74Z41awBQ67PRlRAQOJQm5J8VgExePxyzz1BQI AMfosl1b1gyQgRIQWBJz1RHl2BqeVFryAjDyYpZ2HdiT5SxeYtHoznCdx8O6Bd1fvMf1 sYjrIVeak/e0PLlRDnGF6EAZgTlD98DnZrQTVTS2S4rBMtVoHts1AFaJsEsjU4b+a+RM +zCg== X-Gm-Message-State: AO0yUKX72G//OpTD+oA1F5zjY2VTqlWgmj66wFvLqezanhQ6qcw86d1l /jelHXwpKYZdzjjZurHb1E5V2cCM8PUACV6L5HftamrLjrGh9FfFdTrVKfRuzPqqhWl19XmM5T3 lA0ugyTjhEV7ILoyEaLeUXGsiBspvEiSfFwRWw/Hft1b6QAiVMegfmVODX7i/VGL3+/w= X-Received: by 2002:ac8:7f46:0:b0:3b8:461c:12ed with SMTP id g6-20020ac87f46000000b003b8461c12edmr43565156qtk.8.1676262189347; Sun, 12 Feb 2023 20:23:09 -0800 (PST) X-Google-Smtp-Source: AK7set+T3poc79E6oLVwFjQHp1QNyLKvumG09yuT3+DOx6rEQFBogtcyNXVJfo7KLnwe3cjvx72icw== X-Received: by 2002:ac8:7f46:0:b0:3b8:461c:12ed with SMTP id g6-20020ac87f46000000b003b8461c12edmr43565127qtk.8.1676262188836; Sun, 12 Feb 2023 20:23:08 -0800 (PST) Received: from ?IPV6:2600:8805:3a00:3:3b4f:6d3c:92c4:a5c7? ([2600:8805:3a00:3:3b4f:6d3c:92c4:a5c7]) by smtp.gmail.com with ESMTPSA id 136-20020a370c8e000000b00706aeebe71csm8991579qkm.108.2023.02.12.20.23.08 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 12 Feb 2023 20:23:08 -0800 (PST) Message-ID: <8d0eebd7-34b0-0d74-3a53-48685142e34b@redhat.com> Date: Sun, 12 Feb 2023 23:23:07 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 Subject: Re: [PATCH v2 6/9] make conf_ugid() exit immediately after logging error To: passt-dev@passt.top References: <20230208174838.1680517-1-laine@redhat.com> <20230208174838.1680517-7-laine@redhat.com> From: Laine Stump Organization: Red Hat In-Reply-To: <20230208174838.1680517-7-laine@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-MailFrom: lstump@redhat.com X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation Message-ID-Hash: M65P6NITCF7WZRFMIHG7LMWUHBWTFZWV X-Message-ID-Hash: M65P6NITCF7WZRFMIHG7LMWUHBWTFZWV X-Mailman-Approved-At: Mon, 13 Feb 2023 10:06:45 +0100 X-Mailman-Version: 3.3.3 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: On 2/8/23 12:48 PM, Laine Stump wrote: > Again, it can then be made to return void, simplifying the caller. > > Signed-off-by: Laine Stump > --- > conf.c | 22 +++++++--------------- > 1 file changed, 7 insertions(+), 15 deletions(-) > > diff --git a/conf.c b/conf.c > index 1e9c6f6..5e9a6f9 100644 > --- a/conf.c > +++ b/conf.c > @@ -998,10 +998,8 @@ static int conf_runas(char *opt, unsigned int *uid, unsigned int *gid) > * @runas: --runas option, may be NULL > * @uid: User ID, set on success > * @gid: Group ID, set on success > - * > - * Return: 0 on success, negative error code on failure > */ > -static int conf_ugid(char *runas, uid_t *uid, gid_t *gid) > +static void conf_ugid(char *runas, uid_t *uid, gid_t *gid) > { > const char root_uid_map[] = " 0 0 4294967295"; > char buf[BUFSIZ]; > @@ -1012,8 +1010,7 @@ static int conf_ugid(char *runas, uid_t *uid, gid_t *gid) > if (runas) { > ret = conf_runas(runas, uid, gid); > if (ret) > - err("Invalid --runas option: %s", runas); > - return ret; > + errexit("Invalid --runas option: %s", runas); Noticed while reviewing my own patches in email - I was moving too quick/tired and counted the err() inside the "if (ret)" together with the subsequent return, when the return is actually outside of "if (ret)". I'll fix that up before reposting (along with your other suggestions). > } > > /* ...otherwise default to current user and group... */ > @@ -1022,20 +1019,18 @@ static int conf_ugid(char *runas, uid_t *uid, gid_t *gid) > > /* ...as long as it's not root... */ > if (*uid) > - return 0; > + return; > > /* ...or at least not root in the init namespace... */ > if ((fd = open("/proc/self/uid_map", O_RDONLY | O_CLOEXEC)) < 0) { > - ret = -errno; > - err("Can't determine if we're in init namespace: %s", > - strerror(-ret)); > - return ret; > + errexit("Can't determine if we're in init namespace: %s", > + strerror(-errno)); > } > > if (read(fd, buf, BUFSIZ) != sizeof(root_uid_map) || > strncmp(buf, root_uid_map, sizeof(root_uid_map) - 1)) { > close(fd); > - return 0; > + return; > } > > close(fd); > @@ -1059,7 +1054,6 @@ static int conf_ugid(char *runas, uid_t *uid, gid_t *gid) > *uid = *gid = 65534; > #endif > } > - return 0; > } > > /** > @@ -1522,9 +1516,7 @@ void conf(struct ctx *c, int argc, char **argv) > if (*c->sock_path && c->fd_tap >= 0) > errexit("Options --socket and --fd are mutually exclusive"); > > - ret = conf_ugid(runas, &uid, &gid); > - if (ret) > - usage(argv[0]); > + conf_ugid(runas, &uid, &gid); > > if (logfile) { > logfile_init(c->mode == MODE_PASST ? "passt" : "pasta",