Date: Sat, 28 Apr 2007 14:49:49 -0400 (EDT) From: Antoine Beaupre <anarcat@koumbit.org> To: FreeBSD-gnats-submit@FreeBSD.org Subject: ports/112210: New port: nagircbot Message-ID: <20070428184949.B1A5C171DD@lethe.koumbit.net> Resent-Message-ID: <200704281910.l3SJA6XN050314@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 112210 >Category: ports >Synopsis: New port: nagircbot >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-ports-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Sat Apr 28 19:10:05 GMT 2007 >Closed-Date: >Last-Modified: >Originator: Antoine Beaupre >Release: FreeBSD 6.2-RELEASE-p2 i386 >Organization: Koumbit >Environment: System: FreeBSD lethe.koumbit.net 6.2-RELEASE-p2 FreeBSD 6.2-RELEASE-p2 #0: Fri Mar 9 14:54:27 EST 2007 anarcat@lethe.koumbit.net:/usr/obj/usr/src/sys/LETHE6 i386 >Description: Nagircbot is an IRC bot that monitors Nagios's status file for changes and announces those in an IRC channel. It can also change the topic of the channel to reflect current status. >How-To-Repeat: The upstream source has been severly patched to work under freebsd, and it would be appreciated if a peer could review the actual code for security issues. >Fix: # This is a shell archive. Save it in a file, remove anything before # this line, and then unpack it by entering "sh file". Note, it may # create directories; files and directories will be owned by you and # have default permissions. # # This archive contains: # # nagircbot # nagircbot/pkg-descr # nagircbot/distinfo # nagircbot/Makefile # nagircbot/files # nagircbot/files/patch-anna.cpp # nagircbot/files/patch-Makefile # nagircbot/files/patch-br.cpp # nagircbot/files/patch-br.h # nagircbot/files/patch-utils.h # nagircbot/files/patch-utils.cpp # nagircbot/files/nagircbot.sh # nagircbot/files/patch-error.c # nagircbot/files/patch-anna.h # echo c - nagircbot mkdir -p nagircbot > /dev/null 2>&1 echo x - nagircbot/pkg-descr sed 's/^X//' >nagircbot/pkg-descr << 'END-of-nagircbot/pkg-descr' XNagircbot is an IRC bot that monitors Nagios's status file for changes and Xannounces those in an IRC channel. It can also change the topic of the channel Xto reflect current status. X XWWW: http://www.vanheusden.com/nagircbot/ END-of-nagircbot/pkg-descr echo x - nagircbot/distinfo sed 's/^X//' >nagircbot/distinfo << 'END-of-nagircbot/distinfo' XMD5 (nagircbot-0.0.20.tgz) = c4692e5557d278b597cff0cec09dd0e0 XSHA256 (nagircbot-0.0.20.tgz) = 22164ff2290c4bf2bebda60d5c09438f61e1973529d03a53bebd3bb36e43fc59 XSIZE (nagircbot-0.0.20.tgz) = 17548 END-of-nagircbot/distinfo echo x - nagircbot/Makefile sed 's/^X//' >nagircbot/Makefile << 'END-of-nagircbot/Makefile' X# New ports collection makefile for: backupninja X# Date created: 7 june 2006 X# Whom: anarcat X# X# $FreeBSD$ X# X XPORTNAME= nagircbot XPORTVERSION= 0.0.20 XCATEGORIES= net-mgmt irc XMASTER_SITES= http://www.vanheusden.com/nagircbot/ XEXTRACT_SUFX= .tgz X XMAINTAINER= anarcat@anarcat.ath.cx XCOMMENT= IRC bot for Nagios X XPLIST_FILES= bin/nagircbot XUSE_GMAKE= yes X Xpost-install: X ${INSTALL_SCRIPT} ${FILESDIR}/nagircbot.sh ${PREFIX}/etc/rc.d/nagircbot.sh X X.include <bsd.port.mk> END-of-nagircbot/Makefile echo c - nagircbot/files mkdir -p nagircbot/files > /dev/null 2>&1 echo x - nagircbot/files/patch-anna.cpp sed 's/^X//' >nagircbot/files/patch-anna.cpp << 'END-of-nagircbot/files/patch-anna.cpp' X--- anna.cpp.orig Mon Nov 27 06:21:58 2006 X+++ anna.cpp Sat Apr 28 14:24:58 2007 X@@ -12,6 +12,8 @@ X #include <stdlib.h> X #include <signal.h> X #include <pwd.h> X+#include <sys/param.h> X+#include <libutil.h> X X #include "utils.h" X #include "pl.h" X@@ -19,6 +21,7 @@ X #include "error.h" X #include "log.h" X } X+#include "anna.h" X X #define S_DISCONNECTED 1 X #define S_CONNECTED 2 X@@ -166,7 +169,7 @@ X X /* open file or connection to nagios status socket */ X if (is_file == 1) /* file */ X- fd = open64(statuslog, O_RDONLY); X+ fd = open(statuslog, O_RDONLY); X else X fd = connect_to(statuslog); X if (fd == -1) X@@ -416,7 +419,7 @@ X if (verbose > 1) dolog("reload_statuslog started"); X X if (statuslog_location == L_FILE) /* file */ X- fd_sl = open64(statuslog, O_RDONLY); X+ fd_sl = open(statuslog, O_RDONLY); X else X fd_sl = connect_to(statuslog); X X@@ -712,6 +715,7 @@ X printf("-z user user to run as\n"); X printf("-H show only state type 'HARD' (default)\n"); X printf("-S show also state type 'SOFT'\n"); X+ printf("-P file store the pid in a file\n"); X } X X int main(int argc, char *argv[]) X@@ -724,14 +728,19 @@ X time_t time_join_channel_started = (time_t)0; X time_t time_tcp_connected = (time_t)0; X int join_tries = 0; X- char *runas = NULL; X+ char *runas = NULL, *pidfile = NULL; X+ pid_t otherpid; X+ X X color_str[0][0] = color_str[1][0] = color_str[2][0] = color_str[3][0] = 3; X X- while((c = getopt(argc, argv, "xXF:f:i:hHSs:c:Ctn:u:U:p:T:mvdVz:")) != -1) X+ while((c = getopt(argc, argv, "xXP:F:f:i:hHSs:c:Ctn:u:U:p:T:mvdVz:")) != -1) X { X switch(c) X { X+ case 'P': X+ pidfile = optarg; X+ break; X case 'z': X runas = optarg; X break; X@@ -875,6 +884,17 @@ X } X } X X+ pfh = pidfile_open(pidfile, 0600, &otherpid); X+ if (pfh == NULL) { X+ if (errno == EEXIST) X+ error_exit("Daemon already running, pid: %d.", otherpid); X+ /* If we cannot create pidfile from other reasons, only warn. */ X+ dolog("Cannot open or create pidfile"); X+ } X+ X+ pidfile_write(pfh); X+ X+ X signal(SIGPIPE, SIG_IGN); X X for(;;) X@@ -1056,5 +1076,6 @@ X } X } X X+ pidfile_remove(pfh); X return 0; X } END-of-nagircbot/files/patch-anna.cpp echo x - nagircbot/files/patch-Makefile sed 's/^X//' >nagircbot/files/patch-Makefile << 'END-of-nagircbot/files/patch-Makefile' X--- Makefile.orig Mon Nov 27 06:21:58 2006 X+++ Makefile Sat Apr 28 14:14:16 2007 X@@ -1,9 +1,10 @@ X VERSION=0.0.20 X X DEBUG= -g -D_DEBUG #-fprofile-arcs -ftest-coverage # -pg -g X-CXXFLAGS+=-Wall -O2 -DVERSION=\"${VERSION}\" $(DEBUG) X+CXXFLAGS+=-DUSE_MMAP -Wall -O2 -DVERSION=\"${VERSION}\" $(DEBUG) X CFLAGS+=${CXXFLAGS} X-LDFLAGS+=$(DEBUG) -lstdc++ X+LDFLAGS+=$(DEBUG) -lstdc++ -lutil X+PREFIX?=/usr/local X X OBJS=error.o log.o utils.o br.o pl.o anna.o X X@@ -13,7 +14,7 @@ X $(CC) -Wall -W $(OBJS) $(LDFLAGS) -o nagircbot X X install: nagircbot X- cp nagircbot /usr/local/bin X+ cp nagircbot ${PREFIX}/bin X X clean: X rm -f $(OBJS) nagircbot core *.da *.gcov *.bb* END-of-nagircbot/files/patch-Makefile echo x - nagircbot/files/patch-br.cpp sed 's/^X//' >nagircbot/files/patch-br.cpp << 'END-of-nagircbot/files/patch-br.cpp' X--- br.cpp.orig Mon Nov 27 06:21:58 2006 X+++ br.cpp Sat Apr 28 13:45:23 2007 X@@ -29,11 +29,12 @@ X #include <fcntl.h> X #include <syslog.h> X #include "br.h" X+#include "utils.h" X X buffered_reader::buffered_reader(int cur_fd, int cur_block_size) X { X #ifdef USE_MMAP X- struct stat64 finfo; X+ struct stat finfo; X #endif X X fd = cur_fd; X@@ -44,20 +45,20 @@ X X /* try do mmap */ X #ifdef USE_MMAP X- if (fstat64(cur_fd, &finfo) == 0) X+ if (fstat(cur_fd, &finfo) == 0) X { X if (!S_ISFIFO(finfo.st_mode)) X { X /* mmap */ X size_of_file = finfo.st_size; X- cur_offset = mmap_addr = (char *)mmap64(NULL, size_of_file, PROT_READ, MAP_SHARED, cur_fd, 0); X+ cur_offset = mmap_addr = (char *)mmap(NULL, size_of_file, PROT_READ, MAP_SHARED, cur_fd, 0); X if (!mmap_addr) X { X- fprintf(stderr, "mmap64 failed: %d/%s\n", errno, strerror(errno)); X+ fprintf(stderr, "mmap failed: %d/%s\n", errno, strerror(errno)); X } X X /* advise the kernel how to treat the mmaped region */ X- /* FIXME: change to madvise64 as soon as it comes available */ X+ /* FIXME: change to madvise as soon as it comes available */ X (void)madvise(mmap_addr, size_of_file, MADV_SEQUENTIAL); X X // fprintf(stderr, "*using mmap*\n"); X@@ -237,7 +238,7 @@ X X n_bytes = lf_offset - buffer_pointer; X X- out = strndup(&buffer[buffer_pointer], n_bytes); X+ out = mystrndup(&buffer[buffer_pointer], n_bytes); X if (!out) X { X fprintf(stderr, "buffered_reader::read_line: malloc(%lld) failed\n", n_bytes + 1); X@@ -251,10 +252,10 @@ X return out; X } X X-off64_t buffered_reader::file_offset(void) X+off_t buffered_reader::file_offset(void) X { X if (mmap_addr) X return cur_offset - mmap_addr; X else X- return lseek64(fd, 0, SEEK_CUR); X+ return lseek(fd, 0, SEEK_CUR); X } END-of-nagircbot/files/patch-br.cpp echo x - nagircbot/files/patch-br.h sed 's/^X//' >nagircbot/files/patch-br.h << 'END-of-nagircbot/files/patch-br.h' X--- br.h.orig Mon Nov 27 06:21:58 2006 X+++ br.h Sat Apr 28 13:45:23 2007 X@@ -16,6 +16,8 @@ X * X */ X X+#include <sys/types.h> X+ X /* code taken from linux kernel */ X #if __GNUC__ == 2 && __GNUC_MINOR__ < 96 X #define __builtin_expect(x, expected_value) (x) X@@ -33,7 +35,7 @@ X char *buffer; X long long int buffer_length, buffer_pointer; X char *mmap_addr, *cur_offset; X- off64_t size_of_file; X+ off_t size_of_file; X X int number_of_bytes_in_buffer(void); X int read_into_buffer(void); X@@ -46,5 +48,5 @@ X X char * read_line(void); X X- off64_t file_offset(void); X+ off_t file_offset(void); X }; END-of-nagircbot/files/patch-br.h echo x - nagircbot/files/patch-utils.h sed 's/^X//' >nagircbot/files/patch-utils.h << 'END-of-nagircbot/files/patch-utils.h' X--- utils.h.orig Mon Nov 27 06:21:58 2006 X+++ utils.h Sat Apr 28 13:45:23 2007 X@@ -19,7 +19,7 @@ X void * mymalloc(int size, char *what); X void * myrealloc(void *oldp, int newsize, char *what); X char * mystrdup(char *in); X-char * mtstrndup(char *in, int len); X+char * mystrndup(char *in, int len); X void myfree(void *p, char *what); X ssize_t WRITE(int fd, char *whereto, size_t len); X int get_filesize(char *filename); END-of-nagircbot/files/patch-utils.h echo x - nagircbot/files/patch-utils.cpp sed 's/^X//' >nagircbot/files/patch-utils.cpp << 'END-of-nagircbot/files/patch-utils.cpp' X--- utils.cpp.orig Mon Nov 27 06:21:58 2006 X+++ utils.cpp Sat Apr 28 13:45:23 2007 X@@ -29,6 +29,7 @@ X #include <netdb.h> X #include <sys/types.h> X #include <sys/socket.h> X+#include <netinet/in.h> X extern "C" { X #include "error.h" X } END-of-nagircbot/files/patch-utils.cpp echo x - nagircbot/files/nagircbot.sh sed 's/^X//' >nagircbot/files/nagircbot.sh << 'END-of-nagircbot/files/nagircbot.sh' X#!/bin/sh X# X# $FreeBSD: ports/net-mgmt/nrpe2/files/nrpe2.sh.in,v 1.2 2006/02/20 20:47:33 dougb Exp $ X# X X# PROVIDE: nagircbot X# REQUIRE: NETWORKING X# KEYWORD: shutdown X X# X# Add the following lines to /etc/rc.conf to enable nagircbot: X# X#nagircbot_enable="YES" X# X# You must configure at least some flags to make it connect to a server. See -h. X# X X. /etc/rc.subr X Xname=nagircbot Xrcvar=`set_rcvar` X Xpidfile=/var/run/nagios/${name}.pid Xcommand="/usr/local/bin/nagircbot" Xcommand_args="-P $pidfile -z nagios" X X# set defaults X Xnagircbot_enable=${nagircbot_enable:-"NO"} Xnagircbot_flags=${nagircbot_flags:-""} X Xload_rc_config ${name} Xrun_rc_command "$1" END-of-nagircbot/files/nagircbot.sh echo x - nagircbot/files/patch-error.c sed 's/^X//' >nagircbot/files/patch-error.c << 'END-of-nagircbot/files/patch-error.c' X--- error.c.orig Sat Apr 28 14:08:54 2007 X+++ error.c Sat Apr 28 14:17:12 2007 X@@ -5,6 +5,9 @@ X #include <sys/types.h> X #include <signal.h> X #include <syslog.h> X+#include <sys/param.h> X+#include <libutil.h> X+#include "anna.h" X X void error_exit(char *format, ...) X { X@@ -17,6 +20,7 @@ X X fprintf(stderr, "%s: errno=%d (if applicable)\n", buffer, errno); X syslog(LOG_ERR, "'%s': %m", buffer); X+ pidfile_remove(pfh); X X exit(EXIT_FAILURE); X } END-of-nagircbot/files/patch-error.c echo x - nagircbot/files/patch-anna.h sed 's/^X//' >nagircbot/files/patch-anna.h << 'END-of-nagircbot/files/patch-anna.h' X--- /dev/null Sat Apr 28 14:15:01 2007 X+++ anna.h Sat Apr 28 14:16:47 2007 X@@ -0,0 +1 @@ X+struct pidfh *pfh; END-of-nagircbot/files/patch-anna.h exit >Release-Note: >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20070428184949.B1A5C171DD>