Changeset 2481


Ignore:
Timestamp:
29/03/2009 14:51:24 (3 years ago)
Author:
chris
Message:

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.

Location:
box/trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • box/trunk/bin/bbackupd/BackupClientDirectoryRecord.cpp

    r2460 r2481  
    13871387                        BackupClientDeleteList &rdel(rContext.GetDeleteList()); 
    13881388 
     1389                        BackupStoreFilenameClear clear(en->GetName()); 
    13891390                        std::string localName = MakeFullPath(rLocalPath, 
    1390                                 en->GetName()); 
     1391                                clear.GetClearFilename()); 
    13911392                         
    13921393                        // Delete this entry -- file or directory? 
  • box/trunk/bin/bbstored/HousekeepStoreAccount.cpp

    r2176 r2481  
    350350 
    351351                // map to count the distance from the mark 
    352                 std::map<std::pair<BackupStoreFilename, int32_t>, int32_t> markVersionAges; 
     352                typedef std::pair<std::string, int32_t> version_t; 
     353                std::map<version_t, int32_t> markVersionAges; 
    353354                        // map of pair (filename, mark number) -> version age 
    354355 
     
    368369                        // Work out ages of this version from the last mark 
    369370                        int32_t enVersionAge = 0; 
    370                         std::map<std::pair<BackupStoreFilename, int32_t>, int32_t>::iterator enVersionAgeI(markVersionAges.find(std::pair<BackupStoreFilename, int32_t>(en->GetName(), en->GetMarkNumber()))); 
     371                        std::map<version_t, int32_t>::iterator enVersionAgeI( 
     372                                markVersionAges.find( 
     373                                        version_t(en->GetName().GetEncodedFilename(), 
     374                                                en->GetMarkNumber()))); 
    371375                        if(enVersionAgeI != markVersionAges.end()) 
    372376                        { 
     
    376380                        else 
    377381                        { 
    378                                 markVersionAges[std::pair<BackupStoreFilename, int32_t>(en->GetName(), en->GetMarkNumber())] = enVersionAge; 
     382                                markVersionAges[version_t(en->GetName().GetEncodedFilename(), en->GetMarkNumber())] = enVersionAge; 
    379383                        } 
    380384                        // enVersionAge is now the age of this version. 
  • box/trunk/lib/backupclient/BackupStoreFilename.cpp

    r217 r2481  
    3838// -------------------------------------------------------------------------- 
    3939BackupStoreFilename::BackupStoreFilename(const BackupStoreFilename &rToCopy) 
    40         : BackupStoreFilename_base(rToCopy) 
     40        : mEncryptedName(rToCopy.mEncryptedName) 
    4141{ 
    4242} 
     
    6666        bool ok = true; 
    6767         
    68         if(size() < 2) 
     68        if(mEncryptedName.size() < 2) 
    6969        { 
    7070                // Isn't long enough to have a header 
     
    7474        { 
    7575                // Check size is consistent 
    76                 unsigned int dsize = BACKUPSTOREFILENAME_GET_SIZE(*this); 
    77                 if(dsize != size()) 
     76                unsigned int dsize = BACKUPSTOREFILENAME_GET_SIZE(this->mEncryptedName); 
     77                if(dsize != mEncryptedName.size()) 
    7878                { 
    7979                        ok = false; 
     
    8181                 
    8282                // And encoding is an accepted value 
    83                 unsigned int encoding = BACKUPSTOREFILENAME_GET_ENCODING(*this); 
     83                unsigned int encoding = BACKUPSTOREFILENAME_GET_ENCODING(this->mEncryptedName); 
    8484                if(encoding < Encoding_Min || encoding > Encoding_Max) 
    8585                { 
     
    120120         
    121121        // assign to this string, storing the header and the extra data 
    122         assign(hdr, 2); 
    123         append(data.c_str(), data.size()); 
     122        mEncryptedName.assign(hdr, 2); 
     123        mEncryptedName.append(data.c_str(), data.size()); 
    124124         
    125125        // Check it 
     
    142142        CheckValid(); 
    143143         
    144         rProtocol.Write(c_str(), size()); 
     144        rProtocol.Write(mEncryptedName.c_str(), mEncryptedName.size()); 
    145145} 
    146146 
     
    178178 
    179179                // assign to this string, storing the header and the extra data 
    180                 assign(buf, dsize); 
     180                mEncryptedName.assign(buf, dsize); 
    181181        } 
    182182        else 
     
    195195 
    196196                // assign to this string, storing the header and the extra data 
    197                 assign(data, dsize); 
     197                mEncryptedName.assign(data, dsize); 
    198198        } 
    199199         
     
    217217        CheckValid(); 
    218218         
    219         rStream.Write(c_str(), size()); 
     219        rStream.Write(mEncryptedName.c_str(), mEncryptedName.size()); 
    220220} 
    221221 
     
    243243bool BackupStoreFilename::IsEncrypted() const 
    244244{ 
    245         return BACKUPSTOREFILENAME_GET_ENCODING(*this) != Encoding_Clear; 
     245        return BACKUPSTOREFILENAME_GET_ENCODING(this->mEncryptedName) != 
     246                Encoding_Clear; 
    246247} 
    247248 
     
    251252// Function 
    252253//              Name:    BackupStoreFilename::SetAsClearFilename(const char *) 
    253 //              Purpose: Sets this object to be a valid filename, but with a filename in the clear. 
    254 //                               Used on the server to create filenames when there's no way of encrypting it. 
     254//              Purpose: Sets this object to be a valid filename, but with a 
     255//                       filename in the clear. Used on the server to create 
     256//                       filenames when there's no way of encrypting it. 
    255257//              Created: 22/4/04 
    256258// 
     
    269271         
    270272        // Store the encoded string 
    271         assign(encoded); 
     273        mEncryptedName.assign(encoded); 
    272274         
    273275        // Stuff which must be done 
  • box/trunk/lib/backupclient/BackupStoreFilename.h

    r217 r2481  
    4141// 
    4242// -------------------------------------------------------------------------- 
    43 class BackupStoreFilename : public BackupStoreFilename_base 
     43class BackupStoreFilename /* : public BackupStoreFilename_base */ 
    4444{ 
     45private: 
     46        std::string mEncryptedName; 
     47 
    4548public: 
    4649        BackupStoreFilename(); 
     
    7275        }; 
    7376 
     77        const std::string& GetEncodedFilename() const 
     78        { 
     79                return mEncryptedName; 
     80        } 
     81 
     82        bool operator==(const BackupStoreFilename& rOther) const 
     83        { 
     84                return mEncryptedName == rOther.mEncryptedName; 
     85        } 
     86 
     87        bool operator!=(const BackupStoreFilename& rOther) const 
     88        { 
     89                return mEncryptedName != rOther.mEncryptedName; 
     90        } 
     91 
    7492protected: 
    7593        virtual void EncodedFilenameChanged(); 
     94        void SetEncodedFilename(const std::string &rEncoded) 
     95        { 
     96                mEncryptedName = rEncoded; 
     97        } 
    7698}; 
    7799 
  • box/trunk/lib/backupclient/BackupStoreFilenameClear.cpp

    r2127 r2481  
    161161                 
    162162        // Decode the header 
    163         int size = BACKUPSTOREFILENAME_GET_SIZE(*this); 
    164         int encoding = BACKUPSTOREFILENAME_GET_ENCODING(*this); 
     163        int size = BACKUPSTOREFILENAME_GET_SIZE(GetEncodedFilename()); 
     164        int encoding = BACKUPSTOREFILENAME_GET_ENCODING(GetEncodedFilename()); 
    165165         
    166166        // Decode based on encoding given in the header 
     
    170170                BOX_TRACE("**** BackupStoreFilename encoded with " 
    171171                        "Clear encoding ****"); 
    172                 mClearFilename.assign(c_str() + 2, size - 2); 
     172                mClearFilename.assign(GetEncodedFilename().c_str() + 2, 
     173                        size - 2); 
    173174                break; 
    174175                 
     
    245246         
    246247        // Store the encoded string 
    247         assign((char*)buffer, encSize); 
     248        SetEncodedFilename(std::string((char*)buffer, encSize)); 
    248249} 
    249250 
     
    259260void BackupStoreFilenameClear::DecryptEncoded(CipherContext &rCipherContext) const 
    260261{ 
     262        const std::string& rEncoded = GetEncodedFilename(); 
     263 
    261264        // Work out max size 
    262         int maxOutSize = rCipherContext.MaxOutSizeForInBufferSize(size()) + 4; 
     265        int maxOutSize = rCipherContext.MaxOutSizeForInBufferSize(rEncoded.size()) + 4; 
    263266         
    264267        // Make sure encode/decode buffer has enough space 
     
    269272         
    270273        // Decrypt 
    271         const char *str = c_str() + 2; 
    272         int sizeOut = rCipherContext.TransformBlock(buffer, sEncDecBufferSize, str, size() - 2); 
     274        const char *str = rEncoded.c_str() + 2; 
     275        int sizeOut = rCipherContext.TransformBlock(buffer, sEncDecBufferSize, str, rEncoded.size() - 2); 
    273276         
    274277        // Assign to this 
  • box/trunk/lib/backupclient/BackupStoreObjectDump.cpp

    r2127 r2481  
    7171 
    7272        // So repeated filenames can be illustrated, even though they can't be decoded 
    73         std::map<BackupStoreFilename, int> nameNum; 
     73        std::map<std::string, int> nameNum; 
    7474        int nameNumI = 0; 
    7575 
     
    7979        { 
    8080                // Choose file name index number for this file 
    81                 std::map<BackupStoreFilename, int>::iterator nn(nameNum.find((*i)->GetName())); 
     81                std::map<std::string, int>::iterator nn(nameNum.find((*i)->GetName().GetEncodedFilename())); 
    8282                int ni = nameNumI; 
    8383                if(nn != nameNum.end()) 
     
    8787                else 
    8888                { 
    89                         nameNum[(*i)->GetName()] = nameNumI; 
     89                        nameNum[(*i)->GetName().GetEncodedFilename()] = nameNumI; 
    9090                        ++nameNumI; 
    9191                } 
     
    125125                        (*i)->GetAttributesHash(), 
    126126                        (*i)->GetAttributes().GetSize(), 
    127                         (*i)->GetName().size(), 
     127                        (*i)->GetName().GetEncodedFilename().size(), 
    128128                        ni, 
    129129                        ((f & BackupStoreDirectory::Entry::Flags_File)?" file":""), 
     
    174174        BackupStoreFilename fn; 
    175175        fn.ReadFromStream(rFile, IOStream::TimeOutInfinite); 
    176         OutputLine(file, ToTrace, "Filename size: %d\n", fn.size()); 
     176        OutputLine(file, ToTrace, "Filename size: %d\n", 
     177                fn.GetEncodedFilename().size()); 
    177178         
    178179        BackupClientFileAttributes attr; 
  • box/trunk/lib/backupstore/BackupStoreCheck2.cpp

    r2160 r2481  
    751751                // Records of things seen 
    752752                std::set<int64_t> idsEncountered; 
    753                 std::set<BackupStoreFilename> filenamesEncountered; 
     753                std::set<std::string> filenamesEncountered; 
    754754 
    755755                do 
     
    793793                                        // Check to see if the name has already been encountered -- if not, then it 
    794794                                        // needs to have the old version flag set 
    795                                         if(filenamesEncountered.find((*i)->GetName()) != filenamesEncountered.end()) 
     795                                        if(filenamesEncountered.find((*i)->GetName().GetEncodedFilename()) != filenamesEncountered.end()) 
    796796                                        { 
    797797                                                // Seen before -- check old version flag set 
     
    819819                                                 
    820820                                                // Remember filename 
    821                                                 filenamesEncountered.insert((*i)->GetName()); 
     821                                                filenamesEncountered.insert((*i)->GetName().GetEncodedFilename()); 
    822822                                        } 
    823823                                } 
  • box/trunk/test/backupstore/testbackupstore.cpp

    r2355 r2481  
    233233                 
    234234                // Check that it's been encrypted 
    235                 TEST_THAT(fn2.find("name") == fn2.npos); 
     235                std::string name(fn2.GetEncodedFilename()); 
     236                TEST_THAT(name.find("name") == name.npos); 
    236237                         
    237238                // Bung it in a stream, get it out in a Clear filename 
Note: See TracChangeset for help on using the changeset viewer.