* Note: destructively consumes the string, make a local copy before calling * if that's a problem. */
| 652 | * if that's a problem. |
| 653 | */ |
| 654 | static int |
| 655 | mls_parse(struct mac_mls *mm, char *string) |
| 656 | { |
| 657 | char *rangehigh, *rangelow, *effective; |
| 658 | int error; |
| 659 | |
| 660 | effective = strsep(&string, "("); |
| 661 | if (*effective == '\0') |
| 662 | effective = NULL; |
| 663 | |
| 664 | if (string != NULL) { |
| 665 | rangelow = strsep(&string, "-"); |
| 666 | if (string == NULL) |
| 667 | return (EINVAL); |
| 668 | rangehigh = strsep(&string, ")"); |
| 669 | if (string == NULL) |
| 670 | return (EINVAL); |
| 671 | if (*string != '\0') |
| 672 | return (EINVAL); |
| 673 | } else { |
| 674 | rangelow = NULL; |
| 675 | rangehigh = NULL; |
| 676 | } |
| 677 | |
| 678 | KASSERT((rangelow != NULL && rangehigh != NULL) || |
| 679 | (rangelow == NULL && rangehigh == NULL), |
| 680 | ("mls_parse: range mismatch")); |
| 681 | |
| 682 | bzero(mm, sizeof(*mm)); |
| 683 | if (effective != NULL) { |
| 684 | error = mls_parse_element(&mm->mm_effective, effective); |
| 685 | if (error) |
| 686 | return (error); |
| 687 | mm->mm_flags |= MAC_MLS_FLAG_EFFECTIVE; |
| 688 | } |
| 689 | |
| 690 | if (rangelow != NULL) { |
| 691 | error = mls_parse_element(&mm->mm_rangelow, rangelow); |
| 692 | if (error) |
| 693 | return (error); |
| 694 | error = mls_parse_element(&mm->mm_rangehigh, rangehigh); |
| 695 | if (error) |
| 696 | return (error); |
| 697 | mm->mm_flags |= MAC_MLS_FLAG_RANGE; |
| 698 | } |
| 699 | |
| 700 | error = mls_valid(mm); |
| 701 | if (error) |
| 702 | return (error); |
| 703 | |
| 704 | return (0); |
| 705 | } |
| 706 | |
| 707 | static int |
| 708 | mls_internalize_label(struct label *label, char *element_name, |
no test coverage detected