Skip to content

Commit

Permalink
*** empty log message ***
Browse files Browse the repository at this point in the history
  • Loading branch information
ralfluebben committed Feb 15, 2009
1 parent 23807da commit 8f18e24
Show file tree
Hide file tree
Showing 24 changed files with 1,849 additions and 1,199 deletions.
58 changes: 29 additions & 29 deletions AccountingProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ void AccountingProcess::Accounting(PluginContext * context)
}
catch (Exception &e)
{
cerr << "RADIUS-PLUGIN: BACKGROUND-ACCT:" << e <<"\n";
cerr << getTime() << "RADIUS-PLUGIN: BACKGROUND-ACCT:" << e <<"\n";
goto done;
}

if (DEBUG (context->getVerbosity()))
cerr << "RADIUS-PLUGIN: BACKGROUND ACCT: Started, RESPONSE_INIT_SUCCEEDED was sent to Foreground Process.\n";
cerr << getTime() << "RADIUS-PLUGIN: BACKGROUND ACCT: Started, RESPONSE_INIT_SUCCEEDED was sent to Foreground Process.\n";


// Event loop
Expand All @@ -75,7 +75,7 @@ void AccountingProcess::Accounting(PluginContext * context)
command = context->acctsocketforegr.recvInt();

if (DEBUG (context->getVerbosity()))
cerr << "RADIUS-PLUGIN: BACKGROUND ACCT: Get a command.\n";
cerr << getTime() << "RADIUS-PLUGIN: BACKGROUND ACCT: Get a command.\n";

