* Note: destructively consumes the string, make a local copy before calling * if that's a problem. */
| 749 | * if that's a problem. |
| 750 | */ |
| 751 | static int |
| 752 | lomac_parse(struct mac_lomac *ml, char *string) |
| 753 | { |
| 754 | char *range, *rangeend, *rangehigh, *rangelow, *single, *auxsingle, |
| 755 | *auxsingleend; |
| 756 | int error; |
| 757 | |
| 758 | /* Do we have a range? */ |
| 759 | single = string; |
| 760 | range = strchr(string, '('); |
| 761 | if (range == single) |
| 762 | single = NULL; |
| 763 | auxsingle = strchr(string, '['); |
| 764 | if (auxsingle == single) |
| 765 | single = NULL; |
| 766 | if (range != NULL && auxsingle != NULL) |
| 767 | return (EINVAL); |
| 768 | rangelow = rangehigh = NULL; |
| 769 | if (range != NULL) { |
| 770 | /* Nul terminate the end of the single string. */ |
| 771 | *range = '\0'; |
| 772 | range++; |
| 773 | rangelow = range; |
| 774 | rangehigh = strchr(rangelow, '-'); |
| 775 | if (rangehigh == NULL) |
| 776 | return (EINVAL); |
| 777 | rangehigh++; |
| 778 | if (*rangelow == '\0' || *rangehigh == '\0') |
| 779 | return (EINVAL); |
| 780 | rangeend = strchr(rangehigh, ')'); |
| 781 | if (rangeend == NULL) |
| 782 | return (EINVAL); |
| 783 | if (*(rangeend + 1) != '\0') |
| 784 | return (EINVAL); |
| 785 | /* Nul terminate the ends of the ranges. */ |
| 786 | *(rangehigh - 1) = '\0'; |
| 787 | *rangeend = '\0'; |
| 788 | } |
| 789 | KASSERT((rangelow != NULL && rangehigh != NULL) || |
| 790 | (rangelow == NULL && rangehigh == NULL), |
| 791 | ("lomac_internalize_label: range mismatch")); |
| 792 | if (auxsingle != NULL) { |
| 793 | /* Nul terminate the end of the single string. */ |
| 794 | *auxsingle = '\0'; |
| 795 | auxsingle++; |
| 796 | auxsingleend = strchr(auxsingle, ']'); |
| 797 | if (auxsingleend == NULL) |
| 798 | return (EINVAL); |
| 799 | if (*(auxsingleend + 1) != '\0') |
| 800 | return (EINVAL); |
| 801 | /* Nul terminate the end of the auxsingle. */ |
| 802 | *auxsingleend = '\0'; |
| 803 | } |
| 804 | |
| 805 | bzero(ml, sizeof(*ml)); |
| 806 | if (single != NULL) { |
| 807 | error = lomac_parse_element(&ml->ml_single, single); |
| 808 | if (error) |
no test coverage detected