diff --git a/source/pdo_sqlsrv/pdo_dbh.cpp b/source/pdo_sqlsrv/pdo_dbh.cpp index f4c28611..1391cfb7 100644 --- a/source/pdo_sqlsrv/pdo_dbh.cpp +++ b/source/pdo_sqlsrv/pdo_dbh.cpp @@ -201,15 +201,15 @@ const connection_option PDO_CONN_OPTS[] = { CONN_ATTR_STRING, conn_str_append_func::func }, - { - PDOConnOptionNames::Authentication, - sizeof( PDOConnOptionNames::Authentication ), - SQLSRV_CONN_OPTION_AUTHENTICATION, - ODBCConnOptions::Authentication, - sizeof( ODBCConnOptions::Authentication ), - CONN_ATTR_STRING, - conn_str_append_func::func - }, + { + PDOConnOptionNames::Authentication, + sizeof( PDOConnOptionNames::Authentication ), + SQLSRV_CONN_OPTION_AUTHENTICATION, + ODBCConnOptions::Authentication, + sizeof( ODBCConnOptions::Authentication ), + CONN_ATTR_STRING, + conn_str_append_func::func + }, { PDOConnOptionNames::ConnectionPooling, sizeof( PDOConnOptionNames::ConnectionPooling ), diff --git a/source/pdo_sqlsrv/pdo_parser.cpp b/source/pdo_sqlsrv/pdo_parser.cpp index 9d31c06a..13c111e0 100644 --- a/source/pdo_sqlsrv/pdo_parser.cpp +++ b/source/pdo_sqlsrv/pdo_parser.cpp @@ -139,7 +139,7 @@ void string_parser::add_key_value_pair( const char* value, int len TSRMLS_DC ) void sql_string_parser::add_key_int_value_pair( unsigned int value TSRMLS_DC ) { zval value_z; ZVAL_LONG( &value_z, value ); - + core::sqlsrv_zend_hash_index_update( *ctx, this->element_ht, this->current_key, &value_z TSRMLS_CC ); } @@ -171,26 +171,26 @@ void conn_string_parser::validate_key(const char *key, int key_len TSRMLS_DC ) void conn_string_parser::add_key_value_pair( const char* value, int len TSRMLS_DC ) { - // first need to check if the option for Authention is supported - bool valid = true; - if ( stricmp( this->current_key_name, ODBCConnOptions::Authentication ) == 0 ) { - if (len <= 0) - valid = false; - else { - // extract option from the value by len - sqlsrv_malloc_auto_ptr option; - option = static_cast( sqlsrv_malloc( len + 1 ) ); - memcpy_s( option, len + 1, value, len ); - option[len] = '\0'; + // first need to check if the option for Authention is supported + bool valid = true; + if ( stricmp( this->current_key_name, ODBCConnOptions::Authentication ) == 0 ) { + if (len <= 0) + valid = false; + else { + // extract option from the value by len + sqlsrv_malloc_auto_ptr option; + option = static_cast( sqlsrv_malloc( len + 1 ) ); + memcpy_s( option, len + 1, value, len ); + option[len] = '\0'; - valid = core_is_authentication_option_valid( option, len ); - } - } - if( !valid ) { - THROW_PDO_ERROR( this->ctx, PDO_SQLSRV_ERROR_INVALID_AUTHENTICATION_OPTION, this->current_key_name ); - } - - string_parser::add_key_value_pair( value, len ); + valid = core_is_authentication_option_valid( option, len ); + } + } + if( !valid ) { + THROW_PDO_ERROR( this->ctx, PDO_SQLSRV_ERROR_INVALID_AUTHENTICATION_OPTION, this->current_key_name ); + } + + string_parser::add_key_value_pair( value, len ); } @@ -436,7 +436,7 @@ void sql_string_parser::parse_sql_string( TSRMLS_D ) { start_pos = this->pos; next(); // keep going until the next space or line break - // while (!is_white_space(this->orig_str[pos]) && !this->is_eos()) { + // while (!is_white_space(this->orig_str[pos]) && !this->is_eos()) { while ( is_placeholder_char( this->orig_str[pos] )) { next(); } diff --git a/source/pdo_sqlsrv/pdo_util.cpp b/source/pdo_sqlsrv/pdo_util.cpp index e9d10975..2a89538d 100644 --- a/source/pdo_sqlsrv/pdo_util.cpp +++ b/source/pdo_sqlsrv/pdo_util.cpp @@ -377,10 +377,10 @@ pdo_error PDO_ERRORS[] = { PDO_SQLSRV_ERROR_EMULATE_INOUT_UNSUPPORTED, { IMSSP, (SQLCHAR*) "Statement with emulate prepare on does not support output or input_output parameters.", -72, false } }, - { - PDO_SQLSRV_ERROR_INVALID_AUTHENTICATION_OPTION, - { IMSSP, (SQLCHAR*) "Invalid option for the Authentication keyword. Only SqlPassword or ActiveDirectoryPassword is supported.", -73, false } - }, + { + PDO_SQLSRV_ERROR_INVALID_AUTHENTICATION_OPTION, + { IMSSP, (SQLCHAR*) "Invalid option for the Authentication keyword. Only SqlPassword or ActiveDirectoryPassword is supported.", -73, false } + }, { UINT_MAX, {} } }; @@ -562,15 +562,15 @@ namespace { // Place get_error_message into the anonymous namespace in pdo_util.cpp sqlsrv_error_const* get_error_message(unsigned int sqlsrv_error_code) { - sqlsrv_error_const *error_message = NULL; - int zr = (error_message = reinterpret_cast(zend_hash_index_find_ptr(g_pdo_errors_ht, sqlsrv_error_code))) != NULL ? SUCCESS : FAILURE; - if (zr == FAILURE) { - DIE("get_error_message: zend_hash_index_find returned failure for sqlsrv_error_code = %1!d!", sqlsrv_error_code); - } + sqlsrv_error_const *error_message = NULL; + int zr = (error_message = reinterpret_cast(zend_hash_index_find_ptr(g_pdo_errors_ht, sqlsrv_error_code))) != NULL ? SUCCESS : FAILURE; + if (zr == FAILURE) { + DIE("get_error_message: zend_hash_index_find returned failure for sqlsrv_error_code = %1!d!", sqlsrv_error_code); + } - SQLSRV_ASSERT(error_message != NULL, "get_error_message: error_message was null"); + SQLSRV_ASSERT(error_message != NULL, "get_error_message: error_message was null"); - return error_message; + return error_message; } void pdo_sqlsrv_throw_exception( sqlsrv_error_const* error TSRMLS_DC ) diff --git a/source/pdo_sqlsrv/php_pdo_sqlsrv.h b/source/pdo_sqlsrv/php_pdo_sqlsrv.h index e3889e03..5519f07c 100644 --- a/source/pdo_sqlsrv/php_pdo_sqlsrv.h +++ b/source/pdo_sqlsrv/php_pdo_sqlsrv.h @@ -393,7 +393,7 @@ enum PDO_ERROR_CODES { PDO_SQLSRV_ERROR_INVALID_OUTPUT_PARAM_TYPE, PDO_SQLSRV_ERROR_INVALID_CURSOR_WITH_SCROLL_TYPE, PDO_SQLSRV_ERROR_EMULATE_INOUT_UNSUPPORTED, - PDO_SQLSRV_ERROR_INVALID_AUTHENTICATION_OPTION + PDO_SQLSRV_ERROR_INVALID_AUTHENTICATION_OPTION }; extern pdo_error PDO_ERRORS[]; diff --git a/source/shared/core_conn.cpp b/source/shared/core_conn.cpp index f10af137..a459c16d 100644 --- a/source/shared/core_conn.cpp +++ b/source/shared/core_conn.cpp @@ -92,7 +92,7 @@ void common_conn_str_append_func( const char* odbc_name, const char* val, size_t sqlsrv_conn* core_sqlsrv_connect( sqlsrv_context& henv_cp, sqlsrv_context& henv_ncp, driver_conn_factory conn_factory, const char* server, const char* uid, const char* pwd, HashTable* options_ht, error_callback err, const connection_option valid_conn_opts[], - void* driver, const char* driver_func TSRMLS_DC ) + void* driver, const char* driver_func TSRMLS_DC ) { SQLRETURN r; @@ -112,7 +112,7 @@ sqlsrv_conn* core_sqlsrv_connect( sqlsrv_context& henv_cp, sqlsrv_context& henv_ // Due to the limitations on connection pooling in unixODBC 2.3.1 driver manager, we do not consider // the connection string attributes to set (enable/disable) connection pooling. // Instead, MSPHPSQL connection pooling is set according to the ODBCINST.INI file in [ODBC] section. - + #ifndef _WIN32 char pooling_string[ 128 ] = {0}; 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_ // it in build_connection_string_and_set_conn_attr. if( options_ht && zend_hash_num_elements( options_ht ) > 0 ) { - + zval* option_z = NULL; option_z = zend_hash_index_find(options_ht, SQLSRV_CONN_OPTION_CONN_POOLING); if ( option_z ) { @@ -163,18 +163,18 @@ sqlsrv_conn* core_sqlsrv_connect( sqlsrv_context& henv_cp, sqlsrv_context& henv_ SQLSMALLINT output_conn_size; #ifndef _WIN32 - // unixODBC 2.3.1 requires a non-wide SQLDriverConnect call while pooling enabled. - // connection handle has been allocated using henv_cp, means pooling enabled in a PHP script - if ( henv == &henv_cp ) - { - r = SQLDriverConnect( conn->handle(), NULL, (SQLCHAR*)conn_str.c_str(), SQL_NTS, NULL, 0, &output_conn_size, SQL_DRIVER_NOPROMPT ); - } - else - { - r = SQLDriverConnectW( conn->handle(), NULL, reinterpret_cast( wconn_string.get() ), static_cast( wconn_len ), NULL, 0, &output_conn_size, SQL_DRIVER_NOPROMPT ); + // unixODBC 2.3.1 requires a non-wide SQLDriverConnect call while pooling enabled. + // connection handle has been allocated using henv_cp, means pooling enabled in a PHP script + if ( henv == &henv_cp ) + { + r = SQLDriverConnect( conn->handle(), NULL, (SQLCHAR*)conn_str.c_str(), SQL_NTS, NULL, 0, &output_conn_size, SQL_DRIVER_NOPROMPT ); + } + else + { + r = SQLDriverConnectW( conn->handle(), NULL, reinterpret_cast( wconn_string.get() ), static_cast( wconn_len ), NULL, 0, &output_conn_size, SQL_DRIVER_NOPROMPT ); } #else - r = SQLDriverConnectW( conn->handle(), NULL, reinterpret_cast( wconn_string.get() ), static_cast( wconn_len ), NULL, 0, &output_conn_size, SQL_DRIVER_NOPROMPT ); + r = SQLDriverConnectW( conn->handle(), NULL, reinterpret_cast( wconn_string.get() ), static_cast( wconn_len ), NULL, 0, &output_conn_size, SQL_DRIVER_NOPROMPT ); #endif // !_WIN32 // 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_ // but fails if the connection is using a pool, i.e. r= SQL_SUCCESS. // Thus, in Linux, we don't call determine_server_version() for a connection that uses pool. #ifndef _WIN32 - if ( r == SQL_SUCCESS_WITH_INFO ) { + if ( r == SQL_SUCCESS_WITH_INFO ) { #endif // !_WIN32 determine_server_version( conn TSRMLS_CC ); #ifndef _WIN32 - } + } #endif // !_WIN32 } catch( std::bad_alloc& ) { @@ -554,14 +554,14 @@ bool core_is_conn_opt_value_escaped( const char* value, size_t value_len ) // if the option for the authentication is valid, returns true. This returns false otherwise. bool core_is_authentication_option_valid(const char* value, size_t value_len) { - if (value_len <= 0) - return false; + if (value_len <= 0) + return false; - if( ! stricmp( value, AzureADOptions::AZURE_AUTH_SQL_PASSWORD ) || ! stricmp( value, AzureADOptions::AZURE_AUTH_AD_PASSWORD ) ) { - return true; + if( ! stricmp( value, AzureADOptions::AZURE_AUTH_SQL_PASSWORD ) || ! stricmp( value, AzureADOptions::AZURE_AUTH_AD_PASSWORD ) ) { + return true; } - return false; + return false; } @@ -639,33 +639,33 @@ void build_connection_string_and_set_conn_attr( sqlsrv_conn* conn, const char* s if( zend_hash_index_exists( options, SQLSRV_CONN_OPTION_TRACE_FILE )) { zval* trace_value = NULL; - trace_value = zend_hash_index_find(options, SQLSRV_CONN_OPTION_TRACE_ON); + trace_value = zend_hash_index_find(options, SQLSRV_CONN_OPTION_TRACE_ON); - if (trace_value == NULL || !zend_is_true(trace_value)) { + if (trace_value == NULL || !zend_is_true(trace_value)) { zend_hash_index_del( options, SQLSRV_CONN_OPTION_TRACE_FILE ); } } - zend_string *key = NULL; - zend_ulong index = -1; - zval* data = NULL; + zend_string *key = NULL; + zend_ulong index = -1; + zval* data = NULL; - ZEND_HASH_FOREACH_KEY_VAL( options, index, key, data ) { - int type = HASH_KEY_NON_EXISTENT; - type = key ? HASH_KEY_IS_STRING : HASH_KEY_IS_LONG; + ZEND_HASH_FOREACH_KEY_VAL( options, index, key, data ) { + int type = HASH_KEY_NON_EXISTENT; + type = key ? HASH_KEY_IS_STRING : HASH_KEY_IS_LONG; - // The driver layer should ensure a valid key. - DEBUG_SQLSRV_ASSERT(( type == HASH_KEY_IS_LONG ), "build_connection_string_and_set_conn_attr: invalid connection option key type." ); + // The driver layer should ensure a valid key. + DEBUG_SQLSRV_ASSERT(( type == HASH_KEY_IS_LONG ), "build_connection_string_and_set_conn_attr: invalid connection option key type." ); - conn_opt = get_connection_option( conn, index, valid_conn_opts TSRMLS_CC ); + conn_opt = get_connection_option( conn, index, valid_conn_opts TSRMLS_CC ); - if( index == SQLSRV_CONN_OPTION_MARS ) { - mars_mentioned = true; - } + if( index == SQLSRV_CONN_OPTION_MARS ) { + mars_mentioned = true; + } - conn_opt->func( conn_opt, data, conn, connection_string TSRMLS_CC ); - } ZEND_HASH_FOREACH_END(); + conn_opt->func( conn_opt, data, conn, connection_string TSRMLS_CC ); + } ZEND_HASH_FOREACH_END(); // MARS on if not explicitly turned off if( !mars_mentioned ) { @@ -721,7 +721,7 @@ const char* get_processor_arch( void ) return PROCESSOR_ARCH[2]; } else { DIE( "Unknown processor architecture." ); - } + } return NULL; #else SYSTEM_INFO sys_info; @@ -741,7 +741,7 @@ const char* get_processor_arch( void ) DIE( "Unknown Windows processor architecture." ); return NULL; } - return NULL; + return NULL; #endif // !_WIN32 } @@ -761,7 +761,7 @@ void determine_server_version( sqlsrv_conn* conn TSRMLS_DC ) errno = 0; char version_major_str[ 3 ]; SERVER_VERSION version_major; - memcpy_s( version_major_str, sizeof( version_major_str ), p, 2 ); + memcpy_s( version_major_str, sizeof( version_major_str ), p, 2 ); version_major_str[ 2 ] = '\0'; version_major = static_cast( atoi( version_major_str )); @@ -831,7 +831,7 @@ size_t core_str_zval_is_true( zval* value_z ) } // save adjustments to the value made by stripping whitespace at the end - Z_STRLEN_P( value_z ) = val_len; + Z_STRLEN_P( value_z ) = val_len; const char VALID_TRUE_VALUE_1[] = "true"; const char VALID_TRUE_VALUE_2[] = "1"; diff --git a/source/shared/core_sqlsrv.h b/source/shared/core_sqlsrv.h index fff21653..dd3c3bbc 100644 --- a/source/shared/core_sqlsrv.h +++ b/source/shared/core_sqlsrv.h @@ -181,9 +181,8 @@ const int SQL_SERVER_2008_DEFAULT_DATETIME_PRECISION = 34; const int SQL_SERVER_2008_DEFAULT_DATETIME_SCALE = 7; namespace AzureADOptions { - - const char AZURE_AUTH_SQL_PASSWORD[] = "SqlPassword"; - const char AZURE_AUTH_AD_PASSWORD[] = "ActiveDirectoryPassword"; + const char AZURE_AUTH_SQL_PASSWORD[] = "SqlPassword"; + const char AZURE_AUTH_AD_PASSWORD[] = "ActiveDirectoryPassword"; } // types for conversions on output parameters (though they can be used for input parameters, they are ignored) @@ -1128,7 +1127,7 @@ enum SQLSRV_CONN_OPTIONS { SQLSRV_CONN_OPTION_ATTACHDBFILENAME, SQLSRV_CONN_OPTION_APPLICATION_INTENT, SQLSRV_CONN_OPTION_MULTI_SUBNET_FAILOVER, - SQLSRV_CONN_OPTION_AUTHENTICATION, + SQLSRV_CONN_OPTION_AUTHENTICATION, #ifdef _WIN32 SQLSRV_CONN_OPTION_CONN_RETRY_COUNT, SQLSRV_CONN_OPTION_CONN_RETRY_INTERVAL, diff --git a/source/sqlsrv/php_sqlsrv.h b/source/sqlsrv/php_sqlsrv.h index cec74f3a..e7e46c4d 100644 --- a/source/sqlsrv/php_sqlsrv.h +++ b/source/sqlsrv/php_sqlsrv.h @@ -353,7 +353,7 @@ enum SS_ERROR_CODES { SS_SQLSRV_ERROR_CONNECT_BRACES_NOT_ESCAPED, SS_SQLSRV_ERROR_INVALID_OUTPUT_PARAM_TYPE, SS_SQLSRV_ERROR_PARAM_VAR_NOT_REF, - SS_SQLSRV_ERROR_INVALID_AUTHENTICATION_OPTION + SS_SQLSRV_ERROR_INVALID_AUTHENTICATION_OPTION }; extern ss_error SS_ERRORS[];