From edb4c48d8a9d58135c46542bdf4798c3f7765acc Mon Sep 17 00:00:00 2001 From: sthen Date: Sun, 4 Dec 2022 18:18:24 +0000 Subject: [PATCH] nmap: port ndiff to python 3 (via 2to3 plus a few extra patches) and reenable it --- net/nmap/Makefile | 13 ++++++---- net/nmap/patches/patch-configure_ac | 18 ++++++-------- net/nmap/patches/patch-ndiff_ndiff_py | 36 +++++++++++++++++++++++++++ net/nmap/patches/patch-ndiff_setup_py | 12 +++++++++ net/nmap/pkg/PLIST-main | 8 ++++++ 5 files changed, 72 insertions(+), 15 deletions(-) create mode 100644 net/nmap/patches/patch-ndiff_ndiff_py create mode 100644 net/nmap/patches/patch-ndiff_setup_py diff --git a/net/nmap/Makefile b/net/nmap/Makefile index ee1d3fa8ec1..b9510bb383e 100644 --- a/net/nmap/Makefile +++ b/net/nmap/Makefile @@ -1,8 +1,9 @@ COMMENT-main= scan ports and fingerprint stack of network hosts -DISTNAME= nmap-7.91 +MODPY_EGG_VERSION= 7.91 +DISTNAME= nmap-${MODPY_EGG_VERSION} PKGNAME-main= ${DISTNAME} -REVISION= 3 +REVISION= 4 CATEGORIES= net security MASTER_SITES= ${HOMEPAGE}/dist/ @@ -24,7 +25,8 @@ COMPILER= base-clang ports-gcc base-gcc USE_GMAKE= Yes MODLUA_SA= Yes MODLUA_VERSION= 5.3 -MODULES= lang/lua +MODULES= lang/python \ + lang/lua DEBUG_PACKAGES= ${BUILD_PACKAGES} CONFIGURE_STYLE=autoconf @@ -43,7 +45,6 @@ CONFIGURE_ARGS= --with-libpcap=included \ --with-libpcre=${LOCALBASE} \ --with-mandir=${LOCALBASE}/man \ --without-nmap-update \ - --without-ndiff \ --without-zenmap \ --disable-nls @@ -53,10 +54,12 @@ LIB_DEPENDS-main= ${MODLUA_LIB_DEPENDS} \ devel/pcre \ security/libssh2 -BUILD_DEPENDS= devel/bison +BUILD_DEPENDS= devel/bison post-extract: @cd ${WRKSRC} && rm -rf liblua/ libpcre/ + 2to3 --fix=all --no-diffs --nobackups --verbose --write \ + ${WRKSRC}/ndiff/*py ${WRKSRC}/ndiff/scripts/ndiff pre-configure: @cd ${WRKSRC}/nping ; env PATH=${PORTPATH} \ diff --git a/net/nmap/patches/patch-configure_ac b/net/nmap/patches/patch-configure_ac index e23c31798a2..9684e39072b 100644 --- a/net/nmap/patches/patch-configure_ac +++ b/net/nmap/patches/patch-configure_ac @@ -1,14 +1,12 @@ -Neuter Python 2 detection, nothing uses it - Index: configure.ac --- configure.ac.orig +++ configure.ac -@@ -230,8 +230,6 @@ AC_SEARCH_LIBS(gethostbyname, nsl) - dnl Check IPv6 raw sending flavor. - CHECK_IPV6_IPPROTO_RAW +@@ -241,7 +241,7 @@ NDIFFDIR=ndiff --m4_define_default([_AM_PYTHON_INTERPRETER_LIST],[python2 python2.7 python2.6 python2.5 python2.4 python]) --AM_PATH_PYTHON([2.4], [HAVE_PYTHON=true], [HAVE_PYTHON=false]) - HAVE_PYTHON2=false - if test $HAVE_PYTHON && test "x${PYTHON_VERSION%%.*}" = "x2"; then - HAVE_PYTHON2=true + # Do they want Ndiff? + AC_ARG_WITH(ndiff, AC_HELP_STRING([--without-ndiff], [Skip installation of the Ndiff utility]), [], [with_ndiff=check]) +-if $HAVE_PYTHON2 ; then : ; ++if $HAVE_PYTHON ; then : ; + else + if test "$with_ndiff" = "check" ; then + AC_MSG_WARN([Not building Ndiff because Python 2.x with x>=4 was not found]) diff --git a/net/nmap/patches/patch-ndiff_ndiff_py b/net/nmap/patches/patch-ndiff_ndiff_py new file mode 100644 index 00000000000..686b311234c --- /dev/null +++ b/net/nmap/patches/patch-ndiff_ndiff_py @@ -0,0 +1,36 @@ +Index: ndiff/ndiff.py +--- ndiff/ndiff.py.orig ++++ ndiff/ndiff.py +@@ -32,6 +32,8 @@ verbose = False + + NDIFF_XML_VERSION = "1" + ++def cmp(x, y): ++ return (x > y) - (x < y) + + class OverrideEntityResolver(xml.sax.handler.EntityResolver): + """This class overrides the default behavior of xml.sax to download +@@ -160,11 +162,11 @@ class Host(object): + return state is None or state in self.extraports + + def extraports_string(self): +- list = [(count, state) for (state, count) in list(self.extraports.items())] ++ mylist = [(count, state) for (state, count) in list(self.extraports.items())] + # Reverse-sort by count. +- list.sort(reverse=True) ++ mylist.sort(reverse=True) + return ", ".join( +- ["%d %s ports" % (count, state) for (count, state) in list]) ++ ["%d %s ports" % (count, state) for (count, state) in mylist]) + + def state_to_dom_fragment(self, document): + frag = document.createDocumentFragment() +@@ -183,7 +185,7 @@ class Host(object): + + def extraports_to_dom_fragment(self, document): + frag = document.createDocumentFragment() +- for state, count in list(self.extraports.items()): ++ for state, count in mylist(self.extraports.items()): + elem = document.createElement("extraports") + elem.setAttribute("state", state) + elem.setAttribute("count", str(count)) diff --git a/net/nmap/patches/patch-ndiff_setup_py b/net/nmap/patches/patch-ndiff_setup_py new file mode 100644 index 00000000000..44ba64fe622 --- /dev/null +++ b/net/nmap/patches/patch-ndiff_setup_py @@ -0,0 +1,12 @@ +Index: ndiff/setup.py +--- ndiff/setup.py.orig ++++ ndiff/setup.py +@@ -306,7 +306,7 @@ class my_uninstall(distutils.cmd.Command): + + distutils.core.setup(name="ndiff", scripts=["scripts/ndiff"], + py_modules=["ndiff"], +- data_files=[("share/man/man1", ["docs/ndiff.1"])], ++ data_files=[("man/man1", ["docs/ndiff.1"])], + cmdclass={ + "install_egg_info": null_command, + "install": checked_install, diff --git a/net/nmap/pkg/PLIST-main b/net/nmap/pkg/PLIST-main index 634a29599ba..2a3bd6543e3 100644 --- a/net/nmap/pkg/PLIST-main +++ b/net/nmap/pkg/PLIST-main @@ -3,9 +3,17 @@ @pkgpath net/nmap @pkgpath net/nmap,no_x11 @bin bin/ncat +bin/ndiff @bin bin/nmap @bin bin/nping +@comment bin/uninstall_ndiff +lib/python${MODPY_VERSION}/ +lib/python${MODPY_VERSION}/site-packages/ +${MODPY_COMMENT}lib/python${MODPY_VERSION}/site-packages/${MODPY_PYCACHE}/ +lib/python${MODPY_VERSION}/site-packages/${MODPY_PYCACHE}ndiff.${MODPY_PYC_MAGIC_TAG}pyc +lib/python${MODPY_VERSION}/site-packages/ndiff.py @man man/man1/ncat.1 +@man man/man1/ndiff.1 @man man/man1/nmap.1 @man man/man1/nping.1 @comment share/applications/