-
Notifications
You must be signed in to change notification settings - Fork 2
/
PluginContext.cpp
executable file
·289 lines (239 loc) · 5.63 KB
/
PluginContext.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
/*
* radiusplugin -- An OpenVPN plugin for do radius authentication
* and accounting.
*
* Copyright (C) 2005 EWE TEL GmbH/Ralf Luebben <ralfluebben@gmx.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "PluginContext.h"
/** The constructor. All sockets all set to -1, the process ids and the
* verbosity level are set to 0. The session id is set to to 1.*/
PluginContext::PluginContext()
{
this->authsocketforegr.setSocket(-1);
this->authsocketbackgr.setSocket(-1);
this->acctsocketforegr.setSocket(-1);
this->acctsocketbackgr.setSocket(-1);
this->authpid=0;
this->acctpid=0;
this->verb=0;
this->sessionid=1;
this->stopthread=false;
this->startthread=true;
}
/** The destructor clears the users and nasportlist.*/
PluginContext::~PluginContext()
{
this->users.clear();
this->nasportlist.clear();
}
/** The method searches the first free nas port in a list.
* @return The nas port.
*/
int PluginContext::addNasPort(void)
{
int newport=0;
list<int>::iterator i;
list<int>::iterator j;
i=nasportlist.begin();
j=nasportlist.end();
if (this->nasportlist.empty())
{
newport=1;
this->nasportlist.push_front(newport);
}
else
{
newport=1;
while( i != this->nasportlist.end())
{
if (newport < *i)
{
j=i;
i=this->nasportlist.end();
}
else
{
i++;
newport++;
}
}
this->nasportlist.insert(j, newport);
}
return newport;
}
/**The method deletes the nas port from the list.
* @param The nas port number to delete.
*/
void PluginContext::delNasPort(int num)
{
this->nasportlist.remove(num);
}
/**The method adds an user to the user map of the foreground
* process.
* @param newuser A pointer to the user.
* @throws Exception::ALREADYAUTHENTICATED if the user could not add to the map, this happens if a user with the key is already in the list.
*/
void PluginContext::addUser(UserPlugin * newuser)
{
pair<map<string,UserPlugin *>::iterator,bool> success;
success=users.insert(make_pair(newuser->getKey(),newuser));
if(success.second==false)
{
throw Exception(Exception::ALREADYAUTHENTICATED);
}
else
{
this->sessionid++;
}
}
/**The method deletes the user from the map with the key.
* @param key The key of the user.
*/
void PluginContext::delUser(string key)
{
users.erase(key);
}
/**The method finds a user in the user map.
* @param key The key of the user.
* @return A pointer to the user.
*/
UserPlugin * PluginContext::findUser(string key)
{
map<string,UserPlugin *>::iterator iter = users.find(key);
if (iter != users.end())
{
return iter->second;
}
return NULL;
}
/** The getter method for the verbosity level.
* @return The verbosity level.
*/
int PluginContext::getVerbosity(void)
{
return this->verb;
}
/** The setter method for the verbosisty level.
* @param v The verbosity level.
*/
void PluginContext::setVerbosity(int v)
{
this->verb=v;
}
/** The getter method for the authentication
* background process id.
* @returns The process id.
*/
pid_t PluginContext::getAuthPid(void)
{
return this->authpid;
}
/** The setter method for the authentication
* background process id.
* @param The process id.
*/
void PluginContext::setAuthPid(pid_t p)
{
this->authpid=p;
}
/** The getter method for the accounting
* background process id.
* @returns The process id.
*/
pid_t PluginContext::getAcctPid(void)
{
return this->acctpid;
}
/** The setter method for the accounting
* background process id.
* @param The process id.
*/
void PluginContext::setAcctPid(pid_t p)
{
this->acctpid=p;
}
/** The setter method method for the session id.
* @returns The sessionid.
*/
int PluginContext::getSessionId(void)
{
return this->sessionid;
}
/**The method adds an new user to the user list of users waiting for authentication
* @param newuser A pointer to the user.
*/
void PluginContext::addNewUser(UserPlugin * newuser)
{
this->newusers.push_back(newuser);
}
/**The method return the first element in the list of waiting users.
*/
UserPlugin * PluginContext::getNewUser()
{
UserPlugin * user = this->newusers.front();
this->newusers.pop_front();
return user;
}
pthread_cond_t * PluginContext::getCondSend(void )
{
return &condsend;
}
pthread_cond_t * PluginContext::getCondRecv(void )
{
return &condrecv;
}
pthread_mutex_t * PluginContext::getMutexSend(void )
{
return &mutexsend;
}
pthread_mutex_t * PluginContext::getMutexRecv(void )
{
return &mutexrecv;
}
pthread_t * PluginContext::getThread()
{
return &thread;
}
int PluginContext::getResult()
{
return result;
}
void PluginContext::setResult(int r)
{
result=r;
}
bool PluginContext::UserWaitingtoAuth()
{
if (this->newusers.size()>0) return true;
else return false;
}
bool PluginContext::getStopThread()
{
return stopthread;
}
void PluginContext::setStopThread(bool s)
{
stopthread=s;
}
bool PluginContext::getStartThread()
{
return startthread;
}
void PluginContext::setStartThread(bool value)
{
startthread=value;
}