您可以使用下面提供的示例 PowerShell 预锁定挂钩脚本检查 AD 组成员身份。
pre-lock.ps1 PowerShell脚本检查用户是否是管理员Active Directory 组的成员,如果用户不是该组的成员,则拒绝窃取锁定。
将pre-lock.bat和pre-lock.ps1放入您的存储库“钩子”文件夹中,例如C:\Repositories\repository\hooks\
.
预锁.ps1
# Function check if $user is a member of $group
function Check-GroupMembership
{
param([string]$group, [string]$user)
$server = get-content env:COMPUTERNAME
$query = [ADSI]("WinNT://$server/$group,group")
$ulist = $query.psbase.invoke("Members") |`
%{$_.GetType().InvokeMember("Name", 'GetProperty', $null, $_, $null)}
$ulist -contains $user
}
# Store hook arguments into variables with mnemonic names
$repos = $args[0]
$path = $args[1]
$user = $args[2]
$comment = $args[3]
$steallock = $args[4]
# Build path to svnlook.exe
$svnlook = "$env:VISUALSVN_SERVER\bin\svnlook.exe"
# Get the lock description
$lockdescr = (&"$svnlook" lock $repos $path)
# Find owner name
foreach ($str in $lockdescr)
{
if ($str.StartsWith("Owner: "))
{
$owner = $str.Substring(7)
# We find lock owner's name and it is not the user name
if ($owner -ne "" -and $owner -ne $user)
{
# If the $user is a member of 'Administrators'
# group allow to steal the lock
if (-not (Check-GroupMembership "Administrators" $user))
{
[Console]::Error.WriteLine("Error: $path already locked by $owner.")
exit 1
}
}
exit 0
}
}
exit 0
预锁.bat
@echo off
set PWSH=%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe
%PWSH% %1\hooks\pre-lock.ps1 %1 %2 %3 %4 %5
if errorlevel 1 exit %errorlevel%