From 22b2ce74724dcd4bcef56c29b2e27e3e5faa2db2 Mon Sep 17 00:00:00 2001
From: Britney Fransen <brfransen@gmail.com>
Date: Thu, 10 Apr 2014 18:01:25 +0000
Subject: samba: update to 4.1.6. refs #961

---
 abs/extra/samba/PKGBUILD                           | 339 +++++++++++++--------
 abs/extra/samba/nmbd.service                       |   6 +-
 abs/extra/samba/readline-6.3.patch                 |  26 ++
 abs/extra/samba/samba                              |  54 ----
 .../samba/samba-4.0.3-fix_pidl_with_gcc48.patch    |  60 ++++
 abs/extra/samba/samba.conf                         |   1 +
 abs/extra/samba/samba.conf.d                       |  25 +-
 abs/extra/samba/samba.install                      |   9 +-
 abs/extra/samba/samba.service                      |  14 +
 abs/extra/samba/smbd.service                       |   5 +-
 abs/extra/samba/smbd.socket                        |   9 +
 abs/extra/samba/smbd@.service                      |   7 +
 abs/extra/samba/swat.xinetd                        |  10 -
 abs/extra/samba/winbindd.service                   |   5 +-
 14 files changed, 375 insertions(+), 195 deletions(-)
 create mode 100644 abs/extra/samba/readline-6.3.patch
 delete mode 100755 abs/extra/samba/samba
 create mode 100644 abs/extra/samba/samba-4.0.3-fix_pidl_with_gcc48.patch
 create mode 100644 abs/extra/samba/samba.service
 create mode 100644 abs/extra/samba/smbd.socket
 create mode 100644 abs/extra/samba/smbd@.service
 delete mode 100644 abs/extra/samba/swat.xinetd

diff --git a/abs/extra/samba/PKGBUILD b/abs/extra/samba/PKGBUILD
index 63d943d..4209761 100644
--- a/abs/extra/samba/PKGBUILD
+++ b/abs/extra/samba/PKGBUILD
@@ -1,168 +1,267 @@
-# $Id: PKGBUILD 162373 2012-06-26 05:39:58Z tpowa $
+
 # Maintainer: Tobias Powalowski <tpowa@archlinux.org>
 # Contributor: judd <jvinet@zeroflux.org>
+# Contributor: Michael Hansen <zrax0111 gmail com>
+# Contributor: Marco A Rojas <marquicus at gmail.com>
+# Contributor: Netanel Shine <netanel at archlinux.org.il >
+# Contributor: ngoonee <ngoonee.talk@gmail.com>
+# Contributor: Adam Russell <adamlr6+arch@gmail.com>
+# Contributor: Dhananjay Sathe <dhananjaysathe@gmail.com>
+
 pkgbase=samba
 pkgname=('libwbclient' 'smbclient' 'samba')
-pkgver=3.6.6
+pkgver=4.1.6
 # We use the 'A' to fake out pacman's version comparators.  Samba chooses
 # to append 'a','b',etc to their subsequent releases, which pamcan
 # misconstrues as alpha, beta, etc.  Bad samba!
-_realver=3.6.6
+_realver=4.1.6
 pkgrel=1
 arch=(i686 x86_64)
 url="http://www.samba.org"
 license=('GPL3')
