[SCM] Samba Shared Repository - branch master updated
Jelmer Vernooij
jelmer at samba.org
Fri Mar 23 21:53:03 MDT 2012
The branch, master has been updated
via ae9b5ad selftest.py: Add cleanup_pid.
via 99b4d52 selftest.py: Add write_krb5_conf.
via 289632f selftest.py: Add mk_realms_stanza function.
via f18d9e1 selftest.py: Add selftest.target.samba with bindir_path function.
from a15aefe Make it possible for developers of out-of-tree modules to use the same names as in-tree modules.
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit ae9b5add1e4c64b578915f35fc23110b686262fb
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Sat Mar 24 00:40:49 2012 +0100
selftest.py: Add cleanup_pid.
Autobuild-User: Jelmer Vernooij <jelmer at samba.org>
Autobuild-Date: Sat Mar 24 04:52:59 CET 2012 on sn-devel-104
commit 99b4d52633a9c099c31254b6ed59122261414a67
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Fri Mar 23 23:46:34 2012 +0100
selftest.py: Add write_krb5_conf.
commit 289632f85eefe987b429f6ca8500b3a17e42ebbb
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Fri Mar 23 23:46:19 2012 +0100
selftest.py: Add mk_realms_stanza function.
commit f18d9e147d4a242cdfb31a816d91d277b99badae
Author: Jelmer Vernooij <jelmer at samba.org>
Date: Fri Mar 23 23:46:02 2012 +0100
selftest.py: Add selftest.target.samba with bindir_path function.
-----------------------------------------------------------------------
Summary of changes:
selftest/target/samba.py | 121 ++++++++++++++++++++++++++++++++++++++++++
selftest/tests/__init__.py | 2 +-
selftest/tests/test_samba.py | 109 +++++++++++++++++++++++++++++++++++++
3 files changed, 231 insertions(+), 1 deletions(-)
create mode 100644 selftest/target/samba.py
create mode 100644 selftest/tests/test_samba.py
Changeset truncated at 500 lines:
diff --git a/selftest/target/samba.py b/selftest/target/samba.py
new file mode 100644
index 0000000..1ea156c
--- /dev/null
+++ b/selftest/target/samba.py
@@ -0,0 +1,121 @@
+#!/usr/bin/perl
+# Bootstrap Samba and run a number of tests against it.
+# Copyright (C) 2005-2012 Jelmer Vernooij <jelmer at samba.org>
+# Published under the GNU GPL, v3 or later.
+
+import os
+import sys
+
+
+def bindir_path(binary_mapping, bindir, path):
+ """Find the executable to use.
+
+ :param binary_mapping: Dictionary mapping binary names
+ :param bindir: Directory with binaries
+ :param path: Name of the executable to run
+ :return: Full path to the executable to run
+ """
+ path = binary_mapping.get(path, path)
+ valpath = os.path.join(bindir, path)
+ if os.path.isfile(valpath):
+ return valpath
+ return path
+
+
+def mk_realms_stanza(realm, dnsname, domain, kdc_ipv4):
+ """Create a realms stanza for use in a krb5.conf file.
+
+ :param realm: Real name
+ :param dnsname: DNS name matching the realm
+ :param domain: Domain name
+ :param kdc_ipv4: IPv4 address of the KDC
+ :return: String with stanza
+ """
+ return """\
+ %(realm)s = {
+ kdc = %(kdc_ipv4)s:88
+ admin_server = %(kdc_ipv4)s:88
+ default_domain = %(dnsname)s
+ }
+ %(dnsname)s = {
+ kdc = %(kdc_ipv4)s:88
+ admin_server = %(kdc_ipv4)s:88
+ default_domain = %(dnsname)s
+ }
+ %(domain)s = {
+ kdc = %(kdc_ipv4)s:88
+ admin_server = %(kdc_ipv4)s:88
+ default_domain = %(dnsname)s
+ }
+
+""" % {
+ "kdc_ipv4": kdc_ipv4, "dnsname": dnsname, "realm": realm, "domain": domain}
+
+
+def write_krb5_conf(f, realm, dnsname, domain, kdc_ipv4, tlsdir=None,
+ other_realms_stanza=None):
+ """Write a krb5.conf file.
+
+ :param f: File-like object to write to
+ :param realm: Realm
+ :param dnsname: DNS domain name
+ :param domain: Domain name
+ :param kdc_ipv4: IPv4 address of KDC
+ :param tlsdir: Optional TLS directory
+ :param other_realms_stanza: Optional extra raw text for [realms] section
+ """
+ f.write("""\
+#Generated krb5.conf for %(realm)s
+
+[libdefaults]
+\tdefault_realm = %(realm)s
+\tdns_lookup_realm = false
+\tdns_lookup_kdc = false
+\tticket_lifetime = 24h
+\tforwardable = yes
+\tallow_weak_crypto = yes
+""" % {"realm": realm})
+
+ f.write("\n[realms]\n")
+ f.write(mk_realms_stanza(realm, dnsname, domain, kdc_ipv4))
+ if other_realms_stanza:
+ f.write(other_realms_stanza)
+
+ if tlsdir:
+ f.write("""
+[appdefaults]
+ pkinit_anchors = FILE:%(tlsdir)s/ca.pem
+
+[kdc]
+ enable-pkinit = true
+ pkinit_identity = FILE:%(tlsdir)s/kdc.pem,%(tlsdir)s/key.pem
+ pkinit_anchors = FILE:%(tlsdir)s/ca.pem
+
+ """ % {"tlsdir": tlsdir})
+
+
+def cleanup_child(pid, name, outf=None):
+ """Cleanup a child process.
+
+ :param pid: Parent pid process to be passed to waitpid()
+ :param name: Name to use when referring to process
+ :param outf: File-like object to write to (defaults to stderr)
+ :return: Child pid
+ """
+ if outf is None:
+ outf = sys.stderr
+ (childpid, status) = os.waitpid(pid, os.WNOHANG)
+ if childpid == 0:
+ pass
+ elif childpid < 0:
+ outf.write("%s child process %d isn't here any more.\n" % (name, pid))
+ return childpid
+ elif status & 127:
+ if status & 128:
+ core_status = 'with'
+ else:
+ core_status = 'without'
+ outf.write("%s child process %d, died with signal %d, %s coredump.\n" % (name, childpid, (status & 127), core_status))
+ else:
+ outf.write("%s child process %d exited with value %d.\n" % (name, childpid, status >> 8))
+ return childpid
diff --git a/selftest/tests/__init__.py b/selftest/tests/__init__.py
index 5ff1f6b..85d0316 100644
--- a/selftest/tests/__init__.py
+++ b/selftest/tests/__init__.py
@@ -25,7 +25,7 @@ import unittest
def test_suite():
result = unittest.TestSuite()
- names = ['socket_wrapper', 'target', 'testlist', 'run']
+ names = ['socket_wrapper', 'target', 'testlist', 'run', 'samba']
module_names = ['selftest.tests.test_' + name for name in names]
loader = unittest.TestLoader()
result.addTests(loader.loadTestsFromNames(module_names))
diff --git a/selftest/tests/test_samba.py b/selftest/tests/test_samba.py
new file mode 100644
index 0000000..f06d846
--- /dev/null
+++ b/selftest/tests/test_samba.py
@@ -0,0 +1,109 @@
+# test_run.py -- Tests for selftest.target.samba
+# Copyright (C) 2012 Jelmer Vernooij <jelmer at samba.org>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; version 3
+# of the License or (at your option) any later version of
+# the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1301, USA.
+
+"""Tests for selftest.target.samba."""
+
+import os
+import sys
+
+from cStringIO import StringIO
+
+from selftest.tests import TestCase
+
+from selftest.target.samba import (
+ bindir_path,
+ cleanup_child,
+ mk_realms_stanza,
+ write_krb5_conf,
+ )
+
+
+class BinDirPathTests(TestCase):
+
+ def test_mapping(self):
+ self.assertEquals("exe4",
+ bindir_path({"exe": "exe4"}, "/some/path", "exe"))
+ self.assertEquals("/bin/ls",
+ bindir_path({"exe": "ls"}, "/bin", "exe"))
+
+ def test_no_mapping(self):
+ self.assertEqual("exe", bindir_path({}, "/some/path", "exe"))
+ self.assertEqual("/bin/ls",
+ bindir_path({}, "/bin", "ls"))
+
+
+class MkRealmsStanzaTests(TestCase):
+
+ def test_basic(self):
+ self.assertEqual(
+ mk_realms_stanza("rijk", "dnsnaam", "domein", "ipv4_kdc"),
+ '''\
+ rijk = {
+ kdc = ipv4_kdc:88
+ admin_server = ipv4_kdc:88
+ default_domain = dnsnaam
+ }
+ dnsnaam = {
+ kdc = ipv4_kdc:88
+ admin_server = ipv4_kdc:88
+ default_domain = dnsnaam
+ }
+ domein = {
+ kdc = ipv4_kdc:88
+ admin_server = ipv4_kdc:88
+ default_domain = dnsnaam
+ }
+
+''')
+
+
+class WriteKrb5ConfTests(TestCase):
+
+ def test_simple(self):
+ f = StringIO()
+ write_krb5_conf(f, "rijk", "dnsnaam", "domein", "kdc_ipv4")
+ self.assertEquals('''\
+#Generated krb5.conf for rijk
+
+[libdefaults]
+\tdefault_realm = rijk
+\tdns_lookup_realm = false
+\tdns_lookup_kdc = false
+\tticket_lifetime = 24h
+\tforwardable = yes
+\tallow_weak_crypto = yes
+
+[realms]
+ rijk = {
+ kdc = kdc_ipv4:88
+ admin_server = kdc_ipv4:88
+ default_domain = dnsnaam
+ }
+ dnsnaam = {
+ kdc = kdc_ipv4:88
+ admin_server = kdc_ipv4:88
+ default_domain = dnsnaam
+ }
+ domein = {
+ kdc = kdc_ipv4:88
+ admin_server = kdc_ipv4:88
+ default_domain = dnsnaam
+ }
+
+''', f.getvalue())
--
Samba Shared Repository
More information about the samba-cvs
mailing list