Changeset 41919 in vbox
- Timestamp:
- Jun 27, 2012 8:06:27 AM (13 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/process.h
r40571 r41919 364 364 RTR3DECL(bool) RTProcIsRunningByName(const char *pszName); 365 365 366 /** 367 * Query the username of the given process. 368 * 369 * @returns IPRT status code. 370 * @retval VERR_BUFFER_OVERFLOW if the given buffer size is to small for the username. 371 * @param hProcess The process handle to query the username for. 372 * @param pszUser Where to store the user name on success. 373 * @param cbUser The size of the user name buffer. 374 * @param pcbUser Where to store the username length on success 375 * or the required buffer size if VERR_BUFFER_OVERFLOW 376 * is returned. 377 */ 378 RTR3DECL(int) RTProcQueryUsername(RTPROCESS hProcess, char *pszUser, size_t cbUser, 379 size_t *pcbUser); 380 366 381 #endif /* IN_RING3 */ 367 382 -
trunk/src/VBox/Runtime/r3/posix/process-posix.cpp
r39801 r41919 38 38 #include <sys/wait.h> 39 39 #include <signal.h> 40 #include <pwd.h> 40 41 41 42 #include <iprt/process.h> … … 146 147 } 147 148 149 150 RTR3DECL(int) RTProcQueryUsername(RTPROCESS hProcess, char *pszUser, size_t cbUser, 151 size_t *pcbUser) 152 { 153 AssertPtrReturn(pszUser, VERR_INVALID_POINTER); 154 AssertReturn(cbUser > 0, VERR_INVALID_PARAMETER); 155 AssertPtrReturn(pcbUser, VERR_INVALID_POINTER); 156 157 if (hProcess != RTProcSelf()) 158 return VERR_NOT_SUPPORTED; 159 160 int32_t cbPwdMax = sysconf(_SC_GETPW_R_SIZE_MAX); 161 if (cbPwdMax == -1) 162 return RTErrConvertFromErrno(errno); 163 164 char *pbBuf = (char *)RTMemAllocZ(cbPwdMax); 165 if (!pbBuf) 166 return VERR_NO_MEMORY; 167 168 struct passwd Pwd, *pPwd; 169 int rc = getpwuid_r(geteuid(), &Pwd, pbBuf, cbPwdMax, &pPwd); 170 if (!rc) 171 { 172 size_t cbPwdUser = strlen(pPwd->pw_name) + 1; 173 174 *pcbUser = cbPwdUser; 175 176 if (cbPwdUser > cbUser) 177 rc = VERR_BUFFER_OVERFLOW; 178 else 179 { 180 memcpy(pszUser, pPwd->pw_name, cbPwdUser); 181 rc = VINF_SUCCESS; 182 } 183 } 184 else 185 rc = RTErrConvertFromErrno(rc); 186 187 RTMemFree(pbBuf); 188 return rc; 189 } 190 191 -
trunk/src/VBox/Runtime/r3/win/process-win.cpp
r41182 r41919 38 38 #include <errno.h> 39 39 #include <Strsafe.h> 40 #include <Lmcons.h> 40 41 41 42 #include <iprt/process.h> … … 1424 1425 } 1425 1426 1427 1428 RTR3DECL(int) RTProcQueryUsername(RTPROCESS hProcess, char *pszUser, size_t cbUser, 1429 size_t *pcbUser) 1430 { 1431 AssertPtrReturn(pszUser, VERR_INVALID_POINTER); 1432 AssertReturn(cbUser > 0, VERR_INVALID_PARAMETER); 1433 AssertPtrReturn(pcbUser, VERR_INVALID_POINTER); 1434 1435 if (hProcess != RTProcSelf()) 1436 return VERR_NOT_SUPPORTED; 1437 1438 RTUTF16 awszUserName[UNLEN + 1]; 1439 DWORD cchUserName = UNLEN + 1; 1440 1441 if (!GetUserNameW(&awszUserName[0], &cchUserName)) 1442 return RTErrConvertFromWin32(GetLastError()); 1443 1444 char *pszUserName = NULL; 1445 int rc = RTUtf16ToUtf8(awszUserName, &pszUserName); 1446 if (RT_SUCCESS(rc)) 1447 { 1448 size_t cbUserName = strlen(pszUserName) + 1; 1449 1450 *pcbUser = cbUserName; 1451 1452 if (cbUserName > cbUser) 1453 rc = VERR_BUFFER_OVERFLOW; 1454 else 1455 { 1456 memcpy(pszUser, pszUserName, cbUserName); 1457 rc = VINF_SUCCESS; 1458 } 1459 1460 RTStrFree(pszUserName); 1461 } 1462 1463 return rc; 1464 } 1465 -
trunk/src/VBox/Runtime/testcase/Makefile.kmk
r41557 r41919 93 93 tstRTPrfIO \ 94 94 tstRTProcCreateEx \ 95 tstRTProcQueryUsername \ 95 96 tstPrfRT \ 96 97 tstRand \ … … 451 452 tstRTProcCreateEx_SOURCES = tstRTProcCreateEx.cpp 452 453 454 tstRTProcQueryUsername_TEMPLATE = VBOXR3TSTEXE 455 tstRTProcQueryUsername_SOURCES = tstRTProcQueryUsername.cpp 456 453 457 tstRTProcWait_TEMPLATE = VBOXR3TSTEXE 454 458 tstRTProcWait_SOURCES = tstRTProcWait.cpp
Note:
See TracChangeset
for help on using the changeset viewer.