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.

242 lines
6.1 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. memdbutil.c
  5. Abstract:
  6. MemDb Utility functions
  7. Author:
  8. Jim Schmidt (jimschm) 8-Aug-1996
  9. Revision History:
  10. mvander xx-xxx-1999 split from memdb.c
  11. --*/
  12. #include "pch.h"
  13. BOOL
  14. MemDbValidateDatabase (
  15. VOID
  16. )
  17. {
  18. // NTRAID#NTBUG9-153308-2000/08/01-jimschm Reimplement MemDbValidateDatabase
  19. return TRUE;
  20. }
  21. /*++
  22. Routine Description:
  23. MemDbMakeNonPrintableKey converts the double-backslashe pairs in a string
  24. to ASCII 1, a non-printable character. This allows the caller to store
  25. properly escaped strings in MemDb.
  26. This routine is desinged to be expanded for other types of escape
  27. processing.
  28. Arguments:
  29. KeyName - Specifies the key text; receives the converted text. The DBCS
  30. version may grow the text buffer, so the text buffer must be twice
  31. the length of the inbound string.
  32. Flags - Specifies the type of conversion. Currently only
  33. MEMDB_CONVERT_DOUBLEWACKS_TO_ASCII_1 is supported.
  34. Return Value:
  35. none
  36. --*/
  37. VOID
  38. MemDbMakeNonPrintableKeyA (
  39. IN OUT PSTR KeyName,
  40. IN UINT Flags
  41. )
  42. {
  43. while (*KeyName) {
  44. if (Flags & MEMDB_CONVERT_DOUBLEWACKS_TO_ASCII_1) {
  45. if (_mbsnextc (KeyName) == '\\' &&
  46. _mbsnextc (_mbsinc (KeyName)) == '\\'
  47. ) {
  48. _setmbchar (KeyName, 1);
  49. KeyName = _mbsinc (KeyName);
  50. MYASSERT (_mbsnextc (KeyName) == '\\');
  51. _setmbchar (KeyName, 1);
  52. }
  53. DEBUGMSG_IF ((
  54. _mbsnextc (KeyName) == 1,
  55. DBG_WHOOPS,
  56. "MemDbMakeNonPrintableKeyA: Non-printable character "
  57. "collision detected; key was damaged"
  58. ));
  59. }
  60. if (Flags & MEMDB_CONVERT_WILD_STAR_TO_ASCII_2) {
  61. if (_mbsnextc (KeyName) == '*') {
  62. _setmbchar (KeyName, 2);
  63. }
  64. DEBUGMSG_IF ((
  65. _mbsnextc (_mbsinc (KeyName)) == 2,
  66. DBG_WHOOPS,
  67. "MemDbMakeNonPrintableKeyA: Non-printable character "
  68. "collision detected; key was damaged"
  69. ));
  70. }
  71. if (Flags & MEMDB_CONVERT_WILD_QMARK_TO_ASCII_3) {
  72. if (_mbsnextc (KeyName) == '?') {
  73. _setmbchar (KeyName, 3);
  74. }
  75. DEBUGMSG_IF ((
  76. _mbsnextc (_mbsinc (KeyName)) == 3,
  77. DBG_WHOOPS,
  78. "MemDbMakeNonPrintableKeyA: Non-printable character "
  79. "collision detected; key was damaged"
  80. ));
  81. }
  82. KeyName = _mbsinc (KeyName);
  83. }
  84. }
  85. VOID
  86. MemDbMakeNonPrintableKeyW (
  87. IN OUT PWSTR KeyName,
  88. IN UINT Flags
  89. )
  90. {
  91. while (*KeyName) {
  92. if (Flags & MEMDB_CONVERT_DOUBLEWACKS_TO_ASCII_1) {
  93. if (KeyName[0] == L'\\' && KeyName[1] == L'\\') {
  94. KeyName[0] = 1;
  95. KeyName[1] = 1;
  96. KeyName++;
  97. }
  98. DEBUGMSG_IF ((
  99. KeyName[0] == 1,
  100. DBG_WHOOPS,
  101. "MemDbMakeNonPrintableKeyW: Non-printable character "
  102. "collision detected; key was damaged"
  103. ));
  104. }
  105. if (Flags & MEMDB_CONVERT_WILD_STAR_TO_ASCII_2) {
  106. if (KeyName[0] == L'*') {
  107. KeyName[0] = 2;
  108. }
  109. DEBUGMSG_IF ((
  110. KeyName[1] == 2,
  111. DBG_WHOOPS,
  112. "MemDbMakeNonPrintableKeyW: Non-printable character "
  113. "collision detected; key was damaged"
  114. ));
  115. }
  116. if (Flags & MEMDB_CONVERT_WILD_QMARK_TO_ASCII_3) {
  117. if (KeyName[0] == L'*') {
  118. KeyName[0] = 3;
  119. }
  120. DEBUGMSG_IF ((
  121. KeyName[1] == 3,
  122. DBG_WHOOPS,
  123. "MemDbMakeNonPrintableKeyW: Non-printable character "
  124. "collision detected; key was damaged"
  125. ));
  126. }
  127. KeyName++;
  128. }
  129. }
  130. /*++
  131. Routine Description:
  132. MemDbMakePrintableKey converts the ASCII 1 characters to backslashes,
  133. restoring the string converted by MemDbMakeNonPrintableKey.
  134. This routine is desinged to be expanded for other types of escape
  135. processing.
  136. Arguments:
  137. KeyName - Specifies the key text; receives the converted text. The DBCS
  138. version may grow the text buffer, so the text buffer must be twice
  139. the length of the inbound string.
  140. Flags - Specifies the type of conversion. Currently only
  141. MEMDB_CONVERT_DOUBLEWACKS_TO_ASCII_1 is supported.
  142. Return Value:
  143. none
  144. --*/
  145. VOID
  146. MemDbMakePrintableKeyA (
  147. IN OUT PSTR KeyName,
  148. IN UINT Flags
  149. )
  150. {
  151. while (*KeyName) {
  152. if (Flags & MEMDB_CONVERT_DOUBLEWACKS_TO_ASCII_1) {
  153. if (_mbsnextc (KeyName) == 1) {
  154. _setmbchar (KeyName, '\\');
  155. }
  156. }
  157. if (Flags & MEMDB_CONVERT_WILD_STAR_TO_ASCII_2) {
  158. if (_mbsnextc (KeyName) == 2) {
  159. _setmbchar (KeyName, '*');
  160. }
  161. }
  162. if (Flags & MEMDB_CONVERT_WILD_QMARK_TO_ASCII_3) {
  163. if (_mbsnextc (KeyName) == 3) {
  164. _setmbchar (KeyName, '?');
  165. }
  166. }
  167. KeyName = _mbsinc (KeyName);
  168. }
  169. }
  170. VOID
  171. MemDbMakePrintableKeyW (
  172. IN OUT PWSTR KeyName,
  173. IN UINT Flags
  174. )
  175. {
  176. while (*KeyName) {
  177. if (Flags & MEMDB_CONVERT_DOUBLEWACKS_TO_ASCII_1) {
  178. if (KeyName[0] == 1) {
  179. KeyName[0] = L'\\';
  180. }
  181. }
  182. if (Flags & MEMDB_CONVERT_WILD_STAR_TO_ASCII_2) {
  183. if (KeyName[0] == 2) {
  184. KeyName[0] = L'*';
  185. }
  186. }
  187. if (Flags & MEMDB_CONVERT_WILD_QMARK_TO_ASCII_3) {
  188. if (KeyName[0] == 3) {
  189. KeyName[0] = L'?';
  190. }
  191. }
  192. KeyName++;
  193. }
  194. }