diff --git a/gui/kivy/main_window.py b/gui/kivy/main_window.py index a067f8c0a..e9a1fed84 100644 --- a/gui/kivy/main_window.py +++ b/gui/kivy/main_window.py @@ -509,6 +509,9 @@ class ElectrumWindow(App): return wallet = self.daemon.load_wallet(path, None) if wallet: + if not wallet.storage.file_writable(): + self.show_error(_("Wallet file not writable")) + return if wallet.has_password(): self.password_dialog(wallet, _('Enter PIN code'), lambda x: self.load_wallet(wallet), self.stop) else: diff --git a/gui/kivy/uix/dialogs/wallets.py b/gui/kivy/uix/dialogs/wallets.py index d7b0469bf..9f0046f08 100644 --- a/gui/kivy/uix/dialogs/wallets.py +++ b/gui/kivy/uix/dialogs/wallets.py @@ -61,5 +61,9 @@ class WalletDialog(Factory.Popup): d.open() def open_wallet(self, app): - app.load_wallet_by_name(self.ids.wallet_selector.selection[0]) + path = self.ids.wallet_selector.selection[0] + if not os.access(path, os.W_OK) or not os.access(path, os.R_OK): + app.show_error(_("Wallet file not writable")) + return + app.load_wallet_by_name(path) diff --git a/gui/qt/__init__.py b/gui/qt/__init__.py index a2c216cdf..984a19f56 100644 --- a/gui/qt/__init__.py +++ b/gui/qt/__init__.py @@ -204,6 +204,8 @@ class ElectrumGui: opens the wallet and creates a new window for it''' try: wallet = self.daemon.load_wallet(path, None) + if wallet and not wallet.storage.file_writable(): + raise Exception(_("Wallet file not writable")) except BaseException as e: traceback.print_exc(file=sys.stdout) d = QMessageBox(QMessageBox.Warning, _('Error'), diff --git a/lib/base_wizard.py b/lib/base_wizard.py index fd3c8cc39..9d671ce23 100644 --- a/lib/base_wizard.py +++ b/lib/base_wizard.py @@ -91,6 +91,9 @@ class BaseWizard(object): self.run(action, *args) def new(self): + if not self.storage.file_writable(): + self.show_error(_("Wallet file not writable")) + return name = os.path.basename(self.storage.path) title = _("Create") + ' ' + name message = '\n'.join([ diff --git a/lib/storage.py b/lib/storage.py index 69875e3f1..d94cd3102 100644 --- a/lib/storage.py +++ b/lib/storage.py @@ -165,6 +165,15 @@ class WalletStorage(PrintError): def file_exists(self): return self.path and os.path.exists(self.path) + def file_writable(self): + if not self.file_exists(): + if not os.access(os.path.dirname(self.path), os.W_OK): + return False + else: + if not os.access(self.path, os.W_OK): + return False + return True + @staticmethod def get_eckey_from_password(password): secret = pbkdf2.PBKDF2(password, '', iterations=1024, macmodule=hmac, digestmodule=hashlib.sha512).read(64)