From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from sa-prd-fep-043.btinternet.com (mailomta31-sa.btinternet.com [213.120.69.37]) by sourceware.org (Postfix) with ESMTPS id 94B88396B43B for ; Tue, 10 Aug 2021 17:04:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 94B88396B43B 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-043.btinternet.com with ESMTP id <20210810170441.PGBP19470.sa-prd-fep-043.btinternet.com@sa-prd-rgout-002.btmx-prd.synchronoss.net>; Tue, 10 Aug 2021 18:04:41 +0100 Authentication-Results: btinternet.com; none X-SNCR-Rigid: 60FF56FA02421210 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: gggruggvucftvghtrhhoucdtuddrgedvtddrjeelgddutdelucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuueftkffvkffujffvgffngfevqffopdfqfgfvnecuuegrihhlohhuthemuceftddunecunecujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeflohhnucfvuhhrnhgvhicuoehjohhnrdhtuhhrnhgvhiesughrohhnvggtohguvgdrohhrghdruhhkqeenucggtffrrghtthgvrhhnpeefieduveehgfffffeuueehleefgeevfedvffeljeefheduteelteelvdettefhvdenucfkphepkeeirddugedtrdduuddvrdeitdenucevlhhushhtvghrufhiiigvpeejnecurfgrrhgrmhephhgvlhhopehlohgtrghlhhhoshhtrdhlohgtrghlughomhgrihhnpdhinhgvthepkeeirddugedtrdduuddvrdeitddpmhgrihhlfhhrohhmpeeojhhonhdrthhurhhnvgihsegurhhonhgvtghouggvrdhorhhgrdhukheqpdhrtghpthhtohepoegthihgfihinhdqrghpphhssegthihgfihinhdrtghomheqpdhrtghpthhtohepoehjohhnrdhtuhhrnhgvhiesughrohhnvggtohguvgdrohhrghdruhhkqe 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 60FF56FA02421210; Tue, 10 Aug 2021 18:04:41 +0100 From: Jon Turney To: cygwin-apps@cygwin.com Cc: Jon Turney Subject: [PATCH setup 09/11] Add a command line option to choose symlink type used Date: Tue, 10 Aug 2021 18:02:26 +0100 Message-Id: <20210810170228.1690-10-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:04:53 -0000 The default is 'sys', the historical behaviour of setup. v2: Adjust to use StringChoiceOption Align option names with winsymlink values --- main.cc | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/main.cc b/main.cc index b3854a8..023d505 100644 --- a/main.cc +++ b/main.cc @@ -63,6 +63,8 @@ #include "getopt++/GetOption.h" #include "getopt++/BoolOption.h" #include "getopt++/StringOption.h" +#include "getopt++/StringChoiceOption.h" +#include "mklink2.h" #include "Exception.h" #include @@ -86,6 +88,13 @@ std::string SetupIniDir; HINSTANCE hinstance; +static StringChoiceOption::StringChoices symlink_types({ + {"native", SymlinkTypeNative}, + {"lnk", SymlinkTypeShortcut}, + {"sys", SymlinkTypeMagic}, + {"wsl", SymlinkTypeWsl}, + }); + static StringOption Arch ("", 'a', "arch", "Architecture to install (x86_64 or x86)", false); static BoolOption UnattendedOption (false, 'q', "quiet-mode", "Unattended setup mode"); static BoolOption PackageManagerOption (false, 'M', "package-manager", "Semi-attended chooser-only mode"); @@ -95,6 +104,8 @@ static BoolOption HelpOption (false, 'h', "help", "Print help"); static BoolOption VersionOption (false, 'V', "version", "Show version"); static StringOption SetupBaseNameOpt ("setup", 'i', "ini-basename", "Use a different basename, e.g. \"foo\", instead of \"setup\"", false); BoolOption UnsupportedOption (false, '\0', "allow-unsupported-windows", "Allow old, unsupported Windows versions"); +static StringChoiceOption SymlinkTypeOption(symlink_types, '\0', "symlink-type", "Symlink type (lnk, native, sys, wsl)", false, SymlinkTypeMagic); + std::string SetupBaseName; static void inline @@ -320,6 +331,34 @@ WinMain (HINSTANCE h, Logger ().exit (1, false); } + /* Set default DACL and Group. */ + nt_sec.setDefaultSecurity ((root_scope == IDC_ROOT_SYSTEM)); + + symlinkType = (SymlinkTypeEnum)(int)SymlinkTypeOption; + if (symlinkType == SymlinkTypeWsl) + { + VersionInfo v = GetVer(); + if ((v.major() < 10) || + ((v.major() == 10) && (v.buildNumber() < 14393))) + { + fprintf (stderr, "*** --symlink-type wsl requires Windows 10 1607 or later\n"); + exit(1); + } + } + else if (symlinkType == SymlinkTypeNative) + { + if (!(elevate || is_developer_mode() || nt_sec.hasSymlinkCreationRights())) + { + fprintf (stderr, "*** --symlink-type native requires SeCreateSymbolicLink privilege or 'Developer Mode'\n"); + exit(1); + } + } + else if (symlinkType == SymlinkTypeShortcut) + { + fprintf (stderr, "*** --symlink-type lnk is not implemented\n"); + exit(1); + } + if (elevate) { char exe_path[MAX_PATH]; @@ -354,9 +393,6 @@ WinMain (HINSTANCE h, } else { - /* Set default DACL and Group. */ - nt_sec.setDefaultSecurity ((root_scope == IDC_ROOT_SYSTEM)); - UserSettings Settings; UserSettings::instance().load (local_dir); main_display (); -- 2.32.0