Как вызвать функцию AllocateAndInitializeSid из C #? - PullRequest
2 голосов
/ 11 сентября 2008

Может кто-нибудь дать мне полный и рабочий пример вызова функции AllocateAndInitializeSid из кода C #?

Я нашел это :

BOOL WINAPI AllocateAndInitializeSid(
  __in   PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,
  __in   BYTE nSubAuthorityCount,
  __in   DWORD dwSubAuthority0,
  __in   DWORD dwSubAuthority1,
  __in   DWORD dwSubAuthority2,
  __in   DWORD dwSubAuthority3,
  __in   DWORD dwSubAuthority4,
  __in   DWORD dwSubAuthority5,
  __in   DWORD dwSubAuthority6,
  __in   DWORD dwSubAuthority7,
  __out  PSID *pSid
);

и я не знаю, как создать сигнатуру этого метода - что мне делать с типами PSID_IDENTIFIER_AUTHORITY и PSID? Как мне их передать - используя ref или out?

Ответы [ 3 ]

1 голос
/ 12 сентября 2008

Если вы ориентируетесь на .NET 2.0 или более позднюю версию, класс System.Security.Principal.SecurityIdentifier оборачивает SID и позволяет избежать подверженных ошибкам Win32 API.

Не совсем ответ на ваш вопрос, но кто знает, что это может быть полезно.

1 голос
/ 12 сентября 2008

Использование P / Invoke Interop Assistant :

    [System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
    public struct SidIdentifierAuthority {

        /// BYTE[6]
        [System.Runtime.InteropServices.MarshalAsAttribute(
            System.Runtime.InteropServices.UnmanagedType.ByValArray, 
            SizeConst = 6, 
            ArraySubType = 
            System.Runtime.InteropServices.UnmanagedType.I1)]
        public byte[] Value;
    }

    public partial class NativeMethods {

        /// Return Type: BOOL->int
        ///pIdentifierAuthority: PSID_IDENTIFIER_AUTHORITY->_SID_IDENTIFIER_AUTHORITY*
        ///nSubAuthorityCount: BYTE->unsigned char
        ///nSubAuthority0: DWORD->unsigned int
        ///nSubAuthority1: DWORD->unsigned int
        ///nSubAuthority2: DWORD->unsigned int
        ///nSubAuthority3: DWORD->unsigned int
        ///nSubAuthority4: DWORD->unsigned int
        ///nSubAuthority5: DWORD->unsigned int
        ///nSubAuthority6: DWORD->unsigned int
        ///nSubAuthority7: DWORD->unsigned int
        ///pSid: PSID*
        [System.Runtime.InteropServices.DllImportAttribute("advapi32.dll", EntryPoint = "AllocateAndInitializeSid")]
        [return: System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.Bool)]
        public static extern bool AllocateAndInitializeSid(
            [System.Runtime.InteropServices.InAttribute()] 
            ref SidIdentifierAuthority pIdentifierAuthority, 
            byte nSubAuthorityCount, 
            uint nSubAuthority0, 
            uint nSubAuthority1, 
            uint nSubAuthority2, 
            uint nSubAuthority3, 
            uint nSubAuthority4, 
            uint nSubAuthority5, 
            uint nSubAuthority6, 
            uint nSubAuthority7, 
            out System.IntPtr pSid);

    }
0 голосов
/ 11 сентября 2008

Для Платформы Invoke www.pinvoke.net - ваш новый лучший друг!

http://www.pinvoke.net/default.aspx/advapi32/AllocateAndInitializeSid.html

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...