Skip to content

Commit 2e3fc57

Browse files
committed
MNDR:
- move things out of mysqlnd_priv.h
1 parent e8ace2d commit 2e3fc57

28 files changed

+582
-461
lines changed

ext/mysqlnd/mysqlnd.c

+3-202
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020

2121
#include "php.h"
2222
#include "mysqlnd.h"
23+
#include "mysqlnd_connection.h"
2324
#include "mysqlnd_vio.h"
2425
#include "mysqlnd_protocol_frame_codec.h"
26+
#include "mysqlnd_auth.h"
2527
#include "mysqlnd_wireprotocol.h"
2628
#include "mysqlnd_priv.h"
2729
#include "mysqlnd_result.h"
@@ -34,11 +36,6 @@
3436

3537
extern MYSQLND_CHARSET *mysqlnd_charsets;
3638

37-
PHPAPI const char * const mysqlnd_old_passwd = "mysqlnd cannot connect to MySQL 4.1+ using the old insecure authentication. "
38-
"Please use an administration tool to reset your password with the command SET PASSWORD = PASSWORD('your_existing_password'). This will "
39-
"store a new, and more secure, hash value in mysql.user. If this user is used in other scripts executed by PHP 5.2 or earlier you might need to remove the old-passwords "
40-
"flag from your my.cnf file";
41-
4239
PHPAPI const char * const mysqlnd_server_gone = "MySQL server has gone away";
4340
PHPAPI const char * const mysqlnd_out_of_sync = "Commands out of sync; you can't run this command now";
4441
PHPAPI const char * const mysqlnd_out_of_memory = "Out of memory";
@@ -417,36 +414,6 @@ MYSQLND_METHOD(mysqlnd_conn_data, end_psession)(MYSQLND_CONN_DATA * conn)
417414
/* }}} */
418415

419416

