STDMETHODIMP CKpUtilitiesImpl::WriteFile(LPCTSTR lpFilePath, const BYTE* pData, DWORD dwDataSize) { if(lpFilePath == NULL) return E_POINTER; if(pData == NULL) return E_POINTER; const int nResult = AU_WriteBigFile(lpFilePath, pData, dwDataSize, FALSE); if(nResult == PWE_SUCCESS) return S_OK; if(nResult == PWE_NOFILEACCESS_WRITE) return E_ACCESSDENIED; return E_FAIL; }
BOOL CPwSafeApp::ProcessControlCommands() { LPCTSTR lpTrimChars = _T("\"' \t\r\n\\$%"); CString strCmdLine = (LPCTSTR)GetCommandLine(); strCmdLine = strCmdLine.Trim(lpTrimChars); strCmdLine = strCmdLine.MakeLower(); if((strCmdLine.Right(9) == _T("-exit-all")) || (strCmdLine.Right(9) == _T("/exit-all"))) { ::PostMessage(HWND_BROADCAST, CPwSafeDlg::GetKeePassControlMessageID(), KPCM_EXIT, 0); return TRUE; } if((strCmdLine.Right(10) == _T("-auto-type")) || (strCmdLine.Right(10) == _T("/auto-type"))) { ::PostMessage(HWND_BROADCAST, CPwSafeDlg::GetKeePassControlMessageID(), KPCM_AUTOTYPE, 0); return TRUE; } if((strCmdLine.Right(9) == _T("-lock-all")) || (strCmdLine.Right(9) == _T("/lock-all"))) { ::PostMessage(HWND_BROADCAST, CPwSafeDlg::GetKeePassControlMessageID(), KPCM_LOCK, 0); return TRUE; } if((strCmdLine.Right(11) == _T("-unlock-all")) || (strCmdLine.Right(11) == _T("/unlock-all"))) { ::PostMessage(HWND_BROADCAST, CPwSafeDlg::GetKeePassControlMessageID(), KPCM_UNLOCK, 0); return TRUE; } if((strCmdLine.Right(18).CompareNoCase(KPCLOPT_FILEEXT_UNREG) == 0) || (strCmdLine.Right(18).CompareNoCase(KPCLOPT_FILEEXT_UNREG_ALT) == 0)) { ChangeKdbShellAssociation(FALSE, NULL); return TRUE; } if((strCmdLine.Right(16).CompareNoCase(KPCLOPT_FILEEXT_REG) == 0) || (strCmdLine.Right(16).CompareNoCase(KPCLOPT_FILEEXT_REG_ALT) == 0)) { ChangeKdbShellAssociation(TRUE, NULL); return TRUE; } if((strCmdLine.Right(18) == _T("-clear-urloverride")) || (strCmdLine.Right(18) == _T("/clear-urloverride"))) { CPrivateConfigEx cfg(TRUE); cfg.Set(PWMKEY_URLOVERRIDE, _T("")); return TRUE; } if((strCmdLine.Right(16) == _T("-get-urloverride")) || (strCmdLine.Right(16) == _T("/get-urloverride"))) { CPrivateConfigEx cfg(FALSE); TCHAR tszUrlOverride[SI_REGSIZE]; tszUrlOverride[0] = 0; cfg.Get(PWMKEY_URLOVERRIDE, tszUrlOverride); std::basic_string<TCHAR> strOutFile = WU_GetTempDirectory(); strOutFile += _T("KeePass_UrlOverride.tmp"); std::basic_string<TCHAR> strContent = _T("[KeePass]\r\n"); strContent += PWMKEY_URLOVERRIDE; strContent += _T("="); strContent += tszUrlOverride; strContent += _T("\r\n"); VERIFY(AU_WriteBigFile(strOutFile.c_str(), (const BYTE*)strContent.c_str(), static_cast<DWORD>(strContent.size() * sizeof(TCHAR)), FALSE) == PWE_SUCCESS); return TRUE; } // Pre-check whether the option is present or not; if the option is not present, // the CmdArgs instance must not be created at this point of time (plugins // haven't added option prefixes yet, so creating the CmdArgs instance leads // to unknown option errors here) int nSetUrl = strCmdLine.Find(_T("-set-urloverride:")); if(nSetUrl < 0) nSetUrl = strCmdLine.Find(_T("-set-urloverride=")); if(nSetUrl < 0) nSetUrl = strCmdLine.Find(_T("/set-urloverride:")); if(nSetUrl < 0) nSetUrl = strCmdLine.Find(_T("/set-urloverride=")); if(nSetUrl >= 0) { const std_string strUrlOverride = CmdArgs::instance().getUrlOverride(); CPrivateConfigEx cfg(TRUE); cfg.Set(PWMKEY_URLOVERRIDE, strUrlOverride.c_str()); return TRUE; } if((strCmdLine.Right(8) == _T("-preload")) || (strCmdLine.Right(8) == _T("/preload"))) return TRUE; return FALSE; }