OSDN Git Service

Edit documentation and comment.
[opengate/opengate.git] / opengate / opengatesrv / auth-rad.c
1 /**************************************************
2 opengate server
3  module for Authentication by RADIUS
4
5 Copyright (C) 2002 Opengate Project Team
6 Written by Yoshiaki Watanabe
7
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.
12
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.
17
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.
21
22 Email: watanaby@is.saga-u.ac.jp
23 **************************************************/
24 /*
25   Thanks to programs and documentations refered.
26    The experimental implementation by Fuyuta Sato.
27    Manual files about RADIUS.
28 */
29
30 #include <radlib.h>
31 #include "opengatesrv.h"
32
33 /*****************************************/
34 /* Authenticate by RADIUS */
35 /*****************************************/
36 int authRadius(char *userid, char *passwd)
37 {
38   char* confFile;
39   int           authResult;
40   struct rad_handle *radh;
41   char hostname[ADDRMAXLN];
42
43   /* get radius config file path */
44   confFile=GetRadiusConfFile();
45
46   /* If not set, set default conf file path */
47   if(confFile==NULL){
48     strncpy(confFile, RADIUSCONF, ADDRMAXLN);
49   }
50
51   if( !(radh=rad_auth_open()) ){
52     err_msg("ERR in auth-rad: cannot start radius");
53     return DENY;
54   }
55
56   if(gethostname(hostname,ADDRMAXLN) < 0){
57     err_msg("ERR in auth-rad: cannot get hostname");
58     return DENY;
59   }
60     
61   if(rad_config(radh,confFile) < 0){
62     err_msg("ERR in auth-rad: cannot open conffile");
63     return DENY;
64   }
65
66   if(rad_create_request(radh, RAD_ACCESS_REQUEST) < 0){
67     err_msg("ERR in auth-rad: cannot create radius request");
68     return DENY;
69   }
70
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);
75
76   switch(rad_send_request(radh)){
77   case RAD_ACCESS_ACCEPT:
78     authResult=ACCEPT;
79     break;
80   case RAD_ACCESS_REJECT:
81   case RAD_ACCESS_CHALLENGE:
82   case RAD_ACCOUNTING_RESPONSE:
83   default:
84     authResult=DENY;
85     break;
86   }
87
88   return authResult;
89 }
90   
91 int AuthRadius(char *userid, char *passwd)
92 {
93   int ret;
94
95   if(DEBUG) err_msg("DEBUG:=>authRadius(%s,passwd)",userid);
96   ret=authRadius(userid,passwd);
97   if(DEBUG) err_msg("DEBUG:(%d)<=authRadius( )",ret);
98
99   return ret;
100 }