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.

389 lines
9.6 KiB

  1. /*++
  2. Copyright (c) 1991-1992 Microsoft Corporation
  3. Module Name:
  4. wslsa.c
  5. Abstract:
  6. This module contains the interfaces to the Local Security Authority
  7. MS V 1.0 authentication package.
  8. Author:
  9. Rita Wong (ritaw) 15-May-1991
  10. Revision History:
  11. --*/
  12. #include "wsutil.h"
  13. #include "wslsa.h"
  14. #include "winreg.h"
  15. //-------------------------------------------------------------------//
  16. // //
  17. // Global variables //
  18. // //
  19. //-------------------------------------------------------------------//
  20. STATIC HANDLE LsaHandle = NULL;
  21. STATIC ULONG AuthPackageId = 0;
  22. #define FULL_LSA_CONTROL_REGISTRY_PATH L"SYSTEM\\CurrentControlSet\\Control\\Lsa"
  23. #define LSA_RESTRICT_ANONYMOUS_VALUE_NAME L"RestrictAnonymous"
  24. DWORD WsLsaRestrictAnonymous = 0;
  25. NET_API_STATUS
  26. WsInitializeLsa(
  27. VOID
  28. )
  29. /*++
  30. Routine Description:
  31. This function registers the Workstation service as a logon process and
  32. gets a handle to the MS V1.0 authentication package.
  33. Arguments:
  34. None.
  35. Return Value:
  36. NET_API_STATUS - NERR_Success or reason for failing.
  37. --*/
  38. {
  39. NTSTATUS ntstatus;
  40. STRING InputString;
  41. LSA_OPERATIONAL_MODE SecurityMode = 0;
  42. //
  43. // Register the Workstation service as a logon process
  44. //
  45. RtlInitString(&InputString, "LAN Manager Workstation Service");
  46. ntstatus = LsaRegisterLogonProcess(
  47. &InputString,
  48. &LsaHandle,
  49. &SecurityMode
  50. );
  51. IF_DEBUG(INFO) {
  52. NetpKdPrint(("[Wksta] LsaRegisterLogonProcess returns x%08lx, "
  53. "SecurityMode=x%08lx\n", ntstatus, SecurityMode));
  54. }
  55. if (! NT_SUCCESS(ntstatus)) {
  56. return WsMapStatus(ntstatus);
  57. }
  58. //
  59. // Look up the MS V1.0 authentication package
  60. //
  61. RtlInitString(&InputString,
  62. "MICROSOFT_AUTHENTICATION_PACKAGE_V1_0");
  63. ntstatus = LsaLookupAuthenticationPackage(
  64. LsaHandle,
  65. &InputString,
  66. &AuthPackageId
  67. );
  68. if (! NT_SUCCESS(ntstatus)) {
  69. IF_DEBUG(INFO) {
  70. NetpKdPrint(("[Wksta] LsaLookupAuthenticationPackage returns x%08lx, "
  71. "AuthPackageId=%lu\n", ntstatus, AuthPackageId));
  72. }
  73. }
  74. WsLsaRestrictAnonymous = 0;
  75. if (NT_SUCCESS(ntstatus)) {
  76. HKEY handle;
  77. DWORD error;
  78. error = RegOpenKeyEx(
  79. HKEY_LOCAL_MACHINE,
  80. FULL_LSA_CONTROL_REGISTRY_PATH,
  81. 0,
  82. KEY_READ,
  83. &handle
  84. );
  85. if( error == ERROR_SUCCESS ) {
  86. DWORD type;
  87. DWORD size = sizeof( WsLsaRestrictAnonymous );
  88. error = RegQueryValueEx(
  89. handle,
  90. LSA_RESTRICT_ANONYMOUS_VALUE_NAME,
  91. NULL,
  92. &type,
  93. (LPBYTE)&WsLsaRestrictAnonymous,
  94. &size);
  95. if ((error != ERROR_SUCCESS) ||
  96. (type != REG_DWORD) ||
  97. (size != sizeof(DWORD))) {
  98. WsLsaRestrictAnonymous = 0;
  99. }
  100. RegCloseKey(handle);
  101. }
  102. }
  103. return WsMapStatus(ntstatus);
  104. }
  105. VOID
  106. WsShutdownLsa(
  107. VOID
  108. )
  109. /*++
  110. Routine Description:
  111. This function deregisters the Workstation service as a logon process.
  112. Arguments:
  113. None.
  114. Return Value:
  115. None.
  116. --*/
  117. {
  118. (void) LsaDeregisterLogonProcess(
  119. LsaHandle
  120. );
  121. }
  122. NET_API_STATUS
  123. WsLsaEnumUsers(
  124. OUT LPBYTE *EnumUsersResponse
  125. )
  126. /*++
  127. Routine Description:
  128. This function asks the MS V1.0 Authentication Package to list all users
  129. who are physically logged on to the local computer.
  130. Arguments:
  131. EnumUsersResponse - Returns a pointer to a list of user logon ids. This
  132. memory is allocated by the authentication package and must be freed
  133. with LsaFreeReturnBuffer when done with it.
  134. Return Value:
  135. NET_API_STATUS - NERR_Success or reason for failure.
  136. --*/
  137. {
  138. NTSTATUS ntstatus;
  139. NTSTATUS AuthPackageStatus;
  140. MSV1_0_ENUMUSERS_REQUEST EnumUsersRequest;
  141. ULONG EnumUsersResponseLength;
  142. //
  143. // Ask authentication package to enumerate users who are physically
  144. // logged to the local machine.
  145. //
  146. EnumUsersRequest.MessageType = MsV1_0EnumerateUsers;
  147. ntstatus = LsaCallAuthenticationPackage(
  148. LsaHandle,
  149. AuthPackageId,
  150. &EnumUsersRequest,
  151. sizeof(MSV1_0_ENUMUSERS_REQUEST),
  152. (PVOID *)EnumUsersResponse,
  153. &EnumUsersResponseLength,
  154. &AuthPackageStatus
  155. );
  156. if (ntstatus == STATUS_SUCCESS) {
  157. ntstatus = AuthPackageStatus;
  158. }
  159. if (ntstatus != STATUS_SUCCESS) {
  160. return WsMapStatus(ntstatus);
  161. }
  162. return(NERR_Success);
  163. }
  164. NET_API_STATUS
  165. WsLsaGetUserInfo(
  166. IN PLUID LogonId,
  167. OUT LPBYTE *UserInfoResponse,
  168. OUT LPDWORD UserInfoResponseLength
  169. )
  170. /*++
  171. Routine Description:
  172. This function asks the MS V1.0 Authentication Package for information on
  173. a specific user.
  174. Arguments:
  175. LogonId - Supplies the logon id of the user we want information about.
  176. UserInfoResponse - Returns a pointer to a structure of information about
  177. the user. This memory is allocated by the authentication package
  178. and must be freed with LsaFreeReturnBuffer when done with it.
  179. UserInfoResponseLength - Returns the length of the returned information
  180. in number of bytes.
  181. Return Value:
  182. NET_API_STATUS - NERR_Success or reason for failure.
  183. --*/
  184. {
  185. NTSTATUS ntstatus;
  186. NTSTATUS AuthPackageStatus;
  187. MSV1_0_GETUSERINFO_REQUEST UserInfoRequest;
  188. //
  189. // Ask authentication package for user information.
  190. //
  191. UserInfoRequest.MessageType = MsV1_0GetUserInfo;
  192. RtlCopyLuid(&UserInfoRequest.LogonId, LogonId);
  193. ntstatus = LsaCallAuthenticationPackage(
  194. LsaHandle,
  195. AuthPackageId,
  196. &UserInfoRequest,
  197. sizeof(MSV1_0_GETUSERINFO_REQUEST),
  198. (PVOID *)UserInfoResponse,
  199. UserInfoResponseLength,
  200. &AuthPackageStatus
  201. );
  202. if (ntstatus == STATUS_SUCCESS) {
  203. ntstatus = AuthPackageStatus;
  204. }
  205. if (ntstatus != STATUS_SUCCESS) {
  206. return WsMapStatus(ntstatus);
  207. }
  208. return(NERR_Success);
  209. }
  210. NET_API_STATUS
  211. WsLsaRelogonUsers(
  212. IN LPTSTR LogonServer
  213. )
  214. /*++
  215. Routine Description:
  216. This function asks the MS V1.0 Authentication Package to relogon users
  217. that are logged on by the specified logon server. This is because the
  218. server had been reset and need to restore the database of users logged
  219. on by it before it went down.
  220. Arguments:
  221. LogonServer - Name of logon server which requests that all its previously
  222. logged on users be relogged on.
  223. Return Value:
  224. NET_API_STATUS - NERR_Success or reason for failure.
  225. --*/
  226. {
  227. NTSTATUS ntstatus;
  228. NTSTATUS AuthPackageStatus;
  229. OEM_STRING AnsiLogonServerName;
  230. PMSV1_0_RELOGON_REQUEST RelogonUsersRequest;
  231. ULONG RelogonUsersRequestLength = sizeof(MSV1_0_RELOGON_REQUEST) +
  232. (STRLEN(LogonServer) + 1) * sizeof(WCHAR);
  233. //
  234. // NTRAID-70701-2/6/2000 davey Since we cannot yet use optional parameters in call to
  235. // LsaCallAuthentication package, provide these variables for now.
  236. //
  237. PVOID RelogonUsersResponse;
  238. ULONG ResponseLength;
  239. //
  240. // Allocate the relogon request package dynamically because the logon
  241. // server name length is dynamic
  242. //
  243. if ((RelogonUsersRequest = (PMSV1_0_RELOGON_REQUEST)
  244. LocalAlloc(
  245. LMEM_ZEROINIT,
  246. (UINT) RelogonUsersRequestLength
  247. )) == NULL) {
  248. return GetLastError();
  249. }
  250. RelogonUsersRequest->LogonServer.Buffer = (LPWSTR)
  251. ((DWORD_PTR) RelogonUsersRequest) +
  252. sizeof(MSV1_0_RELOGON_REQUEST);
  253. RtlInitUnicodeString(&RelogonUsersRequest->LogonServer, LogonServer);
  254. //
  255. // Ask authentication package to relogon users for the specified
  256. // logon server.
  257. //
  258. RelogonUsersRequest->MessageType = MsV1_0ReLogonUsers;
  259. ntstatus = LsaCallAuthenticationPackage(
  260. LsaHandle,
  261. AuthPackageId,
  262. &RelogonUsersRequest,
  263. RelogonUsersRequestLength,
  264. &RelogonUsersResponse, // should be NULL if OPTIONAL
  265. &ResponseLength, // should be NULL if OPTIONAL
  266. &AuthPackageStatus
  267. );
  268. //
  269. // Free memory allocated for request package
  270. //
  271. (void) LocalFree(RelogonUsersRequest);
  272. if (ntstatus == STATUS_SUCCESS) {
  273. ntstatus = AuthPackageStatus;
  274. }
  275. if (ntstatus != STATUS_SUCCESS) {
  276. return WsMapStatus(ntstatus);
  277. }
  278. return(NERR_Success);
  279. }
  280.