//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ int __cdecl CP_printfCreate( char * szTitle ){ x_CmdWnd.Create(szTitle, TRUE); x_CmdWnd.Color( x_awDebugColors[LEVEL_NORMAL] ); x_CmdWnd.Clear(); return 0; }
void CConsole::ConToggleStroke(IConsole::IResult *pResult, void *pUser) { CConsole* pConsole = static_cast<CConsole *>(pUser); char aBuf[128] = {0}; CCommand *pCommand = pConsole->FindCommand(pResult->GetString(1), pConsole->m_FlagMask); if(pCommand) { FCommandCallback pfnCallback = pCommand->m_pfnCallback; // check for chain if(pCommand->m_pfnCallback == Con_Chain) { CChain *pChainInfo = static_cast<CChain *>(pCommand->m_pUserData); pfnCallback = pChainInfo->m_pfnCallback; } if(pfnCallback == IntVariableCommand) { int Val = pResult->GetInteger(0)==0 ? pResult->GetInteger(3) : pResult->GetInteger(2); str_format(aBuf, sizeof(aBuf), "%s %i", pResult->GetString(1), Val); pConsole->ExecuteLine(aBuf); aBuf[0] = 0; } else str_format(aBuf, sizeof(aBuf), "Invalid command: '%s'.", pResult->GetString(1)); } else str_format(aBuf, sizeof(aBuf), "No such command: '%s'.", pResult->GetString(1)); if(aBuf[0] != 0) pConsole->Print(OUTPUT_LEVEL_STANDARD, "Console", aBuf); }
BOOL WINAPI HandlerRoutine(DWORD dwCtrlType) { switch(dwCtrlType) { case CTRL_C_EVENT: case CTRL_BREAK_EVENT: if (blnCommandExecutionInProgress) { /* Beep(1000,100); Beep(2000,100); Beep(3000,100); Beep(4000,100); Beep(5000,100); Beep(4000,100); Beep(3000,100); Beep(2000,100); Beep(1000,100);*/ Console.Write(_T("\n")); Console.DisableWrite(); } return TRUE; default: return FALSE; } }
int CShellCommandChangeKey::Execute(CConsole &rConsole, CArgumentParser& rArguments) { BOOL blnHelp = FALSE; rArguments.ResetArgumentIteration(); const TCHAR *pchCommandItself = rArguments.GetNextArgument(); const TCHAR *pchPath = rArguments.GetNextArgument(); if ((_tcsnicmp(pchCommandItself,CD_CMD _T(".."),CD_CMD_LENGTH+2*sizeof(TCHAR)) == 0)|| (_tcsnicmp(pchCommandItself,CD_CMD _T("\\"),CD_CMD_LENGTH+1*sizeof(TCHAR)) == 0)) { if (!pchPath) pchPath = pchCommandItself + CD_CMD_LENGTH; else blnHelp = TRUE; } if ((!blnHelp)&&(pchPath != NULL)&&(!rArguments.GetNextArgument())) { size_t size = _tcslen(pchPath); ASSERT(size <= PROMPT_BUFFER_SIZE); if (!m_rTree.ChangeCurrentKey(pchPath)) { rConsole.Write(m_rTree.GetLastErrorDescription()); rConsole.Write(_T("\n")); } } else { rConsole.Write(GetHelpString()); } return 0; }
void CConsole::ConModCommandStatus(IResult *pResult, void *pUser) { CConsole* pConsole = static_cast<CConsole *>(pUser); char aBuf[240]; mem_zero(aBuf, sizeof(aBuf)); int Used = 0; for(CCommand *pCommand = pConsole->m_pFirstCommand; pCommand; pCommand = pCommand->m_pNext) { if(pCommand->m_Flags&pConsole->m_FlagMask && pCommand->GetAccessLevel() == ACCESS_LEVEL_MOD) { int Length = str_length(pCommand->m_pName); if(Used + Length + 2 < (int)(sizeof(aBuf))) { if(Used > 0) { Used += 2; str_append(aBuf, ", ", sizeof(aBuf)); } str_append(aBuf, pCommand->m_pName, sizeof(aBuf)); Used += Length; } else { pConsole->Print(OUTPUT_LEVEL_STANDARD, "Console", aBuf); mem_zero(aBuf, sizeof(aBuf)); str_copy(aBuf, pCommand->m_pName, sizeof(aBuf)); Used = Length; } } } if(Used > 0) pConsole->Print(OUTPUT_LEVEL_STANDARD, "Console", aBuf); }
void CApplication::CloseConsole() { if (!Get()) return; CConsole* pConsole = Get()->GetConsole(); pConsole->SetVisible(false); }
bool CApplication::IsConsoleOpen() { if (!Get()) return false; CConsole* pConsole = Get()->GetConsole(); return pConsole->IsOpen(); }
void CCore::ApplyConsoleSettings ( void ) { CVector2D vec; CConsole * pConsole = m_pLocalGUI->GetConsole (); CVARS_GET ( "console_pos", vec ); pConsole->SetPosition ( vec ); CVARS_GET ( "console_size", vec ); pConsole->SetSize ( vec ); }
void CConsole::ConModCommandAccess(IResult *pResult, void *pUser) { CConsole* pConsole = static_cast<CConsole *>(pUser); char aBuf[128]; CCommand *pCommand = pConsole->FindCommand(pResult->GetString(0), CFGFLAG_SERVER); if(pCommand) { if(pResult->NumArguments() == 2) { pCommand->SetAccessLevel(pResult->GetInteger(1) == 0 ? ACCESS_LEVEL_USER : pResult->GetInteger(1) == 1 ? ACCESS_LEVEL_HELPER : pResult->GetInteger(1) == 2 ? ACCESS_LEVEL_MOD : pResult->GetInteger(1) == 3 ? ACCESS_LEVEL_SUBADMIN : ACCESS_LEVEL_ADMIN); str_format(aBuf, sizeof(aBuf), "subadmin access for '%s' is now %s", pResult->GetString(0), pCommand->GetAccessLevel() ? "enabled" : "disabled"); pConsole->Print(OUTPUT_LEVEL_STANDARD, "Console", aBuf); str_format(aBuf, sizeof(aBuf), "moderator access for '%s' is now %s", pResult->GetString(0), pCommand->GetAccessLevel() >= ACCESS_LEVEL_MOD ? "enabled" : "disabled"); pConsole->Print(OUTPUT_LEVEL_STANDARD, "Console", aBuf); str_format(aBuf, sizeof(aBuf), "helper access for '%s' is now %s", pResult->GetString(0), pCommand->GetAccessLevel() >= ACCESS_LEVEL_HELPER ? "enabled" : "disabled"); pConsole->Print(OUTPUT_LEVEL_STANDARD, "Console", aBuf); str_format(aBuf, sizeof(aBuf), "user access for '%s' is now %s", pResult->GetString(0), pCommand->GetAccessLevel() >= ACCESS_LEVEL_USER ? "enabled" : "disabled"); } else { str_format(aBuf, sizeof(aBuf), "subadmin access for '%s' is %s", pResult->GetString(0), pCommand->GetAccessLevel() ? "enabled" : "disabled"); pConsole->Print(OUTPUT_LEVEL_STANDARD, "Console", aBuf); str_format(aBuf, sizeof(aBuf), "moderator access for '%s' is %s", pResult->GetString(0), pCommand->GetAccessLevel() >= ACCESS_LEVEL_MOD ? "enabled" : "disabled"); pConsole->Print(OUTPUT_LEVEL_STANDARD, "Console", aBuf); str_format(aBuf, sizeof(aBuf), "helper access for '%s' is %s", pResult->GetString(0), pCommand->GetAccessLevel() >= ACCESS_LEVEL_HELPER ? "enabled" : "disabled"); pConsole->Print(OUTPUT_LEVEL_STANDARD, "Console", aBuf); str_format(aBuf, sizeof(aBuf), "user access for '%s' is %s", pResult->GetString(0), pCommand->GetAccessLevel() >= ACCESS_LEVEL_USER ? "enabled" : "disabled"); } } else str_format(aBuf, sizeof(aBuf), "No such command: '%s'.", pResult->GetString(0)); pConsole->Print(OUTPUT_LEVEL_STANDARD, "Console", aBuf); }
void CApplication::OpenConsole() { if (!Get()) return; CConsole* pConsole = Get()->GetConsole(); pConsole->Layout(); pConsole->SetVisible(true); glgui::CRootPanel::Get()->MoveToTop(pConsole); }
void CConsole::ConUserCommandStatus(IResult *pResult, void *pUser) { CConsole* pConsole = static_cast<CConsole *>(pUser); CResult Result; Result.m_pCommand = "access_status"; char aBuf[4]; str_format(aBuf, sizeof(aBuf), "%d", IConsole::ACCESS_LEVEL_USER); Result.AddArgument(aBuf); pConsole->ConCommandStatus(&Result, pConsole); }
void CmdCommandList_f() { gConsole.Output("Full command list:"); for (int i=0;i<gConsole.m_CommandList.Size();i++) { if ( gConsole.m_CommandList[i]->IsCommand() ) { gConsole.Output(" %s", gConsole.m_CommandList[i]->GetName() ); } } }
void CmdCvarList_f() { gConsole.Output("Full CVar list:"); for (int i=0;i<gConsole.m_CommandList.Size();i++) { if ( !gConsole.m_CommandList[i]->IsCommand() ) { gConsole.Output(" %s = %s", ((CVar*)gConsole.m_CommandList[i])->GetName(), ((CVar*)gConsole.m_CommandList[i])->GetString() ); } } }
void UIConsoleEventHandler::cleanup() { /* Get console: */ const CConsole console = m_pSession->session().GetConsole(); if (console.isNull() || !console.isOk()) return; /* Get event-source: */ CEventSource eventSource = console.GetEventSource(); AssertReturnVoid(!eventSource.isNull() || eventSource.isOk()); /* Unregister listener: */ eventSource.UnregisterListener(m_mainEventListener); }
void VBoxSnapshotsWgt::sltRestoreSnapshot(bool fSuppressNonCriticalWarnings /* = false*/) { /* Get currently chosen item: */ SnapshotWgtItem *pItem = mTreeWidget->currentItem() ? static_cast<SnapshotWgtItem*>(mTreeWidget->currentItem()) : 0; AssertReturn(pItem, (void)0); /* Detemine snapshot id: */ QString strSnapshotId = pItem->snapshotId(); AssertReturn(!strSnapshotId.isNull(), (void)0); /* Get currently desired snapshot: */ CSnapshot snapshot = mMachine.FindSnapshot(strSnapshotId); /* Ask the user if he really wants to restore the snapshot: */ int iResultCode = AlertButton_Ok; if (!fSuppressNonCriticalWarnings || mMachine.GetCurrentStateModified()) { iResultCode = msgCenter().confirmSnapshotRestoring(snapshot.GetName(), mMachine.GetCurrentStateModified()); if (iResultCode & AlertButton_Cancel) return; } /* If user also confirmed new snapshot creation: */ if (iResultCode & AlertOption_CheckBox) { /* Take snapshot of changed current state: */ mTreeWidget->setCurrentItem(curStateItem()); if (!takeSnapshot()) return; } /* Open a direct session (this call will handle all errors): */ CSession session = vboxGlobal().openSession(mMachineId); if (session.isNull()) return; /* Restore chosen snapshot: */ CConsole console = session.GetConsole(); CProgress progress = console.RestoreSnapshot(snapshot); if (console.isOk()) { msgCenter().showModalProgressDialog(progress, mMachine.GetName(), ":/progress_snapshot_restore_90px.png"); if (progress.GetResultCode() != 0) msgCenter().cannotRestoreSnapshot(progress, snapshot.GetName(), mMachine.GetName()); } else msgCenter().cannotRestoreSnapshot(console, snapshot.GetName(), mMachine.GetName()); /* Unlock machine finally: */ session.UnlockMachine(); }
void VBoxSnapshotsWgt::sltDeleteSnapshot() { SnapshotWgtItem *item = !mTreeWidget->currentItem() ? 0 : static_cast <SnapshotWgtItem*> (mTreeWidget->currentItem()); AssertReturn (item, (void) 0); QString snapId = item->snapshotId(); AssertReturn (!snapId.isNull(), (void) 0); CSnapshot snapshot = mMachine.FindSnapshot(snapId); if (!msgCenter().confirmSnapshotRemoval(snapshot.GetName())) return; /** @todo check available space on the target filesystem etc etc. */ #if 0 if (!msgCenter().warnAboutSnapshotRemovalFreeSpace(snapshot.GetName(), "/home/juser/.VirtualBox/Machines/SampleVM/Snapshots/{01020304-0102-0102-0102-010203040506}.vdi", "59 GiB", "15 GiB")) return; #endif /* Open a direct session (this call will handle all errors) */ bool busy = mSessionState != KSessionState_Unlocked; CSession session; if (busy) session = vboxGlobal().openExistingSession(mMachineId); else session = vboxGlobal().openSession(mMachineId); if (session.isNull()) return; CConsole console = session.GetConsole(); CProgress progress = console.DeleteSnapshot (snapId); if (console.isOk()) { /* Show the progress dialog */ msgCenter().showModalProgressDialog(progress, mMachine.GetName(), ":/progress_snapshot_discard_90px.png"); if (progress.GetResultCode() != 0) msgCenter().cannotRemoveSnapshot(progress, snapshot.GetName(), mMachine.GetName()); } else msgCenter().cannotRemoveSnapshot(console, snapshot.GetName(), mMachine.GetName()); session.UnlockMachine(); }
int __cdecl CP_vprintf( int iDebugLevel, const char *format, va_list args) { int iRet; if( (iDebugLevel < DEBUG_THRESHOLD) || (iDebugLevel < 0) || (iDebugLevel >= N_PRINT_LEVELS)) return 0; iRet = _vsnprintf( x_szTmp, MAX_STR_LEN, format, args); // Did some error, but not buffer overflow occur? if( (iRet < 0) && (iRet != -1) ) { return iRet; } // Set text color x_CmdWnd.Color( x_awDebugColors[iDebugLevel] ); x_CmdWnd.Output(x_szTmp); // strcat( g_szLogBuffer, x_szTmp ); // add to the log string return iRet; }
void CConsole::ConModCommandAccess(IResult *pResult, void *pUser) { CConsole* pConsole = static_cast<CConsole *>(pUser); char aBuf[128]; CCommand *pCommand = pConsole->FindCommand(pResult->GetString(0), CFGFLAG_SERVER); if(pCommand) { if(pResult->NumArguments() == 2) { pCommand->m_AccessLevel = clamp(pResult->GetInteger(1), (int)(ACCESS_LEVEL_ADMIN), (int)(ACCESS_LEVEL_MOD)); str_format(aBuf, sizeof(aBuf), "moderator access for '%s' is now %s", pResult->GetString(0), pCommand->m_AccessLevel ? "enabled" : "disabled"); } else str_format(aBuf, sizeof(aBuf), "moderator access for '%s' is %s", pResult->GetString(0), pCommand->m_AccessLevel ? "enabled" : "disabled"); } else str_format(aBuf, sizeof(aBuf), "No such command: '%s'.", pResult->GetString(0)); pConsole->Print(OUTPUT_LEVEL_STANDARD, "Console", aBuf); }
void CPrompt::ShowPrompt(CConsole &rConsole) { TCHAR *pch = m_pszPrompt; TCHAR Buffer[2] = " "; const TCHAR *pszCurrentPath; while (*pch) { if (_tcsncmp(pch,CURRENT_PATH_ALIAS,_tcslen(CURRENT_PATH_ALIAS)) == 0) { pszCurrentPath = m_rTree.GetCurrentPath(); rConsole.Write(pszCurrentPath?pszCurrentPath:_T("NULL (Internal Error)")); pch += _tcslen(CURRENT_PATH_ALIAS); } else { Buffer[0] = *pch++; rConsole.Write(Buffer); } } }
bool CConsole::ConToggle(IConsole::IResult *pResult, void *pUser) { CConsole* pConsole = static_cast<CConsole *>(pUser); char aBuf[128] = {0}; CCommand *pCommand = pConsole->FindCommand(pResult->GetString(0), pConsole->m_FlagMask); if(pCommand) { FCommandCallback pfnCallback = pCommand->m_pfnCallback; void *pUserData = pCommand->m_pUserData; // check for chain if(pCommand->m_pfnCallback == Con_Chain) { CChain *pChainInfo = static_cast<CChain *>(pCommand->m_pUserData); pfnCallback = pChainInfo->m_pfnCallback; pUserData = pChainInfo->m_pCallbackUserData; } if(pfnCallback == IntVariableCommand) { CIntVariableData *pData = static_cast<CIntVariableData *>(pUserData); int Val = *(pData->m_pVariable)==pResult->GetInteger(1) ? pResult->GetInteger(2) : pResult->GetInteger(1); str_format(aBuf, sizeof(aBuf), "%s %i", pResult->GetString(0), Val); pConsole->ExecuteLine(aBuf, -1, false); aBuf[0] = 0; } else str_format(aBuf, sizeof(aBuf), "Invalid command: '%s'.", pResult->GetString(0)); } else str_format(aBuf, sizeof(aBuf), "No such command: '%s'.", pResult->GetString(0)); if(aBuf[0] != 0) pConsole->Print(OUTPUT_LEVEL_STANDARD, "Console", aBuf); return true; }
int CShellCommandConnect::Execute(CConsole &rConsole, CArgumentParser& rArguments) { const TCHAR *pchArg; const TCHAR *pchMachine = NULL; BOOL blnHelp = FALSE; VERIFY(m_rTree.ChangeCurrentKey(_T("\\"))); while ((pchArg = rArguments.GetNextArgument()) != NULL) { if ((_tcsicmp(pchArg,_T("/?")) == 0) ||(_tcsicmp(pchArg,_T("-?")) == 0)) { blnHelp = TRUE; } // else if ((_tcsicmp(pchArg,_T("-a")) == 0)|| // (_tcsicmp(pchArg,_T("/a")) == 0)) // { // } else { pchMachine = pchArg; } } if (blnHelp) rConsole.Write(GetHelpString()); if (!m_rTree.SetMachineName(pchMachine)) { rConsole.Write(m_rTree.GetLastErrorDescription()); rConsole.Write(_T("\n")); } return 0; }
void CmdExec_f() { if ( gConsole.GetArgumentCount() < 2 ) return; std::ifstream file( gConsole.GetArgument(1), ios::in ); if ( !file.is_open() ) { gConsole.Output("Unable to exec '%s'", gConsole.GetArgument(1) ); return; } std::string str((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>()); gConsole.AddCommand("\n"); gConsole.AddCommand( (char*)str.c_str()); gConsole.AddCommand("\n"); file.close(); }
int CShellCommandDeleteValue::Execute(CConsole &rConsole, CArgumentParser& rArguments) { rArguments.ResetArgumentIteration(); TCHAR *pszCommandItself = rArguments.GetNextArgument(); TCHAR *pszParameter; TCHAR *pszValueFull = NULL; BOOL blnHelp = FALSE; if ((_tcsnicmp(pszCommandItself,DV_CMD _T(".."),DV_CMD_LENGTH+2*sizeof(TCHAR)) == 0)|| (_tcsnicmp(pszCommandItself,DV_CMD _T("\\"),DV_CMD_LENGTH+1*sizeof(TCHAR)) == 0)) { pszValueFull = pszCommandItself + DV_CMD_LENGTH; } else if (_tcsnicmp(pszCommandItself,DV_CMD _T("/"),DV_CMD_LENGTH+1*sizeof(TCHAR)) == 0) { pszParameter = pszCommandItself + DV_CMD_LENGTH; goto CheckValueArgument; } while((pszParameter = rArguments.GetNextArgument()) != NULL) { CheckValueArgument: if ((_tcsicmp(pszParameter,_T("/?")) == 0) ||(_tcsicmp(pszParameter,_T("-?")) == 0)) { blnHelp = TRUE; break; } else if (!pszValueFull) { pszValueFull = pszParameter; } else { rConsole.Write(_T("Bad parameter: ")); rConsole.Write(pszParameter); rConsole.Write(_T("\n")); } } CRegistryKey Key; TCHAR *pszValueNamePattern; const TCHAR *pszEmpty = _T(""); const TCHAR *pszPath; if (blnHelp) { rConsole.Write(GetHelpString()); return 0; } if (pszValueFull) { if (_tcscmp(pszValueFull,_T("\\")) == 0) goto CommandNAonRoot; TCHAR *pchSep = _tcsrchr(pszValueFull,_T('\\')); pszValueNamePattern = pchSep?(pchSep+1):(pszValueFull); pszPath = pchSep?pszValueFull:_T("."); if (pchSep) *pchSep = 0; } else { pszValueNamePattern = (TCHAR*)pszEmpty; pszPath = _T("."); } { size_t s = _tcslen(pszValueNamePattern); if (s && (pszValueNamePattern[0] == _T('\"'))&&(pszValueNamePattern[s-1] == _T('\"'))) { pszValueNamePattern[s-1] = 0; pszValueNamePattern++; } } if (!m_rTree.GetKey(pszPath,KEY_QUERY_VALUE|KEY_SET_VALUE,Key)) { rConsole.Write(m_rTree.GetLastErrorDescription()); return 0; } if (!Key.IsRoot()) { // not root key ??? TCHAR Buffer[254]; DWORD dwMaxValueNameLength; LONG nError = Key.GetMaxValueNameLength(dwMaxValueNameLength); if (nError != ERROR_SUCCESS) { _stprintf(Buffer,_T("Cannot query info about %s key. Error is %u\n"),Key.GetKeyName(),(unsigned int)nError); rConsole.Write(Buffer); return 0; } TCHAR *pszValueName = new (std::nothrow) TCHAR[dwMaxValueNameLength]; if (!pszValueName) { rConsole.Write("Out of memory."); return 0; } Key.InitValueEnumeration(pszValueName,dwMaxValueNameLength,NULL,0,NULL); while ((nError = Key.GetNextValue()) == ERROR_SUCCESS) { if (PatternMatch(pszValueNamePattern,pszValueName)) { nError = Key.DeleteValue(pszValueName); if (nError != ERROR_SUCCESS) { _stprintf(Buffer,_T("Cannot delete value. Error is %u\n"),(unsigned int)nError); rConsole.Write(Buffer); } else { InvalidateCompletion(); } Key.InitValueEnumeration(pszValueName,dwMaxValueNameLength,NULL,0,NULL); // reset iteration } } } // if (pKey) else { CommandNAonRoot: rConsole.Write(DV_CMD COMMAND_NA_ON_ROOT); } return 0; }
int CShellCommandOwner::Execute(CConsole &rConsole, CArgumentParser& rArguments) { const TCHAR *pchKey = NULL; BOOL blnDo = TRUE; BOOL blnBadParameter = FALSE; BOOL blnHelp = FALSE; const TCHAR *pchParameter; DWORD dwError; rArguments.ResetArgumentIteration(); const TCHAR *pchCommandItself = rArguments.GetNextArgument(); if ((_tcsnicmp(pchCommandItself,OWNER_CMD _T(".."),OWNER_CMD_LENGTH+2*sizeof(TCHAR)) == 0)|| (_tcsnicmp(pchCommandItself,OWNER_CMD _T("\\"),OWNER_CMD_LENGTH+1*sizeof(TCHAR)) == 0)) { pchKey = pchCommandItself + OWNER_CMD_LENGTH; } else if (_tcsnicmp(pchCommandItself,OWNER_CMD _T("/"),OWNER_CMD_LENGTH+1*sizeof(TCHAR)) == 0) { pchParameter = pchCommandItself + OWNER_CMD_LENGTH; goto CheckOwnerArgument; } while((pchParameter = rArguments.GetNextArgument()) != NULL) { CheckOwnerArgument: blnBadParameter = FALSE; if ((_tcsicmp(pchParameter,_T("/?")) == 0) ||(_tcsicmp(pchParameter,_T("-?")) == 0)) { blnHelp = TRUE; blnDo = pchKey != NULL; } else if (!pchKey) { pchKey = pchParameter; blnDo = TRUE; } else { blnBadParameter = TRUE; } if (blnBadParameter) { rConsole.Write(_T("Bad parameter: ")); rConsole.Write(pchParameter); rConsole.Write(_T("\n")); } } CRegistryKey Key; if (!m_rTree.GetKey(pchKey?pchKey:_T("."),KEY_QUERY_VALUE|READ_CONTROL,Key)) { rConsole.Write(m_rTree.GetLastErrorDescription()); blnDo = FALSE; } if (blnHelp) { rConsole.Write(GetHelpString()); } if (blnDo&&blnHelp) rConsole.Write(_T("\n")); if (!blnDo) return 0; if (Key.IsRoot()) { // root key rConsole.Write(OWNER_CMD COMMAND_NA_ON_ROOT); return 0; } PISECURITY_DESCRIPTOR pSecurityDescriptor = NULL; TCHAR *pchName = NULL, *pchDomainName = NULL; try { DWORD dwSecurityDescriptorLength; rConsole.Write(_T("Key : ")); rConsole.Write(_T("\\")); rConsole.Write(Key.GetKeyName()); rConsole.Write(_T("\n")); dwError = Key.GetSecurityDescriptorLength(&dwSecurityDescriptorLength); if (dwError != ERROR_SUCCESS) throw dwError; pSecurityDescriptor = (PISECURITY_DESCRIPTOR) new unsigned char [dwSecurityDescriptorLength]; DWORD dwSecurityDescriptorLength1 = dwSecurityDescriptorLength; dwError = Key.GetSecurityDescriptor((SECURITY_INFORMATION)OWNER_SECURITY_INFORMATION,pSecurityDescriptor,&dwSecurityDescriptorLength1); if (dwError != ERROR_SUCCESS) throw dwError; PSID psidOwner; BOOL blnOwnerDefaulted; if (!GetSecurityDescriptorOwner(pSecurityDescriptor,&psidOwner,&blnOwnerDefaulted)) throw GetLastError(); if (psidOwner == NULL) { rConsole.Write(_T("Key has no owner.")); } else { if (!IsValidSid(psidOwner)) { rConsole.Write(_T("Key has invalid owner SID.")); } else { rConsole.Write(_T("Key Owner: \n")); DWORD dwSIDStringSize = 0; BOOL blnRet = GetTextualSid(psidOwner,NULL,&dwSIDStringSize); ASSERT(!blnRet); ASSERT(GetLastError() == ERROR_INSUFFICIENT_BUFFER); TCHAR *pchSID = new TCHAR[dwSIDStringSize]; if(!GetTextualSid(psidOwner,pchSID,&dwSIDStringSize)) { dwError = GetLastError(); ASSERT(dwError != ERROR_INSUFFICIENT_BUFFER); rConsole.Write(_T("Error ")); TCHAR Buffer[256]; rConsole.Write(_itoa(dwError,Buffer,10)); rConsole.Write(_T("\nGetting string representation of SID\n")); } else { rConsole.Write(_T("\tSID: ")); rConsole.Write(pchSID); rConsole.Write(_T("\n")); } delete [] pchSID; DWORD dwNameBufferLength, dwDomainNameBufferLength; dwNameBufferLength = 1024; dwDomainNameBufferLength = 1024; pchName = new TCHAR [dwNameBufferLength]; pchDomainName = new TCHAR [dwDomainNameBufferLength]; DWORD dwNameLength = dwNameBufferLength, dwDomainNameLength = dwDomainNameBufferLength; SID_NAME_USE Use; if (!LookupAccountSid(NULL,psidOwner,pchName,&dwNameLength,pchDomainName,&dwDomainNameLength,&Use)) throw GetLastError(); else { rConsole.Write(_T("\tOwner Domain: ")); rConsole.Write(pchDomainName); rConsole.Write(_T("\n")); rConsole.Write(_T("\tOwner Name: ")); rConsole.Write(pchName); rConsole.Write(_T("\n\tSID type: ")); rConsole.Write(GetSidTypeName(Use)); rConsole.Write(_T("\n")); rConsole.Write(_T("\tOwner defaulted: ")); rConsole.Write(blnOwnerDefaulted?_T("Yes"):_T("No")); rConsole.Write(_T("\n")); } delete [] pchName; pchName = NULL; delete [] pchDomainName; pchDomainName = NULL; } } delete [] pSecurityDescriptor; } catch (DWORD dwError) { rConsole.Write(_T("Error ")); TCHAR Buffer[256]; rConsole.Write(_itoa(dwError,Buffer,10)); rConsole.Write(_T("\n")); if (pchName) delete [] pchName; if (pchDomainName) delete [] pchDomainName; if (pSecurityDescriptor) delete [] pSecurityDescriptor; } return 0; }
bool VBoxSnapshotsWgt::takeSnapshot() { /* Prepare result: */ bool fIsValid = true; /* Get currently chosen item: */ SnapshotWgtItem *pItem = mTreeWidget->currentItem() ? static_cast<SnapshotWgtItem*>(mTreeWidget->currentItem()) : 0; AssertReturn(pItem, (bool)0); /* Open a session to work with corresponding VM: */ CSession session; if (mSessionState != KSessionState_Unlocked) session = vboxGlobal().openExistingSession(mMachineId); else session = vboxGlobal().openSession(mMachineId); fIsValid = !session.isNull(); if (fIsValid) { /* Get corresponding console object also: */ CConsole console = session.GetConsole(); /* Remember runtime state: */ bool fAtRuntime = mMachine.GetState() == KMachineState_Running; /* Remember paused state: */ bool fWasPaused = mMachine.GetState() == KMachineState_Paused || mMachine.GetState() == KMachineState_TeleportingPausedVM; /* Pause VM if necessary: */ if (fIsValid && fAtRuntime && !fWasPaused) { /* Pausing VM: */ console.Pause(); if (!console.isOk()) { msgCenter().cannotPauseMachine(console); fIsValid = false; } } if (fIsValid) { /* Create take-snapshot dialog: */ QWidget *pDlgParent = windowManager().realParentWindow(this); QPointer<VBoxTakeSnapshotDlg> pDlg = new VBoxTakeSnapshotDlg(pDlgParent, mMachine); windowManager().registerNewParent(pDlg, pDlgParent); /* Assign corresponding icon: */ pDlg->mLbIcon->setPixmap(vboxGlobal().vmGuestOSTypeIcon(mMachine.GetOSTypeId())); /* Search for the max available snapshot index: */ int iMaxSnapShotIndex = 0; QString snapShotName = tr("Snapshot %1"); QRegExp regExp(QString("^") + snapShotName.arg("([0-9]+)") + QString("$")); QTreeWidgetItemIterator iterator(mTreeWidget); while (*iterator) { QString snapShot = static_cast<SnapshotWgtItem*>(*iterator)->text(0); int pos = regExp.indexIn(snapShot); if (pos != -1) iMaxSnapShotIndex = regExp.cap(1).toInt() > iMaxSnapShotIndex ? regExp.cap(1).toInt() : iMaxSnapShotIndex; ++iterator; } pDlg->mLeName->setText(snapShotName.arg(iMaxSnapShotIndex + 1)); /* Exec the dialog: */ bool fDialogAccepted = pDlg->exec() == QDialog::Accepted; /* Is the dialog still valid? */ if (pDlg) { /* Acquire variables: */ QString strSnapshotName = pDlg->mLeName->text().trimmed(); QString strSnapshotDescription = pDlg->mTeDescription->toPlainText(); /* Destroy dialog early: */ delete pDlg; /* Was the dialog accepted? */ if (fDialogAccepted) { /* Prepare the take-snapshot progress: */ CProgress progress = console.TakeSnapshot(strSnapshotName, strSnapshotDescription); if (console.isOk()) { /* Show the take-snapshot progress: */ msgCenter().showModalProgressDialog(progress, mMachine.GetName(), ":/progress_snapshot_create_90px.png"); if (!progress.isOk() || progress.GetResultCode() != 0) { msgCenter().cannotTakeSnapshot(progress, mMachine.GetName()); fIsValid = false; } } else { msgCenter().cannotTakeSnapshot(console, mMachine.GetName()); fIsValid = false; } } else fIsValid = false; } else fIsValid = false; } /* Resume VM if necessary: */ if (fIsValid && fAtRuntime && !fWasPaused) { /* Resuming VM: */ console.Resume(); if (!console.isOk()) { msgCenter().cannotResumeMachine(console); fIsValid = false; } } /* Unlock machine finally: */ session.UnlockMachine(); } /* Return result: */ return fIsValid; }
int CShellCommandSetValue::Execute(CConsole &rConsole, CArgumentParser& rArguments) { LONG nError; rArguments.ResetArgumentIteration(); TCHAR *pszCommandItself = rArguments.GetNextArgument(); TCHAR *pszParameter; TCHAR *pszValueFull = NULL; TCHAR *pszValueData = NULL; BOOL blnBadParameter = FALSE; BOOL blnHelp = FALSE; DWORD dwValueSize = 0; DWORD dwType = REG_NONE; BYTE *pDataBuffer = NULL; if ((_tcsnicmp(pszCommandItself,SET_VALUE_CMD _T(".."),SET_VALUE_CMD_LENGTH+2*sizeof(TCHAR)) == 0)|| (_tcsnicmp(pszCommandItself,SET_VALUE_CMD _T("\\"),SET_VALUE_CMD_LENGTH+1*sizeof(TCHAR)) == 0)) { pszValueFull = pszCommandItself + SET_VALUE_CMD_LENGTH; } else if (_tcsnicmp(pszCommandItself,SET_VALUE_CMD _T("/"),SET_VALUE_CMD_LENGTH+1*sizeof(TCHAR)) == 0) { pszParameter = pszCommandItself + SET_VALUE_CMD_LENGTH; goto CheckValueArgument; } while((pszParameter = rArguments.GetNextArgument()) != NULL) { CheckValueArgument: blnBadParameter = FALSE; if (((*pszParameter == _T('/'))||(*pszParameter == _T('-'))) &&(*(pszParameter+1) == _T('?'))) { blnHelp = TRUE; } else if (dwType == REG_NONE) { if (_tcsicmp(pszParameter,_T("b")) == 0) { dwType = REG_BINARY; } else if (_tcsicmp(pszParameter,_T("dw")) == 0) { dwType = REG_DWORD; } else if (_tcsicmp(pszParameter,_T("dwle")) == 0) { dwType = REG_DWORD_LITTLE_ENDIAN; } else if (_tcsicmp(pszParameter,_T("dwbe")) == 0) { dwType = REG_DWORD_BIG_ENDIAN; } else if (_tcsicmp(pszParameter,_T("sz")) == 0) { dwType = REG_SZ; } else if (_tcsicmp(pszParameter,_T("esz")) == 0) { dwType = REG_EXPAND_SZ; } else { blnBadParameter = TRUE; } } else if (pszValueData == NULL) { pszValueData = pszParameter; } else if (!pszValueFull) { pszValueFull = pszParameter; } else { blnBadParameter = TRUE; } if (blnBadParameter) { rConsole.Write(_T("Bad parameter: ")); rConsole.Write(pszParameter); rConsole.Write(_T("\n")); } } if (!pszValueData) blnHelp = TRUE; CRegistryKey Key; TCHAR *pszValueName; const TCHAR *pszEmpty = _T(""); const TCHAR *pszPath; if (blnHelp) { rConsole.Write(GetHelpString()); if (pDataBuffer) delete pDataBuffer; return 0; } if (pszValueFull) { if (_tcscmp(pszValueFull,_T("\\")) == 0) goto CommandNAonRoot; TCHAR *pchSep = _tcsrchr(pszValueFull,_T('\\')); pszValueName = pchSep?(pchSep+1):(pszValueFull); pszPath = pchSep?pszValueFull:_T("."); //if (_tcsrchr(pszValueName,_T('.'))) //{ // pszValueName = _T(""); // pszPath = pszValueFull; //} //else if (pchSep) *pchSep = 0; } else { pszValueName = (TCHAR*)pszEmpty; pszPath = _T("."); } if (!m_rTree.GetKey(pszPath,KEY_SET_VALUE,Key)) { rConsole.Write(m_rTree.GetLastErrorDescription()); goto SkipCommand; } if (Key.IsRoot()) goto CommandNAonRoot; switch (dwType) { case REG_BINARY: { HANDLE hFile; DWORD dwBytesReaded; hFile = CreateFile(pszValueData,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,0,NULL); if (hFile == INVALID_HANDLE_VALUE) { rConsole.Write(_T("Cannot open file ")); rConsole.Write(pszValueData); rConsole.Write(_T("\n")); goto SkipCommand; } dwValueSize = GetFileSize(hFile,NULL); if (dwValueSize == (DWORD)-1) // ok, that's right, we compare signed with unsigned here. // GetFileSize is documented and declared to return DWORD. // Error is indicated by checking if return is -1. Design->documentation bug ??? { rConsole.Write(_T("Cannot get size of file ")); rConsole.Write(pszValueData); rConsole.Write(_T("\n")); VERIFY(CloseHandle(hFile)); goto SkipCommand; } pDataBuffer = new BYTE [dwValueSize]; if (!pDataBuffer) { rConsole.Write(_T("Cannot load file into memory. Out of memory.\n")); VERIFY(CloseHandle(hFile)); goto SkipCommand; } if (!ReadFile(hFile,pDataBuffer,dwValueSize,&dwBytesReaded,NULL)) { rConsole.Write(_T("Cannot load file into memory. Error reading file.\n")); VERIFY(CloseHandle(hFile)); goto SkipCommand; } VERIFY(CloseHandle(hFile)); ASSERT(dwBytesReaded == dwValueSize); } break; case REG_DWORD_LITTLE_ENDIAN: case REG_DWORD_BIG_ENDIAN: dwValueSize = 4; pDataBuffer = (BYTE *) new BYTE [dwValueSize]; if (!StringToDWORD(*(DWORD *)pDataBuffer,pszValueData)) { rConsole.Write(_T("Cannot convert ")); rConsole.Write(pszValueData); rConsole.Write(_T(" to DWORD \n")); goto SkipCommand; } if (dwType == REG_DWORD_BIG_ENDIAN) { unsigned char nByte; nByte = *pDataBuffer; *pDataBuffer = *(pDataBuffer+3); *(pDataBuffer+3) = nByte; nByte = *(pDataBuffer+1); *(pDataBuffer+1) = *(pDataBuffer+2); *(pDataBuffer+2) = nByte; } break; case REG_SZ: case REG_EXPAND_SZ: dwValueSize = _tcslen(pszValueData)+1; if (*pszValueData == _T('\"')) { dwValueSize -= 2; *(pszValueData+dwValueSize) = 0; pszValueData++; } dwValueSize *= sizeof(TCHAR); pDataBuffer = (BYTE *) new BYTE [dwValueSize]; { const TCHAR *pchSrc = pszValueData; TCHAR *pchDest = (TCHAR *)pDataBuffer; while(*pchSrc) { if (pchSrc[0] == _T('^')) { if (pchSrc[1] == _T('a')) *pchDest = _T('\a'); else if (pchSrc[1] == _T('b')) *pchDest = _T('\b'); else if (pchSrc[1] == _T('f')) *pchDest = _T('\f'); else if (pchSrc[1] == _T('n')) *pchDest = _T('\n'); else if (pchSrc[1] == _T('r')) *pchDest = _T('\r'); else if (pchSrc[1] == _T('t')) *pchDest = _T('\t'); else *pchDest = pchSrc[1]; pchSrc +=2; pchDest++; dwValueSize--; } else { *pchDest = *pchSrc; pchSrc++; pchDest++; } } *pchDest = _T('\0'); } break; default: ASSERT(FALSE); } { size_t s = _tcslen(pszValueName); if (s && (pszValueName[0] == _T('\"'))&&(pszValueName[s-1] == _T('\"'))) { pszValueName[s-1] = 0; pszValueName++; } } nError = Key.SetValue(pszValueName,dwType,pDataBuffer,dwValueSize); if (nError != ERROR_SUCCESS) { char Buffer[254]; _stprintf(Buffer,_T("Cannot set value. Error is %u\n"),(unsigned int)nError); rConsole.Write(Buffer); } else { InvalidateCompletion(); } SkipCommand: if (pDataBuffer) delete[] pDataBuffer; return 0; CommandNAonRoot: rConsole.Write(SET_VALUE_CMD COMMAND_NA_ON_ROOT); return 0; }
int CShellCommandValue::Execute(CConsole &rConsole, CArgumentParser& rArguments) { rArguments.ResetArgumentIteration(); TCHAR *pchCommandItself = rArguments.GetNextArgument(); TCHAR *pchParameter; TCHAR *pchValueFull = NULL; BOOL blnUnicodeDump = FALSE; BOOL blnBadParameter = FALSE; BOOL blnHelp = FALSE; LONG nError; DWORD dwValueSize; DWORD dwType = REG_NONE; BYTE *pDataBuffer = NULL; TCHAR *pchFilename = NULL; if ((_tcsnicmp(pchCommandItself,VALUE_CMD _T(".."),VALUE_CMD_LENGTH+2*sizeof(TCHAR)) == 0)|| (_tcsnicmp(pchCommandItself,VALUE_CMD _T("\\"),VALUE_CMD_LENGTH+1*sizeof(TCHAR)) == 0)) { pchValueFull = pchCommandItself + VALUE_CMD_LENGTH; } else if (_tcsnicmp(pchCommandItself,VALUE_CMD _T("/"),VALUE_CMD_LENGTH+1*sizeof(TCHAR)) == 0) { pchParameter = pchCommandItself + VALUE_CMD_LENGTH; goto CheckValueArgument; } while((pchParameter = rArguments.GetNextArgument()) != NULL) { CheckValueArgument: blnBadParameter = FALSE; if ((_tcsicmp(pchParameter,_T("/?")) == 0) ||(_tcsicmp(pchParameter,_T("-?")) == 0)) { blnHelp = TRUE; break; } else if (_tcsicmp(pchParameter,_T("/u")) == 0) { blnUnicodeDump = TRUE; } else if ((*pchParameter == _T('/'))&&(*(pchParameter+1) == _T('f'))) { pchFilename = pchParameter+2; } else if (!pchValueFull) { pchValueFull = pchParameter; } else { blnBadParameter = TRUE; } if (blnBadParameter) { rConsole.Write(_T("Bad parameter: ")); rConsole.Write(pchParameter); rConsole.Write(_T("\n")); } } CRegistryKey Key; TCHAR *pchValueName; const TCHAR *pszEmpty = _T(""); const TCHAR *pszPath; if (blnHelp) { rConsole.Write(GetHelpString()); if (pDataBuffer) delete pDataBuffer; return 0; } if (pchValueFull) { if (_tcscmp(pchValueFull,_T("\\")) == 0) goto ValueCommandNAonRoot; TCHAR *pchSep = _tcsrchr(pchValueFull,_T('\\')); pchValueName = pchSep?(pchSep+1):(pchValueFull); pszPath = pchSep?pchValueFull:_T("."); //if (_tcsrchr(pchValueName,_T('.'))) //{ // pchValueName = _T(""); // pchPath = pchValueFull; //} //else if (pchSep) *pchSep = 0; } else { pchValueName = (TCHAR*)pszEmpty; pszPath = _T("."); } if (!m_rTree.GetKey(pszPath,KEY_READ,Key)) { rConsole.Write(m_rTree.GetLastErrorDescription()); goto SkipValueCommand; } if (Key.IsRoot()) goto ValueCommandNAonRoot; { rConsole.Write(_T("Value name : \"")); rConsole.Write(_T("\\")); rConsole.Write(Key.GetKeyName()); size_t l = _tcslen(pchValueName); if (l&& (*pchValueName == _T('\"'))&& (pchValueName[l-1] == _T('\"'))) { pchValueName[l-1] = 0; pchValueName++; } rConsole.Write(pchValueName); rConsole.Write(_T("\"\n")); nError = Key.GetValue(pchValueName,NULL,NULL,&dwValueSize); if (nError == ERROR_SUCCESS) { pDataBuffer = new BYTE [dwValueSize]; Key.GetValue(pchValueName,&dwType,pDataBuffer,&dwValueSize); rConsole.Write(_T("Value type : ")); rConsole.Write(CRegistryKey::GetValueTypeName(dwType)); rConsole.Write(_T("\nValue data : ")); switch(dwType) { case REG_DWORD_LITTLE_ENDIAN: { TCHAR Buffer[3]; rConsole.Write(_T("0x")); for (unsigned int i = 0 ; i < dwValueSize ; i++) { _stprintf(Buffer,_T("%02X"),*(pDataBuffer+((dwValueSize-1)-i))); rConsole.Write(Buffer); } } rConsole.Write(_T("\n")); break; case REG_DWORD_BIG_ENDIAN: { TCHAR Buffer[3]; rConsole.Write(_T("0x")); for (unsigned int i = 0 ; i < dwValueSize ; i++) { _stprintf(Buffer,_T("%02X"),*(pDataBuffer+i)); rConsole.Write(Buffer); } } rConsole.Write(_T("\n")); break; case REG_LINK: break; case REG_MULTI_SZ: { TCHAR *pchCurrentString = (TCHAR *)pDataBuffer; rConsole.Write(_T("\n")); while(*pchCurrentString) { rConsole.Write(_T("\"")); rConsole.Write(pchCurrentString); rConsole.Write(_T("\"\n")); pchCurrentString += _tcslen(pchCurrentString)+1; } } break; case REG_RESOURCE_LIST: break; case REG_SZ: case REG_EXPAND_SZ: rConsole.Write(_T("\"")); rConsole.Write((TCHAR *)pDataBuffer); rConsole.Write(_T("\"\n")); break; case REG_BINARY: default: { TCHAR Buffer[256]; DWORD i, j; for (i = 0 ; i < dwValueSize ; i++) { if (i%16 == 0) { // ok this is begining of line rConsole.Write(_T("\n")); // print offset _stprintf(Buffer,_T("0x%08X "),(unsigned int)i); rConsole.Write(Buffer); } else if (i%8 == 0) { // this is the additional space between 7th and 8th byte in current line rConsole.Write(_T(" ")); } // print current byte unsigned int n = *(pDataBuffer+i); _stprintf(Buffer,_T("%02X "),n); rConsole.Write(Buffer); if (i && (i%16 == 15)) { // if this is the last byte in line // Dump text representation for (j = i-15; j <= i; j += blnUnicodeDump?2:1)\ { if ((j%8 == 0)&&(j%16 != 0)) { // this is the additional space between 7th and 8th byte in current line rConsole.Write(_T(" ")); } ASSERT(i-j < 16); // write current char representation if (blnUnicodeDump) { ASSERT(j%2 == 0); wchar_t ch = *(TCHAR *)(pDataBuffer+j); _stprintf(Buffer, #ifdef _UNICODE _T("%c"), #else // g++ may print warnings here (warning: __wchar_t format, different type arg (arg 3)) // %C in format string is a Microsoft extension. _T("%C"), #endif iswprint(ch)?ch:L'.'); } else { unsigned char ch = *(pDataBuffer+j); _stprintf(Buffer, #ifdef _UNICODE // g++ may print warnings here (warning: __wchar_t format, different type arg (arg 3)) // %C in format string is a Microsoft extension. _T("%C"), #else _T("%c"), #endif isprint(ch)?ch:'.'); } rConsole.Write(Buffer); } // for } // if } // for // print text representation of last line if it is not full (it have less than 16 bytes) // k is pseudo offset for (DWORD k = i; k%16 != 0; k++) { if (k%8 == 0) { // this is the additional space between 7th and 8th byte in current line rConsole.Write(_T(" ")); } _tcscpy(Buffer,_T(" ")); // the replacement of two digit of current byte + spacing rConsole.Write(Buffer); if (k && (k%16 == 15)) { // if this is the last byte in line ASSERT((k-15)%16 == 0); // k-15 must point at begin of last line for (j = k-15; j < i; j += blnUnicodeDump?2:1) { if (blnUnicodeDump&&(j+1 >= i)) { // ok, buffer size is odd number, so we don't display last byte. ASSERT(j+1 == i); break; } if ((j%8 == 0)&&(j%16 != 0)) { // this is the additional space between 7th and 8th byte in current line rConsole.Write(_T(" ")); } // write current char representation if (blnUnicodeDump) { ASSERT(j%2 == 0); wchar_t ch = *(TCHAR *)(pDataBuffer+j); _stprintf(Buffer, #ifdef _UNICODE _T("%c"), #else // g++ may print warnings here (warning: __wchar_t format, different type arg (arg 3)) // %C in format string is a Microsoft extension. _T("%C"), #endif iswprint(ch)?ch:L'.'); } else { unsigned char ch = *(pDataBuffer+j); _stprintf(Buffer, #ifdef _UNICODE // g++ may print warnings here (warning: __wchar_t format, different type arg (arg 3)) // %C in format string is a Microsoft extension. _T("%C"), #else _T("%c"), #endif isprint(ch)?ch:'.'); } rConsole.Write(Buffer); } // for } // if } // for } // default: rConsole.Write(_T("\n")); } // switch rConsole.Write(_T("\n")); if (pchFilename) { rConsole.Write(_T("Exporting value data to ")); rConsole.Write(pchFilename); rConsole.Write(_T(" ...\n")); HANDLE hFile = CreateFile(pchFilename,GENERIC_WRITE,0,NULL,CREATE_NEW,FILE_ATTRIBUTE_NORMAL,NULL); if (hFile == INVALID_HANDLE_VALUE) { rConsole.Write(_T("Cannot create new file ")); rConsole.Write(pchFilename); rConsole.Write(_T("\n")); goto SkipValueCommand; } DWORD dwBytesWritten; if (!WriteFile(hFile,pDataBuffer,dwValueSize,&dwBytesWritten,NULL)) { rConsole.Write(_T("Error writting file.\n")); VERIFY(CloseHandle(hFile)); goto SkipValueCommand; } ASSERT(dwBytesWritten == dwValueSize); VERIFY(CloseHandle(hFile)); } } else { rConsole.Write(_T("Error ")); TCHAR Buffer[256]; rConsole.Write(_itoa(nError,Buffer,10)); rConsole.Write(_T("\n")); if (nError == ERROR_FILE_NOT_FOUND) { rConsole.Write(_T("(System cannot find the value specified)\n")); } } } SkipValueCommand: if (pDataBuffer) delete[] pDataBuffer; return 0; ValueCommandNAonRoot: rConsole.Write(VALUE_CMD COMMAND_NA_ON_ROOT); return 0; }
bool UIWizardCloneVM::cloneVM() { /* Get clone name: */ QString strName = field("cloneName").toString(); /* Should we reinit mac status? */ bool fReinitMACs = field("reinitMACs").toBool(); /* Should we create linked clone? */ bool fLinked = field("linkedClone").toBool(); /* Get clone mode: */ KCloneMode cloneMode = (mode() == UIWizardMode_Basic && page(Page3)) || (mode() == UIWizardMode_Expert && page(PageExpert)) ? field("cloneMode").value<KCloneMode>() : KCloneMode_MachineState; /* Get VBox object: */ CVirtualBox vbox = vboxGlobal().virtualBox(); /* Prepare machine for cloning: */ CMachine srcMachine = m_machine; /* If the user like to create a linked clone from the current machine, we * have to take a little bit more action. First we create an snapshot, so * that new differencing images on the source VM are created. Based on that * we could use the new snapshot machine for cloning. */ if (fLinked && m_snapshot.isNull()) { /* Open session: */ CSession session = vboxGlobal().openSession(m_machine.GetId()); if (session.isNull()) return false; /* Prepare console: */ CConsole console = session.GetConsole(); /* Take the snapshot: */ QString strSnapshotName = tr("Linked Base for %1 and %2").arg(m_machine.GetName()).arg(strName); CProgress progress = console.TakeSnapshot(strSnapshotName, ""); if (console.isOk()) { /* Show the "Taking Snapshot" progress dialog: */ msgCenter().showModalProgressDialog(progress, m_machine.GetName(), ":/progress_snapshot_create_90px.png", this, true); if (!progress.isOk() || progress.GetResultCode() != 0) { msgCenter().cannotTakeSnapshot(progress); return false; } } else { msgCenter().cannotTakeSnapshot(console); return false; } /* Unlock machine finally: */ session.UnlockMachine(); /* Get the new snapshot and the snapshot machine. */ const CSnapshot &newSnapshot = m_machine.FindSnapshot(strSnapshotName); if (newSnapshot.isNull()) { msgCenter().cannotFindSnapshotByName(this, m_machine, strSnapshotName); return false; } srcMachine = newSnapshot.GetMachine(); } /* Create a new machine object. */ const QString &strSettingsFile = vbox.ComposeMachineFilename(strName, QString::null /**< @todo group support */, QString::null, QString::null); CMachine cloneMachine = vbox.CreateMachine(strSettingsFile, strName, QVector<QString>(), QString::null, QString::null); if (!vbox.isOk()) { msgCenter().cannotCreateMachine(vbox, this); return false; } /* Add the keep all MACs option to the import settings when requested. */ QVector<KCloneOptions> options; if (!fReinitMACs) options.append(KCloneOptions_KeepAllMACs); /* Linked clones requested? */ if (fLinked) options.append(KCloneOptions_Link); /* Start cloning. */ CProgress progress = srcMachine.CloneTo(cloneMachine, cloneMode, options); if (!srcMachine.isOk()) { msgCenter().cannotCreateClone(srcMachine, this); return false; } /* Wait until done. */ msgCenter().showModalProgressDialog(progress, windowTitle(), ":/progress_clone_90px.png", this, true); if (progress.GetCanceled()) return false; if (!progress.isOk() || progress.GetResultCode() != 0) { msgCenter().cannotCreateClone(srcMachine, progress, this); return false; } /* Finally register the clone machine. */ vbox.RegisterMachine(cloneMachine); if (!vbox.isOk()) { msgCenter().cannotRegisterMachine(vbox, cloneMachine, this); return false; } return true; }
int CShellCommandDOKA::Execute(CConsole &rConsole, CArgumentParser& rArguments) { REGSAM Access = m_rTree.GetDesiredOpenKeyAccess(); const TCHAR *pchParameter; BOOL blnBadParameter = FALSE; BOOL blnHelp = FALSE; while((pchParameter = rArguments.GetNextArgument()) != NULL) { blnBadParameter = FALSE; // Console.Write(_T("Processing parameter: \")"); // Console.Write(pchParameter); // Console.Write(_T("\")\n"); if ((_tcsicmp(pchParameter,_T("/?")) == 0) ||(_tcsicmp(pchParameter,_T("-?")) == 0)) { blnHelp = TRUE; } else if (*pchParameter == _T('-')) { TCHAR a = *(pchParameter+1); if (a == 0) { Access = 0; } else { if (*(pchParameter+2) != 0) { blnBadParameter = TRUE; } else { switch(a) { case _T('l'): // KEY_CREATE_LINK case _T('L'): Access &= ~KEY_CREATE_LINK; break; case _T('c'): // KEY_CREATE_SUB_KEY case _T('C'): Access &= ~KEY_CREATE_SUB_KEY; break; case _T('e'): // KEY_ENUMERATE_SUB_KEYS case _T('E'): Access &= ~KEY_ENUMERATE_SUB_KEYS; break; case _T('n'): // KEY_NOTIFY case _T('N'): Access &= ~KEY_NOTIFY; break; case _T('q'): // KEY_QUERY_VALUE case _T('Q'): Access &= ~KEY_QUERY_VALUE; break; case _T('s'): // KEY_SET_VALUE case _T('S'): Access &= ~KEY_SET_VALUE; break; default: blnBadParameter = TRUE; } // switch } // else (*(pchParameter+2) != 0) } // else (a == 0) } // if (*pchParameter == _T('-')) else if (*pchParameter == _T('+')) { TCHAR a = *(pchParameter+1); if (a == 0) { blnBadParameter = TRUE; } else { if (*(pchParameter+2) != 0) { blnBadParameter = TRUE; } else { switch(a) { case _T('a'): // KEY_ALL_ACCESS case _T('A'): Access |= KEY_ALL_ACCESS; break; case _T('l'): // KEY_CREATE_LINK case _T('L'): Access |= KEY_CREATE_LINK; break; case _T('c'): // KEY_CREATE_SUB_KEY case _T('C'): Access |= KEY_CREATE_SUB_KEY; break; case _T('e'): // KEY_ENUMERATE_SUB_KEYS case _T('E'): Access |= KEY_ENUMERATE_SUB_KEYS; break; case _T('n'): // KEY_NOTIFY case _T('N'): Access |= KEY_NOTIFY; break; case _T('q'): // KEY_QUERY_VALUE case _T('Q'): Access |= KEY_QUERY_VALUE; break; case _T('s'): // KEY_SET_VALUE case _T('S'): Access |= KEY_SET_VALUE; break; // case _T('X'): // KEY_EXECUTE // case _T('x'): // Access |= KEY_EXECUTE; // break; case _T('R'): // KEY_READ case _T('r'): Access |= KEY_READ; break; default: blnBadParameter = TRUE; } // switch } // else (*(pchParameter+2) != 0) } // else (a == 0) } // if (*pchParameter == _T('-')) else { blnBadParameter = TRUE; } if (blnBadParameter) { rConsole.Write(_T("Bad parameter: ")); rConsole.Write(pchParameter); rConsole.Write(_T("\n")); blnHelp = TRUE; } } // while((pchParameter = Parser.GetNextArgument()) != NULL) if (blnHelp) { rConsole.Write(GetHelpString()); } else { m_rTree.SetDesiredOpenKeyAccess(Access); rConsole.Write(_T("Desired open key access:\n")); REGSAM Access = m_rTree.GetDesiredOpenKeyAccess(); if (Access & KEY_CREATE_LINK) { rConsole.Write(_T("\tKEY_CREATE_LINK - Permission to create a symbolic link.\n")); } if (Access & KEY_CREATE_SUB_KEY) { rConsole.Write(_T("\tKEY_CREATE_SUB_KEY - Permission to create subkeys.\n")); } if (Access & KEY_ENUMERATE_SUB_KEYS) { rConsole.Write(_T("\tKEY_ENUMERATE_SUB_KEYS - Permission to enumerate subkeys.\n")); } if (Access & KEY_NOTIFY) { rConsole.Write(_T("\tKEY_NOTIFY - Permission for change notification.\n")); } if (Access & KEY_QUERY_VALUE) { rConsole.Write(_T("\tKEY_QUERY_VALUE - Permission to query subkey data.\n")); } if (Access & KEY_SET_VALUE) { rConsole.Write(_T("\tKEY_SET_VALUE - Permission to set subkey data.\n")); } } return 0; }
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ int __cdecl CP_printfDestroy( ){ x_CmdWnd.Close(); return 0; }