# $Id: PKGBUILD 161792 2012-06-14 10:14:53Z tpowa $
# Maintainer: Tobias Powalowski <tpowa@archlinux.org>
# Contributor: judd <jvinet@zeroflux.org>

pkgname=pam
pkgver=1.1.5
pkgrel=4
pkgdesc="PAM (Pluggable Authentication Modules) library"
arch=('i686' 'x86_64')
license=('GPL2')
url="http://www.kernel.org/pub/linux/libs/pam/"
depends=('glibc' 'db' 'cracklib' 'libtirpc' 'pambase')
makedepends=('flex' 'w3m' 'docbook-xml>=4.4' 'docbook-xsl')
backup=(etc/security/{access.conf,group.conf,limits.conf,namespace.conf,namespace.init,pam_env.conf,time.conf} etc/default/passwd etc/environment)
source=(https://fedorahosted.org/releases/l/i/linux-pam/Linux-PAM-$pkgver.tar.bz2
        #http://www.kernel.org/pub/linux/libs/pam/library/Linux-PAM-$pkgver.tar.bz2
        ftp://ftp.suse.com/pub/people/kukuk/pam/pam_unix2/pam_unix2-2.6.tar.bz2)
options=('!libtool' '!emptydirs')
md5sums=('927ee5585bdec5256c75117e9348aa47'
         'e2788389a6c59224110a45fcff30e02b')

build() {
  cd $srcdir/Linux-PAM-$pkgver
  sed -i '1 i#include <sys/resource.h>' modules/pam_unix/pam_unix_auth.c
  sed -i '1 i#include <sys/resource.h>' modules/pam_unix/pam_unix_acct.c
  ./configure --libdir=/usr/lib
  make

 # cd $srcdir/pam_unix2-2.6
 # ./configure --libdir=/usr/lib
#  make
}

package() {
  cd $srcdir/Linux-PAM-$pkgver
  make DESTDIR=$pkgdir install

  # build pam_unix2 module
  # source ftp://ftp.suse.com/pub/people/kukuk/pam/pam_unix2
#  cd $srcdir/pam_unix2-2.6
#  make DESTDIR=$pkgdir install

  # add the realtime permissions for audio users
  sed -i 's|# End of file||' $pkgdir/etc/security/limits.conf
  cat >>$pkgdir/etc/security/limits.conf <<_EOT
*               -       rtprio          0
*               -       nice            0
@audio          -       rtprio          65
@audio          -       nice           -10
@audio          -       memlock         40000
_EOT

  # fix some missing symlinks from old pam for compatibility
  cd $pkgdir/usr/lib/security
  ln -s pam_unix.so pam_unix_acct.so
  ln -s pam_unix.so pam_unix_auth.so
  ln -s pam_unix.so pam_unix_passwd.so
  ln -s pam_unix.so pam_unix_session.so

  # set unix_chkpwd uid
  chmod +s $pkgdir/sbin/unix_chkpwd
}