static int vbglR3DnDCreateDropDir(char* pszDropDir, size_t cbSize) { /* Validate input */ AssertPtrReturn(pszDropDir, VERR_INVALID_POINTER); AssertReturn(cbSize, VERR_INVALID_PARAMETER); /* Get the users document directory (usually $HOME/Documents). */ int rc = RTPathUserDocuments(pszDropDir, cbSize); if (RT_FAILURE(rc)) return rc; /* Append our base drop directory. */ rc = RTPathAppend(pszDropDir, cbSize, "VirtualBox Dropped Files"); if (RT_FAILURE(rc)) return rc; /* Create it when necessary. */ if (!RTDirExists(pszDropDir)) { rc = RTDirCreateFullPath(pszDropDir, RTFS_UNIX_IRWXU); if (RT_FAILURE(rc)) return rc; } /* The actually drop directory consist of the current time stamp and a * unique number when necessary. */ char pszTime[64]; RTTIMESPEC time; if (!RTTimeSpecToString(RTTimeNow(&time), pszTime, sizeof(pszTime))) return VERR_BUFFER_OVERFLOW; rc = RTPathAppend(pszDropDir, cbSize, pszTime); if (RT_FAILURE(rc)) return rc; /* Create it (only accessible by the current user) */ return RTDirCreateUniqueNumbered(pszDropDir, cbSize, RTFS_UNIX_IRWXU, 3, '-'); }
int GetVBoxUserHomeDirectory(char *aDir, size_t aDirLen) { AssertReturn(aDir, VERR_INVALID_POINTER); AssertReturn(aDirLen > 0, VERR_BUFFER_OVERFLOW); /* start with null */ *aDir = 0; char szTmp[RTPATH_MAX]; int vrc = RTEnvGetEx(RTENV_DEFAULT, "VBOX_USER_HOME", szTmp, sizeof(szTmp), NULL); if (RT_SUCCESS(vrc) || vrc == VERR_ENV_VAR_NOT_FOUND) { if (RT_SUCCESS(vrc)) { /* get the full path name */ vrc = RTPathAbs(szTmp, aDir, aDirLen); } else { /* compose the config directory (full path) */ /** @todo r=bird: RTPathUserHome doesn't necessarily return a full (abs) path * like the comment above seems to indicate. */ vrc = RTPathUserHome(aDir, aDirLen); if (RT_SUCCESS(vrc)) vrc = RTPathAppend(aDir, aDirLen, VBOX_USER_HOME_SUFFIX); } /* ensure the home directory exists */ if (RT_SUCCESS(vrc)) if (!RTDirExists(aDir)) vrc = RTDirCreateFullPath(aDir, 0700); } return vrc; }
static RTEXITCODE rtZipUnzipCmdExtractCallback(PRTZIPUNZIPCMDOPS pOpts, RTVFSOBJ hVfsObj, const char *pszName, RTEXITCODE rcExit, PRTFOFF pcBytes) { if (pOpts->fVerbose) RTPrintf("%s\n", pszName); /* * Query all the information. */ RTFSOBJINFO UnixInfo; int rc = RTVfsObjQueryInfo(hVfsObj, &UnixInfo, RTFSOBJATTRADD_UNIX); if (RT_FAILURE(rc)) return RTMsgErrorExit(RTEXITCODE_FAILURE, "RTVfsObjQueryInfo returned %Rrc on '%s'", rc, pszName); *pcBytes = UnixInfo.cbObject; char szDst[RTPATH_MAX]; rc = RTPathJoin(szDst, sizeof(szDst), pOpts->pszDirectory ? pOpts->pszDirectory : ".", pszName); if (RT_FAILURE(rc)) return RTMsgErrorExit(RTEXITCODE_FAILURE, "%s: Failed to construct destination path for: %Rrc", pszName, rc); /* * Extract according to the type. */ switch (UnixInfo.Attr.fMode & RTFS_TYPE_MASK) { case RTFS_TYPE_FILE: return rtZipUnzipCmdExtractFile(pOpts, hVfsObj, rcExit, szDst, &UnixInfo); case RTFS_TYPE_DIRECTORY: rc = RTDirCreateFullPath(szDst, UnixInfo.Attr.fMode & RTFS_UNIX_ALL_ACCESS_PERMS); if (RT_FAILURE(rc)) return RTMsgErrorExit(RTEXITCODE_FAILURE, "%s: Error creating directory: %Rrc", szDst, rc); break; default: return RTMsgErrorExit(RTEXITCODE_FAILURE, "%s: Unknown file type.", pszName); } if (!pOpts->fNoModTimeDirectories) { rc = RTPathSetTimesEx(szDst, NULL, &UnixInfo.ModificationTime, NULL, NULL, RTPATH_F_ON_LINK); if (RT_FAILURE(rc) && rc != VERR_NOT_SUPPORTED && rc != VERR_NS_SYMLINK_SET_TIME) rcExit = RTMsgErrorExit(RTEXITCODE_FAILURE, "%s: Error changing modification time: %Rrc.", pszName, rc); } return rcExit; }
static int VBoxServiceAutoMountPrepareMountPoint(const char *pszMountPoint, const char *pszShareName, vbsf_mount_opts *pOpts) { AssertPtrReturn(pOpts, VERR_INVALID_PARAMETER); AssertPtrReturn(pszMountPoint, VERR_INVALID_PARAMETER); AssertPtrReturn(pszShareName, VERR_INVALID_PARAMETER); RTFMODE fMode = RTFS_UNIX_IRWXU | RTFS_UNIX_IRWXG; /* Owner (=root) and the group (=vboxsf) have full access. */ int rc = RTDirCreateFullPath(pszMountPoint, fMode); if (RT_SUCCESS(rc)) { rc = RTPathSetOwnerEx(pszMountPoint, NIL_RTUID /* Owner, unchanged */, pOpts->gid, RTPATH_F_ON_LINK); if (RT_SUCCESS(rc)) { rc = RTPathSetMode(pszMountPoint, fMode); if (RT_FAILURE(rc)) { if (rc == VERR_WRITE_PROTECT) { VBoxServiceVerbose(3, "VBoxServiceAutoMountPrepareMountPoint: Mount directory \"%s\" already is used/mounted\n", pszMountPoint); rc = VINF_SUCCESS; } else VBoxServiceError("VBoxServiceAutoMountPrepareMountPoint: Could not set mode %RTfmode for mount directory \"%s\", rc = %Rrc\n", fMode, pszMountPoint, rc); } } else VBoxServiceError("VBoxServiceAutoMountPrepareMountPoint: Could not set permissions for mount directory \"%s\", rc = %Rrc\n", pszMountPoint, rc); } else VBoxServiceError("VBoxServiceAutoMountPrepareMountPoint: Could not create mount directory \"%s\" with mode %RTfmode, rc = %Rrc\n", pszMountPoint, fMode, rc); return rc; }