Quellcode durchsuchen

fix the url_parse logic when looking for a missing suffix DN

The logic looking for a missing suffix DN in a parsed URL was incorrect.
In addition, since passthru requires a suffix DN, pass the require_dn
flag.
Rich Megginson vor 15 Jahren
Ursprung
Commit
17d86aef5a
2 geänderte Dateien mit 5 neuen und 2 gelöschten Zeilen
  1. 1 1
      ldap/servers/plugins/passthru/ptconfig.c
  2. 4 1
      ldap/servers/slapd/ldaputil.c

+ 1 - 1
ldap/servers/plugins/passthru/ptconfig.c

@@ -238,7 +238,7 @@ passthru_config( int argc, char **argv )
 	/*
 	 * parse the LDAP URL
 	 */
-	if (( rc = slapi_ldap_url_parse( srvr->ptsrvr_url, &ludp, 0, &secure )) != 0 ) {
+	if (( rc = slapi_ldap_url_parse( srvr->ptsrvr_url, &ludp, 1, &secure )) != 0 ) {
 	    slapi_log_error( SLAPI_LOG_FATAL, PASSTHRU_PLUGIN_SUBSYSTEM,
 		    "unable to parse LDAP URL \"%s\" (%s)\n",
 		    srvr->ptsrvr_url, slapi_urlparse_err2string( rc ));

+ 4 - 1
ldap/servers/slapd/ldaputil.c

@@ -155,13 +155,16 @@ slapi_ldap_url_parse(const char *url, LDAPURLDesc **ludpp, int require_dn, int *
     rc = ldap_url_parse_ext(url, ludpp, require_dn ? LDAP_PVT_URL_PARSE_NONE : LDAP_PVT_URL_PARSE_NOEMPTY_DN);
 #else
     rc = ldap_url_parse(url, ludpp);
-    if (rc || !*ludpp || !require_dn) { /* failed - see if failure was due to missing dn */
+    if ((rc || !*ludpp) && !require_dn) { /* failed - see if failure was due to missing dn */
         size_t len = strlen(url);
         /* assume the url is just scheme://host:port[/] - add the empty string
            as the DN (adding a trailing / first if needed) and try to parse
            again
         */
         char *urlcopy = slapi_ch_smprintf("%s%s%s", url, (url[len-1] == '/' ? "" : "/"), "");
+        if (*ludpp) {
+            ldap_free_urldesc(*ludpp); /* free the old one, if any */
+        }
         rc = ldap_url_parse(urlcopy, ludpp);
         slapi_ch_free_string(&urlcopy);
         if (0 == rc) { /* only problem was the DN - free it */