Subject: [bug#32268] [PATCH] gnu: Add net-snmp.

From: Marius Bakke <[email-masked]>
Date: Mon, 30 Jul 2018 00:03:50 +0200

Oleg Pykhalov <[email-masked]> writes:

> * gnu/packages/networking.scm (net-snmp): New variable.

Hello!  This patch reminded me I had an ancient patch for Net-SNMP too,
but got stuck on a single test failure and forgot all about it.

I see you've disabled tests altogether which is a neat workaround.
However I'm hoping we can consolidate our efforts and just disable the
one (or was it two) tests that are failing.

Comments inline, my patch attached at the end.

> ---
>  gnu/packages/networking.scm | 76 +++++++++++++++++++++++++++++++++++++
>  1 file changed, 76 insertions(+)

I chose to add a (gnu packages snmp) module, but that may be overkill
indeed.

[...]

> +(define-public net-snmp
> +  (package
> +    (name "net-snmp")
> +    (version "5.7.3")
> +    (source
> +     (origin
> +       (method url-fetch)
> +       (uri (string-append "mirror://sourceforge/net-snmp/net-snmp/" version
> +                           "/net-snmp-" version ".tar.gz"))
> +       (sha256
> +        (base32
> +         "1w5l9w0sgi1zkzq8ww6kc6fzq7ljq59z2d9ks6bdq1vp7ihqkvqj"))
> +       (patches
> +        (map (lambda (file hash)
> +               (origin
> +                 (method url-fetch)
> +                 (uri (string-append
> +                       "https://git.alpinelinux.org\
> +/cgit/aports/plain/main/net-snmp/"
> +                       file "?id=f25d3fb08341b60b6ccef424399f060dfcf3f1a5"))
> +                 (sha256
> +                  (base32
> +                   hash))))
> +             '("CVE-2015-5621.patch"
> +               "fix-Makefile-PL.patch"
> +               "fix-includes.patch"
> +               "netsnmp-swinst-crash.patch"
> +               "remove-U64-typedef.patch")
> +             '("0mg2mlfb45fnv7m1k9wckrqjfizipyvrl1q4dn1r0zc774mm7zjc"
> +               "1pd85sy04n76q1ri3l33f0zpnnw76nd5mcny2j39ilzp76bjfik5"
> +               "0zpkbb6k366qpq4dax5wknwprhwnhighcp402mlm7950d39zfa3m"
> +               "0gh164wy6zfiwiszh58fsvr25k0ns14r3099664qykgpmickkqid"
> +               "0jcpcpgx4z9k1w0x6km0132n67qc29mz6cialwfjm02l76q2yk5n")))))

Instead of adding all these patches, I opted to use the 5.8
pre-release instead.  No strong opinion, but since it's a new package
and 5.8 is "just around the corner" I think that's fine.  WDYT?

Also note that this packages bundles a copy of OpenSSL, which should be
purged.

> +    (build-system gnu-build-system)
> +    (native-inputs
> +     `(("autoconf" ,autoconf)
> +       ("automake" ,automake)
> +       ("libtool" ,libtool)))

Why are these needed?  Because of the patches?

> +    (inputs
> +     `(("file" ,file)
> +       ("perl" ,perl)
> +       ("openssl" ,openssl)))

"file" is an implicit input.  Can you add a comment about why it's
needed here (I guess it's referenced somewhere?)?

> +    (arguments
> +     `(#:tests? #f
> +       #:configure-flags
> +       (list "--with-default-snmp-version=3"
> +             "--with-sys-location=Unknown"
> +             "--with-sys-contact=root@unknown"
> +             "--with-logfile=/var/log/net-snmpd.log"
> +             "--with-persistent-directory=/var/lib/net-snmp"
> +             (string-append "--with-openssl="
> +                            (assoc-ref %build-inputs "openssl"))
> +             "--with-mnttab=/proc/mounts")
> +       #:make-flags
> +       (let ((out (assoc-ref %outputs "out")))
> +         (list (string-append "INSTALLSITEARCH=" out
> +                              "/lib/perl5/site_perl/" ,(package-version perl)
> +                              "/x86_64-linux-thread-multi")
> +               (string-append"INSTALLSITEMAN3DIR=" out "/share/man/man3")))
> +
> +       #:phases
> +       (modify-phases %standard-phases
> +         (add-before 'configure 'autoreconf
> +           (lambda _
> +             (invoke "autoreconf" "-vfi"))))))
> +    (home-page "http://net-snmp.sourceforge.net/")
> +    (synopsis "Clients and server for the SNMP network monitoring protocol")
> +    (description "The Simple Network Management Protocol (SNMP) provides a
> +framework for the exchange of management information between agents (servers)
> +and clients.
> +
> +The Net-SNMP applications are a collection of command line clients for issuing
> +SNMP requests to agents.")
> +    (license license:bsd-3)))

The main license is actually CMU/UCDs "Historic Permission Notice and
Disclaimer", which is not in Guix.  Do you think it's worth adding, or
should we simply use a non-copyleft style URI here?

My patch attached:

From ac4684bb69b0e14abef4b81006115a4077ca6d94 Mon Sep 17 00:00:00 2001
From: Marius Bakke <[email-masked]>
Date: Mon, 29 Jan 2018 17:06:24 +0100
Subject: [PATCH] gnu: Add net-snmp.

* gnu/packages/snmp.scm,
gnu/packages/patches/net-snmp-disable-network-tests.patch: New files.
* gnu/local.mk (GNU_SYSTEM_MODULES, dist_patch_DATA): Register it.
---
 gnu/local.mk                                  |   2 +
 .../net-snmp-disable-network-tests.patch      |  84 +++++++++++++++
 gnu/packages/snmp.scm                         | 101 ++++++++++++++++++
 3 files changed, 187 insertions(+)
 create mode 100644 gnu/packages/patches/net-snmp-disable-network-tests.patch
 create mode 100644 gnu/packages/snmp.scm

diff --git a/gnu/local.mk b/gnu/local.mk
index 80d6a8d4c..0a468578b 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -385,6 +385,7 @@ GNU_SYSTEM_MODULES =				\
   %D%/packages/slang.scm			\
   %D%/packages/smalltalk.scm			\
   %D%/packages/sml.scm				\
+  %D%/packages/snmp.scm				\
   %D%/packages/speech.scm			\
   %D%/packages/spice.scm			\
   %D%/packages/ssh.scm				\
@@ -920,6 +921,7 @@ dist_patch_DATA =						\
   %D%/packages/patches/mupen64plus-ui-console-notice.patch	\
   %D%/packages/patches/mutt-store-references.patch		\
   %D%/packages/patches/ncurses-CVE-2017-10684-10685.patch	\
+  %D%/packages/patches/net-snmp-disable-network-tests.patch	\
   %D%/packages/patches/net-tools-bitrot.patch			\
   %D%/packages/patches/netcdf-date-time.patch			\
   %D%/packages/patches/netcdf-tst_h_par.patch			\
diff --git a/gnu/packages/patches/net-snmp-disable-network-tests.patch b/gnu/packages/patches/net-snmp-disable-network-tests.patch
new file mode 100644
index 000000000..c1869a9b1
--- /dev/null
+++ b/gnu/packages/patches/net-snmp-disable-network-tests.patch
@@ -0,0 +1,84 @@
+Drop tests that require network access.
+
+--- a/testing/fulltests/default/T070com2sec_simple
++++ b/testing/fulltests/default/T070com2sec_simple
+@@ -80,12 +80,6 @@
+ # 407b Test maximally long host name/mask
+ CONFIGAGENT 'com2sec t407b a23456789012345678901234567890123456789012345678901234567890123.a23456789012345678901234567890123456789012345678901234567890123.a23456789012345678901234567890123456789012345678901234567890123.a234567890123456789012345678901234567890123456789012345678901./255.255.255.255 c407b'
+ 
+-# 408 Lookup tests, require network access
+-# 408a Test lookup returning a single host
+-CONFIGAGENT 'com2sec t408a onea.net-snmp.org c408a'
+-# 408a Test lookup returning multiple hosts
+-CONFIGAGENT 'com2sec t408b twoa.net-snmp.org c408b'
+-
+ # Default agent setup
+ CONFIGAGENT "[snmp] persistentdir $SNMP_TMP_PERSISTENTDIR"
+ # Dummy config to prevent the basic_setup warning
+@@ -134,26 +128,4 @@
+ SAVECHECKAGENT 'line 30: Error:' # msg from h_strerror so it varies
+ SAVECHECKAGENT 'line 31: Error:' # msg from h_strerror so it varies
+ 
+-CHECKAGENT '<"c408a"'
+-if [ "$snmp_last_test_result" -eq 0 ] ; then
+-  CHECKAGENT 'line 32: Error:'
+-  if [ "$snmp_last_test_result" -ne 1 ] ; then
+-    return_value=1
+-    FINISHED
+-  fi
+-elif [ "$snmp_last_test_result" -ne 1 ] ; then
+-  return_value=1
+-  FINISHED
+-fi
+-
+-CHECKAGENT '<"c408b"'
+-if [ "$snmp_last_test_result" -eq 0 ] ; then
+-  CHECKAGENT 'line 33: Error:'
+-  if [ "$snmp_last_test_result" -ne 1 ] ; then
+-    return_value=1
+-  fi
+-elif [ "$snmp_last_test_result" -ne 1 ] ; then
+-  return_value=1
+-fi
+-
+ FINISHED
+--- a/testing/fulltests/default/T071com2sec6_simple
++++ b/testing/fulltests/default/T071com2sec6_simple
+@@ -74,12 +74,6 @@
+ # 607b Test maximally long host name/mask
+ CONFIGAGENT 'com2sec6 t607b a23456789012345678901234567890123456789012345678901234567890123.a23456789012345678901234567890123456789012345678901234567890123.a23456789012345678901234567890123456789012345678901234567890123.a234567890123456789012345678901234567890123456789012345678901./ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff c607b'
+ 
+-# 608 Lookup tests, require network access
+-# 608a Test lookup returning a single host
+-CONFIGAGENT 'com2sec6 t608a oneAAAA.net-snmp.org c608a'
+-# 608b Test lookup returning multiple hosts
+-CONFIGAGENT 'com2sec6 t608b twoAAAA.net-snmp.org c608b'
+-
+ # Default agent setup
+ CONFIGAGENT "[snmp] persistentdir $SNMP_TMP_PERSISTENTDIR"
+ # Dummy config to prevent the basic_setup warning
+@@ -132,24 +126,4 @@
+ SAVECHECKAGENT 'line 27: Error:'
+ SAVECHECKAGENT 'line 28: Error:'
+ 
+-# 608
+-CHECKAGENT '<"c608a"'
+-if [ "$snmp_last_test_result" -eq 0 ] ; then
+-  CHECKAGENT 'line 29: Error:'
+-  errnum=`expr $errnum - 1`
+-  if [ "$snmp_last_test_result" -ne 1 ] ; then
+-    FINISHED
+-  fi
+-elif [ "$snmp_last_test_result" -ne 1 ] ; then
+-  FINISHED
+-fi
+-
+-CHECKAGENTCOUNT atleastone '<"c608b"'
+-if [ "$snmp_last_test_result" -eq 0 ] ; then
+-  CHECKAGENT 'line 30: Error:'
+-  if [ "$snmp_last_test_result" -eq 1 ] ; then
+-    errnum=`expr $errnum - 1`
+-  fi
+-fi
+-
+ FINISHED
diff --git a/gnu/packages/snmp.scm b/gnu/packages/snmp.scm
new file mode 100644
index 000000000..be79f5458
--- /dev/null
+++ b/gnu/packages/snmp.scm
@@ -0,0 +1,101 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2018 Marius Bakke <[email-masked]>
+;;;
+;;; This file is part of GNU Guix.
+;;;
+;;; GNU Guix 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 3 of the License, or (at
+;;; your option) any later version.
+;;;
+;;; GNU Guix 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 GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
+
+(define-module (gnu packages snmp)
+  #:use-module (gnu packages)
+  #:use-module (gnu packages compression)
+  #:use-module (gnu packages linux)
+  #:use-module (gnu packages perl)
+  #:use-module (gnu packages tls)
+  #:use-module (guix build-system gnu)
+  #:use-module (guix download)
+  #:use-module ((guix licenses) #:prefix license:)
+  #:use-module (guix packages)
+  #:use-module (guix utils))
+
+(define-public net-snmp
+  (package
+    (name "net-snmp")
+    (version "5.8.pre1")
+    (source (origin
+              (method url-fetch)
+              (uri (string-append "mirror://sourceforge/net-snmp/"
+                                  "5.8-pre-releases/net-snmp-" version
+                                  ".tar.gz"))
+              (sha256
+               (base32
+                "1f1rwq2cqz9ysapl96rsay240dbz8s6wsprms7skl2vacq94s2bd"))
+              (patches (search-patches "net-snmp-disable-network-tests.patch"))
+              (modules '((guix build utils)))
+              (snippet
+               '(begin
+                  ;; Drop bundled libraries.
+                  (delete-file-recursively "snmplib/openssl")
+                  #t))))
+    (build-system gnu-build-system)
+    (arguments
+     `(#:test-target "test"
+       ;; XXX: With parallel build enabled, Perl modules may not get linked with
+       ;; libnetsnmp.  See e.g. <https://bugzilla.novell.com/show_bug.cgi?id=819497>.
+       #:parallel-build? #f
+       #:make-flags (let ((out (assoc-ref %outputs "out")))
+                      (list (string-append "INSTALLSITEARCH=" out
+                                           "/lib/perl5/site_perl/"
+                                           ,(package-version perl))
+                            (string-append "INSTALLSITEMAN3DIR=" out
+                                           "/share/man/man3")
+                            ;; Make sure the Perl modules get a proper RUNPATH.
+                            ;(string-append "LDFLAGS=-Wl,-rpath=" out "/lib")
+                            ))
+       #:phases (modify-phases %standard-phases
+                  (add-before 'check 'patch-tests
+                    (lambda _
+                      (substitute* "testing/fulltests/support/simple_TESTCONF.sh"
+                        (("NETSTAT=\"\"") (string-append "NETSTAT="
+                                                         (which "netstat"))))
+                      (substitute* "testing/fulltests/default/T065agentextend_sh_simple"
+                        (("/bin/sh") (which "sh")))
+                      (substitute* '("testing/fulltests/default/T061agentperl_simple"
+                                     "testing/fulltests/default/T065agentextend_simple"
+                                     "testing/fulltests/default/T115agentxperl_simple")
+                        (("/usr/bin/env") (which "env")))
+
+                      ;; Note: to debug test failures, step into the failed build
+                      ;; directory, export OK_TO_SAVE_RESULT and run "make testfailed".
+                      #t)))))
+    (native-inputs
+     `(("net-tools" ,net-tools-for-tests)))
+    (inputs
+     `(("bzip2" ,bzip2)
+       ("libnl" ,libnl)
+       ("linux-libre-headers" ,linux-libre-headers)
+       ("openssl" ,openssl)
+       ("perl" ,perl)
+       ("zlib" ,zlib)))
+    (home-page "http://net-snmp.sourceforge.net/")
+    (synopsis "SNMP tools and libraries")
+    (description
+     "@dfn{SNMP} (Simple Network Management Protocol) is a widely used protocol
+for monitoring and managing servers and network devices.  This package includes
+command-line utilities for retrieving information and sending commands, a
+graphical @dfn{MIB} (Management Information Base) browser, a daemon for responding
+to SNMP commands (@command{snmptrapd}), an extensible SNMP server (@command{snmpd}),
+and libraries for writing other SNMP applications.")
+    ;; Distributed under HPND and multiple variants of the 3-clause BSD license.
+    ;; See COPYING for full information.
+    (license (list license:hpnd license:bsd-3))))
-- 
2.18.0