AC_CHECK_HEADERS(fcntl.h)
AC_CHECK_HEADERS(inttypes.h)
AC_CHECK_HEADERS(stdint.h)
+AC_CHECK_HEADERS(pthread.h)
dnl Cygwin workaround
AC_MSG_CHECKING(if LINE_MAX is defined)
AM_GNU_GETTEXT_VERSION
AM_GNU_GETTEXT([external])
-AC_OUTPUT(util/Makefile lib/Makefile doc/Makefile Makefile \
+dnl Check for python, unless we were told to not try to build a python module
+AC_ARG_WITH(python,
+AC_HELP_STRING(--without,[Build a python module (default auto)]),
+build_python=$withval,build_python=auto)
+if test "$build_python" != no ; then
+ AM_PATH_PYTHON(,,[
+ if test "$build_python" = auto ; then
+ AC_MSG_WARN([python was not found, continuing])
+ build_python=no
+ else
+ AC_MSG_ERROR([python was required but not found])
+ fi
+ ])
+ if test "$build_python" != no ; then
+ build_python=yes
+ fi
+fi
+AM_CONDITIONAL(BUILD_PYTHON,[test "$build_python" = "yes"])
+
+AC_OUTPUT(util/Makefile lib/Makefile doc/Makefile python/Makefile Makefile \
po/Makefile.in m4/Makefile cracklib.spec)
--- /dev/null
+/*
+ * A Python binding for cracklib.
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <Python.h>
+#ifdef HAVE_PTHREAD_H
+#include <pthread.h>
+#endif
+#include "../lib/crack.h"
+
+#ifdef HAVE_PTHREAD_H
+static pthread_mutex_t cracklib_mutex = PTHREAD_MUTEX_INITIALIZER;
+#define LOCK() pthread_mutex_lock(&cracklib_mutex)
+#define UNLOCK() pthread_mutex_unlock(&cracklib_mutex)
+#else
+#define LOCK()
+#define UNLOCK()
+#endif
+
+static PyObject *
+cracklib_FascistCheck(PyObject *self, PyObject *args, PyObject *kwargs)
+{
+ int i;
+ char *candidate, *dict;
+ const char *result;
+ struct stat st;
+ char *keywords[] = {"pw", "dictpath", NULL};
+
+ self = NULL;
+ candidate = NULL;
+ dict = NULL;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|s", keywords,
+ &candidate, &dict))
+ {
+ PyErr_SetString(PyExc_ValueError, "error parsing arguments");
+ return NULL;
+ }
+
+ if (candidate == NULL)
+ {
+ PyErr_SetString(PyExc_ValueError, "first argument was not a string!");
+ return NULL;
+ }
+ if (dict != NULL)
+ {
+ if (dict[0] != '/')
+ {
+ PyErr_SetString(PyExc_ValueError,
+ "second argument was not an absolute path!");
+ return NULL;
+ }
+ if (lstat(dict, &st) == -1)
+ {
+ PyErr_SetFromErrnoWithFilename(PyExc_OSError, dict);
+ return NULL;
+ }
+ } else
+ {
+ if (lstat(DEFAULT_CRACKLIB_DICT ".pwd", &st) == -1)
+ {
+ PyErr_SetFromErrnoWithFilename(PyExc_OSError,
+ DEFAULT_CRACKLIB_DICT);
+ return NULL;
+ }
+ }
+
+ LOCK();
+ result = FascistCheck(candidate, dict ? dict : DEFAULT_CRACKLIB_DICT);
+ UNLOCK();
+
+ if (result != NULL)
+ {
+ return PyString_FromString(result);
+ } else
+ {
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
+}
+
+static PyMethodDef
+cracklibmethods[] =
+{
+ {"FascistCheck", cracklib_FascistCheck, METH_VARARGS | METH_KEYWORDS},
+ {NULL, NULL},
+};
+
+void
+initcracklib(void)
+{
+ Py_InitModule("cracklib", cracklibmethods);
+}