Changeset 996:cf09fde3d7f5 in freeDiameter for extensions/app_radgw/radius.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/radius.c
r979 r996 57 57 /*********************************************************************************/ 58 58 #include "rgw.h" 59 60 /* Overwrite printf */61 #define printf(args...) fd_log_debug(args)62 63 59 64 60 static struct radius_attr_hdr * … … 237 233 } 238 234 239 240 static void print_char(char c) 235 static char print_char_buf[5]; 236 237 static char * print_char(char c) 241 238 { 242 239 if (c >= 32 && c < 127) 243 printf("%c", c);240 sprintf(print_char_buf, "%c", c); 244 241 else 245 printf("<%02x>", c); 246 } 247 248 249 static void radius_msg_dump_attr_val(struct radius_attr_hdr *hdr) 242 sprintf(print_char_buf, "<%02x>", c); 243 return print_char_buf; 244 } 245 246 247 static char * radius_msg_dump_attr_val(struct radius_attr_hdr *hdr, char * outbuf, size_t buflen) 250 248 { 251 249 struct radius_attr_type *attr; … … 253 251 unsigned char *pos; 254 252 u8 attrtype; 253 size_t offset = 0; 254 255 memset(outbuf, 0, buflen); 255 256 256 257 attr = radius_get_attr_type(hdr->type); … … 266 267 switch (attrtype) { 267 268 case RADIUS_ATTR_TEXT: 268 printf(" Value: '");269 snprintf(outbuf + strlen(outbuf), buflen - strlen(outbuf), " Value: '"); 269 270 for (i = 0; i < len; i++) 270 print_char(pos[i]);271 printf("'\n");271 snprintf(outbuf + strlen(outbuf), buflen - strlen(outbuf), "%s", print_char(pos[i])); 272 snprintf(outbuf + strlen(outbuf), buflen - strlen(outbuf), "'"); 272 273 break; 273 274 … … 276 277 struct in_addr addr; 277 278 os_memcpy(&addr, pos, 4); 278 printf(" Value: %s\n", inet_ntoa(addr));279 snprintf(outbuf + strlen(outbuf), buflen - strlen(outbuf), " Value: %s", inet_ntoa(addr)); 279 280 } else 280 printf(" Invalid IP address length %d\n", len);281 snprintf(outbuf + strlen(outbuf), buflen - strlen(outbuf), " Invalid IP address length %d", len); 281 282 break; 282 283 … … 287 288 struct in6_addr *addr = (struct in6_addr *) pos; 288 289 atxt = inet_ntop(AF_INET6, addr, buf, sizeof(buf)); 289 printf(" Value: %s\n", atxt ? atxt : "?");290 snprintf(outbuf + strlen(outbuf), buflen - strlen(outbuf), " Value: %s", atxt ? atxt : "?"); 290 291 } else 291 printf(" Invalid IPv6 address length %d\n", len);292 snprintf(outbuf + strlen(outbuf), buflen - strlen(outbuf), " Invalid IPv6 address length %d", len); 292 293 break; 293 294 294 295 case RADIUS_ATTR_INT32: 295 296 if (len == 4) 296 printf(" Value: %u\n", WPA_GET_BE32(pos));297 snprintf(outbuf + strlen(outbuf), buflen - strlen(outbuf), " Value: %u", WPA_GET_BE32(pos)); 297 298 else 298 printf(" Invalid INT32 length %d\n", len);299 snprintf(outbuf + strlen(outbuf), buflen - strlen(outbuf), " Invalid INT32 length %d", len); 299 300 break; 300 301 … … 302 303 case RADIUS_ATTR_UNDIST: 303 304 default: 304 printf(" Value:");305 snprintf(outbuf + strlen(outbuf), buflen - strlen(outbuf), " Value:"); 305 306 for (i = 0; i < len; i++) 306 printf(" %02x", pos[i]); 307 printf("\n"); 307 snprintf(outbuf + strlen(outbuf), buflen - strlen(outbuf), " %02x", pos[i]); 308 308 break; 309 309 } 310 311 return outbuf; 310 312 } 311 313 … … 314 316 { 315 317 unsigned char *auth; 318 char buf[256]; 316 319 size_t i; 317 320 if (! TRACE_BOOL(FULL) ) … … 329 332 struct radius_attr_hdr *attr = (struct radius_attr_hdr *)(msg->radius.buf + msg->radius.attr_pos[i]); 330 333 fd_log_debug(" - Type: 0x%02hhx (%s) Len: %-3hhu", attr->type, rgw_msg_attrtype_str(attr->type), attr->length); 331 radius_msg_dump_attr_val(attr);334 fd_log_debug("%s", radius_msg_dump_attr_val(attr, buf, sizeof(buf))); 332 335 } 333 336 if (has_meta && msg->ps_nb) { … … 336 339 struct radius_attr_hdr *attr = (struct radius_attr_hdr *)(msg->radius.buf + msg->radius.attr_pos[i]); 337 340 fd_log_debug(" - Type: 0x%02hhx (%s) Len: %-3hhu", attr->type, rgw_msg_attrtype_str(attr->type), attr->length); 338 radius_msg_dump_attr_val(attr);341 fd_log_debug("%s", radius_msg_dump_attr_val(attr, buf, sizeof(buf))); 339 342 } 340 343 } … … 355 358 auth, MD5_MAC_LEN); 356 359 if (attr == NULL) { 357 printf("WARNING: Could not add Message-Authenticator\n");360 fd_log_debug("WARNING: Could not add Message-Authenticator"); 358 361 return -1; 359 362 } … … 365 368 366 369 if (msg->buf_used > 0xffff) { 367 printf("WARNING: too long RADIUS message (%lu)\n",370 fd_log_debug("WARNING: too long RADIUS message (%lu)", 368 371 (unsigned long) msg->buf_used); 369 372 return -1; … … 386 389 auth, MD5_MAC_LEN); 387 390 if (attr == NULL) { 388 printf("WARNING: Could not add Message-Authenticator\n");391 fd_log_debug("WARNING: Could not add Message-Authenticator"); 389 392 return -1; 390 393 } … … 410 413 411 414 if (msg->buf_used > 0xffff) { 412 printf("WARNING: too long RADIUS message (%lu)\n",415 fd_log_debug("WARNING: too long RADIUS message (%lu)", 413 416 (unsigned long) msg->buf_used); 414 417 return -1; … … 433 436 434 437 if (msg->buf_used > 0xffff) { 435 printf("WARNING: too long RADIUS messages (%lu)\n",438 fd_log_debug("WARNING: too long RADIUS messages (%lu)", 436 439 (unsigned long) msg->buf_used); 437 440 } … … 468 471 469 472 if (data_len > RADIUS_MAX_ATTR_LEN) { 470 printf("radius_msg_add_attr: too long attribute (%lu bytes)\n",473 fd_log_debug("radius_msg_add_attr: too long attribute (%lu bytes)", 471 474 (unsigned long) data_len); 472 475 return NULL; … … 692 695 if (tmp->type == RADIUS_ATTR_MESSAGE_AUTHENTICATOR) { 693 696 if (attr != NULL) { 694 printf("Multiple Message-Authenticator attributes in RADIUS message\n");697 fd_log_debug("Multiple Message-Authenticator attributes in RADIUS message"); 695 698 return 1; 696 699 } … … 700 703 701 704 if (attr == NULL) { 702 printf("No Message-Authenticator attribute found\n");705 fd_log_debug("No Message-Authenticator attribute found"); 703 706 return 1; 704 707 } … … 720 723 721 724 if (os_memcmp(orig, auth, MD5_MAC_LEN) != 0) { 722 printf("Invalid Message-Authenticator!\n");725 fd_log_debug("Invalid Message-Authenticator!"); 723 726 return 1; 724 727 } … … 736 739 737 740 if (sent_msg == NULL) { 738 printf("No matching Access-Request message found\n");741 fd_log_debug("No matching Access-Request message found"); 739 742 return 1; 740 743 } … … 757 760 md5_vector(4, addr, len, hash); 758 761 if (os_memcmp(hash, msg->hdr->authenticator, MD5_MAC_LEN) != 0) { 759 printf("Response Authenticator invalid!\n");762 fd_log_debug("Response Authenticator invalid!"); 760 763 return 1; 761 764 } … … 895 898 left = len - 2; 896 899 if (left % 16) { 897 printf("Invalid ms key len %lu\n", (unsigned long) left);900 fd_log_debug("Invalid ms key len %lu", (unsigned long) left); 898 901 return NULL; 899 902 } … … 929 932 930 933 if (plain[0] == 0 || plain[0] > plen - 1) { 931 printf("Failed to decrypt MPPE key\n");934 fd_log_debug("Failed to decrypt MPPE key"); 932 935 os_free(plain); 933 936 return NULL;
Note: See TracChangeset
for help on using the changeset viewer.