1
0
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:
Dan O'Reilly
2009-03-25 20:19:11 -04:00
parent 42bb9aa487
commit d7f2fd4780
3 changed files with 172 additions and 153 deletions

View File

@@ -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):

View File

@@ -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. """
@@ -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
@@ -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)

View File

@@ -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))