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.

487 lines
15 KiB

  1. /*++
  2. Copyright (c) 1998-2000, Microsoft Corporation All rights reserved.
  3. Module Name:
  4. csrlocal.c
  5. Abstract:
  6. This module implements functions that are used by the functions in locale.c
  7. to communicate with csrss.
  8. Author:
  9. Michael Zoran (mzoran) 21-Jun-1998
  10. Revision History:
  11. --*/
  12. //
  13. // Include Files.
  14. //
  15. #include "nls.h"
  16. #include "ntwow64n.h"
  17. ////////////////////////////////////////////////////////////////////////////
  18. //
  19. // CsrBasepNlsSetUserInfo
  20. //
  21. // Parameters:
  22. // LCType The type of locale information to be set.
  23. // pData The buffer which contains the information to be set.
  24. // This is usually an Unicode string.
  25. // DataLength The length of pData in BYTE.
  26. //
  27. // Return:
  28. // STATUS_SUCCESS if the locale information is set correctly.
  29. // Otherwise, a proper NTSTATUS error code is returned.
  30. //
  31. // Note:
  32. // When kernel32.dll is complied for the WOW64 layer, we will call
  33. // a thunk function NtWow64CsrBasepNlsSetUserInfo(), and it will
  34. // in turn call the corresponding 64-bit version of this function.
  35. //
  36. ////////////////////////////////////////////////////////////////////////////
  37. NTSTATUS CsrBasepNlsSetUserInfo(
  38. IN LCTYPE LCType,
  39. IN LPWSTR pData,
  40. IN ULONG DataLength)
  41. {
  42. #if defined(BUILD_WOW6432)
  43. return (NtWow64CsrBasepNlsSetUserInfo( LCType,
  44. pData,
  45. DataLength ));
  46. #else
  47. BASE_API_MSG m;
  48. PBASE_NLS_SET_USER_INFO_MSG a = &m.u.NlsSetUserInfo;
  49. PCSR_CAPTURE_HEADER CaptureBuffer = NULL;
  50. //
  51. // Get the capture buffer for the strings.
  52. //
  53. CaptureBuffer = CsrAllocateCaptureBuffer( 1, DataLength );
  54. if (CaptureBuffer == NULL)
  55. {
  56. return (STATUS_NO_MEMORY);
  57. }
  58. if (CsrAllocateMessagePointer(CaptureBuffer, DataLength, (PVOID *)&(a->pData)) == 0)
  59. {
  60. goto exit;
  61. }
  62. RtlCopyMemory (a->pData, pData, DataLength);
  63. //
  64. // Save the pointer to the cache string.
  65. //
  66. a->LCType = LCType;
  67. //
  68. // Save the length of the data in the msg structure.
  69. //
  70. a->DataLength = DataLength;
  71. //
  72. // Call the server to set the registry value.
  73. //
  74. CsrClientCallServer( (PCSR_API_MSG)&m,
  75. CaptureBuffer,
  76. CSR_MAKE_API_NUMBER( BASESRV_SERVERDLL_INDEX,
  77. BasepNlsSetUserInfo ),
  78. sizeof(*a) );
  79. exit:
  80. //
  81. // Free the capture buffer.
  82. //
  83. if (CaptureBuffer != NULL)
  84. {
  85. CsrFreeCaptureBuffer(CaptureBuffer);
  86. }
  87. return (m.ReturnValue);
  88. #endif
  89. }
  90. ////////////////////////////////////////////////////////////////////////////
  91. //
  92. // CsrBasepNlsGetUserInfo
  93. //
  94. // This function uses LPC to call into server side (csrss.exe) to retrieve
  95. // the locale setting from the registry cache.
  96. //
  97. // Parameters
  98. // Locale The locale to be retrived. Note that this could be different from
  99. // the current user locale stored in the registry cache.
  100. // If that's the case, this function will return FALSE.
  101. // CacheOffset The offset in BYTE for the field in the NLS_USER_INFO cache to retrieve.
  102. // FIELD_OFFSET(NLS_USER_INFO, fieldName) should be used to get the offset.
  103. // pData The pointer which points to the target buffer
  104. // DataLength The size of the target buffer in BYTE (the NULL terminator is included in the count)
  105. //
  106. // BIGNOTE BIGNOTE
  107. // This function follows the convention of CsrBasepNlsSetUserInfo to use
  108. // DataLength in BYTE.
  109. //
  110. // BIGNOTE BIGNOTE
  111. // This method should be called in a critical section protected by gcsNlsProcessCache
  112. // since it will copy data into the process-wide cache pNlsUserInfo.
  113. //
  114. ////////////////////////////////////////////////////////////////////////////
  115. NTSTATUS CsrBasepNlsGetUserInfo(
  116. IN PNLS_USER_INFO pNlsCache,
  117. IN ULONG DataLength)
  118. {
  119. #if defined(BUILD_WOW6432)
  120. return (NtWow64CsrBasepNlsGetUserInfo( pNlsCache, DataLength));
  121. #else
  122. BASE_API_MSG m;
  123. PBASE_NLS_GET_USER_INFO_MSG a = &m.u.NlsGetUserInfo;
  124. PCSR_CAPTURE_HEADER CaptureBuffer = NULL;
  125. NTSTATUS rc;
  126. //
  127. // Get the capture buffer for the strings.
  128. //
  129. CaptureBuffer = CsrAllocateCaptureBuffer( 1, DataLength );
  130. if (CaptureBuffer == NULL)
  131. {
  132. return (STATUS_NO_MEMORY);
  133. }
  134. CsrCaptureMessageBuffer( CaptureBuffer,
  135. NULL,
  136. DataLength,
  137. (PVOID *)&a->pData );
  138. //
  139. // Save the length of the data in the msg structure.
  140. //
  141. a->DataLength = DataLength;
  142. //
  143. // Call the server to set the registry value.
  144. //
  145. rc = CsrClientCallServer( (PCSR_API_MSG)&m,
  146. CaptureBuffer,
  147. CSR_MAKE_API_NUMBER( BASESRV_SERVERDLL_INDEX,
  148. BasepNlsGetUserInfo ),
  149. sizeof(*a) );
  150. if (NT_SUCCESS(rc))
  151. {
  152. // NOTE: DataLength is in BYTE.
  153. RtlCopyMemory(pNlsCache, a->pData, DataLength);
  154. }
  155. //
  156. // Free the capture buffer.
  157. //
  158. if (CaptureBuffer != NULL)
  159. {
  160. CsrFreeCaptureBuffer(CaptureBuffer);
  161. }
  162. return (rc);
  163. #endif
  164. }
  165. ////////////////////////////////////////////////////////////////////////////
  166. //
  167. // CsrBasepNlsSetMultipleUserInfo
  168. //
  169. ////////////////////////////////////////////////////////////////////////////
  170. NTSTATUS CsrBasepNlsSetMultipleUserInfo(
  171. IN DWORD dwFlags,
  172. IN int cchData,
  173. IN LPCWSTR pPicture,
  174. IN LPCWSTR pSeparator,
  175. IN LPCWSTR pOrder,
  176. IN LPCWSTR pTLZero,
  177. IN LPCWSTR pTimeMarkPosn)
  178. {
  179. #if defined(BUILD_WOW6432)
  180. return (NtWow64CsrBasepNlsSetMultipleUserInfo( dwFlags,
  181. cchData,
  182. pPicture,
  183. pSeparator,
  184. pOrder,
  185. pTLZero,
  186. pTimeMarkPosn ));
  187. #else
  188. ULONG CaptureLength; // length of capture buffer
  189. ULONG Length; // temp storage for length of string
  190. BASE_API_MSG m;
  191. PBASE_NLS_SET_MULTIPLE_USER_INFO_MSG a = &m.u.NlsSetMultipleUserInfo;
  192. PCSR_CAPTURE_HEADER CaptureBuffer = NULL;
  193. //
  194. // Initialize the msg structure to NULL.
  195. //
  196. RtlZeroMemory(a, sizeof(BASE_NLS_SET_MULTIPLE_USER_INFO_MSG));
  197. //
  198. // Save the flags and the length of the data in the msg structure.
  199. //
  200. a->Flags = dwFlags;
  201. a->DataLength = cchData * sizeof(WCHAR);
  202. //
  203. // Save the appropriate strings in the msg structure.
  204. //
  205. switch (dwFlags)
  206. {
  207. case ( LOCALE_STIMEFORMAT ) :
  208. {
  209. //
  210. // Get the length of the capture buffer.
  211. //
  212. Length = wcslen(pSeparator) + 1;
  213. CaptureLength = (cchData + Length + 2 + 2 + 2) * sizeof(WCHAR);
  214. //
  215. // Get the capture buffer for the strings.
  216. //
  217. CaptureBuffer = CsrAllocateCaptureBuffer( 5,
  218. CaptureLength );
  219. if (CaptureBuffer != NULL)
  220. {
  221. CsrCaptureMessageBuffer( CaptureBuffer,
  222. (PCHAR)pPicture,
  223. cchData * sizeof(WCHAR),
  224. (PVOID *)&a->pPicture );
  225. CsrCaptureMessageBuffer( CaptureBuffer,
  226. (PCHAR)pSeparator,
  227. Length * sizeof(WCHAR),
  228. (PVOID *)&a->pSeparator );
  229. CsrCaptureMessageBuffer( CaptureBuffer,
  230. (PCHAR)pOrder,
  231. 2 * sizeof(WCHAR),
  232. (PVOID *)&a->pOrder );
  233. CsrCaptureMessageBuffer( CaptureBuffer,
  234. (PCHAR)pTLZero,
  235. 2 * sizeof(WCHAR),
  236. (PVOID *)&a->pTLZero );
  237. CsrCaptureMessageBuffer( CaptureBuffer,
  238. (PCHAR)pTimeMarkPosn,
  239. 2 * sizeof(WCHAR),
  240. (PVOID *)&a->pTimeMarkPosn );
  241. }
  242. break;
  243. }
  244. case ( LOCALE_STIME ) :
  245. {
  246. //
  247. // Get the length of the capture buffer.
  248. //
  249. Length = wcslen(pPicture) + 1;
  250. CaptureLength = (Length + cchData) * sizeof(WCHAR);
  251. //
  252. // Get the capture buffer for the strings.
  253. //
  254. CaptureBuffer = CsrAllocateCaptureBuffer( 2,
  255. CaptureLength );
  256. if (CaptureBuffer != NULL)
  257. {
  258. CsrCaptureMessageBuffer( CaptureBuffer,
  259. (PCHAR)pPicture,
  260. Length * sizeof(WCHAR),
  261. (PVOID *)&a->pPicture );
  262. CsrCaptureMessageBuffer( CaptureBuffer,
  263. (PCHAR)pSeparator,
  264. cchData * sizeof(WCHAR),
  265. (PVOID *)&a->pSeparator );
  266. }
  267. break;
  268. }
  269. case ( LOCALE_ITIME ) :
  270. {
  271. //
  272. // Get the length of the capture buffer.
  273. //
  274. Length = wcslen(pPicture) + 1;
  275. CaptureLength = (Length + cchData) * sizeof(WCHAR);
  276. //
  277. // Get the capture buffer for the strings.
  278. //
  279. CaptureBuffer = CsrAllocateCaptureBuffer( 2,
  280. CaptureLength );
  281. if (CaptureBuffer != NULL)
  282. {
  283. CsrCaptureMessageBuffer( CaptureBuffer,
  284. (PCHAR)pPicture,
  285. Length * sizeof(WCHAR),
  286. (PVOID *)&a->pPicture );
  287. CsrCaptureMessageBuffer( CaptureBuffer,
  288. (PCHAR)pOrder,
  289. cchData * sizeof(WCHAR),
  290. (PVOID *)&a->pOrder );
  291. }
  292. break;
  293. }
  294. case ( LOCALE_SSHORTDATE ) :
  295. {
  296. //
  297. // Get the length of the capture buffer.
  298. //
  299. Length = wcslen(pSeparator) + 1;
  300. CaptureLength = (cchData + Length + 2) * sizeof(WCHAR);
  301. //
  302. // Get the capture buffer for the strings.
  303. //
  304. CaptureBuffer = CsrAllocateCaptureBuffer( 3,
  305. CaptureLength );
  306. if (CaptureBuffer != NULL)
  307. {
  308. CsrCaptureMessageBuffer( CaptureBuffer,
  309. (PCHAR)pPicture,
  310. cchData * sizeof(WCHAR),
  311. (PVOID *)&a->pPicture );
  312. CsrCaptureMessageBuffer( CaptureBuffer,
  313. (PCHAR)pSeparator,
  314. Length * sizeof(WCHAR),
  315. (PVOID *)&a->pSeparator );
  316. CsrCaptureMessageBuffer( CaptureBuffer,
  317. (PCHAR)pOrder,
  318. 2 * sizeof(WCHAR),
  319. (PVOID *)&a->pOrder );
  320. }
  321. break;
  322. }
  323. case ( LOCALE_SDATE ) :
  324. {
  325. //
  326. // Get the length of the capture buffer.
  327. //
  328. Length = wcslen(pPicture) + 1;
  329. CaptureLength = (Length + cchData) * sizeof(WCHAR);
  330. //
  331. // Get the capture buffer for the strings.
  332. //
  333. CaptureBuffer = CsrAllocateCaptureBuffer( 2,
  334. CaptureLength );
  335. if (CaptureBuffer != NULL)
  336. {
  337. CsrCaptureMessageBuffer( CaptureBuffer,
  338. (PCHAR)pPicture,
  339. Length * sizeof(WCHAR),
  340. (PVOID *)&a->pPicture );
  341. CsrCaptureMessageBuffer( CaptureBuffer,
  342. (PCHAR)pSeparator,
  343. cchData * sizeof(WCHAR),
  344. (PVOID *)&a->pSeparator );
  345. }
  346. break;
  347. }
  348. }
  349. //
  350. // Make sure the CaptureBuffer was created and filled in.
  351. //
  352. if (CaptureBuffer == NULL)
  353. {
  354. return (STATUS_NO_MEMORY);
  355. }
  356. //
  357. // Call the server to set the registry values.
  358. //
  359. CsrClientCallServer( (PCSR_API_MSG)&m,
  360. CaptureBuffer,
  361. CSR_MAKE_API_NUMBER( BASESRV_SERVERDLL_INDEX,
  362. BasepNlsSetMultipleUserInfo ),
  363. sizeof(*a) );
  364. //
  365. // Free the capture buffer.
  366. //
  367. if (CaptureBuffer != NULL)
  368. {
  369. CsrFreeCaptureBuffer(CaptureBuffer);
  370. }
  371. return (m.ReturnValue);
  372. #endif
  373. }
  374. ////////////////////////////////////////////////////////////////////////////
  375. //
  376. // CsrBasepNlsUpdateCacheCount
  377. //
  378. ////////////////////////////////////////////////////////////////////////////
  379. NTSTATUS CsrBasepNlsUpdateCacheCount()
  380. {
  381. #if defined(BUILD_WOW6432)
  382. return (NtWow64CsrBasepNlsUpdateCacheCount());
  383. #else
  384. BASE_API_MSG m;
  385. PBASE_NLS_UPDATE_CACHE_COUNT_MSG a = &m.u.NlsCacheUpdateCount;
  386. a->Reserved = 0L;
  387. CsrClientCallServer( (PCSR_API_MSG)&m,
  388. NULL,
  389. CSR_MAKE_API_NUMBER( BASESRV_SERVERDLL_INDEX,
  390. BasepNlsUpdateCacheCount ),
  391. sizeof(*a) );
  392. return (m.ReturnValue);
  393. #endif
  394. }