[smartmontools-support] How to encode $passwordEnc within smartd_mailer.conf.ps1 appropriately?

Christian Franke Christian.Franke at t-online.de
Fri Sep 1 18:17:04 CEST 2023


B.S. wrote:
> How do I munge my SMTP password appropriately for inclusion into my
> smartd_mailer.conf.ps1 file?

This encrypts the PW, folds the very long string and appends the setting 
to the config file:

$password = '...'
$sec = ConvertTo-SecureString -AsPlainText -Force $password
$str = ConvertFrom-SecureString $sec
$pwe = ($str -split '(.{78})' ` | Where-Object {$_}) -replace '^',' '
'$passwordEnc = "', $pwe, '"' `
| Out-File -Encoding "UTF8" -Append -FilePath "smartd_mailer.conf.ps1"

I agree that such a script should be added to smartmontools package.

This could be used to decrypt the PW later:

$str = $passwordEnc -replace '[\r\n\t ]',''
$sec = ConvertTo-SecureString -String $str
$bstr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($sec)
[System.Runtime.InteropServices.Marshal]::PtrToStringAuto($bstr)


The encryption is machine and user specific. If smartd is run as a 
service under the SYSTEM account, the above needs to be run on the same 
machine under this account, for example with 'psexec -s powershell' 
(Sysinternals tools).

Alternatively run the service under a local user with admin privileges. 
Then the option '--warn-as-user=restricted' could be used. If specified, 
the smartd warning script is run under the same user but without admin 
privileges.

Regards,
Christian



More information about the Smartmontools-support mailing list