Brian Waters | 13d9601 | 2017-12-08 16:53:31 -0600 | [diff] [blame] | 1 | /***************************************************************************************************** |
| 2 | * Software License Agreement (BSD License) |
| 3 | * Author : Souheil Ben Ayed <souheil@tera.ics.keio.ac.jp> |
| 4 | * |
| 5 | * Copyright (c) 2009-2010, Souheil Ben Ayed, Teraoka Laboratory of Keio University, and the WIDE Project |
| 6 | * All rights reserved. |
| 7 | * |
| 8 | * Redistribution and use of this software in source and binary forms, with or without |
| 9 | * modification, are permitted provided that the following conditions are met: |
| 10 | * |
| 11 | * 1. Redistributions of source code must retain the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer. |
| 13 | * |
| 14 | * 2. Redistributions in binary form must reproduce the above copyright |
| 15 | * notice, this list of conditions and the following disclaimer in the |
| 16 | * documentation and/or other materials provided with the distribution. |
| 17 | * |
| 18 | * 3. All advertising materials mentioning features or use of this software |
| 19 | * must display the following acknowledgement: |
| 20 | * This product includes software developed by Souheil Ben Ayed <souheil@tera.ics.keio.ac.jp>. |
| 21 | * |
| 22 | * 4. Neither the name of Souheil Ben Ayed, Teraoka Laboratory of Keio University or the WIDE Project nor the |
| 23 | * names of its contributors may be used to endorse or promote products |
| 24 | * derived from this software without specific prior written permission. |
| 25 | * |
| 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' AND ANY |
| 27 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 28 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 29 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY |
| 30 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 31 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 32 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 33 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 34 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 35 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 36 | *****************************************************************************************************/ |
| 37 | |
| 38 | |
| 39 | #include "diameap_common.h" |
| 40 | |
| 41 | /* Dictionary Object templates */ |
| 42 | struct dict_object * dataobj_diameap_cmd = NULL; /* Diameter-EAP-Request Command Code */ |
| 43 | struct dict_object * dataobj_diameap_app = NULL; /* Diameter EAP Application object */ |
| 44 | struct dict_object * dataobj_diameap_ven = NULL; /* Diameter EAP Application Vendor object */ |
| 45 | struct dict_object * dataobj_accounting_eap_auth_method = NULL; |
| 46 | struct dict_object * dataobj_acct_interim_interval = NULL; |
| 47 | struct dict_object * dataobj_auth_application_id = NULL; |
| 48 | struct dict_object * dataobj_auth_grace_period = NULL; |
| 49 | struct dict_object * dataobj_auth_request_type = NULL; |
| 50 | struct dict_object * dataobj_auth_session_state = NULL; |
| 51 | struct dict_object * dataobj_authorization_lifetime = NULL; |
| 52 | struct dict_object * dataobj_callback_id = NULL; |
| 53 | struct dict_object * dataobj_callback_number = NULL; |
| 54 | struct dict_object * dataobj_called_station_id = NULL; |
| 55 | struct dict_object * dataobj_calling_station_id = NULL; |
| 56 | struct dict_object * dataobj_class = NULL; |
| 57 | struct dict_object * dataobj_configuration_token = NULL; |
| 58 | struct dict_object * dataobj_connect_info = NULL; |
| 59 | struct dict_object * dataobj_destination_host = NULL; |
| 60 | struct dict_object * dataobj_destination_realm = NULL; |
| 61 | struct dict_object * dataobj_eap_master_session_key = NULL; |
| 62 | struct dict_object * dataobj_eap_key_name = NULL; |
| 63 | struct dict_object * dataobj_eap_payload = NULL; |
| 64 | struct dict_object * dataobj_eap_reissued_payload = NULL; |
| 65 | struct dict_object * dataobj_error_message = NULL; |
| 66 | struct dict_object * dataobj_error_reporting_host = NULL; |
| 67 | struct dict_object * dataobj_failed_avp = NULL; |
| 68 | struct dict_object * dataobj_filter_id = NULL; |
| 69 | struct dict_object * dataobj_framed_appletalk_link = NULL; |
| 70 | struct dict_object * dataobj_framed_appletalk_network = NULL; |
| 71 | struct dict_object * dataobj_framed_appletalk_zone = NULL; |
| 72 | struct dict_object * dataobj_framed_compression = NULL; |
| 73 | struct dict_object * dataobj_framed_interface_id = NULL; |
| 74 | struct dict_object * dataobj_framed_ip_address = NULL; |
| 75 | struct dict_object * dataobj_framed_ip_netmask = NULL; |
| 76 | struct dict_object * dataobj_framed_ipv6_prefix = NULL; |
| 77 | struct dict_object * dataobj_framed_ipv6_pool = NULL; |
| 78 | struct dict_object * dataobj_framed_ipv6_route = NULL; |
| 79 | struct dict_object * dataobj_framed_ipx_network = NULL; |
| 80 | struct dict_object * dataobj_framed_mtu = NULL; |
| 81 | struct dict_object * dataobj_framed_pool = NULL; |
| 82 | struct dict_object * dataobj_framed_protocol = NULL; |
| 83 | struct dict_object * dataobj_framed_route = NULL; |
| 84 | struct dict_object * dataobj_framed_routing = NULL; |
| 85 | struct dict_object * dataobj_idle_timeout = NULL; |
| 86 | struct dict_object * dataobj_multi_round_time_out = NULL; |
| 87 | struct dict_object * dataobj_nas_filter_rule = NULL; |
| 88 | struct dict_object * dataobj_nas_identifier = NULL; |
| 89 | struct dict_object * dataobj_nas_ip_address = NULL; |
| 90 | struct dict_object * dataobj_nas_ipv6_address = NULL; |
| 91 | struct dict_object * dataobj_nas_port = NULL; |
| 92 | struct dict_object * dataobj_nas_port_id = NULL; |
| 93 | struct dict_object * dataobj_nas_port_type = NULL; |
| 94 | struct dict_object * dataobj_originating_line_info = NULL; |
| 95 | struct dict_object * dataobj_origin_host = NULL; |
| 96 | struct dict_object * dataobj_origin_realm = NULL; |
| 97 | struct dict_object * dataobj_origin_state_id = NULL; |
| 98 | struct dict_object * dataobj_port_limit = NULL; |
| 99 | struct dict_object * dataobj_proxy_info = NULL; |
| 100 | struct dict_object * dataobj_qos_filter_rule = NULL; |
| 101 | struct dict_object * dataobj_re_auth_request_type = NULL; |
| 102 | struct dict_object * dataobj_redirect_host = NULL; |
| 103 | struct dict_object * dataobj_redirect_host_usage = NULL; |
| 104 | struct dict_object * dataobj_redirect_max_cache_time = NULL; |
| 105 | struct dict_object * dataobj_reply_message = NULL; |
| 106 | struct dict_object * dataobj_result_code = NULL; |
| 107 | struct dict_object * dataobj_route_record = NULL; |
| 108 | struct dict_object * dataobj_service_type = NULL; |
| 109 | struct dict_object * dataobj_session_id = NULL; |
| 110 | struct dict_object * dataobj_session_timeout = NULL; |
| 111 | struct dict_object * dataobj_state = NULL; |
| 112 | struct dict_object * dataobj_tunneling = NULL; |
| 113 | struct dict_object * dataobj_user_name = NULL; |
| 114 | |
| 115 | |
| 116 | |
| 117 | static int diameap_init_config(char * conffile) |
| 118 | { |
| 119 | TRACE_ENTRY("%p",conffile); |
| 120 | |
| 121 | if (conffile != NULL) |
| 122 | { |
| 123 | diameap_config->conffile = conffile; |
| 124 | } |
| 125 | else |
| 126 | { |
| 127 | TRACE_DEBUG(FULL,"%sNo configuration file provided with the DiamEAP extension: default parameters will be used.",DIAMEAP_EXTENSION); |
| 128 | } |
| 129 | |
| 130 | diameap_config->application_id = 5; |
| 131 | diameap_config->vendor_id = 0; |
| 132 | diameap_config->command_code = 268; |
| 133 | diameap_config->diam_realm = strdup(fd_g_config->cnf_diamrlm); |
| 134 | diameap_config->max_invalid_eap_packet = 5; |
| 135 | diameap_config->multi_round_time_out = 30; |
| 136 | check_user_identity = TRUE; |
| 137 | |
| 138 | return 0; |
| 139 | } |
| 140 | |
| 141 | static int diameap_init_obj(void) |
| 142 | { |
| 143 | |
| 144 | CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_APPLICATION, APPLICATION_BY_ID, &(diameap_config->application_id),&dataobj_diameap_app, ENOENT)); |
| 145 | CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_COMMAND,CMD_BY_CODE_R, &(diameap_config->command_code), &dataobj_diameap_cmd, ENOENT)); |
| 146 | // CHECK_FCT( fd_dict_search( fd_g_config->cnf_dict, DICT_VENDOR,VENDOR_OF_APPLICATION, &dataobj_diameap_app, &dataobj_diameap_ven,ENOENT) ); |
| 147 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 148 | "Accounting-EAP-Auth-Method", &dataobj_accounting_eap_auth_method, |
| 149 | ENOENT)); |
| 150 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 151 | "Acct-Interim-Interval", &dataobj_acct_interim_interval, ENOENT)); |
| 152 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 153 | "Auth-Application-Id", &dataobj_auth_application_id, ENOENT)); |
| 154 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 155 | "Auth-Grace-Period", &dataobj_auth_grace_period, ENOENT)); |
| 156 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 157 | "Auth-Request-Type", &dataobj_auth_request_type, ENOENT)); |
| 158 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 159 | "Auth-Session-State", &dataobj_auth_session_state, ENOENT)); |
| 160 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 161 | "Authorization-Lifetime", &dataobj_authorization_lifetime, ENOENT)); |
| 162 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 163 | "Callback-Id", &dataobj_callback_id, ENOENT)); |
| 164 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 165 | "Callback-Number", &dataobj_callback_number, ENOENT)); |
| 166 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 167 | "Called-Station-Id", &dataobj_called_station_id, ENOENT)); |
| 168 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 169 | "Calling-Station-Id", &dataobj_calling_station_id, ENOENT)); |
| 170 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 171 | "Class", &dataobj_class, ENOENT)); |
| 172 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 173 | "Configuration-Token", &dataobj_configuration_token, ENOENT)); |
| 174 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 175 | "Connect-Info", &dataobj_connect_info, ENOENT)); |
| 176 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 177 | "Destination-Host", &dataobj_destination_host, ENOENT)); |
| 178 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 179 | "Destination-Realm", &dataobj_destination_realm, ENOENT)); |
| 180 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 181 | "EAP-Master-Session-Key", &dataobj_eap_master_session_key, ENOENT)); |
| 182 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 183 | "EAP-Key-Name", &dataobj_eap_key_name, ENOENT)); |
| 184 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 185 | "EAP-Payload", &dataobj_eap_payload, ENOENT)); |
| 186 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 187 | "EAP-Reissued-Payload", &dataobj_eap_reissued_payload, ENOENT)); |
| 188 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 189 | "Error-Message", &dataobj_error_message, ENOENT)); |
| 190 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 191 | "Error-Reporting-Host", &dataobj_error_reporting_host, ENOENT)); |
| 192 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 193 | "Failed-AVP", &dataobj_failed_avp, ENOENT)); |
| 194 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 195 | "Filter-Id", &dataobj_filter_id, ENOENT)); |
| 196 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 197 | "Framed-AppleTalk-Link", &dataobj_framed_appletalk_link, ENOENT)); |
| 198 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 199 | "Framed-AppleTalk-Network", &dataobj_framed_appletalk_network, |
| 200 | ENOENT)); |
| 201 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 202 | "Framed-AppleTalk-Zone", &dataobj_framed_appletalk_zone, ENOENT)); |
| 203 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 204 | "Framed-Compression", &dataobj_framed_compression, ENOENT)); |
| 205 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 206 | "Framed-Interface-Id", &dataobj_framed_interface_id, ENOENT)); |
| 207 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 208 | "Framed-IP-Address", &dataobj_framed_ip_address, ENOENT)); |
| 209 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 210 | "Framed-IP-Netmask", &dataobj_framed_ip_netmask, ENOENT)); |
| 211 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 212 | "Framed-IPv6-Prefix", &dataobj_framed_ipv6_prefix, ENOENT)); |
| 213 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 214 | "Framed-IPv6-Pool", &dataobj_framed_ipv6_pool, ENOENT)); |
| 215 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 216 | "Framed-IPv6-Route", &dataobj_framed_ipv6_route, ENOENT)); |
| 217 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 218 | "Framed-IPX-Network", &dataobj_framed_ipx_network, ENOENT)); |
| 219 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 220 | "Framed-MTU", &dataobj_framed_mtu, ENOENT)); |
| 221 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 222 | "Framed-Pool", &dataobj_framed_pool, ENOENT)); |
| 223 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 224 | "Framed-Protocol", &dataobj_framed_protocol, ENOENT)); |
| 225 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 226 | "Framed-Route", &dataobj_framed_route, ENOENT)); |
| 227 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 228 | "Framed-Routing", &dataobj_framed_routing, ENOENT)); |
| 229 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 230 | "Idle-Timeout", &dataobj_idle_timeout, ENOENT)); |
| 231 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 232 | "Multi-Round-Time-Out", &dataobj_multi_round_time_out, ENOENT)); |
| 233 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 234 | "NAS-Filter-Rule", &dataobj_nas_filter_rule, ENOENT)); |
| 235 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 236 | "NAS-Identifier", &dataobj_nas_identifier, ENOENT)); |
| 237 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 238 | "NAS-IP-Address", &dataobj_nas_ip_address, ENOENT)); |
| 239 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 240 | "NAS-IPv6-Address", &dataobj_nas_ipv6_address, ENOENT)); |
| 241 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 242 | "NAS-Port", &dataobj_nas_port, ENOENT)); |
| 243 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 244 | "NAS-Port-Id", &dataobj_nas_port_id, ENOENT)); |
| 245 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 246 | "NAS-Port-Type", &dataobj_nas_port_type, ENOENT)); |
| 247 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 248 | "Originating-Line-Info", &dataobj_originating_line_info, ENOENT)); |
| 249 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 250 | "Origin-Host", &dataobj_origin_host, ENOENT)); |
| 251 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 252 | "Origin-Realm", &dataobj_origin_realm, ENOENT)); |
| 253 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 254 | "Origin-State-Id", &dataobj_origin_state_id, ENOENT)); |
| 255 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 256 | "Port-Limit", &dataobj_port_limit, ENOENT)); |
| 257 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 258 | "Proxy-Info", &dataobj_proxy_info, ENOENT)); |
| 259 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 260 | "QoS-Filter-Rule", &dataobj_qos_filter_rule, ENOENT)); |
| 261 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 262 | "Re-Auth-Request-Type", &dataobj_re_auth_request_type, ENOENT)); |
| 263 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 264 | "Redirect-Host", &dataobj_redirect_host, ENOENT)); |
| 265 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 266 | "Redirect-Host-Usage", &dataobj_redirect_host_usage, ENOENT)); |
| 267 | CHECK_FCT( |
| 268 | fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 269 | "Redirect-Max-Cache-Time", |
| 270 | &dataobj_redirect_max_cache_time, ENOENT)); |
| 271 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 272 | "Reply-Message", &dataobj_reply_message, ENOENT)); |
| 273 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 274 | "Result-Code", &dataobj_result_code, ENOENT)); |
| 275 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 276 | "Route-Record", &dataobj_route_record, ENOENT)); |
| 277 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 278 | "Service-Type", &dataobj_service_type, ENOENT)); |
| 279 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 280 | "Session-Id", &dataobj_session_id, ENOENT)); |
| 281 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 282 | "Session-Timeout", &dataobj_session_timeout, ENOENT)); |
| 283 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 284 | "State", &dataobj_state, ENOENT)); |
| 285 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 286 | "Tunneling", &dataobj_tunneling, ENOENT)); |
| 287 | CHECK_FCT(fd_dict_search(fd_g_config->cnf_dict, DICT_AVP, AVP_BY_NAME, |
| 288 | "User-Name", &dataobj_user_name, ENOENT)); |
| 289 | |
| 290 | return 0; |
| 291 | } |
| 292 | |
| 293 | /* Parse the configuration file (using the yacc parser) */ |
| 294 | static int diameap_parse_conffile(void) |
| 295 | { |
| 296 | if (!diameap_config->conffile) |
| 297 | { |
| 298 | TRACE_DEBUG (INFO,"%sNo configuration file to parse for DiamEAP Extension.",DIAMEAP_EXTENSION); |
| 299 | return EINVAL; |
| 300 | } |
| 301 | extern FILE * diameapin; |
| 302 | |
| 303 | TRACE_DEBUG (FULL, "%sParsing configuration file: %s",DIAMEAP_EXTENSION, diameap_config->conffile); |
| 304 | diameapin = fopen(diameap_config->conffile, "r"); |
| 305 | if (!diameapin) |
| 306 | { |
| 307 | TRACE_DEBUG(INFO,"%sUnable to open configuration file %s for reading: %s",DIAMEAP_EXTENSION, diameap_config->conffile, strerror(errno)); |
| 308 | return errno; |
| 309 | } |
| 310 | |
| 311 | /* call yacc parser */ |
| 312 | CHECK_FCT(diameapparse(diameap_config)); |
| 313 | |
| 314 | /* close the file */ |
| 315 | CHECK_FCT(fclose(diameapin)); |
| 316 | return 0; |
| 317 | } |
| 318 | |
| 319 | int diameap_set_mysql_param(char * user, char * passwd, char * server, |
| 320 | char * database) |
| 321 | { |
| 322 | TRACE_ENTRY("%p %p %p %p",user,passwd,server,database); |
| 323 | if (user == NULL) |
| 324 | { |
| 325 | TRACE_DEBUG(INFO,"%sUnable to connect to MySQL Database Server: Empty user name or missing in the configuration file.",DIAMEAP_EXTENSION); |
| 326 | return EINVAL; |
| 327 | } |
| 328 | |
| 329 | if (server == NULL) |
| 330 | { |
| 331 | TRACE_DEBUG(INFO,"%sUnable to connect to MySQL Database Server: MySQL Database Server address missing in the configuration file.",DIAMEAP_EXTENSION); |
| 332 | return EINVAL; |
| 333 | } |
| 334 | if (database == NULL) |
| 335 | { |
| 336 | TRACE_DEBUG(INFO,"%sUnable to connect to MySQL Database Server: MySQL Database name missing in configuration file.",DIAMEAP_EXTENSION); |
| 337 | return EINVAL; |
| 338 | } |
| 339 | diameap_config->db.user = user; |
| 340 | diameap_config->db.password = passwd; |
| 341 | diameap_config->db.server = server; |
| 342 | diameap_config->db.database = database; |
| 343 | return 0; |
| 344 | } |
| 345 | |
| 346 | /* Connecting to MySQL Database */ |
| 347 | int diameap_mysql_connect(void) |
| 348 | { |
| 349 | TRACE_ENTRY(); |
| 350 | db_conn = mysql_init(NULL); |
| 351 | const my_bool mysql_reconnect_val=1; |
| 352 | mysql_options(db_conn,MYSQL_OPT_RECONNECT,&mysql_reconnect_val); |
| 353 | /* Connect to database */ |
| 354 | if (!mysql_real_connect(db_conn, diameap_config->db.server, |
| 355 | diameap_config->db.user, diameap_config->db.password, |
| 356 | diameap_config->db.database, 0, NULL, 0)) |
| 357 | { |
| 358 | TRACE_DEBUG(INFO,"%sConnection to MySQL Database Server failed: %s",DIAMEAP_EXTENSION, mysql_error(db_conn)); |
| 359 | return errno; |
| 360 | } |
| 361 | return 0; |
| 362 | } |
| 363 | |
| 364 | static void diameap_conf_dump(void) |
| 365 | { |
| 366 | |
| 367 | if (!TRACE_BOOL(INFO)) |
| 368 | return; |
| 369 | |
| 370 | fd_log_debug("-------- DiamEAP extension : Configuration parameters (Dump) -------------"); |
| 371 | fd_log_debug("\t-Configuration file.....: %s", diameap_config->conffile); |
| 372 | fd_log_debug("\t-EAP Application Id.....: %u", |
| 373 | diameap_config->application_id); |
| 374 | fd_log_debug("\t-EAP Application Command: %u", |
| 375 | diameap_config->command_code); |
| 376 | fd_log_debug("\t-EAP Application Vendor.: %u", diameap_config->vendor_id); |
| 377 | fd_log_debug("\t-Max invalid EAP packets: %u", diameap_config->max_invalid_eap_packet); |
| 378 | fd_log_debug("\t-Multi-Round Timeout....: %u", diameap_config->multi_round_time_out); |
| 379 | if (diameap_config->db.user) |
| 380 | { |
| 381 | fd_log_debug("\t-MySQL Database Params..:"); |
| 382 | fd_log_debug("\t\tUser .......:%s", diameap_config->db.user); |
| 383 | fd_log_debug("\t\tServer .....:%s", diameap_config->db.server); |
| 384 | fd_log_debug("\t\tDatabase....:%s", diameap_config->db.database); |
| 385 | } |
| 386 | |
| 387 | fd_log_debug("\t-EAP Method Plugins.....: "); |
| 388 | diameap_plugin_dump(); |
| 389 | |
| 390 | fd_log_debug("-------- DiamEAP extension : Configuration parameters (End) ---------------"); |
| 391 | } |
| 392 | |
| 393 | int diameap_init(char * conffile) |
| 394 | { |
| 395 | TRACE_ENTRY("%p",conffile); |
| 396 | |
| 397 | /* Initialize the diameap_config structure*/ |
| 398 | CHECK_FCT(diameap_init_config(conffile)); |
| 399 | |
| 400 | if (diameap_config->conffile) |
| 401 | { |
| 402 | /* parse the configuration file*/ |
| 403 | CHECK_FCT(diameap_parse_conffile()); |
| 404 | |
| 405 | /* Load EAP methods plug-ins */ |
| 406 | CHECK_FCT(diameap_plugin_load()); |
| 407 | |
| 408 | } |
| 409 | else |
| 410 | { |
| 411 | TRACE_DEBUG(FULL,"%sNo EAP method plug-in available with a default configuration.",DIAMEAP_EXTENSION); |
| 412 | } |
| 413 | |
| 414 | /* Initialize Dictionary templates */ |
| 415 | CHECK_FCT(diameap_init_obj()); |
| 416 | |
| 417 | /* Initialize access to user's information Database */ |
| 418 | CHECK_FCT(diameap_mysql_connect()); |
| 419 | |
| 420 | /* Dump DiamEAP extension configuration */ |
| 421 | diameap_conf_dump(); |
| 422 | |
| 423 | return 0; |
| 424 | } |