Privilege bracketing

Once applications have been modified to check for authorizations, they can be further modified to utilize fine-grained privilege bracketing during operation.

Applications can use the priv_raise API to raise the privileges required to perform an operation and lower the privilege with the priv_lower API. Raising privileges immediately before a privileged operation is attempted and lowering privileges after the operation has completed is known as privileged bracketing and is the preferred method for applications to use privileges. To raise a privilege, the privilege needs to be available in the maximum privilege set of the application in the privileged commands database. Raising a privilege causes the privilege to be placed in the effective privilege set (EPS) of the process. Lowering a privilege removes the privilege from the EPS. The following code sample shows privilege bracketing around the auditproc API.
priv_raise(PV_AU_ADMIN, -1);	/* raise privilege when needed */ 
auditproc();  			/* call auditing system call */ 
priv_lower(PV_AU_ADMIN, -1);	/* lower privilege */