1.2.9. pylibc

This module provides a wrapped interface for Linux’s libc. Most of this functionality is duplicated in Python’s own grp and pwd modules. This implementation however, using ctypes to directly interface with libc is necessary to avoid dead-lock issues when authenticating non-local users such as would be found in an environment using an LDAP server.

1.2.9.1. Functions

getgrnam(name, encoding='utf-8')[source]

Get the structure containing the fields from the specified entry in the group database. See getgrnam(3) for more information.

Parameters:
  • name (str) – The group name to look up.
  • encoding (str) – The encoding to use for strings.
Returns:

The entry from the group database or None if it was not found.

Return type:

tuple

getgrouplist(user, group=AUTOMATIC, encoding='utf-8')[source]

Get the groups that the specified user belongs to. If group is not specified, it will be looked up from the password record for user. See getgrouplist(3) for more information.

Parameters:
  • user (str) – The user name to look up.
  • group (int) – An optional group to add to the returned groups.
  • encoding (str) – The encoding to use for strings.
Returns:

The group IDs that user belongs to.

Return type:

tuple

getpwnam(name, encoding='utf-8')[source]

Get the structure containing the fields from the specified entry in the password database. See getpwnam(3) for more information.

Parameters:
  • name (str) – The user name to look up.
  • encoding (str) – The encoding to use for strings.
Returns:

The entry from the user database or None if it was not found.

Return type:

tuple

getpwuid(uid)[source]

Get the structure containing the fields from the specified entry in the password database. See getpwuid(3) for more information.

Parameters:uid (int) – The user id to look up.
Returns:The entry from the user database or None if it was not found.
Return type:tuple