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<- |