From nobody Mon Feb 9 08:56:14 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1579779905; cv=none; d=zohomail.com; s=zohoarc; b=JT0VmGXpNpRVtaeRXTY9txnW2wHCuzskU3r3cyPtCWxRQX8/Sw2d23MZY1QOQEB98gF6tegsN+ziOR+PhiYHeyEy6IlDKKM/jHvVUqDNiiIRakRWSJXDE4wSFIkxtCjPV0BLZw2ta94M439DpOGjmlsGDdy8b1gn5XyTRpPcijw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579779905; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=NyIkVOPygV5RG35niznNd6Tlz9Nciz64weohKqc/JS4=; b=njKg01OkOJF4YqpEjToKFXOuRZi1v0oo1lzsYTQBeuKRAN7LBpg5rK1mLNc3QjV0/PbfIq0fsrEjCHAu9wFplKaJuWyM1Mbz0211r3m6jI9mF7aLRfULzySelNN5xidCX0F+GeY1S+oUCQATlMrrmDCeGTXesB7CrsHrtOsl5hs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 157977990582077.87548280736235; Thu, 23 Jan 2020 03:45:05 -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-423-hfgiZIw8NcSV8cS41Xn17g-1; Thu, 23 Jan 2020 06:44:24 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5B1F9190D340; Thu, 23 Jan 2020 11:44:18 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 29FD98CCD5; Thu, 23 Jan 2020 11:44:18 +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 C54D485917; Thu, 23 Jan 2020 11:44:17 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 00NBiEI1025582 for ; Thu, 23 Jan 2020 06:44:14 -0500 Received: by smtp.corp.redhat.com (Postfix) id 715928575F; Thu, 23 Jan 2020 11:44:14 +0000 (UTC) Received: from domokun.gsslab.fab.redhat.com (unknown [10.33.8.110]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4DA0F1CB; Thu, 23 Jan 2020 11:44:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579779903; 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=NyIkVOPygV5RG35niznNd6Tlz9Nciz64weohKqc/JS4=; b=jMCpzhYThXjqOV8x74r/v+6+VgomR12z/ancST543dmfdBDib4u9S2W7WibbxgLgd5h6lV fKaN2rmqfrMCiuseXPKNY/W1skzVbxeWRgTA6rJiNzqHuy7pg8nLMsgbB6W9m9RmSd10zA 3iAxnvXcSkeSFUJqGSOWAuQDvsA+PSg= From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH 28/32] src: conditionalize use of chown & stat constants Date: Thu, 23 Jan 2020 11:43:21 +0000 Message-Id: <20200123114325.3860881-29-berrange@redhat.com> In-Reply-To: <20200123114325.3860881-1-berrange@redhat.com> References: <20200123114325.3860881-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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.13 X-MC-Unique: hfgiZIw8NcSV8cS41Xn17g-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 --- 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 617d5d7a48..d08eae5a1d 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 + + int virFileClose(int *fdptr, virFileCloseFlags flags) { int saved_errno =3D 0; @@ -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