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

Preface

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

Index

Obtaining the Color Names of Labels

This code example uses the label_to_str() function to obtain the color name of a label. The mappings between color names and labels are defined in the label_encodings file.

#include <stdlib.h>
#include <stdio.h>

#include <tsol/label.h>

int
main()
{
   m_label_t *plabel;
   char *label = NULL;
   char *color = NULL;

   plabel = m_label_alloc(MAC_LABEL);

   if (getplabel(plabel) == -1) {
      perror("getplabel");
      exit(1);
   }

   if (label_to_str(plabel, &color, M_COLOR, 0) != 0) {
      perror("label_to_string(M_COLOR)");
      exit(1);
   }
   if (label_to_str(plabel, &label, M_LABEL, DEF_NAMES) != 0) {
      perror("label_to_str(M_LABEL)");
      exit(1);
   }

   printf("The color for the \"%s\" label is \"%s\".\n, label, color);

   m_label_free(plabel);

   return (0);
}

If the label_encodings file maps the color blue to the label CONFIDENTIAL, the program prints the following:

The color for the "CONFIDENTIAL" label is "BLUE".