Index: driver/connect.c =================================================================== --- driver/connect.c (revision 259) +++ driver/connect.c (working copy) @@ -209,7 +209,8 @@ SQLCHAR FAR * szUID, SQLSMALLINT cbUID, SQLCHAR FAR * szAuthStr, - SQLSMALLINT cbAuthStr ) + SQLSMALLINT cbAuthStr + ) { char host[64],user[64],passwd[64],dsn[NAME_LEN+1],database[NAME_LEN+1]; char port[10],flag[10],init_stmt[256],*dsn_ptr; @@ -266,6 +267,7 @@ copy_if_not_empty(passwd,sizeof(passwd), (char FAR*) szAuthStr,cbAuthStr); copy_if_not_empty(user, sizeof(user), (char FAR *) szUID, cbUID); + /* socket[0] is always 0 if you are not under UNIX */ if (!mysql_real_connect(&dbc->mysql, host, @@ -306,6 +308,8 @@ (uint)dbc->login_timeout, pDataSource->pszSTMT ? pDataSource->pszSTMT : "" ); + /* set SSL parameters */ + mysql_ssl_set(&dbc->mysql, pDataSource->sSslSettings.pszSSLKEY, pDataSource->sSslSettings.pszSSLCERT, pDataSource->sSslSettings.pszSSLCA, pDataSource->sSslSettings.pszSSLCAPATH, pDataSource->sSslSettings.pszSSLCIPHER); if ( !mysql_real_connect( &dbc->mysql, pDataSource->pszSERVER, pDataSource->pszUSER, @@ -313,7 +317,7 @@ pDataSource->pszDATABASE, atoi( pDataSource ->pszPORT ), pDataSource->pszSOCKET, - nFlag ) ) + nFlag) ) { set_dbc_error( dbc, "HY000", mysql_error( &dbc->mysql ), mysql_errno( &dbc->mysql ) ); translate_error( dbc->error.sqlstate, MYERR_S1000, mysql_errno( &dbc->mysql ) ); Index: util/MYODBCUtil.h =================================================================== --- util/MYODBCUtil.h (revision 259) +++ util/MYODBCUtil.h (working copy) @@ -155,6 +155,16 @@ } MYODBCUTIL_DATASOURCE_MODE; +typedef struct +{ + char *pszSSLKEY; /* pathname to SSL key file */ + char *pszSSLCERT; /* pathname to SSL certificate file */ + char *pszSSLCA; /* pathname to SSL certificate authority file */ + char *pszSSLCAPATH; /* pathname to a directory that contains SSL ceritificate authority files */ + char *pszSSLCIPHER; /* pathname to a list of allowable ciphers */ + +} MYODBC_SSL; + /*! DSN fields. @@ -175,7 +185,7 @@ char *pszSOCKET; /* Unix socket file or Windows named pipe to connect to. */ char *pszSTMT; /* Statement that will be exec when connecting to MySQL. */ char *pszOPTION; /* Options that specify how MyODBC should work. */ - + MYODBC_SSL sSslSettings; MYODBCUTIL_DATASOURCE_MODE nMode; /* ConfigDSN mode or SQLDriverConnect mode. */ MYODBCUTIL_DATASOURCE_CONNECT nConnect; /* SQLDriverConnect() using a DSN or a DRIVER to connect. */ MYODBCUTIL_DATASOURCE_PROMPT nPrompt; /* SQLDriverConnect() kind of prompting (if any). */ Index: util/MYODBCUtilClearDataSource.c =================================================================== --- util/MYODBCUtilClearDataSource.c (revision 259) +++ util/MYODBCUtilClearDataSource.c (working copy) @@ -83,6 +83,33 @@ _global_free( pDataSource->pszUSER ); pDataSource->pszUSER = NULL; } + + if( pDataSource->sSslSettings.pszSSLCA) + { + _global_free (pDataSource->sSslSettings.pszSSLCA); + pDataSource->sSslSettings.pszSSLCA = NULL; + } + if( pDataSource->sSslSettings.pszSSLCAPATH) + { + _global_free (pDataSource->sSslSettings.pszSSLCAPATH); + pDataSource->sSslSettings.pszSSLCAPATH = NULL; + } + if( pDataSource->sSslSettings.pszSSLCERT) + { + _global_free (pDataSource->sSslSettings.pszSSLCERT); + pDataSource->sSslSettings.pszSSLCERT = NULL; + } + if( pDataSource->sSslSettings.pszSSLCIPHER) + { + _global_free (pDataSource->sSslSettings.pszSSLCIPHER); + pDataSource->sSslSettings.pszSSLCIPHER = NULL; + } + if( pDataSource->sSslSettings.pszSSLKEY) + { + _global_free (pDataSource->sSslSettings.pszSSLKEY); + pDataSource->sSslSettings.pszSSLKEY = NULL; + } + } Index: util/MYODBCUtilDefaultDataSource.c =================================================================== --- util/MYODBCUtilDefaultDataSource.c (revision 259) +++ util/MYODBCUtilDefaultDataSource.c (working copy) @@ -65,6 +65,33 @@ if ( !pDataSource->pszOPTION ) pDataSource->pszOPTION = _global_strdup( "0" ); + + if( pDataSource->sSslSettings.pszSSLCA && !pDataSource->sSslSettings.pszSSLCA[0] ) + { + _global_free (pDataSource->sSslSettings.pszSSLCA); + pDataSource->sSslSettings.pszSSLCA = NULL; + } + if( pDataSource->sSslSettings.pszSSLCAPATH && !pDataSource->sSslSettings.pszSSLCAPATH[0] ) + { + _global_free (pDataSource->sSslSettings.pszSSLCAPATH); + pDataSource->sSslSettings.pszSSLCAPATH = NULL; + } + if( pDataSource->sSslSettings.pszSSLCERT && !pDataSource->sSslSettings.pszSSLCERT[0] ) + { + _global_free (pDataSource->sSslSettings.pszSSLCERT); + pDataSource->sSslSettings.pszSSLCERT = NULL; + } + if( pDataSource->sSslSettings.pszSSLCIPHER && !pDataSource->sSslSettings.pszSSLCIPHER[0] ) + { + _global_free (pDataSource->sSslSettings.pszSSLCIPHER); + pDataSource->sSslSettings.pszSSLCIPHER = NULL; + } + if( pDataSource->sSslSettings.pszSSLKEY && !pDataSource->sSslSettings.pszSSLKEY[0] ) + { + _global_free (pDataSource->sSslSettings.pszSSLKEY); + pDataSource->sSslSettings.pszSSLKEY = NULL; + } + #ifndef _UNIX_ /* Here we actually unset socket for non-UNIX as it does not apply. */ if ( pDataSource->pszSOCKET && !pDataSource->pszSOCKET[0] ) Index: util/MYODBCUtilReadConnectStr.c =================================================================== --- util/MYODBCUtilReadConnectStr.c (revision 259) +++ util/MYODBCUtilReadConnectStr.c (working copy) @@ -172,6 +172,31 @@ if ( !pDataSource->pszUSER ) pDataSource->pszUSER = (char *)_global_strndup( pAnchorChar, pScanChar - pAnchorChar ); } + else if ( strcasecmp( pszName, "SSLCA" ) == 0 ) + { + if ( !pDataSource->sSslSettings.pszSSLCA ) + pDataSource->sSslSettings.pszSSLCA = (char *)_global_strndup( pAnchorChar, pScanChar - pAnchorChar ); + } + else if ( strcasecmp( pszName, "SSLCAPATH" ) == 0 ) + { + if ( !pDataSource->sSslSettings.pszSSLCAPATH ) + pDataSource->sSslSettings.pszSSLCAPATH = (char *)_global_strndup( pAnchorChar, pScanChar - pAnchorChar ); + } + else if ( strcasecmp( pszName, "SSLCERT" ) == 0 ) + { + if ( !pDataSource->sSslSettings.pszSSLCERT ) + pDataSource->sSslSettings.pszSSLCERT = (char *)_global_strndup( pAnchorChar, pScanChar - pAnchorChar ); + } + else if ( strcasecmp( pszName, "SSLCIPHER" ) == 0 ) + { + if ( !pDataSource->sSslSettings.pszSSLCIPHER ) + pDataSource->sSslSettings.pszSSLCIPHER = (char *)_global_strndup( pAnchorChar, pScanChar - pAnchorChar ); + } + else if ( strcasecmp( pszName, "SSLKEY" ) == 0 ) + { + if ( !pDataSource->sSslSettings.pszSSLKEY ) + pDataSource->sSslSettings.pszSSLKEY = (char *)_global_strndup( pAnchorChar, pScanChar - pAnchorChar ); + } else if ( strcasecmp( pszName, "SAVEFILE" ) == 0 ) { pDataSource->bSaveFileDSN = TRUE; Index: util/MYODBCUtilReadDataSource.c =================================================================== --- util/MYODBCUtilReadDataSource.c (revision 259) +++ util/MYODBCUtilReadDataSource.c (working copy) @@ -204,6 +204,31 @@ if ( !pDataSource->pszUSER ) pDataSource->pszUSER = _global_strdup( szValue ); } + else if ( strcasecmp( pszEntryName, "SSLCA" ) == 0 ) + { + if ( !pDataSource->sSslSettings.pszSSLCA ) + pDataSource->sSslSettings.pszSSLCA = _global_strdup( szValue ); + } + else if ( strcasecmp( pszEntryName, "SSLCAPATH" ) == 0 ) + { + if ( !pDataSource->sSslSettings.pszSSLCAPATH ) + pDataSource->sSslSettings.pszSSLCAPATH = _global_strdup( szValue ); + } + else if ( strcasecmp( pszEntryName, "SSLCERT" ) == 0 ) + { + if ( !pDataSource->sSslSettings.pszSSLCERT ) + pDataSource->sSslSettings.pszSSLCERT = _global_strdup( szValue ); + } + else if ( strcasecmp( pszEntryName, "SSLCIPHER" ) == 0 ) + { + if ( !pDataSource->sSslSettings.pszSSLCIPHER ) + pDataSource->sSslSettings.pszSSLCIPHER = _global_strdup( szValue ); + } + else if ( strcasecmp( pszEntryName, "SSLKEY" ) == 0 ) + { + if ( !pDataSource->sSslSettings.pszSSLKEY ) + pDataSource->sSslSettings.pszSSLKEY = _global_strdup( szValue ); + } else { /* What the ? */ Index: util/MYODBCUtilReadDataSourceStr.c =================================================================== --- util/MYODBCUtilReadDataSourceStr.c (revision 259) +++ util/MYODBCUtilReadDataSourceStr.c (working copy) @@ -257,6 +257,31 @@ if ( !pDataSource->pszUSER ) pDataSource->pszUSER = (char *)_global_strndup( pAnchorChar, pScanChar - pAnchorChar ); } + else if ( strcasecmp( pszName, "SSLCA" ) == 0 ) + { + if ( !pDataSource->sSslSettings.pszSSLCA ) + pDataSource->sSslSettings.pszSSLCA = (char *)_global_strndup( pAnchorChar, pScanChar - pAnchorChar ); + } + else if ( strcasecmp( pszName, "SSLCAPATH" ) == 0 ) + { + if ( !pDataSource->sSslSettings.pszSSLCAPATH ) + pDataSource->sSslSettings.pszSSLCAPATH = (char *)_global_strndup( pAnchorChar, pScanChar - pAnchorChar ); + } + else if ( strcasecmp( pszName, "SSLCERT" ) == 0 ) + { + if ( !pDataSource->sSslSettings.pszSSLCERT ) + pDataSource->sSslSettings.pszSSLCERT = (char *)_global_strndup( pAnchorChar, pScanChar - pAnchorChar ); + } + else if ( strcasecmp( pszName, "SSLCIPHER" ) == 0 ) + { + if ( !pDataSource->sSslSettings.pszSSLCIPHER ) + pDataSource->sSslSettings.pszSSLCIPHER = (char *)_global_strndup( pAnchorChar, pScanChar - pAnchorChar ); + } + else if ( strcasecmp( pszName, "SSLKEY" ) == 0 ) + { + if ( !pDataSource->sSslSettings.pszSSLKEY ) + pDataSource->sSslSettings.pszSSLKEY = (char *)_global_strndup( pAnchorChar, pScanChar - pAnchorChar ); + } else { fprintf( stderr, "[%s][%d][ERROR] Unhandled attribute (%s).\n", __FILE__, __LINE__, pszName ); Index: util/MYODBCUtilWriteConnectStr.c =================================================================== --- util/MYODBCUtilWriteConnectStr.c (revision 259) +++ util/MYODBCUtilWriteConnectStr.c (working copy) @@ -139,6 +139,56 @@ return FALSE; } + if ( pDataSource->sSslSettings.pszSSLCA ) + { + if ( nIndex && !MYODBCUtilInsertStr( pszStr, ";", nMaxLen, &nIndex ) ) + return FALSE; + if ( !MYODBCUtilInsertStr( pszStr, "SSLCA=", nMaxLen, &nIndex ) ) + return FALSE; + if ( !MYODBCUtilInsertStr( pszStr, pDataSource->sSslSettings.pszSSLCA, nMaxLen, &nIndex ) ) + return FALSE; + } + + if ( pDataSource->sSslSettings.pszSSLCAPATH ) + { + if ( nIndex && !MYODBCUtilInsertStr( pszStr, ";", nMaxLen, &nIndex ) ) + return FALSE; + if ( !MYODBCUtilInsertStr( pszStr, "SSLCAPATH=", nMaxLen, &nIndex ) ) + return FALSE; + if ( !MYODBCUtilInsertStr( pszStr, pDataSource->sSslSettings.pszSSLCAPATH, nMaxLen, &nIndex ) ) + return FALSE; + } + + if ( pDataSource->sSslSettings.pszSSLCERT ) + { + if ( nIndex && !MYODBCUtilInsertStr( pszStr, ";", nMaxLen, &nIndex ) ) + return FALSE; + if ( !MYODBCUtilInsertStr( pszStr, "SSLCERT=", nMaxLen, &nIndex ) ) + return FALSE; + if ( !MYODBCUtilInsertStr( pszStr, pDataSource->sSslSettings.pszSSLCERT, nMaxLen, &nIndex ) ) + return FALSE; + } + + if ( pDataSource->sSslSettings.pszSSLCIPHER ) + { + if ( nIndex && !MYODBCUtilInsertStr( pszStr, ";", nMaxLen, &nIndex ) ) + return FALSE; + if ( !MYODBCUtilInsertStr( pszStr, "SSLCIPHER=", nMaxLen, &nIndex ) ) + return FALSE; + if ( !MYODBCUtilInsertStr( pszStr, pDataSource->sSslSettings.pszSSLCIPHER, nMaxLen, &nIndex ) ) + return FALSE; + } + + if ( pDataSource->sSslSettings.pszSSLKEY ) + { + if ( nIndex && !MYODBCUtilInsertStr( pszStr, ";", nMaxLen, &nIndex ) ) + return FALSE; + if ( !MYODBCUtilInsertStr( pszStr, "SSLKEY=", nMaxLen, &nIndex ) ) + return FALSE; + if ( !MYODBCUtilInsertStr( pszStr, pDataSource->sSslSettings.pszSSLKEY, nMaxLen, &nIndex ) ) + return FALSE; + } + return TRUE; } Index: util/MYODBCUtilWriteDataSource.c =================================================================== --- util/MYODBCUtilWriteDataSource.c (revision 259) +++ util/MYODBCUtilWriteDataSource.c (working copy) @@ -70,6 +70,21 @@ if ( pDataSource->pszUSER && !SQLWritePrivateProfileString( pDataSource->pszDSN, "UID", pDataSource->pszUSER, "odbc.ini" ) ) return FALSE; + if ( pDataSource->sSslSettings.pszSSLCA && + !SQLWritePrivateProfileString( pDataSource->pszDSN, "SSLCA", pDataSource->sSslSettings.pszSSLCA, "odbc.ini" ) ) + return FALSE; + if ( pDataSource->sSslSettings.pszSSLCAPATH && + !SQLWritePrivateProfileString( pDataSource->pszDSN, "SSLCAPATH", pDataSource->sSslSettings.pszSSLCAPATH, "odbc.ini" ) ) + return FALSE; + if ( pDataSource->sSslSettings.pszSSLCERT && + !SQLWritePrivateProfileString( pDataSource->pszDSN, "SSLCERT", pDataSource->sSslSettings.pszSSLCERT, "odbc.ini" ) ) + return FALSE; + if ( pDataSource->sSslSettings.pszSSLCIPHER && + !SQLWritePrivateProfileString( pDataSource->pszDSN, "SSLCIPHER", pDataSource->sSslSettings.pszSSLCIPHER, "odbc.ini" ) ) + return FALSE; + if ( pDataSource->sSslSettings.pszSSLKEY && + !SQLWritePrivateProfileString( pDataSource->pszDSN, "SSLKEY", pDataSource->sSslSettings.pszSSLKEY, "odbc.ini" ) ) + return FALSE; return TRUE; } Index: util/MYODBCUtilWriteDataSourceStr.c =================================================================== --- util/MYODBCUtilWriteDataSourceStr.c (revision 259) +++ util/MYODBCUtilWriteDataSourceStr.c (working copy) @@ -162,6 +162,56 @@ return FALSE; } + if ( pDataSource->sSslSettings.pszSSLCA ) + { + MYODBCUTILWRITEDATASOURCESTR_DELIM; + + if ( !MYODBCUtilInsertStr( pszStr, "SSLCA=", nMaxLen, &nIndex ) ) + return FALSE; + if ( !MYODBCUtilInsertStr( pszStr, pDataSource->sSslSettings.pszSSLCA, nMaxLen, &nIndex ) ) + return FALSE; + } + + if ( pDataSource->sSslSettings.pszSSLCAPATH ) + { + MYODBCUTILWRITEDATASOURCESTR_DELIM; + + if ( !MYODBCUtilInsertStr( pszStr, "SSLCAPATH=", nMaxLen, &nIndex ) ) + return FALSE; + if ( !MYODBCUtilInsertStr( pszStr, pDataSource->sSslSettings.pszSSLCAPATH, nMaxLen, &nIndex ) ) + return FALSE; + } + + if ( pDataSource->sSslSettings.pszSSLCERT ) + { + MYODBCUTILWRITEDATASOURCESTR_DELIM; + + if ( !MYODBCUtilInsertStr( pszStr, "SSLCERT=", nMaxLen, &nIndex ) ) + return FALSE; + if ( !MYODBCUtilInsertStr( pszStr, pDataSource->sSslSettings.pszSSLCERT, nMaxLen, &nIndex ) ) + return FALSE; + } + + if ( pDataSource->sSslSettings.pszSSLCIPHER ) + { + MYODBCUTILWRITEDATASOURCESTR_DELIM; + + if ( !MYODBCUtilInsertStr( pszStr, "SSLCIPHER=", nMaxLen, &nIndex ) ) + return FALSE; + if ( !MYODBCUtilInsertStr( pszStr, pDataSource->sSslSettings.pszSSLCIPHER, nMaxLen, &nIndex ) ) + return FALSE; + } + + if ( pDataSource->sSslSettings.pszSSLKEY ) + { + MYODBCUTILWRITEDATASOURCESTR_DELIM; + + if ( !MYODBCUtilInsertStr( pszStr, "SSLKEY=", nMaxLen, &nIndex ) ) + return FALSE; + if ( !MYODBCUtilInsertStr( pszStr, pDataSource->sSslSettings.pszSSLKEY, nMaxLen, &nIndex ) ) + return FALSE; + } + if ( nDelim == MYODBCUTIL_DELIM_NULL ) { MYODBCUTILWRITEDATASOURCESTR_DELIM;