mirror of
https://github.com/gravitational/teleport.git
synced 2026-11-01 05:27:24 +08:00
* refactor(sqlserver): change to microsoft fork * chore(gomod): update mssqldb dep * test(sqlserver): add server on parsing PLP RPC packets * fix(db): change mssql import * chore(gomod): update go-mssqldb reference * test(protocol): use fuzz arguments * chore: code review suggestions * test(sqlserver): add missing protocols attribute
62 lines
1.4 KiB
Go
62 lines
1.4 KiB
Go
/*
|
|
Copyright 2022 Gravitational, Inc.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package protocol
|
|
|
|
import (
|
|
"io"
|
|
|
|
"github.com/gravitational/trace"
|
|
mssql "github.com/microsoft/go-mssqldb"
|
|
)
|
|
|
|
// WriteStreamResponse writes stream response packet to the writer.
|
|
func WriteStreamResponse(w io.Writer, tokens []mssql.Token) error {
|
|
var data []byte
|
|
|
|
for _, token := range tokens {
|
|
bytes, err := token.Marshal()
|
|
if err != nil {
|
|
return trace.Wrap(err)
|
|
}
|
|
data = append(data, bytes...)
|
|
}
|
|
|
|
pkt, err := makePacket(PacketTypeResponse, data)
|
|
if err != nil {
|
|
return trace.Wrap(err)
|
|
}
|
|
|
|
_, err = w.Write(pkt)
|
|
if err != nil {
|
|
return trace.Wrap(err)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// WriteErrorResponse writes error response to the client.
|
|
func WriteErrorResponse(w io.Writer, err error) error {
|
|
return WriteStreamResponse(w, []mssql.Token{
|
|
&mssql.Error{
|
|
Number: errorNumber,
|
|
Class: errorClassSecurity,
|
|
Message: err.Error(),
|
|
},
|
|
mssql.DoneToken(),
|
|
})
|
|
}
|