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
11 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. ApiAcct.c
  5. Abstract:
  6. This module contains individual API handlers for the Account APIs.
  7. SUPPORTED - NetAccountDeltas, NetAccountSync.
  8. SEE ALSO - Other NetLogon service APIs - in ApiLogon.c.
  9. Author:
  10. Shanku Niyogi (w-shanku) 04-Apr-1991
  11. Jim Waters (t-jamesw) 09-August-1991
  12. Revision History:
  13. --*/
  14. // Account APIs are UNICODE only.
  15. #ifndef UNICODE
  16. #define UNICODE
  17. #endif
  18. #include "XactSrvP.h"
  19. #include <netlibnt.h>
  20. #include <crypt.h> // must be included before <logonmsv.h>
  21. #include <ntsam.h> // must be included before <logonmsv.h>
  22. #include <logonmsv.h> // must be included before <ssi.h>
  23. #include <ssi.h> // I_NetAccountDeltas and I_NetAccountSync prototypes
  24. NTSTATUS
  25. XsNetAccountDeltas (
  26. API_HANDLER_PARAMETERS
  27. )
  28. /*++
  29. Routine Description:
  30. This routine handles a call to NetAccountDeltas.
  31. Arguments:
  32. API_HANDLER_PARAMETERS - information about the API call. See
  33. XsTypes.h for details.
  34. Return Value:
  35. NTSTATUS - STATUS_SUCCESS or reason for failure.
  36. --*/
  37. {
  38. NET_API_STATUS status;
  39. PXS_I_NET_ACCOUNT_DELTAS parameters = Parameters;
  40. LPTSTR nativeComputerName = NULL; // Native parameters
  41. NETLOGON_AUTHENTICATOR authIn;
  42. NETLOGON_AUTHENTICATOR authOut;
  43. UAS_INFO_0 infoIn;
  44. DWORD entriesRead;
  45. DWORD totalEntries;
  46. UAS_INFO_0 infoOut;
  47. LPBYTE structure = NULL; // Conversion variables
  48. API_HANDLER_PARAMETERS_REFERENCE; // Avoid warnings
  49. IF_DEBUG(ACCOUNT) {
  50. NetpKdPrint(( "XsNetAccountDeltas: header at %lx, params at %lx, "
  51. "buf size %ld\n",
  52. Header,
  53. parameters,
  54. SmbGetUshort( &parameters->BufferLen )));
  55. }
  56. try {
  57. //
  58. // Convert parameters to Unicode, check for errors.
  59. //
  60. if ( SmbGetUshort( &parameters->Level ) != 0 ) {
  61. status = ERROR_INVALID_LEVEL;
  62. goto cleanup;
  63. }
  64. XsConvertTextParameter(
  65. nativeComputerName,
  66. (LPSTR)XsSmbGetPointer( &parameters->ComputerName )
  67. );
  68. //
  69. // Set up the input structures. This is to make sure that the
  70. // structures we pass to the API are naturally aligned, as well
  71. // as properly byte-aligned.
  72. //
  73. structure = (LPBYTE)XsSmbGetPointer( &parameters->RecordID );
  74. RtlCopyMemory( infoIn.ComputerName, structure, sizeof( infoIn.ComputerName ) );
  75. structure += sizeof( infoIn.ComputerName );
  76. infoIn.TimeCreated = SmbGetUlong( structure );
  77. structure += sizeof(DWORD);
  78. infoIn.SerialNumber = SmbGetUlong( structure );
  79. structure = (LPBYTE)XsSmbGetPointer( &parameters->Authenticator );
  80. RtlCopyMemory(
  81. &authIn.Credential,
  82. structure,
  83. sizeof(NETLOGON_CREDENTIAL)
  84. );
  85. structure += sizeof(NETLOGON_CREDENTIAL);
  86. authIn.timestamp = SmbGetUlong( structure );
  87. RtlZeroMemory( &authOut, sizeof(NETLOGON_AUTHENTICATOR) );
  88. //
  89. // Make the local I_NetAccountDeltas call.
  90. //
  91. status = NetpNtStatusToApiStatus(
  92. I_NetAccountDeltas(
  93. NULL,
  94. nativeComputerName,
  95. &authIn,
  96. &authOut,
  97. &infoIn,
  98. (DWORD)SmbGetUshort( &parameters->Count ),
  99. (DWORD)SmbGetUshort( &parameters->Level ),
  100. (LPBYTE)XsSmbGetPointer( &parameters->Buffer ),
  101. (DWORD)SmbGetUshort( &parameters->BufferLen ),
  102. (LPDWORD)&entriesRead,
  103. (LPDWORD)&totalEntries,
  104. &infoOut
  105. ));
  106. if ( !XsApiSuccess( status )) {
  107. IF_DEBUG(API_ERRORS) {
  108. NetpKdPrint(( "XsNetAccountDeltas: I_NetAccountDeltas failed: "
  109. "%X\n", status ));
  110. }
  111. //
  112. // !!! When protocol level is available in the header information,
  113. // we can check it. Right now, we ignore this code.
  114. //
  115. // For clients older than LanMan 2.1, return a different error code.
  116. // LANMAN 2.1 Protocol Level is 6.
  117. //
  118. #if 0
  119. if ( status == NERR_TimeDiffAtDC && Header->ProtocolLevel < 6 ) {
  120. status = NERR_SyncRequired;
  121. }
  122. #endif
  123. goto cleanup;
  124. }
  125. //
  126. // Fill in 16 bit return structures.
  127. //
  128. structure = parameters->NextRecordID;
  129. RtlCopyMemory( structure, infoOut.ComputerName, sizeof( infoOut.ComputerName ) );
  130. structure += sizeof( infoOut.ComputerName );
  131. SmbPutUlong( (LPDWORD)structure, infoOut.TimeCreated );
  132. structure += sizeof(DWORD);
  133. SmbPutUlong( (LPDWORD)structure, infoOut.SerialNumber );
  134. structure = parameters->RetAuth;
  135. RtlCopyMemory(
  136. structure,
  137. &authOut.Credential,
  138. sizeof(NETLOGON_CREDENTIAL)
  139. );
  140. structure += sizeof(NETLOGON_CREDENTIAL);
  141. SmbPutUlong( (LPDWORD)structure, authOut.timestamp );
  142. //
  143. // Fill in 16 bit return values.
  144. //
  145. SmbPutUshort( &parameters->EntriesRead, (WORD)entriesRead );
  146. SmbPutUshort( &parameters->TotalEntries, (WORD)totalEntries );
  147. cleanup:
  148. ;
  149. } except( EXCEPTION_EXECUTE_HANDLER ) {
  150. status = (WORD)RtlNtStatusToDosError( GetExceptionCode() );
  151. }
  152. //
  153. // Free strings.
  154. //
  155. NetpMemoryFree( nativeComputerName );
  156. Header->Status = (WORD)status;
  157. return STATUS_SUCCESS;
  158. } // XsNetAccountDeltas
  159. NTSTATUS
  160. XsNetAccountSync (
  161. API_HANDLER_PARAMETERS
  162. )
  163. /*++
  164. Routine Description:
  165. This routine handles a call to NetAccountSync.
  166. Arguments:
  167. API_HANDLER_PARAMETERS - information about the API call. See
  168. XsTypes.h for details.
  169. Return Value:
  170. NTSTATUS - STATUS_SUCCESS or reason for failure.
  171. --*/
  172. {
  173. NET_API_STATUS status;
  174. PXS_I_NET_ACCOUNT_SYNC parameters = Parameters;
  175. LPTSTR nativeComputerName = NULL; // Native parameters
  176. NETLOGON_AUTHENTICATOR authIn;
  177. NETLOGON_AUTHENTICATOR authOut;
  178. DWORD entriesRead;
  179. DWORD totalEntries;
  180. DWORD nextReference;
  181. UAS_INFO_0 infoOut;
  182. LPBYTE structure; // Conversion variables
  183. API_HANDLER_PARAMETERS_REFERENCE; // Avoid warnings
  184. IF_DEBUG(ACCOUNT) {
  185. NetpKdPrint(( "XsNetAccountSync: header at %lx, params at %lx, "
  186. "buf size %ld\n",
  187. Header,
  188. parameters,
  189. SmbGetUshort( &parameters->BufferLen )));
  190. }
  191. // NetpBreakPoint();
  192. try {
  193. //
  194. // Convert parameters to Unicode, check for errors.
  195. //
  196. if ( SmbGetUshort( &parameters->Level ) != 0 ) {
  197. status = ERROR_INVALID_LEVEL;
  198. goto cleanup;
  199. }
  200. XsConvertTextParameter(
  201. nativeComputerName,
  202. (LPSTR)XsSmbGetPointer( &parameters->ComputerName )
  203. );
  204. //
  205. // Set up the input structure. This is to make sure that the
  206. // structure we pass to the API is naturally aligned, as well
  207. // as properly byte-aligned.
  208. //
  209. structure = (LPBYTE)XsSmbGetPointer( &parameters->Authenticator );
  210. RtlCopyMemory(
  211. &authIn.Credential,
  212. structure,
  213. sizeof(NETLOGON_CREDENTIAL)
  214. );
  215. structure += sizeof(NETLOGON_CREDENTIAL);
  216. authIn.timestamp = SmbGetUlong( structure );
  217. RtlZeroMemory( &authOut, sizeof(NETLOGON_AUTHENTICATOR) );
  218. //
  219. // Make the local I_NetAccountSync call.
  220. //
  221. status = NetpNtStatusToApiStatus(
  222. I_NetAccountSync(
  223. NULL,
  224. nativeComputerName,
  225. &authIn,
  226. &authOut,
  227. (DWORD)SmbGetUlong( &parameters->Reference ),
  228. (DWORD)SmbGetUshort( &parameters->Level ),
  229. (LPBYTE)XsSmbGetPointer( &parameters->Buffer ),
  230. (DWORD)SmbGetUshort( &parameters->BufferLen ),
  231. (LPDWORD)&entriesRead,
  232. (LPDWORD)&totalEntries,
  233. (LPDWORD)&nextReference,
  234. &infoOut
  235. ));
  236. if ( !XsApiSuccess( status )) {
  237. IF_DEBUG(API_ERRORS) {
  238. NetpKdPrint(( "XsNetAccountSync: I_NetAccountSync failed: "
  239. "%X\n", status ));
  240. }
  241. //
  242. // !!! When protocol level is available in the header information,
  243. // we can check it. Right now, we ignore this code.
  244. //
  245. // For clients older than LanMan 2.1, return a different error code.
  246. // LANMAN 2.1 Protocol Level is 6.
  247. //
  248. #if 0
  249. if ( status == NERR_TimeDiffAtDC && Header->ProtocolLevel < 6 ) {
  250. status = NERR_SyncRequired;
  251. }
  252. #endif
  253. goto cleanup;
  254. }
  255. //
  256. // Fill in 16 bit return structures.
  257. //
  258. structure = parameters->LastRecordID;
  259. RtlCopyMemory( structure, infoOut.ComputerName, sizeof( infoOut.ComputerName ) );
  260. structure += sizeof( infoOut.ComputerName );
  261. SmbPutUlong( (LPDWORD)structure, infoOut.TimeCreated );
  262. structure += sizeof(DWORD);
  263. SmbPutUlong( (LPDWORD)structure, infoOut.SerialNumber );
  264. structure = parameters->RetAuth;
  265. RtlCopyMemory(
  266. structure,
  267. &authOut.Credential,
  268. sizeof(NETLOGON_CREDENTIAL)
  269. );
  270. structure += sizeof(NETLOGON_CREDENTIAL);
  271. SmbPutUlong( (LPDWORD)structure, authOut.timestamp );
  272. //
  273. // Fill in 16 bit return values.
  274. //
  275. SmbPutUshort( &parameters->EntriesRead, (WORD)entriesRead );
  276. SmbPutUshort( &parameters->TotalEntries, (WORD)totalEntries );
  277. SmbPutUlong( &parameters->NextReference, nextReference );
  278. cleanup:
  279. ;
  280. } except( EXCEPTION_EXECUTE_HANDLER ) {
  281. status = (WORD)RtlNtStatusToDosError( GetExceptionCode() );
  282. }
  283. //
  284. // Free strings.
  285. //
  286. NetpMemoryFree( nativeComputerName );
  287. Header->Status = (WORD)status;
  288. return STATUS_SUCCESS;
  289. } // XsNetAccountSync