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