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.

96 lines
1.9 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Copyright (c) 1997-1999 Microsoft Corporation
  4. //
  5. // File: misc.cpp
  6. //
  7. // Contents:
  8. //
  9. // History:
  10. //
  11. //---------------------------------------------------------------------------
  12. #include "tlsdb.h"
  13. //-----------------------------------------------------------
  14. BOOL
  15. TLSDBCopySid(
  16. PSID pbSrcSid,
  17. DWORD cbSrcSid,
  18. PSID* pbDestSid,
  19. DWORD* cbDestSid
  20. )
  21. /*++
  22. ++*/
  23. {
  24. if( *pbDestSid == NULL || pbSrcSid == NULL ||
  25. LocalSize(*pbDestSid) < cbSrcSid )
  26. {
  27. if(*pbDestSid != NULL)
  28. {
  29. FreeMemory(*pbDestSid);
  30. *pbDestSid = NULL;
  31. }
  32. if(cbSrcSid && pbSrcSid)
  33. {
  34. *pbDestSid = (PBYTE)AllocateMemory(cbSrcSid);
  35. if(*pbDestSid == NULL)
  36. {
  37. return FALSE;
  38. }
  39. }
  40. }
  41. *cbDestSid = cbSrcSid;
  42. return (cbSrcSid) ? CopySid(*cbDestSid, *pbDestSid, pbSrcSid) : TRUE;
  43. }
  44. //-----------------------------------------------------------
  45. BOOL
  46. TLSDBCopyBinaryData(
  47. PBYTE pbSrcData,
  48. DWORD cbSrcData,
  49. PBYTE* ppbDestData,
  50. DWORD* pcbDestData
  51. )
  52. /*++
  53. ++*/
  54. {
  55. if( ppbDestData == NULL || pcbDestData == NULL )
  56. {
  57. return(FALSE);
  58. }
  59. if( pbSrcData == NULL || cbSrcData == 0 )
  60. {
  61. return(TRUE);
  62. }
  63. //
  64. // would be nice to get the actual size of memory allocated
  65. //
  66. if( *ppbDestData != NULL && LocalSize(*ppbDestData) < cbSrcData )
  67. {
  68. LocalFree(*ppbDestData);
  69. *ppbDestData = NULL;
  70. }
  71. if( *ppbDestData == NULL )
  72. {
  73. *ppbDestData = (PBYTE)AllocateMemory(cbSrcData);
  74. if( *ppbDestData == NULL )
  75. {
  76. return FALSE;
  77. }
  78. }
  79. *pcbDestData = cbSrcData;
  80. memcpy(*ppbDestData, pbSrcData, cbSrcData);
  81. return TRUE;
  82. }