SVN: nss_python/trunk/src: nss_grp.c nss_pwd.c nss_spwd.c

arekm arekm at pld-linux.org
Sun Feb 18 16:23:54 CET 2007


Author: arekm
Date: Sun Feb 18 16:23:54 2007
New Revision: 8279

Modified:
   nss_python/trunk/src/nss_grp.c
   nss_python/trunk/src/nss_pwd.c
   nss_python/trunk/src/nss_spwd.c
Log:
Add some reference counting. Debugging errors with PyErr_Print().

Modified: nss_python/trunk/src/nss_grp.c
==============================================================================
--- nss_python/trunk/src/nss_grp.c	(original)
+++ nss_python/trunk/src/nss_grp.c	Sun Feb 18 16:23:54 2007
@@ -105,8 +105,9 @@
 
 		p = buffer_end -= s + 1;
 		
-		if ((void *) grmemptr >= (void *) buffer_end)
+		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));
@@ -133,7 +134,7 @@
 		struct group * result,
 		char *buffer, size_t buflen, int *errnop)
 {
-	PyObject *pynss_getgrnam_r, *pValue, *pInGroupName;
+	PyObject *pynss_getgrnam_r = NULL, *pValue = NULL, *pInGroupName = NULL;
 
 	if (DEBUG)
 		nss_python_log(LOG_ERR, "_nss_python_getgrnam_r: called");
@@ -144,6 +145,7 @@
 	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");
+		Py_XDECREF(pynss_getgrnam_r);
 		return NSS_STATUS_UNAVAIL;
 	}
 
@@ -151,13 +153,18 @@
 	if (pInGroupName == NULL) {
 		if (DEBUG)
 			nss_python_log(LOG_ERR, "_nss_python_getgrnam_r: can't convert group name to python format: %s", name);
+		Py_XDECREF(pynss_getgrnam_r);
 		return NSS_STATUS_UNAVAIL;
 	}
 
 	pValue = PyObject_CallFunction(pynss_getgrnam_r, "s", pInGroupName);
+	Py_XDECREF(pynss_getgrnam_r);
+	Py_XDECREF(pInGroupName);
 	if (pValue == NULL || !PyTuple_Check(pValue)) {
-		if (DEBUG)
+		if (DEBUG) {
 			nss_python_log(LOG_ERR, "_nss_python_getgrnam_r: calling pynss_getgrnam_r python function failed or result is not a tuple");
+			PyErr_Print();
+		}
 		return NSS_STATUS_UNAVAIL;
 	}
 
@@ -168,7 +175,7 @@
 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;
+	PyObject *pynss_getgrgid_r = NULL, *pValue = NULL, *pGid = NULL;
 
 	if (DEBUG)
 		nss_python_log(LOG_ERR, "_nss_python_getgrgid_r: called");
@@ -179,6 +186,7 @@
 	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");
+		Py_XDECREF(pynss_getgrgid_r);
 		return NSS_STATUS_UNAVAIL;
 	}
 
@@ -186,13 +194,18 @@
 	if (pGid == NULL) {
 		if (DEBUG)
 			nss_python_log(LOG_ERR, "_nss_python_getgrgid_r: can't convert gid to python format: %d", gid);
+		Py_XDECREF(pynss_getgrgid_r);
 		return NSS_STATUS_UNAVAIL;
 	}
 
 	pValue = PyObject_CallFunction(pynss_getgrgid_r, "i", pGid);
+	Py_XDECREF(pynss_getgrgid_r);
+	Py_XDECREF(pGid);
 	if (pValue == NULL || !PyTuple_Check(pValue)) {
-		if (DEBUG)
+		if (DEBUG) {
 			nss_python_log(LOG_ERR, "_nss_python_getgrgid_r: calling pynss_getgrgid_r python function failed or result is not a tuple");
+			PyErr_Print();
+		}
 		return NSS_STATUS_UNAVAIL;
 	}
 
