/mandos/trunk

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/trunk

« back to all changes in this revision

Viewing changes to mandos

* debian/source/local-options: New; contains "--single-debian-patch".

Show diffs side-by-side

added added

removed removed

Lines of Context:
83
83
        SO_BINDTODEVICE = None
84
84
 
85
85
 
86
 
version = "1.4.1"
 
86
version = "1.3.1"
87
87
 
88
88
#logger = logging.getLogger('mandos')
89
89
logger = logging.Logger('mandos')
464
464
        if timeout is None:
465
465
            timeout = self.timeout
466
466
        self.last_checked_ok = datetime.datetime.utcnow()
467
 
        if self.disable_initiator_tag is not None:
468
 
            gobject.source_remove(self.disable_initiator_tag)
469
 
        if getattr(self, "enabled", False):
470
 
            self.disable_initiator_tag = (gobject.timeout_add
471
 
                                          (_timedelta_to_milliseconds
472
 
                                           (timeout), self.disable))
473
 
            self.expires = datetime.datetime.utcnow() + timeout
 
467
        gobject.source_remove(self.disable_initiator_tag)
 
468
        self.expires = datetime.datetime.utcnow() + timeout
 
469
        self.disable_initiator_tag = (gobject.timeout_add
 
470
                                      (_timedelta_to_milliseconds
 
471
                                       (timeout), self.disable))
474
472
    
475
473
    def need_approval(self):
476
474
        self.last_approval_request = datetime.datetime.utcnow()
893
891
        """ Modify a variable so that it's a property which announces
894
892
        its changes to DBus.
895
893
 
896
 
        transform_fun: Function that takes a value and a variant_level
897
 
                       and transforms it to a D-Bus type.
 
894
        transform_fun: Function that takes a value and transforms it
 
895
                       to a D-Bus type.
898
896
        dbus_name: D-Bus name of the variable
899
897
        type_func: Function that transform the value before sending it
900
898
                   to the D-Bus.  Default: no transform
907
905
                    type_func(getattr(self, attrname, None))
908
906
                    != type_func(value)):
909
907
                    dbus_value = transform_func(type_func(value),
910
 
                                                variant_level
911
 
                                                =variant_level)
 
908
                                                variant_level)
912
909
                    self.PropertyChanged(dbus.String(dbus_name),
913
910
                                         dbus_value)
914
911
            setattr(self, attrname, value)
1190
1187
        gobject.source_remove(self.disable_initiator_tag)
1191
1188
        self.disable_initiator_tag = None
1192
1189
        self.expires = None
1193
 
        time_to_die = _timedelta_to_milliseconds((self
1194
 
                                                  .last_checked_ok
1195
 
                                                  + self.timeout)
1196
 
                                                 - datetime.datetime
1197
 
                                                 .utcnow())
 
1190
        time_to_die = (self.
 
1191
                       _timedelta_to_milliseconds((self
 
1192
                                                   .last_checked_ok
 
1193
                                                   + self.timeout)
 
1194
                                                  - datetime.datetime
 
1195
                                                  .utcnow()))
1198
1196
        if time_to_die <= 0:
1199
1197
            # The timeout has passed
1200
1198
            self.disable()
1396
1394
                        return
1397
1395
                    
1398
1396
                    #wait until timeout or approved
 
1397
                    #x = float(client
 
1398
                    #          ._timedelta_to_milliseconds(delay))
1399
1399
                    time = datetime.datetime.now()
1400
1400
                    client.changedstate.acquire()
1401
1401
                    (client.changedstate.wait
1430
1430
                    sent_size += sent
1431
1431
                
1432
1432
                logger.info("Sending secret to %s", client.name)
1433
 
                # bump the timeout using extended_timeout
 
1433
                # bump the timeout as if seen
1434
1434
                client.checked_ok(client.extended_timeout)
1435
1435
                if self.server.use_dbus:
1436
1436
                    # Emit D-Bus signal
1516
1516
        except:
1517
1517
            self.handle_error(request, address)
1518
1518
        self.close_request(request)
1519
 
    
 
1519
            
1520
1520
    def process_request(self, request, address):
1521
1521
        """Start a new process to process the request."""
1522
 
        proc = multiprocessing.Process(target = self.sub_process_main,
1523
 
                                       args = (request,
1524
 
                                               address))
1525
 
        proc.start()
1526
 
        return proc
 
1522
        multiprocessing.Process(target = self.sub_process_main,
 
1523
                                args = (request, address)).start()
1527
1524
 
1528
1525
 
1529
1526
class MultiprocessingMixInWithPipe(MultiprocessingMixIn, object):
1535
1532
        """
