* mls_element_to_string() accepts an sbuf and MLS element. It converts the * MLS element to a string and stores the result in the sbuf; if there isn't * space in the sbuf, -1 is returned. */
| 502 | * space in the sbuf, -1 is returned. |
| 503 | */ |
| 504 | static int |
| 505 | mls_element_to_string(struct sbuf *sb, struct mac_mls_element *element) |
| 506 | { |
| 507 | int i, first; |
| 508 | |
| 509 | switch (element->mme_type) { |
| 510 | case MAC_MLS_TYPE_HIGH: |
| 511 | return (sbuf_printf(sb, "high")); |
| 512 | |
| 513 | case MAC_MLS_TYPE_LOW: |
| 514 | return (sbuf_printf(sb, "low")); |
| 515 | |
| 516 | case MAC_MLS_TYPE_EQUAL: |
| 517 | return (sbuf_printf(sb, "equal")); |
| 518 | |
| 519 | case MAC_MLS_TYPE_LEVEL: |
| 520 | if (sbuf_printf(sb, "%d", element->mme_level) == -1) |
| 521 | return (-1); |
| 522 | |
| 523 | first = 1; |
| 524 | for (i = 1; i <= MAC_MLS_MAX_COMPARTMENTS; i++) { |
| 525 | if (MAC_MLS_BIT_TEST(i, element->mme_compartments)) { |
| 526 | if (first) { |
| 527 | if (sbuf_putc(sb, ':') == -1) |
| 528 | return (-1); |
| 529 | if (sbuf_printf(sb, "%d", i) == -1) |
| 530 | return (-1); |
| 531 | first = 0; |
| 532 | } else { |
| 533 | if (sbuf_printf(sb, "+%d", i) == -1) |
| 534 | return (-1); |
| 535 | } |
| 536 | } |
| 537 | } |
| 538 | return (0); |
| 539 | |
| 540 | default: |
| 541 | panic("mls_element_to_string: invalid type (%d)", |
| 542 | element->mme_type); |
| 543 | } |
| 544 | } |
| 545 | |
| 546 | /* |
| 547 | * mls_to_string() converts an MLS label to a string, and places the results |
no test coverage detected