/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: Teddy Hogeborn
  • Date: 2015-05-31 15:56:58 UTC
  • Revision ID: teddy@recompile.se-20150531155658-l7znu7zlqr2dmuwd
mandos: Generate better messages in exceptions.

mandos (ProxyClient.__init__): Include fingerprint in KeyError().
(rfc3339_duration_to_delta): Include duration in ValueError().

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
 
37
37
from future_builtins import *
38
38
 
39
 
import SocketServer as socketserver
 
39
try:
 
40
    import SocketServer as socketserver
 
41
except ImportError:
 
42
    import socketserver
40
43
import socket
41
44
import argparse
42
45
import datetime
47
50
import gnutls.library.functions
48
51
import gnutls.library.constants
49
52
import gnutls.library.types
50
 
import ConfigParser as configparser
 
53
try:
 
54
    import ConfigParser as configparser
 
55
except ImportError:
 
56
    import configparser
51
57
import sys
52
58
import re
53
59
import os
62
68
import struct
63
69
import fcntl
64
70
import functools
65
 
import cPickle as pickle
 
71
try:
 
72
    import cPickle as pickle
 
73
except ImportError:
 
74
    import pickle
66
75
import multiprocessing
67
76
import types
68
77
import binascii
69
78
import tempfile
70
79
import itertools
71
80
import collections
 
81
import codecs
72
82
 
73
83
import dbus
74
84
import dbus.service
75
 
import gobject
 
85
try:
 
86
    import gobject
 
87
except ImportError:
 
88
    from gi.repository import GObject as gobject
76
89
import avahi
77
90
from dbus.mainloop.glib import DBusGMainLoop
78
91
import ctypes
1659
1672
        self._pipe = child_pipe
1660
1673
        self._pipe.send(('init', fpr, address))
1661
1674
        if not self._pipe.recv():
1662
 
            raise KeyError()
 
1675
            raise KeyError(fpr)
1663
1676
    
1664
1677
    def __getattribute__(self, name):
1665
1678
        if name == '_pipe':
2241
2254
                break
2242
2255
        else:
2243
2256
            # No currently valid tokens were found
2244
 
            raise ValueError("Invalid RFC 3339 duration")
 
2257
            raise ValueError("Invalid RFC 3339 duration: {!r}"
 
2258
                             .format(duration))
2245
2259
    # End token found
2246
2260
    return value
2247
2261
 
2498
2512
            pidfilename = "/var/run/mandos.pid"
2499
2513
        pidfile = None
2500
2514
        try:
2501
 
            pidfile = open(pidfilename, "w")
 
2515
            pidfile = codecs.open(pidfilename, "w", encoding="utf-8")
2502
2516
        except IOError as e:
2503
2517
            logger.error("Could not open file %r", pidfilename,
2504
2518
                         exc_info=e)
2563
2577
            old_bus_name = dbus.service.BusName(
2564
2578
                "se.bsnet.fukt.Mandos", bus,
2565
2579
                do_not_queue=True)
2566
 
        except dbus.exceptions.NameExistsException as e:
 
2580
        except dbus.exceptions.DBusException as e:
2567
2581
            logger.error("Disabling D-Bus:", exc_info=e)
2568
2582
            use_dbus = False
2569
2583
            server_settings["use_dbus"] = False
2700
2714
    
2701
2715
    if not foreground:
2702
2716
        if pidfile is not None:
 
2717
            pid = os.getpid()
2703
2718
            try:
2704
2719
                with pidfile:
2705
 
                    pid = os.getpid()
2706
 
                    pidfile.write("{}\n".format(pid).encode("utf-8"))
 
2720
                    print(pid, file=pidfile)
2707
2721
            except IOError:
2708
2722
                logger.error("Could not write to file %r with PID %d",
2709
2723
                             pidfilename, pid)