From 42a6406bfb42e4d756a2b34e2b86496e14f895ff Mon Sep 17 00:00:00 2001
From: Pierangelo Masarati <ando@openldap.org>
Date: Mon, 5 Jul 2004 12:03:39 +0000
Subject: [PATCH] fix URI parsing error code

---
 clients/tools/common.c      |  4 ++--
 libraries/libldap/options.c | 23 ++++++++++++++++++++++-
 2 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/clients/tools/common.c b/clients/tools/common.c
index 0f0c6ab940..5617d49c1e 100644
--- a/clients/tools/common.c
+++ b/clients/tools/common.c
@@ -709,8 +709,8 @@ tool_conn_setup( int not, void (*private_setup)( LDAP * ) )
 		rc = ldap_initialize( &ld, ldapuri );
 		if( rc != LDAP_SUCCESS ) {
 			fprintf( stderr,
-				"Could not create LDAP session handle (%d): %s\n",
-				rc, ldap_err2string(rc) );
+				"Could not create LDAP session handle for URI=%s %d): %s\n",
+				ldapuri, rc, ldap_err2string(rc) );
 			exit( EXIT_FAILURE );
 		}
 
diff --git a/libraries/libldap/options.c b/libraries/libldap/options.c
index c8b2ac286a..f191cb8161 100644
--- a/libraries/libldap/options.c
+++ b/libraries/libldap/options.c
@@ -529,7 +529,6 @@ ldap_set_option(
 
 			if(urls != NULL) {
 				rc = ldap_url_parselist(&ludlist, urls);
-
 			} else if(ld == NULL) {
 				/*
 				 * must want global default returned
@@ -548,6 +547,28 @@ ldap_set_option(
 					rc = LDAP_NO_MEMORY;
 			}
 
+			switch (rc) {
+			case LDAP_URL_SUCCESS:		/* Success */
+				rc = LDAP_SUCCESS;
+				break;
+
+			case LDAP_URL_ERR_MEM:		/* can't allocate memory space */
+				rc = LDAP_NO_MEMORY;
+				break;
+
+			case LDAP_URL_ERR_PARAM:	/* parameter is bad */
+			case LDAP_URL_ERR_BADSCHEME:	/* URL doesn't begin with "ldap[si]://" */
+			case LDAP_URL_ERR_BADENCLOSURE:	/* URL is missing trailing ">" */
+			case LDAP_URL_ERR_BADURL:	/* URL is bad */
+			case LDAP_URL_ERR_BADHOST:	/* host port is bad */
+			case LDAP_URL_ERR_BADATTRS:	/* bad (or missing) attributes */
+			case LDAP_URL_ERR_BADSCOPE:	/* scope string is invalid (or missing) */
+			case LDAP_URL_ERR_BADFILTER:	/* bad or missing filter */
+			case LDAP_URL_ERR_BADEXTS:	/* bad or missing extensions */
+				rc = LDAP_PARAM_ERROR;
+				break;
+			}
+
 			if (rc == LDAP_OPT_SUCCESS) {
 				if (lo->ldo_defludp != NULL)
 					ldap_free_urllist(lo->ldo_defludp);
-- 
GitLab