VirtualBox

Changeset 27437 in vbox


Ignore:
Timestamp:
Mar 17, 2010 11:30:28 AM (15 years ago)
Author:
vboxsync
Message:

IPRT/testcase: Bits for user RTProcCreateEx.

Location:
trunk/src/VBox/Runtime/testcase
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/testcase/Makefile.kmk

    r27345 r27437  
    394394tstRTProcCreateEx_TEMPLATE = VBOXR3TSTEXE
    395395tstRTProcCreateEx_SOURCES = tstRTProcCreateEx.cpp
     396tstRTProcCreateEx_LIBS += Secur32.lib
    396397
    397398tstRTProcWait_SOURCES = tstRTProcWait.cpp
     
    470471
    471472#
    472 # odds and  ends
     473# odds and ends
    473474#
    474475
  • trunk/src/VBox/Runtime/testcase/tstRTProcCreateEx.cpp

    r27387 r27437  
    3939#include <iprt/err.h>
    4040#include <iprt/initterm.h>
     41#include <iprt/mem.h>
    4142#include <iprt/message.h>
    4243#include <iprt/param.h>
     
    4748#include <iprt/thread.h>
    4849
     50#ifdef RT_OS_WINDOWS
     51# define SECURITY_WIN32
     52# include <windows.h>
     53# include <Security.h>
     54#endif
    4955
    5056/*******************************************************************************
     
    6975};
    7076
     77static int tstRTCreateProcEx5Child(int argc, char **argv)
     78{
     79    int rc = RTR3Init();
     80    if (rc)
     81        return RTMsgInitFailure(rc);
     82
     83#ifdef RT_OS_WINDOWS
     84    char szUser[_1K];
     85    DWORD cbLen = sizeof(szUser);
     86    /** @todo Does not yet handle ERROR_MORE_DATA for user names longer than 32767. */
     87    if (!GetUserNameEx(NameSamCompatible, szUser, &cbLen))
     88    {
     89        RTPrintf("GetUserNameEx failed with last error=%ld\n", GetLastError());
     90        return VERR_AUTHENTICATION_FAILURE;
     91    }
     92    else
     93    {
     94        DWORD cbSid = 0;
     95        DWORD cbDomain = 0;
     96        SID_NAME_USE sidUse;
     97        /* First try to figure out how much space for SID + domain name we need. */
     98        BOOL bRet = LookupAccountName(NULL /* current system*/,
     99                                      szUser,
     100                                      NULL,
     101                                      &cbSid,
     102                                      NULL,
     103                                      &cbDomain,
     104                                      &sidUse);
     105        if (!bRet)
     106        {
     107            DWORD dwErr = GetLastError();
     108            if (dwErr != ERROR_INSUFFICIENT_BUFFER)
     109            {
     110                RTPrintf("LookupAccountName(1) failed with last error=%ld\n", dwErr);
     111                return VERR_AUTHENTICATION_FAILURE;
     112            }
     113        }
     114
     115        /* Now try getting the real SID + domain name. */
     116        SID *pSid = (SID *)RTMemAlloc(cbSid);
     117        AssertPtr(pSid);
     118        char *pszDomain = (char *)RTMemAlloc(cbDomain); /* Size in TCHAR! */
     119        AssertPtr(pszDomain);
     120   
     121        if (!LookupAccountName(NULL /* Current system */,
     122                               szUser,
     123                               pSid,
     124                               &cbSid,
     125                               pszDomain,
     126                               &cbDomain,
     127                               &sidUse))
     128        {
     129            RTPrintf("LookupAccountName(2) failed with last error=%ld\n", GetLastError());
     130            return VERR_AUTHENTICATION_FAILURE;
     131        }
     132        else
     133        {
     134            RTPrintf("NameSamCompatible: %s\n"
     135                     "DomainName: %s\n",
     136                     pszDomain, szUser);
     137        }
     138        RTMemFree(pSid);
     139        RTMemFree(pszDomain);
     140    }
     141#else
     142    /** @todo Lookup UID/effective UID, maybe GID? */
     143#endif
     144    return rc;
     145}
     146
     147static void tstRTCreateProcEx5(void)
     148{
     149    RTTestISub("Impersonation (as user)");
     150
     151    const char * apszArgs[3] =
     152    {
     153        "test", /* user name */
     154        "--testcase-child-5",
     155        NULL
     156    };
     157
     158    RTPROCESS hProc;
     159    RTTESTI_CHECK_RC_RETV(RTProcCreateEx(g_szExecName, apszArgs, RTENV_DEFAULT, 0 /*fFlags*/, NULL,
     160                                         NULL, NULL, NULL, &hProc), VINF_SUCCESS);
     161    RTPROCSTATUS ProcStatus = { -1, RTPROCEXITREASON_ABEND };
     162    RTTESTI_CHECK_RC(RTProcWait(hProc, RTPROCWAIT_FLAGS_BLOCK, &ProcStatus), VINF_SUCCESS);
     163
     164    if (ProcStatus.enmReason != RTPROCEXITREASON_NORMAL || ProcStatus.iStatus != 0)
     165        RTTestIFailed("enmReason=%d iStatus=%d", ProcStatus.enmReason, ProcStatus.iStatus);
     166    else
     167        RTTestIPassed(NULL);
     168}
     169
     170
    71171static int tstRTCreateProcEx4Child(int argc, char **argv)
    72172{
     
    316416    if (argc >= 5 && !strcmp(argv[1], "--testcase-child-4"))
    317417        return tstRTCreateProcEx4Child(argc, argv);
     418    if (argc == 2 && !strcmp(argv[1], "--testcase-child-5"))
     419        return tstRTCreateProcEx5Child(argc, argv);
    318420    if (argc != 1)
    319421        return 99;
     
    335437    tstRTCreateProcEx3();
    336438    tstRTCreateProcEx4();
    337     /** @todo Cover files, pszAsUser, ++ */
     439    /** @todo Do not run tstRTCreateProcEx5 on NT4, may not work (?) */
     440    tstRTCreateProcEx5();
     441    /** @todo Cover files, ++ */
    338442
    339443    /*
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette