~ubuntu-branches/ubuntu/saucy/wicd/saucy

« back to all changes in this revision

Viewing changes to debian/patches/07-add_resolvconf_support.patch

  • Committer: Bazaar Package Importer
  • Author(s): David Paleino
  • Date: 2009-06-22 17:59:27 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20090622175927-iax3alden0bmj6zg
Tags: 1.6.1-3
* debian/config, debian/templates updated:
  - only show users to add to netdev, skip those who are already
    members (Closes: #534138)
  - gracefully handle upgrades from previous broken versions, where
    debconf set a value of ${default} for wicd/users
    (Closes: #532112)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
Author: David Paleino <d.paleino@gmail.com>
2
 
Support Debian's resolvconf mechanism.
3
 
---
4
 
 wicd/networking.py |   11 ++++++-----
5
 
 wicd/wnettools.py  |   53 +++++++++++++++++++++++++++++++++++++++++++++++------
6
 
 2 files changed, 53 insertions(+), 11 deletions(-)
7
 
 
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):
11
 
     else:
12
 
         return string
13
 
 
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.
17
 
 
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.
21
 
 
22
 
     Keyword arguments:
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)
27
 
 
28
 
     """
29
 
-    resolv = open("/etc/resolv.conf","w")
30
 
+
31
 
+    resolvconf = False
32
 
+    paths = ['/sbin/', '/usr/sbin/', '/bin/', '/usr/bin/',
33
 
+             '/usr/local/sbin/', '/usr/local/bin/']
34
 
+    for path in paths:
35
 
+        if os.access("%s%s" % (path, "resolvconf"), os.F_OK):
36
 
+            resolvconf = True
37
 
+            break
38
 
+
39
 
+    if resolvconf:
40
 
+        dnslist = ""
41
 
+    else:
42
 
+        resolv = open("/etc/resolv.conf","w")
43
 
+
44
 
     for dns in [dns1, dns2, dns3]:
45
 
         if dns:
46
 
             if misc.IsValidIP(dns):
47
 
                 print 'Setting DNS : ' + dns
48
 
-                resolv.write('nameserver ' + dns + '\n')
49
 
+                if resolvconf:
50
 
+                    dnslist += dns + ' '
51
 
+                else:
52
 
+                    resolv.write('nameserver ' + dns + '\n')
53
 
             else:
54
 
-                print 'DNS IP is not a valid IP address, not writing to resolv.conf'
55
 
-    resolv.close()
56
 
+                if resolvconf:
57
 
+                    print 'DNS IP is not a valid IP address, not adding to resolvconf call'
58
 
+                else:
59
 
+                    print 'DNS IP is not a valid IP address, not writing to resolv.conf'
60
 
+
61
 
+    if resolvconf:
62
 
+        if not dnslist:
63
 
+            print 'No valid DNS has been provided for resolvconf'
64
 
+        elif not iface:
65
 
+            print 'No valid interface has been provided for resolvconf, please file a bug'
66
 
+        else:
67
 
+            print dnslist
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]
71
 
+    else:
72
 
+        resolv.close()
73
 
 
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
79
 
         self.IP_FOUND = False
80
 
+        self.RESOLVCONF = False
81
 
         self.flush_tool = flush_tool
82
 
         self.link_detect = None
83
 
         self.Check()
84
 
@@ -314,6 +348,11 @@ class Interface(object):
85
 
             self.ip_cmd = None
86
 
             self.IP_FOUND = False
87
 
 
88
 
+        if self._find_client_path("resolvconf"):
89
 
+            self.RESOLVCONF = True
90
 
+        else:
91
 
+            self.RESOLVCONF = False
92
 
+
93
 
     def Up(self):
94
 
         """ Bring the network interface up.
95
 
 
96
 
@@ -338,6 +377,8 @@ class Interface(object):
97
 
         cmd = 'ifconfig ' + self.iface + ' down'
98
 
         if self.verbose: print cmd
99
 
         misc.Run(cmd)
100
 
+        if self.RESOLVCONF:
101
 
+            misc.Run(["/sbin/resolvconf", "-d", self.iface])
102
 
         return True
103
 
 
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)
109
 
                 return
110
 
             
111
 
-    def set_dns_addresses(self):
112
 
+    def set_dns_addresses(self, iface):
113
 
         """ Set the DNS address(es).
114
 
 
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),
122
 
+                             iface)
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)
129
 
 
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)
138
 
         
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()
148
 
         
149
 
         # Run post-connection script.