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.

143 lines
2.8 KiB

  1. /*++
  2. Copyright (c) 2000-2001 Microsoft Corporation
  3. Module Name:
  4. HandleDBCSUserName2.cpp
  5. Abstract:
  6. Disable DBCS handling for CharNextA if the string is DBCS user profile
  7. for non-DBCS enabled application support.
  8. More info:
  9. Return next byte address instead of next character address.
  10. History:
  11. 05/01/2001 geoffguo Created
  12. --*/
  13. #include "precomp.h"
  14. #include "userenv.h"
  15. IMPLEMENT_SHIM_BEGIN(HandleDBCSUserName2)
  16. #include "ShimHookMacro.h"
  17. //
  18. // Add APIs that you wish to hook to this macro construction.
  19. //
  20. APIHOOK_ENUM_BEGIN
  21. APIHOOK_ENUM_ENTRY(CharNextA)
  22. APIHOOK_ENUM_END
  23. //
  24. // Reverse compare strings
  25. //
  26. BOOL ReverseStrCmp(
  27. LPCSTR lpCurrentChar,
  28. LPCSTR lpStrBuf)
  29. {
  30. BOOL bRet = FALSE;
  31. DWORD i, dwLen;
  32. LPCSTR lpStr1, lpStr2;
  33. if (!lpStrBuf || !lpCurrentChar || *lpStrBuf == '\0')
  34. goto Exit;
  35. dwLen = lstrlenA(lpStrBuf);
  36. do
  37. {
  38. bRet = TRUE;
  39. lpStr1 = lpCurrentChar;
  40. lpStr2 = &lpStrBuf[dwLen-1];
  41. for (i = 0; i < dwLen; i++)
  42. {
  43. if (IsBadStringPtrA(lpStr1, 1) || *lpStr1 == '\0' ||
  44. toupper(*lpStr1) != toupper(*lpStr2))
  45. {
  46. bRet = FALSE;
  47. break;
  48. }
  49. lpStr1--;
  50. lpStr2--;
  51. }
  52. if (bRet)
  53. break;
  54. dwLen--;
  55. } while (dwLen > 0 && lpStrBuf[dwLen-1] != '\\');
  56. Exit:
  57. return bRet;
  58. }
  59. //
  60. // Checking if the string is user profile path
  61. //
  62. BOOL IsUserProfilePath(
  63. LPCSTR lpCurrentChar)
  64. {
  65. HANDLE hToken;
  66. DWORD dwLen;
  67. BOOL bRet = FALSE;
  68. char szProfile[MAX_PATH];
  69. char szShortProfile[MAX_PATH];
  70. if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken))
  71. goto Exit;
  72. dwLen = MAX_PATH;
  73. if (!GetUserProfileDirectoryA(hToken, szProfile, &dwLen))
  74. goto Exit;
  75. bRet = ReverseStrCmp(lpCurrentChar, szProfile);
  76. if (bRet)
  77. goto Exit;
  78. dwLen = GetShortPathNameA(szProfile, szShortProfile, MAX_PATH);
  79. if (dwLen >= MAX_PATH || dwLen == 0)
  80. goto Exit;
  81. bRet = ReverseStrCmp(lpCurrentChar, szShortProfile);
  82. Exit:
  83. return bRet;
  84. }
  85. //
  86. // Disable DBCS handling for CharNextA
  87. //
  88. LPSTR
  89. APIHOOK(CharNextA)(
  90. LPCSTR lpCurrentChar)
  91. {
  92. if (lpCurrentChar != NULL && *lpCurrentChar != (char)NULL) {
  93. // Disable DBCS support for DBCS username in user profile path
  94. if (IsDBCSLeadByte(*lpCurrentChar) && !IsUserProfilePath(lpCurrentChar))
  95. lpCurrentChar++;
  96. lpCurrentChar++;
  97. }
  98. return (LPSTR)lpCurrentChar;
  99. }
  100. /*++
  101. Register hooked functions
  102. --*/
  103. HOOK_BEGIN
  104. APIHOOK_ENTRY(USER32.DLL, CharNextA)
  105. HOOK_END
  106. IMPLEMENT_SHIM_END