1536
1533
        parent_pipe, self.child_pipe = multiprocessing.Pipe()
1537
1534
        
1538
 
        proc = MultiprocessingMixIn.process_request(self, request,
1539
 
                                                    client_address)
 
1535
        super(MultiprocessingMixInWithPipe,
 
1536
              self).process_request(request, client_address)
1540
1537
        self.child_pipe.close()
1541
 
        self.add_pipe(parent_pipe, proc)
 
1538
        self.add_pipe(parent_pipe)
1542
1539
    
1543
 
    def add_pipe(self, parent_pipe, proc):
 
1540
    def add_pipe(self, parent_pipe):
1544
1541
        """Dummy function; override as necessary"""
1545
1542
        raise NotImplementedError
1546
1543
 
1634
1631
    def server_activate(self):
1635
1632
        if self.enabled:
1636
1633
            return socketserver.TCPServer.server_activate(self)
1637
 
    
1638
1634
    def enable(self):
1639
1635
        self.enabled = True
1640
 
    
1641
 
    def add_pipe(self, parent_pipe, proc):
 
1636
    def add_pipe(self, parent_pipe):
1642
1637
        # Call "handle_ipc" for both data and EOF events
1643
1638
        gobject.io_add_watch(parent_pipe.fileno(),
1644
1639
                             gobject.IO_IN | gobject.IO_HUP,
1645
1640
                             functools.partial(self.handle_ipc,
1646
1641
                                               parent_pipe =
1647
 
                                               parent_pipe,
1648
 
                                               proc = proc))
1649
 
    
 
1642
                                               parent_pipe))
 
1643
        
1650
1644
    def handle_ipc(self, source, condition, parent_pipe=None,
1651
 
                   proc = None, client_object=None):
 
1645
                   client_object=None):
1652
1646
        condition_names = {
1653
1647
            gobject.IO_IN: "IN",   # There is data to read.
1654
1648
            gobject.IO_OUT: "OUT", # Data can be written (without
1663
1657
                                       for cond, name in
1664
1658
                                       condition_names.iteritems()
1665
1659
                                       if cond & condition)
1666
 
        # error, or the other end of multiprocessing.Pipe has closed
 
1660
        # error or the other end of multiprocessing.Pipe has closed
1667
1661
        if condition & (gobject.IO_ERR | condition & gobject.IO_HUP):
1668
 
            # Wait for other process to exit
1669
 
            proc.join()
1670
1662
            return False
1671
1663
        
1672
1664
        # Read a request from the child
1696
1688
                                 functools.partial(self.handle_ipc,
1697
1689
                                                   parent_pipe =
1698
1690
                                                   parent_pipe,
1699
 
                                                   proc = proc,
1700
1691
                                                   client_object =
1701
1692
                                                   client))
1702
1693
            parent_pipe.send(True)
2138
2129
        "Cleanup function; run on exit"
2139
2130
        service.cleanup()
2140
2131
        
2141
 
        multiprocessing.active_children()
2142
2132
        while tcp_server.clients:
2143
2133
            client = tcp_server.clients.pop()
2144
2134
            if use_dbus: