SVN: nss_python: . trunk trunk/Makefile.am trunk/README trunk/autogen.sh trunk/configure.ac trunk/do...

arekm arekm at pld-linux.org
Sun Feb 18 12:36:59 CET 2007


Author: arekm
Date: Sun Feb 18 12:36:59 2007
New Revision: 8274

Added:
   nss_python/
   nss_python/trunk/
   nss_python/trunk/Makefile.am
   nss_python/trunk/README
   nss_python/trunk/autogen.sh   (contents, props changed)
   nss_python/trunk/configure.ac
   nss_python/trunk/doc/
   nss_python/trunk/doc/Makefile.am
   nss_python/trunk/doc/nss_python.py
   nss_python/trunk/src/
   nss_python/trunk/src/Makefile.am
   nss_python/trunk/src/exports.linux
   nss_python/trunk/src/lib.c
   nss_python/trunk/src/lib.h
   nss_python/trunk/src/nss_grp.c
   nss_python/trunk/src/nss_pwd.c
   nss_python/trunk/src/nss_python.h
   nss_python/trunk/src/nss_spwd.c
   nss_python/trunk/tests/
   nss_python/trunk/tests/Makefile.am
Log:
nss_python NSS module. Initial import.


Added: nss_python/trunk/Makefile.am
==============================================================================
--- (empty file)
+++ nss_python/trunk/Makefile.am	Sun Feb 18 12:36:59 2007
@@ -0,0 +1,3 @@
+SUBDIRS = doc src tests
+
+EXTRA_DIST = README

Added: nss_python/trunk/README
==============================================================================
--- (empty file)
+++ nss_python/trunk/README	Sun Feb 18 12:36:59 2007
@@ -0,0 +1,8 @@
+(C) 2007 Arkadiusz Miśkiewicz <arekm at pld-linux.org>
+
+Experimental and not tested nss_python module which
+allows to write python backends for glibc NSS.
+
+TODO:
+	- testing
+	- locking, threading problems

Added: nss_python/trunk/autogen.sh
==============================================================================
--- (empty file)
+++ nss_python/trunk/autogen.sh	Sun Feb 18 12:36:59 2007
@@ -0,0 +1,7 @@
+#!/bin/sh
+set -x
+libtoolize --copy --force
+aclocal
+autoheader
+autoconf
+automake -a -c --foreign

Added: nss_python/trunk/configure.ac
==============================================================================
--- (empty file)
+++ nss_python/trunk/configure.ac	Sun Feb 18 12:36:59 2007
@@ -0,0 +1,43 @@
+AC_PREREQ(2.60)
+AC_INIT([nss-python],[0.1],[arekm at pld-linux.org])
+AM_INIT_AUTOMAKE(AC_PACKAGE_TARNAME,AC_PACKAGE_VERSION)
+
+AC_CONFIG_HEADERS([config.h])
+
+AC_DISABLE_STATIC
+
+AC_PROG_CC
+AC_PROG_CPP
+AC_PROG_INSTALL
+AC_PROG_LIBTOOL
+
+AC_ARG_WITH([debug], [  --with-debug	enable internal debugging through syslog],
+	    [AC_DEFINE([DEBUGME], [1], [Define to 1 if you want to enable debugging])], [])
+
+AC_ARG_WITH([python-config], [  --with-python-config=SCRIPT	path to python-config script],
+	    [python_config=$withval], [])
+
+if test x$python_config = x; then
+	AC_PATH_PROG([python_config], [python2.5-config])
+fi
+
+if test x$python_config = x; then
+	AC_PATH_PROG([python_config], [python-config])
+fi
+
+if test x$python_config = x; then
+	AC_MSG_FAILURE([specify path to python-config script using --with-python-config option])
+fi
+
+PYTHON_CFLAGS=`$python_config --cflags`
+PYTHON_CPPFLAGS=`$python_config --includes`
+PYTHON_LDFLAGS=`$python_config --ldflags`
+PYTHON_LIBS=`$python_config --libs`
+
+AC_SUBST(PYTHON_CFLAGS)
+AC_SUBST(PYTHON_CPPFLAGS)
+AC_SUBST(PYTHON_LDFLAGS)
+AC_SUBST(PYTHON_LIBS)
+
+AC_CONFIG_FILES([Makefile doc/Makefile src/Makefile tests/Makefile])
+AC_OUTPUT

Added: nss_python/trunk/doc/Makefile.am
==============================================================================
--- (empty file)
+++ nss_python/trunk/doc/Makefile.am	Sun Feb 18 12:36:59 2007
@@ -0,0 +1,5 @@
+ at SET_MAKE@
+
+sysconf_DATA = nss_python.py
+
+EXTRA_DIST = $(sysconf_DATA)

Added: nss_python/trunk/doc/nss_python.py
==============================================================================
--- (empty file)
+++ nss_python/trunk/doc/nss_python.py	Sun Feb 18 12:36:59 2007
@@ -0,0 +1,72 @@
+#
+#    nss_python - NSS module which allows to write python bacends for NSS
+#    Copyright (C) 2007 Arkadiusz Miśkiewicz <arekm at pld-linux.org>
+#
+#    This program 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; either version 2 of the License.
+#
+#    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, write to the Free Software
+#    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+
+# group
+
+t = ("testing", "", 3434, [ "aaa", "bbb" ] )
+
+def pynss_getgrnam_r(group):
+	return t
+
+def pynss_getgrgid_r(gid):
+	return t
+
+def pynss_setgrent():
+	return
+
+def pynss_endgrent():
+	return
+
+def pynss_getgrent_r():
+	return t
+
+# password
+
+u = ("some-user", "dfsdf", 2323, 4444, "gecos field", "/tmp", "/bin/false")
+
+def pynss_getpwnam_r(login):
+	return u
+
+def pynss_getpwuid_r(uid):
+	return u
+
+def pynss_setpwent():
+	return
+
+def pynss_endpwent():
+	return
+
+def pynss_getpwent_r():
+	return
+
+# shadow
+s = ("some-login", "bleble", 0, 1, 2, 3, 4, 5, 6)
+
+def pynss_getspwnam_r(login):
+	return s
+
+def pynss_getspwuid_r(uid):
+	return s
+
+def pynss_setspwent():
+	return
+
+def pynss_endspwent():
+	return
+
+def pynss_getspwent_r():
+	return s

Added: nss_python/trunk/src/Makefile.am
==============================================================================
--- (empty file)
+++ nss_python/trunk/src/Makefile.am	Sun Feb 18 12:36:59 2007
@@ -0,0 +1,16 @@
+AM_CFLAGS = -fPIC @PYTHON_CFLAGS@
+AM_CPPFLAGS = -DSYSCONFDIR=\"${sysconfdir}\" @PYTHON_CPPFLAGS@
+
+NSS_VERS = 2
+NSS_PYTHON_NSS_VERSIONED = libnss_python.so.$(NSS_VERS)
+
+lib_LTLIBRARIES = libnss_python.la
+
+noinst_HEADERS = lib.h nss_python.h
+
+libnss_python_la_SOURCES = lib.c nss_grp.c nss_pwd.c nss_spwd.c
+libnss_python_la_LIBADD = @PYTHON_LIBS@
+libnss_python_la_LDFLAGS = @PYTHON_LDFLAGS@ -module -version-info $(NSS_VERS):0:0 \
+			   -Wl,--version-script,\$(srcdir)/exports.linux
+
+EXTRA_DIST = exports.linux

Added: nss_python/trunk/src/exports.linux
==============================================================================
--- (empty file)
+++ nss_python/trunk/src/exports.linux	Sun Feb 18 12:36:59 2007
@@ -0,0 +1,31 @@
+EXPORTED {
+
+  # published NSS service functions
+  global:
+
+	# group
+	_nss_python_getgrnam_r;
+	_nss_python_getgrgid_r;
+	_nss_python_setgrent;
+	_nss_python_endgrent;
+	_nss_python_getgrent_r;
+
+	# password
+	_nss_python_getpwnam_r;
+	_nss_python_getpwuid_r;
+	_nss_python_setpwent;
+	_nss_python_endpwent;
+	_nss_python_getpwent_r;
+
+	# shadow
+	_nss_python_getspwnam_r;
+	_nss_python_getspwuid_r;
+	_nss_python_setspwent;
+	_nss_python_endspwent;
+	_nss_python_getspwent_r;
+
+  # everything else should not be exported
+  local:
+    *;
+
+};

Added: nss_python/trunk/src/lib.c
==============================================================================
--- (empty file)
+++ nss_python/trunk/src/lib.c	Sun Feb 18 12:36:59 2007
@@ -0,0 +1,87 @@
+/*
+    nss_python - NSS module which allows to write python bacends for NSS
+    Copyright (C) 2007 Arkadiusz Miśkiewicz <arekm at pld-linux.org>
+
+    This program 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; either version 2 of the License.
+
+    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, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+
+*/
+
+#include <stdarg.h>
+#include <nss.h>
+#include <Python.h>
+
+#include "nss_python.h"
+#include "lib.h"
+
+static int py_initialized = 0;
+
+PyObject *pymod;
+
+#ifndef SYSCONFDIR
+#define	SYSCONFDIR "/etc"
+#endif
+
+void nss_python_log(int err, const char *format, ...) {
+        static int openlog_ac = 0;
+        va_list args;
+
+        va_start(args, format);
+        /* this is not thread safe, but it does not matter here */
+        if (! openlog_ac) {
+                ++openlog_ac;
+                openlog("nss-python", LOG_PID, LOG_AUTH);
+        }
+
+        vsyslog(err, format, args);
+        va_end(args);
+}
+
+char *copy_to_buffer(char ** buffer,size_t * buflen, const char * string) {
+        size_t len = strlen(string) + 1;
+        char *ptr;
+
+        if (buflen && len > *buflen)
+                return NULL;
+        memcpy(*buffer,string,len);
+        if (buflen)
+                *buflen -= len;
+        ptr = *buffer;
+        (*buffer) += len;
+        return ptr;
+}
+
+NSS_STATUS init_python(void) {
+        if (py_initialized) {
+		if (DEBUG)
+			nss_python_log(LOG_ERR, "init_python: already initialized");
+                return NSS_STATUS_SUCCESS;
+        }
+
+        putenv("PYTHONPATH=" SYSCONFDIR);
+
+        Py_Initialize();
+
+        pymod = PyImport_ImportModule("nss_python");
+        if (pymod == NULL) {
+                nss_python_log(LOG_ERR, "init_python: importing nss_python.py failed");
+                return NSS_STATUS_UNAVAIL;
+        }
+
+        py_initialized = 1;
+
+	nss_python_log(LOG_ERR, "init_python: python initialized");
+
+        return NSS_STATUS_SUCCESS;
+}
+

Added: nss_python/trunk/src/lib.h
==============================================================================
--- (empty file)
+++ nss_python/trunk/src/lib.h	Sun Feb 18 12:36:59 2007
@@ -0,0 +1,24 @@
+/*
+    nss_python - NSS module which allows to write python bacends for NSS
+    Copyright (C) 2007 Arkadiusz Miśkiewicz <arekm at pld-linux.org>
+
+    This program 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; either version 2 of the License.
+
+    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, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+
+*/
+
+extern PyObject *pymod;
+
+extern void nss_python_log(int err, const char *format, ...);
+extern char *copy_to_buffer(char ** buffer,size_t * buflen, const char * string);
+extern NSS_STATUS init_python(void);

Added: nss_python/trunk/src/nss_grp.c
==============================================================================
--- (empty file)
+++ nss_python/trunk/src/nss_grp.c	Sun Feb 18 12:36:59 2007
@@ -0,0 +1,278 @@
+/*
+    nss_python - NSS module which allows to write python bacends for NSS
+    Copyright (C) 2007 Arkadiusz Miśkiewicz <arekm at pld-linux.org>
+
+    This program 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; either version 2 of the License.
+
+    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, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+
+*/
+
+#include <sys/types.h>
+#include <grp.h>
+#include <nss.h>
+#include <Python.h>
+
+#include "nss_python.h"
+#include "lib.h"
+
+static NSS_STATUS nss_grp_parse(PyObject *pValue,
+		struct group * result,
+		char *buffer, size_t buflen, int *errnop)
+{
+	PyObject *pGroupName = NULL, *pGroupPasswd = NULL, *pGid = NULL, *pGrMem = NULL;
+	Py_ssize_t i, pGrMemSize;
+	char **grmemptr = NULL;
+	char *buffer_end;
+
+	i = PyTuple_Size(pValue);
+	if (i != 4) {
+		nss_python_log(LOG_ERR, "nss_grp_parse: result is a tuple of size %d, need 4", i);
+		return NSS_STATUS_UNAVAIL;
+	}
+
+	pGroupName = PyTuple_GetItem(pValue, 0);
+	if (pGroupName == NULL || !PyString_Check(pGroupName) || PyString_Size(pGroupName) == 0) {
+		if (DEBUG)
+			nss_python_log(LOG_ERR, "nss_grp_parse: first tuple item has to be a string with size > 0");
+		return NSS_STATUS_UNAVAIL;
+	}
+
+	result->gr_name = copy_to_buffer(&buffer, &buflen, PyString_AsString(pGroupName));
+	if (result->gr_name == NULL)
+		goto out_nomem;
+
+	pGroupPasswd = PyTuple_GetItem(pValue, 1);
+	if (pGroupPasswd == NULL || !PyString_Check(pGroupPasswd)) {
+		if (DEBUG)
+			nss_python_log(LOG_ERR, "nss_grp_parse: second tuple item has to be a string");
+		return NSS_STATUS_UNAVAIL;
+	}
+
+	result->gr_passwd = copy_to_buffer(&buffer, &buflen, PyString_AsString(pGroupPasswd));
+	if (result->gr_passwd == NULL)
+		goto out_nomem;
+
+	pGid = PyTuple_GetItem(pValue, 2);
+	if (pGid == NULL || !PyInt_Check(pGid)) {
+		if (DEBUG)
+			nss_python_log(LOG_ERR, "nss_grp_parse: third tuple item has to be a integer");
+		return NSS_STATUS_UNAVAIL;
+	}
+
+	result->gr_gid = PyLong_AsUnsignedLong(pGid);
+
+	pGrMem = PyTuple_GetItem(pValue, 3);
+	if (pGrMem == NULL || !PyList_Check(pGrMem)) {
+		if (DEBUG)
+			nss_python_log(LOG_ERR, "nss_grp_parse: fourth tuple needs to be a list");
+		return NSS_STATUS_UNAVAIL;
+	}
+
+	pGrMemSize = PyList_Size(pGrMem);
+	grmemptr = (char **) buffer;
+	result->gr_mem = grmemptr;
+	buffer_end = buffer + buflen - 1;
+	for (i = 0; i < pGrMemSize; i++) {
+		char *p;
+		Py_ssize_t s;
+
+		PyObject *pGroupMember = PyList_GetItem(pGrMem, i);
+		if (pGroupMember == NULL || !PyString_Check(pGroupMember)) {
+			if (DEBUG)
+				nss_python_log(LOG_ERR, "nss_grp_parse: each element for groups list needs to be a string");
+			return NSS_STATUS_UNAVAIL;
+		}
+
+		s = PyString_Size(pGroupMember);
+
+		/* 0 size == no memers */
+		if (i == 0 && s == 0)
+			break;
+
+		p = buffer_end -= s + 1;
+		
+		if ((void *) grmemptr >= (void *) buffer_end)
+			goto out_nomem;
+
+		/* we don't want for buffer_end to change */
+		*grmemptr = copy_to_buffer(&p, NULL, PyString_AsString(pGroupMember));
+		if (*grmemptr == NULL)
+			goto out_nomem;
+
+		++grmemptr;
+	}
+
+	if ((void *) grmemptr >= (void *) buffer_end)
+		goto out_nomem;
+
+	*grmemptr = NULL;
+	*errnop = 0;
+	return NSS_STATUS_SUCCESS;
+out_nomem:
+	if (DEBUG)
+		nss_python_log(LOG_ERR, "nss_grp_parse: glibc provided buffer is to small, we ask glibc for extended one");
+	*errnop = ERANGE;
+	return NSS_STATUS_TRYAGAIN;
+}
+
+NSS_STATUS _nss_python_getgrnam_r (const char *name,
+		struct group * result,
+		char *buffer, size_t buflen, int *errnop)
+{
+	PyObject *pynss_getgrnam_r, *pValue, *pInGroupName;
+
+	if (DEBUG)
+		nss_python_log(LOG_ERR, "_nss_python_getgrnam_r: called");
+
+	if (init_python() != NSS_STATUS_SUCCESS)
+		return NSS_STATUS_UNAVAIL;
+
+	pynss_getgrnam_r = PyObject_GetAttrString(pymod, "pynss_getgrnam_r");
+	if (pynss_getgrnam_r == NULL || !PyFunction_Check(pynss_getgrnam_r)) {
+		nss_python_log(LOG_ERR, "_nss_python_getgrnam_r: pynss_getgrnam_r not found in python script");
+		return NSS_STATUS_UNAVAIL;
+	}
+
+	pInGroupName = PyString_FromString(name);
+	if (pInGroupName == NULL) {
+		if (DEBUG)
+			nss_python_log(LOG_ERR, "_nss_python_getgrnam_r: can't convert group name to python format: %s", name);
+		return NSS_STATUS_UNAVAIL;
+	}
+
+	pValue = PyObject_CallFunction(pynss_getgrnam_r, "s", pInGroupName);
+	if (pValue == NULL || !PyTuple_Check(pValue)) {
+		if (DEBUG)
+			nss_python_log(LOG_ERR, "_nss_python_getgrnam_r: calling pynss_getgrnam_r python function failed or result is not a tuple");
+		return NSS_STATUS_UNAVAIL;
+	}
+
+	return nss_grp_parse(pValue, result, buffer, buflen, errnop);
+
+}
+
+NSS_STATUS _nss_python_getgrgid_r (gid_t gid,
+		struct group *result,
+		char *buffer, size_t buflen, int *errnop) {
+	PyObject *pynss_getgrgid_r, *pValue, *pGid;
+
+	if (DEBUG)
+		nss_python_log(LOG_ERR, "_nss_python_getgrgid_r: called");
+
+	if (init_python() != NSS_STATUS_SUCCESS)
+		return NSS_STATUS_UNAVAIL;
+
+	pynss_getgrgid_r = PyObject_GetAttrString(pymod, "pynss_getgrgid_r");
+	if (pynss_getgrgid_r == NULL || !PyFunction_Check(pynss_getgrgid_r)) {
+		nss_python_log(LOG_ERR, "_nss_python_getgrgid_r: pynss_getgrgid_r not found in python script");
+		return NSS_STATUS_UNAVAIL;
+	}
+
+	pGid = PyInt_FromSsize_t(gid);
+	if (pGid == NULL) {
+		if (DEBUG)
+			nss_python_log(LOG_ERR, "_nss_python_getgrgid_r: can't convert gid to python format: %d", gid);
+		return NSS_STATUS_UNAVAIL;
+	}
+
+	pValue = PyObject_CallFunction(pynss_getgrgid_r, "i", pGid);
+	if (pValue == NULL || !PyTuple_Check(pValue)) {
+		if (DEBUG)
+			nss_python_log(LOG_ERR, "_nss_python_getgrgid_r: calling pynss_getgrgid_r python function failed or result is not a tuple");
+		return NSS_STATUS_UNAVAIL;
+	}
+
+	return nss_grp_parse(pValue, result, buffer, buflen, errnop);
+}
+
+NSS_STATUS _nss_python_setgrent (void) {
+	PyObject *pynss_setgrent, *pValue;
+
+	if (DEBUG)
+		nss_python_log(LOG_ERR, "_nss_python_setgrent: called");
+
+	if (init_python() != NSS_STATUS_SUCCESS)
+		return NSS_STATUS_UNAVAIL;
+
+	pynss_setgrent = PyObject_GetAttrString(pymod, "pynss_setgrent");
+	if (pynss_setgrent == NULL || !PyFunction_Check(pynss_setgrent)) {
+		nss_python_log(LOG_ERR, "_nss_python_setgrent: pynss_setgrent not found in python script");
+		return NSS_STATUS_UNAVAIL;
+	}
+
+	pValue = PyObject_CallFunction(pynss_setgrent, NULL);
+	if (pValue == NULL || !PyBool_Check(pValue)) {
+		if (DEBUG)
+			nss_python_log(LOG_ERR, "_nss_python_setgrent: calling pynss_setgrent python function failed or result is not a boolean");
+		return NSS_STATUS_UNAVAIL;
+	}
+
+	if (pValue == Py_True)
+		return NSS_STATUS_SUCCESS;
+
+	return NSS_STATUS_SUCCESS;
+}
+
+
+NSS_STATUS _nss_python_endgrent (void) {
+	PyObject *pynss_endgrent, *pValue;
+
+	if (DEBUG)
+		nss_python_log(LOG_ERR, "_nss_python_endgrent: called");
+
+	if (init_python() != NSS_STATUS_SUCCESS)
+		return NSS_STATUS_UNAVAIL;
+
+	pynss_endgrent = PyObject_GetAttrString(pymod, "pynss_endgrent");
+	if (pynss_endgrent == NULL || !PyFunction_Check(pynss_endgrent)) {
+		nss_python_log(LOG_ERR, "_nss_python_endgrent: pynss_endgrent not found in python script");
+		return NSS_STATUS_UNAVAIL;
+	}
+
+	pValue = PyObject_CallFunction(pynss_endgrent, NULL);
+	if (pValue == NULL) {
+		if (DEBUG)
+			nss_python_log(LOG_ERR, "_nss_python_endgrent: calling pynss_endgrent python function failed");
+		return NSS_STATUS_UNAVAIL;
+	}
+
+	return NSS_STATUS_SUCCESS;
+}
+
+NSS_STATUS _nss_python_getgrent_r (struct group *result,
+		char *buffer, size_t buflen, int *errnop) {
+	PyObject *pynss_getgrent_r, *pValue;
+
+	if (DEBUG)
+		nss_python_log(LOG_ERR, "_nss_python_getgrent_r: called");
+
+	if (init_python() != NSS_STATUS_SUCCESS)
+		return NSS_STATUS_UNAVAIL;
+
+	pynss_getgrent_r = PyObject_GetAttrString(pymod, "pynss_getgrent_r");
+	if (pynss_getgrent_r == NULL || !PyFunction_Check(pynss_getgrent_r)) {
+		nss_python_log(LOG_ERR, "_nss_python_getgrent_r: pynss_getgrent_r not found in python script");
+		return NSS_STATUS_UNAVAIL;
+	}
+
+
+	pValue = PyObject_CallFunction(pynss_getgrent_r, NULL);
+	if (pValue == NULL || !PyTuple_Check(pValue)) {
+		if (DEBUG)
+			nss_python_log(LOG_ERR, "_nss_python_getgrent_r: calling pynss_getgrent_r python function failed or result is not a tuple");
+		return NSS_STATUS_UNAVAIL;
+	}
+
+	return nss_grp_parse(pValue, result, buffer, buflen, errnop);
+}
+

Added: nss_python/trunk/src/nss_pwd.c
==============================================================================
--- (empty file)
+++ nss_python/trunk/src/nss_pwd.c	Sun Feb 18 12:36:59 2007
@@ -0,0 +1,272 @@
+/*
+    nss_python - NSS module which allows to write python bacends for NSS
+    Copyright (C) 2007 Arkadiusz Miśkiewicz <arekm at pld-linux.org>
+
+    This program 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; either version 2 of the License.
+
+    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, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+
+*/
+
+#include <sys/types.h>
+#include <pwd.h>
+#include <nss.h>
+#include <Python.h>
+
+#include "nss_python.h"
+#include "lib.h"
+
+static NSS_STATUS nss_pwd_parse(PyObject *pValue,
+		struct passwd * result,
+		char *buffer, size_t buflen, int *errnop)
+{
+	PyObject *pName = NULL, *pPasswd = NULL, *pUid = NULL, *pGid = NULL, *pGecos = NULL, *pDir = NULL, *pShell = NULL;
+	Py_ssize_t i;
+
+	i = PyTuple_Size(pValue);
+	if (i != 7) {
+		nss_python_log(LOG_ERR, "nss_pwd_parse: result is a tuple of size %d, need 7", i);
+		return NSS_STATUS_UNAVAIL;
+	}
+
+	pName = PyTuple_GetItem(pValue, 0);
+	if (pName == NULL || !PyString_Check(pName) || PyString_Size(pName) == 0) {
+		if (DEBUG)
+			nss_python_log(LOG_ERR, "nss_pwd_parse: first tuple item has to be a string with size > 0");
+		return NSS_STATUS_UNAVAIL;
+	}
+
+	result->pw_name = copy_to_buffer(&buffer, &buflen, PyString_AsString(pName));
+	if (result->pw_name == NULL)
+		goto out_nomem;
+
+	pPasswd = PyTuple_GetItem(pValue, 1);
+	if (pPasswd == NULL || !PyString_Check(pPasswd)) {
+		if (DEBUG)
+			nss_python_log(LOG_ERR, "nss_pwd_parse: second tuple item has to be a string");
+		return NSS_STATUS_UNAVAIL;
+	}
+
+	result->pw_passwd = copy_to_buffer(&buffer, &buflen, PyString_AsString(pPasswd));
+	if (result->pw_passwd == NULL)
+		goto out_nomem;
+
+	pUid = PyTuple_GetItem(pValue, 2);
+	if (pUid == NULL || !PyInt_Check(pUid)) {
+		if (DEBUG)
+			nss_python_log(LOG_ERR, "nss_pwd_parse: third tuple item has to be a integer");
+		return NSS_STATUS_UNAVAIL;
+	}
+
+	result->pw_uid = PyLong_AsUnsignedLong(pUid);
+
+	pGid = PyTuple_GetItem(pValue, 3);
+	if (pGid == NULL || !PyInt_Check(pGid)) {
+		if (DEBUG)
+			nss_python_log(LOG_ERR, "nss_pwd_parse: fourth tuple item has to be a integer");
+		return NSS_STATUS_UNAVAIL;
+	}
+
+	result->pw_gid = PyLong_AsUnsignedLong(pGid);
+
+	pGecos = PyTuple_GetItem(pValue, 4);
+	if (pGecos == NULL || !PyString_Check(pGecos)) {
+		if (DEBUG)
+			nss_python_log(LOG_ERR, "nss_pwd_parse: fifth tuple item has to be a string");
+		return NSS_STATUS_UNAVAIL;
+	}
+
+	result->pw_gecos = copy_to_buffer(&buffer, &buflen, PyString_AsString(pGecos));
+	if (result->pw_gecos == NULL)
+		goto out_nomem;
+
+	pDir = PyTuple_GetItem(pValue, 5);
+	if (pDir == NULL || !PyString_Check(pDir)) {
+		if (DEBUG)
+			nss_python_log(LOG_ERR, "nss_pwd_parse: sixth tuple item has to be a string");
+		return NSS_STATUS_UNAVAIL;
+	}
+
+	result->pw_dir = copy_to_buffer(&buffer, &buflen, PyString_AsString(pDir));
+	if (result->pw_dir == NULL)
+		goto out_nomem;
+
+	pShell = PyTuple_GetItem(pValue, 6);
+	if (pShell == NULL || !PyString_Check(pShell)) {
+		if (DEBUG)
+			nss_python_log(LOG_ERR, "nss_pwd_parse: seventh tuple item has to be a string");
+		return NSS_STATUS_UNAVAIL;
+	}
+
+	result->pw_shell = copy_to_buffer(&buffer, &buflen, PyString_AsString(pShell));
+	if (result->pw_shell == NULL)
+		goto out_nomem;
+
+	*errnop = 0;
+	return NSS_STATUS_SUCCESS;
+out_nomem:
+	if (DEBUG)
+		nss_python_log(LOG_ERR, "nss_pwd_parse: glibc provided buffer is to small, we ask glibc for extended one");
+	*errnop = ERANGE;
+	return NSS_STATUS_TRYAGAIN;
+}
+
+NSS_STATUS _nss_python_getpwnam_r (const char *name,
+		struct passwd * result,
+		char *buffer, size_t buflen, int *errnop) {
+
+	PyObject *pynss_getpwnam_r, *pValue, *pInName;
+
+	if (DEBUG)
+		nss_python_log(LOG_ERR, "_nss_python_getpwnam_r: called");
+
+	if (init_python() != NSS_STATUS_SUCCESS)
+		return NSS_STATUS_UNAVAIL;
+
+	pynss_getpwnam_r = PyObject_GetAttrString(pymod, "pynss_getpwnam_r");
+	if (pynss_getpwnam_r == NULL || !PyFunction_Check(pynss_getpwnam_r)) {
+		nss_python_log(LOG_ERR, "_nss_python_getgrnam_r: pynss_getpwnam_r not found in python script");
+		return NSS_STATUS_UNAVAIL;
+	}
+
+	pInName = PyString_FromString(name);
+	if (pInName == NULL) {
+		if (DEBUG)
+			nss_python_log(LOG_ERR, "_nss_python_getpwnam_r: can't convert group name to python format: %s", name);
+		return NSS_STATUS_UNAVAIL;
+	}
+
+	pValue = PyObject_CallFunction(pynss_getpwnam_r, "s", pInName);
+	if (pValue == NULL || !PyTuple_Check(pValue)) {
+		if (DEBUG)
+			nss_python_log(LOG_ERR, "_nss_python_getpwnam_r: calling pynss_getpwnam_r python function failed or result is not a tuple");
+		return NSS_STATUS_UNAVAIL;
+	}
+
+	return nss_pwd_parse(pValue, result, buffer, buflen, errnop);
+}
+
+NSS_STATUS _nss_python_getpwuid_r (uid_t uid,
+		struct passwd *result,
+		char *buffer, size_t buflen, int *errnop) {
+	PyObject *pynss_getpwuid_r, *pValue, *pInUid;
+
+	if (DEBUG)
+		nss_python_log(LOG_ERR, "_nss_python_getpwuid_r: called");
+
+	if (init_python() != NSS_STATUS_SUCCESS)
+		return NSS_STATUS_UNAVAIL;
+
+	pynss_getpwuid_r = PyObject_GetAttrString(pymod, "pynss_getpwuid_r");
+	if (pynss_getpwuid_r == NULL || !PyFunction_Check(pynss_getpwuid_r)) {
+		nss_python_log(LOG_ERR, "_nss_python_getgrnam_r: pynss_getpwuid_r not found in python script");
+		return NSS_STATUS_UNAVAIL;
+	}
+
+	pInUid = PyInt_FromSsize_t(uid);
+	if (pInUid == NULL) {
+		if (DEBUG)
+			nss_python_log(LOG_ERR, "_nss_python_getpwnam_r: can't convert UID to python format: %d", uid);
+		return NSS_STATUS_UNAVAIL;
+	}
+
+	pValue = PyObject_CallFunction(pynss_getpwuid_r, "i", pInUid);
+	if (pValue == NULL || !PyTuple_Check(pValue)) {
+		if (DEBUG)
+			nss_python_log(LOG_ERR, "_nss_python_getpwnam_r: calling pynss_getpwuid_r python function failed or result is not a tuple");
+		return NSS_STATUS_UNAVAIL;
+	}
+
+	return nss_pwd_parse(pValue, result, buffer, buflen, errnop);
+
+}
+
+NSS_STATUS _nss_python_setpwent (void) {
+	PyObject *pynss_setpwent, *pValue;
+
+	if (DEBUG)
+		nss_python_log(LOG_ERR, "_nss_python_setpwent: called");
+
+	if (init_python() != NSS_STATUS_SUCCESS)
+		return NSS_STATUS_UNAVAIL;
+
+	pynss_setpwent = PyObject_GetAttrString(pymod, "pynss_setpwent");
+	if (pynss_setpwent == NULL || !PyFunction_Check(pynss_setpwent)) {
+		nss_python_log(LOG_ERR, "_nss_python_setpwent: pynss_setpwent not found in python script");
+		return NSS_STATUS_UNAVAIL;
+	}
+
+        pValue = PyObject_CallFunction(pynss_setpwent, NULL);
+        if (pValue == NULL || !PyBool_Check(pValue)) {
+                if (DEBUG)
+                        nss_python_log(LOG_ERR, "_nss_python_setpwent: calling pynss_setpwent python function failed or result is not a boolean");
+                return NSS_STATUS_UNAVAIL;
+        }
+
+        if (pValue == Py_True)
+                return NSS_STATUS_SUCCESS;
+
+	return NSS_STATUS_SUCCESS;
+}
+
+NSS_STATUS _nss_python_endpwent (void) {
+	PyObject *pynss_endpwent, *pValue;
+
+	if (DEBUG)
+		nss_python_log(LOG_ERR, "_nss_python_endpwent: called");
+
+	if (init_python() != NSS_STATUS_SUCCESS)
+		return NSS_STATUS_UNAVAIL;
+
+	pynss_endpwent = PyObject_GetAttrString(pymod, "pynss_endpwent");
+	if (pynss_endpwent == NULL || !PyFunction_Check(pynss_endpwent)) {
+		nss_python_log(LOG_ERR, "_nss_python_endpwent: pynss_endpwent not found in python script");
+		return NSS_STATUS_UNAVAIL;
+	}
+
+	pValue = PyObject_CallFunction(pynss_endpwent, NULL);
+	if (pValue == NULL) {
+		if (DEBUG)
+			nss_python_log(LOG_ERR, "_nss_python_endpwent: calling pynss_endpwent python function failed");
+		return NSS_STATUS_UNAVAIL;
+	}
+
+	return NSS_STATUS_SUCCESS;
+}
+
+
+NSS_STATUS _nss_python_getpwent_r (struct passwd *result,
+		char *buffer, size_t buflen, int *errnop) {
+	PyObject *pynss_getpwent_r, *pValue;
+
+	if (DEBUG)
+		nss_python_log(LOG_ERR, "_nss_python_getpwent_r: called");
+
+	if (init_python() != NSS_STATUS_SUCCESS)
+		return NSS_STATUS_UNAVAIL;
+
+	pynss_getpwent_r = PyObject_GetAttrString(pymod, "pynss_getpwent_r");
+	if (pynss_getpwent_r == NULL || !PyFunction_Check(pynss_getpwent_r)) {
+		nss_python_log(LOG_ERR, "_nss_python_getpwent_r: pynss_getpwent_r not found in python script");
+		return NSS_STATUS_UNAVAIL;
+	}
+
+	pValue = PyObject_CallFunction(pynss_getpwent_r, NULL);
+	if (pValue == NULL || !PyTuple_Check(pValue)) {
+		if (DEBUG)
+			nss_python_log(LOG_ERR, "_nss_python_getpwent_r: calling pynss_getpwent_r python function failed or result is not a tuple");
+		return NSS_STATUS_UNAVAIL;
+	}
+
+	return nss_pwd_parse(pValue, result, buffer, buflen, errnop);
+}
+

Added: nss_python/trunk/src/nss_python.h
==============================================================================
--- (empty file)
+++ nss_python/trunk/src/nss_python.h	Sun Feb 18 12:36:59 2007
@@ -0,0 +1,33 @@
+/*
+    nss_python - NSS module which allows to write python bacends for NSS
+    Copyright (C) 2007 Arkadiusz Miśkiewicz <arekm at pld-linux.org>
+
+    This program 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; either version 2 of the License.
+
+    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, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+
+*/
+
+#ifdef	DEBUGME
+#define DEBUG   1
+#define DEBUGP(x)       fprintf(stderr, "%s", x)
+#else
+#define	DEBUG	0
+#define	DEBUGP(x)
+#endif
+
+#define	_GNU_SOURCE	1
+
+#include <nss.h>
+#include <syslog.h>
+
+typedef enum nss_status NSS_STATUS;

Added: nss_python/trunk/src/nss_spwd.c
==============================================================================
--- (empty file)
+++ nss_python/trunk/src/nss_spwd.c	Sun Feb 18 12:36:59 2007
@@ -0,0 +1,283 @@
+/*
+    nss_python - NSS module which allows to write python bacends for NSS
+    Copyright (C) 2007 Arkadiusz Miśkiewicz <arekm at pld-linux.org>
+
+    This program 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; either version 2 of the License.
+
+    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, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+
+*/
+
+#include <sys/types.h>
+#include <shadow.h>
+#include <nss.h>
+#include <Python.h>
+
+#include "nss_python.h"
+#include "lib.h"
+
+static NSS_STATUS nss_spwd_parse(PyObject *pValue,
+		struct spwd * result,
+		char *buffer, size_t buflen, int *errnop)
+{
+	PyObject *pNamp = NULL, *pPwdp = NULL, *pLstChg = NULL, *pMin = NULL, *pMax = NULL, *pWarn = NULL, *pInact = NULL, *pExpire = NULL, *pFlag;
+	Py_ssize_t i;
+
+	i = PyTuple_Size(pValue);
+	if (i != 9) {
+		nss_python_log(LOG_ERR, "nss_spwd_parse: result is a tuple of size %d, need 9", i);
+		return NSS_STATUS_UNAVAIL;
+	}
+
+	pNamp = PyTuple_GetItem(pValue, 0);
+	if (pNamp == NULL || !PyString_Check(pNamp) || PyString_Size(pNamp) == 0) {
+		if (DEBUG)
+			nss_python_log(LOG_ERR, "nss_spwd_parse: first tuple item has to be a string with size > 0");
+		return NSS_STATUS_UNAVAIL;
+	}
+
+	result->sp_namp = copy_to_buffer(&buffer, &buflen, PyString_AsString(pNamp));
+	if (result->sp_namp == NULL)
+		goto out_nomem;
+
+	pPwdp = PyTuple_GetItem(pValue, 1);
+	if (pPwdp == NULL || !PyString_Check(pPwdp)) {
+		if (DEBUG)
+			nss_python_log(LOG_ERR, "nss_spwd_parse: second tuple item has to be a string");
+		return NSS_STATUS_UNAVAIL;
+	}
+
+	result->sp_pwdp = copy_to_buffer(&buffer, &buflen, PyString_AsString(pPwdp));
+	if (result->sp_pwdp == NULL)
+		goto out_nomem;
+
+	pLstChg = PyTuple_GetItem(pValue, 2);
+	if (pLstChg == NULL || !PyInt_Check(pLstChg)) {
+		if (DEBUG)
+			nss_python_log(LOG_ERR, "nss_spwd_parse: third tuple item has to be a integer");
+		return NSS_STATUS_UNAVAIL;
+	}
+
+	result->sp_lstchg = PyLong_AsLong(pLstChg);
+
+	pMin = PyTuple_GetItem(pValue, 3);
+	if (pMin == NULL || !PyInt_Check(pMin)) {
+		if (DEBUG)
+			nss_python_log(LOG_ERR, "nss_spwd_parse: fourth tuple item has to be a integer");
+		return NSS_STATUS_UNAVAIL;
+	}
+
+	result->sp_min = PyLong_AsLong(pMin);
+
+	pMax = PyTuple_GetItem(pValue, 4);
+	if (pMax == NULL || !PyInt_Check(pMax)) {
+		if (DEBUG)
+			nss_python_log(LOG_ERR, "nss_spwd_parse: fifth tuple item has to be a integer");
+		return NSS_STATUS_UNAVAIL;
+	}
+
+	result->sp_max = PyLong_AsLong(pMax);
+
+	pWarn = PyTuple_GetItem(pValue, 5);
+	if (pWarn == NULL || !PyInt_Check(pWarn)) {
+		if (DEBUG)
+			nss_python_log(LOG_ERR, "nss_spwd_parse: sixth tuple item has to be a integer");
+		return NSS_STATUS_UNAVAIL;
+	}
+
+	result->sp_warn = PyLong_AsLong(pWarn);
+
+	pInact = PyTuple_GetItem(pValue, 6);
+	if (pInact == NULL || !PyInt_Check(pInact)) {
+		if (DEBUG)
+			nss_python_log(LOG_ERR, "nss_spwd_parse: seventh tuple item has to be a integer");
+		return NSS_STATUS_UNAVAIL;
+	}
+
+	result->sp_inact = PyLong_AsLong(pInact);
+
+	pExpire = PyTuple_GetItem(pValue, 7);
+	if (pExpire == NULL || !PyInt_Check(pExpire)) {
+		if (DEBUG)
+			nss_python_log(LOG_ERR, "nss_spwd_parse: eighth tuple item has to be a integer");
+		return NSS_STATUS_UNAVAIL;
+	}
+
+	result->sp_expire = PyLong_AsLong(pExpire);
+
+	pFlag = PyTuple_GetItem(pValue, 8);
+	if (pFlag == NULL || !PyInt_Check(pFlag)) {
+		if (DEBUG)
+			nss_python_log(LOG_ERR, "nss_spwd_parse: nineth tuple item has to be a integer");
+		return NSS_STATUS_UNAVAIL;
+	}
+
+	result->sp_flag = PyLong_AsUnsignedLong(pFlag);
+
+	*errnop = 0;
+	return NSS_STATUS_SUCCESS;
+out_nomem:
+	if (DEBUG)
+		nss_python_log(LOG_ERR, "nss_spwd_parse: glibc provided buffer is to small, we ask glibc for extended one");
+	*errnop = ERANGE;
+	return NSS_STATUS_TRYAGAIN;
+}
+
+NSS_STATUS _nss_python_getspwnam_r (const char *name,
+		struct spwd * result,
+		char *buffer, size_t buflen, int *errnop) {
+
+	PyObject *pynss_getspwnam_r, *pValue, *pInName;
+
+	if (DEBUG)
+		nss_python_log(LOG_ERR, "_nss_python_getspwnam_r: called");
+
+	if (init_python() != NSS_STATUS_SUCCESS)
+		return NSS_STATUS_UNAVAIL;
+
+	pynss_getspwnam_r = PyObject_GetAttrString(pymod, "pynss_getspwnam_r");
+	if (pynss_getspwnam_r == NULL || !PyFunction_Check(pynss_getspwnam_r)) {
+		nss_python_log(LOG_ERR, "_nss_python_getgrnam_r: pynss_getpwnam_r not found in python script");
+		return NSS_STATUS_UNAVAIL;
+	}
+
+	pInName = PyString_FromString(name);
+	if (pInName == NULL) {
+		if (DEBUG)
+			nss_python_log(LOG_ERR, "_nss_python_getspwnam_r: can't convert login name to python format: %s", name);
+		return NSS_STATUS_UNAVAIL;
+	}
+
+	pValue = PyObject_CallFunction(pynss_getspwnam_r, "s", pInName);
+	if (pValue == NULL || !PyTuple_Check(pValue)) {
+		if (DEBUG)
+			nss_python_log(LOG_ERR, "_nss_python_getspwnam_r: calling pynss_getspwnam_r python function failed or result is not a tuple");
+		return NSS_STATUS_UNAVAIL;
+	}
+
+	return nss_spwd_parse(pValue, result, buffer, buflen, errnop);
+}
+
+NSS_STATUS _nss_python_getspwuid_r (uid_t uid,
+		struct spwd *result,
+		char *buffer, size_t buflen, int *errnop) {
+	PyObject *pynss_getspwuid_r, *pValue, *pInUid;
+
+	if (DEBUG)
+		nss_python_log(LOG_ERR, "_nss_python_getspwuid_r: called");
+
+	if (init_python() != NSS_STATUS_SUCCESS)
+		return NSS_STATUS_UNAVAIL;
+
+	pynss_getspwuid_r = PyObject_GetAttrString(pymod, "pynss_getspwuid_r");
+	if (pynss_getspwuid_r == NULL || !PyFunction_Check(pynss_getspwuid_r)) {
+		nss_python_log(LOG_ERR, "_nss_python_getspwuid_r: pynss_getspwuid_r not found in python script");
+		return NSS_STATUS_UNAVAIL;
+	}
+
+	pInUid = PyInt_FromSsize_t(uid);
+	if (pInUid == NULL) {
+		if (DEBUG)
+			nss_python_log(LOG_ERR, "_nss_python_getspwnam_r: can't convert UID to python format: %d", uid);
+		return NSS_STATUS_UNAVAIL;
+	}
+
+	pValue = PyObject_CallFunction(pynss_getspwuid_r, "i", pInUid);
+	if (pValue == NULL || !PyTuple_Check(pValue)) {
+		if (DEBUG)
+			nss_python_log(LOG_ERR, "_nss_python_getspwnam_r: calling pynss_getspwuid_r python function failed or result is not a tuple");
+		return NSS_STATUS_UNAVAIL;
+	}
+
+	return nss_spwd_parse(pValue, result, buffer, buflen, errnop);
+
+}
+
+NSS_STATUS _nss_python_setspwent (void) {
+	PyObject *pynss_setspwent, *pValue;
+
+	if (DEBUG)
+		nss_python_log(LOG_ERR, "_nss_python_setpwent: called");
+
+	if (init_python() != NSS_STATUS_SUCCESS)
+		return NSS_STATUS_UNAVAIL;
+
+	pynss_setspwent = PyObject_GetAttrString(pymod, "pynss_setspwent");
+	if (pynss_setspwent == NULL || !PyFunction_Check(pynss_setspwent)) {
+		nss_python_log(LOG_ERR, "_nss_python_setpwent: pynss_setpwent not found in python script");
+		return NSS_STATUS_UNAVAIL;
+	}
+
+	pValue = PyObject_CallFunction(pynss_setspwent, NULL);
+	if (pValue == NULL || !PyBool_Check(pValue)) {
+		if (DEBUG)
+			nss_python_log(LOG_ERR, "_nss_python_setspwent: calling pynss_setspwent python function failed or result is not a boolean");
+		return NSS_STATUS_UNAVAIL;
+	}
+
+	if (pValue == Py_True)
+		return NSS_STATUS_SUCCESS;
+	return NSS_STATUS_NOTFOUND;
+}
+
+NSS_STATUS _nss_python_endspwent (void) {
+	PyObject *pynss_endspwent, *pValue;
+
+	if (DEBUG)
+		nss_python_log(LOG_ERR, "_nss_python_endspwent: called");
+
+	if (init_python() != NSS_STATUS_SUCCESS)
+		return NSS_STATUS_UNAVAIL;
+
+	pynss_endspwent = PyObject_GetAttrString(pymod, "pynss_endspwent");
+	if (pynss_endspwent == NULL || !PyFunction_Check(pynss_endspwent)) {
+		nss_python_log(LOG_ERR, "_nss_python_endspwent: pynss_endspwent not found in python script");
+		return NSS_STATUS_UNAVAIL;
+	}
+
+	pValue = PyObject_CallFunction(pynss_endspwent, NULL);
+	if (pValue == NULL) {
+		if (DEBUG)
+			nss_python_log(LOG_ERR, "_nss_python_endspwent: calling pynss_endspwent python function failed");
+		return NSS_STATUS_UNAVAIL;
+	}
+
+	return NSS_STATUS_SUCCESS;
+}
+
+
+NSS_STATUS _nss_python_getspwent_r (struct spwd *result,
+		char *buffer, size_t buflen, int *errnop) {
+	PyObject *pynss_getspwent_r, *pValue;
+
+	if (DEBUG)
+		nss_python_log(LOG_ERR, "_nss_python_getspwent_r: called");
+
+	if (init_python() != NSS_STATUS_SUCCESS)
+		return NSS_STATUS_UNAVAIL;
+
+	pynss_getspwent_r = PyObject_GetAttrString(pymod, "pynss_getspwent_r");
+	if (pynss_getspwent_r == NULL || !PyFunction_Check(pynss_getspwent_r)) {
+		nss_python_log(LOG_ERR, "_nss_python_getspwent_r: pynss_getspwent_r not found in python script");
+		return NSS_STATUS_UNAVAIL;
+	}
+
+	pValue = PyObject_CallFunction(pynss_getspwent_r, NULL);
+	if (pValue == NULL || !PyTuple_Check(pValue)) {
+		if (DEBUG)
+			nss_python_log(LOG_ERR, "_nss_python_getspwent_r: calling pynss_getspwent_r python function failed or result is not a tuple");
+		return NSS_STATUS_UNAVAIL;
+	}
+
+	return nss_spwd_parse(pValue, result, buffer, buflen, errnop);
+}
+

Added: nss_python/trunk/tests/Makefile.am
==============================================================================


More information about the pld-cvs-commit mailing list