oracle

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2026 License: AGPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DumpDirClientToServer byte = 0
	DumpDirServerToClient byte = 1
)

Dump packet direction constants.

View Source
const (
	PiggybackSubClose   byte = 0x09 // Close cursor
	PiggybackSubExecSQL byte = 0x5e // Execute with SQL (OALL8 equivalent)
	PiggybackSubAuth1   byte = 0x76 // AUTH Phase 1
	PiggybackSubAuth2   byte = 0x73 // AUTH Phase 2
)

Piggyback sub-operation codes (byte 1 when func=0x03).

View Source
const (
	OracleTypeVARCHAR2     uint8 = 1
	OracleTypeNUMBER       uint8 = 2
	OracleTypeDATE         uint8 = 12
	OracleTypeRAW          uint8 = 23
	OracleTypeCHAR         uint8 = 96
	OracleTypeBINFLOAT     uint8 = 100
	OracleTypeBINDOUBLE    uint8 = 101
	OracleTypeCLOB         uint8 = 112
	OracleTypeBLOB         uint8 = 113
	OracleTypeTIMESTAMP    uint8 = 180
	OracleTypeTIMESTAMPTZ  uint8 = 181
	OracleTypeTIMESTAMPLTZ uint8 = 231
)

Oracle data type codes.

Variables

View Source
var (
	// ErrEmptyUsername indicates an AUTH message with no username.
	ErrEmptyUsername = errors.New("empty username in AUTH message")
	// ErrNoActiveGrant indicates no active grant exists for the user/database pair.
	ErrNoActiveGrant = errors.New("no active grant for this user/database")
	// ErrQueryLimitExceed indicates the grant's query count quota has been reached.
	ErrQueryLimitExceed = errors.New("query limit exceeded")
	// ErrDataLimitExceed indicates the grant's data transfer quota has been reached.
	ErrDataLimitExceed = errors.New("data transfer limit exceeded")
	// ErrDatabaseNotFound indicates the requested database was not found in the store.
	ErrDatabaseNotFound = errors.New("database not found")
	// ErrUserNotFound indicates the requested user was not found in the store.
	ErrUserNotFound = errors.New("user not found")

	// ErrTTCPayloadTooShort indicates a TTC payload is shorter than expected.
	ErrTTCPayloadTooShort = errors.New("TTC payload too short")
	// ErrNotDataPacket indicates a non-Data TNS packet was received where Data was expected.
	ErrNotDataPacket = errors.New("expected TNS Data packet")
	// ErrAuthFailed indicates upstream authentication did not succeed.
	ErrAuthFailed = errors.New("upstream authentication failed")

	// ErrExpectedConnectPacket indicates a non-Connect packet was received at session start.
	ErrExpectedConnectPacket = errors.New("expected TNS Connect packet")
	// ErrNoServiceName indicates the connect descriptor lacks a SERVICE_NAME.
	ErrNoServiceName = errors.New("no SERVICE_NAME in connect descriptor")
	// ErrUpstreamRefused indicates the upstream Oracle server refused the connection.
	ErrUpstreamRefused = errors.New("upstream refused connection")

	// ErrColumnDefTooShort indicates a column definition is shorter than expected.
	ErrColumnDefTooShort = errors.New("column definition too short")
	// ErrColumnNameTruncated indicates a column name extends beyond the payload.
	ErrColumnNameTruncated = errors.New("column name exceeds payload")
	// ErrNoTypeCode indicates a column definition is missing the type code byte.
	ErrNoTypeCode = errors.New("column definition missing type code")
	// ErrEmptyRowData indicates an empty row data payload.
	ErrEmptyRowData = errors.New("empty row data")
	// ErrRowValueTruncated indicates a row value extends beyond the payload.
	ErrRowValueTruncated = errors.New("row value exceeds payload")
	// ErrInvalidFloatLength indicates float data has an unexpected length.
	ErrInvalidFloatLength = errors.New("invalid float data length")
)

Oracle proxy errors.

View Source
var (
	ErrTNSHeaderTooShort = errors.New("TNS header too short: need at least 8 bytes")
	ErrTNSPacketTooLarge = errors.New("TNS packet length exceeds maximum")
)

