     This patch file is derived from OpenLDAP Software. All of the
     modifications to OpenLDAP Software represented in the following
     patch(es) were developed by Brian Candler <B.Candler@pobox.com>. These
     modifications are not subject to any license of
     Inspired Broadcast Networks.

     I, Brian Candler, hereby place the following modifications to
     OpenLDAP Software (and only these modifications) into the public
     domain. Hence, these modifications may be freely used and/or 
     redistributed for any purpose with or without attribution and/or
     other notice.

Index: doc/man/man5/slapd-shell.5
===================================================================
RCS file: /repo/OpenLDAP/pkg/ldap/doc/man/man5/slapd-shell.5,v
retrieving revision 1.15
diff -u -r1.15 slapd-shell.5
--- doc/man/man5/slapd-shell.5	8 Apr 2005 17:27:22 -0000	1.15
+++ doc/man/man5/slapd-shell.5	19 Oct 2005 13:00:56 -0000
@@ -69,6 +69,14 @@
 dn: <DN>
 .fi
 .TP
+.B extensions      [ binddn | peername | ssf ]*
+Enables the sending of additional meta-attributes with each request.
+.nf
+binddn: <bound DN>
+peername: IP=<address>:<port>
+ssf: <SSF value>
+.fi
+.TP
 .B modify   <pathname> <argument>...
 .nf
 MODIFY
@@ -113,7 +121,7 @@
 UNBIND
 msgid: <message id>
 <repeat { "suffix:" <database suffix DN> }>
-dn: <bound DN>
+dn: <bound DN>  [unless 'extensions binddn' is enabled]
 .fi
 .LP
 Note that you need only supply configuration lines for those commands you
Index: servers/slapd/back-shell/add.c
===================================================================
RCS file: /repo/OpenLDAP/pkg/ldap/servers/slapd/back-shell/add.c,v
retrieving revision 1.26
diff -u -r1.26 add.c
--- servers/slapd/back-shell/add.c	7 Apr 2005 22:18:25 -0000	1.26
+++ servers/slapd/back-shell/add.c	19 Oct 2005 13:00:58 -0000
@@ -70,6 +70,7 @@
 	/* write out the request to the add process */
 	fprintf( wfp, "ADD\n" );
 	fprintf( wfp, "msgid: %ld\n", (long) op->o_msgid );
+	print_conn( wfp, op->o_conn, si );
 	print_suffixes( wfp, op->o_bd );
 	ldap_pvt_thread_mutex_lock( &entry2str_mutex );
 	fprintf( wfp, "%s", entry2str( op->oq_add.rs_e, &len ) );
Index: servers/slapd/back-shell/bind.c
===================================================================
RCS file: /repo/OpenLDAP/pkg/ldap/servers/slapd/back-shell/bind.c,v
retrieving revision 1.26
diff -u -r1.26 bind.c
--- servers/slapd/back-shell/bind.c	1 Jan 2005 19:49:57 -0000	1.26
+++ servers/slapd/back-shell/bind.c	19 Oct 2005 13:00:58 -0000
@@ -80,6 +80,7 @@
 	/* write out the request to the bind process */
 	fprintf( wfp, "BIND\n" );
 	fprintf( wfp, "msgid: %ld\n", (long) op->o_msgid );
+	print_conn( wfp, op->o_conn, si );
 	print_suffixes( wfp, op->o_bd );
 	fprintf( wfp, "dn: %s\n", op->o_req_dn.bv_val );
 	fprintf( wfp, "method: %d\n", op->oq_bind.rb_method );
Index: servers/slapd/back-shell/compare.c
===================================================================
RCS file: /repo/OpenLDAP/pkg/ldap/servers/slapd/back-shell/compare.c,v
retrieving revision 1.27
diff -u -r1.27 compare.c
--- servers/slapd/back-shell/compare.c	1 Jan 2005 19:49:57 -0000	1.27
+++ servers/slapd/back-shell/compare.c	19 Oct 2005 13:00:58 -0000
@@ -84,6 +84,7 @@
 	/* write out the request to the compare process */
 	fprintf( wfp, "COMPARE\n" );
 	fprintf( wfp, "msgid: %ld\n", (long) op->o_msgid );
