~vanhoof/+junk/znc

« back to all changes in this revision

Viewing changes to ClientCommand.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Patrick Matthäi
  • Date: 2009-07-24 13:46:00 UTC
  • mfrom: (1.2.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20090724134600-uaxedj9f92i72ru1
Tags: 0.074-1
* New upstream release.
  - Bump urgency to high. This release fixes an high-impact directory
    traversal buf, where unpriviliged users can save about DCC SEND files on
    the server with the rights of the znc process. The attacker could also
    use the exploit to get a shell on the server.
    Closes: #537977
  - Use c-ares for DNS resolving, add libc-ares-dev and pkg-config as
    build-dependency.
* Merge 0.058-2+lenny2, 0.058-2+lenny3, 0.070-1~bpo40+1 and 0.070-1~bpo50+1
  changelog.
* Bump Standards-Version to 3.8.2 (no changes needed).

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
#include "User.h"
16
16
#include "znc.h"
17
17
 
18
 
void CClient::UserCommand(const CString& sLine) {
 
18
void CClient::UserCommand(CString& sLine) {
19
19
        if (!m_pUser) {
20
20
                return;
21
21
        }
24
24
                return;
25
25
        }
26
26
 
 
27
        MODULECALL(OnStatusCommand(sLine), m_pUser, this, return);
 
28
 
27
29
        CString sCommand = sLine.Token(0);
28
30
 
29
31
        if (sCommand.Equals("HELP")) {
395
397
                        return;
396
398
                }
397
399
 
398
 
                sAbsolutePath = CDir::ChangeDir(m_pUser->GetDLPath(), sFile, CZNC::Get().GetHomePath());
 
400
                sAbsolutePath = CDir::CheckPathPrefix(sAllowedPath, sFile);
399
401
 
400
 
                if (sAbsolutePath.Left(sAllowedPath.length()) != sAllowedPath) {
 
402
                if (sAbsolutePath.empty()) {
401
403
                        PutStatus("Illegal path.");
402
404
                        return;
403
405
                }
413
415
                        return;
414
416
                }
415
417
 
416
 
                sAbsolutePath = CDir::ChangeDir(m_pUser->GetDLPath(), sFile, CZNC::Get().GetHomePath());
 
418
                sAbsolutePath = CDir::CheckPathPrefix(sAllowedPath, sFile);
417
419
 
418
 
                if (sAbsolutePath.Left(sAllowedPath.length()) != sAllowedPath) {
 
420
                if (sAbsolutePath.empty()) {
419
421
                        PutStatus("Illegal path.");
420
422
                        return;
421
423
                }
928
930
 
929
931
                PutStatus("BufferCount for [" + sChan + "] set to [" + CString(pChan->GetBufferCount()) + "]");
930
932
        } else if (m_pUser->IsAdmin() && sCommand.Equals("TRAFFIC")) {
931
 
                CZNC::Get().UpdateTrafficStats();
932
 
                const map<CString, CUser*>& msUsers = CZNC::Get().GetUserMap();
 
933
                CZNC::TrafficStatsPair Users, ZNC, Total;
 
934
                CZNC::TrafficStatsMap traffic = CZNC::Get().GetTrafficStats(Users, ZNC, Total);
 
935
                CZNC::TrafficStatsMap::const_iterator it;
 
936
 
933
937
                CTable Table;
934
938
                Table.AddColumn("Username");
935
939
                Table.AddColumn("In");
936
940
                Table.AddColumn("Out");
937
941
                Table.AddColumn("Total");
938
 
                unsigned long long users_total_in = 0;
939
 
                unsigned long long users_total_out = 0;
940
 
                for (map<CString, CUser*>::const_iterator it = msUsers.begin(); it != msUsers.end(); it++) {
 
942
 
 
943
                for (it = traffic.begin(); it != traffic.end(); it++) {
941
944
                        Table.AddRow();
942
945
                        Table.SetCell("Username", it->first);
943
 
                        Table.SetCell("In", CString::ToByteStr(it->second->BytesRead()));
944
 
                        Table.SetCell("Out", CString::ToByteStr(it->second->BytesWritten()));
945
 
                        Table.SetCell("Total", CString::ToByteStr(it->second->BytesRead() + it->second->BytesWritten()));
946
 
                        users_total_in += it->second->BytesRead();
947
 
                        users_total_out += it->second->BytesWritten();
 
946
                        Table.SetCell("In", CString::ToByteStr(it->second.first));
 
947
                        Table.SetCell("Out", CString::ToByteStr(it->second.second));
 
948
                        Table.SetCell("Total", CString::ToByteStr(it->second.first + it->second.second));
948
949
                }
 
950
 
949
951
                Table.AddRow();
950
952
                Table.SetCell("Username", "<Users>");
951
 
                Table.SetCell("In", CString::ToByteStr(users_total_in));
952
 
                Table.SetCell("Out", CString::ToByteStr(users_total_out));
953
 
                Table.SetCell("Total", CString::ToByteStr(users_total_in + users_total_out));
 
953
                Table.SetCell("In", CString::ToByteStr(Users.first));
 
954
                Table.SetCell("Out", CString::ToByteStr(Users.second));
 
955
                Table.SetCell("Total", CString::ToByteStr(Users.first + Users.second));
954
956
 
955
957
                Table.AddRow();
956
958
                Table.SetCell("Username", "<ZNC>");
957
 
                Table.SetCell("In", CString::ToByteStr(CZNC::Get().BytesRead()));
958
 
                Table.SetCell("Out", CString::ToByteStr(CZNC::Get().BytesWritten()));
959
 
                Table.SetCell("Total", CString::ToByteStr(CZNC::Get().BytesRead() + CZNC::Get().BytesWritten()));
 
959
                Table.SetCell("In", CString::ToByteStr(ZNC.first));
 
960
                Table.SetCell("Out", CString::ToByteStr(ZNC.second));
 
961
                Table.SetCell("Total", CString::ToByteStr(ZNC.first + ZNC.second));
960
962
 
961
963
                Table.AddRow();
962
964
                Table.SetCell("Username", "<Total>");
963
 
                Table.SetCell("In", CString::ToByteStr(users_total_in + CZNC::Get().BytesRead()));
964
 
                Table.SetCell("Out", CString::ToByteStr(users_total_out + CZNC::Get().BytesWritten()));
965
 
                Table.SetCell("Total", CString::ToByteStr(users_total_in + CZNC::Get().BytesRead() + users_total_out + CZNC::Get().BytesWritten()));
 
965
                Table.SetCell("In", CString::ToByteStr(Total.first));
 
966
                Table.SetCell("Out", CString::ToByteStr(Total.second));
 
967
                Table.SetCell("Total", CString::ToByteStr(Total.first + Total.second));
966
968
 
967
969
                PutStatus(Table);
968
 
        } else if (m_pUser->IsAdmin() && sCommand.Equals("UPTIME")) {
 
970
        } else if (sCommand.Equals("UPTIME")) {
969
971
                PutStatus("Running for " + CZNC::Get().GetUptime());
970
972
        } else {
971
973
                PutStatus("Unknown command [" + sCommand + "] try 'Help'");
1119
1121
        Table.SetCell("Arguments", "<file>");
1120
1122
        Table.SetCell("Description", "Send a shell file to yourself");
1121
1123
 
 
1124
        Table.AddRow();
 
1125
        Table.SetCell("Command", "Uptime");
 
1126
        Table.SetCell("Arguments", "");
 
1127
        Table.SetCell("Description", "Show how long ZNC is already running");
 
1128
 
1122
1129
        if (!m_pUser->DenyLoadMod()) {
1123
1130
                Table.AddRow();
1124
1131
                Table.SetCell("Command", "LoadMod");
1190
1197
                Table.SetCell("Description", "Show basic traffic stats for all znc users");
1191
1198
 
1192
1199
                Table.AddRow();
1193
 
                Table.SetCell("Command", "Uptime");
1194
 
                Table.SetCell("Arguments", "");
1195
 
                Table.SetCell("Description", "Show how long ZNC is already running");
1196
 
 
1197
 
                Table.AddRow();
1198
1200
                Table.SetCell("Command", "Broadcast");
1199
1201
                Table.SetCell("Arguments", "[message]");
1200
1202
                Table.SetCell("Description", "Broadcast a message to all users");