Trusted Solaris Developer's Guide

Translating Privileges

These library routines convert the specified privilege ID to its corresponding external name or numeric ID and back. These routines read the privilege names database file described on the priv_name(4) man page to translate between the priv_id and *string.

Privilege ID to String

In this example, priv_id is initialized to the manifest constant name PRIV_FILE_DAC_WRITE and passed to priv_to_str(3TSOL) routine to convert it to the external name.

The header files and declarations for the code segments in this section are provided in the first program.

#include <tsol/priv.h>

main()
{
	priv_t priv_id = PRIV_FILE_DAC_WRITE;
	char *string;

	string = priv_to_str(priv_id);
	printf("Priv string = %s\n", string);
}

The printf statement prints the following:


Priv string = file_dac_write

String to Privilege ID

In the next example, the string returned from the priv_to_str(3TSOL) routine is passed to the str_to_priv(3TSOL) routine to convert the string to the numeric ID.

	priv_id = str_to_priv(string);
	printf("Priv ID = %d\n", priv_id);

The printf statement prints the following:


Priv ID = 6