1 /* Copyright (c) 2010, 2021, Oracle and/or its affiliates.
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 Foundation,
21   51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
22 
23 #ifndef PFS_SETUP_ACTOR_H
24 #define PFS_SETUP_ACTOR_H
25 
26 /**
27   @file storage/perfschema/pfs_setup_actor.h
28   Performance schema setup actors (declarations).
29 */
30 
31 #include "sql_string.h"
32 #include "pfs_lock.h"
33 #include "lf.h"
34 
35 struct PFS_global_param;
36 class PFS_opaque_container_page;
37 
38 /* WL#988 Roles Not implemented yet */
39 #define ROLENAME_LENGTH 64
40 
41 /**
42   @addtogroup Performance_schema_buffers
43   @{
44 */
45 
46 /** Hash key for @sa PFS_setup_actor. */
47 struct PFS_setup_actor_key
48 {
49   /**
50     Hash search key.
51     This has to be a string for LF_HASH,
52     the format is "<username><0x00><hostname><0x00><rolename><0x00>"
53   */
54   char m_hash_key[USERNAME_LENGTH + 1 + HOSTNAME_LENGTH + 1 + ROLENAME_LENGTH + 1];
55   /** Length of @c m_hash_key. */
56   uint m_key_length;
57 };
58 
59 /** A setup_actor record. */
60 struct PFS_ALIGNED PFS_setup_actor
61 {
62   /** Internal lock. */
63   pfs_lock m_lock;
64   /** Hash key. */
65   PFS_setup_actor_key m_key;
66   /** User name. This points inside the hash key. */
67   const char *m_username;
68   /** Length of @c m_username. */
69   uint m_username_length;
70   /** Host name. This points inside the hash key. */
71   const char *m_hostname;
72   /** Length of @c m_hostname. */
73   uint m_hostname_length;
74   /** Role name. This points inside the hash key. */
75   const char *m_rolename;
76   /** Length of @c m_rolename. */
77   uint m_rolename_length;
78   /** ENABLED flag. */
79   bool m_enabled;
80   /** HISTORY flag. */
81   bool m_history;
82   /** Container page. */
83   PFS_opaque_container_page *m_page;
84 };
85 
86 int init_setup_actor(const PFS_global_param *param);
87 void cleanup_setup_actor(void);
88 int init_setup_actor_hash(const PFS_global_param *param);
89 void cleanup_setup_actor_hash(void);
90 
91 int insert_setup_actor(const String *user, const String *host,
92                        const String *role, bool enabled, bool history);
93 int delete_setup_actor(const String *user, const String *host,
94                        const String *role);
95 int reset_setup_actor(void);
96 long setup_actor_count(void);
97 
98 void lookup_setup_actor(PFS_thread *thread,
99                         const char *user, uint user_length,
100                         const char *host, uint host_length,
101                         bool *enabled, bool *history);
102 
103 /** Update derived flags for all setup_actors. */
104 int update_setup_actors_derived_flags();
105 
106 /* For show status. */
107 
108 extern LF_HASH setup_actor_hash;
109 
110 /** @} */
111 #endif
112 
113