TNS errors.

View Source
var (
	ErrEmptySQL         = errors.New("OALL8 message contains empty SQL")
	ErrOALL8TooShort    = errors.New("OALL8 payload too short")
	ErrOFETCHTooShort   = errors.New("OFETCH payload too short")
	ErrSQLLengthInvalid = errors.New("OALL8 SQL length exceeds payload")
)

Decoding errors.

View Source
var (
	ErrInvalidDateLength      = errors.New("oracle DATE requires exactly 7 bytes")
	ErrInvalidTimestampLength = errors.New("oracle TIMESTAMP requires at least 11 bytes")
	ErrInvalidNumberData      = errors.New("oracle NUMBER data is empty")
)

Type decoding errors.

View Source
var (
	ErrInvalidDumpMagic = errors.New("invalid dump file magic")
)

Dump reader errors.

Functions

func CleanupOldDumps

func CleanupOldDumps(dir string, retention time.Duration) (int, error)

CleanupOldDumps deletes dump files older than the retention period. Returns the number of files deleted.

func IsPiggybackClose

func IsPiggybackClose(ttcPayload []byte) bool

IsPiggybackClose checks if a piggyback payload is a close cursor message.

func IsPiggybackExecSQL

func IsPiggybackExecSQL(ttcPayload []byte) bool

IsPiggybackExecSQL checks if a piggyback payload is an execute-with-SQL message.

Types

type ConnectDescriptor

type ConnectDescriptor struct {
	ServiceName string
	SID         string
	Host        string
	Port        int
	Program     string // From CID
	OSUser      string // From CID
}

ConnectDescriptor holds metadata parsed from an Oracle connect descriptor.

type DumpHeader

type DumpHeader struct {
	Version      uint16
	SessionUID   uuid.UUID
	ServiceName  string
	UpstreamAddr string
	StartTime    time.Time
}

DumpHeader holds metadata from a dump file header.

type DumpPacket

type DumpPacket struct {
	RelativeNs int64
	Direction  byte // 0=C->S, 1=S->C, 0xFF=EOF
	Data       []byte
}

DumpPacket represents a single captured packet.

type DumpReader

type DumpReader struct {
	Header DumpHeader
	// contains filtered or unexported fields
}

DumpReader reads packets from a dump file.

func OpenDump

func OpenDump(path string) (*DumpReader, error)

OpenDump opens a dump file for reading.

func (*DumpReader) Close

func (r *DumpReader) Close() error

Close closes the dump reader.

func (*DumpReader) ReadPacket

func (r *DumpReader) ReadPacket() (*DumpPacket, error)

ReadPacket reads the next packet from the dump. Returns io.EOF when the EOF marker is reached.

type DumpWriter

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

DumpWriter writes TNS packet dumps to a binary file.

func NewDumpWriter

func NewDumpWriter(path string, sessionUID uuid.UUID, serviceName, upstreamAddr string, maxSize int64) (*DumpWriter, error)

NewDumpWriter creates a new dump file and writes the header.

func (*DumpWriter) Close

func (w *DumpWriter) Close() error

Close writes the EOF marker and closes the file.

func (*DumpWriter) WritePacket

func (w *DumpWriter) WritePacket(direction byte, data []byte) error

WritePacket writes a single TNS packet to the dump file. direction: 0 = client->upstream, 1 = upstream->client

type OALL8Result

type OALL8Result struct {
	SQL        string
	CursorID   uint16
	BindValues []string
}

OALL8Result contains the decoded fields from an OALL8 (parse+execute) message.

func (*OALL8Result) IsPLSQL

func (r *OALL8Result) IsPLSQL() bool

IsPLSQL returns true if the SQL text is a PL/SQL block.

type OFETCHResult

type OFETCHResult struct {
	CursorID  uint16
	FetchSize uint32
}

OFETCHResult contains the decoded fields from an OFETCH message.

type QueryResultV2

type QueryResultV2 struct {
	Columns []string
	Rows    [][]string
	NoData  bool // true if ORA-01403 (normal end-of-data)
}

