Skip to content

Commit

Permalink
Fix Confirm-FGTUserLDAP (Source port) and rearrange password code
Browse files Browse the repository at this point in the history
  • Loading branch information
Cédric Moreau committed Sep 5, 2024
1 parent 88f9b88 commit 626f614
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
3 changes: 0 additions & 3 deletions PowerFGT/Private/Confirm.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
Expand Down
27 changes: 13 additions & 14 deletions PowerFGT/Public/cmdb/user/ldap.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down

0 comments on commit 626f614

Please sign in to comment.