1
0
mirror of https://github.com/gryf/wicd.git synced 2026-01-04 21:04:15 +01:00

Fix bug where encryption keys with non-ascii characters caused crashes.

Only write settings being saved if debug mode is on.
Clear keys entered through the GUI when the encryption checkbox is disabled.
This commit is contained in:
Dan O'Reilly
2009-01-17 12:58:02 -05:00
parent 4f22df62b0
commit 75219d78c4
3 changed files with 15 additions and 12 deletions

View File

@@ -26,14 +26,15 @@ reusable for other purposes as well.
from ConfigParser import RawConfigParser
from wicd.misc import stringToNone, Noneify
from wicd.misc import stringToNone, Noneify, to_unicode
class ConfigManager(RawConfigParser):
""" A class that can be used to manage a given configuration file. """
def __init__(self, path):
def __init__(self, path, debug=False):
RawConfigParser.__init__(self)
self.config_file = path
self.debug = debug
self.read(path)
def __repr__(self):
@@ -57,8 +58,9 @@ class ConfigManager(RawConfigParser):
"""
if not self.has_section(section):
self.add_section(section)
RawConfigParser.set(self, section, str(option), str(value))
if isinstance(value, basestring):
value = to_unicode(value)
RawConfigParser.set(self, section, str(option), value)
if save:
self.write()
@@ -80,11 +82,13 @@ class ConfigManager(RawConfigParser):
if self.has_option(section, option):
ret = RawConfigParser.get(self, section, option)
if default:
print ''.join(['found ', option, ' in configuration ', ret])
if self.debug:
print ''.join(['found ', option, ' in configuration ',
str(ret)])
else:
if default != "__None__":
print ''.join(['did not find ', option,
' in configuration, setting default ', str(default)])
if self.debug:
print 'did not find %s in configuration, setting default %s' % (option, str(default))
self.set(section, option, str(default), save=True)
ret = default
else:

View File

@@ -318,7 +318,7 @@ def get_gettext():
def to_unicode(x):
""" Attempts to convert a string to utf-8. """
# If this is a unicode string, encode it and return
if type(x) not in [unicode, str]:
if not isinstance(x, basestring):
return x
if isinstance(x, unicode):
return x.encode('utf-8')

View File

@@ -471,17 +471,16 @@ class WirelessSettingsDialog(AdvancedSettingsDialog):
if encryption_info[x].get_text() == "":
error(self, language['encrypt_info_missing'])
return False
self.set_net_prop(x, noneToString(encryption_info[x].
get_text()))
self.set_net_prop(x, noneToString(encryption_info[x].get_text()))
elif not self.chkbox_encryption.get_active() and \
wireless.GetWirelessProperty(networkid, "encryption"):
error(self, language['enable_encryption'])
return False
else:
print 'encryption is ' + str(wireless.GetWirelessProperty(networkid,
"encryption"))
print "no encryption specified..."
self.set_net_prop("enctype", "None")
for x in self.encryption_info:
self.set_net_prop(x, "")
AdvancedSettingsDialog.save_settings(self)
if self.chkbox_global_settings.get_active():