Skip to content

Commit

Permalink
Merge pull request #7 from jcasale/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
jcasale authored Nov 13, 2024
2 parents 298b3a3 + 836f982 commit 53de688
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 55 deletions.
23 changes: 15 additions & 8 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,14 @@ jobs:
with:
global-json-file: src/global.json

- run: echo '${{ steps.setup-dotnet.outputs.dotnet-version }}'
- name: Set dotnet version
id: dotnet-version
run: |
$version = [version]::new('${{ steps.setup-dotnet.outputs.dotnet-version }}')
$label = 'net{0}{1}' -f $version.Major, $version.Minor
echo $label
"label=$label" >> $env:GITHUB_OUTPUT
- name: Run tests
run: dotnet.exe test .\src\UserRights.sln --configuration Release --runtime win-x64
Expand All @@ -41,12 +48,12 @@ jobs:
- name: Archive runtime-dependent release
run: |
cd ./publish
Get-ChildItem . -Exclude *.pdb,*.xml -Recurse |Compress-Archive -DestinationPath ../UserRights-net80-x64.zip
Get-ChildItem . -Exclude *.pdb,*.xml -Recurse |Compress-Archive -DestinationPath ../UserRights-${{ steps.dotnet-version.outputs.label }}-x64.zip
- name: Upload runtime-dependent release
uses: actions/upload-artifact@v4
with:
name: UserRights-net80-x64
name: UserRights-${{ steps.dotnet-version.outputs.label }}-x64
path: publish
if-no-files-found: error

Expand All @@ -59,12 +66,12 @@ jobs:
- name: Archive self-contained release
run: |
cd ./publish-packed
Compress-Archive -Path ./UserRights.exe -DestinationPath ../UserRights-net80-x64-self-contained.zip
Compress-Archive -Path ./UserRights.exe -DestinationPath ../UserRights-${{ steps.dotnet-version.outputs.label }}-x64-self-contained.zip
- name: Upload self-contained release
uses: actions/upload-artifact@v4
with:
name: UserRights-net80-x64-self-contained
name: UserRights-${{ steps.dotnet-version.outputs.label }}-x64-self-contained
path: publish-packed
if-no-files-found: error

