1 /**************************************************
3 module for Authentication by RADIUS
5 Copyright (C) 2002 Opengate Project Team
6 Written by Yoshiaki Watanabe
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 Email: watanaby@is.saga-u.ac.jp
23 **************************************************/
25 Thanks to programs and documentations refered.
26 The experimental implementation by Fuyuta Sato.
27 Manual files about RADIUS.
31 #include "opengatesrv.h"
33 /*****************************************/
34 /* Authenticate by RADIUS */
35 /*****************************************/
36 int authRadius(char *userid, char *passwd)
40 struct rad_handle *radh;
41 char hostname[ADDRMAXLN];
43 /* get radius config file path */
44 confFile=GetRadiusConfFile();
46 /* If not set, set default conf file path */
48 strncpy(confFile, RADIUSCONF, ADDRMAXLN);
51 if( !(radh=rad_auth_open()) ){
52 err_msg("ERR in auth-rad: cannot start radius");
56 if(gethostname(hostname,ADDRMAXLN) < 0){
57 err_msg("ERR in auth-rad: cannot get hostname");
61 if(rad_config(radh,confFile) < 0){
62 err_msg("ERR in auth-rad: cannot open conffile");
66 if(rad_create_request(radh, RAD_ACCESS_REQUEST) < 0){
67 err_msg("ERR in auth-rad: cannot create radius request");
71 rad_put_string(radh,RAD_USER_NAME,userid);
72 rad_put_string(radh,RAD_USER_PASSWORD,passwd);
73 rad_put_string(radh,RAD_NAS_IDENTIFIER,hostname);
74 rad_put_int(radh,RAD_SERVICE_TYPE,RAD_LOGIN);
76 switch(rad_send_request(radh)){
77 case RAD_ACCESS_ACCEPT:
80 case RAD_ACCESS_REJECT:
81 case RAD_ACCESS_CHALLENGE:
82 case RAD_ACCOUNTING_RESPONSE:
91 int AuthRadius(char *userid, char *passwd)
95 if(DEBUG) err_msg("DEBUG:=>authRadius(%s,passwd)",userid);
96 ret=authRadius(userid,passwd);
97 if(DEBUG) err_msg("DEBUG:(%d)<=authRadius( )",ret);