-
Notifications
You must be signed in to change notification settings - Fork 43
/
User.cpp
447 lines (407 loc) · 10.1 KB
/
User.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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
/*
* radiusplugin -- An OpenVPN plugin for do radius authentication
* and accounting.
*
* Copyright (C) 2005 EWE TEL GmbH/Ralf Luebben <[email protected]>
*
* 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 "User.h"
/** The constructor sets the acctinteriminterval and the portnumber to 0.*/
User::User()
{
this->dev="";
this->framedip="";
this->framedroutes="";
this->framedip6="";
this->framedroutes6="";
this->key="";
this->statusfilekey="";
this->untrustedport="";
// this->trustedport="";
// this->trustedip="";
this->acctinteriminterval=0;
this->portnumber=0;
this->vsabuf=NULL;
this->vsabuflen=0;
}
/** The constructor sets the acctinteriminterval to 0 and the portnumber to num.
* @param num The portnumber.*/
/*User::User(int num)
{
this->dev="";
this->framedip="";
this->framedroutes="";
this->framedip6="";
this->framedroutes6="";
this->key="";
this->untrustedport="";
this->acctinteriminterval=0;
this->portnumber=num;
this->vsabuf=NULL;
this->vsabuflen=0;
}*/
/** The destructor.*/
User::~User()
{
if(this->getVsaBufLen() > 0)
{
delete [] this->getVsaBuf();
}
}
/** The overloading of the assignment operator.
* @param u A reference to an object of the User class.
* @return A reference to the User class.*/
User & User::operator=(const User & u)
{
this->username=u.username;
this->commonname=u.commonname;
this->dev=u.dev;
this->framedip=u.framedip;
this->framedroutes=u.framedroutes;
this->framedip6=u.framedip6;
this->framedroutes6=u.framedroutes6;
this->key=u.key;
this->statusfilekey=u.statusfilekey;
this->callingstationid=u.callingstationid;
this->portnumber=u.portnumber;
this->acctinteriminterval=u.acctinteriminterval;
this->untrustedport=u.untrustedport;
this->sessionid=u.sessionid;
// this->trustedport=u.trustedport;
// this->trustedip=u.trustedip;
this->vsabuflen=u.vsabuflen;
if(u.vsabuf != NULL)
{
try{
this->vsabuf=new Octet[this->vsabuflen];
}
catch(...)
{
cerr << "RADIUS-PLUGIN: BACKGROUND ACCT: New failed for vsabuflen." << endl;
}
memcpy(this->vsabuf, u.vsabuf, this->vsabuflen);
}
else
{
this->vsabuf=u.vsabuf;
}
return *this;
}
/** The copy constructor.
* @param u A reference to an object of the User class.*/
User::User(const User & u)
{
this->username=u.username;
this->commonname=u.commonname;
this->dev=u.dev;
this->framedip=u.framedip;
this->framedroutes=u.framedroutes;
this->framedip6=u.framedip6;
this->framedroutes6=u.framedroutes6;
this->key=u.key;
this->statusfilekey=u.statusfilekey;
this->callingstationid=u.callingstationid;
this->portnumber=u.portnumber;
this->acctinteriminterval=u.acctinteriminterval;
this->untrustedport=u.untrustedport;
this->sessionid=u.sessionid;
// this->trustedport=u.trustedport;
// this->trustedip=u.trustedip;
this->vsabuflen=u.vsabuflen;
if(u.vsabuf != NULL)
{
try{
this->vsabuf=new Octet[this->vsabuflen];
}
catch(...)
{
cerr << "RADIUS-PLUGIN: BACKGROUND ACCT: New failed for vsabuflen." << endl;
}
memcpy(this->vsabuf, u.vsabuf, this->vsabuflen);
}
else
{
this->vsabuf=u.vsabuf;
}
}
/** The getter method for the username.
* @return The username as a string.*/
string User::getUsername(void)
{
return this->username;
}
/** The setter method for the username.
* @param uname The username.*/
void User::setUsername(string uname)
{
this->username=uname;
}
/** The getter method for the commonname.
* @return The commonname as a string.*/
string User::getCommonname(void)
{
return this->commonname;
}
/** The setter method for the commonname.
* @param cn The commonname.*/
void User::setCommonname(string cn)
{
this->commonname=cn;
}
/** The getter method for the device.
* @return The device as a string.*/
string User::getDev(void)
{
return this->dev;
}
/** The setter method for the device.
* @param dev The device.*/
void User::setDev(string dev)
{
this->dev=dev;
}
/** The getter method for the framed routes.
* @return The framed routes as a string.*/
string User::getFramedRoutes(void)
{
return this->framedroutes;
}
/** The setter method for the framedroutes.
* @param froutes The framedroutes, if there are more
* routes they are divided through a ';'.*/
void User::setFramedRoutes(string froutes)
{
this->framedroutes=froutes;
}
/** The getter method for the framed ip.
* @return The framed ip as a string.*/
string User::getFramedIp(void)
{
return this->framedip;
}
/** The setter method for the framedip.
* @param ip The framedip.*/
void User::setFramedIp(string ip)
{
this->framedip=ip;
}
/** The getter method for the framed IPv6 routes.
* @return The framed IPv6 routes as a string.*/
string User::getFramedRoutes6(void)
{
return this->framedroutes6;
}
/** The setter method for the framed IPv6 routes.
* @param froutes6 The framed IPv6 routes, if there are more
* routes they are divided through a ';'.*/
void User::setFramedRoutes6(string froutes6)
{
this->framedroutes6=froutes6;
}
/** The getter method for the framed IPv6.
* @return The framed IPv6 as a string.*/
string User::getFramedIp6(void)
{
return this->framedip6;
}
/** The setter method for the framedip6.
* @param ip The framedip.*/
void User::setFramedIp6(string ip)
{
this->framedip6=ip;
}
/** The getter method for the fkey.
* @return The unique key as a string.*/
string User::getKey(void)
{
return this->key;
}
/** The setter method for a unique, it is build from ip and port.
* @param key The unique key.
*/
void User::setKey(string key)
{
this->key=key;
}
/** The getter method for the status file key.
* @return The unique status file key as a string.*/
string User::getStatusFileKey(void)
{
return this->statusfilekey;
}
/** The setter method for a unique, it is build from commonname, ip and port.
* @param key The unique status file key.
*/
void User::setStatusFileKey(string key)
{
this->statusfilekey=key;
}
/** The getter method for the calling station id.
* @return The calling station id as a string.*/
string User::getCallingStationId(void)
{
return this->callingstationid;
}
/** The setter method for the callingstationid.
* @param id The callingstationid.*/
void User::setCallingStationId(string id)
{
this->callingstationid=id;
}
/** The getter method for the portnumber.
* @return The portnumber as an integer.*/
int User::getPortnumber(void)
{
return this->portnumber;
}
/** The setter method for the portnumber.
* @param port The portnumber.*/
void User::setPortnumber(int port)
{
this->portnumber=port;
}
/** The getter method for the acctinteriminterval.
* @return The acctinteriminterval as struct time_t.*/
time_t User::getAcctInterimInterval(void)
{
return this->acctinteriminterval;
}
/** The setter method for the username.
* @param t The acctinteriminterval.*/
void User::setAcctInterimInterval(time_t t)
{
this->acctinteriminterval=t;
}
/** The getter method for untrusted port.
* @return untrusted port
*/
string User::getUntrustedPort(void)
{
return this->untrustedport;
}
/**The setter method for untrusted port.
* @param The untrusted port number as string.
*/
void User::setUntrustedPort(string port)
{
this->untrustedport=port;
}
/**This method copies the octets form the vendor specific attributes to
* the buffer vsabuf. It also calculates the length of the buffer.
* @param value Pointer to vendor specific attribute.
* @param len Length of the attribute.
* @return 0 in case of no error.
*/
int User::appendVsaBuf(Octet *value, unsigned int len)
{
if(this->vsabuf == NULL)
{
try{
this->vsabuf=new Octet[len];
}
catch(...)
{
cerr << "RADIUS-PLUGIN: BACKGROUND ACCT: New failed for vsabuflen." << endl;
}
memcpy(this->vsabuf, value, len);
this->vsabuflen=len;
}
else
{
Octet old_vsa[this->vsabuflen];
memcpy(old_vsa, this->vsabuf, this->vsabuflen);
delete [] this->vsabuf;
try{
this->vsabuf=new Octet[this->vsabuflen+len];
}
catch(...)
{
cerr << "RADIUS-PLUGIN: BACKGROUND ACCT: New failed for vsabuflen." << endl;
}
memcpy(this->vsabuf, old_vsa, this->vsabuflen);
memcpy((this->vsabuf+this->vsabuflen), value, len);
this->vsabuflen=this->vsabuflen+len;
}
return 0;
}
/** Getter method for the vsabuf
* @return Pointer to the buffer.
*/
Octet * User::getVsaBuf()
{
return this->vsabuf;
}
/** Setter method for the vsabuf.
* @param pbuf Pointer to buffer.
*/
void User::setVsaBuf(Octet * pbuf)
{
this->vsabuf=pbuf;
}
/** Getter method for the buffer length.
* @return Length of the buffer.
*/
unsigned int User::getVsaBufLen()
{
return this->vsabuflen;
}
/** Setter method for the vsabuf length.
* @param len Length of the buffer.
*/
void User::setVsaBufLen(unsigned int len)
{
this->vsabuflen=len;
}
/** The getter method for the sessionid.
* @return An integer of the sessionid.*/
string User::getSessionId(void)
{
return this->sessionid;
}
/**The setter method for the sessionid.
* @param id The session id.*/
void User::setSessionId(string id)
{
this->sessionid=id;
}
/** The getter method for trusted port.
* @return trusted port
*/
// string User::getTrustedPort() const
// {
// return trustedport;
// }
/**The setter method for trusted port.
* @param The trusted port number as string.
*/
// void User::setTrustedPort ( const string& port )
// {
// trustedport = port;
// }
/** The getter method for trusted ip.
* @return trusted ip
*/
// string User::getTrustedIp() const
// {
// return trustedip;
// }
/**The setter method for trusted ip.
* @param The trusted ip as string.
*/
// void User::setTrustedIp ( const string& ip )
// {
// trustedip = ip;
// }