Expand All @@ -76,14 +83,14 @@ jobs:
Compiled with .NET SDK ${{ steps.setup-dotnet.outputs.dotnet-version }}
## UserRights-net80-x64-self-contained.zip
## UserRights-${{ steps.dotnet-version.outputs.label }}-x64-self-contained.zip
Self-contained release for Windows x64
## UserRights-net80-x64.zip
## UserRights-${{ steps.dotnet-version.outputs.label }}-x64.zip
Framework-dependent release for Windows x64
'@ |gh.exe release create ${{ github.ref }} --title ${{ github.ref_name }} --notes-file - UserRights-net80-x64.zip UserRights-net80-x64-self-contained.zip
'@ |gh.exe release create ${{ github.ref }} --title ${{ github.ref_name }} --notes-file - UserRights-${{ steps.dotnet-version.outputs.label }}-x64.zip UserRights-${{ steps.dotnet-version.outputs.label }}-x64-self-contained.zip
env:
# Requires a personal access token with a fine-grained permission of contents:read/write.
GH_TOKEN: ${{ secrets.MY_GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions src/StyleCop.ruleset
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<Rule Id="CA1014" Action="None" />
<Rule Id="CA1016" Action="None" />
<Rule Id="CA1031" Action="None" />
<Rule Id="CA1515" Action="None" />
<Rule Id="CA1819" Action="None" />
<Rule Id="CA1848" Action="None" />
<Rule Id="CA1859" Action="None" />
Expand Down
14 changes: 7 additions & 7 deletions src/Tests.Application/Tests.Application.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<TargetFramework>net9.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<AnalysisLevel>latest-All</AnalysisLevel>
Expand All @@ -11,15 +11,15 @@

<ItemGroup>
<PackageReference Include="CsvHelper" Version="33.0.1" />
<PackageReference Include="Meziantou.Analyzer" Version="2.0.169">
<PackageReference Include="Meziantou.Analyzer" Version="2.0.178">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Ini" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Ini" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="9.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="StyleCop.Analyzers.Unstable" Version="1.2.0.556">
<PrivateAssets>all</PrivateAssets>
Expand Down
6 changes: 3 additions & 3 deletions src/Tests.Application/UserRightsManagerListTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ public async Task SerializingToCsvShouldWork()
var policy = new MockLsaUserRights(database);
policy.Connect("SystemName");

Assert.Equal(new[] { PrincipalSid1, PrincipalSid2 }, policy.LsaEnumerateAccountsWithUserRight().Order());
Assert.Equal(new[] { Privilege1, Privilege2 }, policy.LsaEnumerateAccountRights(PrincipalSid1));
Assert.Equal(new[] { Privilege1, Privilege2 }, policy.LsaEnumerateAccountRights(PrincipalSid2));
Assert.Equal([PrincipalSid1, PrincipalSid2], policy.LsaEnumerateAccountsWithUserRight().Order());
Assert.Equal([Privilege1, Privilege2], policy.LsaEnumerateAccountRights(PrincipalSid1));
Assert.Equal([Privilege1, Privilege2], policy.LsaEnumerateAccountRights(PrincipalSid2));

var manager = this.ServiceProvider.GetRequiredService<IUserRightsManager>();
var userRights = manager.GetUserRights(policy).ToArray();
Expand Down
20 changes: 10 additions & 10 deletions src/Tests.Application/UserRightsManagerPrivilegeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,16 @@ public void GrantAndRevokeOthersShouldWork()
Assert.Equal(new[] { Privilege1 }, policy.LsaEnumerateAccountRights(PrincipalSid1));
Assert.Equal(new[] { Privilege1, Privilege2 }.Order(StringComparer.OrdinalIgnoreCase), policy.LsaEnumerateAccountRights(PrincipalSid2).Order(StringComparer.OrdinalIgnoreCase));
Assert.Equal(new[] { PrincipalSid1, PrincipalSid2 }.Order(), policy.LsaEnumerateAccountsWithUserRight(Privilege1).Order());
Assert.Equal(new[] { PrincipalSid2 }, policy.LsaEnumerateAccountsWithUserRight(Privilege2));
Assert.Equal([PrincipalSid2], policy.LsaEnumerateAccountsWithUserRight(Privilege2));

var manager = this.ServiceProvider.GetRequiredService<IUserRightsManager>();
manager.ModifyPrivilege(policy, Privilege2, [PrincipalName1], [], false, true, null!, false);

Assert.Equal(new[] { PrincipalSid1, PrincipalSid2 }.Order(), policy.LsaEnumerateAccountsWithUserRight().Order());
Assert.Equal(new[] { Privilege1, Privilege2 }.Order(StringComparer.OrdinalIgnoreCase), policy.LsaEnumerateAccountRights(PrincipalSid1).Order(StringComparer.OrdinalIgnoreCase));
Assert.Equal(new[] { Privilege1 }, policy.LsaEnumerateAccountRights(PrincipalSid2));
Assert.Equal([Privilege1], policy.LsaEnumerateAccountRights(PrincipalSid2));
Assert.Equal(new[] { PrincipalSid1, PrincipalSid2 }.Order(), policy.LsaEnumerateAccountsWithUserRight(Privilege1).Order());
Assert.Equal(new[] { PrincipalSid1 }, policy.LsaEnumerateAccountsWithUserRight(Privilege2));
Assert.Equal([PrincipalSid1], policy.LsaEnumerateAccountsWithUserRight(Privilege2));
}

/// <summary>
Expand Down Expand Up @@ -191,8 +191,8 @@ public void GrantAndRevokePatternShouldWork()

Assert.Equal(new[] { PrincipalSid1, PrincipalSid2, PrincipalSid3 }.Order(), policy.LsaEnumerateAccountsWithUserRight().Order());
Assert.Equal(new[] { Privilege1, Privilege2 }.Order(StringComparer.OrdinalIgnoreCase), policy.LsaEnumerateAccountRights(PrincipalSid1).Order(StringComparer.OrdinalIgnoreCase));
Assert.Equal(new[] { Privilege1, Privilege2 }, policy.LsaEnumerateAccountRights(PrincipalSid2).Order(StringComparer.OrdinalIgnoreCase));
Assert.Equal(new[] { Privilege1, Privilege2 }, policy.LsaEnumerateAccountRights(PrincipalSid3).Order(StringComparer.OrdinalIgnoreCase));
Assert.Equal([Privilege1, Privilege2], policy.LsaEnumerateAccountRights(PrincipalSid2).Order(StringComparer.OrdinalIgnoreCase));
Assert.Equal([Privilege1, Privilege2], policy.LsaEnumerateAccountRights(PrincipalSid3).Order(StringComparer.OrdinalIgnoreCase));
}

