]> granicus.if.org Git - php/commitdiff
Minor changes in ldap_connect(): fixed crash with OpenLDAP 2 libs when
authorStig Venaas <venaas@php.net>
Tue, 13 Nov 2001 18:05:47 +0000 (18:05 +0000)
committerStig Venaas <venaas@php.net>
Tue, 13 Nov 2001 18:05:47 +0000 (18:05 +0000)
called without args and also use ldap_init() rather than ldap_open();
simplified code a little

ext/ldap/ldap.c

index e03612a118c49f3e0114e134b8f71521da6f642f..2237a760e186a30147f2a41bbe65bf2d9a7a6dce 100644 (file)
@@ -295,8 +295,8 @@ PHP_MINFO_FUNCTION(ldap)
    Connect to an LDAP server */
 PHP_FUNCTION(ldap_connect)
 {
-       char *host;
-       int port;
+       char *host = NULL;
+       int port = 389; /* Default port */
 #ifdef HAVE_ORALDAP
        char *wallet, *walletpasswd;
        int authmode;
@@ -306,8 +306,6 @@ PHP_FUNCTION(ldap_connect)
 
        switch(ZEND_NUM_ARGS()) {
                case 0: 
-                       host = NULL;
-                       port = 0;
                        break;
 
                case 1: {
@@ -319,7 +317,6 @@ PHP_FUNCTION(ldap_connect)
 
                                convert_to_string_ex(yyhost);
                                host = Z_STRVAL_PP(yyhost);
-                               port = 389; /* Default port */
                        }
                        break;
 
@@ -339,7 +336,7 @@ PHP_FUNCTION(ldap_connect)
 #ifdef HAVE_ORALDAP
 
                case 5: {
-                       pval **yyhost, **yyport, **yywallet, **yywalletpasswd, **yyauthmode;
+                               pval **yyhost, **yyport, **yywallet, **yywalletpasswd, **yyauthmode;
 
                                if (zend_get_parameters_ex(5, &yyhost, &yyport, &yywallet, &yywalletpasswd, &yyauthmode) == FAILURE) {
                                        RETURN_FALSE;
@@ -371,7 +368,7 @@ PHP_FUNCTION(ldap_connect)
        }
 
 #ifdef LDAP_API_FEATURE_X_OPENLDAP
-       if (strchr(host, '/')) {
+       if (host != NULL && strchr(host, '/')) {
                int rc;
                
                rc = ldap_initialize(&ldap, host);
@@ -379,11 +376,12 @@ PHP_FUNCTION(ldap_connect)
                        php_error(E_WARNING, "Could not create LDAP session handle (%d): %s\n", rc, ldap_err2string(rc));
                        RETURN_FALSE;
                }
-       } else
-#endif
-       {
-               ldap = ldap_open(host, port);
+       } else {
+               ldap = ldap_init(host, port);
        }
+#else
+       ldap = ldap_open(host, port);
+#endif
        
        if ( ldap == NULL ) {
                RETURN_FALSE;