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.

232 lines
6.3 KiB

  1. #include "stdafx.h"
  2. #include "common.h"
  3. #include "coauth.h"
  4. #ifdef _DEBUG
  5. #undef THIS_FILE
  6. static char BASED_CODE THIS_FILE[] = __FILE__;
  7. #endif
  8. #define new DEBUG_NEW
  9. BOOL
  10. EqualAuthInfo(
  11. COAUTHINFO* pAuthInfo,
  12. COAUTHINFO* pAuthInfoOther)
  13. {
  14. if ( pAuthInfo && pAuthInfoOther )
  15. {
  16. if ( (pAuthInfo->dwAuthnSvc != pAuthInfoOther->dwAuthnSvc) ||
  17. (pAuthInfo->dwAuthzSvc != pAuthInfoOther->dwAuthzSvc) ||
  18. (pAuthInfo->dwAuthnLevel != pAuthInfoOther->dwAuthnLevel) ||
  19. (pAuthInfo->dwImpersonationLevel != pAuthInfoOther->dwImpersonationLevel) ||
  20. (pAuthInfo->dwCapabilities != pAuthInfoOther->dwCapabilities) )
  21. {
  22. return FALSE;
  23. }
  24. // only compare pwszServerPrincName's if they're both specified
  25. if (pAuthInfo->pwszServerPrincName && pAuthInfoOther->pwszServerPrincName)
  26. {
  27. if ( lstrcmpW(pAuthInfo->pwszServerPrincName,
  28. pAuthInfoOther->pwszServerPrincName) != 0 )
  29. {
  30. return FALSE;
  31. }
  32. }
  33. else
  34. {
  35. // if one was NULL, both should be NULL for equality
  36. if (pAuthInfo->pwszServerPrincName != pAuthInfoOther->pwszServerPrincName)
  37. {
  38. return FALSE;
  39. }
  40. }
  41. // we never cache authid, so one of them must be NULL
  42. ASSERT(!(pAuthInfo->pAuthIdentityData && pAuthInfoOther->pAuthIdentityData));
  43. if (pAuthInfo->pAuthIdentityData || pAuthInfoOther->pAuthIdentityData)
  44. {
  45. return FALSE;
  46. }
  47. }
  48. else
  49. {
  50. if ( pAuthInfo != pAuthInfoOther )
  51. {
  52. return FALSE;
  53. }
  54. }
  55. return TRUE;
  56. }
  57. HRESULT
  58. CopyServerInfoStruct(
  59. IN COSERVERINFO * pServerInfoSrc,
  60. IN COSERVERINFO * pServerInfoDest
  61. )
  62. {
  63. HRESULT hr = E_OUTOFMEMORY;
  64. if (pServerInfoSrc == NULL)
  65. {
  66. return S_OK;
  67. }
  68. if (pServerInfoDest == NULL)
  69. {
  70. return E_POINTER;
  71. }
  72. CopyMemory(pServerInfoDest, pServerInfoSrc, sizeof(COSERVERINFO));
  73. // We need to allocate these fields and make a copy
  74. pServerInfoDest->pwszName = NULL;
  75. // only alloc space for pwszServerPrincName if its non-null
  76. if (pServerInfoSrc->pwszName)
  77. {
  78. pServerInfoDest->pwszName =
  79. (LPWSTR) LocalAlloc(LPTR,(lstrlenW(pServerInfoSrc->pwszName) + 1) * sizeof(WCHAR));
  80. if (!pServerInfoDest->pwszName)
  81. goto Cleanup;
  82. lstrcpyW(pServerInfoDest->pwszName, pServerInfoSrc->pwszName);
  83. }
  84. pServerInfoDest->pAuthInfo = NULL;
  85. hr = S_OK;
  86. Cleanup:
  87. return hr;
  88. }
  89. HRESULT
  90. CopyAuthInfoStruct(
  91. IN COAUTHINFO * pAuthInfoSrc,
  92. IN COAUTHINFO * pAuthInfoDest
  93. )
  94. {
  95. HRESULT hr = E_OUTOFMEMORY;
  96. if (pAuthInfoSrc == NULL)
  97. {
  98. return S_OK;
  99. }
  100. if (pAuthInfoDest == NULL)
  101. {
  102. return E_POINTER;
  103. }
  104. CopyMemory(pAuthInfoDest, pAuthInfoSrc, sizeof(COAUTHINFO));
  105. // We need to allocate these fields and make a copy
  106. pAuthInfoDest->pwszServerPrincName = NULL;
  107. pAuthInfoDest->pAuthIdentityData = NULL;
  108. // only alloc space for pwszServerPrincName if its non-null
  109. if (pAuthInfoSrc->pwszServerPrincName)
  110. {
  111. pAuthInfoDest->pwszServerPrincName =
  112. (LPWSTR) LocalAlloc(LPTR,(lstrlenW(pAuthInfoSrc->pwszServerPrincName) + 1) * sizeof(WCHAR));
  113. if (!pAuthInfoDest->pwszServerPrincName)
  114. goto Cleanup;
  115. lstrcpyW(pAuthInfoDest->pwszServerPrincName, pAuthInfoSrc->pwszServerPrincName);
  116. }
  117. pAuthInfoDest->pAuthIdentityData = NULL;
  118. hr = S_OK;
  119. Cleanup:
  120. return hr;
  121. }
  122. HRESULT
  123. CopyAuthIdentityStruct(
  124. IN COAUTHIDENTITY * pAuthIdentSrc,
  125. IN COAUTHIDENTITY * pAuthIdentDest
  126. )
  127. {
  128. HRESULT hr = E_OUTOFMEMORY;
  129. ULONG ulCharLen = 1;
  130. if (pAuthIdentSrc == NULL)
  131. {
  132. hr = E_POINTER;
  133. goto Cleanup;
  134. }
  135. if (pAuthIdentDest == NULL)
  136. {
  137. hr = E_POINTER;
  138. goto Cleanup;
  139. }
  140. // Guard against both being set, although presumably this would have
  141. // caused grief before we got to this point.
  142. if ((pAuthIdentSrc->Flags & SEC_WINNT_AUTH_IDENTITY_UNICODE) &&
  143. (pAuthIdentSrc->Flags & SEC_WINNT_AUTH_IDENTITY_ANSI))
  144. {
  145. ASSERT(0 && "Both string type flags were set!");
  146. hr = E_UNEXPECTED;
  147. goto Cleanup;
  148. }
  149. if (pAuthIdentSrc->Flags & SEC_WINNT_AUTH_IDENTITY_UNICODE)
  150. {
  151. ulCharLen = sizeof(WCHAR);
  152. }
  153. else if (pAuthIdentSrc->Flags & SEC_WINNT_AUTH_IDENTITY_ANSI)
  154. {
  155. ulCharLen = sizeof(CHAR);
  156. }
  157. else
  158. {
  159. // The user didn't specify either string bit? How did we get here?
  160. ASSERT(0 && "String type flag was not set!");
  161. hr = E_UNEXPECTED;
  162. goto Cleanup;
  163. }
  164. CopyMemory(pAuthIdentDest, pAuthIdentSrc, sizeof(COAUTHIDENTITY));
  165. // Strings need to be allocated individually and copied
  166. pAuthIdentDest->User = pAuthIdentDest->Domain = pAuthIdentDest->Password = NULL;
  167. if (pAuthIdentSrc->User)
  168. {
  169. pAuthIdentDest->User = (USHORT *)LocalAlloc(LPTR,(pAuthIdentDest->UserLength+1) * ulCharLen);
  170. if (!pAuthIdentDest->User)
  171. goto Cleanup;
  172. CopyMemory(pAuthIdentDest->User, pAuthIdentSrc->User, (pAuthIdentDest->UserLength+1) * ulCharLen);
  173. }
  174. if (pAuthIdentSrc->Domain)
  175. {
  176. pAuthIdentDest->Domain = (USHORT *)LocalAlloc(LPTR,(pAuthIdentDest->DomainLength+1) * ulCharLen);
  177. if (!pAuthIdentDest->Domain)
  178. goto Cleanup;
  179. CopyMemory(pAuthIdentDest->Domain, pAuthIdentSrc->Domain, (pAuthIdentDest->DomainLength+1) * ulCharLen);
  180. }
  181. if (pAuthIdentSrc->Password)
  182. {
  183. pAuthIdentDest->Password = (USHORT *)LocalAlloc(LPTR,(pAuthIdentDest->PasswordLength+1) * ulCharLen);
  184. if (!pAuthIdentDest->Password)
  185. goto Cleanup;
  186. CopyMemory(pAuthIdentDest->Password, pAuthIdentSrc->Password, (pAuthIdentDest->PasswordLength+1) * ulCharLen);
  187. }
  188. hr = S_OK;
  189. Cleanup:
  190. return hr;
  191. }