Go to main content

man pages section 3: Basic Library Functions

Exit Print View

Updated: July 2017
 
 

getuserattrnam(3C)

Name

getuserattrnam - get a user's attribute

Synopsis

#include <user_attr.h>

char *getuserattrnam(const char *user, const char *key,
     char **where, const char *deflt);

char *getuserattruid(const uid_t userid, const char *key,
     char **where, const char *deflt);

Description

The getuserattrnam() function returns the first attribute value associated with key for user by searching first the attributes directly assigned to the user in user_attr(4), then the attributes of the profiles of the user, and finally an administrator-defined local default in the “defaults” style deflt file path. If deflt is NULL, policy.conf(4) is used. If where is non-null, the source of the returned value is returned in it. For example, the source could be user_attr, a Rights Profile name, or a “defaults” style file path name.

The getuserattruid() function operates the same as the getuserattrnam() function except that it takes a user ID rather then a user name for its first parameter.

Return Values

These functions return the value found for the user's attribute key. They return NULL if the no value found or if an error such as ENOMEM occurred. The value returned and, if specified, the value returned in where should be released when no longer in use with free(3C).

Errors

ENOMEM

There is insufficient memory to return the attribute value.

Examples

Example 1 Determine if the process is being run by a role.
#include <string.h>
#include <unistd.h>
#include <user_attr.h>
...
     char *type;

     if ((type = getuserattruid(getuid(), USERATTR_TYPE_KW, NULL,
         NULL)) != NULL) &&
         (strcmp(type, USERATTR_TYPE_NONADMIN_KW) == 0)) {
          /* is a role */
     } else {
          /* not a role */
     }

Attributes

See attributes(5) for descriptions of the following attributes:

ATTRIBUTE TYPE
ATTRIBUTE VALUE
Interface Stability
Committed
MT-Level
MT-Safe

See Also

free(3C), policy.conf(4), prof_attr(4), user_attr(4), attributes(5)