/mandos/release

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

« back to all changes in this revision

Viewing changes to mandos

Reorder TODO entries

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
# "AvahiService" class, and some lines in "main".
12
12
13
13
# Everything else is
14
 
# Copyright © 2008-2012 Teddy Hogeborn
15
 
# Copyright © 2008-2012 Björn Påhlsson
 
14
# Copyright © 2008-2011 Teddy Hogeborn
 
15
# Copyright © 2008-2011 Björn Påhlsson
16
16
17
17
# This program is free software: you can redistribute it and/or modify
18
18
# it under the terms of the GNU General Public License as published by
85
85
    except ImportError:
86
86
        SO_BINDTODEVICE = None
87
87
 
88
 
version = "1.5.0"
 
88
version = "1.4.1"
89
89
stored_state_file = "clients.pickle"
90
90
 
91
91
logger = logging.getLogger()
142
142
        self.gnupg.options.meta_interactive = False
143
143
        self.gnupg.options.homedir = self.tempdir
144
144
        self.gnupg.options.extra_args.extend(['--force-mdc',
145
 
                                              '--quiet',
146
 
                                              '--no-use-agent'])
 
145
                                              '--quiet'])
147
146
    
148
147
    def __enter__(self):
149
148
        return self
460
459
 
461
460
    @staticmethod
462
461
    def config_parser(config):
463
 
        """Construct a new dict of client settings of this form:
 
462
        """ Construct a new dict of client settings of this form:
464
463
        { client_name: {setting_name: value, ...}, ...}
465
 
        with exceptions for any special settings as defined above.
466
 
        NOTE: Must be a pure function. Must return the same result
467
 
        value given the same arguments.
468
 
        """
 
464
        with exceptions for any special settings as defined above"""
469
465
        settings = {}
470
466
        for client_name in config.sections():
471
467
            section = dict(config.items(client_name))
475
471
            # Reformat values from string types to Python types
476
472
            client["approved_by_default"] = config.getboolean(
477
473
                client_name, "approved_by_default")
478
 
            client["enabled"] = config.getboolean(client_name,
479
 
                                                  "enabled")
 
474
            client["enabled"] = config.getboolean(client_name, "enabled")
480
475
            
481
476
            client["fingerprint"] = (section["fingerprint"].upper()
482
477
                                     .replace(" ", ""))
502
497
            client["last_approval_request"] = None
503
498
            client["last_checked_ok"] = None
504
499
            client["last_checker_status"] = None
505
 
        
 
500
            if client["enabled"]:
 
501
                client["last_enabled"] = datetime.datetime.utcnow()
 
502
                client["expires"] = (datetime.datetime.utcnow()
 
503
                                     + client["timeout"])
 
504
            else:
 
505
                client["last_enabled"] = None
 
506
                client["expires"] = None
 
507
 
506
508
        return settings
507
509
        
508
510
        
515
517
        for setting, value in settings.iteritems():
516
518
            setattr(self, setting, value)
517
519
        
518
 
        if self.enabled:
519
 
            if not hasattr(self, "last_enabled"):
520
 
                self.last_enabled = datetime.datetime.utcnow()
521
 
            if not hasattr(self, "expires"):
522
 
                self.expires = (datetime.datetime.utcnow()
523
 
                                + self.timeout)
524
 
        else:
525
 
            self.last_enabled = None
526
 
            self.expires = None
527
 
       
528
520
        logger.debug("Creating client %r", self.name)
529
521
        # Uppercase and remove spaces from fingerprint for later
530
522
        # comparison purposes with return value from the fingerprint()
531
523
        # function
532
524
        logger.debug("  Fingerprint: %s", self.fingerprint)
533
 
        self.created = settings.get("created",
534
 
                                    datetime.datetime.utcnow())
 
525
        self.created = settings.get("created", datetime.datetime.utcnow())
535
526
 
536
527
        # attributes specific for this server instance
537
528
        self.checker = None
850
841
            # signatures other than "ay".
851
842
            if prop._dbus_signature != "ay":
