bool CUser::PrintLine(CFile& File, CString sName, CString sValue) const { sName.Trim(); sValue.Trim(); if (sName.empty() || sValue.empty()) { DEBUG("Refused writing an invalid line to a user config. [" << sName << "] [" << sValue << "]"); return false; } // FirstLine() so that no one can inject new lines to the config if he // manages to add "\n" to e.g. sValue. CString sLine = "\t" + sName.FirstLine() + " = " + sValue.FirstLine() + "\n"; return (File.Write(sLine) > 0); }
EBufferType DecryptBuffer(const CString& sPath, CString& sBuffer, CString& sName) { CString sContent; sBuffer = ""; CFile File(sPath); if (sPath.empty() || !File.Open() || !File.ReadFile(sContent)) return EmptyBuffer; File.Close(); if (!sContent.empty()) { CBlowfish c(m_sPassword, BF_DECRYPT); sBuffer = c.Crypt(sContent); if (sBuffer.TrimPrefix(LEGACY_VERIFICATION_TOKEN)) { sName = FindLegacyBufferName(sPath); return ChanBuffer; } else if (sBuffer.TrimPrefix(CHAN_VERIFICATION_TOKEN)) { sName = sBuffer.FirstLine(); if (sBuffer.TrimLeft(sName + "\n")) return ChanBuffer; } else if (sBuffer.TrimPrefix(QUERY_VERIFICATION_TOKEN)) { sName = sBuffer.FirstLine(); if (sBuffer.TrimLeft(sName + "\n")) return QueryBuffer; } PutModule("Unable to decode Encrypted file [" + sPath + "]"); return InvalidBuffer; } return EmptyBuffer; }