andrey                                   Fri, 14 Jan 2011 13:00:42 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=307475

Log:
Change things to allow passing of the password length
to mysqlnd. This is needed as a password might include
a \0 and thus we need to be binary safe.

Changed paths:
    U   php/php-src/trunk/ext/mysqli/mysqli_api.c
    U   php/php-src/trunk/ext/mysqli/mysqli_libmysql.h
    U   php/php-src/trunk/ext/mysqli/mysqli_mysqlnd.h
    U   php/php-src/trunk/ext/mysqli/mysqli_nonapi.c
    U   php/php-src/trunk/ext/mysqlnd/mysqlnd.c
    U   php/php-src/trunk/ext/mysqlnd/mysqlnd.h
    U   php/php-src/trunk/ext/mysqlnd/mysqlnd_auth.c
    U   php/php-src/trunk/ext/mysqlnd/mysqlnd_structs.h

Modified: php/php-src/trunk/ext/mysqli/mysqli_api.c
===================================================================
--- php/php-src/trunk/ext/mysqli/mysqli_api.c	2011-01-14 12:32:27 UTC (rev 307474)
+++ php/php-src/trunk/ext/mysqli/mysqli_api.c	2011-01-14 13:00:42 UTC (rev 307475)
@@ -535,7 +535,11 @@
 	old_charset = mysql->mysql->charset;
 #endif

+#if defined(MYSQLI_USE_MYSQLND)
+	rc = mysqlnd_change_user_ex(mysql->mysql, user, password, dbname, FALSE, (size_t) password_len);
+#else
 	rc = mysql_change_user(mysql->mysql, user, password, dbname);
