├── .coverity.yml ├── .gitignore ├── .travis.yml ├── AUTHORS ├── COPYING ├── Makefile.am ├── NEWS ├── PROTOCOL ├── README ├── README.md ├── THANKS ├── TODO ├── autogen.sh ├── build-aux ├── Makefile.am ├── clang-analyze ├── generate-change-log ├── make-confuse ├── make-openssl └── man2ps ├── configure.ac ├── contrib ├── Makefile.am ├── README ├── acknowledge ├── debug_server ├── disable_notifications ├── downtime ├── enable_notifications ├── invoke_check └── nsca-ng.init ├── etc ├── Makefile.am ├── nsca-ng.cfg ├── nsca-ng.service ├── nsca-ng.socket ├── send_nsca.cfg └── valgrind.supp ├── lib ├── Makefile.am ├── daemon.c ├── ev │ ├── Makefile.am │ ├── ev.c │ ├── ev.h │ ├── ev_epoll.c │ ├── ev_kqueue.c │ ├── ev_poll.c │ ├── ev_port.c │ ├── ev_select.c │ ├── ev_vars.h │ ├── ev_win32.c │ ├── ev_wrap.h │ └── libev.m4 ├── pidfile │ ├── Makefile.am │ ├── flock.c │ ├── flopen.c │ ├── libutil.h │ └── pidfile.c ├── progname.c ├── strcasecmp.c ├── strdup.c ├── strncasecmp.c ├── system.h ├── wrappers.c ├── wrappers.h └── xprintf.c ├── m4 ├── aio.m4 ├── confuse.m4 ├── daemon.m4 ├── ev.m4 ├── networking.m4 ├── openssl.m4 ├── pidfile.m4 ├── progname.m4 ├── systemd.m4 └── xprintf.m4 ├── man ├── Makefile.am ├── nsca-ng.cfg.in ├── nsca-ng.in ├── send_nsca.cfg.in └── send_nsca.in ├── perl ├── .gitignore ├── Changes ├── Client.xs ├── MANIFEST ├── Makefile.PL ├── Makefile.am ├── README ├── README.md ├── client.c ├── client.h ├── lib │ └── Net │ │ └── NSCAng │ │ └── Client.pm ├── ppport.h ├── t │ ├── 001_load.t │ ├── Net-NSCAng-Client.t │ ├── manifest.t │ └── pod.t ├── typemap └── uthash.h ├── python ├── Makefile.am ├── PKG-INFO ├── README ├── README.md ├── client.c ├── client.h ├── nscang.c ├── setup.py └── uthash.h ├── src ├── Makefile.am ├── client │ ├── Makefile.am │ ├── auth.c │ ├── auth.h │ ├── client.c │ ├── client.h │ ├── conf.c │ ├── conf.h │ ├── input.c │ ├── input.h │ ├── parse.c │ ├── parse.h │ ├── send_nsca.c │ └── send_nsca.h ├── common │ ├── Makefile.am │ ├── buffer.c │ ├── buffer.h │ ├── log.c │ ├── log.h │ ├── tls.c │ ├── tls.h │ ├── util.c │ └── util.h └── server │ ├── Makefile.am │ ├── auth.c │ ├── auth.h │ ├── conf.c │ ├── conf.h │ ├── fifo.c │ ├── fifo.h │ ├── hash.c │ ├── hash.h │ ├── nsca-ng.c │ ├── server.c │ └── server.h └── tests ├── Makefile.am ├── atlocal.in ├── auth.at ├── basic.at ├── input.at ├── local.at ├── test_nsca.c └── testsuite.at /.coverity.yml: -------------------------------------------------------------------------------- 1 | configurationVersion: 1 2 | 3 | filters: 4 | - filePath: /tests/test_nsca.c 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.a 2 | *.o 3 | *.plist 4 | *~ 5 | .*.swp 6 | .deps/ 7 | /ChangeLog 8 | /INSTALL 9 | /aclocal.in 10 | /aclocal.m4 11 | /autom4te.cache/ 12 | /build-aux/ar-lib 13 | /build-aux/compile 14 | /build-aux/depcomp 15 | /build-aux/install-sh 16 | /build-aux/missing 17 | /config.h 18 | /config.h.in 19 | /config.log 20 | /config.status 21 | /configure 22 | /confuse-* 23 | /lib/confuse/ 24 | /lib/ssl/ 25 | /man/*.man 26 | /man/*.pdf 27 | /man/*.ps 28 | /nsca-ng-*.tar.gz 29 | /openssl-* 30 | /python/build/ 31 | /src/client/send_nsca 32 | /src/server/nsca-ng 33 | /stamp-h1 34 | /tests/atconfig 35 | /tests/atlocal 36 | /tests/package.m4 37 | /tests/test_nsca 38 | /tests/testsuite 39 | /tests/testsuite.dir/ 40 | /tests/testsuite.log 41 | Makefile 42 | Makefile.in 43 | gmon.out 44 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | dist: xenial 2 | 3 | language: c 4 | 5 | install: 6 | - sudo apt-get -qq install libconfuse-dev libsystemd-dev 7 | 8 | before_script: 9 | - ./autogen.sh 10 | 11 | script: 12 | - ./configure --enable-server && make check 13 | 14 | # 15 | # Trigger Coverity Scan whenever we push into the "coverity" branch. 16 | # 17 | 18 | env: 19 | global: 20 | # This is the encrypted COVERITY_SCAN_TOKEN, created via the "travis 21 | # encrypt" command using the project repository's public key. 22 | - secure: "exX2eoF7QqazwvGrY+NoG/Q3xuMQORX0SB8buWYBIkGm3g/2BOYOWcP0f0TvMySW7Jnop+YIukJCxlrn8qlxyBhHD+TL+Lp5ehVECxsGT5Ls+fYW+35CQoHt/92i8ELiKeMrWghzLq5tstFjdQa6XEv8bKi35XwMHQlX8XuRFvU=" 23 | 24 | addons: 25 | coverity_scan: 26 | project: 27 | name: "weiss/nsca-ng" 28 | description: "An add-on for transferring monitoring data" 29 | notification_email: holger@weiss.in-berlin.de 30 | build_command_prepend: ./autogen.sh && ./configure --enable-server 31 | build_command: make 32 | branch_pattern: coverity 33 | 34 | # vim:set nowrap: 35 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Holger Weiss wrote most of the NSCA-ng client 2 | and server code. 3 | 4 | Alexander Golovko wrote the (technically separate) 5 | Python client module distributed with NSCA-ng. 6 | 7 | Matthias Bethke wrote the (technically 8 | separate) Perl client module distributed with NSCA-ng. 9 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | Unless otherwise noted, all files distributed as part of NSCA-ng are covered 2 | by the copyright and license statement below. Some files (outside the `src' 3 | directory) are subject to different copyright and/or license terms, as 4 | specified at the top of those files. However, all NSCA-ng code is believed 5 | to be covered by terms which are at least as permissive as the following 6 | license. 7 | 8 | | Copyright (c) 2013 Holger Weiss 9 | | All rights reserved. 10 | | 11 | | Redistribution and use in source and binary forms, with or without 12 | | modification, are permitted provided that the following conditions are 13 | | met: 14 | | 15 | | 1. Redistributions of source code must retain the above copyright notice, 16 | | this list of conditions and the following disclaimer. 17 | | 18 | | 2. Redistributions in binary form must reproduce the above copyright 19 | | notice, this list of conditions and the following disclaimer in the 20 | | documentation and/or other materials provided with the distribution. 21 | | 22 | | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 23 | | IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 24 | | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 25 | | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 26 | | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 27 | | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 28 | | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 30 | | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 31 | | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | 34 | In addition to these copyright and license terms, binary redistributions may 35 | be required to reproduce the following copyright notices, depending on which 36 | source files are compiled. The above license statement applies to all of 37 | them. 38 | 39 | If any files in the `lib/ev' directory are used during compilation: 40 | 41 | | Copyright (c) 2007-2018 Marc Alexander Lehmann 42 | | Copyright (c) 2011 Emanuele Giaquinta 43 | 44 | If any files in the `lib/pidfile' directory are used during compilation: 45 | 46 | | Copyright (c) 2005 Pawel Jakub Dawidek 47 | | Copyright (c) 2007 Dag-Erling Coidan Smoergrav 48 | 49 | If the file `lib/pidfile/flock.c' is used during compilation: 50 | 51 | | Copyright (c) 2001 The NetBSD Foundation, Inc. 52 | 53 | If any files in the `python' directory (except for `uthash.h') are used: 54 | 55 | | Copyright (c) 2014 Alexander Golovko 56 | 57 | If any files in the `perl' directory are used: 58 | 59 | | Copyright (c) 2015 Matthias Bethke 60 | 61 | Additional requirements may be imposed by external libraries. 62 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake(1) to produce Makefile.in. 2 | 3 | ## Copyright (c) 2013 Holger Weiss 4 | ## All rights reserved. 5 | ## 6 | ## Redistribution and use in source and binary forms, with or without 7 | ## modification, are permitted provided that the following conditions are met: 8 | ## 9 | ## 1. Redistributions of source code must retain the above copyright notice, 10 | ## this list of conditions and the following disclaimer. 11 | ## 12 | ## 2. Redistributions in binary form must reproduce the above copyright notice, 13 | ## this list of conditions and the following disclaimer in the documentation 14 | ## and/or other materials provided with the distribution. 15 | ## 16 | ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | ## ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 | ## LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | ## CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | ## SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | ## INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | ## CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | ## ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | ## POSSIBILITY OF SUCH DAMAGE. 27 | 28 | ACLOCAL_AMFLAGS = -I m4 29 | EXTRA_DIST = ChangeLog PROTOCOL autogen.sh 30 | 31 | SUBDIRS = lib src man etc build-aux contrib perl python tests 32 | 33 | # 34 | # The ChangeLog file is auto-generated from the Git history. We let it depend 35 | # on configure.ac, as we bump our version number in that file. 36 | # 37 | ChangeLog: configure.ac 38 | $(AM_V_GEN)$(top_srcdir)/build-aux/generate-change-log > $@ 39 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | README -------------------------------------------------------------------------------- /THANKS: -------------------------------------------------------------------------------- 1 | Many thanks go to my employer, Zentraleinrichtung fuer Datenverarbeitung 2 | (ZEDAT) at Freie Universitaet Berlin, and especially to Heiko Schlichting, 3 | who contributed most of the good ideas behind NSCA-ng. 4 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | NSCA-ng Task List 2 | ================= 3 | 4 | The to-do items are listed in no particular order. 5 | 6 | Wish List Items for NSCA-ng 7 | --------------------------- 8 | 9 | - Let the server support command authorization based on host and service 10 | groups. This requires the server to actually parse the submitted 11 | commands, as oppposed to simply matching them against the user-supplied 12 | regular expressions. 13 | 14 | - Let the server support a `clients` or `sources` directive that allows the 15 | user to specify one or more subnets (globally and/or per-client). 16 | Connections from source addresses outside these subnets should be 17 | rejected. 18 | 19 | - Let the server support proxying of (selected or all) data (with `forward` 20 | blocks in the configuration, for example). 21 | 22 | - Support requests for status and configuration data in order to provide a 23 | full-blown remote API. 24 | 25 | - Let the client execute standard Nagios plugins directly (as an alternative 26 | to using a script such as `contrib/invoke_check`), and maybe provide a 27 | daemon mode with poor man's check scheduling (i.e., add `check_interval` 28 | and `retry_interval` directives to the client configuration). 29 | 30 | - If the server is not available, let the client queue commands and results 31 | using local storage and submit them as soon as the server comes up again. 32 | 33 | - Let the client talk to multiple servers. 34 | 35 | - Port the client to Microsoft Windows. 36 | 37 | - Create a client library with Perl (and maybe Python) bindings. 38 | 39 | Wish List Items for OpenSSL 40 | --------------------------- 41 | 42 | - Add IPv6 support to OpenSSL's `BIO_s_connect(3)` API, so that the client 43 | can use IPv6. (The server supports IPv6 already.) There's a [ticket][1] 44 | with a patch in OpenSSL's tracker, and a related [discussion][2] on the 45 | OpenSSL development mailing list. 46 | 47 | - Support NULL encryption TLS-PSK cipher suites as defined in [RFC 4785][3]. 48 | This should make it easier to use tools such as `tcpdump(8)` for debugging 49 | NSCA-ng sessions. There's an [older][4] and a [newer][5] patch in 50 | OpenSSL's tracker. 51 | 52 | - Support SHA-256/384 (and GCM) TLS-PSK cipher suites as per [RFC 5487][6]. 53 | Someone [played around with this][7] already. 54 | 55 | [1]: http://rt.openssl.org/Ticket/Display.html?id=1365 56 | [2]: http://thread.gmane.org/gmane.comp.encryption.openssl.devel/11207 57 | [3]: http://tools.ietf.org/html/rfc4785 58 | [4]: http://rt.openssl.org/Ticket/Display.html?id=1886 59 | [5]: http://rt.openssl.org/Ticket/Display.html?id=2299 60 | [6]: http://tools.ietf.org/html/rfc5487 61 | [7]: http://permalink.gmane.org/gmane.comp.encryption.openssl.user/44388 62 | 63 | 64 | -------------------------------------------------------------------------------- /autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | exec autoreconf --force --install 4 | -------------------------------------------------------------------------------- /build-aux/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake(1) to produce Makefile.in. 2 | 3 | ## Copyright (c) 2013 Holger Weiss 4 | ## All rights reserved. 5 | ## 6 | ## Redistribution and use in source and binary forms, with or without 7 | ## modification, are permitted provided that the following conditions are met: 8 | ## 9 | ## 1. Redistributions of source code must retain the above copyright notice, 10 | ## this list of conditions and the following disclaimer. 11 | ## 12 | ## 2. Redistributions in binary form must reproduce the above copyright notice, 13 | ## this list of conditions and the following disclaimer in the documentation 14 | ## and/or other materials provided with the distribution. 15 | ## 16 | ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | ## ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 | ## LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | ## CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | ## SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | ## INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | ## CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | ## ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | ## POSSIBILITY OF SUCH DAMAGE. 27 | 28 | EXTRA_DIST = clang-analyze generate-change-log make-confuse make-openssl man2ps 29 | -------------------------------------------------------------------------------- /build-aux/clang-analyze: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | set -u 5 | 6 | myself=`echo "$0" | sed 's,.*/,,'` 7 | 8 | say() 9 | { 10 | echo "$myself: $@." 11 | } 12 | 13 | die() 14 | { 15 | echo >&2 "$myself: $@." 16 | exit 1 17 | } 18 | 19 | general_args='--analyze' 20 | include_args=' 21 | -I. 22 | -Ilib 23 | -Ilib/ev 24 | -Ilib/pidfile 25 | -Isrc/common 26 | -I/usr/local/include 27 | -I/usr/pkg/include' 28 | definition_args=' 29 | -DHAVE_CONFIG_H 30 | -DNSCA_VERSION=PACKAGE_VERSION 31 | -DSYSCONFDIR="/foo" 32 | -DLOCALSTATEDIR="/bar"' 33 | 34 | test -f 'lib/system.h' \ 35 | || die 'Please call me from the NSCA-ng source directory' 36 | test -f 'config.h' \ 37 | || die "Please run ./configure before calling $0" 38 | 39 | files=`find 'src' -type 'f' -name '*.c' -print` 40 | 41 | echo "Letting Clang analyze the following list of files:" 42 | echo 43 | echo "$files" 44 | echo 45 | 46 | exec clang $general_args $include_args $definition_args $files 47 | -------------------------------------------------------------------------------- /build-aux/generate-change-log: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | use warnings; 4 | use strict; 5 | use open ':encoding(UTF-8)'; 6 | use Encode; 7 | use Text::Wrap; 8 | 9 | # 10 | # We'd like to minimize the number of dependencies, otherwise we'd probably use 11 | # the Text::Unidecode module instead. 12 | # 13 | sub asciify { 14 | my $text = shift; 15 | my %charmap = ( 16 | ord "\N{LATIN CAPITAL LETTER A WITH DIAERESIS}" => 'Ae', 17 | ord "\N{LATIN CAPITAL LETTER O WITH DIAERESIS}" => 'Oe', 18 | ord "\N{LATIN CAPITAL LETTER U WITH DIAERESIS}" => 'Ue', 19 | ord "\N{LATIN SMALL LETTER A WITH DIAERESIS}" => 'ae', 20 | ord "\N{LATIN SMALL LETTER O WITH DIAERESIS}" => 'oe', 21 | ord "\N{LATIN SMALL LETTER U WITH DIAERESIS}" => 'ue', 22 | ord "\N{LATIN SMALL LETTER SHARP S}" => 'ss' 23 | ); 24 | 25 | return encode('ascii', $text, sub { 26 | my $char = shift; 27 | 28 | foreach my $key (keys %charmap) { 29 | return $charmap{$key} if $key == $char; 30 | } 31 | return sprintf('', $char); 32 | }); 33 | } 34 | 35 | # The lines will have a length of no more than $columns - 1. 36 | $Text::Wrap::columns = 81; 37 | 38 | if (system('git rev-parse --git-dir >/dev/null 2>&1') != 0) { 39 | print "Not a Git repository, so I won't update the ChangeLog.\n"; 40 | exit 0; 41 | } 42 | 43 | my $regex = 44 | '^commit [0-9a-f]+\n' . 45 | '^Author: (?.+) <(?.*)>\n' . 46 | '^Date: (?\d{4}-\d{2}-\d{2})\n' . 47 | '^\n' . 48 | '(?(^ .*\n)+)' . 49 | '^\n' . 50 | '(?(^.+\n)+)'; 51 | 52 | my $git_log = qx'git log -M -C --stat --name-only --date=short'; 53 | die "Cannot get `git log' output\n" if $? != 0; 54 | 55 | my ($prev_date, $prev_name, $prev_email); 56 | 57 | while ($git_log =~ /$regex/gm) { 58 | my %commit = %+; 59 | 60 | if (not defined $prev_date 61 | or $commit{date} ne $prev_date 62 | or $commit{name} ne $prev_name 63 | or $commit{email} ne $prev_email) { 64 | print $commit{date}, ' '; 65 | print asciify($commit{name}), ' '; 66 | print '<', $commit{email}, '>', "\n\n"; 67 | } 68 | $prev_date = $commit{date}; 69 | $prev_name = $commit{name}; 70 | $prev_email = $commit{email}; 71 | 72 | my @files = split(/\n/, $commit{files}); 73 | my @message = map { s/^ {4}//r } split(/\n/, asciify($commit{message})); 74 | my $first_line = shift(@message) =~ s/^$files[-1]: //r; 75 | my $intro = sprintf('* %s: %s', join(', ', @files), $first_line); 76 | 77 | print fill("\t", "\t", $intro), "\n"; 78 | foreach my $line (@message) { 79 | print "\t$line" if length($line) > 0; 80 | print "\n"; 81 | } 82 | print "\n"; 83 | } 84 | -------------------------------------------------------------------------------- /build-aux/make-confuse: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | set -u 5 | 6 | myself=`echo "$0" | sed 's,.*/,,'` 7 | 8 | say() 9 | { 10 | echo "$myself: $@." 11 | } 12 | 13 | die() 14 | { 15 | echo >&2 "$myself: $@." 16 | exit 1 17 | } 18 | 19 | if [ $# -eq 1 ] 20 | then 21 | version=$1 22 | else 23 | version=3.2.2 24 | fi 25 | 26 | if [ ! -f lib/system.h ] 27 | then 28 | if [ -f ../lib/system.h ] 29 | then 30 | cd .. 31 | else 32 | die 'Please call me from the NSCA-ng source directory' 33 | fi 34 | fi 35 | 36 | install_dir=`pwd`/lib/confuse 37 | tarball="confuse-$version.tar.gz" 38 | 39 | if [ ! -f "$tarball" ] 40 | then 41 | if type curl >/dev/null 2>&1 42 | then 43 | get="curl -L -o $tarball" 44 | elif type wget >/dev/null 2>&1 45 | then 46 | get=wget 47 | else 48 | say 'Cannot find an HTTP client' 49 | die "Please download '$tarball' into `pwd`" 50 | fi 51 | 52 | $get "https://github.com/martinh/libconfuse/releases/download/v$version/$tarball" 53 | test -f "$tarball" || die "Downloading '$tarball' failed" 54 | fi 55 | 56 | gzip -c -d "$tarball" | tar xf - 57 | cd `expr "$tarball" : '\(.*\)\.tar\.gz$'` 58 | 59 | ./configure --prefix="$install_dir" --enable-static --disable-shared 60 | make 61 | make install 62 | 63 | say 'Success' 64 | 65 | # vim:set joinspaces noexpandtab textwidth=80: 66 | -------------------------------------------------------------------------------- /build-aux/make-openssl: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | set -u 5 | 6 | myself=`echo "$0" | sed 's,.*/,,'` 7 | 8 | say() 9 | { 10 | echo "$myself: $@." 11 | } 12 | 13 | die() 14 | { 15 | echo >&2 "$myself: $@." 16 | exit 1 17 | } 18 | 19 | found_browser=no 20 | 21 | if [ ! -f lib/system.h ] 22 | then 23 | if [ -f ../lib/system.h ] 24 | then 25 | cd .. 26 | else 27 | die 'Please call me from the NSCA-ng source directory' 28 | fi 29 | fi 30 | 31 | for browser in 'lynx' 'elinks' 'links' 32 | do 33 | if type `expr "$browser" : '\([^ ]*\)'` >/dev/null 2>&1 && 34 | $browser -dump 'https://www.openssl.org/' >/dev/null 2>&1 35 | then 36 | found_browser=yes 37 | break 38 | fi 39 | done 40 | 41 | test "$found_browser" = yes || 42 | die 'Cannot find a usable text web browser, please install lynx(1)' 43 | 44 | install_dir=`pwd`/lib/ssl 45 | tarball=`$browser -dump 'https://www.openssl.org/source/' | 46 | sed -n 's/.*\(openssl-[1-9].*\.tar\.gz\).*/\1/p' | head -1` 47 | 48 | if [ ! -f "$tarball" ] 49 | then 50 | if type curl >/dev/null 2>&1 51 | then 52 | get="curl -L -o $tarball" 53 | elif type wget >/dev/null 2>&1 54 | then 55 | get=wget 56 | else 57 | say 'Cannot find an HTTP client' 58 | die "Please download '$tarball' into `pwd`" 59 | fi 60 | 61 | $get "https://www.openssl.org/source/$tarball" 62 | test -f "$tarball" || die "Downloading '$tarball' failed" 63 | fi 64 | 65 | gzip -c -d "$tarball" | tar xf - 66 | cd `expr "$tarball" : '\(.*\)\.tar\.gz$'` 67 | 68 | ./config --prefix="$install_dir" no-shared no-threads 69 | make 70 | make install 71 | 72 | say 'Success' 73 | 74 | # vim:set joinspaces noexpandtab textwidth=80: 75 | -------------------------------------------------------------------------------- /build-aux/man2ps: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | set -u 5 | 6 | heirloom_settings='.\\" Heirloom Settings\ 7 | .\ 8 | .do xflag 3\ 9 | .\ 10 | .fp 1 R utrg____ pfb\ 11 | .fp 2 I uti_____ pfb\ 12 | .fp 3 B utb_____ pfb\ 13 | .fp 4 BI utbi____ pfb\ 14 | .\ 15 | .fp 101 ER uerg____ pfb\ 16 | .fp 102 EI uei_____ pfb\ 17 | .fp 103 EB ueb_____ pfb\ 18 | .fp 104 EBI uebi____ pfb\ 19 | .\ 20 | .fp 5 CW l047013t pfa\ 21 | .fzoom CW .92\ 22 | .\ 23 | .fallback R ER\ 24 | .hidechar R 0123456789\ 25 | .flig R ff \\(ff ffi \\(Fi ffl \\(Fl\ 26 | .\ 27 | .fallback I EI\ 28 | .hidechar I 0123456789\ 29 | .flig I ff \\(ff ffi \\(Fi ffl \\(Fl\ 30 | .\ 31 | .fallback B EB\ 32 | .hidechar B 0123456789\ 33 | .flig B ff \\(ff ffi \\(Fi ffl \\(Fl\ 34 | .\ 35 | .fallback BI EBI\ 36 | .hidechar BI 0123456789\ 37 | .flig BI ff \\(ff ffi \\(Fi ffl \\(Fl\ 38 | .\ 39 | .padj\ 40 | .minss 9\ 41 | .letadj 95 98 18 105 102\ 42 | .\ 43 | ' 44 | 45 | if [ $# -ne 2 ] 46 | then 47 | echo >&2 "Usage: $0 " 48 | exit 2 49 | fi 50 | 51 | man_file=$1 52 | ps_file=$2 53 | tmp_file='man.tmp' 54 | 55 | if [ ! -r "$HOME/.fonts/type1/uerg____.pfb" ] 56 | then 57 | groff -Tps -fN -man "$man_file" >"$ps_file" 58 | else # We're probably on Holger's box. 59 | PATH="$HOME/opt/heirloom/bin:$PATH" 60 | TROFFONTS="$HOME/.fonts/type1" 61 | export PATH TROFFONTS 62 | 63 | sed "s,^\.TH.*,$heirloom_settings&," "$man_file" >"$tmp_file" 64 | troff -mg -msafe -man "$tmp_file" | dpost >"$ps_file" 65 | rm -f "$tmp_file" 66 | fi 67 | 68 | # vim:set joinspaces noexpandtab textwidth=80: 69 | -------------------------------------------------------------------------------- /contrib/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake(1) to produce Makefile.in. 2 | 3 | ## Copyright (c) 2013 Holger Weiss 4 | ## All rights reserved. 5 | ## 6 | ## Redistribution and use in source and binary forms, with or without 7 | ## modification, are permitted provided that the following conditions are met: 8 | ## 9 | ## 1. Redistributions of source code must retain the above copyright notice, 10 | ## this list of conditions and the following disclaimer. 11 | ## 12 | ## 2. Redistributions in binary form must reproduce the above copyright notice, 13 | ## this list of conditions and the following disclaimer in the documentation 14 | ## and/or other materials provided with the distribution. 15 | ## 16 | ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | ## ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 | ## LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | ## CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | ## SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | ## INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | ## CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | ## ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | ## POSSIBILITY OF SUCH DAMAGE. 27 | 28 | EXTRA_DIST = acknowledge debug_server disable_notifications downtime \ 29 | enable_notifications invoke_check nsca-ng.init 30 | -------------------------------------------------------------------------------- /contrib/README: -------------------------------------------------------------------------------- 1 | NSCA-ng's "contrib" Directory 2 | ============================= 3 | 4 | This directory contains a collection of scripts that may be useful. All 5 | scripts except for `nsca-ng.init` allow for specifying the path to the 6 | `send_nsca.cfg(5)` file via `-c `. Other `send_nsca(8)` options can 7 | be specified by setting the environment variable `SEND_NSCA_ARGS`. All 8 | scripts print usage information when called with the `-h` option. 9 | 10 | * `acknowledge` 11 | 12 | Acknowledges a problem using `send_nsca(8)`. If the `-S` option is 13 | specified, a service problem is acknowledged; otherwise, a host problem 14 | is acknowledged. Example invocation: 15 | 16 | $ acknowledge -H www -S HTTP 17 | 18 | * `debug_server` 19 | 20 | Opens a raw TLS connection to the `nsca-ng(8)` server, sends any lines 21 | read from the standard input, and prints any server responses to the 22 | standard output. Requires `s_client(1)` from OpenSSL 1.0.0 or newer, 23 | and `xxd(1)`. Example invocation: 24 | 25 | $ debug_server -c /etc/send_nsca.cfg 26 | 27 | * `disable_notifications` 28 | 29 | Globally disables host and service notifications using `send_nsca(8)`. 30 | Example invocation: 31 | 32 | $ disable_notifications 33 | 34 | * `downtime` 35 | 36 | Schedules a host or service downtime using `send_nsca(8)`. If the `-S` 37 | option is used, a service downtime is scheduled; otherwise, a host 38 | downtime is scheduled. The start and end times are specified with the 39 | `-s` and `-e` options, respectively. They accept the same date string 40 | format as GNU `date(1)'s` `-d` option. Requires GNU `date(1)` or BSD 41 | `date(1)`. Example invocation (the `-s` and `-e` options could be 42 | omitted here, as these are their default values): 43 | 44 | $ downtime -H mail -S IMAP -s now -e +2hours 45 | 46 | * `enable_notifications` 47 | 48 | Globally enables host and service notifications using `send_nsca(8)`. 49 | Example invocation: 50 | 51 | $ enable_notifications 52 | 53 | * `invoke_check` 54 | 55 | Executes standard plugins and transmits their results using 56 | `send_nsca(8)`. Example invocation: 57 | 58 | $ invoke_check check_disk -w 20% -c 10% 59 | 60 | * `nsca-ng.init` 61 | 62 | Starts, stops, restarts, or reloads the `nsca-ng(8)` server running on 63 | the local system. Example invocation: 64 | 65 | $ nsca-ng.init start 66 | 67 | 68 | -------------------------------------------------------------------------------- /contrib/acknowledge: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright (c) 2013 Holger Weiss 4 | # 5 | # This file is free software; Holger Weiss gives unlimited permission to copy 6 | # and/or distribute it, with or without modifications, as long as this notice is 7 | # preserved. 8 | # 9 | # This program is distributed in the hope that it will be useful, but WITHOUT 10 | # ANY WARRANTY, to the extent permitted by law; without even the implied 11 | # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | 13 | set -e 14 | set -u 15 | 16 | send_nsca_args=${SEND_NSCA_ARGS:+$SEND_NSCA_ARGS} 17 | 18 | die() 19 | { 20 | echo >&2 "$@" 21 | exit 1 22 | } 23 | 24 | usage() 25 | { 26 | die "Usage: $0 [-C ] [-c ] [-H ] [-S ]" 27 | } 28 | 29 | while getopts C:c:H:hS: option 30 | do 31 | case $option in 32 | C) 33 | comment=$OPTARG 34 | ;; 35 | c) 36 | send_nsca_args="${send_nsca_args:+$send_nsca_args }-c $OPTARG" 37 | ;; 38 | H) 39 | host=$OPTARG 40 | ;; 41 | S) 42 | service=$OPTARG 43 | ;; 44 | h|\?) 45 | usage 46 | ;; 47 | esac 48 | done 49 | 50 | shift `expr $OPTIND - 1` 51 | test $# -eq 0 || usage 52 | 53 | host=${host:-`hostname -s`} 54 | service=${service:+$service} 55 | author=`getent passwd "$USER" | cut -d: -f5` 56 | comment=${comment:-"Submitted by send_nsca@`hostname -s`"} 57 | 58 | if [ -z "$service" ] 59 | then # Host acknowledgement. 60 | printf '%b' "ACKNOWLEDGE_HOST_PROBLEM;$host;1;0;1;$author;$comment\n" \ 61 | | send_nsca -C $send_nsca_args 62 | else # Service acknowledgement. 63 | printf '%b' "ACKNOWLEDGE_SVC_PROBLEM;$host;$service;1;0;1;$author;$comment\n" \ 64 | | send_nsca -C $send_nsca_args 65 | fi 66 | 67 | # vim:set joinspaces noexpandtab textwidth=80: 68 | -------------------------------------------------------------------------------- /contrib/debug_server: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright (c) 2013 Holger Weiss 4 | # 5 | # This file is free software; Holger Weiss gives unlimited permission to copy 6 | # and/or distribute it, with or without modifications, as long as this notice is 7 | # preserved. 8 | # 9 | # This program is distributed in the hope that it will be useful, but WITHOUT 10 | # ANY WARRANTY, to the extent permitted by law; without even the implied 11 | # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | 13 | set -e 14 | set -u 15 | 16 | default_config_file='/etc/send_nsca.cfg' 17 | default_port='5668' 18 | 19 | die() 20 | { 21 | echo >&2 "$@" 22 | exit 1 23 | } 24 | 25 | usage() 26 | { 27 | die "Usage: $0 [-c ] [-H ] [-p ]" 28 | } 29 | 30 | xxd /dev/null 2>&1 || die "$0: xxd(1) is required" 31 | 32 | while getopts c:H:hp: option 33 | do 34 | case $option in 35 | c) 36 | config_file=$OPTARG 37 | ;; 38 | H) 39 | opt_server=$OPTARG 40 | ;; 41 | h|\?) 42 | usage 43 | ;; 44 | p) 45 | opt_port=$OPTARG 46 | ;; 47 | esac 48 | done 49 | 50 | shift `expr $OPTIND - 1` 51 | test $# -eq 0 || usage 52 | 53 | config_file=${config_file:-$default_config_file} 54 | 55 | if [ -r "$config_file" ] 56 | then 57 | eval "`sed 's/[[:space:]]*=[[:space:]]*/=/' "$config_file"`" 58 | else 59 | echo >&2 "Cannot read $config_file (continuing anyway)" 60 | fi 61 | 62 | server=${server:-'localhost'} 63 | server=${opt_server:-$server} 64 | port=${port:-$default_port} 65 | port=${opt_port:-$port} 66 | identity=${identity:-`hostname -s`} 67 | password=${password:-'change-me'} 68 | ciphers=${tls_ciphers:-'PSK-AES256-CBC-SHA:PSK-AES128-CBC-SHA:PSK-3DES-EDE-CBC-SHA:PSK-RC4-SHA'} 69 | 70 | exec openssl s_client \ 71 | -crlf \ 72 | -cipher "$ciphers" \ 73 | -psk_identity "$identity" \ 74 | -psk `printf '%s' "$password" | xxd -p | tr -d '\n'` \ 75 | -connect "$server:$port" 76 | 77 | # vim:set joinspaces noexpandtab textwidth=80: 78 | -------------------------------------------------------------------------------- /contrib/disable_notifications: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright (c) 2013 Holger Weiss 4 | # 5 | # This file is free software; Holger Weiss gives unlimited permission to copy 6 | # and/or distribute it, with or without modifications, as long as this notice is 7 | # preserved. 8 | # 9 | # This program is distributed in the hope that it will be useful, but WITHOUT 10 | # ANY WARRANTY, to the extent permitted by law; without even the implied 11 | # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | 13 | set -e 14 | set -u 15 | 16 | send_nsca_args=${SEND_NSCA_ARGS:+$SEND_NSCA_ARGS} 17 | 18 | die() 19 | { 20 | echo >&2 "$@" 21 | exit 1 22 | } 23 | 24 | usage() 25 | { 26 | die "Usage: $0 [-c ]" 27 | } 28 | 29 | while getopts c:h option 30 | do 31 | case $option in 32 | c) 33 | send_nsca_args="${send_nsca_args:+$send_nsca_args }-c $OPTARG" 34 | ;; 35 | h|\?) 36 | usage 37 | ;; 38 | esac 39 | done 40 | 41 | shift `expr $OPTIND - 1` 42 | test $# -eq 0 || usage 43 | 44 | printf '%b' 'DISABLE_NOTIFICATIONS\n' | send_nsca -C $send_nsca_args 45 | 46 | # vim:set joinspaces noexpandtab textwidth=80: 47 | -------------------------------------------------------------------------------- /contrib/downtime: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright (c) 2013 Holger Weiss 4 | # 5 | # This file is free software; Holger Weiss gives unlimited permission to copy 6 | # and/or distribute it, with or without modifications, as long as this notice is 7 | # preserved. 8 | # 9 | # This program is distributed in the hope that it will be useful, but WITHOUT 10 | # ANY WARRANTY, to the extent permitted by law; without even the implied 11 | # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | 13 | # Note that this script uses non-standard date(1) extensions which aren't 14 | # available on all systems. GNU date(1) provides them: 15 | # 16 | # http://www.gnu.org/software/coreutils/ 17 | 18 | set -e 19 | set -u 20 | 21 | send_nsca_args=${SEND_NSCA_ARGS:+$SEND_NSCA_ARGS} 22 | 23 | die() 24 | { 25 | echo >&2 "$@" 26 | exit 1 27 | } 28 | 29 | usage() 30 | { 31 | die "Usage: $0 [-C ] [-c ] [-H ] [-S ]" 32 | } 33 | 34 | date -d 'now' '+%s' 2>&1 | grep '^[[:digit:]]*$' >/dev/null \ 35 | || die "$0: GNU date(1) or BSD date(1) is required" 36 | 37 | while getopts C:c:e:H:hS:s: option 38 | do 39 | case $option in 40 | C) 41 | comment=$OPTARG 42 | ;; 43 | c) 44 | send_nsca_args="${send_nsca_args:+$send_nsca_args }-c $OPTARG" 45 | ;; 46 | e) 47 | end=$OPTARG 48 | ;; 49 | H) 50 | host=$OPTARG 51 | ;; 52 | S) 53 | service=$OPTARG 54 | ;; 55 | s) 56 | start=$OPTARG 57 | ;; 58 | h|\?) 59 | usage 60 | ;; 61 | esac 62 | done 63 | 64 | shift `expr $OPTIND - 1` 65 | test $# -eq 0 || usage 66 | 67 | host=${host:-`hostname -s`} 68 | service=${service:+$service} 69 | start=`date -d ${start:-'now'} '+%s'` 70 | end=`date -d ${end:-'+2 hours'} '+%s'` 71 | author=`getent passwd "$USER" | cut -d: -f5` 72 | comment=${comment:-"Submitted by send_nsca@`hostname -s`"} 73 | 74 | if [ -z "$service" ] 75 | then # Host check. 76 | printf '%b' "SCHEDULE_HOST_DOWNTIME;$host;$start;$end;1;0;0;$author;$comment\n" \ 77 | | send_nsca -C $send_nsca_args 78 | else # Service check. 79 | printf '%b' "SCHEDULE_SVC_DOWNTIME;$host;$service;$start;$end;1;0;0;$author;$comment\n" \ 80 | | send_nsca -C $send_nsca_args 81 | fi 82 | 83 | # vim:set joinspaces noexpandtab textwidth=80: 84 | -------------------------------------------------------------------------------- /contrib/enable_notifications: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright (c) 2013 Holger Weiss 4 | # 5 | # This file is free software; Holger Weiss gives unlimited permission to copy 6 | # and/or distribute it, with or without modifications, as long as this notice is 7 | # preserved. 8 | # 9 | # This program is distributed in the hope that it will be useful, but WITHOUT 10 | # ANY WARRANTY, to the extent permitted by law; without even the implied 11 | # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | 13 | set -e 14 | set -u 15 | 16 | send_nsca_args=${SEND_NSCA_ARGS:+$SEND_NSCA_ARGS} 17 | 18 | die() 19 | { 20 | echo >&2 "$@" 21 | exit 1 22 | } 23 | 24 | usage() 25 | { 26 | die "Usage: $0 [-c ]" 27 | } 28 | 29 | while getopts c:h option 30 | do 31 | case $option in 32 | c) 33 | send_nsca_args="${send_nsca_args:+$send_nsca_args }-c $OPTARG" 34 | ;; 35 | h|\?) 36 | usage 37 | ;; 38 | esac 39 | done 40 | 41 | shift `expr $OPTIND - 1` 42 | test $# -eq 0 || usage 43 | 44 | printf '%b' 'ENABLE_NOTIFICATIONS\n' | send_nsca -C $send_nsca_args 45 | 46 | # vim:set joinspaces noexpandtab textwidth=80: 47 | -------------------------------------------------------------------------------- /contrib/invoke_check: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright (c) 2013 Holger Weiss 4 | # 5 | # This file is free software; Holger Weiss gives unlimited permission to copy 6 | # and/or distribute it, with or without modifications, as long as this notice is 7 | # preserved. 8 | # 9 | # This program is distributed in the hope that it will be useful, but WITHOUT 10 | # ANY WARRANTY, to the extent permitted by law; without even the implied 11 | # warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | 13 | set -u 14 | 15 | send_nsca_args=${SEND_NSCA_ARGS:+$SEND_NSCA_ARGS} 16 | 17 | PATH="$PATH:/usr/local/nagios/libexec:/usr/lib/nagios/plugins" 18 | export PATH 19 | 20 | die() 21 | { 22 | echo >&2 "$@" 23 | exit 1 24 | } 25 | 26 | usage() 27 | { 28 | die "Usage: $0 [-c ] [-H ] [-S ]" \ 29 | " [ ...]" 30 | } 31 | 32 | while getopts c:H:hS: option 33 | do 34 | case $option in 35 | c) 36 | send_nsca_args="${send_nsca_args:+$send_nsca_args }-c $OPTARG" 37 | ;; 38 | H) 39 | host=$OPTARG 40 | ;; 41 | S) 42 | service=$OPTARG 43 | ;; 44 | h|\?) 45 | usage 46 | ;; 47 | esac 48 | done 49 | 50 | shift `expr $OPTIND - 1` 51 | test $# -ge 1 || usage 52 | 53 | host=${host:-`hostname | sed 's+\..*++' | tr '[:upper:]' '[:lower:]'`} 54 | service=${service:-`echo "$1" | sed 's+.*[_/]++' | tr '[:lower:]' '[:upper:]'`} 55 | output=`"$@"` 56 | state=$? 57 | 58 | test $state -le 3 || die "$0: '$@' yields invalid plugin return code $state" 59 | 60 | printf '%b' "$host\t$service\t$state\t$output\n" | send_nsca $send_nsca_args 61 | 62 | # vim:set joinspaces noexpandtab textwidth=80: 63 | -------------------------------------------------------------------------------- /contrib/nsca-ng.init: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | ### BEGIN INIT INFO 4 | # Provides: nsca-ng 5 | # Required-Start: $local_fs $network $remote_fs $syslog 6 | # Required-Stop: $local_fs $network $remote_fs $syslog 7 | # Default-Start: 2 3 4 5 8 | # Default-Stop: 0 1 6 9 | # Short-Description: Receive monitoring commands 10 | # Description: The NSCA-ng server makes the Nagios command file accessible 11 | # from remote systems. 12 | ### END INIT INFO 13 | 14 | PATH='/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin' 15 | export PATH 16 | 17 | name='NSCA-ng' 18 | pid_file="$HOME/.nsca-ng.pid" 19 | 20 | get_pid() 21 | { 22 | pid=`cat "$pid_file" 2>/dev/null` 23 | 24 | if expr "X$pid" : 'X[0-9]\{1,\}$' >/dev/null && kill -0 $pid 2>/dev/null 25 | then 26 | echo "$pid" 27 | else 28 | rm -f "$pid_file" # In case it was left over. 29 | echo 0 30 | fi 31 | } 32 | 33 | pid=`get_pid` 34 | 35 | case $1 in 36 | start) 37 | if [ $pid -eq 0 ] 38 | then 39 | printf 'Starting %s daemon ... ' "$name" 40 | nsca-ng -P "$pid_file" && echo 'done.' || echo 'failed.' 41 | else 42 | echo "$name daemon is already running" 43 | fi 44 | ;; 45 | stop) 46 | if [ $pid -ne 0 ] 47 | then 48 | printf 'Stopping %s daemon ... ' "$name" 49 | kill $pid 2>/dev/null && echo 'done.' || echo 'failed.' 50 | else 51 | echo "$name daemon is already stopped." 52 | fi 53 | ;; 54 | restart) 55 | "$0" stop && sleep 1 && "$0" start 56 | ;; 57 | try-restart) 58 | if [ $pid -ne 0 ] 59 | then 60 | "$0" restart 61 | else 62 | echo "$name daemon doesn't appear to be running." 63 | fi 64 | ;; 65 | reload|force-reload) 66 | if [ $pid -ne 0 ] 67 | then 68 | printf 'Reloading %s daemon ... ' "$name" 69 | kill -1 $pid 2>/dev/null && echo 'done.' || echo 'failed.' 70 | else 71 | echo "$name daemon is already stopped." 72 | fi 73 | ;; 74 | status) 75 | if [ $pid -ne 0 ] 76 | then 77 | echo "$name daemon appears to be running." 78 | else 79 | echo "$name daemon does NOT appear to be running." 80 | exit 3 81 | fi 82 | ;; 83 | *) 84 | echo >&2 "Usage: $0 {start|stop|restart|try-restart|reload|status}" 85 | exit 2 86 | ;; 87 | esac 88 | 89 | exit 0 90 | 91 | # vim:set joinspaces noexpandtab textwidth=80: 92 | -------------------------------------------------------------------------------- /etc/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake(1) to produce Makefile.in. 2 | 3 | ## Copyright (c) 2013 Holger Weiss 4 | ## All rights reserved. 5 | ## 6 | ## Redistribution and use in source and binary forms, with or without 7 | ## modification, are permitted provided that the following conditions are met: 8 | ## 9 | ## 1. Redistributions of source code must retain the above copyright notice, 10 | ## this list of conditions and the following disclaimer. 11 | ## 12 | ## 2. Redistributions in binary form must reproduce the above copyright notice, 13 | ## this list of conditions and the following disclaimer in the documentation 14 | ## and/or other materials provided with the distribution. 15 | ## 16 | ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | ## ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 | ## LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | ## CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | ## SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | ## INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | ## CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | ## ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | ## POSSIBILITY OF SUCH DAMAGE. 27 | 28 | EXTRA_DIST = nsca-ng.cfg nsca-ng.service nsca-ng.socket send_nsca.cfg \ 29 | valgrind.supp 30 | 31 | if BUILD_CLIENT 32 | install-data-local: install-nsca-client-conf 33 | uninstall-local: uninstall-nsca-client-conf 34 | endif 35 | 36 | if BUILD_SERVER 37 | install-data-local: install-nsca-server-conf 38 | uninstall-local: uninstall-nsca-server-conf 39 | endif 40 | 41 | # We use "test -r" because Solaris 10 doesn't provide "test -e". 42 | 43 | install-nsca-client-conf: 44 | $(AM_V_at)$(MKDIR_P) '$(DESTDIR)$(sysconfdir)' 45 | $(AM_V_at)if [ -r '$(DESTDIR)$(sysconfdir)/send_nsca.cfg' ]; then \ 46 | echo 'Preserving the installed send_nsca.cfg file.'; \ 47 | else \ 48 | $(INSTALL_DATA) '$(srcdir)/send_nsca.cfg' \ 49 | '$(DESTDIR)$(sysconfdir)'; \ 50 | fi 51 | 52 | install-nsca-server-conf: 53 | $(AM_V_at)$(MKDIR_P) '$(DESTDIR)$(sysconfdir)' 54 | $(AM_V_at)if [ -r '$(DESTDIR)$(sysconfdir)/nsca-ng.cfg' ]; then \ 55 | echo 'Preserving the installed nsca-ng.cfg file.'; \ 56 | else \ 57 | $(INSTALL_DATA) '$(srcdir)/nsca-ng.cfg' \ 58 | '$(DESTDIR)$(sysconfdir)'; \ 59 | fi 60 | 61 | uninstall-nsca-client-conf: 62 | $(AM_V_at)if cmp -s '$(srcdir)/send_nsca.cfg' \ 63 | '$(DESTDIR)$(sysconfdir)/send_nsca.cfg'; then \ 64 | rm -f '$(DESTDIR)$(sysconfdir)/send_nsca.cfg'; \ 65 | else \ 66 | echo 'Preserving the installed send_nsca.cfg file.'; \ 67 | fi 68 | 69 | uninstall-nsca-server-conf: 70 | $(AM_V_at)if cmp -s '$(srcdir)/nsca-ng.cfg' \ 71 | '$(DESTDIR)$(sysconfdir)/nsca-ng.cfg'; then \ 72 | rm -f '$(DESTDIR)$(sysconfdir)/nsca-ng.cfg'; \ 73 | else \ 74 | echo 'Preserving the installed nsca-ng.cfg file.'; \ 75 | fi 76 | -------------------------------------------------------------------------------- /etc/nsca-ng.cfg: -------------------------------------------------------------------------------- 1 | # 2 | # Sample configuration for nsca-ng(8). See the nsca-ng.cfg(5) man page. 3 | # 4 | # PLEASE SET THE PERMISSIONS OF THIS FILE APPROPRIATELY TO MAKE SURE THAT ONLY 5 | # AUTHORIZED USERS CAN ACCESS IT! 6 | # 7 | 8 | # 9 | # Most probably, you'll have to specify the path to the Nagios command file. 10 | # 11 | command_file = "/usr/local/nagios/var/rw/nagios.cmd" 12 | 13 | # 14 | # These configuration settings are optional. 15 | # 16 | # listen = "monitoring.example.com:5668" # Default: "*". 17 | # pid_file = "/var/run/nsca-ng.pid" # Default: create no PID file. 18 | # temp_directory = "/dev/shm" # Default: "/tmp". 19 | # tls_ciphers = "PSK-AES256-CBC-SHA" # Default: see nsca-ng.cfg(5). 20 | # chroot = "/usr/local/nagios/var" # Default: don't chroot(2). 21 | # user = "nagios" # Default: don't switch user. 22 | # log_level = 2 # Default: 3. 23 | # max_command_size = 65536 # Default: 16384. 24 | # max_queue_size = 128 # Default: 1024. 25 | # timeout = 15.0 # Default: 60.0. 26 | # 27 | 28 | # 29 | # Clients provide a client ID (think: user name) and a password. The same 30 | # ID/password combination may be used by multiple clients. In order to 31 | # authorize clients to submit check results and/or other external commands, at 32 | # least one "authorize" section must be specified. The client ID (which follows 33 | # the "authorize" keyword) may be "*". In this case, the block will be used as 34 | # fallback if no section is defined for a given client ID. No other wildcard 35 | # characters are available, and "*" has no special meaning unless the client ID 36 | # is exactly "*". 37 | # 38 | # Authorizations are specified using the "commands", "hosts, and/or "services" 39 | # variables within an "authorize" section. These variables are (lists of) 40 | # extended POSIX regular expressions (see the regex(7) man page), but with an 41 | # implicit leading "^" and trailing "$". The "commands" patterns are matched 42 | # against the full command string transmitted by the client, except for the 43 | # leading bracketed timestamp. The "hosts" and "services" variables are 44 | # syntactic sugar, e.g.: 45 | # 46 | # services = { 47 | # "http@web-server", 48 | # "disk" 49 | # } 50 | # 51 | # is equivalent to 52 | # 53 | # commands = { 54 | # "PROCESS_SERVICE_CHECK_RESULT;web-server;http;.+;.+", 55 | # "PROCESS_SERVICE_CHECK_RESULT;[^;]+;disk;.+;.+" 56 | # } 57 | # 58 | # Some examples: 59 | # 60 | # Authenticated "root" clients may submit arbitrary check results and any other 61 | # monitoring commands. 62 | # 63 | # authorize "root" { 64 | # password = "cM5vBM9CtCWTH1SwnxFEOfp8VAmQq2vd" 65 | # commands = ".*" 66 | # } 67 | # 68 | # Authenticated "checker" clients may submit arbitrary check results, but no 69 | # other commands. 70 | # 71 | # authorize "checker" { 72 | # password = "s2LDCy4CiK6yrlcHhTXT6agFh067XYE3" 73 | # hosts = ".*" 74 | # services = ".*" 75 | # } 76 | # 77 | # Authenticated "mail-checker" clients may submit check results for arbitrary 78 | # services on hosts whose names begin with "pop", "imap", or "smtp". 79 | # 80 | # authorize "mail-checker" { 81 | # password = "1HOiwYonRoLByCaX6lfY5KDhP484THzV" 82 | # services = { 83 | # ".+@pop.*", 84 | # ".+@imap.*", 85 | # ".+@smtp.*" 86 | # } 87 | # } 88 | # 89 | # Authenticated "system-checker" clients may submit check results for the 90 | # "disk", "swap", and "load" services on arbitrary hosts. 91 | # 92 | # authorize "system-checker" { 93 | # password = "rDCnSMFaM9wb5Yzjd6JwRcvHEwmC9ZlQ" 94 | # services = { 95 | # "disk", 96 | # "swap", 97 | # "load" 98 | # } 99 | # } 100 | # 101 | 102 | # 103 | # The "*" section applies when no other section matches the client's identity. 104 | # In order to authorize clients to actually submit check results (or other 105 | # commands), at least one "commands", "hosts", and/or "services" expression must 106 | # be specified. 107 | # 108 | authorize "*" { 109 | password = "change-me" 110 | # 111 | # The original NSCA server permits all authenticated clients to submit 112 | # arbitrary check results. To get this behaviour, enable the following 113 | # lines: 114 | # 115 | # hosts = ".*" 116 | # services = ".*" 117 | } 118 | 119 | # 120 | # Other files can be included. If a directory is specified, all "*.cfg" and 121 | # "*.conf" files within this directory and all subdirectories are included. 122 | # 123 | # include(nsca-ng.d/included.cfg) 124 | # 125 | -------------------------------------------------------------------------------- /etc/nsca-ng.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Monitoring Command Acceptor 3 | Documentation=man:nsca-ng(8) man:nsca-ng.cfg(5) 4 | Requires=nsca-ng.socket 5 | 6 | [Service] 7 | ExecStart=/usr/sbin/nsca-ng 8 | Type=notify 9 | User=nagios 10 | StandardError=syslog 11 | NonBlocking=true 12 | Restart=on-failure 13 | # Don't use this with systemd < 207 (see Red Hat bug #982379): 14 | WatchdogSec=30 15 | 16 | [Install] 17 | Also=nsca-ng.socket 18 | -------------------------------------------------------------------------------- /etc/nsca-ng.socket: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=NSCA-ng Socket 3 | Documentation=man:nsca-ng(8) man:nsca-ng.cfg(5) 4 | 5 | [Socket] 6 | ListenStream=5668 7 | BindIPv6Only=both 8 | 9 | [Install] 10 | WantedBy=sockets.target 11 | -------------------------------------------------------------------------------- /etc/send_nsca.cfg: -------------------------------------------------------------------------------- 1 | # 2 | # Sample configuration for send_nsca(8). See the send_nsca.cfg(5) man page. 3 | # 4 | # PLEASE SET THE PERMISSIONS OF THIS FILE APPROPRIATELY TO MAKE SURE THAT ONLY 5 | # AUTHORIZED USERS CAN ACCESS IT! 6 | # 7 | 8 | # identity = "web-checker" # Default: `hostname`. 9 | # password = "8a5UMsMzZhu6sSPkSmSaqC3HjMGCLwdt" # Default: "change-me". 10 | # server = "monitoring.example.com" # Default: "localhost". 11 | # tls_ciphers = "PSK-AES256-CBC-SHA" # See send_nsca.cfg(5). 12 | # delay = 2 # Default: 0. 13 | # port = 5668 # Default: 5668. 14 | # timeout = 10 # Default: 15. 15 | -------------------------------------------------------------------------------- /etc/valgrind.supp: -------------------------------------------------------------------------------- 1 | # CRYPTO_malloc is a malloc(3)-like function. 2 | { 3 | CRYPTO_malloc 4 | Memcheck:Leak 5 | fun:malloc 6 | fun:CRYPTO_malloc 7 | } 8 | 9 | # Ignore an SSL_accept issue. 10 | { 11 | SSL_accept 12 | Memcheck:Param 13 | write(buf) 14 | fun:__write_nocancel 15 | fun:sock_write 16 | fun:BIO_write 17 | fun:buffer_ctrl 18 | fun:ssl3_accept 19 | fun:ssl23_get_client_hello 20 | fun:ssl23_accept 21 | fun:accept_ssl_cb 22 | fun:ev_invoke_pending 23 | fun:ev_run 24 | fun:main 25 | } 26 | 27 | # Ignore an SSL_write issue. 28 | { 29 | SSL_write 30 | Memcheck:Param 31 | write(buf) 32 | fun:__write_nocancel 33 | fun:sock_write 34 | fun:BIO_write 35 | fun:ssl3_write_pending 36 | fun:ssl3_write_bytes 37 | fun:write_cb 38 | fun:ev_invoke_pending 39 | fun:ev_run 40 | fun:main 41 | } 42 | 43 | # We base64-encode random data. See: 44 | # 45 | # https://groups.google.com/group/comp.unix.programmer/msg/d62a0baba3c78b02 46 | { 47 | RAND_pseudo_bytes 48 | Memcheck:Value8 49 | fun:EVP_EncodeBlock 50 | fun:b64_write 51 | fun:BIO_write 52 | fun:main 53 | } 54 | -------------------------------------------------------------------------------- /lib/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake(1) to produce Makefile.in. 2 | 3 | ## Copyright (c) 2013 Holger Weiss 4 | ## All rights reserved. 5 | ## 6 | ## Redistribution and use in source and binary forms, with or without 7 | ## modification, are permitted provided that the following conditions are met: 8 | ## 9 | ## 1. Redistributions of source code must retain the above copyright notice, 10 | ## this list of conditions and the following disclaimer. 11 | ## 12 | ## 2. Redistributions in binary form must reproduce the above copyright notice, 13 | ## this list of conditions and the following disclaimer in the documentation 14 | ## and/or other materials provided with the distribution. 15 | ## 16 | ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | ## ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 | ## LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | ## CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | ## SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | ## INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | ## CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | ## ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | ## POSSIBILITY OF SUCH DAMAGE. 27 | 28 | if USE_EMBEDDED_EV 29 | MAYBE_EV = ev 30 | endif 31 | 32 | if USE_EMBEDDED_PIDFILE 33 | MAYBE_PIDFILE = pidfile 34 | endif 35 | 36 | SUBDIRS = $(MAYBE_EV) $(MAYBE_PIDFILE) 37 | 38 | AM_CPPFLAGS = -I$(top_srcdir)/src/common # For wrappers.c. 39 | 40 | noinst_LIBRARIES = libcompat.a 41 | libcompat_a_SOURCES = wrappers.c wrappers.h system.h 42 | libcompat_a_LIBADD = $(LIBOBJS) 43 | -------------------------------------------------------------------------------- /lib/daemon.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 Holger Weiss 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 19 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | * POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #if HAVE_CONFIG_H 29 | # include 30 | #endif 31 | 32 | #include 33 | #include 34 | #include 35 | #if HAVE_PATHS_H 36 | # include 37 | #endif 38 | #include 39 | #include 40 | 41 | #include "system.h" 42 | 43 | static int 44 | become_child(void) 45 | { 46 | switch (fork()) { 47 | case -1: 48 | return -1; 49 | case 0: 50 | return 0; 51 | default: 52 | _exit(EXIT_SUCCESS); 53 | } 54 | } 55 | 56 | int 57 | daemon(int nochdir, int noclose) 58 | { 59 | int fd; 60 | 61 | if (become_child() == -1) 62 | return -1; 63 | if (setsid() == -1) 64 | return -1; 65 | if (become_child() == -1) 66 | return -1; 67 | 68 | if (!nochdir) 69 | (void)chdir("/"); 70 | 71 | if (!noclose && (fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) { 72 | (void)dup2(fd, STDIN_FILENO); 73 | (void)dup2(fd, STDOUT_FILENO); 74 | (void)dup2(fd, STDERR_FILENO); 75 | if (fd > STDERR_FILENO) 76 | (void)close(fd); 77 | } 78 | return 0; 79 | } 80 | 81 | /* vim:set joinspaces noexpandtab textwidth=80 cinoptions=(4,u0: */ 82 | -------------------------------------------------------------------------------- /lib/ev/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake(1) to produce Makefile.in. 2 | 3 | ## Copyright (c) 2013 Holger Weiss 4 | ## All rights reserved. 5 | ## 6 | ## Redistribution and use in source and binary forms, with or without 7 | ## modification, are permitted provided that the following conditions are met: 8 | ## 9 | ## 1. Redistributions of source code must retain the above copyright notice, 10 | ## this list of conditions and the following disclaimer. 11 | ## 12 | ## 2. Redistributions in binary form must reproduce the above copyright notice, 13 | ## this list of conditions and the following disclaimer in the documentation 14 | ## and/or other materials provided with the distribution. 15 | ## 16 | ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | ## ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 | ## LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | ## CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | ## SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | ## INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | ## CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | ## ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | ## POSSIBILITY OF SUCH DAMAGE. 27 | 28 | # We don't maintain the libev code, so lets ignore any warnings. 29 | if GCC 30 | AM_CFLAGS = -w 31 | endif 32 | 33 | noinst_LIBRARIES = libev.a 34 | libev_a_SOURCES = ev.c ev.h ev_vars.h ev_wrap.h 35 | EXTRA_libev_a_SOURCES = ev_epoll.c ev_kqueue.c ev_poll.c ev_port.c ev_select.c \ 36 | ev_win32.c 37 | EXTRA_DIST = libev.m4 38 | -------------------------------------------------------------------------------- /lib/ev/ev_poll.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libev poll fd activity backend 3 | * 4 | * Copyright (c) 2007,2008,2009,2010,2011 Marc Alexander Lehmann 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without modifica- 8 | * tion, are permitted provided that the following conditions are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 18 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER- 19 | * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 20 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE- 21 | * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 22 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 23 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTH- 25 | * ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 26 | * OF THE POSSIBILITY OF SUCH DAMAGE. 27 | * 28 | * Alternatively, the contents of this file may be used under the terms of 29 | * the GNU General Public License ("GPL") version 2 or any later version, 30 | * in which case the provisions of the GPL are applicable instead of 31 | * the above. If you wish to allow the use of your version of this file 32 | * only under the terms of the GPL and not to allow others to use your 33 | * version of this file under the BSD license, indicate your decision 34 | * by deleting the provisions above and replace them with the notice 35 | * and other provisions required by the GPL. If you do not delete the 36 | * provisions above, a recipient may use your version of this file under 37 | * either the BSD or the GPL. 38 | */ 39 | 40 | #include 41 | 42 | inline_size 43 | void 44 | pollidx_init (int *base, int count) 45 | { 46 | /* consider using memset (.., -1, ...), which is practically guaranteed 47 | * to work on all systems implementing poll */ 48 | while (count--) 49 | *base++ = -1; 50 | } 51 | 52 | static void 53 | poll_modify (EV_P_ int fd, int oev, int nev) 54 | { 55 | int idx; 56 | 57 | if (oev == nev) 58 | return; 59 | 60 | array_needsize (int, pollidxs, pollidxmax, fd + 1, pollidx_init); 61 | 62 | idx = pollidxs [fd]; 63 | 64 | if (idx < 0) /* need to allocate a new pollfd */ 65 | { 66 | pollidxs [fd] = idx = pollcnt++; 67 | array_needsize (struct pollfd, polls, pollmax, pollcnt, EMPTY2); 68 | polls [idx].fd = fd; 69 | } 70 | 71 | assert (polls [idx].fd == fd); 72 | 73 | if (nev) 74 | polls [idx].events = 75 | (nev & EV_READ ? POLLIN : 0) 76 | | (nev & EV_WRITE ? POLLOUT : 0); 77 | else /* remove pollfd */ 78 | { 79 | pollidxs [fd] = -1; 80 | 81 | if (expect_true (idx < --pollcnt)) 82 | { 83 | polls [idx] = polls [pollcnt]; 84 | pollidxs [polls [idx].fd] = idx; 85 | } 86 | } 87 | } 88 | 89 | static void 90 | poll_poll (EV_P_ ev_tstamp timeout) 91 | { 92 | struct pollfd *p; 93 | int res; 94 | 95 | EV_RELEASE_CB; 96 | res = poll (polls, pollcnt, timeout * 1e3); 97 | EV_ACQUIRE_CB; 98 | 99 | if (expect_false (res < 0)) 100 | { 101 | if (errno == EBADF) 102 | fd_ebadf (EV_A); 103 | else if (errno == ENOMEM && !syserr_cb) 104 | fd_enomem (EV_A); 105 | else if (errno != EINTR) 106 | ev_syserr ("(libev) poll"); 107 | } 108 | else 109 | for (p = polls; res; ++p) 110 | { 111 | assert (("libev: poll() returned illegal result, broken BSD kernel?", p < polls + pollcnt)); 112 | 113 | if (expect_false (p->revents)) /* this expect is debatable */ 114 | { 115 | --res; 116 | 117 | if (expect_false (p->revents & POLLNVAL)) 118 | fd_kill (EV_A_ p->fd); 119 | else 120 | fd_event ( 121 | EV_A_ 122 | p->fd, 123 | (p->revents & (POLLOUT | POLLERR | POLLHUP) ? EV_WRITE : 0) 124 | | (p->revents & (POLLIN | POLLERR | POLLHUP) ? EV_READ : 0) 125 | ); 126 | } 127 | } 128 | } 129 | 130 | inline_size 131 | int 132 | poll_init (EV_P_ int flags) 133 | { 134 | backend_mintime = 1e-3; 135 | backend_modify = poll_modify; 136 | backend_poll = poll_poll; 137 | 138 | pollidxs = 0; pollidxmax = 0; 139 | polls = 0; pollmax = 0; pollcnt = 0; 140 | 141 | return EVBACKEND_POLL; 142 | } 143 | 144 | inline_size 145 | void 146 | poll_destroy (EV_P) 147 | { 148 | ev_free (pollidxs); 149 | ev_free (polls); 150 | } 151 | 152 | -------------------------------------------------------------------------------- /lib/ev/libev.m4: -------------------------------------------------------------------------------- 1 | dnl this file is part of libev, do not make local modifications 2 | dnl http://software.schmorp.de/pkg/libev 3 | 4 | dnl libev support 5 | AC_CHECK_HEADERS(sys/inotify.h sys/epoll.h sys/event.h port.h poll.h sys/select.h sys/eventfd.h sys/signalfd.h) 6 | 7 | AC_CHECK_FUNCS(inotify_init epoll_ctl kqueue port_create poll select eventfd signalfd) 8 | 9 | AC_CHECK_FUNCS(clock_gettime, [], [ 10 | dnl on linux, try syscall wrapper first 11 | if test $(uname) = Linux; then 12 | AC_MSG_CHECKING(for clock_gettime syscall) 13 | AC_LINK_IFELSE([AC_LANG_PROGRAM( 14 | [#include 15 | #include 16 | #include ], 17 | [struct timespec ts; int status = syscall (SYS_clock_gettime, CLOCK_REALTIME, &ts)])], 18 | [ac_have_clock_syscall=1 19 | AC_DEFINE(HAVE_CLOCK_SYSCALL, 1, Define to 1 to use the syscall interface for clock_gettime) 20 | AC_MSG_RESULT(yes)], 21 | [AC_MSG_RESULT(no)]) 22 | fi 23 | if test -z "$LIBEV_M4_AVOID_LIBRT" && test -z "$ac_have_clock_syscall"; then 24 | AC_CHECK_LIB(rt, clock_gettime) 25 | unset ac_cv_func_clock_gettime 26 | AC_CHECK_FUNCS(clock_gettime) 27 | fi 28 | ]) 29 | 30 | AC_CHECK_FUNCS(nanosleep, [], [ 31 | if test -z "$LIBEV_M4_AVOID_LIBRT"; then 32 | AC_CHECK_LIB(rt, nanosleep) 33 | unset ac_cv_func_nanosleep 34 | AC_CHECK_FUNCS(nanosleep) 35 | fi 36 | ]) 37 | 38 | if test -z "$LIBEV_M4_AVOID_LIBM"; then 39 | LIBM=m 40 | fi 41 | AC_SEARCH_LIBS(floor, $LIBM, [AC_DEFINE(HAVE_FLOOR, 1, Define to 1 if the floor function is available)]) 42 | 43 | -------------------------------------------------------------------------------- /lib/pidfile/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake(1) to produce Makefile.in. 2 | 3 | ## Copyright (c) 2013 Holger Weiss 4 | ## All rights reserved. 5 | ## 6 | ## Redistribution and use in source and binary forms, with or without 7 | ## modification, are permitted provided that the following conditions are met: 8 | ## 9 | ## 1. Redistributions of source code must retain the above copyright notice, 10 | ## this list of conditions and the following disclaimer. 11 | ## 12 | ## 2. Redistributions in binary form must reproduce the above copyright notice, 13 | ## this list of conditions and the following disclaimer in the documentation 14 | ## and/or other materials provided with the distribution. 15 | ## 16 | ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | ## ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 | ## LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | ## CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | ## SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | ## INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | ## CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | ## ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | ## POSSIBILITY OF SUCH DAMAGE. 27 | 28 | AM_CPPFLAGS = -I$(top_srcdir)/lib 29 | 30 | noinst_LIBRARIES = libpidfile.a 31 | libpidfile_a_SOURCES = flopen.c libutil.h pidfile.c 32 | 33 | if !HAVE_FLOCK 34 | libpidfile_a_SOURCES += flock.c 35 | endif 36 | -------------------------------------------------------------------------------- /lib/pidfile/flock.c: -------------------------------------------------------------------------------- 1 | /* $NetBSD: flock.c,v 1.6 2008/04/28 20:24:12 martin Exp $ */ 2 | 3 | /*- 4 | * Copyright (c) 2001 The NetBSD Foundation, Inc. 5 | * All rights reserved. 6 | * 7 | * This code is derived from software contributed to The NetBSD Foundation 8 | * by Todd Vierling. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | /* 33 | * This is the file src/tools/compat/flock.c taken from NetBSD 6.0 and slightly 34 | * modified by Holger Weiss in 2012. 35 | */ 36 | 37 | /* 38 | * Emulate flock() with fcntl(), where available. Otherwise, don't do locking; 39 | * just pretend success. 40 | */ 41 | 42 | #if HAVE_CONFIG_H 43 | # include 44 | #endif 45 | 46 | #include 47 | #include 48 | 49 | #include "libutil.h" 50 | #include "system.h" 51 | 52 | int 53 | flock(int fd, int op) 54 | { 55 | int rc = 0; 56 | 57 | #if defined(F_SETLK) && defined(F_SETLKW) 58 | struct flock fl = {0}; 59 | 60 | switch (op & (LOCK_EX|LOCK_SH|LOCK_UN)) { 61 | case LOCK_EX: 62 | fl.l_type = F_WRLCK; 63 | break; 64 | 65 | case LOCK_SH: 66 | fl.l_type = F_RDLCK; 67 | break; 68 | 69 | case LOCK_UN: 70 | fl.l_type = F_UNLCK; 71 | break; 72 | 73 | default: 74 | errno = EINVAL; 75 | return -1; 76 | } 77 | 78 | fl.l_whence = SEEK_SET; 79 | rc = fcntl(fd, op & LOCK_NB ? F_SETLK : F_SETLKW, &fl); 80 | 81 | if (rc && (errno == EAGAIN)) 82 | errno = EWOULDBLOCK; 83 | #endif 84 | return rc; 85 | } 86 | -------------------------------------------------------------------------------- /lib/pidfile/flopen.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2007 Dag-Erling Coïdan Smørgrav 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer 10 | * in this position and unchanged. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 | * SUCH DAMAGE. 26 | */ 27 | 28 | /* 29 | * This is the file lib/libutil/flopen.c taken from FreeBSD's SVN trunk as of 30 | * 2012-10-30 and modified by Holger Weiss in 2012. 31 | */ 32 | 33 | #if HAVE_CONFIG_H 34 | # include 35 | #endif 36 | 37 | #if HAVE_SYS_FILE_H 38 | # include 39 | #endif 40 | #include 41 | 42 | #include 43 | #include 44 | #include 45 | 46 | #include "libutil.h" 47 | #include "system.h" 48 | 49 | int 50 | flopen(const char *path, int flags, ...) 51 | { 52 | int fd, operation, serrno, trunc; 53 | struct stat sb, fsb; 54 | mode_t mode; 55 | 56 | #ifdef O_EXLOCK 57 | flags &= ~O_EXLOCK; 58 | #endif 59 | 60 | mode = 0; 61 | if (flags & O_CREAT) { 62 | va_list ap; 63 | 64 | va_start(ap, flags); 65 | mode = (mode_t)va_arg(ap, int); /* mode_t promoted to int */ 66 | va_end(ap); 67 | } 68 | 69 | operation = LOCK_EX; 70 | if (flags & O_NONBLOCK) 71 | operation |= LOCK_NB; 72 | 73 | trunc = (flags & O_TRUNC); 74 | flags &= ~O_TRUNC; 75 | 76 | for (;;) { 77 | if ((fd = open(path, flags, mode)) == -1) 78 | /* non-existent or no access */ 79 | return (-1); 80 | if (flock(fd, operation) == -1) { 81 | /* unsupported or interrupted */ 82 | serrno = errno; 83 | (void)close(fd); 84 | errno = serrno; 85 | return (-1); 86 | } 87 | if (stat(path, &sb) == -1) { 88 | /* disappeared from under our feet */ 89 | (void)close(fd); 90 | continue; 91 | } 92 | if (fstat(fd, &fsb) == -1) { 93 | /* can't happen [tm] */ 94 | serrno = errno; 95 | (void)close(fd); 96 | errno = serrno; 97 | return (-1); 98 | } 99 | if (sb.st_dev != fsb.st_dev || 100 | sb.st_ino != fsb.st_ino) { 101 | /* changed under our feet */ 102 | (void)close(fd); 103 | continue; 104 | } 105 | if (trunc && ftruncate(fd, 0) != 0) { 106 | /* can't happen [tm] */ 107 | serrno = errno; 108 | (void)close(fd); 109 | errno = serrno; 110 | return (-1); 111 | } 112 | return (fd); 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /lib/pidfile/libutil.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 Holger Weiss 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 19 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | * POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef LIBUTIL_H 29 | # define LIBUTIL_H 30 | 31 | # if HAVE_CONFIG_H 32 | # include 33 | # endif 34 | 35 | # include 36 | # include 37 | # include 38 | 39 | # ifndef HAVE_FLOCK 40 | int flock(int, int); 41 | # ifndef LOCK_SH 42 | # define LOCK_SH 1 43 | # endif 44 | # ifndef LOCK_EX 45 | # define LOCK_EX 2 46 | # endif 47 | # ifndef LOCK_NB 48 | # define LOCK_NB 4 49 | # endif 50 | # ifndef LOCK_UN 51 | # define LOCK_UN 8 52 | # endif 53 | # endif 54 | 55 | struct pidfh; 56 | 57 | int flopen(const char *, int, ...); 58 | struct pidfh *pidfile_open(const char *, mode_t, pid_t *); 59 | int pidfile_write(struct pidfh *); 60 | int pidfile_remove(struct pidfh *); 61 | int pidfile_close(struct pidfh *); 62 | int pidfile_fileno(const struct pidfh *); 63 | 64 | #endif 65 | 66 | /* vim:set joinspaces noexpandtab textwidth=80 cinoptions=(4,u0: */ 67 | -------------------------------------------------------------------------------- /lib/progname.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 Holger Weiss 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 19 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | * POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #if HAVE_CONFIG_H 29 | # include 30 | #endif 31 | 32 | #include 33 | 34 | #include "system.h" 35 | 36 | static const char *progname; 37 | 38 | const char * 39 | getprogname(void) 40 | { 41 | return progname; 42 | } 43 | 44 | void 45 | setprogname(const char *path) 46 | { 47 | const char *p; 48 | 49 | if ((p = strrchr(path, '/')) == NULL) 50 | p = path; 51 | else 52 | p++; 53 | 54 | progname = p; 55 | } 56 | 57 | /* vim:set joinspaces noexpandtab textwidth=80 cinoptions=(4,u0: */ 58 | -------------------------------------------------------------------------------- /lib/strcasecmp.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 Holger Weiss 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 19 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | * POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #if HAVE_CONFIG_H 29 | # include 30 | #endif 31 | 32 | #include 33 | 34 | #include "system.h" 35 | 36 | int 37 | strcasecmp(const char *s1, const char *s2) 38 | { 39 | size_t i = 0; 40 | int c1, c2; 41 | 42 | while ((c1 = tolower(s1[i])) == (c2 = tolower(s2[i]))) { 43 | if (s1[i] == '\0') 44 | return 0; 45 | i++; 46 | } 47 | return c1 - c2; 48 | } 49 | 50 | /* vim:set joinspaces noexpandtab textwidth=80 cinoptions=(4,u0: */ 51 | -------------------------------------------------------------------------------- /lib/strdup.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 Holger Weiss 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 19 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | * POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #if HAVE_CONFIG_H 29 | # include 30 | #endif 31 | 32 | #include 33 | #include 34 | 35 | #include "system.h" 36 | 37 | char * 38 | strdup(const char *string) 39 | { 40 | char *new; 41 | size_t size = strlen(string) + 1; 42 | 43 | if ((new = malloc(size)) == NULL) 44 | return NULL; 45 | return memcpy(new, string, size); 46 | } 47 | 48 | /* vim:set joinspaces noexpandtab textwidth=80 cinoptions=(4,u0: */ 49 | -------------------------------------------------------------------------------- /lib/strncasecmp.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 Holger Weiss 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 19 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | * POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #if HAVE_CONFIG_H 29 | # include 30 | #endif 31 | 32 | #include 33 | #include /* For size_t. */ 34 | 35 | #include "system.h" 36 | 37 | int 38 | strncasecmp(const char *s1, const char *s2, size_t n) 39 | { 40 | size_t i; 41 | 42 | for (i = 0; i < n; i++) { 43 | int c1 = tolower(s1[i]); 44 | int c2 = tolower(s2[i]); 45 | 46 | if (c1 != c2) 47 | return c1 - c2; 48 | if (s1[i] == '\0') 49 | break; 50 | } 51 | return 0; 52 | } 53 | 54 | /* vim:set joinspaces noexpandtab textwidth=80 cinoptions=(4,u0: */ 55 | -------------------------------------------------------------------------------- /lib/system.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 Holger Weiss 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 19 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | * POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef NSCA_NG_H 29 | # define NSCA_NG_H 30 | 31 | # if HAVE_CONFIG_H 32 | # include 33 | # endif 34 | 35 | # include /* For size_t. */ 36 | 37 | /* 38 | * Turn __attribute__() into a no-op unless GCC is used. 39 | */ 40 | # ifndef __GNUC__ 41 | # define __attribute__(x) /* Nothing. */ 42 | # endif 43 | 44 | /* 45 | * Define the bool type. 46 | */ 47 | # if HAVE_STDBOOL_H 48 | # include 49 | # else 50 | # if HAVE__BOOL 51 | # ifdef __cplusplus 52 | typedef bool _Bool; 53 | # else 54 | # define _Bool signed char 55 | # endif 56 | # endif 57 | # define bool _Bool 58 | # define false 0 59 | # define true 1 60 | # define __bool_true_false_are_defined 1 61 | # endif 62 | 63 | /* 64 | * Make sure EWOULDBLOCK is defined. 65 | */ 66 | # ifndef EWOULDBLOCK 67 | # define EWOULDBLOCK EAGAIN 68 | # endif 69 | 70 | /* 71 | * Define a MIN() macro. 72 | */ 73 | # ifdef MIN 74 | # undef MIN 75 | # endif 76 | # define MIN(x, y) ((x) < (y) ? (x) : (y)) 77 | 78 | /* 79 | * For building without systemd(1) support. 80 | */ 81 | # ifndef SD_LISTEN_FDS_START 82 | # define SD_LISTEN_FDS_START 3 83 | # endif 84 | # ifndef HAVE_SYSTEMD_SD_DAEMON_H 85 | # define sd_notify(a, b) 0 86 | # define sd_listen_fds(a) 0 87 | # endif 88 | 89 | /* 90 | * Declare replacement functions (if necessary). 91 | */ 92 | # ifndef HAVE_DAEMON 93 | int daemon(int, int); 94 | # endif 95 | # ifndef HAVE_GETPROGNAME 96 | const char *getprogname(void); 97 | # endif 98 | # ifndef HAVE_SETPROGNAME 99 | void setprogname(const char *); 100 | # endif 101 | # ifndef HAVE_STRDUP 102 | char *strdup(const char *); 103 | # endif 104 | # ifndef HAVE_STRCASECMP 105 | int strcasecmp(const char *, const char *); 106 | # endif 107 | # ifndef HAVE_STRNCASECMP 108 | int strncasecmp(const char *, const char *, size_t); 109 | # endif 110 | 111 | # if !HAVE_SNPRINTF || !HAVE_VSNPRINTF || !HAVE_ASPRINTF || !HAVE_VASPRINTF 112 | # if HAVE_STDARG_H 113 | # include 114 | # if !HAVE_VSNPRINTF 115 | int rpl_vsnprintf(char *, size_t, const char *, va_list); 116 | # endif 117 | # if !HAVE_SNPRINTF 118 | int rpl_snprintf(char *, size_t, const char *, ...); 119 | # endif 120 | # if !HAVE_VASPRINTF 121 | int rpl_vasprintf(char **, const char *, va_list); 122 | # endif 123 | # if !HAVE_ASPRINTF 124 | int rpl_asprintf(char **, const char *, ...); 125 | # endif 126 | # endif 127 | # endif 128 | 129 | #endif 130 | 131 | /* vim:set joinspaces noexpandtab textwidth=80 cinoptions=(4,u0: */ 132 | -------------------------------------------------------------------------------- /lib/wrappers.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 Holger Weiss 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 19 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | * POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #if HAVE_CONFIG_H 29 | # include 30 | #endif 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | #include "log.h" 37 | #include "system.h" 38 | #include "wrappers.h" 39 | 40 | void * 41 | xmalloc(size_t size) 42 | { 43 | void *new; 44 | 45 | if ((new = malloc(size)) == NULL) 46 | die("Error: Cannot allocate %zu bytes", size); 47 | 48 | return new; 49 | } 50 | 51 | void * 52 | xrealloc(void *p, size_t size) 53 | { 54 | void *new; 55 | 56 | if ((new = realloc(p, size)) == NULL) { 57 | free(p); 58 | die("Cannot reallocate %zu bytes: %m", size); 59 | } 60 | return new; 61 | } 62 | 63 | char * 64 | xstrdup(const char *string) 65 | { 66 | char *new; 67 | 68 | if ((new = strdup(string)) == NULL) 69 | die("Cannot duplicate string: %m"); 70 | 71 | return new; 72 | } 73 | 74 | void 75 | xasprintf(char ** restrict result, const char * restrict format, ...) 76 | { 77 | va_list ap; 78 | 79 | va_start(ap, format); 80 | xvasprintf(result, format, ap); 81 | va_end(ap); 82 | } 83 | 84 | void 85 | xvasprintf(char ** restrict result, const char * restrict format, va_list ap) 86 | { 87 | if (vasprintf(result, format, ap) < 0) 88 | die("Cannot create buffer with formatted output"); 89 | } 90 | 91 | size_t 92 | xfgets(char * restrict buf, int size, FILE * restrict fp) 93 | { 94 | size_t len; 95 | 96 | if (fgets(buf, size, fp) != NULL) 97 | len = strlen(buf); 98 | else { 99 | if (ferror(fp)) 100 | die("Cannot read input stream: %m"); 101 | len = 0; 102 | } 103 | return len; 104 | } 105 | 106 | /* vim:set joinspaces noexpandtab textwidth=80 cinoptions=(4,u0: */ 107 | -------------------------------------------------------------------------------- /lib/wrappers.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 Holger Weiss 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 19 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | * POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef XLIB_H 29 | # define XLIB_H 30 | 31 | # if HAVE_CONFIG_H 32 | # include 33 | # endif 34 | 35 | # include 36 | # include 37 | 38 | void *xmalloc(size_t); 39 | void *xrealloc(void *, size_t); 40 | char *xstrdup(const char *); 41 | void xasprintf(char ** restrict, const char * restrict, ...); 42 | void xvasprintf(char ** restrict, const char * restrict, va_list); 43 | size_t xfgets(char * restrict, int, FILE * restrict); 44 | 45 | #endif 46 | 47 | /* vim:set joinspaces noexpandtab textwidth=80 cinoptions=(4,u0: */ 48 | -------------------------------------------------------------------------------- /m4/confuse.m4: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013 Holger Weiss 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without 5 | # modification, are permitted provided that the following conditions are met: 6 | # 7 | # 1. Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # 2. Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | 25 | # NSCA_LIB_CONFUSE 26 | # ---------------- 27 | # Check the availability of libConfuse 2.6 or newer. As this is a required 28 | # dependency, we bail out if the user specified "--without-confuse", if we fail 29 | # to link against the library, or if the confuse version we found is too old. 30 | # On success, we set the output variables CONFUSECPPFLAGS, CONFUSELDFLAGS, and 31 | # CONFUSELIBS to appropriate values. (Why are there no underscores in these 32 | # variable names? Because Automake treats names like "foo_CPPFLAGS" specially.) 33 | AC_DEFUN([NSCA_LIB_CONFUSE], 34 | [ 35 | nsca_save_CPPFLAGS=$CPPFLAGS 36 | nsca_save_LDFLAGS=$LDFLAGS 37 | AC_ARG_WITH([confuse], 38 | [AS_HELP_STRING([--with-confuse=PATH], 39 | [use the libConfuse library in PATH])], 40 | [nsca_confuse_dir=$with_confuse], 41 | [nsca_confuse_dir=yes]) 42 | AC_MSG_CHECKING([whether libConfuse is desired]) 43 | AS_CASE([$nsca_confuse_dir], 44 | [no], 45 | [AC_MSG_RESULT([no]) 46 | AC_MSG_ERROR([building without libConfuse is not supported])], 47 | [yes], 48 | [AC_MSG_RESULT([yes]) 49 | AC_MSG_CHECKING([for the location of libConfuse]) 50 | nsca_confuse_dir=unknown 51 | for _nsca_confuse_dir in "$ac_pwd/lib/confuse" /usr /usr/local /usr/pkg 52 | do dnl Solaris 10 doesn't have "test -e". 53 | AS_IF([test -r "$_nsca_confuse_dir/include/confuse.h"], 54 | [nsca_confuse_dir=$_nsca_confuse_dir 55 | break]) 56 | done 57 | AS_IF([test "x$nsca_confuse_dir" != xunknown], 58 | [AC_MSG_RESULT([$nsca_confuse_dir])], 59 | [AC_MSG_RESULT([not found, continuing anyway])])], 60 | [AC_MSG_RESULT([yes])]) 61 | AS_IF([test "x$nsca_confuse_dir" != xunknown && 62 | test "x$nsca_confuse_dir" != x/usr], 63 | [CONFUSECPPFLAGS="-I$nsca_confuse_dir/include" 64 | CONFUSELDFLAGS="-L$nsca_confuse_dir/lib" 65 | CPPFLAGS="$CONFUSECPPFLAGS $CPPFLAGS" 66 | LDFLAGS="$CONFUSELDFLAGS $LDFLAGS"]) 67 | AC_CHECK_HEADER([confuse.h], [], 68 | [AC_MSG_ERROR([libConfuse header file not found])]) 69 | AC_CHECK_LIB([confuse], [cfg_init], 70 | [CONFUSELIBS='-lconfuse'], 71 | [AC_CHECK_LIB([intl], [cfg_init], 72 | [CONFUSELIBS='-lconfuse -lintl'], 73 | [AC_CHECK_LIB([iconv], [cfg_init], 74 | [CONFUSELIBS='-lconfuse -lintl -liconv'], 75 | [AC_MSG_FAILURE([cannot link with libConfuse])], 76 | [-lconfuse -lintl -liconv])], 77 | [-lconfuse -lintl])]) 78 | AC_CHECK_DECL([CFGF_NO_TITLE_DUPES], [], 79 | [AC_MSG_ERROR([libConfuse too old, version 2.6 or newer is required])], 80 | [[#include ]]) 81 | AC_SUBST([CONFUSECPPFLAGS]) 82 | AC_SUBST([CONFUSELDFLAGS]) 83 | AC_SUBST([CONFUSELIBS]) 84 | CPPFLAGS=$nsca_save_CPPFLAGS 85 | LDFLAGS=$nsca_save_LDFLAGS 86 | ])# NSCA_LIB_CONFUSE 87 | 88 | dnl vim:set joinspaces textwidth=80: 89 | -------------------------------------------------------------------------------- /m4/daemon.m4: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013 Holger Weiss 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without 5 | # modification, are permitted provided that the following conditions are met: 6 | # 7 | # 1. Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # 2. Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | 25 | # NSCA_FUNC_DAEMON 26 | # ---------------- 27 | # Check the availability of a BSD-style daemon(3) function. If no such function 28 | # is found, arrange for using the bundled implementation. 29 | AC_DEFUN([NSCA_FUNC_DAEMON], 30 | [ 31 | AC_CHECK_FUNC([daemon], 32 | [AC_DEFINE([HAVE_DAEMON], [1], 33 | [Define to 1 if you have the `daemon' function.])], 34 | [AC_LIBOBJ([daemon]) 35 | AC_CHECK_HEADERS([paths.h]) 36 | AC_CHECK_DECL([_PATH_DEVNULL], [], 37 | [AC_DEFINE([_PATH_DEVNULL], ["/dev/null"], 38 | [Define to the path of the `null' device.])], 39 | [[#ifdef HAVE_PATHS_H 40 | #include 41 | #endif]])]) 42 | ])# NSCA_FUNC_DAEMON 43 | 44 | dnl vim:set joinspaces textwidth=80: 45 | -------------------------------------------------------------------------------- /m4/networking.m4: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013 Holger Weiss 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without 5 | # modification, are permitted provided that the following conditions are met: 6 | # 7 | # 1. Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # 2. Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | 25 | # NSCA_LIB_NETWORKING 26 | # ------------------- 27 | # Check the availability of some networking header files and types. Also, find 28 | # out which libraries define the networking functions we're interested in and 29 | # add the according flags to LIBS. We bail out if any of these functions aren't 30 | # found. 31 | AC_DEFUN([NSCA_LIB_NETWORKING], 32 | [ 33 | AC_CHECK_HEADERS([arpa/inet.h netinet/in.h sys/socket.h]) 34 | AC_CHECK_TYPES([struct sockaddr_storage, struct sockaddr_in6], [], [], 35 | [[#include 36 | #ifdef HAVE_SYS_SOCKET_H 37 | #include 38 | #endif 39 | #ifdef HAVE_NETINET_IN_H 40 | #include 41 | #endif]]) 42 | # Solaris 8 and newer provide the inet_ntop(3) function in libnsl, older 43 | # Solaris versions provide inet_ntop(3) in libresolv instead. 44 | AC_SEARCH_LIBS([inet_ntop], [nsl resolv], [], 45 | [AC_MSG_FAILURE([cannot find the `inet_ntop' function])]) 46 | # The libsocket library might or might not depend on libnsl. 47 | AC_SEARCH_LIBS([getpeername], [socket], [], 48 | [AC_CHECK_LIB([nsl], [getpeername], 49 | [LIBS="-lsocket -lnsl $LIBS"], 50 | [AC_MSG_FAILURE([cannot find the `getpeername' function])], 51 | [-lsocket -lnsl])]) 52 | ])# NSCA_LIB_NETWORKING 53 | 54 | dnl vim:set joinspaces textwidth=80: 55 | -------------------------------------------------------------------------------- /m4/openssl.m4: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013 Holger Weiss 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without 5 | # modification, are permitted provided that the following conditions are met: 6 | # 7 | # 1. Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # 2. Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | 25 | # NSCA_LIB_OPENSSL 26 | # ---------------- 27 | # Check the availability of OpenSSL 1.0.0 or newer. As this is a required 28 | # dependency, we bail out if the user specified "--without-openssl", if we fail 29 | # to link against the library, or if the OpenSSL version we found is too old. 30 | # On success, we set the output variables SSLCPPFLAGS, SSLLDFLAGS, and SSLLIBS 31 | # to appropriate values. (Why are there no underscores in these variable names? 32 | # Because Automake treats names like "foo_CPPFLAGS" specially.) 33 | AC_DEFUN([NSCA_LIB_OPENSSL], 34 | [ 35 | nsca_save_CPPFLAGS=$CPPFLAGS 36 | nsca_save_LDFLAGS=$LDFLAGS 37 | AC_ARG_WITH([openssl], 38 | [AS_HELP_STRING([--with-openssl=PATH], 39 | [use the OpenSSL library in PATH])], 40 | [nsca_ssl_dir=$with_openssl], 41 | [nsca_ssl_dir=yes]) 42 | AC_MSG_CHECKING([whether OpenSSL is desired]) 43 | AS_CASE([$nsca_ssl_dir], 44 | [no], 45 | [AC_MSG_RESULT([no]) 46 | AC_MSG_ERROR([building without OpenSSL is not supported])], 47 | [yes], 48 | [AC_MSG_RESULT([yes]) 49 | AC_MSG_CHECKING([for the location of OpenSSL]) 50 | nsca_ssl_dir=unknown 51 | for _nsca_ssl_dir in "$ac_pwd/lib/ssl" /usr /usr/local /usr/local/ssl \ 52 | /usr/pkg 53 | do dnl Solaris 10 doesn't have "test -e". 54 | AS_IF([test -r "$_nsca_ssl_dir/include/openssl/ssl.h"], 55 | [nsca_ssl_dir=$_nsca_ssl_dir 56 | break]) 57 | done 58 | AS_IF([test "x$nsca_ssl_dir" != xunknown], 59 | [AC_MSG_RESULT([$nsca_ssl_dir])], 60 | [AC_MSG_RESULT([not found, continuing anyway])])], 61 | [AC_MSG_RESULT([yes])]) 62 | AS_IF([test "x$nsca_ssl_dir" != xunknown && test "x$nsca_ssl_dir" != x/usr], 63 | [SSLCPPFLAGS="-I$nsca_ssl_dir/include" 64 | SSLLDFLAGS="-L$nsca_ssl_dir/lib" 65 | CPPFLAGS="$SSLCPPFLAGS $CPPFLAGS" 66 | LDFLAGS="$SSLLDFLAGS $LDFLAGS"]) 67 | AC_CHECK_HEADER([openssl/ssl.h], [], 68 | [AC_MSG_ERROR([OpenSSL header files not found])]) 69 | AC_CHECK_LIB([crypto], [BIO_new], 70 | [SSLLIBS='-lcrypto'], 71 | [AC_CHECK_LIB([crypto], [BIO_push], 72 | [SSLLIBS='-lcrypto -ldl'], 73 | [AC_CHECK_LIB([crypto], [BIO_pop], 74 | [SSLLIBS='-lcrypto -ldl -lpthread'], 75 | [AC_MSG_FAILURE([cannot link with OpenSSL])], 76 | [-lcrypto -ldl -lpthread])], 77 | [-lcrypto -ldl])]) 78 | AC_CHECK_LIB([crypto], [RAND_bytes], 79 | [AC_DEFINE([HAVE_RAND_BYTES], [1], 80 | [Define to 1 if you have the `RAND_bytes' function.])], [], 81 | [$SSLLIBS]) 82 | AC_CHECK_LIB([ssl], [SSL_new], 83 | [SSLLIBS="-lssl $SSLLIBS"], 84 | [AC_MSG_FAILURE([cannot link with OpenSSL])], 85 | [$SSLLIBS]) 86 | AC_CHECK_LIB([ssl], [SSL_get_psk_identity], [:], 87 | [AC_MSG_ERROR([OpenSSL too old, version 1.0.0 or newer is required])], 88 | [$SSLLIBS]) 89 | AC_SUBST([SSLCPPFLAGS]) 90 | AC_SUBST([SSLLDFLAGS]) 91 | AC_SUBST([SSLLIBS]) 92 | CPPFLAGS=$nsca_save_CPPFLAGS 93 | LDFLAGS=$nsca_save_LDFLAGS 94 | ])# NSCA_LIB_OPENSSL 95 | 96 | dnl vim:set joinspaces textwidth=80: 97 | -------------------------------------------------------------------------------- /m4/pidfile.m4: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013 Holger Weiss 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without 5 | # modification, are permitted provided that the following conditions are met: 6 | # 7 | # 1. Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # 2. Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | 25 | # NSCA_LIB_PIDFILE 26 | # ---------------- 27 | # Check the availability of FreeBSD's pidfile(3) API (which is also available on 28 | # some Linux systems). If it's found, we set $nsca_lib_pidfile_embedded to "no" 29 | # and arrange for using the library which provides the API. Otherwise, we set 30 | # $nsca_lib_pidfile_embedded to "yes" and arrange for using the bundled 31 | # replacement functions. 32 | AC_DEFUN([NSCA_LIB_PIDFILE], 33 | [ 34 | AC_CHECK_HEADERS([sys/param.h]) 35 | AC_CHECK_HEADERS([bsd/libutil.h libutil.h], 36 | [AC_CHECK_FUNC([pidfile_open], 37 | [nsca_lib_pidfile_embedded=no], 38 | [AC_CHECK_LIB([bsd], [pidfile_open], 39 | [PIDFILELIBS='-lbsd' 40 | nsca_lib_pidfile_embedded=no], 41 | [AC_CHECK_LIB([util], [pidfile_open], 42 | [PIDFILELIBS='-lutil' 43 | nsca_lib_pidfile_embedded=no], 44 | [nsca_lib_pidfile_embedded=yes])])]) 45 | break], 46 | [nsca_lib_pidfile_embedded=yes], 47 | [[#if HAVE_SYS_PARAM_H 48 | #include 49 | #endif]]) 50 | AS_IF([test "x$nsca_lib_pidfile_embedded" = xyes], 51 | [_NSCA_LIB_PIDFILE_EMBEDDED]) 52 | AC_SUBST([PIDFILELIBS]) 53 | ])# NSCA_LIB_PIDFILE 54 | 55 | # _NSCA_LIB_PIDFILE_EMBEDDED 56 | # -------------------------- 57 | # Arrange for using the bundled pidfile functions. If the flock(2) function is 58 | # found, we set $nsca_func_flock to "yes"; otherwise, we set that variable to 59 | # "no". 60 | AC_DEFUN([_NSCA_LIB_PIDFILE_EMBEDDED], 61 | [ 62 | AC_CHECK_HEADERS([sys/file.h]) 63 | AC_TYPE_MODE_T 64 | # At least on AIX 5.3, flock(2) is hidden in libbsd. 65 | AC_CHECK_FUNC([flock], 66 | [nsca_func_flock=yes], 67 | [AC_CHECK_LIB([bsd], [flock], 68 | [PIDFILELIBS='-lbsd' 69 | nsca_func_flock=yes], 70 | [nsca_func_flock=no])]) 71 | AS_IF([test "x$nsca_func_flock" = xyes], 72 | [AC_DEFINE([HAVE_FLOCK], [1], 73 | [Define to 1 if you have the `flock' function.])]) 74 | ])# _NSCA_LIB_PIDFILE_EMBEDDED 75 | 76 | dnl vim:set joinspaces textwidth=80: 77 | -------------------------------------------------------------------------------- /m4/progname.m4: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013 Holger Weiss 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without 5 | # modification, are permitted provided that the following conditions are met: 6 | # 7 | # 1. Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # 2. Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | 25 | # NSCA_FUNC_PROGNAME 26 | # ------------------ 27 | # Check the availability of BSD-style getprogname(3) and setprogname(3) 28 | # functions. If either of these functions isn't found, arrange for using the 29 | # bundled implementation. 30 | # 31 | # Note that some Linux systems provide a crippled version of these functions in 32 | # libbsd (they return the full pathname of the program, not just the final 33 | # component). On those systems, the functions are declared in . 34 | # Using AC_CHECK_DECL instead of AC_CHECK_FUNC should make sure that they won't 35 | # be used. 36 | # 37 | # Also note that glibc provides program_invocation_short_name(3) in if 38 | # _GNU_SOURCE is defined, but there's not much point in using it. 39 | AC_DEFUN([NSCA_FUNC_PROGNAME], 40 | [ 41 | AC_CHECK_DECL([getprogname], 42 | [nsca_func_getprogname=yes 43 | AC_DEFINE([HAVE_GETPROGNAME], [1], 44 | [Define to 1 if you have the `getprogname' function.])], 45 | [nsca_func_getprogname=no], 46 | [[#include ]]) 47 | AC_CHECK_DECL([setprogname], 48 | [nsca_func_setprogname=yes 49 | AC_DEFINE([HAVE_SETPROGNAME], [1], 50 | [Define to 1 if you have the `setprogname' function.])], 51 | [nsca_func_setprogname=no], 52 | [[#include ]]) 53 | AS_IF([test "x$nsca_func_getprogname" != xyes || 54 | test "x$nsca_func_setprogname" != xyes], 55 | [AC_LIBOBJ([progname])]) 56 | ])# NSCA_FUNC_PROGNAME 57 | 58 | dnl vim:set joinspaces textwidth=80: 59 | -------------------------------------------------------------------------------- /m4/systemd.m4: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013 Holger Weiss 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without 5 | # modification, are permitted provided that the following conditions are met: 6 | # 7 | # 1. Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # 2. Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | 25 | # NSCA_LIB_SYSTEMD 26 | # ---------------- 27 | # Check the availability of systemd. If the systemd (or the old systemd-daemon) 28 | # library is found, we define HAVE_SYSTEMD_SD_DAEMON_H to 1. We then also set 29 | # the output variables SYSTEMDCPPFLAGS, SYSTEMDLDFLAGS, and SYSTEMDLIBS to 30 | # appropriate values. (Why are there no underscores in these variable names? 31 | # Because Automake treats names like "foo_CPPFLAGS" specially.) 32 | AC_DEFUN([NSCA_LIB_SYSTEMD], 33 | [ 34 | nsca_save_CPPFLAGS=$CPPFLAGS 35 | nsca_save_LDFLAGS=$LDFLAGS 36 | nsca_systemd_dir=unknown 37 | AC_ARG_WITH([systemd], 38 | [AS_HELP_STRING([--with-systemd=PATH], 39 | [use the systemd library in PATH])], 40 | [nsca_with_systemd=$with_systemd], 41 | [nsca_with_systemd=maybe]) 42 | AC_MSG_CHECKING([whether systemd is desired]) 43 | AS_CASE([$nsca_with_systemd], 44 | [no], 45 | [AC_MSG_RESULT([no])], 46 | [yes|maybe], 47 | [AC_MSG_RESULT([$nsca_with_systemd]) 48 | AC_MSG_CHECKING([for the location of systemd]) 49 | for _nsca_systemd_dir in "$ac_pwd/lib/systemd" /usr /usr/local /usr/pkg 50 | do dnl Solaris 10 doesn't have "test -e". 51 | AS_IF([test -r "$_nsca_systemd_dir/include/systemd/sd-daemon.h"], 52 | [nsca_systemd_dir=$_nsca_systemd_dir 53 | break]) 54 | done 55 | AS_IF([test "x$nsca_systemd_dir" != xunknown], 56 | [AC_MSG_RESULT([$nsca_systemd_dir]) 57 | AS_IF([test "x$nsca_with_systemd" = xmaybe], 58 | [nsca_with_systemd=yes])], 59 | [AC_MSG_RESULT([not found]) 60 | AS_IF([test "x$nsca_with_systemd" = xmaybe], 61 | [nsca_with_systemd=no])])], 62 | [AC_MSG_RESULT([yes]) 63 | nsca_with_systemd=yes 64 | nsca_systemd_dir=$nsca_with_systemd]) 65 | AS_IF([test "x$nsca_with_systemd" = xyes], 66 | [AS_IF([test "x$nsca_systemd_dir" != xunknown && 67 | test "x$nsca_systemd_dir" != x/usr], 68 | [SYSTEMDCPPFLAGS="-I$nsca_systemd_dir/include" 69 | SYSTEMDLDFLAGS="-L$nsca_systemd_dir/lib" 70 | CPPFLAGS="$SYSTEMDCPPFLAGS $CPPFLAGS" 71 | LDFLAGS="$SYSTEMDLDFLAGS $LDFLAGS"]) 72 | AC_CHECK_HEADERS([systemd/sd-daemon.h], [], 73 | [AC_MSG_ERROR([systemd header file not found])]) 74 | AC_CHECK_LIB([systemd], [sd_notify], 75 | [SYSTEMDLIBS='-lsystemd'], 76 | [AC_CHECK_LIB([systemd-daemon], [sd_notify], 77 | [SYSTEMDLIBS='-lsystemd-daemon'], 78 | [AC_MSG_FAILURE([cannot link with systemd-daemon library])])])]) 79 | AC_SUBST([SYSTEMDCPPFLAGS]) 80 | AC_SUBST([SYSTEMDLDFLAGS]) 81 | AC_SUBST([SYSTEMDLIBS]) 82 | CPPFLAGS=$nsca_save_CPPFLAGS 83 | LDFLAGS=$nsca_save_LDFLAGS 84 | ])# NSCA_LIB_SYSTEMD 85 | 86 | dnl vim:set joinspaces textwidth=80: 87 | -------------------------------------------------------------------------------- /man/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake(1) to produce Makefile.in. 2 | 3 | ## Copyright (c) 2013 Holger Weiss 4 | ## All rights reserved. 5 | ## 6 | ## Redistribution and use in source and binary forms, with or without 7 | ## modification, are permitted provided that the following conditions are met: 8 | ## 9 | ## 1. Redistributions of source code must retain the above copyright notice, 10 | ## this list of conditions and the following disclaimer. 11 | ## 12 | ## 2. Redistributions in binary form must reproduce the above copyright notice, 13 | ## this list of conditions and the following disclaimer in the documentation 14 | ## and/or other materials provided with the distribution. 15 | ## 16 | ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | ## ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 | ## LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | ## CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | ## SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | ## INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | ## CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | ## ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | ## POSSIBILITY OF SUCH DAMAGE. 27 | 28 | edit = sed \ 29 | -e 's|[@]sysconfdir[@]|$(sysconfdir)|g' \ 30 | -e 's|[@]localstatedir[@]|$(localstatedir)|g' \ 31 | -e 's|[@]version[@]|$(PACKAGE_VERSION)|g' \ 32 | -e 's|[@]date[@]|$(RELEASE_DATE)|g' 33 | 34 | man8_MANS = nsca-ng.man send_nsca.man 35 | man5_MANS = nsca-ng.cfg.man send_nsca.cfg.man 36 | 37 | PDF_FILES = nsca-ng.pdf nsca-ng.cfg.pdf send_nsca.pdf send_nsca.cfg.pdf 38 | EXTRA_DIST = nsca-ng.in send_nsca.in nsca-ng.cfg.in send_nsca.cfg.in 39 | CLEANFILES = $(man8_MANS) $(man5_MANS) $(PDF_FILES) 40 | 41 | .in.man: 42 | $(AM_V_GEN)$(edit) $< > $@ 43 | 44 | .man.ps: 45 | $(AM_V_GEN)$(top_srcdir)/build-aux/man2ps $< $@ 46 | 47 | .ps.pdf: 48 | $(AM_V_at)ps2pdf $< $@ 49 | 50 | pdf-local: $(PDF_FILES) 51 | -------------------------------------------------------------------------------- /perl/.gitignore: -------------------------------------------------------------------------------- 1 | *.sw[pqr] 2 | *.o 3 | *.tar.gz 4 | *.tar.bz2 5 | MYMETA.* 6 | Makefile.old 7 | Client.c 8 | Client.bs 9 | pm_to_blib 10 | blib/ 11 | -------------------------------------------------------------------------------- /perl/Changes: -------------------------------------------------------------------------------- 1 | Revision history for Perl extension Net::NSCAng::Client. 2 | 3 | v1.0.0 2016-09-12 4 | - New: provide :rcodes tag to only import return codes 5 | - New: version numbering scheme changed to use version->declare() 6 | - Doc fix: properly hyperlink to methods by separating method name and 7 | argument template. 8 | 9 | 0.05 2015-10-06 10 | - Fix: use Devel::CheckLib in the build script to verify that the 11 | OpenSSL found is actually usable. 12 | 13 | 0.04 2015-09-27 14 | - Fix: on systems such as OpnBSD that use LibreSSL without support for 15 | RFC4279 PSK authentication, try `libeopenssl' (the original) first. 16 | - Test: emit warning on threaded perls 17 | - CPAN: add MIN_PERL_VERSION and repository info 18 | - CPAN: change archive to bzip2 format 19 | 20 | 0.03 2015-08-31 21 | - Test suite: fix spurious failures on non-English locales 22 | 23 | 0.02 2015-08-26 24 | - Doc fix: *_results method documentation had wrong arguments 25 | - Doc fix: "timeout" tag for the constructor was missing 26 | 27 | 0.01 2015-08-25 28 | - original version; created by h2xs 1.23 with options 29 | -b 5.10.1 -O -A -n Net::NSCAng::Client 30 | 31 | vim:set noet ts=8: 32 | -------------------------------------------------------------------------------- /perl/MANIFEST: -------------------------------------------------------------------------------- 1 | Changes 2 | Client.xs 3 | Makefile.PL 4 | MANIFEST 5 | ppport.h 6 | README 7 | t/001_load.t 8 | t/Net-NSCAng-Client.t 9 | t/manifest.t 10 | t/pod.t 11 | lib/Net/NSCAng/Client.pm 12 | client.c 13 | client.h 14 | typemap 15 | uthash.h 16 | -------------------------------------------------------------------------------- /perl/Makefile.PL: -------------------------------------------------------------------------------- 1 | use 5.010001; 2 | use ExtUtils::MakeMaker; 3 | use ExtUtils::PkgConfig; 4 | use Devel::CheckLib; 5 | 6 | my %openssl_info = ExtUtils::PkgConfig->find(qw/ eopenssl openssl /); 7 | die "OpenSSL must be v1.0 or higher" unless ExtUtils::PkgConfig->atleast_version('openssl', '1.0'); 8 | 9 | my $libpath = ExtUtils::PkgConfig->libs_only_L($openssl_info{pkg}); 10 | $libpath =~ s/-L//g; 11 | # If this is not set, non-default paths such as eopenssl's are not found on OpenBSD 12 | $ENV{LD_LIBRARY_PATH} //= ''; 13 | $ENV{LD_LIBRARY_PATH} .= ':' if length $ENV{LD_LIBRARY_PATH}; 14 | $ENV{LD_LIBRARY_PATH} .= $libpath; 15 | 16 | check_lib( 17 | lib => 'ssl', 18 | header => 'openssl/ssl.h', 19 | libpath => $libpath, 20 | function => ' 21 | SSL_CTX *ctx; 22 | SSL_library_init(); 23 | if(!(ctx = SSL_CTX_new(SSLv23_client_method()))) return 1; 24 | SSL_CTX_set_psk_client_callback(ctx, (unsigned int (*)(SSL*,const char*,char*,unsigned int,unsigned char*,unsigned int))NULL); 25 | return 0; 26 | ', 27 | ) or do { 28 | print STDERR < 'Net::NSCAng::Client', 38 | VERSION_FROM => 'lib/Net/NSCAng/Client.pm', 39 | MIN_PERL_VERSION => '5.10.1', 40 | PREREQ_PM => {}, 41 | CONFIGURE_REQUIRES => { 42 | 'ExtUtils::MakeMaker' => 6.52, 43 | 'ExtUtils::PkgConfig' => 0, 44 | 'Devel::CheckLib' => 0, 45 | 'version' => 0.77, 46 | }, 47 | TEST_REQUIRES => { 48 | 'Test::Exception' => 0, 49 | 'Test::More' => 0, 50 | 'Test::Pod' => 0, 51 | 'Test::CheckManifest' => 0, 52 | }, 53 | ABSTRACT_FROM => 'lib/Net/NSCAng/Client.pm', # retrieve abstract from module 54 | AUTHOR => 'Matthias Bethke ', 55 | LICENSE => 'perl', 56 | LIBS => [ ExtUtils::PkgConfig->libs($openssl_info{pkg}) ], 57 | DEFINE => '', 58 | INC => '-I.', 59 | OBJECT => '$(O_FILES)', 60 | META_ADD => { 61 | repository => { 62 | type => 'git', 63 | url => 'git@github.com:mbethke/nsca-ng.git', 64 | web => 'https://github.com/mbethke/nsca-ng/tree/perl-module/perl', 65 | }, 66 | }, 67 | dist => { COMPRESS => 'bzip2', SUFFIX => 'bz2', }, 68 | clean => { FILES => 'Net-NSCAng-Client-*' }, 69 | ); 70 | -------------------------------------------------------------------------------- /perl/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake(1) to produce Makefile.in. 2 | 3 | ## Copyright (c) 2016 Holger Weiss 4 | ## All rights reserved. 5 | ## 6 | ## Redistribution and use in source and binary forms, with or without 7 | ## modification, are permitted provided that the following conditions are met: 8 | ## 9 | ## 1. Redistributions of source code must retain the above copyright notice, 10 | ## this list of conditions and the following disclaimer. 11 | ## 12 | ## 2. Redistributions in binary form must reproduce the above copyright notice, 13 | ## this list of conditions and the following disclaimer in the documentation 14 | ## and/or other materials provided with the distribution. 15 | ## 16 | ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | ## ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 | ## LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | ## CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | ## SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | ## INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | ## CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | ## ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | ## POSSIBILITY OF SUCH DAMAGE. 27 | 28 | EXTRA_DIST = Changes Client.xs MANIFEST Makefile.PL client.c client.h ppport.h \ 29 | typemap uthash.h lib t 30 | -------------------------------------------------------------------------------- /perl/README: -------------------------------------------------------------------------------- 1 | Net-NSCAng-Client version 0.01 2 | ============================== 3 | 4 | This is a Perl interface to Alexander Golovko's NSCA-ng client library. 5 | 6 | INSTALLATION 7 | 8 | To install this module type the following: 9 | 10 | perl Makefile.PL 11 | make 12 | make test 13 | make install 14 | 15 | DEPENDENCIES 16 | 17 | None. Testing requires Test::Exception though. 18 | 19 | COPYRIGHT AND LICENCE 20 | 21 | Copyright (C) 2015 by Matthias Bethke 22 | Portions Copyright (C) by Alexander Golovko 23 | 24 | This library is free software; you can redistribute it and/or modify 25 | it under the same terms as Perl itself, either Perl version 5.20.2 or, 26 | at your option, any later version of Perl 5 you may have available. 27 | -------------------------------------------------------------------------------- /perl/README.md: -------------------------------------------------------------------------------- 1 | README -------------------------------------------------------------------------------- /perl/client.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Alexander Golovko 3 | * All rights reserved. 4 | * Portions (c) 2015 Matthias Bethke 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright notice, 10 | * this list of conditions and the following disclaimer. 11 | * 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, 13 | * this list of conditions and the following disclaimer in the documentation 14 | * and/or other materials provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | * POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef __NSCANG_CLIENT_H 30 | #define __NSCANG_CLIENT_H 31 | 32 | #include 33 | #include 34 | 35 | #include "uthash.h" 36 | 37 | typedef enum { NSCANG_STATE_NONE=0, NSCANG_STATE_NEW, NSCANG_STATE_MOIN } nscang_state_t; 38 | typedef enum { NSCANG_RESP_MOIN=1, NSCANG_RESP_OKAY } nscang_response_t; 39 | typedef enum { 40 | NSCANG_ERROR_MALLOC=1, 41 | NSCANG_ERROR_TIMEOUT, 42 | NSCANG_ERROR_TOO_LONG_RESPONSE, 43 | NSCANG_ERROR_BAD_PROTO_VERSION, 44 | NSCANG_ERROR_PROTOCOL_MISMATCH, 45 | NSCANG_ERROR_UNKNOWN_RESPONSE, 46 | NSCANG_ERROR_BAIL, 47 | NSCANG_ERROR_FAIL, 48 | NSCANG_ERROR_BAD_STATE, 49 | NSCANG_ERROR_SSL_CTX_CREATE=101, 50 | NSCANG_ERROR_SSL_CIPHERS, 51 | NSCANG_ERROR_SSL_BIO_CREATE, 52 | NSCANG_ERROR_SSL_CREATE, 53 | NSCANG_ERROR_SSL 54 | } nscang_error_t; 55 | 56 | typedef struct { 57 | SSL_CTX *ssl_ctx; 58 | BIO *bio; 59 | SSL *ssl; 60 | nscang_state_t state; 61 | 62 | char *identity; 63 | char *psk; 64 | 65 | nscang_error_t _errno; 66 | char errstr[1024]; 67 | 68 | UT_hash_handle hh; 69 | } nscang_client_t; 70 | 71 | int nscang_client_init(nscang_client_t *c, char *host, int port, 72 | char *ciphers, char *identity, char *psk); 73 | void nscang_client_free(nscang_client_t *c); 74 | void nscang_client_disconnect(nscang_client_t *c); 75 | int nscang_client_send_moin(nscang_client_t *c, int timeout); 76 | int nscang_client_send_command(nscang_client_t *c, const char *command, int timeout); 77 | int nscang_client_send_push(nscang_client_t *c, char *host, char *service, 78 | int status, char *message, int timeout); 79 | int nscang_client_send_quit(nscang_client_t *c); 80 | char *nscang_client_errstr(nscang_client_t *c, char *buf, int buf_size); 81 | 82 | #endif /* __NSCANG_CLIENT_H */ 83 | -------------------------------------------------------------------------------- /perl/t/001_load.t: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | use strict; 3 | use warnings; 4 | use Test::More tests => 2; 5 | 6 | BEGIN { 7 | use_ok('Net::NSCAng::Client'); 8 | } 9 | 10 | isa_ok(Net::NSCAng::Client->new('bogushost.invalid', 'none', 'none'), 'Net::NSCAng::Client'); 11 | 12 | 13 | -------------------------------------------------------------------------------- /perl/t/Net-NSCAng-Client.t: -------------------------------------------------------------------------------- 1 | use strict; 2 | use warnings; 3 | use POSIX qw(setlocale LC_ALL); 4 | use Test::More tests => 14; 5 | use Test::Exception; 6 | use Config; 7 | use Net::NSCAng::Client; 8 | 9 | BEGIN { 10 | setlocale(LC_ALL, "C"); 11 | $Config{useithreads} 12 | and warn "WARNING: Net::NSCAng::Client is not thread safe but your perl has threads enabled!\n"; 13 | }; 14 | 15 | my @cparams = qw/ localhost myid s3cr3t /; 16 | my @nn = (node_name => 'here'); 17 | my @sd = (svc_description => 'bogus'); 18 | my $n; 19 | 20 | lives_ok(sub { $n = Net::NSCAng::Client->new(@cparams) }, 'Simple constructor'); 21 | dies_ok(sub { $n->host_result(0, "OK") }, 'host_result() dies w/o node_name'); 22 | dies_ok(sub { $n->svc_result(0, "OK") }, 'svc_result() dies w/o node_name'); 23 | lives_ok(sub { crf(sub { $n->host_result(0, "OK", @nn) })}, 'host_result() with local node_name'); 24 | dies_ok(sub { $n->svc_result(0, "OK", @nn) }, 'svc_result() still dies with local node_name'); 25 | 26 | lives_ok(sub { $n = Net::NSCAng::Client->new(@cparams, @nn) }, 'Constructor with node_name'); 27 | lives_ok(sub {crf(sub { $n->host_result(0, "OK") })}, 'host_result() with node_name from constructor'); 28 | dies_ok(sub { $n->svc_result(0, "OK") }, 'svc_result() dies w/o svc_description'); 29 | lives_ok(sub {crf(sub { $n->svc_result(0, "OK", @sd) })}, 'svc_result() with local svc_description'); 30 | 31 | lives_ok(sub { $n = Net::NSCAng::Client->new(@cparams, @nn, @sd) }, 'Constructor with node_name'); 32 | lives_ok(sub { crf(sub { $n->host_result(0, "OK") })}, 'host_result() OK w/o local params'); 33 | lives_ok(sub { crf(sub { $n->svc_result(0, "OK") })}, 'svc_result() OK w/o local params'); 34 | 35 | dies_ok(sub { $n->command("BOGUS_COMMAND;1;2;3") }, 'command() dies w/o argument'); 36 | lives_ok(sub {crf(sub { $n->command("BOGUS_COMMAND;1;2;3") })}, 'command() works'); 37 | # Connection-refused-filter 38 | # Supresses exceptions with a "connection refused" error as this is expected 39 | sub crf { 40 | my $sub = shift; 41 | eval { $sub->() }; 42 | if($@) { 43 | die $@ unless $@ =~ /SSL error:Connection refused/; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /perl/t/manifest.t: -------------------------------------------------------------------------------- 1 | #!perl -T 2 | use 5.10.1; 3 | use strict; 4 | use warnings FATAL => 'all'; 5 | use Test::More; 6 | 7 | unless ( $ENV{RELEASE_TESTING} ) { 8 | plan( skip_all => "Author tests not required for installation" ); 9 | } 10 | 11 | my $min_tcm = 0.9; 12 | eval "use Test::CheckManifest $min_tcm"; 13 | plan skip_all => "Test::CheckManifest $min_tcm required" if $@; 14 | 15 | ok_manifest({ 16 | exclude => [ qw# /.git /.gitignore /Client.bs /Client.o /Client.c /client.o # ], 17 | filter => [ qr/\.sw[pqr]$/, qr/\.old$/, qr/\.tar.(?:bz2|gz|)$/ ], 18 | } 19 | ); 20 | 21 | -------------------------------------------------------------------------------- /perl/t/pod.t: -------------------------------------------------------------------------------- 1 | #!perl -T 2 | use 5.10.1; 3 | use strict; 4 | use warnings FATAL => 'all'; 5 | use Test::More; 6 | 7 | # Ensure a recent version of Test::Pod 8 | my $min_tp = 1.22; 9 | eval "use Test::Pod $min_tp"; 10 | plan skip_all => "Test::Pod $min_tp required for testing POD" if $@; 11 | 12 | all_pod_files_ok(); 13 | -------------------------------------------------------------------------------- /perl/typemap: -------------------------------------------------------------------------------- 1 | const char * T_PTROBJ 2 | Net::NSCAng::Client T_PTROBJ 3 | nscang_object_t T_PTROBJ 4 | -------------------------------------------------------------------------------- /python/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake(1) to produce Makefile.in. 2 | 3 | ## Copyright (c) 2014 Holger Weiss 4 | ## All rights reserved. 5 | ## 6 | ## Redistribution and use in source and binary forms, with or without 7 | ## modification, are permitted provided that the following conditions are met: 8 | ## 9 | ## 1. Redistributions of source code must retain the above copyright notice, 10 | ## this list of conditions and the following disclaimer. 11 | ## 12 | ## 2. Redistributions in binary form must reproduce the above copyright notice, 13 | ## this list of conditions and the following disclaimer in the documentation 14 | ## and/or other materials provided with the distribution. 15 | ## 16 | ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | ## ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 | ## LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | ## CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | ## SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | ## INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | ## CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | ## ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | ## POSSIBILITY OF SUCH DAMAGE. 27 | 28 | EXTRA_DIST = PKG-INFO client.c client.h nscang.c setup.py uthash.h 29 | 30 | clean-local: 31 | -rm -rf build 32 | -------------------------------------------------------------------------------- /python/PKG-INFO: -------------------------------------------------------------------------------- 1 | Metadata-Version: 1.0 2 | Name: python-nscang 3 | Version: 1.0 4 | Platform: POSIX, Windows 5 | Summary: Python NSCA-ng client. 6 | Home-page: https://www.nsca-ng.org/ 7 | Author: Alexander Golovko 8 | Author-email: alexandro@onsec.ru 9 | License: BSD 10 | -------------------------------------------------------------------------------- /python/README: -------------------------------------------------------------------------------- 1 | This is the `README` file of *python-nscang*. 2 | 3 | Description 4 | ----------- 5 | 6 | The Python NSCA-ng client allows for sending host or service check results 7 | to NSCA-ng servers. 8 | 9 | Examples 10 | -------- 11 | 12 | from nscang import NSCAngNotifyer 13 | 14 | n = NSCAngNotifyer(host="monitoring.example.com", 15 | port=5668, 16 | identity="foo.example.com", 17 | psk="secret") 18 | 19 | n.svc_result(host_name="foo.example.com", 20 | svc_description="RAID status", 21 | return_code=0, 22 | plugin_output="OK: md126[raid1], md127[raid1]", 23 | timeout=5) 24 | -------------------------------------------------------------------------------- /python/README.md: -------------------------------------------------------------------------------- 1 | README -------------------------------------------------------------------------------- /python/client.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014 Alexander Golovko 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 19 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | * POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef __NSCANG_CLIENT_H 29 | #define __NSCANG_CLIENT_H 30 | 31 | #include 32 | #include 33 | 34 | #include "uthash.h" 35 | 36 | typedef struct { 37 | SSL_CTX *ssl_ctx; 38 | BIO *bio; 39 | SSL *ssl; 40 | int state; 41 | 42 | char *identity; 43 | char *psk; 44 | 45 | int _errno; 46 | char errstr[1024]; 47 | 48 | UT_hash_handle hh; 49 | } nscang_client_t; 50 | 51 | #define NSCANG_STATE_NONE 0 52 | #define NSCANG_STATE_NEW 1 53 | #define NSCANG_STATE_MOIN 2 54 | 55 | #define NSCANG_RESP_MOIN 1 56 | #define NSCANG_RESP_OKAY 2 57 | 58 | #define NSCANG_ERROR_MALLOC 1 59 | #define NSCANG_ERROR_TIMEOUT 2 60 | #define NSCANG_ERROR_TOO_LONG_RESPONSE 3 61 | #define NSCANG_ERROR_BAD_PROTO_VERSION 4 62 | #define NSCANG_ERROR_PROTOCOL_MISMATCH 5 63 | #define NSCANG_ERROR_UNKNOWN_RESPONSE 6 64 | #define NSCANG_ERROR_BAIL 7 65 | #define NSCANG_ERROR_FAIL 8 66 | #define NSCANG_ERROR_BAD_STATE 9 67 | #define NSCANG_ERROR_LOCKING 10 68 | 69 | #define NSCANG_ERROR_SSL_CTX_CREATE 101 70 | #define NSCANG_ERROR_SSL_CIPHERS 102 71 | #define NSCANG_ERROR_SSL_BIO_CREATE 103 72 | #define NSCANG_ERROR_SSL_CREATE 104 73 | #define NSCANG_ERROR_SSL 105 74 | 75 | int nscang_client_init(nscang_client_t *c, char *host, int port, 76 | char *ciphers, char *identity, char *psk); 77 | void nscang_client_free(nscang_client_t *c); 78 | void nscang_client_disconnect(nscang_client_t *c); 79 | int nscang_client_send_moin(nscang_client_t *c, int timeout); 80 | int nscang_client_send_push(nscang_client_t *c, char *host, char *service, 81 | int status, char *message, int timeout); 82 | int nscang_client_send_quit(nscang_client_t *c); 83 | char *nscang_client_errstr(nscang_client_t *c, char *buf, int buf_size); 84 | 85 | #endif /* __NSCANG_CLIENT_H */ 86 | -------------------------------------------------------------------------------- /python/setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | from distutils.core import setup, Extension 3 | 4 | VERSION = "1.1" 5 | 6 | setup(name = "python-nscang", 7 | version = VERSION, 8 | description = "Python NSCA-ng client", 9 | author = "Alexander Golovko", 10 | author_email = "alexandro@onsec.ru", 11 | license = "BSD", 12 | long_description = \ 13 | """ 14 | Python NSCA-ng client. 15 | """, 16 | ext_modules = [Extension("nscang", 17 | ["nscang.c", "client.c"], 18 | libraries = ["pthread", "ssl", "crypto"], 19 | define_macros = [("VERSION", '"%s"' % VERSION)])], 20 | ) 21 | -------------------------------------------------------------------------------- /src/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake(1) to produce Makefile.in. 2 | 3 | ## Copyright (c) 2013 Holger Weiss 4 | ## All rights reserved. 5 | ## 6 | ## Redistribution and use in source and binary forms, with or without 7 | ## modification, are permitted provided that the following conditions are met: 8 | ## 9 | ## 1. Redistributions of source code must retain the above copyright notice, 10 | ## this list of conditions and the following disclaimer. 11 | ## 12 | ## 2. Redistributions in binary form must reproduce the above copyright notice, 13 | ## this list of conditions and the following disclaimer in the documentation 14 | ## and/or other materials provided with the distribution. 15 | ## 16 | ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | ## ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 | ## LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | ## CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | ## SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | ## INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | ## CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | ## ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | ## POSSIBILITY OF SUCH DAMAGE. 27 | 28 | SUBDIRS = common 29 | 30 | if BUILD_CLIENT 31 | SUBDIRS += client 32 | endif 33 | 34 | if BUILD_SERVER 35 | SUBDIRS += server 36 | endif 37 | -------------------------------------------------------------------------------- /src/client/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake(1) to produce Makefile.in. 2 | 3 | ## Copyright (c) 2013 Holger Weiss 4 | ## All rights reserved. 5 | ## 6 | ## Redistribution and use in source and binary forms, with or without 7 | ## modification, are permitted provided that the following conditions are met: 8 | ## 9 | ## 1. Redistributions of source code must retain the above copyright notice, 10 | ## this list of conditions and the following disclaimer. 11 | ## 12 | ## 2. Redistributions in binary form must reproduce the above copyright notice, 13 | ## this list of conditions and the following disclaimer in the documentation 14 | ## and/or other materials provided with the distribution. 15 | ## 16 | ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | ## ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 | ## LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | ## CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | ## SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | ## INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | ## CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | ## ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | ## POSSIBILITY OF SUCH DAMAGE. 27 | 28 | AM_CPPFLAGS = \ 29 | -DSYSCONFDIR='"$(sysconfdir)"' \ 30 | -I$(top_srcdir)/src/common \ 31 | -I$(top_srcdir)/lib \ 32 | $(EVCPPFLAGS) \ 33 | $(SSLCPPFLAGS) 34 | 35 | AM_LDFLAGS = \ 36 | $(EVLDFLAGS) \ 37 | $(SSLLDFLAGS) 38 | 39 | LDADD = \ 40 | ../common/libcommon.a \ 41 | ../../lib/libcompat.a \ 42 | $(EVLIBS) \ 43 | $(SSLLIBS) 44 | 45 | if USE_EMBEDDED_EV 46 | AM_CPPFLAGS += -I$(top_srcdir)/lib/ev 47 | LDADD += ../../lib/ev/libev.a 48 | endif 49 | 50 | sbin_PROGRAMS = send_nsca 51 | send_nsca_SOURCES = auth.c auth.h client.c client.h conf.c conf.h input.c \ 52 | input.h parse.c parse.h send_nsca.c send_nsca.h 53 | -------------------------------------------------------------------------------- /src/client/auth.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 Holger Weiss 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 19 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | * POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #if HAVE_CONFIG_H 29 | # include 30 | #endif 31 | 32 | #include 33 | 34 | #include 35 | 36 | #include "auth.h" 37 | #include "conf.h" 38 | #include "send_nsca.h" 39 | #include "system.h" 40 | 41 | unsigned int 42 | set_psk(SSL *ssl __attribute__((__unused__)), 43 | const char *hint __attribute__((__unused__)), 44 | char *identity, 45 | unsigned int max_identity_len, 46 | unsigned char *password, 47 | unsigned int max_password_len) 48 | { 49 | char *configured_id = conf_getstr(cfg, "identity"); 50 | char *configured_pw = conf_getstr(cfg, "password"); 51 | size_t identity_len = MIN(strlen(configured_id), max_identity_len - 1); 52 | size_t password_len = MIN(strlen(configured_pw), max_password_len); 53 | 54 | (void)memcpy(identity, configured_id, identity_len); 55 | (void)memcpy(password, configured_pw, password_len); 56 | 57 | identity[identity_len] = '\0'; 58 | 59 | return (unsigned int)password_len; 60 | } 61 | 62 | /* vim:set joinspaces noexpandtab textwidth=80 cinoptions=(4,u0: */ 63 | -------------------------------------------------------------------------------- /src/client/auth.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 Holger Weiss 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 19 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | * POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef AUTH_H 29 | # define AUTH_H 30 | 31 | # if HAVE_CONFIG_H 32 | # include 33 | # endif 34 | 35 | # include 36 | 37 | # include "system.h" 38 | 39 | unsigned int 40 | set_psk(SSL *, const char *, char *, unsigned int, unsigned char *, 41 | unsigned int); 42 | 43 | #endif 44 | 45 | /* vim:set joinspaces noexpandtab textwidth=80 cinoptions=(4,u0: */ 46 | -------------------------------------------------------------------------------- /src/client/client.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 Holger Weiss 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 19 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | * POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef CLIENT_H 29 | # define CLIENT_H 30 | 31 | # if HAVE_CONFIG_H 32 | # include 33 | # endif 34 | 35 | # include 36 | 37 | # include "system.h" 38 | 39 | enum { 40 | CLIENT_MODE_COMMAND, 41 | CLIENT_MODE_CHECK_RESULT 42 | }; 43 | 44 | typedef struct client_state_s client_state; 45 | 46 | client_state *client_start(const char *, const char *, ev_tstamp, int, char, 47 | char); 48 | void client_stop(client_state *); 49 | 50 | #endif 51 | 52 | /* vim:set joinspaces noexpandtab textwidth=80 cinoptions=(4,u0: */ 53 | -------------------------------------------------------------------------------- /src/client/conf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 Holger Weiss 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 19 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | * POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef CONF_H 29 | # define CONF_H 30 | 31 | # if HAVE_CONFIG_H 32 | # include 33 | # endif 34 | 35 | # include "system.h" 36 | 37 | # define DEFAULT_CONF_FILE SYSCONFDIR "/send_nsca.cfg" 38 | 39 | typedef struct conf_s conf; 40 | 41 | conf *conf_init(const char *); 42 | long conf_getint(conf * restrict, const char * restrict); 43 | char *conf_getstr(conf * restrict, const char * restrict); 44 | void conf_setint(conf * restrict, const char * restrict, long); 45 | void conf_setstr(conf * restrict, const char * restrict, const char * restrict); 46 | void conf_free(conf *); 47 | 48 | #endif 49 | 50 | /* vim:set joinspaces noexpandtab textwidth=80 cinoptions=(4,u0: */ 51 | -------------------------------------------------------------------------------- /src/client/input.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 Holger Weiss 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 19 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | * POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef INPUT_H 29 | # define INPUT_H 30 | 31 | # if HAVE_CONFIG_H 32 | # include 33 | # endif 34 | 35 | # include 36 | 37 | # include "buffer.h" 38 | # include "system.h" 39 | 40 | typedef struct input_state_s { 41 | /* public: */ 42 | void *data; /* Can freely be used by the caller. */ 43 | 44 | /* private: */ 45 | ev_io watcher; 46 | buffer *buffer; 47 | char input[128]; 48 | void (*read_handler)(struct input_state_s * restrict, char * restrict); 49 | void (*eof_handler)(struct input_state_s *); 50 | int fd; 51 | char separator; 52 | bool eof; 53 | } input_state; 54 | 55 | input_state *input_start(char separator); 56 | void input_read_chunk(input_state *, 57 | void (*)(input_state * restrict, char * restrict)); 58 | void input_stop(input_state *); 59 | void input_on_eof(input_state *, void (*)(input_state *)); 60 | void input_on_error(input_state *, void (*)(input_state *)); 61 | 62 | #endif 63 | 64 | /* vim:set joinspaces noexpandtab textwidth=80 cinoptions=(4,u0: */ 65 | -------------------------------------------------------------------------------- /src/client/parse.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 Holger Weiss 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 19 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | * POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #if HAVE_CONFIG_H 29 | # include 30 | #endif 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | #include "log.h" 37 | #include "parse.h" 38 | #include "system.h" 39 | #include "util.h" 40 | #include "wrappers.h" 41 | 42 | static char *escape(const char *); 43 | 44 | /* 45 | * Exported functions. 46 | */ 47 | 48 | char * 49 | parse_command(const char *line) 50 | { 51 | char *command; 52 | 53 | debug("Parsing monitoring command"); 54 | 55 | line = skip_whitespace(line); 56 | if (line[0] == '[') 57 | command = xstrdup(line); 58 | else 59 | xasprintf(&command, "[%lu] %s", (unsigned long)time(NULL), 60 | line); 61 | 62 | return command; 63 | } 64 | 65 | char * 66 | parse_check_result(const char *input, char delimiter) 67 | { 68 | const char *fields[4] = { NULL, NULL, NULL, NULL }; 69 | char *command, *escaped; 70 | int lengths[3]; 71 | int n, pos, start_pos; 72 | 73 | debug("Parsing check result"); 74 | 75 | if (strpbrk(input, "\\\n") != NULL) 76 | input = escaped = escape(input); 77 | else 78 | escaped = NULL; 79 | 80 | fields[0] = input; 81 | start_pos = 0; 82 | n = 1; 83 | 84 | for (pos = 0; n < 4 && input[pos] != '\0'; pos++) 85 | if (input[pos] == delimiter) { 86 | lengths[n - 1] = pos - start_pos; 87 | debug("Check result field %d has %d characters (%d-%d)", 88 | n, lengths[n - 1], start_pos, pos - 1); 89 | 90 | /* Handle the next field. */ 91 | start_pos = pos + 1; 92 | fields[n] = &input[start_pos]; 93 | n++; 94 | } 95 | 96 | switch (n) { 97 | case 3: 98 | debug("Got host check result"); 99 | xasprintf(&command, 100 | "[%lu] PROCESS_HOST_CHECK_RESULT;%.*s;%.*s;%s", 101 | (unsigned long)time(NULL), 102 | lengths[0], fields[0], 103 | lengths[1], fields[1], 104 | fields[2]); 105 | break; 106 | case 4: 107 | debug("Got service check result"); 108 | xasprintf(&command, 109 | "[%lu] PROCESS_SERVICE_CHECK_RESULT;%.*s;%.*s;%.*s;%s", 110 | (unsigned long)time(NULL), 111 | lengths[0], fields[0], 112 | lengths[1], fields[1], 113 | lengths[2], fields[2], 114 | fields[3]); 115 | break; 116 | default: 117 | die("Input format incorrect, see the %s(8) man page", 118 | getprogname()); 119 | } 120 | 121 | if (escaped != NULL) 122 | free(escaped); 123 | 124 | return command; 125 | } 126 | 127 | /* 128 | * Static functions. 129 | */ 130 | 131 | static char * 132 | escape(const char *input) 133 | { 134 | const char *in; 135 | char *escaped, *out; 136 | size_t size = strlen(input) + 1; 137 | 138 | for (in = input; *in != '\0'; in++) 139 | if (*in == '\\' || *in == '\n') 140 | size++; 141 | 142 | escaped = xmalloc(size); 143 | 144 | for (in = input, out = escaped; *in != '\0'; in++, out++) 145 | switch (*in) { 146 | case '\\': 147 | *out++ = '\\'; 148 | *out = '\\'; 149 | break; 150 | case '\n': 151 | *out++ = '\\'; 152 | *out = 'n'; 153 | break; 154 | default: 155 | *out = *in; 156 | } 157 | *out = '\0'; 158 | 159 | return escaped; 160 | } 161 | 162 | /* vim:set joinspaces noexpandtab textwidth=80 cinoptions=(4,u0: */ 163 | -------------------------------------------------------------------------------- /src/client/parse.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 Holger Weiss 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 19 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | * POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef PARSE_H 29 | # define PARSE_H 30 | 31 | # if HAVE_CONFIG_H 32 | # include 33 | # endif 34 | 35 | # include "system.h" 36 | 37 | char *parse_command(const char *); 38 | char *parse_check_result(const char *, char); 39 | 40 | #endif 41 | 42 | /* vim:set joinspaces noexpandtab textwidth=80 cinoptions=(4,u0: */ 43 | -------------------------------------------------------------------------------- /src/client/send_nsca.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 Holger Weiss 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 19 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | * POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef SEND_NSCA_H 29 | # define SEND_NSCA_H 30 | 31 | # if HAVE_CONFIG_H 32 | # include 33 | # endif 34 | 35 | # include "conf.h" 36 | # include "system.h" 37 | 38 | extern conf *cfg; 39 | extern int exit_code; 40 | 41 | #endif 42 | 43 | /* vim:set joinspaces noexpandtab textwidth=80 cinoptions=(4,u0: */ 44 | -------------------------------------------------------------------------------- /src/common/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake(1) to produce Makefile.in. 2 | 3 | ## Copyright (c) 2013 Holger Weiss 4 | ## All rights reserved. 5 | ## 6 | ## Redistribution and use in source and binary forms, with or without 7 | ## modification, are permitted provided that the following conditions are met: 8 | ## 9 | ## 1. Redistributions of source code must retain the above copyright notice, 10 | ## this list of conditions and the following disclaimer. 11 | ## 12 | ## 2. Redistributions in binary form must reproduce the above copyright notice, 13 | ## this list of conditions and the following disclaimer in the documentation 14 | ## and/or other materials provided with the distribution. 15 | ## 16 | ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | ## ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 | ## LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | ## CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | ## SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | ## INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | ## CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | ## ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | ## POSSIBILITY OF SUCH DAMAGE. 27 | 28 | GIT_DESCRIBE = git describe --tags --match 'v[0-9]*' --dirty 2>/dev/null 29 | NSCA_VERSION = `($(GIT_DESCRIBE) || echo $(PACKAGE_VERSION)) | sed 's/^v//'` 30 | 31 | AM_CPPFLAGS = \ 32 | -DNSCA_VERSION=\"$(NSCA_VERSION)\" \ 33 | -I$(top_srcdir)/lib \ 34 | $(EVCPPFLAGS) \ 35 | $(SSLCPPFLAGS) 36 | 37 | AM_LDFLAGS = \ 38 | $(EVLDFLAGS) \ 39 | $(SSLLDFLAGS) 40 | 41 | LDADD = \ 42 | ../../lib/libcompat.a \ 43 | $(EVLIBS) \ 44 | $(SSLLIBS) 45 | 46 | if USE_EMBEDDED_EV 47 | AM_CPPFLAGS += -I$(top_srcdir)/lib/ev 48 | LDADD += ../../lib/ev/libev.a 49 | endif 50 | 51 | noinst_LIBRARIES = libcommon.a 52 | libcommon_a_SOURCES = buffer.c buffer.h log.c log.h tls.c tls.h util.c util.h 53 | -------------------------------------------------------------------------------- /src/common/buffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 Holger Weiss 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 19 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | * POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef BUFFER_H 29 | # define BUFFER_H 30 | 31 | # if HAVE_CONFIG_H 32 | # include 33 | # endif 34 | 35 | # include /* For size_t. */ 36 | 37 | # include "system.h" 38 | 39 | typedef struct buffer_s buffer; 40 | 41 | buffer *buffer_new(void); 42 | void buffer_append(buffer * restrict, const void * restrict, size_t); 43 | size_t buffer_read(buffer * restrict, void * restrict, size_t); 44 | void *buffer_read_alloc(buffer * restrict, size_t * restrict); 45 | char *buffer_read_line(buffer *); 46 | char *buffer_read_chunk(buffer *, char); 47 | void *buffer_slurp(buffer * restrict, size_t * restrict); 48 | size_t buffer_size(buffer *); 49 | void buffer_free(buffer *); 50 | 51 | #endif 52 | 53 | /* vim:set joinspaces noexpandtab textwidth=80 cinoptions=(4,u0: */ 54 | -------------------------------------------------------------------------------- /src/common/log.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 Holger Weiss 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 19 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | * POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #if HAVE_CONFIG_H 29 | # include 30 | #endif 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | #include "log.h" 40 | #include "system.h" 41 | #include "wrappers.h" 42 | 43 | #ifndef LOG_BUFFER_SIZE 44 | # define LOG_BUFFER_SIZE 768 45 | #endif 46 | 47 | int log_level = LOG_LEVEL_INFO; 48 | 49 | static int log_target = LOG_TARGET_STDERR; 50 | static bool log_opened = false; 51 | 52 | static inline const char *level_to_string(int); 53 | 54 | /* 55 | * Exported functions. 56 | */ 57 | 58 | void 59 | log_set(int level, int flags) 60 | { 61 | if (level != -1) 62 | log_level = level; 63 | if (flags != -1) { 64 | log_target = flags; 65 | if (flags & LOG_TARGET_SYSLOG && !log_opened) { 66 | openlog(getprogname(), LOG_PID, LOG_DAEMON); 67 | log_opened = true; 68 | } 69 | } 70 | } 71 | 72 | void 73 | vlog(int level, const char *in_fmt, va_list ap) 74 | { 75 | size_t in_pos, out_pos; 76 | char message[LOG_BUFFER_SIZE], out_fmt[512]; 77 | enum { 78 | STATE_NORMAL, 79 | STATE_PERCENT 80 | } state = STATE_NORMAL; 81 | 82 | /* 83 | * This loop handles `%m'. 84 | * 85 | * Why do we check for "out_pos < sizeof(out_fmt) - 2"? We need one 86 | * extra character when dealing with input such as `%s' (as we write 87 | * both of these characters in one iteration), and another one for 88 | * nul-termination. 89 | */ 90 | for (in_pos = out_pos = 0; in_fmt[in_pos] != '\0' 91 | && out_pos < sizeof(out_fmt) - 2; in_pos++) 92 | switch (in_fmt[in_pos]) { 93 | case '%': 94 | if (state == STATE_PERCENT) { 95 | out_fmt[out_pos++] = '%'; 96 | state = STATE_NORMAL; 97 | } else 98 | state = STATE_PERCENT; 99 | break; 100 | case 'm': 101 | if (state == STATE_PERCENT) { 102 | const char *err_str = strerror(errno); 103 | size_t err_pos; 104 | 105 | for (err_pos = 0; err_str[err_pos] != '\0' 106 | && out_pos < sizeof(out_fmt) - 1; err_pos++) 107 | out_fmt[out_pos++] = err_str[err_pos]; 108 | state = STATE_NORMAL; 109 | break; 110 | } /* Otherwise, fall through. */ 111 | default: 112 | if (state == STATE_PERCENT) 113 | out_fmt[out_pos++] = '%'; 114 | out_fmt[out_pos++] = in_fmt[in_pos]; 115 | state = STATE_NORMAL; 116 | } 117 | 118 | out_fmt[out_pos] = '\0'; 119 | 120 | if (vsnprintf(message, sizeof(message), out_fmt, ap) 121 | > (int)sizeof(message) - 1) 122 | (void)memcpy(message + sizeof(message) - 7, " [...]", 7); 123 | 124 | if (log_target & LOG_TARGET_SYSTEMD) { 125 | (void)fprintf(stderr, "<%d>%s\n", level, message); 126 | (void)fflush(stderr); 127 | } 128 | if (log_target & LOG_TARGET_STDERR) { 129 | (void)fprintf(stderr, "%s: [%s] %s\n", getprogname(), 130 | level_to_string(level), message); 131 | (void)fflush(stderr); 132 | } 133 | if (log_target & LOG_TARGET_SYSLOG) 134 | syslog(level, "[%s] %s", level_to_string(level), message); 135 | } 136 | 137 | void 138 | log_close(void) 139 | { 140 | closelog(); 141 | } 142 | 143 | /* 144 | * Static functions. 145 | */ 146 | 147 | static inline const char * 148 | level_to_string(int level) 149 | { 150 | switch (level) { 151 | case LOG_CRIT: 152 | return "FATAL"; 153 | case LOG_ERR: 154 | return "ERROR"; 155 | case LOG_WARNING: 156 | return "WARNING"; 157 | case LOG_NOTICE: 158 | return "NOTICE"; 159 | case LOG_INFO: 160 | return "INFO"; 161 | case LOG_DEBUG: 162 | return "DEBUG"; 163 | default: 164 | return "UNKNOWN"; 165 | } 166 | } 167 | 168 | /* vim:set joinspaces noexpandtab textwidth=80 cinoptions=(4,u0: */ 169 | -------------------------------------------------------------------------------- /src/common/log.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 Holger Weiss 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 19 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | * POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef SESSION_H 29 | # define SESSION_H 30 | 31 | # if HAVE_CONFIG_H 32 | # include 33 | # endif 34 | 35 | # include 36 | # include 37 | # include 38 | 39 | # include "system.h" 40 | 41 | # define LOG_TARGET_SYSLOG 0x1 42 | # define LOG_TARGET_STDERR 0x2 43 | # define LOG_TARGET_SYSTEMD 0x4 44 | 45 | enum { 46 | LOG_LEVEL_CRITICAL, 47 | LOG_LEVEL_ERROR, 48 | LOG_LEVEL_WARNING, 49 | LOG_LEVEL_NOTICE, 50 | LOG_LEVEL_INFO, 51 | LOG_LEVEL_DEBUG 52 | }; 53 | 54 | extern int log_level; 55 | 56 | void log_set(int, int); 57 | void vlog(int, const char *, va_list); 58 | void log_close(void); 59 | 60 | static inline void __attribute__((__format__(__printf__, 1, 2))) 61 | debug(const char *format, ...) 62 | { 63 | if (log_level >= LOG_LEVEL_DEBUG) { 64 | va_list ap; 65 | 66 | va_start(ap, format); 67 | vlog(LOG_DEBUG, format, ap); 68 | va_end(ap); 69 | } 70 | } 71 | 72 | static inline void __attribute__((__format__(__printf__, 1, 2))) 73 | info(const char *format, ...) 74 | { 75 | if (log_level >= LOG_LEVEL_INFO) { 76 | va_list ap; 77 | 78 | va_start(ap, format); 79 | vlog(LOG_INFO, format, ap); 80 | va_end(ap); 81 | } 82 | } 83 | 84 | static inline void __attribute__((__format__(__printf__, 1, 2))) 85 | notice(const char *format, ...) 86 | { 87 | if (log_level >= LOG_LEVEL_NOTICE) { 88 | va_list ap; 89 | 90 | va_start(ap, format); 91 | vlog(LOG_NOTICE, format, ap); 92 | va_end(ap); 93 | } 94 | } 95 | 96 | static inline void __attribute__((__format__(__printf__, 1, 2))) 97 | warning(const char *format, ...) 98 | { 99 | if (log_level >= LOG_LEVEL_WARNING) { 100 | va_list ap; 101 | 102 | va_start(ap, format); 103 | vlog(LOG_WARNING, format, ap); 104 | va_end(ap); 105 | } 106 | } 107 | 108 | static inline void __attribute__((__format__(__printf__, 1, 2))) 109 | error(const char *format, ...) 110 | { 111 | if (log_level >= LOG_LEVEL_ERROR) { 112 | va_list ap; 113 | 114 | va_start(ap, format); 115 | vlog(LOG_ERR, format, ap); 116 | va_end(ap); 117 | } 118 | } 119 | 120 | static inline void __attribute__((__format__(__printf__, 1, 2))) 121 | critical(const char *format, ...) 122 | { 123 | va_list ap; 124 | 125 | va_start(ap, format); 126 | vlog(LOG_CRIT, format, ap); 127 | va_end(ap); 128 | } 129 | 130 | static inline void __attribute__((__format__(__printf__, 1, 2), __noreturn__)) 131 | die(const char *format, ...) 132 | { 133 | va_list ap; 134 | 135 | va_start(ap, format); 136 | vlog(LOG_CRIT, format, ap); 137 | va_end(ap); 138 | 139 | exit(EXIT_FAILURE); 140 | } 141 | 142 | #endif 143 | 144 | /* vim:set joinspaces noexpandtab textwidth=80 cinoptions=(4,u0: */ 145 | -------------------------------------------------------------------------------- /src/common/util.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 Holger Weiss 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 19 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | * POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #if HAVE_CONFIG_H 29 | # include 30 | #endif 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | #include 37 | #include 38 | 39 | #include "log.h" 40 | #include "system.h" 41 | #include "util.h" 42 | #include "wrappers.h" 43 | 44 | static const char *get_ev_backend(EV_P); 45 | static const char *get_openssl_version(void); 46 | 47 | /* 48 | * Exported functions. 49 | */ 50 | 51 | char * 52 | concat(const char *str1, const char *str2) 53 | { 54 | size_t len1 = strlen(str1); 55 | size_t len2 = strlen(str2); 56 | size_t size; 57 | char *catenated; 58 | 59 | if ((size = len1 + len2 + 1) <= len1) 60 | die("String concatenation would overflow"); 61 | 62 | catenated = xmalloc(size); 63 | (void)memcpy(catenated, str1, len1); 64 | (void)memcpy(catenated + len1, str2, len2); 65 | catenated[len1 + len2] = '\0'; 66 | 67 | return catenated; 68 | } 69 | 70 | bool 71 | parse_line(char * restrict line, char ** restrict args, int n_args) 72 | { 73 | char *p; 74 | int i; 75 | 76 | for (i = 0, p = strtok(line, " \t"); p != NULL; 77 | i++, p = strtok(NULL, " \t")) 78 | if (i < n_args) 79 | args[i] = p; 80 | else { 81 | if (i > 0) 82 | debug("%s message has more than %d argument(s)", 83 | args[0], n_args - 1); 84 | return false; 85 | } 86 | 87 | if (i > 0) 88 | debug("%s message has %d argument(s)", args[0], i - 1); 89 | 90 | return (bool)(i == n_args); 91 | } 92 | 93 | char * 94 | skip_newlines(const char *string) 95 | { 96 | const char *p = string; 97 | 98 | while (*p == '\r' || *p == '\n') 99 | p++; 100 | 101 | return (char *)p; 102 | } 103 | 104 | char * 105 | skip_whitespace(const char *string) 106 | { 107 | const char *p = string; 108 | 109 | while (*p == ' ' || *p == '\t') 110 | p++; 111 | 112 | return (char *)p; 113 | } 114 | 115 | void 116 | chomp(char *string) 117 | { 118 | size_t len; 119 | 120 | if ((len = strlen(string)) > 0 && string[len - 1] == '\n') 121 | string[len - 1] = '\0'; 122 | } 123 | 124 | const char * 125 | nsca_version(void) 126 | { 127 | static char version_string[128]; 128 | 129 | (void)snprintf(version_string, sizeof(version_string), 130 | "%s %s (%s, libev %d.%d with %s)", 131 | getprogname(), 132 | NSCA_VERSION, 133 | get_openssl_version(), 134 | ev_version_major(), 135 | ev_version_minor(), 136 | get_ev_backend(EV_DEFAULT_UC)); 137 | 138 | return version_string; 139 | } 140 | 141 | /* 142 | * Static functions. 143 | */ 144 | 145 | static const char * 146 | get_ev_backend(EV_P) 147 | { 148 | switch (ev_backend(EV_A)) { 149 | case EVBACKEND_SELECT: 150 | return "select"; 151 | case EVBACKEND_POLL: 152 | return "poll"; 153 | case EVBACKEND_EPOLL: 154 | return "epoll"; 155 | case EVBACKEND_KQUEUE: 156 | return "kqueue"; 157 | case EVBACKEND_DEVPOLL: 158 | return "/dev/poll"; 159 | case EVBACKEND_PORT: 160 | return "event port"; 161 | default: 162 | return "(unknown)"; 163 | } 164 | } 165 | 166 | static const char * 167 | get_openssl_version(void) 168 | { 169 | static char version_string[32]; 170 | const char *p; 171 | size_t i, spaces = 0; 172 | 173 | for (i = 0, p = SSLeay_version(SSLEAY_VERSION); 174 | i < sizeof(version_string) - 2 && *p != '\0'; 175 | i++, p++) { 176 | if (*p == ' ') 177 | spaces++; 178 | if (spaces == 2) 179 | break; 180 | version_string[i] = *p; 181 | } 182 | version_string[++i] = '\0'; 183 | return version_string; 184 | } 185 | 186 | /* vim:set joinspaces noexpandtab textwidth=80 cinoptions=(4,u0: */ 187 | -------------------------------------------------------------------------------- /src/common/util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 Holger Weiss 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 19 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | * POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef UTIL_H 29 | # define UTIL_H 30 | 31 | # if HAVE_CONFIG_H 32 | # include 33 | # endif 34 | 35 | # include "system.h" 36 | 37 | char *concat(const char *, const char *); 38 | bool parse_line(char * restrict , char ** restrict, int); 39 | char *skip_newlines(const char *); 40 | char *skip_whitespace(const char *); 41 | void chomp(char *); 42 | const char *nsca_version(void); 43 | 44 | #endif 45 | 46 | /* vim:set joinspaces noexpandtab textwidth=80 cinoptions=(4,u0: */ 47 | -------------------------------------------------------------------------------- /src/server/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake(1) to produce Makefile.in. 2 | 3 | ## Copyright (c) 2013 Holger Weiss 4 | ## All rights reserved. 5 | ## 6 | ## Redistribution and use in source and binary forms, with or without 7 | ## modification, are permitted provided that the following conditions are met: 8 | ## 9 | ## 1. Redistributions of source code must retain the above copyright notice, 10 | ## this list of conditions and the following disclaimer. 11 | ## 12 | ## 2. Redistributions in binary form must reproduce the above copyright notice, 13 | ## this list of conditions and the following disclaimer in the documentation 14 | ## and/or other materials provided with the distribution. 15 | ## 16 | ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | ## ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 | ## LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | ## CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | ## SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | ## INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | ## CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | ## ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | ## POSSIBILITY OF SUCH DAMAGE. 27 | 28 | AM_CPPFLAGS = \ 29 | -DSYSCONFDIR='"$(sysconfdir)"' \ 30 | -DLOCALSTATEDIR='"$(localstatedir)"' \ 31 | -I$(top_srcdir)/src/common \ 32 | -I$(top_srcdir)/lib \ 33 | $(CONFUSECPPFLAGS) \ 34 | $(EVCPPFLAGS) \ 35 | $(SSLCPPFLAGS) \ 36 | $(SYSTEMDLDFLAGS) 37 | 38 | AM_LDFLAGS = \ 39 | $(CONFUSELDFLAGS) \ 40 | $(EVLDFLAGS) \ 41 | $(SSLLDFLAGS) \ 42 | $(SYSTEMDLDFLAGS) 43 | 44 | LDADD = \ 45 | ../common/libcommon.a \ 46 | ../../lib/libcompat.a \ 47 | $(CONFUSELIBS) \ 48 | $(EVLIBS) \ 49 | $(SSLLIBS) \ 50 | $(SYSTEMDLIBS) \ 51 | $(AIOLIBS) \ 52 | $(PIDFILELIBS) 53 | 54 | if USE_EMBEDDED_EV 55 | AM_CPPFLAGS += -I$(top_srcdir)/lib/ev 56 | LDADD += ../../lib/ev/libev.a 57 | endif 58 | 59 | if USE_EMBEDDED_PIDFILE 60 | AM_CPPFLAGS += -I$(top_srcdir)/lib/pidfile 61 | LDADD += ../../lib/pidfile/libpidfile.a 62 | endif 63 | 64 | sbin_PROGRAMS = nsca-ng 65 | nsca_ng_SOURCES = auth.c auth.h conf.c conf.h fifo.c fifo.h hash.c hash.h \ 66 | nsca-ng.c server.c server.h 67 | -------------------------------------------------------------------------------- /src/server/auth.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 Holger Weiss 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 19 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | * POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #if HAVE_CONFIG_H 29 | # include 30 | #endif 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | #include 37 | #include 38 | 39 | #include "auth.h" 40 | #include "hash.h" 41 | #include "log.h" 42 | #include "system.h" 43 | #include "util.h" 44 | #include "wrappers.h" 45 | 46 | static bool match(regex_t * restrict, const char * restrict); 47 | 48 | /* 49 | * Exported functions. 50 | */ 51 | 52 | unsigned int 53 | check_psk(SSL *ssl, const char *identity, unsigned char *password, 54 | unsigned int max_password_len) 55 | { 56 | cfg_t *auth; 57 | const char *configured_pw; 58 | size_t password_len; 59 | 60 | if ((auth = hash_lookup(identity)) == NULL 61 | && (auth = hash_lookup("*")) == NULL) { 62 | warning("Client-supplied ID `%s' is unknown", identity); 63 | return 0; 64 | } 65 | debug("Verifying key provided by %s", identity); 66 | 67 | /* 68 | * With (at least) OpenSSL 1.1.1b, SSL_get_psk_identity(3) returns NULL 69 | * when TLSv1.3 is used. As a workaround, we store the ID ourselves: 70 | */ 71 | if (SSL_set_app_data(ssl, xstrdup(identity)) != 1) { 72 | error("Cannot store client-supplied ID (`%s')", identity); 73 | return 0; 74 | } 75 | 76 | configured_pw = cfg_getstr(auth, "password"); 77 | password_len = MIN(strlen(configured_pw), max_password_len); 78 | (void)memcpy(password, configured_pw, password_len); 79 | return (unsigned int)password_len; 80 | } 81 | 82 | bool 83 | is_authorized(const char * restrict identity, const char * restrict command) 84 | { 85 | const char *settings[] = { "hosts", "services", "commands" }; 86 | cfg_t *auth; 87 | char *newline; 88 | size_t i; 89 | 90 | if ((auth = hash_lookup(identity)) == NULL 91 | && (auth = hash_lookup("*")) == NULL) { 92 | /* Shouldn't happen, as the client is authenticated. */ 93 | error("Cannot find authorizations for %s", identity); 94 | return false; 95 | } 96 | if ((newline = strchr(command, '\n')) == NULL) { 97 | warning("Command submitted by %s isn't newline-terminated", 98 | identity); 99 | return false; 100 | } 101 | if (*(newline + 1) != '\0') { 102 | warning("Command submitted by %s contains embedded newline(s)", 103 | identity); 104 | return false; 105 | } 106 | /* Match against the command without the leading bracketed timestamp. */ 107 | if ((command = strchr(command, ']')) == NULL) { 108 | warning("Timestamp missing from command submitted by %s", 109 | identity); 110 | return false; 111 | } 112 | command = skip_whitespace(command + 1); 113 | 114 | for (i = 0; i < sizeof(settings) / sizeof(*settings); i++) { 115 | cfg_opt_t *opt = cfg_getopt(auth, settings[i]); 116 | unsigned int j; 117 | 118 | for (j = 0; j < cfg_opt_size(opt); j++) { 119 | regex_t *pattern = cfg_opt_getnptr(opt, j); 120 | 121 | if (match(pattern, command)) 122 | return true; 123 | } 124 | } 125 | return false; 126 | } 127 | 128 | /* 129 | * Static functions. 130 | */ 131 | 132 | static bool 133 | match(regex_t * restrict pattern, const char * restrict command) 134 | { 135 | char errbuf[128]; 136 | int result = regexec(pattern, command, 0, NULL, 0); 137 | 138 | switch (result) { 139 | case 0: 140 | return true; 141 | case REG_NOMATCH: 142 | return false; 143 | default: 144 | (void)regerror(result, pattern, errbuf, sizeof(errbuf)); 145 | error("Error matching command: %s", errbuf); 146 | return false; 147 | } 148 | } 149 | 150 | /* vim:set joinspaces noexpandtab textwidth=80 cinoptions=(4,u0: */ 151 | -------------------------------------------------------------------------------- /src/server/auth.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 Holger Weiss 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 19 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | * POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef AUTH_H 29 | # define AUTH_H 30 | 31 | # if HAVE_CONFIG_H 32 | # include 33 | # endif 34 | 35 | # include 36 | 37 | # include "system.h" 38 | 39 | unsigned int check_psk(SSL *, const char *, unsigned char *, unsigned int); 40 | bool is_authorized(const char * restrict, const char * restrict); 41 | 42 | #endif 43 | 44 | /* vim:set joinspaces noexpandtab textwidth=80 cinoptions=(4,u0: */ 45 | -------------------------------------------------------------------------------- /src/server/conf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 Holger Weiss 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 19 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | * POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef CONF_H 29 | # define CONF_H 30 | 31 | # if HAVE_CONFIG_H 32 | # include 33 | # endif 34 | 35 | # include 36 | 37 | # include "system.h" 38 | 39 | # define DEFAULT_CONF_FILE SYSCONFDIR "/nsca-ng.cfg" 40 | # define DEFAULT_PORT "5668" 41 | 42 | cfg_t *conf_parse(const char *); 43 | 44 | #endif 45 | 46 | /* vim:set joinspaces noexpandtab textwidth=80 cinoptions=(4,u0: */ 47 | -------------------------------------------------------------------------------- /src/server/fifo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 Holger Weiss 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 19 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | * POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef FIFO_H 29 | # define FIFO_H 30 | 31 | # if HAVE_CONFIG_H 32 | # include 33 | # endif 34 | 35 | # include "system.h" 36 | 37 | typedef struct fifo_state_s fifo_state; 38 | 39 | fifo_state *fifo_start(const char * restrict, const char * restrict, size_t); 40 | void fifo_write(fifo_state * restrict, void * restrict, size_t, 41 | void (*)(void *)); 42 | void fifo_stop(fifo_state *); 43 | 44 | #endif 45 | 46 | /* vim:set joinspaces noexpandtab textwidth=80 cinoptions=(4,u0: */ 47 | -------------------------------------------------------------------------------- /src/server/hash.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 Holger Weiss 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 19 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | * POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | /* 29 | * NOTE: hdestroy(3) cannot be used in a sane and portable way. On BSD, 30 | * hdestroy(3) calls free(3) on all keys; on Linux, it doesn't. So, if we ever 31 | * need multiple hash tables, we should use a different implementation, such as 32 | * . 33 | */ 34 | 35 | #if HAVE_CONFIG_H 36 | # include 37 | #endif 38 | 39 | #include 40 | 41 | #include "hash.h" 42 | #include "log.h" 43 | #include "system.h" 44 | 45 | void 46 | hash_new(size_t size) 47 | { 48 | debug("Creating hash table for %zu entries", size); 49 | 50 | if (hcreate(size) == 0) 51 | die("Cannot create hash table: %m"); 52 | } 53 | 54 | void 55 | hash_insert(const char * restrict key, void * restrict value) 56 | { 57 | ENTRY e, *p; 58 | 59 | e.key = (char *)key; 60 | e.data = NULL; /* Initialize to make Clang's Static Analyzer happy. */ 61 | 62 | /* 63 | * Quoting the Linux man page: 64 | * 65 | * | SVr4 and POSIX.1-2001 specify that 'action' is significant only for 66 | * | unsuccessful searches, so that an ENTER should not do anything for 67 | * | a successful search. In libc and glibc (before version 2.3), the 68 | * | implementation violates the specification, updating the 'data' for 69 | * | the given 'key' in this case. 70 | * 71 | * In order to replace existing entries on all systems, we update the 72 | * value after searching for the entry. (However, nsca-ng will never 73 | * call this function with an existing key.) 74 | */ 75 | if ((p = hsearch(e, ENTER)) == NULL) 76 | die("Cannot insert `%s' into hash table: %m", key); 77 | p->data = value; 78 | } 79 | 80 | void * 81 | hash_lookup(const char *key) 82 | { 83 | ENTRY e, *p; 84 | 85 | e.key = (char *)key; 86 | e.data = NULL; /* Initialize to make Clang's Static Analyzer happy. */ 87 | 88 | if ((p = hsearch(e, FIND)) == NULL) 89 | return NULL; 90 | else 91 | return p->data; 92 | } 93 | 94 | /* vim:set joinspaces noexpandtab textwidth=80 cinoptions=(4,u0: */ 95 | -------------------------------------------------------------------------------- /src/server/hash.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 Holger Weiss 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 19 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | * POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef HASH_H 29 | # define HASH_H 30 | 31 | # if HAVE_CONFIG_H 32 | # include 33 | # endif 34 | 35 | # include /* For size_t. */ 36 | 37 | # include "system.h" 38 | 39 | void hash_new(size_t); 40 | void hash_insert(const char * restrict, void * restrict); 41 | void *hash_lookup(const char *); 42 | 43 | #endif 44 | 45 | /* vim:set joinspaces noexpandtab textwidth=80 cinoptions=(4,u0: */ 46 | -------------------------------------------------------------------------------- /src/server/server.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013 Holger Weiss 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright notice, 9 | * this list of conditions and the following disclaimer. 10 | * 11 | * 2. Redistributions in binary form must reproduce the above copyright notice, 12 | * this list of conditions and the following disclaimer in the documentation 13 | * and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 19 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | * POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef SERVER_H 29 | # define SERVER_H 30 | 31 | # if HAVE_CONFIG_H 32 | # include 33 | # endif 34 | 35 | # include 36 | 37 | # include "system.h" 38 | 39 | typedef struct server_state_s server_state; 40 | 41 | server_state *server_start(const char * restrict, const char * restrict, 42 | const char * restrict, const char * restrict, 43 | size_t, size_t, ev_tstamp); 44 | void server_stop(server_state *); 45 | 46 | #endif 47 | 48 | /* vim:set joinspaces noexpandtab textwidth=80 cinoptions=(4,u0: */ 49 | -------------------------------------------------------------------------------- /tests/Makefile.am: -------------------------------------------------------------------------------- 1 | ## Process this file with automake(1) to produce Makefile.in. 2 | 3 | ## Copyright (c) 2013 Holger Weiss 4 | ## All rights reserved. 5 | ## 6 | ## Redistribution and use in source and binary forms, with or without 7 | ## modification, are permitted provided that the following conditions are met: 8 | ## 9 | ## 1. Redistributions of source code must retain the above copyright notice, 10 | ## this list of conditions and the following disclaimer. 11 | ## 12 | ## 2. Redistributions in binary form must reproduce the above copyright notice, 13 | ## this list of conditions and the following disclaimer in the documentation 14 | ## and/or other materials provided with the distribution. 15 | ## 16 | ## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | ## AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | ## ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20 | ## LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 | ## CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 | ## SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 | ## INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 | ## CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 | ## ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 | ## POSSIBILITY OF SUCH DAMAGE. 27 | 28 | EXTRA_DIST = $(TESTSUITE) $(TESTSUITE_AT) package.m4 atlocal.in 29 | DISTCLEANFILES = atconfig 30 | 31 | # 32 | # Build test_nsca. 33 | # 34 | 35 | AM_CPPFLAGS = -I$(top_srcdir)/lib 36 | LDADD = ../lib/libcompat.a 37 | 38 | noinst_PROGRAMS = test_nsca 39 | 40 | # 41 | # Build the rest of our test suite (see the Autoconf manual). 42 | # 43 | 44 | TESTSUITE_AT = \ 45 | $(srcdir)/testsuite.at \ 46 | $(srcdir)/local.at \ 47 | $(srcdir)/basic.at \ 48 | $(srcdir)/input.at \ 49 | $(srcdir)/auth.at 50 | TESTSUITE = $(srcdir)/testsuite 51 | AUTOM4TE = $(SHELL) $(top_srcdir)/build-aux/missing --run autom4te 52 | AUTOTEST = $(AUTOM4TE) --language=autotest 53 | 54 | check-local: $(TESTSUITE) atconfig atlocal test_nsca 55 | $(AM_V_at)$(SHELL) '$(TESTSUITE)' $(TESTSUITEFLAGS) 56 | 57 | installcheck-local: $(TESTSUITE) atconfig atlocal test_nsca 58 | $(AM_V_at)$(SHELL) '$(TESTSUITE)' AUTOTEST_PATH='tests:$(sbindir)' \ 59 | $(TESTSUITEFLAGS) 60 | 61 | clean-local: 62 | test ! -f '$(TESTSUITE)' || $(SHELL) '$(TESTSUITE)' --clean 63 | 64 | $(TESTSUITE): $(TESTSUITE_AT) $(srcdir)/package.m4 65 | $(AM_V_GEN)$(AUTOTEST) -I '$(srcdir)' -o $@.tmp $@.at 66 | $(AM_V_at)mv $@.tmp $@ 67 | 68 | # The `:;' works around a Bash 3.2 bug when the output is not writable. 69 | $(srcdir)/package.m4: $(top_srcdir)/configure.ac 70 | $(AM_V_at):;{ \ 71 | echo '# Signature of the current package.' && \ 72 | echo 'm4_define([AT_PACKAGE_NAME],' && \ 73 | echo ' [$(PACKAGE_NAME)])' && \ 74 | echo 'm4_define([AT_PACKAGE_TARNAME],' && \ 75 | echo ' [$(PACKAGE_TARNAME)])' && \ 76 | echo 'm4_define([AT_PACKAGE_VERSION],' && \ 77 | echo ' [$(PACKAGE_VERSION)])' && \ 78 | echo 'm4_define([AT_PACKAGE_STRING],' && \ 79 | echo ' [$(PACKAGE_STRING)])' && \ 80 | echo 'm4_define([AT_PACKAGE_BUGREPORT],' && \ 81 | echo ' [$(PACKAGE_BUGREPORT)])'; \ 82 | echo 'm4_define([AT_PACKAGE_URL],' && \ 83 | echo ' [$(PACKAGE_URL)])'; \ 84 | } >'$(srcdir)/package.m4' 85 | -------------------------------------------------------------------------------- /tests/atlocal.in: -------------------------------------------------------------------------------- 1 | # @configure_input@ 2 | 3 | # Copyright (c) 2013 Holger Weiss 4 | # All rights reserved. 5 | # 6 | # Redistribution and use in source and binary forms, with or without 7 | # modification, are permitted provided that the following conditions are met: 8 | # 9 | # 1. Redistributions of source code must retain the above copyright notice, this 10 | # list of conditions and the following disclaimer. 11 | # 12 | # 2. Redistributions in binary form must reproduce the above copyright notice, 13 | # this list of conditions and the following disclaimer in the documentation 14 | # and/or other materials provided with the distribution. 15 | # 16 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 20 | # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | nsca_pipe_buf='@nsca_pipe_buf@' 28 | 29 | # vim:set joinspaces noexpandtab textwidth=80: 30 | -------------------------------------------------------------------------------- /tests/auth.at: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013 Holger Weiss 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without 5 | # modification, are permitted provided that the following conditions are met: 6 | # 7 | # 1. Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # 2. Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | 25 | AT_BANNER([Authentication and authorization.]) 26 | 27 | AT_SETUP([Incorrect password]) 28 | NSCA_CHECK([jupiter 0 jupiter is alive], [], [stderr], [], [], 29 | [password = "incorrect"], [], [1]) 30 | AT_CHECK([[grep '^send_nsca: \[FATAL\] TLS error (127.0.0.1): ' stderr]], [0], 31 | [ignore]) 32 | AT_CLEANUP 33 | 34 | AT_SETUP([Unauthorized submission]) 35 | NSCA_CHECK([jupiter 0 jupiter is alive], [], 36 | [[send_nsca: [FATAL] Server said: FAIL You're not authorized]], [], [], [], 37 | [authorize "*" { password = "forty-two" commands = "none" }], [1]) 38 | AT_CLEANUP 39 | 40 | AT_SETUP([Legitimate host check result]) 41 | NSCA_CHECK([jupiter 0 jupiter is alive], 42 | [PROCESS_HOST_CHECK_RESULT;jupiter;0;jupiter is alive], [], [], [], [], 43 | [authorize "*" { password = "forty-two" hosts = "jupiter" }]) 44 | AT_CLEANUP 45 | 46 | AT_SETUP([Legitimate service check result]) 47 | NSCA_CHECK([jupiter disk 0 disk is fine], 48 | [PROCESS_SERVICE_CHECK_RESULT;jupiter;disk;0;disk is fine], [], [], [], [], 49 | [authorize "*" { password = "forty-two" services = "disk" }]) 50 | AT_CLEANUP 51 | 52 | AT_SETUP([Malicious host check result]) 53 | NSCA_CHECK([saturn 0 jupiter;0;tricked you!], [], 54 | [[send_nsca: [FATAL] Server said: FAIL You're not authorized]], [], [], [], 55 | [authorize "*" { password = "forty-two" hosts = "jupiter" }], [1]) 56 | AT_CLEANUP 57 | 58 | AT_SETUP([Malicious service check result]) 59 | NSCA_CHECK([jupiter http 0 disk;0;tricked you!], [], 60 | [[send_nsca: [FATAL] Server said: FAIL You're not authorized]], [], [], [], 61 | [authorize "*" { password = "forty-two" services = "disk" }], [1]) 62 | AT_CLEANUP 63 | 64 | dnl vim:set joinspaces textwidth=80 filetype=m4: 65 | -------------------------------------------------------------------------------- /tests/basic.at: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013 Holger Weiss 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without 5 | # modification, are permitted provided that the following conditions are met: 6 | # 7 | # 1. Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # 2. Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | 25 | AT_BANNER([Basic functionality.]) 26 | 27 | AT_SETUP([Host check result]) 28 | NSCA_CHECK([jupiter 0 jupiter is alive], 29 | [PROCESS_HOST_CHECK_RESULT;jupiter;0;jupiter is alive]) 30 | AT_CLEANUP 31 | 32 | AT_SETUP([Host check result, special delimiter]) 33 | NSCA_CHECK([jupiter/0/jupiter is alive], 34 | [PROCESS_HOST_CHECK_RESULT;jupiter;0;jupiter is alive], [], [-d /]) 35 | AT_CLEANUP 36 | 37 | AT_SETUP([Service check result]) 38 | NSCA_CHECK([saturn http 0 HTTP is happy], 39 | [PROCESS_SERVICE_CHECK_RESULT;saturn;http;0;HTTP is happy]) 40 | AT_CLEANUP 41 | 42 | AT_SETUP([Service check result, special delimiter]) 43 | NSCA_CHECK([saturn/http/0/HTTP is happy], 44 | [PROCESS_SERVICE_CHECK_RESULT;saturn;http;0;HTTP is happy], [], [-d /]) 45 | AT_CLEANUP 46 | 47 | AT_SETUP([Monitoring command]) 48 | NSCA_CHECK([[[1360095440]] ADD_HOST_COMMENT;jupiter;1;John Doe;Useless comment], 49 | [ADD_HOST_COMMENT;jupiter;1;John Doe;Useless comment], [], [-C]) 50 | AT_CLEANUP 51 | 52 | AT_SETUP([Monitoring command, no timestamp]) 53 | NSCA_CHECK([ADD_HOST_COMMENT;jupiter;1;John Doe;Useless comment], 54 | [ADD_HOST_COMMENT;jupiter;1;John Doe;Useless comment], [], [-C]) 55 | AT_CLEANUP 56 | 57 | dnl vim:set joinspaces textwidth=80 filetype=m4: 58 | -------------------------------------------------------------------------------- /tests/input.at: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2013 Holger Weiss 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without 5 | # modification, are permitted provided that the following conditions are met: 6 | # 7 | # 1. Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # 2. Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | 25 | AT_BANNER([Unusual input.]) 26 | 27 | AT_SETUP([Multiline check result]) 28 | NSCA_CHECK([jupiter 0 jupiter 29 | is alive], [PROCESS_HOST_CHECK_RESULT;jupiter;0;jupiter\n is alive]) 30 | AT_CLEANUP 31 | 32 | AT_SETUP([Multiple check results]) 33 | printf 'jupiter\t0\tresult 1\n' >input 34 | printf '\27' >>input 35 | printf 'jupiter\t0\tresult 2\n' >>input 36 | printf '\27' >>input 37 | printf 'jupiter\t0\tresult 3\n' >>input 38 | NSCA_CHECK([input], [dnl 39 | PROCESS_HOST_CHECK_RESULT;jupiter;0;result 1 40 | PROCESS_HOST_CHECK_RESULT;jupiter;0;result 2 41 | PROCESS_HOST_CHECK_RESULT;jupiter;0;result 3], [], [], [], [], [], [0], [3]) 42 | AT_CLEANUP 43 | 44 | AT_SETUP([Multiple results, colon-separated]) 45 | printf 'jupiter\t0\tresult 1\n' >input 46 | printf ':' >>input 47 | printf 'jupiter\t0\tresult 2\n' >>input 48 | printf ':' >>input 49 | printf 'jupiter\t0\tresult 3\n' >>input 50 | NSCA_CHECK([input], [dnl 51 | PROCESS_HOST_CHECK_RESULT;jupiter;0;result 1 52 | PROCESS_HOST_CHECK_RESULT;jupiter;0;result 2 53 | PROCESS_HOST_CHECK_RESULT;jupiter;0;result 3], [], [-e :], [], [], [], [0], [3]) 54 | AT_CLEANUP 55 | 56 | AT_SETUP([Multiple monitoring commands]) 57 | cat >input <<'NSCA_EOF' 58 | PROCESS_HOST_CHECK_RESULT;saturn;0;result 1 59 | PROCESS_HOST_CHECK_RESULT;saturn;0;result 2 60 | PROCESS_HOST_CHECK_RESULT;saturn;0;result 3 61 | NSCA_EOF 62 | ln input expout 63 | NSCA_CHECK([input], [expout], [], [-C], [], [], [], [0], [3]) 64 | AT_CLEANUP 65 | 66 | AT_SETUP([Result with trailing ETB and newline]) 67 | printf 'jupiter\t0\tjupiter is alive\n' >input 68 | printf '\27\n' >>input 69 | NSCA_CHECK([input], [PROCESS_HOST_CHECK_RESULT;jupiter;0;jupiter is alive]) 70 | AT_CLEANUP 71 | 72 | AT_SETUP([Incorrect input format]) 73 | NSCA_CHECK([garbage], [], 74 | [[send_nsca: [FATAL] Input format incorrect, see the send_nsca(8) man page]], 75 | [], [], [], [], [1]) 76 | AT_CLEANUP 77 | 78 | AT_SETUP([Data size exceeds max_command_size]) 79 | NSCA_CHECK([jupiter 0 jupiter is alive], [], 80 | [[send_nsca: [FATAL] Server said: FAIL PUSH data size too large]], [], [], [], 81 | [max_command_size = 10 82 | authorize "*" { 83 | password = "forty-two" 84 | commands = ".*" 85 | }], [1]) 86 | AT_CLEANUP 87 | 88 | AT_SETUP([Data size exceeds PIPE_BUF]) 89 | cat >input <server.cfg < 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without 5 | # modification, are permitted provided that the following conditions are met: 6 | # 7 | # 1. Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # 2. Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | 25 | # Initialize Autotest. 26 | AT_INIT 27 | 28 | # Enable colored test output. 29 | AT_COLOR_TESTS 30 | 31 | # Log the `--version' of our programs. 32 | AT_TESTED([test_nsca]) 33 | 34 | # NSCA_CHECK([INPUT], [STDOUT], [STDERR], [CLIENT-FLAGS], [SERVER-FLAGS], 35 | # [CLIENT-CONF], [SERVER-CONF], [STATUS = 0], [COMMANDS = 1]) 36 | # ----------------------------------------------------------------------- 37 | # Transmit the given INPUT to the nsca-ng(8) server using send_nsca(8). If the 38 | # INPUT consists of multiple monitoring commands, the number of COMMANDS must be 39 | # specified. The data written to the FIFO by the server is then checked against 40 | # STDOUT, send_nsca(8)'s standard error output is checked against STDERR, and 41 | # the exit status is checked against STATUS. Non-default CLIENT-CONF and/or 42 | # SERVER-CONF contents may be specified. See also the AT_CHECK documentation. 43 | m4_define([NSCA_CHECK], 44 | [ 45 | dnl Put together the command line. 46 | m4_define([nsca_cmd_line], [ 2 | # All rights reserved. 3 | # 4 | # Redistribution and use in source and binary forms, with or without 5 | # modification, are permitted provided that the following conditions are met: 6 | # 7 | # 1. Redistributions of source code must retain the above copyright notice, this 8 | # list of conditions and the following disclaimer. 9 | # 10 | # 2. Redistributions in binary form must reproduce the above copyright notice, 11 | # this list of conditions and the following disclaimer in the documentation 12 | # and/or other materials provided with the distribution. 13 | # 14 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 18 | # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 21 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 22 | # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | 25 | m4_include([basic.at]) 26 | m4_include([input.at]) 27 | m4_include([auth.at]) 28 | 29 | dnl vim:set joinspaces textwidth=80 filetype=m4: 30 | --------------------------------------------------------------------------------