@@ -200,7 +213,7 @@
 }
 
 NSS_STATUS _nss_python_setgrent (void) {
-	PyObject *pynss_setgrent, *pValue;
+	PyObject *pynss_setgrent = NULL, *pValue = NULL;
 
 	if (DEBUG)
 		nss_python_log(LOG_ERR, "_nss_python_setgrent: called");
@@ -211,13 +224,17 @@
 	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");
+		Py_XDECREF(pynss_setgrent);
 		return NSS_STATUS_UNAVAIL;
 	}
 
 	pValue = PyObject_CallFunction(pynss_setgrent, NULL);
+	Py_XDECREF(pynss_setgrent);
 	if (pValue == NULL || !PyBool_Check(pValue)) {
-		if (DEBUG)
+		if (DEBUG) {
 			nss_python_log(LOG_ERR, "_nss_python_setgrent: calling pynss_setgrent python function failed or result is not a boolean");
+			PyErr_Print();
+		}
 		return NSS_STATUS_UNAVAIL;
 	}
 
@@ -229,7 +246,7 @@
 
 
 NSS_STATUS _nss_python_endgrent (void) {
-	PyObject *pynss_endgrent, *pValue;
+	PyObject *pynss_endgrent = NULL, *pValue = NULL;
 
 	if (DEBUG)
 		nss_python_log(LOG_ERR, "_nss_python_endgrent: called");
@@ -240,13 +257,17 @@
 	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");
+		Py_XDECREF(pynss_endgrent);
 		return NSS_STATUS_UNAVAIL;
 	}
 
 	pValue = PyObject_CallFunction(pynss_endgrent, NULL);
+	Py_XDECREF(pynss_endgrent);
 	if (pValue == NULL) {
-		if (DEBUG)
+		if (DEBUG) {
 			nss_python_log(LOG_ERR, "_nss_python_endgrent: calling pynss_endgrent python function failed");
+			PyErr_Print();
+		}
 		return NSS_STATUS_UNAVAIL;
 	}
 
@@ -255,7 +276,7 @@
 
 NSS_STATUS _nss_python_getgrent_r (struct group *result,
 		char *buffer, size_t buflen, int *errnop) {
-	PyObject *pynss_getgrent_r, *pValue;
+	PyObject *pynss_getgrent_r = NULL, *pValue = NULL;
 
 	if (DEBUG)
 		nss_python_log(LOG_ERR, "_nss_python_getgrent_r: called");
@@ -266,14 +287,17 @@
 	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");
+		Py_XDECREF(pynss_getgrent_r);
 		return NSS_STATUS_UNAVAIL;
 	}
 
-
 	pValue = PyObject_CallFunction(pynss_getgrent_r, NULL);
+	Py_XDECREF(pynss_getgrent_r);
 	if (pValue == NULL) {
-		if (DEBUG)
+		if (DEBUG) {
 			nss_python_log(LOG_ERR, "_nss_python_getgrent_r: calling pynss_getgrent_r python function failed");
+			PyErr_Print();
+		}
 		return NSS_STATUS_UNAVAIL;
 	}
 

Modified: nss_python/trunk/src/nss_pwd.c
==============================================================================
--- nss_python/trunk/src/nss_pwd.c	(original)
+++ nss_python/trunk/src/nss_pwd.c	Sun Feb 18 16:23:54 2007
@@ -128,7 +128,7 @@
 		struct passwd * result,
 		char *buffer, size_t buflen, int *errnop) {
 
-	PyObject *pynss_getpwnam_r, *pValue, *pInName;
+	PyObject *pynss_getpwnam_r = NULL, *pValue = NULL, *pInName = NULL;
 
 	if (DEBUG)
 		nss_python_log(LOG_ERR, "_nss_python_getpwnam_r: called");
@@ -139,6 +139,7 @@
 	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");
+		Py_XDECREF(pynss_getpwnam_r);
 		return NSS_STATUS_UNAVAIL;
 	}
 