-makedepends=('db' 'popt' 'libcups' 'acl' 'libldap' 'libcap' 'krb5' 'pam'  'gnutls>=2.4.1' 'talloc' 'tdb')
+makedepends=('python2' 'docbook-xsl' 'pkg-config' 'libbsd' 'db' 'popt' 'libcups' 
+             'readline' 'tevent' 'acl' 'libldap' 'libcap' 'ldb>=1.1.15' 'krb5' 'pam' 
+             'gnutls>=2.4.1' 'talloc' 'tdb' 'dbus')
 source=(http://us1.samba.org/samba/ftp/stable/${pkgbase}-${_realver}.tar.gz
-        samba samba.logrotate
-        swat.xinetd
+        samba.logrotate
         samba.pam
+        samba.service
         samba.conf.d
         smbd.service
+        smbd.socket
         nmbd.service
+        smbd@.service
         winbindd.service
-        samba.conf)
+        samba.conf
+        readline-6.3.patch)
 ### UNINSTALL dmapi package before building!!!
 
 build() {
-  cd ${srcdir}/${pkgbase}-${_realver}/source3
-  ./configure --prefix=/usr \
-              --libdir=/usr/lib/ \
+  # Use samba-pkg as a staging directory for the split packages
+  # (This is so RPATHS and symlinks are generated correctly via
+  # make install, but the otherwise unsplit pieces can be split)
+  _pkgsrc=${srcdir}/samba-pkg
+  rm -rf ${_pkgsrc}
+  cd ${srcdir}/samba-${_realver}
+  # change to use python2
+  SAVEIFS=${IFS}
+  IFS=$(echo -en "\n\b")
+  PYTHON_CALLERS="$(find ${srcdir}/samba-${_realver} -name '*.py')
+$(find ${srcdir}/samba-${_realver} -name 'wscript*')
+$(find ${srcdir}/samba-${_realver} -name 'configure.ac')
+$(find ${srcdir}/samba-${_realver} -name 'upgrade_from_s3')
+$(find ${srcdir}/samba-${_realver}/buildtools -type f)
+$(find ${srcdir}/samba-${_realver}/source4/scripting -type f)"
+  sed -i -e "s|/usr/bin/env python$|/usr/bin/env python2|" \
+         -e "s|python-config|python2-config|" \
+         -e "s|bin/python|bin/python2|" \
+      ${PYTHON_CALLERS}
+  IFS=${SAVEIFS}
+
+  export PYTHON=/usr/bin/python2
+_samba4_idmap_modules=idmap_ad,idmap_rid,idmap_adex,idmap_hash,idmap_tdb2
+_samba4_pdb_modules=pdb_tdbsam,pdb_ldap,pdb_ads,pdb_smbpasswd,pdb_wbc_sam,pdb_samba4
+_samba4_auth_modules=auth_unix,auth_wbc,auth_server,auth_netlogond,auth_script,auth_samba4
+ cd ${srcdir}/samba-${_realver}
+  patch -Np1 -i ${srcdir}/readline-6.3.patch
+  ./configure --enable-fhs \
+              --prefix=/usr \
+              --sbindir=/usr/bin \
+              --libdir=/usr/lib \
               --localstatedir=/var \
               --with-configdir=/etc/samba \
               --with-lockdir=/var/cache/samba \
-              --with-piddir=/var/run/samba \
-              --with-fhs \
-              --with-pam \
-              --with-pam_smbpass \
-              --with-pammodulesdir=/usr/lib/security \
-              --with-dnsupdate \
-              --with-automount \
-              --with-quotas \
+              --with-sockets-dir=/var/run/samba \
+              --with-piddir=/var/run \
               --with-ads \
+              --with-ldap \
+              --with-winbind \
               --with-acl-support \
-              --with-libsmbclient \
-              --with-syslog \
-              --enable-external-libtalloc \
-              --disable-dnssd \
-              --disable-avahi \
-              --with-shared-modules=idmap_ad,idmap_adex,idmap_rid,idmap_hash,idmap_tdb2 \
-              --enable-external-libtdb
+              --enable-gnutls \
+              --with-pam \
+              --with-pammodulesdir=/usr/lib/security \
+              --with-shared-modules=${_samba4_idmap_modules},${_samba4_pdb_modules},${_samba4_auth_modules} \
+              --disable-rpath-install
+
+              # Add this to the options once it's working...
+               #--with-system-mitkrb5 /opt/heimdal
   make
+  make DESTDIR="${_pkgsrc}/" install
+
+  # This gets skipped somehow
+  if [ ! -e ${_pkgsrc}/usr/bin/smbtar ]; then
+      install -m755 ${srcdir}/samba-${_realver}/source3/script/smbtar ${_pkgsrc}/usr/bin/
+  fi
 }
 
