summaryrefslogtreecommitdiff
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
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.
-rw-r--r--bin/bbackupd/BackupClientDirectoryRecord.cpp3
-rw-r--r--bin/bbstored/HousekeepStoreAccount.cpp10
-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
-rw-r--r--lib/backupstore/BackupStoreCheck2.cpp6
-rw-r--r--test/backupstore/testbackupstore.cpp3
8 files changed, 70 insertions, 36 deletions
diff --git a/bin/bbackupd/BackupClientDirectoryRecord.cpp b/bin/bbackupd/BackupClientDirectoryRecord.cpp
index 4ecb81d9..b8d42d47 100644
--- a/bin/bbackupd/BackupClientDirectoryRecord.cpp
+++ b/bin/bbackupd/BackupClientDirectoryRecord.cpp
@@ -1386,8 +1386,9 @@ bool BackupClientDirectoryRecord::UpdateItems(
// aren't actually deleted, as the whole state will be reset anyway.
BackupClientDeleteList &rdel(rContext.GetDeleteList());
+ BackupStoreFilenameClear clear(en->GetName());
std::string localName = MakeFullPath(rLocalPath,
- en->GetName());
+ clear.GetClearFilename());
// Delete this entry -- file or directory?
if((en->GetFlags() & BackupStoreDirectory::Entry::Flags_File) != 0)
diff --git a/bin/bbstored/HousekeepStoreAccount.cpp b/bin/bbstored/HousekeepStoreAccount.cpp
index 84765209..dbb9b544 100644
--- a/bin/bbstored/HousekeepStoreAccount.cpp
+++ b/bin/bbstored/HousekeepStoreAccount.cpp
@@ -349,7 +349,8 @@ bool HousekeepStoreAccount::ScanDirectory(int64_t ObjectID)
// Add files to the list of potential deletions
// map to count the distance from the mark
- std::map<std::pair<BackupStoreFilename, int32_t>, int32_t> markVersionAges;
+ typedef std::pair<std::string, int32_t> version_t;
+ std::map<version_t, int32_t> markVersionAges;
// map of pair (filename, mark number) -> version age
// NOTE: use a reverse iterator to allow the distance from mark stuff to work
@@ -367,7 +368,10 @@ bool HousekeepStoreAccount::ScanDirectory(int64_t ObjectID)
// Work out ages of this version from the last mark
int32_t enVersionAge = 0;
- std::map<std::pair<BackupStoreFilename, int32_t>, int32_t>::iterator enVersionAgeI(markVersionAges.find(std::pair<BackupStoreFilename, int32_t>(en->GetName(), en->GetMarkNumber())));
+ std::map<version_t, int32_t>::iterator enVersionAgeI(
+ markVersionAges.find(
+ version_t(en->GetName().GetEncodedFilename(),
+ en->GetMarkNumber())));
if(enVersionAgeI != markVersionAges.end())
{
enVersionAge = enVersionAgeI->second + 1;
@@ -375,7 +379,7 @@ bool HousekeepStoreAccount::ScanDirectory(int64_t ObjectID)
}
else
{
- markVersionAges[std::pair<BackupStoreFilename, int32_t>(en->GetName(), en->GetMarkNumber())] = enVersionAge;
+ markVersionAges[version_t(en->GetName().GetEncodedFilename(), en->GetMarkNumber())] = enVersionAge;
}
// enVersionAge is now the age of this version.
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);
diff --git a/lib/backupstore/BackupStoreCheck2.cpp b/lib/backupstore/BackupStoreCheck2.cpp
index 9615516c..bcb5c5e9 100644
--- a/lib/backupstore/BackupStoreCheck2.cpp
+++ b/lib/backupstore/BackupStoreCheck2.cpp
@@ -750,7 +750,7 @@ bool BackupStoreDirectory::CheckAndFix()
// Records of things seen
std::set<int64_t> idsEncountered;
- std::set<BackupStoreFilename> filenamesEncountered;
+ std::set<std::string> filenamesEncountered;
do
{
@@ -792,7 +792,7 @@ bool BackupStoreDirectory::CheckAndFix()
// Check to see if the name has already been encountered -- if not, then it
// needs to have the old version flag set
- if(filenamesEncountered.find((*i)->GetName()) != filenamesEncountered.end())
+ if(filenamesEncountered.find((*i)->GetName().GetEncodedFilename()) != filenamesEncountered.end())
{
// Seen before -- check old version flag set
if(((*i)->GetFlags() & Entry::Flags_OldVersion) != Entry::Flags_OldVersion
@@ -818,7 +818,7 @@ bool BackupStoreDirectory::CheckAndFix()
}
// Remember filename
- filenamesEncountered.insert((*i)->GetName());
+ filenamesEncountered.insert((*i)->GetName().GetEncodedFilename());
}
}
}
diff --git a/test/backupstore/testbackupstore.cpp b/test/backupstore/testbackupstore.cpp
index 39bd9fbe..0266d097 100644
--- a/test/backupstore/testbackupstore.cpp
+++ b/test/backupstore/testbackupstore.cpp
@@ -232,7 +232,8 @@ int test1(int argc, const char *argv[])
TEST_THAT(fn1 == fn3);
// Check that it's been encrypted
- TEST_THAT(fn2.find("name") == fn2.npos);
+ std::string name(fn2.GetEncodedFilename());
+ TEST_THAT(name.find("name") == name.npos);
// Bung it in a stream, get it out in a Clear filename
{