Automating DCOM settings

From: John (no_at_spam.com)
Date: 06/25/04


Date: Thu, 24 Jun 2004 16:49:12 -0700

I would like to automate the changes that are required for our DCOM
server using the access-control API. The code will execute during the
program's installation.

If the user is using peer-to-peer workgroup networking, it is required
to make settings to the machine DCOM defaults.

DCOM Settings:
     Default Authentication Level: None
     COM Security Default Access Permissions:
         Access permitted to \Everyone
         Access permitted to NT AUTHORITY\INTERACTIVE
         Access permitted to NT AUTHORITY\NETWORK
         Access permitted to NT AUTHORITY\SYSTEM
     COM Security Default Launch Permissions:
         Launch permitted to \Everyone
         Launch permitted to NT AUTHORITY\INTERACTIVE
         Access permitted to NT AUTHORITY\NETWORK
         Launch permitted to NT AUTHORITY\SYSTEM

Below I post some code that I thought would be enough to set these
machine defaults. Unfortunately, although things look good in dcomcnfg
after running this code, it seems to have permanently corrupted DCOM and
Windows to the point that the only recovery is to reinstall Windows. Can
anyone see what is missing?

My concerns are:
1) Is it ok to allocate the absolute SD with
SECURITY_DESCRIPTOR* psdAbsolute =
(SECURITY_DESCRIPTOR*)malloc(sizeof(SECURITY_DESCRIPTOR));
before calling InitializeSecurityDescriptor?

2) Do I need to give the SD more properties, for instance an owner. If
it needs an owner who/what should it be?

Thanks

