MySQL 8.0.40
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>
66 try {
67 if (callbacks.keyring_initialized() == false) {
68 return true;
69 }
70
71 if (keyring_operations.init_forward_iterator(it, false) == true) {
72 return true;
73 }
74
75 return false;
76 } catch (...) {
77 LogComponentErr(ERROR_LEVEL, ER_KEYRING_COMPONENT_EXCEPTION, "init",
78 "keyring_keys_metadata_iterator");
79 return true;
80 }
81}
82
83/**
84 Iterator deinitialization
85
86 @param [out] it metadata iterator
87 @param [in] keyring_operations Reference to the object
88 that handles cache and backend
89 @param [in] callbacks Handle to component specific callbacks
90
91 @returns Status of the operation
92 @retval false Success
93 @retval true Failure
94*/
95template <typename Backend, typename Data_extension = Data>
100 try {
101 if (callbacks.keyring_initialized() == false) {
102 return true;
103 }
104 keyring_operations.deinit_forward_iterator(it);
105 return false;
106 } catch (...) {
107 LogComponentErr(ERROR_LEVEL, ER_KEYRING_COMPONENT_EXCEPTION, "deinit",
108 "keyring_keys_metadata_iterator");
109 return true;
110 }
111}
112
113/**
114 Check validity of the iterator
115
116 @param [in] it metadata iterator
117 @param [in] keyring_operations Reference to the object
118 that handles cache and backend
119 @param [in] callbacks Handle to component specific callbacks
120
121 @returns Validty of the iterator
122 @retval true Iterator is valid
123 @retval false Iterator is invalid
124*/
125template <typename Backend, typename Data_extension = Data>
130 try {
131 if (callbacks.keyring_initialized() == false) return false;
132 return keyring_operations.is_valid(it);
133 } catch (...) {
134 LogComponentErr(ERROR_LEVEL, ER_KEYRING_COMPONENT_EXCEPTION, "is_valid",
135 "keyring_keys_metadata_iterator");
136 return false;
137 }
138}
139
140/**
141 Move iterator forward.
142
143 @param [out] it metadata iterator
144 @param [in] keyring_operations Reference to the object
145 that handles cache and backend
146 @param [in] callbacks Component specific callbacks
147
148 @returns Status of the operation
149 @retval false Success - indicates that iterator is pointing to next entry
150 @retval true Failure - indicates that iterator has reached the end
151*/
152template <typename Backend, typename Data_extension = Data>
157 try {
158 if (callbacks.keyring_initialized() == false) {
159 return true;
160 }
161 if (keyring_operations.next(it) == true) {
162 return true;
163 }
164 return false;
165 } catch (...) {
166 LogComponentErr(ERROR_LEVEL, ER_KEYRING_COMPONENT_EXCEPTION, "next",
167 "keyring_keys_metadata_iterator");
168 return true;
169 }
170}
171
172/**
173 Fetch length of metadata for current key pointed by iterator
174
175 @param [out] it metadata iterator
176 @param [out] data_id_length Length of data_id buffer
177 @param [out] auth_id_length Length of auth_id buffer
178 @param [in] keyring_operations Reference to the object
179 that handles cache and backend
180 @param [in] callbacks Handle to component specific callbacks
181
182 @returns Status of the operation
183 @retval false Success
184 @retval true Failure
185*/
186template <typename Backend, typename Data_extension = Data>
188 std::unique_ptr<Iterator<Data_extension>> &it, size_t *data_id_length,
189 size_t *auth_id_length,
192 try {
193 if (callbacks.keyring_initialized() == false) {
194 return true;
195 }
196
197 Data_extension data;
198 Metadata metadata;
199 if (keyring_operations.get_iterator_data(it, metadata, data) == true) {
200 LogComponentErr(
202 ER_NOTE_KEYRING_COMPONENT_KEYS_METADATA_ITERATOR_FETCH_FAILED);
203 return true;
204 }
205
206 *data_id_length = metadata.key_id().length();
207 *auth_id_length = metadata.owner_id().length();
208 return false;
209 } catch (...) {
210 LogComponentErr(ERROR_LEVEL, ER_KEYRING_COMPONENT_EXCEPTION, "get_length",
211 "keyring_keys_metadata_iterator");
212 return true;
213 }
214}
215/**
216 Fetch metadata for current key pointed by iterator
217
218 @param [out] it metadata iterator
219 @param [out] data_id ID information of current data
220 @param [in] data_id_length Length of data_id buffer
221 @param [out] auth_id Owner of the key
222 @param [in] auth_id_length Length of auth_id buffer
223 @param [in] keyring_operations Reference to the object
224 that handles cache and backend
225 @param [in] callbacks Handle to component specific callbacks
226
227 @returns Status of the operation
228 @retval false Success
229 @retval true Failure
230*/
231template <typename Backend, typename Data_extension = Data>
233 std::unique_ptr<Iterator<Data_extension>> &it, char *data_id,
234 size_t data_id_length, char *auth_id, size_t auth_id_length,
237 try {
238 if (callbacks.keyring_initialized() == false) {
239 return true;
240 }
241
242 Data_extension data;
243 Metadata metadata;
244 if (keyring_operations.get_iterator_metadata(it, metadata, data) == true) {
245 LogComponentErr(
247 ER_NOTE_KEYRING_COMPONENT_KEYS_METADATA_ITERATOR_FETCH_FAILED);
248 return true;
249 }
250
251 if (metadata.key_id().length() >= data_id_length) {
252 assert(false);
253 return true;
254 }
255
256 if (metadata.owner_id().length() >= auth_id_length) {
257 assert(false);
258 return true;
259 }
260
261 memcpy(data_id, metadata.key_id().c_str(), metadata.key_id().length());
262 data_id[metadata.key_id().length()] = '\0';
263 memcpy(auth_id, metadata.owner_id().c_str(), metadata.owner_id().length());
264 auth_id[metadata.owner_id().length()] = '\0';
265 return false;
266 } catch (...) {
267 LogComponentErr(ERROR_LEVEL, ER_KEYRING_COMPONENT_EXCEPTION, "get",
268 "keyring_keys_metadata_iterator");
269 return true;
270 }
271}
272
273} // namespace service_implementation
274} // namespace keyring_common
275
276#endif // !KEYRING_KEYS_METADATA_SERVICE_IMPL_TEMPLATE_INCLUDED
static const sasl_callback_t callbacks[]
Definition: auth_ldap_sasl_client.h:45
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
@ 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:96
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:232
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:126
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:153
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:187
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:2439