MySQL 8.3.0
Source Code Documentation
auth_ldap_sasl_client.h
Go to the documentation of this file.
1/* Copyright (c) 2016, 2023, 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
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23#ifndef AUTH_LDAP_SASL_CLIENT_H_
24#define AUTH_LDAP_SASL_CLIENT_H_
25
26#include "my_config.h"
27
28#ifdef HAVE_SASL_SASL_H
29#include <sys/types.h>
30#endif
31
32#include <assert.h>
33#include <mysql/client_plugin.h>
34#include <sasl/sasl.h>
35
37
38#define SASL_MAX_STR_SIZE 1024
39#define SASL_SERVICE_NAME "ldap"
40
41namespace auth_ldap_sasl_client {
42
43/**
44 Class representing SASL client
45*/
47 public:
48 /**
49 Constructor
50
51 @param vio [in] pointer to server communication channel
52 @param mysql [in] pointer to MYSQL structure
53 */
55
56 /**
57 Default constructor -not wanted.
58 */
59 Sasl_client() = delete;
60
61 /**
62 Destructor
63 */
65
66 /**
67 Perform preauthentication step if needed, specific to the SASL mechanism e.g.
68 obtaining Kerberos ticket for GSSAPI.
69
70 @retval true success
71 @retval false failure
72 */
73 bool preauthenticate();
74
75 /**
76 Initializes SASL client exchange.
77
78 @retval true success
79 @retval false failure
80 */
82
83 /**
84 Perform SASL interaction, callled as SASL callback.
85
86 @param ilist [in] list of interaction ids to be served
87 */
88 void interact(sasl_interact_t *ilist);
89
90 /**
91 Decides and sets SASL mechanism to be used for authentication.
92
93 @retval true success
94 @retval false failure
95 */
96 bool set_mechanism();
97
98 /**
99 Starts SASL client exchange.
100
101 @param client_output [out] buffer with the initial client message to be
102 sent to server
103 @param client_output_length [out] length of client_output
104
105 @return SASL result code
106 */
107 int sasl_start(const char **client_output, int *client_output_length);
108
109 /**
110 Perform a step of SASL client exchange.
111
112 @param server_input [in] buffer with message from the server
113 @param server_input_length [in] length of server_input
114 @param client_output [out] buffer with the client message to be
115 sent to server
116 @param client_output_length [out] length of client_output
117
118 @return SASL result code
119 */
120 int sasl_step(char *server_input, int server_input_length,
121 const char **client_output, int *client_output_length);
122
123 /**
124 Sends SASL message to server and receive an response.
125 SASL message is wrapped in a MySQL packet before sending.
126
127 @param request [in] pointer to the SASL request
128 @param request_len [in] length of request
129 @param reponse [out] pointer to received SASL response
130 @param response_len [out] length of reponse or 0 on reading failure
131
132 @retval 1 write failed
133 @retval 0 write succeeded
134 */
135 int send_sasl_request_to_server(const char *request, int request_len,
136 char **reponse, int *response_len);
137
138 /**
139 Check if the authentication method requires conclusion message from the
140 server.
141
142 @retval true conclusion required
143 @retval false conclusion not required
144 */
146 assert(m_sasl_mechanism);
148 }
149
150 private:
151 /**
152 If an empty original user name was given as client parameter and passed to
153 the plugin via MYSQL structure, this function is used to determine the name
154 for authentication and set this user name to the MYSQL structure. For proper
155 memory management (string allocated by the plugin should not be freed by the
156 main client module and vice versa), the original user name from MYSQL is
157 stored to m_mysql_user and on destructing the object the original name is
158 set back to MYSQL and m_mysql_user is freed.
159
160 @retval true success
161 @retval false failure
162 */
163 bool set_user();
164
165 /**
166 Sets (copies) user name and password to the members.
167
168 @param name [in] user name
169 @param pwd [in] user password
170 */
171 void set_user_info(const char *name, const char *pwd);
172
173 /** user name used for authentication */
175
176 /** user password used for authentication */
178
179 /** SASL connection data */
180 sasl_conn_t *m_connection;
181
182 /** pointer to server communication channel */
184
185 /** pointer to MYSQL structure */
187
188 /** the original user name, @see set_user() */
190
191 /** the SASL mechanism used for authentication */
193};
194} // namespace auth_ldap_sasl_client
195#endif // AUTH_LDAP_SASL_CLIENT_H_
#define SASL_MAX_STR_SIZE
Definition: auth_ldap_sasl_client.h:38
Class representing SASL client.
Definition: auth_ldap_sasl_client.h:46
int sasl_step(char *server_input, int server_input_length, const char **client_output, int *client_output_length)
Perform a step of SASL client exchange.
Definition: auth_ldap_sasl_client.cc:255
Sasl_client()=delete
Default constructor -not wanted.
char m_user_pwd[SASL_MAX_STR_SIZE]
user password used for authentication
Definition: auth_ldap_sasl_client.h:177
MYSQL_PLUGIN_VIO * m_vio
pointer to server communication channel
Definition: auth_ldap_sasl_client.h:183
bool require_conclude_by_server()
Check if the authentication method requires conclusion message from the server.
Definition: auth_ldap_sasl_client.h:145
MYSQL * m_mysql
pointer to MYSQL structure
Definition: auth_ldap_sasl_client.h:186
void interact(sasl_interact_t *ilist)
Perform SASL interaction, callled as SASL callback.
Definition: auth_ldap_sasl_client.cc:70
char m_user_name[SASL_MAX_STR_SIZE]
user name used for authentication
Definition: auth_ldap_sasl_client.h:174
void set_user_info(const char *name, const char *pwd)
Sets (copies) user name and password to the members.
Definition: auth_ldap_sasl_client.cc:301
bool set_mechanism()
Decides and sets SASL mechanism to be used for authentication.
Definition: auth_ldap_sasl_client.cc:99
Sasl_mechanism * m_sasl_mechanism
the SASL mechanism used for authentication
Definition: auth_ldap_sasl_client.h:192
int sasl_start(const char **client_output, int *client_output_length)
Starts SASL client exchange.
Definition: auth_ldap_sasl_client.cc:225
sasl_conn_t * m_connection
SASL connection data.
Definition: auth_ldap_sasl_client.h:180
bool initilize_connection()
Initializes SASL client exchange.
Definition: auth_ldap_sasl_client.cc:155
char * m_mysql_user
the original user name,
Definition: auth_ldap_sasl_client.h:189
bool set_user()
If an empty original user name was given as client parameter and passed to the plugin via MYSQL struc...
Definition: auth_ldap_sasl_client.cc:277
bool preauthenticate()
Perform preauthentication step if needed, specific to the SASL mechanism e.g.
Definition: auth_ldap_sasl_client.cc:150
int send_sasl_request_to_server(const char *request, int request_len, char **reponse, int *response_len)
Sends SASL message to server and receive an response.
Definition: auth_ldap_sasl_client.cc:186
~Sasl_client()
Destructor.
Definition: auth_ldap_sasl_client.cc:172
Base class representing SASL mechanism.
Definition: auth_ldap_sasl_mechanism.h:47
virtual bool require_conclude_by_server()
Check if the authentication method requires conclusion message from the server.
Definition: auth_ldap_sasl_mechanism.h:112
MySQL Client Plugin API.
Definition: auth_ldap_kerberos.cc:29
Definition: instrumented_condition_variable.h:31
case opt name
Definition: sslopt-case.h:32
Provides plugin access to communication channel.
Definition: plugin_auth_common.h:145
Definition: mysql.h:297