Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

216 lines
5.2 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright(C) 2002 Microsoft Corporation
  5. //
  6. // File: security.hxx
  7. //
  8. //----------------------------------------------------------------------------
  9. #ifndef __TASKSCHED_SVC_CORE_SECURITY__H_
  10. #define __TASKSCHED_SVC_CORE_SECURITY__H_
  11. //
  12. // These includes are needed to define the types and
  13. // values used in the function declarations below
  14. //
  15. #include <wincrypt.h>
  16. #include <rc2.h> // found in private\inc\crypto
  17. #include "lsa.hxx"
  18. #include "debug.hxx"
  19. #include "task.hxx"
  20. #include "proto.hxx"
  21. #include "misc.hxx"
  22. #include "SASecRPC.h"
  23. //
  24. // Defines and typedefs
  25. //
  26. #define EXTENSION_WILDCARD L"\\*."
  27. #define NULL_PASSWORD_SIZE 0xFFFFFFFF
  28. #define WSZ_SANSC L"SANSC"
  29. #define USER_TOKEN_STACK_BUFFER_SIZE \
  30. (sizeof(TOKEN_USER) + sizeof(SID_AND_ATTRIBUTES) + MAX_SID_SIZE)
  31. // header files say '256' - help files say 127
  32. // testing shows 127 is the real number
  33. #define REAL_PWLEN 127
  34. #if SIGNATURE_SIZE != HASH_DATA_SIZE
  35. #error SIGNATURE_SIZE is assumed to be the same as HASH_DATA_SIZE
  36. #endif
  37. typedef enum _MARSHAL_FUNCTION {
  38. Marshal,
  39. Hash,
  40. HashAndSign
  41. } MARSHAL_FUNCTION;
  42. typedef struct _RC2_KEY_INFO {
  43. BYTE rgbIV[RC2_BLOCKLEN];
  44. WORD rgwKeyTable[RC2_TABLESIZE];
  45. } RC2_KEY_INFO;
  46. typedef struct _JOB_IDENTITY_SET {
  47. BYTE * pbSetStart;
  48. DWORD dwSetSubCount;
  49. BYTE ** rgpbIdentity;
  50. } JOB_IDENTITY_SET;
  51. //
  52. // Security functions
  53. //
  54. void CloseCSPHandle(
  55. HCRYPTPROV hCSP);
  56. HRESULT ComputeCredentialKey(
  57. HCRYPTPROV hCSP,
  58. RC2_KEY_INFO* pRC2KeyInfo);
  59. HRESULT ComputeJobSignature(
  60. LPCWSTR pwszFileName,
  61. LPBYTE pbSignature,
  62. DWORD dwHashMethod = 1);
  63. BOOL CredentialAccessCheck(
  64. HCRYPTPROV hCSP,
  65. BYTE * pbCredentialIdentity);
  66. HRESULT CredentialLookupAndAccessCheck(
  67. HCRYPTPROV hCSP,
  68. PSID pSid,
  69. DWORD cbSAC,
  70. BYTE * pbSAC,
  71. DWORD * pCredentialIndex,
  72. BYTE rgbHashedSid[],
  73. DWORD * pcbCredential,
  74. BYTE ** ppbCredential);
  75. HRESULT DecryptCredentials(
  76. const RC2_KEY_INFO & RC2KeyInfo,
  77. DWORD cbEncryptedData,
  78. BYTE * pbEncryptedData,
  79. PJOB_CREDENTIALS pjc,
  80. BOOL fDecryptInPlace = TRUE);
  81. HRESULT EncryptCredentials(
  82. const RC2_KEY_INFO & RC2KeyInfo,
  83. LPCWSTR pwszAccount,
  84. LPCWSTR pwszDomain,
  85. LPCWSTR pwszPassword,
  86. PSID pSid,
  87. DWORD * pcbEncryptedData,
  88. BYTE ** ppbEncryptedData);
  89. HRESULT GetAccountInformation(
  90. LPCWSTR pwszJobPath,
  91. PJOB_CREDENTIALS pjc);
  92. HRESULT GetAccountSidAndDomain(
  93. LPCWSTR pwszAccount,
  94. PSID pAccountSid,
  95. DWORD cbAccountSid,
  96. LPWSTR pwszDomain,
  97. DWORD ccDomain);
  98. HRESULT GetCSPHandle(
  99. HCRYPTPROV * phCSP);
  100. HRESULT GetNSAccountInformation(
  101. PJOB_CREDENTIALS pjc);
  102. HRESULT GetNSAccountSid(
  103. PSID pAccountSid,
  104. DWORD cbAccountSid);
  105. HRESULT GrantAccountBatchPrivilege(
  106. PSID pAccountSid);
  107. HRESULT HashJobIdentity(
  108. HCRYPTPROV hCSP,
  109. LPCWSTR pwszFileName,
  110. BYTE rgbHash[],
  111. DWORD dwHashMethod = 1);
  112. HRESULT HashSid(
  113. HCRYPTPROV hCSP,
  114. PSID pSid,
  115. BYTE rgbHash[]);
  116. HRESULT InitSS(void);
  117. BOOL LookupAccountNameWrap(
  118. LPCTSTR lpSystemName,
  119. LPCTSTR lpAccountName,
  120. PSID Sid,
  121. LPDWORD cbSid,
  122. LPTSTR ReferencedDomainName,
  123. LPDWORD cbReferencedDomainName,
  124. PSID_NAME_USE peUse);
  125. HRESULT MarshalData(
  126. HCRYPTPROV hCSP,
  127. HCRYPTHASH * phHash,
  128. MARSHAL_FUNCTION MarshalFunction,
  129. DWORD * pcbSignature,
  130. BYTE ** ppbSignature,
  131. DWORD cArgs,
  132. ...);
  133. BOOL MatchThreadCallerAgainstCredential(
  134. HCRYPTPROV hCSP,
  135. HANDLE hThreadToken,
  136. BYTE * pbCredentialIdentity);
  137. void MungeComputerName(
  138. DWORD ccComputerName);
  139. HRESULT SAGetAccountInformation(
  140. SASEC_HANDLE Handle,
  141. LPCWSTR pwszJobName,
  142. DWORD ccBufferSize,
  143. WCHAR wszBuffer[]);
  144. HRESULT SAGetNSAccountInformation(
  145. SASEC_HANDLE Handle,
  146. DWORD ccBufferSize,
  147. WCHAR wszBuffer[]);
  148. HRESULT SASetAccountInformation(
  149. SASEC_HANDLE Handle,
  150. LPCWSTR pwszJobName,
  151. LPCWSTR pwszAccount,
  152. LPCWSTR pwszPassword,
  153. DWORD dwJobFlags);
  154. HRESULT SASetNSAccountInformation(
  155. SASEC_HANDLE Handle,
  156. LPCWSTR pwszAccount,
  157. LPCWSTR pwszPassword);
  158. HRESULT SaveJobCredentials(
  159. LPCWSTR pwszJobPath,
  160. LPCWSTR pwszAccount,
  161. LPCWSTR pwszDomain,
  162. LPCWSTR pwszPassword,
  163. PSID pAccountSid);
  164. void ScavengeSASecurityDBase(void);
  165. DWORD SchedUPNToAccountName(
  166. IN LPCWSTR lpUPN,
  167. OUT LPWSTR *ppAccountName
  168. );
  169. LPWSTR SkipDomainName(
  170. LPCWSTR pwszUserName);
  171. void UninitSS(void);
  172. bool ValidateRunAs(
  173. LPCWSTR pwszAccount,
  174. LPCWSTR pwszDomain,
  175. LPCWSTR pwszPassword);
  176. #endif // __TASKSCHED_SVC_CORE_SECURITY__H_