From nobody Fri May 3 05:43:43 2024 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=1576691622; cv=none; d=zohomail.com; s=zohoarc; b=ncOvdiLdJ77oNxPXmCWqMMOB66xYxFvt5QwIsICmMf7UKyF5uL0LcRGRoAOXhQeKfxnhIJA7IUYiWv0KkhHCa1ufPIpL5KzFKTt+Uuaj4OvKVwqD/aBl5YU4RHqssmWc6AgbIr5EjpBDSJ74FkjxveZLQNQGFS++nUa/ILM9M5Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576691622; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=Kd5qFZeR8HHEuSALiE+Xtg53LxESj9DsEN2tlwrmWpw=; b=A3KaQCGXCb858H6gKhUK9TZ0Ks+24RTX0/6aOIMdFOyf8Pv1Wx+jMlRKteMegd7lGLs63UKv0bwyPHox9U4V6WX7SorFqzHFBWrVIAFd/1t18sucga9eCjhHl4E6dACYLgeD5o60Z7gqpx53T39BE1Gc1sif+997Jd9723cUVFk= 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 1576691622372371.68347097119624; Wed, 18 Dec 2019 09:53:42 -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-263-xAhWl-NKPFiAHtShYK4J5g-1; Wed, 18 Dec 2019 12:53:35 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 58ECADB60; Wed, 18 Dec 2019 17:53:24 +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 E5DF11891F; Wed, 18 Dec 2019 17:53:22 +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 EC73D1809567; Wed, 18 Dec 2019 17:53:17 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xBIHrGbE016157 for ; Wed, 18 Dec 2019 12:53:16 -0500 Received: by smtp.corp.redhat.com (Postfix) id 5B4FB1891F; Wed, 18 Dec 2019 17:53:16 +0000 (UTC) Received: from laerte.redhat.com (unknown [10.43.2.64]) by smtp.corp.redhat.com (Postfix) with ESMTP id 554146888D; Wed, 18 Dec 2019 17:53:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1576691621; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=Kd5qFZeR8HHEuSALiE+Xtg53LxESj9DsEN2tlwrmWpw=; b=eF7otPISSgMKjPuXStsvnLZiu9tXQG7ACpC0i/xz1FQ1WNTh4OPOCOT3C0K/PxArEBlKC5 l3Jdg/z96km/XIuwsu3XkaaAzSQ2loF80ZM2CWh4fylNLKBLwT0IzLo4AEv6HmRM2zeb6J 71Er7Bhyy3ed6o3S6xOlE278N+MMEpw= From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= To: libvir-list@redhat.com Date: Wed, 18 Dec 2019 18:53:10 +0100 Message-Id: <20191218175310.1706088-1-fidencio@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Subject: [libvirt] [PATCH] util: Simplify Windows version of virGetUserDirectoryByUID() 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.15 X-MC-Unique: xAhWl-NKPFiAHtShYK4J5g-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Let's just use the plain g_get_home_dir(), from GLib, instead of maintaining a code adapted from the GLib's one. Signed-off-by: Fabiano Fid=C3=AAncio Reviewed-by: Cole Robinson --- src/util/virutil.c | 92 +--------------------------------------------- 1 file changed, 1 insertion(+), 91 deletions(-) diff --git a/src/util/virutil.c b/src/util/virutil.c index a28feb3daa..4075047cf9 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -1070,100 +1070,10 @@ virDoesGroupExist(const char *name G_GNUC_UNUSED) } =20 # ifdef WIN32 -/* These methods are adapted from GLib2 under terms of LGPLv2+ */ -static int -virGetWin32SpecialFolder(int csidl, char **path) -{ - char buf[MAX_PATH+1]; - LPITEMIDLIST pidl =3D NULL; - int ret =3D 0; - - *path =3D NULL; - - if (SHGetSpecialFolderLocation(NULL, csidl, &pidl) =3D=3D S_OK) { - if (SHGetPathFromIDList(pidl, buf)) - *path =3D g_strdup(buf); - CoTaskMemFree(pidl); - } - return ret; -} - -static int -virGetWin32DirectoryRoot(char **path) -{ - char windowsdir[MAX_PATH]; - - *path =3D NULL; - - if (GetWindowsDirectory(windowsdir, G_N_ELEMENTS(windowsdir))) { - const char *tmp; - /* Usually X:\Windows, but in terminal server environments - * might be an UNC path, AFAIK. - */ - tmp =3D virFileSkipRoot(windowsdir); - if (VIR_FILE_IS_DIR_SEPARATOR(tmp[-1]) && - tmp[-2] !=3D ':') - tmp--; - - windowsdir[tmp - windowsdir] =3D '\0'; - } else { - strcpy(windowsdir, "C:\\"); - } - - *path =3D g_strdup(windowsdir); - return 0; -} - - - char * virGetUserDirectoryByUID(uid_t uid G_GNUC_UNUSED) { - /* Since Windows lacks setuid binaries, and since we already fake - * geteuid(), we can safely assume that this is only called when - * querying about the current user */ - const char *dir; - char *ret; - - dir =3D getenv("HOME"); - - /* Only believe HOME if it is an absolute path and exists */ - if (dir) { - if (!virFileIsAbsPath(dir) || - !virFileExists(dir)) - dir =3D NULL; - } - - /* In case HOME is Unix-style (it happens), convert it to - * Windows style. - */ - if (dir) { - char *p; - while ((p =3D strchr(dir, '/')) !=3D NULL) - *p =3D '\\'; - } - - if (!dir) - /* USERPROFILE is probably the closest equivalent to $HOME? */ - dir =3D getenv("USERPROFILE"); - - ret =3D g_strdup(dir); - - if (!ret && - virGetWin32SpecialFolder(CSIDL_PROFILE, &ret) < 0) - return NULL; - - if (!ret && - virGetWin32DirectoryRoot(&ret) < 0) - return NULL; - - if (!ret) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Unable to determine home directory")); - return NULL; - } - - return ret; + return g_strdup(g_get_home_dir()); } =20 char * --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list