def _getnetgrent_r(result_p, buff, buff_len): """ This private method is ctypes wrapper for enum nss_status _nss_sss_getnetgrent_r(struct __netgrent *result, char *buffer, size_t buflen, int *errnop) @param POINTER(Netgrent) result_p pointer to initialized C structure struct __netgrent @param ctypes.c_char_Array buff buffer used by C functions @param int buff_len size of c_char_Array passed as a parameter buff @return (int, int, List[(string, string, string]) (err, errno, netgroups) if err is NssReturnCode.SUCCESS netgroups will contain list of touples. Each touple will consist of 3 elements either string or """ func = nss_sss_ctypes_loader('_nss_sss_getnetgrent_r') func.restype = c_int func.argtypes = [ POINTER(Netgrent), POINTER(c_char), c_size_t, POINTER(c_int) ] errno = POINTER(c_int)(c_int(0)) res = func(result_p, buff, buff_len, errno) return (int(res), int(errno[0]), result_p)
def gethostbyname2_r(name, af, result_p, buffer_p, buflen): """ ctypes wrapper for: enum nss_status _nss_sss_gethostbyname2_r(const char *name, int af, struct hostent *result, char *buffer, size_t buflen, int *errnop, int *h_errnop) """ func = nss_sss_ctypes_loader("_nss_sss_gethostbyname2_r") func.restype = c_int func.argtypes = [ c_char_p, c_int, POINTER(Hostent), c_char_p, c_ulong, POINTER(c_int), POINTER(c_int) ] errno = POINTER(c_int)(c_int(0)) h_errno = POINTER(c_int)(c_int(0)) name = name.encode('utf-8') res = func(c_char_p(name), af, result_p, buffer_p, buflen, errno, h_errno) return (int(res), int(errno[0]), int(h_errno[0]), result_p)
def _getnetgrent_r(result_p, buff, buff_len): """ This private method is ctypes wrapper for enum nss_status _nss_sss_getnetgrent_r(struct __netgrent *result, char *buffer, size_t buflen, int *errnop) @param POINTER(Netgrent) result_p pointer to initialized C structure struct __netgrent @param ctypes.c_char_Array buff buffer used by C functions @param int buff_len size of c_char_Array passed as a paramere buff @return (int, int, List[(string, string, string]) (err, errno, netgroups) if err is NssReturnCode.SUCCESS netgroups will contain list of touples. Each touple will consist of 3 elements either string or """ func = nss_sss_ctypes_loader('_nss_sss_getnetgrent_r') func.restype = c_int func.argtypes = [POINTER(Netgrent), POINTER(c_char), c_size_t, POINTER(c_int)] errno = POINTER(c_int)(c_int(0)) res = func(result_p, buff, buff_len, errno) return (int(res), int(errno[0]), result_p)
def endpwent(): """ ctypes wrapper for: void endpwent(void) """ func = nss_sss_ctypes_loader("_nss_sss_endpwent") func.argtypes = [] res = func() assert res == NssReturnCode.SUCCESS errno = get_errno() if errno != 0: raise SssdNssError(errno, "endpwent")
def setpwent(): """ ctypes wrapper for: void setpwent(void) """ func = nss_sss_ctypes_loader("_nss_sss_setpwent") func.argtypes = [] res = func() assert res == NssReturnCode.SUCCESS errno = get_errno() if errno != 0: raise SssdNssError(errno, "setpwent")
def getpwent_r(result_p, buffer_p, buflen): """ ctypes wrapper for: enum nss_status _nss_sss_getpwent_r(struct passwd *result, char *buffer, size_t buflen, int *errnop) """ func = nss_sss_ctypes_loader("_nss_sss_getpwent_r") func.restype = c_int func.argtypes = [POINTER(Passwd), c_char_p, c_ulong, POINTER(c_int)] errno = POINTER(c_int)(c_int(0)) res = func(result_p, buffer_p, buflen, errno) return (int(res), int(errno[0]), result_p)
def call_sssd_initgroups(user, gid): """ Function will initialize the supplementary group access list for given user. It will gather groups only provided by sssd. Arguments are the same as for C function initgroups @param string user name of user @param int gid the additional gid will be also added to the list. @return (int, int, List[int]) (err, errno, gids) gids should contain user group IDs if err is NssReturnCode.SUCCESS otherwise errno will contain non-zero value. """ func = nss_sss_ctypes_loader('_nss_sss_initgroups_dyn') func.restype = c_int func.argtypes = [ POINTER(c_char), c_uint32, POINTER(c_long), POINTER(c_long), POINTER(POINTER(c_uint32)), c_long, POINTER(c_int) ] start = POINTER(c_long)(c_long(0)) size = POINTER(c_long)(c_long(0)) groups = POINTER(c_uint32)() p_groups = pointer(groups) limit = c_long(-1) errno = POINTER(c_int)(c_int(0)) res = func(c_char_p(user.encode('utf-8)')), c_uint32(gid), start, size, p_groups, limit, errno) gids = [] if res == NssReturnCode.SUCCESS: gids_count = size[0] assert gids_count > 0, "_nss_sss_initgroups_dyn should return " \ "one gid" for i in range(0, gids_count): gids.append(int(p_groups.contents[i])) # add primary group if missing if gid not in gids: gids.append(gid) return (int(res), errno[0], gids)
def _endnetgrent(result_p): """ This private method is ctypes wrapper for enum nss_status _nss_sss_endnetgrent(struct __netgrent *result) @param POINTER(Netgrent) result_p pointer to initialized C structure struct __netgrent @return int a constant from class NssReturnCode """ func = nss_sss_ctypes_loader('_nss_sss_endnetgrent') func.restype = c_int func.argtypes = [POINTER(Netgrent)] res = func(result_p) return int(res)
def call_sssd_initgroups(user, gid): """ Function will initialize the supplementary group access list for given user. It will gather groups only provided by sssd. Arguments are the same as for C function initgroups @param string user name of user @param int gid the additional gid will be also added to the list. @return (int, int, List[int]) (err, errno, gids) gids should contain user group IDs if err is NssReturnCode.SUCCESS otherwise errno will contain non-zero value. """ func = nss_sss_ctypes_loader('_nss_sss_initgroups_dyn') func.restype = c_int func.argtypes = [POINTER(c_char), c_uint32, POINTER(c_long), POINTER(c_long), POINTER(POINTER(c_uint32)), c_long, POINTER(c_int)] start = POINTER(c_long)(c_long(0)) size = POINTER(c_long)(c_long(0)) groups = POINTER(c_uint32)() p_groups = pointer(groups) limit = c_long(-1) errno = POINTER(c_int)(c_int(0)) res = func(c_char_p(user.encode('utf-8)')), c_uint32(gid), start, size, p_groups, limit, errno) gids = [] if res == NssReturnCode.SUCCESS: gids_count = size[0] assert gids_count > 0, "_nss_sss_initgroups_dyn should return " \ "one gid" for i in range(0, gids_count): gids.append(int(p_groups.contents[i])) # add primary group if missing if gid not in gids: gids.append(gid) return (int(res), errno[0], gids)
def getpwnam_r(name, result_p, buffer_p, buflen): """ ctypes wrapper for: enum nss_status _nss_sss_getpwnam_r(const char *name, struct passwd *result, char *buffer, size_t buflen, int *errnop) """ func = nss_sss_ctypes_loader("_nss_sss_getpwnam_r") func.restype = c_int func.argtypes = [c_char_p, POINTER(Passwd), c_char_p, c_ulong, POINTER(c_int)] errno = POINTER(c_int)(c_int(0)) name = name.encode('utf-8') res = func(c_char_p(name), result_p, buffer_p, buflen, errno) return (int(res), int(errno[0]), result_p)
def getgrnam_r(name, result_p, buffer_p, buflen): """ ctypes wrapper for: enum nss_status _nss_sss_getgrnam_r(const char *name, struct group *result, char *buffer, size_t buflen, int *errnop) """ func = nss_sss_ctypes_loader("_nss_sss_getgrnam_r") func.restype = c_int func.argtypes = [c_char_p, POINTER(Group), c_char_p, c_ulong, POINTER(c_int)] errno = POINTER(c_int)(c_int(0)) name = name.encode('utf-8') res = func(c_char_p(name), result_p, buffer_p, buflen, errno) return (int(res), int(errno[0]), result_p)
def _setnetgrent(netgroup): """ This private method is ctypes wrapper for enum nss_status _nss_sss_setnetgrent(const char *netgroup, struct __netgrent *result) @param string name name of netgroup @return (int, POINTER(Netgrent)) (err, result_p) err is a constant from class NssReturnCode and in case of SUCCESS result_p will contain POINTER(Netgrent) which can be used in _getnetgrent_r or _getnetgrent_r. """ func = nss_sss_ctypes_loader('_nss_sss_setnetgrent') func.restype = c_int func.argtypes = [c_char_p, POINTER(Netgrent)] result = Netgrent() result_p = POINTER(Netgrent)(result) res = func(c_char_p(netgroup), result_p) return (int(res), result_p)
def getnetbyaddr_r(addr, af, result_p, buffer_p, buflen): """ ctypes wrapper for: enum nss_status _nss_sss_getnetbyaddr_r(uint32_t addr, int type, struct netent *result, char *buffer, size_t buflen, int *errnop, int *h_errnop) """ func = nss_sss_ctypes_loader("_nss_sss_getnetbyaddr_r") func.restype = c_int func.argtypes = [ c_uint32, c_int, POINTER(Netent), c_char_p, c_ulong, POINTER(c_int), POINTER(c_int) ] errno = POINTER(c_int)(c_int(0)) h_errno = POINTER(c_int)(c_int(0)) res = func(addr, af, result_p, buffer_p, buflen, errno, h_errno) return (int(res), int(errno[0]), int(h_errno[0]), result_p)