+	print_conn( wfp, op->o_conn, si );
 	print_suffixes( wfp, op->o_bd );
 	fprintf( wfp, "dn: %s\n", op->o_req_dn.bv_val );
 	fprintf( wfp, "%s: %s\n",
Index: servers/slapd/back-shell/config.c
===================================================================
RCS file: /repo/OpenLDAP/pkg/ldap/servers/slapd/back-shell/config.c,v
retrieving revision 1.17
diff -u -r1.17 config.c
--- servers/slapd/back-shell/config.c	1 Jan 2005 19:49:57 -0000	1.17
+++ servers/slapd/back-shell/config.c	19 Oct 2005 13:00:59 -0000
@@ -135,6 +135,24 @@
 		}
 		si->si_delete = ldap_charray_dup( &argv[1] );
 
+	/* extensions */
+	} else if ( strcasecmp( argv[0], "extensions" ) == 0 ) {
+		int i;
+		for ( i=1; i<argc; i++ ) {
+			if ( strcasecmp( argv[i], "binddn" ) == 0 )
+				si->si_extensions |= SHELL_EXT_BINDDN;
+			else if ( strcasecmp( argv[i], "peername" ) == 0 )
+				si->si_extensions |= SHELL_EXT_PEERNAME;
+			else if ( strcasecmp( argv[i], "ssf" ) == 0 )
+				si->si_extensions |= SHELL_EXT_SSF;
+			else {
+				fprintf( stderr,
+	"%s: line %d: unknown extension \"%s\"\n",
+			    fname, lineno, argv[i] );
+				return( 1 );
+			}
+		}
+
 	/* anything else */
 	} else {
 		return SLAP_CONF_UNKNOWN;
Index: servers/slapd/back-shell/delete.c
===================================================================
RCS file: /repo/OpenLDAP/pkg/ldap/servers/slapd/back-shell/delete.c,v
retrieving revision 1.25
diff -u -r1.25 delete.c
--- servers/slapd/back-shell/delete.c	7 Apr 2005 22:18:25 -0000	1.25
+++ servers/slapd/back-shell/delete.c	19 Oct 2005 13:00:59 -0000
@@ -79,6 +79,7 @@
 	/* write out the request to the delete process */
 	fprintf( wfp, "DELETE\n" );
 	fprintf( wfp, "msgid: %ld\n", (long) op->o_msgid );
+	print_conn( wfp, op->o_conn, si );
 	print_suffixes( wfp, op->o_bd );
 	fprintf( wfp, "dn: %s\n", op->o_req_dn.bv_val );
 	fclose( wfp );
Index: servers/slapd/back-shell/modify.c
===================================================================
RCS file: /repo/OpenLDAP/pkg/ldap/servers/slapd/back-shell/modify.c,v
retrieving revision 1.32
diff -u -r1.32 modify.c
--- servers/slapd/back-shell/modify.c	1 Jan 2005 19:49:57 -0000	1.32
+++ servers/slapd/back-shell/modify.c	19 Oct 2005 13:00:59 -0000
@@ -82,6 +82,7 @@
 	/* write out the request to the modify process */
 	fprintf( wfp, "MODIFY\n" );
 	fprintf( wfp, "msgid: %ld\n", (long) op->o_msgid );
+	print_conn( wfp, op->o_conn, si );
 	print_suffixes( wfp, op->o_bd );
 	fprintf( wfp, "dn: %s\n", op->o_req_dn.bv_val );
 	for ( ; ml != NULL; ml = ml->sml_next ) {
Index: servers/slapd/back-shell/modrdn.c
===================================================================
RCS file: /repo/OpenLDAP/pkg/ldap/servers/slapd/back-shell/modrdn.c,v
retrieving revision 1.27
diff -u -r1.27 modrdn.c
--- servers/slapd/back-shell/modrdn.c	7 Apr 2005 22:18:25 -0000	1.27
+++ servers/slapd/back-shell/modrdn.c	19 Oct 2005 13:00:59 -0000
@@ -80,6 +80,7 @@
 	/* write out the request to the modrdn process */
 	fprintf( wfp, "MODRDN\n" );
 	fprintf( wfp, "msgid: %ld\n", (long) op->o_msgid );
+	print_conn( wfp, op->o_conn, si );
 	print_suffixes( wfp, op->o_bd );
 	fprintf( wfp, "dn: %s\n", op->o_req_dn.bv_val );
 	fprintf( wfp, "newrdn: %s\n", op->oq_modrdn.rs_newrdn.bv_val );
Index: servers/slapd/back-shell/result.c
===================================================================
RCS file: /repo/OpenLDAP/pkg/ldap/servers/slapd/back-shell/result.c,v
retrieving revision 1.22
diff -u -r1.22 result.c
--- servers/slapd/back-shell/result.c	1 Jan 2005 19:49:57 -0000	1.22
+++ servers/slapd/back-shell/result.c	19 Oct 2005 13:00:59 -0000
@@ -132,3 +132,25 @@
 		fprintf( fp, "suffix: %s\n", be->be_suffix[i].bv_val );
 	}
 }
+
+void
+print_conn(
+    FILE	*fp,
+    Connection	*conn,
+    struct shellinfo *si
+)
+{
+	if ( conn == NULL ) return;
+
+	if( si->si_extensions & SHELL_EXT_BINDDN ) {
+		fprintf( fp, "binddn: %s\n",
+			conn->c_dn.bv_len ? conn->c_dn.bv_val : "" );
+	}
+	if( si->si_extensions & SHELL_EXT_PEERNAME ) {
+		fprintf( fp, "peername: %s\n",
+			conn->c_peer_name.bv_len ? conn->c_peer_name.bv_val : "" );
+	}
+	if( si->si_extensions & SHELL_EXT_SSF ) {
+		fprintf( fp, "ssf: %d\n", conn->c_ssf );
+	}
+}
Index: servers/slapd/back-shell/search.c
===================================================================
RCS file: /repo/OpenLDAP/pkg/ldap/servers/slapd/back-shell/search.c,v
retrieving revision 1.28
diff -u -r1.28 search.c
--- servers/slapd/back-shell/search.c	1 Jan 2005 19:49:57 -0000	1.28
+++ servers/slapd/back-shell/search.c	19 Oct 2005 13:00:59 -0000
@@ -62,6 +62,7 @@
 	/* write out the request to the search process */
 	fprintf( wfp, "SEARCH\n" );
 	fprintf( wfp, "msgid: %ld\n", (long) op->o_msgid );
+	print_conn( wfp, op->o_conn, si );
 	print_suffixes( wfp, op->o_bd );
 	fprintf( wfp, "base: %s\n", op->o_req_dn.bv_val );
 	fprintf( wfp, "scope: %d\n", op->oq_search.rs_scope );
Index: servers/slapd/back-shell/shell.h
===================================================================
RCS file: /repo/OpenLDAP/pkg/ldap/servers/slapd/back-shell/shell.h,v
retrieving revision 1.23
diff -u -r1.23 shell.h
--- servers/slapd/back-shell/shell.h	1 Jan 2005 19:49:57 -0000	1.23
+++ servers/slapd/back-shell/shell.h	19 Oct 2005 13:00:59 -0000
@@ -44,8 +44,13 @@
 	char	**si_modrdn;	/* cmd + args to exec for modrdn  */
 	char	**si_add;		/* cmd + args to exec for add	  */
 	char	**si_delete;	/* cmd + args to exec for delete  */
+	int	si_extensions;
 };
 
+#define	SHELL_EXT_BINDDN	1
+#define	SHELL_EXT_PEERNAME	2
+#define	SHELL_EXT_SSF		4
+
 struct slap_backend_db;
 struct slap_conn;
 struct slap_op;
@@ -59,6 +64,11 @@
 	FILE *fp,
 	struct slap_backend_db *bd));
 
+extern void print_conn LDAP_P((
+	FILE *fp,
+	Connection *conn,
+	struct shellinfo *si));
+
 extern int read_and_send_results LDAP_P((
 	struct slap_op *op,
 	struct slap_rep *rs,
Index: servers/slapd/back-shell/unbind.c
===================================================================
RCS file: /repo/OpenLDAP/pkg/ldap/servers/slapd/back-shell/unbind.c,v
retrieving revision 1.22
diff -u -r1.22 unbind.c
--- servers/slapd/back-shell/unbind.c	1 Jan 2005 19:49:57 -0000	1.22
+++ servers/slapd/back-shell/unbind.c	19 Oct 2005 13:00:59 -0000
@@ -58,8 +58,10 @@
 	/* write out the request to the unbind process */
 	fprintf( wfp, "UNBIND\n" );
 	fprintf( wfp, "msgid: %ld\n", (long) op->o_msgid );
+	print_conn( wfp, op->o_conn, si );
 	print_suffixes( wfp, op->o_bd );
-	fprintf( wfp, "dn: %s\n", (op->o_conn->c_dn.bv_len ? op->o_conn->c_dn.bv_val : "") );
+	if ( (si->si_extensions & SHELL_EXT_BINDDN) == 0 )
+		fprintf( wfp, "dn: %s\n", (op->o_conn->c_dn.bv_len ? op->o_conn->c_dn.bv_val : "") );
 	fclose( wfp );
 
 	/* no response to unbind */
