Trusted Solaris Developer's Guide

Set SL Portion of File CMW Label

In this example, the process is running at Confidential with a Top Secret clearance. The process upgrades the sensitivity label portion of a file's CMW label to Top Secret and needs the file_upgrade_sl privileges because a label upgrade is a task that always requires privilege. The code comments indicate where privilege bracketing as described in Chapter 3, Privileges should take place.

A process cannot upgrade an object's sensitivity label to a higher level than its own clearance. "Find Greatest Level and Lowest Level"" describes how to check the process clearance against a sensitivity label.

If the system administrator has configured the system in the /etc/system file to not show file names when a file's CMW label has been upgraded, the upgraded file in this example will not be visible to a user who logs in at Confidential and lists the directory. See "Query System Security Configuration" for information on querying the system variables.


Note -

In the character-coded to binary translation, a new label is created with the NEW_LABEL flag parameter. See "Text to Binary and Hexadecimal Label Translation Routines" for information on the text to binary label translation and the flag parameter.


The SETCL_SL value passed to the setcmwlabel(2) system call indicates that the sensitivity portion is to be set. The new sensitivity label must be in the containing file system's label range, and the required privileges must be effective.

#include <tsol/label.h>

main()
{
	int retval, error;
	bclabel_t fileCMWlabel;
	bslabel_t fsenslabel;
	char *string = "TOP SECRET", 
	  *string1 = "TOP SECRET";

/* Create new sensitivity label value */
/* Turn sys_trans_label on in the effective set */
	retval = stobsl(string, &fsenslabel, NEW_LABEL, &error);
/* Turn sys_trans_label off */

/* Set sensitivity label portion of CMW label to new value */
	setcsl(&fileCMWlabel, &fsenslabel);

/* Set file CMW label */
/* Turn file_upgrade_sl privilege on in the effective set */
	retval = setcmwlabel("/export/home/zelda/afile", 
	  &fileCMWlabel, SETCL_SL);
 /* Turn file_upgrade_sl off */
 }

Use getlabel(1) to check the change in the file label. Before the program above runs, the CMW label for afile is as follows:


phoenix%  getlabel afile
afile: [CONFIDENTIAL]

After the program runs, the CMW label is as follows. Be aware that if you use the getlabel(1) command at Confidential, you will need the sys_trans_label privilege to read the label on a Top Secret file.


phoenix%  getlabel afile
afile: [TOP SECRET]