QueryResultV2 contains parsed data from a v315+ TTC QueryResult (func=0x10).

type Server

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

Server is the Oracle proxy server.

func NewServer

func NewServer(
	dataStore *store.Store,
	encryptionKey []byte,
	authCache *cache.AuthCache,
	queryStorage config.QueryStorageConfig,
	dumpConfig config.OracleDumpConfig,
	logger *slog.Logger,
) *Server

NewServer creates a new Oracle proxy server.

func (*Server) Addr

func (s *Server) Addr() net.Addr

Addr returns the listener address, useful for tests with ":0" port.

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

Shutdown gracefully shuts down the server.

func (*Server) Start

func (s *Server) Start(addr string) error

Start starts the Oracle proxy server.

type TNSPacket

type TNSPacket struct {
	Type    TNSPacketType
	Flags   byte
	Length  uint16
	Payload []byte
	Raw     []byte // Original raw bytes (for forwarding without re-encoding)
}

TNSPacket represents a single TNS protocol packet.

func (*TNSPacket) Encode

func (p *TNSPacket) Encode() []byte

Encode encodes the packet into a byte slice (convenience method).

type TNSPacketType

type TNSPacketType byte

TNSPacketType represents a TNS packet type code.

const (
	TNSPacketTypeConnect  TNSPacketType = 1
	TNSPacketTypeAccept   TNSPacketType = 2
	TNSPacketTypeRefuse   TNSPacketType = 3
	TNSPacketTypeRedirect TNSPacketType = 4
	TNSPacketTypeMarker   TNSPacketType = 5
	TNSPacketTypeData     TNSPacketType = 6
	TNSPacketTypeResend   TNSPacketType = 11
	TNSPacketTypeControl  TNSPacketType = 12
)

TNS packet type codes.

func (TNSPacketType) String

func (t TNSPacketType) String() string

String returns a human-readable name for the packet type.

type TTCFunctionCode

type TTCFunctionCode byte

TTCFunctionCode represents a TTC function code inside a TNS Data packet. TTC (Two-Task Common) is Oracle's RPC protocol layered inside TNS Data packets.

Layout of a TNS Data packet payload:

Offset  Size  Field
0       2     Data flags (usually 0x0000)
2       1     TTC function code
3       ...   Function-specific payload
const (
	TTCFuncSetProtocol  TTCFunctionCode = 0x01 // OSETPRO — session init
	TTCFuncSetDataTypes TTCFunctionCode = 0x02 // ODTYPES — session init
	TTCFuncPiggyback    TTCFunctionCode = 0x03 // Generic piggyback (sub-op at byte 1)
	TTCFuncOCLOSE       TTCFunctionCode = 0x05 // OCLOSE — close cursor (legacy)
	TTCFuncResponse     TTCFunctionCode = 0x08 // Server response
	TTCFuncOClosev2     TTCFunctionCode = 0x09 // OCLOSE — close cursor (v315+)
	TTCFuncOVersion     TTCFunctionCode = 0x0B // OVERSION — version request
	TTCFuncOALL8        TTCFunctionCode = 0x0E // OALL8 — parse+execute (legacy)
	TTCFuncQueryResult  TTCFunctionCode = 0x10 // Query result with row data
	TTCFuncOFETCH       TTCFunctionCode = 0x11 // OFETCH — fetch rows
	TTCFuncOCANCEL      TTCFunctionCode = 0x14 // OCANCEL — cancel query
)

TTC function codes for Oracle's Two-Task Common protocol. In modern Oracle (v315+), function 0x03 is a generic "piggyback" that carries sub-operations (auth, execute, close, etc.) identified by byte 1.

func (TTCFunctionCode) String

func (fc TTCFunctionCode) String() string

String returns a human-readable name for the TTC function code.

type TTCResponse

type TTCResponse struct {
	ReturnCode   uint16
	RowCount     uint32
	Columns      []columnDef
	Rows         [][]interface{}
	MoreData     bool
	IsError      bool
	ErrorCode    int
	ErrorMessage string
}

TTCResponse contains decoded fields from a TTC Response message.

Jump to

Keyboard shortcuts

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