/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: Björn Påhlsson
  • Date: 2010-09-07 16:48:58 UTC
  • mto: (237.4.3 mandos-release)
  • mto: This revision was merged to the branch mainline in revision 421.
  • Revision ID: belorn@fukt.bsnet.se-20100907164858-tcg8hkxdj41zizac
mandos server: Added debuglevel that adjust at what level information
               should be reported.
plugin-runner, askpass-fifo, password-prompt, splasy, usplash:
               Using error instead of perror

Show diffs side-by-side

added added

removed removed

Lines of Context:
157
157
                            u" after %i retries, exiting.",
158
158
                            self.rename_count)
159
159
            raise AvahiServiceError(u"Too many renames")
160
 
        self.name = self.server.GetAlternativeServiceName(self.name)
 
160
        self.name = unicode(self.server.GetAlternativeServiceName(self.name))
161
161
        logger.info(u"Changing Zeroconf service name to %r ...",
162
 
                    unicode(self.name))
 
162
                    self.name)
163
163
        syslogger.setFormatter(logging.Formatter
164
164
                               (u'Mandos (%s) [%%(process)d]:'
165
165
                                u' %%(levelname)s: %%(message)s'
304
304
                      "rb") as secfile:
305
305
                self.secret = secfile.read()
306
306
        else:
307
 
            #XXX Need to allow secret on demand!
308
307
            raise TypeError(u"No secret or secfile for client %s"
309
308
                            % self.name)
310
309
        self.host = config.get(u"host", u"")
712
711
        DBusObjectWithProperties.__init__(self, self.bus,
713
712
                                          self.dbus_object_path)
714
713
 
715
 
    #Could possible return a bool(self._approvals_pending),
716
 
    #but this could mess up approvals_pending += 1 XXX 
717
714
    def _get_approvals_pending(self):
718
715
        return self._approvals_pending
719
716
    def _set_approvals_pending(self, value):
859
856
        pass
860
857
    
861
858
    # GotSecret - signal
862
 
    # XXXTEDDY Is sent after succesfull transfer of secret from mandos-server to mandos-client
863
859
    @dbus.service.signal(_interface)
864
860
    def GotSecret(self):
865
 
        "D-Bus signal"
 
861
        """D-Bus signal
 
862
        Is sent after a successful transfer of secret from the Mandos
 
863
        server to mandos-client
 
864
        """
866
865
        pass
867
866
    
868
867
    # Rejected - signal
1231
1230
                
1232
1231
                sent_size = 0
1233
1232
                while sent_size < len(client.secret):
1234
 
                    # XXX handle session exception
1235
 
                    sent = session.send(client.secret[sent_size:])
 
1233
                    try:
 
1234
                        sent = session.send(client.secret[sent_size:])
 
1235
                    except (gnutls.errors.GNUTLSError), error:
 
1236
                        logger.warning("gnutls send failed")
 
1237
                        return
1236
1238
                    logger.debug(u"Sent: %d, remaining: %d",
1237
1239
                                 sent, len(client.secret)
1238
1240
                                 - (sent_size + sent))
1248
1250
            finally:
1249
1251
                if approval_required:
1250
1252
                    client.approvals_pending -= 1
1251
 
                session.bye()
 
1253
                try:
 
1254
                    session.bye()
 
1255
                except (gnutls.errors.GNUTLSError), error:
 
1256
                    logger.warning("gnutls bye failed")
1252
1257
    
1253
1258
    @staticmethod
1254
1259
    def peer_certificate(session):
1463
1468
        logger.debug(u"Handling IPC: FD = %d, condition = %s", source,
1464
1469
                     conditions_string)
1465
1470
 
1466
 
        # XXXTEDDY error or the other end of multiprocessing.Pipe has closed
1467
 
        if condition & gobject.IO_HUP or condition & gobject.IO_ERR:
 
1471
        # error or the other end of multiprocessing.Pipe has closed
 
1472
        if condition & (gobject.IO_ERR | condition & gobject.IO_HUP):
1468
1473
            return False
1469
1474
        
1470
1475
        # Read a request from the child
1624
1629
    parser.add_option("--debug", action=u"store_true",
1625
1630
                      help=u"Debug mode; run in foreground and log to"
1626
1631
                      u" terminal")
 
1632
    parser.add_option("--debuglevel", type=u"string", metavar="Level",
 
1633
                      help=u"Debug level for stdout output")
1627
1634
    parser.add_option("--priority", type=u"string", help=u"GnuTLS"
1628
1635
                      u" priority string (see GnuTLS documentation)")
1629
1636
    parser.add_option("--servicename", type=u"string",
1654
1661
                        u"servicename": u"Mandos",
1655
1662
                        u"use_dbus": u"True",
1656
1663
                        u"use_ipv6": u"True",
 
1664
                        u"debuglevel": u"",
1657
1665
                        }
1658
1666
    
1659
1667
    # Parse config file for server-global settings
1676
1684
    # options, if set.
1677
1685
    for option in (u"interface", u"address", u"port", u"debug",
1678
1686
                   u"priority", u"servicename", u"configdir",
1679
 
                   u"use_dbus", u"use_ipv6"):
 
1687
                   u"use_dbus", u"use_ipv6", u"debuglevel"):
