mirror of
https://github.com/gryf/wicd.git
synced 2025-12-23 14:42:29 +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 dbus import Int32
|
||||
|
||||
class ConfigManager(RawConfigParser):
|
||||
""" A class that can be used to manage a given configuration file. """
|
||||
@@ -108,6 +109,12 @@ class ConfigManager(RawConfigParser):
|
||||
ret = int(ret)
|
||||
except (ValueError, TypeError):
|
||||
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
|
||||
|
||||
def get(self, *args, **kargs):
|
||||
|
||||
@@ -452,7 +452,6 @@ class WicdDaemon(dbus.service.Object):
|
||||
"""
|
||||
return int(self.signal_display_type)
|
||||
|
||||
|
||||
@dbus.service.method('org.wicd.daemon')
|
||||
def SetSignalDisplayType(self, value):
|
||||
""" 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.
|
||||
if (property.strip()).endswith("script"):
|
||||
print "Setting script properties through the daemon is not" \
|
||||
+ " permitted."
|
||||
+ " permitted."
|
||||
return False
|
||||
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.after_script = self.GetWirelessProperty(id, 'afterscript')
|
||||
self.wifi.disconnect_script = self.GetWirelessProperty(id,
|
||||
'disconnectscript')
|
||||
'disconnectscript')
|
||||
print 'Connecting to wireless network ' + self.LastScan[id]['essid']
|
||||
self.daemon.wired_bus.wired.Disconnect()
|
||||
self.daemon.SetForcedDisconnect(False)
|
||||
@@ -1567,14 +1566,12 @@ def daemonize():
|
||||
|
||||
# Decouple from parent environment to stop us from being a zombie.
|
||||
os.setsid()
|
||||
os.umask(0)
|
||||
|
||||
# Fork the second time to prevent us from opening a file that will
|
||||
# become our controlling terminal.
|
||||
try:
|
||||
pid = os.fork()
|
||||
if pid > 0:
|
||||
print wpath.pidfile
|
||||
dirname = os.path.dirname(wpath.pidfile)
|
||||
if not os.path.exists(dirname):
|
||||
os.makedirs(dirname)
|
||||
@@ -1582,18 +1579,34 @@ def daemonize():
|
||||
pidfile.write(str(pid) + '\n')
|
||||
pidfile.close()
|
||||
sys.exit(0)
|
||||
else:
|
||||
os.umask(0)
|
||||
os.chdir('/')
|
||||
except OSError, e:
|
||||
print >> sys.stderr, "Fork #2 failed: %d (%s)" % (e.errno, e.strerror)
|
||||
sys.exit(1)
|
||||
|
||||
sys.stdout.flush()
|
||||
sys.stderr.flush()
|
||||
os.close(sys.__stdin__.fileno())
|
||||
os.close(sys.__stdout__.fileno())
|
||||
os.close(sys.__stderr__.fileno())
|
||||
sys.stdin.close()
|
||||
sys.stdout.close()
|
||||
sys.stderr.close()
|
||||
|
||||
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
|
||||
|
||||
@@ -1612,8 +1625,8 @@ def main(argv):
|
||||
|
||||
try:
|
||||
opts, args = getopt.getopt(sys.argv[1:], 'fenoah',
|
||||
['help', 'no-daemon', 'no-poll', 'no-stderr', 'no-stdout',
|
||||
'no-autoconnect'])
|
||||
['help', 'no-daemon', 'no-poll', 'no-stderr', 'no-stdout',
|
||||
'no-autoconnect'])
|
||||
except getopt.GetoptError:
|
||||
# Print help information and exit
|
||||
usage()
|
||||
@@ -1697,4 +1710,3 @@ if __name__ == '__main__':
|
||||
sys.exit(1)
|
||||
gobject.threads_init()
|
||||
main(sys.argv)
|
||||
|
||||
|
||||
@@ -977,7 +977,7 @@ class BaseWirelessInterface(BaseInterface):
|
||||
if not wpa_pass_path: return None
|
||||
key_pattern = re.compile('network={.*?\spsk=(.*?)\n}.*',
|
||||
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
|
||||
return misc.RunRegex(key_pattern, misc.Run(cmd))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user