[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]

Technical Reference: Base Operating System and Extensions , Volume 2

setpcred Subroutine


Sets the current process credentials.


Security Library (libc.a)


#include <usersec.h>

int setpcred ( User,  Credentials)
char **Credentials;
char *User;


The setpcred subroutine sets a process' credentials according to the Credentials parameter. If the User parameter is specified, the credentials defined for the user in the user database are used. If the Credentials parameter is specified, the credentials in this string are used. If both the User and Credentials parameters are specified, both the user's and the supplied credentials are used. However, the supplied credentials of the Credentials parameter will override those of the user. At least one parameter must be specified.

The setpcred subroutine requires the setpenv subroutine to follow it.

Note: If the auditwrite subroutine is to be called from a program invoked from the inittab file, the setpcred subroutine should be called first to establish the process' credentials.

User Specifies the user for whom credentials are being established.
Credentials Defines specific credentials to be established. This parameter points to an array of null-terminated character strings that may contain the following values. The last character string must be null.

Login user name

Real user name

Real group name

Supplementary group ID

Audit classes

Process soft CPU limit

Process soft file size

Process soft data segment size

Process soft stack segment size

Process soft core file size

Process soft resident set size

Process hard core file size

Process hard CPU limit

Process hard data segment size

Process hard file size

Process hard resident set size

Process hard stack segment size

Process umask (file creation mask)

A process must have root user authority to set all credentials except the UMASK credential.

Resource       Hard          Soft
RLIMIT_CORE    unlimited     %d
RLIMIT_CPU     %d            %d
RLIMIT_DATA    unlimited     %d
RLIMIT_FSIZE   %d            %d
RLIMIT_RSS     unlimited     %d
RLIMIT_STACK   unlimited     %d

The soft limit credentials will override the equivalent hard limit credentials that may proceed them. To set the hard limits, the hard limit credentials should follow the soft limit credentials.

Return Values

Upon successful return, the setpcred subroutine returns a value of 0. If setpcred fails, a value of -1 is returned and the errno global variable is set to indicate the error.

Error Codes

The setpcred subroutine fails if one or more of the following are true:

EINVAL The Credentials parameter contains invalid credentials specifications.
EINVAL The User parameter is null and the Credentials parameter is either null or points to an empty string.
EPERM The process does not have the proper authority to set the requested credentials.

Other errors may be set by subroutines invoked by the setpcred subroutine.

Implementation Specifics

This subroutine is part of Base Operating System (BOS) Runtime.

Related Information

The auditwrite subroutine, ckuseracct subroutine, ckuserID subroutine, getpcred subroutine, getpenv subroutine, setpenv (setpenv Subroutine) subroutine.

List of Security and Auditing Subroutines, Subroutines Overview in AIX 5L Version 5.1 General Programming Concepts: Writing and Debugging Programs.

[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]