Hi
I am coding a GUI to help automate decryption of a particular encryption system (eCryptfs).
There is a Linux command called ecryptfs-unwrap-passphrase that resides in /usr/bin/. When it's ran, it asks the user for their login password, a bit like when you try and do something using sudo or when you try to su.
I am trying to call this program from mine. I have read
http://www.freepascal.org/docs-html/fcl/process/tprocess.html and followed
http://wiki.lazarus.freepascal.org/Executing_External_Programs.
Before I continue trying to make this work, I have two questions :
1) Can you call a none graphical command line program from within a GUI like I am trying to do? Though my program compiles, it hangs, and I can't work out if that because the answer to this question is "no, you can't", or if it's due to question 2
2) How do you call a program and also pass that program additional values? i.e. Assuming the answer to 1 above is "yes", and the reason my program is hanging is merely because ecryptfs-unwrap-passphrase is waiting for the user to input a password but it can't be displayed on screen, how do I pass both the command and the password that I want it to use? e.g. ecryptfs-unwrap-passphrase MyPassword
So far I have :
procedure TForm1.Button1Click(Sender: TObject);
var
FileToAttack : String;
UnwrapPassphraseProcess: TProcess;
UnwrapPassphraseOutput: TStringList;
begin
if OpenDialog1.Execute then
begin
FileToAttack := OpenDialog1.FileName;
if FileExists(FileToAttack) then
begin
Edit1.Caption := FileToAttack;
UnwrapPassphraseProcess := TProcess.Create(nil);
UnwrapPassphraseOutput.Create;
UnwrapPassphraseProcess.CommandLine := ('/usr/bin/ecryptfs-unwrap-passphrase ');
// Have also tried ..:= ('/usr/bin/ecryptfs-unwrap-passphrase ' + 'MyPassword')
UnwrapPassphraseProcess.Options := UnwrapPassphraseProcess.Options + [poWaitOnExit, poUsePipes];
UnwrapPassphraseProcess.Execute;
UnwrapPassphraseOutput.LoadFromStream(UnwrapPassphraseProcess.Output);
UnwrapPassphraseOutput.SaveToFile('/home/ted/testing.txt');
UnwrapPassphraseProcess.Free;
UnwrapPassphraseOutput.Free;
OpenDialog1.Close;
end
else
ShowMessage('An error occurred opening the passphrase file.');
end;
end;
Thanks
Ted