Solaris Trusted Extensions Developer's Guide
Previous Next

Obtaining a File Label

You can obtain a file's sensitivity label and perform operations on that label.

This code example uses the getlabel() routine to obtain the file's label. The fgetlabel() routine can be used in the same way, but it operates on a file descriptor.

#include <tsol/label.h>

main()
{
    m_label_t* docLabel;
    const char* path = "/zone/restricted/documents/designdoc.odt";
    int retval;
    char* label_string;

    /* allocate label and get the file label specified by path */
    docLabel = m_label_alloc(MAC_LABEL);
    retval = getlabel(path, docLabel);

    /* translate the file's label to a string and print the string */
    retval = label_to_str(docLabel, &label_string, M_LABEL, LONG_NAMES);
    printf("The file's label = %s\n", label_string);
    
    /* free allocated memory */
    m_label_free(docLabel);
    free(label_string);
    }

When you run this program, the output might look similar to this:

The file's label = CONFIDENTIAL : INTERNAL USE ONLY
Previous Next