/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-27 01:18:25 UTC
  • Revision ID: teddy@fukt.bsnet.se-20080827011825-ka3ni6xvy2ehi1y8
* .bzrignore: New.

* clients.conf ([foo]): Remove Radix-64 checksum.

* mandos (AvahiService.rename, server_state_changed,
          entry_group_state_changed): Make Avahi log messages more
                                      clear that they are about
                                      Zeroconf.
  (fingerprint): Use plain "0" instead of "ctypes.c_uint(0)".

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
 
    pidfile = None
777
 
    try:
778
 
        pidfile = open(pidfilename, "w")
779
 
    except IOError, error:
780
 
        logger.error("Could not open file %r", pidfilename)
781
 
    
782
 
    uid = 65534
783
 
    gid = 65534
784
 
    try:
785
 
        uid = pwd.getpwnam("mandos").pw_uid
786
 
    except KeyError:
787
 
        try:
788
 
            uid = pwd.getpwnam("nobody").pw_uid
789
 
        except KeyError:
790
 
            pass
791
 
    try:
792
 
        gid = pwd.getpwnam("mandos").pw_gid
793
 
    except KeyError:
794
 
        try:
795
 
            gid = pwd.getpwnam("nogroup").pw_gid
796
 
        except KeyError:
797
 
            pass
798
 
    try:
799
 
        os.setuid(uid)
800
 
        os.setgid(gid)
801
 
    except OSError, error:
802
 
        if error[0] != errno.EPERM:
803
 
            raise error
804
 
    
805
761
    global service
806
762
    service = AvahiService(name = server_settings["servicename"],
807
763
                           type = "_mandos._tcp", );
821
777
                            avahi.DBUS_INTERFACE_SERVER)
822
778
    # End of Avahi example code
823
779
    
 
780
    clients = Set()
824
781
    def remove_from_clients(client):
825
782
        clients.remove(client)
826
783
        if not clients:
848
805
        # Close all input and output, do double fork, etc.
849
806
        daemon()
850
807
    
851
 
    if pidfile is not None:
852
 
        pid = os.getpid()
853
 
        try:
854
 
            pidfile.write(str(pid) + "\n")
855
 
            pidfile.close()
856
 
        except IOError, err:
857
 
            logger.error(u"Could not write %s file with PID %d",
858
 
                         pidfilename, os.getpid())
859
 
    del pidfile
860
 
    del pidfilename
 
808
    pidfilename = "/var/run/mandos/mandos.pid"
 
809
    pid = os.getpid()
 
810
    try:
 
811
        pidfile = open(pidfilename, "w")
 
812
        pidfile.write(str(pid) + "\n")
 
813
        pidfile.close()
 
814
        del pidfile
 
815
    except IOError, err:
 
816
        logger.error(u"Could not write %s file with PID %d",
 
817
                     pidfilename, os.getpid())
861
818
    
862
819
    def cleanup():
863
820
        "Cleanup function; run on exit"
883
840
    for client in clients:
884
841
        client.start()
885
842
    
886
 
    tcp_server.enable()
887
 
    tcp_server.server_activate()
888
 
    
 
843
    tcp_server = IPv6_TCPServer((server_settings["address"],
 
844
                                 server_settings["port"]),
 
845
                                tcp_handler,
 
846
                                settings=server_settings,
 
847
                                clients=clients)
889
848
    # Find out what port we got
890
849
    service.port = tcp_server.socket.getsockname()[1]
891
850
    logger.info(u"Now listening on address %r, port %d, flowinfo %d,"