[Pkg-cracklib-commits] r30 - in cracklib2/trunk/debian: . patches

jandd-guest at alioth.debian.org jandd-guest at alioth.debian.org
Sun Jul 13 14:18:35 UTC 2008


Author: jandd-guest
Date: 2008-07-13 14:18:34 +0000 (Sun, 13 Jul 2008)
New Revision: 30

Added:
   cracklib2/trunk/debian/patches/04-improved-python-binding.patch
Modified:
   cracklib2/trunk/debian/changelog
   cracklib2/trunk/debian/control
   cracklib2/trunk/debian/patches/series
   cracklib2/trunk/debian/rules
   cracklib2/trunk/debian/update-cracklib
Log:
- improved Python binding (based on python-crack by Domenico Andreoli)
- fix for #380546


Modified: cracklib2/trunk/debian/changelog
===================================================================
--- cracklib2/trunk/debian/changelog	2008-07-10 19:30:38 UTC (rev 29)
+++ cracklib2/trunk/debian/changelog	2008-07-13 14:18:34 UTC (rev 30)
@@ -1,3 +1,17 @@
+cracklib2 (2.8.12-2) UNRELEASED; urgency=low
+
+  * debian/patches/04-improved-python-binding.patch patches upstream
+    python bindings to provide the functionallity and documentation
+    strings python-crack had (upstream will apply this patch in the
+    future)
+  * add libtool, autoconf, and automake to build dependencies in
+    debian/control
+  * debian/rules uses autogen.sh
+  * only update cracklib dictionary if any of the source dictionaries has
+    changed (Closes: #380546)
+
+ -- Jan Dittberner <jan at dittberner.info>  Thu, 10 Jul 2008 21:50:35 +0200
+
 cracklib2 (2.8.12-1) unstable; urgency=low
 
   * switch to new upstream branch (Closes: #355692)

Modified: cracklib2/trunk/debian/control
===================================================================
--- cracklib2/trunk/debian/control	2008-07-10 19:30:38 UTC (rev 29)
+++ cracklib2/trunk/debian/control	2008-07-13 14:18:34 UTC (rev 30)
@@ -5,7 +5,8 @@
 Uploaders: Martin Pitt <mpitt at debian.org>
 Standards-Version: 3.8.0
 Build-Depends: debhelper (>= 4.0.0), python-central (>= 0.6.7),
- python-all-dev, python-all, chrpath, xmlto, quilt(>= 0.4)
+ python-all-dev, python-all, chrpath, xmlto, quilt(>= 0.4), automake
+ (>= 1.10.1), autoconf (>= 2.61), libtool
 Homepage: http://sourceforge.net/projects/cracklib
 XS-Python-Version: all
 Vcs-Svn: svn://svn.debian.org/pkg-cracklib/cracklib2/trunk

Added: cracklib2/trunk/debian/patches/04-improved-python-binding.patch
===================================================================
--- cracklib2/trunk/debian/patches/04-improved-python-binding.patch	                        (rev 0)
+++ cracklib2/trunk/debian/patches/04-improved-python-binding.patch	2008-07-13 14:18:34 UTC (rev 30)
@@ -0,0 +1,478 @@
+--- a/python/Makefile.am
++++ b/python/Makefile.am
+@@ -1,6 +1,7 @@
+ if BUILD_PYTHON
+-pyexec_LTLIBRARIES = cracklibmodule.la
+-cracklibmodule_la_LDFLAGS = -module -avoid-version -L$(top_builddir)/lib -lcrack
++python_PYTHON = cracklib.py
++pyexec_LTLIBRARIES = _cracklibmodule.la
++_cracklibmodule_la_LDFLAGS = -module -avoid-version -L$(top_builddir)/lib -lcrack
+ DEFS += '-DDEFAULT_CRACKLIB_DICT="$(DEFAULT_CRACKLIB_DICT)"'
+ DEFS += '-DPYTHON_H="python at PYTHON_VERSION@/Python.h"'
+ endif
+--- /dev/null
++++ b/python/_cracklibmodule.c
+@@ -0,0 +1,149 @@
++/*
++ * A Python binding for cracklib.
++ *
++ * Parts of this code are based on work Copyright (c) 2003 by Domenico
++ * Andreoli.
++ *
++ * Copyright (c) 2008 Jan Dittberner <jan at dittberner.info>
++ *
++ * 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
++ */
++
++#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
++
++#define DICT_SUFFIX ".pwd"
++
++static char _cracklib_FascistCheck_doc [] =
++	"arguments: passwd, dictpath (optional)\n"
++	"\n"
++	"  passwd - password to be checked for weakness\n"
++	"  dictpath - full path name to the cracklib dictionary database\n"
++	"\n"
++	"if dictpath is not specified the default dictionary database\n"
++	"will be used.\n"
++	"\n"
++	"return value: the same password passed as first argument.\n"
++	"\n"
++	"if password is weak, exception ValueError is raised with argument\n"
++	"set to the reason of weakness.\n"
++;
++
++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};
++    char *dictfile;
++
++    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;
++        }
++        dictfile = malloc(strlen(dict) + sizeof(DICT_SUFFIX));
++        if (dictfile == NULL)
++        {
++            PyErr_SetFromErrnoWithFilename(PyExc_OSError, dict);
++            return NULL;
++        }
++        sprintf(dictfile, "%s" DICT_SUFFIX, dict);
++        if (lstat(dictfile, &st) == -1)
++        {
++            PyErr_SetFromErrnoWithFilename(PyExc_OSError, dict);
++            free(dictfile);
++            return NULL;
++        }
++        free(dictfile);
++    } else
++    {
++        if (lstat(DEFAULT_CRACKLIB_DICT DICT_SUFFIX, &st) == -1)
++        {
++            PyErr_SetFromErrnoWithFilename(PyExc_OSError,
++                                           DEFAULT_CRACKLIB_DICT);
++            return NULL;
++        }
++    }
++
++    LOCK();
++    result = FascistCheck(candidate, dict ? dict : DEFAULT_CRACKLIB_DICT);
++    UNLOCK();
++
++    if (result != NULL)
++    {
++    	PyErr_SetString(PyExc_ValueError, result);
++        return NULL;
++    }
++    return Py_BuildValue("s", candidate);
++}
++
++static PyMethodDef
++_cracklibmethods[] =
++{
++    {"FascistCheck", _cracklib_FascistCheck, METH_VARARGS | METH_KEYWORDS,
++     _cracklib_FascistCheck_doc},
++    {NULL, NULL},
++};
++
++static char _cracklib_doc[] =
++    "Python bindings for cracklib.\n"
++    "\n"
++    "This module enables the use of cracklib features from within a Python\n"
++    "program or interpreter.\n"
++;
++
++void
++init_cracklib(void)
++{
++    Py_InitModule3("_cracklib", _cracklibmethods, _cracklib_doc);
++}
+--- a/python/cracklibmodule.c
++++ /dev/null
+@@ -1,107 +0,0 @@
+-/*
+- *  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
+-
+-#define DICT_SUFFIX ".pwd"
+-
+-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};
+-    char *dictfile;
+-
+-    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;
+-        }
+-        dictfile = malloc(strlen(dict) + sizeof(DICT_SUFFIX));
+-        if (dictfile == NULL)
+-        {
+-            PyErr_SetFromErrnoWithFilename(PyExc_OSError, dict);
+-            return NULL;
+-        }
+-        sprintf(dictfile, "%s" DICT_SUFFIX, dict);
+-        if (lstat(dictfile, &st) == -1)
+-        {
+-            PyErr_SetFromErrnoWithFilename(PyExc_OSError, dict);
+-            free(dictfile);
+-            return NULL;
+-        }
+-        free(dictfile);
+-    } else
+-    {
+-        if (lstat(DEFAULT_CRACKLIB_DICT DICT_SUFFIX, &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);
+-}
+--- /dev/null
++++ b/python/cracklib.py
+@@ -0,0 +1,201 @@
++#
++# A Python binding for cracklib.
++#
++# Parts of this code are based on work Copyright (c) 2003 by Domenico
++# Andreoli.
++#
++# Copyright (c) 2008 Jan Dittberner <jan at dittberner.info>
++#
++# 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 string
++from _cracklib import FascistCheck
++
++ascii_uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
++ascii_lowercase = "abcdefghijklmnopqrstuvwxyz"
++
++diff_ok = 5
++min_length = 9
++dig_credit = 1
++up_credit = 1
++low_credit = 1
++oth_credit = 1
++
++
++def palindrome(s):
++    for i in range(len(s)):
++        if s[i] != s[-i - 1]:
++            return 0
++    return 1
++
++
++def distdifferent(old, new, i, j):
++    """Calculate how different two strings are in terms of the number
++    of character removals, additions, and changes needed to go from one
++    to the other."""
++    if i == 0 or len(old) <= i:
++        c = 0
++    else:
++        c = old[i - 1]
++    
++    if j == 0 or len(new) <= i:
++        d = 0
++    else:
++        d = new[j - 1]
++    
++    return c != d
++
++
++def distcalculate(distances, old, new, i, j):
++    tmp = 0
++    
++    if distances[i][j] != -1:
++        return distances[i][j]
++
++    tmp =          distcalculate(distances, old, new, i - 1, j - 1)
++    tmp = min(tmp, distcalculate(distances, old, new, i    , j - 1))
++    tmp = min(tmp, distcalculate(distances, old, new, i - 1, j    ))
++    tmp = tmp + distdifferent(old, new, i, j)
++
++    distances[i][j] = tmp
++
++    return tmp
++
++
++def distance(old, new):
++    m = len(old)
++    n = len(new)
++
++    distances = [ [] for i in range(m + 1) ]
++    for i in range(m + 1):
++        distances[i] = [ -1 for j in range(n + 1) ]
++ 
++    for i in range(m + 1):
++        distances[i][0] = i
++    for j in range(n + 1):
++        distances[0][j] = j
++    distances[0][0] = 0
++
++    r = distcalculate(distances, old, new, m, n)
++
++    for i in range(len(distances)):
++        for j in range(len(distances[i])):
++            distances[i][j] = 0
++
++    return r
++
++
++def similar(old, new):
++    if distance(old, new) >= diff_ok:
++        return 0
++    
++    if len(new) >= (len(old) * 2):
++        return 0
++
++    # passwords are too similar
++    return 1
++
++
++def simple(new):
++    digits = 0
++    uppers = 0
++    lowers = 0
++    others = 0
++
++    for c in new:
++        if c in string.digits:
++            digits = digits + 1
++        elif c in ascii_uppercase:
++            uppers = uppers + 1
++        elif c in ascii_lowercase:
++            lowers = lowers + 1
++        else:
++            others = others + 1
++
++    # The scam was this - a password of only one character type
++    # must be 8 letters long.  Two types, 7, and so on.
++    # This is now changed, the base size and the credits or defaults
++    # see the docs on the module for info on these parameters, the
++    # defaults cause the effect to be the same as before the change
++
++    if dig_credit >= 0 and digits > dig_credit:
++        digits = dig_credit
++
++    if up_credit >= 0 and uppers > up_credit:
++        uppers = up_credit
++
++    if low_credit >= 0 and lowers > low_credit:
++        lowers = low_credit
++
++    if oth_credit >= 0 and others > oth_credit:
++        others = oth_credit
++
++    size = min_length
++
++    if dig_credit >= 0:
++        size = size - digits
++    elif digits < (dig_credit * -1):
++        return 1
++ 
++    if up_credit >= 0:
++        size = size - uppers
++    elif uppers < (up_credit * -1):
++        return 1
++ 
++    if low_credit >= 0:
++        size = size - lowers
++    elif lowers < (low_credit * -1):
++        return 1
++
++    if oth_credit >= 0:
++        size = size - others
++    elif others < (oth_credit * -1):
++        return 1
++
++    if len(new) < size:
++        return 1
++        
++    return 0
++
++
++def VeryFascistCheck(new, old = None, dictpath = None):
++    if dictpath == None:
++        dictpath = default_dictpath
++
++    if old != None:
++        if new == old:
++            raise ValueError, "is the same as the old one"
++                
++        oldmono = old.lower()
++        newmono = new.lower()
++        wrapped = old + old
++
++        if newmono == oldmono:
++            raise ValueError, "case changes only"
++        if wrapped.find(new) != -1:
++            raise ValueError, "is rotated"
++        if similar(oldmono, newmono):
++            raise ValueError, "is too similar to the old one"
++        
++    FascistCheck(new, dictpath)
++
++    if palindrome(new):
++        raise ValueError, "is a palindrome"
++    if simple(new):
++        raise ValueError, "is too simple"
++
++    return new


Property changes on: cracklib2/trunk/debian/patches/04-improved-python-binding.patch
___________________________________________________________________
Name: svn:mergeinfo
   + 

Modified: cracklib2/trunk/debian/patches/series
===================================================================
--- cracklib2/trunk/debian/patches/series	2008-07-10 19:30:38 UTC (rev 29)
+++ cracklib2/trunk/debian/patches/series	2008-07-13 14:18:34 UTC (rev 30)
@@ -1,3 +1,4 @@
 01-cracklib-format-optim.patch
 02-ccwarnings.patch
 03-packer-dont-print-skipping-line.patch
+04-improved-python-binding.patch

Modified: cracklib2/trunk/debian/rules
===================================================================
--- cracklib2/trunk/debian/rules	2008-07-10 19:30:38 UTC (rev 29)
+++ cracklib2/trunk/debian/rules	2008-07-13 14:18:34 UTC (rev 30)
@@ -14,6 +14,7 @@
 
 configure-stamp: configure patch
 	dh_testdir
+	./autogen.sh
 	mkdir -p debian/tmpbuild
 	cd debian/tmpbuild; \
 	../../configure --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) --prefix=/usr --disable-rpath --without-python --with-default-dict=/var/cache/cracklib/cracklib_dict
@@ -66,7 +67,8 @@
 	 debian/tmp/usr/sbin/cracklib-unpacker
 	touch debian/python-cracklib.install
 	for i in $(PYVERS); do \
-		echo "debian/tmp/usr/lib/python$$i/site-packages/cracklibmodule.so usr/lib/python$$i/site-packages" >> debian/python-cracklib.install; \
+		echo "debian/tmp/usr/lib/python$$i/site-packages/_cracklibmodule.so usr/lib/python$$i/site-packages" >> debian/python-cracklib.install; \
+		echo "debian/tmp/usr/lib/python$$i/site-packages/cracklib.py usr/lib/python$$i/site-packages" >> debian/python-cracklib.install; \
 	done
 	dh_install
 

Modified: cracklib2/trunk/debian/update-cracklib
===================================================================
--- cracklib2/trunk/debian/update-cracklib	2008-07-10 19:30:38 UTC (rev 29)
+++ cracklib2/trunk/debian/update-cracklib	2008-07-13 14:18:34 UTC (rev 30)
@@ -22,8 +22,15 @@
 
 if [ -n "${cracklib_dictpath_src}"  -a  -n "${cracklib_dictpath}" ]
 then
-    /usr/sbin/cracklib-format ${cracklib_dictpath_src} | \
-    /usr/sbin/cracklib-packer
+    for i in ${cracklib_dictpath_src}
+    do
+        if [ "$i" -nt "${cracklib_dictpath}.pwd" ]
+        then
+            /usr/sbin/cracklib-format ${cracklib_dictpath_src} | \
+            /usr/sbin/cracklib-packer
+            exit 0
+        fi
+    done
 fi
 
 exit 0




More information about the Pkg-cracklib-commits mailing list