~ubuntu-branches/ubuntu/lucid/inspircd/lucid-security

« back to all changes in this revision

Viewing changes to src/cull_list.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Giacomo Catenazzi, Darren Blaber, Matt Arnold, Giacomo Catenazzi
  • Date: 2008-03-06 07:56:47 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080306075647-z8a4phxkn3vo3ajx
Tags: 1.1.17+dfsg-1
[ Darren Blaber ]
* New upstream release, fix /etc/init.d/inspircd stop.
* Fix the postrm script so there is no duplicate update-rc.d
* Fix the manpage so there are no more errors in it

[ Matt Arnold ]
*  Fix prerm so it works (Closes: #466924)

[ Giacomo Catenazzi ]
* Added me as uploader
* Add again support of dpatch in debian/rules
* Build sources only once!
* Correct make clean target, not to include generated ./inspircd on sources
* Don't change permission of configuration files, when starting inspircd
  (separation of policy and program).

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 *       | Inspire Internet Relay Chat Daemon |
3
3
 *       +------------------------------------+
4
4
 *
5
 
 *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
 
5
 *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
6
6
 * See: http://www.inspircd.org/wiki/index.php/Credits
7
7
 *
8
8
 * This program is free but copyrighted software; see
15
15
#include "users.h"
16
16
#include "cull_list.h"
17
17
 
18
 
CullItem::CullItem(userrec* u, std::string &r, const char* o_reason)
19
 
{
20
 
        this->user = u;
21
 
        this->reason = r;
22
 
        this->silent = false;
23
 
        /* Seperate oper reason not set, use the user reason */
24
 
        if (*o_reason)
25
 
                this->oper_reason = o_reason;
26
 
        else
27
 
                this->oper_reason = r;
28
 
}
29
 
 
30
 
CullItem::CullItem(userrec* u, const char* r, const char* o_reason)
31
 
{
32
 
        this->user = u;
33
 
        this->reason = r;
34
 
        this->silent = false;
35
 
        /* Seperate oper reason not set, use the user reason */
36
 
        if (*o_reason)
37
 
                this->oper_reason = o_reason;
38
 
        else
39
 
                this->oper_reason = r;
40
 
}
41
 
 
42
 
void CullItem::MakeSilent()
43
 
{
44
 
        this->silent = true;
45
 
}
46
 
 
47
 
bool CullItem::IsSilent()
48
 
{
49
 
        return this->silent;
50
 
}
51
 
 
52
 
CullItem::~CullItem()
53
 
{
54
 
}
55
 
 
56
 
userrec* CullItem::GetUser()
57
 
{
58
 
        return this->user;
59
 
}
60
 
 
61
 
std::string& CullItem::GetReason()
62
 
{
63
 
        return this->reason;
64
 
}
65
 
 
66
 
std::string& CullItem::GetOperReason()
67
 
{
68
 
        return this->oper_reason;
69
 
}
70
 
 
71
18
CullList::CullList(InspIRCd* Instance) : ServerInstance(Instance)
72
19
{
73
20
        list.clear();
74
 
        exempt.clear();
75
21
}
76
22
 
77
23
void CullList::AddItem(userrec* user, std::string &reason, const char* o_reason)
82
28
 
83
29
void CullList::AddItem(userrec* user, const char* reason, const char* o_reason)
84
30
{
85
 
        if (exempt.find(user) == exempt.end())
86
 
        {
87
 
                CullItem item(user, reason, o_reason);
88
 
                list.push_back(item);
89
 
                exempt[user] = user;
90
 
        }
 
31
        if (user->quitting)
 
32
                return;
 
33
                
 
34
        user->quitting = true;
 
35
        user->quitmsg = reason;
 
36
        
 
37
        if (!*o_reason)
 
38
                user->operquitmsg = reason;
 
39
        else
 
40
                user->operquitmsg = o_reason;
 
41
 
 
42
        list.push_back(user);
91
43
}
92
44
 
93
45
void CullList::MakeSilent(userrec* user)
94
46
{
95
 
        for (std::vector<CullItem>::iterator a = list.begin(); a != list.end(); ++a)
96
 
        {
97
 
                if (a->GetUser() == user)
98
 
                {
99
 
                        a->MakeSilent();
100
 
                        break;
101
 
                }
102
 
        }
103
 
        return;
 
47
        user->silentquit = true;
104
48
}
105
49
 
106
50
int CullList::Apply()
107
51
{
 
52
        int i = 0;
108
53
        int n = list.size();
109
 
        while (list.size())
 
54
        
 
55
        while (list.size() && i++ != 100)
110
56
        {
111
 
                std::vector<CullItem>::iterator a = list.begin();
112
 
 
113
 
                user_hash::iterator iter = ServerInstance->clientlist->find(a->GetUser()->nick);
114
 
                std::map<userrec*, userrec*>::iterator exemptiter = exempt.find(a->GetUser());
115
 
                const char* preset_reason = a->GetUser()->GetOperQuit();
116
 
                std::string reason = a->GetReason();
117
 
                std::string oper_reason = *preset_reason ? preset_reason : a->GetOperReason();
 
57
                std::vector<userrec *>::iterator li = list.begin();
 
58
                userrec *a = (*li);
 
59
                
 
60
                user_hash::iterator iter = ServerInstance->clientlist->find(a->nick);
 
61
                std::string reason = a->quitmsg;
 
62
                std::string oper_reason = a->operquitmsg;
118
63
 
119
64
                if (reason.length() > MAXQUIT - 1)
120
65
                        reason.resize(MAXQUIT - 1);
121
66
                if (oper_reason.length() > MAXQUIT - 1)
122
67
                        oper_reason.resize(MAXQUIT - 1);
123
68
 
124
 
                if (a->GetUser()->registered != REG_ALL)
 
69
                if (a->registered != REG_ALL)
125
70
                        if (ServerInstance->unregistered_count)
126
71
                                ServerInstance->unregistered_count--;
127
72
 
128
 
                if (IS_LOCAL(a->GetUser()))
129
 
                {
130
 
                        if ((!a->GetUser()->sendq.empty()) && (!(*a->GetUser()->GetWriteError())))
131
 
                                a->GetUser()->FlushWriteBuf();
132
 
                }
133
 
 
134
 
                if (a->GetUser()->registered == REG_ALL)
135
 
                {
136
 
                        FOREACH_MOD_I(ServerInstance,I_OnUserQuit,OnUserQuit(a->GetUser(), reason, oper_reason));
137
 
                        a->GetUser()->PurgeEmptyChannels();
138
 
                        a->GetUser()->WriteCommonQuit(reason, oper_reason);
139
 
                }
140
 
 
141
 
                FOREACH_MOD_I(ServerInstance,I_OnUserDisconnect,OnUserDisconnect(a->GetUser()));
142
 
 
143
 
                if (IS_LOCAL(a->GetUser()))
144
 
                {
145
 
                        if (ServerInstance->Config->GetIOHook(a->GetUser()->GetPort()))
 
73
                if (IS_LOCAL(a))
 
74
                {
 
75
                        if ((!a->sendq.empty()) && (!(*a->GetWriteError())))
 
76
                                a->FlushWriteBuf();
 
77
                }
 
78
 
 
79
                if (a->registered == REG_ALL)
 
80
                {
 
81
                        FOREACH_MOD_I(ServerInstance,I_OnUserQuit,OnUserQuit(a, reason, oper_reason));
 
82
                        a->PurgeEmptyChannels();
 
83
                        a->WriteCommonQuit(reason, oper_reason);
 
84
                }
 
85
 
 
86
                FOREACH_MOD_I(ServerInstance,I_OnUserDisconnect,OnUserDisconnect(a));
 
87
 
 
88
                if (IS_LOCAL(a))
 
89
                {
 
90
                        if (ServerInstance->Config->GetIOHook(a->GetPort()))
146
91
                        {
147
92
                                try
148
93
                                {
149
 
                                        ServerInstance->Config->GetIOHook(a->GetUser()->GetPort())->OnRawSocketClose(a->GetUser()->GetFd());
 
94
                                        ServerInstance->Config->GetIOHook(a->GetPort())->OnRawSocketClose(a->GetFd());
150
95
                                }
151
96
                                catch (CoreException& modexcept)
152
97
                                {
154
99
                                }
155
100
                        }
156
101
 
157
 
                        ServerInstance->SE->DelFd(a->GetUser());
158
 
                        a->GetUser()->CloseSocket();
 
102
                        ServerInstance->SE->DelFd(a);
 
103
                        a->CloseSocket();
159
104
                }
160
105
 
161
106
                /*
162
107
                 * this must come before the ServerInstance->SNO->WriteToSnoMaskso that it doesnt try to fill their buffer with anything
163
108
                 * if they were an oper with +sn +qQ.
164
109
                 */
165
 
                if (a->GetUser()->registered == REG_ALL)
 
110
                if (a->registered == REG_ALL)
166
111
                {
167
 
                        if (IS_LOCAL(a->GetUser()))
 
112
                        if (IS_LOCAL(a))
168
113
                        {
169
 
                                if (!a->IsSilent())
 
114
                                if (!a->silentquit)
170
115
                                {
171
 
                                        ServerInstance->SNO->WriteToSnoMask('q',"Client exiting: %s!%s@%s [%s]",a->GetUser()->nick,a->GetUser()->ident,a->GetUser()->host,oper_reason.c_str());
 
116
                                        ServerInstance->SNO->WriteToSnoMask('q',"Client exiting: %s!%s@%s [%s]",a->nick,a->ident,a->host,oper_reason.c_str());
172
117
                                }
173
118
                        }
174
119
                        else
175
120
                        {
176
 
                                if ((!ServerInstance->SilentULine(a->GetUser()->server)) && (!a->IsSilent()))
 
121
                                if ((!ServerInstance->SilentULine(a->server)) && (!a->silentquit))
177
122
                                {
178
 
                                        ServerInstance->SNO->WriteToSnoMask('Q',"Client exiting on server %s: %s!%s@%s [%s]",a->GetUser()->server,a->GetUser()->nick,a->GetUser()->ident,a->GetUser()->host,oper_reason.c_str());
 
123
                                        ServerInstance->SNO->WriteToSnoMask('Q',"Client exiting on server %s: %s!%s@%s [%s]",a->server,a->nick,a->ident,a->host,oper_reason.c_str());
179
124
                                }
180
125
                        }
181
 
                        a->GetUser()->AddToWhoWas();
 
126
                        a->AddToWhoWas();
182
127
                }
183
128
 
184
129
                if (iter != ServerInstance->clientlist->end())
185
130
                {
186
 
                        if (IS_LOCAL(a->GetUser()))
 
131
                        if (IS_LOCAL(a))
187
132
                        {
188
 
                                std::vector<userrec*>::iterator x = find(ServerInstance->local_users.begin(),ServerInstance->local_users.end(),a->GetUser());
 
133
                                std::vector<userrec*>::iterator x = find(ServerInstance->local_users.begin(),ServerInstance->local_users.end(),a);
189
134
                                if (x != ServerInstance->local_users.end())
190
135
                                        ServerInstance->local_users.erase(x);
191
136
                        }
192
137
                        ServerInstance->clientlist->erase(iter);
193
 
                        delete a->GetUser();
 
138
                        delete a;
194
139
                }
195
140
 
196
141
                list.erase(list.begin());
197
 
                exempt.erase(exemptiter);
198
142
        }
199
143
        return n;
200
144
}