bmh10 / rpms / openssh

Forked from rpms/openssh 10 days ago
Clone
f5835d
diff -up openssh-6.8p1/HOWTO.ldap-keys.ldap openssh-6.8p1/HOWTO.ldap-keys
f5835d
--- openssh-6.8p1/HOWTO.ldap-keys.ldap	2015-03-18 11:11:29.029801467 +0100
f5835d
+++ openssh-6.8p1/HOWTO.ldap-keys	2015-03-18 11:11:29.029801467 +0100
f5835d
@@ -0,0 +1,122 @@
f5835d
+
f5835d
+HOW TO START
f5835d
+
f5835d
+1) configure LDAP server
f5835d
+  * Use LDAP server documentation
f5835d
+2) add appropriate LDAP schema
f5835d
+  * For OpenLDAP or SunONE Use attached schema, otherwise you have to create it. 
f5835d
+  * LDAP user entry
f5835d
+        User entry:
f5835d
+	- attached to the 'ldapPublicKey' objectclass
f5835d
+	- attached to the 'posixAccount' objectclass
f5835d
+	- with a filled 'sshPublicKey' attribute 
f5835d
+3) insert users into LDAP
f5835d
+  * Use LDAP Tree management tool as useful
f5835d
+  * Entry in the LDAP server must respect 'posixAccount' and 'ldapPublicKey' which are defined in core.schema and the additionnal lpk.schema.
f5835d
+  * Example:
f5835d
+	dn: uid=captain,ou=commanders,dc=enterprise,dc=universe
f5835d
+	objectclass: top
f5835d
+	objectclass: person
f5835d
+	objectclass: organizationalPerson
f5835d
+	objectclass: posixAccount
f5835d
+	objectclass: ldapPublicKey
f5835d
+	description: Jonathan Archer
f5835d
+	userPassword: Porthos
f5835d
+	cn: onathan Archer
f5835d
+	sn: onathan Archer
f5835d
+	uid: captain
f5835d
+	uidNumber: 1001
f5835d
+	gidNumber: 1001
f5835d
+	homeDirectory: /home/captain
f5835d
+	sshPublicKey: ssh-rss AAAAB3.... =captain@universe
f5835d
+	sshPublicKey: command="kill -9 1" ssh-rss AAAAM5...
f5835d
+4) on the ssh side set in sshd_config
f5835d
+  * Set up the backend
f5835d
+	AuthorizedKeysCommand /usr/libexec/openssh/ssh-ldap-wrapper
f5835d
+	AuthorizedKeysCommandUser <appropriate user to run LDAP>
f5835d
+  * Do not forget to set
f5835d
+	PubkeyAuthentication yes
f5835d
+  * Swith off unnecessary auth methods
f5835d
+5) confugure ldap.conf
f5835d
+  * Default ldap.conf is placed in /etc/ssh
f5835d
+  * The configuration style is the same as other ldap based aplications
f5835d
+6) if necessary edit ssh-ldap-wrapper
f5835d
+  * There is a possibility to change ldap.conf location
f5835d
+  * There are some debug options
f5835d
+  * Example
f5835d
+	/usr/libexec/openssh -s -f /etc/ldap.conf -w -d >> /tmp/ldapdebuglog.txt
f5835d
+7) Configure SELinux boolean which allows ldap-helper to bind ldap server
f5835d
+  Run this command
f5835d
+  # setsebool -P authlogin_nsswitch_use_ldap on
f5835d
+
f5835d
+HOW TO MIGRATE FROM LPK
f5835d
+
f5835d
+1) goto HOW TO START 4) .... the ldap schema is the same
f5835d
+
f5835d
+2) convert the group requests to the appropriate LDAP requests
f5835d
+
f5835d
+HOW TO SOLVE PROBLEMS
f5835d
+
f5835d
+1) use debug in sshd
f5835d
+  * /usr/sbin/sshd -d -d -d -d
f5835d
+2) use debug in ssh-ldap-helper
f5835d
+  * ssh-ldap-helper -d -d -d -d -s <username>
f5835d
+3) use tcpdump ... other ldap client etc.
f5835d
+
f5835d
+HOW TO CONFIGURE SSH FOR OTHER LDAP CONFIGURATION / SERVER /SCHEMA
f5835d
+
f5835d
+You can adjust search format string in /etc/ldap.conf using
f5835d
+ 1) SSH_Filter option to limit results for only specified users
f5835d
+    (this appends search condition after original query)
f5835d
+ 2) Search_Format option to define your own search string using expansion
f5835d
+    characters %u for username, %c for objectclass and %f for above mentioned filter.
f5835d
+
f5835d
+Example:
f5835d
+Search_Format (&(objectclass=posixAccount)(objectclass=ldapPublicKey)(uid=%u)%f)
f5835d
+
f5835d
+ADVANTAGES
f5835d
+
f5835d
+1) Blocking an user account can be done directly from LDAP (if sshd is using PubkeyAuthentication + AuthorizedKeysCommand with ldap only).
f5835d
+
f5835d
+DISADVANTAGES
f5835d
+
f5835d
+1)  LDAP must be well configured, getting the public key of some user is not a problem, but if anonymous LDAP 
f5835d
+  allows write to users dn, somebody could replace some user's public key by his own and impersonate some 
f5835d
+  of your users in all your server farm -- be VERY CAREFUL.
f5835d
+2) With incomplete PKI the MITM attack when sshd is requesting the public key, could lead to a compromise of your servers allowing login 
f5835d
+  as the impersonated user.
f5835d
+3) If LDAP server is down there may be no fallback on passwd auth.
f5835d
+  
f5835d
+MISC.
f5835d
+  
f5835d
+1) todo
f5835d
+  * Possibility to reuse the ssh-ldap-helper.
f5835d
+  * Tune the LDAP part to accept  all possible LDAP configurations.
f5835d
+
f5835d
+2) differences from original lpk
f5835d
+  * No LDAP code in sshd.
f5835d
+  * Support for various LDAP platforms and configurations.
f5835d
+  * LDAP is configured in separate ldap.conf file.
f5835d
+
f5835d
+3) docs/link 
f5835d
+  * http://pacsec.jp/core05/psj05-barisani-en.pdf
f5835d
+  * http://fritz.potsdam.edu/projects/openssh-lpk/
f5835d
+  * http://fritz.potsdam.edu/projects/sshgate/
f5835d
+  * http://dev.inversepath.com/trac/openssh-lpk
f5835d
+  * http://lam.sf.net/ ( http://lam.sourceforge.net/documentation/supportedSchemas.htm )
f5835d
+
f5835d
+4) contributors/ideas/greets
f5835d
+  - Eric AUGE <eau@phear.org>
f5835d
+  - Andrea Barisani <andrea@inversepath.com>
f5835d
+  - Falk Siemonsmeier.
f5835d
+  - Jacob Rief.
f5835d
+  - Michael Durchgraf.
f5835d
+  - frederic peters.
f5835d
+  - Finlay dobbie.
f5835d
+  - Stefan Fisher.
f5835d
+  - Robin H. Johnson.
f5835d
+  - Adrian Bridgett.
f5835d
+
f5835d
+5) Author
f5835d
+    Jan F. Chadima <jchadima@redhat.com>
f5835d
+
f5835d
diff -up openssh-6.8p1/Makefile.in.ldap openssh-6.8p1/Makefile.in
f5835d
--- openssh-6.8p1/Makefile.in.ldap	2015-03-17 06:49:20.000000000 +0100
f5835d
+++ openssh-6.8p1/Makefile.in	2015-03-18 11:13:10.147561177 +0100
f5835d
@@ -25,6 +25,8 @@ SSH_PROGRAM=@bindir@/ssh
f5835d
 ASKPASS_PROGRAM=$(libexecdir)/ssh-askpass
f5835d
 SFTP_SERVER=$(libexecdir)/sftp-server
f5835d
 SSH_KEYSIGN=$(libexecdir)/ssh-keysign
f5835d
+SSH_LDAP_HELPER=$(libexecdir)/ssh-ldap-helper
f5835d
+SSH_LDAP_WRAPPER=$(libexecdir)/ssh-ldap-wrapper
f5835d
 SSH_PKCS11_HELPER=$(libexecdir)/ssh-pkcs11-helper
f5835d
 PRIVSEP_PATH=@PRIVSEP_PATH@
f5835d
 SSH_PRIVSEP_USER=@SSH_PRIVSEP_USER@
f5835d
@@ -50,6 +50,7 @@
f5835d
 CFLAGS=@CFLAGS@
f5835d
 CPPFLAGS=-I. -I$(srcdir) @CPPFLAGS@ $(PATHS) @DEFS@
f5835d
 LIBS=@LIBS@
f5835d
+LDAPLIBS=@LDAPLIBS@
f5835d
 K5LIBS=@K5LIBS@
f5835d
 GSSLIBS=@GSSLIBS@
f5835d
 SSHLIBS=@SSHLIBS@
f5835d
@@ -61,8 +63,9 @@ XAUTH_PATH=@XAUTH_PATH@
f5835d
 EXEEXT=@EXEEXT@
f5835d
 MANFMT=@MANFMT@
f5835d
 MKDIR_P=@MKDIR_P@
f5835d
+INSTALL_SSH_LDAP_HELPER=@INSTALL_SSH_LDAP_HELPER@
f5835d
 
f5835d
-TARGETS=ssh$(EXEEXT) sshd$(EXEEXT) ssh-add$(EXEEXT) ssh-keygen$(EXEEXT) ssh-keyscan${EXEEXT} ssh-keysign${EXEEXT} ssh-pkcs11-helper$(EXEEXT) ssh-agent$(EXEEXT) scp$(EXEEXT) sftp-server$(EXEEXT) sftp$(EXEEXT)
f5835d
+TARGETS=ssh$(EXEEXT) sshd$(EXEEXT) ssh-add$(EXEEXT) ssh-keygen$(EXEEXT) ssh-keyscan${EXEEXT} ssh-keysign${EXEEXT} ssh-pkcs11-helper$(EXEEXT) ssh-agent$(EXEEXT) scp$(EXEEXT) sftp-server$(EXEEXT) sftp$(EXEEXT) ssh-ldap-helper$(EXEEXT)
f5835d
 
f5835d
 XMSS_OBJS=\
f5835d
 	ssh-xmss.o \
f5835d
@@ -112,8 +115,8 @@ SSHDOBJS=sshd.o auth-rhosts.o auth-passw
f5835d
 	sandbox-seccomp-filter.o sandbox-capsicum.o sandbox-pledge.o \
f5835d
 	sandbox-solaris.o uidswap.o
f5835d
 
f5835d
-MANPAGES	= moduli.5.out scp.1.out ssh-add.1.out ssh-agent.1.out ssh-keygen.1.out ssh-keyscan.1.out ssh.1.out sshd.8.out sftp-server.8.out sftp.1.out ssh-keysign.8.out ssh-pkcs11-helper.8.out sshd_config.5.out ssh_config.5.out
f5835d
-MANPAGES_IN	= moduli.5 scp.1 ssh-add.1 ssh-agent.1 ssh-keygen.1 ssh-keyscan.1 ssh.1 sshd.8 sftp-server.8 sftp.1 ssh-keysign.8 ssh-pkcs11-helper.8 sshd_config.5 ssh_config.5
f5835d
+MANPAGES	= moduli.5.out scp.1.out ssh-add.1.out ssh-agent.1.out ssh-keygen.1.out ssh-keyscan.1.out ssh.1.out sshd.8.out sftp-server.8.out sftp.1.out ssh-keysign.8.out ssh-pkcs11-helper.8.out sshd_config.5.out ssh_config.5.out ssh-ldap-helper.8.out ssh-ldap.conf.5.out
f5835d
+MANPAGES_IN	= moduli.5 scp.1 ssh-add.1 ssh-agent.1 ssh-keygen.1 ssh-keyscan.1 ssh.1 sshd.8 sftp-server.8 sftp.1 ssh-keysign.8 ssh-pkcs11-helper.8 sshd_config.5 ssh_config.5 ssh-ldap-helper.8 ssh-ldap.conf.5
f5835d
 MANTYPE		= @MANTYPE@
f5835d
 
f5835d
 CONFIGFILES=sshd_config.out ssh_config.out moduli.out
f5835d
@@ -184,6 +187,9 @@ ssh-keysign$(EXEEXT): $(LIBCOMPAT) libss
f5835d
 ssh-pkcs11-helper$(EXEEXT): $(LIBCOMPAT) libssh.a ssh-pkcs11-helper.o ssh-pkcs11.o
f5835d
 	$(LD) -o $@ ssh-pkcs11-helper.o ssh-pkcs11.o $(LDFLAGS) -lssh -lopenbsd-compat -lssh -lopenbsd-compat $(LIBS)
f5835d
 
f5835d
+ssh-ldap-helper$(EXEEXT): $(LIBCOMPAT) libssh.a ldapconf.o ldapbody.o ldapmisc.o ldap-helper.o
0d83e7
+	$(LD) -o $@ ldapconf.o ldapbody.o ldapmisc.o ldap-helper.o $(LDFLAGS) -lssh -lopenbsd-compat -lssh -lopenbsd-compat $(LIBS) $(LDAPLIBS)
f5835d
+
f5835d
 ssh-keyscan$(EXEEXT): $(LIBCOMPAT) libssh.a ssh-keyscan.o
f5835d
 	$(LD) -o $@ ssh-keyscan.o $(LDFLAGS) -lssh -lopenbsd-compat -lssh $(LIBS)
f5835d
 
f5835d
@@ -311,6 +317,10 @@ install-files:
f5835d
 	$(INSTALL) -m 0755 $(STRIP_OPT) sshd$(EXEEXT) $(DESTDIR)$(sbindir)/sshd$(EXEEXT)
f5835d
 	$(INSTALL) -m 4711 $(STRIP_OPT) ssh-keysign$(EXEEXT) $(DESTDIR)$(SSH_KEYSIGN)$(EXEEXT)
f5835d
 	$(INSTALL) -m 0755 $(STRIP_OPT) ssh-pkcs11-helper$(EXEEXT) $(DESTDIR)$(SSH_PKCS11_HELPER)$(EXEEXT)
f5835d
+	if test ! -z "$(INSTALL_SSH_LDAP_HELPER)" ; then \
f5835d
+		$(INSTALL) -m 0700 $(STRIP_OPT) ssh-ldap-helper $(DESTDIR)$(SSH_LDAP_HELPER) ; \
f5835d
+		$(INSTALL) -m 0700 ssh-ldap-wrapper $(DESTDIR)$(SSH_LDAP_WRAPPER) ; \
f5835d
+	fi
f5835d
 	$(INSTALL) -m 0755 $(STRIP_OPT) sftp$(EXEEXT) $(DESTDIR)$(bindir)/sftp$(EXEEXT)
f5835d
 	$(INSTALL) -m 0755 $(STRIP_OPT) sftp-server$(EXEEXT) $(DESTDIR)$(SFTP_SERVER)$(EXEEXT)
f5835d
 	$(INSTALL) -m 644 ssh.1.out $(DESTDIR)$(mandir)/$(mansubdir)1/ssh.1
f5835d
@@ -327,6 +337,10 @@ install-files:
f5835d
 	$(INSTALL) -m 644 sftp-server.8.out $(DESTDIR)$(mandir)/$(mansubdir)8/sftp-server.8
f5835d
 	$(INSTALL) -m 644 ssh-keysign.8.out $(DESTDIR)$(mandir)/$(mansubdir)8/ssh-keysign.8
f5835d
 	$(INSTALL) -m 644 ssh-pkcs11-helper.8.out $(DESTDIR)$(mandir)/$(mansubdir)8/ssh-pkcs11-helper.8
f5835d
+	if test ! -z "$(INSTALL_SSH_LDAP_HELPER)" ; then \
f5835d
+		$(INSTALL) -m 644 ssh-ldap-helper.8.out $(DESTDIR)$(mandir)/$(mansubdir)8/ssh-ldap-helper.8 ; \
f5835d
+		$(INSTALL) -m 644 ssh-ldap.conf.5.out $(DESTDIR)$(mandir)/$(mansubdir)5/ssh-ldap.conf.5 ; \
f5835d
+	fi
f5835d
 
f5835d
 install-sysconf:
f5835d
 	$(MKDIR_P) $(DESTDIR)$(sysconfdir)
f5835d
@@ -356,6 +370,13 @@ install-sysconf:
f5835d
 	else \
f5835d
 		echo "$(DESTDIR)$(sysconfdir)/moduli already exists, install will not overwrite"; \
f5835d
 	fi
f5835d
+	if test ! -z "$(INSTALL_SSH_LDAP_HELPER)" ; then \
f5835d
+		if [ ! -f $(DESTDIR)$(sysconfdir)/ldap.conf ]; then \
f5835d
+			$(INSTALL) -m 644 ldap.conf $(DESTDIR)$(sysconfdir)/ldap.conf; \
f5835d
+		else \
f5835d
+			echo "$(DESTDIR)$(sysconfdir)/ldap.conf already exists, install will not overwrite"; \
f5835d
+		fi ; \
f5835d
+	fi
f5835d
 
f5835d
 host-key: ssh-keygen$(EXEEXT)
f5835d
 	@if [ -z "$(DESTDIR)" ] ; then \
f5835d
@@ -419,6 +440,8 @@ uninstall:
f5835d
 	-rm -r $(DESTDIR)$(SFTP_SERVER)$(EXEEXT)
f5835d
 	-rm -f $(DESTDIR)$(SSH_KEYSIGN)$(EXEEXT)
f5835d
 	-rm -f $(DESTDIR)$(SSH_PKCS11_HELPER)$(EXEEXT)
f5835d
+	-rm -f $(DESTDIR)$(SSH_LDAP_HELPER)$(EXEEXT)
f5835d
+	-rm -f $(DESTDIR)$(SSH_LDAP_WRAPPER)$(EXEEXT)
f5835d
 	-rm -f $(DESTDIR)$(mandir)/$(mansubdir)1/ssh.1
f5835d
 	-rm -f $(DESTDIR)$(mandir)/$(mansubdir)1/scp.1
