From nobody Sat Feb 7 08:23:42 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1580217255930543.3492811049215; Tue, 28 Jan 2020 05:14:15 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-140-CrC8Fna0M2CLbebs0f2ABg-1; Tue, 28 Jan 2020 08:13:25 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 257811088396; Tue, 28 Jan 2020 13:13:20 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 008D75DA7E; Tue, 28 Jan 2020 13:13:19 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id AF2B518034EF; Tue, 28 Jan 2020 13:13:19 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 00SDDId2019434 for ; Tue, 28 Jan 2020 08:13:18 -0500 Received: by smtp.corp.redhat.com (Postfix) id E6392100032E; Tue, 28 Jan 2020 13:13:18 +0000 (UTC) Received: from domokun.gsslab.fab.redhat.com (unknown [10.33.8.110]) by smtp.corp.redhat.com (Postfix) with ESMTP id D8CF61001DE1; Tue, 28 Jan 2020 13:13:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1580217254; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=/O646Sglp3c4/CY9kr1L+vGwaaJqgL+MnsG4f3DJ/e0=; b=JUOpoQRjUoV3ip068ZPA/vAIdEPASQltkPzOYbDYhrO4c9eXYt+thzan2G79eqJczz9Sx4 XwKhIZBaFTvPrElLbO/DVFaxEpjWQs1r0Ayx9wzdddCZJ/qYy8EDtBkLIrtyXfKr2a4nQY tkCznz/zL15jFqRFVLHQXY9mVq6t2i8= From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH v2 28/56] src: conditionalize use of chown & stat constants Date: Tue, 28 Jan 2020 13:11:09 +0000 Message-Id: <20200128131137.1762449-29-berrange@redhat.com> In-Reply-To: <20200128131137.1762449-1-berrange@redhat.com> References: <20200128131137.1762449-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-MC-Unique: CrC8Fna0M2CLbebs0f2ABg-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" chown and some stat constants are not available on the Windows platform. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Pavel Hrdina --- src/security/security_dac.c | 4 ++++ src/storage/storage_util.c | 3 +++ src/util/virfile.c | 44 +++++++++++++++++++++++++++++++++---- 3 files changed, 47 insertions(+), 4 deletions(-) diff --git a/src/security/security_dac.c b/src/security/security_dac.c index 2561ee440e..2aab227d71 100644 --- a/src/security/security_dac.c +++ b/src/security/security_dac.c @@ -710,7 +710,11 @@ virSecurityDACSetOwnershipInternal(const virSecurityDA= CData *priv, return 0; } =20 +#ifdef WIN32 + rc =3D ENOSYS; +#else /* !WIN32 */ rc =3D chown(path, uid, gid); +#endif /* !WIN32 */ } =20 if (rc < 0) { diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index 7bbcfde064..b6ea0a2760 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -79,6 +79,9 @@ =20 VIR_LOG_INIT("storage.storage_util"); =20 +#ifndef S_IRWXUGO +# define S_IRWXUGO (S_IRWXU | S_IRWXG | S_IRWXO) +#endif =20 /* virStorageBackendNamespaceInit: * @poolType: virStoragePoolType diff --git a/src/util/virfile.c b/src/util/virfile.c index efa59f2b13..74a679cb5c 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -95,6 +95,17 @@ =20 VIR_LOG_INIT("util.file"); =20 +#ifndef S_ISUID +# define S_ISUID 04000 +#endif +#ifndef S_ISGID +# define S_ISGID 02000 +#endif +#ifndef S_ISVTX +# define S_ISVTX 01000 +#endif + + #ifndef O_DIRECT # define O_DIRECT 0 #endif @@ -314,7 +325,7 @@ virFileWrapperFdNew(int *fd, const char *name, unsigned= int flags) virFileWrapperFdFree(ret); return NULL; } -#else +#else /* WIN32 */ virFileWrapperFdPtr virFileWrapperFdNew(int *fd G_GNUC_UNUSED, const char *name G_GNUC_UNUSED, @@ -324,7 +335,7 @@ virFileWrapperFdNew(int *fd G_GNUC_UNUSED, _("virFileWrapperFd unsupported on this platform")); return NULL; } -#endif +#endif /* WIN32 */ =20 /** * virFileWrapperFdClose: @@ -479,7 +490,7 @@ int virFileFlock(int fd, bool lock, bool shared) return flock(fd, LOCK_UN); } =20 -#else +#else /* WIN32 */ =20 int virFileLock(int fd G_GNUC_UNUSED, bool shared G_GNUC_UNUSED, @@ -507,7 +518,7 @@ int virFileFlock(int fd G_GNUC_UNUSED, return -1; } =20 -#endif +#endif /* WIN32 */ =20 =20 int @@ -1581,10 +1592,12 @@ virFileResolveLinkHelper(const char *linkpath, if (g_lstat(linkpath, &st) < 0) return -1; =20 +#ifndef WIN32 if (!S_ISLNK(st.st_mode)) { *resultpath =3D g_strdup(linkpath); return 0; } +#endif /* WIN32 */ } =20 *resultpath =3D virFileCanonicalizePath(linkpath); @@ -1630,10 +1643,17 @@ virFileIsLink(const char *linkpath) { GStatBuf st; =20 + /* Still do this on Windows so we report + * errors like ENOENT, etc + */ if (g_lstat(linkpath, &st) < 0) return -errno; =20 +#ifndef WIN32 return S_ISLNK(st.st_mode) !=3D 0; +#else /* WIN32 */ + return 0; +#endif /* WIN32 */ } =20 /* @@ -2615,6 +2635,7 @@ virDirCreateNoFork(const char *path, virReportSystemError(errno, _("stat of '%s' failed"), path); goto error; } +# ifndef WIN32 if (((uid !=3D (uid_t) -1 && st.st_uid !=3D uid) || (gid !=3D (gid_t) -1 && st.st_gid !=3D gid)) && (chown(path, uid, gid) < 0)) { @@ -2623,6 +2644,7 @@ virDirCreateNoFork(const char *path, path, (unsigned int) uid, (unsigned int) gid); goto error; } +# endif if (mode !=3D (mode_t) -1 && chmod(path, mode) < 0) { ret =3D -errno; virReportSystemError(errno, @@ -2959,6 +2981,7 @@ void virDirClose(DIR **dirp) * * Returns -1 on error, with error already reported, 0 on success. */ +#ifndef WIN32 int virFileChownFiles(const char *name, uid_t uid, gid_t gid) @@ -2999,6 +3022,19 @@ int virFileChownFiles(const char *name, return ret; } =20 +#else + +int virFileChownFiles(const char *name, + uid_t uid, + gid_t gid) +{ + virReportSystemError(ENOSYS, + _("cannot chown '%s' to (%u, %u)"), + name, (unsigned int) uid, + (unsigned int) gid); + return -1; +} +#endif /* WIN32 */ =20 static int virFileMakePathHelper(char *path, mode_t mode) --=20 2.24.1