switch (command)
{
Expand All @@ -85,7 +85,7 @@ void AccountingProcess::Accounting(PluginContext * context)
{

if (DEBUG (context->getVerbosity()))
cerr << "RADIUS-PLUGIN: BACKGROUND ACCT: New User.\n";
cerr << getTime() << "RADIUS-PLUGIN: BACKGROUND ACCT: New User.\n";

//allocate memory
user= new UserAcct;
Expand All @@ -103,7 +103,7 @@ void AccountingProcess::Accounting(PluginContext * context)
user->setUntrustedPort(context->acctsocketforegr.recvStr());
context->acctsocketforegr.recvBuf(user);
if (DEBUG (context->getVerbosity()))
cerr << "RADIUS-PLUGIN: BACKGROUND ACCT: New user acct: username: " << user->getUsername() << ", interval: " << user->getAcctInterimInterval() << ", calling station: " << user->getCallingStationId() << ", commonname: " << user->getCommonname() << ", framed ip: " << user->getFramedIp() <<".\n";
cerr << getTime() << "RADIUS-PLUGIN: BACKGROUND ACCT: New user acct: username: " << user->getUsername() << ", interval: " << user->getAcctInterimInterval() << ", calling station: " << user->getCallingStationId() << ", commonname: " << user->getCommonname() << ", framed ip: " << user->getFramedIp() <<".\n";


//set the starttime
Expand All @@ -117,10 +117,10 @@ void AccountingProcess::Accounting(PluginContext * context)
{

if (DEBUG (context->getVerbosity()))
cerr << "RADIUS-PLUGIN: BACKGROUND ACCT: Start packet was send.\n";
cerr << getTime() << "RADIUS-PLUGIN: BACKGROUND ACCT: Start packet was send.\n";

if (DEBUG (context->getVerbosity()))
cerr << "RADIUS-PLUGIN: BACKGROUND ACCT: User was added to accounting scheduler.\n";
cerr << getTime() << "RADIUS-PLUGIN: BACKGROUND ACCT: User was added to accounting scheduler.\n";

//set the system routes
user->addSystemRoutes(context);
Expand All @@ -131,7 +131,7 @@ void AccountingProcess::Accounting(PluginContext * context)
if(script.length() > 0)
{
if (DEBUG (context->getVerbosity()))
cerr << "RADIUS-PLUGIN: BACKGROUND ACCT: Call vendor specific attribute script.\n";
cerr << getTime() << "RADIUS-PLUGIN: BACKGROUND ACCT: Call vendor specific attribute script.\n";
if(callVsaScript(context, user, 1, 0) != 0)
{
throw Exception("Vendor specific attribute script failed.\n");
Expand All @@ -157,19 +157,19 @@ void AccountingProcess::Accounting(PluginContext * context)
}
catch (Exception &e)
{
cerr << "RADIUS-PLUGIN: BACKGROUND ACCT: "<< e << "!\n";
cerr << getTime() << "RADIUS-PLUGIN: BACKGROUND ACCT: "<< e << "!\n";
context->acctsocketforegr.send(RESPONSE_FAILED);
//close the background process, if the ipc socket is bad
if (e.getErrnum()==Exception::SOCKETSEND || e.getErrnum()==Exception::SOCKETRECV)
{
cerr << "RADIUS-PLUGIN: BACKGROUND ACCT: Error in socket!\n";
cerr << getTime() << "RADIUS-PLUGIN: BACKGROUND ACCT: Error in socket!\n";
goto done;
}
}
catch (...)
{
context->acctsocketforegr.send(RESPONSE_FAILED);
cerr << "RADIUS-PLUGIN: BACKGROUND ACCT: Unknown Exception!\n";
cerr << getTime() << "RADIUS-PLUGIN: BACKGROUND ACCT: Unknown Exception!\n";
}
delete user;
break;
Expand All @@ -178,7 +178,7 @@ void AccountingProcess::Accounting(PluginContext * context)
case DEL_USER:

if (DEBUG (context->getVerbosity()))
cerr << "RADIUS-PLUGIN: BACKGROUND-ACCT: Delete user from accounting.\n";
cerr << getTime() << "RADIUS-PLUGIN: BACKGROUND-ACCT: Delete user from accounting.\n";

//receive the information
try
Expand All @@ -187,7 +187,7 @@ void AccountingProcess::Accounting(PluginContext * context)
}
catch(Exception &e)
{
cerr << "RADIUS-PLUGIN: BACKGROUND ACCT: "<< e << "!\n";
cerr << getTime() << "RADIUS-PLUGIN: BACKGROUND ACCT: "<< e << "!\n";
//close the background process, if the ipc socket is bad
if (e.getErrnum()==Exception::SOCKETSEND || e.getErrnum()==Exception::SOCKETRECV)
{
Expand All @@ -196,7 +196,7 @@ void AccountingProcess::Accounting(PluginContext * context)
}
catch (...)
{
cerr << "RADIUS-PLUGIN: BACKGROUND ACCT: Unknown Exception!\n";
cerr << getTime() << "RADIUS-PLUGIN: BACKGROUND ACCT: Unknown Exception!\n";
}

//find the user, he must be already there
Expand All @@ -205,7 +205,7 @@ void AccountingProcess::Accounting(PluginContext * context)
if (user)
{
if (DEBUG (context->getVerbosity()))
cerr << "RADIUS-PLUGIN: BACKGROUND ACCT: Stop acct: username: " << user->getUsername()<< ", calling station: " << user->getCallingStationId()<< ", commonname: " << user->getCommonname() << ".\n";
cerr << getTime() << "RADIUS-PLUGIN: BACKGROUND ACCT: Stop acct: username: " << user->getUsername()<< ", calling station: " << user->getCallingStationId()<< ", commonname: " << user->getCommonname() << ".\n";

//delete the system routes
user->delSystemRoutes(context);
Expand All @@ -219,7 +219,7 @@ void AccountingProcess::Accounting(PluginContext * context)
{
//string command= context->conf.getVsaScript() + string(" ") + string("ACTION=CLIENT_CONNECT")+string(" ")+string("USERNAME=")+user->getUsername()+string(" ")+string("COMMONNAME=")+user->getCommonname()+string(" ")+string("UNTRUSTED_IP=")+user->getCallingStationId() + string(" ") + string("UNTRUSTED_PORT=") + user->getUntrustedPort() + user->getVsaString();
if (DEBUG (context->getVerbosity()))
cerr << "RADIUS-PLUGIN: BACKGROUND ACCT: Call vendor specific attribute script.\n";
cerr << getTime() << "RADIUS-PLUGIN: BACKGROUND ACCT: Call vendor specific attribute script.\n";
if(callVsaScript(context, user, 1, 0) != 0)
{
throw Exception("Vendor specific attribute script failed.\n");
Expand All @@ -232,7 +232,7 @@ void AccountingProcess::Accounting(PluginContext * context)
scheduler.delUser(context, user);

if (DEBUG (context->getVerbosity()))
cerr << "RADIUS-PLUGIN: BACKGROUND ACCT: User with key: " << key << " was deleted from accouting.\n";
cerr << getTime() << "RADIUS-PLUGIN: BACKGROUND ACCT: User with key: " << key << " was deleted from accouting.\n";

//send the parent process the ok
context->acctsocketforegr.send(RESPONSE_SUCCEEDED);
Expand All @@ -241,17 +241,17 @@ void AccountingProcess::Accounting(PluginContext * context)
}
catch(Exception &e)
{
cerr << "RADIUS-PLUGIN: BACKGROUND-ACCT: " << e << "\n";
cerr << getTime() << "RADIUS-PLUGIN: BACKGROUND-ACCT: " << e << "\n";
goto done;
}
catch (...)
{
cerr << "RADIUS-PLUGIN: BACKGROUND ACCT: Unknown Exception!\n";
cerr << getTime() << "RADIUS-PLUGIN: BACKGROUND ACCT: Unknown Exception!\n";
}
}
else
{
cerr << "RADIUS-PLUGIN: BACKGROUND ACCT: No user with this key "<< key <<".\n";
cerr << getTime() << "RADIUS-PLUGIN: BACKGROUND ACCT: No user with this key "<< key <<".\n";
context->acctsocketforegr.send(RESPONSE_FAILED);

}
Expand All @@ -260,15 +260,15 @@ void AccountingProcess::Accounting(PluginContext * context)
//exit the loop
case COMMAND_EXIT:
if (DEBUG (context->getVerbosity()))
cerr << "RADIUS-PLUGIN: BACKGROUND-ACCT: Get command exit.\n";
cerr << getTime() << "RADIUS-PLUGIN: BACKGROUND-ACCT: Get command exit.\n";
goto done;

case -1:
cerr << "RADIUS-PLUGIN: BACKGROUND: read error on command channel.\n";
cerr << getTime() << "RADIUS-PLUGIN: BACKGROUND: read error on command channel.\n";
break;

default:
cerr << "RADIUS-PLUGIN: BACKGROUND: unknown command code: code= "<< command <<", exiting.\n";
cerr << getTime() << "RADIUS-PLUGIN: BACKGROUND: unknown command code: code= "<< command <<", exiting.\n";
goto done;


Expand All @@ -282,7 +282,7 @@ void AccountingProcess::Accounting(PluginContext * context)
//end the process
if(1)
scheduler.delallUsers(context);
cerr << "RADIUS-PLUGIN: BACKGROUND ACCT: EXIT\n";
cerr << getTime() << "RADIUS-PLUGIN: BACKGROUND ACCT: EXIT\n";
return;
}

Expand Down Expand Up @@ -459,31 +459,31 @@ int AccountingProcess::callVsaScript(PluginContext * context, User * user, unsig
/* FIFO bereits vorhanden - kein fataler Fehler */
if(errno == EEXIST)
{
cerr << "RADIUS-PLUGIN:FIFO already exist.";
cerr << getTime() << "RADIUS-PLUGIN:FIFO already exist.";
}
else
{
cerr <<"RADIUS-PLUGIN: Error in mkfifio()";
cerr << getTime() <<"RADIUS-PLUGIN: Error in mkfifio()";
return -1;
}
}
int fd_fifo=open(context->conf.getVsaNamedPipe().c_str(), O_RDWR | O_NONBLOCK);

if (fd_fifo == -1)
{
cerr <<"RADIUS-PLUGIN: Error in opening pipe to VSAScript.";
cerr << getTime() <<"RADIUS-PLUGIN: Error in opening pipe to VSAScript.";
return -1;
}
string exe=string(context->conf.getVsaScript()) + " " + string(context->conf.getVsaNamedPipe());
if (write (fd_fifo, buf, buflen) != buflen)
{
cerr << "RADIUS-PLUGIN: Could not write in Pipe to VSAScript!";
cerr << getTime() << "RADIUS-PLUGIN: Could not write in Pipe to VSAScript!";
return -1;
}

if(system(exe.c_str())!=0)
{
cerr << "RADIUS-PLUGIN: Error in VSAScript!";
cerr << getTime() << "RADIUS-PLUGIN: Error in VSAScript!";
return -1;
}
close(fd_fifo);
Expand Down
18 changes: 9 additions & 9 deletions AcctScheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,18 @@ void AcctScheduler::delUser(PluginContext * context, UserAcct *user)
user->setGigaOut(bytesout >> 32);

if (DEBUG (context->getVerbosity()))
cerr << "RADIUS-PLUGIN: BACKGROUND-ACCT: Got accouting data from file, CN: " << user->getCommonname() << " in: " << user->getBytesIn() << " out: " << user->getBytesOut() << ".\n";
cerr << getTime() << "RADIUS-PLUGIN: BACKGROUND-ACCT: Got accouting data from file, CN: " << user->getCommonname() << " in: " << user->getBytesIn() << " out: " << user->getBytesOut() << ".\n";


//send the stop ticket
if (user->sendStopPacket(context)==0)
{
if (DEBUG (context->getVerbosity()))
cerr << "RADIUS-PLUGIN: BACKGROUND-ACCT: Stop packet was sent. CN: " << user->getCommonname() << ".\n";
cerr << getTime() << "RADIUS-PLUGIN: BACKGROUND-ACCT: Stop packet was sent. CN: " << user->getCommonname() << ".\n";
}
else
{
cerr << "RADIUS-PLUGIN: BACKGROUND-ACCT: Error on sending stop packet.";
cerr << getTime() << "RADIUS-PLUGIN: BACKGROUND-ACCT: Error on sending stop packet.";
}

if (user->getAcctInterimInterval()==0)
Expand All @@ -120,7 +120,7 @@ void AcctScheduler::delallUsers(PluginContext * context)
{
map<string, UserAcct>::iterator iter1, iter2;
if (DEBUG (context->getVerbosity()))
cerr << "RADIUS-PLUGIN: BACKGROUND-ACCT: Delete all users.";
cerr << getTime() << "RADIUS-PLUGIN: BACKGROUND-ACCT: Delete all users.";
iter1=activeuserlist.begin();
iter2=activeuserlist.end();

Expand Down Expand Up @@ -160,7 +160,7 @@ void AcctScheduler::doAccounting(PluginContext * context)
if ( t>=iter1->second.getNextUpdate())
{
if (DEBUG (context->getVerbosity()))
cerr << "RADIUS-PLUGIN: BACKGROUND-ACCT: Scheduler: Update for User " << iter1->second.getUsername() << ".\n";
cerr << getTime() << "RADIUS-PLUGIN: BACKGROUND-ACCT: Scheduler: Update for User " << iter1->second.getUsername() << ".\n";

this->parseStatusFile(context, &bytesin, &bytesout,iter1->second.getKey().c_str());
iter1->second.setBytesIn(bytesin & 0xFFFFFFFF);
Expand All @@ -170,7 +170,7 @@ void AcctScheduler::doAccounting(PluginContext * context)
iter1->second.sendUpdatePacket(context);

if (DEBUG (context->getVerbosity()))
cerr << "RADIUS-PLUGIN: BACKGROUND-ACCT: Scheduler: Update packet for User " << iter1->second.getUsername() << " was send.\n";
cerr << getTime() << "RADIUS-PLUGIN: BACKGROUND-ACCT: Scheduler: Update packet for User " << iter1->second.getUsername() << " was send.\n";

//calculate the next update
iter1->second.setNextUpdate(iter1->second.getNextUpdate()+iter1->second.getAcctInterimInterval());
Expand Down Expand Up @@ -199,7 +199,7 @@ void AcctScheduler::parseStatusFile(PluginContext *context, uint64_t *bytesin, u
if (file.is_open())
{
if (DEBUG (context->getVerbosity()))
fprintf (stderr, "RADIUS-PLUGIN: BACKGROUND ACCT: Scheduler: Read Statusfile.\n");
cerr << getTime() << "RADIUS-PLUGIN: BACKGROUND ACCT: Scheduler: Read Statusfile.\n";

//find the key, is delimited with a ',' from the informations

Expand All @@ -224,14 +224,14 @@ void AcctScheduler::parseStatusFile(PluginContext *context, uint64_t *bytesin, u
else
{

cerr << "RADIUS-PLUGIN: BACKGROUND ACCT: No accounting data was found for "<< key <<".\n";
cerr << getTime() << "RADIUS-PLUGIN: BACKGROUND ACCT: No accounting data was found for "<< key <<".\n";

}
file.close();
}
else
{
cerr << "RADIUS-PLUGIN: BACKGROUND-ACCT: Statusfile "<< context->conf.getStatusFile() <<" could not opened.\n";
cerr << getTime() << "RADIUS-PLUGIN: BACKGROUND-ACCT: Statusfile "<< context->conf.getStatusFile() <<" could not opened.\n";
}
}

Expand Down
18 changes: 9 additions & 9 deletions AuthenticationProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ void AuthenticationProcess::Authentication(PluginContext * context)
}
catch(Exception &e)
{
cerr << "RADIUS-PLUGIN: BACKGROUND AUTH:" << e <<"\n";
cerr << getTime() << "RADIUS-PLUGIN: BACKGROUND AUTH:" << e <<"\n";
goto done;
}
if (DEBUG (context->getVerbosity()))
cerr << "RADIUS-PLUGIN: BACKGROUND AUTH: Started, RESPONSE_INIT_SUCCEEDED was sent to Foreground Process.\n";
cerr << getTime() << "RADIUS-PLUGIN: BACKGROUND AUTH: Started, RESPONSE_INIT_SUCCEEDED was sent to Foreground Process.\n";
// Event loop
while (1)
{
Expand All @@ -80,10 +80,10 @@ void AuthenticationProcess::Authentication(PluginContext * context)
user->setFramedIp(context->authsocketforegr.recvStr());

if (DEBUG (context->getVerbosity()) && (user->getFramedIp().compare("") == 0))
cerr << "RADIUS-PLUGIN: BACKGROUND AUTH: New user auth: username: " << user->getUsername() << ", password: *****, calling station: " << user->getCallingStationId() << ", commonname: " << user->getCommonname() << ".\n";
cerr << getTime() << "RADIUS-PLUGIN: BACKGROUND AUTH: New user auth: username: " << user->getUsername() << ", password: *****, calling station: " << user->getCallingStationId() << ", commonname: " << user->getCommonname() << ".\n";

if (DEBUG (context->getVerbosity()) && (user->getFramedIp().compare("") !=0 ))
cerr << "RADIUS-PLUGIN: BACKGROUND AUTH: Old user ReAuth: username: " << user->getUsername() << ", password: *****, calling station: " << user->getCallingStationId() << ", commonname: " << user->getCommonname() << ".\n";
cerr << getTime() << "RADIUS-PLUGIN: BACKGROUND AUTH: Old user ReAuth: username: " << user->getUsername() << ", password: *****, calling station: " << user->getCallingStationId() << ", commonname: " << user->getCommonname() << ".\n";

//send the AcceptRequestPacket
if (user->sendAcceptRequestPacket(context)==0) /* Succeeded */
Expand Down Expand Up @@ -116,7 +116,7 @@ void AuthenticationProcess::Authentication(PluginContext * context)
delete user;

if (DEBUG (context->getVerbosity()))
fprintf (stderr, "RADIUS-PLUGIN: BACKGROUND AUTH: Auth succeeded in radius_server().\n");
cerr << getTime() << "RADIUS-PLUGIN: BACKGROUND AUTH: Auth succeeded in radius_server().\n";



Expand All @@ -129,7 +129,7 @@ void AuthenticationProcess::Authentication(PluginContext * context)
}
catch (Exception &e)
{
cerr << e;
cerr << getTime() << e;
delete user;
if (e.getErrnum()==Exception::SOCKETSEND || e.getErrnum()==Exception::SOCKETRECV)
{
Expand All @@ -149,18 +149,18 @@ void AuthenticationProcess::Authentication(PluginContext * context)
goto done;

case -1:
cerr << "RADIUS-PLUGIN: BACKGROUND AUTH: read error on command channel.\n";
cerr << getTime() << "RADIUS-PLUGIN: BACKGROUND AUTH: read error on command channel.\n";
break;

default:
cerr << "RADIUS-PLUGIN: BACKGROUND AUTH: unknown command code: code="<<command<<", exiting.\n";
cerr << getTime() << "RADIUS-PLUGIN: BACKGROUND AUTH: unknown command code: code="<<command<<", exiting.\n";
goto done;
}
}
done:

if (1)
cerr << "RADIUS-PLUGIN: BACKGROUND AUTH: EXIT\n";
cerr << getTime() << "RADIUS-PLUGIN: BACKGROUND AUTH: EXIT\n";

return;
}
Expand Down
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,10 @@ radiusplugin_2.0d_beta:
- add some some headerfiles to avoid compiling errors on Fedora with gcc4
- close socket in radiuspacket.cpp on retries
- add parenthesize to avoid compiler warnings

radiusplugin_2.1_beta:
- Support for OPENVPN_PLUGIN_FUNC_DEFERRED, the authentication is done a thread if an auth_control_file is defined.
-- The OpenVPN process needs write permission in the OpenVPN directory.
- Timestamps are included in the debug information.


4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ FAILED =[$(RED) failed $(ESC)]
CC=g++
INCL=
LDFLAGS=
LIBS=-lgcrypt
LIBS=-lgcrypt -lpthread
CFLAGS=-Wall -shared
PLUGIN=radiusplugin.so
OBJECTS=\
Expand Down Expand Up @@ -41,5 +41,7 @@ $(PLUGIN): $(OBJECTS)
@echo -e 'OBJ: $(GREEN) $@ $(ESC)'
@$(CC) $(INCL) $(CFLAGS) -o $@ -c $<

test: $(OBJECTS)
@$(CC) -Wall $(OBJECTS) -o main $(LDFLAGS) $(LIBS)
clean:
-rm $(PLUGIN) *.o */*.o
Loading

0 comments on commit 8f18e24

Please sign in to comment.