From 41bcc0bb45309347ea2488d792a331cf6de04c00 Mon Sep 17 00:00:00 2001 From: Malik Abdullah Date: Wed, 6 Apr 2022 19:16:08 +0200 Subject: [PATCH 1/2] Ctype wrapper is used to call getnetgrent for the lists of host --- src/api/python/hidra/utils/utils_netgroup.py | 31 ++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/api/python/hidra/utils/utils_netgroup.py diff --git a/src/api/python/hidra/utils/utils_netgroup.py b/src/api/python/hidra/utils/utils_netgroup.py new file mode 100644 index 00000000..748acb6a --- /dev/null +++ b/src/api/python/hidra/utils/utils_netgroup.py @@ -0,0 +1,31 @@ + +from ctypes import * + +def find_hostname(netgroup): + + libc = CDLL("libc.so.6") + if (libc != None): + pass + else: + libc = CDLL("libc.so.7") + + + hosts = None + if libc.setnetgrent(netgroup): + # returns 1 if successful and 0 otherwise + host = c_char_p() + user = c_char_p() + domain = c_char_p() + + hosts = [] + while libc.getnetgrent(byref(host), byref(user), byref(domain)): + if host: + # check is host is not a NULL pointer + hosts.append(host.value) + + return(hosts) + + +hosts = find_hostname(b"a3p62-hosts") +print(hosts) +print("done") \ No newline at end of file From 0c9926ac0f9ef7e8a852a15394f40cdb0f1a2417 Mon Sep 17 00:00:00 2001 From: Malik Abdullah Date: Mon, 30 May 2022 10:30:58 +0200 Subject: [PATCH 2/2] function find_hostname modified to get_hostname --- src/api/python/hidra/utils/utils_netgroup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/api/python/hidra/utils/utils_netgroup.py b/src/api/python/hidra/utils/utils_netgroup.py index 748acb6a..401d6dfa 100644 --- a/src/api/python/hidra/utils/utils_netgroup.py +++ b/src/api/python/hidra/utils/utils_netgroup.py @@ -1,7 +1,7 @@ from ctypes import * -def find_hostname(netgroup): +def get_hostname(netgroup): libc = CDLL("libc.so.6") if (libc != None): @@ -26,6 +26,6 @@ def find_hostname(netgroup): return(hosts) -hosts = find_hostname(b"a3p62-hosts") +hosts = get_hostname(b"a3p62-hosts") print(hosts) print("done") \ No newline at end of file