Skip to content

Commit

Permalink
fix TCP read
Browse files Browse the repository at this point in the history
  • Loading branch information
jcmturner committed Nov 16, 2017
1 parent f23eb64 commit 5cf868a
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions client/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"gopkg.in/jcmturner/gokrb5.v2/iana/errorcode"
"gopkg.in/jcmturner/gokrb5.v2/messages"
"io"
"math/rand"
"net"
"time"
Expand Down Expand Up @@ -154,10 +153,21 @@ func sendTCP(kdc string, b []byte) ([]byte, error) {
if err != nil {
return r, fmt.Errorf("Error sending to KDC: %v", err)
}
var rBuf bytes.Buffer
io.Copy(&rBuf, conn)
r = rBuf.Bytes()
return checkForKRBError(r[4:])

sh := make([]byte, 4, 4)
_, err = conn.Read(sh)
if err != nil {
return r, fmt.Errorf("error reading response size header: %v", err)
}
s := binary.BigEndian.Uint32(sh)

rb := make([]byte, s, s)
_, err = conn.Read(rb)
if err != nil {
return r, fmt.Errorf("error reading response: %v", err)
}

return checkForKRBError(rb)
}

func checkForKRBError(b []byte) ([]byte, error) {
Expand Down

0 comments on commit 5cf868a

Please sign in to comment.