1
Author: David Paleino <d.paleino@gmail.com>
2
Support Debian's resolvconf mechanism.
4
wicd/networking.py | 11 ++++++-----
5
wicd/wnettools.py | 53 +++++++++++++++++++++++++++++++++++++++++++++++------
6
2 files changed, 53 insertions(+), 11 deletions(-)
8
--- wicd-1.5.9.orig/wicd/wnettools.py
9
+++ wicd-1.5.9/wicd/wnettools.py
10
@@ -81,26 +81,59 @@ def _sanitize_string_strict(string):
14
-def SetDNS(dns1=None, dns2=None, dns3=None):
15
+def SetDNS(dns1=None, dns2=None, dns3=None, iface=None):
16
""" Set the DNS of the system to the specified DNS servers.
18
- Opens up resolv.conf and writes in the nameservers.
19
+ Uses /sbin/resolvconf if present, otherwise opens up resolv.conf and
20
+ writes in the nameservers.
23
dns1 -- IP address of DNS server 1
24
dns2 -- IP address of DNS server 2
25
dns3 -- IP address of DNS server 3
26
+ iface -- Interface to apply DNS addresses to (resolvconf)
29
- resolv = open("/etc/resolv.conf","w")
32
+ paths = ['/sbin/', '/usr/sbin/', '/bin/', '/usr/bin/',
33
+ '/usr/local/sbin/', '/usr/local/bin/']
35
+ if os.access("%s%s" % (path, "resolvconf"), os.F_OK):
42
+ resolv = open("/etc/resolv.conf","w")
44
for dns in [dns1, dns2, dns3]:
46
if misc.IsValidIP(dns):
47
print 'Setting DNS : ' + dns
48
- resolv.write('nameserver ' + dns + '\n')
50
+ dnslist += dns + ' '
52
+ resolv.write('nameserver ' + dns + '\n')
54
- print 'DNS IP is not a valid IP address, not writing to resolv.conf'
57
+ print 'DNS IP is not a valid IP address, not adding to resolvconf call'
59
+ print 'DNS IP is not a valid IP address, not writing to resolv.conf'
63
+ print 'No valid DNS has been provided for resolvconf'
65
+ print 'No valid interface has been provided for resolvconf, please file a bug'
68
+ from subprocess import Popen, PIPE, STDOUT
69
+ p = Popen(['resolvconf', '-a', iface.iface], stdout=PIPE, stdin=PIPE, stderr=STDOUT)
70
+ resolvconf_stdout = p.communicate(input='nameserver '+dnslist.strip())[0]
74
def GetDefaultGateway():
75
""" Attempts to determine the default gateway by parsing route -n. """
76
@@ -175,6 +208,7 @@ class Interface(object):
77
self.MIITOOL_FOUND = False
78
self.ETHTOOL_FOUND = False
80
+ self.RESOLVCONF = False
81
self.flush_tool = flush_tool
82
self.link_detect = None
84
@@ -314,6 +348,11 @@ class Interface(object):
88
+ if self._find_client_path("resolvconf"):
89
+ self.RESOLVCONF = True
91
+ self.RESOLVCONF = False
94
""" Bring the network interface up.
96
@@ -338,6 +377,8 @@ class Interface(object):
97
cmd = 'ifconfig ' + self.iface + ' down'
98
if self.verbose: print cmd
100
+ if self.RESOLVCONF:
101
+ misc.Run(["/sbin/resolvconf", "-d", self.iface])
104
def SetAddress(self, ip=None, netmask=None, broadcast=None):
105
--- wicd-1.5.9.orig/wicd/networking.py
106
+++ wicd-1.5.9/wicd/networking.py
107
@@ -290,7 +290,7 @@ class ConnectThread(threading.Thread):
108
self.abort_connection(dhcp_status)
111
- def set_dns_addresses(self):
112
+ def set_dns_addresses(self, iface):
113
""" Set the DNS address(es).
115
If static DNS servers or global DNS servers are specified, set them.
116
@@ -300,12 +300,13 @@ class ConnectThread(threading.Thread):
117
if self.network.get('use_global_dns'):
118
wnettools.SetDNS(misc.Noneify(self.global_dns_1),
119
misc.Noneify(self.global_dns_2),
120
- misc.Noneify(self.global_dns_3))
121
+ misc.Noneify(self.global_dns_3),
123
elif self.network.get('use_static_dns') and (self.network.get('dns1') or
124
self.network.get('dns2') or self.network.get('dns3')):
125
self.SetStatus('setting_static_dns')
126
wnettools.SetDNS(self.network.get('dns1'), self.network.get('dns2'),
127
- self.network.get('dns3'))
128
+ self.network.get('dns3'), iface)
130
def connect_aborted(self, reason):
131
""" Sets the thread status to aborted in a thread-safe way.
132
@@ -707,7 +708,7 @@ class WirelessConnectThread(ConnectThrea
133
self.set_broadcast_address(wiface)
134
self.abort_if_needed()
135
self.set_ip_address(wiface)
136
- self.set_dns_addresses()
137
+ self.set_dns_addresses(wiface)
139
# Run post-connection script.
140
self.abort_if_needed()
141
@@ -924,7 +925,7 @@ class WiredConnectThread(ConnectThread):
142
self.set_broadcast_address(liface)
143
self.abort_if_needed()
144
self.set_ip_address(liface)
145
- self.set_dns_addresses()
146
+ self.set_dns_addresses(liface)
147
self.abort_if_needed()
149
# Run post-connection script.