--- ldapvi-1.7.orig/arguments.c
+++ ldapvi-1.7/arguments.c
@@ -115,7 +115,7 @@
 	OPTION_NOQUESTIONS, OPTION_LDAPSEARCH, OPTION_LDAPMODIFY,
 	OPTION_LDAPDELETE, OPTION_LDAPMODDN, OPTION_LDAPMODRDN, OPTION_ADD,
 	OPTION_CONFIG, OPTION_READ, OPTION_LDAP_CONF, OPTION_BIND,
-	OPTION_BIND_DIALOG
+	OPTION_BIND_DIALOG, OPTION_UNPAGED_HELP
 };
 
 static struct poptOption options[] = {
@@ -170,14 +170,17 @@
 	{"ldapdelete",	  0, 0, 0, OPTION_LDAPDELETE, 0, 0},
 	{"ldapmoddn",	  0, 0, 0, OPTION_LDAPMODDN, 0, 0},
 	{"ldapmodrdn",	  0, 0, 0, OPTION_LDAPMODRDN, 0, 0},
+	{"unpaged-help",  0, 0, 0, OPTION_UNPAGED_HELP, 0, 0},
 	{0, 0, 0, 0, 0}
 };
 
 
+static int usage_pagerp = 1;
+
 void
 usage(int fd, int rc)
 {
-	if (fd == -1 && rc == 0 && isatty(1)) {
+	if (usage_pagerp && fd == -1 && rc == 0 && isatty(1)) {
 		int fd;
 		int pid = pipeview(&fd);
 		write(fd, USAGE, strlen(USAGE));
@@ -479,6 +482,9 @@
 	case OPTION_LDAP_CONF:
 		result->profileonlyp = 0;
 		break;
+	case OPTION_UNPAGED_HELP:
+		usage_pagerp = 0;
+		break;
 	case 'p':
 		parse_configuration(arg, result, ctrls);
 		break;
--- ldapvi-1.7.orig/manual/manual.xml
+++ ldapvi-1.7/manual/manual.xml
@@ -718,6 +718,10 @@
 		 suppress-configuration="suppress-configuration">
 	Print help on command line arguments.
       </parameter>
+      <parameter long="unpaged-help" brief="Disable pager for --help">
+	Disable the use of a pager
+	for <a href="#parameter-rename"><tt>--help</tt></a>.
+      </parameter>
       <parameter long="deleteoldrdn" brief="Delete the old RDN">
 	When changing the relative distinguished name to a new attribute
 	value, delete the old attribute value instead of keeping it.
--- ldapvi-1.7.orig/configure.in
+++ ldapvi-1.7/configure.in
@@ -73,11 +73,14 @@
 		AC_DEFINE(HAVE_GNUTLS)
 		AC_DEFINE(SHA_DIGEST_LENGTH,20)
 		;;
+	none)
+		;;
 	*)
 		AC_MSG_ERROR([invalid value --with-libcrypto=$with_libcrypto, expected openssl or gnutls])
 		;;
 esac
 AC_CHECK_FUNCS([SHA1])
+AC_CHECK_FUNCS([MD5])
 AC_CHECK_FUNCS([RAND_pseudo_bytes])
 
 AC_CHECK_LIB([crypt],[main])
--- ldapvi-1.7.orig/config.h.in
+++ ldapvi-1.7/config.h.in
@@ -5,5 +5,6 @@
 #undef HAVE_OPENSSL
 #undef HAVE_GNUTLS
 #undef HAVE_SHA1
+#undef HAVE_MD5
 #undef RAND_PSEUDO_BYTES
 #undef HAVE_SASL
--- ldapvi-1.7.orig/misc.c
+++ ldapvi-1.7/misc.c
@@ -163,7 +163,9 @@
 
 	vi = getenv("VISUAL");
 	if (!vi) vi = getenv("EDITOR");
-	if (!vi) vi = "vi";
+	/* changed from "vi" as fallback to "sensible-editor" which is what
+	 * Debian really uses (closes: #367995) */
+	if (!vi) vi = "sensible-editor";
 
 	switch ( (childpid = fork())) {
 	case -1:
@@ -204,7 +206,9 @@
 	char *clear = tigetstr("clear");
 
 	pg = getenv("PAGER");
-	if (!pg) pg = "less";
+	/* changed from "less" as fallback to "sensible-editor" which is what
+	 * Debian really uses */
+	if (!pg) pg = "sensible-pager";
 
 	if (!invalidp(clear))
 		putp(clear);
--- ldapvi-1.7.orig/configure
+++ ldapvi-1.7/configure
@@ -4836,6 +4836,8 @@
 _ACEOF
 
 		;;
+	none)
+		;;
 	*)
 		{ { echo "$as_me:$LINENO: error: invalid value --with-libcrypto=$with_libcrypto, expected openssl or gnutls" >&5
 echo "$as_me: error: invalid value --with-libcrypto=$with_libcrypto, expected openssl or gnutls" >&2;}
@@ -4937,6 +4939,100 @@
 done
 
 
+for ac_func in MD5
+do
+as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
+{ echo "$as_me:$LINENO: checking for $ac_func" >&5
+echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6; }
+if { as_var=$as_ac_var; eval "test \"\${$as_var+set}\" = set"; }; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+/* Define $ac_func to an innocuous variant, in case <limits.h> declares $ac_func.
+   For example, HP-UX 11i <limits.h> declares gettimeofday.  */
+#define $ac_func innocuous_$ac_func
+
+/* System header to define __stub macros and hopefully few prototypes,
+    which can conflict with char $ac_func (); below.
+    Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+    <limits.h> exists even on freestanding compilers.  */
+
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+
+#undef $ac_func
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char $ac_func ();
+/* The GNU C library defines this for functions which it implements
+    to always fail with ENOSYS.  Some functions are actually named
+    something starting with __ and the normal name is an alias.  */
+#if defined __stub_$ac_func || defined __stub___$ac_func
+choke me
+#endif
+
+int
+main ()
+{
+return $ac_func ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext &&
+       $as_test_x conftest$ac_exeext; then
+  eval "$as_ac_var=yes"
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	eval "$as_ac_var=no"
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
+fi
+ac_res=`eval echo '${'$as_ac_var'}'`
+	       { echo "$as_me:$LINENO: result: $ac_res" >&5
+echo "${ECHO_T}$ac_res" >&6; }
+if test `eval echo '${'$as_ac_var'}'` = yes; then
+  cat >>confdefs.h <<_ACEOF
+#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1
+_ACEOF
+
+fi
+done
+
+
 for ac_func in RAND_pseudo_bytes
 do
 as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
--- ldapvi-1.7.orig/NEWS
+++ ldapvi-1.7/NEWS
@@ -1,3 +1,6 @@
+1.8 2007-mm-dd
+  - new configuration option `unpaged-help'
+
 1.7 2007-05-05
   - Fixed buffer overrun in home_filename(), thanks to Thomas Friebel.
 
--- ldapvi-1.7.orig/port.c
+++ ldapvi-1.7/port.c
@@ -39,7 +39,7 @@
 #include <gnutls/gnutls.h>
 #include <gnutls/openssl.h>
 #else
-#error oops
+#warning Compiling without cryptographic routines.
 #endif
 
 #ifndef HAVE_RAND_PSEUDO_BYTES
@@ -148,15 +148,21 @@
 int
 g_string_append_md5(GString *string, char *key)
 {
+#ifdef HAVE_MD5
 	unsigned char tmp[MD5_DIGEST_LENGTH];
 	MD5((unsigned char *) key, strlen(key), tmp);
 	g_string_append_base64(string, tmp, sizeof(tmp));
 	return 1;
+#else
+	puts("Sorry, MD5 support not linked into ldapvi.");
+	return 0;
+#endif
 }
 
 int
 g_string_append_smd5(GString *string, char *key)
 {
+#ifdef HAVE_MD5
 	unsigned char rand[4];
 	unsigned char tmp[MD5_DIGEST_LENGTH + sizeof(rand)];
 	MD5_CTX MD5context;
@@ -172,4 +178,8 @@
 	g_string_append_base64(string, tmp, sizeof(tmp));
 
 	return 1;
+#else
+	puts("Sorry, SMD5 support not linked into ldapvi.");
+	return 0;
+#endif
 }
--- ldapvi-1.7.orig/debian/changelog
+++ ldapvi-1.7/debian/changelog
@@ -0,0 +1,82 @@
+ldapvi (1.7-2~bpo.1) etch-backports; urgency=low
+
+  * Backport to etch.
+
+ -- Gerfried Fuchs <rhonda@debian.at>  Wed, 22 Aug 2007 11:29:50 +0200
+
+ldapvi (1.7-2) unstable; urgency=low
+
+  * s/less/sensible-pager/: use Debian's pager magic instead of hardcoded
+    less.
+  * Pulled patch for unpaged-help config option from upstream and ship
+    systemwide configuration file that sets it (closes: #424978)
+
+ -- Gerfried Fuchs <rhonda@debian.at>  Sat, 28 Jul 2007 21:08:26 +0200
+
+ldapvi (1.7-1) unstable; urgency=low
+
+  * New upstream release which includes the buffer overflow fix.
+  * Updated copyright file with current year list.
+  * Build manual.html and install only itself and its dependencies.
+
+ -- Gerfried Fuchs <rhonda@debian.at>  Sun, 20 May 2007 00:20:59 +0200
+
+ldapvi (1.6-3) unstable; urgency=high
+
+  * Fixed a buffer overflow in home_filename function which was reported to
+    upstream.
+
+ -- Gerfried Fuchs <alfie@debian.org>  Fri, 09 Feb 2007 00:16:48 +0100
+
+ldapvi (1.6-2) unstable; urgency=low
+
+  * Alright, it's called libsasl2-dev now, not libsasl2-2-dev anymore...
+
+ -- Gerfried Fuchs <alfie@debian.org>  Sun, 10 Dec 2006 15:20:32 +0100
+
+ldapvi (1.6-1) unstable; urgency=low
+
+  * New upstream release which supports SASL, UTF-8 and configuration file.
+    Requires additional dependencies: libsasl2-2-dev, libreadline5-dev
+  * Made the watch file watch again.
+  * Don't patch GNUmakefile.in but instead save configure before calling
+    distclean.
+  * Lowercased synopsis start.
+  * Applied patch from upstream to be able to compile without a libcrypto, see
+    README.Debian.
+
+ -- Gerfried Fuchs <alfie@debian.org>  Sat, 18 Nov 2006 13:02:21 +0100
+
+ldapvi (1.5-2) unstable; urgency=low
+
+  * Patched misc.c to fall back onto sensible-editor instead of vi, and add
+    depends on editor so at least one is available for sure (closes: #367995)
+  * Applied replace_not_delete_add.diff to make it work for changing attributes
+    which are allowed only once (closes: #374962)
+  * Bumped Standards-Version to 3.7.2, no changes required.
+
+ -- Gerfried Fuchs <alfie@debian.org>  Fri, 23 Jun 2006 03:56:36 -0500
+
+ldapvi (1.5-1) unstable; urgency=low
+
+  * New upstream release.
+  * Updated watch file to version 3, and make it work again.
+  * Bumped Standards-Version to 3.6.2, no changes required.
+  * Applied patch from David Lichteblau himself for libldap 2.1, because
+    vanilla ldapvi requires libldap 2.2. Thanks!
+  * Updated FSF address in copyright file.
+
+ -- Gerfried Fuchs <alfie@debian.org>  Tue, 13 Dec 2005 21:30:13 +0100
+
+ldapvi (1.1-2) unstable; urgency=low
+
+  * fixed segfault: allow deletions to be skipped
+
+ -- Gerfried Fuchs <alfie@debian.org>  Wed,  7 Jul 2004 14:33:02 +0200
+
+ldapvi (1.1-1) unstable; urgency=low
+
+  * Initial Release (closes: #237082)
+  * GNUmakefile.in: removed configure from distclean target  :-(
+
+ -- Gerfried Fuchs <alfie@debian.org>  Tue, 06 Jul 2004 17:21:19 +0200
--- ldapvi-1.7.orig/debian/rules
+++ ldapvi-1.7/debian/rules
@@ -0,0 +1,116 @@
+#!/usr/bin/make -f
+# debian/rules for ldapvi
+# copyright 2004++ by Gerfried Fuchs.
+# Licenced the same way as ldapvi itself
+
+PKG = ldapvi
+TMP = $(CURDIR)/debian/$(PKG)
+
+# These are used for cross-compiling and for saving the configure script
+# from having to guess our platform (since we know it already)
+DEB_HOST_GNU_TYPE   ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
+DEB_BUILD_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
+
+CFLAGS = -Wall -g
+INSTALL = install
+INSTALL_FILE    = $(INSTALL) -p    -oroot -groot -m644
+INSTALL_PROGRAM = $(INSTALL) -p    -oroot -groot -m755
+INSTALL_SCRIPT  = $(INSTALL) -p    -oroot -groot -m755
+INSTALL_DIR     = $(INSTALL) -p -d -oroot -groot -m755
+ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
+	CFLAGS += -O0
+else
+	CFLAGS += -O2
+endif
+ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
+	INSTALL_PROGRAM += -s
+endif
+
+
+clean:
+	$(checkdir)
+	$(checkroot)
+	-rm -rf $(TMP) debian/substvars debian/files \
+		build-stamp install-stamp config.log test/*.out \
+		manual/manual.html
+	[ ! -f Makefile ] || $(MAKE) clean
+	# saving configure from distclean
+	cp -a configure configure.save
+	[ ! -f Makefile ] || $(MAKE) distclean
+	mv configure.save configure
+
+
+config.status: configure
+	$(checkdir)
+	# Add here commands to configure the package.
+	CFLAGS="$(CFLAGS)" ./configure --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) --prefix=/usr --mandir=\$${prefix}/share/man --infodir=\$${prefix}/share/info --with-libcrypto=none
+
+
+build: build-stamp
+build-stamp:  config.status
+	$(checkdir)
+	$(MAKE)
+	cd manual && $(MAKE) manual.html
+	touch build-stamp
+
+
+check: build
+	$(checkdir)
+	cd test && ./try
+
+install: install-stamp
+install-stamp: build
+	$(checkdir)
+	$(checkroot)
+	-rm -rf $(TMP)
+	$(INSTALL_DIR) $(TMP)/usr/bin $(TMP)/usr/share/man/man1 \
+		$(TMP)/usr/share/doc/$(PKG) $(TMP)/etc
+	### install currently broken, do it on our own
+	# $(MAKE) install prefix=$(TMP)/usr
+	$(INSTALL_PROGRAM) ldapvi $(TMP)/usr/bin
+	$(INSTALL_FILE) debian/ldapvi.conf $(TMP)/etc
+	$(INSTALL_FILE) ldapvi.1 $(TMP)/usr/share/man/man1
+	$(INSTALL_FILE) manual/manual.css manual/manual.html manual/bg.png \
+		$(TMP)/usr/share/doc/ldapvi
+	$(INSTALL_FILE) NEWS $(TMP)/usr/share/doc/$(PKG)/changelog
+	cd $(TMP)/usr && gzip -9 share/doc/$(PKG)/changelog \
+		share/man/man1/ldapvi.1
+	touch install-stamp
+
+
+# Build architecture-independent files here.
+binary-indep: build install
+# We have nothing to do by default.
+
+
+# Build architecture-dependent files here.
+binary-arch: build install
+	$(checkdir)
+	$(checkroot)
+	$(INSTALL_DIR) $(TMP)/DEBIAN
+	$(INSTALL_FILE) debian/copyright debian/README.Debian \
+		$(TMP)/usr/share/doc/$(PKG)
+	$(INSTALL_FILE) debian/changelog \
+		$(TMP)/usr/share/doc/$(PKG)/changelog.Debian
+	gzip -9 $(TMP)/usr/share/doc/$(PKG)/changelog.Debian
+	$(INSTALL_FILE) debian/conffiles \
+		$(TMP)/DEBIAN
+	dpkg-shlibdeps -Tdebian/substvars -dDepends $(TMP)/usr/bin/ldapvi
+	dpkg-gencontrol -ldebian/changelog -isp -Tdebian/substvars \
+		-p$(PKG) -P$(TMP)
+	cd $(TMP) && find * -type f ! -regex '^DEBIAN/.*' -print0 | \
+		xargs -r0 md5sum > DEBIAN/md5sums
+	dpkg --build $(TMP) ..
+
+
+binary: binary-arch
+
+define checkdir
+	test -f debian/rules
+endef
+
+define checkroot
+	test root = "`whoami`"
+endef
+
+.PHONY: clean build check install binary-indep binary-arch binary
--- ldapvi-1.7.orig/debian/copyright
+++ ldapvi-1.7/debian/copyright
@@ -0,0 +1,27 @@
+This package was debianized by Gerfried Fuchs <rhonda@debian.at> on
+Mon,  8 Mar 2004 11:38:57 +0100.
+
+It was downloaded from <http://www.lichteblau.com/src.html#ldapvi>
+
+Upstream Author: David Lichteblau <david@lichteblau.com>
+
+Copyright:
+
+    Copyright (c) 2003,2004,2005,2006,2007 David Lichteblau
+    
+    This program is free software; you can redistribute it and/or modify it
+    under the terms of the GNU General Public License as published by the
+    Free Software Foundation; either version 2, or (at your option) any
+    later version.
+    
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+
+On Debian GNU/Linux systems, the complete text of the GNU General
+Public License can be found in `/usr/share/common-licenses/GPL'.
--- ldapvi-1.7.orig/debian/control
+++ ldapvi-1.7/debian/control
@@ -0,0 +1,16 @@
+Source: ldapvi
+Section: text
+Priority: optional
+Maintainer: Gerfried Fuchs <rhonda@debian.at>
+Build-Depends: libldap2-dev, libglib2.0-dev, libpopt-dev, libncurses5-dev, libsasl2-dev, libreadline5-dev, xsltproc
+Standards-Version: 3.7.2
+
+Package: ldapvi
+Architecture: any
+Depends: ${shlibs:Depends}, editor
+Description: perform an LDAP search and update results using a text editor
+ From a first glance ldapvi looks like ldapsearch: You search for entries in
+ the ldap database. But the results get opened in your preferred editor, and
+ you can change, add or delete entries from there. After you are done you quit
+ the editor and ldapvi offers you several options: View your changes as LDIF,
+ commit changes or discard them.
--- ldapvi-1.7.orig/debian/watch
+++ ldapvi-1.7/debian/watch
@@ -0,0 +1,3 @@
+version=3
+http://www.lichteblau.com/ldapvi/  http://www.lichteblau.com/download/ldapvi-([0-9.]+).tar.gz  debian  uupdate
+# Site/Directory                   Pattern                                                     Version  Script
--- ldapvi-1.7.orig/debian/README.Debian
+++ ldapvi-1.7/debian/README.Debian
@@ -0,0 +1,16 @@
+ldapvi for Debian
+-----------------
+
+   Since version 1.6 of ldapvi it is able to link against a libcrypto for
+  supporting MD5.  Unfortunately there are some problems with this:  It
+  supports both linking it against the openssl and the gnutls libraries.
+  The former is out of scope because of the licence incompatibility of it
+  with the GPL.  ldapvi author would add linking exception to its licence,
+  though it uses libreadline and that one doesn't have the exception.
+
+   The latter though has a more severe problem: The password prompt will be
+  displayed in clear text on the screen.  It is yet unknown why, but for the
+  time being upstream was so kind to send a patch along to disable libcrypto
+  linking all along.
+
+ -- Gerfried Fuchs <alfie@debian.org>  Sat, 18 Nov 2006 13:02:21 +0100
--- ldapvi-1.7.orig/debian/ldapvi.conf
+++ ldapvi-1.7/debian/ldapvi.conf
@@ -0,0 +1,2 @@
+profile default
+unpaged-help: yes
--- ldapvi-1.7.orig/debian/conffiles
+++ ldapvi-1.7/debian/conffiles
@@ -0,0 +1 @@
+/etc/ldapvi.conf
