Skip to content

Commit

Permalink
dnMerge working. Added wait timer option to exec.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mayyhem committed Oct 26, 2023
1 parent 3ca6b99 commit 955817a
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 1,198 deletions.
4 changes: 4 additions & 0 deletions App.config
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
11 changes: 0 additions & 11 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -997,17 +997,6 @@ static void Main(string[] args)
newCommand.AddGlobalOption(new Option<string>(new[] { "--site-code", "-sc" }, "The three character site code (e.g., \"PS1\") (default: the site code of the client running SharpSCCM)"));
rootCommand.Add(newCommand);

// new admin
//var newAdmin = new Command("admin", "Add a user to the RBAC_Admins table to obtain Full Administrator access to ConfigMgr console and WMI objects (requires local administrator privileges on the server running the site database)");
//newCommand.Add(newAdmin);
//newAdmin.Add(new Argument<string>("user-name", "The domain and user name you would like to grant Full Administrator privilege to (e.g., DOMAIN-SHORTNAME\\USERNAME)"));
//newAdmin.Handler = CommandHandler.Create(
// (string server, string siteCode, string userName) =>
// {
// var connection = Database.Connect(server, siteCode);
// Database.Query(connection, "SELECT * FROM RBAC_Admins");
// });

// new application
var newApplication = new Command("application", "Create an application by contacting an SMS Provider via WMI\n" +
" Permitted security roles:\n" +
Expand Down
7 changes: 5 additions & 2 deletions SharpSCCM.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
<Compile Include="lib\LDAP.cs" />
<Compile Include="lib\LSADump.cs" />
<Compile Include="lib\MgmtPointMessaging.cs" />
<Compile Include="lib\MgmtPointWmi.cs" />
<Compile Include="lib\SmsProviderWmi.cs" />
<Compile Include="lib\MgmtUtil.cs" />
<Compile Include="lib\Credentials.cs" />
<Compile Include="lib\Helpers.cs" />
Expand Down Expand Up @@ -164,9 +164,12 @@
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('packages\dnMerge.0.5.15\build\dnMerge.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\dnMerge.0.5.15\build\dnMerge.targets'))" />
<Error Condition="!Exists('packages\ILMerge.3.0.41\build\ILMerge.props')" Text="$([System.String]::Format('$(ErrorText)', 'packages\ILMerge.3.0.41\build\ILMerge.props'))" />
</Target>
<PropertyGroup>
<PostBuildEvent>$(ProjectDir)packages\ILMerge.3.0.41\tools\net452\ILMerge.exe $(TargetPath) $(TargetDir)System.CommandLine.dll $(TargetDir)System.CommandLine.NamingConventionBinder.dll $(TargetDir)System.Runtime.CompilerServices.Unsafe.dll $(TargetDir)System.Memory.dll $(TargetDir)Microsoft.ConfigurationManagement.Messaging.dll $(TargetDir)Microsoft.ConfigurationManagement.Security.Cryptography.dll $(TargetDir)Newtonsoft.Json.dll $(TargetDir)System.Net.Http.Formatting.dll /out:$(TargetDir)SharpSCCM_merged.exe</PostBuildEvent>
<PostBuildEvent>if $(ConfigurationName) == Debug $(ProjectDir)packages\ILMerge.3.0.41\tools\net452\ILMerge.exe $(TargetPath) $(TargetDir)System.CommandLine.dll $(TargetDir)System.CommandLine.NamingConventionBinder.dll $(TargetDir)System.Runtime.CompilerServices.Unsafe.dll $(TargetDir)System.Memory.dll $(TargetDir)Microsoft.ConfigurationManagement.Messaging.dll $(TargetDir)Microsoft.ConfigurationManagement.Security.Cryptography.dll $(TargetDir)Newtonsoft.Json.dll $(TargetDir)System.Net.Http.Formatting.dll /out:$(TargetDir)SharpSCCM_merged.exe
if $(ConfigurationName) == Debug copy $(TargetDir)SharpSCCM_merged.exe \\192.168.57.101\Users\cthompson\git\SharpSCCM\bin\x64\Debug\SharpSCCM.exe</PostBuildEvent>
</PropertyGroup>
<Import Project="packages\dnMerge.0.5.15\build\dnMerge.targets" Condition="Exists('packages\dnMerge.0.5.15\build\dnMerge.targets')" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
using System.IO;
using System.Management;
using System.Net;
using System.Resources;

