syscall.go 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. // Copyright 2015 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. // +build windows
  5. package sspi
  6. import (
  7. "syscall"
  8. )
  9. const (
  10. SEC_E_OK = syscall.Errno(0)
  11. SEC_I_COMPLETE_AND_CONTINUE = syscall.Errno(590612)
  12. SEC_I_COMPLETE_NEEDED = syscall.Errno(590611)
  13. SEC_I_CONTINUE_NEEDED = syscall.Errno(590610)
  14. SEC_E_LOGON_DENIED = syscall.Errno(0x8009030c)
  15. SEC_E_CONTEXT_EXPIRED = syscall.Errno(0x80090317) // not sure if the value is valid
  16. SEC_E_INCOMPLETE_MESSAGE = syscall.Errno(0x80090318)
  17. NTLMSP_NAME = "NTLM"
  18. MICROSOFT_KERBEROS_NAME = "Kerberos"
  19. NEGOSSP_NAME = "Negotiate"
  20. UNISP_NAME = "Microsoft Unified Security Protocol Provider"
  21. _SECPKG_ATTR_SIZES = 0
  22. _SECPKG_ATTR_NAMES = 1
  23. _SECPKG_ATTR_LIFESPAN = 2
  24. _SECPKG_ATTR_DCE_INFO = 3
  25. _SECPKG_ATTR_STREAM_SIZES = 4
  26. _SECPKG_ATTR_KEY_INFO = 5
  27. _SECPKG_ATTR_AUTHORITY = 6
  28. _SECPKG_ATTR_PROTO_INFO = 7
  29. _SECPKG_ATTR_PASSWORD_EXPIRY = 8
  30. _SECPKG_ATTR_SESSION_KEY = 9
  31. _SECPKG_ATTR_PACKAGE_INFO = 10
  32. _SECPKG_ATTR_USER_FLAGS = 11
  33. _SECPKG_ATTR_NEGOTIATION_INFO = 12
  34. _SECPKG_ATTR_NATIVE_NAMES = 13
  35. _SECPKG_ATTR_FLAGS = 14
  36. )
  37. type SecPkgInfo struct {
  38. Capabilities uint32
  39. Version uint16
  40. RPCID uint16
  41. MaxToken uint32
  42. Name *uint16
  43. Comment *uint16
  44. }
  45. type _SecPkgContext_Sizes struct {
  46. MaxToken uint32
  47. MaxSignature uint32
  48. BlockSize uint32
  49. SecurityTrailer uint32
  50. }
  51. //sys QuerySecurityPackageInfo(pkgname *uint16, pkginfo **SecPkgInfo) (ret syscall.Errno) = secur32.QuerySecurityPackageInfoW
  52. //sys FreeContextBuffer(buf *byte) (ret syscall.Errno) = secur32.FreeContextBuffer
  53. const (
  54. SECPKG_CRED_INBOUND = 1
  55. SECPKG_CRED_OUTBOUND = 2
  56. SECPKG_CRED_BOTH = (SECPKG_CRED_OUTBOUND | SECPKG_CRED_INBOUND)
  57. SEC_WINNT_AUTH_IDENTITY_UNICODE = 0x2
  58. )
  59. type SEC_WINNT_AUTH_IDENTITY struct {
  60. User *uint16
  61. UserLength uint32
  62. Domain *uint16
  63. DomainLength uint32
  64. Password *uint16
  65. PasswordLength uint32
  66. Flags uint32
  67. }
  68. type LUID struct {
  69. LowPart uint32
  70. HighPart int32
  71. }
  72. type CredHandle struct {
  73. Lower uintptr
  74. Upper uintptr
  75. }
  76. //sys AcquireCredentialsHandle(principal *uint16, pkgname *uint16, creduse uint32, logonid *LUID, authdata *byte, getkeyfn uintptr, getkeyarg uintptr, handle *CredHandle, expiry *syscall.Filetime) (ret syscall.Errno) = secur32.AcquireCredentialsHandleW
  77. //sys FreeCredentialsHandle(handle *CredHandle) (ret syscall.Errno) = secur32.FreeCredentialsHandle
  78. const (
  79. SECURITY_NATIVE_DREP = 16
  80. SECBUFFER_DATA = 1
  81. SECBUFFER_TOKEN = 2
  82. SECBUFFER_PKG_PARAMS = 3
  83. SECBUFFER_MISSING = 4
  84. SECBUFFER_EXTRA = 5
  85. SECBUFFER_STREAM_TRAILER = 6
  86. SECBUFFER_STREAM_HEADER = 7
  87. SECBUFFER_PADDING = 9
  88. SECBUFFER_STREAM = 10
  89. SECBUFFER_READONLY = 0x80000000
  90. SECBUFFER_ATTRMASK = 0xf0000000
  91. SECBUFFER_VERSION = 0
  92. SECBUFFER_EMPTY = 0
  93. ISC_REQ_DELEGATE = 1
  94. ISC_REQ_MUTUAL_AUTH = 2
  95. ISC_REQ_REPLAY_DETECT = 4
  96. ISC_REQ_SEQUENCE_DETECT = 8
  97. ISC_REQ_CONFIDENTIALITY = 16
  98. ISC_REQ_USE_SESSION_KEY = 32
  99. ISC_REQ_PROMPT_FOR_CREDS = 64
  100. ISC_REQ_USE_SUPPLIED_CREDS = 128
  101. ISC_REQ_ALLOCATE_MEMORY = 256
  102. ISC_REQ_USE_DCE_STYLE = 512
  103. ISC_REQ_DATAGRAM = 1024
  104. ISC_REQ_CONNECTION = 2048
  105. ISC_REQ_EXTENDED_ERROR = 16384
  106. ISC_REQ_STREAM = 32768
  107. ISC_REQ_INTEGRITY = 65536
  108. ISC_REQ_MANUAL_CRED_VALIDATION = 524288
  109. ISC_REQ_HTTP = 268435456
  110. ASC_REQ_DELEGATE = 1
  111. ASC_REQ_MUTUAL_AUTH = 2
  112. ASC_REQ_REPLAY_DETECT = 4
  113. ASC_REQ_SEQUENCE_DETECT = 8
  114. ASC_REQ_CONFIDENTIALITY = 16
  115. ASC_REQ_USE_SESSION_KEY = 32
  116. ASC_REQ_ALLOCATE_MEMORY = 256
  117. ASC_REQ_USE_DCE_STYLE = 512
  118. ASC_REQ_DATAGRAM = 1024
  119. ASC_REQ_CONNECTION = 2048
  120. ASC_REQ_EXTENDED_ERROR = 32768
  121. ASC_REQ_STREAM = 65536
  122. ASC_REQ_INTEGRITY = 131072
  123. )
  124. type CtxtHandle struct {
  125. Lower uintptr
  126. Upper uintptr
  127. }
  128. type SecBuffer struct {
  129. BufferSize uint32
  130. BufferType uint32
  131. Buffer *byte
  132. }
  133. type SecBufferDesc struct {
  134. Version uint32
  135. BuffersCount uint32
  136. Buffers *SecBuffer
  137. }
  138. //sys InitializeSecurityContext(credential *CredHandle, context *CtxtHandle, targname *uint16, contextreq uint32, reserved1 uint32, targdatarep uint32, input *SecBufferDesc, reserved2 uint32, newcontext *CtxtHandle, output *SecBufferDesc, contextattr *uint32, expiry *syscall.Filetime) (ret syscall.Errno) = secur32.InitializeSecurityContextW
  139. //sys AcceptSecurityContext(credential *CredHandle, context *CtxtHandle, input *SecBufferDesc, contextreq uint32, targdatarep uint32, newcontext *CtxtHandle, output *SecBufferDesc, contextattr *uint32, expiry *syscall.Filetime) (ret syscall.Errno) = secur32.AcceptSecurityContext
  140. //sys CompleteAuthToken(context *CtxtHandle, token *SecBufferDesc) (ret syscall.Errno) = secur32.CompleteAuthToken
  141. //sys DeleteSecurityContext(context *CtxtHandle) (ret syscall.Errno) = secur32.DeleteSecurityContext
  142. //sys ImpersonateSecurityContext(context *CtxtHandle) (ret syscall.Errno) = secur32.ImpersonateSecurityContext
  143. //sys RevertSecurityContext(context *CtxtHandle) (ret syscall.Errno) = secur32.RevertSecurityContext
  144. //sys QueryContextAttributes(context *CtxtHandle, attribute uint32, buf *byte) (ret syscall.Errno) = secur32.QueryContextAttributesW
  145. //sys EncryptMessage(context *CtxtHandle, qop uint32, message *SecBufferDesc, messageseqno uint32) (ret syscall.Errno) = secur32.EncryptMessage
  146. //sys DecryptMessage(context *CtxtHandle, message *SecBufferDesc, messageseqno uint32, qop *uint32) (ret syscall.Errno) = secur32.DecryptMessage
  147. //sys ApplyControlToken(context *CtxtHandle, input *SecBufferDesc) (ret syscall.Errno) = secur32.ApplyControlToken
  148. //sys MakeSignature(context *CtxtHandle, qop uint32, message *SecBufferDesc, messageseqno uint32) (ret syscall.Errno) = secur32.MakeSignature
  149. //sys VerifySignature(context *CtxtHandle, message *SecBufferDesc, messageseqno uint32, qop *uint32) (ret syscall.Errno) = secur32.VerifySignature