Changeset 4026 in vbox for trunk/src/VBox/Runtime/r3/posix
- Timestamp:
- Aug 3, 2007 5:29:19 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r3/posix/path-posix.cpp
r3916 r4026 32 32 #include <sys/time.h> 33 33 #include <stdio.h> 34 #include <sys/types.h> 35 #include <pwd.h> 34 36 #ifdef RT_OS_DARWIN 35 37 # include <mach-o/dyld.h> … … 484 486 RTDECL(int) RTPathUserHome(char *pszPath, unsigned cchPath) 485 487 { 488 int rc; 489 #ifndef RT_OS_L4 490 /* 491 * We make an exception for the root user and use the system call 492 * getpwuid_r to determine their initial home path instead of 493 * reading it from the $HOME variable. This is because the $HOME 494 * variable does not get changed by sudo (and possibly su and others) 495 * which can cause root-owned files to appear in user's home folders. 496 */ 497 uid_t uid = geteuid(); 498 if (uid == 0) 499 { 500 /* The getpwuid_r function "allocates" any pointer memory it 501 needs from here. In theory one should use the sysconf 502 function to find the appropriate size, but sysconf is 503 unreliable by design. This should definitely be enough. */ 504 char buffer[5120]; 505 struct passwd sPasswd, *psPasswd; 506 rc = getpwuid_r(0, &sPasswd, buffer, sizeof(buffer), &psPasswd); 507 if (rc != 0) 508 return RTErrConvertFromErrno(rc); 509 /* 510 * Convert it to UTF-8 and copy it to the return buffer. 511 */ 512 char *pszUtf8Path; 513 rc = rtPathFromNative(&pszUtf8Path, psPasswd->pw_dir); 514 if (RT_SUCCESS(rc)) 515 { 516 size_t cchHome = strlen(pszUtf8Path); 517 if (cchHome < cchPath) 518 memcpy(pszPath, pszUtf8Path, cchHome + 1); 519 else 520 rc = VERR_BUFFER_OVERFLOW; 521 RTStrFree(pszUtf8Path); 522 } 523 LogFlow(("RTPathUserHome(%p:{%s}, %u): returns %Rrc\n", pszPath, 524 RT_SUCCESS(rc) ? pszPath : "<failed>", cchPath, rc)); 525 return rc; 526 } 527 #endif 486 528 /* 487 529 * Get HOME env. var it and validate it's existance. 488 530 */ 489 int rc;490 531 struct stat s; 491 532 const char *pszHome = getenv("HOME");
Note:
See TracChangeset
for help on using the changeset viewer.