From subversion at boxbackup.org Sat Dec 3 23:07:41 2011 From: subversion at boxbackup.org (subversion at boxbackup.org) Date: Sat, 3 Dec 2011 23:07:41 +0000 (GMT) Subject: [Box Backup-commit] COMMIT r3047 - box/trunk/lib/common Message-ID: <20111203230741.DA02419F510@www.boxbackup.org> Author: chris Date: 2011-12-03 23:07:41 +0000 (Sat, 03 Dec 2011) New Revision: 3047 Modified: box/trunk/lib/common/ExcludeList.cpp Log: Fix regex case issues on Windows (\S converted to \s for example). Ensure that filename comparison is always case insensitive on Windows, by convention. Modified: box/trunk/lib/common/ExcludeList.cpp =================================================================== --- box/trunk/lib/common/ExcludeList.cpp 2011-11-21 22:27:45 UTC (rev 3046) +++ box/trunk/lib/common/ExcludeList.cpp 2011-12-03 23:07:41 UTC (rev 3047) @@ -101,11 +101,6 @@ output.replace(pos, 1, "\\" DIRECTORY_SEPARATOR); } - for (std::string::iterator i = output.begin(); i != output.end(); i++) - { - *i = tolower(*i); - } - return output; } #endif @@ -185,17 +180,19 @@ try { std::string entry = *i; + int flags = REG_EXTENDED | REG_NOSUB; // Convert any forward slashes in the string // to appropriately escaped backslashes #ifdef WIN32 entry = ReplaceSlashesRegex(entry); + flags |= REG_ICASE; // Windows convention #endif // Compile - int errcode = ::regcomp(pregex, entry.c_str(), - REG_EXTENDED | REG_NOSUB); + int errcode = ::regcomp(pregex, entry.c_str(), + flags); if (errcode != 0) { @@ -238,6 +235,7 @@ std::string test = rTest; #ifdef WIN32 + // converts to lower case as well test = ReplaceSlashesDefinite(test); #endif From subversion at boxbackup.org Mon Dec 12 23:36:26 2011 From: subversion at boxbackup.org (subversion at boxbackup.org) Date: Mon, 12 Dec 2011 23:36:26 +0000 (GMT) Subject: [Box Backup-commit] COMMIT r3048 - in box/trunk: . bin/bbstored lib/backupstore Message-ID: <20111212233626.69C181A332A@www.boxbackup.org> Author: chris Date: 2011-12-12 23:36:25 +0000 (Mon, 12 Dec 2011) New Revision: 3048 Modified: box/trunk/ box/trunk/bin/bbstored/BackupStoreDaemon.cpp box/trunk/bin/bbstored/BackupStoreDaemon.h box/trunk/lib/backupstore/BackupCommands.cpp box/trunk/lib/backupstore/BackupStoreContext.h Log: Log the account name with connections, disconnections and statistics, requested by Pete Jalajas. Property changes on: box/trunk ___________________________________________________________________ Modified: svn:mergeinfo - /box/RELEASE/0.11rc5:2575 + /box/RELEASE/0.11:2741-2745 /box/RELEASE/0.11.1:2823,2827 /box/RELEASE/0.11rc5:2575 Modified: box/trunk/bin/bbstored/BackupStoreDaemon.cpp =================================================================== --- box/trunk/bin/bbstored/BackupStoreDaemon.cpp 2011-12-03 23:07:41 UTC (rev 3047) +++ box/trunk/bin/bbstored/BackupStoreDaemon.cpp 2011-12-12 23:36:25 UTC (rev 3048) @@ -317,6 +317,8 @@ if(::sscanf(clientCommonName.c_str(), "BACKUP-%x", &id) != 1) { // Bad! Disconnect immediately + BOX_WARNING("Failed login: invalid client common name: " << + clientCommonName); return; } @@ -353,18 +355,20 @@ } catch(...) { - LogConnectionStats(clientCommonName.c_str(), rStream); + LogConnectionStats(id, context.GetAccountName(), rStream); throw; } - LogConnectionStats(clientCommonName.c_str(), rStream); + LogConnectionStats(id, context.GetAccountName(), rStream); context.CleanUp(); } -void BackupStoreDaemon::LogConnectionStats(const char *commonName, - const SocketStreamTLS &s) +void BackupStoreDaemon::LogConnectionStats(uint32_t accountId, + const std::string& accountName, const SocketStreamTLS &s) { // Log the amount of data transferred - BOX_NOTICE("Connection statistics for " << commonName << ":" + BOX_NOTICE("Connection statistics for " << + BOX_FORMAT_ACCOUNT(accountId) << " " + "(name=" << accountName << "):" " IN=" << s.GetBytesRead() << " OUT=" << s.GetBytesWritten() << " NET_IN=" << (s.GetBytesRead() - s.GetBytesWritten()) << Modified: box/trunk/bin/bbstored/BackupStoreDaemon.h =================================================================== --- box/trunk/bin/bbstored/BackupStoreDaemon.h 2011-12-03 23:07:41 UTC (rev 3047) +++ box/trunk/bin/bbstored/BackupStoreDaemon.h 2011-12-12 23:36:25 UTC (rev 3048) @@ -63,7 +63,8 @@ // Housekeeping functions void HousekeepingProcess(); - void LogConnectionStats(const char *commonName, const SocketStreamTLS &s); + void LogConnectionStats(uint32_t accountId, + const std::string& accountName, const SocketStreamTLS &s); public: // HousekeepingInterface implementation Modified: box/trunk/lib/backupstore/BackupCommands.cpp =================================================================== --- box/trunk/lib/backupstore/BackupCommands.cpp 2011-12-03 23:07:41 UTC (rev 3047) +++ box/trunk/lib/backupstore/BackupCommands.cpp 2011-12-12 23:36:25 UTC (rev 3048) @@ -89,16 +89,16 @@ if(mClientID != rContext.GetClientID()) { BOX_WARNING("Failed login from client ID " << - BOX_FORMAT_ACCOUNT(mClientID) << - ": wrong certificate for this account"); + BOX_FORMAT_ACCOUNT(mClientID) << ": " + "wrong certificate for this account"); return PROTOCOL_ERROR(Err_BadLogin); } if(!rContext.GetClientHasAccount()) { BOX_WARNING("Failed login from client ID " << - BOX_FORMAT_ACCOUNT(mClientID) << - ": no such account on this server"); + BOX_FORMAT_ACCOUNT(mClientID) << ": " + "no such account on this server"); return PROTOCOL_ERROR(Err_BadLogin); } @@ -128,8 +128,8 @@ // Log login BOX_NOTICE("Login from Client ID " << - BOX_FORMAT_ACCOUNT(mClientID) << - " " << + BOX_FORMAT_ACCOUNT(mClientID) << " " + "(name=" << rContext.GetAccountName() << "): " << (((mFlags & Flags_ReadOnly) != Flags_ReadOnly) ?"Read/Write":"Read-only")); @@ -152,7 +152,8 @@ std::auto_ptr BackupProtocolFinished::DoCommand(BackupProtocolReplyable &rProtocol, BackupStoreContext &rContext) const { BOX_NOTICE("Session finished for Client ID " << - BOX_FORMAT_ACCOUNT(rContext.GetClientID())); + BOX_FORMAT_ACCOUNT(rContext.GetClientID()) << " " + "(name=" << rContext.GetAccountName() << ")"); // Let the context know about it rContext.ReceivedFinishCommand(); Modified: box/trunk/lib/backupstore/BackupStoreContext.h =================================================================== --- box/trunk/lib/backupstore/BackupStoreContext.h 2011-12-03 23:07:41 UTC (rev 3047) +++ box/trunk/lib/backupstore/BackupStoreContext.h 2011-12-12 23:36:25 UTC (rev 3048) @@ -15,6 +15,7 @@ #include #include "autogen_BackupProtocol.h" +#include "BackupStoreInfo.h" #include "BackupStoreRefCountDatabase.h" #include "NamedLock.h" #include "Message.h" @@ -22,7 +23,6 @@ class BackupStoreDirectory; class BackupStoreFilename; -class BackupStoreInfo; class IOStream; class BackupProtocolMessage; class StreamableMemBlock; @@ -80,6 +80,14 @@ void LoadStoreInfo(); void SaveStoreInfo(bool AllowDelay = true); const BackupStoreInfo &GetBackupStoreInfo() const; + const std::string GetAccountName() + { + if(!mapStoreInfo.get()) + { + return "Unknown"; + } + return mapStoreInfo->GetAccountName(); + } // Client marker int64_t GetClientStoreMarker(); From subversion at boxbackup.org Tue Dec 13 00:43:41 2011 From: subversion at boxbackup.org (subversion at boxbackup.org) Date: Tue, 13 Dec 2011 00:43:41 +0000 (GMT) Subject: [Box Backup-commit] COMMIT r3049 - in box/trunk: bin/bbstored lib/backupstore lib/server Message-ID: <20111213004341.E4E6D1A3A58@www.boxbackup.org> Author: chris Date: 2011-12-13 00:43:41 +0000 (Tue, 13 Dec 2011) New Revision: 3049 Modified: box/trunk/bin/bbstored/BackupStoreDaemon.cpp box/trunk/lib/backupstore/BackupCommands.cpp box/trunk/lib/backupstore/BackupStoreContext.cpp box/trunk/lib/backupstore/BackupStoreContext.h box/trunk/lib/server/ServerStream.h box/trunk/lib/server/Socket.cpp Log: Add remote host and port to post-login login message, requested by Pete Jalajas. Modified: box/trunk/bin/bbstored/BackupStoreDaemon.cpp =================================================================== --- box/trunk/bin/bbstored/BackupStoreDaemon.cpp 2011-12-12 23:36:25 UTC (rev 3048) +++ box/trunk/bin/bbstored/BackupStoreDaemon.cpp 2011-12-13 00:43:41 UTC (rev 3049) @@ -329,7 +329,7 @@ Logging::Tagger tagWithClientID(tag.str()); // Create a context, using this ID - BackupStoreContext context(id, *this); + BackupStoreContext context(id, *this, GetConnectionDetails()); if (mpTestHook) { Modified: box/trunk/lib/backupstore/BackupCommands.cpp =================================================================== --- box/trunk/lib/backupstore/BackupCommands.cpp 2011-12-12 23:36:25 UTC (rev 3048) +++ box/trunk/lib/backupstore/BackupCommands.cpp 2011-12-13 00:43:41 UTC (rev 3049) @@ -131,7 +131,8 @@ BOX_FORMAT_ACCOUNT(mClientID) << " " "(name=" << rContext.GetAccountName() << "): " << (((mFlags & Flags_ReadOnly) != Flags_ReadOnly) - ?"Read/Write":"Read-only")); + ?"Read/Write":"Read-only") << " from " << + rContext.GetConnectionDetails()); // Get the usage info for reporting to the client int64_t blocksUsed = 0, blocksSoftLimit = 0, blocksHardLimit = 0; Modified: box/trunk/lib/backupstore/BackupStoreContext.cpp =================================================================== --- box/trunk/lib/backupstore/BackupStoreContext.cpp 2011-12-12 23:36:25 UTC (rev 3048) +++ box/trunk/lib/backupstore/BackupStoreContext.cpp 2011-12-13 00:43:41 UTC (rev 3049) @@ -54,8 +54,9 @@ // // -------------------------------------------------------------------------- BackupStoreContext::BackupStoreContext(int32_t ClientID, - HousekeepingInterface &rDaemon) - : mClientID(ClientID), + HousekeepingInterface &rDaemon, const std::string& rConnectionDetails) + : mConnectionDetails(rConnectionDetails), + mClientID(ClientID), mrDaemon(rDaemon), mProtocolPhase(Phase_START), mClientHasAccount(false), Modified: box/trunk/lib/backupstore/BackupStoreContext.h =================================================================== --- box/trunk/lib/backupstore/BackupStoreContext.h 2011-12-12 23:36:25 UTC (rev 3048) +++ box/trunk/lib/backupstore/BackupStoreContext.h 2011-12-13 00:43:41 UTC (rev 3049) @@ -45,7 +45,8 @@ class BackupStoreContext { public: - BackupStoreContext(int32_t ClientID, HousekeepingInterface &rDaemon); + BackupStoreContext(int32_t ClientID, HousekeepingInterface &rDaemon, + const std::string& rConnectionDetails); ~BackupStoreContext(); private: BackupStoreContext(const BackupStoreContext &rToCopy); @@ -137,6 +138,7 @@ // Info int32_t GetClientID() const {return mClientID;} + const std::string& GetConnectionDetails() { return mConnectionDetails; } private: void MakeObjectFilename(int64_t ObjectID, std::string &rOutput, bool EnsureDirectoryExists = false); @@ -146,6 +148,7 @@ void DeleteDirectoryRecurse(int64_t ObjectID, int64_t &rBlocksDeletedOut, bool Undelete); int64_t AllocateObjectID(); + std::string mConnectionDetails; int32_t mClientID; HousekeepingInterface &mrDaemon; int mProtocolPhase; Modified: box/trunk/lib/server/ServerStream.h =================================================================== --- box/trunk/lib/server/ServerStream.h 2011-12-12 23:36:25 UTC (rev 3048) +++ box/trunk/lib/server/ServerStream.h 2011-12-13 00:43:41 UTC (rev 3049) @@ -48,6 +48,15 @@ ServerStream(const ServerStream &rToCopy) { } + + std::string mConnectionDetails; + +protected: + const std::string& GetConnectionDetails() + { + return mConnectionDetails; + } + public: virtual const char *DaemonName() const @@ -122,6 +131,10 @@ protected: virtual void NotifyListenerIsReady() { } + virtual void LogConnectionDetails(std::string details) + { + BOX_NOTICE("Handling incoming connection from " << details); + } public: virtual void Run2(bool &rChildExit) @@ -237,8 +250,9 @@ { // Get the incoming connection // (with zero wait time) - std::string logMessage; - std::auto_ptr connection(psocket->Accept(0, &logMessage)); + std::auto_ptr connection( + psocket->Accept(0, + &mConnectionDetails)); // Was there one (there should be...) if(connection.get()) @@ -264,6 +278,7 @@ // Set up daemon EnterChild(); SetProcessTitle("transaction"); + LogConnectionDetails(mConnectionDetails); // Memory leak test the forked process #ifdef BOX_MEMORY_LEAK_TESTING @@ -281,7 +296,9 @@ } // Log it - BOX_NOTICE("Message from child process " << pid << ": " << logMessage); + BOX_TRACE("Forked child process " << pid << + "to handle connection from " << + mConnectionDetails); } else { Modified: box/trunk/lib/server/Socket.cpp =================================================================== --- box/trunk/lib/server/Socket.cpp 2011-12-12 23:36:25 UTC (rev 3048) +++ box/trunk/lib/server/Socket.cpp 2011-12-13 00:43:41 UTC (rev 3049) @@ -123,27 +123,8 @@ // -------------------------------------------------------------------------- void Socket::LogIncomingConnection(const struct sockaddr *addr, socklen_t addrlen) { - if(addr == NULL) {THROW_EXCEPTION(CommonException, BadArguments)} - - switch(addr->sa_family) - { - case AF_UNIX: - BOX_INFO("Incoming connection from local (UNIX socket)"); - break; - - case AF_INET: - { - sockaddr_in *a = (sockaddr_in*)addr; - BOX_INFO("Incoming connection from " << - inet_ntoa(a->sin_addr) << " port " << - ntohs(a->sin_port)); - } - break; - - default: - BOX_WARNING("Incoming connection of unknown type"); - break; - } + BOX_INFO("Incoming connection from " << + IncomingConnectionLogMessage(addr, addrlen)); } // -------------------------------------------------------------------------- @@ -161,20 +142,25 @@ switch(addr->sa_family) { case AF_UNIX: - return std::string("Incoming connection from local (UNIX socket)"); + return std::string("local (UNIX socket)"); break; case AF_INET: { - char msg[256]; // more than enough sockaddr_in *a = (sockaddr_in*)addr; - sprintf(msg, "Incoming connection from %s port %d", inet_ntoa(a->sin_addr), ntohs(a->sin_port)); - return std::string(msg); + std::ostringstream oss; + oss << inet_ntoa(a->sin_addr) << " port " << + ntohs(a->sin_port); + return oss.str(); } break; default: - return std::string("Incoming connection of unknown type"); + { + std::ostringstream oss; + oss << "unknown socket type " << addr->sa_family; + return oss.str(); + } break; }