1680
1688
        value = getattr(options, option)
1681
1689
        if value is not None:
1682
1690
            server_settings[option] = value
1691
1699
    
1692
1700
    # For convenience
1693
1701
    debug = server_settings[u"debug"]
 
1702
    debuglevel = server_settings[u"debuglevel"]
1694
1703
    use_dbus = server_settings[u"use_dbus"]
1695
1704
    use_ipv6 = server_settings[u"use_ipv6"]
1696
 
    
1697
 
    if not debug:
1698
 
        syslogger.setLevel(logging.WARNING)
1699
 
        console.setLevel(logging.WARNING)
1700
 
    
 
1705
 
1701
1706
    if server_settings[u"servicename"] != u"Mandos":
1702
1707
        syslogger.setFormatter(logging.Formatter
1703
1708
                               (u'Mandos (%s) [%%(process)d]:'
1755
1760
            raise error
1756
1761
    
1757
1762
    # Enable all possible GnuTLS debugging
 
1763
 
 
1764
 
 
1765
    if not debug and not debuglevel:
 
1766
        syslogger.setLevel(logging.WARNING)
 
1767
        console.setLevel(logging.WARNING)
 
1768
    if debuglevel:
 
1769
        level = getattr(logging, debuglevel.upper())
 
1770
        syslogger.setLevel(level)
 
1771
        console.setLevel(level)
 
1772
 
1758
1773
    if debug:
1759
1774
        # "Use a log level over 10 to enable all debugging options."
1760
1775
        # - GnuTLS manual
1766
1781
        
1767
1782
        (gnutls.library.functions
1768
1783
         .gnutls_global_set_log_function(debug_gnutls))
 
1784
 
 
1785
        # Redirect stdin so all checkers get /dev/null
 
1786
        null = os.open(os.path.devnull, os.O_NOCTTY | os.O_RDWR)
 
1787
        os.dup2(null, sys.stdin.fileno())
 
1788
        if null > 2:
 
1789
            os.close(null)
 
1790
    else:
 
1791
        # No console logging
 
1792
        logger.removeHandler(console)
 
1793
 
1769
1794
    
1770
1795
    global main_loop
1771
1796
    # From the Avahi example code
1790
1815
        service.interface = (if_nametoindex
1791
1816
                             (str(server_settings[u"interface"])))
1792
1817
 
 
1818
    if not debug:
 
1819
        # Close all input and output, do double fork, etc.
 
1820
        daemon()
 
1821
        
1793
1822
    global multiprocessing_manager
1794
1823
    multiprocessing_manager = multiprocessing.Manager()
1795
1824
    
1815
1844
            for section in client_config.sections()))
1816
1845
    if not tcp_server.clients:
1817
1846
        logger.warning(u"No clients defined")
1818
 
    
1819
 
    if debug:
1820
 
        # Redirect stdin so all checkers get /dev/null
1821
 
        null = os.open(os.path.devnull, os.O_NOCTTY | os.O_RDWR)
1822
 
        os.dup2(null, sys.stdin.fileno())
1823
 
        if null > 2:
1824
 
            os.close(null)
1825
 
    else:
1826
 
        # No console logging
1827
 
        logger.removeHandler(console)
1828
 
        # Close all input and output, do double fork, etc.
1829
 
        daemon()
1830
 
    
 
1847
        
1831
1848
    try:
1832
1849
        with pidfile:
1833
1850
            pid = os.getpid()