@@ -146,13 +147,18 @@
 	if (pInName == NULL) {
 		if (DEBUG)
 			nss_python_log(LOG_ERR, "_nss_python_getpwnam_r: can't convert group name to python format: %s", name);
+		Py_XDECREF(pynss_getpwnam_r);
 		return NSS_STATUS_UNAVAIL;
 	}
 
 	pValue = PyObject_CallFunction(pynss_getpwnam_r, "s", pInName);
+	Py_XDECREF(pynss_getpwnam_r);
+	Py_XDECREF(pInName);
 	if (pValue == NULL || !PyTuple_Check(pValue)) {
-		if (DEBUG)
+		if (DEBUG) {
 			nss_python_log(LOG_ERR, "_nss_python_getpwnam_r: calling pynss_getpwnam_r python function failed or result is not a tuple");
+			PyErr_Print();
+		}
 		return NSS_STATUS_UNAVAIL;
 	}
 
@@ -162,7 +168,7 @@
 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;
+	PyObject *pynss_getpwuid_r = NULL, *pValue = NULL, *pInUid = NULL;
 
 	if (DEBUG)
 		nss_python_log(LOG_ERR, "_nss_python_getpwuid_r: called");
@@ -173,6 +179,7 @@
 	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");
+		Py_XDECREF(pynss_getpwuid_r);
 		return NSS_STATUS_UNAVAIL;
 	}
 
@@ -180,13 +187,18 @@
 	if (pInUid == NULL) {
 		if (DEBUG)
 			nss_python_log(LOG_ERR, "_nss_python_getpwnam_r: can't convert UID to python format: %d", uid);
+		Py_XDECREF(pynss_getpwuid_r);
 		return NSS_STATUS_UNAVAIL;
 	}
 
 	pValue = PyObject_CallFunction(pynss_getpwuid_r, "i", pInUid);
+	Py_XDECREF(pynss_getpwuid_r);
+	Py_XDECREF(pInUid);
 	if (pValue == NULL || !PyTuple_Check(pValue)) {
-		if (DEBUG)
+		if (DEBUG) {
 			nss_python_log(LOG_ERR, "_nss_python_getpwnam_r: calling pynss_getpwuid_r python function failed or result is not a tuple");
+			PyErr_Print();
+		}
 		return NSS_STATUS_UNAVAIL;
 	}
 
@@ -195,7 +207,7 @@
 }
 
 NSS_STATUS _nss_python_setpwent (void) {
-	PyObject *pynss_setpwent, *pValue;
+	PyObject *pynss_setpwent = NULL, *pValue = NULL;
 
 	if (DEBUG)
 		nss_python_log(LOG_ERR, "_nss_python_setpwent: called");
@@ -206,13 +218,17 @@
 	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");
+		Py_XDECREF(pynss_setpwent);
 		return NSS_STATUS_UNAVAIL;
 	}
 
         pValue = PyObject_CallFunction(pynss_setpwent, NULL);
+	Py_XDECREF(pynss_setpwent);
         if (pValue == NULL || !PyBool_Check(pValue)) {
-                if (DEBUG)
+                if (DEBUG) {
                         nss_python_log(LOG_ERR, "_nss_python_setpwent: calling pynss_setpwent python function failed or result is not a boolean");
+			PyErr_Print();
+		}
                 return NSS_STATUS_UNAVAIL;
         }
 
@@ -223,7 +239,7 @@
 }
 
 NSS_STATUS _nss_python_endpwent (void) {
-	PyObject *pynss_endpwent, *pValue;
+	PyObject *pynss_endpwent = NULL, *pValue = NULL;
 
 	if (DEBUG)
 		nss_python_log(LOG_ERR, "_nss_python_endpwent: called");
@@ -234,13 +250,17 @@
 	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");
+		Py_XDECREF(pynss_endpwent);
 		return NSS_STATUS_UNAVAIL;
 	}
 
 	pValue = PyObject_CallFunction(pynss_endpwent, NULL);
