JavaScript is required to for searching.
Skip Navigation Links
Exit Print View
Oracle Solaris Trusted Extensions Developer's Guide     Oracle Solaris 10 8/11 Information Library
search filter icon
search icon

Document Information


1.  Trusted Extensions APIs and Security Policy

2.  Labels and Clearances

3.  Label Code Examples

Obtaining a Process Label

Obtaining a File Label

Setting a File Sensitivity Label

Determining the Relationship Between Two Labels

Obtaining the Color Names of Labels

Obtaining Printer Banner Information

4.  Printing and the Label APIs

5.  Interprocess Communications

6.  Trusted X Window System

7.  Label Builder APIs

8.  Trusted Web Guard Prototype

9.  Experimental Java Bindings for the Solaris Trusted Extensions Label APIs

A.  Programmer's Reference

B.  Trusted Extensions API Reference


Obtaining a Process Label

This code example shows how to obtain and print the sensitivity label of the zone in which this program is run.

#include <tsol/label.h>

    m_label_t* pl;
    char *plabel = NULL;
    int retval;

    /* allocate an m_label_t for the process sensitivity label */
    pl = m_label_alloc(MAC_LABEL);
    /* get the process sensitivity label */
    if ((retval = getplabel(pl)) != 0) {
        perror("getplabel(pl) failed");

    /* Translate the process sensitivity label to text and print */
    if ((retval = label_to_str(pl, &plabel, M_LABEL, LONG_NAMES)) != 0) {
        perror("label_to_str(M_LABEL, LONG_NAMES) failed");
    printf("Process label = %s\n", plabel);

    /* free allocated memory */

The printf() statement prints the sensitivity label. The sensitivity label is inherited from the zone in which the program is run. The following shows the text output of this example program:

Process label = ADMIN_LOW

The text output depends on the specifications in the label_encodings file.