1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-30 16:24:05 +03:00

Bug#11766631 (59780) - Move the client authentication_windows plugin

into the server repository

This patch adds client windows authentication plugin code to the client 
library libmysql (only on Windows platform). The plugin is compiled into 
the library and added to the list of built-in plugins. This way clients 
should be able to connect to a server which uses windows authentication 
plugin even as an SQL user which uses such authentication.

Note: this makes the client library to depend on Secur32 Windows system
library. When building clients, they must be linked against Secur32. 
Command mysql_config --libs correctly lists Secur32 as a required 
dependency.
This commit is contained in:
Rafal Somla
2011-04-28 21:17:29 +02:00
parent d410bdb9a8
commit 6d7aceeead
10 changed files with 1685 additions and 1 deletions

View File

@ -0,0 +1,168 @@
/* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#ifndef HANDSHAKE_H
#define HANDSHAKE_H
#include "common.h"
/**
Name of the SSP (Security Support Provider) to be used for authentication.
We use "Negotiate" which will find the most secure SSP which can be used
and redirect to that SSP.
*/
#define SSP_NAME "Negotiate"
/**
Maximal number of rounds in authentication handshake.
Server will interrupt authentication handshake with error if client's
identity can not be determined within this many rounds.
*/
#define MAX_HANDSHAKE_ROUNDS 50
/// Convenience wrapper around @c SecBufferDesc.
class Security_buffer: public SecBufferDesc
{
SecBuffer m_buf; ///< A @c SecBuffer instance.
void init(byte *ptr, size_t len)
{
ulVersion= 0;
cBuffers= 1;
pBuffers= &m_buf;
m_buf.BufferType= SECBUFFER_TOKEN;
m_buf.pvBuffer= ptr;
m_buf.cbBuffer= len;
}
/// If @c false, no deallocation will be done in the destructor.
bool m_allocated;
public:
Security_buffer(const Blob&);
Security_buffer();
~Security_buffer()
{
free();
}
byte* ptr() const
{
return (byte*)m_buf.pvBuffer;
}
size_t len() const
{
return m_buf.cbBuffer;
}
bool is_valid() const
{
return ptr() != NULL;
}
const Blob as_blob() const
{
return Blob(ptr(), len());
}
void free(void);
};
/// Common base for Handshake_{server,client}.
class Handshake
{
public:
typedef enum {CLIENT, SERVER} side_t;
Handshake(const char *ssp, side_t side);
virtual ~Handshake();
int Handshake::packet_processing_loop(Connection &con);
bool virtual is_complete() const
{
return m_complete;
}
int error() const
{
return m_error;
}
protected:
/// Security context object created during the handshake.
CtxtHandle m_sctx;
/// Credentials of the principal performing this handshake.
CredHandle m_cred;
/// Stores expiry date of the created security context.
TimeStamp m_expire;
/// Stores attributes of the created security context.
ULONG m_atts;
/// If non-zero, stores error code of the last failed operation.
int m_error;
/// @c true when handshake is complete.
bool m_complete;
/// @c true when the principal credentials has been determined.
bool m_have_credentials;
/// @c true when the security context has been created.
bool m_have_sec_context;
/// Buffer for data to be send to the other side.
Security_buffer m_output;
bool process_result(int);
/**
This method is used inside @c packet_processing_loop to process
data packets received from the other end.
@param[IN] data data to be processed
@return A blob with data to be sent to the other end or null blob if
no more data needs to be exchanged.
*/
virtual Blob process_data(const Blob &data)= 0;
#ifndef DBUG_OFF
private:
SecPkgInfo *m_ssp_info;
public:
const char* ssp_name();
#endif
};
#endif