+	Py_XDECREF(pynss_endpwent);
 	if (pValue == NULL) {
-		if (DEBUG)
+		if (DEBUG) {
 			nss_python_log(LOG_ERR, "_nss_python_endpwent: calling pynss_endpwent python function failed");
+			PyErr_Print();
+		}
 		return NSS_STATUS_UNAVAIL;
 	}
 
@@ -250,7 +270,7 @@
 
 NSS_STATUS _nss_python_getpwent_r (struct passwd *result,
 		char *buffer, size_t buflen, int *errnop) {
-	PyObject *pynss_getpwent_r, *pValue;
+	PyObject *pynss_getpwent_r = NULL, *pValue = NULL;
 
 	if (DEBUG)
 		nss_python_log(LOG_ERR, "_nss_python_getpwent_r: called");
@@ -261,13 +281,17 @@
 	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");
+		Py_XDECREF(pynss_getpwent_r);
 		return NSS_STATUS_UNAVAIL;
 	}
 
 	pValue = PyObject_CallFunction(pynss_getpwent_r, NULL);
+	Py_XDECREF(pynss_getpwent_r);
 	if (pValue == NULL) {
-		if (DEBUG)
+		if (DEBUG) {
 			nss_python_log(LOG_ERR, "_nss_python_getpwent_r: calling pynss_getpwent_r python function failed");
+			PyErr_Print();
+		}
 		return NSS_STATUS_UNAVAIL;
 	}
 

Modified: nss_python/trunk/src/nss_spwd.c
==============================================================================
--- nss_python/trunk/src/nss_spwd.c	(original)
+++ nss_python/trunk/src/nss_spwd.c	Sun Feb 18 16:23:54 2007
@@ -140,7 +140,7 @@
 		struct spwd * result,
 		char *buffer, size_t buflen, int *errnop) {
 
-	PyObject *pynss_getspwnam_r, *pValue, *pInName;
+	PyObject *pynss_getspwnam_r = NULL, *pValue = NULL, *pInName = NULL;
 
 	if (DEBUG)
 		nss_python_log(LOG_ERR, "_nss_python_getspwnam_r: called");
@@ -151,6 +151,7 @@
 	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");
+		Py_XDECREF(pynss_getspwnam_r);
 		return NSS_STATUS_UNAVAIL;
 	}
 
@@ -158,13 +159,18 @@
 	if (pInName == NULL) {
 		if (DEBUG)
 			nss_python_log(LOG_ERR, "_nss_python_getspwnam_r: can't convert login name to python format: %s", name);
+		Py_XDECREF(pynss_getspwnam_r);
 		return NSS_STATUS_UNAVAIL;
 	}
 
 	pValue = PyObject_CallFunction(pynss_getspwnam_r, "s", pInName);
+	Py_XDECREF(pynss_getspwnam_r);
+	Py_XDECREF(pInName);
 	if (pValue == NULL || !PyTuple_Check(pValue)) {
-		if (DEBUG)
+		if (DEBUG) {
 			nss_python_log(LOG_ERR, "_nss_python_getspwnam_r: calling pynss_getspwnam_r python function failed or result is not a tuple");
+			PyErr_Print();
+		}
 		return NSS_STATUS_UNAVAIL;
 	}
 
@@ -174,7 +180,7 @@
 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;
+	PyObject *pynss_getspwuid_r = NULL, *pValue = NULL, *pInUid = NULL;
 
 	if (DEBUG)
 		nss_python_log(LOG_ERR, "_nss_python_getspwuid_r: called");
@@ -185,6 +191,7 @@
 	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");
+		Py_XDECREF(pynss_getspwuid_r);
 		return NSS_STATUS_UNAVAIL;
 	}
 
@@ -192,13 +199,18 @@
 	if (pInUid == NULL) {
 		if (DEBUG)
 			nss_python_log(LOG_ERR, "_nss_python_getspwnam_r: can't convert UID to python format: %d", uid);
+		Py_XDECREF(pynss_getspwuid_r);
 		return NSS_STATUS_UNAVAIL;
 	}
 
 	pValue = PyObject_CallFunction(pynss_getspwuid_r, "i", pInUid);
