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

# source: BLFS 11.3
TARBALL=krb5-$PKGVER.tar.gz
MD5SUM=73f5780e7b587ccd8b8cfc10c965a686
SRC_URL=https://kerberos.org/dist/krb5/1.20/$TARBALL
BUNDLE=

SLACKREQ='keyutils openssl'
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: https://web.mit.edu/Kerberos/
krb5: 
krb5: 
"

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

	# BLFS 11.3 remove failing tests
	sed -i -e '/eq 0/{N;s/12 //}'    plugins/kdb/db2/libdb2/test/run.test &&
	sed -i '/t_kadm5.py/d'           lib/kadm5/Makefile.in                &&

	#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   \
				--with-readline          \
				--with-keyutils          \
				&&
	make $MAKEFLAGS && make install &&

	# docs
	install -v -dm755 /usr/share/doc/krb5-$PKGVER &&
	cp -vfr ../doc/*  /usr/share/doc/krb5-$PKGVER &&

<< "EOF" && # older BLFS relocate libs from /usr/lib to /lib
	# 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 &&
EOF

	mv -v /usr/bin/ksu /bin &&
	chmod -v 755 /bin/ksu   &&
	
	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 <EXAMPLE.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.example.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.

	# 10. Create an empty ACL file that can be modified later: 
	# touch /var/lib/krb5kdc/kadm5.acl

	# At this point, if everything has been successful so far, you can feel fairly confident in the installation and configuration of the package. 
}


