summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJakub Hrozek <jhrozek@redhat.com>2016-11-17 15:46:00 +0100
committerJakub Hrozek <jhrozek@redhat.com>2017-02-15 14:53:41 +0100
commit1921d739ff7b028baa591272cc8969e330c8f872 (patch)
tree85e72b2f6531951e113899ed947572832f634a3b
parent4e17c050dac8f2c6e2d278c4c4a27001c8d7d164 (diff)
downloadsssd-1921d739ff7b028baa591272cc8969e330c8f872.tar.gz
sssd-1921d739ff7b028baa591272cc8969e330c8f872.tar.xz
sssd-1921d739ff7b028baa591272cc8969e330c8f872.zip
TESTS: add a helper module with shared NSS constants
Every module that reads the sssd_nss module directly copied around the same definition of NSS constants. This commit moves them into a single file to avoid code duplication. Reviewed-by: Pavel Březina <pbrezina@redhat.com> Reviewed-by: Lukáš Slebodník <lslebodn@redhat.com>
-rw-r--r--src/tests/intg/Makefile.am1
-rw-r--r--src/tests/intg/sssd_id.py14
-rw-r--r--src/tests/intg/sssd_netgroup.py25
-rw-r--r--src/tests/intg/sssd_nss.py46
4 files changed, 53 insertions, 33 deletions
diff --git a/src/tests/intg/Makefile.am b/src/tests/intg/Makefile.am
index 90e0f3080..4d364f84a 100644
--- a/src/tests/intg/Makefile.am
+++ b/src/tests/intg/Makefile.am
@@ -1,6 +1,7 @@
dist_noinst_DATA = \
config.py.m4 \
util.py \
+ sssd_nss.py \
sssd_id.py \
sssd_ldb.py \
sssd_netgroup.py \
diff --git a/src/tests/intg/sssd_id.py b/src/tests/intg/sssd_id.py
index 4f020c3a2..f4ab9cfb8 100644
--- a/src/tests/intg/sssd_id.py
+++ b/src/tests/intg/sssd_id.py
@@ -21,15 +21,7 @@ import pwd
import grp
from ctypes import (cdll, c_int, c_char, c_uint32, c_long, c_char_p,
POINTER, pointer)
-
-
-class NssReturnCode(object):
- """ 'enum' class for name service switch return code """
- TRYAGAIN = -2,
- UNAVAIL = -1
- NOTFOUND = 0
- SUCCESS = 1
- RETURN = 2
+from sssd_nss import NssReturnCode, nss_sss_ctypes_loader
def call_sssd_initgroups(user, gid):
@@ -45,10 +37,8 @@ def call_sssd_initgroups(user, gid):
gids should contain user group IDs if err is NssReturnCode.SUCCESS
otherwise errno will contain non-zero value.
"""
- libnss_sss_path = config.NSS_MODULE_DIR + "/libnss_sss.so.2"
- libnss_sss = cdll.LoadLibrary(libnss_sss_path)
+ func = nss_sss_ctypes_loader('_nss_sss_initgroups_dyn')
- func = libnss_sss._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,
diff --git a/src/tests/intg/sssd_netgroup.py b/src/tests/intg/sssd_netgroup.py
index 0ea3db3cf..162c5aac8 100644
--- a/src/tests/intg/sssd_netgroup.py
+++ b/src/tests/intg/sssd_netgroup.py
@@ -19,6 +19,7 @@
from ctypes import (cdll, c_int, c_char, c_char_p, c_size_t, c_void_p, c_ulong,
POINTER, Structure, Union, create_string_buffer, get_errno)
import config
+from sssd_nss import NssReturnCode, nss_sss_ctypes_loader
class NetgroupType(object):
@@ -50,15 +51,6 @@ NameList._fields_ = [("next", POINTER(NameList)),
("name", POINTER(c_char))]
-class NssReturnCode(object):
- """ 'enum' class for name service switch return code """
- TRYAGAIN = -2,
- UNAVAIL = -1
- NOTFOUND = 0
- SUCCESS = 1
- RETURN = 2
-
-
class Netgrent(Structure):
_fields_ = [("type", c_int),
("val", Val),
@@ -92,10 +84,7 @@ class NetgroupRetriever(object):
result_p will contain POINTER(Netgrent) which can be used in
_getnetgrent_r or _getnetgrent_r.
"""
- libnss_sss_path = config.NSS_MODULE_DIR + "/libnss_sss.so.2"
- libnss_sss = cdll.LoadLibrary(libnss_sss_path)
-
- func = libnss_sss._nss_sss_setnetgrent
+ func = nss_sss_ctypes_loader('_nss_sss_setnetgrent')
func.restype = c_int
func.argtypes = [c_char_p, POINTER(Netgrent)]
@@ -123,10 +112,7 @@ class NetgroupRetriever(object):
if err is NssReturnCode.SUCCESS netgroups will contain list of
touples. Each touple will consist of 3 elemets either string or
"""
- libnss_sss_path = config.NSS_MODULE_DIR + "/libnss_sss.so.2"
- libnss_sss = cdll.LoadLibrary(libnss_sss_path)
-
- func = libnss_sss._nss_sss_getnetgrent_r
+ 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)]
@@ -148,10 +134,7 @@ class NetgroupRetriever(object):
@return int a constant from class NssReturnCode
"""
- libnss_sss_path = config.NSS_MODULE_DIR + "/libnss_sss.so.2"
- libnss_sss = cdll.LoadLibrary(libnss_sss_path)
-
- func = libnss_sss._nss_sss_endnetgrent
+ func = nss_sss_ctypes_loader('_nss_sss_endnetgrent')
func.restype = c_int
func.argtypes = [POINTER(Netgrent)]
diff --git a/src/tests/intg/sssd_nss.py b/src/tests/intg/sssd_nss.py
new file mode 100644
index 000000000..1e846310b
--- /dev/null
+++ b/src/tests/intg/sssd_nss.py
@@ -0,0 +1,46 @@
+#
+# Shared module for integration tests that need to access the sssd_nss
+# module directly
+#
+# Copyright (c) 2016 Red Hat, Inc.
+#
+# This is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 only
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+import config
+import ctypes
+
+
+class NssReturnCode(object):
+ """ 'enum' class for name service switch return code """
+ TRYAGAIN = -2,
+ UNAVAIL = -1
+ NOTFOUND = 0
+ SUCCESS = 1
+ RETURN = 2
+
+
+class SssdNssError(Exception):
+ """ Raised when one of the NSS operations fail """
+ def __init__(self, errno, nssop):
+ self.errno = errno
+ self.nssop = nssop
+
+ def __str__(self):
+ return "NSS operation %s failed %d" % (nssop, errno)
+
+
+def nss_sss_ctypes_loader(func_name):
+ libnss_sss_path = config.NSS_MODULE_DIR + "/libnss_sss.so.2"
+ libnss_sss = ctypes.cdll.LoadLibrary(libnss_sss_path)
+ func = getattr(libnss_sss, func_name)
+ return func