Skip to content

Commit

Permalink
Sanitize connection strings
Browse files Browse the repository at this point in the history
Removes UID and PWD values from connection strings where `Trusted_Connection=True`. These values are not needed in this context, and will be different when the database is built and exported by different users. Closes #181
  • Loading branch information
joyfullservice committed Feb 26, 2021
1 parent c098927 commit f5dd5b6
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Version Control.accda.src/dbs-properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"Type": 10
},
"AppVersion": {
"Value": "3.3.2",
"Value": "3.3.3",
"Type": 10
},
"Auto Compact": {
Expand Down
55 changes: 54 additions & 1 deletion Version Control.accda.src/modules/clsDbTableDef.bas
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Private Sub IDbComponent_Export()
Set dItem = New Dictionary
With dItem
.Add "Name", tbl.Name
.Add "Connect", Secure(GetRelativeConnect(tbl.Connect))
.Add "Connect", Secure(SanitizeConnectionString(tbl.Connect))
.Add "SourceTableName", tbl.SourceTableName
.Add "Attributes", tbl.Attributes
' indexes (Find primary key)
Expand Down Expand Up @@ -458,6 +458,59 @@ Private Function SafeAttributes(lngAttributes As Long) As Long
End Function


'---------------------------------------------------------------------------------------
' Procedure : SanitizeConnectionString
' Author : Adam Waller
' Date : 2/26/2021
' Purpose : Sanitize the connection string by removing unneeded information and
' : converting database path to relative.
'---------------------------------------------------------------------------------------
'
Private Function SanitizeConnectionString(strConnection As String) As String

Dim lngPart As Long
Dim varParts As Variant
Dim strPart As String

If strConnection = vbNullString Then Exit Function

' Create array of connection string parts
varParts = Split(strConnection, ";")

' Loop through parts, building new connection string
With New clsConcat
.AppendOnAdd = ";"
For lngPart = 0 To UBound(varParts)
strPart = CStr(varParts(lngPart))
Select Case True

' Check for username/password
Case StartsWith(strPart, "UID=", vbTextCompare), _
StartsWith(strPart, "PWD=", vbTextCompare)
' These values are not needed when using a trusted connection.
If InStr(1, strConnection, "Trusted_Connection=True", vbTextCompare) > 0 Then
' Strip out username/pwd if AggressiveSanitize option set. (Typically True)
If Not Options.AggressiveSanitize Then .Add strPart
End If

' Check database path to convert to relative
Case StartsWith(strPart, "DATABASE=", vbTextCompare)
.Add GetRelativeConnect(strPart)

' Add all other sections
Case Else
.Add strPart
End Select
Next lngPart

' Remove trailing semicolon, and return string
.Remove 1
SanitizeConnectionString = .GetStr
End With

End Function


'---------------------------------------------------------------------------------------
' Procedure : GetRelativeConnect
' Author : Adam Waller
Expand Down
2 changes: 1 addition & 1 deletion Version Control.accda.src/vbe-project.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"Items": {
"Name": "MSAccessVCS",
"Description": "Version 3.3.2 deployed on 2/24/2021",
"Description": "Version 3.3.3 deployed on 2/26/2021",
"FileName": "rel:Version Control.accda",
"HelpFile": "",
"HelpContextId": 0,
Expand Down
2 changes: 1 addition & 1 deletion Version Control.accda.src/vcs-options.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"Info": {
"AddinVersion": "3.3.2",
"AddinVersion": "3.3.3",
"AccessVersion": "14.0 32-bit"
},
"Options": {
Expand Down

0 comments on commit f5dd5b6

Please sign in to comment.