/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

  • Committer: Teddy Hogeborn
  • Date: 2013-10-28 20:08:32 UTC
  • mto: (237.7.272 trunk)
  • mto: This revision was merged to the branch mainline in revision 307.
  • Revision ID: teddy@recompile.se-20131028200832-80d1k8c5e8mugpkx
Syntax fix; use "raise" better in Mandos server.

* mandos: Syntax fix; use "raise" better in Mandos server; Always
          raise instances, not classes, skip argument when re-raising,
          etc.

Show diffs side-by-side

added added

removed removed

Lines of Context:
88
88
    except ImportError:
89
89
        SO_BINDTODEVICE = None
90
90
 
91
 
version = "1.6.1"
 
91
version = "1.6.2"
92
92
stored_state_file = "clients.pickle"
93
93
 
94
94
logger = logging.getLogger()
172
172
    def password_encode(self, password):
173
173
        # Passphrase can not be empty and can not contain newlines or
174
174
        # NUL bytes.  So we prefix it and hex encode it.
175
 
        return b"mandos" + binascii.hexlify(password)
 
175
        encoded = b"mandos" + binascii.hexlify(password)
 
176
        if len(encoded) > 2048:
 
177
            # GnuPG can't handle long passwords, so encode differently
 
178
            encoded = (b"mandos" + password.replace(b"\\", b"\\\\")
 
179
                       .replace(b"\n", b"\\n")
 
180
                       .replace(b"\0", b"\\x00"))
 
181
        return encoded
176
182
    
177
183
    def encrypt(self, data, password):
178
184
        passphrase = self.password_encode(password)
684
690
        # If a checker exists, make sure it is not a zombie
685
691
        try:
686
692
            pid, status = os.waitpid(self.checker.pid, os.WNOHANG)
687
 
        except (AttributeError, OSError) as error:
688
 
            if (isinstance(error, OSError)
689
 
                and error.errno != errno.ECHILD):
690
 
                raise error
 
693
        except AttributeError:
 
694
            pass
 
695
        except OSError as error:
 
696
            if error.errno != errno.ECHILD:
 
697
                raise
691
698
        else:
692
699
            if pid:
693
700
                logger.warning("Checker was a zombie")
1696
1703
            logger.debug("Protocol version: %r", line)
1697
1704
            try:
1698
1705
                if int(line.strip().split()[0]) > 1:
1699
 
                    raise RuntimeError
 
1706
                    raise RuntimeError(line)
1700
1707
            except (ValueError, IndexError, RuntimeError) as error:
1701
1708
                logger.error("Unknown protocol version: %s", error)
1702
1709
                return
1909
1916
    
1910
1917
    def add_pipe(self, parent_pipe, proc):
1911
1918
        """Dummy function; override as necessary"""
1912
 
        raise NotImplementedError
 
1919
        raise NotImplementedError()
1913
1920
 
1914
1921
 
1915
1922
class IPv6_TCPServer(MultiprocessingMixInWithPipe,
2252
2259
            else:
2253
2260
                raise ValueError("Unknown suffix {0!r}"
2254
2261
                                 .format(suffix))
2255
 
        except (ValueError, IndexError) as e:
 
2262
        except IndexError as e:
2256
2263
            raise ValueError(*(e.args))
2257
2264
        timevalue += delta
2258
2265
    return timevalue
2343
2350
                        "port": "",
2344
2351
                        "debug": "False",
2345
2352
                        "priority":
2346
 
                        "SECURE256:!CTYPE-X.509:+CTYPE-OPENPGP",
 
2353
                        "SECURE256:!CTYPE-X.509:+CTYPE-OPENPGP:+SIGN-RSA-SHA224:+SIGN-RSA-RMD160",
2347
2354
                        "servicename": "Mandos",
2348
2355
                        "use_dbus": "True",
2349
2356
                        "use_ipv6": "True",
2451
2458
                                        or None))
2452
2459
    if not foreground:
2453
2460
        pidfilename = "/run/mandos.pid"
 
2461
        if not os.path.isdir("/run/."):
 
2462
            pidfilename = "/var/run/mandos.pid"
2454
2463
        pidfile = None
2455
2464
        try:
2456
2465
            pidfile = open(pidfilename, "w")
2473
2482
        os.setuid(uid)
2474
2483
    except OSError as error:
2475
2484
        if error.errno != errno.EPERM:
2476
 
            raise error
 
2485
            raise
2477
2486
    
2478
2487
    if debug:
2479
2488
        # Enable all possible GnuTLS debugging
2784
2793
            else:
2785
2794
                logger.warning("Could not save persistent state:",
2786
2795
                               exc_info=e)
2787
 
                raise e
 
2796
                raise
2788
2797
        
2789
2798
        # Delete all clients, and settings from config
2790
2799
        while tcp_server.clients: