Blame SOURCES/openldap-cbinding-ITS-8573-allow-all-libldap-options-in-tools-o-option.patch

e4ff3b
NOTE: The patch has been adjusted to match the base code before backporting.
e4ff3b
e4ff3b
From 8a259e3df16def3f05828f355e98a5089cd6e6d0 Mon Sep 17 00:00:00 2001
e4ff3b
From: =?UTF-8?q?Ond=C5=99ej=20Kuzn=C3=ADk?= <ondra@openldap.org>
e4ff3b
Date: Thu, 14 Jun 2018 16:14:15 +0100
e4ff3b
Subject: [PATCH] ITS#8573 allow all libldap options in tools -o option
e4ff3b
e4ff3b
---
e4ff3b
 clients/tools/common.c     |  15 ++-
e4ff3b
 doc/devel/args             |   2 +-
e4ff3b
 doc/man/man1/ldapcompare.1 |   9 +-
e4ff3b
 doc/man/man1/ldapdelete.1  |   9 +-
e4ff3b
 doc/man/man1/ldapexop.1    |   9 +-
e4ff3b
 doc/man/man1/ldapmodify.1  |   9 +-
e4ff3b
 doc/man/man1/ldapmodrdn.1  |   9 +-
e4ff3b
 doc/man/man1/ldappasswd.1  |   9 +-
e4ff3b
 doc/man/man1/ldapsearch.1  |   9 +-
e4ff3b
 doc/man/man1/ldapwhoami.1  |  13 ++-
e4ff3b
 doc/man/man8/slapcat.8     |   2 +-
e4ff3b
 include/ldap_pvt.h         |   5 +
e4ff3b
 libraries/libldap/init.c   | 231 ++++++++++++++++++++++---------------
e4ff3b
 servers/slapd/slapcommon.c |   5 +-
e4ff3b
 14 files changed, 200 insertions(+), 136 deletions(-)
e4ff3b
e4ff3b
diff --git a/clients/tools/common.c b/clients/tools/common.c
e4ff3b
index 39db70b93..d5c3491fc 100644
e4ff3b
--- a/clients/tools/common.c
e4ff3b
+++ b/clients/tools/common.c
e4ff3b
@@ -351,9 +351,9 @@ N_("  -I         use SASL Interactive mode\n"),
e4ff3b
 N_("  -n         show what would be done but don't actually do it\n"),
e4ff3b
 N_("  -N         do not use reverse DNS to canonicalize SASL host name\n"),
e4ff3b
 N_("  -O props   SASL security properties\n"),
e4ff3b
-N_("  -o <opt>[=<optparam>] general options\n"),
e4ff3b
+N_("  -o <opt>[=<optparam>] any libldap ldap.conf options, plus\n"),
e4ff3b
+N_("             ldif_wrap=<width> (in columns, or \"no\" for no wrapping)\n"),
e4ff3b
 N_("             nettimeout=<timeout> (in seconds, or \"none\" or \"max\")\n"),
e4ff3b
-N_("             ldif-wrap=<width> (in columns, or \"no\" for no wrapping)\n"),
e4ff3b
 N_("  -p port    port on LDAP server\n"),
e4ff3b
 N_("  -Q         use SASL Quiet mode\n"),
e4ff3b
 N_("  -R realm   SASL realm\n"),
e4ff3b
@@ -785,6 +785,11 @@ tool_args( int argc, char **argv )
e4ff3b
 			if ( (cvalue = strchr( control, '=' )) != NULL ) {
e4ff3b
 				*cvalue++ = '\0';
e4ff3b
 			}
e4ff3b
+			for ( next=control; *next; next++ ) {
e4ff3b
+				if ( *next == '-' ) {
e4ff3b
+					*next = '_';
e4ff3b
+				}
e4ff3b
+			}
e4ff3b
 
e4ff3b
 			if ( strcasecmp( control, "nettimeout" ) == 0 ) {
e4ff3b
 				if( nettimeout.tv_sec != -1 ) {
e4ff3b
@@ -814,7 +819,7 @@ tool_args( int argc, char **argv )
e4ff3b
 	 				exit( EXIT_FAILURE );
e4ff3b
  				}
e4ff3b
 
e4ff3b
-			} else if ( strcasecmp( control, "ldif-wrap" ) == 0 ) {
e4ff3b
+			} else if ( strcasecmp( control, "ldif_wrap" ) == 0 ) {
e4ff3b
 				if ( cvalue == 0 ) {
e4ff3b
 					ldif_wrap = LDIF_LINE_WIDTH;
e4ff3b
 
e4ff3b
@@ -825,13 +830,13 @@ tool_args( int argc, char **argv )
e4ff3b
 					unsigned int u;
e4ff3b
 					if ( lutil_atou( &u, cvalue ) ) {
e4ff3b
 						fprintf( stderr,
e4ff3b
-							_("Unable to parse ldif-wrap=\"%s\"\n"), cvalue );
e4ff3b
+							_("Unable to parse ldif_wrap=\"%s\"\n"), cvalue );
e4ff3b
 		 				exit( EXIT_FAILURE );
e4ff3b
 					}
e4ff3b
 					ldif_wrap = (ber_len_t)u;
e4ff3b
 				}
e4ff3b
 
e4ff3b
-			} else {
e4ff3b
+			} else if ( ldap_pvt_conf_option( control, cvalue, 1 ) ) {
e4ff3b
 				fprintf( stderr, "Invalid general option name: %s\n",
e4ff3b
 					control );
e4ff3b
 				usage();
e4ff3b
diff --git a/doc/devel/args b/doc/devel/args
e4ff3b
index 7805eff1c..31c22f948 100644
e4ff3b
--- a/doc/devel/args
e4ff3b
+++ b/doc/devel/args
e4ff3b
@@ -27,7 +27,7 @@ ldapwhoami       * DE**HI**  NO QR  UVWXYZ   def*h*** *nop*    vwxy
e4ff3b
 	-h host
e4ff3b
 	-n no-op
e4ff3b
 	-N no (SASLprep) normalization of simple bind password
e4ff3b
-	-o general options (currently nettimeout and ldif-wrap only)
e4ff3b
+	-o general libldap options (plus ldif_wrap and nettimeout for backwards comp.)
e4ff3b
 	-p port
e4ff3b
 	-v verbose
e4ff3b
 	-V version
e4ff3b
diff --git a/doc/man/man1/ldapcompare.1 b/doc/man/man1/ldapcompare.1
e4ff3b
index 667815a26..de90498db 100644
e4ff3b
--- a/doc/man/man1/ldapcompare.1
e4ff3b
+++ b/doc/man/man1/ldapcompare.1
e4ff3b
@@ -186,13 +186,14 @@ Compare extensions:
e4ff3b
 .TP
e4ff3b
 .BI \-o \ opt \fR[= optparam \fR]
e4ff3b
 
e4ff3b
-Specify general options.
e4ff3b
-
e4ff3b
-General options:
e4ff3b
+Specify any
e4ff3b
+.BR ldap.conf (5)
e4ff3b
+option or one of the following:
e4ff3b
 .nf
e4ff3b
   nettimeout=<timeout>  (in seconds, or "none" or "max")
e4ff3b
-  ldif-wrap=<width>     (in columns, or "no" for no wrapping)
e4ff3b
+  ldif_wrap=<width>     (in columns, or "no" for no wrapping)
e4ff3b
 .fi
e4ff3b
+
e4ff3b
 .TP
e4ff3b
 .BI \-O \ security-properties
e4ff3b
 Specify SASL security properties.
e4ff3b
diff --git a/doc/man/man1/ldapdelete.1 b/doc/man/man1/ldapdelete.1
e4ff3b
index 9e7036230..872424a65 100644
e4ff3b
--- a/doc/man/man1/ldapdelete.1
e4ff3b
+++ b/doc/man/man1/ldapdelete.1
e4ff3b
@@ -192,13 +192,14 @@ Delete extensions:
e4ff3b
 .TP
e4ff3b
 .BI \-o \ opt \fR[= optparam \fR]
e4ff3b
 
e4ff3b
-Specify general options.
e4ff3b
-
e4ff3b
-General options:
e4ff3b
+Specify any
e4ff3b
+.BR ldap.conf (5)
e4ff3b
+option or one of the following:
e4ff3b
 .nf
e4ff3b
   nettimeout=<timeout>  (in seconds, or "none" or "max")
e4ff3b
-  ldif-wrap=<width>     (in columns, or "no" for no wrapping)
e4ff3b
+  ldif_wrap=<width>     (in columns, or "no" for no wrapping)
e4ff3b
 .fi
e4ff3b
+
e4ff3b
 .TP
e4ff3b
 .BI \-O \ security-properties
e4ff3b
 Specify SASL security properties.
e4ff3b
diff --git a/doc/man/man1/ldapexop.1 b/doc/man/man1/ldapexop.1
e4ff3b
index 5f5ae7aae..96a7c514e 100644
e4ff3b
--- a/doc/man/man1/ldapexop.1
e4ff3b
+++ b/doc/man/man1/ldapexop.1
e4ff3b
@@ -189,13 +189,14 @@ Specify general extensions.  \'!\' indicates criticality.
e4ff3b
 .TP
e4ff3b
 .BI \-o \ opt \fR[= optparam \fR]
e4ff3b
 
e4ff3b
-Specify general options.
e4ff3b
-
e4ff3b
-General options:
e4ff3b
+Specify any
e4ff3b
+.BR ldap.conf (5)
e4ff3b
+option or one of the following:
e4ff3b
 .nf
e4ff3b
   nettimeout=<timeout>  (in seconds, or "none" or "max")
e4ff3b
-  ldif-wrap=<width>     (in columns, or "no" for no wrapping)
e4ff3b
+  ldif_wrap=<width>     (in columns, or "no" for no wrapping)
e4ff3b
 .fi
e4ff3b
+
e4ff3b
 .TP
e4ff3b
 .BI \-O \ security-properties
e4ff3b
 Specify SASL security properties.
e4ff3b
diff --git a/doc/man/man1/ldapmodify.1 b/doc/man/man1/ldapmodify.1
e4ff3b
index f884c5bfb..90f813506 100644
e4ff3b
--- a/doc/man/man1/ldapmodify.1
e4ff3b
+++ b/doc/man/man1/ldapmodify.1
e4ff3b
@@ -255,13 +255,14 @@ Modify extensions:
e4ff3b
 .TP
e4ff3b
 .BI \-o \ opt \fR[= optparam \fR]]
e4ff3b
 
e4ff3b
-Specify general options.
e4ff3b
-
e4ff3b
-General options:
e4ff3b
+Specify any
e4ff3b
+.BR ldap.conf (5)
e4ff3b
+option or one of the following:
e4ff3b
 .nf
e4ff3b
   nettimeout=<timeout>  (in seconds, or "none" or "max")
e4ff3b
-  ldif-wrap=<width>     (in columns, or "no" for no wrapping)
e4ff3b
+  ldif_wrap=<width>     (in columns, or "no" for no wrapping)
e4ff3b
 .fi
e4ff3b
+
e4ff3b
 .TP
e4ff3b
 .BI \-O \ security-properties
e4ff3b
 Specify SASL security properties.
e4ff3b
diff --git a/doc/man/man1/ldapmodrdn.1 b/doc/man/man1/ldapmodrdn.1
e4ff3b
index fa9eac627..900ba7e0e 100644
e4ff3b
--- a/doc/man/man1/ldapmodrdn.1
e4ff3b
+++ b/doc/man/man1/ldapmodrdn.1
e4ff3b
@@ -186,13 +186,14 @@ Modrdn extensions:
e4ff3b
 .TP
e4ff3b
 .BI \-o \ opt \fR[= optparam \fR]
e4ff3b
 
e4ff3b
-Specify general options.
e4ff3b
-
e4ff3b
-General options:
e4ff3b
+Specify any
e4ff3b
+.BR ldap.conf (5)
e4ff3b
+option or one of the following:
e4ff3b
 .nf
e4ff3b
   nettimeout=<timeout>  (in seconds, or "none" or "max")
e4ff3b
-  ldif-wrap=<width>     (in columns, or "no" for no wrapping)
e4ff3b
+  ldif_wrap=<width>     (in columns, or "no" for no wrapping)
e4ff3b
 .fi
e4ff3b
+
e4ff3b
 .TP
e4ff3b
 .BI \-O \ security-properties
e4ff3b
 Specify SASL security properties.
e4ff3b
diff --git a/doc/man/man1/ldappasswd.1 b/doc/man/man1/ldappasswd.1
e4ff3b
index d3f45b082..bf273fb25 100644
e4ff3b
--- a/doc/man/man1/ldappasswd.1
e4ff3b
+++ b/doc/man/man1/ldappasswd.1
e4ff3b
@@ -188,13 +188,14 @@ Passwd Modify extensions:
e4ff3b
 .TP
e4ff3b
 .BI \-o \ opt \fR[= optparam \fR]]
e4ff3b
 
e4ff3b
-Specify general options.
e4ff3b
-
e4ff3b
-General options:
e4ff3b
+Specify any
e4ff3b
+.BR ldap.conf (5)
e4ff3b
+option or one of the following:
e4ff3b
 .nf
e4ff3b
   nettimeout=<timeout>  (in seconds, or "none" or "max")
e4ff3b
-  ldif-wrap=<width>     (in columns, or "no" for no wrapping)
e4ff3b
+  ldif_wrap=<width>     (in columns, or "no" for no wrapping)
e4ff3b
 .fi
e4ff3b
+
e4ff3b
 .TP
e4ff3b
 .BI \-O \ security-properties
e4ff3b
 Specify SASL security properties.
e4ff3b
diff --git a/doc/man/man1/ldapsearch.1 b/doc/man/man1/ldapsearch.1
e4ff3b
index 196179232..901e56043 100644
e4ff3b
--- a/doc/man/man1/ldapsearch.1
e4ff3b
+++ b/doc/man/man1/ldapsearch.1
e4ff3b
@@ -332,13 +332,14 @@ Search extensions:
e4ff3b
 .TP
e4ff3b
 .BI \-o \ opt \fR[= optparam \fR]
e4ff3b
 
e4ff3b
-Specify general options.
e4ff3b
-
e4ff3b
-General options:
e4ff3b
+Specify any
e4ff3b
+.BR ldap.conf (5)
e4ff3b
+option or one of the following:
e4ff3b
 .nf
e4ff3b
   nettimeout=<timeout>  (in seconds, or "none" or "max")
e4ff3b
-  ldif-wrap=<width>     (in columns, or "no" for no wrapping)
e4ff3b
+  ldif_wrap=<width>     (in columns, or "no" for no wrapping)
e4ff3b
 .fi
e4ff3b
+
e4ff3b
 .TP
e4ff3b
 .BI \-O \ security-properties
e4ff3b
 Specify SASL security properties.
e4ff3b
diff --git a/doc/man/man1/ldapwhoami.1 b/doc/man/man1/ldapwhoami.1
e4ff3b
index b684de54a..79864c729 100644
e4ff3b
--- a/doc/man/man1/ldapwhoami.1
e4ff3b
+++ b/doc/man/man1/ldapwhoami.1
e4ff3b
@@ -143,13 +143,18 @@ WhoAmI extensions:
e4ff3b
 .TP
e4ff3b
 .BI \-o \ opt \fR[= optparam \fR]
e4ff3b
 
e4ff3b
-Specify general options.
e4ff3b
-
e4ff3b
-General options:
e4ff3b
+Specify any
e4ff3b
+.BR ldap.conf (5)
e4ff3b
+option or one of the following:
e4ff3b
 .nf
e4ff3b
   nettimeout=<timeout>  (in seconds, or "none" or "max")
e4ff3b
-  ldif-wrap=<width>     (in columns, or "no" for no wrapping)
e4ff3b
+  ldif_wrap=<width>     (in columns, or "no" for no wrapping)
e4ff3b
 .fi
e4ff3b
+
e4ff3b
+.B -o
e4ff3b
+option that can be passed here, check
e4ff3b
+.BR ldap.conf (5)
e4ff3b
+for details.
e4ff3b
 .TP
e4ff3b
 .BI \-O \ security-properties
e4ff3b
 Specify SASL security properties.
e4ff3b
diff --git a/doc/man/man8/slapcat.8 b/doc/man/man8/slapcat.8
e4ff3b
index d05cfa643..24c8f03ea 100644
e4ff3b
--- a/doc/man/man8/slapcat.8
e4ff3b
+++ b/doc/man/man8/slapcat.8
e4ff3b
@@ -149,7 +149,7 @@ Possible generic options/values are:
e4ff3b
               syslog\-level=<level> (see `\-S' in slapd(8))
e4ff3b
               syslog\-user=<user>   (see `\-l' in slapd(8))
e4ff3b
 
e4ff3b
-              ldif-wrap={no|<n>}
e4ff3b
+              ldif_wrap={no|<n>}
e4ff3b
 
e4ff3b
 .in
e4ff3b
 \fIn\fP is the number of columns allowed for the LDIF output
e4ff3b
diff --git a/include/ldap_pvt.h b/include/ldap_pvt.h
e4ff3b
index 61c620785..c586a95b5 100644
e4ff3b
--- a/include/ldap_pvt.h
e4ff3b
+++ b/include/ldap_pvt.h
e4ff3b
@@ -321,6 +321,11 @@ struct ldapmsg;
e4ff3b
 LDAP_F ( int ) ldap_pvt_discard LDAP_P((
e4ff3b
 	struct ldap *ld, ber_int_t msgid ));
e4ff3b
 
e4ff3b
+/* init.c */
e4ff3b
+LDAP_F( int )
e4ff3b
+ldap_pvt_conf_option LDAP_P((
e4ff3b
+	char *cmd, char *opt, int userconf ));
e4ff3b
+
e4ff3b
 /* messages.c */
e4ff3b
 LDAP_F( BerElement * )
e4ff3b
 ldap_get_message_ber LDAP_P((
e4ff3b
diff --git a/libraries/libldap/init.c b/libraries/libldap/init.c
e4ff3b
index 182ef7d7e..746824fbd 100644
e4ff3b
--- a/libraries/libldap/init.c
e4ff3b
+++ b/libraries/libldap/init.c
e4ff3b
@@ -148,6 +148,141 @@ static const struct ol_attribute {
e4ff3b
 #define MAX_LDAP_ATTR_LEN  sizeof("GSSAPI_ALLOW_REMOTE_PRINCIPAL")
e4ff3b
 #define MAX_LDAP_ENV_PREFIX_LEN 8
e4ff3b
 
e4ff3b
+static int
e4ff3b
+ldap_int_conf_option(
e4ff3b
+	struct ldapoptions *gopts,
e4ff3b
+	char *cmd, char *opt, int userconf )
e4ff3b
+{
e4ff3b
+	int i;
e4ff3b
+
e4ff3b
+	for(i=0; attrs[i].type != ATTR_NONE; i++) {
e4ff3b
+		void *p;
e4ff3b
+
e4ff3b
+		if( !userconf && attrs[i].useronly ) {
e4ff3b
+			continue;
e4ff3b
+		}
e4ff3b
+
e4ff3b
+		if(strcasecmp(cmd, attrs[i].name) != 0) {
e4ff3b
+			continue;
e4ff3b
+		}
e4ff3b
+
e4ff3b
+		switch(attrs[i].type) {
e4ff3b
+		case ATTR_BOOL:
e4ff3b
+			if((strcasecmp(opt, "on") == 0)
e4ff3b
+				|| (strcasecmp(opt, "yes") == 0)
e4ff3b
+				|| (strcasecmp(opt, "true") == 0))
e4ff3b
+			{
e4ff3b
+				LDAP_BOOL_SET(gopts, attrs[i].offset);
e4ff3b
+
e4ff3b
+			} else {
e4ff3b
+				LDAP_BOOL_CLR(gopts, attrs[i].offset);
e4ff3b
+			}
e4ff3b
+
e4ff3b
+			break;
e4ff3b
+
e4ff3b
+		case ATTR_INT: {
e4ff3b
+			char *next;
e4ff3b
+			long l;
e4ff3b
+			p = &((char *) gopts)[attrs[i].offset];
e4ff3b
+			l = strtol( opt, &next, 10 );
e4ff3b
+			if ( next != opt && next[ 0 ] == '\0' ) {
e4ff3b
+				* (int*) p = l;
e4ff3b
+			}
e4ff3b
+			} break;
e4ff3b
+
e4ff3b
+		case ATTR_KV: {
e4ff3b
+				const struct ol_keyvalue *kv;
e4ff3b
+
e4ff3b
+				for(kv = attrs[i].data;
e4ff3b
+					kv->key != NULL;
e4ff3b
+					kv++) {
e4ff3b
+
e4ff3b
+					if(strcasecmp(opt, kv->key) == 0) {
e4ff3b
+						p = &((char *) gopts)[attrs[i].offset];
e4ff3b
+						* (int*) p = kv->value;
e4ff3b
+						break;
e4ff3b
+					}
e4ff3b
+				}
e4ff3b
+			} break;
e4ff3b
+
e4ff3b
+		case ATTR_STRING:
e4ff3b
+			p = &((char *) gopts)[attrs[i].offset];
e4ff3b
+			if (* (char**) p != NULL) LDAP_FREE(* (char**) p);
e4ff3b
+			* (char**) p = LDAP_STRDUP(opt);
e4ff3b
+			break;
e4ff3b
+		case ATTR_OPTION:
e4ff3b
+			ldap_set_option( NULL, attrs[i].offset, opt );
e4ff3b
+			break;
e4ff3b
+		case ATTR_SASL:
e4ff3b
+#ifdef HAVE_CYRUS_SASL
e4ff3b
+			ldap_int_sasl_config( gopts, attrs[i].offset, opt );
e4ff3b
+#endif
e4ff3b
+			break;
e4ff3b
+		case ATTR_GSSAPI:
e4ff3b
+#ifdef HAVE_GSSAPI
e4ff3b
+			ldap_int_gssapi_config( gopts, attrs[i].offset, opt );
e4ff3b
+#endif
e4ff3b
+			break;
e4ff3b
+		case ATTR_TLS:
e4ff3b
+#ifdef HAVE_TLS
e4ff3b
+			ldap_int_tls_config( NULL, attrs[i].offset, opt );
e4ff3b
+#endif
e4ff3b
+			break;
e4ff3b
+		case ATTR_OPT_TV: {
e4ff3b
+			struct timeval tv;
e4ff3b
+			char *next;
e4ff3b
+			tv.tv_usec = 0;
e4ff3b
+			tv.tv_sec = strtol( opt, &next, 10 );
e4ff3b
+			if ( next != opt && next[ 0 ] == '\0' && tv.tv_sec > 0 ) {
e4ff3b
+				(void)ldap_set_option( NULL, attrs[i].offset, (const void *)&tv );
e4ff3b
+			}
e4ff3b
+			} break;
e4ff3b
+		case ATTR_OPT_INT: {
e4ff3b
+			long l;
e4ff3b
+			char *next;
e4ff3b
+			l = strtol( opt, &next, 10 );
e4ff3b
+			if ( next != opt && next[ 0 ] == '\0' && l > 0 && (long)((int)l) == l ) {
e4ff3b
+				int v = (int)l;
e4ff3b
+				(void)ldap_set_option( NULL, attrs[i].offset, (const void *)&v );
e4ff3b
+			}
e4ff3b
+			} break;
e4ff3b
+		}
e4ff3b
+
e4ff3b
+		break;
e4ff3b
+	}
e4ff3b
+
e4ff3b
+	if ( attrs[i].type == ATTR_NONE ) {
e4ff3b
+		Debug( LDAP_DEBUG_TRACE, "ldap_int_tls_config: "
e4ff3b
+				"unknown option '%s'",
e4ff3b
+				cmd, 0, 0 );
e4ff3b
+		return 1;
e4ff3b
+	}
e4ff3b
+
e4ff3b
+	return 0;
e4ff3b
+}
e4ff3b
+
e4ff3b
+int
e4ff3b
+ldap_pvt_conf_option(
e4ff3b
+	char *cmd, char *opt, int userconf )
e4ff3b
+{
e4ff3b
+	struct ldapoptions *gopts;
e4ff3b
+	int rc = LDAP_OPT_ERROR;
e4ff3b
+
e4ff3b
+	/* Get pointer to global option structure */
e4ff3b
+	gopts = LDAP_INT_GLOBAL_OPT();
e4ff3b
+	if (NULL == gopts) {
e4ff3b
+		return LDAP_NO_MEMORY;
e4ff3b
+	}
e4ff3b
+
e4ff3b
+	if ( gopts->ldo_valid != LDAP_INITIALIZED ) {
e4ff3b
+		ldap_int_initialize(gopts, NULL);
e4ff3b
+		if ( gopts->ldo_valid != LDAP_INITIALIZED )
e4ff3b
+			return LDAP_LOCAL_ERROR;
e4ff3b
+	}
e4ff3b
+
e4ff3b
+	return ldap_int_conf_option( gopts, cmd, opt, userconf );
e4ff3b
+}
e4ff3b
+
e4ff3b
 static void openldap_ldap_init_w_conf(
e4ff3b
 	const char *file, int userconf )
e4ff3b
 {
e4ff3b
@@ -213,101 +348,7 @@ static void openldap_ldap_init_w_conf(
e4ff3b
 		while(isspace((unsigned char)*start)) start++;
e4ff3b
 		opt = start;
e4ff3b
 
e4ff3b
-		for(i=0; attrs[i].type != ATTR_NONE; i++) {
e4ff3b
-			void *p;
e4ff3b
-
e4ff3b
-			if( !userconf && attrs[i].useronly ) {
e4ff3b
-				continue;
e4ff3b
-			}
e4ff3b
-
e4ff3b
-			if(strcasecmp(cmd, attrs[i].name) != 0) {
e4ff3b
-				continue;
e4ff3b
-			}
e4ff3b
-
e4ff3b
-			switch(attrs[i].type) {
e4ff3b
-			case ATTR_BOOL:
e4ff3b
-				if((strcasecmp(opt, "on") == 0) 
e4ff3b
-					|| (strcasecmp(opt, "yes") == 0)
e4ff3b
-					|| (strcasecmp(opt, "true") == 0))
e4ff3b
-				{
e4ff3b
-					LDAP_BOOL_SET(gopts, attrs[i].offset);
e4ff3b
-
e4ff3b
-				} else {
e4ff3b
-					LDAP_BOOL_CLR(gopts, attrs[i].offset);
e4ff3b
-				}
e4ff3b
-
e4ff3b
-				break;
e4ff3b
-
e4ff3b
-			case ATTR_INT: {
e4ff3b
-				char *next;
e4ff3b
-				long l;
e4ff3b
-				p = &((char *) gopts)[attrs[i].offset];
e4ff3b
-				l = strtol( opt, &next, 10 );
e4ff3b
-				if ( next != opt && next[ 0 ] == '\0' ) {
e4ff3b
-					* (int*) p = l;
e4ff3b
-				}
e4ff3b
-				} break;
e4ff3b
-
e4ff3b
-			case ATTR_KV: {
e4ff3b
-					const struct ol_keyvalue *kv;
e4ff3b
-
e4ff3b
-					for(kv = attrs[i].data;
e4ff3b
-						kv->key != NULL;
e4ff3b
-						kv++) {
e4ff3b
-
e4ff3b
-						if(strcasecmp(opt, kv->key) == 0) {
e4ff3b
-							p = &((char *) gopts)[attrs[i].offset];
e4ff3b
-							* (int*) p = kv->value;
e4ff3b
-							break;
e4ff3b
-						}
e4ff3b
-					}
e4ff3b
-				} break;
e4ff3b
-
e4ff3b
-			case ATTR_STRING:
e4ff3b
-				p = &((char *) gopts)[attrs[i].offset];
e4ff3b
-				if (* (char**) p != NULL) LDAP_FREE(* (char**) p);
e4ff3b
-				* (char**) p = LDAP_STRDUP(opt);
e4ff3b
-				break;
e4ff3b
-			case ATTR_OPTION:
e4ff3b
-				ldap_set_option( NULL, attrs[i].offset, opt );
e4ff3b
-				break;
e4ff3b
-			case ATTR_SASL:
e4ff3b
-#ifdef HAVE_CYRUS_SASL
e4ff3b
-			   	ldap_int_sasl_config( gopts, attrs[i].offset, opt );
e4ff3b
-#endif
e4ff3b
-				break;
e4ff3b
-			case ATTR_GSSAPI:
e4ff3b
-#ifdef HAVE_GSSAPI
e4ff3b
-				ldap_int_gssapi_config( gopts, attrs[i].offset, opt );
e4ff3b
-#endif
e4ff3b
-				break;
e4ff3b
-			case ATTR_TLS:
e4ff3b
-#ifdef HAVE_TLS
e4ff3b
-			   	ldap_int_tls_config( NULL, attrs[i].offset, opt );
e4ff3b
-#endif
e4ff3b
-				break;
e4ff3b
-			case ATTR_OPT_TV: {
e4ff3b
-				struct timeval tv;
e4ff3b
-				char *next;
e4ff3b
-				tv.tv_usec = 0;
e4ff3b
-				tv.tv_sec = strtol( opt, &next, 10 );
e4ff3b
-				if ( next != opt && next[ 0 ] == '\0' && tv.tv_sec > 0 ) {
e4ff3b
-					(void)ldap_set_option( NULL, attrs[i].offset, (const void *)&tv );
e4ff3b
-				}
e4ff3b
-				} break;
e4ff3b
-			case ATTR_OPT_INT: {
e4ff3b
-				long l;
e4ff3b
-				char *next;
e4ff3b
-				l = strtol( opt, &next, 10 );
e4ff3b
-				if ( next != opt && next[ 0 ] == '\0' && l > 0 && (long)((int)l) == l ) {
e4ff3b
-					int v = (int)l;
e4ff3b
-					(void)ldap_set_option( NULL, attrs[i].offset, (const void *)&v );
e4ff3b
-				}
e4ff3b
-				} break;
e4ff3b
-			}
e4ff3b
-
e4ff3b
-			break;
e4ff3b
-		}
e4ff3b
+		ldap_int_conf_option( gopts, cmd, opt, userconf );
e4ff3b
 	}
e4ff3b
 
e4ff3b
 	fclose(fp);
e4ff3b
diff --git a/servers/slapd/slapcommon.c b/servers/slapd/slapcommon.c
e4ff3b
index 01574af1e..a62c69581 100644
e4ff3b
--- a/servers/slapd/slapcommon.c
e4ff3b
+++ b/servers/slapd/slapcommon.c
e4ff3b
@@ -228,7 +228,8 @@ parse_slapopt( int tool, int *mode )
e4ff3b
 			break;
e4ff3b
 		}
e4ff3b
 
e4ff3b
-	} else if ( strncasecmp( optarg, "ldif-wrap", len ) == 0 ) {
e4ff3b
+	} else if ( ( strncasecmp( optarg, "ldif_wrap", len ) == 0 ) ||
e4ff3b
+			( strncasecmp( optarg, "ldif-wrap", len ) == 0 ) ) {
e4ff3b
 		switch ( tool ) {
e4ff3b
 		case SLAPCAT:
e4ff3b
 			if ( strcasecmp( p, "no" ) == 0 ) {
e4ff3b
@@ -237,7 +238,7 @@ parse_slapopt( int tool, int *mode )
e4ff3b
 			} else {
e4ff3b
 				unsigned int u;
e4ff3b
 				if ( lutil_atou( &u, p ) ) {
e4ff3b
-					Debug( LDAP_DEBUG_ANY, "unable to parse ldif-wrap=\"%s\".\n", p, 0, 0 );
e4ff3b
+					Debug( LDAP_DEBUG_ANY, "unable to parse ldif_wrap=\"%s\".\n", p, 0, 0 );
e4ff3b
 					return -1;
e4ff3b
 				}
e4ff3b
 				ldif_wrap = (ber_len_t)u;
e4ff3b
-- 
e4ff3b
2.29.2
e4ff3b