ASCINST_API void WINAPI
DoDCOMConfigServerWG(LPCTSTR serverName)
{
   BOOL test = FALSE; //debug
   /*
     Registry entries

     Machine Default AuthenticationLevel=None
     Machine Default LaunchPermission={self-relative security descriptor}
     Machine Default AccessPermission={self-relative security descriptor}
   */

   // generate the entries for the ACL to be used for Access and Launch
permissions
   EXPLICIT_ACCESS ea[4];
   for( int i=0; i<4; i++ )
   {
     ZeroMemory(&ea[i], sizeof(EXPLICIT_ACCESS));
     ea[i].grfAccessPermissions = 1; //COM_RIGHTS_EXECUTE;
     ea[i].grfAccessMode = GRANT_ACCESS;
     ea[i].grfInheritance= SUB_CONTAINERS_AND_OBJECTS_INHERIT;

     ea[i].Trustee.pMultipleTrustee = NULL;
     ea[i].Trustee.MultipleTrusteeOperation = NO_MULTIPLE_TRUSTEE;

     switch (i)
     {
     case 0:
       ea[i].Trustee.TrusteeForm = TRUSTEE_IS_NAME;
       ea[i].Trustee.TrusteeType = TRUSTEE_IS_GROUP;
       ea[i].Trustee.ptstrName = _T("EVERYONE");
       break;
     case 1:
       ea[i].Trustee.TrusteeForm = TRUSTEE_IS_NAME;
       ea[i].Trustee.TrusteeType = TRUSTEE_IS_GROUP;
       ea[i].Trustee.ptstrName = _T("SYSTEM");
       break;
     case 2:
       ea[i].Trustee.TrusteeForm = TRUSTEE_IS_NAME;
       ea[i].Trustee.TrusteeType = TRUSTEE_IS_GROUP;
       ea[i].Trustee.ptstrName = _T("NETWORK");
       break;
     case 3:
       ea[i].Trustee.TrusteeForm = TRUSTEE_IS_NAME;
       ea[i].Trustee.TrusteeType = TRUSTEE_IS_GROUP;
       ea[i].Trustee.ptstrName = _T("INTERACTIVE");
       break;
     }
   }

   // we need to create a self-relative security descriptor that will be
stored in the registry.
   // if all goes well setting up the security descriptor, continue with
the DCOM configuration
   ACL* pACL = NULL;
   SECURITY_DESCRIPTOR* psdAbsolute =
(SECURITY_DESCRIPTOR*)malloc(sizeof(SECURITY_DESCRIPTOR));
   SECURITY_DESCRIPTOR* psdSelfRelative = NULL;

   HKEY key = 0;
   DWORD AuthLevel = 0;

   if (SetEntriesInAcl(4, &ea[0], NULL, &pACL) == ERROR_SUCCESS)
   {
     test = IsValidAcl(pACL); //debug
     if( ::InitializeSecurityDescriptor(psdAbsolute,
SECURITY_DESCRIPTOR_REVISION) )
     {
       test = IsValidSecurityDescriptor(psdAbsolute); //debug
       if( ::SetSecurityDescriptorDacl(psdAbsolute, TRUE, pACL, FALSE) )
       {
         test = IsValidSecurityDescriptor(psdAbsolute); //debug
         DWORD sdSize = 0;
         ::MakeSelfRelativeSD(psdAbsolute, psdSelfRelative, &sdSize);
         psdSelfRelative = (SECURITY_DESCRIPTOR*) malloc(sdSize);
         if( ::MakeSelfRelativeSD(psdAbsolute, psdSelfRelative, &sdSize) )
         {
           test = IsValidSecurityDescriptor(psdSelfRelative); //debug
           // we have now succesfully created a self-relative security
descriptor which contains our ACL

           if( ::RegOpenKeyEx(HKEY_LOCAL_MACHINE,
_T("Software\\Microsoft\\Ole"), 0,
                              KEY_ALL_ACCESS, &key) == ERROR_SUCCESS )
           {
             // set the machine default LaunchPermission
            ::RegSetValueEx(key, _T("DefaultLaunchPermission"), 0,
REG_BINARY,
                            reinterpret_cast<const BYTE*>(psdSelfRelative),
                            GetSecurityDescriptorLength(psdSelfRelative));

             // set the machine default AccessPermission
             ::RegSetValueEx(key, _T("DefaultAccessPermission"), 0,
REG_BINARY,
                             reinterpret_cast<const
BYTE*>(psdSelfRelative),
                             GetSecurityDescriptorLength(psdSelfRelative));

             // set the machine default AuthenticationLevel
             DWORD AuthLevel = 1; // None

             ::RegSetValueEx(key, _T("LegacyAuthenticationLevel"), 0,
REG_DWORD,
                             reinterpret_cast<const BYTE*>(&AuthLevel),
                             sizeof(DWORD));

             // close the key
             ::RegCloseKey(key);
           }
         }
       }
     }
   }

   // cleanup
   if( pACL )
     LocalFree((HLOCAL) pACL);
   if( psdAbsolute )
     free(psdAbsolute);
   if( psdSelfRelative )
     free(psdSelfRelative);
}



Relevant Pages

  • Re: Win2k3 SP1 error: New transaction cannot enlist in the specifi
    ... When I wrote NT4 post SP4, that was because DCOM was not available before ... twiddling with the authetication settings might get ... >>> that the WEB server lies in another domain than the SQL Server. ...
    (microsoft.public.windows.server.general)
  • Re: DCOM problems
    ... > configuring DCOM. ... > server and receives callbacks from the server. ... > We have tried tens of settings in DCOMCNFG with any success. ... reboot, ...
    (microsoft.public.vb.com)
  • Re: Queries regarding DCOM Security Enhancements in Windows XP Service Pack 2
    ... server or for access to one of its methods is received by Windows XP SP2, ... DCOM applies the *most restrictive* security settings of those assigned to ...
    (microsoft.public.win32.programmer.ole)
  • Re: DCOM Error in SBS20032 SP1
    ... You may disable DCOM for this service on the Windows server. ... you will see the of the DCOM application. ... Microsoft CSS Online Newsgroup Support ... |>> obviously it did not resolve the error and have no idea where to go. ...
    (microsoft.public.windows.server.sbs)
  • RE: DCOM Server Event ID 10003
    ... I don't know what DCOM is. ... And I don't understand what Microsoft ... "Access denied attempting to launch a DCOM Server using ... > an instance of a word application / a word document using DCOM. ...
    (microsoft.public.windows.server.sbs)