Skip to content

Commit

Permalink
ODBC-23 Packaging C/C auth plugins.
Browse files Browse the repository at this point in the history
And settting path to those installed plugins as default plugins location
for the connector.
  • Loading branch information
lawrinn committed Oct 8, 2018
1 parent 10b5dda commit 077f001
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ SET(MARIADB_ODBC_VERSION_QUALITY "alpha")

SET(MARIADB_ODBC_VERSION "03.01.0000")

SET(MARIADB_DEFAULT_PLUGINS_SUBDIR "plugin")
CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/ma_odbc_version.h.in
${CMAKE_SOURCE_DIR}/ma_odbc_version.h)

Expand Down Expand Up @@ -284,6 +285,8 @@ TARGET_LINK_LIBRARIES(${LIBRARY_NAME} ${MARIADB_CLIENT_TARGET_NAME} ${ODBC_INSTL
IF(WIN32)
ADD_CUSTOM_COMMAND(TARGET maodbc POST_BUILD
COMMAND ${CMAKE_COMMAND} ARGS -DDRIVER_LIB_DIR=$<TARGET_FILE_DIR:maodbc>
-DPLUGINS_LIB_DIR=$<TARGET_FILE_DIR:dialog>
-DPLUGINS_SUBDIR_NAME=${MARIADB_DEFAULT_PLUGINS_SUBDIR}
-DFILE_IN=${CMAKE_SOURCE_DIR}/wininstall/binaries_dir.xml.in
-DFILE_OUT=${CMAKE_SOURCE_DIR}/wininstall/binaries_dir.xml
-P ${CMAKE_SOURCE_DIR}/cmake/ConfigureFile.cmake
Expand Down
4 changes: 4 additions & 0 deletions ma_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,10 @@ SQLRETURN MADB_DbcConnectDB(MADB_Dbc *Connection,
{
mysql_options(Connection->mariadb, MYSQL_PLUGIN_DIR, Dsn->ConnCPluginsDir);
}
else
{
MADB_SetDefaultPluginsDir(Connection->mariadb);
}

/* If a client character set was specified in DSN, we will always use it.
Otherwise for ANSI applications we will use the current character set,
Expand Down
5 changes: 2 additions & 3 deletions ma_odbc.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
#ifndef _ma_odbc_h_
#define _ma_odbc_h_

#include <ma_odbc_version.h>

#ifdef _WIN32
# include "ma_platform_win32.h"
#else
# include "ma_platform_posix.h"
#endif

#define ODBCVER 0x0351

#include <stdlib.h>

#include <mysql.h>
Expand All @@ -45,7 +45,6 @@
#include <assert.h>
#include <time.h>

#include <ma_odbc_version.h>

typedef struct st_ma_odbc_connection MADB_Dbc;
typedef struct st_ma_odbc_stmt MADB_Stmt;
Expand Down
6 changes: 6 additions & 0 deletions ma_odbc_version.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,10 @@
#define MARIADB_ODBC_VERSION "@MARIADB_ODBC_VERSION@"

#define MARIADB_ODBC_ERR_PREFIX "[ma-@MARIADB_ODBC_VERSION_MAJOR@.@MARIADB_ODBC_VERSION_MINOR@.@MARIADB_ODBC_VERSION_PATCH@]"

#define MADB_DRIVER_NAME "maodbc.dll"

#define ODBCVER 0x0351

#define MADB_DEFAULT_PLUGINS_SUBDIR "@MARIADB_DEFAULT_PLUGINS_SUBDIR@"
#endif /* _ma_odbc_version_h_ */
28 changes: 28 additions & 0 deletions ma_platform_win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
of the function you are changing, needs to be changed accordingly */

#include <ma_odbc.h>
#include "Shlwapi.h"

extern Client_Charset utf8;
char LogFile[256];
Expand Down Expand Up @@ -282,3 +283,30 @@ int GetSourceAnsiCs(Client_Charset *cc)
/* We don't need cs_info for this */
return cc->CodePage;
}

BOOL MADB_DirectoryExists(const char *Path)
{
DWORD FileAttributes = GetFileAttributes(Path);

return (FileAttributes != INVALID_FILE_ATTRIBUTES) && (FileAttributes & FILE_ATTRIBUTE_DIRECTORY);
}

void MADB_SetDefaultPluginsDir(MYSQL *mariadb)
{
HMODULE hModule = GetModuleHandle(MADB_DRIVER_NAME);
char OurLocation[_MAX_PATH];
const char *PluginsSubDirName= "\\"MADB_DEFAULT_PLUGINS_SUBDIR;

GetModuleFileName(hModule, OurLocation, _MAX_PATH);
PathRemoveFileSpec(OurLocation);

if (strlen(OurLocation) < _MAX_PATH - strlen(PluginsSubDirName))
{
strcpy(OurLocation + strlen(OurLocation), PluginsSubDirName);

if (MADB_DirectoryExists(OurLocation) != FALSE)
{
mysql_options(mariadb, MYSQL_PLUGIN_DIR, OurLocation);
}
}
}
2 changes: 0 additions & 2 deletions ma_platform_win32.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@
#endif
#define strcasecmp(A,B) _stricmp((A),(B))

#define MADB_DRIVER_NAME "maodbc.dll"

char *strndup(const char *s, size_t n);

#endif /*_ma_platform_x_h_ */
4 changes: 4 additions & 0 deletions wininstall/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ IF(CMAKE_SIZEOF_VOID_P EQUAL 8)
SET(GUID_SETUP "BF255F46-18CA-4244-9A17-6B33BDAAFBF4")
SET(GUID_DRIVER "3535FD95-1F44-454E-A6E4-81F865E8C57F")
SET(GUID_DEBUG "4FA6E79A-4630-4CB8-A4E1-00A4740E9280")
SET(GUID_PLUGINS "9D1B41AA-CE86-4c6d-93C8-FDCD40D5D2E9")
SET(GUID_PLUGINS_DEBUG "63541EC9-9C2B-4763-8C18-03313DAE6F8E")
ELSE()
SET(PLATFORM "win32")
SET(IS_WIN64 "no")
Expand All @@ -39,6 +41,8 @@ ELSE()
SET(GUID_SETUP "16E13D0B-7BFE-4BC4-A524-940716EE749F")
SET(GUID_DRIVER "8BD16D93-30E0-4DF0-8B40-9A5A3D967DD6")
SET(GUID_DEBUG "2EA8B4DD-F470-4362-8D87-59090D255981")
SET(GUID_PLUGINS "B6355F5E-FA0B-427a-AC77-BC145887D11B")
SET(GUID_PLUGINS_DEBUG "B2CB2291-249C-4258-83CB-A3E9C4DC9CFE")
ENDIF()

CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/wininstall/mariadb_odbc.xml.in
Expand Down
2 changes: 2 additions & 0 deletions wininstall/binaries_dir.xml.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<Include>
<?define binaries_dir="@DRIVER_LIB_DIR@" ?>
<?define plugins_source_dir="@PLUGINS_LIB_DIR@" ?>
<?define plugins_subdir_name="@PLUGINS_SUBDIR_NAME@" ?>
</Include>
23 changes: 21 additions & 2 deletions wininstall/mariadb_odbc.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,24 @@
<ComponentRef Id="RegistryKeys" />
<ComponentRef Id="Setup" />
<ComponentRef Id="Driver" />
<ComponentRef Id="CcPlugins" />
</Feature>
<Feature Id="DebugFeature" Title="Debug Information" Level="2">
<ComponentRef Id="Debug" />
</Feature>
<Feature Id="PluginsFeature" Title="Authentification Plugins" Level="2">
<ComponentRef Id="CcPlugins" />
<ComponentRef Id="PluginsDebug" />
</Feature>
</Product>

<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="@FOLDER@">
<Directory Id="MariaDB" Name="@PRODUCT_MANUFACTURER@">
<Directory Id="INSTALLFOLDER" Name="@PRODUCT_NAME@" />
<Directory Id="INSTALLFOLDER" Name="@PRODUCT_NAME@">
<Directory Id="PLUGINSFOLDER" Name="@plugins_subdir_name@" />
</Directory>
</Directory>
</Directory>
</Directory>
Expand All @@ -51,10 +58,22 @@
</File>
<File Id="mariadb_odbc_lib" Name="maodbc.lib" DiskId="1" Source="$(var.binaries_dir)/maodbc.lib" />
</Component>
<Component Id="Debug" Guid="2EA8B4DD-F470-4362-8D87-59090D255981" Directory="INSTALLFOLDER" DiskId="1" Win64="@IS_WIN64@">
<Component Id="Debug" Guid="@GUID_DEBUG@" Directory="INSTALLFOLDER" DiskId="1" Win64="@IS_WIN64@">
<File Id="mariadb_odbc_dll_pdb" Name="maodbc.pdb" KeyPath="yes" DiskId="1" Source="$(var.binaries_dir)/maodbc.pdb" />
<File Id="mariadb_odbc_setup_pdb" Name="maodbcs.pdb" DiskId="1" Source="$(var.binaries_dir)/maodbcs.pdb" />
</Component>
<Component Id="CcPlugins" Guid="@GUID_PLUGINS@" Directory="PLUGINSFOLDER" DiskId="1" Win64="@IS_WIN64@">
<File Id="dialog_dll" Name="dialog.dll" KeyPath="yes" DiskId="1" Source="$(var.plugins_source_dir)/dialog.dll" />
<File Id="auth_gssapi_client_dll" Name="auth_gssapi_client.dll" DiskId="1" Source="$(var.plugins_source_dir)/auth_gssapi_client.dll" />
<File Id="mysql_clear_password_dll" Name="mysql_clear_password.dll" DiskId="1" Source="$(var.plugins_source_dir)/mysql_clear_password.dll" />
<File Id="sha256_password_dll" Name="sha256_password.dll" DiskId="1" Source="$(var.plugins_source_dir)/sha256_password.dll" />
</Component>
<Component Id="PluginsDebug" Guid="@GUID_PLUGINS_DEBUG@" Directory="PLUGINSFOLDER" DiskId="1" Win64="@IS_WIN64@">
<File Id="dialog_pdb" Name="dialog.pdb" DiskId="1" Source="$(var.plugins_source_dir)/dialog.pdb" />
<File Id="auth_gssapi_client_pdb" Name="auth_gssapi_client.pdb" DiskId="1" Source="$(var.plugins_source_dir)/auth_gssapi_client.pdb" />
<File Id="mysql_clear_password_pdb" Name="mysql_clear_password.pdb" DiskId="1" Source="$(var.plugins_source_dir)/mysql_clear_password.pdb" />
<File Id="sha256_password_pdb" Name="sha256_password.pdb" DiskId="1" Source="$(var.plugins_source_dir)/sha256_password.pdb" />
</Component>
<!-- </ComponentGroup> -->
</Fragment>
</Wix>

0 comments on commit 077f001

Please sign in to comment.