Skip to content
Open
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
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ add_library(TrinoODBC SHARED
"src/trinoAPIWrapper/authProvider/externalAuthProvider.cpp"
"src/trinoAPIWrapper/authProvider/noAuthProvider.cpp"
"src/trinoAPIWrapper/authProvider/tokenCacheAuthProviderBase.cpp"
"src/trinoAPIWrapper/authProvider/deviceFlowAuthProvider.cpp"
"src/trinoAPIWrapper/trinoQuery.cpp"
"src/trinoAPIWrapper/connectionConfig.cpp"
"src/trinoAPIWrapper/environmentConfig.cpp"
"src/trinoAPIWrapper/columnDescription.cpp"
"src/trinoAPIWrapper/trinoExceptions.cpp"
"src/trinoAPIWrapper/TrinoOdbcErrorHandler.cpp"
"src/driver/config/configDSN.cpp"
"src/driver/config/driverConfig.cpp"
"src/driver/config/dsnConfigForm.cpp"
Expand Down
194 changes: 194 additions & 0 deletions install_development_drivers.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
<# install_development_drivers.ps1
Creates/updates ODBC driver registry keys for Trino based on the current directory.
Also writes a .reg file for manual review/import.
#>

param(
[string]$DriverName = "", # Leave empty to auto-pick based on DLL path
[string]$DllPath = "", # Optional explicit path to TrinoODBC.dll
[string]$DriverODBCVer = "03.80",
[string]$ConnectFunctions = "YYN",
[string]$APILevel = "0",
[string]$SQLLevel = "0",
[string]$FileUsage = "0",
[string]$RegOutPath = "" # Optional path for the .reg file; defaults next to this script
)

Set-StrictMode -Version 2.0
$ErrorActionPreference = 'Stop'

function Assert-Admin {
$id = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = New-Object Security.Principal.WindowsPrincipal($id)
if (-not $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
throw "This script must be run as Administrator."
}
}

function Classify-Build([string]$dllFullPath) {
if ($dllFullPath -match '(?i)(\\|/)Debug(\\|/)' ) { return 'Debug' }
if ($dllFullPath -match '(?i)(\\|/)Release(\\|/)' ) { return 'Release' }
return 'Unknown'
}

function Resolve-Dll([string]$PathFromUser) {
if ($PathFromUser) {
if (-not (Test-Path -LiteralPath $PathFromUser)) {
throw ("Specified DllPath not found: {0}" -f $PathFromUser)
}
$p = (Resolve-Path -LiteralPath $PathFromUser).Path
return [pscustomobject]@{ Path = $p; Build = (Classify-Build $p) }
}

$candidates = @(
".\build\Debug\TrinoODBC.dll",
".\build\Release\TrinoODBC.dll",
".\TrinoODBC.dll"
)

foreach ($c in $candidates) {
if (Test-Path -LiteralPath $c) {
$p = (Resolve-Path -LiteralPath $c).Path
return [pscustomobject]@{ Path = $p; Build = (Classify-Build $p) }
}
}

$list = ($candidates -join "`n ")
throw ("Could not find TrinoODBC.dll. Pass -DllPath or place the DLL in one of:`n {0}" -f $list)
}

function Choose-DriverName([string]$UserProvided, [string]$BuildKind) {
if ($UserProvided) { return $UserProvided }
switch ($BuildKind) {
'Debug' { return 'TrinoODBCDebug' }
'Release' { return 'TrinoODBCRelease' }
default { return 'TrinoODBCRelease' } # default when unknown
}
}

function Set-DriverKeys([string]$BaseKey, [string]$DriverName, [hashtable]$Props) {
$driversKey = Join-Path $BaseKey "ODBC Drivers"
New-Item -Path $driversKey -Force | Out-Null
New-ItemProperty -Path $driversKey -Name $DriverName -Value "Installed" -PropertyType String -Force | Out-Null

$driverKey = Join-Path $BaseKey $DriverName
New-Item -Path $driverKey -Force | Out-Null

foreach ($k in $Props.Keys) {
New-ItemProperty -Path $driverKey -Name $k -Value $Props[$k] -PropertyType String -Force | Out-Null
}

Write-Host ("Updated: {0} -> {1}=Installed" -f $driversKey, $DriverName)
Write-Host ("Updated: {0}" -f $driverKey)
}

function Write-RegFile(
[string]$OutPath,
[string]$DriverName,
[string]$DllFullPath,
[string]$DriverODBCVer,
[string]$ConnectFunctions,
[string]$APILevel,
[string]$SQLLevel,
[string]$FileUsage,
[bool]$IncludeWow6432
) {
# 1) Collapse any runs of backslashes to a single backslash
$normalized = ($DllFullPath -replace '\\+', '\')
# 2) Escape ONCE for .reg: single '\' -> double '\\'
$dllReg = ($normalized -replace '\\', '\\')

$lines = @()
$lines += 'Windows Registry Editor Version 5.00'
$lines += ''

# 64-bit hive
$lines += '[HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers]'
$lines += ('"{0}"="Installed"' -f $DriverName)
$lines += ''
$lines += ('[HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI\{0}]' -f $DriverName)
$lines += ('"APILevel"="{0}"' -f $APILevel)
$lines += ('"Driver"="{0}"' -f $dllReg)
$lines += ('"Setup"="{0}"' -f $dllReg)
$lines += ('"DriverODBCVer"="{0}"' -f $DriverODBCVer)
$lines += ('"ConnectFunctions"="{0}"' -f $ConnectFunctions)
$lines += ('"FileUsage"="{0}"' -f $FileUsage)
$lines += ('"SQLLevel"="{0}"' -f $SQLLevel)

if ($IncludeWow6432) {
$lines += ''
$lines += '[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\ODBC\ODBCINST.INI\ODBC Drivers]'
$lines += ('"{0}"="Installed"' -f $DriverName)
$lines += ''
$lines += ('[HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\ODBC\ODBCINST.INI\{0}]' -f $DriverName)
$lines += ('"APILevel"="{0}"' -f $APILevel)
$lines += ('"Driver"="{0}"' -f $dllReg)
$lines += ('"Setup"="{0}"' -f $dllReg)
$lines += ('"DriverODBCVer"="{0}"' -f $DriverODBCVer)
$lines += ('"ConnectFunctions"="{0}"' -f $ConnectFunctions)
$lines += ('"FileUsage"="{0}"' -f $FileUsage)
$lines += ('"SQLLevel"="{0}"' -f $SQLLevel)
}

$content = ($lines -join "`r`n")
Set-Content -Path $OutPath -Value $content -Encoding Unicode
Write-Host ("Wrote .reg file: {0}" -f $OutPath)
}

try {
Assert-Admin

$dllInfo = Resolve-Dll $DllPath
$effectiveDriverName = Choose-DriverName -UserProvided $DriverName -BuildKind $dllInfo.Build

$props = @{
"APILevel" = $APILevel
"Driver" = $dllInfo.Path
"Setup" = $dllInfo.Path
"DriverODBCVer" = $DriverODBCVer
"ConnectFunctions" = $ConnectFunctions
"FileUsage" = $FileUsage
"SQLLevel" = $SQLLevel
}

# 64-bit ODBC driver registration
$base64 = "HKLM:\SOFTWARE\ODBC\ODBCINST.INI"
Set-DriverKeys -BaseKey $base64 -DriverName $effectiveDriverName -Props $props

# 32-bit ODBC driver registration on 64-bit OS (WOW6432Node)
$includeWow = $false
if ([Environment]::Is64BitOperatingSystem) {
$includeWow = $true
$base32 = "HKLM:\SOFTWARE\WOW6432Node\ODBC\ODBCINST.INI"
Set-DriverKeys -BaseKey $base32 -DriverName $effectiveDriverName -Props $props
} else {
Write-Host "Info: Detected 32-bit OS. WOW6432Node not used."
}

# Pick a default .reg output path if none supplied
if (-not $RegOutPath) {
$namePart = $effectiveDriverName -replace '[^A-Za-z0-9._-]', '_'
$RegOutPath = Join-Path -Path $PSScriptRoot -ChildPath ("TrinoODBC-{0}.reg" -f $namePart)
}

Write-RegFile -OutPath $RegOutPath `
-DriverName $effectiveDriverName `
-DllFullPath $dllInfo.Path `
-DriverODBCVer $DriverODBCVer `
-ConnectFunctions $ConnectFunctions `
-APILevel $APILevel `
-SQLLevel $SQLLevel `
-FileUsage $FileUsage `
-IncludeWow6432:$includeWow

Write-Host ""
Write-Host "Done."
Write-Host (" DLL: {0}" -f $dllInfo.Path)
Write-Host (" Build: {0}" -f $dllInfo.Build)
Write-Host (" DriverKey: {0}" -f $effectiveDriverName)
Write-Host (" .reg: {0}" -f $RegOutPath)
}
catch {
Write-Error ($_ | Out-String)
exit 1
}
28 changes: 24 additions & 4 deletions src/driver/config/driverConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,22 @@ std::map<std::string, LogLevel> LOG_NAME_TO_LOG_LEVEL = {
};

std::vector<std::string> AUTH_METHOD_NAMES = {
"No Auth", "External Auth", "OIDC Client Cred Auth"};
"No Auth", "External Auth", "OIDC Client Cred Auth", "Device Flow"};

std::vector<ApiAuthMethod> AUTH_METHOD_VALUES = {
AM_NO_AUTH, AM_EXTERNAL_AUTH, AM_CLIENT_CRED_AUTH};
AM_NO_AUTH, AM_EXTERNAL_AUTH, AM_CLIENT_CRED_AUTH, AM_DEVICE_FLOW};

