summaryrefslogtreecommitdiff
path: root/lib/backupclient
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2009-03-29 13:51:24 +0000
committerChris Wilson <chris+github@qwirx.com>2009-03-29 13:51:24 +0000
commitef3d1642c083a9c69eb48c6ab8ecc9be43dfbcfc (patch)
tree832e4994de4e02343616b5cd4454a3bb85f61b3b /lib/backupclient
parent2b51c2d2a265957abf6b2aee9901f9bd51d07ba6 (diff)
Change type of BackupStoreFilename not to derive from std::string, so
it can't accidentally be used as one. Fix use of encrypted filename in deleted file message, thanks to Kenny Millington for reporting.
Diffstat (limited to 'lib/backupclient')
-rw-r--r--lib/backupclient/BackupStoreFilename.cpp32
-rw-r--r--lib/backupclient/BackupStoreFilename.h24
-rw-r--r--lib/backupclient/BackupStoreFilenameClear.cpp17
-rw-r--r--lib/backupclient/BackupStoreObjectDump.cpp11
4 files changed, 56 insertions, 28 deletions
diff --git a/lib/backupclient/BackupStoreFilename.cpp b/lib/backupclient/BackupStoreFilename.cpp
index fbfe3313..72cd1acd 100644
--- a/lib/backupclient/BackupStoreFilename.cpp
+++ b/lib/backupclient/BackupStoreFilename.cpp
@@ -37,7 +37,7 @@ BackupStoreFilename::BackupStoreFilename()
//
// --------------------------------------------------------------------------
BackupStoreFilename::BackupStoreFilename(const BackupStoreFilename &rToCopy)
- : BackupStoreFilename_base(rToCopy)
+ : mEncryptedName(rToCopy.mEncryptedName)
{
}
@@ -65,7 +65,7 @@ bool BackupStoreFilename::CheckValid(bool ExceptionIfInvalid) const
{
bool ok = true;
- if(size() < 2)
+ if(mEncryptedName.size() < 2)
{
// Isn't long enough to have a header
ok = false;
@@ -73,14 +73,14 @@ bool BackupStoreFilename::CheckValid(bool ExceptionIfInvalid) const
else
{
// Check size is consistent
- unsigned int dsize = BACKUPSTOREFILENAME_GET_SIZE(*this);
- if(dsize != size())
+ unsigned int dsize = BACKUPSTOREFILENAME_GET_SIZE(this->mEncryptedName);
+ if(dsize != mEncryptedName.size())
{
ok = false;
}
// And encoding is an accepted value
- unsigned int encoding = BACKUPSTOREFILENAME_GET_ENCODING(*this);
+ unsigned int encoding = BACKUPSTOREFILENAME_GET_ENCODING(this->mEncryptedName);
if(encoding < Encoding_Min || encoding > Encoding_Max)
{
ok = false;
@@ -119,8 +119,8 @@ void BackupStoreFilename::ReadFromProtocol(Protocol &rProtocol)
rProtocol.Read(data, dsize - 2);
// assign to this string, storing the header and the extra data
- assign(hdr, 2);
- append(data.c_str(), data.size());
+ mEncryptedName.assign(hdr, 2);
+ mEncryptedName.append(data.c_str(), data.size());
// Check it
CheckValid();
@@ -141,7 +141,7 @@ void BackupStoreFilename::WriteToProtocol(Protocol &rProtocol) const
{
CheckValid();
- rProtocol.Write(c_str(), size());
+ rProtocol.Write(mEncryptedName.c_str(), mEncryptedName.size());
}
// --------------------------------------------------------------------------
@@ -177,7 +177,7 @@ void BackupStoreFilename::ReadFromStream(IOStream &rStream, int Timeout)
buf[0] = hdr[0]; buf[1] = hdr[1];
// assign to this string, storing the header and the extra data
- assign(buf, dsize);
+ mEncryptedName.assign(buf, dsize);
}
else
{
@@ -194,7 +194,7 @@ void BackupStoreFilename::ReadFromStream(IOStream &rStream, int Timeout)
data[0] = hdr[0]; data[1] = hdr[1];
// assign to this string, storing the header and the extra data
- assign(data, dsize);
+ mEncryptedName.assign(data, dsize);
}
// Check it
@@ -216,7 +216,7 @@ void BackupStoreFilename::WriteToStream(IOStream &rStream) const
{
CheckValid();
- rStream.Write(c_str(), size());
+ rStream.Write(mEncryptedName.c_str(), mEncryptedName.size());
}
// --------------------------------------------------------------------------
@@ -242,7 +242,8 @@ void BackupStoreFilename::EncodedFilenameChanged()
// --------------------------------------------------------------------------
bool BackupStoreFilename::IsEncrypted() const
{
- return BACKUPSTOREFILENAME_GET_ENCODING(*this) != Encoding_Clear;
+ return BACKUPSTOREFILENAME_GET_ENCODING(this->mEncryptedName) !=
+ Encoding_Clear;
}
@@ -250,8 +251,9 @@ bool BackupStoreFilename::IsEncrypted() const
//
// Function
// Name: BackupStoreFilename::SetAsClearFilename(const char *)
-// Purpose: Sets this object to be a valid filename, but with a filename in the clear.
-// Used on the server to create filenames when there's no way of encrypting it.
+// Purpose: Sets this object to be a valid filename, but with a
+// filename in the clear. Used on the server to create
+// filenames when there's no way of encrypting it.
// Created: 22/4/04
//
// --------------------------------------------------------------------------
@@ -268,7 +270,7 @@ void BackupStoreFilename::SetAsClearFilename(const char *Clear)
ASSERT(encoded.size() == toEncode.size() + 2);
// Store the encoded string
- assign(encoded);
+ mEncryptedName.assign(encoded);
// Stuff which must be done
EncodedFilenameChanged();
diff --git a/lib/backupclient/BackupStoreFilename.h b/lib/backupclient/BackupStoreFilename.h
index a7b6c437..80db9516 100644
--- a/lib/backupclient/BackupStoreFilename.h
+++ b/lib/backupclient/BackupStoreFilename.h
@@ -40,8 +40,11 @@ class IOStream;
// Created: 2003/08/26
//
// --------------------------------------------------------------------------
-class BackupStoreFilename : public BackupStoreFilename_base
+class BackupStoreFilename /* : public BackupStoreFilename_base */
{
+private:
+ std::string mEncryptedName;
+
public:
BackupStoreFilename();
BackupStoreFilename(const BackupStoreFilename &rToCopy);
@@ -71,8 +74,27 @@ public:
Encoding_Max = 2
};
+ const std::string& GetEncodedFilename() const
+ {
+ return mEncryptedName;
+ }
+
+ bool operator==(const BackupStoreFilename& rOther) const
+ {
+ return mEncryptedName == rOther.mEncryptedName;
+ }
+
+ bool operator!=(const BackupStoreFilename& rOther) const
+ {
+ return mEncryptedName != rOther.mEncryptedName;
+ }
+
protected:
virtual void EncodedFilenameChanged();
+ void SetEncodedFilename(const std::string &rEncoded)
+ {
+ mEncryptedName = rEncoded;
+ }
};
// On the wire utilities for class and derived class
diff --git a/lib/backupclient/BackupStoreFilenameClear.cpp b/lib/backupclient/BackupStoreFilenameClear.cpp
index cf168bfc..e529d8d3 100644
--- a/lib/backupclient/BackupStoreFilenameClear.cpp
+++ b/lib/backupclient/BackupStoreFilenameClear.cpp
@@ -160,8 +160,8 @@ void BackupStoreFilenameClear::MakeClearAvailable() const
CheckValid();
// Decode the header
- int size = BACKUPSTOREFILENAME_GET_SIZE(*this);
- int encoding = BACKUPSTOREFILENAME_GET_ENCODING(*this);
+ int size = BACKUPSTOREFILENAME_GET_SIZE(GetEncodedFilename());
+ int encoding = BACKUPSTOREFILENAME_GET_ENCODING(GetEncodedFilename());
// Decode based on encoding given in the header
switch(encoding)
@@ -169,7 +169,8 @@ void BackupStoreFilenameClear::MakeClearAvailable() const
case Encoding_Clear:
BOX_TRACE("**** BackupStoreFilename encoded with "
"Clear encoding ****");
- mClearFilename.assign(c_str() + 2, size - 2);
+ mClearFilename.assign(GetEncodedFilename().c_str() + 2,
+ size - 2);
break;
case Encoding_Blowfish:
@@ -244,7 +245,7 @@ void BackupStoreFilenameClear::EncryptClear(const std::string &rToEncode, Cipher
BACKUPSTOREFILENAME_MAKE_HDR(buffer, encSize, StoreAsEncoding);
// Store the encoded string
- assign((char*)buffer, encSize);
+ SetEncodedFilename(std::string((char*)buffer, encSize));
}
@@ -258,8 +259,10 @@ void BackupStoreFilenameClear::EncryptClear(const std::string &rToEncode, Cipher
// --------------------------------------------------------------------------
void BackupStoreFilenameClear::DecryptEncoded(CipherContext &rCipherContext) const
{
+ const std::string& rEncoded = GetEncodedFilename();
+
// Work out max size
- int maxOutSize = rCipherContext.MaxOutSizeForInBufferSize(size()) + 4;
+ int maxOutSize = rCipherContext.MaxOutSizeForInBufferSize(rEncoded.size()) + 4;
// Make sure encode/decode buffer has enough space
EnsureEncDecBufferSize(maxOutSize);
@@ -268,8 +271,8 @@ void BackupStoreFilenameClear::DecryptEncoded(CipherContext &rCipherContext) con
uint8_t *buffer = *spEncDecBuffer;
// Decrypt
- const char *str = c_str() + 2;
- int sizeOut = rCipherContext.TransformBlock(buffer, sEncDecBufferSize, str, size() - 2);
+ const char *str = rEncoded.c_str() + 2;
+ int sizeOut = rCipherContext.TransformBlock(buffer, sEncDecBufferSize, str, rEncoded.size() - 2);
// Assign to this
mClearFilename.assign((char*)buffer, sizeOut);
diff --git a/lib/backupclient/BackupStoreObjectDump.cpp b/lib/backupclient/BackupStoreObjectDump.cpp
index 0ad044bb..654317c1 100644
--- a/lib/backupclient/BackupStoreObjectDump.cpp
+++ b/lib/backupclient/BackupStoreObjectDump.cpp
@@ -70,7 +70,7 @@ void BackupStoreDirectory::Dump(void *clibFileHandle, bool ToTrace)
mAttributesModTime, mAttributes.GetSize());
// So repeated filenames can be illustrated, even though they can't be decoded
- std::map<BackupStoreFilename, int> nameNum;
+ std::map<std::string, int> nameNum;
int nameNumI = 0;
// Dump items
@@ -78,7 +78,7 @@ void BackupStoreDirectory::Dump(void *clibFileHandle, bool ToTrace)
for(std::vector<Entry*>::const_iterator i(mEntries.begin()); i != mEntries.end(); ++i)
{
// Choose file name index number for this file
- std::map<BackupStoreFilename, int>::iterator nn(nameNum.find((*i)->GetName()));
+ std::map<std::string, int>::iterator nn(nameNum.find((*i)->GetName().GetEncodedFilename()));
int ni = nameNumI;
if(nn != nameNum.end())
{
@@ -86,7 +86,7 @@ void BackupStoreDirectory::Dump(void *clibFileHandle, bool ToTrace)
}
else
{
- nameNum[(*i)->GetName()] = nameNumI;
+ nameNum[(*i)->GetName().GetEncodedFilename()] = nameNumI;
++nameNumI;
}
@@ -124,7 +124,7 @@ void BackupStoreDirectory::Dump(void *clibFileHandle, bool ToTrace)
(*i)->GetSizeInBlocks(),
(*i)->GetAttributesHash(),
(*i)->GetAttributes().GetSize(),
- (*i)->GetName().size(),
+ (*i)->GetName().GetEncodedFilename().size(),
ni,
((f & BackupStoreDirectory::Entry::Flags_File)?" file":""),
((f & BackupStoreDirectory::Entry::Flags_Dir)?" dir":""),
@@ -173,7 +173,8 @@ void BackupStoreFile::DumpFile(void *clibFileHandle, bool ToTrace, IOStream &rFi
// Read the next two objects
BackupStoreFilename fn;
fn.ReadFromStream(rFile, IOStream::TimeOutInfinite);
- OutputLine(file, ToTrace, "Filename size: %d\n", fn.size());
+ OutputLine(file, ToTrace, "Filename size: %d\n",
+ fn.GetEncodedFilename().size());
BackupClientFileAttributes attr;
attr.ReadFromStream(rFile, IOStream::TimeOutInfinite);