From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from sa-prd-fep-045.btinternet.com (mailomta17-sa.btinternet.com [213.120.69.23]) by sourceware.org (Postfix) with ESMTPS id BE61D396DC2B for ; Tue, 10 Aug 2021 17:04:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BE61D396DC2B Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=dronecode.org.uk Authentication-Results: sourceware.org; spf=none smtp.mailfrom=dronecode.org.uk Received: from sa-prd-rgout-002.btmx-prd.synchronoss.net ([10.2.38.5]) by sa-prd-fep-045.btinternet.com with ESMTP id <20210810170457.PJYZ17681.sa-prd-fep-045.btinternet.com@sa-prd-rgout-002.btmx-prd.synchronoss.net>; Tue, 10 Aug 2021 18:04:57 +0100 Authentication-Results: btinternet.com; none X-SNCR-Rigid: 60FF56FA02421485 X-Originating-IP: [86.140.112.60] X-OWM-Source-IP: 86.140.112.60 (GB) X-OWM-Env-Sender: jonturney@btinternet.com X-VadeSecure-score: verdict=clean score=0/300, class=clean X-RazorGate-Vade: gggruggvucftvghtrhhoucdtuddrgedvtddrjeelgddutdelucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuueftkffvkffujffvgffngfevqffopdfqfgfvnecuuegrihhlohhuthemuceftddunecunecujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeflohhnucfvuhhrnhgvhicuoehjohhnrdhtuhhrnhgvhiesughrohhnvggtohguvgdrohhrghdruhhkqeenucggtffrrghtthgvrhhnpeefieduveehgfffffeuueehleefgeevfedvffeljeefheduteelteelvdettefhvdenucfkphepkeeirddugedtrdduuddvrdeitdenucevlhhushhtvghrufhiiigvpeelnecurfgrrhgrmhephhgvlhhopehlohgtrghlhhhoshhtrdhlohgtrghlughomhgrihhnpdhinhgvthepkeeirddugedtrdduuddvrdeitddpmhgrihhlfhhrohhmpeeojhhonhdrthhurhhnvgihsegurhhonhgvtghouggvrdhorhhgrdhukheqpdhrtghpthhtohepoegthihgfihinhdqrghpphhssegthihgfihinhdrtghomheqpdhrtghpthhtohepoehjohhnrdhtuhhrnhgvhiesughrohhnvggtohguvgdrohhrghdruhhkqe X-RazorGate-Vade-Verdict: clean 0 X-RazorGate-Vade-Classification: clean Received: from localhost.localdomain (86.140.112.60) by sa-prd-rgout-002.btmx-prd.synchronoss.net (5.8.340) (authenticated as jonturney@btinternet.com) id 60FF56FA02421485; Tue, 10 Aug 2021 18:04:57 +0100 From: Jon Turney To: cygwin-apps@cygwin.com Cc: Jon Turney Subject: [PATCH setup 11/11] Default symlink mode from CYGWIN env var Date: Tue, 10 Aug 2021 18:02:28 +0100 Message-Id: <20210810170228.1690-12-jon.turney@dronecode.org.uk> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210810170228.1690-1-jon.turney@dronecode.org.uk> References: <20210810170228.1690-1-jon.turney@dronecode.org.uk> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1200.6 required=5.0 tests=BAYES_00, FORGED_SPF_HELO, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: cygwin-apps@cygwin.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Cygwin package maintainer discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 10 Aug 2021 17:05:09 -0000 --- main.cc | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/main.cc b/main.cc index 023d505..f4756c7 100644 --- a/main.cc +++ b/main.cc @@ -284,6 +284,7 @@ WinMain (HINSTANCE h, /* Check if we have to elevate. */ bool elevate = !output_only && OSMajorVersion () >= 6 && !NoAdminOption && !nt_sec.isRunAsAdmin (); + std::string elevate_extra_args; if (unattended_mode || output_only || !elevate) set_cout (); @@ -334,7 +335,46 @@ WinMain (HINSTANCE h, /* Set default DACL and Group. */ nt_sec.setDefaultSecurity ((root_scope == IDC_ROOT_SYSTEM)); - symlinkType = (SymlinkTypeEnum)(int)SymlinkTypeOption; + /* + If --symlink-type option isn't given, look for winsymlinks in CYGWIN + env var for a default + + Since the current environment doesn't get passed to the process started + with with ShellExecuteEx, we need to convert the env var into an option + for that elevated instance. + */ + if (!SymlinkTypeOption.isPresent()) { + std::string cygwin; + DWORD len = GetEnvironmentVariable ("CYGWIN", &cygwin[0], 0); + cygwin.resize(len); + GetEnvironmentVariable ("CYGWIN", &cygwin[0], len); + + if (cygwin.find("winsymlinks:native") != std::string::npos) + { + symlinkType = SymlinkTypeNative; + elevate_extra_args.append("--symlink-type native"); + } + else if (cygwin.find("winsymlinks:wsl") != std::string::npos) + { + symlinkType = SymlinkTypeWsl; + elevate_extra_args.append("--symlink-type wsl"); + } + else if (cygwin.find("winsymlinks:sys") != std::string::npos) + { + symlinkType = SymlinkTypeMagic; + elevate_extra_args.append("--symlink-type sys"); + } + else if (cygwin.find("winsymlinks:lnk") != std::string::npos) + { + symlinkType = SymlinkTypeShortcut; + elevate_extra_args.append("--symlink-type lnk"); + } + } + else + { + symlinkType = (SymlinkTypeEnum)(int)SymlinkTypeOption; + } + if (symlinkType == SymlinkTypeWsl) { VersionInfo v = GetVer(); @@ -376,6 +416,8 @@ WinMain (HINSTANCE h, std::string command_line_cs (command_line); command_line_cs += " -"; command_line_cs += NoAdminOption.shortOption(); + command_line_cs += " "; + command_line_cs += elevate_extra_args; sei.lpParameters = command_line_cs.c_str (); if (ShellExecuteEx(&sei)) -- 2.32.0