Changeset 442:02e3976b9163 in freeDiameter
- Timestamp:
- Jul 28, 2010, 5:51:29 PM (14 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/app_radgw/rgw_clients.c
r403 r442 67 67 /* The FQDN, realm, and optional aliases */ 68 68 char *fqdn; 69 size_t fqdn_len; 69 70 char *realm; 70 71 char **aliases; … … 109 110 /* Copy the fqdn */ 110 111 CHECK_MALLOC( tmp->fqdn = strdup(buf) ); 112 tmp->fqdn_len = strlen(tmp->fqdn); 111 113 /* Find an appropriate realm */ 112 114 tmp->realm = strchr(tmp->fqdn, '.'); … … 370 372 /* Now check the nas_id */ 371 373 if (nas_id) { 374 char * str; 375 int found, ret; 376 struct addrinfo hint, *res, *ptr; 377 372 378 /* 373 379 In RADIUS it would be possible for a rogue NAS to forge the NAS- … … 386 392 found, then an error is logged, but no other action is taken. 387 393 */ 388 389 /* copy the alias */ 390 char * str; 391 int found, ret; 392 struct addrinfo hint, *res; 393 CHECK_MALLOC( str = malloc(nas_id->length - sizeof(struct radius_attr_hdr) + 1) ); 394 memcpy(str, nas_id + 1, nas_id->length - sizeof(struct radius_attr_hdr)); 395 str[nas_id->length - sizeof(struct radius_attr_hdr)] = '\0'; 396 397 /* Check if this alias is already in the aliases list */ 398 if (!strcasecmp(str, cli->fqdn)) { 394 395 /* first, check if the nas_id is the fqdn of the peer or a known alias */ 396 if ((cli->fqdn_len == (nas_id->length - sizeof(struct radius_attr_hdr))) 397 && (!strncasecmp((char *)(nas_id + 1), cli->fqdn, nas_id->length - sizeof(struct radius_attr_hdr)))) { 399 398 TRACE_DEBUG(FULL, "NAS-Identifier contains the fqdn of the NAS"); 400 399 found = 1; 401 400 } else { 402 401 for (idx = 0; idx < cli->aliases_nb; idx++) { 403 if (!strcasecmp(str, cli->aliases[idx])) { 402 if (((nas_id->length - sizeof(struct radius_attr_hdr)) == strlen(cli->aliases[idx])) 403 && (!strncasecmp((char *)(nas_id + 1), cli->aliases[idx], nas_id->length - sizeof(struct radius_attr_hdr)))) { 404 404 TRACE_DEBUG(FULL, "NAS-Identifier valid value found in the cache"); 405 405 found = 1; … … 410 410 411 411 if (found) { 412 free(str);413 412 msg->valid_nas_info |= 2; 414 413 goto end; 415 414 } 415 416 /* copy the identifier, we try to DNS resolve it */ 417 CHECK_MALLOC( str = malloc(nas_id->length - sizeof(struct radius_attr_hdr) + 1) ); 418 memcpy(str, nas_id + 1, nas_id->length - sizeof(struct radius_attr_hdr)); 419 str[nas_id->length - sizeof(struct radius_attr_hdr)] = '\0'; 416 420 417 421 /* Now check if this alias is valid for this peer */ … … 420 424 hint.ai_flags = AI_CANONNAME; 421 425 ret = getaddrinfo(str, NULL, &hint, &res); 422 if (ret) { 423 TRACE_DEBUG(INFO, "Error while resolving NAS-Identifier value '%s': %s. Discarding message...", str, gai_strerror(ret)); 424 free(str); 425 return EINVAL; 426 } 427 if (strcasecmp(cli->fqdn, res->ai_canonname)) { 428 TRACE_DEBUG(INFO, "The NAS-Identifier value is not valid: '%s' resolved to '%s', expected '%s'. Discarding...", str, res->ai_canonname, cli->fqdn); 429 free(str); 426 if (ret == 0) { 427 /* The name was resolved correctly, it must match the IP of the client: */ 428 for (ptr = res; ptr != NULL; ptr = ptr->ai_next) { 429 if (cli->sa->sa_family != ptr->ai_family) 430 continue; 431 if (memcmp(cli->sa, ptr->ai_addr, sSAlen(cli->sa))) 432 continue; 433 434 /* It matches: the alias is valid */ 435 found = 1; 436 break; 437 } 430 438 freeaddrinfo(res); 431 return EINVAL; 439 440 if (!found) { 441 TRACE_DEBUG(INFO, "The NAS-Identifier value '%s' resolves to a different IP from the NAS's, discarding the message.", str); 442 free(str); 443 return EINVAL; 444 } 445 } else { 446 /* Error resolving the name */ 447 TRACE_DEBUG(INFO, "Error while resolving NAS-Identifier value '%s': %s. Ignoring...", str, gai_strerror(ret)); 432 448 } 433 449 434 450 /* It is a valid alias, save it */ 435 freeaddrinfo(res);436 451 CHECK_MALLOC( cli->aliases = realloc(cli->aliases, (cli->aliases_nb + 1) * sizeof(char *)) ); 437 452 cli->aliases[cli->aliases_nb + 1] = str;
Note: See TracChangeset
for help on using the changeset viewer.