Changeset 27437 in vbox
- Timestamp:
- Mar 17, 2010 11:30:28 AM (15 years ago)
- Location:
- trunk/src/VBox/Runtime/testcase
- Files:
-
- 2 edited
-
Makefile.kmk (modified) (2 diffs)
-
tstRTProcCreateEx.cpp (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/testcase/Makefile.kmk
r27345 r27437 394 394 tstRTProcCreateEx_TEMPLATE = VBOXR3TSTEXE 395 395 tstRTProcCreateEx_SOURCES = tstRTProcCreateEx.cpp 396 tstRTProcCreateEx_LIBS += Secur32.lib 396 397 397 398 tstRTProcWait_SOURCES = tstRTProcWait.cpp … … 470 471 471 472 # 472 # odds and ends473 # odds and ends 473 474 # 474 475 -
trunk/src/VBox/Runtime/testcase/tstRTProcCreateEx.cpp
r27387 r27437 39 39 #include <iprt/err.h> 40 40 #include <iprt/initterm.h> 41 #include <iprt/mem.h> 41 42 #include <iprt/message.h> 42 43 #include <iprt/param.h> … … 47 48 #include <iprt/thread.h> 48 49 50 #ifdef RT_OS_WINDOWS 51 # define SECURITY_WIN32 52 # include <windows.h> 53 # include <Security.h> 54 #endif 49 55 50 56 /******************************************************************************* … … 69 75 }; 70 76 77 static 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 147 static 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 71 171 static int tstRTCreateProcEx4Child(int argc, char **argv) 72 172 { … … 316 416 if (argc >= 5 && !strcmp(argv[1], "--testcase-child-4")) 317 417 return tstRTCreateProcEx4Child(argc, argv); 418 if (argc == 2 && !strcmp(argv[1], "--testcase-child-5")) 419 return tstRTCreateProcEx5Child(argc, argv); 318 420 if (argc != 1) 319 421 return 99; … … 335 437 tstRTCreateProcEx3(); 336 438 tstRTCreateProcEx4(); 337 /** @todo Cover files, pszAsUser, ++ */ 439 /** @todo Do not run tstRTCreateProcEx5 on NT4, may not work (?) */ 440 tstRTCreateProcEx5(); 441 /** @todo Cover files, ++ */ 338 442 339 443 /*
Note:
See TracChangeset
for help on using the changeset viewer.

