Starting an Interactive Client Process in C++

简介:

The following example uses the LogonUser function to start a new logon session for a client. The example gets the logon SID from the client's access token, and uses it to add access control entries (ACEs) to the discretionary access control list (DACL) of the interactive window station and desktop. The ACEs allow the client access to the interactive desktop for the duration of the logon session. Next, the example calls the ImpersonateLoggedOnUserfunction to ensure that it has access to the client's executable file. A call to the CreateProcessAsUser function creates the client's process, specifying that it run in the interactive desktop. Note that your process must have the SE_ASSIGNPRIMARYTOKEN_NAME and SE_INCREASE_QUOTA_NAME privileges for successful execution of CreateProcessAsUser. Before the function returns, it calls the RevertToSelf function to end the caller's impersonation of the client.

This example calls the GetLogonSID and FreeLogonSID functions described in Getting the Logon SID in C++.

None.gif  #define  DESKTOP_ALL (DESKTOP_READOBJECTS | DESKTOP_CREATEWINDOW | \ 
None.gifDESKTOP_CREATEMENU  |  DESKTOP_HOOKCONTROL  |  DESKTOP_JOURNALRECORD  |  \
None.gifDESKTOP_JOURNALPLAYBACK  |  DESKTOP_ENUMERATE  |  DESKTOP_WRITEOBJECTS  |  \
None.gifDESKTOP_SWITCHDESKTOP  |  STANDARD_RIGHTS_REQUIRED)
None.gif
None.gif  #define  WINSTA_ALL (WINSTA_ENUMDESKTOPS | WINSTA_READATTRIBUTES | \ 
None.gifWINSTA_ACCESSCLIPBOARD  |  WINSTA_CREATEDESKTOP  |  WINSTA_WRITEATTRIBUTES  |  \
None.gifWINSTA_ACCESSGLOBALATOMS  |  WINSTA_EXITWINDOWS  |  WINSTA_ENUMERATE  |  \
None.gifWINSTA_READSCREEN  |  STANDARD_RIGHTS_REQUIRED)
None.gif
None.gif  #define  GENERIC_ACCESS (GENERIC_READ | GENERIC_WRITE | GENERIC_EXECUTE | \ 
None.gifGENERIC_ALL)
None.gif
None.gifBOOL AddAceToWindowStation(HWINSTA hwinsta, PSID psid);
None.gif
None.gifBOOL AddAceToDesktop(HDESK hdesk, PSID psid);
None.gif
None.gifBOOL StartInteractiveClientProcess (
None.gif    LPTSTR lpszUsername,      //   client to log on 
None.gif 
    LPTSTR lpszDomain,        //   domain of client's account 
None.gif 
    LPTSTR lpszPassword,      //   client's password 
None.gif 
    LPTSTR lpCommandLine      //   command line to execute 
None.gif 

ExpandedBlockStart.gif  {
InBlock.gif   HANDLE      hToken;
InBlock.gif   HDESK       hdesk  =  NULL;
InBlock.gif   HWINSTA     hwinsta  =  NULL, hwinstaSave  =  NULL;
InBlock.gif   PROCESS_INFORMATION pi;
InBlock.gif   PSID pSid  =  NULL;
InBlock.gif   STARTUPINFO si;
InBlock.gif   BOOL bResult  =  FALSE;
InBlock.gif
InBlock.gif //  Log the client on to the local computer. 
InBlock.gif 

InBlock.gif    if  ( ! LogonUser(
InBlock.gif           lpszUsername,
InBlock.gif           lpszDomain,
InBlock.gif           lpszPassword,
InBlock.gif           LOGON32_LOGON_INTERACTIVE,
InBlock.gif           LOGON32_PROVIDER_DEFAULT,
InBlock.gif            & hToken) ) 
ExpandedSubBlockStart.gif    {
InBlock.gif       goto  Cleanup;
ExpandedSubBlockEnd.gif   } 

InBlock.gif 
InBlock.gif //  Save a handle to the caller's current window station. 
InBlock.gif 

InBlock.gif    if  ( (hwinstaSave  =  GetProcessWindowStation() )  ==  NULL)
InBlock.gif       goto  Cleanup;
InBlock.gif
InBlock.gif //  Get a handle to the interactive window station. 
InBlock.gif 

InBlock.gif   hwinsta  =  OpenWindowStation(
InBlock.gif        " winsta0 " ,                    //  the interactive window station  
InBlock.gif 
       FALSE,                        //  handle is not inheritable 
InBlock.gif 
       READ_CONTROL  |  WRITE_DAC);    //  rights to read/write the DACL 
InBlock.gif 

InBlock.gif    if  (hwinsta  ==  NULL) 
InBlock.gif       goto  Cleanup;
InBlock.gif
InBlock.gif //  To get the correct default desktop, set the caller's 
InBlock.gif
 //  window station to the interactive window station. 
InBlock.gif 

InBlock.gif    if  ( ! SetProcessWindowStation(hwinsta))
InBlock.gif       goto  Cleanup;
InBlock.gif
InBlock.gif //  Get a handle to the interactive desktop. 
InBlock.gif 

InBlock.gif   hdesk  =  OpenDesktop(
InBlock.gif       " default " ,      //  the interactive window station  
InBlock.gif 
       0 ,              //  no interaction with other desktop processes 
InBlock.gif 
      FALSE,          //  handle is not inheritable 
InBlock.gif 
      READ_CONTROL  |   //  request the rights to read and write the DACL 
InBlock.gif 
      WRITE_DAC  |  
InBlock.gif      DESKTOP_WRITEOBJECTS  |  
InBlock.gif      DESKTOP_READOBJECTS);
InBlock.gif
InBlock.gif //  Restore the caller's window station. 
InBlock.gif 

InBlock.gif    if  ( ! SetProcessWindowStation(hwinstaSave)) 
InBlock.gif       goto  Cleanup;
InBlock.gif
InBlock.gif    if  (hdesk  ==  NULL) 
InBlock.gif       goto  Cleanup;
InBlock.gif
InBlock.gif //  Get the SID for the client's logon session. 
InBlock.gif 

InBlock.gif    if  ( ! GetLogonSID(hToken,  & pSid)) 
InBlock.gif       goto  Cleanup;
InBlock.gif
InBlock.gif //  Allow logon SID full access to interactive window station. 
InBlock.gif 

InBlock.gif    if  ( !  AddAceToWindowStation(hwinsta, pSid) ) 
InBlock.gif       goto  Cleanup;
InBlock.gif
InBlock.gif //  Allow logon SID full access to interactive desktop. 
InBlock.gif 

InBlock.gif    if  ( !  AddAceToDesktop(hdesk, pSid) ) 
InBlock.gif       goto  Cleanup;
InBlock.gif
InBlock.gif //  Impersonate client to ensure access to executable file. 
InBlock.gif 

InBlock.gif    if  ( !  ImpersonateLoggedOnUser(hToken) ) 
InBlock.gif       goto  Cleanup;
InBlock.gif
InBlock.gif //  Initialize the STARTUPINFO structure.
InBlock.gif
 //  Specify that the process runs in the interactive desktop. 
InBlock.gif 

InBlock.gif   ZeroMemory( & si,  sizeof (STARTUPINFO));
InBlock.gif   si.cb =   sizeof (STARTUPINFO);
InBlock.gif   si.lpDesktop  =  TEXT( " winsta0\\default " );
InBlock.gif
InBlock.gif //  Launch the process in the client's logon session. 
InBlock.gif 

InBlock.gif   bResult  =  CreateProcessAsUser(
InBlock.gif      hToken,             //  client's access token 
InBlock.gif 
      NULL,               //  file to execute 
InBlock.gif 
      lpCommandLine,      //  command line 
InBlock.gif 
      NULL,               //  pointer to process SECURITY_ATTRIBUTES 
InBlock.gif 
      NULL,               //  pointer to thread SECURITY_ATTRIBUTES 
InBlock.gif 
      FALSE,              //  handles are not inheritable 
InBlock.gif 
      NORMAL_PRIORITY_CLASS  |  CREATE_NEW_CONSOLE,    //  creation flags 
InBlock.gif 
      NULL,               //  pointer to new environment block  
InBlock.gif 
      NULL,               //  name of current directory  
InBlock.gif 
       & si,                //  pointer to STARTUPINFO structure 
InBlock.gif 
       & pi                 //  receives information about new process 
InBlock.gif 
   ); 
InBlock.gif
InBlock.gif //  End impersonation of client. 
InBlock.gif 

InBlock.gif   RevertToSelf();
InBlock.gif
InBlock.gif    if  (bResult  &&  pi.hProcess  !=  INVALID_HANDLE_VALUE) 
ExpandedSubBlockStart.gif    
InBlock.gif      WaitForSingleObject(pi.hProcess, INFINITE); 
InBlock.gif      CloseHandle(pi.hProcess); 
ExpandedSubBlockEnd.gif   } 
 
InBlock.gif
InBlock.gif    if  (pi.hThread  !=  INVALID_HANDLE_VALUE)
InBlock.gif      CloseHandle(pi.hThread);  
InBlock.gif
InBlock.gifCleanup: 
InBlock.gif
InBlock.gif    if  (hwinstaSave  !=  NULL)
InBlock.gif      SetProcessWindowStation (hwinstaSave);
InBlock.gif
InBlock.gif //  Free the buffer for the logon SID. 
InBlock.gif 

InBlock.gif    if  (pSid)
InBlock.gif      FreeLogonSID( & pSid);
InBlock.gif
InBlock.gif //  Close the handles to the interactive window station and desktop. 
InBlock.gif 

InBlock.gif    if  (hwinsta)
InBlock.gif      CloseWindowStation(hwinsta);
InBlock.gif
InBlock.gif    if  (hdesk)
InBlock.gif      CloseDesktop(hdesk);
InBlock.gif
InBlock.gif //  Close the handle to the client's access token. 
InBlock.gif 

InBlock.gif    if  (hToken  !=  INVALID_HANDLE_VALUE)
InBlock.gif      CloseHandle(hToken);  
InBlock.gif
InBlock.gif    return  bResult;
ExpandedBlockEnd.gif

None.gif 
None.gifBOOL AddAceToWindowStation(HWINSTA hwinsta, PSID psid)
ExpandedBlockStart.gif  {
InBlock.gif   ACCESS_ALLOWED_ACE    * pace;
InBlock.gif   ACL_SIZE_INFORMATION aclSizeInfo;
InBlock.gif   BOOL                 bDaclExist;
InBlock.gif   BOOL                 bDaclPresent;
InBlock.gif   BOOL                 bSuccess  =  FALSE;
InBlock.gif   DWORD                dwNewAclSize;
InBlock.gif   DWORD                dwSidSize  =   0 ;
InBlock.gif   DWORD                dwSdSizeNeeded;
InBlock.gif   PACL                 pacl;
InBlock.gif   PACL                 pNewAcl;
InBlock.gif   PSECURITY_DESCRIPTOR psd  =  NULL;
InBlock.gif   PSECURITY_DESCRIPTOR psdNew  =  NULL;
InBlock.gif   PVOID                pTempAce;
InBlock.gif   SECURITY_INFORMATION si  =  DACL_SECURITY_INFORMATION;
InBlock.gif   unsigned  int          i;
InBlock.gif
InBlock.gif   __try
ExpandedSubBlockStart.gif    {
InBlock.gif       //  Obtain the DACL for the window station. 
InBlock.gif 

InBlock.gif       if  ( ! GetUserObjectSecurity(
InBlock.gif             hwinsta,
InBlock.gif              & si,
InBlock.gif             psd,
InBlock.gif             dwSidSize,
InBlock.gif              & dwSdSizeNeeded)
InBlock.gif      )
InBlock.gif       if  (GetLastError()  ==  ERROR_INSUFFICIENT_BUFFER)
ExpandedSubBlockStart.gif       {
InBlock.gif         psd  =  (PSECURITY_DESCRIPTOR)HeapAlloc(
InBlock.gif               GetProcessHeap(),
InBlock.gif               HEAP_ZERO_MEMORY,
InBlock.gif               dwSdSizeNeeded);
InBlock.gif
InBlock.gif          if  (psd  ==  NULL)
InBlock.gif            __leave;
InBlock.gif
InBlock.gif         psdNew  =  (PSECURITY_DESCRIPTOR)HeapAlloc(
InBlock.gif               GetProcessHeap(),
InBlock.gif               HEAP_ZERO_MEMORY,
InBlock.gif               dwSdSizeNeeded);
InBlock.gif
InBlock.gif          if  (psdNew  ==  NULL)
InBlock.gif            __leave;
InBlock.gif
InBlock.gif         dwSidSize  =  dwSdSizeNeeded;
InBlock.gif
InBlock.gif          if  ( ! GetUserObjectSecurity(
InBlock.gif               hwinsta,
InBlock.gif                & si,
InBlock.gif               psd,
InBlock.gif               dwSidSize,
InBlock.gif                & dwSdSizeNeeded)
InBlock.gif         )
InBlock.gif            __leave;
ExpandedSubBlockEnd.gif      } 

InBlock.gif       else 
InBlock.gif         __leave;
InBlock.gif
InBlock.gif       //  Create a new DACL. 
InBlock.gif 

InBlock.gif       if  ( ! InitializeSecurityDescriptor(
InBlock.gif            psdNew,
InBlock.gif            SECURITY_DESCRIPTOR_REVISION)
InBlock.gif      )
InBlock.gif         __leave;
InBlock.gif
InBlock.gif       //  Get the DACL from the security descriptor. 
InBlock.gif 

InBlock.gif       if  ( ! GetSecurityDescriptorDacl(
InBlock.gif            psd,
InBlock.gif             & bDaclPresent,
InBlock.gif             & pacl,
InBlock.gif             & bDaclExist)
InBlock.gif      )
InBlock.gif         __leave;
InBlock.gif
InBlock.gif       //  Initialize the ACL. 
InBlock.gif 

InBlock.gif      ZeroMemory( & aclSizeInfo,  sizeof (ACL_SIZE_INFORMATION));
InBlock.gif      aclSizeInfo.AclBytesInUse  =   sizeof (ACL);
InBlock.gif
InBlock.gif       //  Call only if the DACL is not NULL. 
InBlock.gif 

InBlock.gif       if  (pacl  !=  NULL)
ExpandedSubBlockStart.gif       {
InBlock.gif          //  get the file ACL size info 
InBlock.gif 
          if  ( ! GetAclInformation(
InBlock.gif               pacl,
InBlock.gif               (LPVOID) & aclSizeInfo,
InBlock.gif                sizeof (ACL_SIZE_INFORMATION),
InBlock.gif               AclSizeInformation)
InBlock.gif         )
InBlock.gif            __leave;
ExpandedSubBlockEnd.gif      } 

InBlock.gif 
InBlock.gif       //  Compute the size of the new ACL. 
InBlock.gif 

InBlock.gif      dwNewAclSize  =  aclSizeInfo.AclBytesInUse  +  ( 2 * sizeof (ACCESS_ALLOWED_ACE))  +  
InBlock.gif( 2 * GetLengthSid(psid))  -  ( 2 * sizeof (DWORD));
InBlock.gif
InBlock.gif       //  Allocate memory for the new ACL. 
InBlock.gif 

InBlock.gif      pNewAcl  =  (PACL)HeapAlloc(
InBlock.gif            GetProcessHeap(),
InBlock.gif            HEAP_ZERO_MEMORY,
InBlock.gif            dwNewAclSize);
InBlock.gif
InBlock.gif       if  (pNewAcl  ==  NULL)
InBlock.gif         __leave;
InBlock.gif
InBlock.gif       //  Initialize the new DACL. 
InBlock.gif 

InBlock.gif       if  ( ! InitializeAcl(pNewAcl, dwNewAclSize, ACL_REVISION))
InBlock.gif         __leave;
InBlock.gif
InBlock.gif       //  If DACL is present, copy it to a new DACL. 
InBlock.gif 

InBlock.gif       if  (bDaclPresent)
ExpandedSubBlockStart.gif       {
InBlock.gif          //  Copy the ACEs to the new ACL. 
InBlock.gif 
          if  (aclSizeInfo.AceCount)
ExpandedSubBlockStart.gif          {
InBlock.gif             for  (i = 0 ; i  <  aclSizeInfo.AceCount; i ++ )
ExpandedSubBlockStart.gif             {
InBlock.gif                //  Get an ACE. 
InBlock.gif 
                if  ( ! GetAce(pacl, i,  & pTempAce))
InBlock.gif                  __leave;
InBlock.gif
InBlock.gif                //  Add the ACE to the new ACL. 
InBlock.gif 
                if  ( ! AddAce(
InBlock.gif                     pNewAcl,
InBlock.gif                     ACL_REVISION,
InBlock.gif                     MAXDWORD,
InBlock.gif                     pTempAce,
InBlock.gif                    ((PACE_HEADER)pTempAce) -> AceSize)
InBlock.gif               )
InBlock.gif                  __leave;
ExpandedSubBlockEnd.gif            } 

ExpandedSubBlockEnd.gif         } 

ExpandedSubBlockEnd.gif      } 

InBlock.gif 
InBlock.gif       //  Add the first ACE to the window station. 
InBlock.gif 

InBlock.gif      pace  =  (ACCESS_ALLOWED_ACE  * )HeapAlloc(
InBlock.gif            GetProcessHeap(),
InBlock.gif            HEAP_ZERO_MEMORY,
InBlock.gif             sizeof (ACCESS_ALLOWED_ACE)  +  GetLengthSid(psid)  - 
InBlock.gif                   sizeof (DWORD));
InBlock.gif
InBlock.gif       if  (pace  ==  NULL)
InBlock.gif         __leave;
InBlock.gif
InBlock.gif      pace -> Header.AceType   =  ACCESS_ALLOWED_ACE_TYPE;
InBlock.gif      pace -> Header.AceFlags  =  CONTAINER_INHERIT_ACE  | 
InBlock.gif                   INHERIT_ONLY_ACE  |  OBJECT_INHERIT_ACE;
InBlock.gif      pace -> Header.AceSize   =   sizeof (ACCESS_ALLOWED_ACE)  + 
InBlock.gif                   GetLengthSid(psid)  -   sizeof (DWORD);
InBlock.gif      pace -> Mask             =  GENERIC_ACCESS;
InBlock.gif
InBlock.gif       if  ( ! CopySid(GetLengthSid(psid),  & pace -> SidStart, psid))
InBlock.gif         __leave;
InBlock.gif
InBlock.gif       if  ( ! AddAce(
InBlock.gif            pNewAcl,
InBlock.gif            ACL_REVISION,
InBlock.gif            MAXDWORD,
InBlock.gif            (LPVOID)pace,
InBlock.gif            pace -> Header.AceSize)
InBlock.gif      )
InBlock.gif         __leave;
InBlock.gif
InBlock.gif       //  Add the second ACE to the window station. 
InBlock.gif 

InBlock.gif      pace -> Header.AceFlags  =  NO_PROPAGATE_INHERIT_ACE;
InBlock.gif      pace -> Mask             =  WINSTA_ALL;
InBlock.gif
InBlock.gif       if  ( ! AddAce(
InBlock.gif            pNewAcl,
InBlock.gif            ACL_REVISION,
InBlock.gif            MAXDWORD,
InBlock.gif            (LPVOID)pace,
InBlock.gif            pace -> Header.AceSize)
InBlock.gif      )
InBlock.gif         __leave;
InBlock.gif
InBlock.gif       //  Set a new DACL for the security descriptor. 
InBlock.gif 

InBlock.gif       if  ( ! SetSecurityDescriptorDacl(
InBlock.gif            psdNew,
InBlock.gif            TRUE,
InBlock.gif            pNewAcl,
InBlock.gif            FALSE)
InBlock.gif      )
InBlock.gif         __leave;
InBlock.gif
InBlock.gif       //  Set the new security descriptor for the window station. 
InBlock.gif 

InBlock.gif       if  ( ! SetUserObjectSecurity(hwinsta,  & si, psdNew))
InBlock.gif         __leave;
InBlock.gif
InBlock.gif       //  Indicate success. 
InBlock.gif 

InBlock.gif      bSuccess  =  TRUE;
ExpandedSubBlockEnd.gif   } 

InBlock.gif   __finally
ExpandedSubBlockStart.gif    {
InBlock.gif       //  Free the allocated buffers. 
InBlock.gif 

InBlock.gif       if  (pace  !=  NULL)
InBlock.gif         HeapFree(GetProcessHeap(),  0 , (LPVOID)pace);
InBlock.gif
InBlock.gif       if  (pNewAcl  !=  NULL)
InBlock.gif         HeapFree(GetProcessHeap(),  0 , (LPVOID)pNewAcl);
InBlock.gif
InBlock.gif       if  (psd  !=  NULL)
InBlock.gif         HeapFree(GetProcessHeap(),  0 , (LPVOID)psd);
InBlock.gif
InBlock.gif       if  (psdNew  !=  NULL)
InBlock.gif         HeapFree(GetProcessHeap(),  0 , (LPVOID)psdNew);
ExpandedSubBlockEnd.gif   } 

InBlock.gif 
InBlock.gif    return  bSuccess;
InBlock.gif
ExpandedBlockEnd.gif

None.gif 
None.gifBOOL AddAceToDesktop(HDESK hdesk, PSID psid)
ExpandedBlockStart.gif  {
InBlock.gif   ACL_SIZE_INFORMATION aclSizeInfo;
InBlock.gif   BOOL                 bDaclExist;
InBlock.gif   BOOL                 bDaclPresent;
InBlock.gif   BOOL                 bSuccess  =  FALSE;
InBlock.gif   DWORD                dwNewAclSize;
InBlock.gif   DWORD                dwSidSize  =   0 ;
InBlock.gif   DWORD                dwSdSizeNeeded;
InBlock.gif   PACL                 pacl;
InBlock.gif   PACL                 pNewAcl;
InBlock.gif   PSECURITY_DESCRIPTOR psd  =  NULL;
InBlock.gif   PSECURITY_DESCRIPTOR psdNew  =  NULL;
InBlock.gif   PVOID                pTempAce;
InBlock.gif   SECURITY_INFORMATION si  =  DACL_SECURITY_INFORMATION;
InBlock.gif   unsigned  int          i;
InBlock.gif
InBlock.gif   __try
ExpandedSubBlockStart.gif    {
InBlock.gif       //  Obtain the security descriptor for the desktop object. 
InBlock.gif 

InBlock.gif       if  ( ! GetUserObjectSecurity(
InBlock.gif            hdesk,
InBlock.gif             & si,
InBlock.gif            psd,
InBlock.gif            dwSidSize,
InBlock.gif             & dwSdSizeNeeded))
ExpandedSubBlockStart.gif       {
InBlock.gif          if  (GetLastError()  ==  ERROR_INSUFFICIENT_BUFFER)
ExpandedSubBlockStart.gif          {
InBlock.gif            psd  =  (PSECURITY_DESCRIPTOR)HeapAlloc(
InBlock.gif                  GetProcessHeap(),
InBlock.gif                  HEAP_ZERO_MEMORY,
InBlock.gif                  dwSdSizeNeeded );
InBlock.gif
InBlock.gif             if  (psd  ==  NULL)
InBlock.gif               __leave;
InBlock.gif
InBlock.gif            psdNew  =  (PSECURITY_DESCRIPTOR)HeapAlloc(
InBlock.gif                  GetProcessHeap(),
InBlock.gif                  HEAP_ZERO_MEMORY,
InBlock.gif                  dwSdSizeNeeded);
InBlock.gif
InBlock.gif             if  (psdNew  ==  NULL)
InBlock.gif               __leave;
InBlock.gif
InBlock.gif            dwSidSize  =  dwSdSizeNeeded;
InBlock.gif
InBlock.gif             if  ( ! GetUserObjectSecurity(
InBlock.gif                  hdesk,
InBlock.gif                   & si,
InBlock.gif                  psd,
InBlock.gif                  dwSidSize,
InBlock.gif                   & dwSdSizeNeeded)
InBlock.gif            )
InBlock.gif               __leave;
ExpandedSubBlockEnd.gif         } 

InBlock.gif          else 
InBlock.gif            __leave;
ExpandedSubBlockEnd.gif      } 

InBlock.gif 
InBlock.gif       //  Create a new security descriptor. 
InBlock.gif 

InBlock.gif       if  ( ! InitializeSecurityDescriptor(
InBlock.gif            psdNew,
InBlock.gif            SECURITY_DESCRIPTOR_REVISION)
InBlock.gif      )
InBlock.gif         __leave;
InBlock.gif
InBlock.gif       //  Obtain the DACL from the security descriptor. 
InBlock.gif 

InBlock.gif       if  ( ! GetSecurityDescriptorDacl(
InBlock.gif            psd,
InBlock.gif             & bDaclPresent,
InBlock.gif             & pacl,
InBlock.gif             & bDaclExist)
InBlock.gif      )
InBlock.gif         __leave;
InBlock.gif
InBlock.gif       //  Initialize. 
InBlock.gif 

InBlock.gif      ZeroMemory( & aclSizeInfo,  sizeof (ACL_SIZE_INFORMATION));
InBlock.gif      aclSizeInfo.AclBytesInUse  =   sizeof (ACL);
InBlock.gif
InBlock.gif       //  Call only if NULL DACL. 
InBlock.gif 

InBlock.gif       if  (pacl  !=  NULL)
ExpandedSubBlockStart.gif       {
InBlock.gif          //  Determine the size of the ACL information. 
InBlock.gif 

InBlock.gif          if  ( ! GetAclInformation(
InBlock.gif               pacl,
InBlock.gif               (LPVOID) & aclSizeInfo,
InBlock.gif                sizeof (ACL_SIZE_INFORMATION),
InBlock.gif               AclSizeInformation)
InBlock.gif         )
InBlock.gif            __leave;
ExpandedSubBlockEnd.gif      } 

InBlock.gif 
InBlock.gif       //  Compute the size of the new ACL. 
InBlock.gif 

InBlock.gif      dwNewAclSize  =  aclSizeInfo.AclBytesInUse  + 
InBlock.gif             sizeof (ACCESS_ALLOWED_ACE)  + 
InBlock.gif            GetLengthSid(psid)  -   sizeof (DWORD);
InBlock.gif
InBlock.gif       //  Allocate buffer for the new ACL. 
InBlock.gif 

InBlock.gif      pNewAcl  =  (PACL)HeapAlloc(
InBlock.gif            GetProcessHeap(),
InBlock.gif            HEAP_ZERO_MEMORY,
InBlock.gif            dwNewAclSize);
InBlock.gif
InBlock.gif       if  (pNewAcl  ==  NULL)
InBlock.gif         __leave;
InBlock.gif
InBlock.gif       //  Initialize the new ACL. 
InBlock.gif 

InBlock.gif       if  ( ! InitializeAcl(pNewAcl, dwNewAclSize, ACL_REVISION))
InBlock.gif         __leave;
InBlock.gif
InBlock.gif       //  If DACL is present, copy it to a new DACL. 
InBlock.gif 

InBlock.gif       if  (bDaclPresent)
ExpandedSubBlockStart.gif       {
InBlock.gif          //  Copy the ACEs to the new ACL. 
InBlock.gif 
          if  (aclSizeInfo.AceCount)
ExpandedSubBlockStart.gif          {
InBlock.gif             for  (i = 0 ; i  <  aclSizeInfo.AceCount; i ++ )
ExpandedSubBlockStart.gif             {
InBlock.gif                //  Get an ACE. 
InBlock.gif 
                if  ( ! GetAce(pacl, i,  & pTempAce))
InBlock.gif                  __leave;
InBlock.gif
InBlock.gif                //  Add the ACE to the new ACL. 
InBlock.gif 
                if  ( ! AddAce(
InBlock.gif                  pNewAcl,
InBlock.gif                  ACL_REVISION,
InBlock.gif                  MAXDWORD,
InBlock.gif                  pTempAce,
InBlock.gif                  ((PACE_HEADER)pTempAce) -> AceSize)
InBlock.gif               )
InBlock.gif                  __leave;
ExpandedSubBlockEnd.gif            } 

ExpandedSubBlockEnd.gif         } 

ExpandedSubBlockEnd.gif      } 

InBlock.gif 
InBlock.gif       //  Add ACE to the DACL. 
InBlock.gif 

InBlock.gif       if  ( ! AddAccessAllowedAce(
InBlock.gif            pNewAcl,
InBlock.gif            ACL_REVISION,
InBlock.gif            DESKTOP_ALL,
InBlock.gif            psid)
InBlock.gif      )
InBlock.gif         __leave;
InBlock.gif
InBlock.gif       //  Set new DACL to the new security descriptor. 
InBlock.gif 

InBlock.gif       if  ( ! SetSecurityDescriptorDacl(
InBlock.gif            psdNew,
InBlock.gif            TRUE,
InBlock.gif            pNewAcl,
InBlock.gif            FALSE)
InBlock.gif      )
InBlock.gif         __leave;
InBlock.gif
InBlock.gif       //  Set the new security descriptor for the desktop object. 
InBlock.gif 

InBlock.gif       if  ( ! SetUserObjectSecurity(hdesk,  & si, psdNew))
InBlock.gif         __leave;
InBlock.gif
InBlock.gif       //  Indicate success. 
InBlock.gif 

InBlock.gif      bSuccess  =  TRUE;
ExpandedSubBlockEnd.gif   } 

InBlock.gif   __finally
ExpandedSubBlockStart.gif    {
InBlock.gif       //  Free buffers. 
InBlock.gif 

InBlock.gif       if  (pNewAcl  !=  NULL)
InBlock.gif         HeapFree(GetProcessHeap(),  0 , (LPVOID)pNewAcl);
InBlock.gif
InBlock.gif       if  (psd  !=  NULL)
InBlock.gif         HeapFree(GetProcessHeap(),  0 , (LPVOID)psd);
InBlock.gif
InBlock.gif       if  (psdNew  !=  NULL)
InBlock.gif         HeapFree(GetProcessHeap(),  0 , (LPVOID)psdNew);
ExpandedSubBlockEnd.gif   } 

InBlock.gif 
InBlock.gif    return  bSuccess;
ExpandedBlockEnd.gif
目录
相关文章
|
1月前
|
负载均衡 Java 应用服务中间件
Client not connected, current status:STARTING
Client not connected, current status:STARTING
166 1
|
网络协议
Job for named.service failed because the control process exited with error code.
Job for named.service failed because the control process exited with error code.
637 0
|
网络安全 开发工具
【解决方案】A session ended very soon after starting. Check that the command in profile “XXX” is correct.
【解决方案】A session ended very soon after starting. Check that the command in profile “XXX” is correct.
827 0
【解决方案】A session ended very soon after starting. Check that the command in profile “XXX” is correct.
‘Client‘ is not allowed to run in parallel.Would you like to stop the running one?
‘Client‘ is not allowed to run in parallel.Would you like to stop the running one?
476 0
‘Client‘ is not allowed to run in parallel.Would you like to stop the running one?
|
网络协议
Job for named.service failed because the control process exited with error code.怎么解决
本篇内容记录了如何解决Job for named.service failed because the control process exited with error code.的问题。
3291 0
Job for named.service failed because the control process exited with error code.怎么解决
|
网络协议 网络安全 Android开发
ADB Server failed to start daemon * error: cannot connect to daemon
问题描述:Invalid argument: cannot open transport registration socketpair could not read ok from ADB Server failed to start daemon * error: cannot connect to daemon
616 0
Starting a Gradle Daemon, 5 busy and 1 incompatible and 1 stopped Daemons could not be reused, use --status for details FAILURE: Build failed with an
执行gradle build出的问题,查看hs_err_pid11064.log日志文件发现,是电脑的RAM不足导致
4013 0