From nobody Fri Nov 22 10:42:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1716393680280485.1901878881905; Wed, 22 May 2024 09:01:20 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id CA2BF1C6B; Wed, 22 May 2024 12:01:18 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 084F01A48; Wed, 22 May 2024 12:00:29 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id EE0961A1F; Wed, 22 May 2024 12:00:24 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 739C91A12 for ; Wed, 22 May 2024 12:00:24 -0400 (EDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-401-6ReJoSq5MwCi8RHOB_G0zQ-1; Wed, 22 May 2024 12:00:22 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 67B8D101A55E for ; Wed, 22 May 2024 16:00:22 +0000 (UTC) Received: from speedmetal.lan (unknown [10.45.242.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id CE59DC15BB9 for ; Wed, 22 May 2024 16:00:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.5 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1716393624; 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=uM2SFycEWb1xNhDJTuP7ZA4nyC2cRvbgQKAdlh7LE3U=; b=HbcR41EODiUY3uZ6hv9Rkwvn37qGONwxF8g/yn+01d86I+BHEZ5LYQAtQ8fXt4yhfKa1Wv b5dh2GJMhGDKnzX4U7+2ge7UJj/PJ73zkSv/CHTdaKUQC14vfCaXcLh+EBhCvBKmzkXyWQ 92SX+tsJTI9WjBFl+6pRgoHJ3GwEIh8= X-MC-Unique: 6ReJoSq5MwCi8RHOB_G0zQ-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 1/4] virfile: Modernize definition of virFileOpenForked/virFileOpenForceOwnerMode/virFileOpenAs Date: Wed, 22 May 2024 18:00:16 +0200 Message-ID: <2bf1ebbf530384b21e954af15a0c712af54db45d.1716393556.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: U4RDH2HA3EX37X5N7X7WVUAJYFHR6Q25 X-Message-ID-Hash: U4RDH2HA3EX37X5N7X7WVUAJYFHR6Q25 X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1716393681194100001 Content-Type: text/plain; charset="utf-8" Declare one argument per line and one variable per line and use boolean operators at the end of the line rather than at the beginning. Signed-off-by: Peter Krempa Reviewed-by: Jiri Denemark --- src/util/virfile.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/src/util/virfile.c b/src/util/virfile.c index c769f7d650..f66ecd29a2 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -2330,8 +2330,12 @@ virFileAccessibleAs(const char *path, int mode, * opened as "fd" if it's not correct AND the flags say it should be * forced. */ static int -virFileOpenForceOwnerMode(const char *path, int fd, mode_t mode, - uid_t uid, gid_t gid, unsigned int flags) +virFileOpenForceOwnerMode(const char *path, + int fd, + mode_t mode, + uid_t uid, + gid_t gid, + unsigned int flags) { int ret =3D 0; struct stat st; @@ -2381,11 +2385,16 @@ virFileOpenForceOwnerMode(const char *path, int fd,= mode_t mode, * buildVol backend function expects the file to be deleted on error. */ static int -virFileOpenForked(const char *path, int openflags, mode_t mode, - uid_t uid, gid_t gid, unsigned int flags) +virFileOpenForked(const char *path, + int openflags, + mode_t mode, + uid_t uid, + gid_t gid, + unsigned int flags) { pid_t pid; - int status =3D 0, ret =3D 0; + int status =3D 0; + int ret =3D 0; int recvfd_errno =3D 0; int fd =3D -1; int pair[2] =3D { -1, -1 }; @@ -2546,10 +2555,15 @@ virFileOpenForked(const char *path, int openflags, = mode_t mode, * expects the file to be deleted on error. */ int -virFileOpenAs(const char *path, int openflags, mode_t mode, - uid_t uid, gid_t gid, unsigned int flags) +virFileOpenAs(const char *path, + int openflags, + mode_t mode, + uid_t uid, + gid_t gid, + unsigned int flags) { - int ret =3D 0, fd =3D -1; + int ret =3D 0; + int fd =3D -1; bool created =3D false; /* allow using -1 to mean "current value" */ @@ -2563,9 +2577,9 @@ virFileOpenAs(const char *path, int openflags, mode_t= mode, if (!(flags & (VIR_FILE_OPEN_NOFORK|VIR_FILE_OPEN_FORK))) flags |=3D VIR_FILE_OPEN_NOFORK|VIR_FILE_OPEN_FORK; - if ((flags & VIR_FILE_OPEN_NOFORK) - || (geteuid() !=3D 0) - || ((uid =3D=3D 0) && (gid =3D=3D 0))) { + if ((flags & VIR_FILE_OPEN_NOFORK) || + (geteuid() !=3D 0) || + ((uid =3D=3D 0) && (gid =3D=3D 0))) { if ((fd =3D open(path, openflags, mode)) < 0) { ret =3D -errno; --=20 2.45.1