| 707 | | void |
|---|
| 708 | | parse_trusted_mac_list(char *ptr) |
|---|
| 709 | | { |
|---|
| 710 | | char *mac; |
|---|
| 711 | | mac = (char *)safe_malloc(18); |
|---|
| 712 | | t_trusted_mac *p; |
|---|
| 713 | | |
|---|
| 714 | | while (1 == sscanf(ptr, "%17s", mac)) { |
|---|
| 715 | | if (config.trustedmaclist == NULL) { |
|---|
| 716 | | config.trustedmaclist = safe_malloc(sizeof(t_trusted_mac)); |
|---|
| 717 | | config.trustedmaclist->mac = mac; |
|---|
| 718 | | config.trustedmaclist->next = NULL; |
|---|
| 719 | | } else { |
|---|
| 720 | | /* Advance to the last entry */ |
|---|
| 721 | | for (p = config.trustedmaclist; p->next != NULL; p = p->next); |
|---|
| 722 | | p->next = safe_malloc(sizeof(t_trusted_mac)); |
|---|
| 723 | | p = p->next; |
|---|
| 724 | | p->mac = mac; |
|---|
| 725 | | p->next = NULL; |
|---|
| 726 | | } |
|---|
| 727 | | |
|---|
| 728 | | /* We put our pointer in the structure, re-allocate memory */ |
|---|
| 729 | | mac = (char *)safe_malloc(18); |
|---|
| 730 | | |
|---|
| 731 | | while (*ptr != '\n' && *ptr != ',') |
|---|
| 732 | | ptr++; |
|---|
| 733 | | /* Advance one more to actually begin the next MAC */ |
|---|
| 734 | | ptr++; |
|---|
| 735 | | } |
|---|
| 736 | | |
|---|
| 737 | | free(mac); |
|---|
| | 706 | void parse_trusted_mac_list(char *ptr) { |
|---|
| | 707 | char *ptrcopy = NULL; |
|---|
| | 708 | char *possiblemac = NULL; |
|---|
| | 709 | char *mac = NULL; |
|---|
| | 710 | t_trusted_mac *p = NULL; |
|---|
| | 711 | |
|---|
| | 712 | debug(LOG_DEBUG, "Parsing string [%s] for trusted MAC addresses", ptr); |
|---|
| | 713 | |
|---|
| | 714 | mac = safe_malloc(18); |
|---|
| | 715 | |
|---|
| | 716 | /* strsep modifies original, so let's make a copy */ |
|---|
| | 717 | ptrcopy = safe_strdup(ptr); |
|---|
| | 718 | |
|---|
| | 719 | while ((possiblemac = strsep(&ptrcopy, ", "))) { |
|---|
| | 720 | if (sscanf(possiblemac, " %17[A-Fa-f0-9:]", mac) == 1) { |
|---|
| | 721 | /* Copy mac to the list */ |
|---|
| | 722 | |
|---|
| | 723 | debug(LOG_DEBUG, "Adding MAC address [%s] to trusted list", mac); |
|---|
| | 724 | |
|---|
| | 725 | if (config.trustedmaclist == NULL) { |
|---|
| | 726 | config.trustedmaclist = safe_malloc(sizeof(t_trusted_mac)); |
|---|
| | 727 | config.trustedmaclist->mac = safe_strdup(mac); |
|---|
| | 728 | config.trustedmaclist->next = NULL; |
|---|
| | 729 | } |
|---|
| | 730 | else { |
|---|
| | 731 | /* Advance to the last entry */ |
|---|
| | 732 | for (p = config.trustedmaclist; p->next != NULL; p = p->next); |
|---|
| | 733 | p->next = safe_malloc(sizeof(t_trusted_mac)); |
|---|
| | 734 | p = p->next; |
|---|
| | 735 | p->mac = safe_strdup(mac); |
|---|
| | 736 | p->next = NULL; |
|---|
| | 737 | } |
|---|
| | 738 | |
|---|
| | 739 | } |
|---|
| | 740 | } |
|---|
| | 741 | |
|---|
| | 742 | free(ptrcopy); |
|---|
| | 743 | |
|---|
| | 744 | free(mac); |
|---|
| | 745 | |
|---|