* biba_to_string() converts a Biba label to a string, and places the results * in the passed sbuf. It returns 0 on success, or EINVAL if there isn't * room in the sbuf. Note: the sbuf will be modified even in a failure case, * so the caller may need to revert the sbuf by restoring the offset if * that's undesired. */
| 586 | * that's undesired. |
| 587 | */ |
| 588 | static int |
| 589 | biba_to_string(struct sbuf *sb, struct mac_biba *mb) |
| 590 | { |
| 591 | |
| 592 | if (mb->mb_flags & MAC_BIBA_FLAG_EFFECTIVE) { |
| 593 | if (biba_element_to_string(sb, &mb->mb_effective) == -1) |
| 594 | return (EINVAL); |
| 595 | } |
| 596 | |
| 597 | if (mb->mb_flags & MAC_BIBA_FLAG_RANGE) { |
| 598 | if (sbuf_putc(sb, '(') == -1) |
| 599 | return (EINVAL); |
| 600 | |
| 601 | if (biba_element_to_string(sb, &mb->mb_rangelow) == -1) |
| 602 | return (EINVAL); |
| 603 | |
| 604 | if (sbuf_putc(sb, '-') == -1) |
| 605 | return (EINVAL); |
| 606 | |
| 607 | if (biba_element_to_string(sb, &mb->mb_rangehigh) == -1) |
| 608 | return (EINVAL); |
| 609 | |
| 610 | if (sbuf_putc(sb, ')') == -1) |
| 611 | return (EINVAL); |
| 612 | } |
| 613 | |
| 614 | return (0); |
| 615 | } |
| 616 | |
| 617 | static int |
| 618 | biba_externalize_label(struct label *label, char *element_name, |
no test coverage detected