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.

153 lines
3.0 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1995 - 1999
  6. //
  7. // File: advapi32.cpp
  8. //
  9. // Contents: advapi32.dll wrapper functions
  10. //
  11. //--------------------------------------------------------------------------
  12. #include <pch.cpp>
  13. #pragma hdrstop
  14. typedef BOOL (WINAPI FNSTRINGSDTOSD)(
  15. IN LPCWSTR StringSecurityDescriptor,
  16. IN DWORD StringSDRevision,
  17. OUT PSECURITY_DESCRIPTOR *SecurityDescriptor,
  18. OUT PULONG SecurityDescriptorSize OPTIONAL);
  19. BOOL
  20. myConvertStringSecurityDescriptorToSecurityDescriptor(
  21. IN LPCWSTR StringSecurityDescriptor,
  22. IN DWORD StringSDRevision,
  23. OUT PSECURITY_DESCRIPTOR *SecurityDescriptor,
  24. OUT PULONG SecurityDescriptorSize OPTIONAL)
  25. {
  26. HMODULE hModule;
  27. BOOL f = FALSE;
  28. DWORD err;
  29. static FNSTRINGSDTOSD *s_pfn = NULL;
  30. if (NULL == s_pfn)
  31. {
  32. // load dll
  33. hModule = GetModuleHandle(TEXT("advapi32.dll"));
  34. if (NULL == hModule)
  35. {
  36. goto error;
  37. }
  38. // load system function
  39. s_pfn = (FNSTRINGSDTOSD *) GetProcAddress(
  40. hModule,
  41. "ConvertStringSecurityDescriptorToSecurityDescriptorW");
  42. if (NULL == s_pfn)
  43. {
  44. goto error;
  45. }
  46. }
  47. f = (*s_pfn)(
  48. StringSecurityDescriptor,
  49. StringSDRevision,
  50. SecurityDescriptor,
  51. SecurityDescriptorSize);
  52. if (!f)
  53. goto error;
  54. myRegisterMemAlloc(
  55. *SecurityDescriptor,
  56. ((NULL == SecurityDescriptorSize) ? -1 : *SecurityDescriptorSize),
  57. CSM_LOCALALLOC);
  58. error:
  59. return(f);
  60. }
  61. typedef BOOL (WINAPI FNSIDTOSTRINGSID)(
  62. IN PSID Sid,
  63. OUT LPWSTR *StringSid);
  64. BOOL
  65. myConvertSidToStringSid(
  66. IN PSID Sid,
  67. OUT LPWSTR *StringSid)
  68. {
  69. HMODULE hModule;
  70. BOOL f = FALSE;
  71. DWORD err;
  72. static FNSIDTOSTRINGSID *s_pfn = NULL;
  73. if (NULL == s_pfn)
  74. {
  75. // load dll
  76. hModule = GetModuleHandle(TEXT("advapi32.dll"));
  77. if (NULL == hModule)
  78. {
  79. goto error;
  80. }
  81. // load system function
  82. s_pfn = (FNSIDTOSTRINGSID *) GetProcAddress(
  83. hModule,
  84. "ConvertSidToStringSidW");
  85. if (NULL == s_pfn)
  86. {
  87. goto error;
  88. }
  89. }
  90. f = (*s_pfn)(Sid, StringSid);
  91. if (!f)
  92. goto error;
  93. myRegisterMemAlloc(*StringSid, -1, CSM_LOCALALLOC);
  94. error:
  95. return(f);
  96. }
  97. typedef BOOL (WINAPI FNSTRINGSIDTOSID)(
  98. IN LPCWSTR StringSid,
  99. OUT PSID *Sid);
  100. BOOL
  101. myConvertStringSidToSid(
  102. IN LPCWSTR StringSid,
  103. OUT PSID *Sid)
  104. {
  105. HMODULE hModule;
  106. BOOL f = FALSE;
  107. DWORD err;
  108. static FNSTRINGSIDTOSID *s_pfn = NULL;
  109. if (NULL == s_pfn)
  110. {
  111. // load dll
  112. hModule = GetModuleHandle(TEXT("advapi32.dll"));
  113. if (NULL == hModule)
  114. {
  115. goto error;
  116. }
  117. // load system function
  118. s_pfn = (FNSTRINGSIDTOSID *) GetProcAddress(
  119. hModule,
  120. "ConvertStringSidToSidW");
  121. if (NULL == s_pfn)
  122. {
  123. goto error;
  124. }
  125. }
  126. f = (*s_pfn)(StringSid, Sid);
  127. if (!f)
  128. goto error;
  129. myRegisterMemAlloc(*Sid, -1, CSM_LOCALALLOC);
  130. error:
  131. return(f);
  132. }