Changeset 996:cf09fde3d7f5 in freeDiameter for extensions/app_radgw/rgwx_auth.c
- Timestamp:
- Mar 20, 2013, 12:13:14 AM (11 years ago)
- Branch:
- default
- Children:
- 997:632913581c37, 998:ad6c1ee04d2d
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/app_radgw/rgwx_auth.c
r979 r996 229 229 230 230 /* Handle an incoming RADIUS request */ 231 static int auth_rad_req( struct rgwp_config * cs, struct session ** session, structradius_msg * rad_req, struct radius_msg ** rad_ans, struct msg ** diam_fw, struct rgw_client * cli )231 static int auth_rad_req( struct rgwp_config * cs, struct radius_msg * rad_req, struct radius_msg ** rad_ans, struct msg ** diam_fw, struct rgw_client * cli ) 232 232 { 233 233 int idx; … … 250 250 struct avp ** avp_tun = NULL, *avp = NULL; 251 251 union avp_value value; 252 253 TRACE_ENTRY("%p %p %p %p %p %p", cs, session, rad_req, rad_ans, diam_fw, cli); 254 CHECK_PARAMS(cs && session && rad_req && (rad_req->hdr->code == RADIUS_CODE_ACCESS_REQUEST) && rad_ans && diam_fw && *diam_fw); 252 struct session * sess; 253 254 TRACE_ENTRY("%p %p %p %p %p", cs, rad_req, rad_ans, diam_fw, cli); 255 CHECK_PARAMS(cs && rad_req && (rad_req->hdr->code == RADIUS_CODE_ACCESS_REQUEST) && rad_ans && diam_fw && *diam_fw); 255 256 256 257 pref_len = strlen(prefix); … … 440 441 } 441 442 CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) ); 442 CHECK_FCT( fd_msg_avp_add ( *diam_fw, *session ? MSG_BRW_LAST_CHILD :MSG_BRW_FIRST_CHILD, avp) );443 CHECK_FCT( fd_msg_avp_add ( *diam_fw, MSG_BRW_FIRST_CHILD, avp) ); 443 444 444 445 /* Add the Destination-Host if found */ … … 448 449 value.os.len = dh_len; 449 450 CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) ); 450 CHECK_FCT( fd_msg_avp_add ( *diam_fw, *session ? MSG_BRW_LAST_CHILD :MSG_BRW_FIRST_CHILD, avp) );451 CHECK_FCT( fd_msg_avp_add ( *diam_fw, MSG_BRW_FIRST_CHILD, avp) ); 451 452 } 452 453 453 454 /* Create the session if it is not already done */ 454 if (*session == NULL){455 { 455 456 os0_t sess_str = NULL; 456 457 size_t sess_strlen; … … 458 459 if (si_len) { 459 460 /* We already have the Session-Id, just use it */ 460 CHECK_FCT( fd_sess_fromsid_msg ( si, si_len, session, NULL) );461 CHECK_FCT( fd_sess_fromsid_msg ( si, si_len, &sess, NULL) ); 461 462 } else { 462 463 /* Create a new Session-Id string */ … … 476 477 CHECK_MALLOC( sess_str = malloc(un_len + 1 /* ';' */ + fd_g_config->cnf_diamid_len + 1 /* '\0' */) ); 477 478 len = sprintf((char *)sess_str, "%.*s;%s", (int)un_len, un, fd_g_config->cnf_diamid); 478 CHECK_FCT( fd_sess_new( session, fqdn, fqdnlen, sess_str, len) );479 CHECK_FCT( fd_sess_new(&sess, fqdn, fqdnlen, sess_str, len) ); 479 480 free(sess_str); 480 481 } else { … … 486 487 487 488 /* Now, add the Session-Id AVP at beginning of Diameter message */ 488 CHECK_FCT( fd_sess_getsid(*session, &sess_str, &sess_strlen) ); 489 489 CHECK_FCT( fd_sess_getsid(sess, &sess_str, &sess_strlen) ); 490 490 TRACE_DEBUG(FULL, "[auth.rgwx] Translating new message for session '%s'...", sess_str); 491 491 492 /* Add the Session-Id AVP as first AVP*/492 /* Now add this session in the message */ 493 493 CHECK_FCT( fd_msg_avp_new ( cs->dict.Session_Id, 0, &avp ) ); 494 494 value.os.data = sess_str; … … 496 496 CHECK_FCT( fd_msg_avp_setvalue ( avp, &value ) ); 497 497 CHECK_FCT( fd_msg_avp_add ( *diam_fw, MSG_BRW_FIRST_CHILD, avp) ); 498 CHECK_FCT( fd_msg_sess_set( *diam_fw, *session) );498 CHECK_FCT( fd_msg_sess_set(*diam_fw, sess) ); 499 499 } 500 500 … … 1056 1056 1057 1057 /* Store the request identifier in the session (if provided) */ 1058 if (*session){1058 { 1059 1059 unsigned char * req_auth; 1060 1060 CHECK_MALLOC(req_auth = malloc(16)); 1061 1061 memcpy(req_auth, &rad_req->hdr->authenticator[0], 16); 1062 1062 1063 CHECK_FCT( fd_sess_state_store( cs->sess_hdl, *session, &req_auth ) );1063 CHECK_FCT( fd_sess_state_store( cs->sess_hdl, sess, &req_auth ) ); 1064 1064 } 1065 1065 … … 1067 1067 } 1068 1068 1069 static int auth_diam_ans( struct rgwp_config * cs, struct session * session, struct msg ** diam_ans, struct radius_msg ** rad_fw, struct rgw_client * cli, int * stateful)1069 static int auth_diam_ans( struct rgwp_config * cs, struct msg ** diam_ans, struct radius_msg ** rad_fw, struct rgw_client * cli ) 1070 1070 { 1071 1071 struct msg_hdr * hdr; 1072 struct avp *avp, *next, *avp_x, *avp_y, *a sid, *aoh;1073 struct avp_hdr *ahdr, * sid, *oh;1072 struct avp *avp, *next, *avp_x, *avp_y, *aoh; 1073 struct avp_hdr *ahdr, *oh; 1074 1074 uint8_t buf[254]; /* to store some attributes values (with final '\0') */ 1075 1075 size_t sz; … … 1079 1079 unsigned char * req_auth = NULL; 1080 1080 int error_cause = 0; 1081 1082 TRACE_ENTRY("%p %p %p %p %p", cs, session, diam_ans, rad_fw, cli); 1083 CHECK_PARAMS(cs && session && diam_ans && *diam_ans && rad_fw && *rad_fw); 1081 struct session * sess; 1082 os0_t sid = NULL; 1083 size_t sidlen; 1084 1085 TRACE_ENTRY("%p %p %p %p", cs, diam_ans, rad_fw, cli); 1086 CHECK_PARAMS(cs && diam_ans && *diam_ans && rad_fw && *rad_fw); 1084 1087 1085 1088 /* Retrieve the request identified which was stored in the session */ 1086 if (session) { 1087 CHECK_FCT( fd_sess_state_retrieve( cs->sess_hdl, session, &req_auth ) ); 1088 } 1089 CHECK_FCT( fd_msg_sess_get(fd_g_config->cnf_dict, *diam_ans, &sess, NULL) ); 1090 if (sess) { 1091 CHECK_FCT( fd_sess_state_retrieve( cs->sess_hdl, sess, &req_auth ) ); 1092 CHECK_FCT( fd_sess_getsid(sess, &sid, &sidlen) ); 1093 } /* else ? */ 1089 1094 1090 1095 /* … … 1145 1150 1146 1151 /* Search the different AVPs we handle here */ 1147 CHECK_FCT( fd_msg_search_avp (*diam_ans, cs->dict.Session_Id, &asid) );1148 CHECK_FCT( fd_msg_avp_hdr ( asid, &sid ) );1149 1152 CHECK_FCT( fd_msg_search_avp (*diam_ans, cs->dict.Origin_Host, &aoh) ); 1150 1153 CHECK_FCT( fd_msg_avp_hdr ( aoh, &oh ) ); … … 1240 1243 ahdr->avp_value->u32, 1241 1244 oh->avp_value->os.len, oh->avp_value->os.data, 1242 sid ->avp_value->os.len, sid->avp_value->os.data);1245 sidlen, sid); 1243 1246 CHECK_FCT( fd_msg_search_avp (*diam_ans, cs->dict.Error_Message, &avp_x) ); 1244 1247 if (avp_x) { … … 1271 1274 (int)oh->avp_value->os.len, (char *)oh->avp_value->os.data, 1272 1275 (int)ahdr->avp_value->os.len, (char *)ahdr->avp_value->os.data, 1273 (int)sid ->avp_value->os.len, (char *)sid->avp_value->os.data))) {1276 (int)sidlen, (char *)sid))) { 1274 1277 TRACE_DEBUG(INFO, "Data truncated in State attribute: %s", buf); 1275 1278 } … … 1280 1283 /* Add the Session-Id */ 1281 1284 if (sizeof(buf) < (sz = snprintf((char *)buf, sizeof(buf), "Diameter/%.*s", 1282 (int)sid ->avp_value->os.len, sid->avp_value->os.data))) {1285 (int)sidlen, sid))) { 1283 1286 TRACE_DEBUG(INFO, "Data truncated in Class attribute: %s", buf); 1284 1287 } … … 1455 1458 ((ahdr->avp_value->u32 == 2) ? "AUTHORIZE_ONLY" : "???"), 1456 1459 oh->avp_value->os.len, oh->avp_value->os.data, 1457 sid ->avp_value->os.len, sid->avp_value->os.len);1460 sidlen, sid); 1458 1461 } 1459 1462 break; … … 1616 1619 fd_log_debug("[auth.rgwx] Received Diameter answer with non-translatable NAS-Filter-Rule AVP from '%.*s' (session: '%.*s'), ignoring.", 1617 1620 oh->avp_value->os.len, oh->avp_value->os.data, 1618 sid ->avp_value->os.len, sid->avp_value->os.data);1621 sidlen, sid); 1619 1622 handled = 0; 1620 1623 break; … … 1649 1652 fd_log_debug("[auth.rgwx] Received Diameter answer with non-translatable QoS-Filter-Rule AVP from '%.*s' (session: '%.*s'), ignoring.", 1650 1653 oh->avp_value->os.len, oh->avp_value->os.data, 1651 sid ->avp_value->os.len, sid->avp_value->os.data);1654 sidlen, sid); 1652 1655 handled = 0; 1653 1656 break; … … 1921 1924 } 1922 1925 1923 CHECK_FCT( fd_msg_free( asid ) );1924 1926 CHECK_FCT( fd_msg_free( aoh ) ); 1925 1927 free(req_auth); … … 1930 1932 return ENOMEM; 1931 1933 } 1932 } 1934 } 1933 1935 1934 1936 if ((*rad_fw)->hdr->code == RADIUS_CODE_ACCESS_ACCEPT) {
Note: See TracChangeset
for help on using the changeset viewer.