ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

NTSTATUS NTAPI CmLoadKey ( IN POBJECT_ATTRIBUTES  TargetKey,
IN POBJECT_ATTRIBUTES  SourceFile,
IN ULONG  Flags,
IN PCM_KEY_BODY  KeyBody 
)

Definition at line 1659 of file cmapi.c.

Referenced by NtLoadKeyEx().

{
    SECURITY_QUALITY_OF_SERVICE ServiceQos;
    SECURITY_CLIENT_CONTEXT ClientSecurityContext;
    HANDLE KeyHandle;
    BOOLEAN Allocate = TRUE;
    PCMHIVE CmHive, LoadedHive;
    NTSTATUS Status;
    CM_PARSE_CONTEXT ParseContext;
    
    /* Check if we have a trust key */
    if (KeyBody)
    {
        /* Fail */
        DPRINT1("Trusted classes not yet supported\n");
        return STATUS_NOT_IMPLEMENTED;
    }
    
    /* Build a service QoS for a security context */
    ServiceQos.Length = sizeof(SECURITY_QUALITY_OF_SERVICE);
    ServiceQos.ImpersonationLevel = SecurityImpersonation;
    ServiceQos.ContextTrackingMode = SECURITY_DYNAMIC_TRACKING;
    ServiceQos.EffectiveOnly = TRUE;
    Status = SeCreateClientSecurity(PsGetCurrentThread(),
                                    &ServiceQos,
                                    FALSE,
                                    &ClientSecurityContext);
    if (!NT_SUCCESS(Status))
    {
        /* Fail */
        DPRINT1("Security context failed\n");
        return Status;
    }
    
    /* Open the target key */
#if 0
    Status = ZwOpenKey(&KeyHandle, KEY_READ, TargetKey);
#else
    RtlZeroMemory(&ParseContext, sizeof(ParseContext));
    ParseContext.CreateOperation = FALSE;
    Status = ObOpenObjectByName(TargetKey,
                                CmpKeyObjectType,
                                KernelMode,
                                NULL,
                                KEY_READ,
                                &ParseContext,
                                &KeyHandle);
#endif
    if (!NT_SUCCESS(Status)) KeyHandle = NULL;

    /* Open the hive */
    Status = CmpCmdHiveOpen(SourceFile,
                            &ClientSecurityContext,
                            &Allocate,
                            &CmHive,
                            0);

    /* Get rid of the security context */
    SeDeleteClientSecurity(&ClientSecurityContext);

    /* See if we failed */
    if (!NT_SUCCESS(Status))
    {
        /* See if the target already existed */
        if (KeyHandle)
        {
            /* Lock the registry */
            CmpLockRegistryExclusive();
            
            /* Check if we are already loaded */
            if (CmpIsHiveAlreadyLoaded(KeyHandle, SourceFile, &LoadedHive))
            {
                /* That's okay then */
                ASSERT(LoadedHive);
                Status = STATUS_SUCCESS;
            }

            /* Release the registry */
            CmpUnlockRegistry();
        }
        
        /* Close the key handle if we had one */
        if (KeyHandle) ZwClose(KeyHandle);
        return Status;
    }
    
    /* Lock the registry shared */
    CmpLockRegistry();
    
    /* Lock loading */
    ExAcquirePushLockExclusive(&CmpLoadHiveLock);
    
    /* Lock the hive to this thread */
    CmHive->Hive.HiveFlags |= HIVE_IS_UNLOADING;
    CmHive->CreatorOwner = KeGetCurrentThread();
    
    /* Set flag */
    if (Flags & REG_NO_LAZY_FLUSH) CmHive->Hive.HiveFlags |= HIVE_NOLAZYFLUSH;
    
    /* Link the hive */
    Status = CmpLinkHiveToMaster(TargetKey->ObjectName,
                                 TargetKey->RootDirectory,
                                 CmHive,
                                 Allocate,
                                 TargetKey->SecurityDescriptor);
    if (NT_SUCCESS(Status))
    {
        /* Add to HiveList key */
        CmpAddToHiveFileList(CmHive);
        
        /* Sync the hive if necessary */
        if (Allocate)
        {
            /* Sync it under the flusher lock */
            CmpLockHiveFlusherExclusive(CmHive);
            HvSyncHive(&CmHive->Hive);
            CmpUnlockHiveFlusher(CmHive);
        }
        
        /* Release the hive */
        CmHive->Hive.HiveFlags &= ~HIVE_IS_UNLOADING;
        CmHive->CreatorOwner = NULL;
        
        /* Allow loads */
        ExReleasePushLock(&CmpLoadHiveLock);
    }
    else
    {
        DPRINT1("CmpLinkHiveToMaster failed, Status %lx\n", Status);
        /* FIXME: TODO */
        ASSERT(FALSE);
    }
    
    /* Is this first profile load? */
    if (!(CmpProfileLoaded) && !(CmpWasSetupBoot))
    {
        /* User is now logged on, set quotas */
        CmpProfileLoaded = TRUE;
        CmpSetGlobalQuotaAllowed();
    }
    
    /* Unlock the registry */
    CmpUnlockRegistry();
    
    /* Close handle and return */
    if (KeyHandle) ZwClose(KeyHandle);
    return Status;
}

Generated on Fri May 25 2012 06:04:29 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.