MySQL 8.4.0
Source Code Documentation
keyring_keys_metadata_iterator_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_KEYS_METADATA_SERVICE_IMPL_TEMPLATE_INCLUDED
25#define KEYRING_KEYS_METADATA_SERVICE_IMPL_TEMPLATE_INCLUDED
26
27#include <cstring>
28#include <functional> /* std::function */
29#include <memory>
30
31#include <my_dbug.h>
32#include <mysql/components/services/log_builtins.h> /* LogComponentErr */
33#include <mysqld_error.h>
34
40
45
46namespace keyring_common {
47namespace service_implementation {
48
49/**
50 Forward iterator initialization
51
52 @param [out] it metadata iterator
53 @param [in] keyring_operations Reference to the object
54 that handles cache and backend
55 @param [in] callbacks Handle to component specific callbacks
56
57 @returns Status of the operation
58 @retval false Success
59 @retval true Failure
60*/
61template <typename Backend, typename Data_extension = Data>
65 Component_callbacks &callbacks) {
66 try {
67 if (callbacks.keyring_initialized() == false) {
68 LogComponentErr(INFORMATION_LEVEL,
69 ER_NOTE_KEYRING_COMPONENT_NOT_INITIALIZED);
70 return true;
71 }
72
73 if (keyring_operations.init_forward_iterator(it, false) == true) {
74 LogComponentErr(
76 ER_NOTE_KEYRING_COMPONENT_KEYS_METADATA_ITERATOR_INIT_FAILED);
77 return true;
78 }
79
80 return false;
81 } catch (...) {
82 LogComponentErr(ERROR_LEVEL, ER_KEYRING_COMPONENT_EXCEPTION, "init",
83 "keyring_keys_metadata_iterator");
84 return true;
85 }
86}
87
88/**
89 Iterator deinitialization
90
91 @param [out] it metadata iterator
92 @param [in] keyring_operations Reference to the object
93 that handles cache and backend
94 @param [in] callbacks Handle to component specific callbacks
95
96 @returns Status of the operation
97 @retval false Success
98 @retval true Failure
99*/
100template <typename Backend, typename Data_extension = Data>
104 Component_callbacks &callbacks) {
105 try {
106 if (callbacks.keyring_initialized() == false) {
107 LogComponentErr(INFORMATION_LEVEL,
108 ER_NOTE_KEYRING_COMPONENT_NOT_INITIALIZED);
109 return true;
110 }
111 keyring_operations.deinit_forward_iterator(it);
112 return false;
113 } catch (...) {
114 LogComponentErr(ERROR_LEVEL, ER_KEYRING_COMPONENT_EXCEPTION, "deinit",
115 "keyring_keys_metadata_iterator");
116 return true;
117 }
118}
119
120/**
121 Check validity of the iterator
122
123 @param [in] it metadata iterator
124 @param [in] keyring_operations Reference to the object
125 that handles cache and backend
126 @param [in] callbacks Handle to component specific callbacks
127
128 @returns Validty of the iterator
129 @retval true Iterator is valid
130 @retval false Iterator is invalid
131*/
132template <typename Backend, typename Data_extension = Data>
136 Component_callbacks &callbacks) {
137 try {
138 if (callbacks.keyring_initialized() == false) {
139 LogComponentErr(INFORMATION_LEVEL,
140 ER_NOTE_KEYRING_COMPONENT_NOT_INITIALIZED);
141 return false;
142 }
143 return keyring_operations.is_valid(it);
144 } catch (...) {
145 LogComponentErr(ERROR_LEVEL, ER_KEYRING_COMPONENT_EXCEPTION, "is_valid",
146 "keyring_keys_metadata_iterator");
147 return false;
148 }
149}
150
151/**
152 Move iterator forward.
153
154 @param [out] it metadata iterator
155 @param [in] keyring_operations Reference to the object
156 that handles cache and backend
157 @param [in] callbacks Component specific callbacks
158
159 @returns Status of the operation
160 @retval false Success - indicates that iterator is pointing to next entry
161 @retval true Failure - indicates that iterator has reached the end
162*/
163template <typename Backend, typename Data_extension = Data>
167 Component_callbacks &callbacks) {
168 try {
169 if (callbacks.keyring_initialized() == false) {
170 LogComponentErr(INFORMATION_LEVEL,
171 ER_NOTE_KEYRING_COMPONENT_NOT_INITIALIZED);
172 return true;
173 }
174 if (keyring_operations.next(it) == true) {
175 return true;
176 }
177 return false;
178 } catch (...) {
179 LogComponentErr(ERROR_LEVEL, ER_KEYRING_COMPONENT_EXCEPTION, "next",
180 "keyring_keys_metadata_iterator");
181 return true;
182 }
183}
184
185/**
186 Fetch length of metadata for current key pointed by iterator
187
188 @param [out] it metadata iterator
189 @param [out] data_id_length Length of data_id buffer
190 @param [out] auth_id_length Length of auth_id buffer
191 @param [in] keyring_operations Reference to the object
192 that handles cache and backend
193 @param [in] callbacks Handle to component specific callbacks
194
195 @returns Status of the operation
196 @retval false Success
197 @retval true Failure
198*/
199template <typename Backend, typename Data_extension = Data>
201 std::unique_ptr<Iterator<Data_extension>> &it, size_t *data_id_length,
202 size_t *auth_id_length,
204 Component_callbacks &callbacks) {
205 try {
206 if (callbacks.keyring_initialized() == false) {
207 LogComponentErr(INFORMATION_LEVEL,
208 ER_NOTE_KEYRING_COMPONENT_NOT_INITIALIZED);
209 return true;
210 }
211
212 Data_extension data;
213 Metadata metadata;
214 if (keyring_operations.get_iterator_data(it, metadata, data) == true) {
215 LogComponentErr(
217 ER_NOTE_KEYRING_COMPONENT_KEYS_METADATA_ITERATOR_FETCH_FAILED);
218 return true;
219 }
220
221 *data_id_length = metadata.key_id().length();
222 *auth_id_length = metadata.owner_id().length();
223 return false;
224 } catch (...) {
225 LogComponentErr(ERROR_LEVEL, ER_KEYRING_COMPONENT_EXCEPTION, "get_length",
226 "keyring_keys_metadata_iterator");
227 return true;
228 }
229}
230/**
231 Fetch metadata for current key pointed by iterator
232
233 @param [out] it metadata iterator
234 @param [out] data_id ID information of current data
235 @param [in] data_id_length Length of data_id buffer
236 @param [out] auth_id Owner of the key
237 @param [in] auth_id_length Length of auth_id buffer
238 @param [in] keyring_operations Reference to the object
239 that handles cache and backend
240 @param [in] callbacks Handle to component specific callbacks
241
242 @returns Status of the operation
243 @retval false Success
244 @retval true Failure
245*/
246template <typename Backend, typename Data_extension = Data>
248 std::unique_ptr<Iterator<Data_extension>> &it, char *data_id,
249 size_t data_id_length, char *auth_id, size_t auth_id_length,
251 Component_callbacks &callbacks) {
252 try {
253 if (callbacks.keyring_initialized() == false) {
254 LogComponentErr(INFORMATION_LEVEL,
255 ER_NOTE_KEYRING_COMPONENT_NOT_INITIALIZED);
256 return true;
257 }
258
259 Data_extension data;
260 Metadata metadata;
261 if (keyring_operations.get_iterator_metadata(it, metadata, data) == true) {
262 LogComponentErr(
264 ER_NOTE_KEYRING_COMPONENT_KEYS_METADATA_ITERATOR_FETCH_FAILED);
265 return true;
266 }
267
268 if (metadata.key_id().length() >= data_id_length) {
269 assert(false);
270 return true;
271 }
272
273 if (metadata.owner_id().length() >= auth_id_length) {
274 assert(false);
275 return true;
276 }
277
278 memcpy(data_id, metadata.key_id().c_str(), metadata.key_id().length());
279 data_id[metadata.key_id().length()] = '\0';
280 memcpy(auth_id, metadata.owner_id().c_str(), metadata.owner_id().length());
281 auth_id[metadata.owner_id().length()] = '\0';
282 return false;
283 } catch (...) {
284 LogComponentErr(ERROR_LEVEL, ER_KEYRING_COMPONENT_EXCEPTION, "get",
285 "keyring_keys_metadata_iterator");
286 return true;
287 }
288}
289
290} // namespace service_implementation
291} // namespace keyring_common
292
293#endif // !KEYRING_KEYS_METADATA_SERVICE_IMPL_TEMPLATE_INCLUDED
Sensitive data storage.
Definition: data.h:40
Definition: iterator.h:33
Common metadata.
Definition: meta.h:39
const std::string owner_id() const
Get owner info.
Definition: meta.cc:73
const std::string key_id() const
Get key ID.
Definition: meta.cc:70
Keyring operations A class to perform operations on keyring.
Definition: operations.h:483
bool next(std::unique_ptr< iterator::Iterator< Data_extension > > &it)
Move iterator forward.
Definition: operations.h:721
bool get_iterator_data(std::unique_ptr< iterator::Iterator< Data_extension > > &it, meta::Metadata &metadata, Data_extension &data)
Get data from iterator.
Definition: operations.h:737
bool init_forward_iterator(std::unique_ptr< iterator::Iterator< Data_extension > > &it, bool cached)
Iterator creation.
Definition: operations.h:681
void deinit_forward_iterator(std::unique_ptr< iterator::Iterator< Data_extension > > &it)
Iterator destruction.
Definition: operations.h:694
bool is_valid(std::unique_ptr< iterator::Iterator< Data_extension > > &it)
Check iterator validity.
Definition: operations.h:708
bool get_iterator_metadata(std::unique_ptr< iterator::Iterator< Data_extension > > &it, meta::Metadata &metadata, Data_extension &data)
Get metadata from iterator.
Definition: operations.h:763
bool keyring_initialized()
Keyring component status.
Definition: component_callbacks.cc:29
@ ERROR_LEVEL
Definition: my_loglevel.h:43
@ INFORMATION_LEVEL
Definition: my_loglevel.h:45
bool deinit_keys_metadata_iterator_template(std::unique_ptr< Iterator< Data_extension > > &it, Keyring_operations< Backend, Data_extension > &keyring_operations, Component_callbacks &callbacks)
Iterator deinitialization.
Definition: keyring_keys_metadata_iterator_service_impl_template.h:101
bool keys_metadata_get_template(std::unique_ptr< Iterator< Data_extension > > &it, char *data_id, size_t data_id_length, char *auth_id, size_t auth_id_length, Keyring_operations< Backend, Data_extension > &keyring_operations, Component_callbacks &callbacks)
Fetch metadata for current key pointed by iterator.
Definition: keyring_keys_metadata_iterator_service_impl_template.h:247
bool keys_metadata_iterator_is_valid(std::unique_ptr< Iterator< Data_extension > > &it, Keyring_operations< Backend, Data_extension > &keyring_operations, Component_callbacks &callbacks)
Check validity of the iterator.
Definition: keyring_keys_metadata_iterator_service_impl_template.h:133
bool init_keys_metadata_iterator_template(std::unique_ptr< Iterator< Data_extension > > &it, Keyring_operations< Backend, Data_extension > &keyring_operations, Component_callbacks &callbacks)
Forward iterator initialization.
Definition: keyring_keys_metadata_iterator_service_impl_template.h:62
bool keys_metadata_iterator_next(std::unique_ptr< Iterator< Data_extension > > &it, Keyring_operations< Backend, Data_extension > &keyring_operations, Component_callbacks &callbacks)
Move iterator forward.
Definition: keyring_keys_metadata_iterator_service_impl_template.h:164
bool keys_metadata_get_length_template(std::unique_ptr< Iterator< Data_extension > > &it, size_t *data_id_length, size_t *auth_id_length, Keyring_operations< Backend, Data_extension > &keyring_operations, Component_callbacks &callbacks)
Fetch length of metadata for current key pointed by iterator.
Definition: keyring_keys_metadata_iterator_service_impl_template.h:200
Definition: keyring_encryption_service_definition.h:32
std::conditional_t< !std::is_array< T >::value, std::unique_ptr< T, detail::Deleter< T > >, std::conditional_t< detail::is_unbounded_array_v< T >, std::unique_ptr< T, detail::Array_deleter< std::remove_extent_t< T > > >, void > > unique_ptr
The following is a common type that is returned by all the ut::make_unique (non-aligned) specializati...
Definition: ut0new.h:2438