Trusted Solaris Developer's Guide

Query MLD and SLD Name

The following code queries the MLD adornment with the getmldadorn(2) system call and queries the SLD name for the Top Secret SLD with the getsldname(2) system call. In this example, the Top Secret SLD does not already exist, so the call to getsldname(2) will create it.

The process is running at Confidential with a clearance of Top Secret. The process needs the sys_trans_label privilege to translate the Top Secret label, the file_upgrade_sl privilege to create the Top Secret SLD, and the file_mac_search and file_mac_read privileges to access the Top Secret SLD information.

#include <tsol/label.h>

main()
{
	int retval, error, length;
	bslabel_t label;
	char *buffer[1025], *buf[1025], *string = "TOP SECRET";
	char *file = "/export/home/zelda";

	retval = getmldadorn(file, buffer);
	printf("MLD adornment = %s\n", buffer);

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

	length = sizeof(buf);

/* Turn file_upgrade_sl, file_mac_search, and file_mac_read on */
	retval = getsldname(file, &label, buf, length);
/* Turn file_upgrade_sl, file_mac_search, and file_mac_read off*/

	printf("SLD name = %s\n", buf);
}

The printf(1) statements print the following:


MLD adornment = .MLD.
SLD name = .SLD.3

This example queries the current working directory (MLD plus current SLD) with the mldgetcwd(3TSOL) routine, gets the adorned name for the MLD with the adornfc(1) routine, and finds the real path with the mldrealpath(1) routine by removing the extra slash in the path name stored in resolvefile. The process is running at Confidential.

#include <tsol/label.h>
#include <sys/types.h>

main()
{
	int retval;
	char *buffer[1025];
	char *file = "/export/home/zelda";
	char *string2, *name[1025], *string3, *resolved[1025];
	size_t size;

/* Character string with errors to be resolved */
	char *resolvefile = "./";

	size = sizeof(buffer);
	string2 = (char *)mldgetcwd(buffer, size);
	printf("Current working directory = %s\n", buffer);

	retval = adornfc(file, name);
	printf("Adorned name = %s\n", name);

	string3 = (char *)mldrealpath(resolvefile, resolved);
	printf("Real path = %s\n", resolved);
}

The printf statements print the following:


Note -

If the SLD name is included in the file parameter to the adornfc(1) routine, the adorned name is returned with the SLD appended in the form /export/home/zelda/.MLD..SLD.1.



Current working directory = /export/home/.MLD.zelda/.SLD.2
Adorned name = /export/home/.MLD.zelda
Real path = /export/home/.MLD.zelda/.SLD.2

This example gets attribute information for the /export/home/zelda MLD. In the printf(1) statements, the stat(2) system call macros test whether the MLD is a directory or regular file, and the time returned in seconds is converted to a human-readable time with the ctime(3C) routine.

#include <tsol/label.h>
#include <sys/stat.h>

main()
{
	int retval;
	struct stat statbuf;
	char *file = "/export/home/zelda";

	retval = mldstat(file, &statbuf);

	printf("Is file system object a directory? = %d\n",
		S_ISDIR(statbuf.st_mode));

	printf("Is file system object a regular file? = %d\n",
		S_ISREG(statbuf.st_mode));

	printf("Number of links = %d\n", statbuf.st_nlink);
	printf("Owner's user ID = %d\n", statbuf.st_uid);
	printf("Owner's group Id = %d\n", statbuf.st_gid);
	printf("Last access time = %s\n", ctime(&statbuf.st_atime));
	printf("Last modify time = %s\n", ctime(&statbuf.st_mtime));
	printf("Last status change = %s\n", ctime(&statbuf.st_ctime));
}

The printf statements print the following:


Is file system object a directory? = 1
Is file system object a regular file? = 0
Number of links = 6
Owner's user ID = 29378
Owner's group Id = 10
Last access time = Wed May 28 10:58:25 1999
Last modify time = Wed May 28 09:39:18 1999
Last status change = Wed May 28 09:39:18 1999