/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: 2016-06-21 19:22:26 UTC
  • mfrom: (237.7.401 trunk)
  • Revision ID: teddy@recompile.se-20160621192226-yvrxurc8e2ur913y
MergeĀ fromĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
86
86
import xml.dom.minidom
87
87
import inspect
88
88
 
 
89
# Try to find the value of SO_BINDTODEVICE:
89
90
try:
 
91
    # This is where SO_BINDTODEVICE is in Python 3.3 (or 3.4?) and
 
92
    # newer, and it is also the most natural place for it:
90
93
    SO_BINDTODEVICE = socket.SO_BINDTODEVICE
91
94
except AttributeError:
92
95
    try:
 
96
        # This is where SO_BINDTODEVICE was up to and including Python
 
97
        # 2.6, and also 3.2:
93
98
        from IN import SO_BINDTODEVICE
94
99
    except ImportError:
95
 
        SO_BINDTODEVICE = None
 
100
        # In Python 2.7 it seems to have been removed entirely.
 
101
        # Try running the C preprocessor:
 
102
        try:
 
103
            cc = subprocess.Popen(["cc", "--language=c", "-E",
 
104
                                   "/dev/stdin"],
 
105
                                  stdin=subprocess.PIPE,
 
106
                                  stdout=subprocess.PIPE)
 
107
            stdout = cc.communicate(
 
108
                "#include <sys/socket.h>\nSO_BINDTODEVICE\n")[0]
 
109
            SO_BINDTODEVICE = int(stdout.splitlines()[-1])
 
110
        except (OSError, ValueError, IndexError):
 
111
            # No value found
 
112
            SO_BINDTODEVICE = None
96
113
 
97
114
if sys.version_info.major == 2:
98
115
    str = unicode
180
197
        self.gnupgargs = ['--batch',
181
198
                          '--homedir', self.tempdir,
182
199
                          '--force-mdc',
183
 
                          '--quiet',
184
 
                          '--no-use-agent']
 
200
                          '--quiet']
 
201
        # Only GPG version 1 has the --no-use-agent option.
 
202
        if self.gpg == "gpg" or self.gpg.endswith("/gpg"):
 
203
            self.gnupgargs.append("--no-use-agent")
185
204
    
186
205
    def __enter__(self):
187
206
        return self
2172
2191
            priority = self.server.gnutls_priority
2173
2192
            if priority is None:
2174
2193
                priority = "NORMAL"
2175
 
            gnutls.priority_set_direct(session._c_object, priority,
 
2194
            gnutls.priority_set_direct(session._c_object,
 
2195
                                       priority.encode("utf-8"),
2176
2196
                                       None)
2177
2197
            
2178
2198
            # Start communication using the Mandos protocol
2435
2455
        bind to an address or port if they were not specified."""
2436
2456
        if self.interface is not None:
2437
2457
            if SO_BINDTODEVICE is None:
2438
 
                logger.error("SO_BINDTODEVICE does not exist;"
2439
 
                             " cannot bind to interface %s",
2440
 
                             self.interface)
2441
 
            else:
2442
 
                try:
2443
 
                    self.socket.setsockopt(
2444
 
                        socket.SOL_SOCKET, SO_BINDTODEVICE,
2445
 
                        (self.interface + "\0").encode("utf-8"))
2446
 
                except socket.error as error:
2447
 
                    if error.errno == errno.EPERM:
2448
 
                        logger.error("No permission to bind to"
2449
 
                                     " interface %s", self.interface)
2450
 
                    elif error.errno == errno.ENOPROTOOPT:
2451
 
                        logger.error("SO_BINDTODEVICE not available;"
2452
 
                                     " cannot bind to interface %s",
2453
 
                                     self.interface)
2454
 
                    elif error.errno == errno.ENODEV:
2455
 
                        logger.error("Interface %s does not exist,"
2456
 
                                     " cannot bind", self.interface)
2457
 
                    else:
2458
 
                        raise
 
2458
                # Fall back to a hard-coded value which seems to be
 
2459
                # common enough.
 
2460
                logger.warning("SO_BINDTODEVICE not found, trying 25")
 
2461
                SO_BINDTODEVICE = 25
 
2462
            try:
 
2463
                self.socket.setsockopt(
 
2464
                    socket.SOL_SOCKET, SO_BINDTODEVICE,
 
2465
                    (self.interface + "\0").encode("utf-8"))
 
2466
            except socket.error as error:
 
2467
                if error.errno == errno.EPERM:
 
2468
                    logger.error("No permission to bind to"
 
2469
                                 " interface %s", self.interface)
 
2470
                elif error.errno == errno.ENOPROTOOPT:
 
2471
                    logger.error("SO_BINDTODEVICE not available;"
 
2472
                                 " cannot bind to interface %s",
 
2473
                                 self.interface)
 
2474
                elif error.errno == errno.ENODEV:
 
2475
                    logger.error("Interface %s does not exist,"
 
2476
                                 " cannot bind", self.interface)
 
2477
                else:
 
2478
                    raise
2459
2479
        # Only bind(2) the socket if we really need to.
2460
2480
        if self.server_address[0] or self.server_address[1]:
2461
2481
            if not self.server_address[0]:
3307
3327
        
3308
3328
        mandos_dbus_service = MandosDBusService()
3309
3329
    
 
3330
    # Save modules to variables to exempt the modules from being
 
3331
    # unloaded before the function registered with atexit() is run.
 
3332
    mp = multiprocessing
 
3333
    wn = wnull
3310
3334
    def cleanup():
3311
3335
        "Cleanup function; run on exit"
3312
3336
        if zeroconf:
3313
3337
            service.cleanup()
3314
3338
        
3315
 
        multiprocessing.active_children()
3316
 
        wnull.close()
 
3339
        mp.active_children()
 
3340
        wn.close()
3317
3341
        if not (tcp_server.clients or client_settings):
3318
3342
            return
3319
3343