RTR3DECL(int) RTS3Create(PRTS3 ppS3, const char* pszAccessKey, const char* pszSecretKey, const char* pszBaseUrl, const char* pszUserAgent /* = NULL */) { AssertPtrReturn(ppS3, VERR_INVALID_POINTER); /* We need at least an URL to connect with */ if (pszBaseUrl == NULL || pszBaseUrl[0] == 0) return VERR_INVALID_PARAMETER; /* In windows, this will init the winsock stuff */ if (curl_global_init(CURL_GLOBAL_ALL) != 0) return VERR_INTERNAL_ERROR; CURL* pCurl = curl_easy_init(); if (!pCurl) return VERR_INTERNAL_ERROR; PRTS3INTERNAL pS3Int = (PRTS3INTERNAL)RTMemAllocZ(sizeof(RTS3INTERNAL)); if (pS3Int == NULL) return VERR_NO_MEMORY; pS3Int->u32Magic = RTS3_MAGIC; pS3Int->pCurl = pCurl; pS3Int->pszAccessKey = RTStrDup(pszAccessKey); pS3Int->pszSecretKey = RTStrDup(pszSecretKey); pS3Int->pszBaseUrl = RTStrDup(pszBaseUrl); if (pszUserAgent) pS3Int->pszUserAgent = RTStrDup(pszUserAgent); *ppS3 = (RTS3)pS3Int; return VINF_SUCCESS; }
/** * Schedules the setting of a property. * * @returns IPRT status code. * @retval VERR_INVALID_STATE if not a SVN WC file. * @param pState The rewrite state to work on. * @param pszName The name of the property to set. * @param pszValue The value. NULL means deleting it. */ int ScmSvnSetProperty(PSCMRWSTATE pState, const char *pszName, const char *pszValue) { /* * Update any existing entry first. */ size_t i = pState->cSvnPropChanges; while (i-- > 0) if (!strcmp(pState->paSvnPropChanges[i].pszName, pszName)) { if (!pszValue) { RTStrFree(pState->paSvnPropChanges[i].pszValue); pState->paSvnPropChanges[i].pszValue = NULL; } else { char *pszCopy; int rc = RTStrDupEx(&pszCopy, pszValue); if (RT_FAILURE(rc)) return rc; pState->paSvnPropChanges[i].pszValue = pszCopy; } return VINF_SUCCESS; } /* * Insert a new entry. */ i = pState->cSvnPropChanges; if ((i % 32) == 0) { void *pvNew = RTMemRealloc(pState->paSvnPropChanges, (i + 32) * sizeof(SCMSVNPROP)); if (!pvNew) return VERR_NO_MEMORY; pState->paSvnPropChanges = (PSCMSVNPROP)pvNew; } pState->paSvnPropChanges[i].pszName = RTStrDup(pszName); pState->paSvnPropChanges[i].pszValue = pszValue ? RTStrDup(pszValue) : NULL; if ( pState->paSvnPropChanges[i].pszName && (pState->paSvnPropChanges[i].pszValue || !pszValue) ) pState->cSvnPropChanges = i + 1; else { RTStrFree(pState->paSvnPropChanges[i].pszName); pState->paSvnPropChanges[i].pszName = NULL; RTStrFree(pState->paSvnPropChanges[i].pszValue); pState->paSvnPropChanges[i].pszValue = NULL; return VERR_NO_MEMORY; } return VINF_SUCCESS; }
int DnDURIList::AppendNativePath(const char *pszPath, uint32_t fFlags) { AssertPtrReturn(pszPath, VERR_INVALID_POINTER); int rc; char *pszPathNative = RTStrDup(pszPath); if (pszPathNative) { RTPathChangeToUnixSlashes(pszPathNative, true /* fForce */); char *pszPathURI = RTUriCreate("file" /* pszScheme */, "/" /* pszAuthority */, pszPathNative, NULL /* pszQuery */, NULL /* pszFragment */); if (pszPathURI) { rc = AppendURIPath(pszPathURI, fFlags); RTStrFree(pszPathURI); } else rc = VERR_INVALID_PARAMETER; RTStrFree(pszPathNative); } else rc = VERR_NO_MEMORY; return rc; }
PUSBDEVICE USBProxyBackendUsbIp::getDevices(void) { PUSBDEVICE pFirst = NULL; PUSBDEVICE *ppNext = &pFirst; /* Create a deep copy of the device list. */ RTSemFastMutexRequest(m->hMtxDevices); PUSBDEVICE pCur = m->pUsbDevicesCur; while (pCur) { PUSBDEVICE pNew = (PUSBDEVICE)RTMemAllocZ(sizeof(USBDEVICE)); if (pNew) { pNew->pszManufacturer = RTStrDup(pCur->pszManufacturer); pNew->pszProduct = RTStrDup(pCur->pszProduct); if (pCur->pszSerialNumber) pNew->pszSerialNumber = RTStrDup(pCur->pszSerialNumber); pNew->pszBackend = RTStrDup(pCur->pszBackend); pNew->pszAddress = RTStrDup(pCur->pszAddress); pNew->idVendor = pCur->idVendor; pNew->idProduct = pCur->idProduct; pNew->bcdDevice = pCur->bcdDevice; pNew->bcdUSB = pCur->bcdUSB; pNew->bDeviceClass = pCur->bDeviceClass; pNew->bDeviceSubClass = pCur->bDeviceSubClass; pNew->bDeviceProtocol = pCur->bDeviceProtocol; pNew->bNumConfigurations = pCur->bNumConfigurations; pNew->enmState = pCur->enmState; pNew->u64SerialHash = pCur->u64SerialHash; pNew->bBus = pCur->bBus; pNew->bPort = pCur->bPort; pNew->enmSpeed = pCur->enmSpeed; /* link it */ pNew->pNext = NULL; pNew->pPrev = *ppNext; *ppNext = pNew; ppNext = &pNew->pNext; } pCur = pCur->pNext; } RTSemFastMutexRelease(m->hMtxDevices); return pFirst; }
/** * Same as RTPathReal only the result is RTStrDup()'ed. * * @returns Pointer to real path. Use RTStrFree() to free this string. * @returns NULL if RTPathReal() or RTStrDup() fails. * @param pszPath */ RTDECL(char *) RTPathRealDup(const char *pszPath) { char szPath[RTPATH_MAX]; int rc = RTPathReal(pszPath, szPath, sizeof(szPath)); if (RT_SUCCESS(rc)) return RTStrDup(szPath); return NULL; }
static void rtS3ExtractAllKeys(xmlDocPtr pDoc, xmlNodePtr pNode, PCRTS3KEYENTRY *ppKeys) { if (pNode != NULL) { PRTS3KEYENTRY pPrevKey = NULL; xmlNodePtr pCurKey = pNode->xmlChildrenNode; while (pCurKey != NULL) { if ((!xmlStrcmp(pCurKey->name, (const xmlChar *)"Contents"))) { PRTS3KEYENTRY pKey = (PRTS3KEYENTRY)RTMemAllocZ(sizeof(RTS3KEYENTRY)); pKey->pPrev = pPrevKey; if (pPrevKey) pPrevKey->pNext = pKey; else (*ppKeys) = pKey; pPrevKey = pKey; xmlNodePtr pCurCont = pCurKey->xmlChildrenNode; while (pCurCont != NULL) { if ((!xmlStrcmp(pCurCont->name, (const xmlChar *)"Key"))) { xmlChar *pszKey = xmlNodeListGetString(pDoc, pCurCont->xmlChildrenNode, 1); pKey->pszName = RTStrDup((const char*)pszKey); xmlFree(pszKey); } if ((!xmlStrcmp(pCurCont->name, (const xmlChar*)"LastModified"))) { xmlChar *pszKey = xmlNodeListGetString(pDoc, pCurCont->xmlChildrenNode, 1); pKey->pszLastModified = RTStrDup((const char*)pszKey); xmlFree(pszKey); } if ((!xmlStrcmp(pCurCont->name, (const xmlChar*)"Size"))) { xmlChar *pszKey = xmlNodeListGetString(pDoc, pCurCont->xmlChildrenNode, 1); pKey->cbFile = RTStrToUInt64((const char*)pszKey); xmlFree(pszKey); } pCurCont = pCurCont->next; } } pCurKey = pCurKey->next; } } }
/** * Search for a USB test device and return the device path. * * @returns Path to the USB test device or NULL if none was found. */ static char *usbTestFindDevice(void) { /* * Very crude and quick way to search for the correct test device. * Assumption is that the path looks like /dev/bus/usb/%3d/%3d. */ uint8_t uBus = 1; bool fBusExists = false; char aszDevPath[64]; RT_ZERO(aszDevPath); do { RTStrPrintf(aszDevPath, sizeof(aszDevPath), "/dev/bus/usb/%03d", uBus); fBusExists = RTPathExists(aszDevPath); if (fBusExists) { /* Check every device. */ bool fDevExists = false; uint8_t uDev = 1; do { RTStrPrintf(aszDevPath, sizeof(aszDevPath), "/dev/bus/usb/%03d/%03d", uBus, uDev); fDevExists = RTPathExists(aszDevPath); if (fDevExists) { RTFILE hFileDev; int rc = RTFileOpen(&hFileDev, aszDevPath, RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_NONE); if (RT_SUCCESS(rc)) { USBDEVDESC DevDesc; rc = RTFileRead(hFileDev, &DevDesc, sizeof(DevDesc), NULL); RTFileClose(hFileDev); if ( RT_SUCCESS(rc) && DevDesc.idVendor == 0x0525 && DevDesc.idProduct == 0xa4a0) return RTStrDup(aszDevPath); } } uDev++; } while (fDevExists); } uBus++; } while (fBusExists); return NULL; }
MemoryBuf::MemoryBuf (const char *aBuf, size_t aLen, const char *aURI /* = NULL */) : m (new Data()) { if (aBuf == NULL) throw EInvalidArg (RT_SRC_POS); m->buf = aBuf; m->len = aLen; m->uri = RTStrDup (aURI); }
static void tst1(size_t cTest, size_t cchDigits, char chSep) { RTTestISubF("tst #%u (digits: %u; sep: %c)", cTest, cchDigits, chSep ? chSep : ' '); /* We try to create max possible + one. */ size_t cTimes = 1; for (size_t i = 0; i < cchDigits; ++i) cTimes *= 10; /* Allocate the result array. */ char **papszNames = (char **)RTMemTmpAllocZ(cTimes * sizeof(char *)); RTTESTI_CHECK_RETV(papszNames != NULL); int rc = VERR_INTERNAL_ERROR; /* The test loop. */ size_t i; for (i = 0; i < cTimes; i++) { char szName[RTPATH_MAX]; RTTESTI_CHECK_RC(rc = RTPathAppend(strcpy(szName, g_szTempPath), sizeof(szName), "RTDirCreateUniqueNumbered"), VINF_SUCCESS); if (RT_FAILURE(rc)) break; RTTESTI_CHECK_RC(rc = RTDirCreateUniqueNumbered(szName, sizeof(szName), 0700, cchDigits, chSep), VINF_SUCCESS); if (RT_FAILURE(rc)) { RTTestIFailed("RTDirCreateUniqueNumbered(%s) call #%u -> %Rrc\n", szName, i, rc); break; } RTTESTI_CHECK(papszNames[i] = RTStrDup(szName)); if (!papszNames[i]) break; RTTestIPrintf(RTTESTLVL_DEBUG, "%s\n", papszNames[i]); } /* Try to create one more, which shouldn't be possible. */ if (RT_SUCCESS(rc)) { char szName[RTPATH_MAX]; RTTESTI_CHECK_RC(rc = RTPathAppend(strcpy(szName, g_szTempPath), sizeof(szName), "RTDirCreateUniqueNumbered"), VINF_SUCCESS); if (RT_SUCCESS(rc)) RTTESTI_CHECK_RC(rc = RTDirCreateUniqueNumbered(szName, sizeof(szName), 0700, cchDigits, chSep), VERR_ALREADY_EXISTS); } /* cleanup */ while (i-- > 0) { RTTESTI_CHECK_RC(RTDirRemove(papszNames[i]), VINF_SUCCESS); RTStrFree(papszNames[i]); } RTMemTmpFree(papszNames); }
RTR3DECL(int) RTHttpGetRedirLocation(RTHTTP hHttp, char **ppszRedirLocation) { PRTHTTPINTERNAL pHttpInt = hHttp; RTHTTP_VALID_RETURN(pHttpInt); if (!pHttpInt->pszRedirLocation) return VERR_HTTP_NOT_FOUND; *ppszRedirLocation = RTStrDup(pHttpInt->pszRedirLocation); return VINF_SUCCESS; }
RTR3DECL(int) RTS3CreateBucket(RTS3 hS3, const char* pszBucketName) { PRTS3INTERNAL pS3Int = hS3; RTS3_VALID_RETURN(pS3Int); /* Reset the CURL object to an defined state */ rtS3ReinitCurl(pS3Int); char* pszUrl = rtS3Host(pszBucketName, "", pS3Int->pszBaseUrl); curl_easy_setopt(pS3Int->pCurl, CURLOPT_URL, pszUrl); RTStrFree(pszUrl); /* Create the basic header entries */ char *apszHead[4] = { RTStrDup("Content-Length: 0"), /* Content length entry */ rtS3HostHeader(pszBucketName, pS3Int->pszBaseUrl), /* Host entry */ rtS3DateHeader(), /* Date entry */ NULL /* Authorization entry */ }; /* Create the authorization header entry */ apszHead[RT_ELEMENTS(apszHead)-1] = rtS3CreateAuthHeader(pS3Int, "PUT", pszBucketName, "", apszHead, RT_ELEMENTS(apszHead)); /* Add all headers to curl */ struct curl_slist* pHeaders = NULL; /* Init to NULL is important */ for(size_t i=0; i < RT_ELEMENTS(apszHead); ++i) pHeaders = curl_slist_append(pHeaders, apszHead[i]); /* Pass our list of custom made headers */ curl_easy_setopt(pS3Int->pCurl, CURLOPT_HTTPHEADER, pHeaders); /* Set CURL in upload mode */ curl_easy_setopt(pS3Int->pCurl, CURLOPT_PUT, 1); curl_easy_setopt(pS3Int->pCurl, CURLOPT_UPLOAD, 1); /* Set the size of the file we like to transfer */ curl_easy_setopt(pS3Int->pCurl, CURLOPT_INFILESIZE_LARGE, 0); /* Start the request */ int rc = rtS3Perform(pS3Int); if (RT_FAILURE(rc)) { /* Handle special failures */ if (pS3Int->lLastResp == 409) rc = VERR_S3_BUCKET_ALREADY_EXISTS; } /* Regardless of the result, free all used resources first*/ curl_slist_free_all(pHeaders); for(size_t i=0; i < RT_ELEMENTS(apszHead); ++i) RTStrFree(apszHead[i]); return rc; }
/* static */ int DnDURIObject::RebaseURIPath(RTCString &strPathAbs, const RTCString &strBaseOld /* = "" */, const RTCString &strBaseNew /* = "" */) { char *pszPath = RTUriFilePath(strPathAbs.c_str()); if (!pszPath) /* No URI? */ pszPath = RTStrDup(strPathAbs.c_str()); int rc; if (pszPath) { const char *pszPathStart = pszPath; const char *pszBaseOld = strBaseOld.c_str(); if ( pszBaseOld && RTPathStartsWith(pszPath, pszBaseOld)) { pszPathStart += strlen(pszBaseOld); } rc = VINF_SUCCESS; if (RT_SUCCESS(rc)) { char *pszPathNew = RTPathJoinA(strBaseNew.c_str(), pszPathStart); if (pszPathNew) { char *pszPathURI = RTUriCreate("file" /* pszScheme */, "/" /* pszAuthority */, pszPathNew /* pszPath */, NULL /* pszQuery */, NULL /* pszFragment */); if (pszPathURI) { LogFlowFunc(("Rebasing \"%s\" to \"%s\"\n", strPathAbs.c_str(), pszPathURI)); strPathAbs = RTCString(pszPathURI) + "\r\n"; RTStrFree(pszPathURI); } else rc = VERR_INVALID_PARAMETER; RTStrFree(pszPathNew); } else rc = VERR_NO_MEMORY; } RTStrFree(pszPath); } else rc = VERR_NO_MEMORY; return rc; }
static void rtS3ExtractAllBuckets(xmlDocPtr pDoc, xmlNodePtr pNode, PCRTS3BUCKETENTRY *ppBuckets) { pNode = rtS3FindNode(pNode, "Buckets"); if (pNode != NULL) { PRTS3BUCKETENTRY pPrevBucket = NULL; xmlNodePtr pCurBucket = pNode->xmlChildrenNode; while (pCurBucket != NULL) { if ((!xmlStrcmp(pCurBucket->name, (const xmlChar *)"Bucket"))) { PRTS3BUCKETENTRY pBucket = (PRTS3BUCKETENTRY)RTMemAllocZ(sizeof(RTS3BUCKETENTRY)); pBucket->pPrev = pPrevBucket; if (pPrevBucket) pPrevBucket->pNext = pBucket; else (*ppBuckets) = pBucket; pPrevBucket = pBucket; xmlNodePtr pCurCont = pCurBucket->xmlChildrenNode; while (pCurCont != NULL) { if ((!xmlStrcmp(pCurCont->name, (const xmlChar *)"Name"))) { xmlChar *pszKey = xmlNodeListGetString(pDoc, pCurCont->xmlChildrenNode, 1); pBucket->pszName = RTStrDup((const char*)pszKey); xmlFree(pszKey); } if ((!xmlStrcmp(pCurCont->name, (const xmlChar*)"CreationDate"))) { xmlChar *pszKey = xmlNodeListGetString(pDoc, pCurCont->xmlChildrenNode, 1); pBucket->pszCreationDate = RTStrDup((const char*)pszKey); xmlFree(pszKey); } pCurCont = pCurCont->next; } } pCurBucket = pCurBucket->next; } } }
RTR3DECL(int) RTHttpSetCAFile(RTHTTP hHttp, const char *pcszCAFile) { PRTHTTPINTERNAL pHttpInt = hHttp; RTHTTP_VALID_RETURN(pHttpInt); if (pHttpInt->pcszCAFile) RTStrFree(pHttpInt->pcszCAFile); pHttpInt->pcszCAFile = RTStrDup(pcszCAFile); if (!pHttpInt->pcszCAFile) return VERR_NO_MEMORY; return VINF_SUCCESS; }
static int pdmNsBwGroupCreate(PPDMNETSHAPER pShaper, const char *pcszBwGroup, uint64_t cbTransferPerSecMax) { LogFlowFunc(("pShaper=%#p pcszBwGroup=%#p{%s} cbTransferPerSecMax=%u\n", pShaper, pcszBwGroup, pcszBwGroup, cbTransferPerSecMax)); AssertPtrReturn(pShaper, VERR_INVALID_POINTER); AssertPtrReturn(pcszBwGroup, VERR_INVALID_POINTER); AssertReturn(*pcszBwGroup != '\0', VERR_INVALID_PARAMETER); int rc; PPDMNSBWGROUP pBwGroup = pdmNsBwGroupFindById(pShaper, pcszBwGroup); if (!pBwGroup) { rc = MMR3HeapAllocZEx(pShaper->pVM, MM_TAG_PDM_NET_SHAPER, sizeof(PDMNSBWGROUP), (void **)&pBwGroup); if (RT_SUCCESS(rc)) { rc = RTCritSectInit(&pBwGroup->cs); if (RT_SUCCESS(rc)) { pBwGroup->pszName = RTStrDup(pcszBwGroup); if (pBwGroup->pszName) { pBwGroup->pShaper = pShaper; pBwGroup->cRefs = 0; pdmNsBwGroupSetLimit(pBwGroup, cbTransferPerSecMax); ; pBwGroup->cbTokensLast = pBwGroup->cbBucketSize; pBwGroup->tsUpdatedLast = RTTimeSystemNanoTS(); LogFlowFunc(("pcszBwGroup={%s} cbBucketSize=%u\n", pcszBwGroup, pBwGroup->cbBucketSize)); pdmNsBwGroupLink(pBwGroup); return VINF_SUCCESS; } RTCritSectDelete(&pBwGroup->cs); } MMR3HeapFree(pBwGroup); } else rc = VERR_NO_MEMORY; } else rc = VERR_ALREADY_EXISTS; LogFlowFunc(("returns rc=%Rrc\n", rc)); return rc; }
HRESULT VFSExplorer::cdUp(ComPtr<IProgress> &aProgress) { Utf8Str strUpPath; { AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); /* Remove lowest dir entry in a platform neutral way. */ char *pszNewPath = RTStrDup(m->strPath.c_str()); RTPathStripTrailingSlash(pszNewPath); RTPathStripFilename(pszNewPath); strUpPath = pszNewPath; RTStrFree(pszNewPath); } return cd(strUpPath, aProgress); }
/** * Helper for opening the specified kernel module. * * @param pszModule The name of the module. * @param ppMod Where to store the module handle. * @param ppCtf Where to store the module's CTF handle. * * @returns Pointer to the CTF structure for the module. */ static int rtR0DbgKrnlInfoModRetainEx(const char *pszModule, modctl_t **ppMod, ctf_file_t **ppCtf) { char *pszMod = RTStrDup(pszModule); if (RT_LIKELY(pszMod)) { int rc = rtR0DbgKrnlInfoModRetain(pszMod, ppMod, ppCtf); RTStrFree(pszMod); if (RT_SUCCESS(rc)) { AssertPtrReturn(*ppMod, VERR_INTERNAL_ERROR_2); AssertPtrReturn(*ppCtf, VERR_INTERNAL_ERROR_3); } return rc; } return VERR_NO_MEMORY; }
STDMETHODIMP VFSExplorer::CdUp(IProgress **aProgress) { AutoCaller autoCaller(this); if (FAILED(autoCaller.rc())) return autoCaller.rc(); Utf8Str strUpPath; { AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); /* Remove lowest dir entry in a platform neutral way. */ char *pszNewPath = RTStrDup(m->strPath.c_str()); RTPathStripTrailingSlash(pszNewPath); RTPathStripFilename(pszNewPath); strUpPath = pszNewPath; RTStrFree(pszNewPath); } return Cd(Bstr(strUpPath).raw(), aProgress); }
/* Only used for write handles. */ static PRTTARFILEINTERNAL rtTarFileCreateForWrite(PRTTARINTERNAL pInt, const char *pszFilename, uint32_t fOpen) { PRTTARFILEINTERNAL pFileInt = (PRTTARFILEINTERNAL)RTMemAllocZ(sizeof(RTTARFILEINTERNAL)); if (!pFileInt) return NULL; pFileInt->u32Magic = RTTARFILE_MAGIC; pFileInt->pTar = pInt; pFileInt->fOpenMode = fOpen; pFileInt->pszFilename = RTStrDup(pszFilename); pFileInt->hVfsIos = NIL_RTVFSIOSTREAM; if (pFileInt->pszFilename) return pFileInt; RTMemFree(pFileInt); return NULL; }
static void tstDirCreateTemp(const char *pszSubTest, const char *pszTemplate, unsigned cTimes, bool fSkipXCheck) { RTTestISub(pszSubTest); /* Allocate the result array. */ char **papszNames = (char **)RTMemTmpAllocZ(cTimes * sizeof(char *)); RTTESTI_CHECK_RETV(papszNames != NULL); /* The test loop. */ unsigned i; for (i = 0; i < cTimes; i++) { int rc; char szName[RTPATH_MAX]; RTTESTI_CHECK_RC(rc = RTPathAppend(strcpy(szName, g_szTempPath), sizeof(szName), pszTemplate), VINF_SUCCESS); if (RT_FAILURE(rc)) break; RTTESTI_CHECK(papszNames[i] = RTStrDup(szName)); if (!papszNames[i]) break; rc = RTDirCreateTemp(papszNames[i]); if (rc != VINF_SUCCESS) { RTTestIFailed("RTDirCreateTemp(%s) call #%u -> %Rrc\n", szName, i, rc); RTStrFree(papszNames[i]); papszNames[i] = NULL; break; } RTTestIPrintf(RTTESTLVL_DEBUG, "%s\n", papszNames[i]); RTTESTI_CHECK_MSG(strlen(szName) == strlen(papszNames[i]), ("szName %s\nReturned %s\n", szName, papszNames[i])); if (!fSkipXCheck) RTTESTI_CHECK_MSG(strchr(RTPathFilename(papszNames[i]), 'X') == NULL, ("szName %s\nReturned %s\n", szName, papszNames[i])); } /* cleanup */ while (i-- > 0) { RTTESTI_CHECK_RC(RTDirRemove(papszNames[i]), VINF_SUCCESS); RTStrFree(papszNames[i]); } RTMemTmpFree(papszNames); }
/** * Add an entry for an I/O stream using a passthru stream. * * The passthru I/O stream will hash all the data read from or written to the * stream and automatically add an entry to the manifest with the desired * attributes when it is released. Alternatively one can call * RTManifestPtIosAddEntryNow() to have more control over exactly when this * action is performed and which status it yields. * * @returns IPRT status code. * @param hManifest The manifest to add the entry to. * @param hVfsIos The I/O stream to pass thru to/from. * @param pszEntry The entry name. * @param fAttrs The attributes to create for this stream. * @param fReadOrWrite Whether it's a read or write I/O stream. * @param phVfsIosPassthru Where to return the new handle. */ RTDECL(int) RTManifestEntryAddPassthruIoStream(RTMANIFEST hManifest, RTVFSIOSTREAM hVfsIos, const char *pszEntry, uint32_t fAttrs, bool fReadOrWrite, PRTVFSIOSTREAM phVfsIosPassthru) { /* * Validate input. */ AssertReturn(fAttrs < RTMANIFEST_ATTR_END, VERR_INVALID_PARAMETER); AssertPtr(pszEntry); AssertPtr(phVfsIosPassthru); uint32_t cRefs = RTManifestRetain(hManifest); AssertReturn(cRefs != UINT32_MAX, VERR_INVALID_HANDLE); cRefs = RTVfsIoStrmRetain(hVfsIos); AssertReturnStmt(cRefs != UINT32_MAX, RTManifestRelease(hManifest), VERR_INVALID_HANDLE); /* * Create an instace of the passthru I/O stream. */ PRTMANIFESTPTIOS pThis; RTVFSIOSTREAM hVfsPtIos; int rc = RTVfsNewIoStream(&g_rtManifestPassthruIosOps, sizeof(*pThis), fReadOrWrite ? RTFILE_O_READ : RTFILE_O_WRITE, NIL_RTVFS, NIL_RTVFSLOCK, &hVfsPtIos, (void **)&pThis); if (RT_SUCCESS(rc)) { pThis->hVfsIos = hVfsIos; pThis->pHashes = rtManifestHashesCreate(fAttrs); pThis->hManifest = hManifest; pThis->fReadOrWrite = fReadOrWrite; pThis->fAddedEntry = false; pThis->pszEntry = RTStrDup(pszEntry); if (pThis->pszEntry && pThis->pHashes) { *phVfsIosPassthru = hVfsPtIos; return VINF_SUCCESS; } RTVfsIoStrmRelease(hVfsPtIos); } else { RTVfsIoStrmRelease(hVfsIos); RTManifestRelease(hManifest); } return rc; }
/** * Checks if a testcase is include or should be skipped. * * @param pszTestcase The testcase (filename). * * @return true if the testcase is included. * false if the testcase should be skipped. */ static bool IsTestcaseIncluded(const char *pszTestcase) { /* exclude special modules based on extension. */ const char *pszExt = RTPathExt(pszTestcase); if ( !RTStrICmp(pszExt, ".r0") || !RTStrICmp(pszExt, ".gc") || !RTStrICmp(pszExt, ".sys") || !RTStrICmp(pszExt, ".ko") || !RTStrICmp(pszExt, ".o") || !RTStrICmp(pszExt, ".obj") || !RTStrICmp(pszExt, ".lib") || !RTStrICmp(pszExt, ".a") || !RTStrICmp(pszExt, ".so") || !RTStrICmp(pszExt, ".dll") || !RTStrICmp(pszExt, ".dylib") || !RTStrICmp(pszExt, ".tmp") || !RTStrICmp(pszExt, ".log") ) return false; /* check by name */ char *pszDup = RTStrDup(pszTestcase); if (pszDup) { RTPathStripExt(pszDup); for (unsigned i = 0; i < RT_ELEMENTS(g_apszExclude); i++) { if (!strcmp(g_apszExclude[i], pszDup)) { RTStrFree(pszDup); return false; } } RTStrFree(pszDup); return true; } RTPrintf("tstRunTestcases: Out of memory!\n"); return false; }
int AutostartDb::setAutostartDbPath(const char *pszAutostartDbPathNew) { #if defined(RT_OS_LINUX) char *pszAutostartDbPathTmp = NULL; if (pszAutostartDbPathNew) { pszAutostartDbPathTmp = RTStrDup(pszAutostartDbPathNew); if (!pszAutostartDbPathTmp) return VERR_NO_MEMORY; } RTCritSectEnter(&this->CritSect); if (m_pszAutostartDbPath) RTStrFree(m_pszAutostartDbPath); m_pszAutostartDbPath = pszAutostartDbPathTmp; RTCritSectLeave(&this->CritSect); return VINF_SUCCESS; #else NOREF(pszAutostartDbPathNew); return VERR_NOT_SUPPORTED; #endif }
/** * Parse a key value node and returns the AST. * * @returns VBox status code. * @param pCfgTokenizer The tokenizer for the config stream. * @param pszKey The key for the pair. * @param ppCfgAst Where to store the resulting AST on success. */ static int autostartConfigParseValue(PCFGTOKENIZER pCfgTokenizer, const char *pszKey, PCFGAST *ppCfgAst) { int rc = VINF_SUCCESS; PCFGTOKEN pToken = NULL; rc = autostartConfigTokenizerGetNextToken(pCfgTokenizer, &pToken); if ( RT_SUCCESS(rc) && pToken->enmType == CFGTOKENTYPE_ID) { PCFGAST pCfgAst = NULL; pCfgAst = (PCFGAST)RTMemAllocZ(RT_OFFSETOF(CFGAST, u.KeyValue.aszValue[pToken->u.Id.cchToken + 1])); if (!pCfgAst) return VERR_NO_MEMORY; pCfgAst->enmType = CFGASTNODETYPE_KEYVALUE; pCfgAst->pszKey = RTStrDup(pszKey); if (!pCfgAst->pszKey) { RTMemFree(pCfgAst); return VERR_NO_MEMORY; } memcpy(pCfgAst->u.KeyValue.aszValue, pToken->u.Id.achToken, pToken->u.Id.cchToken); pCfgAst->u.KeyValue.cchValue = pToken->u.Id.cchToken; *ppCfgAst = pCfgAst; } else { autostartConfigTokenizerMsgUnexpectedToken(pToken, "non reserved token"); rc = VERR_INVALID_PARAMETER; } return rc; }
/** * Basic API checks. * We'll return if any of these fails. */ static void tst1(void) { RTTestISub("Basics"); char *psz; int rc = VINF_SUCCESS; /* RTStrAlloc */ RTTESTI_CHECK(psz = RTStrAlloc(0)); RTTESTI_CHECK(psz && !*psz); RTStrFree(psz); RTTESTI_CHECK(psz = RTStrAlloc(1)); RTTESTI_CHECK(psz && !*psz); RTStrFree(psz); RTTESTI_CHECK(psz = RTStrAlloc(128)); RTTESTI_CHECK(psz && !*psz); RTStrFree(psz); /* RTStrAllocEx */ psz = (char*)"asdfasdf"; RTTESTI_CHECK_RC(RTStrAllocEx(&psz, 0), VINF_SUCCESS); RTTESTI_CHECK(psz && !*psz); RTStrFree(psz); RTTESTI_CHECK_RC(RTStrAllocEx(&psz, 1), VINF_SUCCESS); RTTESTI_CHECK(psz && !*psz); RTStrFree(psz); RTTESTI_CHECK_RC(RTStrAllocEx(&psz, 128), VINF_SUCCESS); RTTESTI_CHECK(psz && !*psz); RTStrFree(psz); /* RTStrRealloc */ psz = NULL; RTTESTI_CHECK_RC(RTStrRealloc(&psz, 10), VINF_SUCCESS); RTTESTI_CHECK(psz && !psz[0]); RTTESTI_CHECK(psz && !psz[9]); RTStrFree(psz); psz = NULL; RTTESTI_CHECK_RC(RTStrRealloc(&psz, 0), VINF_SUCCESS); RTTESTI_CHECK(!psz); psz = NULL; RTTESTI_CHECK_RC(RTStrRealloc(&psz, 128), VINF_SUCCESS); RTTESTI_CHECK(psz && !psz[0]); RTTESTI_CHECK(psz && !psz[127]); if (psz) { memset(psz, 'a', 127); RTTESTI_CHECK_RC(rc = RTStrRealloc(&psz, 160), VINF_SUCCESS); if (RT_SUCCESS(rc) && psz) { RTTESTI_CHECK(!psz[127]); RTTESTI_CHECK(!psz[159]); RTTESTI_CHECK(ASMMemIsAll8(psz, 127, 'a') == NULL); memset(psz, 'b', 159); RTTESTI_CHECK_RC(rc = RTStrRealloc(&psz, 79), VINF_SUCCESS); if (RT_SUCCESS(rc)) { RTTESTI_CHECK(!psz[78]); RTTESTI_CHECK(ASMMemIsAll8(psz, 78, 'b') == NULL); RTTESTI_CHECK_RC(rc = RTStrRealloc(&psz, 0), VINF_SUCCESS); RTTESTI_CHECK(!psz); } } } RTStrFree(psz); /* RTStrDup */ RTTESTI_CHECK(psz = RTStrDup("")); RTTESTI_CHECK(psz && *psz == '\0'); RTStrFree(psz); RTTESTI_CHECK(psz = RTStrDup("abcdefghijklmnop")); RTTESTI_CHECK(!RTStrCmp(psz, "abcdefghijklmnop")); RTStrFree(psz); /* RTStrDupEx */ psz = NULL; RTTESTI_CHECK_RC(RTStrDupEx(&psz, ""), VINF_SUCCESS); RTTESTI_CHECK(RT_FAILURE(rc) || *psz == '\0'); if (RT_SUCCESS(rc)) RTStrFree(psz); psz = (char*)"asdfasdfasdfasdf"; RTTESTI_CHECK_RC(rc = RTStrDupEx(&psz, "abcdefghijklmnop"), VINF_SUCCESS); RTTESTI_CHECK(RT_FAILURE(rc) || !RTStrCmp(psz, "abcdefghijklmnop")); if (RT_SUCCESS(rc)) RTStrFree(psz); /* RTStrDupN */ RTTESTI_CHECK(psz = RTStrDupN("abcdefg", 3)); RTTESTI_CHECK(!RTStrCmp(psz, "abc")); RTStrFree(psz); RTTESTI_CHECK(psz = RTStrDupN("abc", 100000)); RTTESTI_CHECK(!RTStrCmp(psz, "abc")); RTStrFree(psz); RTTESTI_CHECK(psz = RTStrDupN("abc", 0)); RTTESTI_CHECK(psz && *psz == '\0'); RTStrFree(psz); /* RTStrAAppend */ RTTESTI_CHECK(psz = RTStrDup("abc")); RTTESTI_CHECK_RC(RTStrAAppend(&psz, "def"), VINF_SUCCESS); RTTESTI_CHECK(!RTStrCmp(psz, "abcdef")); RTStrFree(psz); RTTESTI_CHECK(psz = RTStrDup("abc")); RTTESTI_CHECK_RC(RTStrAAppend(&psz, ""), VINF_SUCCESS); RTTESTI_CHECK(!RTStrCmp(psz, "abc")); RTTESTI_CHECK_RC(RTStrAAppend(&psz, NULL), VINF_SUCCESS); RTTESTI_CHECK(!RTStrCmp(psz, "abc")); RTStrFree(psz); psz = NULL; RTTESTI_CHECK_RC(RTStrAAppend(&psz, "xyz"), VINF_SUCCESS); RTTESTI_CHECK(!RTStrCmp(psz, "xyz")); RTStrFree(psz); /* RTStrAAppendN */ RTTESTI_CHECK(psz = RTStrDup("abc")); RTTESTI_CHECK_RC(RTStrAAppendN(&psz, "def", 1), VINF_SUCCESS); RTTESTI_CHECK(!RTStrCmp(psz, "abcd")); RTStrFree(psz); RTTESTI_CHECK(psz = RTStrDup("abc")); RTTESTI_CHECK_RC(RTStrAAppendN(&psz, "", 0), VINF_SUCCESS); RTTESTI_CHECK(!RTStrCmp(psz, "abc")); RTTESTI_CHECK_RC(RTStrAAppendN(&psz, "", RTSTR_MAX), VINF_SUCCESS); RTTESTI_CHECK(!RTStrCmp(psz, "abc")); RTTESTI_CHECK_RC(RTStrAAppendN(&psz, NULL, 0), VINF_SUCCESS); RTTESTI_CHECK(!RTStrCmp(psz, "abc")); RTStrFree(psz); psz = NULL; RTTESTI_CHECK_RC(RTStrAAppendN(&psz, "abc", 2), VINF_SUCCESS); RTTESTI_CHECK(!RTStrCmp(psz, "ab")); RTTESTI_CHECK_RC(RTStrAAppendN(&psz, "cdefghijklm", 1), VINF_SUCCESS); RTTESTI_CHECK(!RTStrCmp(psz, "abc")); RTTESTI_CHECK_RC(RTStrAAppendN(&psz, "defghijklm", RTSTR_MAX), VINF_SUCCESS); RTTESTI_CHECK(!RTStrCmp(psz, "abcdefghijklm")); RTStrFree(psz); /* RTStrAAppendExN / RTStrAAppendExNV */ psz = NULL; RTTESTI_CHECK_RC(RTStrAAppendExN(&psz, 5, "a", (size_t)1, "bc", (size_t)1, "cdefg", RTSTR_MAX, "hijkl", (size_t)2, "jklmnopqrstuvwxyz", RTSTR_MAX), VINF_SUCCESS); RTTESTI_CHECK(!RTStrCmp(psz, "abcdefghijklmnopqrstuvwxyz")); RTTESTI_CHECK_RC(RTStrAAppendExN(&psz, 0), VINF_SUCCESS); RTTESTI_CHECK(!RTStrCmp(psz, "abcdefghijklmnopqrstuvwxyz")); RTTESTI_CHECK_RC(RTStrAAppendExN(&psz, 2, NULL, (size_t)0, "", (size_t)0), VINF_SUCCESS); RTTESTI_CHECK(!RTStrCmp(psz, "abcdefghijklmnopqrstuvwxyz")); RTTESTI_CHECK_RC(RTStrAAppendExN(&psz, 1, "-", (size_t)1), VINF_SUCCESS); RTTESTI_CHECK(!RTStrCmp(psz, "abcdefghijklmnopqrstuvwxyz-")); RTStrFree(psz); /* RTStrATruncate */ psz = NULL; RTTESTI_CHECK_RC(RTStrATruncate(&psz, 0), VINF_SUCCESS); RTTESTI_CHECK(!psz); RTTESTI_CHECK(psz = RTStrDup("")); RTTESTI_CHECK_RC(RTStrATruncate(&psz, 0), VINF_SUCCESS); RTStrFree(psz); RTTESTI_CHECK(psz = RTStrDup("1234567890")); RTTESTI_CHECK_RC(RTStrATruncate(&psz, 5), VINF_SUCCESS); RTTESTI_CHECK(!RTStrCmp(psz, "12345")); RTStrFree(psz); psz = NULL; for (uint32_t i = 0; i < 128; i++) RTTESTI_CHECK_RC_RETV(RTStrAAppend(&psz, "abcdefghijklmnopqrstuvwxyz"), VINF_SUCCESS); RTTESTI_CHECK_RC(RTStrATruncate(&psz, sizeof("abcdefghijklmnopqrstuvwxyz") - 1), VINF_SUCCESS); RTTESTI_CHECK(!RTStrCmp(psz, "abcdefghijklmnopqrstuvwxyz")); RTTESTI_CHECK_RC(RTStrATruncate(&psz, 6), VINF_SUCCESS); RTTESTI_CHECK(!RTStrCmp(psz, "abcdef")); RTTESTI_CHECK_RC(RTStrATruncate(&psz, 1), VINF_SUCCESS); RTTESTI_CHECK(!RTStrCmp(psz, "a")); RTTESTI_CHECK_RC(RTStrATruncate(&psz, 0), VINF_SUCCESS); RTTESTI_CHECK(!RTStrCmp(psz, "")); RTStrFree(psz); }
/** * Reads the CFGM configuration of the DBGC. * * Popuplates the PDBGC::pszHistoryFile, PDBGC::pszGlobalInitScript and * PDBGC::pszLocalInitScript members. * * @returns VBox status code. * @param pDbgc The console instance. * @param pUVM The user mode VM handle. */ static int dbgcReadConfig(PDBGC pDbgc, PUVM pUVM) { /* * Get and validate the configuration node. */ PCFGMNODE pNode = CFGMR3GetChild(CFGMR3GetRootU(pUVM), "DBGC"); int rc = CFGMR3ValidateConfig(pNode, "/DBGC/", "Enabled|" "HistoryFile|" "LocalInitScript|" "GlobalInitScript", "", "DBGC", 0); AssertRCReturn(rc, rc); /* * Query the values. */ char szHomeDefault[RTPATH_MAX]; rc = RTPathUserHome(szHomeDefault, sizeof(szHomeDefault) - 32); AssertLogRelRCReturn(rc, rc); size_t cchHome = strlen(szHomeDefault); /** @cfgm{/DBGC/HistoryFile, string, ${HOME}/.vboxdbgc-history} * The command history file of the VBox debugger. */ rc = RTPathAppend(szHomeDefault, sizeof(szHomeDefault), ".vboxdbgc-history"); AssertLogRelRCReturn(rc, rc); char szPath[RTPATH_MAX]; rc = CFGMR3QueryStringDef(pNode, "HistoryFile", szPath, sizeof(szPath), szHomeDefault); AssertLogRelRCReturn(rc, rc); pDbgc->pszHistoryFile = RTStrDup(szPath); AssertReturn(pDbgc->pszHistoryFile, VERR_NO_STR_MEMORY); /** @cfgm{/DBGC/GlobalInitFile, string, ${HOME}/.vboxdbgc-init} * The global init script of the VBox debugger. */ szHomeDefault[cchHome] = '\0'; rc = RTPathAppend(szHomeDefault, sizeof(szHomeDefault), ".vboxdbgc-init"); AssertLogRelRCReturn(rc, rc); rc = CFGMR3QueryStringDef(pNode, "GlobalInitScript", szPath, sizeof(szPath), szHomeDefault); AssertLogRelRCReturn(rc, rc); pDbgc->pszGlobalInitScript = RTStrDup(szPath); AssertReturn(pDbgc->pszGlobalInitScript, VERR_NO_STR_MEMORY); /** @cfgm{/DBGC/LocalInitFile, string, none} * The VM local init script of the VBox debugger. */ rc = CFGMR3QueryString(pNode, "LocalInitScript", szPath, sizeof(szPath)); if (RT_SUCCESS(rc)) { pDbgc->pszLocalInitScript = RTStrDup(szPath); AssertReturn(pDbgc->pszLocalInitScript, VERR_NO_STR_MEMORY); } else { AssertLogRelReturn(rc == VERR_CFGM_VALUE_NOT_FOUND || rc == VERR_CFGM_NO_PARENT, rc); pDbgc->pszLocalInitScript = NULL; } return VINF_SUCCESS; }
PUSBDEVICE USBProxyBackendFreeBSD::getDevices(void) { PUSBDEVICE pDevices = NULL; int FileUsb = 0; int iBus = 0; int iAddr = 1; int rc = VINF_SUCCESS; char *pszDevicePath = NULL; uint32_t PlugTime = 0; for (;;) { rc = RTStrAPrintf(&pszDevicePath, "/dev/%s%d.%d", USB_GENERIC_NAME, iBus, iAddr); if (RT_FAILURE(rc)) { mLastError = rc; break; } LogFlowFunc((": Opening %s\n", pszDevicePath)); FileUsb = open(pszDevicePath, O_RDONLY); if (FileUsb < 0) { if ( (errno != ENOENT) && (errno != EACCES)) mLastError = RTErrConvertFromErrno(errno); RTStrFree(pszDevicePath); if ((errno == ENOENT) && (iAddr > 1)) { iAddr = 1; iBus++; continue; } else if (errno == EACCES) { /* Skip devices without the right permission. */ iAddr++; continue; } else break; } LogFlowFunc((": %s opened successfully\n", pszDevicePath)); struct usb_device_info UsbDevInfo; RT_ZERO(UsbDevInfo); rc = ioctl(FileUsb, USB_GET_DEVICEINFO, &UsbDevInfo); if (rc < 0) { LogFlowFunc((": Error querying device info rc=%Rrc\n", RTErrConvertFromErrno(errno))); mLastError = RTErrConvertFromErrno(errno); close(FileUsb); RTStrFree(pszDevicePath); break; } /* Filter out hubs */ if (UsbDevInfo.udi_class != 0x09) { PUSBDEVICE pDevice = (PUSBDEVICE)RTMemAllocZ(sizeof(USBDEVICE)); if (!pDevice) { mLastError = VERR_NO_MEMORY; close(FileUsb); RTStrFree(pszDevicePath); break; } pDevice->enmState = USBDEVICESTATE_UNUSED; pDevice->bBus = UsbDevInfo.udi_bus; pDevice->bDeviceClass = UsbDevInfo.udi_class; pDevice->bDeviceSubClass = UsbDevInfo.udi_subclass; pDevice->bDeviceProtocol = UsbDevInfo.udi_protocol; pDevice->bNumConfigurations = UsbDevInfo.udi_config_no; pDevice->idVendor = UsbDevInfo.udi_vendorNo; pDevice->idProduct = UsbDevInfo.udi_productNo; pDevice->bDevNum = UsbDevInfo.udi_index; switch (UsbDevInfo.udi_speed) { case USB_SPEED_LOW: pDevice->enmSpeed = USBDEVICESPEED_LOW; break; case USB_SPEED_FULL: pDevice->enmSpeed = USBDEVICESPEED_FULL; break; case USB_SPEED_HIGH: pDevice->enmSpeed = USBDEVICESPEED_HIGH; break; case USB_SPEED_SUPER: case USB_SPEED_VARIABLE: default: pDevice->enmSpeed = USBDEVICESPEED_UNKNOWN; } if (UsbDevInfo.udi_vendor[0] != '\0') pDevice->pszManufacturer = RTStrDupN(UsbDevInfo.udi_vendor, sizeof(UsbDevInfo.udi_vendor)); if (UsbDevInfo.udi_product[0] != '\0') pDevice->pszProduct = RTStrDupN(UsbDevInfo.udi_product, sizeof(UsbDevInfo.udi_product)); if (UsbDevInfo.udi_serial[0] != '\0') { pDevice->pszSerialNumber = RTStrDupN(UsbDevInfo.udi_serial, sizeof(UsbDevInfo.udi_serial)); pDevice->u64SerialHash = USBLibHashSerial(pDevice->pszSerialNumber); } rc = ioctl(FileUsb, USB_GET_PLUGTIME, &PlugTime); if (rc == 0) pDevice->u64SerialHash += PlugTime; pDevice->pszAddress = RTStrDup(pszDevicePath); pDevice->pszBackend = RTStrDup("host"); pDevice->enmState = USBDEVICESTATE_USED_BY_HOST_CAPTURABLE; usbLogDevice(pDevice); pDevice->pNext = pDevices; if (pDevices) pDevices->pPrev = pDevice; pDevices = pDevice; } close(FileUsb); RTStrFree(pszDevicePath); iAddr++; } return pDevices; }
/** * Reads a guest property. * * @returns VBox status code, fully bitched. * * @param u32ClientId The HGCM client ID for the guest property session. * @param pszPropName The property name. * @param ppszValue Where to return the value. This is always set * to NULL. Free it using RTStrFree(). * @param ppszFlags Where to return the value flags. Free it * using RTStrFree(). Optional. * @param puTimestamp Where to return the timestamp. This is only set * on success. Optional. */ int VBoxServiceReadProp(uint32_t u32ClientId, const char *pszPropName, char **ppszValue, char **ppszFlags, uint64_t *puTimestamp) { AssertPtrReturn(pszPropName, VERR_INVALID_POINTER); AssertPtrReturn(ppszValue, VERR_INVALID_POINTER); uint32_t cbBuf = _1K; void *pvBuf = NULL; int rc; *ppszValue = NULL; for (unsigned cTries = 0; cTries < 10; cTries++) { /* * (Re-)Allocate the buffer and try read the property. */ RTMemFree(pvBuf); pvBuf = RTMemAlloc(cbBuf); if (!pvBuf) { VBoxServiceError("Guest Property: Failed to allocate %zu bytes\n", cbBuf); rc = VERR_NO_MEMORY; break; } char *pszValue; char *pszFlags; uint64_t uTimestamp; rc = VbglR3GuestPropRead(u32ClientId, pszPropName, pvBuf, cbBuf, &pszValue, &uTimestamp, &pszFlags, NULL); if (RT_FAILURE(rc)) { if (rc == VERR_BUFFER_OVERFLOW) { /* try again with a bigger buffer. */ cbBuf *= 2; continue; } if (rc == VERR_NOT_FOUND) VBoxServiceVerbose(2, "Guest Property: %s not found\n", pszPropName); else VBoxServiceError("Guest Property: Failed to query \"%s\": %Rrc\n", pszPropName, rc); break; } VBoxServiceVerbose(2, "Guest Property: Read \"%s\" = \"%s\", timestamp %RU64n\n", pszPropName, pszValue, uTimestamp); *ppszValue = RTStrDup(pszValue); if (!*ppszValue) { VBoxServiceError("Guest Property: RTStrDup failed for \"%s\"\n", pszValue); rc = VERR_NO_MEMORY; break; } if (puTimestamp) *puTimestamp = uTimestamp; if (ppszFlags) *ppszFlags = RTStrDup(pszFlags); break; /* done */ } if (pvBuf) RTMemFree(pvBuf); return rc; }
static void tstObjectCreateTemp(const char *pszSubTest, const char *pszTemplate, bool fFile, RTFMODE fMode, unsigned cTimes, bool fSkipXCheck) { RTTestISub(pszSubTest); const char *pcszAPI = fFile ? "RTFileCreateTemp" : "RTDirCreateTemp"; /* Allocate the result array. */ char **papszNames = (char **)RTMemTmpAllocZ(cTimes * sizeof(char *)); RTTESTI_CHECK_RETV(papszNames != NULL); /* The test loop. */ unsigned i; for (i = 0; i < cTimes; i++) { int rc; char szName[RTPATH_MAX]; RTFMODE fModeFinal; RTTESTI_CHECK_RC(rc = RTPathAppend(strcpy(szName, g_szTempPath), sizeof(szName), pszTemplate), VINF_SUCCESS); if (RT_FAILURE(rc)) break; RTTESTI_CHECK(papszNames[i] = RTStrDup(szName)); if (!papszNames[i]) break; rc = fFile ? RTFileCreateTemp(papszNames[i], fMode) : RTDirCreateTemp(papszNames[i], fMode); if (rc != VINF_SUCCESS) { RTTestIFailed("%s(%s, %#o) call #%u -> %Rrc\n", pcszAPI, szName, (int)fMode, i, rc); RTStrFree(papszNames[i]); papszNames[i] = NULL; break; } /* Check that the final permissions are not more permissive than * the ones requested (less permissive is fine, c.f. umask etc.). * I mask out the group as I am not sure how we deal with that on * Windows. */ RTTESTI_CHECK_RC_OK(rc = RTPathGetMode(papszNames[i], &fModeFinal)); if (RT_SUCCESS(rc)) { fModeFinal &= (RTFS_UNIX_IRWXU | RTFS_UNIX_IRWXO); RTTESTI_CHECK_MSG((fModeFinal & ~fMode) == 0, ("%s: szName %s\nfModeFinal ~= %#o, expected %#o\n", pcszAPI, szName, fModeFinal, (int)fMode)); } RTTestIPrintf(RTTESTLVL_DEBUG, "%s: %s\n", pcszAPI, papszNames[i]); RTTESTI_CHECK_MSG(strlen(szName) == strlen(papszNames[i]), ("%s: szName %s\nReturned %s\n", pcszAPI, szName, papszNames[i])); if (!fSkipXCheck) RTTESTI_CHECK_MSG(strchr(RTPathFilename(papszNames[i]), 'X') == NULL, ("%s: szName %s\nReturned %s\n", pcszAPI, szName, papszNames[i])); } /* cleanup */ while (i-- > 0) { if (fFile) RTTESTI_CHECK_RC(RTFileDelete(papszNames[i]), VINF_SUCCESS); else RTTESTI_CHECK_RC(RTDirRemove(papszNames[i]), VINF_SUCCESS); RTStrFree(papszNames[i]); } RTMemTmpFree(papszNames); }
/** * Returns the path of the ACPI CPU device with the given core and package ID. * * @returns VBox status code. * @param ppszPath Where to store the path. * @param idCpuCore The core ID of the CPU. * @param idCpuPackage The package ID of the CPU. */ static int VBoxServiceCpuHotPlugGetACPIDevicePath(char **ppszPath, uint32_t idCpuCore, uint32_t idCpuPackage) { int rc = VINF_SUCCESS; AssertPtrReturn(ppszPath, VERR_INVALID_PARAMETER); rc = VBoxServiceCpuHotPlugProbePath(); if (RT_SUCCESS(rc)) { /* Build the path from all components. */ bool fFound = false; unsigned iLvlCurr = 0; char *pszPath = NULL; char *pszPathDir = NULL; PSYSFSCPUPATH pAcpiCpuPathLvl = &g_aAcpiCpuPath[iLvlCurr]; /* Init everything. */ Assert(pAcpiCpuPathLvl->uId != ACPI_CPU_PATH_NOT_PROBED); pszPath = RTPathJoinA(SYSFS_ACPI_CPU_PATH, pAcpiCpuPathLvl->aComponentsPossible[pAcpiCpuPathLvl->uId].pcszName); if (!pszPath) return VERR_NO_STR_MEMORY; pAcpiCpuPathLvl->pszPath = RTStrDup(SYSFS_ACPI_CPU_PATH); if (!pAcpiCpuPathLvl->pszPath) { RTStrFree(pszPath); return VERR_NO_STR_MEMORY; } /* Open the directory */ rc = RTDirOpenFiltered(&pAcpiCpuPathLvl->pDir, pszPath, RTDIRFILTER_WINNT, 0); if (RT_SUCCESS(rc)) { RTStrFree(pszPath); /* Search for CPU */ while (!fFound) { /* Get the next directory. */ RTDIRENTRY DirFolderContent; rc = RTDirRead(pAcpiCpuPathLvl->pDir, &DirFolderContent, NULL); if (RT_SUCCESS(rc)) { /* Create the new path. */ char *pszPathCurr = RTPathJoinA(pAcpiCpuPathLvl->pszPath, DirFolderContent.szName); if (!pszPathCurr) { rc = VERR_NO_STR_MEMORY; break; } /* If this is the last level check for the given core and package id. */ if (iLvlCurr == RT_ELEMENTS(g_aAcpiCpuPath) - 1) { /* Get the sysdev */ uint32_t idCore = RTLinuxSysFsReadIntFile(10, "%s/sysdev/topology/core_id", pszPathCurr); uint32_t idPackage = RTLinuxSysFsReadIntFile(10, "%s/sysdev/topology/physical_package_id", pszPathCurr); if ( idCore == idCpuCore && idPackage == idCpuPackage) { /* Return the path */ pszPath = pszPathCurr; fFound = true; VBoxServiceVerbose(3, "CPU found\n"); break; } else { /* Get the next directory. */ RTStrFree(pszPathCurr); VBoxServiceVerbose(3, "CPU doesn't match, next directory\n"); } } else { /* Go deeper */ iLvlCurr++; VBoxServiceVerbose(3, "Going deeper (iLvlCurr=%u)\n", iLvlCurr); pAcpiCpuPathLvl = &g_aAcpiCpuPath[iLvlCurr]; Assert(!pAcpiCpuPathLvl->pDir); Assert(!pAcpiCpuPathLvl->pszPath); pAcpiCpuPathLvl->pszPath = pszPathCurr; PCSYSFSCPUPATHCOMP pPathComponent = &pAcpiCpuPathLvl->aComponentsPossible[pAcpiCpuPathLvl->uId]; Assert(pAcpiCpuPathLvl->uId != ACPI_CPU_PATH_NOT_PROBED); pszPathDir = RTPathJoinA(pszPathCurr, pPathComponent->pcszName); if (!pszPathDir) { rc = VERR_NO_STR_MEMORY; break; } VBoxServiceVerbose(3, "New path %s\n", pszPathDir); /* Open the directory */ rc = RTDirOpenFiltered(&pAcpiCpuPathLvl->pDir, pszPathDir, RTDIRFILTER_WINNT, 0); if (RT_FAILURE(rc)) break; } } else { /* Go back one level and try to get the next entry. */ Assert(iLvlCurr > 0); RTDirClose(pAcpiCpuPathLvl->pDir); RTStrFree(pAcpiCpuPathLvl->pszPath); pAcpiCpuPathLvl->pDir = NULL; pAcpiCpuPathLvl->pszPath = NULL; iLvlCurr--; pAcpiCpuPathLvl = &g_aAcpiCpuPath[iLvlCurr]; VBoxServiceVerbose(3, "Directory not found, going back (iLvlCurr=%u)\n", iLvlCurr); } } /* while not found */ } /* Successful init */ /* Cleanup */ for (unsigned i = 0; i < RT_ELEMENTS(g_aAcpiCpuPath); i++) { if (g_aAcpiCpuPath[i].pDir) RTDirClose(g_aAcpiCpuPath[i].pDir); if (g_aAcpiCpuPath[i].pszPath) RTStrFree(g_aAcpiCpuPath[i].pszPath); g_aAcpiCpuPath[i].pDir = NULL; g_aAcpiCpuPath[i].pszPath = NULL; } if (pszPathDir) RTStrFree(pszPathDir); if (RT_FAILURE(rc) && pszPath) RTStrFree(pszPath); if (RT_SUCCESS(rc)) *ppszPath = pszPath; } return rc; }