Skip to content

Commit

Permalink
Add client_os_user_name for session (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
sitingren authored Sep 30, 2022
1 parent 610cb07 commit 26e75fe
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions msgs/festartupmsg.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ package msgs
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

import "fmt"
import (
"fmt"
"os/user"
)

// FEStartupMsg docs
type FEStartupMsg struct {
Expand All @@ -43,11 +46,18 @@ type FEStartupMsg struct {
Database string
SessionID string
ClientPID int
OSUsername string
}

// Flatten docs
func (m *FEStartupMsg) Flatten() ([]byte, byte) {

m.OSUsername = ""
currentUser, err := user.Current()
if err == nil {
m.OSUsername = currentUser.Username
}

buf := newMsgBuffer()
const fixedProtocolVersion uint32 = 0x00030005
buf.appendUint32(fixedProtocolVersion)
Expand All @@ -69,19 +79,21 @@ func (m *FEStartupMsg) Flatten() ([]byte, byte) {
buf.appendLabeledString("client_version", m.DriverVersion)
buf.appendLabeledString("client_label", m.SessionID)
buf.appendLabeledString("client_pid", fmt.Sprintf("%d", m.ClientPID))
buf.appendLabeledString("client_os_user_name", m.OSUsername)
buf.appendBytes([]byte{0})

return buf.bytes(), 0
}

func (m *FEStartupMsg) String() string {
return fmt.Sprintf(
"Startup (packet): ProtocolVersion:%08X, DriverName='%s', DriverVersion='%s', UserName='%s', Database='%s', SessionID='%s', ClientPID=%d",
"Startup (packet): ProtocolVersion:%08X, DriverName='%s', DriverVersion='%s', UserName='%s', Database='%s', SessionID='%s', ClientPID=%d, ClientOSUserName='%s'",
m.ProtocolVersion,
m.DriverName,
m.DriverVersion,
m.Username,
m.Database,
m.SessionID,
m.ClientPID)
m.ClientPID,
m.OSUsername)
}

0 comments on commit 26e75fe

Please sign in to comment.