f5835d
 	-rm -f $(DESTDIR)$(mandir)/$(mansubdir)1/ssh-add.1
f5835d
@@ -430,6 +453,7 @@ uninstall:
f5835d
 	-rm -f $(DESTDIR)$(mandir)/$(mansubdir)8/sftp-server.8
f5835d
 	-rm -f $(DESTDIR)$(mandir)/$(mansubdir)8/ssh-keysign.8
f5835d
 	-rm -f $(DESTDIR)$(mandir)/$(mansubdir)8/ssh-pkcs11-helper.8
f5835d
+	-rm -f $(DESTDIR)$(mandir)/$(mansubdir)8/ssh-ldap-helper.8
f5835d
 
f5835d
 regress-prep:
f5835d
 	$(MKDIR_P) `pwd`/regress/unittests/test_helper
f5835d
diff -up openssh-6.8p1/configure.ac.ldap openssh-6.8p1/configure.ac
f5835d
--- openssh-6.8p1/configure.ac.ldap	2015-03-17 06:49:20.000000000 +0100
f5835d
+++ openssh-6.8p1/configure.ac	2015-03-18 11:11:29.030801464 +0100
f5835d
@@ -1605,6 +1605,110 @@ if test "x$use_pie" != "xno"; then
f5835d
 	fi
f5835d
 fi
f5835d
 
f5835d
+# Check whether user wants LDAP support
f5835d
+LDAP_MSG="no"
f5835d
+INSTALL_SSH_LDAP_HELPER=""
f5835d
+AC_ARG_WITH(ldap,
f5835d
+	[  --with-ldap[[=PATH]]      Enable LDAP pubkey support (optionally in PATH)],
f5835d
+	[
f5835d
+		if test "x$withval" != "xno" ; then
f5835d
+
f5835d
+			INSTALL_SSH_LDAP_HELPER="yes"
f5835d
+			CPPFLAGS="$CPPFLAGS -DLDAP_DEPRECATED"
f5835d
+
f5835d
+			if test "x$withval" != "xyes" ; then
f5835d
+				CPPFLAGS="$CPPFLAGS -I${withval}/include"
f5835d
+				LDFLAGS="$LDFLAGS -L${withval}/lib"
f5835d
+			fi
f5835d
+
f5835d
+			AC_DEFINE([WITH_LDAP_PUBKEY], 1, [Enable LDAP pubkey support])
f5835d
+			LDAP_MSG="yes"
f5835d
+
f5835d
+			AC_CHECK_HEADERS(lber.h)
f5835d
+			AC_CHECK_HEADERS(ldap.h, , AC_MSG_ERROR(could not locate <ldap.h>))
f5835d
+			AC_CHECK_HEADERS(ldap_ssl.h)
f5835d
+
f5835d
+			AC_ARG_WITH(ldap-lib,
f5835d
+				[  --with-ldap-lib=type    select ldap library [auto|netscape5|netscape4|netscape3|umich|openldap]])
f5835d
+
f5835d
+			if test -z "$with_ldap_lib"; then
f5835d
+				with_ldap_lib=auto
f5835d
+			fi
f5835d
+
f5835d
+			if test -z "$found_ldap_lib" -a \( $with_ldap_lib = auto -o $with_ldap_lib = umich -o $with_ldap_lib = openldap \); then
f5835d
+				AC_CHECK_LIB(lber, main, LDAPLIBS="-llber $LDAPLIBS" found_ldap_lib=yes)
f5835d
+				AC_CHECK_LIB(ldap, main, LDAPLIBS="-lldap $LDAPLIBS" found_ldap_lib=yes)
f5835d
+			fi
f5835d
+
f5835d
+			if test -z "$found_ldap_lib" -a \( $with_ldap_lib = auto -o $with_ldap_lib = netscape5 \); then
f5835d
+				AC_CHECK_LIB(ldap50, main, LDAPLIBS="-lldap50 -lssldap50 -lssl3 -lnss3 -lnspr4 -lprldap50 -lplc4 -lplds4 $LDAPLIBS" found_ldap_lib=yes)
f5835d
+			fi
f5835d
+
f5835d
+			if test -z "$found_ldap_lib" -a \( $with_ldap_lib = auto -o $with_ldap_lib = netscape4 \); then
f5835d
+				AC_CHECK_LIB(ldapssl41, main, LDAPLIBS="-lldapssl41 -lplc3 -lplds3 -lnspr3 $LDAPLIBS" found_ldap_lib=yes)
f5835d
+				if test -z "$found_ldap_lib"; then
f5835d
+					AC_CHECK_LIB(ldapssl40, main, LDAPLIBS="-lldapssl40 $LDAPLIBS" found_ldap_lib=yes)
f5835d
+				fi
f5835d
+				if test -z "$found_ldap_lib"; then
f5835d
+					AC_CHECK_LIB(ldap41, main, LDAPLIBS="-lldap41 $LDAPLIBS" found_ldap_lib=yes)
f5835d
+				fi
f5835d
+				if test -z "$found_ldap_lib"; then
f5835d
+					AC_CHECK_LIB(ldap40, main, LDAPLIBS="-lldap40 $LDAPLIBS" found_ldap_lib=yes)
f5835d
+				fi
f5835d
+			fi
f5835d
+
f5835d
+			if test -z "$found_ldap_lib" -a \( $with_ldap_lib = auto -o $with_ldap_lib = netscape3 \); then
f5835d
+				AC_CHECK_LIB(ldapssl30, main, LDAPLIBS="-lldapssl30 $LDAPLIBS" found_ldap_lib=yes)
f5835d
+			fi
f5835d
+
f5835d
+			if test -z "$found_ldap_lib"; then
f5835d
+				AC_MSG_ERROR(could not locate a valid LDAP library)
f5835d
+			fi
f5835d
+
f5835d
+			saved_LIBS="$LIBS"
f5835d
+			LIBS="$LIBS $LDAPLIBS"
f5835d
+			AC_MSG_CHECKING([for working LDAP support])
f5835d
+			AC_TRY_COMPILE(
f5835d
+				[#include <sys/types.h>
f5835d
+				 #include <ldap.h>],
f5835d
+				[(void)ldap_init(0, 0);],
f5835d
+				[AC_MSG_RESULT(yes)],
f5835d
+				[
f5835d
+				    AC_MSG_RESULT(no) 
f5835d
+					AC_MSG_ERROR([** Incomplete or missing ldap libraries **])
f5835d
+				])
f5835d
+			AC_CHECK_FUNCS( \
f5835d
+				ldap_init \
f5835d
+				ldap_get_lderrno \
f5835d
+				ldap_set_lderrno \
f5835d
+				ldap_parse_result \
f5835d
+				ldap_memfree \
f5835d
+				ldap_controls_free \
f5835d
+				ldap_set_option \
f5835d
+				ldap_get_option \
f5835d
+				ldapssl_init \
f5835d
+				ldap_start_tls_s \
f5835d
+				ldap_pvt_tls_set_option \
f5835d
+				ldap_initialize \
f5835d
+			)
f5835d
+			AC_CHECK_FUNCS(ldap_set_rebind_proc,
f5835d
+				AC_MSG_CHECKING([number arguments of ldap_set_rebind_proc])
f5835d
+				AC_TRY_COMPILE(
f5835d
+					[#include <lber.h>
f5835d
+					#include <ldap.h>],
f5835d
+					[ldap_set_rebind_proc(0, 0, 0);],
f5835d
+					[ac_cv_ldap_set_rebind_proc=3],
f5835d
+					[ac_cv_ldap_set_rebind_proc=2])
f5835d
+				AC_MSG_RESULT($ac_cv_ldap_set_rebind_proc)
4369a3
+				AC_DEFINE_UNQUOTED(LDAP_SET_REBIND_PROC_ARGS, $ac_cv_ldap_set_rebind_proc, [number arguments of ldap_set_rebind_proc])
f5835d
+			)
f5835d
+			LIBS="$saved_LIBS"
f5835d
+		fi
f5835d
+	]
f5835d
+)
f5835d
+AC_SUBST(INSTALL_SSH_LDAP_HELPER)
f5835d
+AC_SUBST(LDAPLIBS)
f5835d
+
f5835d
 dnl    Checks for library functions. Please keep in alphabetical order
f5835d
 AC_CHECK_FUNCS([ \
f5835d
 	Blowfish_initstate \
f5835d
@@ -5227,6 +5352,9 @@
f5835d
 echo "Preprocessor flags: ${CPPFLAGS}"
f5835d
 echo "      Linker flags: ${LDFLAGS}"
f5835d
 echo "         Libraries: ${LIBS}"
f5835d
+if test ! -z "${LDAPLIBS}"; then
f5835d
+echo "         +for ldap: ${LDAPLIBS}"
f5835d
+fi
f5835d
 if test ! -z "${SSHDLIBS}"; then
f5835d
 echo "         +for sshd: ${SSHDLIBS}"
f5835d
 fi
f5835d
diff -up openssh-6.8p1/ldap-helper.c.ldap openssh-6.8p1/ldap-helper.c
f5835d
--- openssh-6.8p1/ldap-helper.c.ldap	2015-03-18 11:11:29.030801464 +0100
f5835d
+++ openssh-6.8p1/ldap-helper.c	2015-03-18 11:11:29.030801464 +0100
f5835d
@@ -0,0 +1,151 @@
f5835d
+/* $OpenBSD: ssh-pka-ldap.c,v 1.1 2009/12/03 03:34:42 jfch Exp $ */
f5835d
+/*
f5835d
+ * Copyright (c) 2009 Jan F. Chadima.  All rights reserved.
f5835d
+ *
f5835d
+ * Redistribution and use in source and binary forms, with or without
f5835d
+ * modification, are permitted provided that the following conditions
f5835d
+ * are met:
f5835d
+ * 1. Redistributions of source code must retain the above copyright
f5835d
+ *    notice, this list of conditions and the following disclaimer.
f5835d
+ * 2. Redistributions in binary form must reproduce the above copyright
f5835d
+ *    notice, this list of conditions and the following disclaimer in the
f5835d
+ *    documentation and/or other materials provided with the distribution.
f5835d
+ *
f5835d
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
f5835d
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
f5835d
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
f5835d
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
f5835d
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
f5835d
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
f5835d
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
f5835d
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
f5835d
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
f5835d
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
f5835d
+ */
f5835d
+
f5835d
+#include "ldapincludes.h"
f5835d
+#include "log.h"
f5835d
+#include "misc.h"
f5835d
+#include "xmalloc.h"
f5835d
+#include "ldapconf.h"
f5835d
+#include "ldapbody.h"
f5835d
+#include <string.h>
f5835d
+#include <unistd.h>
f5835d
+#include <stdlib.h>
f5835d
+
f5835d
+static int config_debug = 0;
f5835d
+int config_exclusive_config_file = 0;
f5835d
+static char *config_file_name = "/etc/ssh/ldap.conf";
f5835d
+static char *config_single_user = NULL;
f5835d
+static int config_verbose = SYSLOG_LEVEL_VERBOSE;
f5835d
+int config_warning_config_file = 0;
f5835d
+extern char *__progname;
f5835d
+
f5835d
+static void
f5835d
+usage(void)
f5835d
+{
f5835d
+	fprintf(stderr, "usage: %s [options]\n",
f5835d
+	    __progname);
f5835d
+	fprintf(stderr, "Options:\n");
f5835d
+	fprintf(stderr, "  -d          Output the log messages to stderr.\n");
f5835d
+	fprintf(stderr, "  -e          Check the config file for unknown commands.\n");
f5835d
+	fprintf(stderr, "  -f file     Use alternate config file (default is /etc/ssh/ldap.conf).\n");
f5835d
+	fprintf(stderr, "  -s user     Do not demonize, send the user's key to stdout.\n");
f5835d
+	fprintf(stderr, "  -v          Increase verbosity of the debug output (implies -d).\n");
f5835d
+	fprintf(stderr, "  -w          Warn on unknown commands in the config file.\n");
f5835d
+	exit(1);
f5835d
+}
f5835d
+
f5835d
+/*
f5835d
+ * Main program for the ssh pka ldap agent.
f5835d
+ */
f5835d
+
f5835d
+int
f5835d
+main(int ac, char **av)
f5835d
+{
f5835d
+	int opt;
f5835d
+	FILE *outfile = NULL;
f5835d
+
f5835d
+	__progname = ssh_get_progname(av[0]);
f5835d
+
f5835d
+	log_init(__progname, SYSLOG_LEVEL_DEBUG3, SYSLOG_FACILITY_AUTH, 0);
f5835d
+
f5835d
+	/*
f5835d
+	 * Initialize option structure to indicate that no values have been
f5835d
+	 * set.
f5835d
+	 */
f5835d
+	initialize_options();
f5835d
+
f5835d
+	/* Parse command-line arguments. */
f5835d
+	while ((opt = getopt(ac, av, "def:s:vw")) != -1) {
f5835d
+		switch (opt) {
f5835d
+		case 'd':
f5835d
+			config_debug = 1;
f5835d
+			break;
f5835d
+
f5835d
+		case 'e':
f5835d
+			config_exclusive_config_file = 1;
f5835d
+			config_warning_config_file = 1;
f5835d
+			break;
f5835d
+
f5835d
+		case 'f':
f5835d
+			config_file_name = optarg;
f5835d
+			break;
f5835d
+
f5835d
+		case 's':
f5835d
+			config_single_user = optarg;
f5835d
+			outfile = fdopen (dup (fileno (stdout)), "w");
f5835d
+			break;
f5835d
+
f5835d
+		case 'v':
f5835d
+			config_debug = 1;
f5835d
+			if (config_verbose < SYSLOG_LEVEL_DEBUG3)
f5835d
+			    config_verbose++;
f5835d
+			break;
f5835d
+
f5835d
+		case 'w':
f5835d
+			config_warning_config_file = 1;
f5835d
+			break;
f5835d
+
f5835d
+		case '?':
f5835d
+		default:
f5835d
+			usage();
f5835d
+			break;
f5835d
+		}
f5835d
+	}
f5835d
+
f5835d
+	/* Initialize loging */
f5835d
+	log_init(__progname, config_verbose, SYSLOG_FACILITY_AUTH, config_debug);
f5835d
+
f5835d
+	if (ac != optind)
f5835d
+	    fatal ("illegal extra parameter %s", av[1]);
f5835d
+
f5835d
+	/* Ensure that fds 0 and 2 are open or directed to /dev/null */
f5835d
+	if (config_debug == 0)
f5835d
+	    sanitise_stdfd();
f5835d
+
f5835d
+	/* Read config file */
f5835d
+	read_config_file(config_file_name);
f5835d
+	fill_default_options();
f5835d
+	if (config_verbose == SYSLOG_LEVEL_DEBUG3) {
f5835d
+		debug3 ("=== Configuration ===");
f5835d
+		dump_config();
f5835d
+		debug3 ("=== *** ===");
f5835d
+	}
f5835d
+
f5835d
+	ldap_checkconfig();
f5835d
+	ldap_do_connect();
f5835d
+
f5835d
+	if (config_single_user) {
f5835d
+		process_user (config_single_user, outfile);
f5835d
+	} else {
f5835d
+		usage();
f5835d
+		fatal ("Not yet implemented");
f5835d
+/* TODO
f5835d
+ * open unix socket a run the loop on it
f5835d
+ */
f5835d
+	}
f5835d
+
f5835d
+	ldap_do_close();
f5835d
+	return 0;
f5835d
+}
f5835d
diff -up openssh-6.8p1/ldap-helper.h.ldap openssh-6.8p1/ldap-helper.h
f5835d
--- openssh-6.8p1/ldap-helper.h.ldap	2015-03-18 11:11:29.031801462 +0100
f5835d
+++ openssh-6.8p1/ldap-helper.h	2015-03-18 11:11:29.031801462 +0100
f5835d
@@ -0,0 +1,32 @@
f5835d
+/* $OpenBSD: ldap-helper.h,v 1.1 2009/12/03 03:34:42 jfch Exp $ */
f5835d
+/*
f5835d
+ * Copyright (c) 2009 Jan F. Chadima.  All rights reserved.
f5835d
+ *
f5835d
+ * Redistribution and use in source and binary forms, with or without
f5835d
+ * modification, are permitted provided that the following conditions
f5835d
+ * are met:
f5835d
+ * 1. Redistributions of source code must retain the above copyright
f5835d
+ *    notice, this list of conditions and the following disclaimer.
f5835d
+ * 2. Redistributions in binary form must reproduce the above copyright
f5835d
+ *    notice, this list of conditions and the following disclaimer in the
f5835d
+ *    documentation and/or other materials provided with the distribution.
f5835d
+ *
f5835d
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
f5835d
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
f5835d
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
f5835d
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
f5835d
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
f5835d
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
f5835d
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
f5835d
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
f5835d
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
f5835d
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
f5835d
+ */
f5835d
+
f5835d
+#ifndef LDAP_HELPER_H
f5835d
+#define LDAP_HELPER_H
f5835d
+
f5835d
+extern int config_exclusive_config_file;
f5835d
+extern int config_warning_config_file;
f5835d
+
f5835d
+#endif /* LDAP_HELPER_H */
f5835d
diff -up openssh-6.8p1/ldap.conf.ldap openssh-6.8p1/ldap.conf
f5835d
--- openssh-6.8p1/ldap.conf.ldap	2015-03-18 11:11:29.031801462 +0100
f5835d
+++ openssh-6.8p1/ldap.conf	2015-03-18 11:11:29.031801462 +0100
f5835d
@@ -0,0 +1,95 @@
f5835d
+# $Id: openssh-5.5p1-ldap.patch,v 1.3 2010/07/07 13:48:36 jfch2222 Exp $
f5835d
+#
f5835d
+# This is the example configuration file for the OpenSSH
f5835d
+# LDAP backend
f5835d
+# 
f5835d
+# see ssh-ldap.conf(5)
f5835d
+#
f5835d
+
f5835d
+# URI with your LDAP server name. This allows to use
f5835d
+# Unix Domain Sockets to connect to a local LDAP Server.
f5835d
+#uri ldap://127.0.0.1/
f5835d
+#uri ldaps://127.0.0.1/   
f5835d
+#uri ldapi://%2fvar%2frun%2fldapi_sock/
f5835d
+# Note: %2f encodes the '/' used as directory separator
f5835d
+
f5835d
+# Another way to specify your LDAP server is to provide an
f5835d
+# host name and the port of our LDAP server. Host name
f5835d
+# must be resolvable without using LDAP.
f5835d
+# Multiple hosts may be specified, each separated by a 
f5835d
+# space. How long nss_ldap takes to failover depends on
f5835d
+# whether your LDAP client library supports configurable
f5835d
+# network or connect timeouts (see bind_timelimit).
f5835d
+#host 127.0.0.1
f5835d
+
f5835d
+# The port.
f5835d
+# Optional: default is 389.
f5835d
+#port 389
f5835d
+
f5835d
+# The distinguished name to bind to the server with.
f5835d
+# Optional: default is to bind anonymously.
f5835d
+#binddn cn=openssh_keys,dc=example,dc=org
f5835d
+
f5835d
+# The credentials to bind with. 
f5835d
+# Optional: default is no credential.
f5835d
+#bindpw TopSecret
f5835d
+
f5835d
+# The distinguished name of the search base.
f5835d
+#base dc=example,dc=org
f5835d
+
f5835d
+# The LDAP version to use (defaults to 3
f5835d
+# if supported by client library)
f5835d
+#ldap_version 3
f5835d
+
f5835d
+# The search scope.
f5835d
+#scope sub
f5835d
+#scope one
f5835d
+#scope base
f5835d
+
f5835d
+# Search timelimit
f5835d
+#timelimit 30
f5835d
+
f5835d
+# Bind/connect timelimit
f5835d
+#bind_timelimit 30
f5835d
+
f5835d
+# Reconnect policy: hard (default) will retry connecting to
f5835d
+# the software with exponential backoff, soft will fail
f5835d
+# immediately.
f5835d
+#bind_policy hard
f5835d
+
f5835d
+# SSL setup, may be implied by URI also.
f5835d
+#ssl no
f5835d
+#ssl on
f5835d
+#ssl start_tls
f5835d
+
f5835d
+# OpenLDAP SSL options
f5835d
+# Require and verify server certificate (yes/no)
f5835d
+# Default is to use libldap's default behavior, which can be configured in
f5835d
+# /etc/openldap/ldap.conf using the TLS_REQCERT setting.  The default for
f5835d
+# OpenLDAP 2.0 and earlier is "no", for 2.1 and later is "yes".
f5835d
+#tls_checkpeer hard
f5835d
+
f5835d
+# CA certificates for server certificate verification
f5835d
+# At least one of these are required if tls_checkpeer is "yes"
f5835d
+#tls_cacertfile /etc/ssl/ca.cert
f5835d
+#tls_cacertdir /etc/pki/tls/certs
f5835d
+
f5835d
+# Seed the PRNG if /dev/urandom is not provided
f5835d
+#tls_randfile /var/run/egd-pool
f5835d
+
f5835d
+# SSL cipher suite
f5835d
+# See man ciphers for syntax
f5835d
+#tls_ciphers TLSv1
f5835d
+
f5835d
+# Client certificate and key
f5835d
+# Use these, if your server requires client authentication.
f5835d
+#tls_cert
f5835d
+#tls_key
f5835d
+
f5835d
+# OpenLDAP search_format
f5835d
+# format used to search for users in LDAP directory using substitution
f5835d
+# for %u for user name and %f for SSH_Filter option (optional, empty by default)
f5835d
+#search_format (&(objectclass=%c)(objectclass=ldapPublicKey)(uid=%u)%f)
f5835d
+
f5835d
+#AccountClass posixAccount
f5835d
+
f5835d
diff -up openssh-6.8p1/ldapbody.c.ldap openssh-6.8p1/ldapbody.c
f5835d
--- openssh-6.8p1/ldapbody.c.ldap	2015-03-18 11:11:29.031801462 +0100
f5835d
+++ openssh-6.8p1/ldapbody.c	2015-03-18 11:11:29.031801462 +0100
4369a3
@@ -0,0 +1,499 @@
f5835d
+/* $OpenBSD: ldapbody.c,v 1.1 2009/12/03 03:34:42 jfch Exp $ */
f5835d
+/*
f5835d
+ * Copyright (c) 2009 Jan F. Chadima.  All rights reserved.
f5835d
+ *
f5835d
+ * Redistribution and use in source and binary forms, with or without
f5835d
+ * modification, are permitted provided that the following conditions
f5835d
+ * are met:
f5835d
+ * 1. Redistributions of source code must retain the above copyright
f5835d
+ *    notice, this list of conditions and the following disclaimer.
f5835d
+ * 2. Redistributions in binary form must reproduce the above copyright
f5835d
+ *    notice, this list of conditions and the following disclaimer in the
f5835d
+ *    documentation and/or other materials provided with the distribution.
f5835d
+ *
f5835d
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
f5835d
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
f5835d
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
f5835d
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
f5835d
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
f5835d
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
f5835d
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
f5835d
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
f5835d
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
f5835d
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
f5835d
+ */
f5835d
+
f5835d
+#include "ldapincludes.h"
f5835d
+#include "log.h"
f5835d
+#include "xmalloc.h"
f5835d
+#include "ldapconf.h"
f5835d
+#include "ldapmisc.h"
f5835d
+#include "ldapbody.h"
f5835d
+#include <stdio.h>
f5835d
+#include <unistd.h>
f5835d
+#include <stdlib.h>
f5835d
+#include "misc.h"
f5835d
+
f5835d
+#define LDAPSEARCH_FORMAT "(&(objectclass=%c)(objectclass=ldapPublicKey)(uid=%u)%f)"
f5835d
+#define PUBKEYATTR "sshPublicKey"
f5835d
+#define LDAP_LOGFILE	"%s/ldap.%d"
f5835d
+
f5835d
+static FILE *logfile = NULL;
f5835d
+static LDAP *ld;
f5835d
+
f5835d
+static char *attrs[] = {
f5835d
+    PUBKEYATTR,
f5835d
+    NULL
f5835d
+};
f5835d
+
f5835d
+void
f5835d
+ldap_checkconfig (void)
f5835d
+{
f5835d
+#ifdef HAVE_LDAP_INITIALIZE
f5835d
+		if (options.host == NULL && options.uri == NULL)
f5835d
+#else
f5835d
+		if (options.host == NULL)
f5835d
+#endif
f5835d
+		    fatal ("missing  \"host\" in config file");
f5835d
+}
f5835d
+
f5835d
+#if defined(LDAP_API_FEATURE_X_OPENLDAP) && (LDAP_API_VERSION > 2000)
f5835d
+static int
4369a3
+#if LDAP_API_VERSION > 3000
4369a3
+_rebind_proc (LDAP * ld, LDAP_CONST char *url, ber_tag_t request, ber_int_t msgid, void *params)
4369a3
+#else
f5835d
+_rebind_proc (LDAP * ld, LDAP_CONST char *url, int request, ber_int_t msgid)
4369a3
+#endif
f5835d
+{
f5835d
+	struct timeval timeout;
f5835d
+	int rc;
f5835d
+#if defined(HAVE_LDAP_PARSE_RESULT) && defined(HAVE_LDAP_CONTROLS_FREE)
f5835d
+	LDAPMessage *result;
f5835d
+#endif /* HAVE_LDAP_PARSE_RESULT && HAVE_LDAP_CONTROLS_FREE */
f5835d
+
f5835d
+	debug2 ("Doing LDAP rebind to %s", options.binddn);
f5835d
+	if (options.ssl == SSL_START_TLS) {
f5835d
+		if ((rc = ldap_start_tls_s (ld, NULL, NULL)) != LDAP_SUCCESS) {
f5835d
+			error ("ldap_starttls_s: %s", ldap_err2string (rc));
f5835d
+			return LDAP_OPERATIONS_ERROR;
f5835d
+		}
f5835d
+	}
f5835d
+
f5835d
+#if !defined(HAVE_LDAP_PARSE_RESULT) || !defined(HAVE_LDAP_CONTROLS_FREE)
f5835d
+	return ldap_simple_bind_s (ld, options.binddn, options.bindpw);
f5835d
+#else
f5835d
+	if (ldap_simple_bind(ld, options.binddn, options.bindpw) < 0)
f5835d
+	    fatal ("ldap_simple_bind %s", ldap_err2string (ldap_get_lderrno (ld, 0, 0)));
f5835d
+
f5835d
+	timeout.tv_sec = options.bind_timelimit;
f5835d
+	timeout.tv_usec = 0;
f5835d
+	result = NULL;
f5835d
+	if ((rc = ldap_result (ld, msgid, 0, &timeout, &result)) < 1) {
f5835d
+		error ("ldap_result %s", ldap_err2string (ldap_get_lderrno (ld, 0, 0)));
f5835d
+		ldap_msgfree (result);
f5835d
+		return LDAP_OPERATIONS_ERROR;
f5835d
+	}
f5835d
+	debug3 ("LDAP rebind to %s succesfull", options.binddn);
f5835d
+	return rc;
f5835d
+#endif
f5835d
+}
f5835d
+#else
f5835d
+
f5835d
+static int
f5835d
+_rebind_proc (LDAP * ld, char **whop, char **credp, int *methodp, int freeit)
f5835d
+{
f5835d
+	if (freeit)
f5835d
+	    return LDAP_SUCCESS;
f5835d
+
f5835d
+	*whop = strdup (options.binddn);
f5835d
+	*credp = strdup (options.bindpw);
f5835d
+	*methodp = LDAP_AUTH_SIMPLE;
f5835d
+	debug2 ("Doing LDAP rebind for %s", *whop);
f5835d
+	return LDAP_SUCCESS;
f5835d
+}
f5835d
+#endif
f5835d
+
f5835d
+void
f5835d
+ldap_do_connect(void)
f5835d
+{
f5835d
+	int rc, msgid, ld_errno = 0;
f5835d
+	struct timeval timeout;
f5835d
+#if defined(HAVE_LDAP_PARSE_RESULT) && defined(HAVE_LDAP_CONTROLS_FREE)
f5835d
+	int parserc;
f5835d
+	LDAPMessage *result;
f5835d
+	LDAPControl **controls;
f5835d
+	int reconnect = 0;
f5835d
+#endif /* HAVE_LDAP_PARSE_RESULT && HAVE_LDAP_CONTROLS_FREE */
f5835d
+
f5835d
+	debug ("LDAP do connect");
f5835d
+
f5835d
+retry:
f5835d
+	if (reconnect) {
f5835d
+		debug3 ("Reconnecting with ld_errno %d", ld_errno);
f5835d
+		if (options.bind_policy == 0 ||
f5835d
+		    (ld_errno != LDAP_SERVER_DOWN && ld_errno != LDAP_TIMEOUT) ||
f5835d
+			reconnect > 5)
f5835d
+			    fatal ("Cannot connect to LDAP server");
f5835d
+	
f5835d
+		if (reconnect > 1)
f5835d
+			sleep (reconnect - 1);
f5835d
+
f5835d
+		if (ld != NULL) {
f5835d
+			ldap_unbind (ld);
f5835d
+			ld = NULL;
f5835d
+		}
f5835d
+		logit("reconnecting to LDAP server...");
f5835d
+	}
f5835d
+
f5835d
+	if (ld == NULL) {
f5835d
+		int rc;
f5835d
+		struct timeval tv;
f5835d
+
f5835d
+#ifdef HAVE_LDAP_SET_OPTION
f5835d
+		if (options.debug > 0) {
f5835d
+#ifdef LBER_OPT_LOG_PRINT_FILE
f5835d
+			if (options.logdir) {
f5835d
+				char *logfilename;
f5835d
+				int logfilenamelen;
f5835d
+
f5835d
+				logfilenamelen = strlen(LDAP_LOGFILE)
f5835d
+				    + strlen("000000") + strlen (options.logdir);
f5835d
+				logfilename = xmalloc (logfilenamelen);
f5835d
+				snprintf (logfilename, logfilenamelen, LDAP_LOGFILE, options.logdir, (int) getpid ());
f5835d
+				logfilename[logfilenamelen - 1] = 0;
f5835d
+				if ((logfile = fopen (logfilename, "a")) == NULL)
f5835d
+				    fatal ("cannot append to %s: %s", logfilename, strerror (errno));
f5835d
+				debug3 ("LDAP debug into %s", logfilename);
f5835d
+				free (logfilename);
f5835d
+				ber_set_option (NULL, LBER_OPT_LOG_PRINT_FILE, logfile);
f5835d
+			}
f5835d
+#endif
f5835d
+			if (options.debug) {
f5835d
+#ifdef LBER_OPT_DEBUG_LEVEL
f5835d
+				ber_set_option (NULL, LBER_OPT_DEBUG_LEVEL, &options.debug);
f5835d
+#endif /* LBER_OPT_DEBUG_LEVEL */
f5835d
+#ifdef LDAP_OPT_DEBUG_LEVEL
f5835d
+				(void) ldap_set_option (NULL, LDAP_OPT_DEBUG_LEVEL, &options.debug);
f5835d
+#endif /* LDAP_OPT_DEBUG_LEVEL */
f5835d
+				debug3 ("Set LDAP debug to %d", options.debug);
f5835d
+			}
f5835d
+		}
f5835d
+#endif /* HAVE_LDAP_SET_OPTION */
f5835d
+
f5835d
+		ld = NULL;
f5835d
+#ifdef HAVE_LDAPSSL_INIT
f5835d
+		if (options.host != NULL) {
f5835d
+			if (options.ssl_on == SSL_LDAPS) {
f5835d
+				if ((rc = ldapssl_client_init (options.sslpath, NULL)) != LDAP_SUCCESS)
f5835d
+				    fatal ("ldapssl_client_init %s", ldap_err2string (rc));
f5835d
+				debug3 ("LDAPssl client init");
f5835d
+			}
f5835d
+
f5835d
+			if (options.ssl_on != SSL_OFF) {
f5835d
+				if ((ld = ldapssl_init (options.host, options.port, 1)) == NULL)
f5835d
+				    fatal ("ldapssl_init failed");
f5835d
+				debug3 ("LDAPssl init");
f5835d
+			}
f5835d
+		}
f5835d
+#endif /* HAVE_LDAPSSL_INIT */
f5835d
+
f5835d
+		/* continue with opening */
f5835d
+		if (ld == NULL) {
f5835d
+#if defined (HAVE_LDAP_START_TLS_S) || (defined(HAVE_LDAP_SET_OPTION) && defined(LDAP_OPT_X_TLS))
f5835d
+			/* Some global TLS-specific options need to be set before we create our
f5835d
+			 * session context, so we set them here. */
f5835d
+
f5835d
+#ifdef LDAP_OPT_X_TLS_RANDOM_FILE
f5835d
+			/* rand file */
f5835d
+			if (options.tls_randfile != NULL) {
f5835d
+				if ((rc = ldap_set_option (NULL, LDAP_OPT_X_TLS_RANDOM_FILE,
f5835d
+				    options.tls_randfile)) != LDAP_SUCCESS)
f5835d
+					fatal ("ldap_set_option(LDAP_OPT_X_TLS_RANDOM_FILE): %s",
f5835d
+					    ldap_err2string (rc));
f5835d
+				debug3 ("Set TLS random file %s", options.tls_randfile);
f5835d
+			}
f5835d
+#endif /* LDAP_OPT_X_TLS_RANDOM_FILE */
f5835d
+
f5835d
+			/* ca cert file */
f5835d
+			if (options.tls_cacertfile != NULL) {
f5835d
+				if ((rc = ldap_set_option (NULL, LDAP_OPT_X_TLS_CACERTFILE,
f5835d
+				    options.tls_cacertfile)) != LDAP_SUCCESS)
f5835d
+					error ("ldap_set_option(LDAP_OPT_X_TLS_CACERTFILE): %s",
f5835d
+					    ldap_err2string (rc));
f5835d
+				debug3 ("Set TLS CA cert file %s ", options.tls_cacertfile);
f5835d
+			}
f5835d
+
f5835d
+			/* ca cert directory */
f5835d
+			if (options.tls_cacertdir != NULL) {
f5835d
+				if ((rc = ldap_set_option (NULL, LDAP_OPT_X_TLS_CACERTDIR,
f5835d
+				    options.tls_cacertdir)) != LDAP_SUCCESS)
f5835d
+					fatal ("ldap_set_option(LDAP_OPT_X_TLS_CACERTDIR): %s",
f5835d
+					    ldap_err2string (rc));
f5835d
+				debug3 ("Set TLS CA cert dir %s ", options.tls_cacertdir);
f5835d
+			}
f5835d
+
f5835d
+			/* require cert? */
f5835d
+			if ((rc = ldap_set_option (NULL, LDAP_OPT_X_TLS_REQUIRE_CERT,
f5835d
+			    &options.tls_checkpeer)) != LDAP_SUCCESS)
f5835d
+				fatal ("ldap_set_option(LDAP_OPT_X_TLS_REQUIRE_CERT): %s",
f5835d
+				    ldap_err2string (rc));
f5835d
+			debug3 ("Set TLS check peer to %d ", options.tls_checkpeer);
f5835d
+
f5835d
+			/* set cipher suite, certificate and private key: */
f5835d
+			if (options.tls_ciphers != NULL) {
f5835d
+				if ((rc = ldap_set_option (NULL, LDAP_OPT_X_TLS_CIPHER_SUITE,
f5835d
+				    options.tls_ciphers)) != LDAP_SUCCESS)
f5835d
+					fatal ("ldap_set_option(LDAP_OPT_X_TLS_CIPHER_SUITE): %s",
f5835d
+					    ldap_err2string (rc));
f5835d
+				debug3 ("Set TLS ciphers to %s ", options.tls_ciphers);
f5835d
+			}
f5835d
+
f5835d
+			/* cert file */
f5835d
+			if (options.tls_cert != NULL) {
f5835d
+				if ((rc = ldap_set_option (NULL, LDAP_OPT_X_TLS_CERTFILE,
f5835d
+				    options.tls_cert)) != LDAP_SUCCESS)
f5835d
+					fatal ("ldap_set_option(LDAP_OPT_X_TLS_CERTFILE): %s",
f5835d
+					    ldap_err2string (rc));
f5835d
+				debug3 ("Set TLS cert file %s ", options.tls_cert);
f5835d
+			}
f5835d
+
f5835d
+			/* key file */
f5835d
+			if (options.tls_key != NULL) {
f5835d
+				if ((rc = ldap_set_option (NULL, LDAP_OPT_X_TLS_KEYFILE,
f5835d
+				    options.tls_key)) != LDAP_SUCCESS)
f5835d
+					fatal ("ldap_set_option(LDAP_OPT_X_TLS_KEYFILE): %s",
f5835d
+					    ldap_err2string (rc));
f5835d
+				debug3 ("Set TLS key file %s ", options.tls_key);
f5835d
+			}
f5835d
+#endif
f5835d
+#ifdef HAVE_LDAP_INITIALIZE
f5835d
+			if (options.uri != NULL) {
f5835d
+				if ((rc = ldap_initialize (&ld, options.uri)) != LDAP_SUCCESS)
f5835d
+					fatal ("ldap_initialize %s", ldap_err2string (rc));
f5835d
+				debug3 ("LDAP initialize %s", options.uri);
f5835d
+			}
f5835d
+	}
f5835d
+#endif /* HAVE_LDAP_INTITIALIZE */
f5835d
+
f5835d
+		/* continue with opening */
f5835d
+		if ((ld == NULL) && (options.host != NULL)) {
f5835d
+#ifdef HAVE_LDAP_INIT
f5835d
+			if ((ld = ldap_init (options.host, options.port)) == NULL)
f5835d
+			    fatal ("ldap_init failed");
f5835d
+			debug3 ("LDAP init %s:%d", options.host, options.port);
f5835d
+#else
f5835d
+			if ((ld = ldap_open (options.host, options.port)) == NULL)
f5835d
+			    fatal ("ldap_open failed");
f5835d
+			debug3 ("LDAP open %s:%d", options.host, options.port);
f5835d
+#endif /* HAVE_LDAP_INIT */
f5835d
+		}
f5835d
+
f5835d
+		if (ld == NULL)
f5835d
+			fatal ("no way to open ldap");
f5835d
+
f5835d
+#if defined(HAVE_LDAP_SET_OPTION) && defined(LDAP_OPT_X_TLS)
f5835d
+		if (options.ssl == SSL_LDAPS) {
f5835d
+			if ((rc = ldap_set_option (ld, LDAP_OPT_X_TLS, &options.tls_checkpeer)) != LDAP_SUCCESS)
f5835d
+				fatal ("ldap_set_option(LDAP_OPT_X_TLS) %s", ldap_err2string (rc));
f5835d
+			debug3 ("LDAP set LDAP_OPT_X_TLS_%d", options.tls_checkpeer);
f5835d
+		}
f5835d
+#endif /* LDAP_OPT_X_TLS */
f5835d
+
f5835d
+#if defined(HAVE_LDAP_SET_OPTION) && defined(LDAP_OPT_PROTOCOL_VERSION)
f5835d
+		(void) ldap_set_option (ld, LDAP_OPT_PROTOCOL_VERSION,
f5835d
+		    &options.ldap_version);
f5835d
+#else
f5835d
+		ld->ld_version = options.ldap_version;
f5835d
+#endif
f5835d
+		debug3 ("LDAP set version to %d", options.ldap_version);
f5835d
+
f5835d
+#if LDAP_SET_REBIND_PROC_ARGS == 3
f5835d
+		ldap_set_rebind_proc (ld, _rebind_proc, NULL);
f5835d
+#elif LDAP_SET_REBIND_PROC_ARGS == 2
f5835d
+		ldap_set_rebind_proc (ld, _rebind_proc);
f5835d
+#else
f5835d
+#warning unknown LDAP_SET_REBIND_PROC_ARGS
f5835d
+#endif
f5835d
+		debug3 ("LDAP set rebind proc");
f5835d
+
f5835d
+#if defined(HAVE_LDAP_SET_OPTION) && defined(LDAP_OPT_DEREF)
f5835d
+		(void) ldap_set_option (ld, LDAP_OPT_DEREF, &options.deref);
f5835d
+#else
f5835d
+		ld->ld_deref = options.deref;
f5835d
+#endif
f5835d
+		debug3 ("LDAP set deref to %d", options.deref);
f5835d
+
f5835d
+#if defined(HAVE_LDAP_SET_OPTION) && defined(LDAP_OPT_TIMELIMIT)
f5835d
+		(void) ldap_set_option (ld, LDAP_OPT_TIMELIMIT,
f5835d
+		    &options.timelimit);
f5835d
+#else
f5835d
+		ld->ld_timelimit = options.timelimit;
f5835d
+#endif
f5835d
+		debug3 ("LDAP set timelimit to %d", options.timelimit);
f5835d
+
f5835d
+#if defined(HAVE_LDAP_SET_OPTION) && defined(LDAP_X_OPT_CONNECT_TIMEOUT)
f5835d
+		/*
f5835d
+		 * This is a new option in the Netscape SDK which sets 
f5835d
+		 * the TCP connect timeout. For want of a better value,
f5835d
+		 * we use the bind_timelimit to control this.
f5835d
+		 */
f5835d
+		timeout = options.bind_timelimit * 1000;
f5835d
+		(void) ldap_set_option (ld, LDAP_X_OPT_CONNECT_TIMEOUT, &timeout);
f5835d
+		debug3 ("LDAP set opt connect timeout to %d", timeout);
f5835d
+#endif
f5835d
+
f5835d
+#if defined(HAVE_LDAP_SET_OPTION) && defined(LDAP_OPT_NETWORK_TIMEOUT)
f5835d
+		tv.tv_sec = options.bind_timelimit;
f5835d
+		tv.tv_usec = 0;
f5835d
+		(void) ldap_set_option (ld, LDAP_OPT_NETWORK_TIMEOUT, &tv;;
f5835d
+		debug3 ("LDAP set opt network timeout to %ld.0", tv.tv_sec);
f5835d
+#endif
f5835d
+
f5835d
+#if defined(HAVE_LDAP_SET_OPTION) && defined(LDAP_OPT_REFERRALS)
f5835d
+		(void) ldap_set_option (ld, LDAP_OPT_REFERRALS,
f5835d
+		    options.referrals ? LDAP_OPT_ON : LDAP_OPT_OFF);
f5835d
+		debug3 ("LDAP set referrals to %d", options.referrals);
f5835d
+#endif
f5835d
+
f5835d
+#if defined(HAVE_LDAP_SET_OPTION) && defined(LDAP_OPT_RESTART)
f5835d
+		(void) ldap_set_option (ld, LDAP_OPT_RESTART,
f5835d
+		    options.restart ? LDAP_OPT_ON : LDAP_OPT_OFF);
f5835d
+		debug3 ("LDAP set restart to %d", options.restart);
f5835d
+#endif
f5835d
+
f5835d
+#ifdef HAVE_LDAP_START_TLS_S
f5835d
+		if (options.ssl == SSL_START_TLS) {
f5835d
+			int version;
f5835d
+
f5835d
+			if (ldap_get_option (ld, LDAP_OPT_PROTOCOL_VERSION, &version)
f5835d
+			    == LDAP_SUCCESS) {
f5835d
+				if (version < LDAP_VERSION3) {
f5835d
+					version = LDAP_VERSION3;
f5835d
+					(void) ldap_set_option (ld, LDAP_OPT_PROTOCOL_VERSION,
f5835d
+					    &version);
f5835d
+					debug3 ("LDAP set version to %d", version);
f5835d
+				}
f5835d
+			}
f5835d
+
f5835d
+			if ((rc = ldap_start_tls_s (ld, NULL, NULL)) != LDAP_SUCCESS)
f5835d
+			    fatal ("ldap_starttls_s: %s", ldap_err2string (rc));
f5835d
+			debug3 ("LDAP start TLS");
f5835d
+		}
f5835d
+#endif /* HAVE_LDAP_START_TLS_S */
f5835d
+	}
f5835d
+
f5835d
+	if ((msgid = ldap_simple_bind (ld, options.binddn,
f5835d
+	    options.bindpw)) == -1) {
f5835d
+		ld_errno = ldap_get_lderrno (ld, 0, 0);
f5835d
+
f5835d
+		error ("ldap_simple_bind %s", ldap_err2string (ld_errno));
f5835d
+		reconnect++;
f5835d
+		goto retry;
f5835d
+	}
f5835d
+	debug3 ("LDAP simple bind (%s)", options.binddn);
f5835d
+
f5835d
+	timeout.tv_sec = options.bind_timelimit;
f5835d
+	timeout.tv_usec = 0;
f5835d
+	if ((rc = ldap_result (ld, msgid, 0, &timeout, &result)) < 1) {
f5835d
+		ld_errno = ldap_get_lderrno (ld, 0, 0);
f5835d
+
f5835d
+		error ("ldap_result %s", ldap_err2string (ld_errno));
f5835d
+		reconnect++;
f5835d
+		goto retry;
f5835d
+	}
f5835d
+	debug3 ("LDAP result in time");
f5835d
+
f5835d
+#if defined(HAVE_LDAP_PARSE_RESULT) && defined(HAVE_LDAP_CONTROLS_FREE)
f5835d
+	controls = NULL;
f5835d
+	if ((parserc = ldap_parse_result (ld, result, &rc, 0, 0, 0, &controls, 1)) != LDAP_SUCCESS)
f5835d
+	    fatal ("ldap_parse_result %s", ldap_err2string (parserc));
f5835d
+	debug3 ("LDAP parse result OK");
f5835d
+
f5835d
+	if (controls != NULL) {
f5835d
+		ldap_controls_free (controls);
f5835d
+	}
f5835d
+#else
f5835d
+	rc = ldap_result2error (session->ld, result, 1);
f5835d
+#endif
f5835d
+	if (rc != LDAP_SUCCESS)
f5835d
+	    fatal ("error trying to bind as user \"%s\" (%s)",
f5835d
+		options.binddn, ldap_err2string (rc));
f5835d
+
f5835d
+	debug2 ("LDAP do connect OK");
f5835d
+}
f5835d
+
f5835d
+void
f5835d
+process_user (const char *user, FILE *output)
f5835d
+{
f5835d
+	LDAPMessage *res, *e;
f5835d
+	char *buffer, *format;
f5835d
+	int rc, i;
f5835d
+	struct timeval timeout;
f5835d
+
f5835d
+	debug ("LDAP process user");
f5835d
+
f5835d
+	/* quick check for attempts to be evil */
f5835d
+	if ((strchr(user, '(') != NULL) || (strchr(user, ')') != NULL) ||
f5835d
+	    (strchr(user, '*') != NULL) || (strchr(user, '\\') != NULL)) {
f5835d
+		logit ("illegal user name %s not processed", user);
f5835d
+		return;
f5835d
+	}
f5835d
+
f5835d
+	/* build  filter for LDAP request */
f5835d
+	format = LDAPSEARCH_FORMAT;
f5835d
+	if (options.search_format != NULL)
f5835d
+		format = options.search_format;
f5835d
+	buffer = percent_expand(format, "c", options.account_class, "u", user, "f", options.ssh_filter, (char *)NULL);
f5835d
+
f5835d
+	debug3 ("LDAP search scope = %d %s", options.scope, buffer);
f5835d
+
f5835d
+	timeout.tv_sec = options.timelimit;
f5835d
+	timeout.tv_usec = 0;
f5835d
+	if ((rc = ldap_search_st(ld, options.base, options.scope, buffer, attrs, 0, &timeout, &res)) != LDAP_SUCCESS) {
f5835d
+		error ("ldap_search_st(): %s", ldap_err2string (rc));
f5835d
+		free (buffer);
f5835d
+		return;
f5835d
+	}
f5835d
+
f5835d
+	/* free */
f5835d
+	free (buffer);
f5835d
+
f5835d
+	for (e = ldap_first_entry(ld, res); e != NULL; e = ldap_next_entry(ld, e)) {
f5835d
+		int num;
f5835d
+		struct berval **keys;
f5835d
+
f5835d
+		keys = ldap_get_values_len(ld, e, PUBKEYATTR);
f5835d
+		num = ldap_count_values_len(keys);
f5835d
+		for (i = 0 ; i < num ; i++) {
f5835d
+			char *cp; //, *options = NULL;
f5835d
+
f5835d
+			for (cp = keys[i]->bv_val; *cp == ' ' || *cp == '\t'; cp++);
f5835d
+			if (!*cp || *cp == '\n' || *cp == '#')
f5835d
+			    continue;
f5835d
+
f5835d
+			/* We have found the desired key. */
f5835d
+			fprintf (output, "%s\n", keys[i]->bv_val);
f5835d
+		}
f5835d
+
f5835d
+		ldap_value_free_len(keys);
f5835d
+	}
f5835d
+
f5835d
+	ldap_msgfree(res);
f5835d
+	debug2 ("LDAP process user finished");
f5835d
+}
f5835d
+
f5835d
+void
f5835d
+ldap_do_close(void)
f5835d
+{
f5835d
+	int rc;
f5835d
+
f5835d
+	debug ("LDAP do close");
f5835d
+	if ((rc = ldap_unbind_ext(ld, NULL, NULL)) != LDAP_SUCCESS)
f5835d
+	    fatal ("ldap_unbind_ext: %s",
f5835d
+                                    ldap_err2string (rc));
f5835d
+
f5835d
+	ld = NULL;
f5835d
+	debug2 ("LDAP do close OK");
f5835d
+	return;
f5835d
+}
f5835d
+
f5835d
diff -up openssh-6.8p1/ldapbody.h.ldap openssh-6.8p1/ldapbody.h
f5835d
--- openssh-6.8p1/ldapbody.h.ldap	2015-03-18 11:11:29.031801462 +0100
f5835d
+++ openssh-6.8p1/ldapbody.h	2015-03-18 11:11:29.031801462 +0100
f5835d
@@ -0,0 +1,37 @@
f5835d
+/* $OpenBSD: ldapbody.h,v 1.1 2009/12/03 03:34:42 jfch Exp $ */
f5835d
+/*
f5835d
+ * Copyright (c) 2009 Jan F. Chadima.  All rights reserved.
f5835d
+ *
f5835d
+ * Redistribution and use in source and binary forms, with or without
f5835d
+ * modification, are permitted provided that the following conditions
f5835d
+ * are met:
f5835d
+ * 1. Redistributions of source code must retain the above copyright
f5835d
+ *    notice, this list of conditions and the following disclaimer.
f5835d
+ * 2. Redistributions in binary form must reproduce the above copyright
f5835d
+ *    notice, this list of conditions and the following disclaimer in the
f5835d
+ *    documentation and/or other materials provided with the distribution.
f5835d
+ *
f5835d
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
f5835d
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
f5835d
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
f5835d
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
f5835d
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
f5835d
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
f5835d
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
f5835d
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
f5835d
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
f5835d
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
f5835d
+ */
f5835d
+
f5835d
+#ifndef LDAPBODY_H
f5835d
+#define LDAPBODY_H
f5835d
+
f5835d
+#include <stdio.h>
f5835d
+
f5835d
+void ldap_checkconfig(void);
f5835d
+void ldap_do_connect(void);
f5835d
+void process_user(const char *, FILE *);
f5835d
+void ldap_do_close(void);
f5835d
+
f5835d
+#endif /* LDAPBODY_H */
f5835d
+
f5835d
diff -up openssh-6.8p1/ldapconf.c.ldap openssh-6.8p1/ldapconf.c
f5835d
--- openssh-6.8p1/ldapconf.c.ldap	2015-03-18 11:11:29.032801460 +0100
f5835d
+++ openssh-6.8p1/ldapconf.c	2015-03-18 11:11:29.032801460 +0100
f5835d
@@ -0,0 +1,729 @@
f5835d
+/* $OpenBSD: ldapconf.c,v 1.1 2009/12/03 03:34:42 jfch Exp $ */
f5835d
+/*
f5835d
+ * Copyright (c) 2009 Jan F. Chadima.  All rights reserved.
f5835d
+ *
f5835d
+ * Redistribution and use in source and binary forms, with or without
f5835d
+ * modification, are permitted provided that the following conditions
f5835d
+ * are met:
f5835d
+ * 1. Redistributions of source code must retain the above copyright
f5835d
+ *    notice, this list of conditions and the following disclaimer.
f5835d
+ * 2. Redistributions in binary form must reproduce the above copyright
f5835d
+ *    notice, this list of conditions and the following disclaimer in the
f5835d
+ *    documentation and/or other materials provided with the distribution.
f5835d
+ *
f5835d
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
f5835d
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
f5835d
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
f5835d
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
f5835d
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
f5835d
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
f5835d
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
f5835d
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
f5835d
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
f5835d
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
f5835d
+ */
f5835d
+
f5835d
+#include "ldapincludes.h"
f5835d
+#include "ldap-helper.h"
f5835d
+#include "log.h"
f5835d
+#include "misc.h"
f5835d
+#include "xmalloc.h"
f5835d
+#include "ldapconf.h"
f5835d
+#include <unistd.h>
f5835d
+#include <string.h>
f5835d
+#include <stdlib.h>
f5835d
+
f5835d
+/* Keyword tokens. */
f5835d
+
f5835d
+typedef enum {
f5835d
+	lBadOption,
f5835d
+	lHost, lURI, lBase, lBindDN, lBindPW, lRootBindDN,
f5835d
+	lScope, lDeref, lPort, lTimeLimit, lBind_TimeLimit,
f5835d
+	lLdap_Version, lBind_Policy, lSSLPath, lSSL, lReferrals,
f5835d
+	lRestart, lTLS_CheckPeer, lTLS_CaCertFile,
f5835d
+	lTLS_CaCertDir, lTLS_Ciphers, lTLS_Cert, lTLS_Key,
f5835d
+	lTLS_RandFile, lLogDir, lDebug, lSSH_Filter, lSearch_Format,
f5835d
+	lAccountClass, lDeprecated, lUnsupported
f5835d
+} OpCodes;
f5835d
+
f5835d
+/* Textual representations of the tokens. */
f5835d
+
f5835d
+static struct {
f5835d
+	const char *name;
f5835d
+	OpCodes opcode;
f5835d
+} keywords[] = {
f5835d
+	{ "URI", lURI },
f5835d
+	{ "Base", lBase },
f5835d
+	{ "BindDN", lBindDN },
f5835d
+	{ "BindPW", lBindPW },
f5835d
+	{ "RootBindDN", lRootBindDN },
f5835d
+	{ "Host", lHost },
f5835d
+	{ "Port", lPort },
f5835d
+	{ "Scope", lScope },
f5835d
+	{ "Deref", lDeref },
f5835d
+	{ "TimeLimit", lTimeLimit },
f5835d
+	{ "TimeOut", lTimeLimit },
f5835d
+	{ "Bind_Timelimit", lBind_TimeLimit },
f5835d
+	{ "Network_TimeOut", lBind_TimeLimit },
f5835d
+/*
f5835d
+ * Todo
f5835d
+ * SIZELIMIT
f5835d
+ */
f5835d
+	{ "Ldap_Version", lLdap_Version },
f5835d
+	{ "Version", lLdap_Version },
f5835d
+	{ "Bind_Policy", lBind_Policy },
f5835d
+	{ "SSLPath", lSSLPath },
f5835d
+	{ "SSL", lSSL },
f5835d
+	{ "Referrals", lReferrals },
f5835d
+	{ "Restart", lRestart },
f5835d
+	{ "TLS_CheckPeer", lTLS_CheckPeer },
f5835d
+	{ "TLS_ReqCert", lTLS_CheckPeer },
f5835d
+	{ "TLS_CaCertFile", lTLS_CaCertFile },
f5835d
+	{ "TLS_CaCert", lTLS_CaCertFile },
f5835d
+	{ "TLS_CaCertDir", lTLS_CaCertDir },
f5835d
+	{ "TLS_Ciphers", lTLS_Ciphers },
f5835d
+	{ "TLS_Cipher_Suite", lTLS_Ciphers },
f5835d
+	{ "TLS_Cert", lTLS_Cert },
f5835d
+	{ "TLS_Certificate", lTLS_Cert },
f5835d
+	{ "TLS_Key", lTLS_Key },
f5835d
+	{ "TLS_RandFile", lTLS_RandFile },
f5835d
+/*
f5835d
+ * Todo
f5835d
+ * TLS_CRLCHECK
f5835d
+ * TLS_CRLFILE
f5835d
+ */
f5835d
+	{ "LogDir", lLogDir },
f5835d
+	{ "Debug", lDebug },
f5835d
+	{ "SSH_Filter", lSSH_Filter },
f5835d
+	{ "search_format", lSearch_Format },
f5835d
+	{ "AccountClass", lAccountClass },
f5835d
+	{ NULL, lBadOption }
f5835d
+};
f5835d
+
f5835d
+/* Configuration ptions. */
f5835d
+
f5835d
+Options options;
f5835d
+
f5835d
+/*
f5835d
+ * Returns the number of the token pointed to by cp or oBadOption.
f5835d
+ */
f5835d
+
f5835d
+static OpCodes
f5835d
+parse_token(const char *cp, const char *filename, int linenum)
f5835d
+{
f5835d
+	u_int i;
f5835d
+
f5835d
+	for (i = 0; keywords[i].name; i++)
f5835d
+		if (strcasecmp(cp, keywords[i].name) == 0)
f5835d
+			return keywords[i].opcode;
f5835d
+
f5835d
+	if (config_warning_config_file) 
f5835d
+	    logit("%s: line %d: Bad configuration option: %s",
f5835d
+		filename, linenum, cp);
f5835d
+	return lBadOption;
f5835d
+}
f5835d
+
f5835d
+/* Characters considered whitespace in strsep calls. */
f5835d
+#define WHITESPACE " \t\r\n"
f5835d
+
f5835d
+/* return next token in configuration line */
f5835d
+static char *
f5835d
+ldap_strdelim(char **s)
f5835d
+{
f5835d
+      char *old;
f5835d
+      int wspace = 0;
f5835d
+
f5835d
+      if (*s == NULL)
f5835d
+              return NULL;
f5835d
+
f5835d
+      old = *s;
f5835d
+
f5835d
+      *s = strpbrk(*s, WHITESPACE);
f5835d
+      if (*s == NULL)
f5835d
+              return (old);
f5835d
+
f5835d
+      *s[0] = '\0';
f5835d
+
f5835d
+      /* Skip any extra whitespace after first token */
f5835d
+      *s += strspn(*s + 1, WHITESPACE) + 1;
f5835d
+      if (*s[0] == '=' && !wspace)
f5835d
+              *s += strspn(*s + 1, WHITESPACE) + 1;
f5835d
+
f5835d
+      return (old);
f5835d
+}
f5835d
+
f5835d
+/*
f5835d
+ * Processes a single option line as used in the configuration files. This
f5835d
+ * only sets those values that have not already been set.
f5835d
+ */
f5835d
+#define WHITESPACE " \t\r\n"
f5835d
+
f5835d
+static int
f5835d
+process_config_line(char *line, const char *filename, int linenum)
f5835d
+{
f5835d
+	char *s, **charptr, **xstringptr, *endofnumber, *keyword, *arg;
f5835d
+	char *rootbinddn = NULL;
f5835d
+	int opcode, *intptr, value;
f5835d
+	size_t len;
f5835d
+
f5835d
+	/* Strip trailing whitespace */
f5835d
+	for (len = strlen(line) - 1; len > 0; len--) {
f5835d
+		if (strchr(WHITESPACE, line[len]) == NULL)
f5835d
+			break;
f5835d
+		line[len] = '\0';
f5835d
+	}
f5835d
+
f5835d
+	s = line;
f5835d
+	/* Get the keyword. (Each line is supposed to begin with a keyword). */
f5835d
+	if ((keyword = ldap_strdelim(&s)) == NULL)
f5835d
+		return 0;
f5835d
+	/* Ignore leading whitespace. */
f5835d
+	if (*keyword == '\0')
f5835d
+		keyword = ldap_strdelim(&s);
f5835d
+	if (keyword == NULL || !*keyword || *keyword == '\n' || *keyword == '#')
f5835d
+		return 0;
f5835d
+
f5835d
+	opcode = parse_token(keyword, filename, linenum);
f5835d
+
f5835d
+	switch (opcode) {
f5835d
+	case lBadOption:
f5835d
+		/* don't panic, but count bad options */
f5835d
+		return -1;
f5835d
+		/* NOTREACHED */
f5835d
+
f5835d
+	case lHost:
f5835d
+		xstringptr = &options.host;
f5835d
+parse_xstring:
f5835d
+		if (!s || *s == '\0')
f5835d
+		    fatal("%s line %d: missing dn",filename,linenum);
f5835d
+		if (*xstringptr == NULL)
f5835d
+		    *xstringptr = xstrdup(s);
f5835d
+		return 0;
f5835d
+
f5835d
+	case lURI:
f5835d
+		xstringptr = &options.uri;
f5835d
+		goto parse_xstring;
f5835d
+
f5835d
+	case lBase:
f5835d
+		xstringptr = &options.base;
f5835d
+		goto parse_xstring;
f5835d
+
f5835d
+	case lBindDN:
f5835d
+		xstringptr = &options.binddn;
f5835d
+		goto parse_xstring;
f5835d
+
f5835d
+	case lBindPW:
f5835d
+		charptr = &options.bindpw;
f5835d
+parse_string:
f5835d
+		arg = ldap_strdelim(&s);
f5835d
+		if (!arg || *arg == '\0')
f5835d
+			fatal("%.200s line %d: Missing argument.", filename, linenum);
f5835d
+		if (*charptr == NULL)
f5835d
+			*charptr = xstrdup(arg);
f5835d
+		break;
f5835d
+
f5835d
+	case lRootBindDN:
f5835d
+		xstringptr = &rootbinddn;
f5835d
+		goto parse_xstring;
f5835d
+
f5835d
+	case lScope:
f5835d
+		intptr = &options.scope;
f5835d
+		arg = ldap_strdelim(&s);
f5835d
+		if (!arg || *arg == '\0')
f5835d
+			fatal("%.200s line %d: Missing sub/one/base argument.", filename, linenum);
f5835d
+		value = 0;	/* To avoid compiler warning... */
f5835d
+		if (strcasecmp (arg, "sub") == 0 || strcasecmp (arg, "subtree") == 0)
f5835d
+			value = LDAP_SCOPE_SUBTREE;
f5835d
+		else if (strcasecmp (arg, "one") == 0)
f5835d
+			value = LDAP_SCOPE_ONELEVEL;
f5835d
+		else if (strcasecmp (arg, "base") == 0)
f5835d
+			value = LDAP_SCOPE_BASE;
f5835d
+		else
f5835d
+			fatal("%.200s line %d: Bad sub/one/base argument.", filename, linenum);
f5835d
+		if (*intptr == -1)
f5835d
+			*intptr = value;
f5835d
+		break;
f5835d
+
f5835d
+	case lDeref:
f5835d
+		intptr = &options.scope;
f5835d
+		arg = ldap_strdelim(&s);
f5835d
+		if (!arg || *arg == '\0')
f5835d
+			fatal("%.200s line %d: Missing never/searching/finding/always argument.", filename, linenum);
f5835d
+		value = 0;	/* To avoid compiler warning... */
f5835d
+		if (!strcasecmp (arg, "never"))
f5835d
+			value = LDAP_DEREF_NEVER;
f5835d
+		else if (!strcasecmp (arg, "searching"))
f5835d
+			value = LDAP_DEREF_SEARCHING;
f5835d
+		else if (!strcasecmp (arg, "finding"))
f5835d
+			value = LDAP_DEREF_FINDING;
f5835d
+		else if (!strcasecmp (arg, "always"))
f5835d
+			value = LDAP_DEREF_ALWAYS;
f5835d
+		else
f5835d
+			fatal("%.200s line %d: Bad never/searching/finding/always argument.", filename, linenum);
f5835d
+		if (*intptr == -1)
f5835d
+			*intptr = value;
f5835d
+		break;
f5835d
+
f5835d
+	case lPort:
f5835d
+		intptr = &options.port;
f5835d
+parse_int:
f5835d
+		arg = ldap_strdelim(&s);
f5835d
+		if (!arg || *arg == '\0')
f5835d
+			fatal("%.200s line %d: Missing argument.", filename, linenum);
f5835d
+		if (arg[0] < '0' || arg[0] > '9')
f5835d
+			fatal("%.200s line %d: Bad number.", filename, linenum);
f5835d
+
f5835d
+		/* Octal, decimal, or hex format? */
f5835d
+		value = strtol(arg, &endofnumber, 0);
f5835d
+		if (arg == endofnumber)
f5835d
+			fatal("%.200s line %d: Bad number.", filename, linenum);
f5835d
+		if (*intptr == -1)
f5835d
+			*intptr = value;
f5835d
+		break;
f5835d
+
f5835d
+	case lTimeLimit:
f5835d
+		intptr = &options.timelimit;
f5835d
+parse_time:
f5835d
+		arg = ldap_strdelim(&s);
f5835d
+		if (!arg || *arg == '\0')
f5835d
+			fatal("%s line %d: missing time value.",
f5835d
+			    filename, linenum);
f5835d
+		if ((value = convtime(arg)) == -1)
f5835d
+			fatal("%s line %d: invalid time value.",
f5835d
+			    filename, linenum);
f5835d
+		if (*intptr == -1)
f5835d
+			*intptr = value;
f5835d
+		break;
f5835d
+
f5835d
+	case lBind_TimeLimit:
f5835d
+		intptr = &options.bind_timelimit;
f5835d
+		goto parse_time;
f5835d
+
f5835d
+	case lLdap_Version:
f5835d
+		intptr = &options.ldap_version;
f5835d
+		goto parse_int;
f5835d
+
f5835d
+	case lBind_Policy:
f5835d
+		intptr = &options.bind_policy;
f5835d
+		arg = ldap_strdelim(&s);
f5835d
+		if (!arg || *arg == '\0')
f5835d
+			fatal("%.200s line %d: Missing soft/hard argument.", filename, linenum);
f5835d
+		value = 0;	/* To avoid compiler warning... */
f5835d
+		if (strcasecmp(arg, "hard") == 0 || strcasecmp(arg, "hard_open") == 0 || strcasecmp(arg, "hard_init") == 0)
f5835d
+			value = 1;
f5835d
+		else if (strcasecmp(arg, "soft") == 0)
f5835d
+			value = 0;
f5835d
+		else
f5835d
+			fatal("%.200s line %d: Bad soft/hard argument.", filename, linenum);
f5835d
+		if (*intptr == -1)
f5835d
+			*intptr = value;
f5835d
+		break;
f5835d
+
f5835d
+	case lSSLPath:
f5835d
+		charptr = &options.sslpath;
f5835d
+		goto parse_string;
f5835d
+
f5835d
+	case lSSL:
f5835d
+		intptr = &options.ssl;
f5835d
+		arg = ldap_strdelim(&s);
f5835d
+		if (!arg || *arg == '\0')
f5835d
+			fatal("%.200s line %d: Missing yes/no/start_tls argument.", filename, linenum);
f5835d
+		value = 0;	/* To avoid compiler warning... */
f5835d
+		if (strcasecmp(arg, "yes") == 0 || strcasecmp(arg, "true") == 0 || strcasecmp(arg, "on") == 0)
f5835d
+			value = SSL_LDAPS;
f5835d
+		else if (strcasecmp(arg, "no") == 0 || strcasecmp(arg, "false") == 0 || strcasecmp(arg, "off") == 0)
f5835d
+			value = SSL_OFF;
f5835d
+		else if (!strcasecmp (arg, "start_tls"))
f5835d
+			value = SSL_START_TLS;
f5835d
+		else
f5835d
+			fatal("%.200s line %d: Bad yes/no/start_tls argument.", filename, linenum);
f5835d
+		if (*intptr == -1)
f5835d
+			*intptr = value;
f5835d
+		break;
f5835d
+
f5835d
+	case lReferrals:
f5835d
+		intptr = &options.referrals;
f5835d
+parse_flag:
f5835d
+		arg = ldap_strdelim(&s);
f5835d
+		if (!arg || *arg == '\0')
f5835d
+			fatal("%.200s line %d: Missing yes/no argument.", filename, linenum);
f5835d
+		value = 0;	/* To avoid compiler warning... */
f5835d
+		if (strcasecmp(arg, "yes") == 0 || strcasecmp(arg, "true") == 0 || strcasecmp(arg, "on") == 0)
f5835d
+			value = 1;
f5835d
+		else if (strcasecmp(arg, "no") == 0 || strcasecmp(arg, "false") == 0 || strcasecmp(arg, "off") == 0)
f5835d
+			value = 0;
f5835d
+		else
f5835d
+			fatal("%.200s line %d: Bad yes/no argument.", filename, linenum);
f5835d
+		if (*intptr == -1)
f5835d
+			*intptr = value;
f5835d
+		break;
f5835d
+
f5835d
+	case lRestart:
f5835d
+		intptr = &options.restart;
f5835d
+		goto parse_flag;
f5835d
+
f5835d
+	case lTLS_CheckPeer:
f5835d
+		intptr = &options.tls_checkpeer;
f5835d
+		arg = ldap_strdelim(&s);
f5835d
+		if (!arg || *arg == '\0')
f5835d
+			fatal("%.200s line %d: Missing never/hard/demand/alow/try argument.", filename, linenum);
f5835d
+		value = 0;	/* To avoid compiler warning... */
f5835d
+		if (strcasecmp(arg, "never") == 0 || strcasecmp(arg, "no") == 0 || strcasecmp(arg, "false") == 0 || strcasecmp(arg, "off") == 0)
f5835d
+			value = LDAP_OPT_X_TLS_NEVER;
f5835d
+		else if (strcasecmp(arg, "hard") == 0 || strcasecmp(arg, "yes") == 0 || strcasecmp(arg, "true") == 0 || strcasecmp(arg, "on") == 0)
f5835d
+			value = LDAP_OPT_X_TLS_HARD;
f5835d
+		else if (strcasecmp(arg, "demand") == 0)
f5835d
+			value = LDAP_OPT_X_TLS_DEMAND;
f5835d
+		else if (strcasecmp(arg, "allow") == 0)
f5835d
+			value = LDAP_OPT_X_TLS_ALLOW;
f5835d
+		else if (strcasecmp(arg, "try") == 0)
f5835d
+			value = LDAP_OPT_X_TLS_TRY;
f5835d
+		else
f5835d
+			fatal("%.200s line %d: Bad never/hard/demand/alow/try argument.", filename, linenum);
f5835d
+		if (*intptr == -1)
f5835d
+			*intptr = value;
f5835d
+		break;
f5835d
+
f5835d
+	case lTLS_CaCertFile:
f5835d
+		charptr = &options.tls_cacertfile;
f5835d
+		goto parse_string;
f5835d
+
f5835d
+	case lTLS_CaCertDir:
f5835d
+		charptr = &options.tls_cacertdir;
f5835d
+		goto parse_string;
f5835d
+
f5835d
+	case lTLS_Ciphers:
f5835d
+		xstringptr = &options.tls_ciphers;
f5835d
+		goto parse_xstring;
f5835d
+
f5835d
+	case lTLS_Cert:
f5835d
+		charptr = &options.tls_cert;
f5835d
+		goto parse_string;
f5835d
+
f5835d
+	case lTLS_Key:
f5835d
+		charptr = &options.tls_key;
f5835d
+		goto parse_string;
f5835d
+
f5835d
+	case lTLS_RandFile:
f5835d
+		charptr = &options.tls_randfile;
f5835d
+		goto parse_string;
f5835d
+
f5835d
+	case lLogDir:
f5835d
+		charptr = &options.logdir;
f5835d
+		goto parse_string;
f5835d
+
f5835d
+	case lDebug:
f5835d
+		intptr = &options.debug;
f5835d
+		goto parse_int;
f5835d
+
f5835d
+	case lSSH_Filter:
f5835d
+		xstringptr = &options.ssh_filter;
f5835d
+		goto parse_xstring;
f5835d
+
f5835d
+	case lSearch_Format:
f5835d
+		charptr = &options.search_format;
f5835d
+		goto parse_string;
f5835d
+
f5835d
+	case lAccountClass:
f5835d
+		charptr = &options.account_class;
f5835d
+		goto parse_string;
f5835d
+
f5835d
+	case lDeprecated:
f5835d
+		debug("%s line %d: Deprecated option \"%s\"",
f5835d
+		    filename, linenum, keyword);
f5835d
+		return 0;
f5835d
+
f5835d
+	case lUnsupported:
f5835d
+		error("%s line %d: Unsupported option \"%s\"",
f5835d
+		    filename, linenum, keyword);
f5835d
+		return 0;
f5835d
+
f5835d
+	default:
f5835d
+		fatal("process_config_line: Unimplemented opcode %d", opcode);
f5835d
+	}
f5835d
+
f5835d
+	/* Check that there is no garbage at end of line. */
f5835d
+	if ((arg = ldap_strdelim(&s)) != NULL && *arg != '\0') {
f5835d
+		fatal("%.200s line %d: garbage at end of line; \"%.200s\".",
f5835d
+		    filename, linenum, arg);
f5835d
+	}
f5835d
+	return 0;
f5835d
+}
f5835d
+
f5835d
+/*
f5835d
+ * Reads the config file and modifies the options accordingly.  Options
f5835d
+ * should already be initialized before this call.  This never returns if
f5835d
+ * there is an error.  If the file does not exist, this returns 0.
f5835d
+ */
f5835d
+
f5835d
+void
f5835d
+read_config_file(const char *filename)
f5835d
+{
f5835d
+	FILE *f;
f5835d
+	char line[1024];
f5835d
+	int linenum;
f5835d
+	int bad_options = 0;
f5835d
+	struct stat sb;
f5835d
+
f5835d
+	if ((f = fopen(filename, "r")) == NULL)
f5835d
+		fatal("fopen %s: %s", filename, strerror(errno));
f5835d
+
f5835d
+	if (fstat(fileno(f), &sb) == -1)
f5835d
+		fatal("fstat %s: %s", filename, strerror(errno));
f5835d
+	if (((sb.st_uid != 0 && sb.st_uid != getuid()) ||
f5835d
+	    (sb.st_mode & 022) != 0))
f5835d
+		fatal("Bad owner or permissions on %s", filename);
f5835d
+
f5835d
+	debug("Reading configuration data %.200s", filename);
f5835d
+
f5835d
+	/*
f5835d
+	 * Mark that we are now processing the options.  This flag is turned
f5835d
+	 * on/off by Host specifications.
f5835d
+	 */
f5835d
+	linenum = 0;
f5835d
+	while (fgets(line, sizeof(line), f)) {
f5835d
+		/* Update line number counter. */
f5835d
+		linenum++;
f5835d
+		if (process_config_line(line, filename, linenum) != 0)
f5835d
+			bad_options++;
f5835d
+	}
f5835d
+	fclose(f);
f5835d
+	if ((bad_options > 0) && config_exclusive_config_file) 
f5835d
+		fatal("%s: terminating, %d bad configuration options",
f5835d
+		    filename, bad_options);
f5835d
+}
f5835d
+
f5835d
+/*
f5835d
+ * Initializes options to special values that indicate that they have not yet
f5835d
+ * been set.  Read_config_file will only set options with this value. Options
f5835d
+ * are processed in the following order: command line, user config file,
f5835d
+ * system config file.  Last, fill_default_options is called.
f5835d
+ */
f5835d
+
f5835d
+void
f5835d
+initialize_options(void)
f5835d
+{
f5835d
+	memset(&options, 'X', sizeof(options));
f5835d
+	options.host = NULL;
f5835d
+	options.uri = NULL;
f5835d
+	options.base = NULL;
f5835d
+	options.binddn = NULL;
f5835d
+	options.bindpw = NULL;
f5835d
+	options.scope = -1;
f5835d
+	options.deref = -1;
f5835d
+	options.port = -1;
f5835d
+	options.timelimit = -1;
f5835d
+	options.bind_timelimit = -1;
f5835d
+	options.ldap_version = -1;
f5835d
+	options.bind_policy = -1;
f5835d
+	options.sslpath = NULL;
f5835d
+	options.ssl = -1;
f5835d
+	options.referrals = -1;
f5835d
+	options.restart = -1;
f5835d
+	options.tls_checkpeer = -1;
f5835d
+	options.tls_cacertfile = NULL;
f5835d
+	options.tls_cacertdir = NULL;
f5835d
+	options.tls_ciphers = NULL;
f5835d
+	options.tls_cert = NULL;
f5835d
+	options.tls_key = NULL;
f5835d
+	options.tls_randfile = NULL;
f5835d
+	options.logdir = NULL;
f5835d
+	options.debug = -1;
f5835d
+	options.ssh_filter = NULL;
f5835d
+	options.search_format = NULL;
f5835d
+	options.account_class = NULL;
f5835d
+}
f5835d
+
f5835d
+/*
f5835d
+ * Called after processing other sources of option data, this fills those
f5835d
+ * options for which no value has been specified with their default values.
f5835d
+ */
f5835d
+
f5835d
+void
f5835d
+fill_default_options(void)
f5835d
+{
f5835d
+	if (options.uri != NULL) {
f5835d
+		LDAPURLDesc *ludp;
f5835d
+
f5835d
+		if (ldap_url_parse(options.uri, &ludp) == LDAP_SUCCESS) {
f5835d
+			if (options.ssl == -1) {
f5835d
+				if (strcmp (ludp->lud_scheme, "ldap") == 0)
f5835d
+				    options.ssl = 2;
f5835d
+				if (strcmp (ludp->lud_scheme, "ldapi") == 0)
f5835d
+				    options.ssl = 0;
f5835d
+				else if (strcmp (ludp->lud_scheme, "ldaps") == 0)
f5835d
+				    options.ssl = 1;
f5835d
+			}
f5835d
+			if (options.host == NULL)
f5835d
+			    options.host = xstrdup (ludp->lud_host);
f5835d
+			if (options.port == -1)
f5835d
+			    options.port = ludp->lud_port;
f5835d
+
f5835d
+			ldap_free_urldesc (ludp);
f5835d
+		}
f5835d
+	} 
f5835d
+	if (options.ssl == -1)
f5835d
+	    options.ssl = SSL_START_TLS;
f5835d
+	if (options.port == -1)
f5835d
+	    options.port = (options.ssl == 0) ? 389 : 636;
f5835d
+	if (options.uri == NULL) {
f5835d
+		int len;
f5835d
+#define MAXURILEN 4096
f5835d
+
f5835d
+		options.uri = xmalloc (MAXURILEN);
f5835d
+		len = snprintf (options.uri, MAXURILEN, "ldap%s://%s:%d",
f5835d
+		    (options.ssl == 0) ? "" : "s", options.host, options.port);
f5835d
+		options.uri[MAXURILEN - 1] = 0;
f5835d
+		options.uri = xreallocarray(options.uri, len + 1, 1);
f5835d
+	}
f5835d
+	if (options.binddn == NULL)
f5835d
+	    options.binddn = "";
f5835d
+	if (options.bindpw == NULL)
f5835d
+	    options.bindpw = "";
f5835d
+	if (options.scope == -1)
f5835d
+	    options.scope = LDAP_SCOPE_SUBTREE;
f5835d
+	if (options.deref == -1)
f5835d
+	    options.deref = LDAP_DEREF_NEVER;
f5835d
+	if (options.timelimit == -1)
f5835d
+	    options.timelimit = 10;
f5835d
+	if (options.bind_timelimit == -1)
f5835d
+	    options.bind_timelimit = 10;
f5835d
+	if (options.ldap_version == -1)
f5835d
+	    options.ldap_version = 3;
f5835d
+	if (options.bind_policy == -1)
f5835d
+	    options.bind_policy = 1;
f5835d
+	if (options.referrals == -1)
f5835d
+	    options.referrals = 1;
f5835d
+	if (options.restart == -1)
f5835d
+	    options.restart = 1;
f5835d
+	if (options.tls_checkpeer == -1)
f5835d
+	    options.tls_checkpeer = LDAP_OPT_X_TLS_HARD;
f5835d
+	if (options.debug == -1)
f5835d
+	    options.debug = 0;
f5835d
+	if (options.ssh_filter == NULL)
f5835d
+	    options.ssh_filter = "";
f5835d
+	if (options.account_class == NULL)
f5835d
+	    options.account_class = "posixAccount";
f5835d
+}
f5835d
+
f5835d
+static const char *
f5835d
+lookup_opcode_name(OpCodes code)
f5835d
+{
f5835d
+	u_int i;
f5835d
+
f5835d
+	for (i = 0; keywords[i].name != NULL; i++)
f5835d
+	    if (keywords[i].opcode == code)
f5835d
+		return(keywords[i].name);
f5835d
+	return "UNKNOWN";
f5835d
+}
f5835d
+
f5835d
+static void
f5835d
+dump_cfg_string(OpCodes code, const char *val)
f5835d
+{
f5835d
+	if (val == NULL)
f5835d
+	    debug3("%s <UNDEFINED>", lookup_opcode_name(code));
f5835d
+	else
f5835d
+	    debug3("%s %s", lookup_opcode_name(code), val);
f5835d
+}
f5835d
+
f5835d
+static void
f5835d
+dump_cfg_int(OpCodes code, int val)
f5835d
+{
f5835d
+	if (val == -1)
f5835d
+	    debug3("%s <UNDEFINED>", lookup_opcode_name(code));
f5835d
+	else
f5835d
+	    debug3("%s %d", lookup_opcode_name(code), val);
f5835d
+}
f5835d
+
f5835d
+struct names {
f5835d
+	int value;
f5835d
+	char *name;
f5835d
+};
f5835d
+
f5835d
+static void
f5835d
+dump_cfg_namedint(OpCodes code, int val, struct names *names)
f5835d
+{
f5835d
+	u_int i;
f5835d
+
f5835d
+	if (val == -1)
f5835d
+	    debug3("%s <UNDEFINED>", lookup_opcode_name(code));
f5835d
+	else {
f5835d
+		for (i = 0; names[i].value != -1; i++)
f5835d
+	 	    if (names[i].value == val) {
f5835d
+	    		debug3("%s %s", lookup_opcode_name(code), names[i].name);
f5835d
+			    return;
f5835d
+		}
f5835d
+		debug3("%s unknown: %d", lookup_opcode_name(code), val);
f5835d
+	}
f5835d
+}
f5835d
+
f5835d
+static struct names _yesnotls[] = {
f5835d
+	{ 0, "No" },
f5835d
+	{ 1, "Yes" },
f5835d
+	{ 2, "Start_TLS" },
f5835d
+	{ -1, NULL }};
f5835d
+
f5835d
+static struct names _scope[] = {
f5835d
+	{ LDAP_SCOPE_BASE, "Base" },
f5835d
+	{ LDAP_SCOPE_ONELEVEL, "One" },
f5835d
+	{ LDAP_SCOPE_SUBTREE, "Sub"},
f5835d
+	{ -1, NULL }};
f5835d
+
f5835d
+static struct names _deref[] = {
f5835d
+	{ LDAP_DEREF_NEVER, "Never" },
f5835d
+	{ LDAP_DEREF_SEARCHING, "Searching" },
f5835d
+	{ LDAP_DEREF_FINDING, "Finding" },
f5835d
+	{ LDAP_DEREF_ALWAYS, "Always" },
f5835d
+	{ -1, NULL }};
f5835d
+
f5835d
+static struct names _yesno[] = {
f5835d
+	{ 0, "No" },
f5835d
+	{ 1, "Yes" },
f5835d
+	{ -1, NULL }};
f5835d
+
f5835d
+static struct names _bindpolicy[] = {
f5835d
+	{ 0, "Soft" },
f5835d
+	{ 1, "Hard" },
f5835d
+	{ -1, NULL }};
f5835d
+
f5835d
+static struct names _checkpeer[] = {
f5835d
+	{ LDAP_OPT_X_TLS_NEVER, "Never" },
f5835d
+	{ LDAP_OPT_X_TLS_HARD, "Hard" },
f5835d
+	{ LDAP_OPT_X_TLS_DEMAND, "Demand" },
f5835d
+	{ LDAP_OPT_X_TLS_ALLOW, "Allow" },
f5835d
+	{ LDAP_OPT_X_TLS_TRY, "TRY" },
f5835d
+	{ -1, NULL }};
f5835d
+
f5835d
+void
f5835d
+dump_config(void)
f5835d
+{
f5835d
+	dump_cfg_string(lURI, options.uri);
f5835d
+	dump_cfg_string(lHost, options.host);
f5835d
+	dump_cfg_int(lPort, options.port);
f5835d
+	dump_cfg_namedint(lSSL, options.ssl, _yesnotls);
f5835d
+	dump_cfg_int(lLdap_Version, options.ldap_version);
f5835d
+	dump_cfg_int(lTimeLimit, options.timelimit);
f5835d
+	dump_cfg_int(lBind_TimeLimit, options.bind_timelimit);
f5835d
+	dump_cfg_string(lBase, options.base);
f5835d
+	dump_cfg_string(lBindDN, options.binddn);
f5835d
+	dump_cfg_string(lBindPW, options.bindpw);
f5835d
+	dump_cfg_namedint(lScope, options.scope, _scope);
f5835d
+	dump_cfg_namedint(lDeref, options.deref, _deref);
f5835d
+	dump_cfg_namedint(lReferrals, options.referrals, _yesno);
f5835d
+	dump_cfg_namedint(lRestart, options.restart, _yesno);
f5835d
+	dump_cfg_namedint(lBind_Policy, options.bind_policy, _bindpolicy);
f5835d
+	dump_cfg_string(lSSLPath, options.sslpath);
f5835d
+	dump_cfg_namedint(lTLS_CheckPeer, options.tls_checkpeer, _checkpeer);
f5835d
+	dump_cfg_string(lTLS_CaCertFile, options.tls_cacertfile);
f5835d
+	dump_cfg_string(lTLS_CaCertDir, options.tls_cacertdir);
f5835d
+	dump_cfg_string(lTLS_Ciphers, options.tls_ciphers);
f5835d
+	dump_cfg_string(lTLS_Cert, options.tls_cert);
f5835d
+	dump_cfg_string(lTLS_Key, options.tls_key);
f5835d
+	dump_cfg_string(lTLS_RandFile, options.tls_randfile);
f5835d
+	dump_cfg_string(lLogDir, options.logdir);
f5835d
+	dump_cfg_int(lDebug, options.debug);
f5835d
+	dump_cfg_string(lSSH_Filter, options.ssh_filter);
f5835d
+	dump_cfg_string(lSearch_Format, options.search_format);
f5835d
+	dump_cfg_string(lAccountClass, options.account_class);
f5835d
+}
f5835d
+
f5835d
diff -up openssh-6.8p1/ldapconf.h.ldap openssh-6.8p1/ldapconf.h
f5835d
--- openssh-6.8p1/ldapconf.h.ldap	2015-03-18 11:11:29.032801460 +0100
f5835d
+++ openssh-6.8p1/ldapconf.h	2015-03-18 11:11:29.032801460 +0100
f5835d
@@ -0,0 +1,73 @@
f5835d
+/* $OpenBSD: ldapconf.c,v 1.1 2009/12/03 03:34:42 jfch Exp $ */
f5835d
+/*
f5835d
+ * Copyright (c) 2009 Jan F. Chadima.  All rights reserved.
f5835d
+ *
f5835d
+ * Redistribution and use in source and binary forms, with or without
f5835d
+ * modification, are permitted provided that the following conditions
f5835d
+ * are met:
f5835d
+ * 1. Redistributions of source code must retain the above copyright
f5835d
+ *    notice, this list of conditions and the following disclaimer.
f5835d
+ * 2. Redistributions in binary form must reproduce the above copyright
f5835d
+ *    notice, this list of conditions and the following disclaimer in the
f5835d
+ *    documentation and/or other materials provided with the distribution.
f5835d
+ *
f5835d
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
f5835d
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
f5835d
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
f5835d
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
f5835d
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
f5835d
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
f5835d
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
f5835d
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
f5835d
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
f5835d
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
f5835d
+ */
f5835d
+
f5835d
+#ifndef LDAPCONF_H
f5835d
+#define LDAPCONF_H
f5835d
+
f5835d
+#define SSL_OFF          0
f5835d
+#define SSL_LDAPS        1
f5835d
+#define SSL_START_TLS    2
f5835d
+
f5835d
+/* Data structure for representing option data. */
f5835d
+
f5835d
+typedef struct {
f5835d
+	char *host;
f5835d
+	char *uri;
f5835d
+	char *base;
f5835d
+	char *binddn;
f5835d
+	char *bindpw;
f5835d
+	int scope;
f5835d
+	int deref;
f5835d
+	int port;
f5835d
+	int timelimit;
f5835d
+	int bind_timelimit;
f5835d
+	int ldap_version;
f5835d
+	int bind_policy;
f5835d
+	char *sslpath;
f5835d
+	int ssl;
f5835d
+	int referrals;
f5835d
+	int restart;
f5835d
+	int tls_checkpeer;
f5835d
+	char *tls_cacertfile;
f5835d
+	char *tls_cacertdir;
f5835d
+	char *tls_ciphers;
f5835d
+	char *tls_cert;
f5835d
+	char *tls_key;
f5835d
+	char *tls_randfile;
f5835d
+	char *logdir;
f5835d
+	int debug;
f5835d
+	char *ssh_filter;
f5835d
+	char *search_format;
f5835d
+	char *account_class;
f5835d
+}       Options;
f5835d
+
f5835d
+extern Options options;
f5835d
+
f5835d
+void read_config_file(const char *);
f5835d
+void initialize_options(void);
f5835d
+void fill_default_options(void);
f5835d
+void dump_config(void);
f5835d
+
f5835d
+#endif /* LDAPCONF_H */
f5835d
diff -up openssh-6.8p1/ldapincludes.h.ldap openssh-6.8p1/ldapincludes.h
f5835d
--- openssh-6.8p1/ldapincludes.h.ldap	2015-03-18 11:11:29.032801460 +0100
f5835d
+++ openssh-6.8p1/ldapincludes.h	2015-03-18 11:11:29.032801460 +0100
f5835d
@@ -0,0 +1,41 @@
f5835d
+/* $OpenBSD: ldapconf.c,v 1.1 2009/12/03 03:34:42 jfch Exp $ */
f5835d
+/*
f5835d
+ * Copyright (c) 2009 Jan F. Chadima.  All rights reserved.
f5835d
+ *
f5835d
+ * Redistribution and use in source and binary forms, with or without
f5835d
+ * modification, are permitted provided that the following conditions
f5835d
+ * are met:
f5835d
+ * 1. Redistributions of source code must retain the above copyright
f5835d
+ *    notice, this list of conditions and the following disclaimer.
f5835d
+ * 2. Redistributions in binary form must reproduce the above copyright
f5835d
+ *    notice, this list of conditions and the following disclaimer in the
f5835d
+ *    documentation and/or other materials provided with the distribution.
f5835d
+ *
f5835d
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
f5835d
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
f5835d
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
f5835d
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
f5835d
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
f5835d
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
f5835d
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
f5835d
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
f5835d
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
f5835d
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
f5835d
+ */
f5835d
+
f5835d
+#ifndef LDAPINCLUDES_H
f5835d
+#define LDAPINCLUDES_H
f5835d
+
f5835d
+#include "includes.h"
f5835d
+
f5835d
+#ifdef HAVE_LBER_H
f5835d
+#include <lber.h>
f5835d
+#endif
f5835d
+#ifdef HAVE_LDAP_H
f5835d
+#include <ldap.h>
f5835d
+#endif
f5835d
+#ifdef HAVE_LDAP_SSL_H
f5835d
+#include <ldap_ssl.h>
f5835d
+#endif
f5835d
+
f5835d
+#endif /* LDAPINCLUDES_H */
f5835d
diff -up openssh-6.8p1/ldapmisc.c.ldap openssh-6.8p1/ldapmisc.c
f5835d
--- openssh-6.8p1/ldapmisc.c.ldap	2015-03-18 11:11:29.032801460 +0100
f5835d
+++ openssh-6.8p1/ldapmisc.c	2015-03-18 11:11:29.032801460 +0100
f5835d
@@ -0,0 +1,79 @@
f5835d
+
f5835d
+#include "ldapincludes.h"
f5835d
+#include "ldapmisc.h"
f5835d
+
f5835d
+#ifndef HAVE_LDAP_GET_LDERRNO
f5835d
+int
f5835d
+ldap_get_lderrno (LDAP * ld, char **m, char **s)
f5835d
+{
f5835d
+#ifdef HAVE_LDAP_GET_OPTION
f5835d
+	int rc;
f5835d
+#endif
f5835d
+	int lderrno;
f5835d
+
f5835d
+#if defined(HAVE_LDAP_GET_OPTION) && defined(LDAP_OPT_ERROR_NUMBER)
f5835d
+	if ((rc = ldap_get_option (ld, LDAP_OPT_ERROR_NUMBER, &lderrno)) != LDAP_SUCCESS)
f5835d
+	    return rc;
f5835d
+#else
f5835d
+	lderrno = ld->ld_errno;
f5835d
+#endif
f5835d
+
f5835d
+	if (s != NULL) {
f5835d
+#if defined(HAVE_LDAP_GET_OPTION) && defined(LDAP_OPT_ERROR_STRING)
f5835d
+		if ((rc = ldap_get_option (ld, LDAP_OPT_ERROR_STRING, s)) != LDAP_SUCCESS)
f5835d
+		    return rc;
f5835d
+#else
f5835d
+		*s = ld->ld_error;
f5835d
+#endif
f5835d
+	}
f5835d
+
f5835d
+	if (m != NULL) {
f5835d
+#if defined(HAVE_LDAP_GET_OPTION) && defined(LDAP_OPT_MATCHED_DN)
f5835d
+		if ((rc = ldap_get_option (ld, LDAP_OPT_MATCHED_DN, m)) != LDAP_SUCCESS)
f5835d
+		    return rc;
f5835d
+#else
f5835d
+		*m = ld->ld_matched;
f5835d
+#endif
f5835d
+	}
f5835d
+
f5835d
+	return lderrno;
f5835d
+}
f5835d
+#endif
f5835d
+
f5835d
+#ifndef HAVE_LDAP_SET_LDERRNO
f5835d
+int
f5835d
+ldap_set_lderrno (LDAP * ld, int lderrno, const char *m, const char *s)
f5835d
+{
f5835d
+#ifdef HAVE_LDAP_SET_OPTION
f5835d
+	int rc;
f5835d
+#endif
f5835d
+
f5835d
+#if defined(HAVE_LDAP_SET_OPTION) && defined(LDAP_OPT_ERROR_NUMBER)
f5835d
+	if ((rc = ldap_set_option (ld, LDAP_OPT_ERROR_NUMBER, &lderrno)) != LDAP_SUCCESS)
f5835d
+	    return rc;
f5835d
+#else
f5835d
+	ld->ld_errno = lderrno;
f5835d
+#endif
f5835d
+
f5835d
+	if (s != NULL) {
f5835d
+#if defined(HAVE_LDAP_SET_OPTION) && defined(LDAP_OPT_ERROR_STRING)
f5835d
+		if ((rc = ldap_set_option (ld, LDAP_OPT_ERROR_STRING, s)) != LDAP_SUCCESS)
f5835d
+		    return rc;
f5835d
+#else
f5835d
+		ld->ld_error = s;
f5835d
+#endif
f5835d
+	}
f5835d
+
f5835d
+	if (m != NULL) {
f5835d
+#if defined(HAVE_LDAP_SET_OPTION) && defined(LDAP_OPT_MATCHED_DN)
f5835d
+		if ((rc = ldap_set_option (ld, LDAP_OPT_MATCHED_DN, m)) != LDAP_SUCCESS)
f5835d
+		    return rc;
f5835d
+#else
f5835d
+		ld->ld_matched = m;
f5835d
+#endif
f5835d
+	}
f5835d
+
f5835d
+	return LDAP_SUCCESS;
f5835d
+}
f5835d
+#endif
f5835d
+
f5835d
diff -up openssh-6.8p1/ldapmisc.h.ldap openssh-6.8p1/ldapmisc.h
f5835d
--- openssh-6.8p1/ldapmisc.h.ldap	2015-03-18 11:11:29.032801460 +0100
f5835d
+++ openssh-6.8p1/ldapmisc.h	2015-03-18 11:11:29.032801460 +0100
f5835d
@@ -0,0 +1,35 @@
f5835d
+/* $OpenBSD: ldapbody.h,v 1.1 2009/12/03 03:34:42 jfch Exp $ */
f5835d
+/*
f5835d
+ * Copyright (c) 2009 Jan F. Chadima.  All rights reserved.
f5835d
+ *
f5835d
+ * Redistribution and use in source and binary forms, with or without
f5835d
+ * modification, are permitted provided that the following conditions
f5835d
+ * are met:
f5835d
+ * 1. Redistributions of source code must retain the above copyright
f5835d
+ *    notice, this list of conditions and the following disclaimer.
f5835d
+ * 2. Redistributions in binary form must reproduce the above copyright
f5835d
+ *    notice, this list of conditions and the following disclaimer in the
f5835d
+ *    documentation and/or other materials provided with the distribution.
f5835d
+ *
f5835d
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
f5835d
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
f5835d
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
f5835d
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
f5835d
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
f5835d
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
f5835d
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
f5835d
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
f5835d
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
f5835d
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
f5835d
+ */
f5835d
+
f5835d
+#ifndef LDAPMISC_H
f5835d
+#define LDAPMISC_H
f5835d
+
f5835d
+#include "ldapincludes.h"
f5835d
+
f5835d
+int ldap_get_lderrno (LDAP *, char **, char **);
f5835d
+int ldap_set_lderrno (LDAP *, int, const char *, const char *);
f5835d
+
f5835d
+#endif /* LDAPMISC_H */
f5835d
+
f5835d
diff -up openssh-6.8p1/openssh-lpk-openldap.schema.ldap openssh-6.8p1/openssh-lpk-openldap.schema
f5835d
--- openssh-6.8p1/openssh-lpk-openldap.schema.ldap	2015-03-18 11:11:29.033801457 +0100
f5835d
+++ openssh-6.8p1/openssh-lpk-openldap.schema	2015-03-18 11:11:29.033801457 +0100
f5835d
@@ -0,0 +1,21 @@
f5835d
+#
f5835d
+# LDAP Public Key Patch schema for use with openssh-ldappubkey
f5835d
+#                              useful with PKA-LDAP also
f5835d
+#
f5835d
+# Author: Eric AUGE <eau@phear.org>
f5835d
+# 
f5835d
+# Based on the proposal of : Mark Ruijter
f5835d
+#
f5835d
+
f5835d
+
f5835d
+# octetString SYNTAX
f5835d
+attributetype ( 1.3.6.1.4.1.24552.500.1.1.1.13 NAME 'sshPublicKey' 
f5835d
+	DESC 'MANDATORY: OpenSSH Public key' 
f5835d
+	EQUALITY octetStringMatch
f5835d
+	SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )
f5835d
+
f5835d
+# printableString SYNTAX yes|no
f5835d
+objectclass ( 1.3.6.1.4.1.24552.500.1.1.2.0 NAME 'ldapPublicKey' SUP top AUXILIARY
f5835d
+	DESC 'MANDATORY: OpenSSH LPK objectclass'
f5835d
+	MUST ( sshPublicKey $ uid ) 
f5835d
+	)
f5835d
diff -up openssh-6.8p1/openssh-lpk-sun.schema.ldap openssh-6.8p1/openssh-lpk-sun.schema
f5835d
--- openssh-6.8p1/openssh-lpk-sun.schema.ldap	2015-03-18 11:11:29.033801457 +0100
f5835d
+++ openssh-6.8p1/openssh-lpk-sun.schema	2015-03-18 11:11:29.033801457 +0100
f5835d
@@ -0,0 +1,23 @@
f5835d
+#
f5835d
+# LDAP Public Key Patch schema for use with openssh-ldappubkey
f5835d
+#                              useful with PKA-LDAP also
f5835d
+#
f5835d
+# Author: Eric AUGE <eau@phear.org>
f5835d
+# 
f5835d
+# Schema for Sun Directory Server.
f5835d
+# Based on the original schema, modified by Stefan Fischer.
f5835d
+#
f5835d
+
f5835d
+dn: cn=schema
f5835d
+
f5835d
+# octetString SYNTAX
f5835d
+attributeTypes: ( 1.3.6.1.4.1.24552.500.1.1.1.13 NAME 'sshPublicKey' 
f5835d
+	DESC 'MANDATORY: OpenSSH Public key' 
f5835d
+	EQUALITY octetStringMatch
f5835d
+	SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )
f5835d
+
f5835d
+# printableString SYNTAX yes|no
f5835d
+objectClasses: ( 1.3.6.1.4.1.24552.500.1.1.2.0 NAME 'ldapPublicKey' SUP top AUXILIARY
f5835d
+	DESC 'MANDATORY: OpenSSH LPK objectclass'
f5835d
+	MUST ( sshPublicKey $ uid ) 
f5835d
+	)
f5835d
diff -up openssh-6.8p1/ssh-ldap-helper.8.ldap openssh-6.8p1/ssh-ldap-helper.8
f5835d
--- openssh-6.8p1/ssh-ldap-helper.8.ldap	2015-03-18 11:11:29.033801457 +0100
f5835d
+++ openssh-6.8p1/ssh-ldap-helper.8	2015-03-18 11:11:29.033801457 +0100
f5835d
@@ -0,0 +1,79 @@
f5835d
+.\" $OpenBSD: ssh-ldap-helper.8,v 1.1 2010/02/10 23:20:38 markus Exp $
f5835d
+.\"
f5835d
+.\" Copyright (c) 2010 Jan F. Chadima.  All rights reserved.
f5835d
+.\"
f5835d
+.\" Permission to use, copy, modify, and distribute this software for any
f5835d
+.\" purpose with or without fee is hereby granted, provided that the above
f5835d
+.\" copyright notice and this permission notice appear in all copies.
f5835d
+.\"
f5835d
+.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
f5835d
+.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
f5835d
+.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
f5835d
+.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
f5835d
+.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
f5835d
+.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
f5835d
+.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
f5835d
+.\"
f5835d
+.Dd $Mdocdate: April 29 2010 $
f5835d
+.Dt SSH-LDAP-HELPER 8
f5835d
+.Os
f5835d
+.Sh NAME
f5835d
+.Nm ssh-ldap-helper
f5835d
+.Nd sshd helper program for ldap support
f5835d
+.Sh SYNOPSIS
f5835d
+.Nm ssh-ldap-helper
f5835d
+.Op Fl devw
f5835d
+.Op Fl f Ar file
f5835d
+.Op Fl s Ar user
f5835d
+.Sh DESCRIPTION
f5835d
+.Nm
f5835d
+is used by
f5835d
+.Xr sshd 1
f5835d
+to access keys provided by an LDAP.
f5835d
+.Nm
f5835d
+is disabled by default and can only be enabled in the
f5835d
+sshd configuration file
f5835d
+.Pa /etc/ssh/sshd_config
f5835d
+by setting
f5835d
+.Cm AuthorizedKeysCommand
f5835d
+to
f5835d
+.Dq /usr/libexec/ssh-ldap-wrapper .
f5835d
+.Pp
f5835d
+.Nm
f5835d
+is not intended to be invoked by the user, but from
f5835d
+.Xr sshd 8 via
f5835d
+.Xr ssh-ldap-wrapper .
f5835d
+.Pp
f5835d
+The options are as follows:
f5835d
+.Bl -tag -width Ds
f5835d
+.It Fl d
f5835d
+Set the debug mode; 
f5835d
+.Nm
f5835d
+prints all logs to stderr instead of syslog.
f5835d
+.It Fl e
f5835d
+Implies \-w;
f5835d
+.Nm
f5835d
+halts if it encounters an unknown item in the ldap.conf file.
f5835d
+.It Fl f
f5835d
+.Nm
f5835d
+uses this file as the ldap configuration file instead of /etc/ssh/ldap.conf (default).
f5835d
+.It Fl s
f5835d
+.Nm
f5835d
+prints out the user's keys to stdout and exits.
f5835d
+.It Fl v
f5835d
+Implies \-d;
f5835d
+increases verbosity.
f5835d
+.It Fl w
f5835d
+.Nm
f5835d
+writes warnings about unknown items in the ldap.conf configuration file.
f5835d
+.El
f5835d
+.Sh SEE ALSO
f5835d
+.Xr sshd 8 ,
f5835d
+.Xr sshd_config 5 ,
f5835d
+.Xr ssh-ldap.conf 5 ,
f5835d
+.Sh HISTORY
f5835d
+.Nm
f5835d
+first appeared in
f5835d
+OpenSSH 5.5 + PKA-LDAP .
f5835d
+.Sh AUTHORS
f5835d
+.An Jan F. Chadima Aq jchadima@redhat.com
f5835d
diff -up openssh-6.8p1/ssh-ldap-wrapper.ldap openssh-6.8p1/ssh-ldap-wrapper
f5835d
--- openssh-6.8p1/ssh-ldap-wrapper.ldap	2015-03-18 11:11:29.033801457 +0100
f5835d
+++ openssh-6.8p1/ssh-ldap-wrapper	2015-03-18 11:11:29.033801457 +0100
f5835d
@@ -0,0 +1,4 @@
f5835d
+#!/bin/sh
f5835d
+
f5835d
+exec /usr/libexec/openssh/ssh-ldap-helper -s "$1"
f5835d
+
f5835d
diff -up openssh-6.8p1/ssh-ldap.conf.5.ldap openssh-6.8p1/ssh-ldap.conf.5
f5835d
--- openssh-6.8p1/ssh-ldap.conf.5.ldap	2015-03-18 11:11:29.033801457 +0100
f5835d
+++ openssh-6.8p1/ssh-ldap.conf.5	2015-03-18 11:11:29.033801457 +0100
f5835d
@@ -0,0 +1,385 @@
f5835d
+.\" $OpenBSD: ssh-ldap.conf.5,v 1.1 2010/02/10 23:20:38 markus Exp $
f5835d
+.\"
f5835d
+.\" Copyright (c) 2010 Jan F. Chadima.  All rights reserved.
f5835d
+.\"
f5835d
+.\" Permission to use, copy, modify, and distribute this software for any
f5835d
+.\" purpose with or without fee is hereby granted, provided that the above
f5835d
+.\" copyright notice and this permission notice appear in all copies.
f5835d
+.\"
f5835d
+.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
f5835d
+.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
f5835d
+.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
f5835d
+.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
f5835d
+.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
f5835d
+.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
f5835d
+.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
f5835d
+.\"
f5835d
+.Dd $Mdocdate: may 12 2010 $
f5835d
+.Dt SSH-LDAP.CONF 5
f5835d
+.Os
f5835d
+.Sh NAME
f5835d
+.Nm ssh-ldap.conf
f5835d
+.Nd configuration file for ssh-ldap-helper
f5835d
+.Sh SYNOPSIS
f5835d
+.Nm /etc/ssh/ldap.conf
f5835d
+.Sh DESCRIPTION
f5835d
+.Xr ssh-ldap-helper 8
f5835d
+reads configuration data from
f5835d
+.Pa /etc/ssh/ldap.conf
f5835d
+(or the file specified with
f5835d
+.Fl f
f5835d
+on the command line).
f5835d
+The file contains keyword-argument pairs, one per line.
f5835d
+Lines starting with
f5835d
+.Ql #
f5835d
+and empty lines are interpreted as comments.
f5835d
+.Pp
f5835d
+The value starts with the first non-blank character after 
f5835d
+the keyword's name, and terminates at the end of the line, 
f5835d
+or at the last sequence of blanks before the end of the line.
f5835d
+Quoting values that contain blanks 
f5835d
+may be incorrect, as the quotes would become part of the value.
f5835d
+The possible keywords and their meanings are as follows (note that
f5835d
+keywords are case-insensitive, and arguments, on a case by case basis, may be case-sensitive).
f5835d
+.Bl -tag -width Ds
f5835d
+.It Cm URI
f5835d
+The argument(s) are in the form
f5835d
+.Pa ldap[si]://[name[:port]]
f5835d
+and specify the URI(s) of an LDAP server(s) to which the
f5835d
+.Xr ssh-ldap-helper 8 
f5835d
+should connect. The URI scheme may be any of
f5835d
+.Dq ldap ,
f5835d
+.Dq ldaps 
f5835d
+or
f5835d
+.Dq ldapi ,
f5835d
+which refer to LDAP over TCP, LDAP over SSL (TLS) and LDAP
f5835d
+over IPC (UNIX domain sockets), respectively.
f5835d
+Each server's name can be specified as a
f5835d
+domain-style name or an IP address literal.  Optionally, the
f5835d
+server's name can followed by a ':' and the port number the LDAP
f5835d
+server is listening on.  If no port number is provided, the default
f5835d
+port for the scheme is used (389 for ldap://, 636 for ldaps://).
f5835d
+For LDAP over IPC, name is the name of the socket, and no port
f5835d
+is required, nor allowed; note that directory separators must be 
f5835d
+URL-encoded, like any other characters that are special to URLs; 
f5835d
+A space separated list of URIs may be provided.
f5835d
+There is no default.
f5835d
+.It Cm Base
f5835d
+Specifies the default base Distinguished Name (DN) to use when performing ldap operations.
f5835d
+The base must be specified as a DN in LDAP format.
f5835d
+There is no default.
f5835d
+.It Cm BindDN
f5835d
+Specifies the default BIND DN to use when connecting to the ldap server.
f5835d
+The bind DN must be specified as a Distinguished Name in LDAP format.
f5835d
+There is no default.
f5835d
+.It Cm BindPW
f5835d
+Specifies the default password to use when connecting to the ldap server via
f5835d
+.Cm BindDN .
f5835d
+There is no default.
f5835d
+.It Cm RootBindDN
f5835d
+Intentionaly does nothing. Recognized for compatibility reasons.
f5835d
+.It Cm Host
f5835d
+The argument(s) specifies the name(s) of an LDAP server(s) to which the
f5835d
+.Xr ssh-ldap-helper 8
f5835d
+should connect.  Each server's name can be specified as a
f5835d
+domain-style name or an IP address and optionally followed by a ':' and
f5835d
+the port number the ldap server is listening on.  A space-separated
f5835d
+list of hosts may be provided.
f5835d
+There is no default.
f5835d
+.Cm Host
f5835d
+is deprecated in favor of
f5835d
+.Cm URI .
f5835d
+.It Cm Port
f5835d
+Specifies the default port used when connecting to LDAP servers(s).
f5835d
+The port may be specified as a number.
f5835d
+The default port is 389 for ldap:// or 636 for ldaps:// respectively.
f5835d
+.Cm Port
f5835d
+is deprecated in favor of
f5835d
+.Cm URI .
f5835d
+.It Cm Scope
f5835d
+Specifies the starting point of an LDAP search and the depth from the base DN to which the search should descend.
f5835d
+There are three options (values) that can be assigned to the
f5835d
+.Cm Scope parameter:
f5835d
+.Dq base ,
f5835d
+.Dq one
f5835d
+and
f5835d
+.Dq subtree .
f5835d
+Alias for the subtree is
f5835d
+.Dq sub .
f5835d
+The value
f5835d
+.Dq base
f5835d
+is used to indicate searching only the entry at the base DN, resulting in only that entry being returned (keeping in mind that it also has to meet the search filter criteria!).
f5835d
+The value
f5835d
+.Dq one
f5835d
+is used to indicate searching all entries one level under the base DN, but not including the base DN and not including any entries under that one level under the base DN.
f5835d
+The value
f5835d
+.Dq subtree
f5835d
+is used to indicate searching of all entries at all levels under and including the specified base DN.
f5835d
+The default is
f5835d
+.Dq subtree .
f5835d
+.It Cm Deref
f5835d
+Specifies how alias dereferencing is done when performing a search. There are four
f5835d
+possible values that can be assigned to the
f5835d
+.Cm Deref
f5835d
+parameter:
f5835d
+.Dq never ,
f5835d
+.Dq searching ,
f5835d
+.Dq finding ,
f5835d
+and
f5835d
+.Dq always .
f5835d
+The value
f5835d
+.Dq never
f5835d
+means that the aliases are never dereferenced.
f5835d
+The value
f5835d
+.Dq searching
f5835d
+means that the aliases are dereferenced in subordinates of the base object, but
f5835d
+not in locating the base object of the search.
f5835d
+The value
f5835d
+.Dq finding
f5835d
+means that the aliases are only dereferenced when locating the base object of the search.
f5835d
+The value
f5835d
+.Dq always
f5835d
+means that the aliases are dereferenced both in searching and in locating the base object
f5835d
+of the search.
f5835d
+The default is
f5835d
+.Dq never .
f5835d
+.It Cm TimeLimit
f5835d
+Specifies a time limit (in seconds) to use when performing searches.
f5835d
+The number should be a non-negative integer. A
f5835d
+.Cm TimeLimit
f5835d
+of zero (0) specifies that the search time is unlimited. Please note that the server
f5835d
+may still apply any server-side limit on the duration of a search operation.
f5835d
+The default value is 10.
f5835d
+.It Cm TimeOut
f5835d
+Is an aliast to
f5835d
+.Cm TimeLimit .
f5835d
+.It Cm Bind_TimeLimit
f5835d
+Specifies the timeout (in seconds) after which the poll(2)/select(2)
f5835d
+following a connect(2) returns in case of no activity.
f5835d
+The default value is 10.
f5835d
+.It Cm Network_TimeOut
f5835d
+Is an alias to
f5835d
+.Cm Bind_TimeLimit .
f5835d
+.It Cm Ldap_Version
f5835d
+Specifies what version of the LDAP protocol should be used.
f5835d
+The allowed values are 2 or 3. The default is 3.
f5835d
+.It Cm Version
f5835d
+Is an alias to
f5835d
+.Cm Ldap_Version .
f5835d
+.It Cm Bind_Policy
f5835d
+Specifies the policy to use for reconnecting to an unavailable LDAP server. There are 2 available values:
f5835d
+.Dq hard
f5835d
+and
f5835d
+.Dq soft.
f5835d
+.Dq hard has 2 aliases
f5835d
+.Dq hard_open
f5835d
+and
f5835d
+.Dq hard_init .
f5835d
+The value
f5835d
+.Dq hard
f5835d
+means that reconects that the
f5835d
+.Xr ssh-ldap-helper 8
f5835d
+tries to reconnect to the LDAP server 5 times before failure. There is exponential backoff before retrying.
f5835d
+The value
f5835d
+.Dq soft
f5835d
+means that
f5835d
+.Xr ssh-ldap-helper 8
f5835d
+fails immediately when it cannot connect to the LDAP seerver.
f5835d
+The deault is
f5835d
+.Dq hard .
f5835d
+.It Cm SSLPath
f5835d
+Specifies the path to the X.509 certificate database.
f5835d
+There is no default.
f5835d
+.It Cm SSL
f5835d
+Specifies whether to use SSL/TLS or not.
f5835d
+There are three allowed values:
f5835d
+.Dq yes ,
f5835d
+.Dq no
f5835d
+and
f5835d
+.Dq start_tls
f5835d
+Both
f5835d
+.Dq true
f5835d
+and
f5835d
+.Dq on
f5835d
+are the aliases for
f5835d
+.Dq yes .
f5835d
+.Dq false
f5835d
+and
f5835d
+.Dq off
f5835d
+are the aliases for
f5835d
+.Dq no .
f5835d
+If
f5835d
+.Dq start_tls
f5835d
+is specified then StartTLS is used rather than raw LDAP over SSL.
f5835d
+The default for ldap:// is
f5835d
+.Dq start_tls ,
f5835d
+for ldaps://
f5835d
+.Dq yes
f5835d
+and
f5835d
+.Dq no
f5835d
+for the ldapi:// .
f5835d
+In case of host based configuration the default is
f5835d
+.Dq start_tls .
f5835d
+.It Cm Referrals
f5835d
+Specifies if the client should automatically follow referrals returned
f5835d
+by LDAP servers.
f5835d
+The value can be or
f5835d
+.Dq yes
f5835d
+or
f5835d
+.Dq no .
f5835d
+.Dq true
f5835d
+and
f5835d
+.Dq on
f5835d
+are the aliases for
f5835d
+.Dq yes .
f5835d
+.Dq false
f5835d
+and
f5835d
+.Dq off
f5835d
+are the aliases for
f5835d
+.Dq no .
f5835d
+The default is yes.
f5835d
+.It Cm Restart
f5835d
+Specifies whether the LDAP client library should restart the select(2) system call when interrupted.
f5835d
+The value can be or
f5835d
+.Dq yes
f5835d
+or
f5835d
+.Dq no .
f5835d
+.Dq true
f5835d
+and
f5835d
+.Dq on
f5835d
+are the aliases for
f5835d
+.Dq yes .
f5835d
+.Dq false
f5835d
+and
f5835d
+.Dq off
f5835d
+are the aliases for
f5835d
+.Dq no .
f5835d
+The default is yes.
f5835d
+.It Cm TLS_CheckPeer
f5835d
+Specifies what checks to perform on server certificates in a TLS session,
f5835d
+if any. The value
f5835d
+can be specified as one of the following keywords:
f5835d
+.Dq never ,
f5835d
+.Dq hard ,
f5835d
+.Dq demand ,
f5835d
+.Dq allow
f5835d
+and
f5835d
+.Dq try .
f5835d
+.Dq true ,
f5835d
+.Dq on
f5835d
+and
f5835d
+.Dq yes
f5835d
+are aliases for
f5835d
+.Dq hard .
f5835d
+.Dq false ,
f5835d
+.Dq off
f5835d
+and
f5835d
+.Dq no
f5835d
+are the aliases for
f5835d
+.Dq never .
f5835d
+The value
f5835d
+.Dq never
f5835d
+means that the client will not request or check any server certificate.
f5835d
+The value
f5835d
+.Dq allow
f5835d
+means that the server certificate is requested. If no certificate is provided,
f5835d
+the session proceeds normally. If a bad certificate is provided, it will
f5835d
+be ignored and the session proceeds normally.
f5835d
+The value
f5835d
+.Dq try
f5835d
+means that the server certificate is requested. If no certificate is provided,
f5835d
+the session proceeds normally. If a bad certificate is provided,
f5835d
+the session is immediately terminated.
f5835d
+The value
f5835d
+.Dq demand
f5835d
+means that the server certificate is requested. If no
f5835d
+certificate is provided, or a bad certificate is provided, the session
f5835d
+is immediately terminated.
f5835d
+The value
f5835d
+.Dq hard
f5835d
+is the same as
f5835d
+.Dq demand .
f5835d
+It requires an SSL connection. In the case of the plain conection the
f5835d
+session is immediately terminated.
f5835d
+The default is
f5835d
+.Dq hard .
f5835d
+.It Cm TLS_ReqCert
f5835d
+Is an alias for 
f5835d
+.Cm TLS_CheckPeer .
f5835d
+.It Cm TLS_CACertFile
f5835d
+Specifies the file that contains certificates for all of the Certificate
f5835d
+Authorities the client will recognize.
f5835d
+There is no default.
f5835d
+.It Cm TLS_CACert
f5835d
+Is an alias for
f5835d
+.Cm TLS_CACertFile .
f5835d
+.It Cm TLS_CACertDIR
f5835d
+Specifies the path of a directory that contains Certificate Authority
f5835d
+certificates in separate individual files. The
f5835d
+.Cm TLS_CACert
f5835d
+is always used before
f5835d
+.Cm TLS_CACertDir .
f5835d
+The specified directory must be managed with the OpenSSL c_rehash utility.
f5835d
+There is no default.
f5835d
+.It Cm TLS_Ciphers
f5835d
+Specifies acceptable cipher suite and preference order.
f5835d
+The value should be a cipher specification for OpenSSL,
f5835d
+e.g.,
f5835d
+.Dq HIGH:MEDIUM:+SSLv2 .
f5835d
+The default is
f5835d
+.Dq ALL .
f5835d
+.It Cm TLS_Cipher_Suite
f5835d
+Is an alias for
f5835d
+.Cm TLS_Ciphers .
f5835d
+.It Cm TLS_Cert
f5835d
+Specifies the file that contains the client certificate.
f5835d
+There is no default.
f5835d
+.It Cm TLS_Certificate
f5835d
+Is an alias for
f5835d
+.Cm TLS_Cert .
f5835d
+.It Cm TLS_Key
f5835d
+Specifies the file that contains the private key that matches the certificate
f5835d
+stored in the
f5835d
+.Cm TLS_Cert
f5835d
+file. Currently, the private key must not be protected with a password, so
f5835d
+it is of critical importance that the key file is protected carefully.
f5835d
+There is no default.
f5835d
+.It Cm TLS_RandFile
f5835d
+Specifies the file to obtain random bits from when /dev/[u]random is
f5835d
+not available. Generally set to the name of the EGD/PRNGD socket.
f5835d
+The environment variable RANDFILE can also be used to specify the filename.
f5835d
+There is no default.
f5835d
+.It Cm LogDir
f5835d
+Specifies the directory used for logging by the LDAP client library.
f5835d
+There is no default.
f5835d
+.It Cm Debug
f5835d
+Specifies the debug level used for logging by the LDAP client library.
f5835d
+There is no default.
f5835d
+.It Cm SSH_Filter
f5835d
+Specifies the user filter applied on the LDAP search.
f5835d
+The default is no filter.
f5835d
+.It Cm AccountClass
f5835d
+Specifies the LDAP class used to find user accounts.
f5835d
+The default is posixAccount.
f5835d
+.It Cm search_format
f5835d
+Specifies the user format of search string in LDAP substituting %u for user name
f5835d
+and %f for additional ssh filter
f5835d
+.Cm SSH_Filter
f5835d
+(optional).
f5835d
+The default value is (&(objectclass=%c)(objectclass=ldapPublicKey)(uid=%u)%f)
f5835d
+.El
f5835d
+.Sh FILES
f5835d
+.Bl -tag -width Ds
f5835d
+.It Pa  /etc/ssh/ldap.conf
f5835d
+Ldap configuration file for
f5835d
+.Xr ssh-ldap-helper 8 .
f5835d
+.El
f5835d
+.Sh "SEE ALSO"
f5835d
+.Xr ldap.conf 5 ,
f5835d
+.Xr ssh-ldap-helper 8
f5835d
+.Sh HISTORY
f5835d
+.Nm
f5835d
+first appeared in
f5835d
+OpenSSH 5.5 + PKA-LDAP .
f5835d
+.Sh AUTHORS
f5835d
+.An Jan F. Chadima Aq jchadima@redhat.com
f5835d
diff --git a/openssh-lpk-openldap.ldif b/openssh-lpk-openldap.ldif
f5835d
new file mode 100644
f5835d
index 0000000..9adf4b8
f5835d
--- /dev/null
f5835d
+++ b/openssh-lpk-openldap.ldif
f5835d
@@ -0,0 +1,19 @@
f5835d
+#
f5835d
+# LDAP Public Key Patch schema for use with openssh-ldappubkey
f5835d
+#                              useful with PKA-LDAP also
f5835d
+#
f5835d
+# Author: Eric AUGE <eau@phear.org>
f5835d
+#
f5835d
+# LDIF for openLDAP Directory Server.
f5835d
+# Based on the original schema, modified by Jakub Jelen.
f5835d
+#
f5835d
+
f5835d
+dn: cn=openssh-lpk,cn=schema,cn=config
f5835d
+objectClass: olcSchemaConfig
f5835d
+cn: openssh-lpk
f5835d
+olcAttributeTypes: {0}( 1.3.6.1.4.1.24552.500.1.1.1.13
f5835d
+  NAME 'sshPublicKey' DESC 'MANDATORY: OpenSSH Public key'
f5835d
+  EQUALITY octetStringMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )
f5835d
+olcObjectClasses: {0}( 1.3.6.1.4.1.24552.500.1.1.2.0
f5835d
+  NAME 'ldapPublicKey' DESC 'MANDATORY: OpenSSH LPK objectclass'
f5835d
+  SUP top AUXILIARY MUST ( sshPublicKey $ uid ) )
f5835d
diff --git a/openssh-lpk-sun.ldif b/openssh-lpk-sun.ldif
f5835d
new file mode 100644
f5835d
index 0000000..9adf4b8
f5835d
--- /dev/null
f5835d
+++ b/openssh-lpk-sun.ldif
f5835d
@@ -0,0 +1,17 @@
f5835d
+#
f5835d
+# LDAP Public Key Patch schema for use with openssh-ldappubkey
f5835d
+#                              useful with PKA-LDAP also
f5835d
+#
f5835d
+# Author: Eric AUGE <eau@phear.org>
f5835d
+#
f5835d
+# LDIF for Sun Directory Server.
f5835d
+# Based on the original schema, modified by Jakub Jelen.
f5835d
+#
f5835d
+
f5835d
+dn: cn=schema
f5835d
+attributeTypes: ( 1.3.6.1.4.1.24552.500.1.1.1.13
f5835d
+  NAME 'sshPublicKey' DESC 'MANDATORY: OpenSSH Public key'
f5835d
+  EQUALITY octetStringMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.40 )
f5835d
+objectClasses: ( 1.3.6.1.4.1.24552.500.1.1.2.0
f5835d
+  NAME 'ldapPublicKey' DESC 'MANDATORY: OpenSSH LPK objectclass'
f5835d
+  SUP top AUXILIARY MUST ( sshPublicKey $ uid ) )