// NewClientContext creates new client context. It uses client // credentials cred generated by AcquireCurrentUserCredentials or // AcquireUserCredentials and SPN to start client Negotiate // negotiation sequence. targetName is the service principal name // (SPN) or the security context of the destination server. // NewClientContext returns new token to be sent to the server. func NewClientContext(cred *sspi.Credentials, targetName string) (cc *ClientContext, outputToken []byte, err error) { var tname *uint16 if len(targetName) > 0 { p, err2 := syscall.UTF16FromString(targetName) if err2 != nil { return nil, nil, err2 } if len(p) > 0 { tname = &p[0] } } otoken := make([]byte, PackageInfo.MaxToken) c := sspi.NewClientContext(cred, sspi.ISC_REQ_CONNECTION) authCompleted, n, err2 := updateContext(c, otoken, nil, tname) if err2 != nil { return nil, nil, err2 } if authCompleted { c.Release() return nil, nil, errors.New("negotiate authentication should not be completed yet") } if n == 0 { c.Release() return nil, nil, errors.New("negotiate token should not be empty") } otoken = otoken[:n] return &ClientContext{sctxt: c, targetName: tname}, otoken, nil }
func NewClientContext(cred *sspi.Credentials, conn io.ReadWriter) *Client { return &Client{ ctx: sspi.NewClientContext(cred, sspi.ISC_REQ_STREAM|sspi.ISC_REQ_ALLOCATE_MEMORY|sspi.ISC_REQ_EXTENDED_ERROR|sspi.ISC_REQ_MANUAL_CRED_VALIDATION), conn: conn, // TODO: decide how large this buffer needs to be (it cannot be too small otherwise messages won't fit) inbuf: newInputBuffer(1000, conn), } }
// NewClientContext creates new client context. It uses client // credentials cred generated by AcquireCurrentUserCredentials or // AcquireUserCredentials and, if successful, outputs negotiate // message. Negotiate message needs to be sent to the server to // start NTLM negotiation sequence. func NewClientContext(cred *sspi.Credentials) (*ClientContext, []byte, error) { negotiate := make([]byte, PackageInfo.MaxToken) c := sspi.NewClientContext(cred, sspi.ISC_REQ_CONNECTION) authCompleted, n, err := updateContext(c, negotiate, nil) if err != nil { return nil, nil, err } if authCompleted { c.Release() return nil, nil, errors.New("ntlm authentication should not be completed yet") } if n == 0 { c.Release() return nil, nil, errors.New("ntlm token should not be empty") } negotiate = negotiate[:n] return &ClientContext{sctxt: c}, negotiate, nil }