MySQL 8.0.39
Source Code Documentation
keyring_metadata_query_service_impl_template.h
Go to the documentation of this file.
1/* Copyright (c) 2021, 2024, Oracle and/or its affiliates.
2
3This program is free software; you can redistribute it and/or modify
4it under the terms of the GNU General Public License, version 2.0,
5as published by the Free Software Foundation.
6
7This program is designed to work with certain software (including
8but not limited to OpenSSL) that is licensed under separate terms,
9as designated in a particular file or component or in included license
10documentation. The authors of MySQL hereby grant you an additional
11permission to link the program and your derivative works with the
12separately licensed software that they have either included with
13the program or referenced in the documentation.
14
15This program is distributed in the hope that it will be useful,
16but WITHOUT ANY WARRANTY; without even the implied warranty of
17MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18GNU General Public License, version 2.0, for more details.
19
20You should have received a copy of the GNU General Public License
21along with this program; if not, write to the Free Software
22Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef KEYRING_METADATA_QUERY_SERVICE_IMPL_TEMPLATE_INCLUDED
25#define KEYRING_METADATA_QUERY_SERVICE_IMPL_TEMPLATE_INCLUDED
26
27#include <cstring>
28#include <functional>
29#include <memory>
30
31#include <my_dbug.h>
32#include <mysql/components/services/log_builtins.h> /* LogComponentErr */
33#include <mysqld_error.h>
34
36
37namespace keyring_common {
38namespace service_implementation {
39
40/**
41 Returns status of the keyring component
42
43 @param [in] callbacks Component specific callbacks
44
45 @returns Status of keyring
46 @retval true Initialized
47 @retval false Not initialized
48*/
51 return callbacks.keyring_initialized();
52}
53
54/**
55 Initialize metadata iterator
56
57 @param [out] it Metadata iterator handle
58 @param [in] callbacks Component callback handle
59
60 @returns Status of iterator initialization
61 @retval false Success
62 @retval true Failure. Check error state.
63*/
64bool keyring_metadata_query_init_template(std::unique_ptr<config_vector> &it,
66 try {
67 return callbacks.create_config(it);
68 } catch (...) {
69 LogComponentErr(ERROR_LEVEL, ER_KEYRING_COMPONENT_EXCEPTION, "init",
70 "keyring_component_metadata_query");
71 return true;
72 }
73}
74
75/**
76 Deinitialize metadata iterator
77
78 @param [in, out] it Metadata iterator handle
79
80 @returns Status of iterator deinitialization
81 @retval false Success
82 @retval true Failure. Check error state.
83*/
85 std::unique_ptr<config_vector> &it) {
86 try {
87 it.reset(nullptr);
88 return false;
89 } catch (...) {
90 LogComponentErr(ERROR_LEVEL, ER_KEYRING_COMPONENT_EXCEPTION, "deinit",
91 "keyring_component_metadata_query");
92 return true;
93 }
94}
95
96/**
97 Check validity of iterator
98
99 @param [in] it Metadata iterator handle
100
101 @returns Validity of the the iterator
102 @retval true Iterator valid
103 @retval false Iterator invalid
104*/
106 std::unique_ptr<config_vector> &it) {
107 try {
108 return ((it.get() != nullptr) && (it.get()->size() > 0));
109 } catch (...) {
110 LogComponentErr(ERROR_LEVEL, ER_KEYRING_COMPONENT_EXCEPTION, "is_valid",
111 "keyring_component_metadata_query");
112 return false;
113 }
114}
115
116/**
117 Move iterator forward
118
119 @param [in, out] it Metadata iterator handle
120
121 @returns Status of operation
122 @retval false Success
123 @retval true Failure.
124*/
125bool keyring_metadata_query_next_template(std::unique_ptr<config_vector> &it) {
126 try {
127 if (it.get()->size() == 0) {
128 return true;
129 }
130 it.get()->erase(it.get()->begin());
131 return false;
132 } catch (...) {
133 LogComponentErr(ERROR_LEVEL, ER_KEYRING_COMPONENT_EXCEPTION, "next",
134 "keyring_component_metadata_query");
135 return true;
136 }
137}
138
139/**
140 Get length information about metadata key and value
141
142 @param [in] it Metadata iterator handle
143 @param [out] key_buffer_length Length of the key buffer
144 @param [out] value_buffer_length Length of the value buffer
145
146 @returns Get length information about key and value
147 @retval false Success check out parameters
148 @retval true Error
149*/
151 std::unique_ptr<config_vector> &it, size_t *key_buffer_length,
152 size_t *value_buffer_length) {
153 try {
154 if (it->size() == 0) {
155 return true;
156 }
157
158 if (key_buffer_length == nullptr || value_buffer_length == nullptr) {
159 assert(false);
160 return true;
161 }
162
163 auto key_value = (*it)[0];
164
165 // Account for null termination
166 *key_buffer_length = key_value.first.length() + 1;
167 *value_buffer_length = key_value.second.length() + 1;
168
169 return false;
170 } catch (...) {
171 LogComponentErr(ERROR_LEVEL, ER_KEYRING_COMPONENT_EXCEPTION, "get_length",
172 "keyring_component_metadata_query");
173 return true;
174 }
175}
176
177/**
178 Get name and value of metadata at current position
179
180 @param [out] key_buffer Output buffer for key
181 @param [in] key_buffer_length Length of key buffer
182 @param [out] value_buffer Output buffer for value
183 @param [in] value_buffer_length Length of value buffer
184 @param [in] it Metadata iterator handle
185
186 @returns Status of fetch operation
187 @retval false Success
188 @retval true Failure. Check error state.
189*/
191 size_t key_buffer_length,
192 char *value_buffer,
193 size_t value_buffer_length,
194 std::unique_ptr<config_vector> &it) {
195 try {
196 if (it->size() == 0) {
197 return true;
198 }
199
200 auto key_value = (*it)[0];
201
202 if (key_value.first.length() >= key_buffer_length) {
203 assert(false);
204 return true;
205 }
206
207 if (key_value.second.length() >= value_buffer_length) {
208 assert(false);
209 return true;
210 }
211
212 memcpy(key_buffer, key_value.first.c_str(), key_value.first.length());
213 key_buffer[key_value.first.length()] = '\0';
214 memcpy(value_buffer, key_value.second.c_str(), key_value.second.length());
215 value_buffer[key_value.second.length()] = '\0';
216
217 return false;
218 } catch (...) {
219 LogComponentErr(ERROR_LEVEL, ER_KEYRING_COMPONENT_EXCEPTION, "get",
220 "keyring_component_metadata_query");
221 return true;
222 }
223}
224
225} // namespace service_implementation
226} // namespace keyring_common
227#endif // !KEYRING_METADATA_QUERY_SERVICE_IMPL_TEMPLATE_INCLUDED
static const sasl_callback_t callbacks[]
Definition: auth_ldap_sasl_client.h:45
@ ERROR_LEVEL
Definition: my_loglevel.h:43
bool keyring_metadata_query_init_template(std::unique_ptr< config_vector > &it, Component_callbacks &callbacks)
Initialize metadata iterator.
Definition: keyring_metadata_query_service_impl_template.h:64
bool keyring_metadata_query_get_template(char *key_buffer, size_t key_buffer_length, char *value_buffer, size_t value_buffer_length, std::unique_ptr< config_vector > &it)
Get name and value of metadata at current position.
Definition: keyring_metadata_query_service_impl_template.h:190
bool keyring_metadata_query_get_length_template(std::unique_ptr< config_vector > &it, size_t *key_buffer_length, size_t *value_buffer_length)
Get length information about metadata key and value.
Definition: keyring_metadata_query_service_impl_template.h:150
bool keyring_metadata_query_keyring_initialized_template(Component_callbacks &callbacks)
Returns status of the keyring component.
Definition: keyring_metadata_query_service_impl_template.h:49
bool keyring_metadata_query_next_template(std::unique_ptr< config_vector > &it)
Move iterator forward.
Definition: keyring_metadata_query_service_impl_template.h:125
bool keyring_metadata_query_deinit_template(std::unique_ptr< config_vector > &it)
Deinitialize metadata iterator.
Definition: keyring_metadata_query_service_impl_template.h:84
bool keyring_metadata_query_is_valid_template(std::unique_ptr< config_vector > &it)
Check validity of iterator.
Definition: keyring_metadata_query_service_impl_template.h:105
Definition: keyring_encryption_service_definition.h:32