* Note: destructively consumes the string, make a local copy before calling * if that's a problem. */
| 686 | * if that's a problem. |
| 687 | */ |
| 688 | static int |
| 689 | biba_parse(struct mac_biba *mb, char *string) |
| 690 | { |
| 691 | char *rangehigh, *rangelow, *effective; |
| 692 | int error; |
| 693 | |
| 694 | effective = strsep(&string, "("); |
| 695 | if (*effective == '\0') |
| 696 | effective = NULL; |
| 697 | |
| 698 | if (string != NULL) { |
| 699 | rangelow = strsep(&string, "-"); |
| 700 | if (string == NULL) |
| 701 | return (EINVAL); |
| 702 | rangehigh = strsep(&string, ")"); |
| 703 | if (string == NULL) |
| 704 | return (EINVAL); |
| 705 | if (*string != '\0') |
| 706 | return (EINVAL); |
| 707 | } else { |
| 708 | rangelow = NULL; |
| 709 | rangehigh = NULL; |
| 710 | } |
| 711 | |
| 712 | KASSERT((rangelow != NULL && rangehigh != NULL) || |
| 713 | (rangelow == NULL && rangehigh == NULL), |
| 714 | ("biba_parse: range mismatch")); |
| 715 | |
| 716 | bzero(mb, sizeof(*mb)); |
| 717 | if (effective != NULL) { |
| 718 | error = biba_parse_element(&mb->mb_effective, effective); |
| 719 | if (error) |
| 720 | return (error); |
| 721 | mb->mb_flags |= MAC_BIBA_FLAG_EFFECTIVE; |
| 722 | } |
| 723 | |
| 724 | if (rangelow != NULL) { |
| 725 | error = biba_parse_element(&mb->mb_rangelow, rangelow); |
| 726 | if (error) |
| 727 | return (error); |
| 728 | error = biba_parse_element(&mb->mb_rangehigh, rangehigh); |
| 729 | if (error) |
| 730 | return (error); |
| 731 | mb->mb_flags |= MAC_BIBA_FLAG_RANGE; |
| 732 | } |
| 733 | |
| 734 | error = biba_valid(mb); |
| 735 | if (error) |
| 736 | return (error); |
| 737 | |
| 738 | return (0); |
| 739 | } |
| 740 | |
| 741 | static int |
| 742 | biba_internalize_label(struct label *label, char *element_name, |
no test coverage detected