/* * Utility Functions _________________________________________________________________ * */ static BOOL OnSalvage() { if (IsButtonChecked(hDlg, IDC_SERVER)) { pszPartitionName = 0; pszVolumeName = 0; } else if (IsButtonChecked(hDlg, IDC_PARTITION)) { pszPartitionName = szPartitionName; pszVolumeName = 0; } else if (IsButtonChecked(hDlg, IDC_VOLUME)) { pszPartitionName = szPartitionName; pszVolumeName = szVolumeName; } nNumProcesses = DEFAULT_NUM_PROCESSES; if (IsButtonChecked(hDlg, IDC_NUM_PROCESSES_CHECKBOX)) { nNumProcesses = _ttoi(szNumProcesses); if ((nNumProcesses < MIN_NUM_PROCESSES) || (nNumProcesses > MAX_NUM_PROCESSES)) { ShowError(hDlg, 0, IDS_INVALID_NUM_SALVAGE_PROCESSSES); return FALSE; } } if (!g_CfgData.bReuseAdminInfo) { if (!GetAdminInfo(hDlg, GAIO_LOGIN_ONLY)) return FALSE; if (!GetHandles(hDlg)) return FALSE; } return TRUE; }
QList<SmartPointer<ExtensionHandle> > RegistryObjectManager::GetExtensionsFromContributor(const QString& contributorId) const { QList<int> ids = GetExtensionsFrom(contributorId); QList<ExtensionHandle::Pointer> result; foreach(Handle::Pointer handle, GetHandles(ids, EXTENSION)) { result.push_back(handle.Cast<ExtensionHandle>()); }
static BOOL PrepareToConfig() { BOOL bMustExit = FALSE; // Use a local copy of the config info to decide what should be configured // or unconfigured. We do this so that if the user cancels for some reason, // the real config state will still be what the user expects (what was // previously read from the system plus the user's changes). CONFIG_STATE configFS = g_CfgData.configFS; // File server CONFIG_STATE configDB = g_CfgData.configDB; // Database server CONFIG_STATE configBak = g_CfgData.configBak; // Backup server CONFIG_STATE configSCS = g_CfgData.configSCS; // System Control server CONFIG_STATE configSCC = g_CfgData.configSCC; // System Control client BOOL bWorkToDo = FALSE; bWorkToDo |= PrepareToConfig(configFS, bFsRunning, bFsOn, IDC_FS_SERVICE); bWorkToDo |= PrepareToConfig(configDB, bDbRunning, bDbOn, IDC_DB_SERVICE); bWorkToDo |= PrepareToConfig(configBak, bBakRunning, bBakOn, IDC_BK_SERVICE); bWorkToDo |= PrepareToConfig(configSCS, bScsRunning, bScsOn, IDC_SCS); bWorkToDo |= PrepareToConfig(configSCC, bSccRunning, bSccOn, IDC_SCC); // If there is nothing to do, then just return TRUE. if (!bWorkToDo) return TRUE; // If we are unconfiguring the last DB server: // 1) Warn user and ask for confirmation // 2) Unconfigure all other servers that are running on this machine // 3) Tell them (after unconfiguring) that they must run the Wizard if they // wish to reconfigure the machine, then exit the program. if (configDB == CS_UNCONFIGURE) { if (g_CfgData.bLastDBServer) { int nChoice = MsgBox(hDlg, IDS_LAST_DB_SERVER, GetAppTitleID(), MB_YESNO | MB_ICONEXCLAMATION); if (nChoice == IDNO) return FALSE; // Make sure these all get unconfigured as well. If they are not configured, then // nothing bad will happen because the config calls are idempotent. configFS = CS_UNCONFIGURE; configBak = CS_UNCONFIGURE; configSCS = CS_UNCONFIGURE; configSCC = CS_UNCONFIGURE; } } // Get additional needed information from the user GET_ADMIN_INFO_OPTIONS eOptions; BOOL bDB = (ShouldConfig(configDB) || ShouldUnconfig(configDB)); // Use this as our default eOptions = GAIO_LOGIN_ONLY; // If we already have a sys control machine, then we don't need to ask for it if (ShouldConfig(configSCC)) { if (szScMachine[0] == 0) { ShowWarning(hDlg, IDS_MUST_ENTER_SCS_NAME); return FALSE; } lstrcpy(g_CfgData.szSysControlMachine, szScMachine); } else if (bDB && !g_CfgData.bLastDBServer) { // We need to know the name of the SCM machine. Are we the SCM machine? if (bScsRunning) lstrcpy(g_CfgData.szSysControlMachine, g_CfgData.szHostname); else eOptions = GAIO_GET_SCS; } // If doing a login only and the admin info is reusable if ((eOptions != GAIO_LOGIN_ONLY) || !g_CfgData.bReuseAdminInfo) { if (!GetAdminInfo(hDlg, eOptions)) return FALSE; // Use the admin info to get new handles if (!GetHandles(hDlg)) return FALSE; } // Now that we are ready to configure, copy our local config info // into the structure that the config engine uses. g_CfgData.configFS = configFS; g_CfgData.configDB = configDB; g_CfgData.configBak = configBak; g_CfgData.configSCS = configSCS; g_CfgData.configSCC = configSCC; // Configure the server BOOL bConfigSucceeded = Configure(hDlg, bMustExit); if (bConfigSucceeded) { if (bMustExit) { PostQuitMessage(0); return TRUE; } g_CfgData.bReuseAdminInfo = TRUE; } else g_CfgData.szAdminPW[0] = 0; // Get current config status BOOL bCanceled = FALSE; DWORD dwStatus = GetCurrentConfig(hDlg, bCanceled); if (dwStatus || bCanceled) { if (!bCanceled) ErrorDialog(dwStatus, IDS_CONFIG_CHECK_FAILED); } // Show the initial services config ShowInitialConfig(); ShowServiceStates(); return TRUE; }
bool Tpm2::DispatchOut(TPM_CC _command, TpmStructureBase *_req) { if (phaseTwoExpected) { throw runtime_error("A TPM command has been dispatched before the previous async-command has been processed. Call Cancel() if you need to abort"); } OutByteBuf reqBuf; StructMarshallInfo *reqInfo = NULL; vector<byte> commBuf; int handleAreaSize = 0; authHandleCount = 0; if (_req != NULL) { reqInfo = TheTypeMap.GetStructMarshallInfo(_req->GetTypeId()); handleAreaSize = reqInfo->HandleCount * 4; authHandleCount = reqInfo->AuthHandleCount; } sessions = false; numSessions = 0; sessionsTag = TPM_ST::NO_SESSIONS; vector<BYTE> sessionBuf; // AuthValues are always retrieved from the object handle. If no explicit sessions // are provided then the auth-value is retrieved for all sessions that require auth // and PWAP is used. // // If explicit sessions are provided then the explicit sessions are used (either a // session handle, or a AUTH_SESSION::PWAP(), if PWAP is desired for a handle). // If there are not enough explicit sessions, then an error is generated. int numExplicitSessions = Sessions.size(); inHandles.clear(); GetHandles(_req, reqInfo, inHandles); if (numExplicitSessions != 0) { if (authHandleCount > Sessions.size()) { throw runtime_error("Too few explicit sessions"); } } // Do we have sessions of either type? if (authHandleCount != 0 || numExplicitSessions != 0) { sessions = true; sessionsTag = TPM_ST::SESSIONS; } int commandLen; if (_req != NULL) { commBuf = _req->ToBuf(); } commandLen = 10 + commBuf.size(); if (sessions) { RollNonces(); PrepareParmEncryptionSessions(); DoParmEncryption(_req, commBuf, true); // No explicit sessions, but auth needed for one or more handles we fabricate // some PWAP sessions if (authHandleCount > 0 && numExplicitSessions == 0) { Sessions.resize(authHandleCount); for (size_t j = 0; j < authHandleCount; j++) { Sessions[j] = &PwapSession; } numExplicitSessions = authHandleCount; numSessions = authHandleCount; } // Then we can process the real or fabricated sessions numSessions = Sessions.size(); vector<BYTE> commBufNoHandles = VectorSlice(commBuf, handleAreaSize, commBuf.size() - handleAreaSize); GetAuthSessions(sessionBuf, _command, commBufNoHandles, authHandleCount, inHandles); commandLen += sessionBuf.size() + 4; } // Construct the command buffer OutByteBuf outCommand; // First the standard header outCommand << (UINT16)sessionsTag << (UINT32)commandLen << (UINT32)_command; // Add the handes (if any). outCommand.AddSlice(commBuf, 0, handleAreaSize); // Add the sessionLen + sessions (if any). if (sessions) { outCommand << (UINT32)sessionBuf.size() << sessionBuf; } // Add the rest of the command (handles already added) outCommand.AddSlice(commBuf, handleAreaSize, commBuf.size() - handleAreaSize); // Command buffer complete if ((CpHash != NULL) || AuditThisCommand ) { // Non-NULL CpHash indicates that the caller wants the CpHash, // but does not want the command invoked. OutByteBuf cpBuf; cpBuf << ToIntegral(_command); for (auto i = inHandles.begin(); i != inHandles.end(); i++) { cpBuf << (*i)->GetName(); } cpBuf.AddSlice(commBuf, handleAreaSize, commBuf.size() - handleAreaSize); if (CpHash != NULL) { CpHash->digest = CryptoServices::Hash(CpHash->hashAlg, cpBuf.GetBuf()); ClearInvocationState(); phaseTwoExpected = false; CpHash = NULL; return false; } // Else we are auditing this command LastCommandAuditCpHash.digest = CryptoServices::Hash(CommandAuditHash.hashAlg, cpBuf.GetBuf()); cout << "CpHash: " << LastCommandAuditCpHash.digest << endl; } // Tpms can be used for operations that do not directly involve the TPM: e.g. getting // a CpHash, but if we get to thhis point we really need a TPM... if (device == NULL) { throw runtime_error("No TPM device. Use _SetDevice() or the constructor that takes a TpmDevice*"); } // And send it to the TPM std::vector<BYTE>& commandBuf = outCommand.GetBuf(); vector<BYTE> tempRespBuf; device->DispatchCommand(commandBuf); lastCommandBuf = commandBuf; UpdateHandleDataCommand(_command, _req); respBuf = tempRespBuf; phaseTwoExpected = true; commandBeingProcessed = _command; return true; }
static ssize_t RecvResponse(struct NaClSrpcMessageChannel* channel, NaClSrpcRpc* rpc, NaClSrpcArg** results) { NaClSrpcArg* result_copy[NACL_SRPC_MAX_ARGS + 1]; struct NaClImcMsgIoVec iov[IOV_ENTRY_MAX]; const size_t kMaxIovLen = NACL_ARRAY_SIZE(iov); size_t iov_len = 0; NaClSrpcMessageHeader header; NaClSrpcImcDescType descs[NACL_SRPC_MAX_ARGS]; size_t expected_bytes; ssize_t retval; size_t i; if (results == NULL) { NaClSrpcLog(NACL_SRPC_LOG_ERROR, "RecvResponse: results should not be NULL\n"); retval = -NACL_ABI_EINVAL; goto done; } /* * SrpcPeekMessage should have been called before this function, and should * have populated rpc. Make sure that rpc points to a sane header. */ if (rpc->is_request || rpc->template_len > 0 || rpc->value_len > NACL_SRPC_MAX_ARGS || rpc->value_len != VectorLen(results)) { NaClSrpcLog(NACL_SRPC_LOG_ERROR, "RecvResponse: rpc header invalid: is_request %"NACL_PRIu32", " "template_len %"NACL_PRIu32", value_len %"NACL_PRIu32"\n", rpc->is_request, rpc->template_len, rpc->value_len); return -NACL_ABI_EINVAL; } /* * Having read the header we know how many elements the results vector * contains. The next peek reads the fixed portion of the results vectors, * but cannot yet read the variable length portion, because we do not yet * know the counts of array types or strings. Because the results read * could conflict with the expected types, we need to read the fixed portion * into a copy. */ if (!AllocateArgs(result_copy, rpc->value_len)) { NaClSrpcLog(NACL_SRPC_LOG_ERROR, "RecvResponse: AllocateArgs failed\n"); retval = -NACL_ABI_EINVAL; goto done; } iov_len = 0; expected_bytes = 0; AddIovEntry(rpc, kRpcSize, kMaxIovLen, iov, &iov_len, &expected_bytes); for (i = 0; i < rpc->value_len; ++i) { AddIovEntry(result_copy[i], kArgSize, kMaxIovLen, iov, &iov_len, &expected_bytes); } header.iov = iov; header.iov_length = (nacl_abi_size_t) iov_len; header.NACL_SRPC_MESSAGE_HEADER_DESCV = NULL; header.NACL_SRPC_MESSAGE_HEADER_DESC_LENGTH = 0; retval = NaClSrpcMessageChannelPeek(channel, &header); if (retval < (ssize_t) expected_bytes) { NaClSrpcLog(NACL_SRPC_LOG_ERROR, "RecvResponse: NaClSrpcMessageChannelPeek incomplete: " "expected %"NACL_PRIdS", got %"NACL_PRIdS"\n", expected_bytes, retval); retval = ErrnoFromImcRet(retval); goto done; } /* * Check that the peeked results vector's types conform to the types passed * in and that any nonfixed size arguments are no larger than the counts * passed in from the caller. If the values are acceptable, we copy the * actual sizes to the caller's vector. */ if (!CheckMatchAndCopyCounts(rpc->value_len, results, result_copy)) { NaClSrpcLog(NACL_SRPC_LOG_ERROR, "RecvResponse: CheckMatchAndCopyCounts failed\n"); retval = -NACL_ABI_EIO; goto done; } /* * After peeking the fixed portion of the results vector we are ready to * read the nonfixed portion as well. So the read just adds the IOV entries * for the nonfixed portion of results. */ iov_len = 0; expected_bytes = 0; AddIovEntry(rpc, kRpcSize, kMaxIovLen, iov, &iov_len, &expected_bytes); AddFixed(results, rpc->value_len, kMaxIovLen, iov, &iov_len, &expected_bytes); if (!AddNonfixedForRead(results, rpc->value_len, kMaxIovLen, 0, 1, iov, &iov_len, &expected_bytes)) { NaClSrpcLog(NACL_SRPC_LOG_ERROR, "RecvResponse: AddNonfixedForRead failed\n"); retval = -NACL_ABI_EIO; goto done; } header.iov = iov; header.iov_length = (nacl_abi_size_t) iov_len; header.NACL_SRPC_MESSAGE_HEADER_DESCV = descs; header.NACL_SRPC_MESSAGE_HEADER_DESC_LENGTH = NACL_ARRAY_SIZE(descs); retval = NaClSrpcMessageChannelReceive(channel, &header); if (retval < (ssize_t) expected_bytes) { NaClSrpcLog(NACL_SRPC_LOG_ERROR, "RecvResponse: NaClSrpcMessageChannelReceive incomplete: " "expected %"NACL_PRIdS", got %"NACL_PRIdS"\n", expected_bytes, retval); retval = ErrnoFromImcRet(retval); goto done; } /* * The read left any descriptors returned in the descs array. We need to * copy those descriptors to the results vector. */ if (!GetHandles(results, rpc->value_len, descs, header.NACL_SRPC_MESSAGE_HEADER_DESC_LENGTH)) { NaClSrpcLog(NACL_SRPC_LOG_ERROR, "RecvResponse: GetHandles failed\n"); retval = -NACL_ABI_EIO; } done: FreeArgs(result_copy); return retval; }
static ssize_t RecvRequest(struct NaClSrpcMessageChannel* channel, NaClSrpcRpc* rpc, NaClSrpcArg** inputs, NaClSrpcArg** results) { struct NaClImcMsgIoVec iov[IOV_ENTRY_MAX]; const size_t kMaxIovLen = NACL_ARRAY_SIZE(iov); size_t iov_len; NaClSrpcMessageHeader header; NaClSrpcImcDescType descs[NACL_SRPC_MAX_ARGS]; size_t expected_bytes; ssize_t retval; /* * SrpcPeekMessage should have been called before this function, and should * have populated rpc. Make sure that rpc points to a sane header. */ if (!rpc->is_request || rpc->template_len > NACL_SRPC_MAX_ARGS || rpc->value_len > NACL_SRPC_MAX_ARGS) { NaClSrpcLog(NACL_SRPC_LOG_ERROR, "RecvRequest: rpc header invalid: is_request %"NACL_PRIu32", " "template_len %"NACL_PRIu32", value_len %"NACL_PRIu32"\n", rpc->is_request, rpc->template_len, rpc->value_len); retval = -NACL_ABI_EINVAL; goto done; } /* * A request will contain two vectors of NaClSrpcArgs. Set the index * pointers passed in to new argument vectors that will be filled during * the next peek. */ if (!AllocateArgs(results, rpc->template_len) || !AllocateArgs(inputs, rpc->value_len)) { NaClSrpcLog(NACL_SRPC_LOG_ERROR, "RecvRequest: AllocateArgs failed\n"); retval = -NACL_ABI_EINVAL; goto done; } /* * Having read the header we know how many elements each argument vector * contains. The next peek reads the fixed portion of these argument vectors, * but cannot yet read the variable length portion, because we do not yet * know the counts of array types or strings. */ iov_len = 0; expected_bytes = 0; AddIovEntry(rpc, kRpcSize, kMaxIovLen, iov, &iov_len, &expected_bytes); AddFixed(results, rpc->template_len, kMaxIovLen, iov, &iov_len, &expected_bytes); AddFixed(inputs, rpc->value_len, kMaxIovLen, iov, &iov_len, &expected_bytes); header.iov = iov; header.iov_length = (nacl_abi_size_t) iov_len; header.NACL_SRPC_MESSAGE_HEADER_DESCV = NULL; header.NACL_SRPC_MESSAGE_HEADER_DESC_LENGTH = 0; retval = NaClSrpcMessageChannelPeek(channel, &header); if (retval < (ssize_t) expected_bytes) { NaClSrpcLog(NACL_SRPC_LOG_ERROR, "RecvRequest:" "NaClSrpcMessageChannelPeek incomplete: expected %" NACL_PRIdS", got %"NACL_PRIdS"\n", expected_bytes, retval); retval = ErrnoFromImcRet(retval); goto done; } /* * After peeking the fixed portion of the argument vectors we are ready to * read the nonfixed portions as well. So the read just adds the IOV entries * for the nonfixed portions of the arguments. */ iov_len = 0; expected_bytes = 0; AddIovEntry(rpc, kRpcSize, kMaxIovLen, iov, &iov_len, &expected_bytes); ClearTemplateStringLengths(results, rpc->template_len); AddFixed(results, rpc->template_len, kMaxIovLen, iov, &iov_len, &expected_bytes); AddFixed(inputs, rpc->value_len, kMaxIovLen, iov, &iov_len, &expected_bytes); if (!AddNonfixedForRead(results, rpc->template_len, kMaxIovLen, 1, 0, iov, &iov_len, &expected_bytes)) { NaClSrpcLog(NACL_SRPC_LOG_ERROR, "RecvRequest: AllocateArgs failed for results\n"); retval = -NACL_ABI_EIO; goto done; } if (!AddNonfixedForRead(inputs, rpc->value_len, kMaxIovLen, 1, 1, iov, &iov_len, &expected_bytes)) { NaClSrpcLog(NACL_SRPC_LOG_ERROR, "RecvRequest: AllocateArgs failed for inputs\n"); retval = -NACL_ABI_EIO; goto done; } header.iov = iov; header.iov_length = (nacl_abi_size_t) iov_len; header.NACL_SRPC_MESSAGE_HEADER_DESCV = descs; header.NACL_SRPC_MESSAGE_HEADER_DESC_LENGTH = NACL_ARRAY_SIZE(descs); retval = NaClSrpcMessageChannelReceive(channel, &header); if (retval < (ssize_t) expected_bytes) { NaClSrpcLog(NACL_SRPC_LOG_ERROR, "RecvRequest:" " NaClSrpcMessageChannelReceive incomplete: expected %" NACL_PRIdS", got %"NACL_PRIdS"\n", expected_bytes, retval); retval = ErrnoFromImcRet(retval); goto done; } /* * The read left any descriptors passed in the descs array. We need to * copy those descriptors to the inputs vector. */ if (!GetHandles(inputs, rpc->value_len, descs, header.NACL_SRPC_MESSAGE_HEADER_DESC_LENGTH)) { NaClSrpcLog(NACL_SRPC_LOG_ERROR, "RecvRequest: GetHandles failed\n"); retval = -NACL_ABI_EIO; goto done; } /* * Success, the caller has taken ownership of the memory we allocated * for inputs and results. */ inputs = NULL; results = NULL; done: FreeArgs(inputs); FreeArgs(results); return retval; }