bmh10 / rpms / openssh

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