+#endif
 	MYSQLI_REPORT_MYSQL_ERROR(mysql->mysql);

 	if (rc) {

Modified: php/php-src/trunk/ext/mysqli/mysqli_libmysql.h
===================================================================
--- php/php-src/trunk/ext/mysqli/mysqli_libmysql.h	2011-01-14 12:32:27 UTC (rev 307474)
+++ php/php-src/trunk/ext/mysqli/mysqli_libmysql.h	2011-01-14 13:00:42 UTC (rev 307475)
@@ -38,7 +38,7 @@
 #define mysqli_close(c, is_forced)			mysql_close((c))
 #define mysqli_stmt_close(c, implicit)		mysql_stmt_close((c))
 #define mysqli_free_result(r, is_forced)	mysql_free_result((r))
-#define mysqli_change_user_silent(c, u, p, d)   mysql_change_user((c), (u), (p), (d))
+#define mysqli_change_user_silent(c, u, p, d, p_len)   mysql_change_user((c), (u), (p), (d))


 /*

Modified: php/php-src/trunk/ext/mysqli/mysqli_mysqlnd.h
===================================================================
--- php/php-src/trunk/ext/mysqli/mysqli_mysqlnd.h	2011-01-14 12:32:27 UTC (rev 307474)
+++ php/php-src/trunk/ext/mysqli/mysqli_mysqlnd.h	2011-01-14 13:00:42 UTC (rev 307475)
@@ -40,7 +40,7 @@
 #define mysqli_stmt_close(c, implicit)	mysqlnd_stmt_close((c), (implicit))
 #define mysqli_free_result(r, implicit)	mysqlnd_free_result((r), (implicit))
 #define mysqli_async_query(c, q, l)		mysqlnd_async_query((c), (q), (l))
-#define mysqli_change_user_silent(c, u, p, d)   mysqlnd_change_user((c), (u), (p), (d), TRUE)
+#define mysqli_change_user_silent(c, u, p, d, p_len)   mysqlnd_change_user_ex((c), (u), (p), (d), TRUE, (size_t)(p_len))

 #define HAVE_STMT_NEXT_RESULT


Modified: php/php-src/trunk/ext/mysqli/mysqli_nonapi.c
===================================================================
--- php/php-src/trunk/ext/mysqli/mysqli_nonapi.c	2011-01-14 12:32:27 UTC (rev 307474)
+++ php/php-src/trunk/ext/mysqli/mysqli_nonapi.c	2011-01-14 13:00:42 UTC (rev 307475)
@@ -172,7 +172,7 @@
 							/* reset variables */

 #ifndef MYSQLI_NO_CHANGE_USER_ON_PCONNECT
-							if (!mysqli_change_user_silent(mysql->mysql, username, passwd, dbname)) {
+							if (!mysqli_change_user_silent(mysql->mysql, username, passwd, dbname, passwd_len)) {
 #else
 							if (!mysql_ping(mysql->mysql)) {
 #endif

Modified: php/php-src/trunk/ext/mysqlnd/mysqlnd.c
===================================================================
--- php/php-src/trunk/ext/mysqlnd/mysqlnd.c	2011-01-14 12:32:27 UTC (rev 307474)
+++ php/php-src/trunk/ext/mysqlnd/mysqlnd.c	2011-01-14 13:00:42 UTC (rev 307475)
@@ -497,6 +497,7 @@
 			const char * const passwd,
 			const char * const db,
 			size_t db_len,
+			size_t passwd_len,
 			const MYSQLND_PACKET_GREET * const greet_packet,
 			const MYSQLND_OPTIONS * const options,
 			unsigned long mysql_flags
@@ -530,7 +531,7 @@

 			DBG_INF("plugin found");

-			ret = auth_plugin->methods.auth_handshake(conn, user, passwd, db, db_len, greet_packet, options, mysql_flags,
+			ret = auth_plugin->methods.auth_handshake(conn, user, passwd, db, db_len, passwd_len, greet_packet, options, mysql_flags,
 													  &switch_to_auth_protocol TSRMLS_CC);
 			DBG_INF_FMT("switch_to_auth_protocol=%s", switch_to_auth_protocol? switch_to_auth_protocol:"n/a");
 		} while (ret == FAIL && switch_to_auth_protocol != NULL);
@@ -729,7 +730,9 @@
 	}
 #endif

-	if (FAIL == mysqlnd_connect_run_authentication(conn, user, passwd, db, db_len, greet_packet, &conn->options, mysql_flags TSRMLS_CC)) {
+	if (FAIL == mysqlnd_connect_run_authentication(conn, user, passwd, db, db_len, (size_t) passwd_len,
+												   greet_packet, &conn->options, mysql_flags TSRMLS_CC))
+	{
 		goto err;
 	}

@@ -1912,7 +1915,9 @@
 										  const char *user,
 										  const char *passwd,
 										  const char *db,
-										  zend_bool silent TSRMLS_DC)
+										  zend_bool silent,
+										  size_t passwd_len
+										  TSRMLS_DC)
 {
 	/*
 	  User could be max 16 * 3 (utf8), pass is 20 usually, db is up to 64*3
@@ -1962,7 +1967,7 @@
 				break;
 			}
 			DBG_INF("plugin found");
-			ret = auth_plugin->methods.auth_change_user(conn, user, strlen(user), passwd, db, strlen(db), silent, &switch_to_auth_protocol TSRMLS_CC);
+			ret = auth_plugin->methods.auth_change_user(conn, user, strlen(user), passwd, db, strlen(db), passwd_len, silent, &switch_to_auth_protocol TSRMLS_CC);
 			DBG_INF_FMT("switch_to_auth_protocol=%s", switch_to_auth_protocol? switch_to_auth_protocol:"n/a");
 		} while (ret == FAIL && switch_to_auth_protocol != NULL);
 		if (ret == PASS) {

Modified: php/php-src/trunk/ext/mysqlnd/mysqlnd.h
===================================================================
--- php/php-src/trunk/ext/mysqlnd/mysqlnd.h	2011-01-14 12:32:27 UTC (rev 307474)
+++ php/php-src/trunk/ext/mysqlnd/mysqlnd.h	2011-01-14 13:00:42 UTC (rev 307475)
@@ -115,7 +115,8 @@
 						  unsigned int mysql_flags
 						  TSRMLS_DC);

-#define mysqlnd_change_user(conn, user, passwd, db, silent)		(conn)->m->change_user((conn), (user), (passwd), (db), (silent) TSRMLS_CC)
+#define mysqlnd_change_user(conn, user, passwd, db, silent)		(conn)->m->change_user((conn), (user), (passwd), (db), (silent), strlen((passwd)) TSRMLS_CC)
+#define mysqlnd_change_user_ex(conn, user, passwd, db, silent, passwd_len)		(conn)->m->change_user((conn), (user), (passwd), (db), (silent), (passwd_len) TSRMLS_CC)

 #define mysqlnd_debug(x)								_mysqlnd_debug((x) TSRMLS_CC)
 PHPAPI void _mysqlnd_debug(const char *mode TSRMLS_DC);

Modified: php/php-src/trunk/ext/mysqlnd/mysqlnd_auth.c
===================================================================
--- php/php-src/trunk/ext/mysqlnd/mysqlnd_auth.c	2011-01-14 12:32:27 UTC (rev 307474)
+++ php/php-src/trunk/ext/mysqlnd/mysqlnd_auth.c	2011-01-14 13:00:42 UTC (rev 307475)
@@ -36,6 +36,7 @@
 							  const char * const passwd,
 							  const char * const db,
 							  const size_t db_len,
+							  const size_t passwd_len,
 							  const MYSQLND_PACKET_GREET * const greet_packet,
 							  const MYSQLND_OPTIONS * const options,
 							  unsigned long mysql_flags,
@@ -132,6 +133,7 @@
 								const char * const passwd,
 								const char * const db,
 								const size_t db_len,
+								const size_t passwd_len,
 								const zend_bool silent,
 								char ** switch_to_auth_protocol
 								TSRMLS_DC)

Modified: php/php-src/trunk/ext/mysqlnd/mysqlnd_structs.h
===================================================================
--- php/php-src/trunk/ext/mysqlnd/mysqlnd_structs.h	2011-01-14 12:32:27 UTC (rev 307474)
+++ php/php-src/trunk/ext/mysqlnd/mysqlnd_structs.h	2011-01-14 13:00:42 UTC (rev 307475)
@@ -300,6 +300,7 @@
 struct st_mysqlnd_packet_stats;
 struct st_mysqlnd_packet_prepare_response;
 struct st_mysqlnd_packet_chg_user_resp;
+struct st_mysqlnd_packet_auth_pam;

 typedef struct st_mysqlnd_packet_greet *		(*func_mysqlnd_protocol__get_greet_packet)(MYSQLND_PROTOCOL * const protocol, zend_bool persistent TSRMLS_DC);
 typedef struct st_mysqlnd_packet_auth *			(*func_mysqlnd_protocol__get_auth_packet)(MYSQLND_PROTOCOL * const protocol, zend_bool persistent TSRMLS_DC);
@@ -357,7 +358,7 @@
 typedef enum_func_status	(*func_mysqlnd_conn__kill_connection)(MYSQLND *conn, unsigned int pid TSRMLS_DC);
 typedef enum_func_status	(*func_mysqlnd_conn__select_db)(MYSQLND * const conn, const char * const db, unsigned int db_len TSRMLS_DC);
 typedef enum_func_status	(*func_mysqlnd_conn__server_dump_debug_information)(MYSQLND * const conn TSRMLS_DC);
-typedef enum_func_status	(*func_mysqlnd_conn__change_user)(MYSQLND * const conn, const char * user, const char * passwd, const char * db, zend_bool silent TSRMLS_DC);
+typedef enum_func_status	(*func_mysqlnd_conn__change_user)(MYSQLND * const conn, const char * user, const char * passwd, const char * db, zend_bool silent, size_t passwd_len TSRMLS_DC);

 typedef unsigned int		(*func_mysqlnd_conn__get_error_no)(const MYSQLND * const conn TSRMLS_DC);
 typedef const char *		(*func_mysqlnd_conn__get_error_str)(const MYSQLND * const conn TSRMLS_DC);
@@ -970,12 +971,12 @@
 	struct st_mysqlnd_plugin_header plugin_header;
 	struct {
 		enum_func_status (*auth_handshake)(MYSQLND * conn, const char * const user, const char * const passwd, const char * const db,
-										   const size_t db_len, const struct st_mysqlnd_packet_greet * const greet_packet,
+										   const size_t db_len, const size_t passwd_len, const struct st_mysqlnd_packet_greet * const greet_packet,
 										   const MYSQLND_OPTIONS * const options, unsigned long mysql_flags,
 										   char ** switch_to_auth_protocol TSRMLS_DC);

 		enum_func_status (*auth_change_user)(MYSQLND * const conn, const char * const user, const size_t user_len, const char * const passwd,
-											 const char * const db, const size_t db_len, const zend_bool silent,
+											 const char * const db, const size_t db_len, const size_t passwd_len, const zend_bool silent,
 											 char ** switch_to_auth_protocol TSRMLS_DC);
 	} methods;
 };
-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to