sssd/0071-TESTS-Add-wrappers-to-request-a-user-or-a-group-by-I.patch
2017-09-01 21:34:35 +02:00

151 lines
5.2 KiB
Diff

From 137e105ac8ca3476d2f74d24ae13860774937000 Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <jhrozek@redhat.com>
Date: Tue, 22 Aug 2017 12:25:31 +0200
Subject: [PATCH 71/93] TESTS: Add wrappers to request a user or a group by ID
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
---
src/tests/intg/sssd_group.py | 43 ++++++++++++++++++++++++++++++++++++++++++-
src/tests/intg/sssd_passwd.py | 43 ++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 84 insertions(+), 2 deletions(-)
diff --git a/src/tests/intg/sssd_group.py b/src/tests/intg/sssd_group.py
index ab873a726d4c1c35ed00fe4c431566ecef648880..32d12cfae4dcc0bb560f168dcf4ac327deac3065 100644
--- a/src/tests/intg/sssd_group.py
+++ b/src/tests/intg/sssd_group.py
@@ -52,6 +52,27 @@ def getgrnam_r(name, result_p, buffer_p, buflen):
return (int(res), int(errno[0]), result_p)
+def getgrgid_r(gid, result_p, buffer_p, buflen):
+ """
+ ctypes wrapper for:
+ enum nss_status _nss_sss_getgrgid_r(gid_t gid,
+ struct passwd *result,
+ char *buffer,
+ size_t buflen,
+ int *errnop)
+ """
+ func = nss_sss_ctypes_loader("_nss_sss_getgrgid_r")
+ func.restype = c_int
+ func.argtypes = [c_ulong, POINTER(Group),
+ c_char_p, c_ulong, POINTER(c_int)]
+
+ errno = POINTER(c_int)(c_int(0))
+
+ res = func(gid, result_p, buffer_p, buflen, errno)
+
+ return (int(res), int(errno[0]), result_p)
+
+
def set_group_dict(res, result_p):
if res != NssReturnCode.SUCCESS:
return dict()
@@ -72,7 +93,7 @@ def set_group_dict(res, result_p):
def call_sssd_getgrnam(name):
"""
- A Python wrapper to retrieve a group. Returns:
+ A Python wrapper to retrieve a group by name. 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
@@ -88,3 +109,23 @@ def call_sssd_getgrnam(name):
group_dict = set_group_dict(res, result_p)
return res, group_dict
+
+
+def call_sssd_getgrgid(gid):
+ """
+ A Python wrapper to retrieve a group by GID. 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 = getgrgid_r(gid, result_p, buff, GROUP_BUFLEN)
+ if errno != 0:
+ raise SssdNssError(errno, "getgrgid_r")
+
+ group_dict = set_group_dict(res, result_p)
+ return res, group_dict
diff --git a/src/tests/intg/sssd_passwd.py b/src/tests/intg/sssd_passwd.py
index f285b4971d0d9e826bf6cb38ebefeaf1b4422187..e97b0c11b02b8cdd5d67229f19c34f9569c049bd 100644
--- a/src/tests/intg/sssd_passwd.py
+++ b/src/tests/intg/sssd_passwd.py
@@ -70,6 +70,27 @@ def getpwnam_r(name, result_p, buffer_p, buflen):
return (int(res), int(errno[0]), result_p)
+def getpwuid_r(uid, result_p, buffer_p, buflen):
+ """
+ ctypes wrapper for:
+ enum nss_status _nss_sss_getpwuid_r(uid_t uid,
+ struct passwd *result,
+ char *buffer,
+ size_t buflen,
+ int *errnop)
+ """
+ func = nss_sss_ctypes_loader("_nss_sss_getpwuid_r")
+ func.restype = c_int
+ func.argtypes = [c_ulong, POINTER(Passwd),
+ c_char_p, c_ulong, POINTER(c_int)]
+
+ errno = POINTER(c_int)(c_int(0))
+
+ res = func(uid, result_p, buffer_p, buflen, errno)
+
+ return (int(res), int(errno[0]), result_p)
+
+
def setpwent():
"""
ctypes wrapper for:
@@ -134,7 +155,7 @@ def getpwent():
def call_sssd_getpwnam(name):
"""
- A Python wrapper to retrieve a user. Returns:
+ A Python wrapper to retrieve a user by name. 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
@@ -152,6 +173,26 @@ def call_sssd_getpwnam(name):
return res, user_dict
+def call_sssd_getpwuid(uid):
+ """
+ A Python wrapper to retrieve a user by UID. 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 = getpwuid_r(uid, result_p, buff, PASSWD_BUFLEN)
+ if errno != 0:
+ raise SssdNssError(errno, "getpwuid_r")
+
+ user_dict = set_user_dict(res, result_p)
+ return res, user_dict
+
+
def call_sssd_enumeration():
"""
enumerate users from sssd module only
--
2.14.1