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.

507 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. ////////////////////////////////////////////////////////////////////////////
  111. NTSTATUS CsrBasepNlsGetUserInfo(
  112. IN LCID Locale,
  113. IN SIZE_T CacheOffset,
  114. IN LPWSTR pData,
  115. IN ULONG DataLength)
  116. {
  117. #if defined(BUILD_WOW6432)
  118. return (NtWow64CsrBasepNlsGetUserInfo( Locale, CacheOffset,
  119. pData,
  120. 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. // Check the following:
  127. // 1. Make sure that the CacheOffset can not be greater than the offset of the last field. The assumption here is that
  128. // UserLocaleId the FIRST field after any field that contains strings.
  129. // 2. Make sure that CacheOffset is always aligned in WCHAR and is aligned with the beginning of each field.
  130. // 3. DataLength can not be greater than the maximum length in BYTE.
  131. // 4. The pointer to the data is not NULL.
  132. //
  133. // There is a duplicated check in BaseSrvNlsGetUserInfo().
  134. if ((CacheOffset > FIELD_OFFSET(NLS_USER_INFO, UserLocaleId) - sizeof(WCHAR) * MAX_REG_VAL_SIZE) ||
  135. ((CacheOffset % (sizeof(WCHAR) * MAX_REG_VAL_SIZE)) != 0) ||
  136. (DataLength > MAX_REG_VAL_SIZE * sizeof(WCHAR)) ||
  137. (pData == NULL))
  138. {
  139. return (STATUS_INVALID_PARAMETER);
  140. }
  141. //
  142. // Get the capture buffer for the strings.
  143. //
  144. CaptureBuffer = CsrAllocateCaptureBuffer( 1, DataLength );
  145. if (CaptureBuffer == NULL)
  146. {
  147. return (STATUS_NO_MEMORY);
  148. }
  149. CsrCaptureMessageBuffer( CaptureBuffer,
  150. NULL,
  151. DataLength,
  152. (PVOID *)&a->pData );
  153. a->Locale = Locale;
  154. a->CacheOffset = CacheOffset;
  155. //
  156. // Save the length of the data in the msg structure.
  157. //
  158. a->DataLength = DataLength;
  159. //
  160. // Call the server to set the registry value.
  161. //
  162. rc = CsrClientCallServer( (PCSR_API_MSG)&m,
  163. CaptureBuffer,
  164. CSR_MAKE_API_NUMBER( BASESRV_SERVERDLL_INDEX,
  165. BasepNlsGetUserInfo ),
  166. sizeof(*a) );
  167. if (NT_SUCCESS(rc))
  168. {
  169. // NOTE: DataLength is in BYTE.
  170. wcsncpy(pData, a->pData, DataLength/sizeof(WCHAR));
  171. }
  172. //
  173. // Free the capture buffer.
  174. //
  175. if (CaptureBuffer != NULL)
  176. {
  177. CsrFreeCaptureBuffer(CaptureBuffer);
  178. }
  179. return (rc);
  180. #endif
  181. }
  182. ////////////////////////////////////////////////////////////////////////////
  183. //
  184. // CsrBasepNlsSetMultipleUserInfo
  185. //
  186. ////////////////////////////////////////////////////////////////////////////
  187. NTSTATUS CsrBasepNlsSetMultipleUserInfo(
  188. IN DWORD dwFlags,
  189. IN int cchData,
  190. IN LPCWSTR pPicture,
  191. IN LPCWSTR pSeparator,
  192. IN LPCWSTR pOrder,
  193. IN LPCWSTR pTLZero,
  194. IN LPCWSTR pTimeMarkPosn)
  195. {
  196. #if defined(BUILD_WOW6432)
  197. return (NtWow64CsrBasepNlsSetMultipleUserInfo( dwFlags,
  198. cchData,
  199. pPicture,
  200. pSeparator,
  201. pOrder,
  202. pTLZero,
  203. pTimeMarkPosn ));
  204. #else
  205. ULONG CaptureLength; // length of capture buffer
  206. ULONG Length; // temp storage for length of string
  207. BASE_API_MSG m;
  208. PBASE_NLS_SET_MULTIPLE_USER_INFO_MSG a = &m.u.NlsSetMultipleUserInfo;
  209. PCSR_CAPTURE_HEADER CaptureBuffer = NULL;
  210. //
  211. // Initialize the msg structure to NULL.
  212. //
  213. RtlZeroMemory(a, sizeof(BASE_NLS_SET_MULTIPLE_USER_INFO_MSG));
  214. //
  215. // Save the flags and the length of the data in the msg structure.
  216. //
  217. a->Flags = dwFlags;
  218. a->DataLength = cchData * sizeof(WCHAR);
  219. //
  220. // Save the appropriate strings in the msg structure.
  221. //
  222. switch (dwFlags)
  223. {
  224. case ( LOCALE_STIMEFORMAT ) :
  225. {
  226. //
  227. // Get the length of the capture buffer.
  228. //
  229. Length = wcslen(pSeparator) + 1;
  230. CaptureLength = (cchData + Length + 2 + 2 + 2) * sizeof(WCHAR);
  231. //
  232. // Get the capture buffer for the strings.
  233. //
  234. CaptureBuffer = CsrAllocateCaptureBuffer( 5,
  235. CaptureLength );
  236. if (CaptureBuffer != NULL)
  237. {
  238. CsrCaptureMessageBuffer( CaptureBuffer,
  239. (PCHAR)pPicture,
  240. cchData * sizeof(WCHAR),
  241. (PVOID *)&a->pPicture );
  242. CsrCaptureMessageBuffer( CaptureBuffer,
  243. (PCHAR)pSeparator,
  244. Length * sizeof(WCHAR),
  245. (PVOID *)&a->pSeparator );
  246. CsrCaptureMessageBuffer( CaptureBuffer,
  247. (PCHAR)pOrder,
  248. 2 * sizeof(WCHAR),
  249. (PVOID *)&a->pOrder );
  250. CsrCaptureMessageBuffer( CaptureBuffer,
  251. (PCHAR)pTLZero,
  252. 2 * sizeof(WCHAR),
  253. (PVOID *)&a->pTLZero );
  254. CsrCaptureMessageBuffer( CaptureBuffer,
  255. (PCHAR)pTimeMarkPosn,
  256. 2 * sizeof(WCHAR),
  257. (PVOID *)&a->pTimeMarkPosn );
  258. }
  259. break;
  260. }
  261. case ( LOCALE_STIME ) :
  262. {
  263. //
  264. // Get the length of the capture buffer.
  265. //
  266. Length = wcslen(pPicture) + 1;
  267. CaptureLength = (Length + cchData) * sizeof(WCHAR);
  268. //
  269. // Get the capture buffer for the strings.
  270. //
  271. CaptureBuffer = CsrAllocateCaptureBuffer( 2,
  272. CaptureLength );
  273. if (CaptureBuffer != NULL)
  274. {
  275. CsrCaptureMessageBuffer( CaptureBuffer,
  276. (PCHAR)pPicture,
  277. Length * sizeof(WCHAR),
  278. (PVOID *)&a->pPicture );
  279. CsrCaptureMessageBuffer( CaptureBuffer,
  280. (PCHAR)pSeparator,
  281. cchData * sizeof(WCHAR),
  282. (PVOID *)&a->pSeparator );
  283. }
  284. break;
  285. }
  286. case ( LOCALE_ITIME ) :
  287. {
  288. //
  289. // Get the length of the capture buffer.
  290. //
  291. Length = wcslen(pPicture) + 1;
  292. CaptureLength = (Length + cchData) * sizeof(WCHAR);
  293. //
  294. // Get the capture buffer for the strings.
  295. //
  296. CaptureBuffer = CsrAllocateCaptureBuffer( 2,
  297. CaptureLength );
  298. if (CaptureBuffer != NULL)
  299. {
  300. CsrCaptureMessageBuffer( CaptureBuffer,
  301. (PCHAR)pPicture,
  302. Length * sizeof(WCHAR),
  303. (PVOID *)&a->pPicture );
  304. CsrCaptureMessageBuffer( CaptureBuffer,
  305. (PCHAR)pOrder,
  306. cchData * sizeof(WCHAR),
  307. (PVOID *)&a->pOrder );
  308. }
  309. break;
  310. }
  311. case ( LOCALE_SSHORTDATE ) :
  312. {
  313. //
  314. // Get the length of the capture buffer.
  315. //
  316. Length = wcslen(pSeparator) + 1;
  317. CaptureLength = (cchData + Length + 2) * sizeof(WCHAR);
  318. //
  319. // Get the capture buffer for the strings.
  320. //
  321. CaptureBuffer = CsrAllocateCaptureBuffer( 3,
  322. CaptureLength );
  323. if (CaptureBuffer != NULL)
  324. {
  325. CsrCaptureMessageBuffer( CaptureBuffer,
  326. (PCHAR)pPicture,
  327. cchData * sizeof(WCHAR),
  328. (PVOID *)&a->pPicture );
  329. CsrCaptureMessageBuffer( CaptureBuffer,
  330. (PCHAR)pSeparator,
  331. Length * sizeof(WCHAR),
  332. (PVOID *)&a->pSeparator );
  333. CsrCaptureMessageBuffer( CaptureBuffer,
  334. (PCHAR)pOrder,
  335. 2 * sizeof(WCHAR),
  336. (PVOID *)&a->pOrder );
  337. }
  338. break;
  339. }
  340. case ( LOCALE_SDATE ) :
  341. {
  342. //
  343. // Get the length of the capture buffer.
  344. //
  345. Length = wcslen(pPicture) + 1;
  346. CaptureLength = (Length + cchData) * sizeof(WCHAR);
  347. //
  348. // Get the capture buffer for the strings.
  349. //
  350. CaptureBuffer = CsrAllocateCaptureBuffer( 2,
  351. CaptureLength );
  352. if (CaptureBuffer != NULL)
  353. {
  354. CsrCaptureMessageBuffer( CaptureBuffer,
  355. (PCHAR)pPicture,
  356. Length * sizeof(WCHAR),
  357. (PVOID *)&a->pPicture );
  358. CsrCaptureMessageBuffer( CaptureBuffer,
  359. (PCHAR)pSeparator,
  360. cchData * sizeof(WCHAR),
  361. (PVOID *)&a->pSeparator );
  362. }
  363. break;
  364. }
  365. }
  366. //
  367. // Make sure the CaptureBuffer was created and filled in.
  368. //
  369. if (CaptureBuffer == NULL)
  370. {
  371. return (STATUS_NO_MEMORY);
  372. }
  373. //
  374. // Call the server to set the registry values.
  375. //
  376. CsrClientCallServer( (PCSR_API_MSG)&m,
  377. CaptureBuffer,
  378. CSR_MAKE_API_NUMBER( BASESRV_SERVERDLL_INDEX,
  379. BasepNlsSetMultipleUserInfo ),
  380. sizeof(*a) );
  381. //
  382. // Free the capture buffer.
  383. //
  384. if (CaptureBuffer != NULL)
  385. {
  386. CsrFreeCaptureBuffer(CaptureBuffer);
  387. }
  388. return (m.ReturnValue);
  389. #endif
  390. }
  391. ////////////////////////////////////////////////////////////////////////////
  392. //
  393. // CsrBasepNlsUpdateCacheCount
  394. //
  395. ////////////////////////////////////////////////////////////////////////////
  396. NTSTATUS CsrBasepNlsUpdateCacheCount()
  397. {
  398. #if defined(BUILD_WOW6432)
  399. return (NtWow64CsrBasepNlsUpdateCacheCount());
  400. #else
  401. BASE_API_MSG m;
  402. PBASE_NLS_UPDATE_CACHE_COUNT_MSG a = &m.u.NlsCacheUpdateCount;
  403. a->Reserved = 0L;
  404. CsrClientCallServer( (PCSR_API_MSG)&m,
  405. NULL,
  406. CSR_MAKE_API_NUMBER( BASESRV_SERVERDLL_INDEX,
  407. BasepNlsUpdateCacheCount ),
  408. sizeof(*a) );
  409. return (m.ReturnValue);
  410. #endif
  411. }