pidl:NDR/Client: fix dcerpc_function() with [out,ref] pointers
[Samba.git] / selftest / target / samba.py
blob666d223ff1707aa78e63aed13a432bdb1bdf30e1
1 #!/usr/bin/perl
2 # Bootstrap Samba and run a number of tests against it.
3 # Copyright (C) 2005-2012 Jelmer Vernooij <jelmer@samba.org>
4 # Published under the GNU GPL, v3 or later.
6 import os
7 import sys
10 def bindir_path(binary_mapping, bindir, path):
11 """Find the executable to use.
13 :param binary_mapping: Dictionary mapping binary names
14 :param bindir: Directory with binaries
15 :param path: Name of the executable to run
16 :return: Full path to the executable to run
17 """
18 path = binary_mapping.get(path, path)
19 valpath = os.path.join(bindir, path)
20 if os.path.isfile(valpath):
21 return valpath
22 return path
25 def mk_realms_stanza(realm, dnsname, domain, kdc_ipv4):
26 """Create a realms stanza for use in a krb5.conf file.
28 :param realm: Real name
29 :param dnsname: DNS name matching the realm
30 :param domain: Domain name
31 :param kdc_ipv4: IPv4 address of the KDC
32 :return: String with stanza
33 """
34 return """\
35 %(realm)s = {
36 kdc = %(kdc_ipv4)s:88
37 admin_server = %(kdc_ipv4)s:88
38 default_domain = %(dnsname)s
40 %(dnsname)s = {
41 kdc = %(kdc_ipv4)s:88
42 admin_server = %(kdc_ipv4)s:88
43 default_domain = %(dnsname)s
45 %(domain)s = {
46 kdc = %(kdc_ipv4)s:88
47 admin_server = %(kdc_ipv4)s:88
48 default_domain = %(dnsname)s
51 """ % {
52 "kdc_ipv4": kdc_ipv4, "dnsname": dnsname, "realm": realm, "domain": domain}
55 def write_krb5_conf(f, realm, dnsname, domain, kdc_ipv4, tlsdir=None,
56 other_realms_stanza=None):
57 """Write a krb5.conf file.
59 :param f: File-like object to write to
60 :param realm: Realm
61 :param dnsname: DNS domain name
62 :param domain: Domain name
63 :param kdc_ipv4: IPv4 address of KDC
64 :param tlsdir: Optional TLS directory
65 :param other_realms_stanza: Optional extra raw text for [realms] section
66 """
67 f.write("""\
68 #Generated krb5.conf for %(realm)s
70 [libdefaults]
71 \tdefault_realm = %(realm)s
72 \tdns_lookup_realm = false
73 \tdns_lookup_kdc = false
74 \tticket_lifetime = 24h
75 \tforwardable = yes
76 \tallow_weak_crypto = yes
77 """ % {"realm": realm})
79 f.write("\n[realms]\n")
80 f.write(mk_realms_stanza(realm, dnsname, domain, kdc_ipv4))
81 if other_realms_stanza:
82 f.write(other_realms_stanza)
84 if tlsdir:
85 f.write("""
86 [appdefaults]
87 pkinit_anchors = FILE:%(tlsdir)s/ca.pem
89 [kdc]
90 enable-pkinit = true
91 pkinit_identity = FILE:%(tlsdir)s/kdc.pem,%(tlsdir)s/key.pem
92 pkinit_anchors = FILE:%(tlsdir)s/ca.pem
94 """ % {"tlsdir": tlsdir})
97 def cleanup_child(pid, name, outf=None):
98 """Cleanup a child process.
100 :param pid: Parent pid process to be passed to waitpid()
101 :param name: Name to use when referring to process
102 :param outf: File-like object to write to (defaults to stderr)
103 :return: Child pid
105 if outf is None:
106 outf = sys.stderr
107 (childpid, status) = os.waitpid(pid, os.WNOHANG)
108 if childpid == 0:
109 pass
110 elif childpid < 0:
111 outf.write("%s child process %d isn't here any more.\n" % (name, pid))
112 return childpid
113 elif status & 127:
114 if status & 128:
115 core_status = 'with'
116 else:
117 core_status = 'without'
118 outf.write("%s child process %d, died with signal %d, %s coredump.\n" % (name, childpid, (status & 127), core_status))
119 else:
120 outf.write("%s child process %d exited with value %d.\n" % (name, childpid, status >> 8))
121 return childpid
124 def get_interface(netbiosname):
125 """Return interface id for a particular server.
127 netbiosname = netbiosname.lower()
129 interfaces = {
130 "locals3dc2": 2,
131 "localmember3": 3,
132 "localshare4": 4,
133 "localserver5": 5,
134 "localktest6": 6,
135 "maptoguest": 7,
137 # 11-16 used by selftest.pl for client interfaces
138 "localdc": 21,
139 "localvampiredc": 22,
140 "s4member": 23,
141 "localrpcproxy": 24,
142 "dc5": 25,
143 "dc6": 26,
144 "dc7": 27,
145 "rodc": 28,
146 "localadmember": 29,
147 "plugindc": 30,
148 "localsubdc": 31,
149 "chgdcpass": 32,
152 # update lib/socket_wrapper/socket_wrapper.c
153 # #define MAX_WRAPPED_INTERFACES 32
154 # if you wish to have more than 32 interfaces
155 return interfaces[netbiosname]