This example translates text strings to a binary CMW label or sensitivity label using the following flag values:
NEW_LABEL - Create a new label and correct the string as much as possible so the binary label is a complete and valid label for the system as defined in label_encodings(4). If the correction cannot be made, an error is returned. The string can be a text or hexadecimal string.
NO_CORRECTION - Create a new label, but do not correct the construction of the string. If the string is not a complete and valid label for the system, an error is returned. The string can be a text hexadecimal string.
Text CMW labels are accepted in the following form: [sensitivity_label]
.
Text sensitivity and information labels are accepted in the following forms. Input items can be separated by white space, commas, or slashes (/). Short and long forms of classification names and words are interchangeable.
{+} {classification} {{+|-}{word}...
The vertical bar (|) indicates a choice between two items. Leading and trailing white space is ignored.
The plus and minus signs can be used to modify an existing label to turn on or off the compartments and markings associated with the words.
Curly braces indicate optional items and ellipses indicate repeated words. In a sensitivity label, the words represent compartments.
This example translates text strings to a binary CMW label and sensitivity label and back again using the NEW_LABEL flag. An example of translating a sensitivity label to a specified length (clipping) is also given. If the process runs at [TS A B]
or higher, the sys_trans_label
privilege is not needed for the label translations.
#include <tsol/label.h> main() { int retval, error, length = 0; char *cmwstring ="SECRET A B [TOP SECRET A B]"; char *sensstring = "TOP SECRET A B"; char *string1 = (char *)0, *string2 = (char *)0, *string3 = (char *)0; bclabel_t cmwlabel; bslabel_t senslabel; retval = stobcl(cmwstring, &cmwlabel, NEW_LABEL, &error); retval = bcltos(&cmwlabel, &string1, length, ALL_ENTRIES); retval = stobsl(sensstring, &senslabel, NEW_LABEL, &error); retval = bsltos(&senslabel, &string2, length, ALL_ENTRIES); string3 = sbsltos(&senslabel, 4); printf("CMW label = %s\nSens label = %s\nClipped label = %s\n'', string1, string2, string3); }
The printf statement prints the following. In the clipped label, the arrow <-indicates the sensitivity label name has clipped letters.
CMW label = [TS A B] Sens label = TS A B Clipped label = TS<- |