mirror of
https://github.com/gryf/wicd.git
synced 2025-12-23 22:52:33 +01:00
Add a workaround for an issue where large integers got mishandled by python-dbus on 64-bit systems.
Fix potential issue if encryption key is a number Close all open fd's in the daemonize code.
This commit is contained in:
@@ -28,6 +28,7 @@ from ConfigParser import RawConfigParser
|
|||||||
|
|
||||||
from wicd.misc import Noneify, to_unicode
|
from wicd.misc import Noneify, to_unicode
|
||||||
|
|
||||||
|
from dbus import Int32
|
||||||
|
|
||||||
class ConfigManager(RawConfigParser):
|
class ConfigManager(RawConfigParser):
|
||||||
""" A class that can be used to manage a given configuration file. """
|
""" A class that can be used to manage a given configuration file. """
|
||||||
@@ -108,6 +109,12 @@ class ConfigManager(RawConfigParser):
|
|||||||
ret = int(ret)
|
ret = int(ret)
|
||||||
except (ValueError, TypeError):
|
except (ValueError, TypeError):
|
||||||
ret = Noneify(ret)
|
ret = Noneify(ret)
|
||||||
|
# This is a workaround for a python-dbus issue on 64-bit systems.
|
||||||
|
if isinstance(ret, (int)):
|
||||||
|
try:
|
||||||
|
Int32(ret)
|
||||||
|
except OverflowError:
|
||||||
|
ret = long(ret)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def get(self, *args, **kargs):
|
def get(self, *args, **kargs):
|
||||||
|
|||||||
@@ -452,7 +452,6 @@ class WicdDaemon(dbus.service.Object):
|
|||||||
"""
|
"""
|
||||||
return int(self.signal_display_type)
|
return int(self.signal_display_type)
|
||||||
|
|
||||||
|
|
||||||
@dbus.service.method('org.wicd.daemon')
|
@dbus.service.method('org.wicd.daemon')
|
||||||
def SetSignalDisplayType(self, value):
|
def SetSignalDisplayType(self, value):
|
||||||
""" Sets the signal display type and writes it the wicd config file. """
|
""" Sets the signal display type and writes it the wicd config file. """
|
||||||
@@ -1037,7 +1036,7 @@ class WirelessDaemon(dbus.service.Object):
|
|||||||
# We don't write script settings here.
|
# We don't write script settings here.
|
||||||
if (property.strip()).endswith("script"):
|
if (property.strip()).endswith("script"):
|
||||||
print "Setting script properties through the daemon is not" \
|
print "Setting script properties through the daemon is not" \
|
||||||
+ " permitted."
|
+ " permitted."
|
||||||
return False
|
return False
|
||||||
self.LastScan[networkid][property] = misc.Noneify(value)
|
self.LastScan[networkid][property] = misc.Noneify(value)
|
||||||
|
|
||||||
@@ -1118,7 +1117,7 @@ class WirelessDaemon(dbus.service.Object):
|
|||||||
self.wifi.before_script = self.GetWirelessProperty(id, 'beforescript')
|
self.wifi.before_script = self.GetWirelessProperty(id, 'beforescript')
|
||||||
self.wifi.after_script = self.GetWirelessProperty(id, 'afterscript')
|
self.wifi.after_script = self.GetWirelessProperty(id, 'afterscript')
|
||||||
self.wifi.disconnect_script = self.GetWirelessProperty(id,
|
self.wifi.disconnect_script = self.GetWirelessProperty(id,
|
||||||
'disconnectscript')
|
'disconnectscript')
|
||||||
print 'Connecting to wireless network ' + self.LastScan[id]['essid']
|
print 'Connecting to wireless network ' + self.LastScan[id]['essid']
|
||||||
self.daemon.wired_bus.wired.Disconnect()
|
self.daemon.wired_bus.wired.Disconnect()
|
||||||
self.daemon.SetForcedDisconnect(False)
|
self.daemon.SetForcedDisconnect(False)
|
||||||
@@ -1567,14 +1566,12 @@ def daemonize():
|
|||||||
|
|
||||||
# Decouple from parent environment to stop us from being a zombie.
|
# Decouple from parent environment to stop us from being a zombie.
|
||||||
os.setsid()
|
os.setsid()
|
||||||
os.umask(0)
|
|
||||||
|
|
||||||
# Fork the second time to prevent us from opening a file that will
|
# Fork the second time to prevent us from opening a file that will
|
||||||
# become our controlling terminal.
|
# become our controlling terminal.
|
||||||
try:
|
try:
|
||||||
pid = os.fork()
|
pid = os.fork()
|
||||||
if pid > 0:
|
if pid > 0:
|
||||||
print wpath.pidfile
|
|
||||||
dirname = os.path.dirname(wpath.pidfile)
|
dirname = os.path.dirname(wpath.pidfile)
|
||||||
if not os.path.exists(dirname):
|
if not os.path.exists(dirname):
|
||||||
os.makedirs(dirname)
|
os.makedirs(dirname)
|
||||||
@@ -1582,18 +1579,34 @@ def daemonize():
|
|||||||
pidfile.write(str(pid) + '\n')
|
pidfile.write(str(pid) + '\n')
|
||||||
pidfile.close()
|
pidfile.close()
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
else:
|
||||||
|
os.umask(0)
|
||||||
|
os.chdir('/')
|
||||||
except OSError, e:
|
except OSError, e:
|
||||||
print >> sys.stderr, "Fork #2 failed: %d (%s)" % (e.errno, e.strerror)
|
print >> sys.stderr, "Fork #2 failed: %d (%s)" % (e.errno, e.strerror)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
sys.stdout.flush()
|
sys.stdin.close()
|
||||||
sys.stderr.flush()
|
sys.stdout.close()
|
||||||
os.close(sys.__stdin__.fileno())
|
sys.stderr.close()
|
||||||
os.close(sys.__stdout__.fileno())
|
|
||||||
os.close(sys.__stderr__.fileno())
|
try:
|
||||||
|
maxfd = os.sysconf("SC_OPEN_MAX")
|
||||||
|
except (AttributeError, ValueError):
|
||||||
|
maxfd = 1024
|
||||||
|
|
||||||
|
for fd in range(0, maxfd):
|
||||||
|
try:
|
||||||
|
os.close(fd)
|
||||||
|
except OSError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
os.open(os.devnull, os.O_RDWR)
|
||||||
|
|
||||||
|
# Duplicate standard input to standard output and standard error.
|
||||||
|
os.dup2(0, 1)
|
||||||
|
os.dup2(0, 2)
|
||||||
|
|
||||||
# stdin always from /dev/null
|
|
||||||
sys.stdin = open('/dev/null', 'r')
|
|
||||||
|
|
||||||
child_pid = None
|
child_pid = None
|
||||||
|
|
||||||
@@ -1612,8 +1625,8 @@ def main(argv):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
opts, args = getopt.getopt(sys.argv[1:], 'fenoah',
|
opts, args = getopt.getopt(sys.argv[1:], 'fenoah',
|
||||||
['help', 'no-daemon', 'no-poll', 'no-stderr', 'no-stdout',
|
['help', 'no-daemon', 'no-poll', 'no-stderr', 'no-stdout',
|
||||||
'no-autoconnect'])
|
'no-autoconnect'])
|
||||||
except getopt.GetoptError:
|
except getopt.GetoptError:
|
||||||
# Print help information and exit
|
# Print help information and exit
|
||||||
usage()
|
usage()
|
||||||
@@ -1697,4 +1710,3 @@ if __name__ == '__main__':
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
gobject.threads_init()
|
gobject.threads_init()
|
||||||
main(sys.argv)
|
main(sys.argv)
|
||||||
|
|
||||||
|
|||||||
@@ -977,7 +977,7 @@ class BaseWirelessInterface(BaseInterface):
|
|||||||
if not wpa_pass_path: return None
|
if not wpa_pass_path: return None
|
||||||
key_pattern = re.compile('network={.*?\spsk=(.*?)\n}.*',
|
key_pattern = re.compile('network={.*?\spsk=(.*?)\n}.*',
|
||||||
re.I | re.M | re.S)
|
re.I | re.M | re.S)
|
||||||
cmd = [wpa_pass_path, network['essid'], network['key']]
|
cmd = [wpa_pass_path, network['essid'], str(network['key'])]
|
||||||
if self.verbose: print cmd
|
if self.verbose: print cmd
|
||||||
return misc.RunRegex(key_pattern, misc.Run(cmd))
|
return misc.RunRegex(key_pattern, misc.Run(cmd))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user