/** * Changes the file mode of one file system object. * * @returns exit code * @param pOpts The chmod options. * @param pszPath The path to the file system object to change the * file mode of. */ static RTEXITCODE rtCmdChModOne(RTCMDCHMODOPTS const *pOpts, const char *pszPath) { int rc; RTFSOBJINFO ObjInfo; bool fChanges = false; if (!pOpts->fAlwaysUseChainApi && !RTVfsChainIsSpec(pszPath) ) { rc = RTPathQueryInfoEx(pszPath, &ObjInfo, RTFSOBJATTRADD_NOTHING, RTPATH_F_FOLLOW_LINK); if (RT_SUCCESS(rc)) { RTFMODE fNewMode = rtCmdMkModCalcNewMode(pOpts, ObjInfo.Attr.fMode); fChanges = fNewMode != ObjInfo.Attr.fMode; if (fChanges) { rc = RTPathSetMode(pszPath, fNewMode); if (RT_FAILURE(rc)) RTMsgError("RTPathSetMode failed on '%s' with fNewMode=%#x: %Rrc", pszPath, fNewMode, rc); } } else RTMsgError("RTPathQueryInfoEx failed on '%s': %Rrc", pszPath, rc); } else { RTVFSOBJ hVfsObj; uint32_t offError; RTERRINFOSTATIC ErrInfo; rc = RTVfsChainOpenObj(pszPath, RTFILE_O_ACCESS_ATTR_READWRITE | RTFILE_O_DENY_NONE | RTFILE_O_OPEN, RTVFSOBJ_F_OPEN_ANY | RTVFSOBJ_F_CREATE_NOTHING | RTPATH_F_FOLLOW_LINK, &hVfsObj, &offError, RTErrInfoInitStatic(&ErrInfo)); if (RT_SUCCESS(rc)) { rc = RTVfsObjQueryInfo(hVfsObj, &ObjInfo, RTFSOBJATTRADD_NOTHING); if (RT_SUCCESS(rc)) { RTFMODE fNewMode = rtCmdMkModCalcNewMode(pOpts, ObjInfo.Attr.fMode); fChanges = fNewMode != ObjInfo.Attr.fMode; if (fChanges) { rc = RTVfsObjSetMode(hVfsObj, fNewMode, RTCHMOD_SET_ALL_MASK); if (RT_FAILURE(rc)) RTMsgError("RTVfsObjSetMode failed on '%s' with fNewMode=%#x: %Rrc", pszPath, fNewMode, rc); } } else RTVfsChainMsgError("RTVfsObjQueryInfo", pszPath, rc, offError, &ErrInfo.Core); RTVfsObjRelease(hVfsObj); } else RTVfsChainMsgError("RTVfsChainOpenObject", pszPath, rc, offError, &ErrInfo.Core); } if (RT_SUCCESS(rc)) { if (pOpts->enmNoiseLevel >= (fChanges ? kRTCmdChModNoise_Changes : kRTCmdChModNoise_Verbose)) RTPrintf("%s\n", pszPath); return RTEXITCODE_SUCCESS; } return RTEXITCODE_FAILURE; }
/** * Executes SVN. * * Standard error and standard output is suppressed. * * @returns VINF_SUCCESS if the command executed successfully. * @param pState The rewrite state to work on. * @param papszArgs The SVN argument. * @param fNormalFailureOk Whether normal failure is ok. */ static int scmSvnRun(PSCMRWSTATE pState, const char **papszArgs, bool fNormalFailureOk) { char *pszCmdLine = NULL; int rc = RTGetOptArgvToString(&pszCmdLine, papszArgs, RTGETOPTARGV_CNV_QUOTE_BOURNE_SH); if (RT_FAILURE(rc)) return rc; ScmVerbose(pState, 2, "executing: %s\n", pszCmdLine); /* Lazy bird uses RTProcExecToString. */ RTPROCSTATUS Status; rc = RTProcExec(g_szSvnPath, papszArgs, RTENV_DEFAULT, RTPROCEXEC_FLAGS_STD_NULL, &Status); if ( RT_SUCCESS(rc) && ( Status.enmReason != RTPROCEXITREASON_NORMAL || Status.iStatus != 0) ) { if (fNormalFailureOk || Status.enmReason != RTPROCEXITREASON_NORMAL) RTMsgError("%s: %s -> %s %u\n", pState->pszFilename, pszCmdLine, Status.enmReason == RTPROCEXITREASON_NORMAL ? "exit code" : Status.enmReason == RTPROCEXITREASON_SIGNAL ? "signal" : Status.enmReason == RTPROCEXITREASON_ABEND ? "abnormal end" : "abducted by alien", Status.iStatus); rc = VERR_GENERAL_FAILURE; } else if (RT_FAILURE(rc)) RTMsgError("%s: %s -> %Rrc\n", pState->pszFilename, pszCmdLine, rc); RTStrFree(pszCmdLine); return rc; }
static int GetKeyByName(uint32_t uKey, SMCPARAM *pKeyData) { SMCPARAM In; RT_ZERO(In); In.uKey.u = uKey; int rc = CallSmc(kSMCGetKeyInfo, &In, pKeyData); if (RT_SUCCESS(rc) && pKeyData->uResult == kSMCSuccess) { SMCPARAM Tmp = *pKeyData; /* Get the key value. */ RT_ZERO(In); In.uKey.u = uKey; In.KeyInfo = Tmp.KeyInfo; rc = CallSmc(kSMCReadKey, &In, pKeyData); if (RT_SUCCESS(rc) && (pKeyData->uResult == kSMCSuccess || pKeyData->uResult == 0x85 /* not readable */)) { pKeyData->uKey.u = uKey; pKeyData->KeyInfo = Tmp.KeyInfo; rc = VINF_SUCCESS; } else if (RT_SUCCESS(rc)) { RTMsgError("kSMCReadKey failed on %.4s: %#x\n", &uKey, pKeyData->uResult); rc = VERR_IO_GEN_FAILURE; } } else if (RT_SUCCESS(rc)) { RTMsgError("kSMCGetKeyInfo failed on %.4s: %#x\n", &uKey, pKeyData->uResult); rc = VERR_IO_GEN_FAILURE; } return rc; }
/** * Free a async I/O request. * * @returns nothing. * @param pThis Disk driver. * @param pIoReq The I/O request to free. */ static void drvdiskintIoReqFree(PDRVDISKINTEGRITY pThis, PDRVDISKAIOREQ pIoReq) { if (pThis->fCheckDoubleCompletion) { /* Search if the I/O request completed already. */ for (unsigned i = 0; i < pThis->cEntries; i++) { if (RT_UNLIKELY(pThis->papIoReq[i] == pIoReq)) { RTMsgError("Request %#p completed already!\n", pIoReq); RTMsgError("Start timestamp %llu Completion timestamp %llu (completed after %llu ms)\n", pIoReq->tsStart, pIoReq->tsComplete, pIoReq->tsComplete - pIoReq->tsStart); RTAssertDebugBreak(); } } pIoReq->tsComplete = RTTimeSystemMilliTS(); Assert(!pThis->papIoReq[pThis->iEntry]); pThis->papIoReq[pThis->iEntry] = pIoReq; pThis->iEntry = (pThis->iEntry+1) % pThis->cEntries; if (pThis->papIoReq[pThis->iEntry]) { RTMemFree(pThis->papIoReq[pThis->iEntry]); pThis->papIoReq[pThis->iEntry] = NULL; } } else RTMemFree(pIoReq); }
/** * Reads a certificate from a file, returning a context or a the handle to a * temporary memory store. * * @returns true on success, false on failure (error message written). * @param pszCertFile The name of the file containing the * certificates. * @param ppOutCtx Where to return the certificate context. * @param phSrcStore Where to return the handle to the temporary * memory store. */ static bool readCertFile(const char *pszCertFile, PCCERT_CONTEXT *ppOutCtx, HCERTSTORE *phSrcStore) { *ppOutCtx = NULL; *phSrcStore = NULL; bool fRc = false; void *pvFile; size_t cbFile; int rc = RTFileReadAll(pszCertFile, &pvFile, &cbFile); if (RT_SUCCESS(rc)) { *ppOutCtx = CertCreateCertificateContext(X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, (PBYTE)pvFile, (DWORD)cbFile); if (*ppOutCtx) fRc = true; else { /** @todo figure out if it's some other format... */ RTMsgError("CertCreateCertificateContext returned %s parsing the content of '%s'", errorToString(GetLastError()), pszCertFile); } } else RTMsgError("RTFileReadAll failed on '%s': %Rrc", pszCertFile, rc); RTFileReadAllFree(pvFile, cbFile); return fRc; }
static int GetKeyByIndex(uint32_t iKey, SMCPARAM *pKeyData) { SMCPARAM In; RT_ZERO(In); In.u32Data = iKey; int rc = CallSmc(kSMCGetKeyFromIndex, &In, pKeyData); if (RT_SUCCESS(rc)) { if (pKeyData->uResult == kSMCSuccess) { SMCPARAM Tmp = *pKeyData; /* Get the key info. */ RT_ZERO(In); In.uKey.u = Tmp.uKey.u; rc = CallSmc(kSMCGetKeyInfo, &In, pKeyData); if (RT_SUCCESS(rc) && pKeyData->uResult == kSMCSuccess) { Tmp.KeyInfo = pKeyData->KeyInfo; /* Get the key value. */ RT_ZERO(In); In.uKey = Tmp.uKey; In.KeyInfo = Tmp.KeyInfo; rc = CallSmc(kSMCReadKey, &In, pKeyData); if (RT_SUCCESS(rc) && (pKeyData->uResult == kSMCSuccess || pKeyData->uResult == 0x85 /* not readable */)) { pKeyData->uKey = Tmp.uKey; pKeyData->KeyInfo = Tmp.KeyInfo; rc = VINF_SUCCESS; } else if (RT_SUCCESS(rc)) { RTMsgError("kSMCReadKey failed on #%x/%.4s: %#x\n", iKey, Tmp.uKey.au8, pKeyData->uResult); rc = VERR_IO_GEN_FAILURE; } } else if (RT_SUCCESS(rc)) { RTMsgError("kSMCGetKeyInfo failed on #%x/%.4s: %#x\n", iKey, Tmp.uKey.au8, pKeyData->uResult); rc = VERR_IO_GEN_FAILURE; } } else { RTMsgError("kSMCGetKeyFromIndex failed on #%x: %#x\n", iKey, pKeyData->uResult); rc = VERR_IO_GEN_FAILURE; } } return rc; }
int VBoxSVCLogRelCreate(const char *pszLogFile, uint32_t cHistory, uint32_t uHistoryFileTime, uint64_t uHistoryFileSize) { /* create release logger */ PRTLOGGER pLoggerReleaseFile; static const char * const s_apszGroups[] = VBOX_LOGGROUP_NAMES; RTUINT fFlags = RTLOGFLAGS_PREFIX_THREAD | RTLOGFLAGS_PREFIX_TIME_PROG; #if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2) fFlags |= RTLOGFLAGS_USECRLF; #endif char szError[RTPATH_MAX + 128] = ""; int vrc = RTLogCreateEx(&pLoggerReleaseFile, fFlags, "all", "VBOXSVC_RELEASE_LOG", RT_ELEMENTS(s_apszGroups), s_apszGroups, 0 /* fDestFlags */, vboxsvcHeaderFooter, cHistory, uHistoryFileSize, uHistoryFileTime, szError, sizeof(szError), pszLogFile); if (RT_SUCCESS(vrc)) { /* register this logger as the release logger */ RTLogRelSetDefaultInstance(pLoggerReleaseFile); /* Explicitly flush the log in case of VBOXWEBSRV_RELEASE_LOG=buffered. */ RTLogFlush(pLoggerReleaseFile); } else { /* print a message, but do not fail */ RTMsgError("failed to open release log (%s, %Rrc)", szError, vrc); } return vrc; }
void GluePrintRCMessage(HRESULT rc) { Utf8Str str = Utf8StrFmt("Code %Rhra (extended info not available)\n", rc); // print and log RTMsgError("%s", str.c_str()); Log(("ERROR: %s", str.c_str())); }
static void glueHandleComErrorInternal(com::ErrorInfo &info, const char *pcszContext, HRESULT rc, const char *pcszSourceFile, uint32_t ulLine) { const com::ErrorInfo *pInfo = &info; do { if (pInfo->isFullAvailable() || pInfo->isBasicAvailable()) GluePrintErrorInfo(*pInfo); else #if defined (RT_OS_WIN) GluePrintRCMessage(rc); #else /* defined (RT_OS_WIN) */ GluePrintRCMessage(pInfo->getResultCode()); #endif pInfo = pInfo->getNext(); /* If there is more than one error, separate them visually. */ if (pInfo) RTMsgError("--------\n"); } while(pInfo); GluePrintErrorContext(pcszContext, pcszSourceFile, ulLine); }
/** * Recursively changes the file mode. * * @returns exit code * @param pOpts The mkdir option. * @param pszPath The path to start changing the mode of. */ static int rtCmdChModRecursive(RTCMDCHMODOPTS const *pOpts, const char *pszPath) { /* * Check if it's a directory first. If not, join the non-recursive code. */ int rc; uint32_t offError; RTFSOBJINFO ObjInfo; RTERRINFOSTATIC ErrInfo; bool const fUseChainApi = pOpts->fAlwaysUseChainApi || RTVfsChainIsSpec(pszPath); if (!fUseChainApi) { rc = RTPathQueryInfoEx(pszPath, &ObjInfo, RTFSOBJATTRADD_NOTHING, RTPATH_F_FOLLOW_LINK); if (RT_FAILURE(rc)) return RTMsgErrorExitFailure("RTPathQueryInfoEx failed on '%s': %Rrc", pszPath, rc); } else { rc = RTVfsChainQueryInfo(pszPath, &ObjInfo, RTFSOBJATTRADD_NOTHING, RTPATH_F_FOLLOW_LINK, &offError, RTErrInfoInitStatic(&ErrInfo)); if (RT_FAILURE(rc)) return RTVfsChainMsgErrorExitFailure("RTVfsChainQueryInfo", pszPath, rc, offError, &ErrInfo.Core); } if (!RTFS_IS_DIRECTORY(ObjInfo.Attr.fMode)) { /* * Don't bother redoing the above work if its not necessary. */ RTFMODE fNewMode = rtCmdMkModCalcNewMode(pOpts, ObjInfo.Attr.fMode); if (fNewMode != ObjInfo.Attr.fMode) return rtCmdChModOne(pOpts, pszPath); if (pOpts->enmNoiseLevel >= kRTCmdChModNoise_Verbose) RTPrintf("%s\n", pszPath); return RTEXITCODE_SUCCESS; } /* * For recursion we always use the VFS layer. */ RTVFSDIR hVfsDir; if (!fUseChainApi) { rc = RTVfsDirOpenNormal(pszPath, 0 /** @todo write attrib flag*/, &hVfsDir); if (RT_FAILURE(rc)) return RTMsgErrorExitFailure("RTVfsDirOpenNormal failed on '%s': %Rrc", pszPath, rc); } else { rc = RTVfsChainOpenDir(pszPath, 0 /** @todo write attrib flag*/, &hVfsDir, &offError, RTErrInfoInitStatic(&ErrInfo)); if (RT_FAILURE(rc)) return RTVfsChainMsgErrorExitFailure("RTVfsChainQueryInfo", pszPath, rc, offError, &ErrInfo.Core); } RTMsgError("Recursion is not yet implemented\n"); RTVfsDirRelease(hVfsDir); rc = VERR_NOT_IMPLEMENTED; return RT_SUCCESS(rc) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE; }
/** * Opens a certificate store. * * @returns true on success, false on failure (error message written). * @param dwDst The destination, like * CERT_SYSTEM_STORE_LOCAL_MACHINE or * CERT_SYSTEM_STORE_CURRENT_USER. * @param pszStoreNm The store name. */ static HCERTSTORE openCertStore(DWORD dwDst, const char *pszStoreNm) { HCERTSTORE hStore = NULL; PRTUTF16 pwszStoreNm; int rc = RTStrToUtf16(pszStoreNm, &pwszStoreNm); if (RT_SUCCESS(rc)) { if (g_cVerbosityLevel > 1) RTMsgInfo("Opening store %#x:'%s'", dwDst, pszStoreNm); /* * Make sure CERT_STORE_OPEN_EXISTING_FLAG is not set. This causes Windows XP * to return ACCESS_DENIED when installing TrustedPublisher certificates via * CertAddCertificateContextToStore() if the TrustedPublisher store never has * been used (through certmgr.exe and friends) yet. * * According to MSDN, if neither CERT_STORE_OPEN_EXISTING_FLAG nor * CERT_STORE_CREATE_NEW_FLAG is set, the store will be either opened or * created accordingly. */ dwDst &= ~CERT_STORE_OPEN_EXISTING_FLAG; hStore = CertOpenStore(CERT_STORE_PROV_SYSTEM_W, PKCS_7_ASN_ENCODING | X509_ASN_ENCODING, NULL /* hCryptProv = default */, dwDst, pwszStoreNm); if (hStore == NULL) RTMsgError("CertOpenStore failed opening %#x:'%s': %s", dwDst, pszStoreNm, errorToString(GetLastError())); RTUtf16Free(pwszStoreNm); } return hStore; }
/** * @interface_method_impl{TXSTRANSPORT,pfnInit} */ static DECLCALLBACK(int) txsTcpInit(void) { int rc = RTCritSectInit(&g_TcpCritSect); if (RT_SUCCESS(rc) && g_enmTcpMode != TXSTCPMODE_CLIENT) { rc = RTTcpServerCreateEx(g_szTcpBindAddr[0] ? g_szTcpBindAddr : NULL, g_uTcpBindPort, &g_pTcpServer); if (RT_FAILURE(rc)) { if (rc == VERR_NET_DOWN) { RTMsgInfo("RTTcpServerCreateEx(%s, %u,) failed: %Rrc, retrying for 20 seconds...\n", g_szTcpBindAddr[0] ? g_szTcpBindAddr : NULL, g_uTcpBindPort, rc); uint64_t StartMs = RTTimeMilliTS(); do { RTThreadSleep(1000); rc = RTTcpServerCreateEx(g_szTcpBindAddr[0] ? g_szTcpBindAddr : NULL, g_uTcpBindPort, &g_pTcpServer); } while ( rc == VERR_NET_DOWN && RTTimeMilliTS() - StartMs < 20000); if (RT_SUCCESS(rc)) RTMsgInfo("RTTcpServerCreateEx succceeded.\n"); } if (RT_FAILURE(rc)) { g_pTcpServer = NULL; RTCritSectDelete(&g_TcpCritSect); RTMsgError("RTTcpServerCreateEx(%s, %u,) failed: %Rrc\n", g_szTcpBindAddr[0] ? g_szTcpBindAddr : NULL, g_uTcpBindPort, rc); } } } return rc; }
static void autostartConfigTokenizerMsgUnexpectedToken(PCFGTOKEN pToken, const char *pszExpected) { RTMsgError("Unexpected token '%s' at %d:%d.%d, expected '%s'", autostartConfigTokenToString(pToken), pToken->iLine, pToken->cchStart, pToken->cchStart + autostartConfigTokenGetLength(pToken) - 1, pszExpected); }
/** * Thread checking for expired requests. * * @returns IPRT status code. * @param pThread Thread handle. * @param pvUser Opaque user data. */ static int drvdiskIntIoReqExpiredCheck(RTTHREAD pThread, void *pvUser) { PDRVDISKINTEGRITY pThis = (PDRVDISKINTEGRITY)pvUser; while (pThis->fRunning) { int rc = RTSemEventWait(pThis->SemEvent, pThis->uCheckIntervalMs); if (!pThis->fRunning) break; Assert(rc == VERR_TIMEOUT); /* Get current timestamp for comparison. */ uint64_t tsCurr = RTTimeSystemMilliTS(); /* Go through the array and check for expired requests. */ for (unsigned i = 0; i < RT_ELEMENTS(pThis->apReqActive); i++) { PDRVDISKAIOREQACTIVE pReqActive = &pThis->apReqActive[i]; PDRVDISKAIOREQ pIoReq = ASMAtomicReadPtrT(&pReqActive->pIoReq, PDRVDISKAIOREQ); if ( pIoReq && (tsCurr > pReqActive->tsStart) && (tsCurr - pReqActive->tsStart) >= pThis->uExpireIntervalMs) { RTMsgError("Request %#p expired (active for %llu ms already)\n", pIoReq, tsCurr - pReqActive->tsStart); RTAssertDebugBreak(); } } } return VINF_SUCCESS; }
int main(int argc, char **argv) { int rc = RTR3InitExe(argc, &argv, 0); if (RT_FAILURE(rc)) return RTMsgInitFailure(rc); /* * Switch on the command. */ RTEXITCODE rcExit = RTEXITCODE_SYNTAX; if (argc < 2) rtDbgSymCacheUsage(argv[0], NULL); else if (!strcmp(argv[1], "add")) rcExit = rtDbgSymCacheCmdAdd(argv[0], argc - 2, argv + 2); else if ( !strcmp(argv[1], "-h") || !strcmp(argv[1], "-?") || !strcmp(argv[1], "--help")) rcExit = rtDbgSymCacheUsage(argv[0], NULL); else if ( !strcmp(argv[1], "-V") || !strcmp(argv[1], "--version")) rcExit = rtDbgSymCacheVersion(); else RTMsgError("Unknown command: '%s'", argv[1]); return rcExit; }
/** * Worker for cmdDisplayAll. */ static BOOL WINAPI displaySystemStoreLocation(LPCWSTR pwszStoreLocation, DWORD dwFlags, void *pvReserved, void *pvArg) { NOREF(pvReserved); NOREF(pvArg); RTPrintf("System store location: %#010x '%ls'\n", dwFlags, pwszStoreLocation); if (!CertEnumSystemStore(dwFlags, NULL, NULL /*pvArg*/, displaySystemStoreCallback)) RTMsgError("CertEnumSystemStore failed on %#x:'%ls': %s\n", dwFlags, pwszStoreLocation, errorToString(GetLastError())); return TRUE; }
static int CallSmc(KSMCFUNCTION enmFunction, SMCPARAM *pIn, SMCPARAM *pOut) { RT_ZERO(*pOut); pIn->bData = enmFunction; size_t cbOut = sizeof(*pOut); IOReturn rcIo = IOConnectCallStructMethod(g_hSmcConnect, kSMCHandleYPCEvent, pIn, sizeof(*pIn), pOut, &cbOut); if (rcIo == kIOReturnSuccess) return VINF_SUCCESS; RTMsgError("SMC call %d failed: rcIo=%d (%#x)\n", enmFunction, rcIo, rcIo); return RTErrConvertFromDarwinIO(rcIo); }
/** * Make sure the Id and Revision keywords are expanded. * * @returns false - the state carries these kinds of changes. * @param pState The rewriter state. * @param pIn The input stream. * @param pOut The output stream. * @param pSettings The settings. */ bool rewrite_SvnKeywords(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings) { if ( !pSettings->fSetSvnKeywords || !ScmSvnIsInWorkingCopy(pState)) return false; char *pszKeywords; int rc = ScmSvnQueryProperty(pState, "svn:keywords", &pszKeywords); if ( RT_SUCCESS(rc) && ( !strstr(pszKeywords, "Id") /** @todo need some function for finding a word in a string. */ || !strstr(pszKeywords, "Revision")) ) { if (!strstr(pszKeywords, "Id") && !strstr(pszKeywords, "Revision")) rc = RTStrAAppend(&pszKeywords, " Id Revision"); else if (!strstr(pszKeywords, "Id")) rc = RTStrAAppend(&pszKeywords, " Id"); else rc = RTStrAAppend(&pszKeywords, " Revision"); if (RT_SUCCESS(rc)) { ScmVerbose(pState, 2, " * changing svn:keywords to '%s'\n", pszKeywords); rc = ScmSvnSetProperty(pState, "svn:keywords", pszKeywords); if (RT_FAILURE(rc)) RTMsgError("ScmSvnSetProperty: %Rrc\n", rc); /** @todo error propagation here.. */ } else RTMsgError("RTStrAppend: %Rrc\n", rc); /** @todo error propagation here.. */ RTStrFree(pszKeywords); } else if (rc == VERR_NOT_FOUND) { ScmVerbose(pState, 2, " * setting svn:keywords to 'Id Revision'\n"); rc = ScmSvnSetProperty(pState, "svn:keywords", "Id Revision"); if (RT_FAILURE(rc)) RTMsgError("ScmSvnSetProperty: %Rrc\n", rc); /** @todo error propagation here.. */ } else if (RT_SUCCESS(rc)) RTStrFree(pszKeywords); return false; }
static int ConnectToSmc(void) { g_hSmcService = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("AppleSMC")); if (g_hSmcService == IO_OBJECT_NULL) return VERR_NOT_FOUND; IOReturn rcIo = IOServiceOpen(g_hSmcService, mach_task_self(), 1, &g_hSmcConnect); if (rcIo == kIOReturnSuccess && g_hSmcConnect != IO_OBJECT_NULL) { rcIo = IOConnectCallMethod(g_hSmcConnect, kSMCUserClientOpen, NULL, 0, NULL, 0, NULL, NULL, NULL, NULL); if (rcIo == kIOReturnSuccess) return VINF_SUCCESS; RTMsgError("kSMCUserClientOpen failed: %#x (%#x)\n", rcIo, rcIo); } else { RTMsgError("IOServiceOpen failed: %#x (%#x)\n", rcIo, rcIo); g_hSmcConnect = IO_OBJECT_NULL; } return RTErrConvertFromDarwinIO(rcIo); }
/** * Adds a debug file to the cache. * * @returns IPRT status code * @param pszPath The path to the debug file in question. * @param pCfg The configuration. */ static int rtDbgSymCacheAddDebugFile(const char *pszPath, PCRTDBGSYMCACHEADDCFG pCfg) { /* * Need to extract an identifier of sorts here in order to put them in * the right place in the cache. Currently only implemnted for Mach-O * files since these use executable containers. * * We take a look at the file header in hope to figure out what to do * with the file. */ RTFILE hFile; int rc = RTFileOpen(&hFile, pszPath, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE); if (RT_FAILURE(rc)) return RTMsgErrorRc(rc, "Error opening '%s': %Rrc", pszPath, rc); union { uint64_t au64[16]; uint32_t au32[16]; uint16_t au16[32]; uint8_t ab[64]; } uBuf; rc = RTFileRead(hFile, &uBuf, sizeof(uBuf), NULL); if (RT_SUCCESS(rc)) { /* * Look for magics and call workers. */ if (!memcmp(uBuf.ab, RT_STR_TUPLE("Microsoft C/C++ MSF 7.00"))) rc = rtDbgSymCacheAddDebugPdb(pszPath, pCfg, hFile); else if ( uBuf.au32[0] == IMAGE_FAT_SIGNATURE || uBuf.au32[0] == IMAGE_FAT_SIGNATURE_OE || uBuf.au32[0] == IMAGE_MACHO32_SIGNATURE || uBuf.au32[0] == IMAGE_MACHO64_SIGNATURE || uBuf.au32[0] == IMAGE_MACHO32_SIGNATURE_OE || uBuf.au32[0] == IMAGE_MACHO64_SIGNATURE_OE) rc = rtDbgSymCacheAddDebugMachO(pszPath, pCfg); else rc = RTMsgErrorRc(VERR_INVALID_MAGIC, "Unsupported debug file '%s' magic: %#010x", pszPath, uBuf.au32[0]); } else rc = RTMsgErrorRc(rc, "Error reading '%s': %Rrc", pszPath, rc); /* close the file. */ int rc2 = RTFileClose(hFile); if (RT_FAILURE(rc2)) { RTMsgError("Error closing '%s': %Rrc", pszPath, rc2); if (RT_SUCCESS(rc)) rc = rc2; } return rc; }
/** * Adds a certificate to a store. * * @returns true on success, false on failure (error message written). * @param dwDst The destination, like * CERT_SYSTEM_STORE_LOCAL_MACHINE or * ERT_SYSTEM_STORE_CURRENT_USER. * @param pszStoreNm The store name. * @param pszCertFile The file containing the certificate to add. * @param dwDisposition The disposition towards existing certificates when * adding it. CERT_STORE_ADD_NEW is a safe one. */ static bool addCertToStore(DWORD dwDst, const char *pszStoreNm, const char *pszCertFile, DWORD dwDisposition) { /* * Read the certificate file first. */ PCCERT_CONTEXT pSrcCtx = NULL; HCERTSTORE hSrcStore = NULL; if (!readCertFile(pszCertFile, &pSrcCtx, &hSrcStore)) return false; /* * Open the destination store. */ bool fRc = false; HCERTSTORE hDstStore = openCertStore(dwDst, pszStoreNm); if (hDstStore) { if (pSrcCtx) { if (g_cVerbosityLevel > 1) RTMsgInfo("Adding '%s' to %#x:'%s'... (disp %d)", pszCertFile, dwDst, pszStoreNm, dwDisposition); if (CertAddCertificateContextToStore(hDstStore, pSrcCtx, dwDisposition, NULL)) fRc = true; else RTMsgError("CertAddCertificateContextToStore returned %s", errorToString(GetLastError())); } else { RTMsgError("Path not implemented at line %d\n", __LINE__); } CertCloseStore(hDstStore, CERT_CLOSE_STORE_CHECK_FLAG); } if (pSrcCtx) CertFreeCertificateContext(pSrcCtx); if (hSrcStore) CertCloseStore(hSrcStore, CERT_CLOSE_STORE_CHECK_FLAG); return fRc; }
void GluePrintErrorContext(const char *pcszContext, const char *pcszSourceFile, uint32_t ulLine) { // pcszSourceFile comes from __FILE__ macro, which always contains the full path, // which we don't want to see printed: Utf8Str strFilename(RTPathFilename(pcszSourceFile)); Utf8Str str = Utf8StrFmt("Context: \"%s\" at line %d of file %s\n", pcszContext, ulLine, strFilename.c_str()); // print and log RTMsgError("%s", str.c_str()); Log(("%s", str.c_str())); }
/** * Adds a image bundle of some sort. * * @returns IPRT status code. * @param pszPath Path to the bundle. This a RTPATH_MAX size * buffer that we can write to when creating the * path to the file inside the bundle that we're * interested in. * @param cchPath The length of the path up to the bundle name. * @param cchName The length of the bundle name. * @param pDirEntry The directory entry buffer, for handling bundle * within bundle recursion. * @param pCfg The configuration. */ static int rtDbgSymCacheAddImageBundle(char *pszPath, size_t cchPath, size_t cchName, PRTDIRENTRYEX pDirEntry, PCRTDBGSYMCACHEADDCFG pCfg) { /* * Assuming these are kexts or simple applications, we only add the image * file itself to the cache. No Info.plist or other files. */ /** @todo consider looking for Frameworks and handling framework bundles. */ int rc = rtDbgSymCacheConstructBundlePath(pszPath, cchPath, cchName, "Contents/MacOS/", g_apszBundleSuffixes); if (RT_SUCCESS(rc)) rc = rtDbgSymCacheAddImageFile(pszPath, NULL, RTDBG_CACHE_UUID_MAP_DIR_IMAGES, pCfg); /* * Look for plugins and other sub-bundles. */ if (pCfg->fRecursive) { static char const * const s_apszSubBundleDirs[] = { "Contents/Plugins/", /** @todo Frameworks ++ */ }; for (uint32_t i = 0; i < RT_ELEMENTS(s_apszSubBundleDirs); i++) { pszPath[cchPath + cchName] = '\0'; int rc2 = RTPathAppend(pszPath, RTPATH_MAX - 1, s_apszSubBundleDirs[i]); if (RT_SUCCESS(rc2)) { if (RTDirExists(pszPath)) { size_t cchPath2 = strlen(pszPath); if (!RTPATH_IS_SLASH(pszPath[cchPath2 - 1])) { pszPath[cchPath2++] = RTPATH_SLASH; pszPath[cchPath2] = '\0'; } rc2 = rtDbgSymCacheAddDirWorker(pszPath, cchPath2, pDirEntry, pCfg); } } else { pszPath[cchPath + cchName] = '\0'; RTMsgError("Error constructing bundle subdir path for '%s' + '%s': %Rrc", pszPath, s_apszSubBundleDirs[i], rc); } if (RT_FAILURE(rc2) && RT_SUCCESS(rc)) rc = rc2; } } return rc; }
/** * Adds a certificate to a store. * * @returns true on success, false on failure (error message written). * @param dwDst The destination, like * CERT_SYSTEM_STORE_LOCAL_MACHINE or * CERT_SYSTEM_STORE_CURRENT_USER. * @param pszStoreNm The store name. * @param kpCertBuf Buffer that contains a certificate * @param cbCertBuf Size of @param kpCertBuf in bytes */ bool addCertToStore(DWORD dwDst, const char *pszStoreNm, const unsigned char kpCertBuf[], DWORD cbCertBuf) { /* * Get certificate from buffer. */ PCCERT_CONTEXT pSrcCtx = NULL; bool fRc = false; if (!readCertBuf(kpCertBuf, cbCertBuf, &pSrcCtx)) { RTMsgError("Unable to get certificate context: %d", GetLastError()); return fRc; } /* * Open the certificates store. */ HCERTSTORE hDstStore = openCertStore(dwDst, pszStoreNm); if (hDstStore) { /* * Finally, add certificate to store */ if (CertAddCertificateContextToStore(hDstStore, pSrcCtx, CERT_STORE_ADD_REPLACE_EXISTING, NULL)) fRc = true; else RTMsgError("Unable to install certificate: %d", GetLastError()); CertCloseStore(hDstStore, CERT_CLOSE_STORE_CHECK_FLAG); } else RTMsgError("Unable to open certificates store: %d", GetLastError()); /* Release resources */ CertFreeCertificateContext(pSrcCtx); return fRc; }
/* * Input file parsing. */ static int ParseAlias(char *pszLine, size_t& id, std::string& desc) { /* First there's a hexadeciman number. */ uint32_t uVal; char *pszNext; int rc = RTStrToUInt32Ex(pszLine, &pszNext, 16, &uVal); if ( rc == VWRN_TRAILING_CHARS || rc == VWRN_TRAILING_SPACES || rc == VINF_SUCCESS) { /* Skip the whipespace following it and at the end of the line. */ pszNext = RTStrStripL(pszNext); if (*pszNext != '\0') { rc = RTStrValidateEncoding(pszNext); if (RT_SUCCESS(rc)) { size_t cchDesc = strlen(pszNext); if (cchDesc <= USB_ID_DATABASE_MAX_STRING) { id = uVal; desc = pszNext; g_cbRawStrings += cchDesc + 1; return RTEXITCODE_SUCCESS; } RTMsgError("String to long: %zu", cchDesc); } else RTMsgError("Invalid encoding: '%s' (rc=%Rrc)", pszNext, rc); } else RTMsgError("Error parsing '%s'", pszLine); } else RTMsgError("Error converting number at the start of '%s': %Rrc", pszLine, rc); return ERROR_IN_PARSE_LINE; }
/** * Worker for rewrite_ForceNativeEol, rewrite_ForceLF and rewrite_ForceCRLF. * * @returns true if modifications were made, false if not. * @param pIn The input stream. * @param pOut The output stream. * @param pSettings The settings. * @param enmDesiredEol The desired end of line indicator type. * @param pszDesiredSvnEol The desired svn:eol-style. */ static bool rewrite_ForceEol(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings, SCMEOL enmDesiredEol, const char *pszDesiredSvnEol) { if (!pSettings->fConvertEol) return false; bool fModified = false; SCMEOL enmEol; size_t cchLine; const char *pchLine; while ((pchLine = ScmStreamGetLine(pIn, &cchLine, &enmEol)) != NULL) { if ( enmEol != enmDesiredEol && enmEol != SCMEOL_NONE) { fModified = true; enmEol = enmDesiredEol; } int rc = ScmStreamPutLine(pOut, pchLine, cchLine, enmEol); if (RT_FAILURE(rc)) return false; } if (fModified) ScmVerbose(pState, 2, " * Converted EOL markers\n"); /* Check svn:eol-style if appropriate */ if ( pSettings->fSetSvnEol && ScmSvnIsInWorkingCopy(pState)) { char *pszEol; int rc = ScmSvnQueryProperty(pState, "svn:eol-style", &pszEol); if ( (RT_SUCCESS(rc) && strcmp(pszEol, pszDesiredSvnEol)) || rc == VERR_NOT_FOUND) { if (rc == VERR_NOT_FOUND) ScmVerbose(pState, 2, " * Setting svn:eol-style to %s (missing)\n", pszDesiredSvnEol); else ScmVerbose(pState, 2, " * Setting svn:eol-style to %s (was: %s)\n", pszDesiredSvnEol, pszEol); int rc2 = ScmSvnSetProperty(pState, "svn:eol-style", pszDesiredSvnEol); if (RT_FAILURE(rc2)) RTMsgError("ScmSvnSetProperty: %Rrc\n", rc2); /** @todo propagate the error somehow... */ } if (RT_SUCCESS(rc)) RTStrFree(pszEol); } /** @todo also check the subversion svn:eol-style state! */ return fModified; }
/** * Adds a file to the manifest. * * @returns IPRT status code, failures with error message. * @param hManifest The manifest to add it to. * @param pszFilename The name of the file to add. * @param fAttr The manifest attributes to add. */ static int rtManifestAddFileToManifest(RTMANIFEST hManifest, const char *pszFilename, uint32_t fAttr) { RTVFSIOSTREAM hVfsIos; const char *pszError; int rc = RTVfsChainOpenIoStream(pszFilename, RTFILE_O_READ | RTFILE_O_DENY_WRITE | RTFILE_O_OPEN, &hVfsIos, &pszError); if (RT_FAILURE(rc)) { if (pszError && *pszError) RTMsgError("RTVfsChainOpenIoStream failed with rc=%Rrc:\n" " '%s'\n", " %*s^\n", rc, pszFilename, pszError - pszFilename, ""); else RTMsgError("Failed with %Rrc opening '%s'", rc, pszFilename); return rc; } rc = RTManifestEntryAddIoStream(hManifest, hVfsIos, pszFilename, fAttr); if (RT_FAILURE(rc)) RTMsgError("RTManifestEntryAddIoStream failed for '%s': %Rrc", rc); RTVfsIoStrmRelease(hVfsIos); return rc; }
/** * Make sure there is no svn:executable keyword on the current file. * * @returns false - the state carries these kinds of changes. * @param pState The rewriter state. * @param pIn The input stream. * @param pOut The output stream. * @param pSettings The settings. */ bool rewrite_SvnNoExecutable(PSCMRWSTATE pState, PSCMSTREAM pIn, PSCMSTREAM pOut, PCSCMSETTINGSBASE pSettings) { if ( !pSettings->fSetSvnExecutable || !ScmSvnIsInWorkingCopy(pState)) return false; int rc = ScmSvnQueryProperty(pState, "svn:executable", NULL); if (RT_SUCCESS(rc)) { ScmVerbose(pState, 2, " * removing svn:executable\n"); rc = ScmSvnDelProperty(pState, "svn:executable"); if (RT_FAILURE(rc)) RTMsgError("ScmSvnSetProperty: %Rrc\n", rc); /** @todo error propagation here.. */ } return false; }
void GluePrintErrorInfo(const com::ErrorInfo &info) { bool haveResultCode = false; #if defined (RT_OS_WIN) haveResultCode = info.isFullAvailable(); bool haveComponent = true; bool haveInterfaceID = true; #else /* defined (RT_OS_WIN) */ haveResultCode = true; bool haveComponent = info.isFullAvailable(); bool haveInterfaceID = info.isFullAvailable(); #endif Utf8Str str; RTCList<Utf8Str> comp; Bstr bstrDetailsText = info.getText(); if (!bstrDetailsText.isEmpty()) str = Utf8StrFmt("%ls\n", bstrDetailsText.raw()); if (haveResultCode) comp.append(Utf8StrFmt("code %Rhrc (0x%RX32)", info.getResultCode(), info.getResultCode())); if (haveComponent) comp.append(Utf8StrFmt("component %ls", info.getComponent().raw())); if (haveInterfaceID) comp.append(Utf8StrFmt("interface %ls", info.getInterfaceName().raw())); if (!info.getCalleeName().isEmpty()) comp.append(Utf8StrFmt("callee %ls", info.getCalleeName().raw())); if (comp.size() > 0) { str += "Details: "; for (size_t i = 0; i < comp.size() - 1; ++i) str += comp.at(i) + ", "; str += comp.last(); str += "\n"; } // print and log RTMsgError("%s", str.c_str()); Log(("ERROR: %s", str.c_str())); }
/** * Pushes the bytes from the input to the output stream, flushes the output * stream and closes both of them. * * On failure, we will delete the output file, if it's a file. The input file * may be deleted, if we're not told to keep it (--keep, --to-stdout). * * @returns RTEXITCODE_SUCCESS or RTEXITCODE_FAILURE. * @param phVfsSrc The input stream. Set to NIL if closed. * @param pOpts The options. * @param phVfsDst The output stream. Set to NIL if closed. */ static RTEXITCODE gzipPushFlushAndClose(PRTVFSIOSTREAM phVfsSrc, PCRTGZIPCMDOPTS pOpts, PRTVFSIOSTREAM phVfsDst) { /* * Push bytes, flush and close the streams. */ RTEXITCODE rcExit = gzipPush(*phVfsSrc, *phVfsDst); RTVfsIoStrmRelease(*phVfsSrc); *phVfsSrc = NIL_RTVFSIOSTREAM; int rc = RTVfsIoStrmFlush(*phVfsDst); if (RT_FAILURE(rc) && rc != VERR_INVALID_PARAMETER) rcExit = RTMsgErrorExit(RTEXITCODE_FAILURE, "Failed to flush the output file: %Rrc", rc); RTVfsIoStrmRelease(*phVfsDst); *phVfsDst = NIL_RTVFSIOSTREAM; /* * Do the cleaning up, if needed. Remove the input file, if that's the * desire of the user, or remove the output file on failure. */ if (!pOpts->fStdOut) { if (rcExit == RTEXITCODE_SUCCESS) { if (!pOpts->fKeep) { rc = RTFileDelete(pOpts->pszInput); if (RT_FAILURE(rc)) rcExit = RTMsgErrorExit(RTEXITCODE_FAILURE, "Failed to delete '%s': %Rrc", pOpts->pszInput, rc); } } else { rc = RTFileDelete(pOpts->szOutput); if (RT_FAILURE(rc)) RTMsgError("Failed to delete '%s': %Rrc", pOpts->szOutput, rc); } } return rcExit; }