1 /* Copyright (c) 2010, 2020, 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, version 2.0,
5   as published by the Free Software Foundation.
6 
7   This program is also distributed with certain software (including
8   but not limited to OpenSSL) that is licensed under separate terms,
9   as designated in a particular file or component or in included license
10   documentation.  The authors of MySQL hereby grant you an additional
11   permission to link the program and your derivative works with the
12   separately licensed software that they have included with MySQL.
13 
14   This program is distributed in the hope that it will be useful,
15   but WITHOUT ANY WARRANTY; without even the implied warranty of
16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   GNU General Public License, version 2.0, for more details.
18 
19   You should have received a copy of the GNU General Public License
20   along with this program; if not, write to the Free Software
21   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
22 
23 /**
24   @file storage/perfschema/pfs_defaults.cc
25   Default setup (implementation).
26 */
27 
28 #include "storage/perfschema/pfs_defaults.h"
29 
30 #include <stddef.h>
31 
32 #include "storage/perfschema/pfs.h"
33 #include "storage/perfschema/pfs_instr.h"
34 #include "storage/perfschema/pfs_instr_class.h"
35 #include "storage/perfschema/pfs_setup_actor.h"
36 #include "storage/perfschema/pfs_setup_object.h"
37 
install_default_setup(PSI_thread_bootstrap * thread_boot)38 void install_default_setup(PSI_thread_bootstrap *thread_boot) {
39   void *service = thread_boot->get_interface(PSI_CURRENT_THREAD_VERSION);
40   if (service == nullptr) {
41     return;
42   }
43 
44 #ifdef HAVE_PSI_THREAD_INTERFACE
45   static PSI_thread_key thread_key;
46   static PSI_thread_info thread_info = {&thread_key, "setup",
47                                         PSI_FLAG_SINGLETON, 0, PSI_DOCUMENT_ME};
48 
49   const char *pfs_category = "performance_schema";
50 
51   PSI_thread_service_t *psi = (PSI_thread_service_t *)service;
52 
53   psi->register_thread(pfs_category, &thread_info, 1);
54   PSI_thread *psi_thread = psi->new_thread(thread_key, nullptr, 0);
55 
56   if (psi_thread != nullptr) {
57     /* LF_HASH needs a thread, for PINS */
58     psi->set_thread(psi_thread);
59 
60     String percent("%", 1, &my_charset_utf8mb4_bin);
61     /* Enable all users on all hosts by default */
62     insert_setup_actor(&percent, &percent, &percent, true, true);
63 
64     String mysql_db("mysql", 5, &my_charset_utf8mb4_bin);
65     String PS_db("performance_schema", 18, &my_charset_utf8mb4_bin);
66     String IS_db("information_schema", 18, &my_charset_utf8mb4_bin);
67 
68     /* Disable sp by default in mysql. */
69     insert_setup_object(OBJECT_TYPE_EVENT, &mysql_db, &percent, false, false);
70     /* Disable sp in performance/information schema. */
71     insert_setup_object(OBJECT_TYPE_EVENT, &PS_db, &percent, false, false);
72     insert_setup_object(OBJECT_TYPE_EVENT, &IS_db, &percent, false, false);
73     /* Enable every other sp. */
74     insert_setup_object(OBJECT_TYPE_EVENT, &percent, &percent, true, true);
75 
76     /* Disable sp by default in mysql. */
77     insert_setup_object(OBJECT_TYPE_FUNCTION, &mysql_db, &percent, false,
78                         false);
79     /* Disable sp in performance/information schema. */
80     insert_setup_object(OBJECT_TYPE_FUNCTION, &PS_db, &percent, false, false);
81     insert_setup_object(OBJECT_TYPE_FUNCTION, &IS_db, &percent, false, false);
82     /* Enable every other sp. */
83     insert_setup_object(OBJECT_TYPE_FUNCTION, &percent, &percent, true, true);
84 
85     /* Disable sp by default in mysql. */
86     insert_setup_object(OBJECT_TYPE_PROCEDURE, &mysql_db, &percent, false,
87                         false);
88     /* Disable sp in performance/information schema. */
89     insert_setup_object(OBJECT_TYPE_PROCEDURE, &PS_db, &percent, false, false);
90     insert_setup_object(OBJECT_TYPE_PROCEDURE, &IS_db, &percent, false, false);
91     /* Enable every other sp. */
92     insert_setup_object(OBJECT_TYPE_PROCEDURE, &percent, &percent, true, true);
93 
94     /* Disable system tables by default */
95     insert_setup_object(OBJECT_TYPE_TABLE, &mysql_db, &percent, false, false);
96     /* Disable performance/information schema tables. */
97     insert_setup_object(OBJECT_TYPE_TABLE, &PS_db, &percent, false, false);
98     insert_setup_object(OBJECT_TYPE_TABLE, &IS_db, &percent, false, false);
99     /* Enable every other tables */
100     insert_setup_object(OBJECT_TYPE_TABLE, &percent, &percent, true, true);
101 
102     /* Disable sp by default in mysql. */
103     insert_setup_object(OBJECT_TYPE_TRIGGER, &mysql_db, &percent, false, false);
104     /* Disable sp in performance/information schema. */
105     insert_setup_object(OBJECT_TYPE_TRIGGER, &PS_db, &percent, false, false);
106     insert_setup_object(OBJECT_TYPE_TRIGGER, &IS_db, &percent, false, false);
107     /* Enable every other sp. */
108     insert_setup_object(OBJECT_TYPE_TRIGGER, &percent, &percent, true, true);
109   }
110 
111   psi->delete_current_thread();
112 #endif /* HAVE_PSI_THREAD_INTERFACE */
113 }
114