~jtaylor/ubuntu/lucid/wicd/CVE-2012-2095

« back to all changes in this revision

Viewing changes to wicd/networking.py

  • Committer: Bazaar Package Importer
  • Author(s): David Paleino
  • Date: 2008-12-24 17:37:13 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20081224173713-l9o484a46w2bq2eb
Tags: 1.5.7-1
* New upstream release (Closes: #503737)
* debian/control:
  - added some runtime dependencies (not really, but used by most 
    users) to wicd (Closes: #503739)
  - added Conflicts: network-manager (Closes: #509051)
  - added Suggests on pm-utils, since we now also have those
    functionalities
  - update Vcs-* and Maintainer fields to reflect injection into
    PAPT
* debian/postrm added:
  - removes runtime-generated files (Closes: #503747)
* debian/patches:
  - 02-fix_logfile_perms.patch added, sets permissions of 
    /var/log/wicd/wicd.log to root:adm (Closes: #503749)
  - 03-fix_lintian_manpage_warning.patch added, gives a more
    meaningful whatis entry
* debian/rules:
  - get-orig-source target to ease upstream tarball fetch
  - ensure right permissions are set in install target
  - using dh7-style rules
* debian/README.source added
* debian/docs removed
* debian/copyright fixed:
  - added copyright year to in/man*
  - removed useless escaping of '=' in filenames
  - fixed pointer to GPL-2

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
# and helped keep this project moving.
42
42
#
43
43
 
44
 
import re
 
44
import time
45
45
import threading
46
46
import thread
47
 
import misc
48
 
import time
49
47
 
50
 
import wicd.wpath as wpath
51
 
import wicd.wnettools as wnettools
 
48
# wicd imports 
 
49
from wicd import misc
 
50
from wicd import wpath
 
51
from wicd import wnettools
52
52
 
53
53
if __name__ == '__main__':
54
54
    wpath.chdir(__file__)
169
169
        self.before_script = before_script
170
170
        self.after_script = after_script
171
171
        self.disconnect_script = disconnect_script
172
 
        self.should_die = False
 
172
        self._should_die = False
173
173
        self.abort_reason = ""
174
174
 
175
175
        self.global_dns_1 = gdns1
183
183
        self.debug = debug
184
184
        
185
185
        self.SetStatus('interface_down')
 
186
        
 
187
    def get_should_die(self):
 
188
        return self._should_die
 
189
    
 
190
    def set_should_die(self, val):
 
191
        self.lock.acquire()
 
192
        try:
 
193
            self._should_die = val
 
194
        finally:
 
195
            self.lock.release()
 
196
    
 
197
    should_die = property(get_should_die, set_should_die)
186
198
 
187
199
 
188
200
    def SetStatus(self, status):
304
316
        """
305
317
        if self.abort_reason:
306
318
            reason = self.abort_reason
307
 
        self.SetStatus(reason)
 
319
        self.connecting_message = reason
308
320
        self.is_aborted = True
309
321
        self.abort_msg = reason
310
322
        self.is_connecting = False
311
323
        print 'exiting connection thread'
312
324
        
313
 
    def abort_connection(self, reason):
 
325
    def abort_connection(self, reason=""):
314
326
        """ Schedule a connection abortion for the given reason. """
315
327
        self.abort_reason = reason
316
328
        self.should_die = True
329
341
        
330
342
    def abort_if_needed(self):
331
343
        """ Abort the thread is it has been requested. """
332
 
        if self.should_die:
333
 
            self.connect_aborted('aborted')
334
 
            thread.exit()
 
344
        self.lock.acquire()
 
345
        try:
 
346
            if self._should_die:
 
347
                self.connect_aborted('aborted')
 
348
                thread.exit()
 
349
        finally:
 
350
            self.lock.release()
335
351
            
336
352
    def put_iface_up(self, iface):
337
353
        """ Bring up given interface. """
363
379
    def LoadInterfaces(self):
364
380
        """ Load the wnettools controls for the wired/wireless interfaces. """
365
381
        self.wiface = wnettools.WirelessInterface(self.wireless_interface,
366
 
                                                  self.debug, self.wpa_driver)
 
382
                                                  self.dhcp_client, 
 
383
                                                  self.flush_tool, self.debug,
 
384
                                                  self.wpa_driver)
367
385
 
368
386
    def Scan(self, essid=None):
369
387
        """ Scan for available wireless networks.
391
409
                else:
392
410
                    return 0
393
411
                
 
412
        if not self.wireless_interface: return []
 
413
        
394
414
        wiface = self.wiface
395
415
 
396
416
        # Prepare the interface for scanning
415
435
        network -- network to connect to
416
436
 
417
437
        """
 
438
        if not self.wireless_interface: return False
 
439
        
418
440
        self.connecting_thread = WirelessConnectThread(network,
419
441
            self.wireless_interface, self.wired_interface,
420
442
            self.wpa_driver, self.before_script, self.after_script,
645
667
        self.run_script_if_needed(self.before_script, 'pre-connection')
646
668
        self.abort_if_needed()
647
669
        
648
 
        # Dake down interface and clean up previous connections.
 
670
        # Take down interface and clean up previous connections.
649
671
        self.put_iface_down(wiface)
650
672
        self.abort_if_needed()
651
673
        self.release_dhcp_clients(wiface, liface)
700
722
    def generate_psk_and_authenticate(self, wiface):
701
723
        """ Generates a PSK and authenticates if necessary. 
702
724
        
703
 
        Generates a PSK using wpa_passphrase, and starts the authentication
704
 
        process if encryption is on.
 
725
        Generates a PSK, and starts the authentication process 
 
726
        if encryption is on.
705
727
        
706
728
        """
707
 
        def _sanitize(key):
708
 
            """ Escapes characters wpa_supplicant doesn't handle properly. """
709
 
            new_key = []
710
 
            blacklist = ["$", "`", "\""]
711
 
            for c in key:
712
 
                if c in blacklist:
713
 
                    new_key.append("\\" + c)
714
 
                else:
715
 
                    new_key.append(c)
716
 
            return ''.join(new_key)
717
 
        
718
 
        # Check to see if we need to generate a PSK (only for non-ralink
719
 
        # cards).
720
729
        if self.network.get('key'):
721
730
            self.SetStatus('generating_psk')
722
 
 
723
731
            print 'Generating psk...'
724
 
            key_pattern = re.compile('network={.*?\spsk=(.*?)\n}.*',
725
 
                                     re.I | re.M  | re.S)
726
 
            self.network['psk'] = misc.RunRegex(key_pattern,
727
 
                                misc.Run(''.join(['wpa_passphrase "',
728
 
                                         self.network['essid'], '" "', 
729
 
                                         _sanitize(self.network['key']), '"'])))
 
732
            self.network['psk'] = self.wiface.GeneratePSK(self.network)
730
733
            
731
 
            if not self.network['psk']:
 
734
            if not self.network.get('psk'):
732
735
                self.network['psk'] = self.network['key']
733
736
                print 'WARNING: PSK generation failed!  Falling back to ' + \
734
737
                      'wireless key.\nPlease report this error to the wicd ' + \
758
761
    def get_link_detect(self): return self._link_detect
759
762
    
760
763
    link_detect = property(get_link_detect, set_link_detect)
761
 
        
 
764
    
762
765
    def LoadInterfaces(self):
763
766
        """ Load the wnettools controls for the wired/wireless interfaces. """
764
 
        self.liface = wnettools.WiredInterface(self.wired_interface, self.debug)
 
767
        self.liface = wnettools.WiredInterface(self.wired_interface, 
 
768
                                               self.dhcp_client, self.flush_tool, 
 
769
                                               self.link_detect, self.debug)
765
770
 
766
771
    def CheckPluggedIn(self):
767
772
        """ Check whether the wired connection is plugged in.
779
784
        network -- network to connect to
780
785
 
781
786
        """
 
787
        if not self.wired_interface: return False
782
788
        self.connecting_thread = WiredConnectThread(network,
783
789
            self.wireless_interface, self.wired_interface,
784
790
            self.before_script, self.after_script,