From: Jan Dittberner Date: Wed, 18 Nov 2009 15:32:22 +0000 (+0000) Subject: add support for Python setuptools X-Git-Tag: v2.8.14 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9c86f441e9249c475f20bc2e7b86489e54cb94d4;p=cracklib add support for Python setuptools * add a function GetDefaultCracklibDict() to libcrack * bump library version to 2.8.1 * add python/setup.py.in to allow building eggs git-svn-id: file:///tmp/cracklib-svn/trunk@142 4175fe1e-86d5-4fdc-8e6a-506fab9d8533 --- diff --git a/cracklib/NEWS b/cracklib/NEWS index 436ac46..8441182 100644 --- a/cracklib/NEWS +++ b/cracklib/NEWS @@ -12,6 +12,9 @@ v2.8.14 Added Assamese translation (Amitakhya Phukan) Updated Panjabi translation (A S Alam) optimize order of commands in util/cracklib-format (Jan Dittberner, Debian) fix several CC warnings (Jan Dittberner, Debian) + add a function GetDefaultCracklibDict() to libcrack + bump library revision + add python/setup.py.in to allow building eggs v2.8.13 Compressed dictionary support and better python module v2.8.11 Better create-cracklib-dict helper script (Mike Frysinger) v2.8.10 Patch for better hanlding of cracklist dictionary paths in python binding. (Nalin Dahyabhai) diff --git a/cracklib/configure.in b/cracklib/configure.in index 876d9ba..aaf8c89 100644 --- a/cracklib/configure.in +++ b/cracklib/configure.in @@ -91,5 +91,6 @@ dnl Handle local dict compiling properly AC_SUBST(CROSS_COMPILING, $cross_compiling) AC_OUTPUT(util/Makefile lib/Makefile doc/Makefile python/Makefile Makefile \ + python/setup.py \ po/Makefile.in m4/Makefile dicts/Makefile cracklib.spec) diff --git a/cracklib/lib/Makefile.am b/cracklib/lib/Makefile.am index 47ebb4f..2db4deb 100644 --- a/cracklib/lib/Makefile.am +++ b/cracklib/lib/Makefile.am @@ -14,7 +14,7 @@ libcrack_la_SOURCES = fascist.c \ # For next ABI changing release, use 3:0:0 # After that, follow the libtool recommended incrementing procedure # -libcrack_la_LDFLAGS = -version-info 10:0:8 +libcrack_la_LDFLAGS = -version-info 10:1:8 # Link in NLS libs. Needed by FreeBSD build libcrack_la_LIBADD = $(LTLIBINTL) diff --git a/cracklib/lib/crack.h b/cracklib/lib/crack.h index 4754b5a..b824a9c 100644 --- a/cracklib/lib/crack.h +++ b/cracklib/lib/crack.h @@ -15,6 +15,10 @@ extern "C" { extern const char *FascistCheck(const char *pw, const char *dictpath); +/* This function returns the compiled in value for DEFAULT_CRACKLIB_DICT. + */ +extern const char *GetDefaultCracklibDict(void); + #ifdef __cplusplus }; #endif diff --git a/cracklib/lib/fascist.c b/cracklib/lib/fascist.c index eaa3942..b4d62b3 100644 --- a/cracklib/lib/fascist.c +++ b/cracklib/lib/fascist.c @@ -876,3 +876,9 @@ FascistCheck(password, path) return res; } + +const char * +GetDefaultCracklibDict() +{ + return DEFAULT_CRACKLIB_DICT; +} diff --git a/cracklib/python/Makefile.am b/cracklib/python/Makefile.am index 92fffc0..1dbb4ab 100644 --- a/cracklib/python/Makefile.am +++ b/cracklib/python/Makefile.am @@ -1,6 +1,7 @@ if BUILD_PYTHON python_PYTHON = cracklib.py pyexec_LTLIBRARIES = _cracklibmodule.la +AM_CFLAGS = -I$(top_builddir)/lib _cracklibmodule_la_LDFLAGS = -module -avoid-version $(top_builddir)/lib/libcrack.la DEFS += '-DDEFAULT_CRACKLIB_DICT="$(DEFAULT_CRACKLIB_DICT)"' DEFS += '-DPYTHON_H="python@PYTHON_VERSION@/Python.h"' diff --git a/cracklib/python/_cracklibmodule.c b/cracklib/python/_cracklibmodule.c index 63c6cdf..cabd4f7 100644 --- a/cracklib/python/_cracklibmodule.c +++ b/cracklib/python/_cracklibmodule.c @@ -23,13 +23,15 @@ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include -#include +#ifdef PYTHON_H #include PYTHON_H +#else +#include +#endif #ifdef HAVE_PTHREAD_H #include #endif -#include "../lib/crack.h" +#include #ifdef HAVE_PTHREAD_H static pthread_mutex_t cracklib_mutex = PTHREAD_MUTEX_INITIALIZER; @@ -60,8 +62,7 @@ static char _cracklib_FascistCheck_doc [] = static PyObject * _cracklib_FascistCheck(PyObject *self, PyObject *args, PyObject *kwargs) { - int i; - char *candidate, *dict; + char *candidate, *dict, *defaultdict; const char *result; struct stat st; char *keywords[] = {"pw", "dictpath", NULL}; @@ -107,18 +108,38 @@ _cracklib_FascistCheck(PyObject *self, PyObject *args, PyObject *kwargs) free(dictfile); } else { - if (lstat(DEFAULT_CRACKLIB_DICT DICT_SUFFIX, &st) == -1) + defaultdict = strdup(GetDefaultCracklibDict()); + if (errno == ENOMEM) { + PyErr_SetFromErrno(PyExc_OSError); + return NULL; + } + dictfile = malloc(strlen(defaultdict) + sizeof(DICT_SUFFIX)); + if (dictfile == NULL) + { + PyErr_SetFromErrnoWithFilename(PyExc_OSError, defaultdict); + free(defaultdict); + return NULL; + } + sprintf(dictfile, "%s" DICT_SUFFIX, defaultdict); + if (lstat(dictfile, &st) == -1) { - PyErr_SetFromErrnoWithFilename(PyExc_OSError, - DEFAULT_CRACKLIB_DICT); + PyErr_SetFromErrnoWithFilename(PyExc_OSError, defaultdict); + free(defaultdict); + free(dictfile); return NULL; } + free(dictfile); } LOCK(); - result = FascistCheck(candidate, dict ? dict : DEFAULT_CRACKLIB_DICT); + result = FascistCheck(candidate, dict ? dict : defaultdict); UNLOCK(); + if (defaultdict != NULL) + { + free(defaultdict); + } + if (result != NULL) { PyErr_SetString(PyExc_ValueError, result); @@ -130,8 +151,8 @@ _cracklib_FascistCheck(PyObject *self, PyObject *args, PyObject *kwargs) static PyMethodDef _cracklibmethods[] = { - {"FascistCheck", _cracklib_FascistCheck, METH_VARARGS | METH_KEYWORDS, - _cracklib_FascistCheck_doc}, + {"FascistCheck", (PyCFunction) _cracklib_FascistCheck, + METH_VARARGS | METH_KEYWORDS, _cracklib_FascistCheck_doc}, {NULL, NULL}, }; diff --git a/cracklib/python/setup.py.in b/cracklib/python/setup.py.in new file mode 100644 index 0000000..a4980fd --- /dev/null +++ b/cracklib/python/setup.py.in @@ -0,0 +1,50 @@ +#!/usr/bin/python +# Copyright 2009 Jan Dittberner +# +# This file is part of cracklib. +# +# cracklib 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, or +# (at your option) any later version. +# +# cracklib 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 Prua; if not, write to the Free Software Foundation, +# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +import os, sys + +from setuptools import setup, Extension, find_packages + +extensions = [ + Extension("_cracklibmodule", + ["_cracklibmodule.c"], + libraries = ["crack"]), +] + +setup( + name="cracklib", + version="@VERSION@", + description="A CPython extension module wrapping the libcrack library", + author="Jan Dittberner", + author_email="jan@dittberner.info", + url="http://cracklib.sourceforge.net/", + license="GPLv2+", + py_modules=['cracklib'], + ext_modules=extensions, + zip_safe=False, + classifiers=[ + "Development Status :: 4 - Beta", + "Intended Audience :: Developers", + "License :: OSI Approved :: GNU General Public License (GPL)", + "Programming Language :: Python", + "Topic :: Security", + "Topic :: Software Development :: Libraries :: Python Modules", + "Topic :: Systems :: Systems Administration", + ], +)