def call_sssd_getnetbyaddr(addrstr, af): """ A Python wrapper to retrieve an IP network by address. Returns: (res, netent_dict) if res is NssReturnCode.SUCCESS, then netent_dict contains the keys corresponding to the C netent structure fields. Otherwise, the dictionary is empty and errno indicates the error code """ result = Netent() result_p = POINTER(Netent)(result) buff = create_string_buffer(IP_NETWORK_BUFLEN) if isinstance(addrstr, bytes): addrstr = addrstr.decode('utf-8') addr = IPv4Address(addrstr) binaddr = unpack('<I', addr.packed)[0] binaddr = socket.ntohl(binaddr) (res, errno, h_errno, result_p) = getnetbyaddr_r(binaddr, af, result_p, buff, IP_NETWORK_BUFLEN) if errno != 0: raise SssdNssError(errno, "getnetbyaddr_r") netent_dict = set_netent_dict(res, result_p) return (res, h_errno, netent_dict)
def getpwent(): result = Passwd() result_p = POINTER(Passwd)(result) buff = create_string_buffer(PASSWD_BUFLEN) res, errno, result_p = getpwent_r(result_p, buff, PASSWD_BUFLEN) if errno != 0: raise SssdNssError(errno, "getpwent_r") user_dict = set_user_dict(res, result_p) return res, user_dict
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 call_sssd_getpwnam(name): """ A Python wrapper to retrieve a user. Returns: (res, user_dict) if res is NssReturnCode.SUCCESS, then user_dict contains the keys corresponding to the C passwd structure fields. Otherwise, the dictionary is empty and errno indicates the error code """ result = Passwd() result_p = POINTER(Passwd)(result) buff = create_string_buffer(PASSWD_BUFLEN) res, errno, result_p = getpwnam_r(name, result_p, buff, PASSWD_BUFLEN) if errno != 0: raise SssdNssError(errno, "getpwnam_r") user_dict = set_user_dict(res, result_p) return res, user_dict
def call_sssd_getgrnam(name): """ A Python wrapper to retrieve a group. Returns: (res, group_dict) if res is NssReturnCode.SUCCESS, then group_dict contains the keys corresponding to the C passwd structure fields. Otherwise, the dictionary is empty and errno indicates the error code """ result = Group() result_p = POINTER(Group)(result) buff = create_string_buffer(GROUP_BUFLEN) res, errno, result_p = getgrnam_r(name, result_p, buff, GROUP_BUFLEN) if errno != 0: raise SssdNssError(errno, "getgrnam_r") group_dict = set_group_dict(res, result_p) return res, group_dict
def call_sssd_getnetbyname(name): """ A Python wrapper to retrieve an IP network by name. Returns: (res, netent_dict) if res is NssReturnCode.SUCCESS, then netent_dict contains the keys corresponding to the C netent structure fields. Otherwise, the dictionary is empty and errno indicates the error code """ result = Netent() result_p = POINTER(Netent)(result) buff = create_string_buffer(IP_NETWORK_BUFLEN) (res, errno, h_errno, result_p) = getnetbyname_r(name, result_p, buff, IP_NETWORK_BUFLEN) if errno != 0: raise SssdNssError(errno, "getnetbyname_r") netent_dict = set_netent_dict(res, result_p) return (res, h_errno, netent_dict)