1HOMEPAGE = "https://www.samba.org/"
2SECTION = "console/network"
3
4LICENSE = "GPL-3.0-or-later & LGPL-3.0-or-later & GPL-2.0-or-later"
5LIC_FILES_CHKSUM = "file://COPYING;md5=d32239bcb673463ab874e80d47fae504 \
6                    file://${COREBASE}/meta/files/common-licenses/LGPL-3.0-or-later;md5=c51d3eef3be114124d11349ca0d7e117 \
7                    file://${COREBASE}/meta/files/common-licenses/GPL-2.0-or-later;md5=fed54355545ffd980b814dab4a3b312c"
8
9SAMBA_MIRROR = "http://samba.org/samba/ftp"
10MIRRORS += "\
11${SAMBA_MIRROR}    http://mirror.internode.on.net/pub/samba \n \
12${SAMBA_MIRROR}    http://www.mirrorservice.org/sites/ftp.samba.org \n \
13"
14
15export PYTHONHASHSEED="1"
16
17SRC_URI = "${SAMBA_MIRROR}/stable/samba-${PV}.tar.gz \
18           file://smb.conf \
19           file://volatiles.03_samba \
20           file://0001-Don-t-check-xsltproc-manpages.patch \
21           file://0002-do-not-import-target-module-while-cross-compile.patch \
22           file://0003-Add-config-option-without-valgrind.patch \
23           file://0004-Add-options-to-configure-the-use-of-libbsd.patch \
24           file://0005-Fix-pyext_PATTERN-for-cross-compilation.patch \
25           file://0006-smbtorture-skip-test-case-tfork_cmd_send.patch \
26           file://0007-Deleted-settiong-of-python-to-fix-the-install-confli.patch \
27           "
28
29SRC_URI:append:libc-musl = " \
30           file://samba-pam.patch \
31           file://samba-4.3.9-remove-getpwent_r.patch \
32           "
33
34SRC_URI[sha256sum] = "0e2405b4cec29d0459621f4340a1a74af771ec7cffedff43250cad7f1f87605e"
35
36UPSTREAM_CHECK_REGEX = "samba\-(?P<pver>4\.19(\.\d+)+).tar.gz"
37
38inherit systemd waf-samba cpan-base perlnative update-rc.d perl-version pkgconfig
39
40CVE_STATUS[CVE-2011-2411] = "not-applicable-platform: vulnerable only on HP NonStop Servers"
41
42# remove default added RDEPENDS on perl
43RDEPENDS:${PN}:remove = "perl"
44
45DEPENDS += "readline virtual/libiconv zlib popt libtalloc libtdb libtevent libldb libaio libpam libtasn1 libtasn1-native jansson libparse-yapp-perl-native gnutls cmocka"
46
47inherit features_check
48REQUIRED_DISTRO_FEATURES = "pam"
49
50DEPENDS:append:libc-musl = " libtirpc"
51CFLAGS:append:libc-musl = " -I${STAGING_INCDIR}/tirpc"
52LDFLAGS:append:libc-musl = " -ltirpc"
53
54COMPATIBLE_HOST:riscv32 = "null"
55
56INITSCRIPT_NAME = "samba"
57INITSCRIPT_PARAMS = "start 20 3 5 . stop 20 0 1 6 ."
58
59SYSTEMD_PACKAGES = "${PN}-base ${PN}-ad-dc winbind ctdb"
60SYSTEMD_SERVICE:${PN}-base = "nmb.service smb.service"
61SYSTEMD_SERVICE:${PN}-ad-dc = "${@bb.utils.contains('PACKAGECONFIG', 'ad-dc', 'samba.service', '', d)}"
62SYSTEMD_SERVICE:winbind = "winbind.service"
63SYSTEMD_SERVICE:ctdb = "ctdb.service"
64
65# There are prerequisite settings to enable ad-dc, so disable the service by default.
66# Reference:
67# https://wiki.samba.org/index.php/Setting_up_Samba_as_an_Active_Directory_Domain_Controller
68SYSTEMD_AUTO_ENABLE:${PN}-ad-dc = "disable"
69
70#cross_compile cannot use preforked process, since fork process earlier than point subproces.popen
71#to cross Popen
72export WAF_NO_PREFORK="yes"
73
74# Use krb5. Build active domain controller.
75#
76PACKAGECONFIG ??= "${@bb.utils.filter('DISTRO_FEATURES', 'systemd zeroconf', d)} \
77                   acl cups ldap mitkrb5 \
78"
79
80PACKAGECONFIG[acl] = "--with-acl-support,--without-acl-support,acl"
81PACKAGECONFIG[fam] = "--with-fam,--without-fam,gamin"
82PACKAGECONFIG[cups] = "--enable-cups,--disable-cups,cups"
83PACKAGECONFIG[ldap] = "--with-ldap,--without-ldap,openldap"
84PACKAGECONFIG[sasl] = ",,cyrus-sasl"
85PACKAGECONFIG[systemd] = "--with-systemd,--without-systemd,systemd"
86PACKAGECONFIG[dmapi] = "--with-dmapi,--without-dmapi,dmapi"
87PACKAGECONFIG[zeroconf] = "--enable-avahi,--disable-avahi,avahi"
88PACKAGECONFIG[valgrind] = "--with-valgrind,--without-valgrind,valgrind"
89PACKAGECONFIG[lttng] = "--with-lttng,--without-lttng,lttng-ust"
90PACKAGECONFIG[archive] = "--with-libarchive,--without-libarchive,libarchive"
91PACKAGECONFIG[libunwind] = "--with-libunwind,--without-libunwind,libunwind"
92PACKAGECONFIG[gpgme] = "--with-gpgme,--without-gpgme,gpgme"
93PACKAGECONFIG[lmdb] = ",--without-ldb-lmdb,lmdb"
94PACKAGECONFIG[libbsd] = "--with-libbsd,--without-libbsd,libbsd"
95PACKAGECONFIG[ad-dc] = "--with-experimental-mit-ad-dc,--without-ad-dc,python3-markdown python3-dnspython,"
96PACKAGECONFIG[mitkrb5] = "--with-system-mitkrb5 --with-system-mitkdc=/usr/sbin/krb5kdc,,krb5,"
97
98SAMBA4_IDMAP_MODULES="idmap_ad,idmap_rid,idmap_adex,idmap_hash,idmap_tdb2"
99SAMBA4_PDB_MODULES="pdb_tdbsam,${@bb.utils.contains('PACKAGECONFIG', 'ldap', 'pdb_ldap,', '', d)}pdb_ads,pdb_smbpasswd,pdb_wbc_sam,pdb_samba4"
100SAMBA4_AUTH_MODULES="auth_unix,auth_wbc,auth_server,auth_netlogond,auth_script,auth_samba4"
101SAMBA4_MODULES="${SAMBA4_IDMAP_MODULES},${SAMBA4_PDB_MODULES},${SAMBA4_AUTH_MODULES}"
102
103# These libraries are supposed to replace others supplied by packages, but decorate the names of
104# .so files so there will not be a conflict.  This is not done consistantly, so be very careful
105# when adding to this list.
106#
107SAMBA4_LIBS="heimdal,NONE"
108
109EXTRA_OECONF += "--enable-fhs \
110                 --with-piddir=/run \
111                 --with-sockets-dir=/run/samba \
112                 --with-modulesdir=${libdir}/samba \
113                 --with-privatelibdir=${libdir}/samba \
114                 --with-lockdir=${localstatedir}/lib/samba \
115                 --with-cachedir=${localstatedir}/lib/samba \
116                 --disable-rpath-install \
117                 --disable-rpath \
118                 --with-shared-modules=${SAMBA4_MODULES} \
119                 --bundled-libraries=${SAMBA4_LIBS} \
120                 ${@oe.utils.conditional('TARGET_ARCH', 'x86_64', '', '--disable-glusterfs', d)} \
121                 --with-cluster-support \
122                 --with-profiling-data \
123                 --with-libiconv=${STAGING_DIR_HOST}${prefix} \
124                 --with-pam --with-pammodulesdir=${base_libdir}/security \
125                 --pythondir=${PYTHON_SITEPACKAGES_DIR} \
126                "
127
128LDFLAGS += "-Wl,-z,relro,-z,now ${@bb.utils.contains('DISTRO_FEATURES', 'ld-is-gold', ' -fuse-ld=bfd ', '', d)}"
129
130do_configure:append() {
131    cd ${S}/pidl/
132    perl Makefile.PL PREFIX=${prefix}
133    sed -e 's,VENDORPREFIX)/lib/perl,VENDORPREFIX)/${baselib}/perl,g' \
134        -e 's,PERLPREFIX)/lib/perl,PERLPREFIX)/${baselib}/perl,g' -i Makefile
135}
136
137do_compile:append() {
138    oe_runmake -C ${S}/pidl
139}
140
141do_install:append() {
142    for section in 1 5 7; do
143        install -d ${D}${mandir}/man$section
144        install -m 0644 ctdb/doc/*.$section ${D}${mandir}/man$section
145    done
146    for section in 1 5 7 8; do
147        install -d ${D}${mandir}/man$section
148        install -m 0644 docs/manpages/*.$section ${D}${mandir}/man$section
149    done
150
151    install -d ${D}${systemd_system_unitdir}
152    install -m 0644 ${S}/bin/default/packaging/systemd/*.service ${D}${systemd_system_unitdir}/
153    sed -e 's,\(ExecReload=\).*\(/kill\),\1${base_bindir}\2,' \
154        -e 's,/etc/sysconfig/samba,${sysconfdir}/default/samba,' \
155        -i ${D}${systemd_system_unitdir}/*.service
156
157    if [ "${@bb.utils.contains('PACKAGECONFIG', 'ad-dc', 'yes', 'no', d)}" = "no" ]; then
158        rm -f ${D}${systemd_system_unitdir}/samba.service
159    fi
160
161    install -d ${D}${sysconfdir}/tmpfiles.d
162    install -m644 packaging/systemd/samba.conf.tmp ${D}${sysconfdir}/tmpfiles.d/samba.conf
163    echo "d ${localstatedir}/log/samba 0755 root root -" \
164        >> ${D}${sysconfdir}/tmpfiles.d/samba.conf
165    install -d ${D}${sysconfdir}/init.d
166    install -m 0755 packaging/sysv/samba.init ${D}${sysconfdir}/init.d/samba
167    sed -e 's,/opt/samba/bin,${sbindir},g' \
168        -e 's,/opt/samba/smb.conf,${sysconfdir}/samba/smb.conf,g' \
169        -e 's,/opt/samba/log,${localstatedir}/log/samba,g' \
170        -e 's,/etc/init.d/samba.server,${sysconfdir}/init.d/samba,g' \
171        -e 's,/usr/bin,${base_bindir},g' \
172        -i ${D}${sysconfdir}/init.d/samba
173
174    install -d ${D}${sysconfdir}/samba
175    echo "127.0.0.1 localhost" > ${D}${sysconfdir}/samba/lmhosts
176    install -m644 ${WORKDIR}/smb.conf ${D}${sysconfdir}/samba/smb.conf
177    install -D -m 644 ${WORKDIR}/volatiles.03_samba ${D}${sysconfdir}/default/volatiles/03_samba
178
179    install -d ${D}${sysconfdir}/default
180    install -m644 packaging/systemd/samba.sysconfig ${D}${sysconfdir}/default/samba
181
182    # the items are from ctdb/tests/run_tests.sh
183    for d in cunit eventd eventscripts onnode shellcheck takeover takeover_helper tool; do
184        testdir=${D}${datadir}/ctdb-tests/UNIT/$d
185        install -d $testdir
186        cp ${S}/ctdb/tests/UNIT/$d/*.sh $testdir
187        cp -r ${S}/ctdb/tests/UNIT/$d/scripts ${S}/ctdb/tests/UNIT/$d/stubs $testdir || true
188    done
189
190    # fix file-rdeps qa warning
191    if [ -f ${D}${bindir}/onnode ]; then
192        sed -i 's:\(#!/bin/\)bash:\1sh:' ${D}${bindir}/onnode
193    fi
194
195    chmod 0750 ${D}${sysconfdir}/sudoers.d || true
196    rm -rf ${D}/run ${D}${localstatedir}/run ${D}${localstatedir}/log
197
198    for f in samba-gpupdate samba_upgradedns samba_spnupdate samba_kcc samba_dnsupdate samba_downgrade_db; do
199        if [ -f "${D}${sbindir}/$f" ]; then
200            sed -i -e 's,${PYTHON},/usr/bin/env python3,g' ${D}${sbindir}/$f
201        fi
202    done
203    if [ -f "${D}${bindir}/samba-tool" ]; then
204        sed -i -e 's,${PYTHON},/usr/bin/env python3,g' ${D}${bindir}/samba-tool
205    fi
206
207    oe_runmake -C ${S}/pidl DESTDIR=${D} install_vendor
208    find ${D}${libdir}/perl5/ -type f -name "perllocal.pod" -delete
209    find ${D}${libdir}/perl5/ -type f -name ".packlist" -delete
210    sed -i -e '1s,#!.*perl,#!${bindir}/env perl,' ${D}${bindir}/pidl
211}
212
213PACKAGES =+ "${PN}-python3 ${PN}-pidl \
214             ${PN}-dsdb-modules ${PN}-testsuite registry-tools \
215             winbind ctdb ctdb-tests \
216             ${PN}-common ${PN}-base ${PN}-ad-dc \
217             smbclient ${PN}-client ${PN}-server ${PN}-test"
218
219python samba_populate_packages() {
220    def module_hook(file, pkg, pattern, format, basename):
221        pn = d.getVar('PN')
222        d.appendVar('RRECOMMENDS:%s-base' % pn, ' %s' % pkg)
223
224    mlprefix = d.getVar('MLPREFIX') or ''
225    pam_libdir = d.expand('${base_libdir}/security')
226    pam_pkgname = mlprefix + 'pam-plugin%s'
227    do_split_packages(d, pam_libdir, r'^pam_(.*)\.so$', pam_pkgname, 'PAM plugin for %s', extra_depends='', prepend=True)
228
229    libdir = d.getVar('libdir')
230    do_split_packages(d, libdir, r'^lib(.*)\.so\..*$', 'lib%s', 'Samba %s library', extra_depends='${PN}-common', prepend=True, allow_links=True)
231    pkglibdir = '%s/samba' % libdir
232    do_split_packages(d, pkglibdir, r'^lib(.*)\.so$', 'lib%s', 'Samba %s library', extra_depends='${PN}-common', prepend=True)
233    moduledir = '%s/samba/auth' % libdir
234    do_split_packages(d, moduledir, r'^(.*)\.so$', 'samba-auth-%s', 'Samba %s authentication backend', hook=module_hook, extra_depends='', prepend=True)
235    moduledir = '%s/samba/pdb' % libdir
236    do_split_packages(d, moduledir, r'^(.*)\.so$', 'samba-pdb-%s', 'Samba %s password backend', hook=module_hook, extra_depends='', prepend=True)
237}
238
239PACKAGESPLITFUNCS:prepend = "samba_populate_packages "
240PACKAGES_DYNAMIC = "samba-auth-.* samba-pdb-.*"
241
242RDEPENDS:${PN} += "${PN}-base ${PN}-python3 ${PN}-dsdb-modules python3"
243RDEPENDS:${PN}-python3 += "pytalloc python3-tdb pyldb"
244
245FILES:${PN}-base = "${sbindir}/nmbd \
246                    ${sbindir}/smbd \
247                    ${sysconfdir}/init.d \
248                    ${systemd_system_unitdir}/nmb.service \
249                    ${systemd_system_unitdir}/smb.service"
250
251FILES:${PN}-ad-dc = "${sbindir}/samba \
252                     ${systemd_system_unitdir}/samba.service \
253                     ${libdir}/krb5/plugins/kdb/samba.so \
254"
255
256RDEPENDS:${PN}-ad-dc = "krb5-kdc"
257
258FILES:ctdb = "${bindir}/ctdb \
259              ${bindir}/ctdb_diagnostics \
260              ${bindir}/ltdbtool \
261              ${bindir}/onnode \
262              ${bindir}/ping_pong \
263              ${sbindir}/ctdbd \
264              ${datadir}/ctdb \
265              ${libexecdir}/ctdb \
266              ${localstatedir}/lib/ctdb \
267              ${sysconfdir}/ctdb \
268              ${sysconfdir}/sudoers.d/ctdb \
269              ${systemd_system_unitdir}/ctdb.service \
270"
271
272FILES:ctdb-tests = "${bindir}/ctdb_run_tests \
273                    ${bindir}/ctdb_run_cluster_tests \
274                    ${datadir}/ctdb-tests \
275                    ${datadir}/ctdb/tests \
276"
277
278RDEPENDS:ctdb-tests += "bash util-linux-getopt ctdb"
279
280FILES:${BPN}-common = "${sysconfdir}/default \
281                       ${sysconfdir}/samba \
282                       ${sysconfdir}/tmpfiles.d \
283                       ${localstatedir}/lib/samba \
284                       ${localstatedir}/spool/samba \
285"
286
287FILES:${PN} += "${libdir}/vfs/*.so \
288                ${libdir}/charset/*.so \
289                ${libdir}/*.dat \
290                ${libdir}/auth/*.so \
291"
292
293FILES:${PN}-dsdb-modules = "${libdir}/samba/ldb"
294
295FILES:${PN}-testsuite = "${bindir}/gentest \
296                         ${bindir}/locktest \
297                         ${bindir}/masktest \
298                         ${bindir}/ndrdump \
299                         ${bindir}/smbtorture"
300
301FILES:registry-tools = "${bindir}/regdiff \
302                        ${bindir}/regpatch \
303                        ${bindir}/regshell \
304                        ${bindir}/regtree"
305
306FILES:winbind = "${sbindir}/winbindd \
307                 ${bindir}/wbinfo \
308                 ${bindir}/ntlm_auth \
309                 ${libdir}/samba/idmap \
310                 ${libdir}/samba/nss_info \
311                 ${libdir}/winbind_krb5_locator.so \
312                 ${libdir}/winbind-krb5-localauth.so \
313                 ${sysconfdir}/init.d/winbind \
314                 ${systemd_system_unitdir}/winbind.service"
315
316FILES:${PN}-python3 = "${PYTHON_SITEPACKAGES_DIR}"
317
318FILES:smbclient = "${bindir}/cifsdd \
319                   ${bindir}/rpcclient \
320                   ${bindir}/smbcacls \
321                   ${bindir}/smbclient \
322                   ${bindir}/smbcquotas \
323                   ${bindir}/smbget \
324                   ${bindir}/smbspool \
325                   ${bindir}/smbtar \
326                   ${bindir}/smbtree \
327                   ${libexecdir}/samba/smbspool_krb5_wrapper"
328
329FILES:${PN}-pidl = "${bindir}/pidl \
330                    ${libdir}/perl5 \
331                   "
332RDEPENDS:${PN}-pidl += "perl perl-modules libparse-yapp-perl"
333
334RDEPENDS:${PN}-client = "\
335    smbclient \
336    winbind \
337    registry-tools \
338    ${PN}-pidl \
339    "
340
341ALLOW_EMPTY:${PN}-client = "1"
342
343RDEPENDS:${PN}-server = "\
344    ${PN} \
345    winbind \
346    registry-tools \
347    "
348
349ALLOW_EMPTY:${PN}-server = "1"
350
351RDEPENDS:${PN}-test = "\
352    ctdb-tests \
353    ${PN}-testsuite \
354    "
355
356ALLOW_EMPTY:${PN}-test = "1"
357