/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 server.py

merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
# This program is partly derived from an example program for an Avahi
7
7
# service publisher, downloaded from
8
8
# <http://avahi.org/wiki/PythonPublishExample>.  This includes the
9
 
# methods "add" and "remove" in the "AvahiService" class, the
10
 
# "server_state_changed" and "entry_group_state_changed" functions,
11
 
# and some lines in "main".
 
9
# following functions: "AvahiService.add", "AvahiService.remove",
 
10
# "server_state_changed", "entry_group_state_changed", and some lines
 
11
# in "main".
12
12
13
13
# Everything else is
14
14
# Copyright © 2007-2008 Teddy Hogeborn & Björn Påhlsson
61
61
from dbus.mainloop.glib import DBusGMainLoop
62
62
import ctypes
63
63
 
 
64
# Brief description of the operation of this program:
 
65
 
66
# This server announces itself as a Zeroconf service.  Connecting
 
67
# clients use the TLS protocol, with the unusual quirk that this
 
68
# server program acts as a TLS "client" while a connecting client acts
 
69
# as a TLS "server".  The client (acting as a TLS "server") must
 
70
# supply an OpenPGP certificate, and the fingerprint of this
 
71
# certificate is used by this server to look up (in a list read from a
 
72
# file at start time) which binary blob to give the client.  No other
 
73
# authentication or authorization is done by this server.
 
74
 
64
75
 
65
76
logger = logging.Logger('mandos')
66
77
syslogger = logging.handlers.SysLogHandler\
616
627
    return if_nametoindex(interface)
617
628
 
618
629
 
619
 
def daemon(nochdir = False, noclose = False):
 
630
def daemon(nochdir, noclose):
620
631
    """See daemon(3).  Standard BSD Unix function.
621
632
    This should really exist as os.daemon, but it doesn't (yet)."""
622
633
    if os.fork():
624
635
    os.setsid()
625
636
    if not nochdir:
626
637
        os.chdir("/")
627
 
    if os.fork():
628
 
        sys.exit()
629
638
    if not noclose:
630
639
        # Close all standard open file descriptors
631
640
        null = os.open(os.path.devnull, os.O_NOCTTY | os.O_RDWR)
683
692
    # Parse config file for server-global settings
684
693
    server_config = ConfigParser.SafeConfigParser(server_defaults)
685
694
    del server_defaults
686
 
    server_config.read(os.path.join(options.configdir, "mandos.conf"))
 
695
    server_config.read(os.path.join(options.configdir, "server.conf"))
687
696
    server_section = "server"
688
697
    # Convert the SafeConfigParser object to a dict
689
698
    server_settings = dict(server_config.items(server_section))
753
762
                       for section in client_config.sections()))
754
763
    
755
764
    if not debug:
756
 
        daemon()
 
765
        daemon(False, False)
757
766
    
758
767
    def cleanup():
759
768
        "Cleanup function; run on exit"