+	Py_XDECREF(pynss_getspwuid_r);
+	Py_XDECREF(pInUid);
 	if (pValue == NULL || !PyTuple_Check(pValue)) {
-		if (DEBUG)
+		if (DEBUG) {
 			nss_python_log(LOG_ERR, "_nss_python_getspwnam_r: calling pynss_getspwuid_r python function failed or result is not a tuple");
+			PyErr_Print();
+		}
 		return NSS_STATUS_UNAVAIL;
 	}
 
@@ -207,7 +219,7 @@
 }
 
 NSS_STATUS _nss_python_setspwent (void) {
-	PyObject *pynss_setspwent, *pValue;
+	PyObject *pynss_setspwent = NULL, *pValue = NULL;
 
 	if (DEBUG)
 		nss_python_log(LOG_ERR, "_nss_python_setpwent: called");
@@ -218,13 +230,17 @@
 	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");
+		Py_XDECREF(pynss_setspwent);
 		return NSS_STATUS_UNAVAIL;
 	}
 
 	pValue = PyObject_CallFunction(pynss_setspwent, NULL);
+	Py_XDECREF(pynss_setspwent);
 	if (pValue == NULL || !PyBool_Check(pValue)) {
-		if (DEBUG)
+		if (DEBUG) {
 			nss_python_log(LOG_ERR, "_nss_python_setspwent: calling pynss_setspwent python function failed or result is not a boolean");
+			PyErr_Print();
+		}
 		return NSS_STATUS_UNAVAIL;
 	}
 
@@ -235,7 +251,7 @@
 }
 
 NSS_STATUS _nss_python_endspwent (void) {
-	PyObject *pynss_endspwent, *pValue;
+	PyObject *pynss_endspwent = NULL, *pValue = NULL;
 
 	if (DEBUG)
 		nss_python_log(LOG_ERR, "_nss_python_endspwent: called");
@@ -246,13 +262,17 @@
 	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");
+		Py_XDECREF(pynss_endspwent);
 		return NSS_STATUS_UNAVAIL;
 	}
 
 	pValue = PyObject_CallFunction(pynss_endspwent, NULL);
+	Py_XDECREF(pynss_endspwent);
 	if (pValue == NULL) {
-		if (DEBUG)
+		if (DEBUG) {
 			nss_python_log(LOG_ERR, "_nss_python_endspwent: calling pynss_endspwent python function failed");
+			PyErr_Print();
+		}
 		return NSS_STATUS_UNAVAIL;
 	}
 
@@ -262,7 +282,7 @@
 
 NSS_STATUS _nss_python_getspwent_r (struct spwd *result,
 		char *buffer, size_t buflen, int *errnop) {
-	PyObject *pynss_getspwent_r, *pValue;
+	PyObject *pynss_getspwent_r = NULL, *pValue = NULL;
 
 	if (DEBUG)
 		nss_python_log(LOG_ERR, "_nss_python_getspwent_r: called");
@@ -273,18 +293,23 @@
 	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");
+		Py_XDECREF(pynss_getspwent_r);
 		return NSS_STATUS_UNAVAIL;
 	}
 
 	pValue = PyObject_CallFunction(pynss_getspwent_r, NULL);
+	Py_XDECREF(pynss_getspwent_r);
 	if (pValue == NULL) {
-		if (DEBUG)
+		if (DEBUG) {
 			nss_python_log(LOG_ERR, "_nss_python_getspwent_r: calling pynss_getspwent_r python function failed");
+			PyErr_Print();
+		}
 		return NSS_STATUS_UNAVAIL;
 	}
 
-	if (PyBool_Check(pValue) && pValue == Py_False)
+	if (PyBool_Check(pValue) && pValue == Py_False) {
 		return NSS_STATUS_NOTFOUND;
+	}
 
 	if (!PyTuple_Check(pValue)) {
 		if (DEBUG)


More information about the pld-cvs-commit mailing list