3728db53ac32da51fcaae96b132e8e56ebbaebfaJakub Hrozek# Module for simulation of utility "getent group -s sss" from coreutils
3728db53ac32da51fcaae96b132e8e56ebbaebfaJakub Hrozek# Copyright (c) 2016 Red Hat, Inc.
3728db53ac32da51fcaae96b132e8e56ebbaebfaJakub Hrozek# This is free software; you can redistribute it and/or modify it
3728db53ac32da51fcaae96b132e8e56ebbaebfaJakub Hrozek# under the terms of the GNU General Public License as published by
3728db53ac32da51fcaae96b132e8e56ebbaebfaJakub Hrozek# the Free Software Foundation; version 2 only
3728db53ac32da51fcaae96b132e8e56ebbaebfaJakub Hrozek# This program is distributed in the hope that it will be useful, but
3728db53ac32da51fcaae96b132e8e56ebbaebfaJakub Hrozek# WITHOUT ANY WARRANTY; without even the implied warranty of
3728db53ac32da51fcaae96b132e8e56ebbaebfaJakub Hrozek# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3728db53ac32da51fcaae96b132e8e56ebbaebfaJakub Hrozek# General Public License for more details.
3728db53ac32da51fcaae96b132e8e56ebbaebfaJakub Hrozek# You should have received a copy of the GNU General Public License
3728db53ac32da51fcaae96b132e8e56ebbaebfaJakub Hrozek# along with this program. If not, see <http://www.gnu.org/licenses/>.
3728db53ac32da51fcaae96b132e8e56ebbaebfaJakub Hrozekfrom ctypes import (c_int, c_char_p, c_ulong, POINTER, Structure,
3728db53ac32da51fcaae96b132e8e56ebbaebfaJakub Hrozekfrom sssd_nss import NssReturnCode, SssdNssError, nss_sss_ctypes_loader
3728db53ac32da51fcaae96b132e8e56ebbaebfaJakub Hrozekdef getgrnam_r(name, result_p, buffer_p, buflen):
3728db53ac32da51fcaae96b132e8e56ebbaebfaJakub Hrozek ctypes wrapper for:
3728db53ac32da51fcaae96b132e8e56ebbaebfaJakub Hrozek enum nss_status _nss_sss_getgrnam_r(const char *name,
3728db53ac32da51fcaae96b132e8e56ebbaebfaJakub Hrozek struct group *result,
3728db53ac32da51fcaae96b132e8e56ebbaebfaJakub Hrozek char *buffer,
3728db53ac32da51fcaae96b132e8e56ebbaebfaJakub Hrozek size_t buflen,
3728db53ac32da51fcaae96b132e8e56ebbaebfaJakub Hrozek int *errnop)
3728db53ac32da51fcaae96b132e8e56ebbaebfaJakub Hrozek func = nss_sss_ctypes_loader("_nss_sss_getgrnam_r")
3728db53ac32da51fcaae96b132e8e56ebbaebfaJakub Hrozek res = func(c_char_p(name), result_p, buffer_p, buflen, errno)
137e105ac8ca3476d2f74d24ae13860774937000Jakub Hrozekdef getgrgid_r(gid, result_p, buffer_p, buflen):
137e105ac8ca3476d2f74d24ae13860774937000Jakub Hrozek ctypes wrapper for:
137e105ac8ca3476d2f74d24ae13860774937000Jakub Hrozek enum nss_status _nss_sss_getgrgid_r(gid_t gid,
137e105ac8ca3476d2f74d24ae13860774937000Jakub Hrozek struct passwd *result,
137e105ac8ca3476d2f74d24ae13860774937000Jakub Hrozek char *buffer,
137e105ac8ca3476d2f74d24ae13860774937000Jakub Hrozek size_t buflen,
137e105ac8ca3476d2f74d24ae13860774937000Jakub Hrozek int *errnop)
137e105ac8ca3476d2f74d24ae13860774937000Jakub Hrozek func = nss_sss_ctypes_loader("_nss_sss_getgrgid_r")
137e105ac8ca3476d2f74d24ae13860774937000Jakub Hrozek res = func(gid, result_p, buffer_p, buflen, errno)
bac4458c89a589055ae3daf4f72cc7dba886264aLukas Slebodnik group_dict['name'] = result_p[0].gr_name.decode('utf-8')
bac4458c89a589055ae3daf4f72cc7dba886264aLukas Slebodnik grp_name = result_p[0].gr_mem[i].decode('utf-8')
137e105ac8ca3476d2f74d24ae13860774937000Jakub Hrozek A Python wrapper to retrieve a group by name. Returns:
3728db53ac32da51fcaae96b132e8e56ebbaebfaJakub Hrozek (res, group_dict)
3728db53ac32da51fcaae96b132e8e56ebbaebfaJakub Hrozek if res is NssReturnCode.SUCCESS, then group_dict contains the keys
3728db53ac32da51fcaae96b132e8e56ebbaebfaJakub Hrozek corresponding to the C passwd structure fields. Otherwise, the dictionary
3728db53ac32da51fcaae96b132e8e56ebbaebfaJakub Hrozek is empty and errno indicates the error code
3728db53ac32da51fcaae96b132e8e56ebbaebfaJakub Hrozek res, errno, result_p = getgrnam_r(name, result_p, buff, GROUP_BUFLEN)
137e105ac8ca3476d2f74d24ae13860774937000Jakub Hrozek A Python wrapper to retrieve a group by GID. Returns:
137e105ac8ca3476d2f74d24ae13860774937000Jakub Hrozek (res, group_dict)
137e105ac8ca3476d2f74d24ae13860774937000Jakub Hrozek if res is NssReturnCode.SUCCESS, then group_dict contains the keys
137e105ac8ca3476d2f74d24ae13860774937000Jakub Hrozek corresponding to the C passwd structure fields. Otherwise, the dictionary
137e105ac8ca3476d2f74d24ae13860774937000Jakub Hrozek is empty and errno indicates the error code