protocol

package
v1.2.3-fred.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 18, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PacketTypeSQLBatch is the SQLBatch packet type.
	PacketTypeSQLBatch uint8 = 0x01
	// PacketTypeRPCRequest is the RPCRequest packet type.
	PacketTypeRPCRequest uint8 = 0x03

	// PacketTypeResponse is the packet type for server response messages.
	PacketTypeResponse uint8 = 0x04
	// PacketTypeLogin7 is the Login7 packet type.
	PacketTypeLogin7 uint8 = 0x10
	// PacketTypePreLogin is the Pre-Login packet type.
	PacketTypePreLogin uint8 = 0x12
)

Variables

This section is empty.

Functions

func WriteErrorResponse

func WriteErrorResponse(w io.Writer, err error) error

WriteErrorResponse writes error response to the client.

func WritePreLoginResponse

func WritePreLoginResponse(w io.Writer) error

WritePreLoginResponse writes response to the Pre-Login packet to the writer.

func WriteStreamResponse

func WriteStreamResponse(w io.Writer, tokens []mssql.Token) error

WriteStreamResponse writes stream response packet to the writer.

Types

type BasicPacket

type BasicPacket struct {
	// contains filtered or unexported fields
}

BasicPacket implements the Packet interfaces allowing to operate on PacketHeader and get underlying packet type.

func ReadPacket

func ReadPacket(r io.Reader) (*BasicPacket, error)

ReadPacket reads a single full packet from the reader.

func (BasicPacket) Bytes

func (g BasicPacket) Bytes() []byte

Bytes returns raw packet bytes.

func (BasicPacket) Data

func (g BasicPacket) Data() []byte

Data is the packet data bytes without header.

func (BasicPacket) Header

func (g BasicPacket) Header() PacketHeader

Header is the parsed packet header.

func (BasicPacket) Type

func (g BasicPacket) Type() uint8

Type is the parsed packet header.

type Login7Header

type Login7Header struct {
	Length            uint32
	TDSVersion        uint32
	PacketSize        uint32
	ClientProgVer     uint32
	ClientPID         uint32
	ConnectionID      uint32
	OptionFlags1      uint8
	OptionFlags2      uint8
	TypeFlags         uint8
	OptionFlags3      uint8
	ClientTimezone    int32
	ClientLCID        uint32
	IbHostName        uint16 // offset
	CchHostName       uint16 // length
	IbUserName        uint16
	CchUserName       uint16
	IbPassword        uint16
	CchPassword       uint16
	IbAppName         uint16
	CchAppName        uint16
	IbServerName      uint16
	CchServerName     uint16
	IbUnused          uint16
	CbUnused          uint16
	IbCltIntName      uint16
	CchCltIntName     uint16
	IbLanguage        uint16
	CchLanguage       uint16
	IbDatabase        uint16
	CchDatabase       uint16
	ClientID          [6]byte
	IbSSPI            uint16
	CbSSPI            uint16
	IbAtchDBFile      uint16
	CchAtchDBFile     uint16
	IbChangePassword  uint16
	CchChangePassword uint16
	CbSSPILong        uint32
}

Login7Header contains options and offset/length pairs parsed from the Login7 packet sent by client.

Note: the order of fields in the struct matters as it gets unpacked from the binary stream.

type Login7Packet

type Login7Packet struct {
	// contains filtered or unexported fields
}

Login7Packet represents a Login7 packet that defines authentication rules between the client and the server.

https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-tds/773a62b6-ee89-4c02-9e5e-344882630aac

func ReadLogin7Packet

func ReadLogin7Packet(r io.Reader) (*Login7Packet, error)

ReadLogin7Packet reads Login7 packet from the reader.

func (*Login7Packet) Database

func (p *Login7Packet) Database() string

Database returns the database from the Login7 packet. May be empty.

func (*Login7Packet) OptionFlags1

func (p *Login7Packet) OptionFlags1() uint8

OptionFlags1 returns the packet's first set of option flags.

func (*Login7Packet) OptionFlags2

func (p *Login7Packet) OptionFlags2() uint8

OptionFlags2 returns the packet's second set of option flags.

func (*Login7Packet) PacketSize

func (p *Login7Packet) PacketSize() uint16

PacketSize return the packet size from the Login7 packet. Packet size is used by a server to negation the size of max packet length.

func (*Login7Packet) TypeFlags

func (p *Login7Packet) TypeFlags() uint8

TypeFlags returns the packet's set of type flags.

func (*Login7Packet) Username

func (p *Login7Packet) Username() string

Username returns the username from the Login7 packet.

type Packet

type Packet interface {
	// Bytes returns whole packet bytes.
	Bytes() []byte
	// Data returns packet data without data related to Header.
	Data() []byte
	// Header returns packet Header definition.
	Header() PacketHeader
	// Type returns packet type ID.
	Type() uint8
}

Packet is a packet interface.

func ToSQLPacket

func ToSQLPacket(p *BasicPacket) (out Packet, err error)

ToSQLPacket tries to convert basicPacket to MSServer SQL packet.

type PacketHeader

type PacketHeader struct {
	Type     uint8
	Status   uint8
	Length   uint16 // network byte order (big-endian)
	SPID     uint16 // network byte order (big-endian)
	PacketID uint8
	Window   uint8
}

PacketHeader represents a 8-byte packet header.

https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-tds/7af53667-1b72-4703-8258-7984e838f746

Note: the order of fields in the struct matters as it gets unpacked from the binary stream.

func (*PacketHeader) Marshal

func (h *PacketHeader) Marshal() ([]byte, error)

Marshal marshals the packet header to the wire protocol byte representation.

type PreLoginPacket

type PreLoginPacket struct {
	// contains filtered or unexported fields
}

PreLoginPacket represents a Pre-Login packet which is sent by the client to set up context for login.

https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-tds/60f56408-0188-4cd5-8b90-25c6f2423868

func ReadPreLoginPacket

func ReadPreLoginPacket(r io.Reader) (*PreLoginPacket, error)

ReadPreLoginPacket reads Pre-Login packet from the reader.

type RPCRequest

type RPCRequest struct {
	Packet
	// ProcName contains name of the procedure to be executed.
	ProcName string
	// Parameters contains list of RPC parameters.
	Parameters []string
}

RPCRequest defines client RPC Request packet: https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-tds/619c43b6-9495-4a58-9e49-a4950db245b3

type SQLBatch

type SQLBatch struct {
	Packet
	// SQLText contains text batch query.
	SQLText string
}

SQLBatch is a representation of MSServer SQL Batch packet. https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-tds/f2026cd3-9a46-4a3f-9a08-f63140bcbbe3

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL