##
##  drac.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:         drac
Summary:      Dynamic Relay Authorization Control (DRAC)
URL:          http://mail.cc.umanitoba.ca/drac/
Vendor:       University of Manitoba
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        Mail
License:      BSD
Version:      1.12
Release:      20120521

#   package options
%option       with_fsl     yes

#   list of sources
Source0:      http://download.openpkg.org/components/versioned/drac/drac-%{version}.tar.Z
Source1:      rc.drac
Source2:      fsl.drac
Source3:      drac.h

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, gcc
PreReq:       OpenPKG, openpkg >= 20160101
%if "%{with_fsl}" == "yes"
BuildPreReq:  fsl
PreReq:       fsl
%endif
BuildPreReq:  db >= 4.2
PreReq:       db >= 4.2

%description
    DRAC is a daemon that dynamically updates a relay authorization
    map for Sendmail, Postfix and other MTA's that supports it. It
    provides a way to allow legitimate users to relay mail through an
    SMTP server, while still preventing others from using it as a spam
    relay. User's IP addresses are added to the map immediately after
    they have authenticated to the POP or IMAP server. By default, map
    entries expire after 30 minutes, but can be renewed by additional
    authentication. Periodically checking mail on a POP server is
    sufficient to do this. The POP and SMTP servers can be on different
    hosts.

%track
    prog drac = {
        version   = %{version}
        url       = http://download.openpkg.org/components/versioned/drac/
        regex     = drac-(__VER__)\.tar\.Z
    }

%prep
    %setup -q -c

%build
    #   determine platform dependent flags
    cppflags="%{l_cppflags}"
    ldflags="%{l_ldflags} -ldb"
    ldflags_tst="-L. -ldrac"
    case "%{l_platform -t}" in
        *-sunos5.10* )
            cppflags="$cppflags -DTI_RPC -DFCNTL_LOCK -DSYSINFO"
            ldflags="$ldflags -lnsl -lrt"
            ldflags_tst="$ldflags_tst -lnsl -lsocket"
            ;;
        *-sunos5.[6-9]* )
            cppflags="$cppflags -DTI_RPC -DFCNTL_LOCK -DSYSINFO"
            ldflags="$ldflags -lnsl"
            ldflags_tst="$ldflags_tst -lnsl"
            ;;
        *-freebsd[4-9]* | *-linux[23].* | *-netbsd1* )
            cppflags="$cppflags -DSOCK_RPC -DFLOCK_LOCK -DGETHOST -DDASH_C"
            ;;
        *-irix6* )
            cppflags="$cppflags -DTI_RPC -DFCNTL_LOCK -DSYSINFO -D_SVR4_TIRPC"
            ldflags="$ldflags -lnsl"
            ldflags_tst="$ldflags_tst -lnsl"
            ;;
    esac

    #   configure build environment
    %{l_shtool} subst \
        -e "s;^\(DEFS =\).*\$;\1 $cppflags;" \
        -e "s;^\(LDLIBS =\).*\$;\1 %{l_fsl_libs} $ldflags;" \
        -e "s;^\(TSTLIBS =\).*\$;\1 $ldflags_tst;" \
        -e 's;^\(CC =\).*$;\1 %{l_cc};' \
        -e 's;^\(RANLIB =\).*$;\1 ranlib;' \
        -e 's;^\(CFLAGS =\).*$;\1 \$(DEFS);' \
        -e 's;^\(RPCGENFLAGS =\).*$;\1 -Y %{l_prefix}/bin;' \
        Makefile

    #   configure paths in source
    %{l_shtool} subst \
        -e "s;/etc/mail;%{l_prefix}/etc/drac;g" \
        rpc.dracd.c

    #   build program and library
    %{l_make} %{l_mflags}

%install
    #   create installation area
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/etc/drac \
        $RPM_BUILD_ROOT%{l_prefix}/var/drac \
        $RPM_BUILD_ROOT%{l_prefix}/sbin \
        $RPM_BUILD_ROOT%{l_prefix}/lib \
        $RPM_BUILD_ROOT%{l_prefix}/include \
        $RPM_BUILD_ROOT%{l_prefix}/man/man8 \
        $RPM_BUILD_ROOT%{l_prefix}/man/man3

    #   install program
    %{l_shtool} install -c -s -m 755 \
        rpc.dracd $RPM_BUILD_ROOT%{l_prefix}/sbin/dracd
    %{l_shtool} install -c -m 644 \
        rpc.dracd.1m $RPM_BUILD_ROOT%{l_prefix}/man/man8/dracd.8

    #   install library
    %{l_shtool} install -c -m 644 \
        %{SOURCE drac.h} $RPM_BUILD_ROOT%{l_prefix}/include/
    %{l_shtool} install -c -m 644 \
        libdrac.a $RPM_BUILD_ROOT%{l_prefix}/lib/
    %{l_shtool} install -c -m 644 \
        dracauth.3 $RPM_BUILD_ROOT%{l_prefix}/man/man3/

    #   install empty database
    %{l_shtool} install -c -m 644 \
        /dev/null $RPM_BUILD_ROOT%{l_prefix}/etc/drac/dracd.db

    #   install run-command script
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d
    %{l_shtool} install -c -m 755 %{l_value -s -a} \
        %{SOURCE rc.drac} $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d/

    #   install OSSP fsl configuration
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/etc/fsl
    %{l_shtool} install -c -m 644 %{l_value -s -a} \
        %{SOURCE fsl.drac} \
        $RPM_BUILD_ROOT%{l_prefix}/etc/fsl/

    #   determine installation files
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std} \
        '%config %{l_prefix}/etc/fsl/fsl.drac' \
        '%config %{l_prefix}/etc/drac/dracd.db'

%files -f files

%clean

