@@ -92,7 +92,7 @@ void common_conn_str_append_func( const char* odbc_name, const char* val, size_t
9292sqlsrv_conn* core_sqlsrv_connect ( sqlsrv_context& henv_cp, sqlsrv_context& henv_ncp, driver_conn_factory conn_factory,
9393 const char * server, const char * uid, const char * pwd,
9494 HashTable* options_ht, error_callback err, const connection_option valid_conn_opts[],
95- void * driver, const char * driver_func TSRMLS_DC )
95+ void * driver, const char * driver_func TSRMLS_DC )
9696
9797{
9898 SQLRETURN r;
@@ -112,7 +112,7 @@ sqlsrv_conn* core_sqlsrv_connect( sqlsrv_context& henv_cp, sqlsrv_context& henv_
112112 // Due to the limitations on connection pooling in unixODBC 2.3.1 driver manager, we do not consider
113113 // the connection string attributes to set (enable/disable) connection pooling.
114114 // Instead, MSPHPSQL connection pooling is set according to the ODBCINST.INI file in [ODBC] section.
115-
115+
116116#ifndef _WIN32
117117 char pooling_string[ 128 ] = {0 };
118118 SQLGetPrivateProfileString ( " ODBC" , " Pooling" , " 0" , pooling_string, sizeof ( pooling_string ), " ODBCINST.INI" );
@@ -128,7 +128,7 @@ sqlsrv_conn* core_sqlsrv_connect( sqlsrv_context& henv_cp, sqlsrv_context& henv_
128128 // it in build_connection_string_and_set_conn_attr.
129129
130130 if ( options_ht && zend_hash_num_elements ( options_ht ) > 0 ) {
131-
131+
132132 zval* option_z = NULL ;
133133 option_z = zend_hash_index_find (options_ht, SQLSRV_CONN_OPTION_CONN_POOLING );
134134 if ( option_z ) {
@@ -163,18 +163,18 @@ sqlsrv_conn* core_sqlsrv_connect( sqlsrv_context& henv_cp, sqlsrv_context& henv_
163163
164164 SQLSMALLINT output_conn_size;
165165#ifndef _WIN32
166- // unixODBC 2.3.1 requires a non-wide SQLDriverConnect call while pooling enabled.
167- // connection handle has been allocated using henv_cp, means pooling enabled in a PHP script
168- if ( henv == &henv_cp )
169- {
170- r = SQLDriverConnect ( conn->handle (), NULL , (SQLCHAR *)conn_str.c_str (), SQL_NTS , NULL , 0 , &output_conn_size, SQL_DRIVER_NOPROMPT );
171- }
172- else
173- {
174- r = SQLDriverConnectW ( conn->handle (), NULL , reinterpret_cast <SQLWCHAR *>( wconn_string.get () ), static_cast <SQLSMALLINT >( wconn_len ), NULL , 0 , &output_conn_size, SQL_DRIVER_NOPROMPT );
166+ // unixODBC 2.3.1 requires a non-wide SQLDriverConnect call while pooling enabled.
167+ // connection handle has been allocated using henv_cp, means pooling enabled in a PHP script
168+ if ( henv == &henv_cp )
169+ {
170+ r = SQLDriverConnect ( conn->handle (), NULL , (SQLCHAR *)conn_str.c_str (), SQL_NTS , NULL , 0 , &output_conn_size, SQL_DRIVER_NOPROMPT );
171+ }
172+ else
173+ {
174+ r = SQLDriverConnectW ( conn->handle (), NULL , reinterpret_cast <SQLWCHAR *>( wconn_string.get () ), static_cast <SQLSMALLINT >( wconn_len ), NULL , 0 , &output_conn_size, SQL_DRIVER_NOPROMPT );
175175 }
176176#else
177- r = SQLDriverConnectW ( conn->handle (), NULL , reinterpret_cast <SQLWCHAR *>( wconn_string.get () ), static_cast <SQLSMALLINT >( wconn_len ), NULL , 0 , &output_conn_size, SQL_DRIVER_NOPROMPT );
177+ r = SQLDriverConnectW ( conn->handle (), NULL , reinterpret_cast <SQLWCHAR *>( wconn_string.get () ), static_cast <SQLSMALLINT >( wconn_len ), NULL , 0 , &output_conn_size, SQL_DRIVER_NOPROMPT );
178178#endif // !_WIN32
179179
180180 // clear the connection string from memory to remove sensitive data (such as a password).
@@ -215,11 +215,11 @@ sqlsrv_conn* core_sqlsrv_connect( sqlsrv_context& henv_cp, sqlsrv_context& henv_
215215 // but fails if the connection is using a pool, i.e. r= SQL_SUCCESS.
216216 // Thus, in Linux, we don't call determine_server_version() for a connection that uses pool.
217217#ifndef _WIN32
218- if ( r == SQL_SUCCESS_WITH_INFO ) {
218+ if ( r == SQL_SUCCESS_WITH_INFO ) {
219219#endif // !_WIN32
220220 determine_server_version ( conn TSRMLS_CC );
221221#ifndef _WIN32
222- }
222+ }
223223#endif // !_WIN32
224224 }
225225 catch ( std::bad_alloc& ) {
@@ -550,6 +550,20 @@ bool core_is_conn_opt_value_escaped( const char* value, size_t value_len )
550550 return true ;
551551}
552552
553+ // core_is_authentication_option_valid
554+ // if the option for the authentication is valid, returns true. This returns false otherwise.
555+ bool core_is_authentication_option_valid (const char * value, size_t value_len)
556+ {
557+ if (value_len <= 0 )
558+ return false ;
559+
560+ if ( ! stricmp ( value, AzureADOptions::AZURE_AUTH_SQL_PASSWORD ) || ! stricmp ( value, AzureADOptions::AZURE_AUTH_AD_PASSWORD ) ) {
561+ return true ;
562+ }
563+
564+ return false ;
565+ }
566+
553567
554568// *** internal connection functions and classes ***
555569
@@ -625,33 +639,33 @@ void build_connection_string_and_set_conn_attr( sqlsrv_conn* conn, const char* s
625639 if ( zend_hash_index_exists ( options, SQLSRV_CONN_OPTION_TRACE_FILE )) {
626640
627641 zval* trace_value = NULL ;
628- trace_value = zend_hash_index_find (options, SQLSRV_CONN_OPTION_TRACE_ON );
642+ trace_value = zend_hash_index_find (options, SQLSRV_CONN_OPTION_TRACE_ON );
629643
630- if (trace_value == NULL || !zend_is_true (trace_value)) {
644+ if (trace_value == NULL || !zend_is_true (trace_value)) {
631645
632646 zend_hash_index_del ( options, SQLSRV_CONN_OPTION_TRACE_FILE );
633647 }
634648 }
635649
636- zend_string *key = NULL ;
637- zend_ulong index = -1 ;
638- zval* data = NULL ;
650+ zend_string *key = NULL ;
651+ zend_ulong index = -1 ;
652+ zval* data = NULL ;
639653
640- ZEND_HASH_FOREACH_KEY_VAL ( options, index, key, data ) {
641- int type = HASH_KEY_NON_EXISTENT ;
642- type = key ? HASH_KEY_IS_STRING : HASH_KEY_IS_LONG ;
654+ ZEND_HASH_FOREACH_KEY_VAL ( options, index, key, data ) {
655+ int type = HASH_KEY_NON_EXISTENT ;
656+ type = key ? HASH_KEY_IS_STRING : HASH_KEY_IS_LONG ;
643657
644- // The driver layer should ensure a valid key.
645- DEBUG_SQLSRV_ASSERT (( type == HASH_KEY_IS_LONG ), " build_connection_string_and_set_conn_attr: invalid connection option key type." );
658+ // The driver layer should ensure a valid key.
659+ DEBUG_SQLSRV_ASSERT (( type == HASH_KEY_IS_LONG ), " build_connection_string_and_set_conn_attr: invalid connection option key type." );
646660
647- conn_opt = get_connection_option ( conn, index, valid_conn_opts TSRMLS_CC );
661+ conn_opt = get_connection_option ( conn, index, valid_conn_opts TSRMLS_CC );
648662
649- if ( index == SQLSRV_CONN_OPTION_MARS ) {
650- mars_mentioned = true ;
651- }
663+ if ( index == SQLSRV_CONN_OPTION_MARS ) {
664+ mars_mentioned = true ;
665+ }
652666
653- conn_opt->func ( conn_opt, data, conn, connection_string TSRMLS_CC );
654- } ZEND_HASH_FOREACH_END ();
667+ conn_opt->func ( conn_opt, data, conn, connection_string TSRMLS_CC );
668+ } ZEND_HASH_FOREACH_END ();
655669
656670 // MARS on if not explicitly turned off
657671 if ( !mars_mentioned ) {
@@ -707,7 +721,7 @@ const char* get_processor_arch( void )
707721 return PROCESSOR_ARCH [2 ];
708722 } else {
709723 DIE ( " Unknown processor architecture." );
710- }
724+ }
711725 return NULL ;
712726#else
713727 SYSTEM_INFO sys_info;
@@ -727,7 +741,7 @@ const char* get_processor_arch( void )
727741 DIE ( " Unknown Windows processor architecture." );
728742 return NULL ;
729743 }
730- return NULL ;
744+ return NULL ;
731745#endif // !_WIN32
732746}
733747
@@ -747,7 +761,7 @@ void determine_server_version( sqlsrv_conn* conn TSRMLS_DC )
747761 errno = 0 ;
748762 char version_major_str[ 3 ];
749763 SERVER_VERSION version_major;
750- memcpy_s ( version_major_str, sizeof ( version_major_str ), p, 2 );
764+ memcpy_s ( version_major_str, sizeof ( version_major_str ), p, 2 );
751765
752766 version_major_str[ 2 ] = ' \0 ' ;
753767 version_major = static_cast <SERVER_VERSION >( atoi ( version_major_str ));
@@ -817,7 +831,7 @@ size_t core_str_zval_is_true( zval* value_z )
817831 }
818832
819833 // save adjustments to the value made by stripping whitespace at the end
820- Z_STRLEN_P ( value_z ) = val_len;
834+ Z_STRLEN_P ( value_z ) = val_len;
821835
822836 const char VALID_TRUE_VALUE_1 [] = " true" ;
823837 const char VALID_TRUE_VALUE_2 [] = " 1" ;
0 commit comments