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.

176 lines
5.2 KiB

  1. //+-----------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (c) Microsoft Corporation 2000
  6. //
  7. // File: util.h
  8. //
  9. // Contents: headerfile for util.cxx and parser.cxx
  10. //
  11. //
  12. // History: KDamour 15Mar00 Created
  13. //
  14. //------------------------------------------------------------------------
  15. #ifndef DIGEST_UTIL_H
  16. #define DIGEST_UTIL_H
  17. #include "global.h"
  18. #ifdef __cplusplus
  19. extern "C"
  20. {
  21. #endif // __cplusplus
  22. // Allocates cb wide chars to UNICODE_STRING Buffer
  23. NTSTATUS UnicodeStringAllocate(IN PUNICODE_STRING pString, IN USHORT cNumWChars);
  24. // Duplicate a UnicodeString (memory alloc and copy)
  25. NTSTATUS UnicodeStringDuplicate(
  26. OUT PUNICODE_STRING DestinationString,
  27. IN OPTIONAL PUNICODE_STRING SourceString);
  28. // Copies a unicode string if destination has enough room to store it
  29. NTSTATUS UnicodeStringCopy(
  30. OUT PUNICODE_STRING DestinationString,
  31. IN OPTIONAL PUNICODE_STRING SourceString);
  32. // Function to duplicate Unicode passwords with padding for cipher
  33. NTSTATUS UnicodeStringDuplicatePassword(
  34. OUT PUNICODE_STRING DestinationString,
  35. IN OPTIONAL PUNICODE_STRING SourceString);
  36. // Clears a UnicodeString and releases the memory
  37. NTSTATUS UnicodeStringClear(OUT PUNICODE_STRING pString);
  38. // Copies a SzUnicodeString to a String (memory alloc and copy)
  39. NTSTATUS UnicodeStringWCharDuplicate(OUT PUNICODE_STRING DestinationString, IN OPTIONAL WCHAR *szSource);
  40. // Decode a string into Unicode
  41. NTSTATUS DecodeUnicodeString(
  42. IN PSTRING pstrSource,
  43. IN UINT CodePage,
  44. OUT PUNICODE_STRING pustrDestination
  45. );
  46. // Encode a unicode string with a given charset
  47. NTSTATUS EncodeUnicodeString(
  48. IN PUNICODE_STRING pustrSource,
  49. IN UINT CodePage,
  50. OUT PSTRING pstrDestination,
  51. IN OUT PBOOL pfUsedDefaultChar
  52. );
  53. // Duplicates a String (memory alloc and copy)
  54. NTSTATUS StringDuplicate(
  55. OUT PSTRING DestinationString,
  56. IN OPTIONAL PSTRING SourceString);
  57. // Copies a string if destination has enough room to store it
  58. NTSTATUS StringCopy(
  59. OUT PSTRING DestinationString,
  60. IN OPTIONAL PSTRING SourceString);
  61. // Reference a String - no buffer memory copied
  62. NTSTATUS StringReference(
  63. OUT PSTRING pDestinationString,
  64. IN PSTRING pSourceString
  65. );
  66. // Reference a Unicode_String - no buffer memory copied
  67. NTSTATUS UnicodeStringReference(
  68. OUT PUNICODE_STRING pDestinationString,
  69. IN PUNICODE_STRING pSourceString
  70. );
  71. // Copies a CzString to a String (memory alloc and copy)
  72. NTSTATUS StringCharDuplicate(
  73. OUT PSTRING DestinationString,
  74. IN OPTIONAL char *czSource,
  75. IN OPTIONAL USHORT uCnt);
  76. // Duplicates a SID (memory alloc and copy)
  77. NTSTATUS SidDuplicate(
  78. OUT PSID * DestinationSid,
  79. IN PSID SourceSid);
  80. NTSTATUS CopyClientString(
  81. IN PWSTR SourceString,
  82. IN ULONG SourceLength,
  83. IN BOOLEAN DoUnicode,
  84. OUT PUNICODE_STRING DestinationString);
  85. // Allocate memory in LSA or user mode
  86. PVOID DigestAllocateMemory(IN ULONG BufferSize);
  87. // De-allocate memory from DigestAllocateMemory
  88. VOID DigestFreeMemory(IN PVOID Buffer);
  89. // Allocates cb bytes to STRING Buffer
  90. NTSTATUS StringAllocate(IN PSTRING pString, IN USHORT cb);
  91. // Clears a String and releases the memory
  92. NTSTATUS StringFree(IN PSTRING pString);
  93. // Quick check on String struct allocations validity
  94. NTSTATUS StringVerify(OUT PSTRING pString);
  95. // Clears a Uniicde_String and releases the memory
  96. NTSTATUS UnicodeStringFree(OUT PUNICODE_STRING pString);
  97. // Hex Encoders and Decoders
  98. VOID BinToHex(LPBYTE pSrc,UINT cSrc, LPSTR pDst);
  99. VOID HexToBin(LPSTR pSrc,UINT cSrc, LPBYTE pDst);
  100. // Parse input string into Parameter section of Digest
  101. NTSTATUS DigestParser2(PSecBuffer pInputBuf, PSTR *pNameTable,UINT cNameTable, PDIGEST_PARAMETER pDigest);
  102. // Scan a Comma Deliminated STRING for an Item
  103. NTSTATUS CheckItemInList(PCHAR pszItem, PSTRING pstrList, BOOL fOneItem);
  104. // Helper function to DigestParser2
  105. NTSTATUS DigestProcessEntry(
  106. IN PSTR pcBeginName,
  107. IN PSTR pcEndName,
  108. IN PSTR pcBeginValue,
  109. IN PSTR pcEndValue,
  110. IN PSTR *pNameTable,
  111. IN UINT cNameTable,
  112. IN BOOL fBSlashEncoded,
  113. OUT PDIGEST_PARAMETER pDigest);
  114. // Check for backslash character in a counted string of chars
  115. BOOL CheckBSlashChar(
  116. IN PSTR pcStr,
  117. IN USHORT len);
  118. // This routine selects a Buffer by indexed count in the BufferIndex
  119. BOOLEAN SspGetTokenBufferByIndex(
  120. IN PSecBufferDesc TokenDescriptor,
  121. IN ULONG BufferIndex,
  122. OUT PSecBuffer * Token,
  123. IN BOOLEAN ReadonlyOK
  124. );
  125. // determine strlen for a counted string buffer which may or may not be terminated
  126. size_t strlencounted(const char *string, size_t maxcnt);
  127. // determine Unicode strlen for a counted string buffer which may or may not be terminated
  128. size_t ustrlencounted(const short *string, size_t maxcnt);
  129. // Performs a percent encoding of the source string into the destination string RFC 2396
  130. NTSTATUS BackslashEncodeString(IN PSTRING pstrSrc, OUT PSTRING pstrDst);
  131. // Print out the date and time from a given TimeStamp (converted to localtime)
  132. NTSTATUS PrintTimeString(TimeStamp tsValue, BOOL fLocalTime);
  133. // Printout the Hex representation of a buffer
  134. NTSTATUS MyPrintBytes(void *pbuff, USHORT uNumBytes, PSTRING pstrOutput);
  135. #ifdef __cplusplus
  136. }
  137. #endif // __cplusplus
  138. #endif // DIGEST_UTIL_H