/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

  • Committer: Björn Påhlsson
  • Date: 2010-09-02 18:53:38 UTC
  • mto: (237.4.3 mandos-release)
  • mto: This revision was merged to the branch mainline in revision 421.
  • Revision ID: belorn@fukt.bsnet.se-20100902185338-d1022sv517txn3sb
early commit to ease todays coding

Show diffs side-by-side

added added

removed removed

Lines of Context:
83
83
 
84
84
version = "1.0.14"
85
85
 
86
 
#logger = logging.getLogger(u'mandos')
87
86
logger = logging.Logger(u'mandos')
88
87
syslogger = (logging.handlers.SysLogHandler
89
88
             (facility = logging.handlers.SysLogHandler.LOG_DAEMON,
322
321
        self.checker_command = config[u"checker"]
323
322
        self.current_checker_command = None
324
323
        self.last_connect = None
 
324
        self.approvals_pending = 0
325
325
        self._approved = None
326
326
        self.approved_by_default = config.get(u"approved_by_default",
327
 
                                              True)
328
 
        self.approvals_pending = 0
 
327
                                              False)
329
328
        self.approved_delay = string_to_delta(
330
329
            config[u"approved_delay"])
331
330
        self.approved_duration = string_to_delta(
332
331
            config[u"approved_duration"])
333
332
        self.changedstate = multiprocessing_manager.Condition(multiprocessing_manager.Lock())
334
 
    
 
333
 
335
334
    def send_changedstate(self):
336
335
        self.changedstate.acquire()
337
336
        self.changedstate.notify_all()
701
700
    # dbus.service.Object doesn't use super(), so we can't either.
702
701
    
703
702
    def __init__(self, bus = None, *args, **kwargs):
704
 
        self._approvals_pending = 0
705
703
        self.bus = bus
706
704
        Client.__init__(self, *args, **kwargs)
707
705
        # Only now, when this client is initialized, can it show up on
711
709
                                  + self.name.replace(u".", u"_")))
712
710
        DBusObjectWithProperties.__init__(self, self.bus,
713
711
                                          self.dbus_object_path)
714
 
 
715
 
    #Could possible return a bool(self._approvals_pending),
716
 
    #but this could mess up approvals_pending += 1 XXX 
717
 
    def _get_approvals_pending(self):
718
 
        return self._approvals_pending
719
 
    def _set_approvals_pending(self, value):
720
 
        old_value = self._approvals_pending
721
 
        self._approvals_pending = value
722
 
        bval = bool(value)
723
 
        if (hasattr(self, "dbus_object_path")
724
 
            and bval is not bool(old_value)):
725
 
            dbus_bool = dbus.Boolean(bval, variant_level=1)
726
 
            self.PropertyChanged(dbus.String(u"approved_pending"),
727
 
                                 dbus_bool)
728
 
 
729
 
    approvals_pending = property(_get_approvals_pending,
730
 
                                 _set_approvals_pending)
731
 
    del _get_approvals_pending, _set_approvals_pending
732
712
    
733
713
    @staticmethod
734
714
    def _datetime_to_dbus(dt, variant_level=0):
829
809
        return False
830
810
    
831
811
    def approve(self, value=True):
832
 
        self.send_changedstate()
833
812
        self._approved = value
834
 
        gobject.timeout_add(self._timedelta_to_milliseconds(self.approved_duration),
835
 
                            self._reset_approved)
836
 
    
 
813
        gobject.timeout_add(self._timedelta_to_milliseconds(self.approved_duration, self._reset_approved))
 
814
 
 
815
    def approved_pending(self):
 
816
        return self.approvals_pending > 0
 
817
 
837
818
    
838
819
    ## D-Bus methods, signals & properties
839
820
    _interface = u"se.bsnet.fukt.Mandos.Client"
859
840
        pass
860
841
    
861
842
    # GotSecret - signal
862
 
    # XXXTEDDY Is sent after succesfull transfer of secret from mandos-server to mandos-client
 
843
    # Is sent after succesfull transfer of secret from mandos-server to mandos-client
863
844
    @dbus.service.signal(_interface)
864
845
    def GotSecret(self):
865
846
        "D-Bus signal"
917
898
    # approved_pending - property
918
899
    @dbus_service_property(_interface, signature=u"b", access=u"read")
919
900
    def approved_pending_dbus_property(self):
920
 
        return dbus.Boolean(bool(self.approvals_pending))
 
901
        return dbus.Boolean(self.approved_pending())
921
902
    
922
903
    # approved_by_default - property
923
904
    @dbus_service_property(_interface, signature=u"b",
1341
1322
              self).process_request(request, client_address)
1342
1323
        self.child_pipe.close()
1343
1324
        self.add_pipe(parent_pipe)
1344
 
 
 
1325
        
1345
1326
    def add_pipe(self, parent_pipe):
1346
1327
        """Dummy function; override as necessary"""
1347
1328
        pass
1463
1444
        logger.debug(u"Handling IPC: FD = %d, condition = %s", source,
1464
1445
                     conditions_string)
1465
1446
 
1466
 
        # XXXTEDDY error or the other end of multiprocessing.Pipe has closed
 
1447
        # error or the other end of multiprocessing.Pipe has closed
1467
1448
        if condition & gobject.IO_HUP or condition & gobject.IO_ERR:
1468
1449
            return False
1469
1450
        
1510
1491
                parent_pipe.send(('function',))
1511
1492
            else:
1512
1493
                parent_pipe.send(('data', client_object.__getattribute__(attrname)))
1513
 
        
 
1494
 
1514
1495
        if command == 'setattr':
1515
1496
            attrname = request[1]
1516
1497
            value = request[2]
1517
1498
            setattr(client_object, attrname, value)
1518
 
 
 
1499
            
1519
1500
        return True
1520
1501
 
1521
1502
 
1709
1690
                        u"interval": u"5m",
1710
1691
                        u"checker": u"fping -q -- %%(host)s",
1711
1692
                        u"host": u"",
1712
 
                        u"approved_delay": u"0s",
 
1693
                        u"approved_delay": u"5m",
1713
1694
                        u"approved_duration": u"1s",
1714
1695
                        }
1715
1696
    client_config = configparser.SafeConfigParser(client_defaults)