示例#1
0
文件: tse.c 项目: mingpen/OpenNT
void
TestGetPrivNameA(
    LPSTR *PrivName,
    PLUID  lpLuid
    )
{


    BOOL          Bool;
    DWORD         cbName = 0;
    PCHAR         Name = NULL;


    Bool = LookupPrivilegeNameA(
               NULL,
               lpLuid,
               Name,
               &cbName
               );
    ASSERT( !Bool && GetLastError() == ERROR_INSUFFICIENT_BUFFER );

    Name = RtlAllocateHeap( RtlProcessHeap(), 0, (cbName+1)*sizeof(CHAR) );

    Bool = LookupPrivilegeNameA(
               NULL,
               lpLuid,
               Name,
               &cbName
               );
    ASSERT(Bool);

    (*PrivName) = (LPSTR)Name;

    return;
}
示例#2
0
文件: tse.c 项目: mingpen/OpenNT
void
TestLookupPrivilegeNameA(
    PLUID lpLuid
    )

{

    //
    // LookupPrivilegeNameA test
    //

    BOOL          Bool;
    DWORD         cbName = 0;
    UCHAR         Name[BUFFER_SIZE];


    printf("      LookupA call . . . . . . . . . . . . . . . . . ");


    Bool = LookupPrivilegeNameA(
               NULL,
               lpLuid,
               Name,
               &cbName
               );

    //
    // Expect failure here
    //

    if ( !Bool && GetLastError() != ERROR_INSUFFICIENT_BUFFER ) {
        printf("** FAILED **\n");
        printf("        First call.\n");
        printf("        Status:             %d\n", GetLastError());
        printf("        Name Length:        %d\n", cbName);
    } else {


        Bool = LookupPrivilegeNameA(
                   NULL,
                   lpLuid,
                   Name,
                   &cbName
                   );

        if ( !Bool ) {
            printf("** FAILED **\n");
            printf("        Second call.\n");
            printf("        Status:             %d\n", GetLastError());
            printf("        Name Length:        %d\n", cbName);
        } else {
            printf("Succeeded\n");
            printf("        Name Length:        %d\n", cbName);
            printf("        Name:               *%s*\n", Name);
            printf("\n\n");
        }
    }

}
BOOL DisplayAllPrivileges(HANDLE hToken)
{
	BOOL bResult = FALSE;
	DWORD dwSize = 0;
	TOKEN_PRIVILEGES* pTokenPrivilegesInfo = NULL;
	pTokenPrivilegesInfo = (TOKEN_PRIVILEGES*)RetrieveTokenInformation(hToken, TokenPrivileges, dwSize);
	ASSERT_NOTNULLRET(pTokenPrivilegesInfo, FALSE);

	CHAR lpwNameBuf[MAX_PATH] = { 0 };
	DWORD bufSize = 0;
	LUID_AND_ATTRIBUTES *pPrivilegeAttr = NULL;
	for (UINT i = 0; i < pTokenPrivilegesInfo->PrivilegeCount; ++i)
	{
		pPrivilegeAttr = &(pTokenPrivilegesInfo->Privileges[i]);
		bufSize = MAX_PATH - 1;
		if (FALSE == LookupPrivilegeNameA("", &(pTokenPrivilegesInfo->Privileges[i].Luid), lpwNameBuf, &bufSize))
		{
			DOLOG("LookupPrivilegeNameW failed ErrorCocde: " + GetLastError());
			bResult = FALSE;
			break;
		}

		DOLOG("Privilege Name:" + lpwNameBuf + " , Enable: " + (pPrivilegeAttr->Attributes == SE_PRIVILEGE_ENABLED)
			+ ", Default Enable: " + (pPrivilegeAttr->Attributes == SE_PRIVILEGE_ENABLED_BY_DEFAULT) 
			+ ", Remove : " + (pPrivilegeAttr->Attributes == SE_PRIVILEGE_REMOVED)
			+ ", Access: " + (pPrivilegeAttr->Attributes == SE_PRIVILEGE_USED_FOR_ACCESS));
		bResult = TRUE;
	}
	free(pTokenPrivilegesInfo);

	return bResult ;
}