Skip to content

Commit e1b7b14

Browse files
author
V S Murthy Sidagam
committed
WL#6667 Reimplement the password validation plugin API and plugin
as a component * The validate password plugin is converted to component. * For mysql-8.0 we will have both component and plugin(But plugin will be installed/uninstalled with below deprecate warning) "validate password plugin' is deprecated and will be removed in a future release. Please use validate_password component instead" * In the next major release we remove the plugin .so file. * With the component enabled, we see the system/status variables preceded with "validate_password." instead of "validate_password_"(for example, if we take 'length' system variable we see it as "validate_password.length" instead of "validate_password_length") * The packaging script should be installing the component by default for new installs The way it currently works with deprecations and removals is the following: 1. We add a deprecation warning to using the old way and we switch the server to use the new way by default for new installations. 2. We expect that people will upgrade their existing installations too to avoid the warning. 3. In the next major release we remove the old way and hope that people did #2.
1 parent 2a7f511 commit e1b7b14

File tree

50 files changed

+3928
-53
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+3928
-53
lines changed
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
2+
#
3+
# This program is free software; you can redistribute it and/or modify it under
4+
# the terms of the GNU General Public License as published by the Free Software
5+
# Foundation; version 2 of the License.
6+
#
7+
# This program is distributed in the hope that it will be useful,
8+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
# GNU General Public License for more details.
11+
#
12+
# You should have received a copy of the GNU General Public License
13+
# along with this program; if not, write to the Free Software
14+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15+
16+
INCLUDE(${MYSQL_CMAKE_SCRIPT_DIR}/compile_flags.cmake)
17+
18+
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
19+
20+
SET(LIBRARY_MYSYS_SOURCES
21+
my_memory.cc
22+
)
23+
24+
ADD_CONVENIENCE_LIBRARY(library_mysys ${LIBRARY_MYSYS_SOURCES})

