├── .config
├── .cdp
│ ├── officialbuild.xml
│ └── release-officialbuild.xml
├── .inc
│ ├── bldver.cpp
│ ├── bldver.cs
│ ├── bldver.h
│ ├── bldver.vb
│ ├── version.htm
│ └── versions.xml
├── CredScanSuppressions.json
├── InPath
│ ├── build.cmd
│ ├── clean.cmd
│ ├── quickbuild.cmd
│ ├── releasebuild.cmd
│ └── restore.cmd
└── PsModules
│ ├── DeveloperHelpers.psm1
│ └── Install-QuickBuild.psm1
├── .gitattributes
├── .github
└── workflows
│ └── msbuild.yml
├── .gitignore
├── .gitmodules
├── .pipelines
├── OneBranch.Buddy.yml
├── OneBranch.Official.yml
└── OneBranch.PullRequest.yml
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── CloudBuild.json
├── Directory.Build.props
├── Directory.Build.rsp
├── Directory.Build.targets
├── LICENSE
├── NuGet.Config
├── Packages.props
├── README.md
├── SECURITY.md
├── SUPPORT.md
├── build
├── CloudServiceSchema.targets
├── DefaultBuildFlavor.props
├── DefaultCloudBuildModifiers.props
├── DefaultRepositoryVariables.props
├── Local
│ └── Extensions
│ │ └── Version.targets
├── NuProj
│ ├── AfterNuProj.props
│ ├── AfterNuProj.targets
│ ├── Microsoft.Build.Utilities.v12.0.dll
│ ├── Microsoft.Common.NuProj.targets
│ ├── NuGet.Core.dll
│ ├── NuGet.exe
│ ├── NuProj.Tasks.dll
│ ├── NuProj.props
│ ├── NuProj.targets
│ └── UnifiedNugetDrop.targets
├── README.txt
├── StyleCop
│ └── StyleCop.props
├── Versions
│ ├── ProcessVersionFiles.ps1
│ ├── bldver.hf
│ ├── bldvercs.hf
│ ├── bldvermc.hf
│ └── bldvervb.hf
├── build.props
├── config
│ ├── signing_options.json
│ └── validation
│ │ └── CiPolicyAnalyzerConfig.json
├── signing
│ ├── 35MSSharedLib1024.snk
│ ├── CloudServiceSigning.targets
│ └── StrongName.props
└── stageoutput
│ └── StageOutput.targets
├── dirs.proj
├── global.json
├── owners.txt
└── src
├── Directory.Build.props
├── Directory.Build.targets
├── PKI
├── ExitModule
│ ├── Buffer.h
│ ├── CertServerExit.cpp
│ ├── CertServerExit.h
│ ├── CertServerPropType.h
│ ├── EventArg.cpp
│ ├── EventArg.h
│ ├── EventProcessor.cpp
│ ├── EventProcessor.h
│ ├── EventProcessorConfig.cpp
│ ├── EventProcessorConfig.h
│ ├── EventSource.cpp
│ ├── EventSource.h
│ ├── ExitModule.cpp
│ ├── ExitModule.def
│ ├── ExitModule.idl
│ ├── ExitModule.rc
│ ├── ExitModule.rgs
│ ├── ExitModule.vcxproj
│ ├── ExitModuleps.def
│ ├── ManageProperty.h
│ ├── PMICertExit.cpp
│ ├── PMICertExit.h
│ ├── PMICertExit.rgs
│ ├── PMIExitModule.cpp
│ ├── PMIExitModule.h
│ ├── PMIExitModule.rgs
│ ├── PMIExitModuleEventSource.cpp
│ ├── PMIExitModuleEventSource.h
│ ├── Process.cpp
│ ├── Process.h
│ ├── ResourceStringManageProperty.cpp
│ ├── ResourceStringManageProperty.h
│ ├── TempFile.cpp
│ ├── TempFile.h
│ ├── dllmain.cpp
│ ├── dllmain.h
│ ├── framework.h
│ ├── pch.cpp
│ ├── pch.h
│ ├── resource.h
│ └── targetver.h
├── ExitModuleEventLog.reg
├── ExitModuleExe.reg
├── ExitModulePS
│ └── ExitModulePS.vcxproj
├── FailedScript.ps1
├── PMIExitModuleMessages
│ ├── PMIExitModuleEventSourceDef.h
│ ├── PMIExitModuleMessages.mc
│ ├── PMIExitModuleMessages.vcxproj
│ ├── dllmain.cpp
│ ├── framework.h
│ ├── pch.cpp
│ └── pch.h
├── PMIExitModuleMessagesSetup
│ ├── Arguments.cpp
│ ├── Arguments.h
│ ├── PMIExitModuleMessagesSetup.vcxproj
│ ├── main.cpp
│ └── packages.config
├── README.md
├── SampleScript.ps1
├── TimeoutScript.ps1
├── WindowsSDKMisc.props
├── WindowsSDKMisc.targets
└── dirs.proj
├── TestConsoleApp
├── TestConsoleApp.cpp
├── TestConsoleApp.sln
├── TestConsoleApp.vcxproj
├── TestConsoleApp.vcxproj.filters
└── packages.config
└── dirs.proj
/.config/.cdp/officialbuild.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
15 |
16 |
17 | src/Vsts/Definitions/OfficialBuildBT.xml
18 |
19 |
20 |
21 |
22 |
23 |
26 | Official Build - MSBuild
27 |
30 | Official Build - MSBuild
31 |
34 |
35 |
36 |
37 |
38 | 0
39 |
40 | true
41 |
42 | Break
43 |
44 |
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/.config/.cdp/release-officialbuild.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
15 |
16 |
17 | src/Vsts/Definitions/OfficialBuildBT.xml
18 |
19 |
20 |
21 |
22 |
23 |
26 | Official Build - MSBuild
27 |
30 | Official Build - MSBuild
31 |
34 |
35 |
36 |
37 |
38 | 1
39 |
40 |
41 | Enforce
42 |
43 |
44 | true
45 |
46 | Break
47 |
48 |
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/.config/.inc/bldver.cpp:
--------------------------------------------------------------------------------
1 | using namespace System::Reflection;
2 | using namespace System::Runtime::CompilerServices;
3 |
4 | //
5 | // if you want to use a private version file and customize this, see
6 | // file://samsndrop02/CoreXT-Latest/docs/corext/corext/version.htm
7 | //
8 |
9 | [assembly: AssemblyVersion("1.1.0.343")];
10 |
11 | [assembly: AssemblyCompany("Microsoft Corp.")];
12 | [assembly: AssemblyProduct("Microsoft Account")];
13 | [assembly: AssemblyCopyright("2020")];
14 |
15 |
16 |
17 | #if ENABLE_CODESIGN
18 | #if !(BUILD_NO_GLOBAL_STRONG_NAME)
19 | #if ENABLE_PRS_DELAYSIGN
20 | [assembly: AssemblyDelaySign(true)];
21 | [assembly: AssemblyKeyFile("%CODESIGN_KEY:\=\\%")];
22 | #else
23 | [assembly: AssemblyKeyFile("%CODESIGN_TESTKEY:\=\\%")];
24 | [assembly: AssemblyKeyName("")];
25 | [assembly: AssemblyDelaySign(false)];
26 | #endif
27 | #endif
28 | #endif
29 |
--------------------------------------------------------------------------------
/.config/.inc/bldver.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 |
4 | //
5 | // if you want to use a private version file and customize this, see
6 | // file://samsndrop02/CoreXT-Latest/docs/corext/corext/version.htm
7 | //
8 |
9 | [assembly: AssemblyVersion("1.1.0.343")]
10 |
11 | [assembly: AssemblyCompany("Microsoft Corp.")]
12 | [assembly: AssemblyProduct("Microsoft Account")]
13 | [assembly: AssemblyCopyright("2020")]
14 |
15 | #if ENABLE_CODESIGN
16 |
17 | #if ENABLE_PRS_DELAYSIGN
18 | [assembly: AssemblyKeyFile(@"")]
19 | [assembly: AssemblyKeyName("")]
20 | [assembly: AssemblyDelaySign(true)]
21 | #else
22 | [assembly: AssemblyKeyFile(@"")]
23 | [assembly: AssemblyKeyName("")]
24 | [assembly: AssemblyDelaySign(false)]
25 | #endif
26 |
27 | #endif
28 |
--------------------------------------------------------------------------------
/.config/.inc/bldver.h:
--------------------------------------------------------------------------------
1 | //
2 | // this file is automatically generated
3 | // by beaver.exe %BeaverVersion%
4 | //
5 |
6 | //
7 | // if you want to use a private version file and customize this, see
8 | // file://samsndrop02/CoreXT-Latest/docs/corext/corext/version.htm
9 | //
10 |
11 | #ifndef _BLDVER_H_
12 | #define _BLDVER_H_
13 |
14 | #define BUILD_NUMBER "0.343"
15 | #define BUILD_NUM 0,343
16 | #define PRODUCT_NUMBER "1.1"
17 | #define PRODUCT_NUM 1,0
18 | #define INET_VERSION "1.1.0.343"
19 | #define INET_VER 1,0,0,343
20 |
21 | #define PRODUCT_MAJOR 1
22 | #define PRODUCT_MAJOR_STRING "1"
23 | #define PRODUCT_MAJOR_NUMBER 1
24 |
25 | #define PRODUCT_MINOR 1
26 | #define PRODUCT_MINOR_STRING "1"
27 | #define PRODUCT_MINOR_NUMBER 0
28 |
29 | #define BUILD_MAJOR 0
30 | #define BUILD_MAJOR_STRING "0"
31 | #define BUILD_MAJOR_NUMBER 0
32 |
33 | #define BUILD_MINOR 343
34 | #define BUILD_MINOR_STRING "343"
35 | #define BUILD_MINOR_NUMBER 343
36 |
37 | #ifdef DEBUG
38 | #define BUILD_FILEFLAGS_DEBUG | VS_FF_DEBUG
39 | #else
40 | #define BUILD_FILEFLAGS_DEBUG
41 | #endif
42 |
43 | #if defined(BUILD_LABBUILD)
44 | #if !defined(ENABLE_PRS_DELAYSIGN)
45 | #define BUILD_FILEFLAGS_RELEASE | VS_FF_PRERELEASE
46 | #else
47 | #define BUILD_FILEFLAGS_RELEASE
48 | #endif
49 |
50 | #ifndef BUILD_PRODUCTION
51 | #define BUILD_FILEFLAGS_SPECIAL | VS_FF_SPECIALBUILD
52 | #define BUILD_SPECIAL "local"
53 | #else
54 | #define BUILD_FILEFLAGS_SPECIAL
55 | #endif
56 |
57 | #define BUILD_FILEFLAGS_PRIVATE
58 | #else
59 | #define BUILD_FILEFLAGS_RELEASE
60 | #define BUILD_FILEFLAGS_SPECIAL
61 | #define BUILD_FILEFLAGS_PRIVATE | VS_FF_PRIVATEBUILD
62 | #define BUILD_PRIVATE "local (by jrowlett on JROWLETT3)"
63 | #endif
64 |
65 | #define BUILD_FILEFLAGS 0x0L BUILD_FILEFLAGS_RELEASE BUILD_FILEFLAGS_SPECIAL BUILD_FILEFLAGS_PRIVATE BUILD_FILEFLAGS_DEBUG
66 |
67 |
68 | #define VER_PRODUCTVERSION 1,0,0,343
69 | #define VER_PRODUCTVERSION_STR "1.0.0.343"
70 | #define VER_PRODUCTVERSION_STR_FULL "1.1.0.343"
71 | #define VER_PRODUCTVERSION_QSTR "1.1,0,343"
72 | #define VER_PRODUCTVERSION_WSTR L"1.1.0.343"
73 | #define VER_PRODUCTVERSION_W ((1 << 8) | 1)
74 | #define VER_PRODUCTMAJORVERSION 1
75 | #define VER_PRODUCTMINORVERSION 1
76 | //This is to appease a BuildDirectories.pm regex in finding the version part3 and we redefine it immediately after.
77 | #define VER_PRODUCTBUILD /* NT */ 0
78 | #define VER_PRODUCTBUILD 0
79 | #define VER_PRODUCTBUILD_QFE 343
80 | #define VER_PRODUCTNAME_STR "Microsoft Account"
81 | #define VER_COMPANYNAME_STR "Microsoft Corporation"
82 |
83 |
84 |
85 |
86 | #endif
87 |
--------------------------------------------------------------------------------
/.config/.inc/bldver.vb:
--------------------------------------------------------------------------------
1 | imports System.Reflection
2 | imports System.Runtime.InteropServices
3 |
4 | '
5 | ' if you want to use a private version file and customize this, see
6 | ' file://samsndrop02/CoreXT-Latest/docs/corext/corext/version.htm
7 | '
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | #if ENABLE_CODESIGN
17 |
18 | #if ENABLE_PRS_DELAYSIGN
19 |
20 |
21 |
22 | #else
23 |
24 |
25 |
26 | #end if
27 |
28 | #end if
29 |
30 |
--------------------------------------------------------------------------------
/.config/.inc/version.htm:
--------------------------------------------------------------------------------
1 | Version 1.1 (Build 0.343)
2 |
--------------------------------------------------------------------------------
/.config/.inc/versions.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/.config/CredScanSuppressions.json:
--------------------------------------------------------------------------------
1 | {
2 | "tool":"Credential Scanner",
3 | "suppressions":[
4 | {
5 | "file":[
6 | "packages\\Kits.10.0.18362.1\\tools\\Tools\\certificates\\OEM_App_Test_Cert_2013.pfx",
7 | "packages\\Kits.10.0.18362.1\\tools\\Tools\\certificates\\OEM_App_Test_Cert_2017.pfx",
8 | "packages\\Kits.10.0.18362.1\\tools\\Tools\\certificates\\OEM_HAL_Extension_Test_Cert_2013.pfx",
9 | "packages\\Kits.10.0.18362.1\\tools\\Tools\\certificates\\OEM_HAL_Extension_Test_Cert_2017.pfx",
10 | "packages\\Kits.10.0.18362.1\\tools\\Tools\\certificates\\OEM_Intermediate_Cert.pfx",
11 | "packages\\Kits.10.0.18362.1\\tools\\Tools\\certificates\\OEM_Intermediate_Cert_2017.pfx",
12 | "packages\\Kits.10.0.18362.1\\tools\\Tools\\certificates\\OEM_Intermediate_FFU_Cert.pfx",
13 | "packages\\Kits.10.0.18362.1\\tools\\Tools\\certificates\\OEM_Intermediate_FFU_Cert_2017.pfx",
14 | "packages\\Kits.10.0.18362.1\\tools\\Tools\\certificates\\OEM_PPL_Test_Cert_2013.pfx",
15 | "packages\\Kits.10.0.18362.1\\tools\\Tools\\certificates\\OEM_PPL_Test_Cert_2017.pfx",
16 | "packages\\Kits.10.0.18362.1\\tools\\Tools\\certificates\\OEM_PP_Test_Cert_2013.pfx",
17 | "packages\\Kits.10.0.18362.1\\tools\\Tools\\certificates\\OEM_PP_Test_Cert_2017.pfx",
18 | "packages\\Kits.10.0.18362.1\\tools\\Tools\\certificates\\OEM_Root_CA.pfx",
19 | "packages\\Kits.10.0.18362.1\\tools\\Tools\\certificates\\OEM_Root_CA_2017.pfx",
20 | "packages\\Kits.10.0.18362.1\\tools\\Tools\\certificates\\OEM_Test_Cert_2013.pfx",
21 | "packages\\Kits.10.0.18362.1\\tools\\Tools\\certificates\\OEM_Test_Cert_2017.pfx",
22 | "packages\\Kits.10.0.18362.1\\tools\\Tools\\certificates\\OEM_Test_PK_Cert_2013.pfx",
23 | "packages\\Kits.10.0.18362.1\\tools\\Tools\\certificates\\OEM_Test_PK_Cert_2017.pfx"
24 | ],
25 | "_justification":"These secrets are froma 3rd party package"
26 | },
27 | {
28 | "file":[
29 | "out\\release-x64\\Voting\\VotingWebPkg\\Code\\wwwroot\\lib\\angular\\angular.js",
30 | "src\\Samples\\ServiceFabric\\VotingWeb\\obj\\release\\net461\\win7-x64\\PubTmp\\Out\\wwwroot\\lib\\angular\\angular.js",
31 | "src\\Samples\\ServiceFabric\\VotingWeb\\wwwroot\\lib\\angular\\angular.js"
32 | ],
33 | "_justification":"These secrets are used as samples"
34 | }
35 | ]
36 | }
37 |
--------------------------------------------------------------------------------
/.config/InPath/build.cmd:
--------------------------------------------------------------------------------
1 | @echo off
2 | set __scriptDir=%~dp0%..\PsModules
3 | powershell -ExecutionPolicy bypass -Command "$psm1p = Join-Path %__scriptDir% DeveloperHelpers.psm1; Import-Module $psm1p ; Invoke-MSBuild"
--------------------------------------------------------------------------------
/.config/InPath/clean.cmd:
--------------------------------------------------------------------------------
1 | @echo off
2 | set __scriptDir=%~dp0%..\PsModules
3 | powershell -ExecutionPolicy bypass -Command "$psm1p = Join-Path %__scriptDir% DeveloperHelpers.psm1; Import-Module $psm1p ; Reset-Repo"
--------------------------------------------------------------------------------
/.config/InPath/quickbuild.cmd:
--------------------------------------------------------------------------------
1 | @echo off
2 | set __scriptDir=%~dp0%..\PsModules
3 | powershell -ExecutionPolicy bypass -Command "$psm1p = Join-Path %__scriptDir% Install-QuickBuild.psm1; Import-Module $psm1p ; quickbuild %*"
--------------------------------------------------------------------------------
/.config/InPath/releasebuild.cmd:
--------------------------------------------------------------------------------
1 | @echo off
2 | set __scriptDir=%~dp0%..\PsModules
3 | powershell -ExecutionPolicy bypass -Command "$psm1p = Join-Path %__scriptDir% DeveloperHelpers.psm1; Import-Module $psm1p ; Invoke-MSBuild -Release"
--------------------------------------------------------------------------------
/.config/InPath/restore.cmd:
--------------------------------------------------------------------------------
1 | @echo off
2 | set __scriptDir=%~dp0%..\PsModules
3 | powershell -ExecutionPolicy bypass -Command "$psm1p = Join-Path %__scriptDir% DeveloperHelpers.psm1; Import-Module $psm1p ; Restore-Packages"
--------------------------------------------------------------------------------
/.config/PsModules/DeveloperHelpers.psm1:
--------------------------------------------------------------------------------
1 | <#
2 | .SYNOPSIS
3 | Add PowerShell functions here which help the local developer experience
4 | - Developer can add these commands to their PS environment by running AddModules.ps1 at the root
5 | - These functions are not available on remote builds
6 | #>
7 |
8 | <#
9 | .SYNOPSIS
10 | Refresh credentials to the NuGet feeds
11 | This allows the credential provider to use an interactive prompt which msbuild /t:restore doesn't do
12 | #>
13 | function Update-NuGetCredentials()
14 | {
15 | $nugetConfig = "$PSScriptRoot\..\..\nuget.config"
16 | $credentialManager = "$PSScriptRoot\..\..\build\local\nuget\CredentialProvider.VSS.exe"
17 | [xml] $xml = Get-Content $nugetConfig
18 | $sources = $xml.Configuration.PackageSources.add.value
19 |
20 | foreach ($source in $sources)
21 | {
22 | Write-Host "Refreshing credentials for $source"
23 | $output = Invoke-Expression "$credentialManager -u $source 2>&1"
24 |
25 | if ($lastExitCode -eq 0)
26 | {
27 | Write-Host "Success"
28 | }
29 | else
30 | {
31 | Write-Error "Credential Provider failed"
32 | Write-Host $output
33 | }
34 | }
35 | }
36 |
37 | <#
38 | .SYNOPSIS
39 | Invokes MSBuild with some default arguments:
40 | 1. N-1 degrees of parallelism. Speeds up the build but doesn't kill your computer
41 | 2. Log to a file (msbuild.log)
42 | #>
43 | function Invoke-MSBuild([switch]$Release, [switch]$SkipProjectReferences, [switch]$Investigate) {
44 | $parallel = $env:NUMBER_OF_PROCESSORS - 1
45 | # explicitly find a *.*proj to avoid invoking it on an sln
46 | $proj = (Get-ChildItem *.*proj)[0]
47 | $configuration = "Debug"
48 | if ($release) {
49 | $configuration = "Release"
50 | }
51 | $skipReferences = "true"
52 | if ($SkipProjectReferences) {
53 | $skipReferences = "false"
54 | }
55 |
56 | if ($Investigate) {
57 | msbuild /maxcpucount:$parallel /v:diag /bl:log.binlog /filelogger /property:BuildProjectReferences=$skipReferences /property:Configuration=$configuration $proj /consoleloggerparameters:Verbosity=normal
58 | } else {
59 | msbuild /maxcpucount:$parallel /v:normal /filelogger /property:BuildProjectReferences=$skipReferences /property:Configuration=$configuration $proj
60 | }
61 | }
62 |
63 | <#
64 | .SYNOPSIS
65 | Forces a NuGet restore by cleaning the CBT 'build' folder and then calling msbuild /t:restore
66 |
67 | MSBuild doesn't eagerly restore packages, so if you do a git pull and someone updated a package,
68 | MSBuild will not download the package unless you do something like clean the 'build' folder.
69 | #>
70 | function Restore-Packages()
71 | {
72 | $buildFolder = Join-Path $PSScriptRoot "..\..\build"
73 | pushd $buildFolder
74 | Write-Host "Cleaning 'build' folder"
75 | git clean -xfd
76 | popd
77 | pushd (Resolve-Path (Join-Path $PSScriptRoot "..\..\"))
78 | Write-Host "Begin restore"
79 | msbuild /t:Restore
80 | popd
81 | }
82 |
83 | <#
84 | .SYNOPSIS
85 | Cleans the repo without wiping out NuGet packages.
86 |
87 | Will check for uncommited files to prevent losing work.
88 | #>
89 | function Reset-Repo()
90 | {
91 | pushd (Resolve-Path (Join-Path $PSScriptRoot "..\..\"))
92 | $changes = git status -s
93 | if ($null -ne $changes) {
94 | Write-Host "!!!WARNING: You have uncommited files" -ForegroundColor 'Yellow'
95 | git status
96 | $response = Read-Host "Proceed? (y/n)"
97 | if ($response -match "n|no") {
98 | Write-Host "Stopping"
99 | return
100 | } else {
101 | Write-Host "Cleaning"
102 | }
103 | }
104 | git clean -xfd -e packages -e .vs
105 | $cores = $env:NUMBER_OF_PROCESSORS
106 | msbuild /t:clean /m:$cores /verbosity:normal dirs.proj
107 | popd
108 | $outFolder = (Join-Path (Resolve-Path (Join-Path $PSScriptRoot "..\..\")) "out")
109 | if (Test-Path $outFolder) {
110 | pushd $outFolder
111 | git clean -xfd
112 | popd
113 | }
114 | }
115 |
116 | <#
117 | .SYNOPSIS
118 | For NuGet packages that VS does not understand, use this script to automate modifying
119 | all the places in the repo that need modification
120 | #>
121 | function Update-NugetPackage()
122 | {
123 | param(
124 | $Package,
125 | $FromVersion,
126 | $ToVersion
127 | )
128 | $repoRoot = (Resolve-Path (Join-Path $PSScriptRoot "..\..\"))
129 | pushd $repoRoot
130 |
131 | Write-Host "Modifying 'packages.config'"
132 | foreach ($packagesConfig in (Get-ChildItem -Filter packages.config -Recurse -Exclude out/**/*,packages/**/*,obj/**/*)) {
133 | [xml]$parsed = (Get-Content $packagesConfig.FullName)
134 | foreach ($p in $parsed.packages.package) {
135 | if (($p.id -eq $package) -and ($p.version -eq $FromVersion)) {
136 | Write-Host "Modified '$($packagesConfig.FullName)'"
137 | $p.version = $ToVersion
138 | $parsed.Save($packagesConfig.FullName)
139 | }
140 | }
141 | }
142 |
143 | cd src
144 | Write-Host "Modifying relative paths in project files"
145 | foreach ($project in (Get-ChildItem -Filter *.*proj -Recurse -Exclude build\**\*,out\**\*,packages\**\*,obj\**\*,objd\**\*)) {
146 | $contents = Get-Content $project.FullName -Raw
147 | if ($contents.Contains("$($Package).$($FromVersion)")) {
148 | Write-Host "Modified '$($project.FullName)'"
149 | $newContent = $contents.Replace("$($Package).$($FromVersion)", "$($Package).$($ToVersion)") > $project.FullName
150 | }
151 | }
152 | popd
153 | }
--------------------------------------------------------------------------------
/.config/PsModules/Install-QuickBuild.psm1:
--------------------------------------------------------------------------------
1 | <#
2 | .SYNOPSIS
3 | Install quickbuild using the official qboostrap script
4 | #>
5 |
6 | Invoke-Expression((New-Object System.Net.WebClient).DownloadString('https://aka.ms/qbootstrap'))
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Set the default behavior, in case people don't have core.autocrlf set.
2 | * text=auto
3 |
4 | # Use text conventions for commonly used text extensions.
5 | *.csv text
6 | *.ini text
7 | *.json text
8 | *.txt text
9 | *.xml text
10 |
11 | # Denote all files that are truly binary and should not be modified.
12 | *.dll binary
13 | *.exe binary
14 | *.gz binary
15 | *.ico binary
16 | *.jpg binary
17 | *.lib binary
18 | *.pdb binary
19 | *.pdf binary
20 | *.png binary
21 | *.wim binary
22 | *.zip binary
23 |
--------------------------------------------------------------------------------
/.github/workflows/msbuild.yml:
--------------------------------------------------------------------------------
1 | # This workflow uses actions that are not certified by GitHub.
2 | # They are provided by a third-party and are governed by
3 | # separate terms of service, privacy policy, and support
4 | # documentation.
5 |
6 | name: MSBuild
7 |
8 | on:
9 | push:
10 | branches: [ "main" ]
11 | pull_request:
12 | branches: [ "main" ]
13 |
14 | env:
15 | # Path to the solution file relative to the root of the project.
16 | SOLUTION_FILE_PATH: dirs.proj
17 |
18 | # Configuration type to build.
19 | # You can convert this to a build matrix if you need coverage of multiple configuration types.
20 | # https://docs.github.com/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
21 | BUILD_CONFIGURATION: Release
22 |
23 | permissions:
24 | contents: read
25 |
26 | jobs:
27 | build:
28 | runs-on: windows-latest
29 |
30 | steps:
31 | - uses: actions/checkout@v3
32 |
33 | - name: Add MSBuild to PATH
34 | uses: microsoft/setup-msbuild@v1.0.2
35 |
36 | - name: Restore NuGet packages
37 | working-directory: ${{env.GITHUB_WORKSPACE}}
38 | run: nuget restore ${{env.SOLUTION_FILE_PATH}}
39 |
40 | - name: Build
41 | working-directory: ${{env.GITHUB_WORKSPACE}}
42 | # Add additional options to the MSBuild command line here (like platform or verbosity level).
43 | # See https://docs.microsoft.com/visualstudio/msbuild/msbuild-command-line-reference
44 | run: msbuild /m /p:Configuration=${{env.BUILD_CONFIGURATION}} ${{env.SOLUTION_FILE_PATH}}
45 |
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "OneBranch"]
2 | path = OneBranch
3 | url = https://msazure.visualstudio.com/One/_git/Submodules-OneBranch-MSBuild
4 | branch = release
5 |
--------------------------------------------------------------------------------
/.pipelines/OneBranch.Official.yml:
--------------------------------------------------------------------------------
1 | #################################################################################
2 | # Onebranch Retail Pipeline #
3 | # This pipeline was created by EasyStart from a sample located at: #
4 | # https://aka.ms/obpipelines/easystart/samples #
5 | # Documentation: https://aka.ms/obpipelines #
6 | # Yaml Schema: https://aka.ms/obpipelines/yaml/schema #
7 | # Retail Tasks: https://aka.ms/obpipelines/tasks #
8 | # Support: https://aka.ms/onebranchsup #
9 | #################################################################################
10 |
11 | trigger: # https://aka.ms/obpipelines/triggers
12 | - main
13 |
14 | parameters: # parameters are shown up in ADO UI in a build queue time
15 | - name: 'debug'
16 | displayName: 'Enable debug output'
17 | type: boolean
18 | default: false
19 |
20 | variables:
21 | CDP_DEFINITION_BUILD_COUNT: $[counter('', 0)] # needed for onebranch.pipeline.version task https://aka.ms/obpipelines/versioning
22 | system.debug: true
23 | ENABLE_PRS_DELAYSIGN: 1
24 | ROOT: $(Build.SourcesDirectory)
25 | REPOROOT: $(Build.SourcesDirectory)
26 | OUTPUTROOT: $(REPOROOT)\out
27 | NUGET_XMLDOC_MODE: none
28 | NUGET_PACKAGES: '$(Agent.WorkFolder)\.nuget'
29 |
30 | # 4.8 SDK: mcr.microsoft.com/dotnet/framework/sdk:4.8-windowsservercore-ltsc2019
31 | # mcr.microsoft.com/dotnet/sdk:6.0-windowsservercore-ltsc2019
32 |
33 | WindowsContainerImage: 'mcr.microsoft.com/windows/servercore:1809' # Docker image which is used to build the project https://aka.ms/obpipelines/containers
34 |
35 | resources:
36 | repositories:
37 | - repository: templates
38 | type: git
39 | name: OneBranch.Pipelines/GovernedTemplates
40 | ref: refs/heads/main
41 |
42 | extends:
43 | template: v2/OneBranch.Official.CrossPlat.yml@templates # https://aka.ms/obpipelines/templates
44 | parameters:
45 | cloudvault: # https://aka.ms/obpipelines/cloudvault
46 | enabled: false
47 | globalSdl: # https://aka.ms/obpipelines/sdl
48 | tsa:
49 | enabled: false # onebranch publish all sdl results to TSA. If TSA is disabled all SDL tools will forced into 'break' build mode.
50 | # credscan:
51 | # suppressionsFile: $(Build.SourcesDirectory)\.config\CredScanSuppressions.json
52 | binskim:
53 | scanOutputDirectoryOnly: true
54 | policheck:
55 | break: true # always break the build on policheck issues. You can disable it by setting to 'false'
56 | # suppression:
57 | # suppressionFile: $(Build.SourcesDirectory)\.gdn\global.gdnsuppress
58 |
59 | stages:
60 | - stage: build
61 | jobs:
62 | - job: MsBuildTask
63 | pool:
64 | type: windows # read more about custom job pool types at https://aka.ms/obpipelines/yaml/jobs
65 |
66 | variables:
67 | ob_outputDirectory: '$(REPOROOT)\out' # this directory is uploaded to pipeline artifacts, reddog and cloudvault. More info at https://aka.ms/obpipelines/artifacts
68 | ob_sdl_binskim_break: true # https://aka.ms/obpipelines/sdl
69 | ob_sdl_cg_failOnAlert: false
70 | ${{ if eq(variables['Build.SourceBranch'], 'refs/heads/master') }}: # conditionally enable symbolsPublishing for master branch only
71 | ob_symbolsPublishing_enabled: true # https://aka.ms/obpipelines/symbols
72 |
73 | # ob_sdl_suppression_suppressionFile: $(Build.SourcesDirectory)\.gdn\job.gdnsuppress
74 |
75 | # Ref assemblies contain interfaces, not code (similar to header files), and can be exluded from signing
76 | # Excluding javascript files because they are run in the browser and not in script host
77 | ob_sdl_codeSignValidation_excludes: -|**\*.js;-|**\ref\**
78 |
79 | steps:
80 | - task: UseDotNet@2
81 | continueOnError: true
82 | inputs:
83 | packageType: 'sdk'
84 | useGlobalJson: true
85 | performMultiLevelLookup: true
86 |
87 | - task: onebranch.pipeline.version@1 # generates automatic version. For other versioning options check https://aka.ms/obpipelines/versioning
88 | displayName: 'Setup BuildNumber'
89 | inputs:
90 | system: 'RevisionCounter'
91 | major: '1'
92 | minor: '0'
93 | exclude_commit: true
94 |
95 | - template: /SharedComponents/OneBranch/Steps/Prepare.MSBuild.yml@templates
96 | parameters:
97 | msBuildVersion: 17.0
98 | msbuildInstallationPath: c:\.vs
99 | includeReferenceAssemblies: 'true'
100 | microsoftSdks:
101 | - 'Azure/.NET SDK/v2.9'
102 |
103 | - task: MSBuild@1
104 | displayName: 'Build'
105 | inputs:
106 | solution: '$(Build.SourcesDirectory)\dirs.proj'
107 | msbuildLocationMethod: 'location'
108 | msbuildLocation: '$(MSBuildPath)'
109 | platform: 'x64'
110 | configuration: 'release'
111 | msbuildArguments: '-bl:$(REPOROOT)\out\output.binlog /nr:false'
112 | maximumCpuCount: true
113 |
114 | - task: onebranch.pipeline.signing@1 # https://aka.ms/obpipelines/signing
115 | displayName: 'Sign output'
116 | inputs:
117 | command: 'sign'
118 | signing_environment: 'azure-ado'
119 | files_to_sign: '**/*.exe;**/*.dll;**/*.ps1;**/*.psm1'
120 | search_root: '$(Build.SourcesDirectory)\out'
--------------------------------------------------------------------------------
/.pipelines/OneBranch.PullRequest.yml:
--------------------------------------------------------------------------------
1 | #################################################################################
2 | # Onebranch Retail Pipeline #
3 | # This pipeline was created by EasyStart from a sample located at: #
4 | # https://aka.ms/obpipelines/easystart/samples #
5 | # Documentation: https://aka.ms/obpipelines #
6 | # Yaml Schema: https://aka.ms/obpipelines/yaml/schema #
7 | # Retail Tasks: https://aka.ms/obpipelines/tasks #
8 | # Support: https://aka.ms/onebranchsup #
9 | #################################################################################
10 |
11 | trigger: none # https://aka.ms/obpipelines/triggers
12 |
13 | parameters: # parameters are shown up in ADO UI in a build queue time
14 | - name: 'debug'
15 | displayName: 'Enable debug output'
16 | type: boolean
17 | default: false
18 |
19 | variables:
20 | CDP_DEFINITION_BUILD_COUNT: $[counter('', 0)] # needed for onebranch.pipeline.version task https://aka.ms/obpipelines/versioning
21 | system.debug: true
22 | ENABLE_PRS_DELAYSIGN: 1
23 | ROOT: $(Build.SourcesDirectory)
24 | REPOROOT: $(Build.SourcesDirectory)
25 | OUTPUTROOT: $(REPOROOT)\out
26 | NUGET_XMLDOC_MODE: none
27 | NUGET_PACKAGES: '$(Agent.WorkFolder)\.nuget'
28 |
29 | # 4.8 SDK: mcr.microsoft.com/dotnet/framework/sdk:4.8-windowsservercore-ltsc2019
30 | # mcr.microsoft.com/dotnet/sdk:6.0-windowsservercore-ltsc2019
31 |
32 | WindowsContainerImage: 'onebranch.azurecr.io/windows/ltsc2019/vse2022:latest' # Docker image which is used to build the project https://aka.ms/obpipelines/containers
33 | # WindowsContainerImage: 'mcr.microsoft.com/windows/servercore:1809' # Docker image which is used to build the project https://aka.ms/obpipelines/containers
34 |
35 | # Ref assemblies contain interfaces, not code (similar to header files), and can be exluded from signing
36 | # Excluding javascript files because they are run in the browser and not in script host
37 | ob_sdl_codeSignValidation_excludes: -|**\*.js;-|**\ref\**
38 |
39 | resources:
40 | repositories:
41 | - repository: templates
42 | type: git
43 | name: OneBranch.Pipelines/GovernedTemplates
44 | ref: refs/heads/main
45 |
46 | extends:
47 | template: v2/OneBranch.NonOfficial.CrossPlat.yml@templates # https://aka.ms/obpipelines/templates
48 | parameters:
49 | cloudvault: # https://aka.ms/obpipelines/cloudvault
50 | enabled: false
51 | globalSdl: # https://aka.ms/obpipelines/sdl
52 | tsa:
53 | enabled: false # onebranch publish all sdl results to TSA. If TSA is disabled all SDL tools will forced into 'break' build mode.
54 | # credscan:
55 | # suppressionsFile: $(Build.SourcesDirectory)\.config\CredScanSuppressions.json
56 | binskim:
57 | scanOutputDirectoryOnly: true
58 | policheck:
59 | break: true # always break the build on policheck issues. You can disable it by setting to 'false'
60 | # suppression:
61 | # suppressionFile: $(Build.SourcesDirectory)\.gdn\global.gdnsuppress
62 |
63 | stages:
64 | - stage: build
65 | jobs:
66 | - job: MsBuildTask
67 | pool:
68 | type: windows # read more about custom job pool types at https://aka.ms/obpipelines/yaml/jobs
69 |
70 | variables:
71 | ob_outputDirectory: '$(REPOROOT)\out' # this directory is uploaded to pipeline artifacts, reddog and cloudvault. More info at https://aka.ms/obpipelines/artifacts
72 | ob_sdl_binskim_break: true # https://aka.ms/obpipelines/sdl
73 | ob_sdl_cg_failOnAlert: false
74 | ${{ if eq(variables['Build.SourceBranch'], 'refs/heads/master') }}: # conditionally enable symbolsPublishing for master branch only
75 | ob_symbolsPublishing_enabled: true # https://aka.ms/obpipelines/symbols
76 |
77 | # ob_sdl_suppression_suppressionFile: $(Build.SourcesDirectory)\.gdn\job.gdnsuppress
78 |
79 | steps:
80 | - task: UseDotNet@2
81 | continueOnError: true
82 | inputs:
83 | packageType: 'sdk'
84 | useGlobalJson: true
85 | performMultiLevelLookup: true
86 |
87 | - task: onebranch.pipeline.version@1 # generates automatic version. For other versioning options check https://aka.ms/obpipelines/versioning
88 | displayName: 'Setup BuildNumber'
89 | inputs:
90 | system: 'RevisionCounter'
91 | major: '1'
92 | minor: '0'
93 | exclude_commit: true
94 |
95 | - template: /SharedComponents/OneBranch/Steps/Prepare.MSBuild.yml@templates
96 | parameters:
97 | msBuildVersion: 17.0
98 | msbuildInstallationPath: c:\.vs
99 | includeReferenceAssemblies: 'true'
100 | microsoftSdks:
101 | - 'Azure/.NET SDK/v2.9'
102 |
103 | - task: MSBuild@1
104 | displayName: 'Build'
105 | inputs:
106 | solution: '$(Build.SourcesDirectory)\dirs.proj'
107 | msbuildLocationMethod: 'location'
108 | msbuildLocation: '$(MSBuildPath)'
109 | platform: 'x64'
110 | configuration: 'release'
111 | msbuildArguments: '-bl:$(REPOROOT)\out\output.binlog /nr:false'
112 | maximumCpuCount: true
113 |
114 | - task: Powershell@2
115 | displayName: 'View Drop Size'
116 | inputs:
117 | targetType: 'inline'
118 | script: |
119 | (get-childitem $(REPOROOT)\out | Measure-Object -Property Length -Sum).sum / 1Gb
120 | errorActionPreference: 'continue'
121 |
122 | - task: onebranch.pipeline.signing@1 # https://aka.ms/obpipelines/signing
123 | displayName: 'Sign output'
124 | inputs:
125 | command: 'sign'
126 | signing_environment: 'azure-ado'
127 | files_to_sign: '**/*.exe;**/*.dll;**/*.ps1;**/*.psm1'
128 | search_root: '$(Build.SourcesDirectory)\out'
129 |
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Microsoft Open Source Code of Conduct
2 |
3 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
4 |
5 | Resources:
6 |
7 | - [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/)
8 | - [Microsoft Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/)
9 | - Contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with questions or concerns
10 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | ---
2 |
3 | ---
4 |
5 | # Contributing
6 |
7 | Welcome contributors to your project then list particular contribution procedures your team follows including but not limited to the sections below.
8 |
9 | Sample text may go like this. *Welcome and thank you for your interest
10 | in contributing to **project-name**! Before contributing to this
11 | project, please review this document for policies and procedures which
12 | will ease the contribution and review process for everyone. If you have
13 | questions, please contact **contact-method**. This project adopted Inner
14 | Source
15 | [model](https://oe-documentation.azurewebsites.net/inner-source/index.html).*
16 |
17 | ## Issues and Feature Requests
18 |
19 | Describe procedures or other requirements on filing issues, fixing bugs, proposing new features, etc that you have including references to roadmaps or other considerations contributors should make before submitting anything to the project team for review.
20 |
21 | ## Style Guidelines
22 |
23 | Include any code and/or documentation style guidelines, linting requirements, etc.
24 |
25 | ## Pull Request Process
26 |
27 | Give very detailed instructions on your PR procedure to ensure contributions are made in the way your teams wants/expects them. This eases the process for everyone. An example process could include the following but this should align with your team's processes.
28 |
29 | 1. Ensure builds are still successful and tests, including any added or updated tests, pass prior to submitting the pull request.
30 | 2. Update any documentation, user and contributor, that is impacted by your changes.
31 | 3. Increase the version numbers in any examples and the `README.md` to the new version that this pull request would represent. The versioning scheme we use is [SemVer](http://semver.org/).
32 | 4. Include your change description in `CHANGELOG.md` file as part of pull request.
33 | 5. You may merge the pull request in once you have the sign-off of two other developers, or if you do not have permission to do that, you may request the second reviewer to merge it for you.
34 |
35 | ## License Information
36 |
37 | Inform the user of the license(s) under which this project accepts and distributes contributions. If you have any license agreement or other legal requirements, include those here as well.
38 |
--------------------------------------------------------------------------------
/CloudBuild.json:
--------------------------------------------------------------------------------
1 | {
2 | "EnlistmentRootPaths": {
3 | "SourceRootDirs": [
4 | "src",
5 | "packages"
6 | ],
7 | "OutputRootDirs": [
8 | "out"
9 | ],
10 | "VersionGenerationMode": "SkipVersionGeneration"
11 | },
12 | "MSBuild": {
13 | "Version": "17.5"
14 | },
15 | "QuickBuildArgs": "-DetectDuplicateBinplace DetectAll -UseHardlinksInCache -UseSharedCompilation"
16 | }
--------------------------------------------------------------------------------
/Directory.Build.props:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
9 | $(MSBuildThisFileDirectory.TrimEnd('\\'))
10 |
11 | Debug
12 | AnyCPU
13 |
14 |
17 | $(DefaultItemExcludes);QTestLogs\**;Logs\**;QLogs\**
18 |
19 |
22 | true
23 |
24 |
27 | true
28 |
29 |
30 | true
31 |
32 |
33 | true
34 |
35 |
36 | $(EnlistmentRoot)\.config
37 | $(CONFROOT)\.inc
38 | local
39 | $(VERSION_PATH)\versions.xml
40 |
41 | false
42 |
43 |
44 |
45 |
48 |
50 |
51 |
54 |
55 |
56 |
57 | $(Platform)
58 |
59 |
60 |
61 |
62 |
63 |
64 | true
65 |
66 |
67 |
70 |
71 | true
72 |
73 |
74 |
75 |
76 |
77 |
81 |
82 | $(MSBuildThisFileDirectory)Out
83 | false
84 | true
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
98 |
99 |
100 | $(EnlistmentRoot)\out\$(Configuration)-$(Platform)\
101 | $(MSBuildProjectName)
102 |
103 |
104 |
105 |
106 |
107 |
108 | $(EnlistmentRoot)\build\local\Extensions\Before.NoTargets.props
109 |
110 |
111 |
112 |
113 | true
114 | pdbonly
115 | false
116 |
117 |
118 |
119 |
120 | True
121 |
122 |
123 |
128 |
129 | 1.0.10
130 |
131 |
--------------------------------------------------------------------------------
/Directory.Build.rsp:
--------------------------------------------------------------------------------
1 | /Restore
2 | /ConsoleLoggerParameters:Verbosity=Minimal;ForceNoAlign;ShowCommandLine;summary
3 | /M
4 | /NodeReuse:false
5 | /bl
6 | /IgnoreProjectExtensions:.sln
7 | /p:Platform=x64
8 |
9 | # Add command-line for Microsoft.Build.Telemetry logger.
10 | # The logger is in a well-known location and must be kept in sync with the $(TelemetryLoggerInstallId) property.
11 | -distributedlogger:TelemetryLogger,%LOCALAPPDATA%\CloudBuild\MSBuildTelemetry\1.0.10\Microsoft.Build.Telemetry.dll,IsOptional*TelemetryForwardingLogger,%LOCALAPPDATA%\CloudBuild\MSBuildTelemetry\1.0.10\Microsoft.Build.Telemetry.dll
12 |
--------------------------------------------------------------------------------
/Directory.Build.targets:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
10 |
11 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
12 |
13 |
14 |
15 |
16 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) Microsoft Corporation.
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE
22 |
--------------------------------------------------------------------------------
/NuGet.Config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/Packages.props:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Project
2 |
3 | > This repo has been populated by an initial template to help get you started. Please
4 | > make sure to update the content to build a great experience for community-building.
5 |
6 | As the maintainer of this project, please make a few updates:
7 |
8 | - Improving this README.MD file to provide a great experience
9 | - Updating SUPPORT.MD with content about this project's support experience
10 | - Understanding the security reporting process in SECURITY.MD
11 | - Remove this section from the README
12 |
13 | ## Contributing
14 |
15 | This project welcomes contributions and suggestions. Most contributions require you to agree to a
16 | Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
17 | the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.
18 |
19 | When you submit a pull request, a CLA bot will automatically determine whether you need to provide
20 | a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions
21 | provided by the bot. You will only need to do this once across all repos using our CLA.
22 |
23 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
24 | For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
25 | contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
26 |
27 | ## Trademarks
28 |
29 | This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft
30 | trademarks or logos is subject to and must follow
31 | [Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general).
32 | Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.
33 | Any use of third-party trademarks or logos are subject to those third-party's policies.
34 |
--------------------------------------------------------------------------------
/SECURITY.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | ## Security
4 |
5 | Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin), and [our GitHub organizations](https://opensource.microsoft.com/).
6 |
7 | If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://aka.ms/opensource/security/definition), please report it to us as described below.
8 |
9 | ## Reporting Security Issues
10 |
11 | **Please do not report security vulnerabilities through public GitHub issues.**
12 |
13 | Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://aka.ms/opensource/security/create-report).
14 |
15 | If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://aka.ms/opensource/security/pgpkey).
16 |
17 | You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://aka.ms/opensource/security/msrc).
18 |
19 | Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue:
20 |
21 | * Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
22 | * Full paths of source file(s) related to the manifestation of the issue
23 | * The location of the affected source code (tag/branch/commit or direct URL)
24 | * Any special configuration required to reproduce the issue
25 | * Step-by-step instructions to reproduce the issue
26 | * Proof-of-concept or exploit code (if possible)
27 | * Impact of the issue, including how an attacker might exploit the issue
28 |
29 | This information will help us triage your report more quickly.
30 |
31 | If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://aka.ms/opensource/security/bounty) page for more details about our active programs.
32 |
33 | ## Preferred Languages
34 |
35 | We prefer all communications to be in English.
36 |
37 | ## Policy
38 |
39 | Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://aka.ms/opensource/security/cvd).
40 |
41 |
42 |
--------------------------------------------------------------------------------
/SUPPORT.md:
--------------------------------------------------------------------------------
1 | # TODO: The maintainer of this repo has not yet edited this file
2 |
3 | **REPO OWNER**: Do you want Customer Service & Support (CSS) support for this product/project?
4 |
5 | - **No CSS support:** Fill out this template with information about how to file issues and get help.
6 | - **Yes CSS support:** Fill out an intake form at [aka.ms/onboardsupport](https://aka.ms/onboardsupport). CSS will work with/help you to determine next steps.
7 | - **Not sure?** Fill out an intake as though the answer were "Yes". CSS will help you decide.
8 |
9 | *Then remove this first heading from this SUPPORT.MD file before publishing your repo.*
10 |
11 | # Support
12 |
13 | ## How to file issues and get help
14 |
15 | This project uses GitHub Issues to track bugs and feature requests. Please search the existing
16 | issues before filing new issues to avoid duplicates. For new issues, file your bug or
17 | feature request as a new Issue.
18 |
19 | For help and questions about using this project, please **REPO MAINTAINER: INSERT INSTRUCTIONS HERE
20 | FOR HOW TO ENGAGE REPO OWNERS OR COMMUNITY FOR HELP. COULD BE A STACK OVERFLOW TAG OR OTHER
21 | CHANNEL. WHERE WILL YOU HELP PEOPLE?**.
22 |
23 | ## Microsoft Support Policy
24 |
25 | Support for this **PROJECT or PRODUCT** is limited to the resources listed above.
26 |
--------------------------------------------------------------------------------
/build/CloudServiceSchema.targets:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
23 |
24 |
25 |
26 |
27 |
30 |
31 |
34 |
35 |
--------------------------------------------------------------------------------
/build/DefaultBuildFlavor.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
5 |
6 | Debug
7 | x64
8 |
9 | full
10 |
13 | $(CBT_UnifiedOutputRootDir)\$(Configuration)-$(Platform)
14 | $(CBTOutputRootDir)
15 |
16 |
19 | $(CBTOutputRootDir)
20 |
21 |
25 |
28 |
29 |
--------------------------------------------------------------------------------
/build/DefaultCloudBuildModifiers.props:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
8 |
9 |
10 |
13 |
14 | <_IsAspNetMvc5Project Condition="$(ProjectTypeGuids.ToLower().Contains('{349c5851-65df-11da-9384-00065b846f21}'))">true
15 |
16 |
17 |
20 |
21 |
22 | False
23 | False
24 |
25 |
26 | true
27 | $(OutDir)Noop\..\
28 |
29 |
30 |
31 |
32 | true
33 | false
34 |
35 |
36 |
37 | bin\
38 | bin\
39 | $([MSBuild]::Escape($([System.IO.Path]::GetFullPath(`$([System.IO.Path]::Combine(`$(MSBuildProjectDirectory)`, `$(OutDir)`))`))))
40 | $(TargetDir)$(TargetFileName)
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/build/DefaultRepositoryVariables.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $(EnlistmentRoot)
5 | $(EnlistmentRoot)\src
6 | $(EnlistmentRoot)
7 | $(EnlistmentRoot)
8 |
9 | $(EnlistmentRoot)\out\$(Configuration)-$(Platform)
10 | $(EnlistmentRoot)\out\$(Configuration)-$(Platform)
11 |
12 |
--------------------------------------------------------------------------------
/build/NuProj/AfterNuProj.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
8 |
9 | $(MSBuildThisFileDirectory)AfterNuProj.targets
10 |
11 |
12 |
--------------------------------------------------------------------------------
/build/NuProj/AfterNuProj.targets:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/build/NuProj/Microsoft.Build.Utilities.v12.0.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/adcs-proxy-exit-module/1e34447acb234504d641c09a48fbb1c278ff7acd/build/NuProj/Microsoft.Build.Utilities.v12.0.dll
--------------------------------------------------------------------------------
/build/NuProj/Microsoft.Common.NuProj.targets:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
18 |
19 |
22 |
23 |
24 |
25 | <_NuProjProjectReferenceClosureWithDuplicates Include="%(_MSBuildProjectReferenceExistent.FullPath)" />
26 |
27 |
28 |
29 |
36 |
38 |
39 |
40 |
41 |
42 |
44 |
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/build/NuProj/NuGet.Core.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/adcs-proxy-exit-module/1e34447acb234504d641c09a48fbb1c278ff7acd/build/NuProj/NuGet.Core.dll
--------------------------------------------------------------------------------
/build/NuProj/NuGet.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/adcs-proxy-exit-module/1e34447acb234504d641c09a48fbb1c278ff7acd/build/NuProj/NuGet.exe
--------------------------------------------------------------------------------
/build/NuProj/NuProj.Tasks.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/adcs-proxy-exit-module/1e34447acb234504d641c09a48fbb1c278ff7acd/build/NuProj/NuProj.Tasks.dll
--------------------------------------------------------------------------------
/build/NuProj/NuProj.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Debug
7 | AnyCPU
8 |
9 | bin\$(Configuration)\
10 |
11 |
12 |
13 | False
14 | True
15 | True
16 | False
17 | False
18 | False
19 |
20 |
21 |
22 | $(MSBuildThisFileDirectory)NuProj.Tasks.dll
23 | $(MSBuildThisFileDirectory)
24 | $(NuProjToolPath)
25 | NuGet.exe
26 |
27 |
28 |
33 |
34 |
35 |
36 | BuiltProjectOutputGroup;
37 | BuiltProjectOutputGroupDependencies;
38 | DebugSymbolsProjectOutputGroup;
39 | DebugSymbolsProjectOutputGroupDependencies;
40 | DocumentationProjectOutputGroup;
41 | DocumentationProjectOutputGroupDependencies;
42 | SatelliteDllsProjectOutputGroup;
43 | SatelliteDllsProjectOutputGroupDependencies;
44 | SGenFilesOutputGroup;
45 | SGenFilesOutputGroupDependencies;
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/build/NuProj/UnifiedNugetDrop.targets:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
5 |
6 |
7 |
9 |
10 |
14 |
15 |
16 | $(StagingOutputRootPath)\NuGetPackages\
17 | $(CBTOutputRootDir)\NuGetPackages\
18 |
19 |
20 |
21 |
22 |
23 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/build/README.txt:
--------------------------------------------------------------------------------
1 | This directory is required for Q. Do not use this directory for anything else. This directory can be removed if Q is not used in this repo.
--------------------------------------------------------------------------------
/build/StyleCop/StyleCop.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
6 |
7 |
8 |
11 |
12 |
13 |
14 | CustomDictionary.xml
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/build/Versions/ProcessVersionFiles.ps1:
--------------------------------------------------------------------------------
1 |
2 | param(
3 | [String] $Version,
4 | [String] $COREXTBRANCH,
5 | [String] $SourceFolder,
6 | [String] $DestinationFolder
7 | )
8 |
9 | $tokens = $Version.Split(".");
10 | $ProductMajor = $tokens[0];
11 | $ProductMinor = $tokens[1];
12 | $BuildMajor = $tokens[2];
13 | $BuildMinor = $tokens[3];
14 |
15 | $ProductMajorNumber = $ProductMajor
16 | $ProductMinorNumber = "0";
17 |
18 | $BuildMajorNumber = $BuildMajor
19 | if ($BuildMinor -eq "00")
20 | {
21 | $BuildMinorNumber = "0";
22 | }
23 | else
24 | {
25 | $BuildMinorNumber = $BuildMinor;
26 | }
27 |
28 | if (!(test-path "$DestinationFolder"))
29 | {
30 | New-Item -Path "$DestinationFolder" -ItemType Directory;
31 | }
32 | Write-Host "Processing $SourceFolder to $DestinationFolder"
33 |
34 | $content = (Get-Content "$SourceFolder\bldver.hf").Replace("%ProductMajorNumber%",$ProductMajorNumber).Replace("%ProductMinorNumber%",$ProductMinorNumber).Replace("%BuildMajorNumber%",$BuildMajorNumber).Replace("%BuildMinorNumber%",$BuildMinorNumber).Replace("%ProductMajor%",$ProductMajor).Replace("%ProductMinor%",$ProductMinor).Replace("%BuildMajor%",$BuildMajor).Replace("%BuildMinor%",$BuildMinor).Replace("%USERNAME%", $env:USERNAME).Replace("%COMPUTERNAME%",$env:COMPUTERNAME).Replace("%corextBranch%", $COREXTBRANCH);
35 | Set-Content -Path "$DestinationFolder\bldver.h" $content -Force
36 |
37 | $content = (Get-Content "$SourceFolder\bldvercs.hf").Replace("%ProductMajor%",$ProductMajor).Replace("%ProductMinor%",$ProductMinor).Replace("%BuildMajor%",$BuildMajor).Replace("%BuildMinor%",$BuildMinor).Replace("%USERNAME%", $env:USERNAME).Replace("%CODESIGN_KEY%",$env:CODESIGN_KEY).Replace("%CODESIGN_TESTKEY%", $env:CODESIGN_TESTKEY);
38 | Set-Content -Path "$DestinationFolder\bldver.cs" $content -Force
39 |
40 | $content = (Get-Content "$SourceFolder\bldvervb.hf").Replace("%ProductMajor%",$ProductMajor).Replace("%ProductMinor%",$ProductMinor).Replace("%BuildMajor%",$BuildMajor).Replace("%BuildMinor%",$BuildMinor).Replace("%USERNAME%", $env:USERNAME).Replace("%CODESIGN_KEY%",$env:CODESIGN_KEY).Replace("%CODESIGN_TESTKEY%", $env:CODESIGN_TESTKEY);
41 | Set-Content -Path "$DestinationFolder\bldver.vb" $content -Force
42 |
43 | $content = (Get-Content "$SourceFolder\bldvermc.hf").Replace("%ProductMajor%",$ProductMajor).Replace("%ProductMinor%",$ProductMinor).Replace("%BuildMajor%",$BuildMajor).Replace("%BuildMinor%",$BuildMinor).Replace("%USERNAME%", $env:USERNAME).Replace("%CODESIGN_KEY%",$env:CODESIGN_KEY).Replace("%CODESIGN_TESTKEY%", $env:CODESIGN_TESTKEY);
44 | Set-Content -Path "$DestinationFolder\bldver.cpp" $content -Force
45 |
46 | $version_htm_content = "Version $ProductMajor.$ProductMinor (Build $BuildMajor.$BuildMinor)"
47 | Set-Content -Path "$DestinationFolder\version.htm" $version_htm_content -Force
48 |
49 | # Needed for cloudbuild to parse version information.
50 | # See details at https://mseng.visualstudio.com/Domino/_git/CloudBuild?path=%2Fprivate%2FCommon%2FRpc%2Fsrc%2FBuildCommon%2FDrop%2FBranchVersion.cs&version=GBmaster
51 | $version_htm_in_public_dir = "$SourceFolder\..\..\public\inc\version.htm"
52 | if (-not(Test-Path $version_htm_in_public_dir))
53 | {
54 | New-Item -Path $version_htm_in_public_dir -ItemType File -Force
55 | }
56 |
57 | Set-Content -Path $version_htm_in_public_dir $version_htm_content -Force
58 |
59 |
--------------------------------------------------------------------------------
/build/Versions/bldver.hf:
--------------------------------------------------------------------------------
1 | //
2 | // this file is automatically generated
3 | // by beaver.exe %BeaverVersion%
4 | //
5 |
6 | //
7 | // if you want to use a private version file and customize this, see
8 | // file://samsndrop02/CoreXT-Latest/docs/corext/corext/version.htm
9 | //
10 |
11 | #ifndef _BLDVER_H_
12 | #define _BLDVER_H_
13 |
14 | #define BUILD_NUMBER "%BuildMajor%.%BuildMinor%"
15 | #define BUILD_NUM %BuildMajorNumber%,%BuildMinorNumber%
16 | #define PRODUCT_NUMBER "%ProductMajor%.%ProductMinor%"
17 | #define PRODUCT_NUM %ProductMajorNumber%,%ProductMinorNumber%
18 | #define INET_VERSION "%ProductMajor%.%ProductMinor%.%BuildMajor%.%BuildMinor%"
19 | #define INET_VER %ProductMajorNumber%,%ProductMinorNumber%,%BuildMajorNumber%,%BuildMinorNumber%
20 |
21 | #define PRODUCT_MAJOR %ProductMajor%
22 | #define PRODUCT_MAJOR_STRING "%ProductMajor%"
23 | #define PRODUCT_MAJOR_NUMBER %ProductMajorNumber%
24 |
25 | #define PRODUCT_MINOR %ProductMinor%
26 | #define PRODUCT_MINOR_STRING "%ProductMinor%"
27 | #define PRODUCT_MINOR_NUMBER %ProductMinorNumber%
28 |
29 | #define BUILD_MAJOR %BuildMajor%
30 | #define BUILD_MAJOR_STRING "%BuildMajor%"
31 | #define BUILD_MAJOR_NUMBER %BuildMajorNumber%
32 |
33 | #define BUILD_MINOR %BuildMinor%
34 | #define BUILD_MINOR_STRING "%BuildMinor%"
35 | #define BUILD_MINOR_NUMBER %BuildMinorNumber%
36 |
37 | #ifdef DEBUG
38 | #define BUILD_FILEFLAGS_DEBUG | VS_FF_DEBUG
39 | #else
40 | #define BUILD_FILEFLAGS_DEBUG
41 | #endif
42 |
43 | #if defined(BUILD_LABBUILD)
44 | #if !defined(ENABLE_PRS_DELAYSIGN)
45 | #define BUILD_FILEFLAGS_RELEASE | VS_FF_PRERELEASE
46 | #else
47 | #define BUILD_FILEFLAGS_RELEASE
48 | #endif
49 |
50 | #ifndef BUILD_PRODUCTION
51 | #define BUILD_FILEFLAGS_SPECIAL | VS_FF_SPECIALBUILD
52 | #define BUILD_SPECIAL "%corextBranch%"
53 | #else
54 | #define BUILD_FILEFLAGS_SPECIAL
55 | #endif
56 |
57 | #define BUILD_FILEFLAGS_PRIVATE
58 | #else
59 | #define BUILD_FILEFLAGS_RELEASE
60 | #define BUILD_FILEFLAGS_SPECIAL
61 | #define BUILD_FILEFLAGS_PRIVATE | VS_FF_PRIVATEBUILD
62 | #define BUILD_PRIVATE "%corextBranch% (by %USERNAME% on %COMPUTERNAME%)"
63 | #endif
64 |
65 | #define BUILD_FILEFLAGS 0x0L BUILD_FILEFLAGS_RELEASE BUILD_FILEFLAGS_SPECIAL BUILD_FILEFLAGS_PRIVATE BUILD_FILEFLAGS_DEBUG
66 |
67 |
68 | #define VER_PRODUCTVERSION %ProductMajorNumber%,%ProductMinorNumber%,%BuildMajorNumber%,%BuildMinorNumber%
69 | #define VER_PRODUCTVERSION_STR "%ProductMajorNumber%.%ProductMinorNumber%.%BuildMajorNumber%.%BuildMinorNumber%"
70 | #define VER_PRODUCTVERSION_STR_FULL "%ProductMajor%.%ProductMinor%.%BuildMajor%.%BuildMinor%"
71 | #define VER_PRODUCTVERSION_QSTR "%ProductMajor%.%ProductMinor%,%BuildMajor%,%BuildMinor%"
72 | #define VER_PRODUCTVERSION_WSTR L"%ProductMajor%.%ProductMinor%.%BuildMajor%.%BuildMinor%"
73 | #define VER_PRODUCTVERSION_W ((%ProductMajor% << 8) | %ProductMinor%)
74 | #define VER_PRODUCTMAJORVERSION %ProductMajor%
75 | #define VER_PRODUCTMINORVERSION %ProductMinor%
76 | //This is to appease a BuildDirectories.pm regex in finding the version part3 and we redefine it immediately after.
77 | #define VER_PRODUCTBUILD /* NT */ %BuildMajor%
78 | #define VER_PRODUCTBUILD %BuildMajor%
79 | #define VER_PRODUCTBUILD_QFE %BuildMinor%
80 | #define VER_PRODUCTNAME_STR "Microsoft Account"
81 | #define VER_COMPANYNAME_STR "Microsoft Corporation"
82 |
83 |
84 |
85 |
86 | #endif
87 |
--------------------------------------------------------------------------------
/build/Versions/bldvercs.hf:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 |
4 | //
5 | // if you want to use a private version file and customize this, see
6 | // file://samsndrop02/CoreXT-Latest/docs/corext/corext/version.htm
7 | //
8 |
9 | [assembly: AssemblyVersion("%ProductMajor%.%ProductMinor%.%BuildMajor%.%BuildMinor%")]
10 |
11 | [assembly: AssemblyCompany("Microsoft Corp.")]
12 | [assembly: AssemblyProduct("Microsoft Account")]
13 | [assembly: AssemblyCopyright("2020")]
14 |
15 | #if ENABLE_CODESIGN
16 |
17 | #if ENABLE_PRS_DELAYSIGN
18 | [assembly: AssemblyKeyFile(@"%CODESIGN_KEY%")]
19 | [assembly: AssemblyKeyName("")]
20 | [assembly: AssemblyDelaySign(true)]
21 | #else
22 | [assembly: AssemblyKeyFile(@"%CODESIGN_TESTKEY%")]
23 | [assembly: AssemblyKeyName("")]
24 | [assembly: AssemblyDelaySign(false)]
25 | #endif
26 |
27 | #endif
28 |
--------------------------------------------------------------------------------
/build/Versions/bldvermc.hf:
--------------------------------------------------------------------------------
1 | using namespace System::Reflection;
2 | using namespace System::Runtime::CompilerServices;
3 |
4 | //
5 | // if you want to use a private version file and customize this, see
6 | // file://samsndrop02/CoreXT-Latest/docs/corext/corext/version.htm
7 | //
8 |
9 | [assembly: AssemblyVersion("%ProductMajor%.%ProductMinor%.%BuildMajor%.%BuildMinor%")];
10 |
11 | [assembly: AssemblyCompany("Microsoft Corp.")];
12 | [assembly: AssemblyProduct("Microsoft Account")];
13 | [assembly: AssemblyCopyright("2020")];
14 |
15 |
16 |
17 | #if ENABLE_CODESIGN
18 | #if !(BUILD_NO_GLOBAL_STRONG_NAME)
19 | #if ENABLE_PRS_DELAYSIGN
20 | [assembly: AssemblyDelaySign(true)];
21 | [assembly: AssemblyKeyFile("%CODESIGN_KEY:\=\\%")];
22 | #else
23 | [assembly: AssemblyKeyFile("%CODESIGN_TESTKEY:\=\\%")];
24 | [assembly: AssemblyKeyName("")];
25 | [assembly: AssemblyDelaySign(false)];
26 | #endif
27 | #endif
28 | #endif
29 |
--------------------------------------------------------------------------------
/build/Versions/bldvervb.hf:
--------------------------------------------------------------------------------
1 | imports System.Reflection
2 | imports System.Runtime.InteropServices
3 |
4 | '
5 | ' if you want to use a private version file and customize this, see
6 | ' file://samsndrop02/CoreXT-Latest/docs/corext/corext/version.htm
7 | '
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | #if ENABLE_CODESIGN
17 |
18 | #if ENABLE_PRS_DELAYSIGN
19 |
20 |
21 |
22 | #else
23 |
24 |
25 |
26 | #end if
27 |
28 | #end if
29 |
30 |
--------------------------------------------------------------------------------
/build/build.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | $(EnlistmentRoot)\build\local\Extensions
6 | $(DefaultProjectConfiguration)
7 | $(DefaultProjectPlatform)
8 |
9 |
10 |
11 |
12 | net461
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/build/config/signing_options.json:
--------------------------------------------------------------------------------
1 | {
2 | "PublicKeysToExclude": [
3 | "6d82608ce3af2ccb",
4 | "b03f5f7f11d50a3a",
5 | ]
6 | }
--------------------------------------------------------------------------------
/build/config/validation/CiPolicyAnalyzerConfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "OmitExtensions": [
3 | ".js"
4 | ],
5 | "OmitFiles": [
6 | "release-x64\\*\\ref\\*.dll",
7 | "release-x64\\*\\ref\\*.exe"
8 | ],
9 | "OmitPaths": [
10 | "loc"
11 | ]
12 | }
--------------------------------------------------------------------------------
/build/signing/35MSSharedLib1024.snk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/adcs-proxy-exit-module/1e34447acb234504d641c09a48fbb1c278ff7acd/build/signing/35MSSharedLib1024.snk
--------------------------------------------------------------------------------
/build/signing/CloudServiceSigning.targets:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
11 | .exe;.dll;.sys;.cat;.msu;.mui;.cab;.ctl;.ocx;.ps1xml;.ps1;.psd1;.psm1;.py;.js
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/build/signing/StrongName.props:
--------------------------------------------------------------------------------
1 |
2 |
3 | true
4 | true
5 | $(MSBuildThisFileDirectory)35MSSharedLib1024.snk
6 |
7 |
--------------------------------------------------------------------------------
/build/stageoutput/StageOutput.targets:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
6 |
7 | <_CopyFilesToStagingAfterTargets Condition=" '$(MSBuildProjectExtension)' == '.ccproj'">AfterBuild
8 | <_CopyFilesToStagingAfterTargets Condition=" '$(_CopyFilesToStagingAfterTargets)' == ''">CopyFilesToOutputDirectory
9 |
10 |
11 |
14 |
15 |
16 |
17 |
18 |
19 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/dirs.proj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/global.json:
--------------------------------------------------------------------------------
1 | {
2 | "msbuild-sdks": {
3 | "Microsoft.Build.CentralPackageVersions": "2.1.3",
4 | "Microsoft.Build.Traversal": "3.1.6",
5 | "Microsoft.Build.NoTargets": "3.3.0"
6 | },
7 | "sdk": {
8 | "comment": "Need to use a particular version to ensure consistency across machines no matter what SDK versions they have installed.",
9 | "version": "6.0.406",
10 | "RollForward": "latestMajor"
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/owners.txt:
--------------------------------------------------------------------------------
1 | ; This owners.txt file was initially populated by Easy Start. Every code
2 | ; change inside of an Ownership Enforcer enabled branch (such as master) must be
3 | ; approved by at least one expert listed in an applicable owners.txt file. This
4 | ; root owners.txt file is applicable to every change. Targeted experts can be
5 | ; defined by placing an owners.txt file inside any subdirectory. More information
6 | ; about Ownership Enforcer can be found at https://aka.ms/ownershipenforcer.
7 | aliciab
8 | jkrolak
9 | lkirkbride
10 | iflo
11 | cavernon
12 | danielmak
13 | acholleti
14 | tematejc
15 | jennross
16 | anbasset
17 | chdavis
18 |
--------------------------------------------------------------------------------
/src/Directory.Build.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
6 |
7 |
8 |
9 |
10 |
11 | false
12 | $(OutputPath)include
13 | 14.31.31104
14 | $(EnlistmentRoot)\packages\VisualCppTools.$(VCToolsVersion)\lib\native
15 | $(VCInstallDir_150)
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 | $(UCRTContentRoot)
26 | $(WDKContentRoot)\
27 |
28 |
29 |
30 | $(LocalSignFilesBeforeTarget);CopyFilesToStagingOutputDirectory
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 | /guard:cf %(AdditionalOptions)
43 | ProgramDatabase
44 |
45 |
46 | /guard:cf %(AdditionalOptions)
47 | ProgramDatabase
48 |
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/src/Directory.Build.targets:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath)
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/src/PKI/ExitModule/Buffer.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | /*++
3 |
4 | Copyright (C) Microsoft Corp. All rights reserved.
5 |
6 | File:
7 |
8 | Buffer.h
9 |
10 | Abstract:
11 |
12 | Buffer management templates.
13 |
14 | Authors:
15 |
16 | Jon Rowlett (jrowlett)
17 |
18 | History:
19 | 10-Apr-2023 jrowlett Created.
20 |
21 | --*/
22 |
23 | /*++
24 |
25 | Abstract:
26 |
27 | Common Buffer class.
28 |
29 | Remarks:
30 |
31 | Use this instead of passing around arrays or raw pointers with a size.
32 | Derived classes do memory management.
33 | --*/
34 | template
35 | class CBuffer
36 | {
37 | public:
38 | inline const T* Get() const
39 | {
40 | return m_p;
41 | }
42 |
43 | inline T* Get()
44 | {
45 | return m_p;
46 | }
47 |
48 | inline size_t GetLength() const
49 | {
50 | return m_cLength;
51 | }
52 |
53 | inline size_t GetSize() const
54 | {
55 | return m_cLength * sizeof(T);
56 | }
57 |
58 | protected:
59 | inline CBuffer()
60 | : m_p(nullptr), m_cLength(0)
61 | {
62 | }
63 |
64 | inline CBuffer(T* p, size_t cLength)
65 | : m_p(p), m_cLength(cLength)
66 | {
67 | }
68 |
69 | T* m_p;
70 | size_t m_cLength;
71 |
72 | private:
73 | CBuffer(const CBuffer&) = delete;
74 | CBuffer& operator=(const CBuffer&) = delete;
75 | };
76 |
77 | /*++
78 |
79 | Abstract:
80 |
81 | A fixed size, statically allocated buffer.
82 |
83 | Remarks:
84 |
85 | Use this for either member variables or stack allocated buffers.
86 | --*/
87 | template
88 | class CStaticBuffer : public CBuffer
89 | {
90 | public:
91 | CStaticBuffer()
92 | : CBuffer(m_Elements, N)
93 | {
94 | }
95 |
96 | private:
97 | T m_Elements[N];
98 | };
99 |
100 | /*++
101 |
102 | Abstract:
103 |
104 | A reference buffer to an externally allocated buffer.
105 |
106 | --*/
107 | template
108 | class CRefBuffer : public CBuffer
109 | {
110 | public:
111 | CRefBuffer(T* p, size_t cLength)
112 | : CBuffer(p, cLength)
113 | {
114 | }
115 |
116 | CRefBuffer()
117 | : CBuffer(nullptr, 0)
118 | {
119 | }
120 | };
121 |
122 | /*++
123 |
124 | Abstract:
125 |
126 | A Heap allocated buffer.
127 |
128 | Remarks:
129 |
130 | The class manages heap memory for the buffer.
131 | --*/
132 | template
133 | class CHeapBuffer : public CBuffer
134 | {
135 | public:
136 | CHeapBuffer()
137 | : CBuffer()
138 | {
139 | }
140 |
141 | ~CHeapBuffer()
142 | {
143 | Clear();
144 | }
145 |
146 | /*++
147 |
148 | Abstract:
149 |
150 | Clears the buffer and frees memory.
151 | --*/
152 | void Clear()
153 | {
154 | if (m_p)
155 | {
156 | delete[] m_p;
157 | m_p = nullptr;
158 | }
159 |
160 | m_cLength = 0;
161 | }
162 |
163 | /*++
164 |
165 | Abstract:
166 |
167 | Allocates a buffer of a given number of elements.
168 |
169 | Parameters:
170 |
171 | cLength - the number of elements to allocate in the new buffer.
172 |
173 | Returns:
174 |
175 | true - success.
176 | false - the new buffer failed to get allocated.
177 |
178 | Remarks:
179 |
180 | It creates a new buffer and does not copy elements from the old buffer.
181 | If the new buffer cannot be allocated, there is no change to the existing buffer.
182 |
183 | --*/
184 | bool Alloc(size_t cLength)
185 | {
186 | T* pNew = new T[cLength];
187 | if (!pNew)
188 | {
189 | return false;
190 | }
191 |
192 | Clear();
193 | m_p = pNew;
194 | m_cLength = cLength;
195 | return true;
196 | }
197 | };
198 |
199 | /*++
200 |
201 | Abstract:
202 |
203 | Specialization of the heap buffer for null terminated WCHAR strings.
204 |
205 | Remarks:
206 |
207 | CStringW and CAtlStringW do not report errors well in low memory conditions.
208 | --*/
209 | class CHeapWString : public CHeapBuffer
210 | {
211 | public:
212 | /*++
213 |
214 | Abstract:
215 |
216 | Copies the source BSTR into the string.
217 |
218 | Parameters:
219 |
220 | bstr - the source bstr to copy.
221 |
222 | Returns:
223 |
224 | S_OK - success.
225 | E_OUTOFMEMORY - out of memory allocating the string.
226 | other - internal error from ::StringCchCopy.
227 | --*/
228 | HRESULT Copy(const BSTR bstr)
229 | {
230 | if (bstr)
231 | {
232 | size_t cch = (size_t)::SysStringLen(bstr) + 1;
233 | if (!Alloc(cch))
234 | {
235 | return E_OUTOFMEMORY;
236 | }
237 |
238 | // include the trailing null in cch.
239 | return StringCchCopyW(m_p, cch, bstr);
240 | }
241 | else
242 | {
243 | Clear();
244 | }
245 |
246 | return S_OK;
247 | }
248 | };
--------------------------------------------------------------------------------
/src/PKI/ExitModule/CertServerExit.cpp:
--------------------------------------------------------------------------------
1 | /*++
2 |
3 | Copyright (C) Microsoft Corp. All rights reserved.
4 |
5 | File:
6 |
7 | CertServerExit.cpp
8 |
9 | Abstract:
10 |
11 | Wrapper for ICertServerExit.
12 |
13 | Authors:
14 |
15 | Jon Rowlett (jrowlett)
16 |
17 | History:
18 | 10-Apr-2023 jrowlett Created.
19 |
20 | --*/
21 |
22 | #include "pch.h"
23 | #include "CertServerExit.h"
24 |
25 | CCertServerExit::CCertServerExit()
26 | : m_ptrInner(), m_lContext(0L)
27 | {
28 | }
29 |
30 | CCertServerExit::~CCertServerExit()
31 | {
32 | }
33 |
34 | HRESULT CCertServerExit::Init(
35 | LONG lContext /* = 0L */)
36 | {
37 | HRESULT hr = S_OK;
38 |
39 | do
40 | {
41 | Clear();
42 |
43 | hr = m_ptrInner.CoCreateInstance(
44 | CLSID_CCertServerExit,
45 | nullptr, // pUnkOuter
46 | CLSCTX_INPROC_SERVER);
47 | if (FAILED(hr))
48 | {
49 | ATLTRACE(L"CCI for CLSID_CCertServerExit failed, hr=%x\n", hr);
50 | break;
51 | }
52 |
53 | if (lContext != 0)
54 | {
55 | hr = m_ptrInner->SetContext(lContext);
56 | if (FAILED(hr))
57 | {
58 | ATLTRACE(L"ICertServerExit::SetContext(%x) failed, hr=%x\n", lContext, hr);
59 | break;
60 | }
61 | }
62 |
63 | m_lContext = lContext;
64 | } while (false);
65 |
66 | if (FAILED(hr))
67 | {
68 | Clear();
69 | }
70 |
71 | return hr;
72 | }
73 |
74 | HRESULT CCertServerExit::GetRequestProperty(
75 | LPCWSTR pwszName,
76 | CertServerPropType ePropType,
77 | OUT ATL::CComVariant& varResult) const
78 | {
79 | HRESULT hr = S_OK;
80 | ATL::CComBSTR bstrName;
81 |
82 | do
83 | {
84 | if (!m_ptrInner)
85 | {
86 | hr = HRESULT_FROM_WIN32(ERROR_INTERNAL_ERROR);
87 | ATLTRACE(L"m_ptrInner is null.\n");
88 | break;
89 | }
90 |
91 | hr = bstrName.Append(pwszName);
92 | if (FAILED(hr))
93 | {
94 | ATLTRACE(L"bstrName.Append failed, hr=%x\n", hr);
95 | break;
96 | }
97 |
98 | varResult.Clear();
99 | hr = m_ptrInner->GetRequestProperty(bstrName, ePropType, &varResult);
100 | if (FAILED(hr))
101 | {
102 | ATLTRACE(
103 | L"ICertServerExit::GetRequestProperty(%s, %x) failed, hr=%x\n",
104 | pwszName,
105 | ePropType,
106 | hr);
107 | break;
108 | }
109 |
110 | } while (false);
111 |
112 | return hr;
113 | }
114 |
115 | HRESULT CCertServerExit::GetCertificateProperty(
116 | LPCWSTR pwszName,
117 | CertServerPropType ePropType,
118 | OUT ATL::CComVariant& varResult) const
119 | {
120 | HRESULT hr = S_OK;
121 | ATL::CComBSTR bstrName;
122 |
123 | do
124 | {
125 | if (!m_ptrInner)
126 | {
127 | hr = HRESULT_FROM_WIN32(ERROR_INTERNAL_ERROR);
128 | ATLTRACE(L"m_ptrInner is null.\n");
129 | break;
130 | }
131 |
132 | hr = bstrName.Append(pwszName);
133 | if (FAILED(hr))
134 | {
135 | ATLTRACE(L"bstrName.Append failed, hr=%x\n", hr);
136 | break;
137 | }
138 |
139 | varResult.Clear();
140 | hr = m_ptrInner->GetCertificateProperty(bstrName, ePropType, &varResult);
141 | if (FAILED(hr))
142 | {
143 | ATLTRACE(
144 | L"ICertServerExit::GetCertificateProperty(%s, %x) failed, hr=%x\n",
145 | pwszName,
146 | ePropType,
147 | hr);
148 | break;
149 | }
150 |
151 | } while (false);
152 |
153 | return hr;
154 | }
155 |
156 | HRESULT CCertServerExit::GetModuleRegistryLocation(
157 | OUT CHeapWString& strResult) const
158 | {
159 | return GetCertificateStringProperty(
160 | wszPROPMODULEREGLOC,
161 | OUT strResult);
162 | }
163 |
164 | HRESULT CCertServerExit::GetRawCertificateProperty(
165 | OUT CHeapBuffer& bufResult) const
166 | {
167 | HRESULT hr = S_OK;
168 | ATL::CComVariant var;
169 |
170 | do
171 | {
172 | hr = GetCertificateProperty(
173 | wszPROPRAWCERTIFICATE,
174 | CertServerPropType::PropTypeBinary,
175 | OUT var);
176 | if (FAILED(hr))
177 | {
178 | // already traced.
179 | break;
180 | }
181 |
182 | if (var.vt != VT_BSTR)
183 | {
184 | ATLTRACE(L"Expected VT_BSTR, actual=%d\n", var.vt);
185 | hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
186 | break;
187 | }
188 |
189 | size_t cb = ::SysStringByteLen(var.bstrVal);
190 |
191 | if (!bufResult.Alloc(cb))
192 | {
193 | hr = E_OUTOFMEMORY;
194 | ATLTRACE(L"Failed to alloc heap for raw cert.\n");
195 | break;
196 | }
197 |
198 | CopyMemory(bufResult.Get(), var.bstrVal, cb);
199 | } while (false);
200 |
201 | return hr;
202 | }
203 |
204 | HRESULT CCertServerExit::CopyString(
205 | const ATL::CComVariant& var,
206 | CHeapWString& strResult)
207 | {
208 | return strResult.Copy(var.bstrVal);
209 | }
210 |
211 | HRESULT CCertServerExit::GetCertificateStringProperty(
212 | LPCWSTR pwszName,
213 | OUT CHeapWString& strResult) const
214 | {
215 | ATL::CComVariant var;
216 | HRESULT hr = GetCertificateProperty(
217 | pwszName,
218 | CertServerPropType::PropTypeString,
219 | OUT var);
220 | if (SUCCEEDED(hr))
221 | {
222 | hr = CopyString(var, strResult);
223 | }
224 |
225 | return hr;
226 | }
227 |
228 | HRESULT CCertServerExit::GetCertificateLongProperty(
229 | LPCWSTR pwszName,
230 | OUT LONG& lResult) const
231 | {
232 | ATL::CComVariant var;
233 | HRESULT hr = GetCertificateProperty(
234 | pwszName,
235 | CertServerPropType::PropTypeLong,
236 | OUT var);
237 | if (SUCCEEDED(hr))
238 | {
239 | lResult = var.lVal;
240 | }
241 |
242 | return hr;
243 | }
--------------------------------------------------------------------------------
/src/PKI/ExitModule/CertServerExit.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | /*++
3 |
4 | Copyright (C) Microsoft Corp. All rights reserved.
5 |
6 | Abstract:
7 |
8 | Wrapper for ICertServerExit.
9 |
10 | --*/
11 |
12 | #include "CertServerPropType.h"
13 |
14 | /*++
15 |
16 | Abstract:
17 |
18 | Wrapper for ICertServerExit.
19 |
20 | --*/
21 | class CCertServerExit
22 | {
23 | public:
24 | /*++
25 |
26 | Abstract:
27 |
28 | Initializes a new instance of the CCertServerExit class.
29 |
30 | --*/
31 | CCertServerExit();
32 |
33 | /*++
34 |
35 | Abstract:
36 |
37 | Destroys the current instance.
38 |
39 | --*/
40 | ~CCertServerExit();
41 |
42 | /*++
43 |
44 | Abstract:
45 |
46 | Initializes the server interface with an optional context.
47 |
48 | Parameters:
49 |
50 | lContext - the context passed to ICertExit::Notify() or 0.
51 |
52 | Returns:
53 |
54 | S_OK for success or an error code.
55 |
56 | Remarks:
57 |
58 | The context is optional during the ICertExit::Initialize() call.
59 | --*/
60 | HRESULT Init(
61 | LONG lContext = 0L);
62 |
63 | /*++
64 |
65 | Abstract:
66 |
67 | Releases the underlying interface.
68 |
69 | --*/
70 | inline void Clear()
71 | {
72 | m_ptrInner.Release();
73 | m_lContext = 0L;
74 | }
75 |
76 | /*++
77 |
78 | Abstract:
79 |
80 | Gets the context id.
81 |
82 | Returns:
83 |
84 | The context id.
85 |
86 | Remarks:
87 |
88 | Use for tracing or anything where a matching number is needed for the context.
89 | --*/
90 | inline LONG GetContext() const
91 | {
92 | return m_lContext;
93 | }
94 |
95 | /*++
96 |
97 | Abstract:
98 |
99 | Gets the property of a request.
100 |
101 | Parameters:
102 |
103 | pwszName - the property name.
104 | ePropType - the property type.
105 | varResult - receives the value of the property.
106 |
107 | Returns:
108 |
109 | S_OK for success. An error code on failure.
110 |
111 | --*/
112 | HRESULT GetRequestProperty(
113 | LPCWSTR pwszName,
114 | CertServerPropType ePropType,
115 | OUT ATL::CComVariant& varResult) const;
116 |
117 | /*++
118 |
119 | Abstract:
120 |
121 | Gets the property of a certificate (or the server).
122 |
123 | Parameters:
124 |
125 | pwszName - the property name.
126 | ePropType - the property type.
127 | varResult - receives the value of the property.
128 |
129 | Returns:
130 |
131 | S_OK for success. An error code on failure.
132 |
133 | --*/
134 | HRESULT GetCertificateProperty(
135 | LPCWSTR pwszName,
136 | CertServerPropType ePropType,
137 | OUT ATL::CComVariant& varResult) const;
138 |
139 | /*++
140 |
141 | Abstract:
142 |
143 | Gets the ModuleRegistryLocation property.
144 |
145 | Parameters:
146 |
147 | strResult - on success, receives the string value.
148 |
149 | Returns:
150 |
151 | S_OK - success.
152 | Other - error code.
153 | --*/
154 | HRESULT GetModuleRegistryLocation(
155 | OUT CHeapWString& strResult) const;
156 |
157 | /*++
158 |
159 | Abstract:
160 |
161 | Gets the CAType property.
162 |
163 | Parameters:
164 |
165 | eResult - on success, receives the enum value.
166 |
167 | Returns:
168 |
169 | S_OK - success.
170 | Other - error code.
171 | --*/
172 | HRESULT GetCATypeProperty(OUT ENUM_CATYPES& eResult) const
173 | {
174 | LONG lResult = 0;
175 | HRESULT hr = GetCertificateLongProperty(wszPROPCATYPE, lResult);
176 | eResult = (ENUM_CATYPES)lResult;
177 | return hr;
178 | }
179 |
180 | /*++
181 |
182 | Abstract:
183 |
184 | Gets the raw certificate property.
185 |
186 | Parameters:
187 |
188 | bufResult - On success, receives the raw bytes of the request.
189 |
190 | Returns:
191 |
192 | S_OK - success.
193 | Other - error code.
194 | --*/
195 | HRESULT GetRawCertificateProperty(OUT CHeapBuffer& bufResult) const;
196 |
197 | /*++
198 |
199 | Abstract:
200 |
201 | Gets the Subject key identifier property.
202 |
203 | Parameters:
204 |
205 | strResult - On success, receives the subject key identifier of the cert.
206 |
207 | Returns:
208 |
209 | S_OK - success.
210 | Other - error code.
211 | --*/
212 | HRESULT GetCertificateSubjectKeyIdentifierProperty(
213 | OUT CHeapWString& strResult) const
214 | {
215 | return GetCertificateStringProperty(
216 | wszPROPCERTIFICATESUBJECTKEYIDENTIFIER,
217 | strResult);
218 | }
219 |
220 | /*++
221 |
222 | Abstract:
223 |
224 | Gets the serial number property.
225 |
226 | Parameters:
227 |
228 | strResult - On success, receives the subject key identifier of the cert.
229 |
230 | Returns:
231 |
232 | S_OK - success.
233 | Other - error code.
234 | --*/
235 | HRESULT GetCertificateSerialNumberProperty(
236 | OUT CHeapWString& strResult) const
237 | {
238 | return GetCertificateStringProperty(
239 | wszPROPCERTIFICATESERIALNUMBER,
240 | strResult);
241 | }
242 |
243 | private:
244 | ATL::CComPtr m_ptrInner;
245 | LONG m_lContext;
246 |
247 | static HRESULT CopyString(
248 | const ATL::CComVariant& var,
249 | CHeapWString& strResult);
250 |
251 | HRESULT GetCertificateStringProperty(
252 | LPCWSTR pwszName,
253 | OUT CHeapWString& strResult) const;
254 |
255 | HRESULT GetCertificateLongProperty(
256 | LPCWSTR pwszName,
257 | OUT LONG& lResult) const;
258 |
259 | CCertServerExit(const CCertServerExit&) = delete;
260 | CCertServerExit& operator=(const CCertServerExit&) = delete;
261 | };
262 |
263 |
--------------------------------------------------------------------------------
/src/PKI/ExitModule/CertServerPropType.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | /*++
3 |
4 | Copyright (C) Microsoft Corp. All rights reserved.
5 |
6 | File:
7 |
8 | CertServerPropType.h
9 |
10 | Abstract:
11 |
12 | CertServerPropType enum
13 |
14 | Authors:
15 |
16 | Jon Rowlett (jrowlett)
17 |
18 | History:
19 | 10-Apr-2023 jrowlett Created.
20 |
21 | --*/
22 |
23 | /*++
24 |
25 | Abstract:
26 |
27 | Enum to wrap the DWORD Certsrv.h has for property types.
28 |
29 | --*/
30 | typedef enum _CertServerPropType : DWORD
31 | {
32 | // signed long.
33 | PropTypeLong = PROPTYPE_LONG,
34 |
35 | // date+time.
36 | PropTypeDate = PROPTYPE_DATE,
37 |
38 | // binary data.
39 | PropTypeBinary = PROPTYPE_BINARY,
40 |
41 | // string.
42 | PropTypeString = PROPTYPE_STRING,
43 | } CertServerPropType;
--------------------------------------------------------------------------------
/src/PKI/ExitModule/EventArg.cpp:
--------------------------------------------------------------------------------
1 | /*++
2 |
3 | Copyright (C) Microsoft Corp. All rights reserved.
4 |
5 | File:
6 |
7 | EventArg.cpp
8 |
9 | Abstract:
10 |
11 | CEventArg and dervived class impls.
12 |
13 | Authors:
14 |
15 | Jon Rowlett (jrowlett)
16 |
17 | History:
18 | 20-Apr-2023 jrowlett Created.
19 |
20 | --*/
21 |
22 | #include "pch.h"
23 | #include "EventArg.h"
24 |
25 | const LPCWSTR CNumericEventArg::s_pwszFormatString = L"%u";
26 | const LPCWSTR CNumericEventArg::s_pwszFormatString = L"%x";
27 | constexpr const size_t g_cchMessage = 4096;
28 |
29 | HRESULT CStringEventArg::Format(OUT LPCWSTR& rpwszResult)
30 | {
31 | rpwszResult = m_pwszValue;
32 | return S_OK;
33 | }
34 |
35 | HRESULT CErrorMessageEventArg::Format(OUT LPCWSTR& rpwszResult)
36 | {
37 | if (!m_bufMessage.Alloc(g_cchMessage))
38 | {
39 | return E_OUTOFMEMORY;
40 | }
41 |
42 | HRESULT hr = S_OK;
43 | DWORD cch = ::FormatMessageW(
44 | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
45 | NULL, // lpSource
46 | m_hr,
47 | LANG_SYSTEM_DEFAULT,
48 | m_bufMessage.Get(),
49 | (DWORD)m_bufMessage.GetLength(),
50 | nullptr);
51 | if (cch == 0)
52 | {
53 | hr = HRESULT_FROM_WIN32(::GetLastError());
54 | ATLTRACE(L"FormatMessage failed for error=%x, hr=%x\n", m_hr, hr);
55 | m_bufMessage.Clear();
56 | }
57 |
58 | rpwszResult = m_bufMessage.Get();
59 | return hr;
60 | }
--------------------------------------------------------------------------------
/src/PKI/ExitModule/EventArg.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | /*++
3 |
4 | Copyright (C) Microsoft Corp. All rights reserved.
5 |
6 | File:
7 |
8 | EventArg.h
9 |
10 | Abstract:
11 |
12 | CEventArg and dervived class declarations.
13 |
14 | Authors:
15 |
16 | Jon Rowlett (jrowlett)
17 |
18 | History:
19 | 20-Apr-2023 jrowlett Created.
20 |
21 | --*/
22 |
23 | /*++
24 |
25 | Abstract:
26 |
27 | Wrapper around event arguments of various types that exposes
28 | an abstract method to convert to string.
29 | --*/
30 | class CEventArg
31 | {
32 | public:
33 | virtual ~CEventArg() = default;
34 |
35 | /*++
36 |
37 | Abstract:
38 |
39 | Formats the value to a string and provides a reference to the string.
40 |
41 | Parameters:
42 |
43 | rpwszResult - on success, receives a pointer to the result string.
44 |
45 | Returns:
46 |
47 | S_OK - success.
48 | other - failure.
49 |
50 | Remarks:
51 |
52 | The class manages any memory allocated for the string. Callers should assume
53 | the string is no longer valid after the class instance is destroyed.
54 |
55 | --*/
56 | virtual HRESULT Format(OUT LPCWSTR& rpwszResult) = 0;
57 |
58 | protected:
59 | CEventArg() = default;
60 | private:
61 | CEventArg(const CEventArg&) = delete;
62 | CEventArg& operator=(const CEventArg&) = delete;
63 | };
64 |
65 | class CStringEventArg : public CEventArg
66 | {
67 | public:
68 | CStringEventArg(LPCWSTR pwszValue)
69 | : CEventArg(), m_pwszValue(pwszValue)
70 | {
71 | }
72 |
73 | virtual HRESULT Format(OUT LPCWSTR& rpwszResult);
74 |
75 | private:
76 | LPCWSTR m_pwszValue;
77 | };
78 |
79 | template
80 | class CNumericEventArg : public CEventArg
81 | {
82 | public:
83 | CNumericEventArg(const T& varValue)
84 | : CEventArg(), m_varValue(varValue)
85 | {
86 | }
87 |
88 | virtual HRESULT Format(OUT LPCWSTR& rpwszResult)
89 | {
90 | rpwszResult = nullptr;
91 | HRESULT hr = ::StringCchPrintfW(
92 | m_bufResult.Get(),
93 | m_bufResult.GetLength(),
94 | s_pwszFormatString,
95 | m_varValue);
96 | if (SUCCEEDED(hr))
97 | {
98 | rpwszResult = m_bufResult.Get();
99 | }
100 |
101 | return hr;
102 | }
103 |
104 | private:
105 | static const LPCWSTR s_pwszFormatString;
106 | const T m_varValue;
107 | CStaticBuffer m_bufResult;
108 | };
109 |
110 | class CErrorMessageEventArg : public CEventArg
111 | {
112 | public:
113 | CErrorMessageEventArg(HRESULT hr)
114 | : CEventArg(), m_hr(hr)
115 | {
116 | }
117 |
118 | virtual HRESULT Format(OUT LPCWSTR& rpwszResult);
119 |
120 | private:
121 | HRESULT m_hr;
122 | CHeapBuffer m_bufMessage;
123 | };
--------------------------------------------------------------------------------
/src/PKI/ExitModule/EventProcessor.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | /*++
3 |
4 | Copyright (C) Microsoft Corp. All rights reserved.
5 |
6 | File:
7 |
8 | EventProcessor.h
9 |
10 | Abstract:
11 |
12 | CEventProcessor class declaration.
13 |
14 | Authors:
15 |
16 | Jon Rowlett (jrowlett)
17 |
18 | History:
19 | 11-Apr-2023 jrowlett Created.
20 |
21 | --*/
22 |
23 | #include "EventProcessorConfig.h"
24 |
25 | /*++
26 |
27 | Abstract:
28 |
29 | Processes structured events from the exit module by calling an external process.
30 |
31 | --*/
32 | class CEventProcessor
33 | {
34 | public:
35 | CEventProcessor(const CPMIExitModuleEventSource& objEventSource);
36 | ~CEventProcessor();
37 |
38 | HRESULT Init();
39 |
40 | HRESULT NotifyCertIssued(
41 | LPCWSTR pwszSubjectKeyIdentifier,
42 | LPCWSTR pwszSerialNumber,
43 | const CBuffer& bufRawCert) const;
44 |
45 | private:
46 | CEventProcessorConfig m_objConfig;
47 | const CPMIExitModuleEventSource& m_objEventSource;
48 |
49 | static HRESULT GetTempFilePath(
50 | OUT CHeapWString& strPath);
51 | static HRESULT EscapeArgumentForPS(
52 | LPCWSTR pwsz,
53 | OUT CHeapWString& strResult);
54 | HRESULT RunProcess(
55 | const CBuffer& bufArgs,
56 | LPCWSTR pwszTempFile,
57 | OUT DWORD& dwExitCode) const;
58 |
59 | CEventProcessor(const CEventProcessor&) = delete;
60 | CEventProcessor& operator=(const CEventProcessor&) = delete;
61 | };
62 |
63 |
--------------------------------------------------------------------------------
/src/PKI/ExitModule/EventProcessorConfig.cpp:
--------------------------------------------------------------------------------
1 | /*++
2 |
3 | Copyright (C) Microsoft Corp. All rights reserved.
4 |
5 | File:
6 |
7 | EventProcessorConfig.cpp
8 |
9 | Abstract:
10 |
11 | CEventProcessorConfig class impl.
12 |
13 | Authors:
14 |
15 | Jon Rowlett (jrowlett)
16 |
17 | History:
18 | 14-Apr-2023 jrowlett Created.
19 |
20 | --*/
21 | #include "pch.h"
22 | #include "EventProcessorConfig.h"
23 |
24 | LPCWSTR g_pwszRegSubkey = L"Software\\Microsoft\\PMI\\PMIExitModule";
25 | LPCWSTR g_pwszExePathValueName = L"ExePath";
26 | LPCWSTR g_pwszArgumentsValueName = L"Arguments";
27 | LPCWSTR g_pwszEscapeForPSValueName = L"EscapeForPS";
28 |
29 | constexpr const size_t g_cbRegValueBuffer = 1024;
30 |
31 | CEventProcessorConfig::CEventProcessorConfig()
32 | : m_fEscapeForPS(false)
33 | {
34 | }
35 |
36 | CEventProcessorConfig::~CEventProcessorConfig()
37 | {
38 | }
39 |
40 | HRESULT CEventProcessorConfig::Init()
41 | {
42 | HRESULT hr = S_OK;
43 | LSTATUS lr = ERROR_SUCCESS;
44 | ATL::CRegKey keyModule;
45 | DWORD dwType = 0;
46 | DWORD cbBuf = 0;
47 |
48 | do
49 | {
50 | lr = keyModule.Open(
51 | HKEY_LOCAL_MACHINE,
52 | g_pwszRegSubkey,
53 | KEY_ENUMERATE_SUB_KEYS | KEY_EXECUTE | KEY_QUERY_VALUE);
54 | if (lr != ERROR_SUCCESS)
55 | {
56 | hr = HRESULT_FROM_WIN32(lr);
57 | ATLTRACE(L"Failed to open reg key HKLM\\%s, hr=%x\n", g_pwszRegSubkey, hr);
58 | break;
59 | }
60 |
61 | if (!m_strExePath.Alloc(g_cbRegValueBuffer))
62 | {
63 | ATLTRACE(L"Failed to alloc wchars for exe path.\n");
64 | hr = E_OUTOFMEMORY;
65 | break;
66 | }
67 |
68 | cbBuf = (DWORD)m_strExePath.GetSize();
69 | lr = keyModule.QueryValue(
70 | g_pwszExePathValueName,
71 | &dwType,
72 | (BYTE*)m_strExePath.Get(),
73 | &cbBuf);
74 | if (lr != ERROR_SUCCESS)
75 | {
76 | hr = HRESULT_FROM_WIN32(lr);
77 | ATLTRACE(L"Failed to query reg value %s, hr=%x\n", g_pwszExePathValueName, hr);
78 | break;
79 | }
80 |
81 | if (dwType != REG_SZ && dwType != REG_EXPAND_SZ)
82 | {
83 | ATLTRACE(L"Expected REG_SZ, actual %d\n", dwType);
84 | hr = E_UNEXPECTED;
85 | break;
86 | }
87 |
88 | DWORD dwEscapeForPS = 0;
89 | lr = keyModule.QueryDWORDValue(
90 | g_pwszEscapeForPSValueName,
91 | OUT dwEscapeForPS);
92 | if (lr != ERROR_SUCCESS)
93 | {
94 | // optional. ignore failure.
95 | ATLTRACE(
96 | L"Failed to query optional reg value %s, hr=%x\n",
97 | g_pwszEscapeForPSValueName,
98 | HRESULT_FROM_WIN32(lr));
99 | }
100 | else
101 | {
102 | m_fEscapeForPS = (dwEscapeForPS != 0);
103 | }
104 |
105 | if (!m_bufArgData.Alloc(g_cbRegValueBuffer))
106 | {
107 | ATLTRACE(L"Failed to alloc wchars for args.\n");
108 | hr = E_OUTOFMEMORY;
109 | break;
110 | }
111 |
112 | ULONG cch = (ULONG)m_bufArgData.GetLength();
113 | lr = keyModule.QueryMultiStringValue(
114 | g_pwszArgumentsValueName,
115 | m_bufArgData.Get(),
116 | &cch);
117 | if (lr != ERROR_SUCCESS)
118 | {
119 | // optional. ignore failure.
120 | ATLTRACE(
121 | L"Failed to query optional reg value %s, hr=%x\n",
122 | g_pwszArgumentsValueName,
123 | HRESULT_FROM_WIN32(lr));
124 | }
125 | else
126 | {
127 | size_t cArgs = 0;
128 | size_t cchMax = cch;
129 | LPCWSTR pwsz = m_bufArgData.Get();
130 | while (pwsz && *pwsz)
131 | {
132 | size_t cchArg = 0;
133 | hr = ::StringCchLengthW(pwsz, cchMax, &cchArg);
134 | if (FAILED(hr))
135 | {
136 | break;
137 | }
138 |
139 | cArgs++;
140 | cchMax -= cchArg + 1;
141 | pwsz += cchArg + 1;
142 | }
143 |
144 | if (!m_bufArguments.Alloc(cArgs))
145 | {
146 | hr = E_OUTOFMEMORY;
147 | break;
148 | }
149 |
150 | pwsz = m_bufArgData.Get();
151 | cchMax = cch;
152 | for (UINT nIndex = 0; pwsz && *pwsz; nIndex++)
153 | {
154 | size_t cchArg = 0;
155 | hr = ::StringCchLengthW(pwsz, cchMax, &cchArg);
156 | if (FAILED(hr))
157 | {
158 | break;
159 | }
160 |
161 | m_bufArguments.Get()[nIndex] = pwsz;
162 |
163 | cchMax -= (ULONG)cchArg + 1;
164 | pwsz += cchArg + 1;
165 | }
166 | }
167 |
168 | } while (false);
169 |
170 | return hr;
171 | }
172 |
--------------------------------------------------------------------------------
/src/PKI/ExitModule/EventProcessorConfig.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | /*++
3 |
4 | Copyright (C) Microsoft Corp. All rights reserved.
5 |
6 | File:
7 |
8 | EventProcessorConfig.h
9 |
10 | Abstract:
11 |
12 | CEventProcessorConfig class declaration.
13 |
14 | Authors:
15 |
16 | Jon Rowlett (jrowlett)
17 |
18 | History:
19 | 14-Apr-2023 jrowlett Created.
20 |
21 | --*/
22 |
23 | /*++
24 |
25 | Abstract:
26 |
27 | Registry Configuration used by the event processor.
28 | --*/
29 | class CEventProcessorConfig
30 | {
31 | public:
32 | CEventProcessorConfig();
33 | ~CEventProcessorConfig();
34 |
35 | /*++
36 |
37 | Abstract:
38 |
39 | Loads config values from the registry.
40 |
41 | Returns:
42 |
43 | S_OK - success.
44 | other - error.
45 | --*/
46 | HRESULT Init();
47 |
48 | inline LPCWSTR GetExePath() const
49 | {
50 | return m_strExePath.Get();
51 | }
52 |
53 | inline const CBuffer& GetArguments() const
54 | {
55 | return m_bufArguments;
56 | }
57 |
58 | inline bool GetEscapeForPS() const
59 | {
60 | return m_fEscapeForPS;
61 | }
62 |
63 | private:
64 | CHeapWString m_strExePath;
65 | CHeapBuffer m_bufArgData;
66 | CHeapBuffer m_bufArguments;
67 | bool m_fEscapeForPS;
68 |
69 | CEventProcessorConfig(const CEventProcessorConfig&) = delete;
70 | CEventProcessorConfig& operator=(const CEventProcessorConfig&) = delete;
71 | };
72 |
73 |
--------------------------------------------------------------------------------
/src/PKI/ExitModule/EventSource.cpp:
--------------------------------------------------------------------------------
1 | /*++
2 |
3 | Copyright (C) Microsoft Corp. All rights reserved.
4 |
5 | File:
6 |
7 | EventSource.cpp
8 |
9 | Abstract:
10 |
11 | CEventSource class impl.
12 |
13 | Authors:
14 |
15 | Jon Rowlett (jrowlett)
16 |
17 | History:
18 | 18-Apr-2023 jrowlett Created.
19 |
20 | --*/
21 |
22 | #include "pch.h"
23 | #include "EventSource.h"
24 |
25 | CEventSource::CEventSource(
26 | LPCWSTR pwszProviderName)
27 | : m_pwszProviderName(pwszProviderName), m_hEventLog(NULL)
28 | {
29 | }
30 |
31 | CEventSource::~CEventSource()
32 | {
33 | Close();
34 | }
35 |
36 | HRESULT CEventSource::Open()
37 | {
38 | HRESULT hr = S_OK;
39 | Close();
40 | m_hEventLog = ::RegisterEventSourceW(
41 | NULL, // lpUNCServerName
42 | m_pwszProviderName); // lpSourceName
43 | if (!m_hEventLog)
44 | {
45 | hr = HRESULT_FROM_WIN32(::GetLastError());
46 | ATLTRACE(L"RegisterEventSourceW(%s) failed, hr=%x\n", m_pwszProviderName, hr);
47 | }
48 |
49 | return hr;
50 | }
51 |
52 | void CEventSource::Close()
53 | {
54 | if (m_hEventLog)
55 | {
56 | ::DeregisterEventSource(m_hEventLog);
57 | m_hEventLog = NULL;
58 | }
59 | }
60 |
61 | HRESULT CEventSource::ReportEvent(
62 | WORD wType,
63 | WORD wCategory,
64 | DWORD dwEventID,
65 | const CBuffer& bufStrings,
66 | const CBuffer& bufData,
67 | const PSID pUserSid /* = nullptr */) const
68 | {
69 | HRESULT hr = S_OK;
70 | if (!m_hEventLog)
71 | {
72 | return HRESULT_FROM_WIN32(ERROR_INVALID_OPERATION);
73 | }
74 |
75 | if (!::ReportEventW(
76 | m_hEventLog,
77 | wType,
78 | wCategory,
79 | dwEventID,
80 | pUserSid,
81 | (WORD)bufStrings.GetLength(),
82 | (DWORD)bufData.GetSize(),
83 | const_cast(bufStrings.Get()),
84 | const_cast(bufData.Get())))
85 | {
86 | hr = HRESULT_FROM_WIN32(::GetLastError());
87 | ATLTRACE(L"ReportEventW failed, hr=%x\n", hr);
88 | }
89 |
90 | return hr;
91 | }
92 |
93 | HRESULT CEventSource::ReportEvent(
94 | WORD wType,
95 | WORD wCategory,
96 | DWORD dwEventID,
97 | const CBuffer& bufStrings,
98 | const CBuffer& bufData,
99 | const PSID pUserSid /* = nullptr */) const
100 | {
101 | CHeapBuffer bufFormattedStrings;
102 | HRESULT hr = S_OK;
103 | if (bufStrings.GetLength() > 0)
104 | {
105 | if (!bufFormattedStrings.Alloc(bufStrings.GetLength()))
106 | {
107 | hr = E_OUTOFMEMORY;
108 | return hr;
109 | }
110 |
111 | for (size_t i = 0; i < bufStrings.GetLength(); i++)
112 | {
113 | CEventArg* arg = bufStrings.Get()[i];
114 | LPCWSTR& pwszResult = bufFormattedStrings.Get()[i];
115 | hr = arg->Format(OUT pwszResult);
116 | if (FAILED(hr))
117 | {
118 | return hr;
119 | }
120 | }
121 | }
122 |
123 | return ReportEvent(
124 | wType,
125 | wCategory,
126 | dwEventID,
127 | bufFormattedStrings,
128 | bufData,
129 | pUserSid);
130 | }
--------------------------------------------------------------------------------
/src/PKI/ExitModule/EventSource.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "EventArg.h"
3 | /*++
4 |
5 | Copyright (C) Microsoft Corp. All rights reserved.
6 |
7 | File:
8 |
9 | EventSource.h
10 |
11 | Abstract:
12 |
13 | CEventSource class declaration.
14 |
15 | Authors:
16 |
17 | Jon Rowlett (jrowlett)
18 |
19 | History:
20 | 18-Apr-2023 jrowlett Created.
21 |
22 | --*/
23 |
24 | /*++
25 |
26 | Abstract:
27 |
28 | Wraps Win32 APIs for interacting with an event source.
29 | --*/
30 | class CEventSource
31 | {
32 | public:
33 | CEventSource(LPCWSTR pwszProviderName);
34 | ~CEventSource();
35 |
36 | /*++
37 |
38 | Abstract:
39 |
40 | Opens the event source by calling the Win32 RegisterEventSource API.
41 |
42 | Returns:
43 | S_OK - success.
44 | other - error.
45 | --*/
46 | HRESULT Open();
47 |
48 | /*++
49 |
50 | Abstract:
51 |
52 | Closes the event log.
53 |
54 | --*/
55 | void Close();
56 |
57 | /*++
58 |
59 | Abstract:
60 |
61 | Wrapper on the Win32 ReportEvent API.
62 |
63 | Arguments:
64 |
65 | wType - event type.
66 | wCategory - event category.
67 | dwEventID - event ID.
68 | bufStrings - list of strings to include in the event.
69 | bufData - custom event data.
70 | pUserSid - user SID.
71 |
72 | Returns:
73 |
74 | S_OK - success.
75 | other - error.
76 | --*/
77 | HRESULT ReportEvent(
78 | WORD wType,
79 | WORD wCategory,
80 | DWORD dwEventID,
81 | const CBuffer& bufStrings,
82 | const CBuffer& bufData,
83 | const PSID pUserSid = nullptr) const;
84 |
85 | /*++
86 |
87 | Abstract:
88 |
89 | Wrapper on the Win32 ReportEvent API.
90 |
91 | Arguments:
92 |
93 | wType - event type.
94 | wCategory - event category.
95 | dwEventID - event ID.
96 | bufStrings - list of values to include as strings in the event.
97 | bufData - custom event data.
98 | pUserSid - user SID.
99 |
100 | Returns:
101 |
102 | S_OK - success.
103 | other - error.
104 | --*/
105 | HRESULT ReportEvent(
106 | WORD wType,
107 | WORD wCategory,
108 | DWORD dwEventID,
109 | const CBuffer& bufStrings,
110 | const CBuffer& bufData,
111 | const PSID pUserSid = nullptr) const;
112 |
113 | private:
114 | LPCWSTR m_pwszProviderName;
115 | HANDLE m_hEventLog;
116 |
117 | CEventSource(const CEventSource&) = delete;
118 | CEventSource& operator=(const CEventSource&) = delete;
119 | };
120 |
121 |
--------------------------------------------------------------------------------
/src/PKI/ExitModule/ExitModule.cpp:
--------------------------------------------------------------------------------
1 | // ExitModule.cpp : Implementation of DLL Exports.
2 |
3 |
4 | #include "pch.h"
5 | #include "framework.h"
6 | #include "resource.h"
7 | #include "ExitModule_i.h"
8 | #include "dllmain.h"
9 |
10 |
11 | using namespace ATL;
12 |
13 | // Used to determine whether the DLL can be unloaded by OLE.
14 | _Use_decl_annotations_
15 | STDAPI DllCanUnloadNow(void)
16 | {
17 | return _Module.DllCanUnloadNow();
18 | }
19 |
20 | // Returns a class factory to create an object of the requested type.
21 | _Use_decl_annotations_
22 | STDAPI DllGetClassObject(_In_ REFCLSID rclsid, _In_ REFIID riid, _Outptr_ LPVOID* ppv)
23 | {
24 | return _Module.DllGetClassObject(rclsid, riid, ppv);
25 | }
26 |
27 | // DllRegisterServer - Adds entries to the system registry.
28 | _Use_decl_annotations_
29 | STDAPI DllRegisterServer(void)
30 | {
31 | // registers object, typelib and all interfaces in typelib
32 | HRESULT hr = _Module.DllRegisterServer();
33 | return hr;
34 | }
35 |
36 | // DllUnregisterServer - Removes entries from the system registry.
37 | _Use_decl_annotations_
38 | STDAPI DllUnregisterServer(void)
39 | {
40 | HRESULT hr = _Module.DllUnregisterServer();
41 | return hr;
42 | }
43 |
44 | // DllInstall - Adds/Removes entries to the system registry per user per machine.
45 | STDAPI DllInstall(BOOL bInstall, _In_opt_ LPCWSTR pszCmdLine)
46 | {
47 | HRESULT hr = E_FAIL;
48 | static const wchar_t szUserSwitch[] = L"user";
49 |
50 | if (pszCmdLine != nullptr)
51 | {
52 | if (_wcsnicmp(pszCmdLine, szUserSwitch, _countof(szUserSwitch)) == 0)
53 | {
54 | ATL::AtlSetPerUserRegistration(true);
55 | }
56 | }
57 |
58 | if (bInstall)
59 | {
60 | hr = DllRegisterServer();
61 | if (FAILED(hr))
62 | {
63 | DllUnregisterServer();
64 | }
65 | }
66 | else
67 | {
68 | hr = DllUnregisterServer();
69 | }
70 |
71 | return hr;
72 | }
73 |
74 |
75 |
--------------------------------------------------------------------------------
/src/PKI/ExitModule/ExitModule.def:
--------------------------------------------------------------------------------
1 | ; ExitModule.def : Declares the module parameters.
2 |
3 | LIBRARY
4 |
5 | EXPORTS
6 | DllCanUnloadNow PRIVATE
7 | DllGetClassObject PRIVATE
8 | DllRegisterServer PRIVATE
9 | DllUnregisterServer PRIVATE
10 | DllInstall PRIVATE
11 |
--------------------------------------------------------------------------------
/src/PKI/ExitModule/ExitModule.idl:
--------------------------------------------------------------------------------
1 | // ExitModule.idl : IDL source for ExitModule
2 | //
3 |
4 | // This file will be processed by the MIDL tool to
5 | // produce the type library (ExitModule.tlb) and marshalling code.
6 |
7 | import "oaidl.idl";
8 | import "ocidl.idl";
9 | import "certexit.idl";
10 |
11 | [
12 | uuid(03c5878a-932c-4063-b21a-5f89f579194f),
13 | version(1.0),
14 | ]
15 | library ExitModuleLib
16 | {
17 | importlib("stdole2.tlb");
18 | [
19 | uuid(8a933dd2-ca9b-44f3-a0a1-ec5c1c860869)
20 | ]
21 | coclass PMIExitModule
22 | {
23 | [default] interface ICertManageModule;
24 | };
25 |
26 | [
27 | uuid(58f3c2bd-d361-46ef-a591-8ee31552647a)
28 | ]
29 | coclass PMICertExit
30 | {
31 | [default] interface ICertExit2;
32 | };
33 | };
34 |
35 | import "shobjidl.idl";
36 | import "shobjidl.idl";
37 |
--------------------------------------------------------------------------------
/src/PKI/ExitModule/ExitModule.rc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/adcs-proxy-exit-module/1e34447acb234504d641c09a48fbb1c278ff7acd/src/PKI/ExitModule/ExitModule.rc
--------------------------------------------------------------------------------
/src/PKI/ExitModule/ExitModule.rgs:
--------------------------------------------------------------------------------
1 | HKCR
2 | {
3 | }
4 |
--------------------------------------------------------------------------------
/src/PKI/ExitModule/ExitModuleps.def:
--------------------------------------------------------------------------------
1 |
2 | LIBRARY
3 |
4 | EXPORTS
5 | DllGetClassObject PRIVATE
6 | DllCanUnloadNow PRIVATE
7 | DllRegisterServer PRIVATE
8 | DllUnregisterServer PRIVATE
9 |
--------------------------------------------------------------------------------
/src/PKI/ExitModule/ManageProperty.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | /*++
3 |
4 | Copyright (C) Microsoft Corp. All rights reserved.
5 |
6 | Abstract:
7 |
8 | Definition of properties used by CPMIExitModule.
9 |
10 | --*/
11 | #include "framework.h"
12 |
13 | /*++
14 |
15 | Abstract:
16 |
17 | Base class for properties used by CPMIExitModule.
18 | --*/
19 | class CManageProperty
20 | {
21 | public:
22 |
23 | /*++
24 | Gets the name of the property.
25 |
26 | Returns:
27 | A constant pointer to the name string.
28 | --*/
29 | inline LPCWSTR GetName() const
30 | {
31 | return m_pwszName;
32 | }
33 |
34 | /*++
35 | Gets the value of the property.
36 |
37 | Parameters:
38 | rvarResult - reference to the variant to receive the value.
39 |
40 | Returns:
41 | S_OK - success
42 | Other - error code.
43 | --*/
44 | virtual HRESULT GetValue(VARIANT& rvarResult) const = 0;
45 |
46 | protected:
47 | /*++
48 | Abstract:
49 |
50 | Initializes a new instance of the CManageProperty class.
51 |
52 | Parameters:
53 | pwszName - static string for the property name.
54 |
55 | --*/
56 | CManageProperty(LPCWSTR pwszName)
57 | : m_pwszName(pwszName)
58 | {
59 | }
60 |
61 | private:
62 | LPCWSTR m_pwszName;
63 | };
64 |
--------------------------------------------------------------------------------
/src/PKI/ExitModule/PMICertExit.h:
--------------------------------------------------------------------------------
1 | // PMICertExit.h : Declaration of the CPMICertExit
2 |
3 | #pragma once
4 | #include "resource.h" // main symbols
5 |
6 |
7 |
8 | #include "ExitModule_i.h"
9 |
10 | #if defined(_WIN32_WCE) && !defined(_CE_DCOM) && !defined(_CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA)
11 | #error "Single-threaded COM objects are not properly supported on Windows CE platform, such as the Windows Mobile platforms that do not include full DCOM support. Define _CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA to force ATL to support creating single-thread COM object's and allow use of it's single-threaded COM object implementations. The threading model in your rgs file was set to 'Free' as that is the only threading model supported in non DCOM Windows CE platforms."
12 | #endif
13 |
14 | using namespace ATL;
15 |
16 |
17 | // CPMICertExit
18 |
19 | class ATL_NO_VTABLE CPMICertExit :
20 | public CComObjectRootEx,
21 | public CComCoClass,
22 | public IDispatchImpl,
23 | public ISupportErrorInfo
24 | {
25 | public:
26 | CPMICertExit()
27 | {
28 | }
29 |
30 | DECLARE_REGISTRY_RESOURCEID(107)
31 |
32 |
33 | BEGIN_COM_MAP(CPMICertExit)
34 | COM_INTERFACE_ENTRY(ICertExit)
35 | COM_INTERFACE_ENTRY(ICertExit2)
36 | COM_INTERFACE_ENTRY(ISupportErrorInfo)
37 | COM_INTERFACE_ENTRY(IDispatch)
38 | END_COM_MAP()
39 |
40 |
41 |
42 | DECLARE_PROTECT_FINAL_CONSTRUCT()
43 |
44 | HRESULT FinalConstruct()
45 | {
46 | return S_OK;
47 | }
48 |
49 | void FinalRelease()
50 | {
51 | }
52 |
53 | public:
54 |
55 | /*
56 | ICertExit
57 | */
58 |
59 | virtual HRESULT STDMETHODCALLTYPE Initialize(
60 | /* [in] */ __RPC__in const BSTR strConfig,
61 | /* [retval][out] */ __RPC__out LONG* pEventMask);
62 |
63 | virtual HRESULT STDMETHODCALLTYPE Notify(
64 | /* [in] */ LONG ExitEvent,
65 | /* [in] */ LONG Context);
66 |
67 | virtual HRESULT STDMETHODCALLTYPE GetDescription(
68 | /* [retval][out] */ __RPC__deref_out_opt BSTR* pstrDescription);
69 |
70 | /*
71 | ICertExit2
72 | */
73 |
74 | virtual HRESULT STDMETHODCALLTYPE GetManageModule(
75 | /* [retval][out] */ __RPC__deref_out_opt ICertManageModule** ppManageModule);
76 |
77 | /*
78 | ISupportErrorInfo
79 | */
80 |
81 | virtual HRESULT STDMETHODCALLTYPE InterfaceSupportsErrorInfo(
82 | /* [in] */ __RPC__in REFIID riid);
83 |
84 | protected:
85 | HRESULT NotifyCertIssued(IN CCertServerExit& objServer);
86 | HRESULT NotifyCRLIssued(IN CCertServerExit& objServer);
87 |
88 | private:
89 | /*
90 | Array of interfaces that support error info.
91 | */
92 | static const IID* s_rgErrorInfoInterfaces[];
93 |
94 | CHeapWString m_strConfig;
95 | CHeapWString m_strRegStorageLoc;
96 | ENUM_CATYPES m_eCAType;
97 | CPMIExitModuleEventSource m_objEventSource;
98 |
99 | HRESULT NotifyCertIssued(LONG lContext);
100 | HRESULT NotifyCertPending(LONG lContext);
101 | HRESULT NotifyCertDenied(LONG lContext);
102 | HRESULT NotifyCertRevoked(LONG lContext);
103 | HRESULT NotifyCertRetrievePending(LONG lContext);
104 | HRESULT NotifyCRLIssued(LONG lContext);
105 | HRESULT NotifyShutdown(LONG lContext);
106 | HRESULT NotifyCertImported(LONG lContext);
107 | };
108 |
109 | OBJECT_ENTRY_AUTO(__uuidof(PMICertExit), CPMICertExit)
110 |
--------------------------------------------------------------------------------
/src/PKI/ExitModule/PMICertExit.rgs:
--------------------------------------------------------------------------------
1 | HKCR
2 | {
3 | PMIExitModule.Exit.1 = s 'PMI Cert Exit class'
4 | {
5 | CLSID = s '{58f3c2bd-d361-46ef-a591-8ee31552647a}'
6 | }
7 | PMIExitModule.Exit = s 'PMI Cert Exit class'
8 | {
9 | CurVer = s 'PMIExitModule.Exit.1'
10 | }
11 | NoRemove CLSID
12 | {
13 | ForceRemove {58f3c2bd-d361-46ef-a591-8ee31552647a} = s 'PMI Cert Exit class'
14 | {
15 | ProgID = s 'PMIExitModule.Exit.1'
16 | VersionIndependentProgID = s 'PMIExitModule.Exit'
17 | ForceRemove Programmable
18 | InprocServer32 = s '%MODULE%'
19 | {
20 | val ThreadingModel = s 'Both'
21 | }
22 | TypeLib = s '{03c5878a-932c-4063-b21a-5f89f579194f}'
23 | Version = s '1.0'
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/PKI/ExitModule/PMIExitModule.cpp:
--------------------------------------------------------------------------------
1 | // PMIExitModule.cpp : Implementation of CPMIExitModule
2 |
3 | #include "pch.h"
4 | #include "PMIExitModule.h"
5 | #include "ResourceStringManageProperty.h"
6 |
7 | const CResourceStringManageProperty propName(
8 | wszCMM_PROP_NAME,
9 | IDS_PMIEXITMODULE_NAME);
10 | const CResourceStringManageProperty propDesc(
11 | wszCMM_PROP_DESCRIPTION,
12 | IDS_PMIEXITMODULE_DESC);
13 | const CResourceStringManageProperty propCopyright(
14 | wszCMM_PROP_COPYRIGHT,
15 | IDS_PMIEXITMODULE_COPYRIGHT);
16 | const CResourceStringManageProperty propFileVer(
17 | wszCMM_PROP_FILEVER,
18 | IDS_PMIEXITMODULE_FILEVER);
19 | const CResourceStringManageProperty propProductVer(
20 | wszCMM_PROP_PRODUCTVER,
21 | IDS_PMIEXITMODULE_PRODUCTVER);
22 | const CManageProperty* CPMIExitModule::s_rgProperties[] =
23 | {
24 | &propName,
25 | &propDesc,
26 | &propCopyright,
27 | &propFileVer,
28 | &propProductVer,
29 | };
30 |
31 | // CPMIExitModule
32 |
33 | STDMETHODIMP CPMIExitModule::GetProperty(
34 | /* [in] */ const BSTR /* strConfig */,
35 | /* [in] */ BSTR /* strStorageLocation */,
36 | /* [in] */ BSTR strPropertyName,
37 | /* [in] */ LONG /* dwFlags */,
38 | /* [retval][out] */ VARIANT __RPC_FAR* pvarProperty)
39 | {
40 | if (!pvarProperty)
41 | {
42 | return E_POINTER;
43 | }
44 |
45 | ::VariantInit(pvarProperty);
46 |
47 | HRESULT hr = S_FALSE;
48 | do
49 | {
50 | if (!strPropertyName || ::SysStringByteLen(strPropertyName) == 0)
51 | {
52 | break;
53 | }
54 |
55 | for (const CManageProperty** p = s_rgProperties;
56 | p != s_rgProperties + (sizeof(s_rgProperties) / sizeof(s_rgProperties[0]));
57 | p++)
58 | {
59 | const CManageProperty* pProp = *p;
60 | if (_wcsicmp(strPropertyName, pProp->GetName()) == 0)
61 | {
62 | hr = pProp->GetValue(*pvarProperty);
63 | break;
64 | }
65 | }
66 | } while (false);
67 |
68 | return hr;
69 | }
70 |
71 | STDMETHODIMP CPMIExitModule::SetProperty(
72 | /* [in] */ const BSTR /* strConfig */,
73 | /* [in] */ BSTR /* strStorageLocation */,
74 | /* [in] */ BSTR /* strPropertyName */,
75 | /* [in] */ LONG /* dwFlags */,
76 | /* [in] */ VARIANT const __RPC_FAR* /* pvarProperty */)
77 | {
78 | // no settable properties supported
79 | return S_FALSE;
80 | }
81 |
82 | STDMETHODIMP CPMIExitModule::Configure(
83 | /* [in] */ const BSTR /* strConfig */,
84 | /* [in] */ BSTR /* strStorageLocation */,
85 | /* [in] */ LONG /* dwFlags */)
86 | {
87 | // TODO: Show a message box.
88 | return S_OK;
89 | }
--------------------------------------------------------------------------------
/src/PKI/ExitModule/PMIExitModule.h:
--------------------------------------------------------------------------------
1 | // PMIExitModule.h : Declaration of the CPMIExitModule
2 |
3 | #pragma once
4 | #include "resource.h" // main symbols
5 |
6 | #include "ManageProperty.h"
7 |
8 | #include "ExitModule_i.h"
9 |
10 |
11 |
12 | #if defined(_WIN32_WCE) && !defined(_CE_DCOM) && !defined(_CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA)
13 | #error "Single-threaded COM objects are not properly supported on Windows CE platform, such as the Windows Mobile platforms that do not include full DCOM support. Define _CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA to force ATL to support creating single-thread COM object's and allow use of it's single-threaded COM object implementations. The threading model in your rgs file was set to 'Free' as that is the only threading model supported in non DCOM Windows CE platforms."
14 | #endif
15 |
16 | using namespace ATL;
17 |
18 | // Get the definition of _Module used by ATL macros.
19 | #include "dllmain.h"
20 |
21 | // CPMIExitModule
22 |
23 | class ATL_NO_VTABLE CPMIExitModule :
24 | public CComObjectRootEx,
25 | public CComCoClass,
26 | public IDispatchImpl
27 | {
28 | public:
29 | CPMIExitModule()
30 | {
31 | }
32 |
33 | DECLARE_REGISTRY_RESOURCEID(106)
34 |
35 | BEGIN_COM_MAP(CPMIExitModule)
36 | COM_INTERFACE_ENTRY(ICertManageModule)
37 | COM_INTERFACE_ENTRY(IDispatch)
38 | END_COM_MAP()
39 |
40 |
41 |
42 | DECLARE_PROTECT_FINAL_CONSTRUCT()
43 |
44 | HRESULT FinalConstruct()
45 | {
46 | return S_OK;
47 | }
48 |
49 | void FinalRelease()
50 | {
51 | }
52 |
53 | public:
54 | virtual HRESULT STDMETHODCALLTYPE GetProperty(
55 | /* [in] */ const BSTR strConfig,
56 | /* [in] */ BSTR strStorageLocation,
57 | /* [in] */ BSTR strPropertyName,
58 | /* [in] */ LONG dwFlags,
59 | /* [retval][out] */ VARIANT __RPC_FAR* pvarProperty);
60 |
61 | virtual HRESULT STDMETHODCALLTYPE SetProperty(
62 | /* [in] */ const BSTR strConfig,
63 | /* [in] */ BSTR strStorageLocation,
64 | /* [in] */ BSTR strPropertyName,
65 | /* [in] */ LONG dwFlags,
66 | /* [in] */ VARIANT const __RPC_FAR* pvarProperty);
67 |
68 | virtual HRESULT STDMETHODCALLTYPE Configure(
69 | /* [in] */ const BSTR strConfig,
70 | /* [in] */ BSTR strStorageLocation,
71 | /* [in] */ LONG dwFlags);
72 |
73 | private:
74 | static const CManageProperty* s_rgProperties[];
75 | };
76 |
77 | OBJECT_ENTRY_AUTO(__uuidof(PMIExitModule), CPMIExitModule)
78 |
--------------------------------------------------------------------------------
/src/PKI/ExitModule/PMIExitModule.rgs:
--------------------------------------------------------------------------------
1 | HKCR
2 | {
3 | NoRemove CLSID
4 | {
5 | ForceRemove {8a933dd2-ca9b-44f3-a0a1-ec5c1c860869} = s 'PMI Cert Exit Module'
6 | {
7 | ForceRemove Programmable
8 | InprocServer32 = s '%MODULE%'
9 | {
10 | val ThreadingModel = s 'Both'
11 | }
12 | ProgID = s 'PMIExitModule.ExitManage.1'
13 | VersionIndependentProgID = s 'PMIExitModule.ExitManage'
14 | TypeLib = s '{03c5878a-932c-4063-b21a-5f89f579194f}'
15 | Version = s '1.0'
16 | }
17 | }
18 | ForceRemove PMIExitModule.ExitManage
19 | {
20 | CLSID = s '{8a933dd2-ca9b-44f3-a0a1-ec5c1c860869}'
21 | CurVer = s 'PMIExitModule.ExitManage.1'
22 | }
23 | ForceRemove PMIExitModule.ExitManage.1
24 | {
25 | CLSID = s '{8a933dd2-ca9b-44f3-a0a1-ec5c1c860869}'
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/PKI/ExitModule/PMIExitModuleEventSource.cpp:
--------------------------------------------------------------------------------
1 | /*++
2 |
3 | Copyright (C) Microsoft Corp. All rights reserved.
4 |
5 | File:
6 |
7 | PMIExitModuleEventSource.cpp
8 |
9 | Abstract:
10 |
11 | CPMIExitModuleEventSource class impl.
12 |
13 | Authors:
14 |
15 | Jon Rowlett (jrowlett)
16 |
17 | History:
18 | 18-Apr-2023 jrowlett Created.
19 |
20 | --*/
21 |
22 | #include "pch.h"
23 | #include "PMIExitModuleEventSource.h"
24 | #include
25 | #include "../PMIExitModuleMessages/PMIExitModuleEventSourceDef.h"
26 |
27 | const LPCWSTR CPMIExitModuleEventSource::s_pwszProviderName = WSZ_PMIEXITMODULE_PROVIDERNAME;
28 |
29 | void CPMIExitModuleEventSource::ReportProcessSucceeded(
30 | DWORD dwProcessID,
31 | DWORD dwThreadID,
32 | DWORD dwExitCode) const
33 | {
34 | CNumericEventArg argProcessID(dwProcessID);
35 | CNumericEventArg argThreadID(dwThreadID);
36 | CNumericEventArg argExitCode(dwExitCode);
37 | CEventArg* rgArgs[] =
38 | {
39 | &argProcessID,
40 | &argThreadID,
41 | &argExitCode,
42 | };
43 |
44 | CRefBuffer bufArgs(rgArgs, sizeof(rgArgs) / sizeof(rgArgs[0]));
45 | HRESULT hr = ReportEvent(
46 | EVENTLOG_INFORMATION_TYPE,
47 | GENERAL_CATEGORY,
48 | MSG_PROCESS_SUCCEEDED,
49 | bufArgs,
50 | CRefBuffer());
51 | if (FAILED(hr))
52 | {
53 | ATLTRACE(L"ReportProcessSucceeded failed, hr=%x\n", hr);
54 | }
55 | }
56 |
57 | void CPMIExitModuleEventSource::ReportProcessFailed(
58 | DWORD dwProcessID,
59 | DWORD dwThreadID,
60 | DWORD dwExitCode,
61 | LPCWSTR pwszTempFilePath) const
62 | {
63 | CNumericEventArg argProcessID(dwProcessID);
64 | CNumericEventArg argThreadID(dwThreadID);
65 | CNumericEventArg argExitCode(dwExitCode);
66 | CStringEventArg argTempFile(pwszTempFilePath);
67 | CEventArg* rgArgs[] =
68 | {
69 | &argProcessID,
70 | &argThreadID,
71 | &argExitCode,
72 | &argTempFile,
73 | };
74 |
75 | CRefBuffer bufArgs(rgArgs, sizeof(rgArgs) / sizeof(rgArgs[0]));
76 | HRESULT hr = ReportEvent(
77 | EVENTLOG_ERROR_TYPE,
78 | GENERAL_CATEGORY,
79 | MSG_PROCESS_FAILED,
80 | bufArgs,
81 | CRefBuffer());
82 | if (FAILED(hr))
83 | {
84 | ATLTRACE(L"ReportProcessFailed failed, hr=%x\n", hr);
85 | }
86 | }
87 |
88 | void CPMIExitModuleEventSource::ReportProcessTimedOut(
89 | DWORD dwSeconds,
90 | DWORD dwProcessID,
91 | DWORD dwThreadID,
92 | LPCWSTR pwszTempFilePath) const
93 | {
94 | CNumericEventArg argSeconds(dwSeconds);
95 | CNumericEventArg argProcessID(dwProcessID);
96 | CNumericEventArg argThreadID(dwThreadID);
97 | CStringEventArg argTempFile(pwszTempFilePath);
98 | CEventArg* rgArgs[] =
99 | {
100 | &argSeconds,
101 | &argProcessID,
102 | &argThreadID,
103 | &argTempFile,
104 | };
105 |
106 | CRefBuffer bufArgs(rgArgs, sizeof(rgArgs) / sizeof(rgArgs[0]));
107 | HRESULT hr = ReportEvent(
108 | EVENTLOG_WARNING_TYPE,
109 | GENERAL_CATEGORY,
110 | MSG_PROCESS_TIMEDOUT,
111 | bufArgs,
112 | CRefBuffer());
113 | if (FAILED(hr))
114 | {
115 | ATLTRACE(L"ReportProcessTimedOut failed, hr=%x\n", hr);
116 | }
117 | }
118 |
119 | void CPMIExitModuleEventSource::ReportProcessStartSucceeded(
120 | LPCWSTR pwszExePath,
121 | LPCWSTR pwszCmdLine,
122 | DWORD dwProcessID,
123 | DWORD dwThreadID) const
124 | {
125 | CStringEventArg argExePath(pwszExePath);
126 | CStringEventArg argCmdLine(pwszCmdLine);
127 | CNumericEventArg argProcessID(dwProcessID);
128 | CNumericEventArg argThreadID(dwThreadID);
129 |
130 | CEventArg* rgArgs[] =
131 | {
132 | &argExePath,
133 | &argCmdLine,
134 | &argProcessID,
135 | &argThreadID,
136 | };
137 |
138 | CRefBuffer bufArgs(rgArgs, sizeof(rgArgs) / sizeof(rgArgs[0]));
139 | HRESULT hr = ReportEvent(
140 | EVENTLOG_INFORMATION_TYPE,
141 | GENERAL_CATEGORY,
142 | MSG_PROCESS_START_SUCCEEDED,
143 | bufArgs,
144 | CRefBuffer());
145 | if (FAILED(hr))
146 | {
147 | ATLTRACE(L"ReportProcessStartSucceeded failed, hr=%x\n", hr);
148 | }
149 | }
150 |
151 | void CPMIExitModuleEventSource::ReportProcessStartFailed(
152 | LPCWSTR pwszExePath,
153 | LPCWSTR pwszCmdLine,
154 | HRESULT hrError) const
155 | {
156 | CStringEventArg argExePath(pwszExePath);
157 | CStringEventArg argCmdLine(pwszCmdLine);
158 | CNumericEventArg argError(hrError);
159 | CErrorMessageEventArg argErrorMessage(hrError);
160 |
161 | CEventArg* rgArgs[] =
162 | {
163 | &argExePath,
164 | &argCmdLine,
165 | &argError,
166 | &argErrorMessage,
167 | };
168 |
169 | CRefBuffer bufArgs(rgArgs, sizeof(rgArgs) / sizeof(rgArgs[0]));
170 | HRESULT hr = ReportEvent(
171 | EVENTLOG_ERROR_TYPE,
172 | GENERAL_CATEGORY,
173 | MSG_PROCESS_START_FAILED,
174 | bufArgs,
175 | CRefBuffer());
176 | if (FAILED(hr))
177 | {
178 | ATLTRACE(L"ReportProcessStartFailed failed, hr=%x\n", hr);
179 | }
180 | }
181 |
182 | void CPMIExitModuleEventSource::ReportNotifyFailedInternalError(
183 | LONG lExitEvent,
184 | LONG lContext,
185 | HRESULT hrError) const
186 | {
187 | CNumericEventArg argExitEvent(lExitEvent);
188 | CNumericEventArg argContext(lContext);
189 | CNumericEventArg argError(hrError);
190 | CErrorMessageEventArg argErrorMessage(hrError);
191 |
192 | CEventArg* rgArgs[] =
193 | {
194 | &argExitEvent,
195 | &argContext,
196 | &argError,
197 | &argErrorMessage,
198 | };
199 |
200 | CRefBuffer bufArgs(rgArgs, sizeof(rgArgs) / sizeof(rgArgs[0]));
201 | HRESULT hr = ReportEvent(
202 | EVENTLOG_ERROR_TYPE,
203 | GENERAL_CATEGORY,
204 | MSG_NOTIFY_FAILED,
205 | bufArgs,
206 | CRefBuffer());
207 | if (FAILED(hr))
208 | {
209 | ATLTRACE(L"ReportNotifyFailedInternalError failed, hr=%x\n", hr);
210 | }
211 | }
--------------------------------------------------------------------------------
/src/PKI/ExitModule/PMIExitModuleEventSource.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | /*++
3 |
4 | Copyright (C) Microsoft Corp. All rights reserved.
5 |
6 | File:
7 |
8 | PMIExitModuleEventSource.h
9 |
10 | Abstract:
11 |
12 | CPMIExitModuleEventSource class declaration.
13 |
14 | Authors:
15 |
16 | Jon Rowlett (jrowlett)
17 |
18 | History:
19 | 18-Apr-2023 jrowlett Created.
20 |
21 | --*/
22 |
23 | #include "EventSource.h"
24 |
25 | /*++
26 |
27 | Abstract:
28 |
29 | Event Source for this module.
30 |
31 | --*/
32 | class CPMIExitModuleEventSource : public CEventSource
33 | {
34 | public:
35 | inline CPMIExitModuleEventSource()
36 | : CEventSource(s_pwszProviderName)
37 | {
38 | }
39 |
40 | inline ~CPMIExitModuleEventSource()
41 | {
42 | }
43 |
44 | /*++
45 |
46 | Abstract:
47 |
48 | Reports a message with text similar to:
49 | The process [%1] with main thread id [%2] succeeded with exit code [%3].
50 |
51 | Parameters:
52 |
53 | dwProcessID - process ID.
54 | dwThreadID - main thread ID.
55 | dwExitCode - exit code from the process.
56 |
57 | --*/
58 | void ReportProcessSucceeded(
59 | DWORD dwProcessID,
60 | DWORD dwThreadID,
61 | DWORD dwExitCode) const;
62 |
63 | /*++
64 |
65 | Abstract:
66 |
67 | Reports a message with text similar to:
68 | The process [%1] with main thread id [%2] failed with exit code [%3]. The temp file [%4] will be preserved for debugging.
69 |
70 | Parameters:
71 |
72 | dwProcessID - process id.
73 | dwThreadID - thread id.
74 | dwExitCode - process exit code.
75 | pwszTempFilePath - path to the temp file that will not be deleted.
76 |
77 | --*/
78 | void ReportProcessFailed(
79 | DWORD dwProcessID,
80 | DWORD dwThreadID,
81 | DWORD dwExitCode,
82 | LPCWSTR pwszTempFilePath) const;
83 |
84 | /*++
85 |
86 | Abstract:
87 |
88 | Reports a message with text similar to:
89 | Timed out waiting %1 seconds for process [%2] with main thread id [%3]. The process was not killed and could still be running. The temp file [%4] will be preserved for debugging.
90 |
91 | Parameters:
92 |
93 | dwSeconds - the timeout in seconds.
94 | dwProcessID - the process id.
95 | dwThreadID - the thread id.
96 | pwszTempFilePath - path to the temp file that will not get deleted.
97 |
98 | --*/
99 | void ReportProcessTimedOut(
100 | DWORD dwSeconds,
101 | DWORD dwProcessID,
102 | DWORD dwThreadID,
103 | LPCWSTR pwszTempFilePath) const;
104 |
105 | /*++
106 |
107 | Abstract:
108 |
109 | Reports a message with text similar to:
110 | Started process [%1] with the following command line [%2]. Process ID=[%3]. Thread ID=[%4].
111 |
112 | Parameters:
113 |
114 | pwszExePath - path to the exe that was started.
115 | pwszCmdLine - full command line.
116 | dwProcessID - process ID of the started process.
117 | dwThreadID - main thread ID of the started process.
118 |
119 | --*/
120 | void ReportProcessStartSucceeded(
121 | LPCWSTR pwszExePath,
122 | LPCWSTR pwszCmdLine,
123 | DWORD dwProcessID,
124 | DWORD dwThreadID) const;
125 |
126 | /*++
127 |
128 | Abstract:
129 |
130 | Reports a message with text similar to:
131 | Failed to start process [%1] with the following command line [%2]. HRESULT=%3. %4
132 |
133 | Parameters:
134 |
135 | pwszExePath - Path to the exe that was attempted.
136 | pwszCmdLine - full command line.
137 | hrError - error code.
138 |
139 | Remarks:
140 |
141 | The last message string is the error message text for the given HRESULT.
142 | --*/
143 | void ReportProcessStartFailed(
144 | LPCWSTR pwszExePath,
145 | LPCWSTR pwszCmdLine,
146 | HRESULT hrError) const;
147 |
148 | /*++
149 |
150 | Abstract:
151 |
152 | Reports a message with text similar to:
153 | Internal error. Use internal tracing to capture more info and open an incident. ICertExit::Notify(). ExitEvent=%1, Context=%2. HRESULT=%3. %4
154 |
155 | Parameters:
156 |
157 | lExitEvent - the exit event argument passed to Notify.
158 | lContext - the context argument passed to Notify.
159 | hrError - the internal error code.
160 |
161 | --*/
162 | void ReportNotifyFailedInternalError(
163 | LONG lExitEvent,
164 | LONG lContext,
165 | HRESULT hrError) const;
166 |
167 | private:
168 | static const LPCWSTR s_pwszProviderName;
169 | };
170 |
171 |
--------------------------------------------------------------------------------
/src/PKI/ExitModule/Process.cpp:
--------------------------------------------------------------------------------
1 | /*++
2 |
3 | Copyright (C) Microsoft Corp. All rights reserved.
4 |
5 | File:
6 |
7 | Process.cpp
8 |
9 | Abstract:
10 |
11 | CProcess class declaration.
12 |
13 | Authors:
14 |
15 | Jon Rowlett (jrowlett)
16 |
17 | History:
18 | 11-Apr-2023 jrowlett Created.
19 |
20 | --*/
21 | #include "pch.h"
22 | #include "Process.h"
23 |
24 | constexpr const size_t g_cchMaxCommandLine = 32768;
25 |
26 | CProcess::CProcess()
27 | {
28 | ZeroMemory(&m_stProcInfo, sizeof(m_stProcInfo));
29 | m_stProcInfo.hProcess = INVALID_HANDLE_VALUE;
30 | m_stProcInfo.hThread = INVALID_HANDLE_VALUE;
31 | }
32 |
33 | CProcess::~CProcess()
34 | {
35 | if (m_stProcInfo.hProcess != INVALID_HANDLE_VALUE)
36 | {
37 | ::CloseHandle(m_stProcInfo.hProcess);
38 | }
39 |
40 | if (m_stProcInfo.hThread != INVALID_HANDLE_VALUE)
41 | {
42 | ::CloseHandle(m_stProcInfo.hThread);
43 | }
44 | }
45 |
46 | HRESULT CProcess::Create(
47 | LPCWSTR pwszApplicationName,
48 | const CBuffer& bufArguments,
49 | DWORD dwCreationFlags)
50 | {
51 | HRESULT hr = S_OK;
52 | STARTUPINFOW stStartupInfo;
53 | ZeroMemory(&stStartupInfo, sizeof(stStartupInfo));
54 | stStartupInfo.cb = sizeof(PROCESS_INFORMATION);
55 |
56 | if (m_stProcInfo.hProcess != INVALID_HANDLE_VALUE)
57 | {
58 | ATLTRACE(L"Process already created, hProcess=%p\n", m_stProcInfo.hProcess);
59 | return HRESULT_FROM_WIN32(ERROR_INVALID_OPERATION);
60 | }
61 |
62 | if (!m_bufCmdLine.Alloc(g_cchMaxCommandLine))
63 | {
64 | ATLTRACE(L"Failed to alloc buffer for command line.\n");
65 | return E_OUTOFMEMORY;
66 | }
67 |
68 | hr = FormatCommandLine(
69 | pwszApplicationName,
70 | bufArguments,
71 | OUT m_bufCmdLine);
72 | if (FAILED(hr))
73 | {
74 | ATLTRACE("CProcess::FormatCommandLine failed, hr=%x\n", hr);
75 | return hr;
76 | }
77 |
78 | ATLTRACE(
79 | L"Launching [%s] with [%s] command line.\n",
80 | pwszApplicationName,
81 | m_bufCmdLine.Get());
82 | if (!CreateProcessW(
83 | NULL, // lpApplicationName
84 | m_bufCmdLine.Get(), // lpCommandLine
85 | NULL, // lpProcessAttributes
86 | NULL, // lpThreadAttributes
87 | FALSE, // bInheritHandles
88 | dwCreationFlags, // dwCreationFlags
89 | NULL, // lpEnvironment
90 | NULL, // lpCurrentDirectory
91 | &stStartupInfo, // lpStartupInfo
92 | &m_stProcInfo)) // lpProcessInformation
93 | {
94 | hr = HRESULT_FROM_WIN32(::GetLastError());
95 | ATLTRACE(L"CreateProcessW failed, hr=%x\n", hr);
96 | return hr;
97 | }
98 |
99 | ATLTRACE(
100 | L"Process created. ProcessID=%d, ThreadID=%d\n",
101 | m_stProcInfo.dwProcessId,
102 | m_stProcInfo.dwThreadId);
103 |
104 | return hr;
105 | }
106 |
107 | HRESULT CProcess::Wait(
108 | DWORD dwMilliseconds)
109 | {
110 | DWORD dwRes = ::WaitForSingleObject(
111 | m_stProcInfo.hProcess,
112 | dwMilliseconds);
113 | switch (dwRes)
114 | {
115 | case WAIT_OBJECT_0:
116 | return S_OK;
117 | case WAIT_ABANDONED:
118 | return E_ABORT;
119 | case WAIT_TIMEOUT:
120 | return HRESULT_FROM_WIN32(ERROR_TIMEOUT);
121 | case WAIT_FAILED:
122 | return HRESULT_FROM_WIN32(::GetLastError());
123 | }
124 |
125 | return E_UNEXPECTED;
126 | }
127 |
128 | HRESULT CProcess::GetExitCode(
129 | OUT DWORD& dwExitCode)
130 | {
131 | if (!::GetExitCodeProcess(m_stProcInfo.hProcess, &dwExitCode))
132 | {
133 | return HRESULT_FROM_WIN32(::GetLastError());
134 | }
135 |
136 | return S_OK;
137 | }
138 |
139 | HRESULT CProcess::FormatCommandLine(
140 | LPCWSTR pwszApplicationName,
141 | const CBuffer& bufArgs,
142 | OUT CBuffer& bufResult)
143 | {
144 | HRESULT hr = S_OK;
145 | LPWSTR pwszCurrent = bufResult.Get();
146 | size_t cchMax = bufResult.GetLength();
147 |
148 | hr = WriteArgument(
149 | pwszCurrent,
150 | cchMax,
151 | pwszApplicationName);
152 | if (FAILED(hr))
153 | {
154 | return hr;
155 | }
156 |
157 | // NOTE: Not using StringCchCat* because it repeats evaluation of string lengths.
158 | for (const LPCWSTR* p = bufArgs.Get();
159 | p != bufArgs.Get() + bufArgs.GetLength();
160 | p++)
161 | {
162 | LPCWSTR pwszArg = *p;
163 |
164 | // Add argument separator.
165 | hr = ::StringCchCopyExW(
166 | pwszCurrent,
167 | cchMax,
168 | L" ",
169 | &pwszCurrent,
170 | &cchMax,
171 | STRSAFE_IGNORE_NULLS);
172 | if (FAILED(hr))
173 | {
174 | break;
175 | }
176 |
177 | hr = WriteArgument(pwszCurrent, cchMax, pwszArg);
178 | if (FAILED(hr))
179 | {
180 | break;
181 | }
182 | }
183 |
184 | return S_OK;
185 | }
186 |
187 | bool CProcess::HasWhiteSpace(LPCWSTR pwsz)
188 | {
189 | for (const WCHAR* p = pwsz;
190 | *p;
191 | p++)
192 | {
193 | if (*p == L' ')
194 | {
195 | return true;
196 | }
197 | }
198 |
199 | return false;
200 | }
201 |
202 | HRESULT CProcess::WriteArgument(
203 | LPWSTR& pwszCurrent,
204 | size_t& cchMax,
205 | LPCWSTR pwszArg)
206 | {
207 | // NOTE: This isn't full feastured argument escaping.
208 | // It handles the current use case of embedded spaces.
209 | // It does not handle embedded quotes.
210 | bool fEscape = HasWhiteSpace(pwszArg);
211 | HRESULT hr = S_OK;
212 |
213 | do
214 | {
215 | if (fEscape)
216 | {
217 | hr = ::StringCchCopyExW(
218 | pwszCurrent,
219 | cchMax,
220 | L"\"",
221 | &pwszCurrent,
222 | &cchMax,
223 | STRSAFE_IGNORE_NULLS);
224 | if (FAILED(hr))
225 | {
226 | break;
227 | }
228 | }
229 |
230 | hr = ::StringCchCopyExW(
231 | pwszCurrent,
232 | cchMax,
233 | pwszArg,
234 | &pwszCurrent,
235 | &cchMax,
236 | STRSAFE_IGNORE_NULLS);
237 | if (FAILED(hr))
238 | {
239 | break;
240 | }
241 |
242 | if (fEscape)
243 | {
244 | hr = ::StringCchCopyExW(
245 | pwszCurrent,
246 | cchMax,
247 | L"\"",
248 | &pwszCurrent,
249 | &cchMax,
250 | STRSAFE_IGNORE_NULLS);
251 | if (FAILED(hr))
252 | {
253 | break;
254 | }
255 | }
256 | } while (false);
257 |
258 | return hr;
259 | }
--------------------------------------------------------------------------------
/src/PKI/ExitModule/Process.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | /*++
3 |
4 | Copyright (C) Microsoft Corp. All rights reserved.
5 |
6 | File:
7 |
8 | Process.h
9 |
10 | Abstract:
11 |
12 | CProcess class declaration.
13 |
14 | Authors:
15 |
16 | Jon Rowlett (jrowlett)
17 |
18 | History:
19 | 11-Apr-2023 jrowlett Created.
20 |
21 | --*/
22 |
23 | /*++
24 |
25 | Abstract:
26 |
27 | Win32 Process wrapper.
28 | --*/
29 | class CProcess
30 | {
31 | public:
32 | CProcess();
33 | ~CProcess();
34 |
35 | /*++
36 |
37 | Abstract:
38 |
39 | Gets the process ID.
40 |
41 | Returns:
42 |
43 | the process id.
44 | --*/
45 | inline DWORD GetProcessID() const
46 | {
47 | return m_stProcInfo.dwProcessId;
48 | }
49 |
50 | /*++
51 |
52 | Abstract:
53 |
54 | Gets the thread ID.
55 |
56 | Returns:
57 |
58 | the thread id.
59 | --*/
60 | inline DWORD GetThreadID() const
61 | {
62 | return m_stProcInfo.dwThreadId;
63 | }
64 |
65 | /*++
66 |
67 | Abstract:
68 |
69 | Gets the full command line including the application.
70 |
71 | Returns:
72 |
73 | The formatted command line after a call to Create.
74 |
75 | --*/
76 | inline LPCWSTR GetCommandLine() const
77 | {
78 | return m_bufCmdLine.Get();
79 | }
80 |
81 | /*++
82 |
83 | Abstract:
84 |
85 | Creates the process.
86 |
87 | Parameters:
88 |
89 | pwszApplicationName - path to exe.
90 | bufArguments - array of args.
91 | dwCreationFlags - flags to pass to CreateProcessW.
92 |
93 | Returns:
94 |
95 | S_OK - success.
96 | other - error code.
97 | --*/
98 | HRESULT Create(
99 | LPCWSTR pwszApplicationName,
100 | const CBuffer& bufArguments,
101 | DWORD dwCreationFlags);
102 |
103 | /*++
104 |
105 | Abstract:
106 |
107 | Waits for the process to exit.
108 |
109 | Parameters:
110 |
111 | dwMilliseconds - the number of milliseconds to wait.
112 |
113 | Returns:
114 |
115 | S_OK - the process exited.
116 | E_ABANDONED - The wait was abandoned.
117 | E_TIMEOUT - the wait timed out.
118 | Other - error code.
119 | --*/
120 | HRESULT Wait(
121 | DWORD dwMilliseconds);
122 |
123 | /*++
124 |
125 | Abstract:
126 |
127 | Gets the exit code from the process.
128 |
129 | Parameters:
130 |
131 | dwExitCode - on success, receives the exit code.
132 |
133 | Returns:
134 |
135 | S_OK - success.
136 | Other - error code.
137 | --*/
138 | HRESULT GetExitCode(
139 | OUT DWORD& dwExitCode);
140 |
141 | private:
142 | PROCESS_INFORMATION m_stProcInfo;
143 | CHeapBuffer m_bufCmdLine;
144 |
145 | static HRESULT FormatCommandLine(
146 | LPCWSTR pwszApplicationName,
147 | const CBuffer& args,
148 | OUT CBuffer& bufResult);
149 |
150 | static bool HasWhiteSpace(LPCWSTR pwsz);
151 | static HRESULT WriteArgument(
152 | LPWSTR& pwszCurrent,
153 | size_t& cchMax,
154 | LPCWSTR pwszArg);
155 |
156 | CProcess(const CProcess&) = delete;
157 | CProcess& operator=(const CProcess&) = delete;
158 | };
159 |
160 |
--------------------------------------------------------------------------------
/src/PKI/ExitModule/ResourceStringManageProperty.cpp:
--------------------------------------------------------------------------------
1 | /*++
2 |
3 | Copyright (C) Microsoft Corp. All rights reserved.
4 |
5 | Abstract:
6 |
7 | Definition of properties used by CPMIExitModule.
8 |
9 | --*/
10 |
11 | #include "pch.h"
12 | #include "ResourceStringManageProperty.h"
13 | #include "PMIExitModule.h"
14 |
15 | /*++
16 | Gets the value of the property.
17 |
18 | Parameters:
19 | rvarResult - reference to the variant to receive the value.
20 |
21 | Returns:
22 | S_OK - success
23 | Other - error code.
24 | --*/
25 | HRESULT CResourceStringManageProperty::GetValue(VARIANT& rvarResult) const
26 | {
27 | CStaticBuffer wszBuffer;
28 | int cch = ::LoadStringW(
29 | _AtlBaseModule.GetModuleInstance(),
30 | m_nResID,
31 | wszBuffer.Get(),
32 | (int)wszBuffer.GetLength());
33 | if (!cch)
34 | {
35 | int nStatus = ::GetLastError();
36 | return HRESULT_FROM_WIN32(nStatus);
37 | }
38 |
39 | BSTR bstrResult = ::SysAllocString(wszBuffer.Get());
40 | if (!bstrResult)
41 | {
42 | return E_OUTOFMEMORY;
43 | }
44 |
45 | rvarResult.bstrVal = bstrResult;
46 | rvarResult.vt = VT_BSTR;
47 | return S_OK;
48 | }
--------------------------------------------------------------------------------
/src/PKI/ExitModule/ResourceStringManageProperty.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | /*++
3 |
4 | Copyright (C) Microsoft Corp. All rights reserved.
5 |
6 | Abstract:
7 |
8 | Definition of properties used by CPMIExitModule.
9 |
10 | --*/
11 | #include "ManageProperty.h"
12 |
13 | /*++
14 |
15 | Abstract:
16 |
17 | A string property that gets loaded from the string table.
18 | --*/
19 | class CResourceStringManageProperty :
20 | public CManageProperty
21 | {
22 | public:
23 | /*++
24 | Abstract:
25 |
26 | Initializes a new instance of the CManageProperty class.
27 |
28 | Parameters:
29 | pwszName - static string for the property name.
30 | nResID - resource id of the string.
31 |
32 | --*/
33 | CResourceStringManageProperty(LPCWSTR pwszName, int nResID)
34 | : CManageProperty(pwszName), m_nResID(nResID)
35 | {
36 | }
37 |
38 | /*++
39 | Gets the value of the property.
40 |
41 | Parameters:
42 | rvarResult - reference to the variant to receive the value.
43 |
44 | Returns:
45 | S_OK - success
46 | Other - error code.
47 | --*/
48 | virtual HRESULT GetValue(VARIANT& rvarResult) const;
49 |
50 | private:
51 | int m_nResID;
52 | };
53 |
54 |
--------------------------------------------------------------------------------
/src/PKI/ExitModule/TempFile.cpp:
--------------------------------------------------------------------------------
1 | /*++
2 |
3 | Copyright (C) Microsoft Corp. All rights reserved.
4 |
5 | File:
6 |
7 | TempFile.cpp
8 |
9 | Abstract:
10 |
11 | CTempFile class implementation.
12 |
13 | Authors:
14 |
15 | Jon Rowlett (jrowlett)
16 |
17 | History:
18 | 11-Apr-2023 jrowlett Created.
19 |
20 | --*/
21 | #include "pch.h"
22 | #include "TempFile.h"
23 |
24 | CTempFile::~CTempFile()
25 | {
26 | Close();
27 | if (!m_fPreserve)
28 | {
29 | if (m_strPath.GetLength() > 0)
30 | {
31 | if (!::DeleteFileW(m_strPath.Get()))
32 | {
33 | HRESULT hr = HRESULT_FROM_WIN32(::GetLastError());
34 | ATLTRACE(
35 | L"Failed to delete temp file [%s], hr=%x\n",
36 | m_strPath.Get(),
37 | hr);
38 | }
39 | }
40 | }
41 | else
42 | {
43 | ATLTRACE(L"Preserving temp file [%s] for debugging.\n", m_strPath.Get());
44 | }
45 | }
46 |
47 | HRESULT CTempFile::Create(LPCWSTR pwszPath)
48 | {
49 | if (m_strPath.GetLength() > 0)
50 | {
51 | ATLTRACE(L"The temp file has been previously initialized.\n");
52 | return HRESULT_FROM_WIN32(ERROR_INVALID_OPERATION);
53 | }
54 |
55 | Close();
56 | size_t cch = 0;
57 | HRESULT hr = ::StringCchLengthW(pwszPath, MAX_PATH + 1, &cch);
58 | if (FAILED(hr))
59 | {
60 | ATLTRACE(L"::StringCchLengthW failed, hr=%x\n", hr);
61 | return hr;
62 | }
63 |
64 | if (!m_strPath.Alloc(cch + 1))
65 | {
66 | ATLTRACE(L"Failed to alloc %d+1 wchars\n", cch);
67 | hr = E_OUTOFMEMORY;
68 | return hr;
69 | }
70 |
71 | hr = ::StringCchCopyW(m_strPath.Get(), m_strPath.GetLength(), pwszPath);
72 | if (FAILED(hr))
73 | {
74 | ATLTRACE(L":StringCchCopyW failed, hr=%x\n", hr);
75 | return hr;
76 | }
77 |
78 | //
79 | // NOTE: The Win32 APIs to get the temp file name already create the file,
80 | // so always recreate the file in this step.
81 | //
82 | m_hFile = ::CreateFileW(
83 | pwszPath,
84 | GENERIC_WRITE,
85 | 0, // dwShareMode
86 | NULL, // lpSecurityAttributes
87 | CREATE_ALWAYS,
88 | FILE_ATTRIBUTE_NORMAL,
89 | NULL); // hTemplateFile
90 | if (m_hFile == INVALID_HANDLE_VALUE)
91 | {
92 | hr = HRESULT_FROM_WIN32(::GetLastError());
93 | ATLTRACE(L"::CreateFileW(%s) failed, hr=%x\n", pwszPath, hr);
94 | m_strPath.Clear();
95 | }
96 |
97 | return hr;
98 | }
99 |
100 | void CTempFile::Close()
101 | {
102 | if (m_hFile != INVALID_HANDLE_VALUE)
103 | {
104 | ::CloseHandle(m_hFile);
105 | m_hFile = INVALID_HANDLE_VALUE;
106 | }
107 | }
108 |
109 | void CTempFile::Preserve()
110 | {
111 | m_fPreserve = true;
112 | }
113 |
114 | HRESULT CTempFile::Write(
115 | const CBuffer& buf,
116 | size_t cbIndex,
117 | size_t cbCount,
118 | OUT size_t& cbWritten)
119 | {
120 | if (m_hFile == INVALID_HANDLE_VALUE)
121 | {
122 | ATLTRACE(L"File not open.");
123 | return HRESULT_FROM_WIN32(ERROR_INVALID_OPERATION);
124 | }
125 |
126 | DWORD nBytesWritten = 0;
127 | if (!::WriteFile(
128 | m_hFile,
129 | buf.Get() + cbIndex,
130 | (DWORD)cbCount,
131 | &nBytesWritten,
132 | NULL)) // lpOverlapped
133 | {
134 | HRESULT hr = HRESULT_FROM_WIN32(::GetLastError());
135 | ATLTRACE(L"::WriteFile failed, cbCount=%x, hr=%x\n", cbCount, hr);
136 | return hr;
137 | }
138 |
139 | cbWritten = nBytesWritten;
140 |
141 | return S_OK;
142 | }
--------------------------------------------------------------------------------
/src/PKI/ExitModule/TempFile.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | /*++
3 |
4 | Copyright (C) Microsoft Corp. All rights reserved.
5 |
6 | File:
7 |
8 | TempFile.h
9 |
10 | Abstract:
11 |
12 | CTempFile class declaration.
13 |
14 | Authors:
15 |
16 | Jon Rowlett (jrowlett)
17 |
18 | History:
19 | 11-Apr-2023 jrowlett Created.
20 |
21 | --*/
22 |
23 | /*++
24 |
25 | Abstract:
26 |
27 | Encapsulates access to a temp file that gets deleted on destruction.
28 | --*/
29 | class CTempFile
30 | {
31 | public:
32 | CTempFile()
33 | : m_hFile(INVALID_HANDLE_VALUE), m_fPreserve(false)
34 | {
35 | }
36 |
37 | ~CTempFile();
38 |
39 | /*++
40 |
41 | Abstract:
42 |
43 | Creates and opens the temp file.
44 |
45 | Parameters:
46 |
47 | pwszPath - path to the file.
48 |
49 | Returns:
50 |
51 | S_OK - success.
52 | other - error code.
53 | --*/
54 | HRESULT Create(LPCWSTR pwszPath);
55 |
56 | /*++
57 |
58 | Abstract:
59 |
60 | Closes the file, but does not delete it.
61 |
62 | --*/
63 | void Close();
64 |
65 | /*++
66 |
67 | Abstract:
68 |
69 | Prevents the file from getting deleted in the destructor.
70 |
71 | --*/
72 | void Preserve();
73 |
74 | /*++
75 |
76 | Abstract:
77 |
78 | Writes bytes to the file.
79 |
80 | Parameters:
81 |
82 | buf - the buffer to write.
83 | cbIndex - index into the buffer to start the write.
84 | cbCount - the number of bytes to write.
85 | cbWritten - on success, receives the number of bytes written.
86 |
87 | Returns:
88 |
89 | S_OK - success. check cbWritten to see if all the bytes have been written.
90 | other - error.
91 | --*/
92 | HRESULT Write(
93 | const CBuffer& buf,
94 | size_t cbIndex,
95 | size_t cbCount,
96 | OUT size_t& cbWritten);
97 |
98 | private:
99 | CHeapWString m_strPath;
100 | HANDLE m_hFile;
101 | bool m_fPreserve;
102 |
103 | CTempFile(const CTempFile&) = delete;
104 | CTempFile& operator=(const CTempFile&) = delete;
105 | };
106 |
107 |
--------------------------------------------------------------------------------
/src/PKI/ExitModule/dllmain.cpp:
--------------------------------------------------------------------------------
1 | // dllmain.cpp : Implementation of DllMain.
2 |
3 | #include "pch.h"
4 | #include "framework.h"
5 | #include "resource.h"
6 | #include "ExitModule_i.h"
7 | #include "dllmain.h"
8 |
9 | CExitModuleModule _Module;
10 |
11 | // DLL Entry Point
12 | extern "C" BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
13 | {
14 | hInstance;
15 | return _Module.DllMain(dwReason, lpReserved);
16 | }
17 |
--------------------------------------------------------------------------------
/src/PKI/ExitModule/dllmain.h:
--------------------------------------------------------------------------------
1 | // dllmain.h : Declaration of module class.
2 |
3 | class CExitModuleModule : public ATL::CAtlDllModuleT< CExitModuleModule >
4 | {
5 | public :
6 | DECLARE_LIBID(LIBID_ExitModuleLib)
7 | DECLARE_REGISTRY_APPID_RESOURCEID(IDR_EXITMODULE, "{03c5878a-932c-4063-b21a-5f89f579194f}")
8 | };
9 |
10 | extern class CExitModuleModule _Module;
11 |
--------------------------------------------------------------------------------
/src/PKI/ExitModule/framework.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #ifndef STRICT
4 | #define STRICT
5 | #endif
6 |
7 | #include "targetver.h"
8 |
9 | #define _ATL_APARTMENT_THREADED
10 |
11 | #define _ATL_NO_AUTOMATIC_NAMESPACE
12 |
13 | #define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // some CString constructors will be explicit
14 |
15 |
16 | #define ATL_NO_ASSERT_ON_DESTROY_NONEXISTENT_WINDOW
17 |
18 | #include "resource.h"
19 | #include
20 | #include
21 | #include
22 |
--------------------------------------------------------------------------------
/src/PKI/ExitModule/pch.cpp:
--------------------------------------------------------------------------------
1 | // pch.cpp: source file corresponding to the pre-compiled header
2 |
3 | #include "pch.h"
4 |
5 | // When you are using pre-compiled headers, this source file is necessary for compilation to succeed.
6 |
--------------------------------------------------------------------------------
/src/PKI/ExitModule/pch.h:
--------------------------------------------------------------------------------
1 | // pch.h: This is a precompiled header file.
2 | // Files listed below are compiled only once, improving build performance for future builds.
3 | // This also affects IntelliSense performance, including code completion and many code browsing features.
4 | // However, files listed here are ALL re-compiled if any one of them is updated between builds.
5 | // Do not add files here that you will be updating frequently as this negates the performance advantage.
6 |
7 | #ifndef PCH_H
8 | #define PCH_H
9 |
10 | #define _ATL_STATIC_REGISTRY
11 |
12 | // add headers that you want to pre-compile here
13 | #include "framework.h"
14 | #include
15 | #include
16 | #include "Buffer.h"
17 |
18 | #endif //PCH_H
19 |
--------------------------------------------------------------------------------
/src/PKI/ExitModule/resource.h:
--------------------------------------------------------------------------------
1 | //{{NO_DEPENDENCIES}}
2 | // Microsoft Visual C++ generated include file.
3 | // Used by ExitModule.rc
4 | //
5 | #define IDS_PROJNAME 100
6 | #define IDR_EXITMODULE 101
7 | #define IDS_PMIEXITMODULE_DESC 101
8 | #define IDS_PMIEXITMODULE_NAME 102
9 | #define IDS_PMIEXITMODULE_COPYRIGHT 103
10 | #define IDS_PMIEXITMODULE_FILEVER 104
11 | #define IDS_PMIEXITMODULE_PRODUCTVER 105
12 | #define IDR_PMIEXITMODULE 106
13 | #define IDR_PMICERTEXIT 107
14 |
15 | // Next default values for new objects
16 | //
17 | #ifdef APSTUDIO_INVOKED
18 | #ifndef APSTUDIO_READONLY_SYMBOLS
19 | #define _APS_NEXT_RESOURCE_VALUE 201
20 | #define _APS_NEXT_COMMAND_VALUE 32768
21 | #define _APS_NEXT_CONTROL_VALUE 201
22 | #define _APS_NEXT_SYMED_VALUE 108
23 | #endif
24 | #endif
25 |
--------------------------------------------------------------------------------
/src/PKI/ExitModule/targetver.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | // Including SDKDDKVer.h defines the highest available Windows platform.
4 |
5 | // If you wish to build your application for a previous Windows platform, include WinSDKVer.h and
6 | // set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h.
7 |
8 | #include
9 |
--------------------------------------------------------------------------------
/src/PKI/ExitModuleEventLog.reg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/adcs-proxy-exit-module/1e34447acb234504d641c09a48fbb1c278ff7acd/src/PKI/ExitModuleEventLog.reg
--------------------------------------------------------------------------------
/src/PKI/ExitModuleExe.reg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/microsoft/adcs-proxy-exit-module/1e34447acb234504d641c09a48fbb1c278ff7acd/src/PKI/ExitModuleExe.reg
--------------------------------------------------------------------------------
/src/PKI/FailedScript.ps1:
--------------------------------------------------------------------------------
1 | param (
2 | [Parameter(Mandatory=$true)]
3 | [string]$Operation,
4 |
5 | [Parameter(Mandatory=$false)]
6 | [string]$SubjectKeyIdentifier,
7 |
8 | [Parameter(Mandatory=$false)]
9 | [string]$SerialNumber,
10 |
11 | [Parameter(Mandatory=$true)]
12 | [string]$RawCertPath
13 | )
14 |
15 | # Cause PS to exit with an error code.
16 | throw "Script Failed."
17 |
18 | if ($Operation -eq 'certissued') {
19 | $cert = [System.Security.Cryptography.X509Certificates.X509Certificate2]::new($RawCertPath)
20 | $cert | fl > "$RawCertPath.txt"
21 | }
--------------------------------------------------------------------------------
/src/PKI/PMIExitModuleMessages/PMIExitModuleEventSourceDef.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | /*++
3 |
4 | Copyright (C) Microsoft Corp. All rights reserved.
5 |
6 | File:
7 |
8 | PMIEditModuleEventSourceDef.h
9 |
10 | Abstract:
11 |
12 | Common defines for the event source used by multiple modules.
13 |
14 | Authors:
15 |
16 | Jon Rowlett (jrowlett)
17 |
18 | History:
19 | 24-Apr-2023 jrowlett Created.
20 |
21 | --*/
22 |
23 | #define WSZ_PMIEXITMODULE_PROVIDERNAME L"PMIExitModule"
24 | #define PMI_EXITMODULE_CATEGORYCOUNT 1
25 | #define PMI_EXITMODULE_PARAMETERCOUNT 0
26 |
--------------------------------------------------------------------------------
/src/PKI/PMIExitModuleMessages/PMIExitModuleMessages.mc:
--------------------------------------------------------------------------------
1 | ; // PMIExitModule.mc
2 | ; // Copyright (C) Microsoft Corp. All rights reserved.
3 |
4 |
5 | SeverityNames=(Success=0x0:STATUS_SEVERITY_SUCCESS
6 | Informational=0x1:STATUS_SEVERITY_INFORMATIONAL
7 | Warning=0x2:STATUS_SEVERITY_WARNING
8 | Error=0x3:STATUS_SEVERITY_ERROR
9 | )
10 |
11 |
12 | FacilityNames=(System=0x0:FACILITY_SYSTEM
13 | Runtime=0x2:FACILITY_RUNTIME
14 | Stubs=0x3:FACILITY_STUBS
15 | Io=0x4:FACILITY_IO_ERROR_CODE
16 | )
17 |
18 | LanguageNames=(English=0x409:MSG00409)
19 |
20 | ; // The following are the categories of events.
21 |
22 | MessageIdTypedef=WORD
23 |
24 | MessageId=0x1
25 | SymbolicName=GENERAL_CATEGORY
26 | Language=English
27 | General
28 | .
29 |
30 | ; // The following are the message definitions.
31 |
32 | MessageIdTypedef=DWORD
33 |
34 | MessageId=0x100
35 | Severity=Informational
36 | Facility=System
37 | SymbolicName=MSG_PROCESS_SUCCEEDED
38 | Language=English
39 | The process [%1] with main thread id [%2] succeeded with exit code [%3].
40 | .
41 |
42 | MessageId=0x101
43 | Severity=Error
44 | Facility=System
45 | SymbolicName=MSG_PROCESS_FAILED
46 | Language=English
47 | The process [%1] with main thread id [%2] failed with exit code [%3]. The temp file [%4] will be preserved for debugging.
48 | .
49 |
50 | MessageId=0x102
51 | Severity=Warning
52 | Facility=System
53 | SymbolicName=MSG_PROCESS_TIMEDOUT
54 | Language=English
55 | Timed out waiting %1 seconds for process [%2] with main thread id [%3]. The process was not killed and could still be running. The temp file [%4] will be preserved for debugging.
56 | .
57 |
58 | MessageId=0x103
59 | Severity=Informational
60 | Facility=System
61 | SymbolicName=MSG_PROCESS_START_SUCCEEDED
62 | Language=English
63 | Started process [%1] with the following command line [%2]. Process ID=[%3]. Thread ID=[%4].
64 | .
65 |
66 | MessageId=0x104
67 | Severity=Error
68 | Facility=System
69 | SymbolicName=MSG_PROCESS_START_FAILED
70 | Language=English
71 | Failed to start process [%1] with the following command line [%2]. HRESULT=%3. %4
72 | .
73 |
74 | MessageId=0x105
75 | Severity=Error
76 | Facility=System
77 | SymbolicName=MSG_NOTIFY_FAILED
78 | Language=English
79 | Internal error. Use internal tracing to capture more info and open a bug. ICertExit::Notify(). ExitEvent=%1, Context=%2. HRESULT=%3. %4
80 | .
81 |
--------------------------------------------------------------------------------
/src/PKI/PMIExitModuleMessages/dllmain.cpp:
--------------------------------------------------------------------------------
1 | // dllmain.cpp : Defines the entry point for the DLL application.
2 | #include "pch.h"
3 |
4 | BOOL APIENTRY DllMain( HMODULE hModule,
5 | DWORD ul_reason_for_call,
6 | LPVOID lpReserved
7 | )
8 | {
9 | switch (ul_reason_for_call)
10 | {
11 | case DLL_PROCESS_ATTACH:
12 | case DLL_THREAD_ATTACH:
13 | case DLL_THREAD_DETACH:
14 | case DLL_PROCESS_DETACH:
15 | break;
16 | }
17 | return TRUE;
18 | }
19 |
20 |
--------------------------------------------------------------------------------
/src/PKI/PMIExitModuleMessages/framework.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
4 | // Windows Header Files
5 | #include
6 |
--------------------------------------------------------------------------------
/src/PKI/PMIExitModuleMessages/pch.cpp:
--------------------------------------------------------------------------------
1 | // pch.cpp: source file corresponding to the pre-compiled header
2 |
3 | #include "pch.h"
4 |
5 | // When you are using pre-compiled headers, this source file is necessary for compilation to succeed.
6 |
--------------------------------------------------------------------------------
/src/PKI/PMIExitModuleMessages/pch.h:
--------------------------------------------------------------------------------
1 | // pch.h: This is a precompiled header file.
2 | // Files listed below are compiled only once, improving build performance for future builds.
3 | // This also affects IntelliSense performance, including code completion and many code browsing features.
4 | // However, files listed here are ALL re-compiled if any one of them is updated between builds.
5 | // Do not add files here that you will be updating frequently as this negates the performance advantage.
6 |
7 | #ifndef PCH_H
8 | #define PCH_H
9 |
10 | // add headers that you want to pre-compile here
11 | #include "framework.h"
12 |
13 | #endif //PCH_H
14 |
--------------------------------------------------------------------------------
/src/PKI/PMIExitModuleMessagesSetup/Arguments.cpp:
--------------------------------------------------------------------------------
1 | /*++
2 |
3 | Copyright (C) Microsoft Corp. All rights reserved.
4 |
5 | File:
6 |
7 | Arguments.cpp
8 |
9 | Abstract:
10 |
11 | CArguments class impl.
12 |
13 | Authors:
14 |
15 | Jon Rowlett (jrowlett)
16 |
17 | History:
18 | 24-Apr-2023 jrowlett Created.
19 |
20 | --*/
21 | #include "Arguments.h"
22 |
23 | CArguments::CArguments()
24 | : m_eOperation(Operation::INSTALL)
25 | {
26 | }
27 |
28 | CArguments::~CArguments()
29 | {
30 | }
31 |
32 | bool CArguments::TryParse(
33 | int argc,
34 | const wchar_t* argv[])
35 | {
36 | int i = 1;
37 | const wchar_t* pArg = nullptr;
38 | if (i < argc)
39 | {
40 | pArg = argv[i];
41 | if (pArg[0] && pArg[0] == L'/')
42 | {
43 | if (wcscmp(pArg, L"/i") == 0)
44 | {
45 | m_eOperation = Operation::INSTALL;
46 | }
47 | else if (wcscmp(pArg, L"/u") == 0)
48 | {
49 | m_eOperation = Operation::UINSTALL;
50 | }
51 | else
52 | {
53 | return false;
54 | }
55 | }
56 |
57 | i++;
58 | }
59 |
60 | if (i < argc)
61 | {
62 | m_strPath = argv[i];
63 | if (m_eOperation != Operation::INSTALL)
64 | {
65 | return false;
66 | }
67 |
68 | i++;
69 | }
70 |
71 | if (i != argc)
72 | {
73 | // Extra args.
74 | return false;
75 | }
76 |
77 | return true;
78 | }
--------------------------------------------------------------------------------
/src/PKI/PMIExitModuleMessagesSetup/Arguments.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | /*++
3 |
4 | Copyright (C) Microsoft Corp. All rights reserved.
5 |
6 | File:
7 |
8 | Arguments.h
9 |
10 | Abstract:
11 |
12 | CArguments class decl.
13 |
14 | Authors:
15 |
16 | Jon Rowlett (jrowlett)
17 |
18 | History:
19 | 24-Apr-2023 jrowlett Created.
20 |
21 | --*/
22 | #include
23 |
24 | /*++
25 |
26 | Abstract:
27 |
28 | The operation to perform.
29 |
30 | --*/
31 | enum Operation
32 | {
33 | INSTALL,
34 | UINSTALL
35 | };
36 |
37 | /*++
38 |
39 | Abstract:
40 |
41 | Parsed program arguments.
42 |
43 | --*/
44 | class CArguments
45 | {
46 | public:
47 | CArguments();
48 | ~CArguments();
49 |
50 | /*++
51 |
52 | Abstract:
53 |
54 | Tries to parse the arguments.
55 |
56 | Arguments:
57 |
58 | argc - count of program arguments.
59 | argv - array of program arguments.
60 |
61 | Returns:
62 |
63 | true - the arguments were parsed.
64 | false - the argument were invalid.
65 |
66 | --*/
67 | bool TryParse(int argc, const wchar_t* argv[]);
68 |
69 | inline Operation GetOperation() const
70 | {
71 | return m_eOperation;
72 | }
73 |
74 | inline const std::wstring& GetPath() const
75 | {
76 | return m_strPath;
77 | }
78 |
79 | private:
80 | Operation m_eOperation;
81 | std::wstring m_strPath;
82 | };
83 |
84 |
--------------------------------------------------------------------------------
/src/PKI/PMIExitModuleMessagesSetup/main.cpp:
--------------------------------------------------------------------------------
1 | /*++
2 |
3 | Copyright (C) Microsoft Corp. All rights reserved.
4 |
5 | File:
6 |
7 | main.cpp
8 |
9 | Abstract:
10 |
11 | Main entry point.
12 |
13 | Authors:
14 |
15 | Jon Rowlett (jrowlett)
16 |
17 | History:
18 | 24-Apr-2023 jrowlett Created.
19 |
20 | --*/
21 | #include
22 | #include "Arguments.h"
23 | #include
24 | #include
25 | #include
26 | #include "../PMIExitModuleMessages/PMIExitModuleEventSourceDef.h"
27 |
28 | #define APPLICATION_PATH L"SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application"
29 | constexpr const wchar_t* g_pwszMessageDLLName = L"PMIExitModuleMessages.dll";
30 | constexpr const wchar_t* g_pwszRegKeyPath = APPLICATION_PATH L"\\" WSZ_PMIEXITMODULE_PROVIDERNAME;
31 |
32 | void PrintUsage();
33 | bool InstallMessageDLL(const std::wstring& strPath);
34 | bool UninstallMessageDLL();
35 | bool FindMessageDLL(OUT std::wstring& strPath);
36 |
37 | /*++
38 |
39 | Abstract:
40 |
41 | Main entry point.
42 |
43 | Arguments:
44 |
45 | argc - count of program arguments.
46 | argv - array of program arguments.
47 |
48 | Returns:
49 |
50 | 0 - success.
51 | 1 - error.
52 |
53 | Remarks:
54 |
55 | Updates the registry to point to the message dll.
56 | Usage:
57 |
58 | PMIExitModuleMessages.exe /?
59 | prints usage.
60 | PMIExitModuleMessages.exe [/i] [path to PMIExitModuleMessages.dll]
61 | installs the messages. If the path is not specified, it looks at the path where this program is.
62 | PMIExitModuleMessages.exe /u
63 | uninstalls the dll.
64 |
65 | --*/
66 | int __cdecl wmain(
67 | int argc,
68 | const wchar_t* argv[])
69 | {
70 | CArguments args;
71 | if (!args.TryParse(argc, argv))
72 | {
73 | PrintUsage();
74 | return EXIT_FAILURE;
75 | }
76 |
77 | bool fSuccess = false;
78 | switch (args.GetOperation())
79 | {
80 | case Operation::INSTALL:
81 | {
82 | std::wstring strPath = args.GetPath();
83 | fSuccess = true;
84 | if (strPath.empty())
85 | {
86 | fSuccess = FindMessageDLL(strPath);
87 | }
88 |
89 | if (fSuccess)
90 | {
91 | fSuccess = InstallMessageDLL(strPath);
92 | }
93 | } break;
94 | case Operation::UINSTALL:
95 | {
96 | fSuccess = UninstallMessageDLL();
97 | } break;
98 | }
99 |
100 | return fSuccess ? EXIT_SUCCESS : EXIT_FAILURE;
101 | }
102 |
103 | void PrintUsage()
104 | {
105 | std::wcerr << L"Usage:" << std::endl;
106 | std::wcerr << L"PMIExitModuleMessages.exe /?" << std::endl;
107 | std::wcerr << L" prints usage." << std::endl;
108 | std::wcerr << L"PMIExitModuleMessages.exe [/i] [path to PMIExitModuleMessages.dll]" << std::endl;
109 | std::wcerr << L" installs the messages. If the path is not specified, it looks at the path where this program is." << std::endl;
110 | std::wcerr << L"PMIExitModuleMessages.exe /u" << std::endl;
111 | std::wcerr << L" uninstalls the messages dll." << std::endl;
112 | }
113 |
114 | bool InstallMessageDLL(const std::wstring& strPath)
115 | {
116 | HKEY hkey = NULL;
117 | LSTATUS lStatus = ::RegCreateKeyExW(
118 | HKEY_LOCAL_MACHINE,
119 | g_pwszRegKeyPath,
120 | 0, // Reserved
121 | NULL, // lpClass
122 | REG_OPTION_NON_VOLATILE,
123 | KEY_WOW64_64KEY | KEY_READ | KEY_WRITE,
124 | NULL, // lpSecurityAttributes
125 | &hkey,
126 | NULL); // lpdwDisposition
127 | if (lStatus != ERROR_SUCCESS)
128 | {
129 | std::wcerr << L"RegCreateKeyExW failed, Win32 error code=" << lStatus << std::endl;
130 | return false;
131 | }
132 |
133 | DWORD dwValue = PMI_EXITMODULE_CATEGORYCOUNT;
134 | lStatus = ::RegSetKeyValueW(
135 | hkey,
136 | NULL,
137 | L"CategoryCount",
138 | REG_DWORD,
139 | &dwValue,
140 | sizeof(dwValue));
141 | if (lStatus != ERROR_SUCCESS)
142 | {
143 | std::wcerr << L"RegSetKeyValueW(CategoryCount) failed, Win32 error code=" << lStatus << std::endl;
144 | return false;
145 | }
146 |
147 | dwValue = PMI_EXITMODULE_PARAMETERCOUNT;
148 | lStatus = ::RegSetKeyValueW(
149 | hkey,
150 | NULL,
151 | L"ParameterCount",
152 | REG_DWORD,
153 | &dwValue,
154 | sizeof(dwValue));
155 | if (lStatus != ERROR_SUCCESS)
156 | {
157 | std::wcerr << L"RegSetKeyValueW(ParameterCount) failed, Win32 error code=" << lStatus << std::endl;
158 | return false;
159 | }
160 |
161 | static const LPCWSTR rgpwszPathValueNames[] =
162 | {
163 | L"CategoryMessageFile",
164 | L"EventMessageFile",
165 | L"ParameterMessageFile",
166 | };
167 |
168 | LPCWSTR pwszPath = strPath.c_str();
169 | DWORD cbPath = (DWORD)strPath.length() * sizeof(WCHAR);
170 | for (
171 | const LPCWSTR* ppwszName = rgpwszPathValueNames;
172 | ppwszName != rgpwszPathValueNames + sizeof(rgpwszPathValueNames) / sizeof(rgpwszPathValueNames[0]);
173 | ppwszName++)
174 | {
175 | LPCWSTR pwszName = *ppwszName;
176 | lStatus = ::RegSetKeyValueW(
177 | hkey,
178 | NULL,
179 | pwszName,
180 | REG_SZ,
181 | pwszPath,
182 | cbPath);
183 | if (lStatus != ERROR_SUCCESS)
184 | {
185 | std::wcerr << L"RegSetKeyValueW(" << pwszName << L") failed, Win32 error code = " << lStatus << std::endl;
186 | return false;
187 | }
188 | }
189 |
190 | return true;
191 | }
192 |
193 | bool UninstallMessageDLL()
194 | {
195 | LSTATUS lStatus = ::RegDeleteKeyExW(
196 | HKEY_LOCAL_MACHINE,
197 | g_pwszRegKeyPath,
198 | KEY_WOW64_64KEY | DELETE,
199 | 0); // Reserved
200 | if (lStatus == ERROR_SUCCESS || lStatus == ERROR_FILE_NOT_FOUND)
201 | {
202 | return true;
203 | }
204 |
205 | std::wcerr << L"Failed to delete reg key HKLM:\\" << g_pwszRegKeyPath << L", Win32 error code=" << lStatus << std::endl;
206 | return false;
207 | }
208 |
209 | bool FindMessageDLL(OUT std::wstring& strPath)
210 | {
211 | LSTATUS lStatus = ERROR_SUCCESS;
212 | WCHAR wszPath[MAX_PATH + 1];
213 | DWORD cch = ::GetModuleFileNameW(
214 | NULL,
215 | wszPath,
216 | sizeof(wszPath) / sizeof(wszPath[0]));
217 | if (cch == 0)
218 | {
219 | lStatus = ::GetLastError();
220 | std::wcerr << L"GetModuleFileNameW failed, Win32 error code=" << lStatus << std::endl;
221 | return false;
222 | }
223 |
224 | const wchar_t* pchDirEnd = wcsrchr(wszPath, L'\\');
225 | if (!pchDirEnd)
226 | {
227 | std::cerr << L"Unable to look for the message DLL based on the location of the current process: " << wszPath << std::endl;
228 | return false;
229 | }
230 |
231 | strPath = std::wstring(wszPath, pchDirEnd - wszPath + 1);
232 | strPath += g_pwszMessageDLLName;
233 |
234 | if (!::PathFileExistsW(strPath.c_str()))
235 | {
236 | std::wcerr << L"Message DLL not found at path " << strPath << std::endl;
237 | return false;
238 | }
239 |
240 | return true;
241 | }
--------------------------------------------------------------------------------
/src/PKI/PMIExitModuleMessagesSetup/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/src/PKI/SampleScript.ps1:
--------------------------------------------------------------------------------
1 | param (
2 | [Parameter(Mandatory=$true)]
3 | [string]$Operation,
4 |
5 | [Parameter(Mandatory=$false)]
6 | [string]$SubjectKeyIdentifier,
7 |
8 | [Parameter(Mandatory=$false)]
9 | [string]$SerialNumber,
10 |
11 | [Parameter(Mandatory=$true)]
12 | [string]$RawCertPath
13 | )
14 |
15 | if ($Operation -eq 'certissued') {
16 | $cert = [System.Security.Cryptography.X509Certificates.X509Certificate2]::new($RawCertPath)
17 | $cert | fl > "$RawCertPath.txt"
18 | }
--------------------------------------------------------------------------------
/src/PKI/TimeoutScript.ps1:
--------------------------------------------------------------------------------
1 | param (
2 | [Parameter(Mandatory=$true)]
3 | [string]$Operation,
4 |
5 | [Parameter(Mandatory=$false)]
6 | [string]$SubjectKeyIdentifier,
7 |
8 | [Parameter(Mandatory=$false)]
9 | [string]$SerialNumber,
10 |
11 | [Parameter(Mandatory=$true)]
12 | [string]$RawCertPath
13 | )
14 |
15 | # Cause a timeout in the exit module.
16 | Start-Sleep 11
17 |
18 | if ($Operation -eq 'certissued') {
19 | $cert = [System.Security.Cryptography.X509Certificates.X509Certificate2]::new($RawCertPath)
20 | $cert | fl > "$RawCertPath.txt"
21 | }
--------------------------------------------------------------------------------
/src/PKI/WindowsSDKMisc.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | $(WindowsSdkDir)bin
7 |
8 | $(WDKBinRoot)\x86
9 | $(WDKBinRoot)\x64
10 |
11 |
12 |
13 |
14 |
15 | %(Filename)
16 | true
17 | $(IntDir)
18 | true
19 | $(IntDir)
20 | $(TLogLocation)
21 | true
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/src/PKI/WindowsSDKMisc.targets:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | $(WDKBinRoot)\x86\
7 | Native32Bit
8 |
9 |
10 |
11 |
12 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 | false
23 |
24 |
25 |
26 |
27 |
30 |
34 |
35 |
36 |
37 |
38 | false
39 |
40 |
41 |
42 |
90 |
91 |
92 |
--------------------------------------------------------------------------------
/src/PKI/dirs.proj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/src/TestConsoleApp/TestConsoleApp.cpp:
--------------------------------------------------------------------------------
1 | // TestConsoleApp.cpp : This file contains the 'main' function. Program execution begins and ends there.
2 | //
3 |
4 | #include
5 |
6 | int main(int argc, const char* argv[])
7 | {
8 | std::cout << "Hello World!\n";
9 | return 0;
10 | }
11 |
12 | // Run program: Ctrl + F5 or Debug > Start Without Debugging menu
13 | // Debug program: F5 or Debug > Start Debugging menu
14 |
15 | // Tips for Getting Started:
16 | // 1. Use the Solution Explorer window to add/manage files
17 | // 2. Use the Team Explorer window to connect to source control
18 | // 3. Use the Output window to see build output and other messages
19 | // 4. Use the Error List window to view errors
20 | // 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
21 | // 6. In the future, to open this project again, go to File > Open > Project and select the .sln file
22 |
--------------------------------------------------------------------------------
/src/TestConsoleApp/TestConsoleApp.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 17
4 | VisualStudioVersion = 17.5.33502.453
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestConsoleApp", "TestConsoleApp.vcxproj", "{03FA442D-0154-41FB-9C98-788A8E9A79E2}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|x64 = Debug|x64
11 | Debug|x86 = Debug|x86
12 | Release|x64 = Release|x64
13 | Release|x86 = Release|x86
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {03FA442D-0154-41FB-9C98-788A8E9A79E2}.Debug|x64.ActiveCfg = Debug|x64
17 | {03FA442D-0154-41FB-9C98-788A8E9A79E2}.Debug|x64.Build.0 = Debug|x64
18 | {03FA442D-0154-41FB-9C98-788A8E9A79E2}.Debug|x86.ActiveCfg = Debug|Win32
19 | {03FA442D-0154-41FB-9C98-788A8E9A79E2}.Debug|x86.Build.0 = Debug|Win32
20 | {03FA442D-0154-41FB-9C98-788A8E9A79E2}.Release|x64.ActiveCfg = Release|x64
21 | {03FA442D-0154-41FB-9C98-788A8E9A79E2}.Release|x64.Build.0 = Release|x64
22 | {03FA442D-0154-41FB-9C98-788A8E9A79E2}.Release|x86.ActiveCfg = Release|Win32
23 | {03FA442D-0154-41FB-9C98-788A8E9A79E2}.Release|x86.Build.0 = Release|Win32
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | GlobalSection(ExtensibilityGlobals) = postSolution
29 | SolutionGuid = {0A732D24-06FC-4AE3-95C4-841495DE6A93}
30 | EndGlobalSection
31 | EndGlobal
32 |
--------------------------------------------------------------------------------
/src/TestConsoleApp/TestConsoleApp.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 | Debug
14 | x64
15 |
16 |
17 | Release
18 | x64
19 |
20 |
21 |
22 | 16.0
23 | Win32Proj
24 | {03fa442d-0154-41fb-9c98-788a8e9a79e2}
25 | TestConsoleApp
26 | 10.0
27 |
28 |
29 |
30 | Application
31 | true
32 | v143
33 | Unicode
34 |
35 |
36 | Application
37 | false
38 | v143
39 | true
40 | Unicode
41 |
42 |
43 | Application
44 | true
45 | v143
46 | Unicode
47 |
48 |
49 | Application
50 | false
51 | v143
52 | true
53 | Unicode
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 | Level3
76 | true
77 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
78 | true
79 |
80 |
81 | Console
82 | true
83 |
84 |
85 |
86 |
87 | Level3
88 | true
89 | true
90 | true
91 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
92 | true
93 |
94 |
95 | Console
96 | true
97 | true
98 | true
99 |
100 |
101 |
102 |
103 | Level3
104 | true
105 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions)
106 | true
107 |
108 |
109 | Console
110 | true
111 |
112 |
113 |
114 |
115 | Level3
116 | true
117 | true
118 | true
119 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
120 | true
121 |
122 |
123 | Console
124 | true
125 | true
126 | true
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
--------------------------------------------------------------------------------
/src/TestConsoleApp/TestConsoleApp.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/src/TestConsoleApp/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/src/dirs.proj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------