/// <summary>
Expand Down Expand Up @@ -364,8 +364,8 @@ public void RevokePatternForAllButBuiltinAndVirtualShouldWork()
policy.Connect("SystemName");

Assert.Equal(new[] { PrincipalSidCurrent, PrincipalSid1, PrincipalSid2, PrincipalSid3 }.Order(), policy.LsaEnumerateAccountsWithUserRight().Order());
Assert.Equal(new[] { Privilege1 }, policy.LsaEnumerateAccountRights(PrincipalSidCurrent));
Assert.Equal(new[] { Privilege2 }, policy.LsaEnumerateAccountRights(PrincipalSid1));
Assert.Equal([Privilege1], policy.LsaEnumerateAccountRights(PrincipalSidCurrent));
Assert.Equal([Privilege2], policy.LsaEnumerateAccountRights(PrincipalSid1));
Assert.Equal(new[] { Privilege1, Privilege2 }.Order(StringComparer.OrdinalIgnoreCase), policy.LsaEnumerateAccountRights(PrincipalSid2).Order(StringComparer.OrdinalIgnoreCase));
Assert.Equal(new[] { Privilege1, Privilege2 }.Order(StringComparer.OrdinalIgnoreCase), policy.LsaEnumerateAccountRights(PrincipalSid3).Order(StringComparer.OrdinalIgnoreCase));

Expand All @@ -374,8 +374,8 @@ public void RevokePatternForAllButBuiltinAndVirtualShouldWork()
manager.ModifyPrivilege(policy, Privilege1, [], [], false, false, pattern, false);

Assert.Equal(new[] { PrincipalSid1, PrincipalSid2, PrincipalSid3 }.Order(), policy.LsaEnumerateAccountsWithUserRight().Order());
Assert.Equal(new[] { Privilege2 }, policy.LsaEnumerateAccountRights(PrincipalSid1));
Assert.Equal(new[] { Privilege1, Privilege2 }, policy.LsaEnumerateAccountRights(PrincipalSid2).Order(StringComparer.OrdinalIgnoreCase));
Assert.Equal(new[] { Privilege1, Privilege2 }, policy.LsaEnumerateAccountRights(PrincipalSid3).Order(StringComparer.OrdinalIgnoreCase));
Assert.Equal([Privilege2], policy.LsaEnumerateAccountRights(PrincipalSid1));
Assert.Equal([Privilege1, Privilege2], policy.LsaEnumerateAccountRights(PrincipalSid2).Order(StringComparer.OrdinalIgnoreCase));
Assert.Equal([Privilege1, Privilege2], policy.LsaEnumerateAccountRights(PrincipalSid3).Order(StringComparer.OrdinalIgnoreCase));
}
}
10 changes: 5 additions & 5 deletions src/Tests.Cli/Tests.Cli.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<TargetFramework>net9.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<AnalysisLevel>latest-All</AnalysisLevel>
Expand All @@ -11,13 +11,13 @@

<ItemGroup>
<PackageReference Include="CsvHelper" Version="33.0.1" />
<PackageReference Include="Meziantou.Analyzer" Version="2.0.169">
<PackageReference Include="Meziantou.Analyzer" Version="2.0.178">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="9.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="StyleCop.Analyzers.Unstable" Version="1.2.0.556">
<PrivateAssets>all</PrivateAssets>
Expand Down
4 changes: 2 additions & 2 deletions src/Tests/Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<TargetFramework>net9.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<AnalysisLevel>latest-All</AnalysisLevel>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Meziantou.Analyzer" Version="2.0.169">
<PackageReference Include="Meziantou.Analyzer" Version="2.0.178">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
13 changes: 6 additions & 7 deletions src/UserRights.Application/LsaUserRights.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,11 @@ public unsafe string[] LsaEnumerateAccountRights(SecurityIdentifier accountSid)

