[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Radiusplugin-devel] PATCH - add CCD template support
From: |
Evgheni Dereveanchin |
Subject: |
[Radiusplugin-devel] PATCH - add CCD template support |
Date: |
Thu, 18 Apr 2013 18:34:34 +0300 |
Hi,
Below you can find a patch that adds CCD file template support to radiusplugin.
If a template is found, its contents are written to the actual CCD before the
information that RADIUS sent.
The patch is against v2.1a_beta1.
diff -rupN radiusplugin_v2.1a_beta1/Config.cpp
radiusplugin_v2.1a_beta1_mod/Config.cpp
--- radiusplugin_v2.1a_beta1/Config.cpp 2010-09-02 13:38:52.000000000 +0300
+++ radiusplugin_v2.1a_beta1_mod/Config.cpp 2013-04-17 20:49:39.522000266
+0300
@@ -36,6 +36,7 @@ Config::Config(void)
this->accountingonly=false;
this->nonfatalaccounting=false;
this->ccdPath="";
+ this->templateDir="";
this->openvpnconfig="";
this->vsanamedpipe="";
this->vsascript="";
@@ -118,6 +119,10 @@ int Config::parseConfigFile(const char *
{
this->vsascript=line.substr(10,line.size()-10);
}
+ if (strncmp(line.c_str(),"templatedir=",12)==0)
+ {
+
this->setTemplateDir(line.substr(12,line.size()-12));
+ }
if (strncmp(line.c_str(),"vsanamedpipe=",13)==0)
{
this->vsanamedpipe=line.substr(13,line.size()-13);
@@ -348,6 +353,20 @@ void Config::setCcdPath(string path)
this->ccdPath=path;
}
+string Config::getTemplateDir( void )
+{
+ return this->templateDir;
+}
+
+void Config::setTemplateDir (string path)
+{
+ if(path[path.length()]!= '/')
+ {
+ path +='/';
+ }
+ this->templateDir=path;
+}
+
/** Returns the path to the status file.
* @param A string to path of the status file.
*/
diff -rupN radiusplugin_v2.1a_beta1/Config.h
radiusplugin_v2.1a_beta1_mod/Config.h
--- radiusplugin_v2.1a_beta1/Config.h 2010-09-02 13:35:23.000000000 +0300
+++ radiusplugin_v2.1a_beta1_mod/Config.h 2013-04-17 19:34:39.657911103
+0300
@@ -48,6 +48,7 @@ private:
bool usernameascommonname; /**<Use the username as
commonname in the plugin (for OpenVPN option username-as-common-name (no
commonname in the enviroment!)).*/
bool clientcertnotrequired; /**<For OpenVPN option
client_cert_not_required, commonname = UNDEF.*/
string openvpnconfig; /**<Path to OpenVPN config.*/
+ string templateDir; /* Path to templates directory*/
bool overwriteccfiles; /**<If true the plugin
overwrites the client config files.*/
bool useauthcontrolfile; /**<If true and the OpenVPN
version supports auth control files, the acf is used.*/
bool accountingonly; /**<Only the accounting is done
by the plugin.*/
@@ -79,7 +80,10 @@ public:
string getVsaScript(void);
void setVsaScript(string);
-
+
+ string getTemplateDir(void);
+ void setTemplateDir(string);
+
string getVsaNamedPipe(void);
void setVsaNamedPipe(string);
diff -rupN radiusplugin_v2.1a_beta1/radiusplugin.cnf
radiusplugin_v2.1a_beta1_mod/radiusplugin.cnf
--- radiusplugin_v2.1a_beta1/radiusplugin.cnf 2010-09-02 13:31:40.000000000
+0300
+++ radiusplugin_v2.1a_beta1_mod/radiusplugin.cnf 2013-04-18
18:28:25.641615798 +0300
@@ -21,6 +21,7 @@ NAS-IP-Address=127.0.0.1
OpenVPNConfig=/etc/openvpn/server.conf
+templatedir=/etc/openvpn/ccd-templates
# Support for topology option in OpenVPN 2.1
# If you don't specify anything, option "net30" (default in OpenVPN) is used.
diff -rupN radiusplugin_v2.1a_beta1/UserAuth.cpp
radiusplugin_v2.1a_beta1_mod/UserAuth.cpp
--- radiusplugin_v2.1a_beta1/UserAuth.cpp 2010-04-02 08:37:59.000000000
+0300
+++ radiusplugin_v2.1a_beta1_mod/UserAuth.cpp 2013-04-17 20:46:59.645742759
+0300
@@ -1482,6 +1482,7 @@ string UserAuth::valueToString(RadiusVen
int UserAuth::createCcdFile(PluginContext *context)
{
ofstream ccdfile;
+ ifstream templatefile;
char * route;
char framedip[16];
@@ -1489,6 +1490,7 @@ int UserAuth::createCcdFile(PluginContex
in_addr_t ip2;
in_addr ip3;
string filename;
+ string templatename;
char framedroutes[4096];
char framednetmask_cidr[3]; // ->/24
char framednetmask[16]; // ->255.255.255.0
@@ -1509,19 +1511,37 @@ int UserAuth::createCcdFile(PluginContex
memset(framedroutes,0,4096);
//create the filename, ccd-path + commonname
- filename=context->conf.getCcdPath()+this->getCommonname();
-
+
templatename=context->conf.getTemplateDir()+this->getCommonname();
if (DEBUG (context->getVerbosity()))
- cerr << getTime() << "RADIUS-PLUGIN: BACKGROUND AUTH: Try to
open ccd file.\n";
+ cerr << getTime() << "RADIUS-PLUGIN: BACKGROUND AUTH: Try to
open template file.\n";
+ cerr << getTime() << "RADIUS-PLUGIN: BACKGROUND AUTH: Template
file name: " <<templatename<<endl;
+
- //open the file
+ //open the files
+ templatefile.open(templatename.c_str(),ios::in);
+
+ filename=context->conf.getCcdPath()+this->getCommonname();
+
+ if (DEBUG (context->getVerbosity()))
+ cerr << getTime() << "RADIUS-PLUGIN: BACKGROUND AUTH: Try to
open ccd file.\n";
+
ccdfile.open(filename.c_str(),ios::out);
-
if (DEBUG (context->getVerbosity()))
cerr << getTime() << "RADIUS-PLUGIN: BACKGROUND AUTH: Opened
ccd file.\n";
-
+ //Get the strings from the template file
+ if (templatefile) {
+ //get length of file:
+ templatefile.seekg (0, templatefile.end);
+ int length = templatefile.tellg();
+ templatefile.seekg (0, templatefile.beg);
+ char * templateText = new char [length];
+ cerr << getTime() << "RADIUS-PLUGIN: BACKGROUND AUTH:
Reading "<<length<<" Bytes from " <<templatename<<endl;
+ //read data as a block:
+ templatefile.read (templateText,length);
+ ccdfile << templateText;
+ }
// copy in a temp-string, becaue strtok deletes the delimiter,
if it is used anywhere
strncpy(framedroutes,this->getFramedRoutes().c_str(),4095);
The information in this email is confidential and may be legally privileged. It
is intended solely for the addressee. Any opinions expressed are mine and do
not necessarily represent the opinions of the Company. Emails are susceptible
to interference. If you are not the intended recipient, any disclosure,
copying, distribution or any action taken or omitted to be taken in reliance on
it, is strictly prohibited and may be unlawful. If you have received this
message in error, do not open any attachments but please notify the EndavaIT
Support Service Desk on (+44 (0)870 423 0187), and delete this message from
your system. The sender accepts no responsibility for information, errors or
omissions in this email, or for its use or misuse, or for any act committed or
omitted in connection with this communication. If in doubt, please verify the
authenticity of the contents with the sender. Please rely on your own virus
checkers as no responsibility is taken by the sender for any damage rising out
of any bug or virus infection.
Endava Limited is a company registered in England under company number 5722669
whose registered office is at 125 Old Broad Street, London, EC2N 1AR, United
Kingdom. Endava Limited is the Endava group holding company and does not
provide any services to clients. Each of Endava Limited and its subsidiaries is
a separate legal entity and has no liability for another such entity's acts or
omissions. Please refer to the “Legal” section on our website for a list of
legal entities.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Radiusplugin-devel] PATCH - add CCD template support,
Evgheni Dereveanchin <=