/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

working new feature: network-hooks - Enables user-scripts to take up
                     interfaces during bootup

Show diffs side-by-side

added added

removed removed

Lines of Context:
110
110
        return interface_index
111
111
 
112
112
 
113
 
def initlogger(debug, level=logging.WARNING):
 
113
def initlogger(level=logging.WARNING):
114
114
    """init logger and add loglevel"""
115
115
    
116
116
    syslogger.setFormatter(logging.Formatter
118
118
                            ' %(message)s'))
119
119
    logger.addHandler(syslogger)
120
120
    
121
 
    if debug:
122
 
        console = logging.StreamHandler()
123
 
        console.setFormatter(logging.Formatter('%(asctime)s %(name)s'
124
 
                                               ' [%(process)d]:'
125
 
                                               ' %(levelname)s:'
126
 
                                               ' %(message)s'))
127
 
        logger.addHandler(console)
 
121
    console = logging.StreamHandler()
 
122
    console.setFormatter(logging.Formatter('%(asctime)s %(name)s'
 
123
                                           ' [%(process)d]:'
 
124
                                           ' %(levelname)s:'
 
125
                                           ' %(message)s'))
 
126
    logger.addHandler(console)
128
127
    logger.setLevel(level)
129
128
 
130
129
 
2079
2078
                                     stored_state_file)
2080
2079
    
2081
2080
    if debug:
2082
 
        initlogger(debug, logging.DEBUG)
 
2081
        initlogger(logging.DEBUG)
2083
2082
    else:
2084
2083
        if not debuglevel:
2085
 
            initlogger(debug)
 
2084
            initlogger()
2086
2085
        else:
2087
2086
            level = getattr(logging, debuglevel.upper())
2088
 
            initlogger(debug, level)
 
2087
            initlogger(level)
2089
2088
    
2090
2089
    if server_settings["servicename"] != "Mandos":
2091
2090
        syslogger.setFormatter(logging.Formatter
2157
2156
        os.dup2(null, sys.stdin.fileno())
2158
2157
        if null > 2:
2159
2158
            os.close(null)
 
2159
    else:
 
2160
        # No console logging
 
2161
        logger.removeHandler(console)
2160
2162
    
2161
2163
    # Need to fork before connecting to D-Bus
2162
2164
    if not debug:
2163
2165
        # Close all input and output, do double fork, etc.
2164
2166
        daemon()
2165
2167
    
2166
 
    gobject.threads_init()
2167
 
    
2168
2168
    global main_loop
2169
2169
    # From the Avahi example code
2170
2170
    DBusGMainLoop(set_as_default=True )
2216
2216
                           .format(e))
2217
2217
            if e.errno != errno.ENOENT:
2218
2218
                raise
2219
 
        except EOFError as e:
2220
 
            logger.warning("Could not load persistent state: "
2221
 
                           "EOFError: {0}".format(e))
2222
2219
    
2223
2220
    with PGPEngine() as pgp:
2224
2221
        for client_name, client in clients_data.iteritems():
2403
2400
                del client_settings[client.name]["secret"]
2404
2401
        
2405
2402
        try:
2406
 
            tempfd, tempname = tempfile.mkstemp(suffix=".pickle",
2407
 
                                                prefix="clients-",
2408
 
                                                dir=os.path.dirname
2409
 
                                                (stored_state_path))
2410
 
            with os.fdopen(tempfd, "wb") as stored_state:
 
2403
            with os.fdopen(os.open(stored_state_path,
 
2404
                                   os.O_CREAT|os.O_WRONLY|os.O_TRUNC,
 
2405
                                   0600), "wb") as stored_state:
2411
2406
                pickle.dump((clients, client_settings), stored_state)
2412
 
            os.rename(tempname, stored_state_path)
2413
2407
        except (IOError, OSError) as e:
2414
2408
            logger.warning("Could not save persistent state: {0}"
2415
2409
                           .format(e))
2416
 
            if not debug:
2417
 
                try:
2418
 
                    os.remove(tempname)
2419
 
                except NameError:
2420
 
                    pass
2421
 
            if e.errno not in set((errno.ENOENT, errno.EACCES,
2422
 
                                   errno.EEXIST)):
2423
 
                raise e
 
2410
            if e.errno not in (errno.ENOENT, errno.EACCES):
 
2411
                raise
2424
2412
        
2425
2413
        # Delete all clients, and settings from config
2426
2414
        while tcp_server.clients: