From 626f6148ee251b869c6e9563c6f7fb57a451bce1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Moreau?= Date: Thu, 5 Sep 2024 17:07:37 +0200 Subject: [PATCH] Fix Confirm-FGTUserLDAP (Source port) and rearrange password code --- PowerFGT/Private/Confirm.ps1 | 3 --- PowerFGT/Public/cmdb/user/ldap.ps1 | 27 +++++++++++++-------------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/PowerFGT/Private/Confirm.ps1 b/PowerFGT/Private/Confirm.ps1 index a2a0a2be3..bbf73881f 100644 --- a/PowerFGT/Private/Confirm.ps1 +++ b/PowerFGT/Private/Confirm.ps1 @@ -257,9 +257,6 @@ Function Confirm-FGTUserLDAP { if ( -not ( $argument | get-member -name source-ip -Membertype Properties)) { throw "Element specified does not contain a source-ip property." } - if ( -not ( $argument | get-member -name source-port -Membertype Properties)) { - throw "Element specified does not contain a source-port property." - } if ( -not ( $argument | get-member -name cnid -Membertype Properties)) { throw "Element specified does not contain a cnid property." } diff --git a/PowerFGT/Public/cmdb/user/ldap.ps1 b/PowerFGT/Public/cmdb/user/ldap.ps1 index e7d630bf0..05fa178a7 100644 --- a/PowerFGT/Public/cmdb/user/ldap.ps1 +++ b/PowerFGT/Public/cmdb/user/ldap.ps1 @@ -130,25 +130,24 @@ function Add-FGTUserLDAP { } if ( $PsBoundParameters.ContainsKey('type') ) { - if ($type -eq "regular") { - if ($Null -eq $username -or $Null -eq $password) { - Throw "You need to specify an username and a passord !" + if ($type -eq "regular" -and ($Null -eq $username -or $Null -eq $password)) { + Throw "You need to specify an username and a passord !" + } + elseif ($type -eq "regular") { + $ldap | add-member -name "type" -membertype NoteProperty -Value $type + $ldap | add-member -name "username" -membertype NoteProperty -Value $username + if (("Desktop" -eq $PSVersionTable.PsEdition) -or ($null -eq $PSVersionTable.PsEdition)) { + $bstr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($password); + $passwd = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($bstr); + $ldap | add-member -name "password" -membertype NoteProperty -Value $passwd } else { - $ldap | add-member -name "type" -membertype NoteProperty -Value $type - $ldap | add-member -name "username" -membertype NoteProperty -Value $username - if (("Desktop" -eq $PSVersionTable.PsEdition) -or ($null -eq $PSVersionTable.PsEdition)) { - $bstr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($password); - $passwd = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($bstr); - $ldap | add-member -name "password" -membertype NoteProperty -Value $passwd - } - else { - $passwd = ConvertFrom-SecureString -SecureString $password -AsPlainText - $ldap | add-member -name "password" -membertype NoteProperty -Value $passwd - } + $passwd = ConvertFrom-SecureString -SecureString $password -AsPlainText + $ldap | add-member -name "password" -membertype NoteProperty -Value $passwd } } else { + #$type is equal to simple or anonymous (Doesn't need username and password) $ldap | add-member -name "type" -membertype NoteProperty -Value $type } }