Skip to content

Commit 3bb70f4

Browse files
authored
Cut 4427 disallow main folders path redirection (#150) (#151)
* Cut 4427 disallow main folders path redirection (#150) * folder redirect validation * default path fix * functions test * docs * ver * test * test fix * test * tests * fix * redirect
1 parent adc8d59 commit 3bb70f4

File tree

8 files changed

+235
-19
lines changed

8 files changed

+235
-19
lines changed

ModuleChangelog.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
## 2.7.10
2+
3+
Release Date: January 3, 2025
4+
5+
#### RELEASE NOTES
6+
```
7+
* This release prevents ADMU from migrating if one of the main user folders (Desktop, Downloads, Documents, Pictures, Music, Videos, Favorites) are redirected to network shared path
8+
```
9+
#### Bug Fixes:
10+
```
11+
* Fix issue when migrating a user with one of their main user folders are redirected to a network path. ADMU will now throw an error and prevent migration if any of the primary user folders (Desktop, Downloads, Documents, Pictures, Music, Videos, Favorites) are redirected to network shared path
12+
```
113
## 2.7.9
214

315
Release Date: November 21, 2024

jumpcloud-ADMU/Docs/Start-Migration.md

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,19 @@ Starts the JumpCloud Active Directory Migration process.
1414
## SYNTAX
1515

1616
### cmd
17+
1718
```
1819
Start-Migration -JumpCloudUserName <String> -SelectedUserName <String> -TempPassword <String>
1920
[-LeaveDomain <Boolean>] [-ForceReboot <Boolean>] [-UpdateHomePath <Boolean>] [-InstallJCAgent <Boolean>]
2021
[-AutobindJCUser <Boolean>] [-BindAsAdmin <Boolean>] [-SetDefaultWindowsUser <Boolean>]
21-
[-JumpCloudConnectKey <String>] [-JumpCloudAPIKey <String>] [-JumpCloudOrgID <String>] [<CommonParameters>]
22+
[-AdminDebug <Boolean>] [-JumpCloudConnectKey <String>] [-JumpCloudAPIKey <String>] [-JumpCloudOrgID <String>]
23+
[-ValidateUserShellFolder <Boolean>] [-ProgressAction <ActionPreference>] [<CommonParameters>]
2224
```
2325

2426
### form
27+
2528
```
26-
Start-Migration [-inputObject <Object>] [<CommonParameters>]
29+
Start-Migration [-inputObject <Object>] [-ProgressAction <ActionPreference>] [<CommonParameters>]
2730
```
2831

2932
## DESCRIPTION
@@ -259,7 +262,40 @@ Accept wildcard characters: False
259262
```
260263

261264
### -SetDefaultWindowsUser
262-
Option to set the windows default login user to the migrated user post-migration. This parameter is not required and will default to $true (the next login window user will be the migrated user). Set to $false if you'd like to disable this functionality during migration.
265+
266+
Option to set the windows default login user to the migrated user post-migration. This parameter is not required and will default to $true (the next login window user will be the migrated user). Set to $false if you'd like to disable this functionality during migration.
267+
268+
```yaml
269+
Type: System.Boolean
270+
Parameter Sets: cmd
271+
Aliases:
272+
273+
Required: False
274+
Position: Named
275+
Default value: None
276+
Accept pipeline input: False
277+
Accept wildcard characters: False
278+
```
279+
280+
### -AdminDebug
281+
282+
Option to display detailed messages during migration. This parameter is optional, but if set to $true, the CLI will show verbose output during the migration process
283+
284+
```yaml
285+
Type: System.Boolean
286+
Parameter Sets: cmd
287+
Aliases:
288+
289+
Required: False
290+
Position: Named
291+
Default value: None
292+
Accept pipeline input: False
293+
Accept wildcard characters: False
294+
```
295+
296+
### -ValidateUserShellFolder
297+
298+
Option to bypass User Shell Folder validation. When set to `$false`, the migration will not verify whether folders (Desktop, Downloads, Documents, Videos, Pictures, Music, Favorites) are redirected to another location, such as a network shared folder (e.g., `\\192.168.50.78\SharedFolder\USERNAME\Desktop`). Use this parameter with caution. After migration, the user may encounter a shared folder error and will need to provide account credentials to restore their shared folders
263299

264300
```yaml
265301
Type: System.Boolean
@@ -274,14 +310,17 @@ Accept wildcard characters: False
274310
```
275311

276312
### CommonParameters
313+
277314
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
278315

279316
## INPUTS
280317

281318
### None
319+
282320
## OUTPUTS
283321

284322
### System.Object
323+
285324
## NOTES
286325

287326
## RELATED LINKS

jumpcloud-ADMU/JumpCloud.ADMU.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
# Version number of this module.
1515

16-
ModuleVersion = '2.7.9'
16+
ModuleVersion = '2.7.10'
1717

1818
# Supported PSEditions
1919
# CompatiblePSEditions = @()

jumpcloud-ADMU/Powershell/Form.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ function show-mtpSelection {
153153
<Window
154154
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
155155
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
156-
Title="JumpCloud ADMU 2.7.9"
156+
Title="JumpCloud ADMU 2.7.10"
157157
WindowStyle="SingleBorderWindow"
158158
ResizeMode="NoResize"
159159
Background="White" ScrollViewer.VerticalScrollBarVisibility="Visible" ScrollViewer.HorizontalScrollBarVisibility="Visible" Width="1020" Height="590">

jumpcloud-ADMU/Powershell/ProgressForm.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function New-ProgressForm {
3737
<Window
3838
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3939
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
40-
Name="Window" Title="JumpCloud ADMU 2.7.9"
40+
Name="Window" Title="JumpCloud ADMU 2.7.10"
4141
WindowStyle="SingleBorderWindow"
4242
ResizeMode="NoResize"
4343
Background="White" Width="720" Height="550 ">

jumpcloud-ADMU/Powershell/Start-Migration.ps1

Lines changed: 94 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,9 @@ Function Test-UserRegistryLoadState {
750750
# User Security Identifier
751751
[Parameter(Mandatory = $true)]
752752
[ValidatePattern("^S-\d-\d+-(\d+-){1,14}\d+$")]
753-
[System.String]$UserSid
753+
[System.String]$UserSid,
754+
[Parameter(Mandatory = $false)]
755+
[bool]$ValidateDirectory
754756
)
755757
begin {
756758
$results = REG QUERY HKU *>&1
@@ -767,16 +769,19 @@ Function Test-UserRegistryLoadState {
767769
}
768770
}
769771
process {
770-
# Load New User Profile Registry Keys
771772
try {
772773
Set-UserRegistryLoadState -op "Load" -ProfilePath $ProfilePath -UserSid $UserSid -hive root
773774
Set-UserRegistryLoadState -op "Load" -ProfilePath $ProfilePath -UserSid $UserSid -hive classes
775+
if ($ValidateDirectory) {
776+
# return boolean for redirected user directories
777+
$isFolderRedirect = Test-UserFolderRedirect -UserSid $UserSid
778+
} else {
779+
Write-ToLog "Skipping User Shell Folder Validation..."
780+
}
774781
} catch {
775782
Write-AdmuErrorMessage -Error:("load_unload_error")
776783
Throw "Could Not Load User Registry During Test-UserRegistryLoadState Load Process"
777784
}
778-
# Load Selected User Profile Keys
779-
# Unload "Selected" and "NewUser"
780785
try {
781786
Set-UserRegistryLoadState -op "Unload" -ProfilePath $ProfilePath -UserSid $UserSid -hive root
782787
Set-UserRegistryLoadState -op "Unload" -ProfilePath $ProfilePath -UserSid $UserSid -hive classes
@@ -799,6 +804,15 @@ Function Test-UserRegistryLoadState {
799804
throw "Registry Keys are still loaded after Test-UserRegistryLoadState Testing Exiting..."
800805
}
801806
}
807+
# If isFolderRedirect is false throw error
808+
if ($isFolderRedirect -and $ValidateDirectory) {
809+
Write-AdmuErrorMessage -Error:("user_folder_redirection_error")
810+
throw "Main user folders are redirected, exiting..."
811+
} elseif ($ValidateDirectory -eq $false) {
812+
Write-ToLog "Skipping User Shell Folder Validation..."
813+
} else {
814+
Write-ToLog "Main user folders are default for Usersid: $($UserSid), continuing..."
815+
}
802816
}
803817
}
804818

@@ -1745,6 +1759,10 @@ function Write-AdmuErrorMessage {
17451759

17461760
$Script:ErrorMessage = "User Creation Error. Click the link below for troubleshooting information."
17471761
}
1762+
"user_folder_redirection_error" {
1763+
Write-ToLog -Message:("User Folder Redirection Error: One of the user's main folder (Desktop, Downloads, Documents, Favorites, Pictures, Videos, Music) path is redirected. Verify that the user's main folders path are set to default and not redirected to another path (ie. Network Drive). Please refer to this link for more information: https://github.com/TheJumpCloud/jumpcloud-ADMU/wiki/troubleshooting-errors") -Level Error
1764+
$Script:ErrorMessage = "User Folder Redirection Error. Click the link below for troubleshooting information."
1765+
}
17481766
Default {
17491767
Write-ToLog -Message:("Error occured, please refer to this link for more information: https://github.com/TheJumpCloud/jumpcloud-ADMU/wiki/troubleshooting-errors") -Level Error
17501768

@@ -1847,6 +1865,74 @@ function Get-DomainStatus {
18471865
# Return both statuses
18481866
return $AzureADStatus, $LocalDomainStatus
18491867
}
1868+
1869+
# Function to validate that the user main folders are default and not redirected
1870+
function Test-UserFolderRedirect {
1871+
param (
1872+
[Parameter(Mandatory = $true)]
1873+
[System.String]
1874+
$UserSid
1875+
)
1876+
begin {
1877+
if ("HKEY_USERS" -notin (Get-psdrive | select-object name).Name) {
1878+
Write-ToLog "Mounting HKEY_USERS"
1879+
New-PSDrive -Name:("HKEY_USERS") -PSProvider:("Registry") -Root:("HKEY_USERS") | Out-Null
1880+
}
1881+
$UserFolders = @( "Desktop", "Documents", "Downloads", "Favorites", "Music", "Pictures", "Videos" )
1882+
# Support doc for personal folders: https://support.microsoft.com/en-us/topic/operation-to-change-a-personal-folder-location-fails-in-windows-ffb95139-6dbb-821d-27ec-62c9aaccd720
1883+
$regFoldersPath = "HKEY_USERS:\$($UserSid)_admu\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders"
1884+
Write-ToLog -Message:("Checking User Shell Folders for USERSID: $($UserSid)")
1885+
}
1886+
process {
1887+
1888+
if (Test-Path -Path $regFoldersPath) {
1889+
$redirectedDirectory = $false
1890+
# Save all the boolean to a hash table
1891+
foreach ($userFolder in $UserFolders) {
1892+
switch ($userFolder) {
1893+
"Desktop" {
1894+
$folderRegKey = "Desktop"
1895+
}
1896+
"Documents" {
1897+
$folderRegKey = "Personal"
1898+
}
1899+
"Downloads" {
1900+
$folderRegKey = "{374DE290-123F-4565-9164-39C4925E467B}"
1901+
}
1902+
"Favorites" {
1903+
$folderRegKey = "Favorites"
1904+
}
1905+
"Music" {
1906+
$folderRegKey = "My Music"
1907+
}
1908+
"Pictures" {
1909+
$folderRegKey = "My Pictures"
1910+
}
1911+
"Videos" {
1912+
$folderRegKey = "My Video"
1913+
}
1914+
}
1915+
# Get the registry value for the user folder
1916+
$folderRegKeyValue = (Get-Item -path $regFoldersPath ).GetValue($folderRegKey , '', 'DoNotExpandEnvironmentNames')
1917+
$defaultRegFolder = "%USERPROFILE%\$userFolder"
1918+
# If the registry value does not match the default path, set redirectedDirectory to true and log the error
1919+
if ($folderRegKeyValue -ne $defaultRegFolder) {
1920+
Write-ToLog -Message:("$($userFolder) path value: $($folderRegKeyValue) does not match default path - $($defaultRegFolder)") -Level Error
1921+
$redirectedDirectory = $true
1922+
} else {
1923+
Write-ToLog -Message:("User Shell Folder: $($userFolder) is default")
1924+
}
1925+
}
1926+
} else {
1927+
# If the registry path does not exist, set redirectedDirectory to true and log the error
1928+
Write-ToLog -Message:("User Shell registry folders not found in registry") -Level Error
1929+
$redirectedDirectory = $true
1930+
}
1931+
}
1932+
end {
1933+
return $redirectedDirectory
1934+
}
1935+
}
18501936
Function Start-Migration {
18511937
[CmdletBinding(HelpURI = "https://github.com/TheJumpCloud/jumpcloud-ADMU/wiki/Start-Migration")]
18521938
Param (
@@ -1864,6 +1950,7 @@ Function Start-Migration {
18641950
[Parameter(ParameterSetName = 'cmd', Mandatory = $false)][ValidateLength(40, 40)][string]$JumpCloudConnectKey,
18651951
[Parameter(ParameterSetName = 'cmd', Mandatory = $false)][string]$JumpCloudAPIKey,
18661952
[Parameter(ParameterSetName = 'cmd', Mandatory = $false)][ValidateLength(24, 24)][string]$JumpCloudOrgID,
1953+
[Parameter(ParameterSetName = 'cmd', Mandatory = $false)][bool]$ValidateUserShellFolder = $true,
18671954
[Parameter(ParameterSetName = "form")][Object]$inputObject)
18681955

18691956
Begin {
@@ -1883,8 +1970,7 @@ Function Start-Migration {
18831970
$AGENT_INSTALLER_URL = "https://cdn02.jumpcloud.com/production/jcagent-msi-signed.msi"
18841971
$AGENT_INSTALLER_PATH = "$windowsDrive\windows\Temp\JCADMU\jcagent-msi-signed.msi"
18851972
$AGENT_CONF_PATH = "$($AGENT_PATH)\Plugins\Contrib\jcagent.conf"
1886-
$admuVersion = '2.7.9'
1887-
1973+
$admuVersion = '2.7.10'
18881974
# Log Windows System Version Information
18891975
Write-ToLog -Message:("OSName: $($systemVersion.OSName), OSVersion: $($systemVersion.OSVersion), OSBuildNumber: $($systemVersion.OsBuildNumber), OSEdition: $($systemVersion.WindowsEditionId)")
18901976

@@ -1899,10 +1985,6 @@ Function Start-Migration {
18991985
$profileSize = Get-ProfileSize -profilePath $oldUserProfileImagePath
19001986

19011987
$JumpCloudUserName = $inputObject.JumpCloudUserName
1902-
1903-
1904-
1905-
19061988
if (($inputObject.JumpCloudConnectKey).Length -eq 40) {
19071989
$JumpCloudConnectKey = $inputObject.JumpCloudConnectKey
19081990
}
@@ -1932,7 +2014,6 @@ Function Start-Migration {
19322014
$UpdateHomePath = $inputObject.UpdateHomePath
19332015
} else {
19342016
$useragent = "JumpCloud_ADMU.Powershell/$($admuVersion)"
1935-
Write-ToLog -Message:("UserAgent: $useragent")
19362017
$SelectedUserSid = Test-UsernameOrSID $SelectedUserName
19372018
}
19382019

@@ -2180,8 +2261,8 @@ Function Start-Migration {
21802261

21812262
Write-ToLog -Message:('Verifying registry files can be loaded and unloaded')
21822263
try {
2183-
Test-UserRegistryLoadState -ProfilePath $newUserProfileImagePath -UserSid $newUserSid
2184-
Test-UserRegistryLoadState -ProfilePath $oldUserProfileImagePath -UserSid $SelectedUserSID
2264+
Test-UserRegistryLoadState -ProfilePath $newUserProfileImagePath -UserSid $newUserSid -ValidateDirectory $ValidateUserShellFolder
2265+
Test-UserRegistryLoadState -ProfilePath $oldUserProfileImagePath -UserSid $SelectedUserSID -ValidateDirectory $ValidateUserShellFolder
21852266
} catch {
21862267
Write-ToLog -Message:('Could not load and unload registry of migration user during Test-UserRegistryLoadState, exiting') -level Warn
21872268
$admuTracker.testRegLoadUnload.fail = $true

jumpcloud-ADMU/Powershell/Tests/Functions.Tests.ps1

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,4 +709,40 @@ Describe 'Functions' {
709709
}
710710
}
711711
}
712+
713+
# Test for Test-UserFolderRedirect
714+
Context 'Validates that the User shell folder for default values' {
715+
BeforeAll {
716+
if ((Get-psdrive | select-object name) -notmatch "HKEY_USERS") {
717+
New-PSDrive -Name:("HKEY_USERS") -PSProvider:("Registry") -Root:("HKEY_USERS")
718+
}
719+
#$currentSID = ([System.Security.Principal.WindowsIdentity]::GetCurrent()).User.Value
720+
$newUser = "ADMU_User" + -join ((65..90) + (97..122) | Get-Random -Count 5 | ForEach-Object { [char]$_ })
721+
$password = '$T#st1234'
722+
InitUser -UserName $newUser -Password $Password
723+
724+
$userSid = Test-UsernameOrSID -usernameOrSid $newUser
725+
# Load the registry hive for the user and add _admu after the sid
726+
REG LOAD HKU\$($userSid)_admu "C:\Users\$newUser\NTUSER.DAT" *>&1
727+
}
728+
# Test for Test-UserFolderRedirect should be default values
729+
It 'Test-UserFolderRedirect - Default values' {
730+
$folderRedirect = Test-UserFolderRedirect -UserSid $userSid
731+
$folderRedirect | Should -Be $false
732+
}
733+
# Test for Test-UserFolderRedirect with one of the folder redirect values changed
734+
It 'Test-UserFolderRedirect - One value changed' {
735+
# Change the value of the folder Desktop to a different value
736+
$folderPath = "HKEY_USERS:\$($userSid)_admu\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders"
737+
Set-ItemProperty -Path $folderpath -Name Desktop -Value "\\server\share\desktop"
738+
{Test-UserFolderRedirect -UserSid $userSid} | Should -Throw
739+
# Change the value of the folder Desktop back to the default value
740+
Set-ItemProperty -Path $folderpath -Name Desktop -Value "%USERPROFILE%\Desktop"
741+
742+
}
743+
# Test for Invalid SID or Invalid User Shell Folder
744+
It 'Test-UserFolderRedirect - Invalid SID or Invalid User Shell Folder' {
745+
{Test-UserFolderRedirect -UserSid "Invalid-3361044348-30300820-1001"} | Should -Throw
746+
}
747+
}
712748
}

0 commit comments

Comments
 (0)