components/library_mysys/my_memory.cc

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
2+
3+
This program is free software; you can redistribute it and/or modify
4+
it under the terms of the GNU General Public License as published by
5+
the Free Software Foundation; version 2 of the License.
6+
7+
This program is distributed in the hope that it will be useful,
8+
but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
GNU General Public License for more details.
11+
12+
You should have received a copy of the GNU General Public License
13+
along with this program; if not, write to the Free Software
14+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
15+
16+
#include <stdlib.h>
17+
#include <assert.h>
18+
#include "mysql/components/library_mysys/my_memory.h"
19+
#include "mysql/components/services/psi_memory.h"
20+
21+
#ifdef HAVE_VALGRIND
22+
#include <valgrind/valgrind.h>
23+
24+
#define MEM_MALLOCLIKE_BLOCK(p1, p2, p3, p4) \
25+
VALGRIND_MALLOCLIKE_BLOCK(p1, p2, p3, p4)
26+
#define MEM_FREELIKE_BLOCK(p1, p2) VALGRIND_FREELIKE_BLOCK(p1, p2)
27+
#else /* HAVE_VALGRIND */
28+
#define MEM_MALLOCLIKE_BLOCK(p1, p2, p3, p4) do {} while (0)
29+
#define MEM_FREELIKE_BLOCK(p1, p2) do {} while (0)
30+
#endif /* HAVE_VALGRIND */
31+
32+
#define MY_ZEROFILL 32 /* fill array with zero */
33+
#define HEADER_SIZE 32
34+
#define MAGIC 1234
35+
#define USER_TO_HEADER(P) \
36+
( (my_memory_header*) (((char *) P) - HEADER_SIZE ))
37+
#define HEADER_TO_USER(P) \
38+
( ((char*) P) + HEADER_SIZE )
39+
40+
struct my_memory_header
41+
{
42+
PSI_memory_key m_key;
43+
unsigned int m_magic;
44+
size_t m_size;
45+
PSI_thread *m_owner;
46+
};
47+
typedef struct my_memory_header my_memory_header;
48+
49+
extern "C" void * my_malloc(PSI_memory_key key, size_t size, int flags)
50+
{
51+
my_memory_header *mh;
52+
size_t raw_size;
53+
static_assert(sizeof(my_memory_header) <= HEADER_SIZE,
54+
"We must reserve enough memory to hold the header.");
55+
56+
raw_size= HEADER_SIZE + size;
57+
if (flags & MY_ZEROFILL)
58+
mh= (my_memory_header *)calloc(raw_size, 1);
59+
else
60+
mh= (my_memory_header *)malloc(raw_size);
61+
62+
if (mh != NULL)
63+
{
64+
void *user_ptr;
65+
mh->m_magic= MAGIC;
66+
mh->m_size= size;
67+
mh->m_key= PSI_MEMORY_CALL(memory_alloc)(key, size, & mh->m_owner);
68+
user_ptr= HEADER_TO_USER(mh);
69+
MEM_MALLOCLIKE_BLOCK(user_ptr, size, 0, (flags & MY_ZEROFILL));
70+
return user_ptr;
71+
}
72+
return NULL;
73+
}
74+
75+
extern "C" void my_free(void *ptr)
76+
{
77+
my_memory_header *mh;
78+
79+
if (ptr == NULL)
80+
return;
81+
82+
mh= USER_TO_HEADER(ptr);
83+
assert(mh->m_magic == MAGIC);
84+
PSI_MEMORY_CALL(memory_free)(mh->m_key, mh->m_size, mh->m_owner);
85+
/* Catch double free */
86+
mh->m_magic= 0xDEAD;
87+
MEM_FREELIKE_BLOCK(ptr, 0);
88+
free(mh);
89+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
2+
3+
This program is free software; you can redistribute it and/or modify
4+
it under the terms of the GNU General Public License as published by
5+
the Free Software Foundation; version 2 of the License.
6+
7+
This program is distributed in the hope that it will be useful,
8+
but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
GNU General Public License for more details.
11+
12+
You should have received a copy of the GNU General Public License
13+
along with this program; if not, write to the Free Software
14+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA */
15+
16+
#ifndef SECURITY_CONTEXT_IMP_H
17+
#define SECURITY_CONTEXT_IMP_H
18+
19+
#include <mysql/components/services/security_context.h>
20+
#include <mysql/components/service_implementation.h>
21+
22+
/**
23+
An implementation of security_context service methods
24+
*/
25+
class mysql_security_context_imp
26+
{
27+
public:
28+
/**
29+
Gets the security context for the thread.
30+
31+
@sa mysql_thd_security_context::get()
32+
*/
33+
static DEFINE_BOOL_METHOD(get,
34+
(void *_thd, Security_context_handle *out_ctx));
35+
36+
/**
37+
Sets a new security context for the thread.
38+
39+
@sa mysql_thd_security_context::set()
40+
*/
41+
static DEFINE_BOOL_METHOD(set,
42+
(void *_thd, Security_context_handle in_ctx));
43+
44+
/**
45+
Creates a new security context and initializes it with the defaults
46+
(no access, no user etc).
47+
48+
@sa mysql_security_context_factory::create()
49+
*/
50+
static DEFINE_BOOL_METHOD(create,
51+
(Security_context_handle *out_ctx));
52+
53+
/**
54+
Deallocates a security context.
55+
56+
@sa mysql_security_context_factory::destroy()
57+
*/
58+
static DEFINE_BOOL_METHOD(destroy,
59+
(Security_context_handle ctx));
60+
61+
/**
62+
Duplicates a security context.
63+
64+
@sa mysql_security_context_factory::copy()
65+
*/
66+
static DEFINE_BOOL_METHOD(copy,
67+
(Security_context_handle in_ctx, Security_context_handle *out_ctx));
68+
69+
/**
70+
Looks up in the defined user accounts.
71+
72+
@sa mysql_account_database_security_context_lookup::lookup()
73+
*/
74+
static DEFINE_BOOL_METHOD(lookup,
75+
(Security_context_handle ctx, const char *user, const char *host,
76+
const char *ip, const char *db));
77+
78+
/**
79+
Reads a named security context attribute and retuns its value.
80+
81+
@sa mysql_security_context_options::get()
82+
*/
83+
static DEFINE_BOOL_METHOD(get,
84+
(Security_context_handle ctx, const char *name, void *inout_pvalue));
85+
86+
/**
87+
Sets a value for a named security context attribute
88+
89+
@sa mysql_security_context_options::set()
90+
*/
91+
static DEFINE_BOOL_METHOD(set,
92+
(Security_context_handle ctx, const char *name, void *pvalue));
93+
};
94+
#endif /* SECURITY_CONTEXT_IMP_H */

components/mysql_server/server_component.cc

+26
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
2525
#include "component_status_var_service.h"
2626
#include "component_sys_var_service.h"
2727
#include "system_variable_source_imp.h"
28+
#include "security_context_imp.h"
2829
#include "dynamic_loader.h"
2930
#include "dynamic_loader_path_filter.h"
3031
#include "dynamic_loader_scheme_file.h"
@@ -291,6 +292,27 @@ BEGIN_SERVICE_IMPLEMENTATION(mysql_server, mysql_backup_lock)
291292
mysql_release_backup_lock
292293
END_SERVICE_IMPLEMENTATION()
293294

295+
BEGIN_SERVICE_IMPLEMENTATION(mysql_server, mysql_thd_security_context)
296+
mysql_security_context_imp::get,
297+
mysql_security_context_imp::set
298+
END_SERVICE_IMPLEMENTATION()
299+
300+
BEGIN_SERVICE_IMPLEMENTATION(mysql_server, mysql_security_context_factory)
301+
mysql_security_context_imp::create,
302+
mysql_security_context_imp::destroy,
303+
mysql_security_context_imp::copy
304+
END_SERVICE_IMPLEMENTATION()
305+
306+
BEGIN_SERVICE_IMPLEMENTATION(mysql_server,
307+
mysql_account_database_security_context_lookup)
308+
mysql_security_context_imp::lookup
309+
END_SERVICE_IMPLEMENTATION()
310+
311+
BEGIN_SERVICE_IMPLEMENTATION(mysql_server, mysql_security_context_options)
312+
mysql_security_context_imp::get,
313+
mysql_security_context_imp::set
314+
END_SERVICE_IMPLEMENTATION()
315+
294316
BEGIN_COMPONENT_PROVIDES(mysql_server)
295317
PROVIDES_SERVICE(mysql_server, registry)
296318
PROVIDES_SERVICE(mysql_server, registry_registration)
@@ -329,6 +351,10 @@ BEGIN_COMPONENT_PROVIDES(mysql_server)
329351
PROVIDES_SERVICE(mysql_server, status_variable_registration)
330352
PROVIDES_SERVICE(mysql_server, system_variable_source)
331353
PROVIDES_SERVICE(mysql_server, mysql_backup_lock)
354+
PROVIDES_SERVICE(mysql_server, mysql_thd_security_context)
355+
PROVIDES_SERVICE(mysql_server, mysql_security_context_factory)
356+
PROVIDES_SERVICE(mysql_server, mysql_account_database_security_context_lookup)
357+
PROVIDES_SERVICE(mysql_server, mysql_security_context_options)
332358
END_COMPONENT_PROVIDES()
333359

334360
static BEGIN_COMPONENT_REQUIRES(mysql_server)

components/mysql_server/server_component.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void mysql_string_services_init();
4949
void mysql_comp_status_var_services_init();
5050
void mysql_comp_sys_var_services_init();
5151
void mysql_comp_system_variable_source_init();
52-
52+
void mysql_security_context_init();
5353
void mysql_backup_lock_service_init();
5454

5555

components/test/test_sys_var_service.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ enum password_policy_enum { PASSWORD_POLICY_LOW,
4949

5050
static const char* policy_names[] = { "LOW", "MEDIUM", "STRONG", NullS };
5151

52-
static TYPELIB password_policy_typelib_t = {
52+
static TYPE_LIB password_policy_typelib_t = {
5353
array_elements(policy_names) - 1,
5454
"password_policy_typelib_t",
5555
policy_names,

components/test/test_sys_var_service_same.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ enum password_policy_enum { PASSWORD_POLICY_LOW,
4949

5050
static const char* policy_names[] = { "LOW", "MEDIUM", "STRONG", NullS };
5151

52-
static TYPELIB password_policy_typelib_t = {
52+
static TYPE_LIB password_policy_typelib_t = {
5353
array_elements(policy_names) - 1,
5454
"password_policy_typelib_t",
5555
policy_names,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
2+
#
3+
# This program is free software; you can redistribute it and/or modify
4+
# it under the terms of the GNU General Public License as published by
5+
# the Free Software Foundation; version 2 of the License.
6+
#
7+
# This program is distributed in the hope that it will be useful,
8+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
# GNU General Public License for more details.
11+
#
12+
# You should have received a copy of the GNU General Public License
13+
# along with this program; if not, write to the Free Software
14+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
15+
16+
MYSQL_ADD_COMPONENT(validate_password
17+
validate_password_imp.cc
18+
MODULE
19+
LINK_LIBRARIES library_mysys)

0 commit comments

Comments
 (0)