Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 119 additions & 5 deletions driver/connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,37 @@ static SQLRETURN dbc_curl_init(esodbc_dbc_st *dbc)
INFOH(dbc, "no username provided: auth disabled.");
}

/* proxy parameters */
if (dbc->proxy_url.cnt) {
dbc->curl_err = curl_easy_setopt(curl, CURLOPT_PROXY,
dbc->proxy_url.str);
if (dbc->curl_err != CURLE_OK) {
ERRH(dbc, "libcurl: failed to set the proxy URL.");
goto err;
}
if (dbc->proxy_uid.cnt) {
dbc->curl_err = curl_easy_setopt(curl, CURLOPT_PROXYUSERNAME,
dbc->proxy_uid.str);
if (dbc->curl_err != CURLE_OK) {
ERRH(dbc, "libcurl: failed to set the proxy username.");
goto err;
}
if (dbc->proxy_pwd.cnt) {
dbc->curl_err = curl_easy_setopt(curl, CURLOPT_PROXYPASSWORD,
dbc->proxy_pwd.str);
if (dbc->curl_err != CURLE_OK) {
ERRH(dbc, "libcurl: failed to set the proxy password.");
goto err;
}
}
}
} else {
dbc->curl_err = curl_easy_setopt(curl, CURLOPT_PROXY, "");
if (dbc->curl_err != CURLE_OK) {
WARNH(dbc, "libcurl: failed to generally disable proxying.");
}
}

/* set the write call-back for answers */
dbc->curl_err = curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
write_callback);
Expand Down Expand Up @@ -1130,7 +1161,7 @@ SQLRETURN config_dbc(esodbc_dbc_st *dbc, esodbc_dsn_attrs_st *attrs)
const static wstr_st http_prefix = WSTR_INIT("http://");
const static wstr_st https_prefix = WSTR_INIT("https://");
wstr_st prefix;
int cnt, ipv6;
int cnt, ipv6, n;
SQLBIGINT secure, timeout, max_body_size, max_fetch_size, varchar_limit;
SQLWCHAR buff_url[ESODBC_MAX_URL_LEN];
wstr_st url = (wstr_st) {
Expand Down Expand Up @@ -1191,7 +1222,7 @@ SQLRETURN config_dbc(esodbc_dbc_st *dbc, esodbc_dsn_attrs_st *attrs)

if (secure) {
if (! wstr_to_utf8(&attrs->ca_path, &dbc->ca_path)) {
ERRNH(dbc, "failed to convert CA path `" LWPDL "` to UTF8.",
ERRH(dbc, "failed to convert CA path `" LWPDL "` to UTF8.",
LWSTR(&attrs->ca_path));
SET_HDIAG(dbc, SQL_STATE_HY000, "reading the CA file path "
"failed", 0);
Expand Down Expand Up @@ -1222,7 +1253,7 @@ SQLRETURN config_dbc(esodbc_dbc_st *dbc, esodbc_dsn_attrs_st *attrs)
url.cnt = (size_t)cnt;
}
if (! wstr_to_utf8(&url, &dbc->close_url)) {
ERRNH(dbc, "failed to convert URL `" LWPDL "` to UTF8.", LWSTR(&url));
ERRH(dbc, "failed to convert URL `" LWPDL "` to UTF8.", LWSTR(&url));
SET_HDIAG(dbc, SQL_STATE_HY000, "server SQL URL's UTF8 conversion "
"failed", 0);
goto err;
Expand All @@ -1233,7 +1264,7 @@ SQLRETURN config_dbc(esodbc_dbc_st *dbc, esodbc_dsn_attrs_st *attrs)
* dup'ed since libcurl needs the 0 terminator */
url.cnt -= sizeof(ELASTIC_SQL_CLOSE_SUBPATH) - /*\0*/1;
if (! wstr_to_utf8(&url, &dbc->url)) {
ERRNH(dbc, "failed to convert URL `" LWPDL "` to UTF8.", LWSTR(&url));
ERRH(dbc, "failed to convert URL `" LWPDL "` to UTF8.", LWSTR(&url));
SET_HDIAG(dbc, SQL_STATE_HY000, "server SQL URL's UTF8 conversion "
"failed", 0);
goto err;
Expand All @@ -1258,7 +1289,7 @@ SQLRETURN config_dbc(esodbc_dbc_st *dbc, esodbc_dsn_attrs_st *attrs)
url.cnt = (size_t)cnt;
}
if (! wstr_to_utf8(&url, &dbc->root_url)) {
ERRNH(dbc, "failed to convert URL `" LWPDL "` to UTF8.", LWSTR(&url));
ERRH(dbc, "failed to convert URL `" LWPDL "` to UTF8.", LWSTR(&url));
SET_HDIAG(dbc, SQL_STATE_HY000, "server root URL's UTF8 conversion "
"failed", 0);
goto err;
Expand Down Expand Up @@ -1312,6 +1343,74 @@ SQLRETURN config_dbc(esodbc_dbc_st *dbc, esodbc_dsn_attrs_st *attrs)
dbc->timeout = (SQLUINTEGER)timeout;
INFOH(dbc, "timeout: %lu.", dbc->timeout);

/*
* proxy settings
*/
if (wstr2bool(&attrs->proxy_enabled)) {
ipv6 = wcsnstr(attrs->proxy_host.str, attrs->proxy_host.cnt, L':') !=
NULL;
cnt = swprintf(url.str, sizeof(buff_url)/sizeof(*buff_url),
L"" WPFWP_LDESC "://" WPFCP_DESC WPFWP_LDESC WPFCP_DESC,
LWSTR(&attrs->proxy_type),
ipv6 ? "[" : "", LWSTR(&attrs->proxy_host), ipv6 ? "]" : "");
if (cnt > 0 && attrs->proxy_port.cnt) {
n = swprintf(url.str + cnt,
sizeof(buff_url)/sizeof(*buff_url) - cnt,
L":" WPFWP_LDESC, LWSTR(&attrs->proxy_port));
} else {
n = 0;
}
if (cnt <= 0 || n < 0) {
ERRNH(dbc, "failed to print proxy URL out of type: `" LWPDL "`, "
"host: `" LWPDL "` and port: `" LWPDL "`.",
LWSTR(&attrs->proxy_type), LWSTR(&attrs->proxy_host),
LWSTR(&attrs->proxy_port));
SET_HDIAG(dbc, SQL_STATE_HY000, "printing proxy URL failed", 0);
goto err;
} else {
url.cnt = cnt + n;
}
if (! wstr_to_utf8(&url, &dbc->proxy_url)) {
ERRH(dbc, "failed to convert URL `" LWPDL "` to UTF8.",
LWSTR(&url));
SET_HDIAG(dbc, SQL_STATE_HY000, "proxy URL's UTF8 conversion "
"failed", 0);
goto err;
}
INFOH(dbc, "proxy URL: `%s`.", dbc->proxy_url.str);

if (wstr2bool(&attrs->proxy_auth_enabled)) {
if (attrs->proxy_auth_uid.cnt) {
if (! wstr_to_utf8(&attrs->proxy_auth_uid, &dbc->proxy_uid)) {
ERRH(dbc, "failed to convert proxy user ID `" LWPDL "` to"
" UTF8.", LWSTR(&attrs->proxy_auth_uid));
SET_HDIAG(dbc, SQL_STATE_HY000, "proxy UID's UTF8 "
"conversion failed", 0);
goto err;
}
INFOH(dbc, "proxy UID: `%s`.", dbc->proxy_uid.str);

if (attrs->proxy_auth_pwd.cnt) {
if (! wstr_to_utf8(&attrs->proxy_auth_pwd,
&dbc->proxy_pwd)) {
ERRH(dbc, "failed to convert proxy password [%zu] `%s`"
" to UTF8", attrs->proxy_auth_pwd.cnt,
ESODBC_PWD_VAL_SUBST);
SET_HDIAG(dbc, SQL_STATE_HY000, "proxy password's "
"UTF8 conversion failed", 0);
goto err;
}
/* indicates the presence of a non-empty password */
INFOH(dbc, "proxy PWD: " ESODBC_PWD_VAL_SUBST ".");
}
}
} else {
INFOH(dbc, "proxy authentication disabled.");
}
} else {
INFOH(dbc, "proxy disabled.");
}

/*
* set max body size
*/
Expand Down Expand Up @@ -1513,6 +1612,21 @@ void cleanup_dbc(esodbc_dbc_st *dbc)
} else {
assert(dbc->pwd.cnt == 0);
}
if (dbc->proxy_url.str) {
free(dbc->proxy_url.str);
dbc->proxy_url.str = NULL;
dbc->proxy_url.cnt = 0;
}
if (dbc->proxy_uid.str) {
free(dbc->proxy_uid.str);
dbc->proxy_uid.str = NULL;
dbc->proxy_uid.cnt = 0;
}
if (dbc->proxy_pwd.str) {
free(dbc->proxy_pwd.str);
dbc->proxy_pwd.str = NULL;
dbc->proxy_pwd.cnt = 0;
}
if (dbc->fetch.str) {
free(dbc->fetch.str);
dbc->fetch.str = NULL;
Expand Down
10 changes: 6 additions & 4 deletions driver/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
#define ESODBC_MAX_URL_LEN 2048
/* maximum DNS attribute value length (should be long enought to accomodate a
* decently long FQ file path name) */
#define ESODBC_DSN_MAX_ATTR_LEN 1024
#define ESODBC_DSN_MAX_ATTR_LEN 768

/* SQL plugin's REST endpoint for SQL */
#define ELASTIC_SQL_PATH "/_sql"
Expand Down Expand Up @@ -167,7 +167,7 @@
/* default global request timeout (0: no timeout) */
#define ESODBC_DEF_TIMEOUT "0"
/* don't follow redirection from the server */
#define ESODBC_DEF_FOLLOW "yes"
#define ESODBC_DEF_FOLLOW "true"
/* packing of REST bodies (JSON or CBOR) */
#define ESODBC_DEF_PACKING ESODBC_DSN_PACK_CBOR
/* zlib compression of REST bodies (auto/true/false) */
Expand All @@ -177,16 +177,18 @@
/* default tracing level */
#define ESODBC_DEF_TRACE_LEVEL "WARN"
/* default TZ handling */
#define ESODBC_DEF_APPLY_TZ "no"
#define ESODBC_DEF_APPLY_TZ "false"
/* default early execution flag */
#define ESODBC_DEF_EARLY_EXEC "yes"
#define ESODBC_DEF_EARLY_EXEC "true"
/* default of scientific floats printing */
#define ESODBC_DEF_SCI_FLOATS ESODBC_DSN_FLTS_DEF
#define ESODBC_PWD_VAL_SUBST "<redacted>"
#define ESODBC_DEF_MFIELD_LENIENT "true"
#define ESODBC_DEF_ESC_PVA "true"
#define ESODBC_DEF_IDX_INC_FROZEN "false"
#define ESODBC_DEF_VARCHAR_LIMIT "0"
#define ESODBC_DEF_PROXY_ENABLED "false"
#define ESODBC_DEF_PROXY_AUTH_ENA "false"

/*
*
Expand Down
57 changes: 57 additions & 0 deletions driver/dsn.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ int assign_dsn_attr(esodbc_dsn_attrs_st *attrs,
{&MK_WSTR(ESODBC_DSN_MFIELD_LENIENT), &attrs->mfield_lenient},
{&MK_WSTR(ESODBC_DSN_ESC_PVA), &attrs->auto_esc_pva},
{&MK_WSTR(ESODBC_DSN_IDX_INC_FROZEN), &attrs->idx_inc_frozen},
{&MK_WSTR(ESODBC_DSN_PROXY_ENABLED), &attrs->proxy_enabled},
{&MK_WSTR(ESODBC_DSN_PROXY_TYPE), &attrs->proxy_type},
{&MK_WSTR(ESODBC_DSN_PROXY_HOST), &attrs->proxy_host},
{&MK_WSTR(ESODBC_DSN_PROXY_PORT), &attrs->proxy_port},
{&MK_WSTR(ESODBC_DSN_PROXY_AUTH_ENA), &attrs->proxy_auth_enabled},
{&MK_WSTR(ESODBC_DSN_PROXY_AUTH_UID), &attrs->proxy_auth_uid},
{&MK_WSTR(ESODBC_DSN_PROXY_AUTH_PWD), &attrs->proxy_auth_pwd},
{&MK_WSTR(ESODBC_DSN_TRACE_ENABLED), &attrs->trace_enabled},
{&MK_WSTR(ESODBC_DSN_TRACE_FILE), &attrs->trace_file},
{&MK_WSTR(ESODBC_DSN_TRACE_LEVEL), &attrs->trace_level},
Expand Down Expand Up @@ -418,6 +425,13 @@ long TEST_API write_00_list(esodbc_dsn_attrs_st *attrs,
{&MK_WSTR(ESODBC_DSN_MFIELD_LENIENT), &attrs->mfield_lenient},
{&MK_WSTR(ESODBC_DSN_ESC_PVA), &attrs->auto_esc_pva},
{&MK_WSTR(ESODBC_DSN_IDX_INC_FROZEN), &attrs->idx_inc_frozen},
{&MK_WSTR(ESODBC_DSN_PROXY_ENABLED), &attrs->proxy_enabled},
{&MK_WSTR(ESODBC_DSN_PROXY_TYPE), &attrs->proxy_type},
{&MK_WSTR(ESODBC_DSN_PROXY_HOST), &attrs->proxy_host},
{&MK_WSTR(ESODBC_DSN_PROXY_PORT), &attrs->proxy_port},
{&MK_WSTR(ESODBC_DSN_PROXY_AUTH_ENA), &attrs->proxy_auth_enabled},
{&MK_WSTR(ESODBC_DSN_PROXY_AUTH_UID), &attrs->proxy_auth_uid},
{&MK_WSTR(ESODBC_DSN_PROXY_AUTH_PWD), &attrs->proxy_auth_pwd},
{&MK_WSTR(ESODBC_DSN_TRACE_ENABLED), &attrs->trace_enabled},
{&MK_WSTR(ESODBC_DSN_TRACE_FILE), &attrs->trace_file},
{&MK_WSTR(ESODBC_DSN_TRACE_LEVEL), &attrs->trace_level},
Expand Down Expand Up @@ -704,6 +718,35 @@ BOOL write_system_dsn(esodbc_dsn_attrs_st *new_attrs,
&new_attrs->idx_inc_frozen,
old_attrs ? &old_attrs->idx_inc_frozen : NULL
},
{
&MK_WSTR(ESODBC_DSN_PROXY_ENABLED), &new_attrs->proxy_enabled,
old_attrs ? &old_attrs->proxy_enabled : NULL
},
{
&MK_WSTR(ESODBC_DSN_PROXY_TYPE), &new_attrs->proxy_type,
old_attrs ? &old_attrs->proxy_type : NULL
},
{
&MK_WSTR(ESODBC_DSN_PROXY_HOST), &new_attrs->proxy_host,
old_attrs ? &old_attrs->proxy_host : NULL
},
{
&MK_WSTR(ESODBC_DSN_PROXY_PORT), &new_attrs->proxy_port,
old_attrs ? &old_attrs->proxy_port : NULL
},
{
&MK_WSTR(ESODBC_DSN_PROXY_AUTH_ENA),
&new_attrs->proxy_auth_enabled,
old_attrs ? &old_attrs->proxy_auth_enabled : NULL
},
{
&MK_WSTR(ESODBC_DSN_PROXY_AUTH_UID), &new_attrs->proxy_auth_uid,
old_attrs ? &old_attrs->proxy_auth_uid : NULL
},
{
&MK_WSTR(ESODBC_DSN_PROXY_AUTH_PWD), &new_attrs->proxy_auth_pwd,
old_attrs ? &old_attrs->proxy_auth_pwd : NULL
},
{
&MK_WSTR(ESODBC_DSN_TRACE_ENABLED), &new_attrs->trace_enabled,
old_attrs ? &old_attrs->trace_enabled : NULL
Expand Down Expand Up @@ -797,6 +840,13 @@ long TEST_API write_connection_string(esodbc_dsn_attrs_st *attrs,
{&attrs->mfield_lenient, &MK_WSTR(ESODBC_DSN_MFIELD_LENIENT)},
{&attrs->auto_esc_pva, &MK_WSTR(ESODBC_DSN_ESC_PVA)},
{&attrs->idx_inc_frozen, &MK_WSTR(ESODBC_DSN_IDX_INC_FROZEN)},
{&attrs->proxy_enabled, &MK_WSTR(ESODBC_DSN_PROXY_ENABLED)},
{&attrs->proxy_type, &MK_WSTR(ESODBC_DSN_PROXY_TYPE)},
{&attrs->proxy_host, &MK_WSTR(ESODBC_DSN_PROXY_HOST)},
{&attrs->proxy_port, &MK_WSTR(ESODBC_DSN_PROXY_PORT)},
{&attrs->proxy_auth_enabled, &MK_WSTR(ESODBC_DSN_PROXY_AUTH_ENA)},
{&attrs->proxy_auth_uid, &MK_WSTR(ESODBC_DSN_PROXY_AUTH_UID)},
{&attrs->proxy_auth_pwd, &MK_WSTR(ESODBC_DSN_PROXY_AUTH_PWD)},
{&attrs->trace_enabled, &MK_WSTR(ESODBC_DSN_TRACE_ENABLED)},
{&attrs->trace_file, &MK_WSTR(ESODBC_DSN_TRACE_FILE)},
{&attrs->trace_level, &MK_WSTR(ESODBC_DSN_TRACE_LEVEL)},
Expand Down Expand Up @@ -909,6 +959,13 @@ void assign_dsn_defaults(esodbc_dsn_attrs_st *attrs)
&MK_WSTR(ESODBC_DSN_IDX_INC_FROZEN),
&MK_WSTR(ESODBC_DEF_IDX_INC_FROZEN), /*overwrite?*/FALSE);

res |= assign_dsn_attr(attrs,
&MK_WSTR(ESODBC_DSN_PROXY_ENABLED),
&MK_WSTR(ESODBC_DEF_PROXY_ENABLED), /*overwrite?*/FALSE);
res |= assign_dsn_attr(attrs,
&MK_WSTR(ESODBC_DSN_PROXY_AUTH_ENA),
&MK_WSTR(ESODBC_DEF_PROXY_AUTH_ENA), /*overwrite?*/FALSE);

/* default: no trace file */
res |= assign_dsn_attr(attrs,
&MK_WSTR(ESODBC_DSN_TRACE_ENABLED),
Expand Down
17 changes: 16 additions & 1 deletion driver/dsn.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@
#define ESODBC_DSN_MFIELD_LENIENT "MultiFieldLenient"
#define ESODBC_DSN_ESC_PVA "AutoEscapePVA"
#define ESODBC_DSN_IDX_INC_FROZEN "IndexIncludeFrozen"
#define ESODBC_DSN_PROXY_ENABLED "ProxyEnabled"
#define ESODBC_DSN_PROXY_TYPE "ProxyType"
#define ESODBC_DSN_PROXY_HOST "ProxyHost"
#define ESODBC_DSN_PROXY_PORT "ProxyPort"
#define ESODBC_DSN_PROXY_AUTH_ENA "ProxyAuthEnabled"
#define ESODBC_DSN_PROXY_AUTH_UID "ProxyAuthUID"
#define ESODBC_DSN_PROXY_AUTH_PWD "ProxyAuthPWD"
#define ESODBC_DSN_TRACE_ENABLED "TraceEnabled"
#define ESODBC_DSN_TRACE_FILE "TraceFile"
#define ESODBC_DSN_TRACE_LEVEL "TraceLevel"
Expand Down Expand Up @@ -85,10 +92,18 @@ typedef struct {
wstr_st mfield_lenient;
wstr_st auto_esc_pva;
wstr_st idx_inc_frozen;
wstr_st proxy_enabled;
wstr_st proxy_type;
wstr_st proxy_host;
wstr_st proxy_port;
wstr_st proxy_auth_enabled;
wstr_st proxy_auth_uid;
wstr_st proxy_auth_pwd;
wstr_st trace_enabled;
wstr_st trace_file;
wstr_st trace_level;
#define ESODBC_DSN_ATTRS_COUNT 29
#define ESODBC_DSN_ATTRS_COUNT 36

SQLWCHAR buff[ESODBC_DSN_ATTRS_COUNT * ESODBC_DSN_MAX_ATTR_LEN];
/* DSN reading/writing functions are passed a SQLSMALLINT length param */
#if SHRT_MAX < ESODBC_DSN_ATTRS_COUNT * ESODBC_DSN_MAX_ATTR_LEN
Expand Down
5 changes: 5 additions & 0 deletions driver/handles.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ typedef struct struct_dbc {
wstr_st server; /* ~ name; requested with SQLGetInfo(SQL_SERVER_NAME) */
wstr_st catalog; /* cached value; checked against if app setting it */
wstr_st srv_ver; /* server version: SQLGetInfo(SQL_DBMS_VER) */

cstr_st proxy_url;
cstr_st proxy_uid;
cstr_st proxy_pwd;
cstr_st url; /* SQL URL (posts) */
cstr_st close_url; /* SQL close URL (posts) */
cstr_st root_url; /* root URL (gets) */
Expand All @@ -145,6 +149,7 @@ typedef struct struct_dbc {
ESODBC_SEC_MAX /* meta */
} secure;
cstr_st ca_path;

cstr_st uid;
cstr_st pwd;
SQLUINTEGER timeout;
Expand Down
5 changes: 5 additions & 0 deletions driver/odbc.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ BOOL WINAPI DllMain(
DWORD fdwReason, // reason for calling function
LPVOID lpReserved) // reserved
{
SQLWCHAR path[MAX_PATH];
// Perform actions based on the reason for calling.
switch (fdwReason) {
// Initialize once for each new process.
Expand All @@ -77,6 +78,10 @@ BOOL WINAPI DllMain(
return FALSE;
}
INFO("process %u attached.", GetCurrentProcessId());
if (GetModuleFileNameW(NULL, path, sizeof(path)/sizeof(*path))
> 0) {
INFO("process path: `" PFWP_DESC "`.", path);
}
break;

// Do thread-specific initialization.
Expand Down
2 changes: 1 addition & 1 deletion driver/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ BOOL wstr2bool(wstr_st *val)
case /*""*/0: return FALSE;
case /*0*/1: return ! EQ_CASE_WSTR(val, &MK_WSTR("0"));
case /*no*/2: return ! EQ_CASE_WSTR(val, &MK_WSTR("no"));
case /*no*/3: return ! EQ_CASE_WSTR(val, &MK_WSTR("off"));
case /*off*/3: return ! EQ_CASE_WSTR(val, &MK_WSTR("off"));
case /*false*/5: return ! EQ_CASE_WSTR(val, &MK_WSTR("false"));
}
/*INDENT-ON*/
Expand Down
Loading