Source code of Windows XP (NT5)
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.

282 lines
6.5 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. logon32.cxx
  5. Abstract:
  6. Provide a replacement for LogonUser to login a user
  7. as a net logon. Also support sub-authentication DLL IDs
  8. Author:
  9. Philippe Choquier (phillich) 10-january-1996
  10. Created from base\advapi\logon32.c
  11. --*/
  12. #include "tcpdllp.hxx"
  13. #pragma hdrstop
  14. #include <lmjoin.h>
  15. #include <lonsi.hxx>
  16. #include <infosec.hxx>
  17. //
  18. // externs
  19. //
  20. extern LOGON32_INITIALIZE_FN pfnLogon32Initialize;
  21. extern LOGON_NET_USER_A_FN pfnLogonNetUserA;
  22. extern LOGON_NET_USER_W_FN pfnLogonNetUserW;
  23. extern NET_USER_COOKIE_A_FN pfnNetUserCookieA;
  24. extern LOGON_DIGEST_USER_A_FN pfnLogonDigestUserA;
  25. BOOL
  26. Logon32Initialize(
  27. IN PVOID hMod,
  28. IN ULONG Reason,
  29. IN PCONTEXT Context)
  30. /*++
  31. Routine Description:
  32. Initializes the critical section
  33. Arguments:
  34. hMod -- reserved, must be NULL
  35. Reason -- DLL_PROCESS_ATTACH or DLL_PROCESS_DETACH
  36. Context -- reserved, must be NULL
  37. Returns:
  38. TRUE if initialization success, else FALSE
  39. --*/
  40. {
  41. DBG_ASSERT( pfnLogon32Initialize != NULL );
  42. return pfnLogon32Initialize(
  43. hMod,
  44. Reason,
  45. Context );
  46. } // Logon32Initialize
  47. BOOL
  48. WINAPI
  49. LogonNetUserW(
  50. PWSTR lpszUsername,
  51. PWSTR lpszDomain,
  52. PSTR lpszPassword,
  53. PWSTR lpszWorkstation,
  54. DWORD dwSubAuth,
  55. DWORD dwLogonType,
  56. DWORD dwLogonProvider,
  57. HANDLE * phToken,
  58. LARGE_INTEGER * pExpiry
  59. )
  60. /*++
  61. Routine Description:
  62. Logs a user on via username and domain
  63. name via the LSA.
  64. Arguments:
  65. lpszUsername -- user name
  66. lpszDomain -- domain validating the user name
  67. lpszPassword -- clear text password, can be empty if a sub-auth DLL
  68. is used
  69. lpszWorkstation -- workstation requesting the login, can be NULL
  70. for local workstation
  71. dwSubAuth -- sub-auth DLL ID
  72. dwLogonType -- one of LOGON32_LOGON_NETWORK, LOGON32_LOGON_IIS_NETWORK
  73. dwLogonProvider -- must be LOGON32_PROVIDER_DEFAULT
  74. phToken -- created access token
  75. pExpiry -- ptr to pwd expiration time
  76. Returns:
  77. TRUE if success, FALSE if error
  78. --*/
  79. {
  80. DBG_ASSERT( pfnLogonNetUserW != NULL );
  81. return pfnLogonNetUserW(
  82. lpszUsername,
  83. lpszDomain,
  84. lpszPassword,
  85. lpszWorkstation,
  86. dwSubAuth,
  87. dwLogonType,
  88. dwLogonProvider,
  89. phToken,
  90. pExpiry
  91. );
  92. } // LogonNetUserW
  93. dllexp
  94. BOOL
  95. WINAPI
  96. LogonNetUserA(
  97. PSTR lpszUsername,
  98. PSTR lpszDomain,
  99. PSTR lpszPassword,
  100. PSTR lpszWorkstation,
  101. DWORD dwSubAuth,
  102. DWORD dwLogonType,
  103. DWORD dwLogonProvider,
  104. HANDLE * phToken,
  105. LARGE_INTEGER * pExpiry
  106. )
  107. /*++
  108. Routine Description:
  109. Logs a user on via username and domain
  110. name via the LSA.
  111. Arguments:
  112. lpszUsername -- user name
  113. lpszDomain -- domain validating the user name
  114. lpszPassword -- clear text password, can be empty if a sub-auth DLL
  115. is used
  116. lpszWorkstation -- workstation requesting the login, can be NULL
  117. for local workstation
  118. dwSubAuth -- sub-auth DLL ID
  119. dwLogonType -- one of LOGON32_LOGON_NETWORK, LOGON32_LOGON_IIS_NETWORK
  120. dwLogonProvider -- must be LOGON32_PROVIDER_DEFAULT
  121. phToken -- created access token
  122. pExpiry -- ptr to pwd expiration time
  123. Returns:
  124. TRUE if success, FALSE if error
  125. --*/
  126. {
  127. DBG_ASSERT( pfnLogonNetUserA != NULL );
  128. return pfnLogonNetUserA(
  129. lpszUsername,
  130. lpszDomain,
  131. lpszPassword,
  132. lpszWorkstation,
  133. dwSubAuth,
  134. dwLogonType,
  135. dwLogonProvider,
  136. phToken,
  137. pExpiry);
  138. } // LogonNetUserA
  139. dllexp
  140. BOOL
  141. WINAPI
  142. NetUserCookieA(
  143. LPSTR lpszUsername,
  144. DWORD dwSeed,
  145. LPSTR lpszCookieBuff,
  146. DWORD dwBuffSize
  147. )
  148. /*++
  149. Routine Description:
  150. Compute logon validator ( to be used as password )
  151. for IISSuba
  152. Arguments:
  153. lpszUsername -- user name
  154. dwSeed -- start value of cookie
  155. Returns:
  156. TRUE if success, FALSE if error
  157. --*/
  158. {
  159. DBG_ASSERT(pfnNetUserCookieA != NULL);
  160. return pfnNetUserCookieA(
  161. lpszUsername,
  162. dwSeed,
  163. lpszCookieBuff,
  164. dwBuffSize
  165. );
  166. } // NetUserCookieA
  167. dllexp
  168. BOOL
  169. WINAPI
  170. LogonDigestUserA(
  171. VOID * pDigestBuffer,
  172. DWORD dwAlgo,
  173. HANDLE * phToken
  174. )
  175. /*++
  176. Routine Description:
  177. Logs a user on via username and domain name via the LSA using Digest authentication.
  178. AMallet, 5/11/98 - This function is currently only called by the Digest Auth filter.
  179. Arguments:
  180. pDigestBuffer - Digest parameters
  181. dwAlgo - Logon type
  182. phToken -- created access token
  183. Returns:
  184. TRUE if success, FALSE if error
  185. --*/
  186. {
  187. PDIGEST_LOGON_INFO pDigestLogonInfo = (PDIGEST_LOGON_INFO) pDigestBuffer;
  188. static CHAR achDefaultDomain[IIS_DNLEN + 1];
  189. //
  190. // [See comment above about where this function is called from]
  191. // The digest filter will do what it can to pass in a non-empty domain [it'll try the
  192. // domain specified by the user, the metabase-configured domain and the domain the computer
  193. // is a part of, in that order], but if everything fails, we'll just have to use the
  194. // "default" domain name, which is usually the name of the machine itself
  195. //
  196. if ( !pDigestLogonInfo->pszDomain ||
  197. pDigestLogonInfo->pszDomain[ 0 ] == '\0' )
  198. {
  199. if ( achDefaultDomain[0] == '\0' )
  200. {
  201. if ( !pfnGetDefaultDomainName( achDefaultDomain,
  202. sizeof(achDefaultDomain) ) )
  203. {
  204. return FALSE;
  205. }
  206. }
  207. pDigestLogonInfo->pszDomain = achDefaultDomain;
  208. }
  209. else if ( pDigestLogonInfo->pszDomain[ 0 ] == '\\' )
  210. {
  211. pDigestLogonInfo->pszDomain[ 0 ] = '\0';
  212. }
  213. return pfnLogonDigestUserA( pDigestLogonInfo,
  214. dwAlgo,
  215. phToken );
  216. } // LogonDigestUserA