[Box Backup-commit] COMMIT r2481 - in box/trunk: bin/bbackupd bin/bbstored lib/backupclient lib/backupstore test/backupstore
boxbackup-dev@boxbackup.org
boxbackup-dev@boxbackup.org
Sun, 29 Mar 2009 14:51:25 +0100 (BST)
Author: chris
Date: 2009-03-29 14:51:24 +0100 (Sun, 29 Mar 2009)
New Revision: 2481
Modified:
box/trunk/bin/bbackupd/BackupClientDirectoryRecord.cpp
box/trunk/bin/bbstored/HousekeepStoreAccount.cpp
box/trunk/lib/backupclient/BackupStoreFilename.cpp
box/trunk/lib/backupclient/BackupStoreFilename.h
box/trunk/lib/backupclient/BackupStoreFilenameClear.cpp
box/trunk/lib/backupclient/BackupStoreObjectDump.cpp
box/trunk/lib/backupstore/BackupStoreCheck2.cpp
box/trunk/test/backupstore/testbackupstore.cpp
Log:
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.
Modified: box/trunk/bin/bbackupd/BackupClientDirectoryRecord.cpp
===================================================================
--- box/trunk/bin/bbackupd/BackupClientDirectoryRecord.cpp 2009-03-29 13:31:14 UTC (rev 2480)
+++ box/trunk/bin/bbackupd/BackupClientDirectoryRecord.cpp 2009-03-29 13:51:24 UTC (rev 2481)
@@ -1386,8 +1386,9 @@
// 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)
Modified: box/trunk/bin/bbstored/HousekeepStoreAccount.cpp
===================================================================
--- box/trunk/bin/bbstored/HousekeepStoreAccount.cpp 2009-03-29 13:31:14 UTC (rev 2480)
+++ box/trunk/bin/bbstored/HousekeepStoreAccount.cpp 2009-03-29 13:51:24 UTC (rev 2481)
@@ -349,7 +349,8 @@
// 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 @@
// 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 @@
}
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.
Modified: box/trunk/lib/backupclient/BackupStoreFilename.cpp
===================================================================
--- box/trunk/lib/backupclient/BackupStoreFilename.cpp 2009-03-29 13:31:14 UTC (rev 2480)
+++ box/trunk/lib/backupclient/BackupStoreFilename.cpp 2009-03-29 13:51:24 UTC (rev 2481)
@@ -37,7 +37,7 @@
//
// --------------------------------------------------------------------------
BackupStoreFilename::BackupStoreFilename(const BackupStoreFilename &rToCopy)
- : BackupStoreFilename_base(rToCopy)
+ : mEncryptedName(rToCopy.mEncryptedName)
{
}
@@ -65,7 +65,7 @@
{
bool ok = true;
- if(size() < 2)
+ if(mEncryptedName.size() < 2)
{
// Isn't long enough to have a header
ok = false;
@@ -73,14 +73,14 @@
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 @@
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 @@
{
CheckValid();
- rProtocol.Write(c_str(), size());
+ rProtocol.Write(mEncryptedName.c_str(), mEncryptedName.size());
}
// --------------------------------------------------------------------------
@@ -177,7 +177,7 @@
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 @@
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 @@
{
CheckValid();
- rStream.Write(c_str(), size());
+ rStream.Write(mEncryptedName.c_str(), mEncryptedName.size());
}
// --------------------------------------------------------------------------
@@ -242,7 +242,8 @@
// --------------------------------------------------------------------------
bool BackupStoreFilename::IsEncrypted() const
{
- return BACKUPSTOREFILENAME_GET_ENCODING(*this) != Encoding_Clear;
+ return BACKUPSTOREFILENAME_GET_ENCODING(this->mEncryptedName) !=
+ Encoding_Clear;
}
@@ -250,8 +251,9 @@
//
// 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 @@
ASSERT(encoded.size() == toEncode.size() + 2);
// Store the encoded string
- assign(encoded);
+ mEncryptedName.assign(encoded);
// Stuff which must be done
EncodedFilenameChanged();
Modified: box/trunk/lib/backupclient/BackupStoreFilename.h
===================================================================
--- box/trunk/lib/backupclient/BackupStoreFilename.h 2009-03-29 13:31:14 UTC (rev 2480)
+++ box/trunk/lib/backupclient/BackupStoreFilename.h 2009-03-29 13:51:24 UTC (rev 2481)
@@ -40,8 +40,11 @@
// 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 @@
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
Modified: box/trunk/lib/backupclient/BackupStoreFilenameClear.cpp
===================================================================
--- box/trunk/lib/backupclient/BackupStoreFilenameClear.cpp 2009-03-29 13:31:14 UTC (rev 2480)
+++ box/trunk/lib/backupclient/BackupStoreFilenameClear.cpp 2009-03-29 13:51:24 UTC (rev 2481)
@@ -160,8 +160,8 @@
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 @@
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 @@
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::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 @@
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);
Modified: box/trunk/lib/backupclient/BackupStoreObjectDump.cpp
===================================================================
--- box/trunk/lib/backupclient/BackupStoreObjectDump.cpp 2009-03-29 13:31:14 UTC (rev 2480)
+++ box/trunk/lib/backupclient/BackupStoreObjectDump.cpp 2009-03-29 13:51:24 UTC (rev 2481)
@@ -70,7 +70,7 @@
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 @@
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 @@
}
else
{
- nameNum[(*i)->GetName()] = nameNumI;
+ nameNum[(*i)->GetName().GetEncodedFilename()] = nameNumI;
++nameNumI;
}
@@ -124,7 +124,7 @@
(*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 @@
// 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);
Modified: box/trunk/lib/backupstore/BackupStoreCheck2.cpp
===================================================================
--- box/trunk/lib/backupstore/BackupStoreCheck2.cpp 2009-03-29 13:31:14 UTC (rev 2480)
+++ box/trunk/lib/backupstore/BackupStoreCheck2.cpp 2009-03-29 13:51:24 UTC (rev 2481)
@@ -750,7 +750,7 @@
// Records of things seen
std::set<int64_t> idsEncountered;
- std::set<BackupStoreFilename> filenamesEncountered;
+ std::set<std::string> filenamesEncountered;
do
{
@@ -792,7 +792,7 @@
// 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 @@
}
// Remember filename
- filenamesEncountered.insert((*i)->GetName());
+ filenamesEncountered.insert((*i)->GetName().GetEncodedFilename());
}
}
}
Modified: box/trunk/test/backupstore/testbackupstore.cpp
===================================================================
--- box/trunk/test/backupstore/testbackupstore.cpp 2009-03-29 13:31:14 UTC (rev 2480)
+++ box/trunk/test/backupstore/testbackupstore.cpp 2009-03-29 13:51:24 UTC (rev 2481)
@@ -232,7 +232,8 @@
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
{