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.

150 lines
3.1 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. static FNSTRINGSDTOSD *s_pfn = NULL;
  29. if (NULL == s_pfn)
  30. {
  31. // load dll
  32. hModule = GetModuleHandle(TEXT("advapi32.dll"));
  33. if (NULL == hModule)
  34. {
  35. goto error;
  36. }
  37. // load system function
  38. s_pfn = (FNSTRINGSDTOSD *) GetProcAddress(
  39. hModule,
  40. "ConvertStringSecurityDescriptorToSecurityDescriptorW");
  41. if (NULL == s_pfn)
  42. {
  43. goto error;
  44. }
  45. }
  46. f = (*s_pfn)(
  47. StringSecurityDescriptor,
  48. StringSDRevision,
  49. SecurityDescriptor,
  50. SecurityDescriptorSize);
  51. if (!f)
  52. goto error;
  53. myRegisterMemAlloc(
  54. *SecurityDescriptor,
  55. ((NULL == SecurityDescriptorSize) ? -1 : *SecurityDescriptorSize),
  56. CSM_LOCALALLOC);
  57. error:
  58. return(f);
  59. }
  60. typedef BOOL (WINAPI FNSIDTOSTRINGSID)(
  61. IN PSID Sid,
  62. OUT LPWSTR *StringSid);
  63. BOOL
  64. myConvertSidToStringSid(
  65. IN PSID Sid,
  66. OUT LPWSTR *StringSid)
  67. {
  68. HMODULE hModule;
  69. BOOL f = FALSE;
  70. static FNSIDTOSTRINGSID *s_pfn = NULL;
  71. if (NULL == s_pfn)
  72. {
  73. // load dll
  74. hModule = GetModuleHandle(TEXT("advapi32.dll"));
  75. if (NULL == hModule)
  76. {
  77. goto error;
  78. }
  79. // load system function
  80. s_pfn = (FNSIDTOSTRINGSID *) GetProcAddress(
  81. hModule,
  82. "ConvertSidToStringSidW");
  83. if (NULL == s_pfn)
  84. {
  85. goto error;
  86. }
  87. }
  88. f = (*s_pfn)(Sid, StringSid);
  89. if (!f)
  90. goto error;
  91. myRegisterMemAlloc(*StringSid, -1, CSM_LOCALALLOC);
  92. error:
  93. return(f);
  94. }
  95. typedef BOOL (WINAPI FNSTRINGSIDTOSID)(
  96. IN LPCWSTR StringSid,
  97. OUT PSID *Sid);
  98. BOOL
  99. myConvertStringSidToSid(
  100. IN LPCWSTR StringSid,
  101. OUT PSID *Sid)
  102. {
  103. HMODULE hModule;
  104. BOOL f = FALSE;
  105. static FNSTRINGSIDTOSID *s_pfn = NULL;
  106. if (NULL == s_pfn)
  107. {
  108. // load dll
  109. hModule = GetModuleHandle(TEXT("advapi32.dll"));
  110. if (NULL == hModule)
  111. {
  112. goto error;
  113. }
  114. // load system function
  115. s_pfn = (FNSTRINGSIDTOSID *) GetProcAddress(
  116. hModule,
  117. "ConvertStringSidToSidW");
  118. if (NULL == s_pfn)
  119. {
  120. goto error;
  121. }
  122. }
  123. f = (*s_pfn)(StringSid, Sid);
  124. if (!f)
  125. goto error;
  126. myRegisterMemAlloc(*Sid, -1, CSM_LOCALALLOC);
  127. error:
  128. return(f);
  129. }