### this file is sourced not run
PKGVER=1.13.2
PKGBUILD=1
PKGARCH=x86_64

# BLFS 7.8 (2015-10-29)
TARBALL=krb5-$PKGVER-signed.tar
MD5SUM=f7ebfa6c99c10b16979ebf9a98343189
SRC_URL=http://web.mit.edu/kerberos/www/dist/krb5/1.13/$TARBALL
BUNDLE=

SLACKREQ='keyutils'
SLACKDESC="krb5: krb5 $PKGVER (MIT Kerberos V5 Library)
krb5: 
krb5: MIT Kerberos V5 is a free implementation of Kerberos 5. Kerberos is a 
krb5: network authentication protocol. It centralizes the authentication 
krb5: database and uses kerberized applications to work with servers or 
krb5: services that support Kerberos allowing single logins and encrypted 
krb5: communication over internal networks or the Internet.
krb5: 
krb5: 
krb5: 
krb5: 
"

### default pkg_download
pkg_prepare() {
	pkg_prepare_default &&
	cd tmp &&
	tar -xf krb5-*.tar.gz
}

### default pkg_package
### build
pkg_build() {
	cd /tmp/krb* &&
	
	cd src &&

	sed -e "s@python2.5/Python.h@& python2.7/Python.h@g" \
		-e "s@-lpython2.5]@&,\n  AC_CHECK_LIB(python2.7,main,[PYTHON_LIB=-lpython2.7])@g" \
		-i configure.in &&

	sed -e 's@\^u}@^u cols 300}@' \
		-i tests/dejagnu/config/default.exp &&

	autoconf &&
	CFLAGS="-Wno-error=maybe-uninitialized" \
	CXXFLAGS="-Wno-error=maybe-uninitialized" \
	./configure --prefix=/usr            \
				--sysconfdir=/etc        \
				--localstatedir=/var/lib \
				--libdir=/usr/$LIBDIR    \
				--with-system-et         \
				--with-system-ss         \
				--with-system-verto=no   \
				--enable-dns-for-realm &&
	make $MAKEFLAGS && make install &&

	# additional setup
	for LIBRARY in gssapi_krb5 gssrpc k5crypto kadm5clnt kadm5srv \
				   kdb5 kdb_ldap krad krb5 krb5support verto ; do
		chmod -v 755 /usr/$LIBDIR/lib$LIBRARY.so
	done          &&
	unset LIBRARY &&

	mv -v /usr/$LIBDIR/libkrb5.so.3*        /$LIBDIR &&
	mv -v /usr/$LIBDIR/libk5crypto.so.3*    /$LIBDIR &&
	mv -v /usr/$LIBDIR/libkrb5support.so.0* /$LIBDIR &&

	ln -v -sf ../../$LIBDIR/libkrb5.so.3.3        /usr/$LIBDIR/libkrb5.so        &&
	ln -v -sf ../../$LIBDIR/libk5crypto.so.3.1    /usr/$LIBDIR/libk5crypto.so    &&
	ln -v -sf ../../$LIBDIR/libkrb5support.so.0.1 /usr/$LIBDIR/libkrb5support.so &&

	mv -v /usr/bin/ksu /bin &&
	chmod -v 755 /bin/ksu   &&

	install -v -dm755 /usr/share/doc/krb5-$PKGVER &&
	cp -vfr ../doc/*  /usr/share/doc/krb5-$PKGVER &&
	
	pkg_build_slackdesc &&
	
	# default config from LFS
	install -m644 /tmp/pkg/krb5.conf /etc
	
	# Things to do after setup (as documented by BLFS)
	###
	# 1. Create the KDC database:
	# kdb5_util create -r <LFS.ORG> -s

	# 2. Populate the database with principals (users).e.g  with regular login name or root.
	# kadmin.local
	# kadmin.local: add_policy dict-only
	# kadmin.local: addprinc -policy dict-only <loginname>

	# 3. The KDC server and any machine running kerberized server daemons must have a host key installed:
	# kadmin.local: addprinc -randkey host/<belgarath.lfs.org>

	# 4. After choosing the defaults when prompted, you will have to export the data to a keytab file:
	# kadmin.local: ktadd host/<belgarath.lfs.org>
	# This should have created a file in /etc named krb5.keytab (Kerberos 5). 
	# This file should have 600 (root rw only) permissions. 
	# Keeping the keytab files from public access is crucial to the overall security of the Kerberos installation.

	# 5. Exit the kadmin program (use quit or exit) and return back to the shell prompt. 
	
	# 6. Start the KDC daemon manually, just to test out the installation:
	# /usr/sbin/krb5kdc

	# 7. Attempt to get a ticket with the following command:
	# kinit <loginname>

	# 8. You will be prompted for the password you created. 
	# After you get your ticket, you can list it with the following command:
	# klist

	# 9. Information about the ticket should be displayed on the screen.
	# To test the functionality of the keytab file, issue the following command:
	# ktutil
	# ktutil: rkt /etc/krb5.keytab
	# ktutil: l

	# This should dump a list of the host principal, along with the encryption methods used to access the principal.
}