namespace SharpSCCM.UnitTests
{
[TestClass]
public class MgmtPointWmiTests
public class SmsProviderWmiTests
{
public TestContext TestContext { get; set; }

Expand Down Expand Up @@ -68,10 +67,10 @@ public void NewCollectionMember_Device_PrintsDeviceNameInCollectionMembers()

ManagementScope wmiConnection = MgmtUtil.NewWmiConnection();
TestContext.WriteLine($"Device name is {deviceName}");
MgmtPointWmi.NewCollection(wmiConnection, "device", collectionName);
SmsProviderWmi.NewCollection(wmiConnection, "device", collectionName);
var stringWriter = new StringWriter();
Console.SetOut(stringWriter);
MgmtPointWmi.NewCollectionMember(wmiConnection, collectionName, null, deviceName);
SmsProviderWmi.NewCollectionMember(wmiConnection, collectionName, null, deviceName);
StringAssert.Contains(stringWriter.ToString(), $"Name: {deviceName.ToUpper()}");
TestContext.WriteLine(stringWriter.ToString());
Cleanup.RemoveCollection(wmiConnection, collectionName, null);
Expand Down
3 changes: 2 additions & 1 deletion UnitTests/UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,10 @@
<Compile Include="ClientWmiTests.cs" />
<Compile Include="MgmtUtilTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="MgmtPointWmiTests.cs" />
<Compile Include="SmsProviderWmiTests.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
Expand Down
15 changes: 15 additions & 0 deletions UnitTests/app.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.6.0" newVersion="4.0.6.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-13.0.0.0" newVersion="13.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
16 changes: 7 additions & 9 deletions lib/AdminService.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Text;
using System.IO;
using System.Net;
using System.Linq;
using System.Management;
using System.Net;
using System.Net.Http;
using System.Net.Security;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Security.Cryptography;
using System.Text.RegularExpressions;
using System.Security.Cryptography.X509Certificates;
using Microsoft.ConfigurationManagement.Messaging.StatusMessages;
using System.Management;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace SharpSCCM
{
Expand Down
3 changes: 1 addition & 2 deletions lib/Crypto.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Microsoft.ConfigurationManagement.Messaging.Framework;
using System;
using System;
using System.Security.Cryptography;

namespace SharpSCCM
Expand Down
13 changes: 0 additions & 13 deletions lib/MgmtPointMessaging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,6 @@ namespace SharpSCCM
{
static class MgmtPointMessaging
{
static MessageCertificateX509 CreateCertificate()
{
// Generate certificate for signing and encrypting messages
string[] oidPurposes = new string[] { "2.5.29.37" }; // Any extended key usage
MessageCertificateX509 certificate = MessageCertificateX509.CreateSelfSignedCertificate("ConfigMgr Client Signing and Encryption", "ConfigMgr Client Signing and Encryption", oidPurposes, DateTime.Now, DateTime.Now.AddMonths(6));
return certificate;
}

public static MessageCertificateX509Volatile CreateUserCertificate(string subjectName = null, bool store = false)
{
// Generate certificate for signing and encrypting messages
Expand Down Expand Up @@ -82,11 +74,6 @@ public static void DeleteCertificate(MessageCertificateX509 certificate)
Console.WriteLine($"[+] Deleted the \"{certificate.X509Certificate.SubjectName.Name}\" certificate from {x509Store.Name} store for {x509Store.Location}");
}

public static void GetAvailablePackages(string managementPoint = null, string siteCode = null)
{

}

public static (MessageCertificateX509, MessageCertificateX509, SmsClientId) GetCertsAndClientId(string managementPoint = null, string siteCode = null, string encodedCertificate = null, string providedClientId = null, string username = null, string password = null, string registerClient = null, string encodedCertPassword = null)
{
MessageCertificateX509 signingCertificate = null;
Expand Down
Loading

0 comments on commit 955817a

Please sign in to comment.