-package_libwbclient () {
+package_libwbclient() {
 pkgdesc="Samba winbind client library"
-depends=('glibc')
-  cd ${srcdir}/${pkgbase}-${_realver}/source3
-  mkdir -p ${pkgdir}/usr/lib  
-  for i in libwbclient*; do
-      cp  -a bin/${i}*.so* ${pkgdir}/usr/lib/
-  done
+depends=('glibc' 'libbsd')
+  # Use samba-pkg as a staging directory for the split packages
+  # (This is so RPATHS and symlinks are generated correctly via
+  # make install, but the otherwise unsplit pieces can be split)
+  _pkgsrc=${srcdir}/samba-pkg
+  install -d -m755 ${pkgdir}/usr/lib
+  mv ${_pkgsrc}/usr/lib/libwbclient*.so* ${pkgdir}/usr/lib/
+
+  install -d -m755 ${pkgdir}/usr/lib/samba
+  mv ${_pkgsrc}/usr/lib/samba/libwinbind-client*.so* ${pkgdir}/usr/lib/samba/
+  mv ${_pkgsrc}/usr/lib/samba/libreplace.so* ${pkgdir}/usr/lib/samba/
+
+  install -d -m755 ${pkgdir}/usr/lib/pkgconfig
+  mv ${_pkgsrc}/usr/lib/pkgconfig/wbclient.pc ${pkgdir}/usr/lib/pkgconfig/
+
+  install -d -m755 ${pkgdir}/usr/include/samba-4.0
+  mv ${_pkgsrc}/usr/include/samba-4.0/wbclient.h ${pkgdir}/usr/include/samba-4.0/
 }
 
-package_smbclient () {
+package_smbclient() {
 pkgdesc="Tools to access a server's filespace and printers via SMB"
-depends=('readline' 'popt' 'libldap' 'cifs-utils' 'libcap' 'krb5' 'db' 'e2fsprogs' 'tdb' 'talloc' 'libwbclient')
-  cd ${srcdir}/${pkgbase}-${_realver}/source3
-  mkdir -p ${pkgdir}/usr/bin ${pkgdir}/usr/lib
-  install -m755 bin/{smbclient,rpcclient,smbspool,smbtree,smbcacls,smbcquotas,smbget,net,nmblookup} ${pkgdir}/usr/bin/
-  for i in libnetapi* libsmbclient*;do
-      cp  -a bin/${i}*.so* ${pkgdir}/usr/lib/
-  done
-  install -m755 script/smbtar ${pkgdir}/usr/bin/
-  mkdir -p ${pkgdir}/usr/lib/cups/backend
-  ln -sf /usr/bin/smbspool ${pkgdir}/usr/lib/cups/backend/smb
-  mkdir -p ${pkgdir}/usr/include
-  install -m644 include/libsmbclient.h ${pkgdir}/usr/include/
-  install -m644 lib/netapi/netapi.h ${pkgdir}/usr/include/
-  mkdir -p ${pkgdir}/usr/share/man/man{1,7}
-  for man in rpcclient smbcacls smbclient smbcquotas smbget \
-      smbtree smbtar nmblookup; do
-      install -m644 ../docs/manpages/${man}.1 ${pkgdir}/usr/share/man/man1/
-  done
-  install -m644 ../docs/manpages/libsmbclient.7 ${pkgdir}/usr/share/man/man7/
+depends=('popt' 'cifs-utils' 'tdb' "libwbclient>=$pkgver" 'ldb'
+         'tevent' 'libgcrypt' 'python2' 'talloc' 'readline' 'gnutls' 
+         'libbsd' 'libldap' 'libcups')
+
+    _smbclient_bins=('smbclient' 'smbclient4' 'rpcclient' 'smbspool'
+                     'smbtree' 'smbcacls' 'smbcquotas' 'smbget' 'net'
+                     'nmblookup' 'nmblookup4' 'smbtar')
+    # Use samba-pkg as a staging directory for the split packages
+    # (This is so RPATHS and symlinks are generated correctly via
+    # make install, but the otherwise unsplit pieces can be split)
+    _pkgsrc=${srcdir}/samba-pkg
+    install -d -m755 ${pkgdir}/usr/bin
+    for bin in ${_smbclient_bins[@]}; do
+        mv ${_pkgsrc}/usr/bin/${bin} ${pkgdir}/usr/bin/
+    done
+
+    # smbclient binaries link to the majority of the samba
+    # libs, so this is a shortcut instead of resolving the
+    # whole dependency tree by hand
+    install -d -m755 ${pkgdir}/usr/lib
+    for lib in ${_pkgsrc}/usr/lib/lib*.so*; do
+        mv ${lib} ${pkgdir}/usr/lib/
+    done
+
+    install -d -m755 ${pkgdir}/usr/lib/samba
+    for lib in ${_pkgsrc}/usr/lib/samba/lib*.so*; do
+        mv ${lib} ${pkgdir}/usr/lib/samba/
+    done
+
+    install -d -m755 ${pkgdir}/usr/lib/pkgconfig
+    mv ${_pkgsrc}/usr/lib/pkgconfig/smbclient.pc ${pkgdir}/usr/lib/pkgconfig/
+    mv ${_pkgsrc}/usr/lib/pkgconfig/smbclient-raw.pc ${pkgdir}/usr/lib/pkgconfig/
+    mv ${_pkgsrc}/usr/lib/pkgconfig/netapi.pc ${pkgdir}/usr/lib/pkgconfig/
+
+    install -d -m755 ${pkgdir}/usr/share/man/man1
+    install -d -m755 ${pkgdir}/usr/share/man/man7
+    install -d -m755 ${pkgdir}/usr/share/man/man8
+    for bin in ${_smbclient_bins[@]}; do
+        if [ -e ${_pkgsrc}/usr/share/man/man1/${bin}.1 ]; then
+            mv ${_pkgsrc}/usr/share/man/man1/${bin}.1 ${pkgdir}/usr/share/man/man1/
+        fi
+        if [ -e ${_pkgsrc}/usr/share/man/man8/${bin}.8 ]; then
+            mv ${_pkgsrc}/usr/share/man/man8/${bin}.8 ${pkgdir}/usr/share/man/man8/
+        fi
+    done
+    mv ${_pkgsrc}/usr/share/man/man7/libsmbclient.7 ${pkgdir}/usr/share/man/man7/
+
+    install -d -m755 ${pkgdir}/usr/include/samba-4.0
+    mv ${_pkgsrc}/usr/include/samba-4.0/libsmbclient.h ${pkgdir}/usr/include/samba-4.0/
+    mv ${_pkgsrc}/usr/include/samba-4.0/netapi.h ${pkgdir}/usr/include/samba-4.0/
+
+    mkdir -p ${pkgdir}/usr/lib/cups/backend
+    ln -sf /usr/bin/smbspool ${pkgdir}/usr/lib/cups/backend/smb
 }
 
-package_samba () {
-pkgdesc="Tools to access a server's filespace and printers via SMB"
+package_samba() {
+pkgdesc="SMB Fileserver and AD Domain server"
+depends=('db>=4.7' 'popt' 'libcups' 'libcap>=2.16' 'gnutls>=2.4.1'
+         'talloc' 'ldb' 'libbsd' 'python2' 'iniparser' 'tdb' 'libaio' "smbclient>=$pkgver")
 backup=(etc/logrotate.d/samba
         etc/pam.d/samba
         etc/samba/smb.conf
         etc/xinetd.d/swat
         etc/conf.d/samba)
-depends=('db' 'popt' 'libcups' 'acl' 'libldap' "smbclient>=$pkgver" 'libcap' 'krb5' 'pam'  'gnutls' 'e2fsprogs' 'tdb' 'talloc')
-install='samba.install'
-  cd ${srcdir}/samba-${_realver}/source3
+install=samba.install
+    # Use samba-pkg as a staging directory for the split packages
+    # (This is so RPATHS and symlinks are generated correctly via
+    # make install, but the otherwise unsplit pieces can be split)
+    _pkgsrc=${srcdir}/samba-pkg
+    # Everything that libwbclient and smbclient didn't install goes
+    # into the samba package...
+    mv ${_pkgsrc}/* ${pkgdir}/
+    rmdir ${_pkgsrc}
+
+    _pyver=`python2 -c 'import sys; print(sys.version[:3])'`
+
+    find ${pkgdir}/usr/lib/python${_pyver}/site-packages/ -name '*.py' | \
+         xargs sed -i "s|#!/usr/bin/env python$|#!/usr/bin/env python2|"
+    find ${pkgdir}/usr/bin ${pkgdir}/usr/bin -type f -executable | \
+         xargs sed -i "s|#!/usr/bin/env python$|#!/usr/bin/env python2|"
+
+    # Make admin scripts look in the right place for the samba python module
+    for script in bin/samba_dnsupdate bin/samba_kcc bin/samba_spnupdate \
+                  bin/samba_upgradedns bin/samba-tool
+    do
+        sed -i "/^sys\.path\.insert/ a\
+sys.path.insert(0, '/usr/lib/python${_pyver}/site-packages')" \
+               ${pkgdir}/usr/${script}
+    done
+
+  # install systemd files
+  install -d -m755 ${pkgdir}/usr/lib/systemd/system
+  #for i in smbd nmbd winbindd; do
+  install -m644 ${srcdir}/*.service ${pkgdir}/usr/lib/systemd/system/
+  install -m644 ${srcdir}/*.socket ${pkgdir}/usr/lib/systemd/system/
+  install -d -m755  ${pkgdir}/etc/conf.d
+  install -m644 ${srcdir}/samba.conf.d ${pkgdir}/etc/conf.d/samba
+  #done
+  # create ephemeral dirs via tmpfiles rather than shipping them in package
+  install -D -m644 ${srcdir}/samba.conf ${pkgdir}/usr/lib/tmpfiles.d/samba.conf
+  # install sample smb.conf
+  install -d -m755 ${pkgdir}/etc/samba
+  install -m644 ${srcdir}/samba-${_realver}/packaging/LSB/smb.conf ${pkgdir}/etc/samba/smb.conf.default
+  
   mkdir -p ${pkgdir}/etc/samba/private
   chmod 700 ${pkgdir}/etc/samba/private
-  make DESTDIR=${pkgdir} install
-  chmod 644 ${pkgdir}/usr/include/*.h
-  rm -rf ${pkgdir}/usr/var
-  rm -rf ${pkgdir}/var/run/samba
-  (cd script; cp installbin.sh i; cat i | sed 's/\/sbin\///' > installbin.sh)
-  install -D -m755 ../../samba ${pkgdir}/etc/rc.d/samba
-  install -D -m644 ../../samba.conf.d ${pkgdir}/etc/conf.d/samba
-  mkdir -p ${pkgdir}/etc/samba
-  cat ../examples/smb.conf.default |  sed 's|log file = .*$|log file = /var/log/samba/log.%m|g' >${pkgdir}/etc/samba/smb.conf.default
-  install -D -m644 ../../samba.logrotate ${pkgdir}/etc/logrotate.d/samba
-  install -D -m644 ../../swat.xinetd ${pkgdir}/etc/xinetd.d/swat
-  install -D -m644 ../../samba.pam ${pkgdir}/etc/pam.d/samba
-  # spool directory
-  install -d -m1777 ${pkgdir}/var/spool/samba
-  sed -i 's|/usr/spool/samba|/var/spool/samba|g' ${pkgdir}/etc/samba/smb.conf.default
-  # fix logrotate
-  sed -i -e 's|log.%m|%m.log|g' ${pkgdir}/etc/samba/smb.conf.default
-  # nsswitch libraries
-  install -D -m755 ${srcdir}/samba-${_realver}/nsswitch/libnss_wins.so ${pkgdir}/usr/lib/libnss_wins.so
-  ln -s libnss_wins.so ${pkgdir}/usr/lib/libnss_wins.so.2
-  install -D -m755 ${srcdir}/samba-${_realver}/nsswitch/libnss_winbind.so ${pkgdir}/usr/lib/libnss_winbind.so
-  ln -s libnss_winbind.so ${pkgdir}/usr/lib/libnss_winbind.so.2
+
+  install -D -m644 ${srcdir}/samba.logrotate ${pkgdir}/etc/logrotate.d/samba
+  install -D -m644 ${srcdir}/samba.pam ${pkgdir}/etc/pam.d/samba 
+
   # winbind krb5 locator
   mkdir -p ${pkgdir}/usr/lib/krb5/plugins/libkrb5
-  install -d -m 0755 ${pkgdir}/usr/lib/krb5/plugins/libkrb5
-  install -m 755 bin/winbind_krb5_locator.so ${pkgdir}/usr/lib/krb5/plugins/libkrb5/winbind_krb5_locator.so
-  # remove conflict files of smbclient
-  for man in libsmbclient smbspool \
-      mount.cifs net cifs.upcall; do
-      rm -f ${pkgdir}/usr/share/man/man8/${man}.8
-  done
-  for i in libnetapi* libwbclient* libsmbclient* winbind_krb5*;do
-      rm -f ${pkgdir}/usr/lib/$i
-  done
-  for bin in net \
-      nmblookup rpcclient smbcacls smbclient \
-      smbcquotas smbget smbspool smbtar smbtree; do
-      rm -f ${pkgdir}/usr/bin/$bin
-  done
-  rm -f ${pkgdir}/usr/sbin/cifs.upcall
-  rm -f ${pkgdir}/usr/include/netapi.h
-  for man in rpcclient smbcacls smbclient smbcquotas \
-      smbtree smbtar nmblookup smbget; do
-      rm -f ${pkgdir}/usr/share/man/man1/${man}.1
-  done
-  for man in tdbbackup tdbdump tdbtool; do
-      rm -f ${pkgdir}/usr/share/man/man8/${man}.8
-  done
-  rm -f ${pkgdir}/usr/share/man/man7/libsmbclient.7
-  rm -f ${pkgdir}/usr/include/libsmbclient.h
+  mv  ${pkgdir}/usr/lib/*.so ${pkgdir}/usr/lib/krb5/plugins/libkrb5/
+
+  # fix logrotate
+  sed -i -e 's|log.%m|%m.log|g' ${pkgdir}/etc/samba/smb.conf.default
+  
+  # spool directory
+  install -d -m1777 ${pkgdir}/var/spool/samba
+  
+  rm -rf ${pkgdir}/var/run
+  
   # copy ldap example
   install -D -m644 ${srcdir}/samba-${_realver}/examples/LDAP/samba.schema ${pkgdir}/usr/share/doc/samba/examples/LDAP/samba.schema
-  # install systemd files
-  for i in smbd nmbd winbindd; do
-  install -D -m644 ${srcdir}/$i.service ${pkgdir}/usr/lib/systemd/system/$i.service
-  done
-  # create ephemeral dirs via tmpfiles rather than shipping them in package
-  install -D -m644 ${srcdir}/samba.conf ${pkgdir}/usr/lib/tmpfiles.d/samba.conf
-  rm -rf ${pkgdir}/var/run
 }
-md5sums=('0bea52842d172231c0c0e23ee570d7af'
-         'a45a4283723be2b0ae32439dc4496a09'
+md5sums=('9dc64658c0cc81e7637f9b975c19638c'
+         '5697da77590ec092cc8a883bae06093c'
+         '96f82c38f3f540b53f3e5144900acf17'
+         'ee4763a656cf00d92bfda31b6bb2c5cb'
+         '6c447748a064d631435dbef0a3dcf32f'
+         'e4ae6a3cac080602120aa151918c4a36'
+         'a78b9aa93eb14b0ac445897395693225'
+         'df6380c73cb73163968eabc8650f7358'
+         '70afd2db60a2e8eff7615dbdecd887ac'
+         'd5f56f43e1280bba20f6bbd88d16fa41'
+         '49abd7b719e3713a3f75a8a50958e381')
+md5sums=('9dc64658c0cc81e7637f9b975c19638c'
          '5697da77590ec092cc8a883bae06093c'
-         'a4bbfa39fee95bba2e7ad6b535fae7e6'
          '96f82c38f3f540b53f3e5144900acf17'
-         'f2f2e348acd1ccb566e95fa8a561b828'
-         '389cc4fa3b459360feaa1b3d93274693'
-         'ea6a1251be979cb30c6098a28b270d2d'
-         '455f106ce7a4f983975b3a686eaa85e5'
-         '8e7ed39b54968e427f9506e9107bfb45')
+         'ee4763a656cf00d92bfda31b6bb2c5cb'
+         '6c447748a064d631435dbef0a3dcf32f'
+         'e4ae6a3cac080602120aa151918c4a36'
+         'a78b9aa93eb14b0ac445897395693225'
+         'df6380c73cb73163968eabc8650f7358'
+         '70afd2db60a2e8eff7615dbdecd887ac'
+         'd5f56f43e1280bba20f6bbd88d16fa41'
+         '49abd7b719e3713a3f75a8a50958e381'
+         '1179c1dcdb95f79b0d5813698d010d2c')
diff --git a/abs/extra/samba/nmbd.service b/abs/extra/samba/nmbd.service
index 6e22ef2..e138225 100644
--- a/abs/extra/samba/nmbd.service
+++ b/abs/extra/samba/nmbd.service
@@ -1,8 +1,12 @@
 [Unit]
 Description=Samba NetBIOS name server
+After=network.target
 
 [Service]
-ExecStart=/usr/sbin/nmbd -F
+Type=forking
+PIDFile=/var/run/nmbd.pid
+ExecStart=/usr/bin/nmbd -D
+ExecReload=/bin/kill -HUP $MAINPID
 
 [Install]
 WantedBy=multi-user.target
diff --git a/abs/extra/samba/readline-6.3.patch b/abs/extra/samba/readline-6.3.patch
new file mode 100644
index 0000000..0dcb1cf
--- /dev/null
+++ b/abs/extra/samba/readline-6.3.patch
@@ -0,0 +1,26 @@
+Function, CPFunction, CPPFunction and VFunction typedefs are considered
+old-style (deprecated) starting from readline 4.2.
+Compatibility typedefs have been in place up to readline 6.2 but were
+removed with the 6.3 release thus causing builds to break.
+Swtich to the new-style specific prototyped typedef.
+
+Signed-off-by: Gustavo Zacarias <gustavo at zacarias.com.ar>
+---
+ libcli/smbreadline/smbreadline.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/libcli/smbreadline/smbreadline.c b/libcli/smbreadline/smbreadline.c
+index cff25a7..80e10b0 100644
+--- a/libcli/smbreadline/smbreadline.c
++++ b/libcli/smbreadline/smbreadline.c
+@@ -141,7 +141,7 @@ char *smb_readline(const char *prompt, void (*callback)(void),
+ 
+ #if HAVE_DECL_RL_EVENT_HOOK
+ 	if (callback)
+-		rl_event_hook = (Function *)callback;
++		rl_event_hook = (rl_hook_func_t *)callback;
+ #endif
+ 	ret = readline(prompt);
+ 	if (ret && *ret)
+-- 
+1.8.3.2
diff --git a/abs/extra/samba/samba b/abs/extra/samba/samba
deleted file mode 100755
index 6098ee0..0000000
--- a/abs/extra/samba/samba
+++ /dev/null
@@ -1,54 +0,0 @@
-#!/bin/bash
-
-. /etc/rc.conf
-. /etc/rc.d/functions
-[ -f /etc/conf.d/samba ] && . /etc/conf.d/samba
-
-[ -z "$SAMBA_DAEMONS" ] && SAMBA_DAEMONS=(smbd nmbd)
-
-case "$1" in
-	start)
-		rc=0
-		stat_busy "Starting Samba Server"
-                if [ ! -x /var/log/samba ] ; then
-                        install -m755 -d /var/log/samba
-                fi
-		for d in ${SAMBA_DAEMONS[@]}; do
-			PID=`pidof -o %PPID /usr/sbin/$d`
-			[ -z "$PID" ] && /usr/sbin/$d -D
-			rc=$(($rc+$?))
-		done
-		if [ $rc -gt 0 ]; then
-			stat_fail
-		else
-			add_daemon samba
-			stat_done
-		fi
-	;;
-	stop)
-		rc=0
-		stat_busy "Stopping Samba Server"
-		for d in ${SAMBA_DAEMONS[@]}; do
-			PID=`pidof -o %PPID /usr/sbin/$d`
-			[ -z "$PID" ] || kill $PID &> /dev/null
-			rc=$(($rc+$?))
-		done
-		if [ $rc -gt 0 ]; then
-			stat_fail
-		else
-			rm /run/samba/smbd.pid &>/dev/null
-			rm /run/samba/nmbd.pid &>/dev/null
-			rm /run/samba/winbindd.pid &>/dev/null
-			rm_daemon samba
-			stat_done
-		fi
-	;;
-	restart)
-		$0 stop
-		sleep 1
-		$0 start
-	;;
-	*)
-		echo "usage: $0 {start|stop|restart}"
-esac
-exit 0
diff --git a/abs/extra/samba/samba-4.0.3-fix_pidl_with_gcc48.patch b/abs/extra/samba/samba-4.0.3-fix_pidl_with_gcc48.patch
new file mode 100644
index 0000000..cb2378a
--- /dev/null
+++ b/abs/extra/samba/samba-4.0.3-fix_pidl_with_gcc48.patch
@@ -0,0 +1,60 @@
+From 1ac743a7d0d20e16fc325749d593edaaed89d706 Mon Sep 17 00:00:00 2001
+From: Alexander Bokovoy <ab@samba.org>
+Date: Wed, 6 Feb 2013 10:17:57 +0200
+Subject: [PATCH] PIDL: fix parsing linemarkers in preprocessor output
+
+When PIDL calls out to C preprocessor to expand IDL files
+and parse the output, it filters out linemarkers and line control
+information as described in http://gcc.gnu.org/onlinedocs/cpp/Preprocessor-Output.html
+and http://gcc.gnu.org/onlinedocs/cpp/Line-Control.html#Line-Control
+
+With gcc 4.8 stdc-predef.h is included automatically and linemarker for the
+file has extended flags that PIDL couldn't parse ('system header that needs to
+be extern "C" protected for C++')
+
+Thanks to Jakub Jelinek <jakub@redhat.com> for explanation of the linemarker format.
+
+Fixes https://bugzilla.redhat.com/show_bug.cgi?id=906517
+
+Reviewed-by: Andreas Schneider <asn@samba.org>
+(cherry picked from commit 6ba7ab5c14801aecae96373d5a9db7ab82957526)
+
+Signed-off-by: Andreas Schneider <asn@samba.org>
+---
+ pidl/idl.yp                | 4 +++-
+ pidl/lib/Parse/Pidl/IDL.pm | 4 +++-
+ 2 files changed, 6 insertions(+), 2 deletions(-)
+
+diff --git a/pidl/idl.yp b/pidl/idl.yp
+index b5c5185..c8a65f6 100644
+--- a/pidl/idl.yp
++++ b/pidl/idl.yp
+@@ -610,7 +610,9 @@ again:
+ 
+ 	for ($parser->YYData->{INPUT}) {
+ 		if (/^\#/) {
+-			if (s/^\# (\d+) \"(.*?)\"( \d+|)//) {
++			# Linemarker format is described at
++			# http://gcc.gnu.org/onlinedocs/cpp/Preprocessor-Output.html
++			if (s/^\# (\d+) \"(.*?)\"(( \d+){1,4}|)//) {
+ 				$parser->YYData->{LINE} = $1-1;
+ 				$parser->YYData->{FILE} = $2;
+ 				goto again;
+diff --git a/pidl/lib/Parse/Pidl/IDL.pm b/pidl/lib/Parse/Pidl/IDL.pm
+index d4820ff..6927c89 100644
+--- a/pidl/lib/Parse/Pidl/IDL.pm
++++ b/pidl/lib/Parse/Pidl/IDL.pm
+@@ -2576,7 +2576,9 @@ again:
+ 
+ 	for ($parser->YYData->{INPUT}) {
+ 		if (/^\#/) {
+-			if (s/^\# (\d+) \"(.*?)\"( \d+|)//) {
++			# Linemarker format is described at
++			# http://gcc.gnu.org/onlinedocs/cpp/Preprocessor-Output.html
++			if (s/^\# (\d+) \"(.*?)\"(( \d+){1,4}|)//) {
+ 				$parser->YYData->{LINE} = $1-1;
+ 				$parser->YYData->{FILE} = $2;
+ 				goto again;
+-- 
+1.8.1.1
+
diff --git a/abs/extra/samba/samba.conf b/abs/extra/samba/samba.conf
index c12610d..32e7228 100644
--- a/abs/extra/samba/samba.conf
+++ b/abs/extra/samba/samba.conf
@@ -1 +1,2 @@
 D /run/samba 0755 - - -
+d /var/log/samba 0755 - - -
\ No newline at end of file
diff --git a/abs/extra/samba/samba.conf.d b/abs/extra/samba/samba.conf.d
index 8721f95..7607426 100644
--- a/abs/extra/samba/samba.conf.d
+++ b/abs/extra/samba/samba.conf.d
@@ -1,7 +1,18 @@
-#
-# Configuration for the samba init script
-#
-
-# space separated list of daemons to launch
-SAMBA_DAEMONS=(smbd nmbd)
-#SAMBA_DAEMONS=(smbd nmbd winbindd)
+## Path:           Network/Samba
+## Description:    Samba process options
+## Type:           string
+## Default:        ""
+## ServiceRestart: samba
+SAMBAOPTIONS=""
+## Type:           string
+## Default:        ""
+## ServiceRestart: smb
+SMBDOPTIONS=""
+## Type:           string
+## Default:        ""
+## ServiceRestart: nmb
+NMBDOPTIONS=""
+## Type:           string
+## Default:        ""
+## ServiceRestart: winbind
+WINBINDOPTIONS=""
diff --git a/abs/extra/samba/samba.install b/abs/extra/samba/samba.install
index d9baeac..420643f 100644
--- a/abs/extra/samba/samba.install
+++ b/abs/extra/samba/samba.install
@@ -1,7 +1,14 @@
 #!/bin/sh
 
 post_install() {
-  systemd-tmpfiles --create /usr/lib/tmpfiles.d/samba.conf
+  systemd-tmpfiles --create samba.conf
 }
 
+post_upgrade() {
+  if [ "$(vercmp $2 4.0.4)" -lt 0 ]; then
+    echo "Major upgrade from samba 3.x to 4.x,"
+    echo "please read the Samba4 migration guide:"
+    echo "http://wiki.samba.org/index.php/Samba4/samba3upgrade/HOWTO"
+  fi
+}
 # vim:set ts=2 sw=2 et:
diff --git a/abs/extra/samba/samba.service b/abs/extra/samba/samba.service
new file mode 100644
index 0000000..562d425
--- /dev/null
+++ b/abs/extra/samba/samba.service
@@ -0,0 +1,14 @@
+[Unit]
+Description=Samba AD Daemon
+After=syslog.target network.target
+
+[Service]
+Type=forking
+PIDFile=/var/run/samba.pid
+LimitNOFILE=16384
+EnvironmentFile=-/etc/conf.d/samba
+ExecStart=/usr/bin/samba $SAMBAOPTIONS
+ExecReload=/usr/bin/kill -HUP $MAINPID
+
+[Install]
+WantedBy=multi-user.target
diff --git a/abs/extra/samba/smbd.service b/abs/extra/samba/smbd.service
index beb9bfa..0a8125d 100644
--- a/abs/extra/samba/smbd.service
+++ b/abs/extra/samba/smbd.service
@@ -1,8 +1,11 @@
 [Unit]
 Description=Samba SMB/CIFS server
+After=network.target nmbd.service winbindd.service
 
 [Service]
-ExecStart=/usr/sbin/smbd -F
+Type=forking
+PIDFile=/var/run/smbd.pid
+ExecStart=/usr/bin/smbd -D
 ExecReload=/bin/kill -HUP $MAINPID
 
 [Install]
diff --git a/abs/extra/samba/smbd.socket b/abs/extra/samba/smbd.socket
new file mode 100644
index 0000000..833bf43
--- /dev/null
+++ b/abs/extra/samba/smbd.socket
@@ -0,0 +1,9 @@
+[Unit]
+Description=Samba SMB/CIFS server socket
+
+[Socket]
+ListenStream=445
+Accept=yes
+
+[Install]
+WantedBy=sockets.target
diff --git a/abs/extra/samba/smbd@.service b/abs/extra/samba/smbd@.service
new file mode 100644
index 0000000..071eb57
--- /dev/null
+++ b/abs/extra/samba/smbd@.service
@@ -0,0 +1,7 @@
+[Unit]
+Description=Samba SMB/CIFS server instance
+
+[Service]
+ExecStart=/usr/bin/smbd -F
+ExecReload=/bin/kill -HUP $MAINPID
+StandardInput=socket
diff --git a/abs/extra/samba/swat.xinetd b/abs/extra/samba/swat.xinetd
deleted file mode 100644
index 2e62a82..0000000
--- a/abs/extra/samba/swat.xinetd
+++ /dev/null
@@ -1,10 +0,0 @@
-service swat
-{
-        socket_type             = stream
-        wait                    = no
-        user                    = root
-        server                  = /usr/sbin/swat
-        log_on_success  += HOST DURATION
-        log_on_failure  += HOST
-        disable                 = yes
-}
diff --git a/abs/extra/samba/winbindd.service b/abs/extra/samba/winbindd.service
index 509c896..41ecbfd 100644
--- a/abs/extra/samba/winbindd.service
+++ b/abs/extra/samba/winbindd.service
@@ -1,8 +1,11 @@
 [Unit]
 Description=Samba Winbind daemon
+After=network.target nmbd.service
 
 [Service]
-ExecStart=/usr/sbin/winbindd -F
+Type=forking
+PIDFile=/var/run/winbindd.pid
+ExecStart=/usr/bin/winbindd -D
 ExecReload=/bin/kill -HUP $MAINPID
 
 [Install]
-- 
cgit v0.12

