diff options
| author | Carl Hetherington <cth@carlh.net> | 2018-10-17 19:23:18 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2018-10-17 19:23:18 +0100 |
| commit | ce9bb37168f52a8d1348e1334fc15d5778fffa75 (patch) | |
| tree | e77c65084e72290f77d5346e4020d3357403c018 /src/wx/config_dialog.cc | |
| parent | 4eaecb1841d3a80a4f06613ad4c0bd44d89285a9 (diff) | |
Prevent un-prompted overwrite of files when exporting things from config (#1383).
Diffstat (limited to 'src/wx/config_dialog.cc')
| -rw-r--r-- | src/wx/config_dialog.cc | 92 |
1 files changed, 54 insertions, 38 deletions
diff --git a/src/wx/config_dialog.cc b/src/wx/config_dialog.cc index 4195aa128..e55de008f 100644 --- a/src/wx/config_dialog.cc +++ b/src/wx/config_dialog.cc @@ -526,14 +526,17 @@ CertificateChainEditor::export_certificate () } if (d->ShowModal () == wxID_OK) { - FILE* f = fopen_boost (path_from_file_dialog (d, "pem"), "w"); - if (!f) { - throw OpenFileError (wx_to_std (d->GetPath ()), errno, false); - } + optional<boost::filesystem::path> path = path_from_file_dialog (d, "pem"); + if (path) { + FILE* f = fopen_boost (*path, "w"); + if (!f) { + throw OpenFileError (*path, errno, false); + } - string const s = j->certificate (true); - fwrite (s.c_str(), 1, s.length(), f); - fclose (f); + string const s = j->certificate (true); + fwrite (s.c_str(), 1, s.length(), f); + fclose (f); + } } d->Destroy (); } @@ -698,14 +701,17 @@ CertificateChainEditor::export_private_key () ); if (d->ShowModal () == wxID_OK) { - FILE* f = fopen_boost (path_from_file_dialog (d, "pem"), "w"); - if (!f) { - throw OpenFileError (wx_to_std (d->GetPath ()), errno, false); - } + optional<boost::filesystem::path> path = path_from_file_dialog (d, "pem"); + if (path) { + FILE* f = fopen_boost (*path, "w"); + if (!f) { + throw OpenFileError (*path, errno, false); + } - string const s = _get()->key().get (); - fwrite (s.c_str(), 1, s.length(), f); - fclose (f); + string const s = _get()->key().get (); + fwrite (s.c_str(), 1, s.length(), f); + fclose (f); + } } d->Destroy (); } @@ -793,17 +799,20 @@ KeysPage::export_decryption_chain_and_key () ); if (d->ShowModal () == wxID_OK) { - FILE* f = fopen_boost (path_from_file_dialog (d, "dom"), "w"); - if (!f) { - throw OpenFileError (wx_to_std (d->GetPath ()), errno, false); - } + optional<boost::filesystem::path> path = path_from_file_dialog (d, "dom"); + if (path) { + FILE* f = fopen_boost (*path, "w"); + if (!f) { + throw OpenFileError (wx_to_std (d->GetPath ()), errno, false); + } - string const chain = Config::instance()->decryption_chain()->chain(); - fwrite (chain.c_str(), 1, chain.length(), f); - optional<string> const key = Config::instance()->decryption_chain()->key(); - DCPOMATIC_ASSERT (key); - fwrite (key->c_str(), 1, key->length(), f); - fclose (f); + string const chain = Config::instance()->decryption_chain()->chain(); + fwrite (chain.c_str(), 1, chain.length(), f); + optional<string> const key = Config::instance()->decryption_chain()->key(); + DCPOMATIC_ASSERT (key); + fwrite (key->c_str(), 1, key->length(), f); + fclose (f); + } } d->Destroy (); @@ -870,14 +879,17 @@ KeysPage::export_decryption_chain () ); if (d->ShowModal () == wxID_OK) { - FILE* f = fopen_boost (path_from_file_dialog (d, "pem"), "w"); - if (!f) { - throw OpenFileError (wx_to_std (d->GetPath ()), errno, false); - } + optional<boost::filesystem::path> path = path_from_file_dialog (d, "pem"); + if (path) { + FILE* f = fopen_boost (*path, "w"); + if (!f) { + throw OpenFileError (*path, errno, false); + } - string const s = Config::instance()->decryption_chain()->chain(); - fwrite (s.c_str(), 1, s.length(), f); - fclose (f); + string const s = Config::instance()->decryption_chain()->chain(); + fwrite (s.c_str(), 1, s.length(), f); + fclose (f); + } } d->Destroy (); } @@ -891,14 +903,18 @@ KeysPage::export_decryption_certificate () ); if (d->ShowModal () == wxID_OK) { - FILE* f = fopen_boost (path_from_file_dialog (d, "pem"), "w"); - if (!f) { - throw OpenFileError (wx_to_std (d->GetPath ()), errno, false); - } + optional<boost::filesystem::path> path = path_from_file_dialog (d, "pem"); + if (path) { + FILE* f = fopen_boost (*path, "w"); + if (!f) { + throw OpenFileError (*path, errno, false); + } - string const s = Config::instance()->decryption_chain()->leaf().certificate (true); - fwrite (s.c_str(), 1, s.length(), f); - fclose (f); + string const s = Config::instance()->decryption_chain()->leaf().certificate (true); + fwrite (s.c_str(), 1, s.length(), f); + fclose (f); + } } + d->Destroy (); } |
