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 SeSetSecurityDescriptorInfo ( IN PVOID Object  OPTIONAL,
IN PSECURITY_INFORMATION  _SecurityInformation,
IN PSECURITY_DESCRIPTOR  _SecurityDescriptor,
IN OUT PSECURITY_DESCRIPTOR ObjectsSecurityDescriptor,
IN POOL_TYPE  PoolType,
IN PGENERIC_MAPPING  GenericMapping 
)

Definition at line 861 of file sd.c.

{
    PISECURITY_DESCRIPTOR_RELATIVE ObjectSd;
    PISECURITY_DESCRIPTOR_RELATIVE NewSd;
    PISECURITY_DESCRIPTOR SecurityDescriptor = _SecurityDescriptor;
    PISECURITY_DESCRIPTOR_RELATIVE RelSD = (PISECURITY_DESCRIPTOR_RELATIVE)SecurityDescriptor;
    PSID Owner = 0;
    PSID Group = 0;
    PACL Dacl = 0;
    PACL Sacl = 0;
    ULONG OwnerLength = 0;
    ULONG GroupLength = 0;
    ULONG DaclLength = 0;
    ULONG SaclLength = 0;
    ULONG Control = 0;
    ULONG Current;
    SECURITY_INFORMATION SecurityInformation;

    ObjectSd = *ObjectsSecurityDescriptor;
    ASSERT(ObjectSd->Control & SE_SELF_RELATIVE);

    /* The object does not have a security descriptor. */
    if (!ObjectSd)
        return STATUS_NO_SECURITY_ON_OBJECT;

    SecurityInformation = *_SecurityInformation;

    /* Get owner and owner size */
    if (SecurityInformation & OWNER_SECURITY_INFORMATION)
    {
        if (SecurityDescriptor->Owner != NULL)
        {
            if (SecurityDescriptor->Control & SE_SELF_RELATIVE)
                Owner = (PSID)((ULONG_PTR)RelSD->Owner +
                               (ULONG_PTR)SecurityDescriptor);
            else
                Owner = (PSID)SecurityDescriptor->Owner;
            OwnerLength = ROUND_UP(RtlLengthSid(Owner), 4);
        }

        Control |= (SecurityDescriptor->Control & SE_OWNER_DEFAULTED);
    }
    else
    {
        if (ObjectSd->Owner)
        {
            Owner = (PSID)((ULONG_PTR)ObjectSd->Owner + (ULONG_PTR)ObjectSd);
            OwnerLength = ROUND_UP(RtlLengthSid(Owner), 4);
        }

        Control |= (ObjectSd->Control & SE_OWNER_DEFAULTED);
    }

    /* Get group and group size */
    if (SecurityInformation & GROUP_SECURITY_INFORMATION)
    {
        if (SecurityDescriptor->Group != NULL)
        {
            if( SecurityDescriptor->Control & SE_SELF_RELATIVE )
                Group = (PSID)((ULONG_PTR)SecurityDescriptor->Group +
                               (ULONG_PTR)SecurityDescriptor);
            else
                Group = (PSID)SecurityDescriptor->Group;
            GroupLength = ROUND_UP(RtlLengthSid(Group), 4);
        }

        Control |= (SecurityDescriptor->Control & SE_GROUP_DEFAULTED);
    }
    else
    {
        if (ObjectSd->Group)
        {
            Group = (PSID)((ULONG_PTR)ObjectSd->Group + (ULONG_PTR)ObjectSd);
            GroupLength = ROUND_UP(RtlLengthSid(Group), 4);
        }

        Control |= (ObjectSd->Control & SE_GROUP_DEFAULTED);
    }

    /* Get DACL and DACL size */
    if (SecurityInformation & DACL_SECURITY_INFORMATION)
    {
        if ((SecurityDescriptor->Control & SE_DACL_PRESENT) &&
            (SecurityDescriptor->Dacl != NULL))
        {
            if( SecurityDescriptor->Control & SE_SELF_RELATIVE )
                Dacl = (PACL)((ULONG_PTR)SecurityDescriptor->Dacl +
                              (ULONG_PTR)SecurityDescriptor);
            else
                Dacl = (PACL)SecurityDescriptor->Dacl;

            DaclLength = ROUND_UP((ULONG)Dacl->AclSize, 4);
        }

        Control |= (SecurityDescriptor->Control & (SE_DACL_DEFAULTED | SE_DACL_PRESENT));
    }
    else
    {
        if ((ObjectSd->Control & SE_DACL_PRESENT) && (ObjectSd->Dacl))
        {
            Dacl = (PACL)((ULONG_PTR)ObjectSd->Dacl + (ULONG_PTR)ObjectSd);
            DaclLength = ROUND_UP((ULONG)Dacl->AclSize, 4);
        }

        Control |= (ObjectSd->Control & (SE_DACL_DEFAULTED | SE_DACL_PRESENT));
    }

    /* Get SACL and SACL size */
    if (SecurityInformation & SACL_SECURITY_INFORMATION)
    {
        if ((SecurityDescriptor->Control & SE_SACL_PRESENT) &&
            (SecurityDescriptor->Sacl != NULL))
        {
            if( SecurityDescriptor->Control & SE_SELF_RELATIVE )
                Sacl = (PACL)((ULONG_PTR)SecurityDescriptor->Sacl +
                              (ULONG_PTR)SecurityDescriptor);
            else
                Sacl = (PACL)SecurityDescriptor->Sacl;
            SaclLength = ROUND_UP((ULONG)Sacl->AclSize, 4);
        }

        Control |= (SecurityDescriptor->Control & (SE_SACL_DEFAULTED | SE_SACL_PRESENT));
    }
    else
    {
        if ((ObjectSd->Control & SE_SACL_PRESENT) && (ObjectSd->Sacl))
        {
            Sacl = (PACL)((ULONG_PTR)ObjectSd->Sacl + (ULONG_PTR)ObjectSd);
            SaclLength = ROUND_UP((ULONG)Sacl->AclSize, 4);
        }

        Control |= (ObjectSd->Control & (SE_SACL_DEFAULTED | SE_SACL_PRESENT));
    }

    NewSd = ExAllocatePool(NonPagedPool,
                           sizeof(SECURITY_DESCRIPTOR_RELATIVE) + OwnerLength + GroupLength +
                           DaclLength + SaclLength);
    if (NewSd == NULL)
    {
        ObDereferenceObject(Object);
        return STATUS_INSUFFICIENT_RESOURCES;
    }

    RtlCreateSecurityDescriptor(NewSd,
                                SECURITY_DESCRIPTOR_REVISION1);

    /* We always build a self-relative descriptor */
    NewSd->Control = (USHORT)Control | SE_SELF_RELATIVE;

    Current = sizeof(SECURITY_DESCRIPTOR);

    if (OwnerLength != 0)
    {
        RtlCopyMemory((PUCHAR)NewSd + Current, Owner, OwnerLength);
        NewSd->Owner = Current;
        Current += OwnerLength;
    }

    if (GroupLength != 0)
    {
        RtlCopyMemory((PUCHAR)NewSd + Current, Group, GroupLength);
        NewSd->Group = Current;
        Current += GroupLength;
    }

    if (DaclLength != 0)
    {
        RtlCopyMemory((PUCHAR)NewSd + Current, Dacl, DaclLength);
        NewSd->Dacl = Current;
        Current += DaclLength;
    }

    if (SaclLength != 0)
    {
        RtlCopyMemory((PUCHAR)NewSd + Current, Sacl, SaclLength);
        NewSd->Sacl = Current;
        Current += SaclLength;
    }

    *ObjectsSecurityDescriptor = NewSd;
    return STATUS_SUCCESS;
}

Generated on Sat May 26 2012 06:04:19 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.