1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-07 13:11:28 +00:00

Fix file permissions again for zenmap.conf. Handle it in one place only.

This commit is contained in:
dmiller
2016-10-17 16:14:58 +00:00
parent ab44513a98
commit 20de140ae6
3 changed files with 24 additions and 34 deletions

View File

@@ -129,6 +129,7 @@ class UmitConfigParser(ConfigParser):
def __init__(self, *args): def __init__(self, *args):
self.filenames = None self.filenames = None
self.failed = False
ConfigParser.__init__(self, *args) ConfigParser.__init__(self, *args)
def set(self, section, option, value): def set(self, section, option, value):
@@ -149,7 +150,14 @@ class UmitConfigParser(ConfigParser):
def save_changes(self): def save_changes(self):
if self.filenames: if self.filenames:
log.debug("saving to %s" % self.filenames) log.debug("saving to %s" % self.filenames)
self.write(open(self.filenames, 'w')) try:
fp = open(self.filenames, 'w')
except Exception as e:
self.failed = e
log.error(">>> Can't save to %s: %s" % (self.filenames, e))
return
self.write(fp)
self.failed = False
else: else:
log.debug(">>> UmitConfigParser can't save changes: no filename") log.debug(">>> UmitConfigParser can't save changes: no filename")

View File

@@ -156,7 +156,7 @@ from zenmapCore.RecentScans import recent_scans
from zenmapCore.UmitLogging import log from zenmapCore.UmitLogging import log
import zenmapCore.I18N import zenmapCore.I18N
import zenmapGUI.Print import zenmapGUI.Print
from zenmapCore.UmitConf import SearchConfig, is_maemo, WindowConfig from zenmapCore.UmitConf import SearchConfig, is_maemo, WindowConfig, config_parser
from zenmapCore.NetworkInventory import FilteredNetworkInventory from zenmapCore.NetworkInventory import FilteredNetworkInventory
UmitScanWindow = None UmitScanWindow = None
@@ -906,23 +906,19 @@ This scan has not been run yet. Start the scan with the "Scan" button first.'))
return True return True
window = WindowConfig() window = WindowConfig()
try: window.x, window.y = self.get_position()
window.x, window.y = self.get_position() window.width, window.height = self.get_size()
window.width, window.height = self.get_size() window.save_changes()
window.save_changes() if config_parser.failed:
except IOError as e: alert = HIGAlertDialog(
if e.errno == errno.EACCES: message_format=_("Can't save Zenmap configuration"),
alert = HIGAlertDialog( # newline before path to help avoid weird line wrapping
message_format=_("Can't save Zenmap configuration"), secondary_text=_(
# newline before path to help avoid weird line wrapping 'An error occurred when saving to\n%s'
secondary_text=_( '\nThe error was: %s.'
'Permission denied when writing to\n%s' ) % (Path.user_config_file, config_parser.failed))
'\nMake sure the file exists and is writable.' alert.run()
) % (Path.user_config_file)) alert.destroy()
alert.run()
alert.destroy()
else:
raise
self.destroy() self.destroy()

View File

@@ -126,7 +126,6 @@ import gtk
import gtk.gdk import gtk.gdk
import pango import pango
import re import re
import errno
import zenmapCore.I18N import zenmapCore.I18N
from zenmapCore.UmitLogging import log from zenmapCore.UmitLogging import log
@@ -264,20 +263,7 @@ class NmapOutputViewer (gtk.VBox):
self.nmap_highlight.__setattr__(widget.property_name, wid_props) self.nmap_highlight.__setattr__(widget.property_name, wid_props)
nmap_out_prop.destroy() nmap_out_prop.destroy()
try: self.nmap_highlight.save_changes()
self.nmap_highlight.save_changes()
except IOError as e:
if e.errno == errno.EACCES:
alert = HIGAlertDialog(
message_format=_("Can't save Zenmap configuration"),
secondary_text=_(
'Permission denied when writing to \n%s'
'\nMake sure the file exists and is writable.'
) % (Path.user_config_file))
alert.run()
alert.destroy()
else:
raise
self.apply_highlighting() self.apply_highlighting()
def apply_highlighting(self, start_iter=None, end_iter=None): def apply_highlighting(self, start_iter=None, end_iter=None):