852
843
                raise ValueError
853
 
            value = dbus.ByteArray(b''.join(chr(byte)
854
 
                                            for byte in value))
 
844
            value = dbus.ByteArray(''.join(unichr(byte)
 
845
                                           for byte in value))
855
846
        prop(value)
856
847
    
857
848
    @dbus.service.method(dbus.PROPERTIES_IFACE, in_signature="s",
1367
1358
        if value is None:       # get
1368
1359
            return dbus.UInt64(self.timeout_milliseconds())
1369
1360
        self.timeout = datetime.timedelta(0, 0, 0, value)
 
1361
        if getattr(self, "disable_initiator_tag", None) is None:
 
1362
            return
1370
1363
        # Reschedule timeout
1371
 
        if self.enabled:
1372
 
            now = datetime.datetime.utcnow()
1373
 
            time_to_die = timedelta_to_milliseconds(
1374
 
                (self.last_checked_ok + self.timeout) - now)
1375
 
            if time_to_die <= 0:
1376
 
                # The timeout has passed
1377
 
                self.disable()
1378
 
            else:
1379
 
                self.expires = (now +
1380
 
                                datetime.timedelta(milliseconds =
1381
 
                                                   time_to_die))
1382
 
                if (getattr(self, "disable_initiator_tag", None)
1383
 
                    is None):
1384
 
                    return
1385
 
                gobject.source_remove(self.disable_initiator_tag)
1386
 
                self.disable_initiator_tag = (gobject.timeout_add
1387
 
                                              (time_to_die,
1388
 
                                               self.disable))
 
1364
        gobject.source_remove(self.disable_initiator_tag)
 
1365
        self.disable_initiator_tag = None
 
1366
        self.expires = None
 
1367
        time_to_die = timedelta_to_milliseconds((self
 
1368
                                                 .last_checked_ok
 
1369
                                                 + self.timeout)
 
1370
                                                - datetime.datetime
 
1371
                                                .utcnow())
 
1372
        if time_to_die <= 0:
 
1373
            # The timeout has passed
 
1374
            self.disable()
 
1375
        else:
 
1376
            self.expires = (datetime.datetime.utcnow()
 
1377
                            + datetime.timedelta(milliseconds =
 
1378
                                                 time_to_die))
 
1379
            self.disable_initiator_tag = (gobject.timeout_add
 
1380
                                          (time_to_die, self.disable))
1389
1381
    
1390
1382
    # ExtendedTimeout - property
1391
1383
    @dbus_service_property(_interface, signature="t",
2102
2094
                                % server_settings["servicename"]))
2103
2095
    
2104
2096
    # Parse config file with clients
2105
 
    client_config = configparser.SafeConfigParser(Client
2106
 
                                                  .client_defaults)
 
2097
    client_config = configparser.SafeConfigParser(Client.client_defaults)
2107
2098
    client_config.read(os.path.join(server_settings["configdir"],
2108
2099
                                    "clients.conf"))
2109
2100
    
2271
2262
                        client["expires"] = (datetime.datetime
2272
2263
                                             .utcnow()
2273
2264
                                             + client["timeout"])
2274
 
                        logger.debug("Last checker succeeded,"
2275
 
                                     " keeping {0} enabled"
2276
 
                                     .format(client["name"]))
 
2265
                    
2277
2266
            try:
2278
2267
                client["secret"] = (
2279
2268
                    pgp.decrypt(client["encrypted_secret"],
2288
2277
 
2289
2278
    
2290
2279
    # Add/remove clients based on new changes made to config
2291
 
    for client_name in (set(old_client_settings)
2292
 
                        - set(client_settings)):
 
2280
    for client_name in set(old_client_settings) - set(client_settings):
2293
2281
        del clients_data[client_name]
2294
 
    for client_name in (set(client_settings)
2295
 
                        - set(old_client_settings)):
 
2282
    for client_name in set(client_settings) - set(old_client_settings):
2296
2283
        clients_data[client_name] = client_settings[client_name]
2297
2284
 
2298
2285
    # Create clients all clients