b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik#
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik# Module for simulation of utility "getent netgroup -s sss" from coreutils
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik#
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik# Copyright (c) 2016 Red Hat, Inc.
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik# Author: Lukas Slebodnik <lslebodn@redhat.com>
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik#
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik# This is free software; you can redistribute it and/or modify it
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik# under the terms of the GNU General Public License as published by
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik# the Free Software Foundation; version 2 only
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik#
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik# This program is distributed in the hope that it will be useful, but
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik# WITHOUT ANY WARRANTY; without even the implied warranty of
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik# General Public License for more details.
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik#
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik# You should have received a copy of the GNU General Public License
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik# along with this program. If not, see <http://www.gnu.org/licenses/>.
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik#
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnikfrom ctypes import (cdll, c_int, c_char, c_char_p, c_size_t, c_void_p, c_ulong,
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik POINTER, Structure, Union, create_string_buffer, get_errno)
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnikimport config
1921d739ff7b028baa591272cc8969e330c8f872Jakub Hrozekfrom sssd_nss import NssReturnCode, nss_sss_ctypes_loader
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnikclass NetgroupType(object):
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik """ 'enum' class for type of netgroup """
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik TRIPLE_VAL = 0
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik GROUP_VAL = 1
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnikclass Triple(Structure):
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik _fields_ = [("host", c_char_p),
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik ("user", c_char_p),
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik ("domain", c_char_p)]
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnikclass Val(Union):
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik _fields_ = [("triple", Triple),
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik ("group", c_char_p)]
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnikclass Idx(Union):
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik _fields_ = [("cursor", POINTER(c_char)),
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik ("position", c_ulong)]
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnikclass NameList(Structure):
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik pass
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik
a7acb83aa5c70547f5575cdbb13228f23e3621c0Fabiano Fidêncio
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas SlebodnikNameList._fields_ = [("next", POINTER(NameList)),
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik ("name", POINTER(c_char))]
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnikclass Netgrent(Structure):
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik _fields_ = [("type", c_int),
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik ("val", Val),
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik ("data", POINTER(c_char)),
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik ("data_size", c_size_t),
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik ("idx", Idx),
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik ("first", c_int),
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik ("known_groups", POINTER(NameList)),
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik ("needed_groups", POINTER(NameList)),
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik ("nip", c_void_p)]
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnikclass NetgroupRetriever(object):
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik def __init__(self, name):
19398379a221a11755c77bb157864dfa9f465488Lukas Slebodnik self.name = name.encode('utf-8')
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik self.needed_groups = []
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik self.known_groups = []
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik self.netgroups = []
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik @staticmethod
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik def _setnetgrent(netgroup):
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik """
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik This private method is ctypes wrapper for
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik enum nss_status _nss_sss_setnetgrent(const char *netgroup,
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik struct __netgrent *result)
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik @param string name name of netgroup
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik @return (int, POINTER(Netgrent)) (err, result_p)
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik err is a constant from class NssReturnCode and in case of SUCCESS
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik result_p will contain POINTER(Netgrent) which can be used in
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik _getnetgrent_r or _getnetgrent_r.
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik """
1921d739ff7b028baa591272cc8969e330c8f872Jakub Hrozek func = nss_sss_ctypes_loader('_nss_sss_setnetgrent')
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik func.restype = c_int
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik func.argtypes = [c_char_p, POINTER(Netgrent)]
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik result = Netgrent()
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik result_p = POINTER(Netgrent)(result)
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik res = func(c_char_p(netgroup), result_p)
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik return (int(res), result_p)
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik @staticmethod
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik def _getnetgrent_r(result_p, buff, buff_len):
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik """
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik This private method is ctypes wrapper for
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik enum nss_status _nss_sss_getnetgrent_r(struct __netgrent *result,
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik char *buffer, size_t buflen,
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik int *errnop)
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik @param POINTER(Netgrent) result_p pointer to initialized C structure
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik struct __netgrent
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik @param ctypes.c_char_Array buff buffer used by C functions
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik @param int buff_len size of c_char_Array passed as a paramere buff
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik @return (int, int, List[(string, string, string])
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik (err, errno, netgroups)
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik if err is NssReturnCode.SUCCESS netgroups will contain list of
49dd8ee2834d9477418961dbaffa4a03cfa9fd1eRené Genz touples. Each touple will consist of 3 elements either string or
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik """
1921d739ff7b028baa591272cc8969e330c8f872Jakub Hrozek func = nss_sss_ctypes_loader('_nss_sss_getnetgrent_r')
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik func.restype = c_int
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik func.argtypes = [POINTER(Netgrent), POINTER(c_char), c_size_t,
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik POINTER(c_int)]
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik errno = POINTER(c_int)(c_int(0))
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik res = func(result_p, buff, buff_len, errno)
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik return (int(res), int(errno[0]), result_p)
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik @staticmethod
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik def _endnetgrent(result_p):
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik """
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik This private method is ctypes wrapper for
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik enum nss_status _nss_sss_endnetgrent(struct __netgrent *result)
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik @param POINTER(Netgrent) result_p pointer to initialized C structure
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik struct __netgrent
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik @return int a constant from class NssReturnCode
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik """
1921d739ff7b028baa591272cc8969e330c8f872Jakub Hrozek func = nss_sss_ctypes_loader('_nss_sss_endnetgrent')
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik func.restype = c_int
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik func.argtypes = [POINTER(Netgrent)]
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik res = func(result_p)
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik return int(res)
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik def get_netgroups(self):
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik """
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik Function will return netgroup triplets for given user. All nested
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik netgroups will be retieved as part of executions and will content
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik will be merged with direct triplets.
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik Missing nested netgroups will not cause failure and are considered
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik as an empty netgroup without triplets.
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik @param string name name of netgroup
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik @return (int, int, List[(string, string, string])
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik (err, errno, netgroups)
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik if err is NssReturnCode.SUCCESS netgroups will contain list of
49dd8ee2834d9477418961dbaffa4a03cfa9fd1eRené Genz touples. Each touple will consist of 3 elements either string or
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik None (host, user, domain).
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik """
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik res, errno, result = self._flat_fetch_netgroups(self.name)
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik if res != NssReturnCode.SUCCESS:
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik return (res, errno, self.netgroups)
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik self.netgroups += result
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik while self.needed_groups:
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik name = self.needed_groups.pop(0)
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik nest_res, nest_errno, result = self._flat_fetch_netgroups(name)
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik # do not fail for missing nested netgroup
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik if nest_res not in (NssReturnCode.SUCCESS, NssReturnCode.NOTFOUND):
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik return (nest_res, nest_errno, self.netgroups)
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik self.netgroups = result + self.netgroups
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik return (res, errno, self.netgroups)
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik def _flat_fetch_netgroups(self, name):
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik """
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik Function will return netgroup triplets for given user. The nested
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik netgroups will not be returned. Missing nested netgroups will be
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik appended to the array needed_groups
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik @param string name name of netgroup
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik @return (int, int, List[(string, string, string])
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik (err, errno, netgroups)
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik if err is NssReturnCode.SUCCESS netgroups will contain list of
49dd8ee2834d9477418961dbaffa4a03cfa9fd1eRené Genz touples. Each touple will consist of 3 elements either string or
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik None (host, user, domain).
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik """
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik buff_len = 1024 * 1024
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik buff = create_string_buffer(buff_len)
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik result = []
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik res, result_p = self._setnetgrent(name)
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik if res != NssReturnCode.SUCCESS:
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik return (res, get_errno(), result)
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik res, errno, result_p = self._getnetgrent_r(result_p, buff, buff_len)
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik while res == NssReturnCode.SUCCESS:
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik if result_p[0].type == NetgroupType.GROUP_VAL:
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik nested_netgroup = result_p[0].val.group
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik if nested_netgroup not in self.known_groups:
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik self.needed_groups.append(nested_netgroup)
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik self.known_groups.append(nested_netgroup)
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik if result_p[0].type == NetgroupType.TRIPLE_VAL:
fd2dfed53be8e3a0b63a1b268be34c2dc11ce837Lukas Slebodnik triple = result_p[0].val.triple
0f8add07b8257fcce9f62ad80d24e79b8013ae42Sumit Bose result.append((triple.host and triple.host.decode('utf-8')
0f8add07b8257fcce9f62ad80d24e79b8013ae42Sumit Bose or "",
0f8add07b8257fcce9f62ad80d24e79b8013ae42Sumit Bose triple.user and triple.user.decode('utf-8')
0f8add07b8257fcce9f62ad80d24e79b8013ae42Sumit Bose or "",
0f8add07b8257fcce9f62ad80d24e79b8013ae42Sumit Bose triple.domain and triple.domain.decode('utf-8')
0f8add07b8257fcce9f62ad80d24e79b8013ae42Sumit Bose or ""))
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik res, errno, result_p = self._getnetgrent_r(result_p, buff,
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik buff_len)
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik if res != NssReturnCode.RETURN:
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik return (res, errno, result)
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik res = self._endnetgrent(result_p)
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik return (res, errno, result)
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnikdef get_sssd_netgroups(name):
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik """
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik Function will return netgroup triplets for given user. It will gather
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik netgroups only provided by sssd.
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik The equivalent of "getent netgroup -s sss user"
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik @param string name name of netgroup
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik @return (int, int, List[(string, string, string]) (err, errno, netgroups)
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik if err is NssReturnCode.SUCCESS netgroups will contain list of touples.
49dd8ee2834d9477418961dbaffa4a03cfa9fd1eRené Genz Each touple will consist of 3 elements either string or None
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik (host, user, domain).
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik """
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik retriever = NetgroupRetriever(name)
b4633e73067d7bf3b0dbaf212569c123de88f306Lukas Slebodnik
c596fc4d75304ff224cbad0aa2aecd3cbe82d2ffLukas Slebodnik return retriever.get_netgroups()