420-
/* {{{ mysqlnd_switch_to_ssl_if_needed */
421-
static enum_func_status
422-
mysqlnd_switch_to_ssl_if_needed(
423-
MYSQLND_CONN_DATA * conn,
424-
unsigned int charset_no,
425-
size_t server_capabilities,
426-
const MYSQLND_SESSION_OPTIONS * const session_options,
427-
zend_ulong mysql_flags)
428-
{
429-
enum_func_status ret = FAIL;
430-
const MYSQLND_CHARSET * charset;
431-
DBG_ENTER("mysqlnd_switch_to_ssl_if_needed");
432-
433-
if (session_options->charset_name && (charset = mysqlnd_find_charset_name(session_options->charset_name))) {
434-
charset_no = charset->nr;
435-
}
436-
437-
{
438-
size_t client_capabilities = mysql_flags;
439-
struct st_mysqlnd_protocol_command * command = conn->command_factory(COM_ENABLE_SSL, conn, client_capabilities, server_capabilities, charset_no);
440-
if (command) {
441-
ret = command->run(command);
442-
command->free_command(command);
443-
}
444-
}
445-
DBG_RETURN(ret);
446-
}
447-
/* }}} */
448-
449-
450417
/* {{{ mysqlnd_conn_data::fetch_auth_plugin_by_name */
451418
static struct st_mysqlnd_authentication_plugin *
452419
MYSQLND_METHOD(mysqlnd_conn_data, fetch_auth_plugin_by_name)(const char * const requested_protocol)
@@ -465,172 +432,6 @@ MYSQLND_METHOD(mysqlnd_conn_data, fetch_auth_plugin_by_name)(const char * const
465432
/* }}} */
466433

467434

468-
/* {{{ mysqlnd_run_authentication */
469-
static enum_func_status
470-
mysqlnd_run_authentication(
471-
MYSQLND_CONN_DATA * conn,
472-
const char * const user,
473-
const char * const passwd,
474-
const size_t passwd_len,
475-
const char * const db,
476-
const size_t db_len,
477-
const MYSQLND_STRING auth_plugin_data,
478-
const char * const auth_protocol,
479-
unsigned int charset_no,
480-
const MYSQLND_SESSION_OPTIONS * const session_options,
481-
zend_ulong mysql_flags,
482-
zend_bool silent,
483-
zend_bool is_change_user
484-
)
485-
{
486-
enum_func_status ret = FAIL;
487-
zend_bool first_call = TRUE;
488-
489-
char * switch_to_auth_protocol = NULL;
490-
size_t switch_to_auth_protocol_len = 0;
491-
char * requested_protocol = NULL;
492-
zend_uchar * plugin_data;
493-
size_t plugin_data_len;
494-
495-
DBG_ENTER("mysqlnd_run_authentication");
496-
497-
plugin_data_len = auth_plugin_data.l;
498-
plugin_data = mnd_emalloc(plugin_data_len + 1);
499-
if (!plugin_data) {
500-
goto end;
501-
}
502-
memcpy(plugin_data, auth_plugin_data.s, plugin_data_len);
503-
plugin_data[plugin_data_len] = '\0';
504-
505-
requested_protocol = mnd_pestrdup(auth_protocol? auth_protocol : MYSQLND_DEFAULT_AUTH_PROTOCOL, FALSE);
506-
if (!requested_protocol) {
507-
goto end;
508-
}
509-
510-
do {
511-
struct st_mysqlnd_authentication_plugin * auth_plugin = conn->m->fetch_auth_plugin_by_name(requested_protocol);
512-
513-
if (!auth_plugin) {
514-
php_error_docref(NULL, E_WARNING, "The server requested authentication method unknown to the client [%s]", requested_protocol);
515-
SET_CLIENT_ERROR(conn->error_info, CR_NOT_IMPLEMENTED, UNKNOWN_SQLSTATE, "The server requested authentication method unknown to the client");
516-
goto end;
517-
}
518-
DBG_INF("plugin found");
519-
520-
{
521-
zend_uchar * switch_to_auth_protocol_data = NULL;
522-
size_t switch_to_auth_protocol_data_len = 0;
523-
zend_uchar * scrambled_data = NULL;
524-
size_t scrambled_data_len = 0;
525-
526-
switch_to_auth_protocol = NULL;
527-
switch_to_auth_protocol_len = 0;
528-
529-
if (conn->authentication_plugin_data.s) {
530-
mnd_pefree(conn->authentication_plugin_data.s, conn->persistent);
531-
conn->authentication_plugin_data.s = NULL;
532-
}
533-
conn->authentication_plugin_data.l = plugin_data_len;
534-
conn->authentication_plugin_data.s = mnd_pemalloc(conn->authentication_plugin_data.l, conn->persistent);
535-
if (!conn->authentication_plugin_data.s) {
536-
SET_OOM_ERROR(conn->error_info);
537-
goto end;
538-
}
539-
memcpy(conn->authentication_plugin_data.s, plugin_data, plugin_data_len);
540-
541-
DBG_INF_FMT("salt(%d)=[%.*s]", plugin_data_len, plugin_data_len, plugin_data);
542-
/* The data should be allocated with malloc() */
543-
scrambled_data =
544-
auth_plugin->methods.get_auth_data(NULL, &scrambled_data_len, conn, user, passwd, passwd_len,
545-
plugin_data, plugin_data_len, session_options,
546-
conn->protocol_frame_codec->data, mysql_flags);
547-
if (conn->error_info->error_no) {
548-
goto end;
549-
}
550-
if (FALSE == is_change_user) {
551-
ret = mysqlnd_auth_handshake(conn, user, passwd, passwd_len, db, db_len, session_options, mysql_flags,
552-
charset_no,
553-
first_call,
554-
requested_protocol,
555-
scrambled_data, scrambled_data_len,
556-
&switch_to_auth_protocol, &switch_to_auth_protocol_len,
557-
&switch_to_auth_protocol_data, &switch_to_auth_protocol_data_len
558-
);
559-
} else {
560-
ret = mysqlnd_auth_change_user(conn, user, strlen(user), passwd, passwd_len, db, db_len, silent,
561-
first_call,
562-
requested_protocol,
563-
scrambled_data, scrambled_data_len,
564-
&switch_to_auth_protocol, &switch_to_auth_protocol_len,
565-
&switch_to_auth_protocol_data, &switch_to_auth_protocol_data_len
566-
);
567-
}
568-
first_call = FALSE;
569-
free(scrambled_data);
570-
571-
DBG_INF_FMT("switch_to_auth_protocol=%s", switch_to_auth_protocol? switch_to_auth_protocol:"n/a");
572-
if (requested_protocol && switch_to_auth_protocol) {
573-
mnd_efree(requested_protocol);
574-
requested_protocol = switch_to_auth_protocol;
575-
}
576-
577-
if (plugin_data) {
578-
mnd_efree(plugin_data);
579-
}
580-
plugin_data_len = switch_to_auth_protocol_data_len;
581-
plugin_data = switch_to_auth_protocol_data;
582-
}
583-
DBG_INF_FMT("conn->error_info->error_no = %d", conn->error_info->error_no);
584-
} while (ret == FAIL && conn->error_info->error_no == 0 && switch_to_auth_protocol != NULL);
585-
586-
if (ret == PASS) {
587-
DBG_INF_FMT("saving requested_protocol=%s", requested_protocol);
588-
conn->m->set_client_option(conn, MYSQLND_OPT_AUTH_PROTOCOL, requested_protocol);
589-
}
590-
end:
591-
if (plugin_data) {
592-
mnd_efree(plugin_data);
593-
}
594-
if (requested_protocol) {
595-
mnd_efree(requested_protocol);
596-
}
597-
598-
DBG_RETURN(ret);
599-
}
600-
/* }}} */
601-
602-
603-
/* {{{ mysqlnd_connect_run_authentication */
604-
enum_func_status
605-
mysqlnd_connect_run_authentication(
606-
MYSQLND_CONN_DATA * conn,
607-
const char * const user,
608-
const char * const passwd,
609-
const char * const db,
610-
size_t db_len,
611-
size_t passwd_len,
612-
MYSQLND_STRING authentication_plugin_data,
613-
const char * const authentication_protocol,
614-
const unsigned int charset_no,
615-
size_t server_capabilities,
616-
const MYSQLND_SESSION_OPTIONS * const session_options,
617-
zend_ulong mysql_flags
618-
)
619-
{
620-
enum_func_status ret = FAIL;
621-
DBG_ENTER("mysqlnd_connect_run_authentication");
622-
623-
ret = mysqlnd_switch_to_ssl_if_needed(conn, charset_no, server_capabilities, session_options, mysql_flags);
624-
if (PASS == ret) {
625-
ret = mysqlnd_run_authentication(conn, user, passwd, passwd_len, db, db_len,
626-
authentication_plugin_data, authentication_protocol,
627-
charset_no, session_options, mysql_flags, FALSE /*silent*/, FALSE/*is_change*/);
628-
}
629-
DBG_RETURN(ret);
630-
}
631-
/* }}} */
632-
633-
634435
/* {{{ mysqlnd_conn_data::execute_init_commands */
635436
static enum_func_status
636437
MYSQLND_METHOD(mysqlnd_conn_data, execute_init_commands)(MYSQLND_CONN_DATA * conn)
@@ -685,7 +486,7 @@ MYSQLND_METHOD(mysqlnd_conn_data, get_updated_connect_flags)(MYSQLND_CONN_DATA *
685486
mysql_flags &= ~CLIENT_COMPRESS;
686487
}
687488
#else
688-
if (pfc && pfc->data->flags & MYSQLND_NET_FLAG_USE_COMPRESSION) {
489+
if (pfc && pfc->data->flags & MYSQLND_PROTOCOL_FLAG_USE_COMPRESSION) {
689490
mysql_flags |= CLIENT_COMPRESS;
690491
}
691492
#endif

ext/mysqlnd/mysqlnd.h

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
#include "mysqlnd_enum_n_def.h"
6262
#include "mysqlnd_structs.h"
6363

64+
#define MYSQLND_STR_W_LEN(str) str, (sizeof(str) - 1)
6465

6566
/* Library related */
6667
PHPAPI void mysqlnd_library_init(void);

ext/mysqlnd/mysqlnd_alloc.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
| obtain it through the world-wide-web, please send a note to |
1313
| [email protected] so we can mail you a copy immediately. |
1414
+----------------------------------------------------------------------+
15-
| Authors: Georg Richter <[email protected]> |
16-
| Andrey Hristov <[email protected]> |
15+
| Authors: Andrey Hristov <[email protected]> |
1716
| Ulf Wendel <[email protected]> |
1817
+----------------------------------------------------------------------+
1918
*/

ext/mysqlnd/mysqlnd_alloc.h

+1-5
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,11 @@
1212
| obtain it through the world-wide-web, please send a note to |
1313
| [email protected] so we can mail you a copy immediately. |
1414
+----------------------------------------------------------------------+
15-
| Authors: Georg Richter <[email protected]> |
16-
| Andrey Hristov <[email protected]> |
15+
| Authors: Andrey Hristov <[email protected]> |
1716
| Ulf Wendel <[email protected]> |
1817
+----------------------------------------------------------------------+
1918
*/
2019

21-
/* $Id: mysqlnd_debug.h 306938 2011-01-01 02:17:06Z felipe $ */
22-
/* $Id: mysqlnd_debug.h 306938 2011-01-01 02:17:06Z felipe $ */
23-
2420
#ifndef MYSQLND_ALLOC_H
2521
#define MYSQLND_ALLOC_H
2622

0 commit comments

Comments
 (0)