for (var i = 0; i < count; i++)
{
var offset = Marshal.SizeOf(typeof(LSA_UNICODE_STRING)) * i;
var offset = Marshal.SizeOf<LSA_UNICODE_STRING>() * i;
var ptr = nint.Add((nint)userRights, offset);
var result = Marshal.PtrToStructure(ptr, typeof(LSA_UNICODE_STRING)) ?? throw new InvalidOperationException();
var unicodeString = (LSA_UNICODE_STRING)result;
var result = Marshal.PtrToStructure<LSA_UNICODE_STRING>(ptr);

results[i] = new string(unicodeString.Buffer.Value);
results[i] = new string(result.Buffer.Value);
}

return results;
Expand Down Expand Up @@ -201,9 +200,9 @@ SecurityIdentifier[] Method(LSA_UNICODE_STRING right)

for (var i = 0; i < count; i++)
{
var offset = Marshal.SizeOf(typeof(LSA_ENUMERATION_INFORMATION)) * i;
var result = Marshal.PtrToStructure(nint.Add((nint)buffer, offset), typeof(LSA_ENUMERATION_INFORMATION)) ?? throw new InvalidOperationException();
var sid = ((LSA_ENUMERATION_INFORMATION)result).Sid;
var offset = Marshal.SizeOf<LSA_ENUMERATION_INFORMATION>() * i;
var result = Marshal.PtrToStructure<LSA_ENUMERATION_INFORMATION>(nint.Add((nint)buffer, offset));
var sid = result.Sid;

results[i] = new SecurityIdentifier((nint)sid.Value);
}
Expand Down
6 changes: 3 additions & 3 deletions src/UserRights.Application/UserRights.Application.csproj
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<TargetFramework>net9.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<AnalysisLevel>latest-All</AnalysisLevel>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Meziantou.Analyzer" Version="2.0.169">
<PackageReference Include="Meziantou.Analyzer" Version="2.0.178">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.0" />
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.106">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
6 changes: 3 additions & 3 deletions src/UserRights.Cli/UserRights.Cli.csproj
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<TargetFramework>net9.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<AnalysisLevel>latest-All</AnalysisLevel>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Meziantou.Analyzer" Version="2.0.169">
<PackageReference Include="Meziantou.Analyzer" Version="2.0.178">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0" />
<PackageReference Include="StyleCop.Analyzers.Unstable" Version="1.2.0.556">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
4 changes: 2 additions & 2 deletions src/UserRights.Extensions/UserRights.Extensions.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<TargetFramework>net9.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<AnalysisLevel>latest-All</AnalysisLevel>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CsvHelper" Version="33.0.1" />
<PackageReference Include="Meziantou.Analyzer" Version="2.0.169">
<PackageReference Include="Meziantou.Analyzer" Version="2.0.178">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
8 changes: 4 additions & 4 deletions src/UserRights/UserRights.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<TargetFramework>net9.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<AnalysisLevel>latest-All</AnalysisLevel>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Meziantou.Analyzer" Version="2.0.169">
<PackageReference Include="Meziantou.Analyzer" Version="2.0.178">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
<PackageReference Include="Serilog" Version="4.0.2" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0" />
<PackageReference Include="Serilog" Version="4.1.0" />
<PackageReference Include="Serilog.Enrichers.Environment" Version="3.0.1" />
<PackageReference Include="Serilog.Enrichers.GlobalLogContext" Version="3.0.0" />
<PackageReference Include="Serilog.Enrichers.Process" Version="3.0.0" />
Expand Down
2 changes: 1 addition & 1 deletion src/global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "8.0.403",
"version": "9.0.100",
"rollForward": "latestFeature"
}
}

0 comments on commit 53de688

Please sign in to comment.