From: Matthias Klose <doko@debian.org>
Subject: python3 port

--- python-pam-0.4.2.orig/PAMmodule.c
+++ python-pam-0.4.2/PAMmodule.c
@@ -24,7 +24,7 @@ typedef struct {
     PyObject            *userData;
 } PyPAMObject;
 
-staticforward PyTypeObject PyPAMObject_Type;
+static PyTypeObject PyPAMObject_Type;
 
 static void PyPAM_Err(PyPAMObject *self, int result)
 {
@@ -80,6 +80,7 @@ static int PyPAM_conv(int num_msg, const
         resp_retcode = 0;
         if (!PyArg_ParseTuple(respTuple, "si", &resp_text, &resp_retcode)) {
             free(*resp);
+            *resp = NULL;
             Py_DECREF(respList);
             return PAM_CONV_ERR;
         }
@@ -106,7 +107,7 @@ static PyObject * PyPAM_pam(PyObject *se
     PyPAMObject         *p;
     struct pam_conv     *spc;
 
-    PyPAMObject_Type.ob_type = &PyType_Type;
+    Py_TYPE(&PyPAMObject_Type) = &PyType_Type;
     p = (PyPAMObject *) PyObject_NEW(PyPAMObject, &PyPAMObject_Type);
 
     if ((spc = (struct pam_conv *) malloc(sizeof(struct pam_conv))) == NULL) {
@@ -489,35 +490,33 @@ static void PyPAM_dealloc(PyPAMObject *s
     PyObject_FREE(self);
 }
 
-static PyObject * PyPAM_getattr(PyPAMObject *self, char *name)
-{
-    return Py_FindMethod(PyPAMObject_Methods, (PyObject *) self, name);
-}
-
 static PyObject * PyPAM_repr(PyPAMObject *self)
 {
     char                buf[1024];
     
     snprintf(buf, 1024, "<pam object, service=\"%s\", user=\"%s\", conv=%p, pamh=%p>",
         self->service, self->user, self->conv, self->pamh);
-    return PyString_FromString(buf);
+    return PyUnicode_FromString(buf);
 }
 
 static PyTypeObject PyPAMObject_Type = {
-    PyObject_HEAD_INIT(0)   /* Must fill in type value later */
-    0,
+    PyVarObject_HEAD_INIT(&PyType_Type, 0)   /* Must fill in type value later */
     "pam",
     sizeof(PyPAMObject),
     0,
     (destructor)PyPAM_dealloc,      /*tp_dealloc*/
     0,      /*tp_print*/
-    (getattrfunc)PyPAM_getattr,     /*tp_getattr*/
+    0,      /*tp_getattr*/
     0,      /*tp_setattr*/
     0,      /*tp_compare*/
     (reprfunc)PyPAM_repr,           /*tp_repr*/
     0,      /*tp_as_number*/
     0,      /*tp_as_sequence*/
     0,      /*tp_as_mapping*/
+    0,      /*hash*/
+    0,      /*ternary*/
+    0,      /*another repr*/
+    (getattrofunc)PyObject_GenericGetAttr,
 };
 
 static PyMethodDef PyPAM_Methods[] = {
@@ -525,6 +524,16 @@ static PyMethodDef PyPAM_Methods[] = {
     {NULL, NULL, 0, NULL}
 };
 
+#if PY_MAJOR_VERSION > 2
+static struct PyModuleDef PyPAM_Module = {
+    PyModuleDef_HEAD_INIT,
+    "PAM",    /* name of module */
+    NULL,     /* module documentation */
+    -1,       /* size of per-interpreter state */
+    PyPAM_Methods
+};
+#endif
+
 static char PyPAMObject_doc[] = "";
 
 /* Convenience routine to export an integer value.
@@ -534,7 +543,11 @@ static char PyPAMObject_doc[] = "";
  */
 static void insint(PyObject *d, char *name, int value)
 {
+#if PY_MAJOR_VERSION > 2
+    PyObject            *v = PyLong_FromLong((long) value);
+#else
     PyObject            *v = PyInt_FromLong((long) value);
+#endif
 
     if (!v || PyDict_SetItemString(d, name, v))
         PyErr_Clear();
@@ -542,20 +555,32 @@ static void insint(PyObject *d, char *na
     Py_XDECREF(v);
 }
 
+#if PY_MAJOR_VERSION > 2
+PyMODINIT_FUNC PyInit_PAM(void)
+#else
 void initPAM(void)
+#endif
 {
     PyObject            *m, *d;
 
+#if PY_MAJOR_VERSION > 2
+    m = PyModule_Create(&PyPAM_Module);
+#else
     m = Py_InitModule("PAM", PyPAM_Methods);
+#endif
     d = PyModule_GetDict(m);
     
     PyPAM_Error = PyErr_NewException("PAM.error", NULL, NULL);
     if (PyPAM_Error == NULL)
-        return;
+#if PY_MAJOR_VERSION > 2
+		return m;
+#else
+		return;
+#endif
     PyDict_SetItemString(d, "error", PyPAM_Error);
 
-    PyPAMObject_Type.ob_type = &PyType_Type;
     PyPAMObject_Type.tp_doc = PyPAMObject_doc;
+    PyPAMObject_Type.tp_methods = PyPAMObject_Methods,
     Py_INCREF(&PyPAMObject_Type);
 
     insint(d, "PAM_SUCCESS", PAM_SUCCESS);
@@ -619,4 +644,7 @@ void initPAM(void)
     insint(d, "PAM_BINARY_PROMPT", PAM_BINARY_PROMPT);
 #endif
 
+#if PY_MAJOR_VERSION > 2
+    return m;
+#endif
 }
