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

BOOL WINAPI LogonUserW ( LPWSTR  lpszUsername,
LPWSTR  lpszDomain,
LPWSTR  lpszPassword,
DWORD  dwLogonType,
DWORD  dwLogonProvider,
PHANDLE  phToken 
)

Definition at line 595 of file logon.c.

Referenced by DoLoginTasks(), InstallReactOS(), LogonUserA(), and TUILockedSAS().

{
    /* FIXME shouldn't use hard-coded list of privileges */
    static struct
    {
      LPCWSTR PrivName;
      DWORD Attributes;
    }
    DefaultPrivs[] =
    {
      { L"SeMachineAccountPrivilege", 0 },
      { L"SeSecurityPrivilege", 0 },
      { L"SeTakeOwnershipPrivilege", 0 },
      { L"SeLoadDriverPrivilege", 0 },
      { L"SeSystemProfilePrivilege", 0 },
      { L"SeSystemtimePrivilege", 0 },
      { L"SeProfileSingleProcessPrivilege", 0 },
      { L"SeIncreaseBasePriorityPrivilege", 0 },
      { L"SeCreatePagefilePrivilege", 0 },
      { L"SeBackupPrivilege", 0 },
      { L"SeRestorePrivilege", 0 },
      { L"SeShutdownPrivilege", 0 },
      { L"SeDebugPrivilege", 0 },
      { L"SeSystemEnvironmentPrivilege", 0 },
      { L"SeChangeNotifyPrivilege", SE_PRIVILEGE_ENABLED | SE_PRIVILEGE_ENABLED_BY_DEFAULT },
      { L"SeRemoteShutdownPrivilege", 0 },
      { L"SeUndockPrivilege", 0 },
      { L"SeEnableDelegationPrivilege", 0 },
      { L"SeImpersonatePrivilege", SE_PRIVILEGE_ENABLED | SE_PRIVILEGE_ENABLED_BY_DEFAULT },
      { L"SeCreateGlobalPrivilege", SE_PRIVILEGE_ENABLED | SE_PRIVILEGE_ENABLED_BY_DEFAULT }
    };
    OBJECT_ATTRIBUTES ObjectAttributes;
    SECURITY_QUALITY_OF_SERVICE Qos;
    TOKEN_USER TokenUser;
    TOKEN_OWNER TokenOwner;
    TOKEN_PRIMARY_GROUP TokenPrimaryGroup;
    PTOKEN_GROUPS TokenGroups;
    PTOKEN_PRIVILEGES TokenPrivileges;
    TOKEN_DEFAULT_DACL TokenDefaultDacl;
    LARGE_INTEGER ExpirationTime;
    LUID AuthenticationId;
    TOKEN_SOURCE TokenSource;
    PSID UserSid = NULL;
    PSID PrimaryGroupSid = NULL;
    PSID OwnerSid = NULL;
    PSID LocalSystemSid;
    PACL Dacl;
    NTSTATUS Status;
    SID_IDENTIFIER_AUTHORITY SystemAuthority = {SECURITY_NT_AUTHORITY};
    unsigned i;

    Qos.Length = sizeof(SECURITY_QUALITY_OF_SERVICE);
    Qos.ImpersonationLevel = SecurityAnonymous;
    Qos.ContextTrackingMode = SECURITY_STATIC_TRACKING;
    Qos.EffectiveOnly = FALSE;

    ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
    ObjectAttributes.RootDirectory = NULL;
    ObjectAttributes.ObjectName = NULL;
    ObjectAttributes.Attributes = 0;
    ObjectAttributes.SecurityDescriptor = NULL;
    ObjectAttributes.SecurityQualityOfService = &Qos;

    Status = NtAllocateLocallyUniqueId(&AuthenticationId);
    if (!NT_SUCCESS(Status))
    {
        return FALSE;
    }

    ExpirationTime.QuadPart = -1;

    /* Get the user SID from the registry */
    if (!SamGetUserSid (lpszUsername, &UserSid))
    {
        ERR("SamGetUserSid() failed\n");
        return FALSE;
    }

    TokenUser.User.Sid = UserSid;
    TokenUser.User.Attributes = 0;

    /* Allocate and initialize token groups */
    TokenGroups = AllocateGroupSids(&PrimaryGroupSid,
                                    &OwnerSid);
    if (NULL == TokenGroups)
    {
        RtlFreeSid(UserSid);
        SetLastError(ERROR_OUTOFMEMORY);
        return FALSE;
    }

    /* Allocate and initialize token privileges */
    TokenPrivileges = RtlAllocateHeap(GetProcessHeap(), 0,
                                      sizeof(TOKEN_PRIVILEGES)
                                    + sizeof(DefaultPrivs) / sizeof(DefaultPrivs[0])
                                      * sizeof(LUID_AND_ATTRIBUTES));
    if (NULL == TokenPrivileges)
    {
        FreeGroupSids(TokenGroups);
        RtlFreeSid(UserSid);
        SetLastError(ERROR_OUTOFMEMORY);
        return FALSE;
    }

    TokenPrivileges->PrivilegeCount = 0;
    for (i = 0; i < sizeof(DefaultPrivs) / sizeof(DefaultPrivs[0]); i++)
    {
        if (! LookupPrivilegeValueW(NULL,
                                    DefaultPrivs[i].PrivName,
                                    &TokenPrivileges->Privileges[TokenPrivileges->PrivilegeCount].Luid))
        {
            WARN("Can't set privilege %S\n", DefaultPrivs[i].PrivName);
        }
        else
        {
            TokenPrivileges->Privileges[TokenPrivileges->PrivilegeCount].Attributes = DefaultPrivs[i].Attributes;
            TokenPrivileges->PrivilegeCount++;
        }
    }

    TokenOwner.Owner = OwnerSid;
    TokenPrimaryGroup.PrimaryGroup = PrimaryGroupSid;

    Dacl = RtlAllocateHeap(GetProcessHeap(), 0, 1024);
    if (Dacl == NULL)
    {
        FreeGroupSids(TokenGroups);
        RtlFreeSid(UserSid);
        SetLastError(ERROR_OUTOFMEMORY);
        return FALSE;
    }

    Status = RtlCreateAcl(Dacl, 1024, ACL_REVISION);
    if (!NT_SUCCESS(Status))
    {
        RtlFreeHeap(GetProcessHeap(), 0, Dacl);
        FreeGroupSids(TokenGroups);
        RtlFreeHeap(GetProcessHeap(), 0, TokenPrivileges);
        RtlFreeSid(UserSid);
        return FALSE;
    }

    RtlAddAccessAllowedAce(Dacl,
                           ACL_REVISION,
                           GENERIC_ALL,
                           OwnerSid);

    RtlAllocateAndInitializeSid(&SystemAuthority,
                                1,
                                SECURITY_LOCAL_SYSTEM_RID,
                                SECURITY_NULL_RID,
                                SECURITY_NULL_RID,
                                SECURITY_NULL_RID,
                                SECURITY_NULL_RID,
                                SECURITY_NULL_RID,
                                SECURITY_NULL_RID,
                                SECURITY_NULL_RID,
                                &LocalSystemSid);

    /* SID: S-1-5-18 */
    RtlAddAccessAllowedAce(Dacl,
                           ACL_REVISION,
                           GENERIC_ALL,
                           LocalSystemSid);

    RtlFreeSid(LocalSystemSid);

    TokenDefaultDacl.DefaultDacl = Dacl;

    memcpy(TokenSource.SourceName,
           "User32  ",
           8);

    Status = NtAllocateLocallyUniqueId(&TokenSource.SourceIdentifier);
    if (!NT_SUCCESS(Status))
    {
        RtlFreeHeap(GetProcessHeap(), 0, Dacl);
        FreeGroupSids(TokenGroups);
        RtlFreeHeap(GetProcessHeap(), 0, TokenPrivileges);
        RtlFreeSid(UserSid);
       return FALSE;
    }

    Status = NtCreateToken(phToken,
                           TOKEN_ALL_ACCESS,
                           &ObjectAttributes,
                           TokenPrimary,
                           &AuthenticationId,
                           &ExpirationTime,
                           &TokenUser,
                           TokenGroups,
                           TokenPrivileges,
                           &TokenOwner,
                           &TokenPrimaryGroup,
                           &TokenDefaultDacl,
                           &TokenSource);

    RtlFreeHeap(GetProcessHeap(), 0, Dacl);
    FreeGroupSids(TokenGroups);
    RtlFreeHeap(GetProcessHeap(), 0, TokenPrivileges);
    RtlFreeSid(UserSid);

    return NT_SUCCESS(Status);
}

Generated on Mon May 28 2012 04:43:33 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.