std::map<ApiAuthMethod, std::string> AUTH_METHOD_TO_AUTH_NAME = {
std::make_pair(AM_NO_AUTH, "No Auth"),
std::make_pair(AM_EXTERNAL_AUTH, "External Auth"),
std::make_pair(AM_CLIENT_CRED_AUTH, "OIDC Client Cred Auth"),
};
std::make_pair(AM_DEVICE_FLOW, "Device Flow")};

std::map<std::string, ApiAuthMethod> AUTH_NAME_TO_AUTH_METHOD = {
std::make_pair("No Auth", AM_NO_AUTH),
std::make_pair("External Auth", AM_EXTERNAL_AUTH),
std::make_pair("Oidc Client Cred Auth", AM_CLIENT_CRED_AUTH),
};
std::make_pair("Device Flow", AM_DEVICE_FLOW)};


// All default values - do not miss any!
Expand Down Expand Up @@ -159,6 +159,20 @@ void DriverConfig::setOidcScope(std::string oidcScope) {
this->oidcScope = oidcScope;
}

std::string DriverConfig::getTokenEndpoint() {
return this->tokenEndpoint;
}
void DriverConfig::setTokenEndpoint(std::string tokenEndpoint) {
this->tokenEndpoint = tokenEndpoint;
}

std::string DriverConfig::getGrantType() {
return this->grantType;
}
void DriverConfig::setGrantType(std::string grantType) {
this->grantType = grantType;
}

