From ba6a57264acbc558058c312594fd4cd4fd63b007 Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Sat, 28 Apr 2018 21:54:36 +0300 Subject: [PATCH] Revert "win: innosetup: don't add symlink perms" This reverts commit e94b78d6770a42f40e6b85f10cea0ed13322ffae. --- scripts/innosetup/addSymLinkPermissions.ps1 | 76 +++++++++++++++++++++ scripts/innosetup/addsymlink.iss | 14 ++++ scripts/innosetup/setup.iss | 13 ++++ 3 files changed, 103 insertions(+) create mode 100644 scripts/innosetup/addSymLinkPermissions.ps1 create mode 100644 scripts/innosetup/addsymlink.iss diff --git a/scripts/innosetup/addSymLinkPermissions.ps1 b/scripts/innosetup/addSymLinkPermissions.ps1 new file mode 100644 index 000000000..ea44eba6b --- /dev/null +++ b/scripts/innosetup/addSymLinkPermissions.ps1 @@ -0,0 +1,76 @@ +param ( + [string]$mytype = 'system' +) + +function addSymLinkPermissions($accountToAdd){ + Write-Host "Checking SymLink permissions.." + $sidstr = $null + if ( "$accountToAdd" -eq "Everyone" ) { + $sidstr = "S-1-1-0" + } else { + try { + $ntprincipal = new-object System.Security.Principal.NTAccount "$accountToAdd" + $sid = $ntprincipal.Translate([System.Security.Principal.SecurityIdentifier]) + $sidstr = $sid.Value.ToString() + } catch { + $sidstr = $null + } + } + Write-Host "Account: $($accountToAdd)" -ForegroundColor DarkCyan + if( [string]::IsNullOrEmpty($sidstr) ) { + Write-Host "Account not found!" -ForegroundColor Red + exit -1 + } + Write-Host "Account SID: $($sidstr)" -ForegroundColor DarkCyan + $tmp = [System.IO.Path]::GetTempFileName() + Write-Host "Export current Local Security Policy" -ForegroundColor DarkCyan + secedit.exe /export /cfg "$($tmp)" + $c = Get-Content -Path $tmp + $currentSetting = "" + foreach($s in $c) { + if( $s -like "SECreateSymbolicLinkPrivilege*") { + $x = $s.split("=",[System.StringSplitOptions]::RemoveEmptyEntries) + $currentSetting = $x[1].Trim() + } + } + if( $currentSetting -notlike "*$($sidstr)*" ) { + Write-Host "Need to add permissions to SymLink" -ForegroundColor Yellow + + Write-Host "Modify Setting ""Create SymLink""" -ForegroundColor DarkCyan + + if( [string]::IsNullOrEmpty($currentSetting) ) { + $currentSetting = "*$($sidstr)" + } else { + $currentSetting = "*$($sidstr),$($currentSetting)" + } + Write-Host "$currentSetting" + $outfile = @" +[Unicode] +Unicode=yes +[Version] +signature="`$CHICAGO`$" +Revision=1 +[Privilege Rights] +SECreateSymbolicLinkPrivilege = $($currentSetting) +"@ + $tmp2 = [System.IO.Path]::GetTempFileName() + Write-Host "Import new settings to Local Security Policy" -ForegroundColor DarkCyan + $outfile | Set-Content -Path $tmp2 -Encoding Unicode -Force + Push-Location (Split-Path $tmp2) + try { + secedit.exe /configure /db "secedit.sdb" /cfg "$($tmp2)" /areas USER_RIGHTS + } finally { + Pop-Location + } + } else { + Write-Host "NO ACTIONS REQUIRED! Account already in ""Create SymLink""" -ForegroundColor DarkCyan + Write-Host "Account $accountToAdd already has permissions to SymLink" -ForegroundColor Green + return $true; + } +} + +if ( "$mytype" -eq "user" ) { + addSymLinkPermissions $(Get-WMIObject -class Win32_ComputerSystem | select username).username +} else { + addSymLinkPermissions Everyone +} diff --git a/scripts/innosetup/addsymlink.iss b/scripts/innosetup/addsymlink.iss new file mode 100644 index 000000000..33fa407af --- /dev/null +++ b/scripts/innosetup/addsymlink.iss @@ -0,0 +1,14 @@ +procedure AddSymLink(); +var + ErrorCode: Integer; + SRCdir: String; +begin + SRCdir := ExpandConstant('{app}'); + if isUninstaller() = false then begin + if not ShellExec('', 'powershell.exe', '-noninteractive -windowstyle hidden -executionpolicy bypass -File "' + SRCdir + '\addSymLinkPermissions.ps1" -mytype ' + SymLinkType, '', SW_HIDE, ewWaitUntilTerminated, ErrorCode) then begin + MsgBox('Failed to automatically grant SeCreateSymbolicLinkPrivilege. Please download Polsedit(www.southsoftware.com/polsedit.zip). Launch polseditx32.exe or polseeditx64.exe (depending on your Windows version), navigate to "Security Settings" -> "User Rights Assignment", add the account(s) to the list named "Create symbolic links", logoff and login back into your account. More info at https://github.com/git-for-windows/git/wiki/Symbolic-Links.', mbInformation, MB_OK); + end else begin + MsgBox('Automatically added SeCreateSymbolicLinkPrivilege. Please logoff and login back into your account in order for the change to take effect.', mbInformation, MB_OK); + end; + end; +end; diff --git a/scripts/innosetup/setup.iss b/scripts/innosetup/setup.iss index d6b169407..35b3fae1a 100644 --- a/scripts/innosetup/setup.iss +++ b/scripts/innosetup/setup.iss @@ -35,14 +35,18 @@ Source: "{#MyAppDir}\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs c [Tasks] Name: modifypath; Description: Adds dvc's application directory to environmental path; Flags: checkablealone; Name: modifypath\system; Description: Adds dvc's application directory to enviromental path for all users; +Name: addsymlinkpermissions; Description: Add permission for creating symbolic links; Flags: checkablealone; +Name: addsymlinkpermissions\system; Description: Add permissions for creating symbolic links for all users; [Code] const ModPathName = 'modifypath'; ModPathPath = '{app}'; + SymLinkName = 'addsymlinkpermissions'; var ModPathType: String; + SymLinkType: String; function GetDefaultDirName(Dummy: string): string; begin @@ -54,6 +58,7 @@ begin end; #include "modpath.iss" +#include "addsymlink.iss" procedure CurStepChanged(CurStep: TSetupStep); begin @@ -64,7 +69,15 @@ begin ModPathType := 'user'; end; + if IsTaskSelected(SymLinkName + '\system') then begin + SymLinkType := 'system'; + end else begin + SymLinkType := 'user'; + end; + if IsTaskSelected(ModPathName) then ModPath(); + if IsTaskSelected(SymLinkName) then + AddSymLink(); end; end;