/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: 2008-08-30 19:05:15 UTC
  • Revision ID: teddy@fukt.bsnet.se-20080830190515-l7e6vu81yyw5kcku
* mandos.xml (SYNOPSIS): Use <option> and <replaceable> tags.  Unify
                         short and long options.

Show diffs side-by-side

added added

removed removed

Lines of Context:
55
55
import stat
56
56
import logging
57
57
import logging.handlers
58
 
import pwd
59
58
 
60
59
import dbus
61
60
import gobject
518
517
    Attributes:
519
518
        settings:       Server settings
520
519
        clients:        Set() of Client objects
521
 
        enabled:        Boolean; whether this server is activated yet
522
520
    """
523
521
    address_family = socket.AF_INET6
524
522
    def __init__(self, *args, **kwargs):
528
526
        if "clients" in kwargs:
529
527
            self.clients = kwargs["clients"]
530
528
            del kwargs["clients"]
531
 
        self.enabled = False
532
529
        return super(type(self), self).__init__(*args, **kwargs)
533
530
    def server_bind(self):
534
531
        """This overrides the normal server_bind() function
565
562
#                                            (self.settings
566
563
#                                             ["interface"]))
567
564
            return super(type(self), self).server_bind()
568
 
    def server_activate(self):
569
 
        if self.enabled:
570
 
            return super(type(self), self).server_activate()
571
 
    def enable(self):
572
 
        self.enabled = True
573
565
 
574
566
 
575
567
def string_to_delta(interval):
766
758
    client_config.read(os.path.join(server_settings["configdir"],
767
759
                                    "clients.conf"))
768
760
    
769
 
    clients = Set()
770
 
    tcp_server = IPv6_TCPServer((server_settings["address"],
771
 
                                 server_settings["port"]),
772
 
                                tcp_handler,
773
 
                                settings=server_settings,
774
 
                                clients=clients)
775
 
    pidfilename = "/var/run/mandos.pid"
776
 
    try:
777
 
        pidfile = open(pidfilename, "w")
778
 
    except IOError, error:
779
 
        logger.error("Could not open file %r", pidfilename)
780
 
    
781
 
    uid = 65534
782
 
    gid = 65534
783
 
    try:
784
 
        uid = pwd.getpwnam("mandos").pw_uid
785
 
    except KeyError:
786
 
        try:
787
 
            uid = pwd.getpwnam("nobody").pw_uid
788
 
        except KeyError:
789
 
            pass
790
 
    try:
791
 
        gid = pwd.getpwnam("mandos").pw_gid
792
 
    except KeyError:
793
 
        try:
794
 
            gid = pwd.getpwnam("nogroup").pw_gid
795
 
        except KeyError:
796
 
            pass
797
 
    try:
798
 
        os.setuid(uid)
799
 
        os.setgid(gid)
800
 
    except OSError, error:
801
 
        if error[0] != errno.EPERM:
802
 
            raise error
803
 
    
804
761
    global service
805
762
    service = AvahiService(name = server_settings["servicename"],
806
763
                           type = "_mandos._tcp", );
820
777
                            avahi.DBUS_INTERFACE_SERVER)
821
778
    # End of Avahi example code
822
779
    
 
780
    clients = Set()
823
781
    def remove_from_clients(client):
824
782
        clients.remove(client)
825
783
        if not clients:
847
805
        # Close all input and output, do double fork, etc.
848
806
        daemon()
849
807
    
 
808
    pidfilename = "/var/run/mandos/mandos.pid"
 
809
    pid = os.getpid()
850
810
    try:
851
 
        pid = os.getpid()
 
811
        pidfile = open(pidfilename, "w")
852
812
        pidfile.write(str(pid) + "\n")
853
813
        pidfile.close()
854
814
        del pidfile
855
815
    except IOError, err:
856
 
        logger.error(u"Could not write to file %r with PID %d",
857
 
                     pidfilename, pid)
858
 
    except NameError:
859
 
        # "pidfile" was never created
860
 
        pass
861
 
    del pidfilename
 
816
        logger.error(u"Could not write %s file with PID %d",
 
817
                     pidfilename, os.getpid())
862
818
    
863
819
    def cleanup():
864
820
        "Cleanup function; run on exit"
884
840
    for client in clients:
885
841
        client.start()
886
842
    
887
 
    tcp_server.enable()
888
 
    tcp_server.server_activate()
889
 
    
 
843
    tcp_server = IPv6_TCPServer((server_settings["address"],
 
844
                                 server_settings["port"]),
 
845
                                tcp_handler,
 
846
                                settings=server_settings,
 
847
                                clients=clients)
890
848
    # Find out what port we got
891
849
    service.port = tcp_server.socket.getsockname()[1]
892
850
    logger.info(u"Now listening on address %r, port %d, flowinfo %d,"