// IsSaved
bool DriverConfig::getIsSaved() {
return this->isSaved;
Expand Down Expand Up @@ -219,6 +233,12 @@ DriverConfig driverConfigFromKVPs(std::map<std::string, std::string> kvps) {
if (kvps.count("oidcscope")) {
config.setOidcScope(kvps.at("oidcscope"));
}
if (kvps.count("granttype")) {
config.setGrantType(kvps.at("granttype"));
}
if (kvps.count("tokenendpoint")) {
config.setTokenEndpoint(kvps.at("tokenendpoint"));
}

return config;
}
Expand Down
11 changes: 11 additions & 0 deletions src/driver/config/driverConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class DriverConfig {
std::string clientId = "";
std::string clientSecret = "";
std::string oidcScope = "";
std::string tokenEndpoint = "";
std::string grantType = "";

// Metadata describing the status of this config object.
bool isSaved = false;
Expand Down Expand Up @@ -68,6 +70,15 @@ class DriverConfig {

bool getIsSaved();
void setIsSaved(bool isSaved);

std::string getTokenEndpoint();
void setTokenEndpoint(std::string tokenEndpoint);

std::string getGrantType();
void setGrantType(std::string grantType);

std::string serialize();
static DriverConfig deserialize(const std::string& jsonStr);
};

DriverConfig driverConfigFromKVPs(std::map<std::string, std::string> kvps);
Expand Down
Loading
Loading