# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0

name                chntpw

version             140201
revision            0
categories          sysutils
maintainers         nomaintainer
license             GPL-2+

description         Offline Windows NT password utility
long_description    chntpw is a utility to clear the password of any user that \
                    has a valid local account on a Windows system. reged is a \
                    utility for interactive edits, exports, and imports of \
                    Windows registry files. This package also contains the \
                    sampasswd, samunlock, and samusrgrp utilities for working \
                    with Windows SAM user databases.

homepage            https://pogostick.net/~pnh/ntpasswd/
master_sites        ${homepage}
distfiles           ${name}-source-${version}.zip

checksums           rmd160  3932e7184c20d9398d99b4864697307909395f20 \
                    sha256  96e20905443e24cba2f21e51162df71dd993a1c02bfa12b1be2d0801a4ee2ccc \
                    size    1404098

use_zip             yes

# chntpw has not been updated since 2014. These Debian patches maintain the
# package, fixing several bugs and other correctness problems. They come from
# https://sources.debian.org/patches/chntpw/140201-1/
# (https://sources.debian.org/data/main/c/chntpw/140201-1/debian/patches/). Of
# the patches there, 02_upstream_documents, 03_keyname-overflow, and
# 05_control_empty_values do not apply, are not listed in the series file, and
# are absent here. 01_port_to_gcrypt.patch has also been excluded: it adds
# libgcrypt as a cryptographic library as an alternative to OpenSSL, but the
# package is not built with any crypto enabled (here or in Debian) because its
# cryptographic features for changing (as opposed to clearing) passwords do not
# work properly with modern versions of Windows, and so the patch provides no
# benefit.
#
# patch-Makefile.diff and patch-warnings_64bit.diff are specific to MacPorts.
patchfiles          patch-debian-04_get_abs_path.diff \
                    patch-debian-06_correct_test_open_syscall.diff \
                    patch-debian-07_detect_failure_to_write_key.diff \
                    patch-debian-08_no_deref_null.diff \
                    patch-debian-09_improve_robustness.diff \
                    patch-debian-10_remove_static.diff \
                    patch-debian-11_improve_documentation.diff \
                    patch-debian-12_readonly_filesystem.diff \
                    patch-debian-13_write_to_hive.diff \
                    patch-debian-14_improve_description.diff \
                    patch-debian-15_added_samunlock_binary.diff \
                    patch-Makefile.diff \
                    patch-warnings_64bit.diff
patch.pre_args-replace  -p0 -p1

use_configure       no

build.args          CC="${configure.cc}" \
                    CFLAGS="${configure.cflags} [get_canonical_archflags cc]" \
                    LIBS=

destroot.args       PREFIX=${prefix}

post-destroot {
    # man pages are from Debian,
    # https://sources.debian.org/src/chntpw/140201-1/debian/
    # (https://sources.debian.org/data/main/c/chntpw/140201-1/debian/).
    file mkdir ${destroot}${prefix}/share/man/man8
    file copy {*}[glob ${filespath}/*.8] ${destroot}${prefix}/share/man/man8
}
