Navigation


Changeset 996:cf09fde3d7f5 in freeDiameter for extensions/app_radgw/radius.c


Ignore:
Timestamp:
Mar 20, 2013, 12:13:14 AM (11 years ago)
Author:
Sebastien Decugis <sdecugis@freediameter.net>
Branch:
default
Children:
997:632913581c37, 998:ad6c1ee04d2d
Phase:
public
Message:

Fix management of sessions in app_radgw: sessions are simply associated with messages, that is sufficient

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/app_radgw/radius.c

    r979 r996  
    5757/*********************************************************************************/
    5858#include "rgw.h"
    59 
    60 /* Overwrite printf */
    61 #define printf(args...) fd_log_debug(args)
    62 
    6359
    6460static struct radius_attr_hdr *
     
    237233}
    238234
    239 
    240 static void print_char(char c)
     235static char print_char_buf[5];
     236
     237static char * print_char(char c)
    241238{
    242239        if (c >= 32 && c < 127)
    243                 printf("%c", c);
     240                sprintf(print_char_buf, "%c", c);
    244241        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
     247static char * radius_msg_dump_attr_val(struct radius_attr_hdr *hdr, char * outbuf, size_t buflen)
    250248{
    251249        struct radius_attr_type *attr;
     
    253251        unsigned char *pos;
    254252        u8 attrtype;
     253        size_t offset = 0;
     254       
     255        memset(outbuf, 0, buflen);
    255256
    256257        attr = radius_get_attr_type(hdr->type);
     
    266267        switch (attrtype) {
    267268        case RADIUS_ATTR_TEXT:
    268                 printf("      Value: '");
     269                snprintf(outbuf + strlen(outbuf), buflen - strlen(outbuf), "      Value: '");
    269270                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), "'");
    272273                break;
    273274
     
    276277                        struct in_addr addr;
    277278                        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));
    279280                } else
    280                         printf("      Invalid IP address length %d\n", len);
     281                        snprintf(outbuf + strlen(outbuf), buflen - strlen(outbuf), "      Invalid IP address length %d", len);
    281282                break;
    282283
     
    287288                        struct in6_addr *addr = (struct in6_addr *) pos;
    288289                        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 : "?");
    290291                } else
    291                         printf("      Invalid IPv6 address length %d\n", len);
     292                        snprintf(outbuf + strlen(outbuf), buflen - strlen(outbuf), "      Invalid IPv6 address length %d", len);
    292293                break;
    293294
    294295        case RADIUS_ATTR_INT32:
    295296                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));
    297298                else
    298                         printf("      Invalid INT32 length %d\n", len);
     299                        snprintf(outbuf + strlen(outbuf), buflen - strlen(outbuf), "      Invalid INT32 length %d", len);
    299300                break;
    300301
     
    302303        case RADIUS_ATTR_UNDIST:
    303304        default:
    304                 printf("      Value:");
     305                snprintf(outbuf + strlen(outbuf), buflen - strlen(outbuf), "      Value:");
    305306                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]);
    308308                break;
    309309        }
     310       
     311        return outbuf;
    310312}
    311313
     
    314316{
    315317        unsigned char *auth;
     318        char buf[256];
    316319        size_t i;
    317320        if (! TRACE_BOOL(FULL) )
     
    329332                struct radius_attr_hdr *attr = (struct radius_attr_hdr *)(msg->radius.buf + msg->radius.attr_pos[i]);
    330333                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)));
    332335        }
    333336        if (has_meta && msg->ps_nb) {
     
    336339                        struct radius_attr_hdr *attr = (struct radius_attr_hdr *)(msg->radius.buf + msg->radius.attr_pos[i]);
    337340                        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)));
    339342                }
    340343        }
     
    355358                                           auth, MD5_MAC_LEN);
    356359                if (attr == NULL) {
    357                         printf("WARNING: Could not add Message-Authenticator\n");
     360                        fd_log_debug("WARNING: Could not add Message-Authenticator");
    358361                        return -1;
    359362                }
     
    365368
    366369        if (msg->buf_used > 0xffff) {
    367                 printf("WARNING: too long RADIUS message (%lu)\n",
     370                fd_log_debug("WARNING: too long RADIUS message (%lu)",
    368371                       (unsigned long) msg->buf_used);
    369372                return -1;
     
    386389                                       auth, MD5_MAC_LEN);
    387390            if (attr == NULL) {
    388                     printf("WARNING: Could not add Message-Authenticator\n");
     391                    fd_log_debug("WARNING: Could not add Message-Authenticator");
    389392                    return -1;
    390393            }
     
    410413
    411414        if (msg->buf_used > 0xffff) {
    412                 printf("WARNING: too long RADIUS message (%lu)\n",
     415                fd_log_debug("WARNING: too long RADIUS message (%lu)",
    413416                       (unsigned long) msg->buf_used);
    414417                return -1;
     
    433436
    434437        if (msg->buf_used > 0xffff) {
    435                 printf("WARNING: too long RADIUS messages (%lu)\n",
     438                fd_log_debug("WARNING: too long RADIUS messages (%lu)",
    436439                       (unsigned long) msg->buf_used);
    437440        }
     
    468471
    469472        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)",
    471474                       (unsigned long) data_len);
    472475                return NULL;
     
    692695                if (tmp->type == RADIUS_ATTR_MESSAGE_AUTHENTICATOR) {
    693696                        if (attr != NULL) {
    694                                 printf("Multiple Message-Authenticator attributes in RADIUS message\n");
     697                                fd_log_debug("Multiple Message-Authenticator attributes in RADIUS message");
    695698                                return 1;
    696699                        }
     
    700703
    701704        if (attr == NULL) {
    702                 printf("No Message-Authenticator attribute found\n");
     705                fd_log_debug("No Message-Authenticator attribute found");
    703706                return 1;
    704707        }
     
    720723
    721724        if (os_memcmp(orig, auth, MD5_MAC_LEN) != 0) {
    722                 printf("Invalid Message-Authenticator!\n");
     725                fd_log_debug("Invalid Message-Authenticator!");
    723726                return 1;
    724727        }
     
    736739
    737740        if (sent_msg == NULL) {
    738                 printf("No matching Access-Request message found\n");
     741                fd_log_debug("No matching Access-Request message found");
    739742                return 1;
    740743        }
     
    757760        md5_vector(4, addr, len, hash);
    758761        if (os_memcmp(hash, msg->hdr->authenticator, MD5_MAC_LEN) != 0) {
    759                 printf("Response Authenticator invalid!\n");
     762                fd_log_debug("Response Authenticator invalid!");
    760763                return 1;
    761764        }
     
    895898        left = len - 2;
    896899        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);
    898901                return NULL;
    899902        }
     
    929932
    930933        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");
    932935                os_free(plain);
    933936                return NULL;
Note: See TracChangeset for help on using the changeset viewer.