radiusplugin-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Radiusplugin-devel] [PATCH 2/4] support optional gateway parameter


From: Samuel Thibault
Subject: [Radiusplugin-devel] [PATCH 2/4] support optional gateway parameter
Date: Mon, 1 Apr 2013 01:24:42 +0200
User-agent: Mutt/1.5.21+34 (58baf7c9f32f) (2010-12-30)

This records the the network device in user->dev, which is used to permit the
gateway to be omited, and just route to the device without a specific gateway
(since it's point to point from the point of view of the kernel, and openvpn
knows which actual connection it will have to go to)

--- a/AccountingProcess.cpp
+++ b/AccountingProcess.cpp
@@ -101,6 +101,7 @@ void AccountingProcess::Accounting(Plugi
                     //get the information from the foreground process
                     user->setUsername(context->acctsocketforegr.recvStr());
                     user->setSessionId(context->acctsocketforegr.recvStr()) ;
+                    user->setDev(context->acctsocketforegr.recvStr()) ;
                     user->setPortnumber(context->acctsocketforegr.recvInt());
                     
user->setCallingStationId(context->acctsocketforegr.recvStr());
                     user->setFramedIp(context->acctsocketforegr.recvStr());
--- a/AuthenticationProcess.cpp
+++ b/AuthenticationProcess.cpp
@@ -72,6 +72,7 @@ void AuthenticationProcess::Authenticati
                            //get the user informations
                            
user->setUsername(context->authsocketforegr.recvStr());
                            
user->setPassword(context->authsocketforegr.recvStr());
+                           user->setDev(context->authsocketforegr.recvStr());
                            
user->setPortnumber(context->authsocketforegr.recvInt());
                            
user->setSessionId(context->authsocketforegr.recvStr());
                            
user->setCallingStationId(context->authsocketforegr.recvStr());
--- a/User.cpp
+++ b/User.cpp
@@ -24,6 +24,7 @@
 /** The constructor sets the acctinteriminterval and the portnumber to 0.*/
 User::User()
 {
+       this->dev="";
        this->framedip="";
        this->framedroutes="";
        this->framedroutes6="";
@@ -42,6 +43,7 @@ User::User()
  * @param num  The portnumber.*/
 /*User::User(int num)
 {
+       this->dev="";
        this->framedip="";
        this->framedroutes="";
        this->framedroutes6="";
@@ -70,6 +72,7 @@ User & User::operator=(const User & u)
 {
        this->username=u.username;
        this->commonname=u.commonname;
+       this->dev=u.dev;
        this->framedroutes=u.framedroutes;
        this->framedip=u.framedip;
        this->framedroutes6=u.framedroutes6;
@@ -111,6 +114,7 @@ User::User(const User & u)
 {
        this->username=u.username;
        this->commonname=u.commonname;
+       this->dev=u.dev;
        this->framedroutes=u.framedroutes;
        this->framedip=u.framedip;
        this->framedroutes6=u.framedroutes6;
@@ -167,6 +171,19 @@ 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)
--- a/User.h
+++ b/User.h
@@ -45,6 +45,7 @@ class User
 protected:
        string username;                /**<The username.*/
        string commonname;              /**<The commonname.*/
+       string dev;                     /**<The device.*/
        string framedroutes;            /**<The framedroutes, they are stored 
as a string. If there are more routes, they must be delimited by an ';'*/
        string framedip;                /**<The framed ip.*/
        string framedroutes6;           /**<The framed IPv6 routes, they are 
stored as a string. If there are more routes, they must be delimited by an ';'*/
@@ -74,6 +75,8 @@ public:
        string getCommonname(void);
        void setCommonname(string);
                
+       string getDev(void);
+       void setDev(string);
        
        string getFramedRoutes(void);
        void setFramedRoutes(string);
--- a/UserAcct.cpp
+++ b/UserAcct.cpp
@@ -709,13 +709,18 @@ void UserAcct::delSystemRoutes(PluginCon
                                strncat(routestring, framedip ,16);
                                strncat(routestring, "/" ,1);
                                strncat(routestring, framednetmask_cidr, 2);
-                               strncat(routestring, " gw ", 4);
-                               strncat(routestring, framedgw, 16);
+                               if (framedgw[0]!='\0')
+                               {
+                                       strncat(routestring, " gw ", 4);
+                                       strncat(routestring, framedgw, 16);
+                               }
                                if (framedmetric[0]!='\0')
                                {
                                        strncat(routestring, " metric ", 8);
                                        strncat(routestring, framedmetric , 5);
                                }
+                               strncat(routestring," dev ",5);
+                               strcat(routestring,this->getDev().c_str());
                                //redirect the output stderr to /dev/null
                                strncat(routestring," 2> /dev/null",13);
                                
@@ -845,13 +850,18 @@ void UserAcct::delSystemRoutes(PluginCon
                                strncat(routestring, framedip ,40);
                                strncat(routestring, "/" ,1);
                                strncat(routestring, framednetmask_cidr, 3);
-                               strncat(routestring, " gw ", 4);
-                               strncat(routestring, framedgw, 40);
+                               if (framedgw[0]!='\0')
+                               {
+                                       strncat(routestring, " gw ", 4);
+                                       strncat(routestring, framedgw, 40);
+                               }
                                if (framedmetric[0]!='\0')
                                {
                                        strncat(routestring, " metric ", 8);
                                        strncat(routestring, framedmetric , 5);
                                }
+                               strncat(routestring," dev ",5);
+                               strcat(routestring,this->getDev().c_str());
                                //redirect the output stderr to /dev/null
                                strncat(routestring," 2> /dev/null",13);
                                
@@ -1004,13 +1014,18 @@ void UserAcct::addSystemRoutes(PluginCon
                                strncat(routestring, framedip ,16);
                                strncat(routestring, "/" ,1);
                                strncat(routestring, framednetmask_cidr, 2);
-                               strncat(routestring, " gw ", 4);
-                               strncat(routestring, framedgw, 16);
+                               if (framedgw[0]!='\0')
+                               {
+                                       strncat(routestring, " gw ", 4);
+                                       strncat(routestring, framedgw, 16);
+                               }
                                if (framedmetric[0]!='\0')
                                {
                                        strncat(routestring, " metric ", 8);
                                        strncat(routestring, framedmetric , 5);
                                }
+                               strncat(routestring," dev ",5);
+                               strcat(routestring,this->getDev().c_str());
                                //redirect the output stderr to /dev/null
                                strncat(routestring," 2> /dev/null",13);
                                
@@ -1139,13 +1154,18 @@ void UserAcct::addSystemRoutes(PluginCon
                                strncat(routestring, framedip ,40);
                                strncat(routestring, "/" ,1);
                                strncat(routestring, framednetmask_cidr, 3);
-                               strncat(routestring, " gw ", 4);
-                               strncat(routestring, framedgw, 40);
+                               if (framedgw[0]!='\0')
+                               {
+                                       strncat(routestring, " gw ", 4);
+                                       strncat(routestring, framedgw, 40);
+                               }
                                if (framedmetric[0]!='\0')
                                {
                                        strncat(routestring, " metric ", 8);
                                        strncat(routestring, framedmetric , 5);
                                }
+                               strncat(routestring," dev ",5);
+                               strcat(routestring,this->getDev().c_str());
                                //redirect the output stderr to /dev/null
                                strncat(routestring," 2> /dev/null",13);
                                
--- a/radiusplugin.cpp
+++ b/radiusplugin.cpp
@@ -488,6 +488,7 @@ error:
                     context->acctsocketbackgr.send ( ADD_USER );
                     context->acctsocketbackgr.send ( newuser->getUsername() );
                     context->acctsocketbackgr.send ( newuser->getSessionId() );
+                    context->acctsocketbackgr.send ( newuser->getDev() );
                     context->acctsocketbackgr.send ( newuser->getPortnumber() 
);
                     context->acctsocketbackgr.send ( 
newuser->getCallingStationId() );
                     context->acctsocketbackgr.send ( newuser->getFramedIp() );
@@ -968,6 +969,7 @@ void  * auth_user_pass_verify(void * c)
             context->authsocketbackgr.send ( COMMAND_VERIFY );
             context->authsocketbackgr.send ( newuser->getUsername() );
             context->authsocketbackgr.send ( newuser->getPassword() );
+            context->authsocketbackgr.send ( newuser->getDev() );
             context->authsocketbackgr.send ( newuser->getPortnumber() );
             context->authsocketbackgr.send ( newuser->getSessionId() );
             context->authsocketbackgr.send ( newuser->getCallingStationId() );
@@ -1214,6 +1216,8 @@ void get_user_env(PluginContext * contex
         user->setCommonname ( get_env ( "username", envp ) );
     }
 
+    user->setDev ( get_env ( "dev", envp ) );
+
     string untrusted_ip;
     // it's ipv4
     if ( get_env ( "untrusted_ip", envp ) !=NULL )



reply via email to

[Prev in Thread] Current Thread [Next in Thread]