summaryrefslogtreecommitdiffstats
path: root/src/tests/intg/sssd_nss.py
blob: 1e846310bca4dc314c47882cc5e7877002c3d78f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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