From 454770e5e99aada3d10f38b2977fff60b7e0156d Mon Sep 17 00:00:00 2001 From: Dan O'Reilly Date: Sat, 28 Feb 2009 16:01:26 -0500 Subject: [PATCH 1/5] Add support for using resolvconf instead of directly editing /etc/resolv.conf if it's available. --- wicd/misc.py | 8 +++-- wicd/networking.py | 26 ++++++++-------- wicd/wnettools.py | 77 +++++++++++++++++++++++++++++----------------- 3 files changed, 67 insertions(+), 44 deletions(-) diff --git a/wicd/misc.py b/wicd/misc.py index feafbf7..b0aaca5 100644 --- a/wicd/misc.py +++ b/wicd/misc.py @@ -96,6 +96,10 @@ def Run(cmd, include_stderr=False, return_pipe=False, return_obj=False): else: err = None fds = False + if return_obj: + std_in = PIPE + else: + std_in = None # We need to make sure that the results of the command we run # are in English, so we set up a temporary environment. @@ -106,8 +110,8 @@ def Run(cmd, include_stderr=False, return_pipe=False, return_obj=False): tmpenv["LANG"] = __LANG try: - f = Popen(cmd, shell=False, stdout=PIPE, stderr=err, close_fds=fds, - cwd='/', env=tmpenv) + f = Popen(cmd, shell=False, stdout=PIPE, stdin=std_in, stderr=err, + close_fds=fds, cwd='/', env=tmpenv) except OSError, e: print "Running command %s failed: %s" % (str(cmd), str(e)) return "" diff --git a/wicd/networking.py b/wicd/networking.py index efb62c5..52c52c7 100644 --- a/wicd/networking.py +++ b/wicd/networking.py @@ -420,7 +420,7 @@ class ConnectThread(threading.Thread): return @abortable - def set_dns_addresses(self): + def set_dns_addresses(self, iface): """ Set the DNS address(es). If static DNS servers or global DNS servers are specified, set them. @@ -428,19 +428,19 @@ class ConnectThread(threading.Thread): """ if self.network.get('use_global_dns'): - BACKEND.SetDNS(misc.Noneify(self.global_dns_1), - misc.Noneify(self.global_dns_2), - misc.Noneify(self.global_dns_3), - misc.Noneify(self.global_dns_dom), - misc.Noneify(self.global_search_dom)) + iface.SetDNS(misc.Noneify(self.global_dns_1), + misc.Noneify(self.global_dns_2), + misc.Noneify(self.global_dns_3), + misc.Noneify(self.global_dns_dom), + misc.Noneify(self.global_search_dom)) elif self.network.get('use_static_dns') and (self.network.get('dns1') or self.network.get('dns2') or self.network.get('dns3')): self.SetStatus('setting_static_dns') - BACKEND.SetDNS(self.network.get('dns1'), - self.network.get('dns2'), - self.network.get('dns3'), - self.network.get('dns_domain'), - self.network.get('search_domain')) + iface.SetDNS(self.network.get('dns1'), + self.network.get('dns2'), + self.network.get('dns3'), + self.network.get('dns_domain'), + self.network.get('search_domain')) @abortable def release_dhcp_clients(self, iface): @@ -799,7 +799,7 @@ class WirelessConnectThread(ConnectThread): # Set up gateway, IP address, and DNS servers. self.set_broadcast_address(wiface) self.set_ip_address(wiface) - self.set_dns_addresses() + self.set_dns_addresses(wiface) # Run post-connection script. self.run_script_if_needed(self.after_script, 'post-connection', @@ -985,7 +985,7 @@ class WiredConnectThread(ConnectThread): # Set gateway, IP adresses, and DNS servers. self.set_broadcast_address(liface) self.set_ip_address(liface) - self.set_dns_addresses() + self.set_dns_addresses(liface) # Run post-connection script. self.run_script_if_needed(self.after_script, 'post-connection', 'wired', diff --git a/wicd/wnettools.py b/wicd/wnettools.py index 774bb6d..fdffe5f 100644 --- a/wicd/wnettools.py +++ b/wicd/wnettools.py @@ -69,7 +69,7 @@ blacklist_strict = '!"#$%&\'()*+,./:;<=>?@[\\]^`{|}~ ' blacklist_norm = ";`$!*|><&\\" blank_trans = maketrans("", "") -__all__ = ["SetDNS", "GetDefaultGateway", "GetWiredInterfaces", +__all__ = ["GetDefaultGateway", "GetWiredInterfaces", "GetWirelessInterfaces", "IsValidWpaSuppDriver"] def _sanitize_string(string): @@ -84,33 +84,6 @@ def _sanitize_string_strict(string): else: return string -def SetDNS(dns1=None, dns2=None, dns3=None, dns_dom=None, search_dom=None): - """ Set the DNS of the system to the specified DNS servers. - - Opens up resolv.conf and writes in the nameservers. - - Keyword arguments: - dns1 -- IP address of DNS server 1 - dns2 -- IP address of DNS server 2 - dns3 -- IP address of DNS server 3 - dns_dom -- DNS domain - search_dom -- DNS search domain - - """ - resolv = open("/etc/resolv.conf", "w") - if dns_dom: - resolv.write("domain %s\n" % dns_dom) - if search_dom: - resolv.write('search %s\n' % search_dom) - for dns in [dns1, dns2, dns3]: - if dns: - if misc.IsValidIP(dns): - print 'Setting DNS : ' + dns - resolv.write('nameserver ' + dns + '\n') - else: - print 'DNS IP is not a valid IP address, not writing to resolv.conf' - resolv.close() - def GetDefaultGateway(): """ Attempts to determine the default gateway by parsing route -n. """ route_info = misc.Run("route -n") @@ -286,6 +259,11 @@ class BaseInterface(object): self.CheckWirelessTools() self.CheckSudoApplications() self.CheckRouteFlushTool() + self.CheckResolvConf() + + def CheckResolvConf(self): + """ Checks for the existence of resolvconf.""" + self.resolvconf_cmd = self._find_program_path("resolvconf") def CheckDHCP(self): """ Check for the existence of valid DHCP clients. @@ -513,7 +491,48 @@ class BaseInterface(object): return if self.verbose: print cmd misc.Run(cmd) - + + def SetDNS(self, dns1=None, dns2=None, dns3=None, + dns_dom=None, search_dom=None): + """ Set the DNS of the system to the specified DNS servers. + + Opens up resolv.conf and writes in the nameservers. + + Keyword arguments: + dns1 -- IP address of DNS server 1 + dns2 -- IP address of DNS server 2 + dns3 -- IP address of DNS server 3 + dns_dom -- DNS domain + search_dom -- DNS search domain + + """ + resolv_params = "" + if dns_dom: + resolv_params = ''.join([resolv_params, 'domain ', dns_dom, '\n']) + if search_dom: + resolv_params = ''.join([resolv_params, 'search ', search_dom, + '\n']) + valid_dns_list = ['nameserver'] + for dns in [dns1, dns2, dns3]: + if dns: + if misc.IsValidIP(dns): + print 'Setting DNS : ' + dns + valid_dns_list.append(dns) + else: + print 'DNS IP is not a valid IP address, skipping' + # Make sure we have more than just 'nameserver' in the list. + if len(valid_dns_list) > 1: + resolv_params += ' '.join(valid_dns_list) + '\n' + + if self.resolvconf_cmd: + print "running resolvconf" + p = misc.Run(' '.join([self.resolvconf_cmd, '-a', self.iface]), + include_stderr=True, return_obj=True) + p.communicate(input=resolv_params)[0] + else: + resolv = open("/etc/resolv.conf", "w") + resolv.write(resolv_params + "\n") + resolv.close() def FlushRoutes(self): """ Flush network routes for this device. """ From 1327bfcc32880acb48d0fad94cb057c61d6f6ae7 Mon Sep 17 00:00:00 2001 From: Andrew Psaltis Date: Sun, 8 Mar 2009 17:38:47 -0400 Subject: [PATCH 2/5] Added an init script for Lunar Linux. --- in/init=lunar=wicd.in | 13 +++++++++++++ setup.py | 3 +++ 2 files changed, 16 insertions(+) create mode 100644 in/init=lunar=wicd.in diff --git a/in/init=lunar=wicd.in b/in/init=lunar=wicd.in new file mode 100644 index 0000000..2045aef --- /dev/null +++ b/in/init=lunar=wicd.in @@ -0,0 +1,13 @@ +#!/bin/bash +# +# Startup script for wicd +# +# chkconfig: 345 99 01 +# +# description: wicd wireless/wired internet connection daemon +# +# processname: wicd +# pidfile: %PIDFILE% +# + +. /lib/lsb.init_functions $1 diff --git a/setup.py b/setup.py index f7c6e3a..b96de8d 100755 --- a/setup.py +++ b/setup.py @@ -162,6 +162,9 @@ class configure(Command): self.initfile = 'init/pld/wicd' elif os.path.exists('/usr/bin/crux'): self.init = '/etc/rc.d/' + elif os.path.exists('/etc/lunar.release'): + self.init='/etc/init.d/' + self.initfile = 'init/lunar/wicd' else: self.init = 'FAIL' self.no_install_init = True From 98277aafb28366224bea564e85053b1a491331ad Mon Sep 17 00:00:00 2001 From: Andrew Psaltis Date: Sun, 8 Mar 2009 18:02:44 -0400 Subject: [PATCH 3/5] Fixed the Lunar init script. --- in/init=lunar=wicd.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100644 => 100755 in/init=lunar=wicd.in diff --git a/in/init=lunar=wicd.in b/in/init=lunar=wicd.in old mode 100644 new mode 100755 index 2045aef..83698ff --- a/in/init=lunar=wicd.in +++ b/in/init=lunar=wicd.in @@ -10,4 +10,4 @@ # pidfile: %PIDFILE% # -. /lib/lsb.init_functions $1 +. /lib/lsb/init_functions $1 From d336a0f42dad899b35d264b1f13b1241f8fc1bef Mon Sep 17 00:00:00 2001 From: Andrew Psaltis Date: Sun, 8 Mar 2009 18:31:36 -0400 Subject: [PATCH 4/5] Fixed the fix. --- in/init=lunar=wicd.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/in/init=lunar=wicd.in b/in/init=lunar=wicd.in index 83698ff..b16ff30 100755 --- a/in/init=lunar=wicd.in +++ b/in/init=lunar=wicd.in @@ -10,4 +10,4 @@ # pidfile: %PIDFILE% # -. /lib/lsb/init_functions $1 +. /lib/lsb/init-functions $1 From 79f64e4180a06c1b7c851ecebb6cfe9ee5750e39 Mon Sep 17 00:00:00 2001 From: Dan O'Reilly Date: Sun, 8 Mar 2009 23:03:04 -0400 Subject: [PATCH 5/5] Undoing accidental commit.