##
##  cracklib.spec -- OpenPKG RPM Package Specification
##  Copyright (c) 2000-2025 OpenPKG Project <http://openpkg.org/>
##
##  Permission to use, copy, modify, and distribute this software for
##  any purpose with or without fee is hereby granted, provided that
##  the above copyright notice and this permission notice appear in all
##  copies.
##
##  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
##  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
##  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
##  IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
##  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
##  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
##  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
##  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
##  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
##  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
##  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
##  SUCH DAMAGE.
##

#   package information
Name:         cracklib
Summary:      Filter Guessable Passwords
URL:          http://cracklib.sourceforge.net/
Vendor:       Alec Muffett et al.
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        PLUS
Group:        Security
License:      Artistic
Version:      2.9.5
Release:      20160228

#   list of sources
Source0:      http://download.sourceforge.net/cracklib/cracklib-%{version}.tar.gz
Source1:      http://download.sourceforge.net/cracklib/cracklib-words.gz
Source2:      ftp://ftp.cerias.purdue.edu/pub/dict/wordlists/computer/common-passwords.txt.gz
Source3:      ftp://ftp.cerias.purdue.edu/pub/dict/wordlists/computer/Jargon.gz
Source4:      http://www.freebsd.org/cgi/cvsweb.cgi/~checkout~/src/share/dict/web2
Source5:      http://www.freebsd.org/cgi/cvsweb.cgi/~checkout~/src/share/dict/web2a
Source6:      http://www.freebsd.org/cgi/cvsweb.cgi/~checkout~/src/share/dict/propernames
Source7:      Makefile

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, make
PreReq:       OpenPKG, openpkg >= 20160101, make

%description
    CrackLib is a library which may be used in a "passwd"-like program.
    The idea is simple: try to prevent users from choosing passwords
    that could be guessed by "Crack" by filtering them out, at source.

%track
    prog cracklib = {
        version   = %{version}
        url       = http://sourceforge.net/projects/cracklib/files/
        regex     = cracklib-(__VER__)\.tar\.gz
    }

%prep
    %setup -q

%build
    #   configure library
    CC="%{l_cc}" \
    CFLAGS="%{l_cflags -O}" \
    ./configure \
        --prefix=%{l_prefix} \
        --with-default-dict=%{l_prefix}/lib/cracklib/pw_dict \
        --without-python \
        --disable-shared \
        --disable-nls

    #   build library
    %{l_make} %{l_mflags}

%install
    #   install library
    %{l_make} %{l_mflags} install DESTDIR=$RPM_BUILD_ROOT

    #   strip down installation files
    rm -f $RPM_BUILD_ROOT%{l_prefix}/sbin/create-cracklib-dict
    rm -f $RPM_BUILD_ROOT%{l_prefix}/share/cracklib/cracklib.magic

    #   install dictionaries
    mv  $RPM_BUILD_ROOT%{l_prefix}/share/cracklib/cracklib-small \
        $RPM_BUILD_ROOT%{l_prefix}/share/cracklib/cracklib-small.txt
    %{l_gzip} -d -c %{SOURCE cracklib-words.gz} \
        >$RPM_BUILD_ROOT%{l_prefix}/share/cracklib/cracklib-large.txt
    %{l_gzip} -d -c %{SOURCE common-passwords.txt.gz} \
        >$RPM_BUILD_ROOT%{l_prefix}/share/cracklib/common-passwords.txt
    %{l_gzip} -d -c %{SOURCE Jargon.gz} \
        >$RPM_BUILD_ROOT%{l_prefix}/share/cracklib/jargon-words.txt
    cp %{SOURCE web2} \
        $RPM_BUILD_ROOT%{l_prefix}/share/cracklib/freebsd-web2.txt
    cp %{SOURCE web2a} \
        $RPM_BUILD_ROOT%{l_prefix}/share/cracklib/freebsd-web2a.txt
    cp %{SOURCE propernames} \
        $RPM_BUILD_ROOT%{l_prefix}/share/cracklib/freebsd-propernames.txt

    #   install dictionary generation stuff
    %{l_shtool} install -c -m 644 %{l_value -s -a} \
        %{SOURCE Makefile} $RPM_BUILD_ROOT%{l_prefix}/share/cracklib/
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/lib/cracklib

    #   determine installation files
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT %{l_files_std}

%files -f files

%clean

%post
    #   (re-)generate run-time password dictionary
    ( echo "(Re-)Generating run-time password dictionary"
    ) | %{l_rpmtool} msg -b -t warn
    ( cd $RPM_INSTALL_PREFIX/share/cracklib && \
      $RPM_INSTALL_PREFIX/bin/make
    ) >/dev/null 2>&1

%preun
    if [ $1 -eq 0 ]; then
        rm -f $RPM_INSTALL_PREFIX/share/cracklib/* >/dev/null 2>&1 || true
    fi

