2  *    This program is free software; you can redistribute it and/or modify
 
   3  *    it under the terms of the GNU General Public License as published by
 
   4  *    the Free Software Foundation; either version 2 of the License, or
 
   5  *    (at your option) any later version.
 
   7  *    This program is distributed in the hope that it will be useful,
 
   8  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
   9  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
  10  *    GNU General Public License for more details.
 
  12  *    You should have received a copy of the GNU General Public License
 
  13  *    along with this program; if not, write to the Free Software
 
  14  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
  18  *    Author : Maxim Mamontov <faust@stargazer.dp.ua>
 
  22  *  Radius data access plugin for Stargazer
 
  25  *  $Date: 2009/12/13 14:17:13 $
 
  40 #include "base_auth.h"
 
  43 #include "../../../user.h"
 
  44 #include "../../../users.h"
 
  46 #include "rad_packets.h"
 
  50 extern "C" BASE_PLUGIN * GetPlugin();
 
  55 //-----------------------------------------------------------------------------
 
  59     RAD_SETTINGS() : port(0) {}
 
  60     virtual ~RAD_SETTINGS() {}
 
  61     const string & GetStrError() const { return errorStr; }
 
  62     int ParseSettings(const MODULE_SETTINGS & s);
 
  63     uint16_t GetPort() const { return port; }
 
  64     const std::string & GetPassword() const { return password; }
 
  65     const list<string> & GetAuthServices() const { return authServices; }
 
  66     const list<string> & GetAcctServices() const { return acctServices; }
 
  69     int ParseIntInRange(const string & str, int min, int max, int * val);
 
  70     int ParseServices(const vector<string> & str, list<string> * lst);
 
  75     list<string> authServices;
 
  76     list<string> acctServices;
 
  78 //-----------------------------------------------------------------------------
 
  81     std::string serviceType;
 
  83 //-----------------------------------------------------------------------------
 
  84 class RADIUS :public BASE_AUTH
 
  90     void                SetUsers(USERS * u);
 
  91     void                SetTariffs(TARIFFS *){};
 
  92     void                SetAdmins(ADMINS *){};
 
  93     void                SetTraffcounter(TRAFFCOUNTER *){};
 
  94     void                SetStore(BASE_STORE * );
 
  95     void                SetStgSettings(const SETTINGS * s);
 
  96     void                SetSettings(const MODULE_SETTINGS & s);
 
 101     int                 Reload() { return 0; };
 
 104     const string      & GetStrError() const { return errorStr; };
 
 105     const string        GetVersion() const;
 
 106     uint16_t            GetStartPosition() const;
 
 107     uint16_t            GetStopPosition() const;
 
 109     int SendMessage(const STG_MSG &, uint32_t) const { return 0; };
 
 112     static void *       Run(void *);
 
 116     int                 Send(const RAD_PACKET & packet, struct sockaddr_in * outerAddr);
 
 117     int                 RecvData(RAD_PACKET * packet, struct sockaddr_in * outerAddr);
 
 118     int                 ProcessData(RAD_PACKET * packet);
 
 120     int                 ProcessAutzPacket(RAD_PACKET * packet);
 
 121     int                 ProcessAuthPacket(RAD_PACKET * packet);
 
 122     int                 ProcessPostAuthPacket(RAD_PACKET * packet);
 
 123     int                 ProcessAcctStartPacket(RAD_PACKET * packet);
 
 124     int                 ProcessAcctStopPacket(RAD_PACKET * packet);
 
 125     int                 ProcessAcctUpdatePacket(RAD_PACKET * packet);
 
 126     int                 ProcessAcctOtherPacket(RAD_PACKET * packet);
 
 128     bool                FindUser(user_iter * ui, const std::string & login) const;
 
 129     bool                CanAuthService(const std::string & svc) const;
 
 130     bool                CanAcctService(const std::string & svc) const;
 
 131     bool                IsAllowedService(const std::string & svc) const;
 
 133     bool                WaitPackets(int sd) const;
 
 135     void                PrintServices(const std::list<std::string> & svcs);
 
 137     struct Printer : public unary_function<std::string, void>
 
 139         void operator()(const std::string & line)
 
 141             printfd("radius.cpp", "'%s'\n", line.c_str()); 
 
 144     struct SPrinter : public unary_function<std::pair<std::string, RAD_SESSION>, void>
 
 146         void operator()(const std::pair<std::string, RAD_SESSION> & it)
 
 148             printfd("radius.cpp", "%s - ('%s', '%s')\n", it.first.c_str(), it.second.userName.c_str(), it.second.serviceType.c_str()); 
 
 154     mutable string      errorStr;
 
 155     RAD_SETTINGS        radSettings;
 
 156     MODULE_SETTINGS     settings;
 
 157     list<string>        authServices;
 
 158     list<string>        acctServices;
 
 159     map<string, RAD_SESSION> sessions;
 
 165     const SETTINGS *    stgSettings;
 
 166     const BASE_STORE *  store;
 
 169     pthread_mutex_t     mutex;
 
 176 //-----------------------------------------------------------------------------