ChangeLog | 13 ++++ NEWS | 6 ++ configure.in | 2 +- contrib/Debian/.gitignore | 4 + contrib/Debian/Makefile.am | 7 ++- contrib/Debian/changelog | 19 +++++ contrib/Debian/control | 28 +++++++- contrib/Debian/rules | 81 +++++++++++++++++---- contrib/Makefile.am | 5 +- contrib/README | 11 ++-- contrib/ngircd-bsd.sh | 51 +++++++++++++ contrib/ngircd-redhat.init | 119 +++++++++++++++++++++++++++++++ contrib/ngircd.sh | 51 ------------- contrib/ngircd.spec | 2 +- doc/src/footer.inc.html | 2 +- src/ngircd/channel.c | 8 +- src/ngircd/channel.h | 8 +- src/ngircd/client.c | 168 ++++++++++++++++++++------------------------ src/ngircd/client.h | 24 +++--- src/ngircd/conf.c | 8 +- src/ngircd/conf.h | 8 +- src/ngircd/conn-func.c | 55 +++++++-------- src/ngircd/conn-zip.c | 69 ++++++++++-------- src/ngircd/conn-zip.h | 2 +- src/ngircd/conn.c | 26 ++++---- src/ngircd/conn.h | 2 +- src/ngircd/irc-info.c | 54 +++++---------- src/ngircd/irc-login.c | 19 ++--- src/ngircd/irc-mode.c | 11 +-- src/ngircd/irc-oper.c | 7 -- src/ngircd/irc-server.c | 73 +++++++------------- src/ngircd/irc-write.c | 34 ++++----- src/ngircd/log.c | 19 +---- src/ngircd/ngircd.c | 43 ++++------- src/ngircd/numeric.c | 2 +- src/ngircd/parse.c | 39 +++-------- 36 files changed, 601 insertions(+), 479 deletions(-) diff --git a/ChangeLog b/ChangeLog index c5bc401..adba5f6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -10,6 +10,19 @@ -- ChangeLog -- +ngIRCd Release 14.1 (2009-05-05) + + - Security: fix remotely triggerable crash in SSL/TLS code. + - BSD start script contrib/ngircd.sh has been renamed to ngircd-bsd.sh. + - New start/stop script for RedHat-based distributions: + contrib/ngircd-redhat.init, thanks to Naoya Nakazawa . + - Doxygen: update source code repository link to GIT. + - Debian: build ngircd-full-dbg package. + - Allow ping timeout quit messages to show the timeout value. + - Fix error handling on compressed links. + - Fix server list announcement. + - Do not remove hostnames from info text. + ngIRCd Release 14 (2009-04-20) - Display IPv6 addresses as "[]" when accepting connections. diff --git a/NEWS b/NEWS index e92a57c..25494c2 100644 --- a/NEWS +++ b/NEWS @@ -10,6 +10,12 @@ -- NEWS -- +ngIRCd Release 14.1 (2009-05-05) + + - Security: fix remotely triggerable crash in SSL/TLS code. + - Debian: build ngircd-full-dbg package. + - Allow ping timeout quit messages to show the timeout value. + ngIRCd Release 14 (2009-04-20) ngIRCd 14~rc1 (2009-03-29) diff --git a/configure.in b/configure.in index 221875d..6738dd6 100644 --- a/configure.in +++ b/configure.in @@ -12,7 +12,7 @@ # -- Initialisation -- AC_PREREQ(2.50) -AC_INIT(ngircd, 14) +AC_INIT(ngircd, 14.1) AC_CONFIG_SRCDIR(src/ngircd/ngircd.c) AC_CANONICAL_TARGET AM_INIT_AUTOMAKE(1.6) diff --git a/contrib/Debian/.gitignore b/contrib/Debian/.gitignore index f2a4c05..111d4ac 100644 --- a/contrib/Debian/.gitignore +++ b/contrib/Debian/.gitignore @@ -7,3 +7,7 @@ ngircd-full/ ngircd-full.default ngircd-full.init ngircd-full.postinst +ngircd-full-dbg/ +ngircd-full-dbg.default +ngircd-full-dbg.init +ngircd-full-dbg.postinst diff --git a/contrib/Debian/Makefile.am b/contrib/Debian/Makefile.am index f3d02a5..b20da99 100644 --- a/contrib/Debian/Makefile.am +++ b/contrib/Debian/Makefile.am @@ -1,6 +1,6 @@ # # ngIRCd -- The Next Generation IRC Daemon -# Copyright (c)2001-2008 Alexander Barton (alex@barton.de) +# Copyright (c)2001-2009 Alexander Barton (alex@barton.de) # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -20,7 +20,10 @@ clean-local: ngircd.prerm.debhelper ngircd.substvars rm -f ngircd-full.postinst.debhelper ngircd-full.postrm.debhelper \ ngircd-full.prerm.debhelper ngircd-full.substvars - rm -rf ngircd ngircd-full + rm -f ngircd-full-dbg.postinst.debhelper \ + ngircd-full-dbg.postrm.debhelper ngircd-full-dbg.prerm.debhelper \ + ngircd-full-dbg.substvars + rm -rf ngircd ngircd-full ngircd-full-dbg rm -f files # -eof- diff --git a/contrib/Debian/changelog b/contrib/Debian/changelog index 9999779..abfad7f 100644 --- a/contrib/Debian/changelog +++ b/contrib/Debian/changelog @@ -1,3 +1,22 @@ +ngircd (14.1-0ab1) unstable; urgency=high + + * New "upstream" release ngIRCd 14.1, fixing a security-related bug. + + -- Alexander Barton Tue, 5 May 2009 13:13:38 +0200 + +ngircd (14-0ab3) unstable; urgency=low + + * Fixed "Conflicts:" line in debian/control: missing comma. + + -- Alexander Barton Mon, 4 May 2009 11:21:55 +0200 + +ngircd (14-0ab2) unstable; urgency=low + + * Add new "ngircd-full-dbg" package including degug code and both + the --debug and --sniffer options, and containing debug symbols. + + -- Alexander Barton Wed, 29 Apr 2009 01:13:03 +0200 + ngircd (14-0ab1) unstable; urgency=low * New "upstream" release: ngIRCd 14. diff --git a/contrib/Debian/control b/contrib/Debian/control index 543c5ad..13163ce 100644 --- a/contrib/Debian/control +++ b/contrib/Debian/control @@ -32,7 +32,7 @@ Package: ngircd-full Architecture: any Depends: ${shlibs:Depends}, ${misc:Depends} Provides: ircd -Conflicts: ngircd +Conflicts: ngircd, ngircd-dbg Description: A lightweight daemon for the Internet Relay Chat (IRC) ngIRCd is a free open source daemon for the Internet Relay Chat (IRC) network. It is written from scratch and is not based upon the original @@ -50,3 +50,29 @@ Description: A lightweight daemon for the Internet Relay Chat (IRC) . ngIRCd is compatible to the "original" ircd 2.10.3p3, so you can run mixed networks. + +Package: ngircd-full-dbg +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends} +Provides: ircd +Conflicts: ngircd, ngircd-full +Description: A lightweight daemon for the Internet Relay Chat (IRC) + ngIRCd is a free open source daemon for the Internet Relay Chat (IRC) + network. It is written from scratch and is not based upon the original + IRCd like many others. + . + In addition to the features of the "standard package", this package + includes support for TCP wrappers, IDENT requests, the IPv6 protocol and + SSL encrypted client and server links. + . + And in addition to the "full" variant, the binaries contained in this + package are build with debug code and contain debug symbols. + . + Advantages of ngIRCd: + - no problems with servers using changing/non-static IP addresses. + - small and lean configuration file. + - free, modern and open source C code. + - still under active development. + . + ngIRCd is compatible to the "original" ircd 2.10.3p3, so you can run + mixed networks. diff --git a/contrib/Debian/rules b/contrib/Debian/rules index 5648846..5f6f826 100755 --- a/contrib/Debian/rules +++ b/contrib/Debian/rules @@ -1,7 +1,7 @@ #!/usr/bin/make -f # # ngIRCd -- The Next Generation IRC Daemon -# Copyright (c)2001-2008 Alexander Barton +# Copyright (c)2001-2009 Alexander Barton # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -36,7 +36,7 @@ endif configure-ngircd: configure dh_testdir - + # configure "standard" variant: ./configure --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) \ --prefix=/usr \ @@ -46,7 +46,7 @@ configure-ngircd: configure configure-ngircd-full: configure dh_testdir - + # configure "full" variant: ./configure --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) \ --prefix=/usr \ @@ -56,6 +56,19 @@ configure-ngircd-full: configure --with-gnutls --with-ident --with-tcp-wrappers \ --enable-ipv6 +configure-ngircd-full-dbg: configure + dh_testdir + + # configure "full debug" variant: + ./configure --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) \ + --prefix=/usr \ + --sysconfdir=/etc/ngircd \ + --mandir=\$${prefix}/share/man \ + --enable-debug --enable-sniffer \ + --with-syslog --with-zlib \ + --with-gnutls --with-ident --with-tcp-wrappers \ + --enable-ipv6 + build: dh_clean -k @@ -63,20 +76,30 @@ build-ngircd: build-stamp-ngircd build-stamp-ngircd: configure-ngircd dh_testdir rm -f build-stamp-* - + # Add here commands to compile the "standard" package: $(MAKE) - + touch build-stamp-ngircd build-ngircd-full: build-stamp-ngircd-full build-stamp-ngircd-full: configure-ngircd-full dh_testdir rm -f build-stamp-* - + # Add here commands to compile the "full" package: $(MAKE) - + + touch build-stamp-ngircd-full + +build-ngircd-full-dbg: build-stamp-ngircd-full-dbg +build-stamp-ngircd-full-dbg: configure-ngircd-full-dbg + dh_testdir + rm -f build-stamp-* + + # Add here commands to compile the "full debug" package: + $(MAKE) + touch build-stamp-ngircd-full clean: @@ -86,10 +109,13 @@ clean: rm -f $(CURDIR)/debian/ngircd-full.default rm -f $(CURDIR)/debian/ngircd-full.init rm -f $(CURDIR)/debian/ngircd-full.postinst - + rm -f $(CURDIR)/debian/ngircd-full-dbg.default + rm -f $(CURDIR)/debian/ngircd-full-dbg.postinst + rm -f $(CURDIR)/debian/ngircd-full-dbg.init + # Add here commands to clean up after the build process: [ ! -f Makefile ] || $(MAKE) distclean - + ifneq "$(wildcard /usr/share/misc/config.sub)" "" cp -f /usr/share/misc/config.sub config.sub endif @@ -98,13 +124,13 @@ ifneq "$(wildcard /usr/share/misc/config.guess)" "" endif dh_clean -install: install-ngircd install-ngircd-full +install: install-ngircd install-ngircd-full install-ngircd-full-dbg install-ngircd: build-ngircd dh_testdir dh_testroot dh_installdirs - + # Add here commands to install the "standard" package into debian/ngircd: $(MAKE) install DESTDIR=$(CURDIR)/debian/ngircd rm $(CURDIR)/debian/ngircd/usr/share/doc/ngircd/INSTALL* @@ -122,7 +148,7 @@ install-ngircd-full: build-ngircd-full dh_testdir dh_testroot dh_installdirs - + # Add here commands to install the "full" package into debian/ngircd-full: $(MAKE) install DESTDIR=$(CURDIR)/debian/ngircd-full rm $(CURDIR)/debian/ngircd-full/usr/share/doc/ngircd/INSTALL* @@ -138,6 +164,26 @@ install-ngircd-full: build-ngircd-full >$(CURDIR)/debian/ngircd-full/etc/ngircd/ngircd.conf touch $(CURDIR)/debian/ngircd-full/etc/ngircd/ngircd.motd +install-ngircd-full-dbg: build-ngircd-full-dbg + dh_testdir + dh_testroot + dh_installdirs + + # Add here commands to install the "full" package into debian/ngircd-full: + $(MAKE) install DESTDIR=$(CURDIR)/debian/ngircd-full-dbg + rm $(CURDIR)/debian/ngircd-full-dbg/usr/share/doc/ngircd/INSTALL* + rm $(CURDIR)/debian/ngircd-full-dbg/usr/share/doc/ngircd/COPYING* + mv $(CURDIR)/debian/ngircd-full-dbg/usr/share/doc/ngircd \ + $(CURDIR)/debian/ngircd-full-dbg/usr/share/doc/ngircd-full-dbg + mkdir -p $(CURDIR)/debian/ngircd-full-dbg/var/run/ircd + cat $(CURDIR)/debian/ngircd-full-dbg/usr/share/doc/ngircd-full-dbg/sample-ngircd.conf | \ + sed -e "s/;ServerUID = 65534/ServerUID = irc/g" | \ + sed -e "s/;ServerGID = 65534/ServerGID = irc/g" | \ + sed -e "s/;MotdFile = \/usr\/local\/etc\/ngircd.motd/MotdFile = \/etc\/ngircd\/ngircd.motd/g" | \ + sed -e "s/;PidFile = \/var\/run\/ngircd\/ngircd.pid/PidFile = \/var\/run\/ircd\/ngircd.pid/g" \ + >$(CURDIR)/debian/ngircd-full-dbg/etc/ngircd/ngircd.conf + touch $(CURDIR)/debian/ngircd-full-dbg/etc/ngircd/ngircd.motd + # Build architecture-independent files here. binary-indep: # We have nothing to do by default. @@ -150,13 +196,20 @@ binary-arch: build install $(CURDIR)/debian/ngircd-full.init ln -s $(CURDIR)/debian/ngircd.postinst \ $(CURDIR)/debian/ngircd-full.postinst - + + ln -s $(CURDIR)/debian/ngircd.default \ + $(CURDIR)/debian/ngircd-full-dbg.default + ln -s $(CURDIR)/debian/ngircd.init \ + $(CURDIR)/debian/ngircd-full-dbg.init + ln -s $(CURDIR)/debian/ngircd.postinst \ + $(CURDIR)/debian/ngircd-full-dbg.postinst + dh_testdir dh_testroot dh_installchangelogs -a -A ChangeLog dh_installdocs -a dh_installinit -a - dh_strip -a + dh_strip -a --no-package=ngircd-full-dbg dh_compress -a dh_fixperms -a dh_installdeb -a diff --git a/contrib/Makefile.am b/contrib/Makefile.am index 2125c10..ab6b342 100644 --- a/contrib/Makefile.am +++ b/contrib/Makefile.am @@ -1,6 +1,6 @@ # # ngIRCd -- The Next Generation IRC Daemon -# Copyright (c)2001-2008 Alexander Barton (alex@barton.de) +# Copyright (c)2001-2009 Alexander Barton (alex@barton.de) # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -11,7 +11,8 @@ SUBDIRS = Debian MacOSX -EXTRA_DIST = README ngircd.spec systrace.policy ngindent ngircd.sh +EXTRA_DIST = README ngircd.spec systrace.policy ngindent ngircd-bsd.sh \ + ngircd-redhat.init maintainer-clean-local: rm -f Makefile Makefile.in diff --git a/contrib/README b/contrib/README index f32005e..353e2bb 100644 --- a/contrib/README +++ b/contrib/README @@ -1,7 +1,7 @@ ngIRCd - Next Generation IRC Server - (c)2001-2005 Alexander Barton, + (c)2001-2009 Alexander Barton, alex@barton.de, http://www.barton.de/ ngIRCd is free software and published under the @@ -19,15 +19,14 @@ MacOSX/ ngindent - Script to indent the code of ngIRCd in the "standard way". -ngircd.sh +ngircd-bsd.sh - Start script for FreeBSD. +ngircd-redhat.init + - Start/stop script for RedHat-based distributions (like CentOS). + ngircd.spec - RPM "spec" file. systrace.policy - Systrace policy file for OpenBSD (and probably NetBSD). - - --- -$Id: README,v 1.3 2006/07/23 11:34:32 alex Exp $ diff --git a/contrib/ngircd-bsd.sh b/contrib/ngircd-bsd.sh new file mode 100644 index 0000000..e085646 --- /dev/null +++ b/contrib/ngircd-bsd.sh @@ -0,0 +1,51 @@ +#!/bin/sh + +# PROVIDE: ngircd +# REQUIRE: NETWORKING SERVERS +# BEFORE: DAEMON +# KEYWORD: FreeBSD shutdown + +# Add the following line to /etc/rc.conf to enable `ngircd': +# +#ngircd_enable="YES" +# + +. "/etc/rc.subr" + +name="ngircd" +rcvar=`set_rcvar` + +command="/usr/local/sbin/ngircd" +command_args="" + +load_rc_config "$name" +: ${ngircd_enable="NO"} +: ${ngircd_flags=""} + +required_files="/usr/local/etc/$name.conf" +pidfile="${ngircd_pidfile:-/var/run/${name}/${name}.pid}" + +if [ ! x"${ngircd_chrootdir}" = x ];then + # Mount a devfs in the chroot directory if needed + if [ ! -c ${ngircd_chrootdir}/dev/random \ + -o ! -c ${ngircd_chrootdir}/dev/null ]; then + umount ${ngircd_chrootdir}/dev 2>/dev/null + mount_devfs devfs ${ngircd_chrootdir}/dev + fi + + devfs -m ${ngircd_chrootdir}/dev rule apply hide + devfs -m ${ngircd_chrootdir}/dev rule apply path null unhide + devfs -m ${ngircd_chrootdir}/dev rule apply path random unhide + + # Copy local timezone information if it is not up to date. + if [ -f /etc/localtime ]; then + cmp -s /etc/localtime "${named_chrootdir}/etc/localtime" || \ + cp -p /etc/localtime "${named_chrootdir}/etc/localtime" + fi + + pidfile="${ngircd_chrootdir}${pidfile}" +fi + +run_rc_command "$1" + +# -eof- diff --git a/contrib/ngircd-redhat.init b/contrib/ngircd-redhat.init new file mode 100644 index 0000000..f63eba7 --- /dev/null +++ b/contrib/ngircd-redhat.init @@ -0,0 +1,119 @@ +#!/bin/sh +# +# ngIRCd start and stop script for RedHat based distributions. +# Written by Naoya Nakazawa for CentOS 5.2, 2009. +# +# chkconfig: 2345 01 +# description: ngIRCd is an Open Source server for \ +# the Internet Relay Chat (IRC), which \ +# is developed and published under \ +# the terms of the GNU General Public +# Licence (URL: http://www.gnu.org/licenses/gpl.html). \ +# ngIRCd means "next generation IRC daemon", \ +# it's written from scratch and not deduced from the \ +# "grandfather of IRC daemons", the daemon of the IRCNet. +# +# processname: /usr/sbin/ngircd +# config: /etc/ngircd +# pidfile: /var/run/ngircd.pid + +PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin +DAEMON=/usr/sbin/ngircd +NAME=ngIRCd +BASENAME=ngircd +CONF=/etc/$BASENAME.conf +DESC="IRC daemon" +PARAMS="-f $CONF" + +# Source function library. +. /etc/init.d/functions + +# Get config. +test -f /etc/sysconfig/network && . /etc/sysconfig/network +test -f /etc/sysconfig/makuosan && . /etc/sysconfig/makuosan + +# Check that networking is up. +[ "${NETWORKING}" = "yes" ] || exit 0 + +[ -x $DAEMON ] || exit 1 +[ -f $CONF ] || exit 2 + +RETVAL=0 + +start(){ + echo -n $"Starting $NAME: " + daemon $DAEMON $PARAMS + RETVAL=$? + [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$BASENAME + echo + return $RETVAL +} + +stop(){ + echo -n $"Stopping $NAME: " + killproc $DAEMON + RETVAL=$? + if [ $RETVAL -eq 0 ] ; then + rm -f /var/lock/subsys/$BASENAME + fi + echo + return $RETVAL +} + +reload(){ + echo -n $"Reloading configuration: " + killproc $DAEMON -HUP + RETVAL=$? + echo + return $RETVAL +} + +restart(){ + stop + start +} + +condrestart(){ + [ -e /var/lock/subsys/$BASENAME ] && restart + return 0 +} + +check_config(){ + $DAEMON $PARAMS --configtest >/dev/null 2>&1 + [ $? -eq 0 ] && return 0 + + echo -n $"Configuration of $NAME is not valid, won't (re)start!" + echo -n $"Run \"$DAEMON --configtest\" and fix it up ..." + exit 6 +} + +# See how we were called. +case "$1" in + start) + check_config + start + ;; + stop) + stop + ;; + status) + status $NAME + ;; + restart) + restart + ;; + reload) + reload + ;; + condrestart) + condrestart + ;; + test) + check_config + ;; + *) + echo $"Usage: $0 {start|stop|status|restart|condrestart|reload|test}" + RETVAL=1 +esac + +exit $RETVAL diff --git a/contrib/ngircd.sh b/contrib/ngircd.sh deleted file mode 100644 index e085646..0000000 --- a/contrib/ngircd.sh +++ /dev/null @@ -1,51 +0,0 @@ -#!/bin/sh - -# PROVIDE: ngircd -# REQUIRE: NETWORKING SERVERS -# BEFORE: DAEMON -# KEYWORD: FreeBSD shutdown - -# Add the following line to /etc/rc.conf to enable `ngircd': -# -#ngircd_enable="YES" -# - -. "/etc/rc.subr" - -name="ngircd" -rcvar=`set_rcvar` - -command="/usr/local/sbin/ngircd" -command_args="" - -load_rc_config "$name" -: ${ngircd_enable="NO"} -: ${ngircd_flags=""} - -required_files="/usr/local/etc/$name.conf" -pidfile="${ngircd_pidfile:-/var/run/${name}/${name}.pid}" - -if [ ! x"${ngircd_chrootdir}" = x ];then - # Mount a devfs in the chroot directory if needed - if [ ! -c ${ngircd_chrootdir}/dev/random \ - -o ! -c ${ngircd_chrootdir}/dev/null ]; then - umount ${ngircd_chrootdir}/dev 2>/dev/null - mount_devfs devfs ${ngircd_chrootdir}/dev - fi - - devfs -m ${ngircd_chrootdir}/dev rule apply hide - devfs -m ${ngircd_chrootdir}/dev rule apply path null unhide - devfs -m ${ngircd_chrootdir}/dev rule apply path random unhide - - # Copy local timezone information if it is not up to date. - if [ -f /etc/localtime ]; then - cmp -s /etc/localtime "${named_chrootdir}/etc/localtime" || \ - cp -p /etc/localtime "${named_chrootdir}/etc/localtime" - fi - - pidfile="${ngircd_chrootdir}${pidfile}" -fi - -run_rc_command "$1" - -# -eof- diff --git a/contrib/ngircd.spec b/contrib/ngircd.spec index dcd2650..1e72f30 100644 --- a/contrib/ngircd.spec +++ b/contrib/ngircd.spec @@ -1,5 +1,5 @@ %define name ngircd -%define version 14 +%define version 14.1 %define release 1 %define prefix %{_prefix} diff --git a/doc/src/footer.inc.html b/doc/src/footer.inc.html index c967b04..a3a9552 100644 --- a/doc/src/footer.inc.html +++ b/doc/src/footer.inc.html @@ -3,7 +3,7 @@

ngIRCd Homepage, - CVS-Repository, + GIT-Repository, Bug-Tracker.

diff --git a/src/ngircd/channel.c b/src/ngircd/channel.c index 0a1ba45..6f85072 100644 --- a/src/ngircd/channel.c +++ b/src/ngircd/channel.c @@ -198,7 +198,7 @@ Channel_Exit( void ) * Add_Client(). */ GLOBAL bool -Channel_Join( CLIENT *Client, char *Name ) +Channel_Join( CLIENT *Client, const char *Name ) { CHANNEL *chan; @@ -325,7 +325,7 @@ Channel_Kick(CLIENT *Peer, CLIENT *Target, CLIENT *Origin, const char *Name, GLOBAL void -Channel_Quit( CLIENT *Client, char *Reason ) +Channel_Quit( CLIENT *Client, const char *Reason ) { CHANNEL *c, *next_c; @@ -731,7 +731,7 @@ Channel_SetTopic(CHANNEL *Chan, CLIENT *Client, const char *Topic) GLOBAL void -Channel_SetModes( CHANNEL *Chan, char *Modes ) +Channel_SetModes( CHANNEL *Chan, const char *Modes ) { assert( Chan != NULL ); assert( Modes != NULL ); @@ -1042,7 +1042,7 @@ Channel_ShowInvites( CLIENT *Client, CHANNEL *Channel ) * Log a message to the local &SERVER channel, if it exists. */ GLOBAL void -Channel_LogServer(char *msg) +Channel_LogServer(const char *msg) { CHANNEL *sc; CLIENT *c; diff --git a/src/ngircd/channel.h b/src/ngircd/channel.h index b41cced..46e7e13 100644 --- a/src/ngircd/channel.h +++ b/src/ngircd/channel.h @@ -62,10 +62,10 @@ GLOBAL void Channel_Init PARAMS(( void )); GLOBAL void Channel_InitPredefined PARAMS(( void )); GLOBAL void Channel_Exit PARAMS(( void )); -GLOBAL bool Channel_Join PARAMS(( CLIENT *Client, char *Name )); +GLOBAL bool Channel_Join PARAMS(( CLIENT *Client, const char *Name )); GLOBAL bool Channel_Part PARAMS(( CLIENT *Client, CLIENT *Origin, const char *Name, const char *Reason )); -GLOBAL void Channel_Quit PARAMS(( CLIENT *Client, char *Reason )); +GLOBAL void Channel_Quit PARAMS(( CLIENT *Client, const char *Reason )); GLOBAL void Channel_Kick PARAMS((CLIENT *Peer, CLIENT *Target, CLIENT *Origin, const char *Name, const char *Reason)); @@ -81,7 +81,7 @@ GLOBAL char *Channel_Key PARAMS(( CHANNEL *Chan )); GLOBAL unsigned long Channel_MaxUsers PARAMS(( CHANNEL *Chan )); GLOBAL void Channel_SetTopic PARAMS(( CHANNEL *Chan, CLIENT *Client, const char *Topic )); -GLOBAL void Channel_SetModes PARAMS(( CHANNEL *Chan, char *Modes )); +GLOBAL void Channel_SetModes PARAMS(( CHANNEL *Chan, const char *Modes )); GLOBAL void Channel_SetKey PARAMS(( CHANNEL *Chan, const char *Key )); GLOBAL void Channel_SetMaxUsers PARAMS(( CHANNEL *Chan, unsigned long Count )); @@ -126,7 +126,7 @@ GLOBAL bool Channel_AddBan PARAMS((CHANNEL *c, const char *Mask )); GLOBAL bool Channel_ShowBans PARAMS((CLIENT *client, CHANNEL *c)); GLOBAL bool Channel_ShowInvites PARAMS((CLIENT *client, CHANNEL *c)); -GLOBAL void Channel_LogServer PARAMS((char *msg)); +GLOBAL void Channel_LogServer PARAMS((const char *msg)); GLOBAL bool Channel_CheckKey PARAMS((CHANNEL *Chan, CLIENT *Client, const char *Key)); diff --git a/src/ngircd/client.c b/src/ngircd/client.c index fbe130a..50648c9 100644 --- a/src/ngircd/client.c +++ b/src/ngircd/client.c @@ -49,7 +49,6 @@ static CLIENT *This_Server, *My_Clients; -static char GetID_Buffer[GETID_LEN]; static WHOWAS My_Whowas[MAX_WHOWAS]; static int Last_Whowas = -1; @@ -64,12 +63,12 @@ static void Generate_MyToken PARAMS(( CLIENT *Client )); static void Adjust_Counters PARAMS(( CLIENT *Client )); static CLIENT *Init_New_Client PARAMS((CONN_ID Idx, CLIENT *Introducer, - CLIENT *TopServer, int Type, char *ID, - char *User, char *Hostname, char *Info, - int Hops, int Token, char *Modes, + CLIENT *TopServer, int Type, const char *ID, + const char *User, const char *Hostname, const char *Info, + int Hops, int Token, const char *Modes, bool Idented)); -static void Destroy_UserOrService PARAMS((CLIENT *Client, char *Txt, char *FwdMsg, +static void Destroy_UserOrService PARAMS((CLIENT *Client,const char *Txt, const char *FwdMsg, bool SendQuit)); @@ -142,7 +141,7 @@ Client_ThisServer( void ) * @return New CLIENT structure. */ GLOBAL CLIENT * -Client_NewLocal(CONN_ID Idx, char *Hostname, int Type, bool Idented) +Client_NewLocal(CONN_ID Idx, const char *Hostname, int Type, bool Idented) { return Init_New_Client(Idx, This_Server, NULL, Type, NULL, NULL, Hostname, NULL, 0, 0, NULL, Idented); @@ -154,8 +153,8 @@ Client_NewLocal(CONN_ID Idx, char *Hostname, int Type, bool Idented) * @return New CLIENT structure. */ GLOBAL CLIENT * -Client_NewRemoteServer(CLIENT *Introducer, char *Hostname, CLIENT *TopServer, - int Hops, int Token, char *Info, bool Idented) +Client_NewRemoteServer(CLIENT *Introducer, const char *Hostname, CLIENT *TopServer, + int Hops, int Token, const char *Info, bool Idented) { return Init_New_Client(NONE, Introducer, TopServer, CLIENT_SERVER, Hostname, NULL, Hostname, Info, Hops, Token, NULL, Idented); @@ -167,8 +166,8 @@ Client_NewRemoteServer(CLIENT *Introducer, char *Hostname, CLIENT *TopServer, * @return New CLIENT structure. */ GLOBAL CLIENT * -Client_NewRemoteUser(CLIENT *Introducer, char *Nick, int Hops, char *User, - char *Hostname, int Token, char *Modes, char *Info, bool Idented) +Client_NewRemoteUser(CLIENT *Introducer, const char *Nick, int Hops, const char *User, + const char *Hostname, int Token, const char *Modes, const char *Info, bool Idented) { return Init_New_Client(NONE, Introducer, NULL, CLIENT_USER, Nick, User, Hostname, Info, Hops, Token, Modes, Idented); @@ -182,8 +181,8 @@ Client_NewRemoteUser(CLIENT *Introducer, char *Nick, int Hops, char *User, */ static CLIENT * Init_New_Client(CONN_ID Idx, CLIENT *Introducer, CLIENT *TopServer, - int Type, char *ID, char *User, char *Hostname, char *Info, int Hops, - int Token, char *Modes, bool Idented) + int Type, const char *ID, const char *User, const char *Hostname, const char *Info, int Hops, + int Token, const char *Modes, bool Idented) { CLIENT *client; @@ -194,7 +193,6 @@ Init_New_Client(CONN_ID Idx, CLIENT *Introducer, CLIENT *TopServer, client = New_Client_Struct( ); if( ! client ) return NULL; - /* Initialisieren */ client->starttime = time(NULL); client->conn_id = Idx; client->introducer = Introducer; @@ -212,11 +210,9 @@ Init_New_Client(CONN_ID Idx, CLIENT *Introducer, CLIENT *TopServer, if( strchr( client->modes, 'a' )) strlcpy( client->away, DEFAULT_AWAY_MSG, sizeof( client->away )); - /* Verketten */ client->next = (POINTER *)My_Clients; My_Clients = client; - /* Adjust counters */ Adjust_Counters( client ); return client; @@ -224,12 +220,13 @@ Init_New_Client(CONN_ID Idx, CLIENT *Introducer, CLIENT *TopServer, GLOBAL void -Client_Destroy( CLIENT *Client, char *LogMsg, char *FwdMsg, bool SendQuit ) +Client_Destroy( CLIENT *Client, const char *LogMsg, const char *FwdMsg, bool SendQuit ) { - /* Client entfernen. */ + /* remove a client */ CLIENT *last, *c; - char msg[LINE_LEN], *txt; + char msg[LINE_LEN]; + const char *txt; assert( Client != NULL ); @@ -237,7 +234,7 @@ Client_Destroy( CLIENT *Client, char *LogMsg, char *FwdMsg, bool SendQuit ) else txt = FwdMsg; if( ! txt ) txt = "Reason unknown."; - /* Netz-Split-Nachricht vorbereiten (noch nicht optimal) */ + /* netsplit message */ if( Client->type == CLIENT_SERVER ) { strlcpy(msg, This_Server->id, sizeof (msg)); strlcat(msg, " ", sizeof (msg)); @@ -250,8 +247,16 @@ Client_Destroy( CLIENT *Client, char *LogMsg, char *FwdMsg, bool SendQuit ) { if(( Client->type == CLIENT_SERVER ) && ( c->introducer == Client ) && ( c != Client )) { - /* der Client, der geloescht wird ist ein Server. Der Client, den wir gerade - * pruefen, ist ein Child von diesem und muss daher auch entfernt werden */ + /* + * The client that is about to be removed is a server, + * the client we are checking right now is a child of that + * server and thus has to be removed, too. + * + * Call Client_Destroy() recursively with the server as the + * new "object to be removed". This starts the cycle again, until + * all servers that are linked via the original server have been + * removed. + */ Client_Destroy( c, NULL, msg, false ); last = NULL; c = My_Clients; @@ -259,7 +264,7 @@ Client_Destroy( CLIENT *Client, char *LogMsg, char *FwdMsg, bool SendQuit ) } if( c == Client ) { - /* Wir haben den Client gefunden: entfernen */ + /* found the client: remove it */ if( last ) last->next = c->next; else My_Clients = (CLIENT *)c->next; @@ -273,7 +278,7 @@ Client_Destroy( CLIENT *Client, char *LogMsg, char *FwdMsg, bool SendQuit ) else Log( LOG_NOTICE|LOG_snotice, "Server \"%s\" unregistered: %s", c->id, txt ); } - /* andere Server informieren */ + /* inform other servers */ if( ! NGIRCd_SignalQuit ) { if( FwdMsg ) IRC_WriteStrServersPrefix( Client_NextHop( c ), c, "SQUIT %s :%s", c->id, FwdMsg ); @@ -302,10 +307,8 @@ Client_Destroy( CLIENT *Client, char *LogMsg, char *FwdMsg, bool SendQuit ) GLOBAL void -Client_SetHostname( CLIENT *Client, char *Hostname ) +Client_SetHostname( CLIENT *Client, const char *Hostname ) { - /* Hostname eines Clients setzen */ - assert( Client != NULL ); assert( Hostname != NULL ); @@ -314,10 +317,8 @@ Client_SetHostname( CLIENT *Client, char *Hostname ) GLOBAL void -Client_SetID( CLIENT *Client, char *ID ) +Client_SetID( CLIENT *Client, const char *ID ) { - /* Hostname eines Clients setzen, Hash-Wert berechnen */ - assert( Client != NULL ); assert( ID != NULL ); @@ -329,72 +330,68 @@ Client_SetID( CLIENT *Client, char *ID ) GLOBAL void -Client_SetUser( CLIENT *Client, char *User, bool Idented ) +Client_SetUser( CLIENT *Client, const char *User, bool Idented ) { - /* Username eines Clients setzen */ + /* set clients username */ assert( Client != NULL ); assert( User != NULL ); - if( Idented ) strlcpy( Client->user, User, sizeof( Client->user )); - else - { + if (Idented) { + strlcpy(Client->user, User, sizeof(Client->user)); + } else { Client->user[0] = '~'; - strlcpy( Client->user + 1, User, sizeof( Client->user ) - 1 ); + strlcpy(Client->user + 1, User, sizeof(Client->user) - 1); } } /* Client_SetUser */ GLOBAL void -Client_SetInfo( CLIENT *Client, char *Info ) +Client_SetInfo( CLIENT *Client, const char *Info ) { - /* Hostname eines Clients setzen */ + /* set client hostname */ assert( Client != NULL ); assert( Info != NULL ); - strlcpy( Client->info, Info, sizeof( Client->info )); + strlcpy(Client->info, Info, sizeof(Client->info)); } /* Client_SetInfo */ GLOBAL void -Client_SetModes( CLIENT *Client, char *Modes ) +Client_SetModes( CLIENT *Client, const char *Modes ) { - /* Modes eines Clients setzen */ - assert( Client != NULL ); assert( Modes != NULL ); - strlcpy( Client->modes, Modes, sizeof( Client->modes )); + strlcpy(Client->modes, Modes, sizeof( Client->modes )); } /* Client_SetModes */ GLOBAL void -Client_SetFlags( CLIENT *Client, char *Flags ) +Client_SetFlags( CLIENT *Client, const char *Flags ) { - /* Flags eines Clients setzen */ - assert( Client != NULL ); assert( Flags != NULL ); - strlcpy( Client->flags, Flags, sizeof( Client->flags )); + strlcpy(Client->flags, Flags, sizeof(Client->flags)); } /* Client_SetFlags */ GLOBAL void -Client_SetPassword( CLIENT *Client, char *Pwd ) +Client_SetPassword( CLIENT *Client, const char *Pwd ) { - /* Von einem Client geliefertes Passwort */ + /* set password sent by client */ assert( Client != NULL ); assert( Pwd != NULL ); - strlcpy( Client->pwd, Pwd, sizeof( Client->pwd )); + strlcpy(Client->pwd, Pwd, sizeof(Client->pwd)); } /* Client_SetPassword */ GLOBAL void -Client_SetAway( CLIENT *Client, char *Txt ) +Client_SetAway( CLIENT *Client, const char *Txt ) { /* Set AWAY reason of client */ @@ -463,9 +460,7 @@ Client_ModeAdd( CLIENT *Client, char Mode ) assert( Client != NULL ); x[0] = Mode; x[1] = '\0'; - if( ! strchr( Client->modes, x[0] )) - { - /* Client hat den Mode noch nicht -> setzen */ + if (!strchr( Client->modes, x[0])) { strlcat( Client->modes, x, sizeof( Client->modes )); return true; } @@ -518,16 +513,12 @@ Client_Search( const char *Nick ) ptr = strchr( search_id, '!' ); if( ptr ) *ptr = '\0'; - search_hash = Hash( search_id ); + search_hash = Hash(search_id); c = My_Clients; - while( c ) - { - if( c->hash == search_hash ) - { - /* lt. Hash-Wert: Treffer! */ - if( strcasecmp( c->id, search_id ) == 0 ) return c; - } + while (c) { + if (c->hash == search_hash && strcasecmp(c->id, search_id) == 0) + return c; c = (CLIENT *)c->next; } return NULL; @@ -547,9 +538,10 @@ Client_GetFromToken( CLIENT *Client, int Token ) assert( Token > 0 ); c = My_Clients; - while( c ) - { - if(( c->type == CLIENT_SERVER ) && ( c->introducer == Client ) && ( c->token == Token )) return c; + while (c) { + if ((c->type == CLIENT_SERVER) && (c->introducer == Client) && + (c->token == Token)) + return c; c = (CLIENT *)c->next; } return NULL; @@ -682,17 +674,20 @@ Client_NextHop( CLIENT *Client ) } /* Client_NextHop */ +/** + * return Client-ID ("client!user@host"), this ID is needed for e.g. + * prefixes. Returnes pointer to static buffer. + */ GLOBAL char * Client_Mask( CLIENT *Client ) { - /* Client-"ID" liefern, wie sie z.B. fuer - * Prefixe benoetigt wird. */ + static char GetID_Buffer[GETID_LEN]; assert( Client != NULL ); if( Client->type == CLIENT_SERVER ) return Client->id; - snprintf( GetID_Buffer, GETID_LEN, "%s!%s@%s", Client->id, Client->user, Client->host ); + snprintf(GetID_Buffer, GETID_LEN, "%s!%s@%s", Client->id, Client->user, Client->host); return GetID_Buffer; } /* Client_Mask */ @@ -724,8 +719,6 @@ Client_HasMode( CLIENT *Client, char Mode ) GLOBAL char * Client_Away( CLIENT *Client ) { - /* AWAY-Text liefern */ - assert( Client != NULL ); return Client->away; } /* Client_Away */ @@ -737,7 +730,7 @@ Client_CheckNick( CLIENT *Client, char *Nick ) assert( Client != NULL ); assert( Nick != NULL ); - if( ! Client_IsValidNick( Nick )) + if (! Client_IsValidNick( Nick )) { IRC_WriteStrClient( Client, ERR_ERRONEUSNICKNAME_MSG, Client_ID( Client ), Nick ); return false; @@ -758,8 +751,6 @@ Client_CheckNick( CLIENT *Client, char *Nick ) GLOBAL bool Client_CheckID( CLIENT *Client, char *ID ) { - /* Nick ueberpruefen */ - char str[COMMAND_LEN]; CLIENT *c; @@ -767,24 +758,22 @@ Client_CheckID( CLIENT *Client, char *ID ) assert( Client->conn_id > NONE ); assert( ID != NULL ); - /* Nick zu lang? */ - if( strlen( ID ) > CLIENT_ID_LEN ) - { - IRC_WriteStrClient( Client, ERR_ERRONEUSNICKNAME_MSG, Client_ID( Client ), ID ); + /* Nick too long? */ + if (strlen(ID) > CLIENT_ID_LEN) { + IRC_WriteStrClient(Client, ERR_ERRONEUSNICKNAME_MSG, Client_ID(Client), ID); return false; } - /* ID bereits vergeben? */ + /* does ID already exist? */ c = My_Clients; - while( c ) - { - if( strcasecmp( c->id, ID ) == 0 ) - { - /* die Server-ID gibt es bereits */ - snprintf( str, sizeof( str ), "ID \"%s\" already registered", ID ); - if( Client->conn_id != c->conn_id ) Log( LOG_ERR, "%s (on connection %d)!", str, c->conn_id ); - else Log( LOG_ERR, "%s (via network)!", str ); - Conn_Close( Client->conn_id, str, str, true); + while (c) { + if (strcasecmp(c->id, ID) == 0) { + snprintf(str, sizeof(str), "ID \"%s\" already registered", ID); + if (Client->conn_id != c->conn_id) + Log(LOG_ERR, "%s (on connection %d)!", str, c->conn_id); + else + Log(LOG_ERR, "%s (via network)!", str); + Conn_Close(Client->conn_id, str, str, true); return false; } c = (CLIENT *)c->next; @@ -797,8 +786,6 @@ Client_CheckID( CLIENT *Client, char *ID ) GLOBAL CLIENT * Client_First( void ) { - /* Ersten Client liefern. */ - return My_Clients; } /* Client_First */ @@ -806,9 +793,6 @@ Client_First( void ) GLOBAL CLIENT * Client_Next( CLIENT *c ) { - /* Naechsten Client liefern. Existiert keiner, - * so wird NULL geliefert. */ - assert( c != NULL ); return (CLIENT *)c->next; } /* Client_Next */ @@ -1137,7 +1121,7 @@ Client_TypeText(CLIENT *Client) * Destroy user or service client. */ static void -Destroy_UserOrService(CLIENT *Client, char *Txt, char *FwdMsg, bool SendQuit) +Destroy_UserOrService(CLIENT *Client, const char *Txt, const char *FwdMsg, bool SendQuit) { if(Client->conn_id != NONE) { /* Local (directly connected) client */ diff --git a/src/ngircd/client.h b/src/ngircd/client.h index 6fcf7b6..1064917 100644 --- a/src/ngircd/client.h +++ b/src/ngircd/client.h @@ -72,11 +72,11 @@ typedef struct _WHOWAS GLOBAL void Client_Init PARAMS(( void )); GLOBAL void Client_Exit PARAMS(( void )); -GLOBAL CLIENT *Client_NewLocal PARAMS(( CONN_ID Idx, char *Hostname, int Type, bool Idented )); -GLOBAL CLIENT *Client_NewRemoteServer PARAMS(( CLIENT *Introducer, char *Hostname, CLIENT *TopServer, int Hops, int Token, char *Info, bool Idented )); -GLOBAL CLIENT *Client_NewRemoteUser PARAMS(( CLIENT *Introducer, char *Nick, int Hops, char *User, char *Hostname, int Token, char *Modes, char *Info, bool Idented )); +GLOBAL CLIENT *Client_NewLocal PARAMS(( CONN_ID Idx, const char *Hostname, int Type, bool Idented )); +GLOBAL CLIENT *Client_NewRemoteServer PARAMS(( CLIENT *Introducer, const char *Hostname, CLIENT *TopServer, int Hops, int Token, const char *Info, bool Idented )); +GLOBAL CLIENT *Client_NewRemoteUser PARAMS(( CLIENT *Introducer, const char *Nick, int Hops, const char *User, const char *Hostname, int Token, const char *Modes, const char *Info, bool Idented )); -GLOBAL void Client_Destroy PARAMS(( CLIENT *Client, char *LogMsg, char *FwdMsg, bool SendQuit )); +GLOBAL void Client_Destroy PARAMS(( CLIENT *Client, const char *LogMsg, const char *FwdMsg, bool SendQuit )); GLOBAL CLIENT *Client_ThisServer PARAMS(( void )); @@ -108,19 +108,19 @@ GLOBAL time_t Client_StartTime PARAMS(( CLIENT *Client )); GLOBAL bool Client_HasMode PARAMS(( CLIENT *Client, char Mode )); -GLOBAL void Client_SetHostname PARAMS(( CLIENT *Client, char *Hostname )); -GLOBAL void Client_SetID PARAMS(( CLIENT *Client, char *Nick )); -GLOBAL void Client_SetUser PARAMS(( CLIENT *Client, char *User, bool Idented )); -GLOBAL void Client_SetInfo PARAMS(( CLIENT *Client, char *Info )); -GLOBAL void Client_SetPassword PARAMS(( CLIENT *Client, char *Pwd )); +GLOBAL void Client_SetHostname PARAMS(( CLIENT *Client, const char *Hostname )); +GLOBAL void Client_SetID PARAMS(( CLIENT *Client, const char *Nick )); +GLOBAL void Client_SetUser PARAMS(( CLIENT *Client, const char *User, bool Idented )); +GLOBAL void Client_SetInfo PARAMS(( CLIENT *Client, const char *Info )); +GLOBAL void Client_SetPassword PARAMS(( CLIENT *Client, const char *Pwd )); GLOBAL void Client_SetType PARAMS(( CLIENT *Client, int Type )); GLOBAL void Client_SetHops PARAMS(( CLIENT *Client, int Hops )); GLOBAL void Client_SetToken PARAMS(( CLIENT *Client, int Token )); GLOBAL void Client_SetOperByMe PARAMS(( CLIENT *Client, bool OperByMe )); -GLOBAL void Client_SetModes PARAMS(( CLIENT *Client, char *Modes )); -GLOBAL void Client_SetFlags PARAMS(( CLIENT *Client, char *Flags )); +GLOBAL void Client_SetModes PARAMS(( CLIENT *Client, const char *Modes )); +GLOBAL void Client_SetFlags PARAMS(( CLIENT *Client, const char *Flags )); GLOBAL void Client_SetIntroducer PARAMS(( CLIENT *Client, CLIENT *Introducer )); -GLOBAL void Client_SetAway PARAMS(( CLIENT *Client, char *Txt )); +GLOBAL void Client_SetAway PARAMS(( CLIENT *Client, const char *Txt )); GLOBAL bool Client_ModeAdd PARAMS(( CLIENT *Client, char Mode )); GLOBAL bool Client_ModeDel PARAMS(( CLIENT *Client, char Mode )); diff --git a/src/ngircd/conf.c b/src/ngircd/conf.c index 71f5760..a3c9afe 100644 --- a/src/ngircd/conf.c +++ b/src/ngircd/conf.c @@ -387,7 +387,7 @@ Conf_GetServer( CONN_ID Idx ) GLOBAL bool -Conf_EnableServer( char *Name, UINT16 Port ) +Conf_EnableServer( const char *Name, UINT16 Port ) { /* Enable specified server and adjust port */ @@ -426,7 +426,7 @@ Conf_EnablePassiveServer(const char *Name) GLOBAL bool -Conf_DisableServer( char *Name ) +Conf_DisableServer( const char *Name ) { /* Enable specified server and adjust port */ @@ -447,7 +447,7 @@ Conf_DisableServer( char *Name ) GLOBAL bool -Conf_AddServer( char *Name, UINT16 Port, char *Host, char *MyPwd, char *PeerPwd ) +Conf_AddServer( const char *Name, UINT16 Port, const char *Host, const char *MyPwd, const char *PeerPwd ) { /* Add new server to configuration */ @@ -481,7 +481,7 @@ Conf_AddServer( char *Name, UINT16 Port, char *Host, char *MyPwd, char *PeerPwd * Check if the given nick name is an service */ GLOBAL bool -Conf_IsService(int ConfServer, char *Nick) +Conf_IsService(int ConfServer, const char *Nick) { return MatchCaseInsensitive(Conf_Server[ConfServer].svs_mask, Nick); } /* Conf_IsService */ diff --git a/src/ngircd/conf.h b/src/ngircd/conf.h index 4695b25..9bdecde 100644 --- a/src/ngircd/conf.h +++ b/src/ngircd/conf.h @@ -180,12 +180,12 @@ GLOBAL void Conf_UnsetServer PARAMS(( CONN_ID Idx )); GLOBAL void Conf_SetServer PARAMS(( int ConfServer, CONN_ID Idx )); GLOBAL int Conf_GetServer PARAMS(( CONN_ID Idx )); -GLOBAL bool Conf_EnableServer PARAMS(( char *Name, UINT16 Port )); +GLOBAL bool Conf_EnableServer PARAMS(( const char *Name, UINT16 Port )); GLOBAL bool Conf_EnablePassiveServer PARAMS((const char *Name)); -GLOBAL bool Conf_DisableServer PARAMS(( char *Name )); -GLOBAL bool Conf_AddServer PARAMS(( char *Name, UINT16 Port, char *Host, char *MyPwd, char *PeerPwd )); +GLOBAL bool Conf_DisableServer PARAMS(( const char *Name )); +GLOBAL bool Conf_AddServer PARAMS(( const char *Name, UINT16 Port, const char *Host, const char *MyPwd, const char *PeerPwd )); -GLOBAL bool Conf_IsService PARAMS((int ConfServer, char *Nick)); +GLOBAL bool Conf_IsService PARAMS((int ConfServer, const char *Nick)); #endif diff --git a/src/ngircd/conn-func.c b/src/ngircd/conn-func.c index 8da62ae..196325e 100644 --- a/src/ngircd/conn-func.c +++ b/src/ngircd/conn-func.c @@ -16,8 +16,6 @@ #include "portab.h" -static char UNUSED id[] = "$Id: conn-func.c,v 1.12 2008/03/11 14:05:27 alex Exp $"; - #include "imp.h" #include #include @@ -33,8 +31,6 @@ static char UNUSED id[] = "$Id: conn-func.c,v 1.12 2008/03/11 14:05:27 alex Exp GLOBAL void Conn_UpdateIdle( CONN_ID Idx ) { - /* Idle-Timer zuruecksetzen */ - assert( Idx > NONE ); My_Connections[Idx].lastprivmsg = time( NULL ); } @@ -53,8 +49,7 @@ Conn_GetSignon(CONN_ID Idx) GLOBAL time_t Conn_GetIdle( CONN_ID Idx ) { - /* Idle-Time einer Verbindung liefern (in Sekunden) */ - + /* Return Idle-Timer of a connetion */ assert( Idx > NONE ); return time( NULL ) - My_Connections[Idx].lastprivmsg; } /* Conn_GetIdle */ @@ -63,8 +58,6 @@ Conn_GetIdle( CONN_ID Idx ) GLOBAL time_t Conn_LastPing( CONN_ID Idx ) { - /* Zeitpunkt des letzten PING liefern */ - assert( Idx > NONE ); return My_Connections[Idx].lastping; } /* Conn_LastPing */ @@ -73,11 +66,11 @@ Conn_LastPing( CONN_ID Idx ) GLOBAL void Conn_SetPenalty( CONN_ID Idx, time_t Seconds ) { - /* Penalty-Delay fuer eine Verbindung (in Sekunden) setzen; - * waehrend dieser Zeit wird der entsprechende Socket vom Server - * bei Lese-Operationen komplett ignoriert. Der Delay kann mit - * dieser Funktion nur erhoeht, nicht aber verringert werden. */ - + /* set Penalty-Delay for a socket. + * during the penalty, the socket is ignored completely, no new + * data is read. This function only increases the penalty, it is + * not possible to decrease the penalty time. + */ time_t t; assert( Idx > NONE ); @@ -105,8 +98,6 @@ Conn_ResetPenalty( CONN_ID Idx ) GLOBAL void Conn_ClearFlags( void ) { - /* Alle Connection auf "nicht-markiert" setzen */ - CONN_ID i; for( i = 0; i < Pool_Size; i++ ) My_Connections[i].flag = 0; @@ -116,8 +107,6 @@ Conn_ClearFlags( void ) GLOBAL int Conn_Flag( CONN_ID Idx ) { - /* Ist eine Connection markiert (true) oder nicht? */ - assert( Idx > NONE ); return My_Connections[Idx].flag; } /* Conn_Flag */ @@ -206,12 +195,12 @@ Conn_StartTime( CONN_ID Idx ) return 0; } /* Conn_StartTime */ - +/** + * return number of bytes queued for writing + */ GLOBAL size_t Conn_SendQ( CONN_ID Idx ) { - /* Laenge der Daten im Schreibbuffer liefern */ - assert( Idx > NONE ); #ifdef ZLIB if( My_Connections[Idx].options & CONN_ZIP ) @@ -222,31 +211,36 @@ Conn_SendQ( CONN_ID Idx ) } /* Conn_SendQ */ +/** + * return number of messages sent on this connection so far + */ GLOBAL long Conn_SendMsg( CONN_ID Idx ) { - /* Anzahl gesendeter Nachrichten liefern */ assert( Idx > NONE ); return My_Connections[Idx].msg_out; } /* Conn_SendMsg */ +/** + * return number of (uncompressed) bytes sent + * on this connection so far + */ GLOBAL long Conn_SendBytes( CONN_ID Idx ) { - /* Anzahl gesendeter Bytes (unkomprimiert) liefern */ - assert( Idx > NONE ); return My_Connections[Idx].bytes_out; } /* Conn_SendBytes */ +/** + * return number of bytes pending in read buffer + */ GLOBAL size_t Conn_RecvQ( CONN_ID Idx ) { - /* Laenge der Daten im Lesebuffer liefern */ - assert( Idx > NONE ); #ifdef ZLIB if( My_Connections[Idx].options & CONN_ZIP ) @@ -257,21 +251,24 @@ Conn_RecvQ( CONN_ID Idx ) } /* Conn_RecvQ */ +/** + * return number of messages received on this connection so far + */ GLOBAL long Conn_RecvMsg( CONN_ID Idx ) { - /* Anzahl empfangener Nachrichten liefern */ - assert( Idx > NONE ); return My_Connections[Idx].msg_in; } /* Conn_RecvMsg */ +/** + * return number of (uncompressed) bytes received on this + * connection so far + */ GLOBAL long Conn_RecvBytes( CONN_ID Idx ) { - /* Anzahl empfangener Bytes (unkomprimiert) liefern */ - assert( Idx > NONE ); return My_Connections[Idx].bytes_in; } /* Conn_RecvBytes */ diff --git a/src/ngircd/conn-zip.c b/src/ngircd/conn-zip.c index 826383b..24577ed 100644 --- a/src/ngircd/conn-zip.c +++ b/src/ngircd/conn-zip.c @@ -11,19 +11,15 @@ * Connection compression using ZLIB */ - #include "portab.h" #define CONN_MODULE - #ifdef ZLIB /* enable more zlib related debug messages: */ /* #define DEBUG_ZLIB */ -static char UNUSED id[] = "$Id: conn-zip.c,v 1.16 2007/05/17 23:34:24 alex Exp $"; - #include "imp.h" #include #include @@ -41,7 +37,7 @@ static char UNUSED id[] = "$Id: conn-zip.c,v 1.16 2007/05/17 23:34:24 alex Exp $ GLOBAL bool Zip_InitConn( CONN_ID Idx ) { - /* Kompression fuer Link initialisieren */ + /* initialize zlib compression on this link */ assert( Idx > NONE ); @@ -52,10 +48,8 @@ Zip_InitConn( CONN_ID Idx ) My_Connections[Idx].zip.in.zfree = NULL; My_Connections[Idx].zip.in.data_type = Z_ASCII; - if( inflateInit( &My_Connections[Idx].zip.in ) != Z_OK ) - { - /* Fehler! */ - Log( LOG_ALERT, "Can't initialize compression on connection %d (zlib inflate)!", Idx ); + if (inflateInit( &My_Connections[Idx].zip.in ) != Z_OK) { + Log(LOG_ALERT, "Can't initialize compression on connection %d (zlib inflate)!", Idx); return false; } @@ -65,17 +59,15 @@ Zip_InitConn( CONN_ID Idx ) My_Connections[Idx].zip.out.zfree = NULL; My_Connections[Idx].zip.out.data_type = Z_ASCII; - if( deflateInit( &My_Connections[Idx].zip.out, Z_DEFAULT_COMPRESSION ) != Z_OK ) - { - /* Fehler! */ - Log( LOG_ALERT, "Can't initialize compression on connection %d (zlib deflate)!", Idx ); + if (deflateInit( &My_Connections[Idx].zip.out, Z_DEFAULT_COMPRESSION ) != Z_OK) { + Log(LOG_ALERT, "Can't initialize compression on connection %d (zlib deflate)!", Idx); return false; } My_Connections[Idx].zip.bytes_in = My_Connections[Idx].bytes_in; My_Connections[Idx].zip.bytes_out = My_Connections[Idx].bytes_out; - Log( LOG_INFO, "Enabled link compression (zlib) on connection %d.", Idx ); + Log(LOG_INFO, "Enabled link compression (zlib) on connection %d.", Idx); Conn_OPTION_ADD( &My_Connections[Idx], CONN_ZIP ); return true; @@ -88,12 +80,14 @@ Zip_InitConn( CONN_ID Idx ) * compression ratios. * If the (pre-)compression buffer is full, we try to flush it ("actually * compress some data") and to add the new (uncompressed) data afterwards. + * This function closes the connection on error. * @param Idx Connection handle. * @param Data Pointer to the data. * @param Len Length of the data to add. - * @return true on success, false otherwise. */ + * @return true on success, false otherwise. + */ GLOBAL bool -Zip_Buffer( CONN_ID Idx, char *Data, size_t Len ) +Zip_Buffer( CONN_ID Idx, const char *Data, size_t Len ) { size_t buflen; @@ -110,9 +104,11 @@ Zip_Buffer( CONN_ID Idx, char *Data, size_t Len ) /* check again; if zip buf is still too large do not append data: * otherwise the zip wbuf would grow too large */ buflen = array_bytes(&My_Connections[Idx].zip.wbuf); - if (buflen + Len >= WRITEBUFFER_SLINK_LEN) + if (buflen + Len >= WRITEBUFFER_SLINK_LEN) { + Log(LOG_ALERT, "Zip Write Buffer overflow: %lu bytes\n", buflen + Len); + Conn_Close(Idx, "Zip Write buffer overflow", NULL, false); return false; - + } return array_catb(&My_Connections[Idx].zip.wbuf, Data, Len); } /* Zip_Buffer */ @@ -120,8 +116,9 @@ Zip_Buffer( CONN_ID Idx, char *Data, size_t Len ) /** * Compress data in ZIP buffer and move result to the write buffer of * the connection. + * This function closes the connection on error. * @param Idx Connection handle. - * @retrun true on success, false otherwise. + * @return true on success, false otherwise. */ GLOBAL bool Zip_Flush( CONN_ID Idx ) @@ -184,13 +181,17 @@ Zip_Flush( CONN_ID Idx ) } /* Zip_Flush */ +/** + * uncompress data and copy it to read buffer. + * Returns true if data has been unpacked or no + * compressed data is currently pending in the zread buffer. + * This function closes the connection on error. + * @param Idx Connection handle. + * @return true on success, false otherwise. + */ GLOBAL bool Unzip_Buffer( CONN_ID Idx ) { - /* Daten entpacken und in Lesepuffer kopieren. Bei Fehlern - * wird false geliefert, ansonsten true. Der Fall, dass keine - * Daten mehr zu entpacken sind, ist _kein_ Fehler! */ - int result; unsigned char unzipbuf[READBUFFER_LEN]; int unzipbuf_used = 0; @@ -221,8 +222,8 @@ Unzip_Buffer( CONN_ID Idx ) result = inflate( in, Z_SYNC_FLUSH ); if( result != Z_OK ) { - Log( LOG_ALERT, "Decompression error: %s (code=%d, ni=%d, ai=%d, no=%d, ao=%d)!?", in->msg, result, in->next_in, in->avail_in, in->next_out, in->avail_out ); - Conn_Close( Idx, "Decompression error!", NULL, false ); + Log(LOG_ALERT, "Decompression error: %s (code=%d, ni=%d, ai=%d, no=%d, ao=%d)!?", in->msg, result, in->next_in, in->avail_in, in->next_out, in->avail_out); + Conn_Close(Idx, "Decompression error!", NULL, false); return false; } @@ -235,9 +236,11 @@ Unzip_Buffer( CONN_ID Idx ) #endif assert(unzipbuf_used <= READBUFFER_LEN); if (!array_catb(&My_Connections[Idx].rbuf, (char*) unzipbuf, - (size_t)unzipbuf_used)) + (size_t)unzipbuf_used)) { + Log (LOG_ALERT, "Decompression error: can't copy data!?"); + Conn_Close(Idx, "Decompression error!", NULL, false); return false; - + } if( in->avail_in > 0 ) { array_moveleft(&My_Connections[Idx].zip.rbuf, 1, in_len ); } else { @@ -249,21 +252,25 @@ Unzip_Buffer( CONN_ID Idx ) } /* Unzip_Buffer */ +/** + * @param Idx Connection handle. + * @return amount of sent (compressed) bytes + */ GLOBAL long Zip_SendBytes( CONN_ID Idx ) { - /* Anzahl gesendeter Bytes (komprimiert!) liefern */ - assert( Idx > NONE ); return My_Connections[Idx].zip.bytes_out; } /* Zip_SendBytes */ +/** + * @param Idx Connection handle. + * @return amount of received (compressed) bytes + */ GLOBAL long Zip_RecvBytes( CONN_ID Idx ) { - /* Anzahl gesendeter Bytes (komprimiert!) liefern */ - assert( Idx > NONE ); return My_Connections[Idx].zip.bytes_in; } /* Zip_RecvBytes */ diff --git a/src/ngircd/conn-zip.h b/src/ngircd/conn-zip.h index 6458a4e..08abb50 100644 --- a/src/ngircd/conn-zip.h +++ b/src/ngircd/conn-zip.h @@ -22,7 +22,7 @@ GLOBAL bool Zip_InitConn PARAMS(( CONN_ID Idx )); -GLOBAL bool Zip_Buffer PARAMS(( CONN_ID Idx, char *Data, size_t Len )); +GLOBAL bool Zip_Buffer PARAMS(( CONN_ID Idx, const char *Data, size_t Len )); GLOBAL bool Zip_Flush PARAMS(( CONN_ID Idx )); GLOBAL bool Unzip_Buffer PARAMS(( CONN_ID Idx )); diff --git a/src/ngircd/conn.c b/src/ngircd/conn.c index 5b52511..c6095a3 100644 --- a/src/ngircd/conn.c +++ b/src/ngircd/conn.c @@ -304,8 +304,6 @@ cb_clientserver_ssl(int sock, short what) GLOBAL void Conn_Init( void ) { - /* Modul initialisieren: statische Strukturen "ausnullen". */ - CONN_ID i; /* Speicher fuer Verbindungs-Pool anfordern */ @@ -341,9 +339,6 @@ Conn_Init( void ) GLOBAL void Conn_Exit( void ) { - /* Modul abmelden: alle noch offenen Connections - * schliessen und freigeben. */ - CONN_ID idx; Conn_ExitListeners(); @@ -886,13 +881,13 @@ Conn_Write( CONN_ID Idx, char *Data, size_t Len ) GLOBAL void -Conn_Close( CONN_ID Idx, char *LogMsg, char *FwdMsg, bool InformClient ) +Conn_Close( CONN_ID Idx, const char *LogMsg, const char *FwdMsg, bool InformClient ) { /* Close connection. Open pipes of asyncronous resolver * sub-processes are closed down. */ CLIENT *c; - char *txt; + const char *txt; double in_k, out_k; UINT16 port; #ifdef ZLIB @@ -1292,13 +1287,11 @@ New_Connection( int Sock ) static CONN_ID Socket2Index( int Sock ) { - /* zum Socket passende Connection suchen */ - assert( Sock >= 0 ); if( Sock >= Pool_Size || My_Connections[Sock].sock != Sock ) { - /* die Connection wurde vermutlich (wegen eines - * Fehlers) bereits wieder abgebaut ... */ + /* the Connection was already closed again, likely due to + * an error. */ LogDebug("Socket2Index: can't get connection for socket %d!", Sock); return NONE; } @@ -1547,6 +1540,7 @@ Check_Connections(void) * if this doesn't help either, disconnect client. */ CLIENT *c; CONN_ID i; + char msg[64]; for (i = 0; i < Pool_Size; i++) { if (My_Connections[i].sock < 0) @@ -1566,8 +1560,8 @@ Check_Connections(void) LogDebug ("Connection %d: Ping timeout: %d seconds.", i, Conf_PongTimeout); - Conn_Close(i, NULL, "Ping timeout", - true); + snprintf(msg, sizeof(msg), "Ping timeout: %d seconds", Conf_PongTimeout); + Conn_Close(i, NULL, msg, true); } } else if (My_Connections[i].lastdata < time(NULL) - Conf_PingTimeout) { @@ -1957,6 +1951,9 @@ Conn_GetClient( CONN_ID Idx ) GLOBAL bool Conn_GetCipherInfo(CONN_ID Idx, char *buf, size_t len) { + if (Idx < 0) + return false; + assert(Idx < (int) array_length(&My_ConnArray, sizeof(CONNECTION))); return ConnSSL_GetCipherInfo(&My_Connections[Idx], buf, len); } @@ -1964,6 +1961,9 @@ Conn_GetCipherInfo(CONN_ID Idx, char *buf, size_t len) GLOBAL bool Conn_UsesSSL(CONN_ID Idx) { + if (Idx < 0) + return false; + assert(Idx < (int) array_length(&My_ConnArray, sizeof(CONNECTION))); return Conn_OPTION_ISSET(&My_Connections[Idx], CONN_SSL); } #endif diff --git a/src/ngircd/conn.h b/src/ngircd/conn.h index 450d3d1..28bbda3 100644 --- a/src/ngircd/conn.h +++ b/src/ngircd/conn.h @@ -108,7 +108,7 @@ GLOBAL void Conn_Handler PARAMS(( void )); GLOBAL bool Conn_WriteStr PARAMS(( CONN_ID Idx, char *Format, ... )); -GLOBAL void Conn_Close PARAMS(( CONN_ID Idx, char *LogMsg, char *FwdMsg, bool InformClient )); +GLOBAL void Conn_Close PARAMS(( CONN_ID Idx, const char *LogMsg, const char *FwdMsg, bool InformClient )); GLOBAL void Conn_SyncServerStruct PARAMS(( void )); diff --git a/src/ngircd/irc-info.c b/src/ngircd/irc-info.c index e934521..f57a6a1 100644 --- a/src/ngircd/irc-info.c +++ b/src/ngircd/irc-info.c @@ -49,24 +49,23 @@ IRC_ADMIN(CLIENT *Client, REQUEST *Req ) assert( Client != NULL ); assert( Req != NULL ); - /* Falsche Anzahl Parameter? */ if(( Req->argc > 1 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command ); - /* Ziel suchen */ + /* find target ... */ if( Req->argc == 1 ) target = Client_Search( Req->argv[0] ); else target = Client_ThisServer( ); - /* Prefix ermitteln */ + /* find Prefix */ if( Client_Type( Client ) == CLIENT_SERVER ) prefix = Client_Search( Req->prefix ); else prefix = Client; if( ! prefix ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix ); - /* An anderen Server weiterleiten? */ + /* forwad message to another server? */ if( target != Client_ThisServer( )) { if(( ! target ) || ( Client_Type( target ) != CLIENT_SERVER )) return IRC_WriteStrClient( prefix, ERR_NOSUCHSERVER_MSG, Client_ID( prefix ), Req->argv[0] ); - /* forwarden */ + /* forward */ IRC_WriteStrClientPrefix( target, prefix, "ADMIN %s", Req->argv[0] ); return CONNECTED; } @@ -199,7 +198,6 @@ IRC_LINKS( CLIENT *Client, REQUEST *Req ) assert( Client != NULL ); assert( Req != NULL ); - /* Falsche Anzahl Parameter? */ if(( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command ); /* Server-Mask ermitteln */ @@ -247,7 +245,6 @@ IRC_LUSERS( CLIENT *Client, REQUEST *Req ) assert( Client != NULL ); assert( Req != NULL ); - /* Falsche Anzahl Parameter? */ if(( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command ); /* Absender ermitteln */ @@ -321,7 +318,6 @@ IRC_MOTD( CLIENT *Client, REQUEST *Req ) assert( Client != NULL ); assert( Req != NULL ); - /* Falsche Anzahl Parameter? */ if( Req->argc > 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command ); /* From aus Prefix ermitteln */ @@ -331,7 +327,7 @@ IRC_MOTD( CLIENT *Client, REQUEST *Req ) if( Req->argc == 1 ) { - /* an anderen Server forwarden */ + /* forward? */ target = Client_Search( Req->argv[0] ); if(( ! target ) || ( Client_Type( target ) != CLIENT_SERVER )) return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[0] ); @@ -357,23 +353,21 @@ IRC_NAMES( CLIENT *Client, REQUEST *Req ) assert( Client != NULL ); assert( Req != NULL ); - /* Falsche Anzahl Parameter? */ if( Req->argc > 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command ); - /* From aus Prefix ermitteln */ + /* use prefix to determine "From" */ if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix ); else from = Client; if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix ); if( Req->argc == 2 ) { - /* an anderen Server forwarden */ + /* forward to another server? */ target = Client_Search( Req->argv[1] ); if(( ! target ) || ( Client_Type( target ) != CLIENT_SERVER )) return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[1] ); - if( target != Client_ThisServer( )) - { - /* Ok, anderer Server ist das Ziel: forwarden */ + if( target != Client_ThisServer( )) { + /* target is another server, forward */ return IRC_WriteStrClientPrefix( target, from, "NAMES %s :%s", Req->argv[0], Req->argv[1] ); } } @@ -387,53 +381,48 @@ IRC_NAMES( CLIENT *Client, REQUEST *Req ) chan = Channel_Search( ptr ); if( chan ) { - /* Namen ausgeben */ + /* print name */ if( ! IRC_Send_NAMES( from, chan )) return DISCONNECTED; } if( ! IRC_WriteStrClient( from, RPL_ENDOFNAMES_MSG, Client_ID( from ), ptr )) return DISCONNECTED; - /* naechsten Namen ermitteln */ + /* get next channel name */ ptr = strtok( NULL, "," ); } return CONNECTED; } - /* alle Channels durchgehen */ chan = Channel_First( ); while( chan ) { - /* Namen ausgeben */ if( ! IRC_Send_NAMES( from, chan )) return DISCONNECTED; - /* naechster Channel */ chan = Channel_Next( chan ); } - /* Nun noch alle Clients ausgeben, die in keinem Channel sind */ + /* Now print all clients which are not in any channel */ c = Client_First( ); snprintf( rpl, sizeof( rpl ), RPL_NAMREPLY_MSG, Client_ID( from ), "*", "*" ); while( c ) { if(( Client_Type( c ) == CLIENT_USER ) && ( Channel_FirstChannelOf( c ) == NULL ) && ( ! strchr( Client_Modes( c ), 'i' ))) { - /* Okay, das ist ein User: anhaengen */ + /* its a user, concatenate ... */ if( rpl[strlen( rpl ) - 1] != ':' ) strlcat( rpl, " ", sizeof( rpl )); strlcat( rpl, Client_ID( c ), sizeof( rpl )); if( strlen( rpl ) > ( LINE_LEN - CLIENT_NICK_LEN - 4 )) { - /* Zeile wird zu lang: senden! */ + /* Line is gwoing too long, send now */ if( ! IRC_WriteStrClient( from, "%s", rpl )) return DISCONNECTED; snprintf( rpl, sizeof( rpl ), RPL_NAMREPLY_MSG, Client_ID( from ), "*", "*" ); } } - /* naechster Client */ c = Client_Next( c ); } if( rpl[strlen( rpl ) - 1] != ':') { - /* es wurden User gefunden */ if( ! IRC_WriteStrClient( from, "%s", rpl )) return DISCONNECTED; } @@ -489,11 +478,10 @@ IRC_STATS( CLIENT *Client, REQUEST *Req ) assert( Client != NULL ); assert( Req != NULL ); - /* Falsche Anzahl Parameter? */ if (Req->argc > 2) return IRC_WriteStrClient(Client, ERR_NEEDMOREPARAMS_MSG, Client_ID(Client), Req->command); - /* From aus Prefix ermitteln */ + /* use prefix to determine "From" */ if (Client_Type(Client) == CLIENT_SERVER) from = Client_Search(Req->prefix); else @@ -503,13 +491,13 @@ IRC_STATS( CLIENT *Client, REQUEST *Req ) return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix); if (Req->argc == 2) { - /* an anderen Server forwarden */ + /* forward to another server? */ target = Client_Search( Req->argv[1] ); if(( ! target ) || ( Client_Type( target ) != CLIENT_SERVER )) return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[1] ); if( target != Client_ThisServer()) { - /* Ok, anderer Server ist das Ziel: forwarden */ + /* forward to another server */ return IRC_WriteStrClientPrefix( target, from, "STATS %s %s", Req->argv[0], Req->argv[1] ); } } @@ -597,23 +585,19 @@ IRC_TIME( CLIENT *Client, REQUEST *Req ) assert( Client != NULL ); assert( Req != NULL ); - /* Falsche Anzahl Parameter? */ if( Req->argc > 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command ); - /* From aus Prefix ermitteln */ if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix ); else from = Client; if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix ); if( Req->argc == 1 ) { - /* an anderen Server forwarden */ target = Client_Search( Req->argv[0] ); if(( ! target ) || ( Client_Type( target ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[0] ); if( target != Client_ThisServer( )) { - /* Ok, anderer Server ist das Ziel: forwarden */ return IRC_WriteStrClientPrefix( target, from, "TIME %s", Req->argv[0] ); } } @@ -634,7 +618,6 @@ IRC_USERHOST( CLIENT *Client, REQUEST *Req ) assert( Client != NULL ); assert( Req != NULL ); - /* Falsche Anzahl Parameter? */ if(( Req->argc < 1 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command ); if( Req->argc > 5 ) max = 5; @@ -646,7 +629,7 @@ IRC_USERHOST( CLIENT *Client, REQUEST *Req ) c = Client_Search( Req->argv[i] ); if( c && ( Client_Type( c ) == CLIENT_USER )) { - /* Dieser Nick ist "online" */ + /* This Nick is "online" */ strlcat( rpl, Client_ID( c ), sizeof( rpl )); if( Client_HasMode( c, 'o' )) strlcat( rpl, "*", sizeof( rpl )); strlcat( rpl, "=", sizeof( rpl )); @@ -684,7 +667,6 @@ IRC_VERSION( CLIENT *Client, REQUEST *Req ) assert( Client != NULL ); assert( Req != NULL ); - /* Falsche Anzahl Parameter? */ if(( Req->argc > 1 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command ); /* Ziel suchen */ diff --git a/src/ngircd/irc-login.c b/src/ngircd/irc-login.c index 1091852..16d1641 100644 --- a/src/ngircd/irc-login.c +++ b/src/ngircd/irc-login.c @@ -322,18 +322,18 @@ IRC_NICK( CLIENT *Client, REQUEST *Req ) info = Req->argv[0]; } - /* Nick ueberpruefen */ c = Client_Search(nick); if(c) { - /* Der neue Nick ist auf diesem Server bereits registriert: - * sowohl der neue, als auch der alte Client muessen nun - * disconnectiert werden. */ + /* + * the new nick is already present on this server: + * the new and the old one have to be disconnected now. + */ Log( LOG_ERR, "Server %s introduces already registered nick \"%s\"!", Client_ID( Client ), Req->argv[0] ); Kill_Nick( Req->argv[0], "Nick collision" ); return CONNECTED; } - /* Server, zu dem der Client connectiert ist, suchen */ + /* Find the Server this client is connected to */ intr_c = Client_GetFromToken(Client, token); if( ! intr_c ) { @@ -342,14 +342,11 @@ IRC_NICK( CLIENT *Client, REQUEST *Req ) return CONNECTED; } - /* Neue Client-Struktur anlegen */ c = Client_NewRemoteUser(intr_c, nick, hops, user, hostname, token, modes, info, true); if( ! c ) { - /* Eine neue Client-Struktur konnte nicht angelegt werden. - * Der Client muss disconnectiert werden, damit der Netz- - * status konsistent bleibt. */ + /* out of memory, need to disconnect client to keep network state consistent */ Log( LOG_ALERT, "Can't create client structure! (on connection %d)", Client_Conn( Client )); Kill_Nick( Req->argv[0], "Server error" ); return CONNECTED; @@ -583,7 +580,6 @@ IRC_QUIT( CLIENT *Client, REQUEST *Req ) target = Client_Search( Req->prefix ); if( ! target ) { - /* Den Client kennen wir nicht (mehr), also nichts zu tun. */ Log( LOG_WARNING, "Got QUIT from %s for unknown client!?", Client_ID( Client )); return CONNECTED; } @@ -601,7 +597,7 @@ IRC_QUIT( CLIENT *Client, REQUEST *Req ) strlcat(quitmsg, "\"", sizeof quitmsg ); } - /* User, Service, oder noch nicht registriert */ + /* User, Service, or not yet registered */ Conn_Close( Client_Conn( Client ), "Got QUIT command.", Req->argc == 1 ? quitmsg : NULL, true); return DISCONNECTED; @@ -617,7 +613,6 @@ IRC_PING(CLIENT *Client, REQUEST *Req) assert(Client != NULL); assert(Req != NULL); - /* Wrong number of arguments? */ if (Req->argc < 1) return IRC_WriteStrClient(Client, ERR_NOORIGIN_MSG, Client_ID(Client)); diff --git a/src/ngircd/irc-mode.c b/src/ngircd/irc-mode.c index ba28f83..8e08565 100644 --- a/src/ngircd/irc-mode.c +++ b/src/ngircd/irc-mode.c @@ -671,12 +671,10 @@ IRC_AWAY( CLIENT *Client, REQUEST *Req ) assert( Client != NULL ); assert( Req != NULL ); - /* Falsche Anzahl Parameter? */ if( Req->argc > 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command ); if(( Req->argc == 1 ) && (Req->argv[0][0] )) { - /* AWAY setzen */ Client_SetAway( Client, Req->argv[0] ); Client_ModeAdd( Client, 'a' ); IRC_WriteStrServersPrefix( Client, Client, "MODE %s :+a", Client_ID( Client )); @@ -684,7 +682,6 @@ IRC_AWAY( CLIENT *Client, REQUEST *Req ) } else { - /* AWAY loeschen */ Client_ModeDel( Client, 'a' ); IRC_WriteStrServersPrefix( Client, Client, "MODE %s :-a", Client_ID( Client )); return IRC_WriteStrClient( Client, RPL_UNAWAY_MSG, Client_ID( Client )); @@ -752,21 +749,19 @@ Del_Ban_Invite(int what, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, const static bool Send_ListChange( char *Mode, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, const char *Mask ) { - /* Bestaetigung an Client schicken & andere Server sowie Channel-User informieren */ - bool ok; if( Client_Type( Client ) == CLIENT_USER ) { - /* Bestaetigung an Client */ + /* send confirmation to client */ ok = IRC_WriteStrClientPrefix( Client, Prefix, "MODE %s %s %s", Channel_Name( Channel ), Mode, Mask ); } else ok = true; - /* an andere Server */ + /* to other servers */ IRC_WriteStrServersPrefix( Client, Prefix, "MODE %s %s %s", Channel_Name( Channel ), Mode, Mask ); - /* und lokale User im Channel */ + /* and local users in channel */ IRC_WriteStrChannelPrefix( Client, Channel, Prefix, false, "MODE %s %s %s", Channel_Name( Channel ), Mode, Mask ); return ok; diff --git a/src/ngircd/irc-oper.c b/src/ngircd/irc-oper.c index c9286d7..b0271df 100644 --- a/src/ngircd/irc-oper.c +++ b/src/ngircd/irc-oper.c @@ -14,8 +14,6 @@ #include "portab.h" -static char UNUSED id[] = "$Id: irc-oper.c,v 1.29 2007/08/02 10:14:26 fw Exp $"; - #include "imp.h" #include #include @@ -55,10 +53,8 @@ IRC_OPER( CLIENT *Client, REQUEST *Req ) assert( Client != NULL ); assert( Req != NULL ); - /* Falsche Anzahl Parameter? */ if( Req->argc != 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command ); - /* Operator suchen */ for( i = 0; i < Conf_Oper_Count; i++) { if( Conf_Oper[i].name[0] && Conf_Oper[i].pwd[0] && ( strcmp( Conf_Oper[i].name, Req->argv[0] ) == 0 )) break; @@ -66,17 +62,14 @@ IRC_OPER( CLIENT *Client, REQUEST *Req ) if( i >= Conf_Oper_Count ) return Bad_OperPass(Client, Req->argv[0], "not configured"); - /* Stimmt das Passwort? */ if( strcmp( Conf_Oper[i].pwd, Req->argv[1] ) != 0 ) return Bad_OperPass(Client, Conf_Oper[i].name, "Bad password"); - /* Authorized Mask? */ if( Conf_Oper[i].mask && (! Match( Conf_Oper[i].mask, Client_Mask( Client ) ))) return Bad_OperPass(Client, Conf_Oper[i].mask, "hostmask check failed" ); if( ! Client_HasMode( Client, 'o' )) { - /* noch kein o-Mode gesetzt */ Client_ModeAdd( Client, 'o' ); if( ! IRC_WriteStrClient( Client, "MODE %s :+o", Client_ID( Client ))) return DISCONNECTED; IRC_WriteStrServersPrefix( NULL, Client, "MODE %s :+o", Client_ID( Client )); diff --git a/src/ngircd/irc-server.c b/src/ngircd/irc-server.c index f1b817c..7236d9a 100644 --- a/src/ngircd/irc-server.c +++ b/src/ngircd/irc-server.c @@ -49,7 +49,7 @@ GLOBAL bool IRC_SERVER( CLIENT *Client, REQUEST *Req ) { - char str[LINE_LEN], *ptr; + char str[LINE_LEN]; CLIENT *from, *c; bool ok; int i; @@ -70,40 +70,37 @@ IRC_SERVER( CLIENT *Client, REQUEST *Req ) LogDebug("Connection %d: got SERVER command (new server link) ...", Client_Conn(Client)); - /* Falsche Anzahl Parameter? */ if(( Req->argc != 2 ) && ( Req->argc != 3 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command ); - /* Ist dieser Server bei uns konfiguriert? */ + /* Ist this server configured on out side? */ for( i = 0; i < MAX_SERVERS; i++ ) if( strcasecmp( Req->argv[0], Conf_Server[i].name ) == 0 ) break; if( i >= MAX_SERVERS ) { - /* Server ist nicht konfiguriert! */ Log( LOG_ERR, "Connection %d: Server \"%s\" not configured here!", Client_Conn( Client ), Req->argv[0] ); Conn_Close( Client_Conn( Client ), NULL, "Server not configured here", true); return DISCONNECTED; } if( strcmp( Client_Password( Client ), Conf_Server[i].pwd_in ) != 0 ) { - /* Falsches Passwort */ + /* wrong password */ Log( LOG_ERR, "Connection %d: Got bad password from server \"%s\"!", Client_Conn( Client ), Req->argv[0] ); Conn_Close( Client_Conn( Client ), NULL, "Bad password", true); return DISCONNECTED; } - /* Ist ein Server mit dieser ID bereits registriert? */ + /* Is there a registered server with this ID? */ if( ! Client_CheckID( Client, Req->argv[0] )) return DISCONNECTED; - /* Server-Strukturen fuellen ;-) */ Client_SetID( Client, Req->argv[0] ); Client_SetHops( Client, 1 ); Client_SetInfo( Client, Req->argv[Req->argc - 1] ); - /* Meldet sich der Server bei uns an (d.h., bauen nicht wir - * selber die Verbindung zu einem anderen Server auf)? */ + /* Is this server registering on our side, or are we connecting to + * a remote server? */ con = Client_Conn( Client ); if( Client_Token( Client ) != TOKEN_OUTBOUND ) { - /* Eingehende Verbindung: Unseren SERVER- und PASS-Befehl senden */ + /* Incoming connection, send user/pass */ ok = true; if( ! IRC_WriteStrClient( Client, "PASS %s %s", Conf_Server[i].pwd_out, NGIRCd_ProtoID )) ok = false; else ok = IRC_WriteStrClient( Client, "SERVER %s 1 :%s", Conf_ServerName, Conf_ServerInfo ); @@ -117,8 +114,7 @@ IRC_SERVER( CLIENT *Client, REQUEST *Req ) } else { - /* Ausgehende verbindung, SERVER und PASS wurden von uns bereits - * an die Gegenseite uerbermittelt */ + /* outgoing connect, we already sent SERVER and PASS to the peer */ Client_SetToken( Client, atoi( Req->argv[1] )); } @@ -139,15 +135,9 @@ IRC_SERVER( CLIENT *Client, REQUEST *Req ) Client_SetType(Client, CLIENT_UNKNOWNSERVER); #ifdef ZLIB - /* Kompression initialisieren, wenn erforderlich */ - if( strchr( Client_Flags( Client ), 'Z' )) - { - if( ! Zip_InitConn( con )) - { - /* Fehler! */ - Conn_Close( con, "Can't inizialize compression (zlib)!", NULL, false ); - return DISCONNECTED; - } + if (strchr(Client_Flags(Client), 'Z') && !Zip_InitConn(con)) { + Conn_Close( con, "Can't inizialize compression (zlib)!", NULL, false ); + return DISCONNECTED; } #endif @@ -171,43 +161,34 @@ IRC_SERVER( CLIENT *Client, REQUEST *Req ) } else if( Client_Type( Client ) == CLIENT_SERVER ) { - /* Neuer Server wird im Netz angekuendigt */ + /* New server is being introduced to the network */ - /* Falsche Anzahl Parameter? */ if( Req->argc != 4 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command ); - /* Ist ein Server mit dieser ID bereits registriert? */ + /* check for existing server with same ID */ if( ! Client_CheckID( Client, Req->argv[0] )) return DISCONNECTED; - /* Ueberfluessige Hostnamen aus Info-Text entfernen */ - ptr = strchr( Req->argv[3] + 2, '[' ); - if( ! ptr ) ptr = Req->argv[3]; - from = Client_Search( Req->prefix ); if( ! from ) { - /* Hm, Server, der diesen einfuehrt, ist nicht bekannt!? */ + /* Uh, Server, that introduced the new server is unknown?! */ Log( LOG_ALERT, "Unknown ID in prefix of SERVER: \"%s\"! (on connection %d)", Req->prefix, Client_Conn( Client )); Conn_Close( Client_Conn( Client ), NULL, "Unknown ID in prefix of SERVER", true); return DISCONNECTED; } - /* Neue Client-Struktur anlegen */ - c = Client_NewRemoteServer( Client, Req->argv[0], from, atoi( Req->argv[1] ), atoi( Req->argv[2] ), ptr, true); - if( ! c ) - { - /* Neue Client-Struktur konnte nicht angelegt werden */ + c = Client_NewRemoteServer(Client, Req->argv[0], from, atoi(Req->argv[1]), atoi(Req->argv[2]), Req->argv[3], true); + if (!c) { Log( LOG_ALERT, "Can't create client structure for server! (on connection %d)", Client_Conn( Client )); Conn_Close( Client_Conn( Client ), NULL, "Can't allocate client structure for remote server", true); return DISCONNECTED; } - /* Log-Meldung zusammenbauen und ausgeben */ if(( Client_Hops( c ) > 1 ) && ( Req->prefix[0] )) snprintf( str, sizeof( str ), "connected to %s, ", Client_ID( from )); else strcpy( str, "" ); Log( LOG_NOTICE|LOG_snotice, "Server \"%s\" registered (via %s, %s%d hop%s).", Client_ID( c ), Client_ID( Client ), str, Client_Hops( c ), Client_Hops( c ) > 1 ? "s": "" ); - /* Andere Server informieren */ + /* notify other servers */ IRC_WriteStrServersPrefix( Client, from, "SERVER %s %d %d :%s", Client_ID( c ), Client_Hops( c ) + 1, Client_MyToken( c ), Client_Info( c )); return CONNECTED; @@ -228,7 +209,6 @@ IRC_NJOIN( CLIENT *Client, REQUEST *Req ) assert( Client != NULL ); assert( Req != NULL ); - /* Falsche Anzahl Parameter? */ if( Req->argc != 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command ); strlcpy( nick_in, Req->argv[1], sizeof( nick_in )); @@ -240,7 +220,7 @@ IRC_NJOIN( CLIENT *Client, REQUEST *Req ) { is_op = is_voiced = false; - /* Prefixe abschneiden */ + /* cut off prefixes */ while(( *ptr == '@' ) || ( *ptr == '+' )) { if( *ptr == '@' ) is_op = true; @@ -258,14 +238,14 @@ IRC_NJOIN( CLIENT *Client, REQUEST *Req ) if( is_op ) Channel_UserModeAdd( chan, c, 'o' ); if( is_voiced ) Channel_UserModeAdd( chan, c, 'v' ); - /* im Channel bekannt machen */ + /* announce to channel... */ IRC_WriteStrChannelPrefix( Client, chan, c, false, "JOIN :%s", channame ); - /* Channel-User-Modes setzen */ + /* set Channel-User-Modes */ strlcpy( modes, Channel_UserModes( chan, c ), sizeof( modes )); if( modes[0] ) { - /* Modes im Channel bekannt machen */ + /* send modes to channel */ IRC_WriteStrChannelPrefix( Client, chan, Client, false, "MODE %s +%s %s", channame, modes, Client_ID( c )); } @@ -276,11 +256,11 @@ IRC_NJOIN( CLIENT *Client, REQUEST *Req ) } else Log( LOG_ERR, "Got NJOIN for unknown nick \"%s\" for channel \"%s\"!", ptr, channame ); - /* naechsten Nick suchen */ + /* search for next Nick */ ptr = strtok( NULL, "," ); } - /* an andere Server weiterleiten */ + /* forward to other servers */ if( nick_out[0] != '\0' ) IRC_WriteStrServersPrefix( Client, Client_ThisServer( ), "NJOIN %s :%s", Req->argv[0], nick_out ); return CONNECTED; @@ -296,7 +276,6 @@ IRC_SQUIT( CLIENT *Client, REQUEST *Req ) assert( Client != NULL ); assert( Req != NULL ); - /* Falsche Anzahl Parameter? */ if( Req->argc != 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command ); Log( LOG_DEBUG, "Got SQUIT from %s for \"%s\": \"%s\" ...", Client_ID( Client ), Req->argv[0], Req->argv[1] ); @@ -304,7 +283,6 @@ IRC_SQUIT( CLIENT *Client, REQUEST *Req ) target = Client_Search( Req->argv[0] ); if( ! target ) { - /* Den Server kennen wir nicht (mehr), also nichts zu tun. */ Log( LOG_WARNING, "Got SQUIT from %s for unknown server \"%s\"!?", Client_ID( Client ), Req->argv[0] ); return CONNECTED; } @@ -318,18 +296,17 @@ IRC_SQUIT( CLIENT *Client, REQUEST *Req ) if( Client_Conn( target ) > NONE ) { - /* dieser Server hat die Connection */ + /* This server has the connection */ if( Req->argv[1][0] ) Conn_Close( Client_Conn( target ), msg, Req->argv[1], true); else Conn_Close( Client_Conn( target ), msg, NULL, true); return DISCONNECTED; } else { - /* Verbindung hielt anderer Server */ + /* connection was on another server */ Client_Destroy( target, msg, Req->argv[1], false ); return CONNECTED; } } /* IRC_SQUIT */ - /* -eof- */ diff --git a/src/ngircd/irc-write.c b/src/ngircd/irc-write.c index 8239c15..ea0f5f8 100644 --- a/src/ngircd/irc-write.c +++ b/src/ngircd/irc-write.c @@ -14,8 +14,6 @@ #include "portab.h" -static char UNUSED id[] = "$Id: irc-write.c,v 1.21 2006/08/12 11:56:24 fw Exp $"; - #include "imp.h" #include #ifdef PROTOTYPES @@ -70,7 +68,7 @@ va_dcl vsnprintf( buffer, 1000, Format, ap ); va_end( ap ); - /* an den Client selber */ + /* to the client itself */ ok = IRC_WriteStrClientPrefix( Client, Client_ThisServer( ), "%s", buffer ); return ok; @@ -89,7 +87,7 @@ char *Format; va_dcl #endif { - /* Text an Clients, lokal bzw. remote, senden. */ + /* send text to local and remote clients */ char buffer[1000]; va_list ap; @@ -141,6 +139,11 @@ va_dcl } /* IRC_WriteStrChannel */ + +/** + * send message to all clients in the same channel, but only send message + * once per remote server. + */ #ifdef PROTOTYPES GLOBAL bool IRC_WriteStrChannelPrefix( CLIENT *Client, CHANNEL *Chan, CLIENT *Prefix, bool Remote, char *Format, ... ) @@ -177,8 +180,6 @@ va_dcl Conn_ClearFlags( ); - /* An alle Clients, die in den selben Channels sind. - * Dabei aber nur einmal je Remote-Server */ cl2chan = Channel_FirstMember( Chan ); while( cl2chan ) { @@ -192,7 +193,7 @@ va_dcl if( c && ( c != Client )) { - /* Ok, anderer Client */ + /* Ok, another Client */ conn = Client_Conn( c ); if( Client_Type( c ) == CLIENT_SERVER ) Conn_SetFlag( conn, SEND_TO_SERVER ); else Conn_SetFlag( conn, SEND_TO_USER ); @@ -200,16 +201,14 @@ va_dcl cl2chan = Channel_NextMember( Chan, cl2chan ); } - /* Senden: alle Verbindungen durchgehen ... */ conn = Conn_First( ); while( conn != NONE ) { - /* muessen Daten ueber diese Verbindung verschickt werden? */ + /* do we need to send data via this connection? */ if( Conn_Flag( conn ) == SEND_TO_SERVER) ok = Conn_WriteStr( conn, ":%s %s", Client_ID( Prefix ), buffer ); else if( Conn_Flag( conn ) == SEND_TO_USER ) ok = Conn_WriteStr( conn, ":%s %s", Client_Mask( Prefix ), buffer ); if( ! ok ) break; - /* naechste Verbindung testen */ conn = Conn_Next( conn ); } @@ -241,7 +240,6 @@ va_dcl vsnprintf( buffer, 1000, Format, ap ); va_end( ap ); - /* an den Client selber */ IRC_WriteStrServersPrefix( ExceptOf, Client_ThisServer( ), "%s", buffer ); } /* IRC_WriteStrServers */ @@ -327,6 +325,10 @@ IRC_WriteStrServersPrefixFlag_CB(CLIENT *ExceptOf, CLIENT *Prefix, char Flag, } /* IRC_WriteStrServersPrefixFlag */ +/** + * send message to all clients that are in the same channels as the client sending this message. + * only send message once per reote server. + */ #ifdef PROTOTYPES GLOBAL bool IRC_WriteStrRelatedPrefix( CLIENT *Client, CLIENT *Prefix, bool Remote, char *Format, ... ) @@ -360,15 +362,11 @@ va_dcl vsnprintf( buffer, 1000, Format, ap ); va_end( ap ); - /* initialisieren */ Conn_ClearFlags( ); - /* An alle Clients, die in einem Channel mit dem "Ausloeser" sind, - * den Text schicken. An Remote-Server aber jeweils nur einmal. */ chan_cl2chan = Channel_FirstChannelOf( Client ); while( chan_cl2chan ) { - /* Channel des Users durchsuchen */ chan = Channel_GetChannel( chan_cl2chan ); cl2chan = Channel_FirstMember( chan ); while( cl2chan ) @@ -383,7 +381,6 @@ va_dcl if( c && ( c != Client )) { - /* Ok, anderer Client */ conn = Client_Conn( c ); if( Client_Type( c ) == CLIENT_SERVER ) Conn_SetFlag( conn, SEND_TO_SERVER ); else Conn_SetFlag( conn, SEND_TO_USER ); @@ -391,20 +388,17 @@ va_dcl cl2chan = Channel_NextMember( chan, cl2chan ); } - /* naechsten Channel */ chan_cl2chan = Channel_NextChannelOf( Client, chan_cl2chan ); } - /* Senden: alle Verbindungen durchgehen ... */ conn = Conn_First( ); while( conn != NONE ) { - /* muessen ueber diese Verbindung Daten gesendet werden? */ + /* send data via this connection? */ if( Conn_Flag( conn ) == SEND_TO_SERVER ) ok = Conn_WriteStr( conn, ":%s %s", Client_ID( Prefix ), buffer ); else if( Conn_Flag( conn ) == SEND_TO_USER ) ok = Conn_WriteStr( conn, ":%s %s", Client_Mask( Prefix ), buffer ); if( ! ok ) break; - /* naechste Verbindung testen */ conn = Conn_Next( conn ); } return ok; diff --git a/src/ngircd/log.c b/src/ngircd/log.c index 5559a2c..5a81b5b 100644 --- a/src/ngircd/log.c +++ b/src/ngircd/log.c @@ -81,14 +81,12 @@ Log_Init( bool Daemon_Mode ) #ifndef LOG_LOCAL5 #define LOG_LOCAL5 0 #endif - /* Syslog initialisieren */ openlog( PACKAGE_NAME, LOG_CONS|LOG_PID, LOG_LOCAL5 ); #endif - /* Hello World! */ Log( LOG_NOTICE, "%s started.", NGIRCd_Version ); - /* Informationen uebern den "Operation Mode" */ + /* Information about "Operation Mode" */ Init_Txt[0] = '\0'; #ifdef DEBUG if( NGIRCd_Debug ) @@ -122,17 +120,11 @@ Log_Init( bool Daemon_Mode ) #ifdef DEBUG - GLOBAL void Log_InitErrorfile( void ) { - /* "Error-Log" initialisieren: stderr in Datei umlenken. Dort - * landen z.B. alle Ausgaben von assert()-Aufrufen. */ - - /* Dateiname zusammen bauen */ snprintf( Error_File, sizeof Error_File, "%s/%s-%ld.err", ERROR_DIR, PACKAGE_NAME, (long)getpid( )); - /* stderr umlenken */ fflush( stderr ); if( ! freopen( Error_File, "w", stderr )) { @@ -140,17 +132,13 @@ Log_InitErrorfile( void ) return; } - /* Einige Infos in das Error-File schreiben */ fputs( ctime( &NGIRCd_Start ), stderr ); fprintf( stderr, "%s started.\n", NGIRCd_Version ); fprintf( stderr, "Activating: %s\n\n", Init_Txt[0] ? Init_Txt : "-" ); fflush( stderr ); -#ifdef DEBUG - Log( LOG_DEBUG, "Redirected stderr to \"%s\".", Error_File ); -#endif + Log(LOG_DEBUG, "Redirected stderr to \"%s\".", Error_File); } /* Log_InitErrfile */ - #endif @@ -170,8 +158,7 @@ Log_Exit( void ) #endif #ifdef SYSLOG - /* syslog abmelden */ - closelog( ); + closelog(); #endif } /* Log_Exit */ diff --git a/src/ngircd/ngircd.c b/src/ngircd/ngircd.c index ad1168a..95c377a 100644 --- a/src/ngircd/ngircd.c +++ b/src/ngircd/ngircd.c @@ -110,14 +110,13 @@ main( int argc, const char *argv[] ) Fill_Version( ); - /* Kommandozeile parsen */ + /* parse conmmand line */ for( i = 1; i < argc; i++ ) { ok = false; if(( argv[i][0] == '-' ) && ( argv[i][1] == '-' )) { - /* Lange Option */ - + /* long option */ if( strcmp( argv[i], "--config" ) == 0 ) { if( i + 1 < argc ) @@ -172,7 +171,7 @@ main( int argc, const char *argv[] ) } else if(( argv[i][0] == '-' ) && ( argv[i][1] != '-' )) { - /* Kurze Option */ + /* short option */ for( n = 1; n < strlen( argv[i] ); n++ ) { ok = false; @@ -241,7 +240,7 @@ main( int argc, const char *argv[] ) } } - /* Debug-Level (fuer IRC-Befehl "VERSION") ermitteln */ + /* Debug-Level (for IRCs "VERSION" command) */ NGIRCd_DebugLevel[0] = '\0'; #ifdef DEBUG if( NGIRCd_Debug ) strcpy( NGIRCd_DebugLevel, "1" ); @@ -254,7 +253,6 @@ main( int argc, const char *argv[] ) } #endif - /* Soll nur die Konfigurations ueberprueft und ausgegeben werden? */ if( configtest ) { Show_Version( ); puts( "" ); @@ -297,12 +295,13 @@ main( int argc, const char *argv[] ) if( ! NGIRCd_NoDaemon ) Log_InitErrorfile( ); #endif - /* Signal-Handler initialisieren */ Initialize_Signal_Handler( ); - /* Protokoll- und Server-Identifikation erzeugen. Die vom ngIRCd - * beim PASS-Befehl verwendete Syntax sowie die erweiterten Flags - * sind in doc/Protocol.txt beschrieben. */ + /* + * create protocol and server identification. + * The syntax used by ngIRCd in PASS commands and the extended flags + * are described in doc/Protocol.txt + */ #ifdef IRCPLUS snprintf( NGIRCd_ProtoID, sizeof NGIRCd_ProtoID, "%s%s %s|%s:%s", PROTOVER, PROTOIRCPLUS, PACKAGE_NAME, PACKAGE_VERSION, IRCPLUSFLAGS ); #ifdef ZLIB @@ -318,10 +317,8 @@ main( int argc, const char *argv[] ) #endif LogDebug("Protocol and server ID is \"%s\".", NGIRCd_ProtoID); - /* Vordefinierte Channels anlegen */ Channel_InitPredefined( ); - /* Listen-Ports initialisieren */ if( Conn_InitListeners( ) < 1 ) { Log( LOG_ALERT, "Server isn't listening on a single port!" ); @@ -490,15 +487,9 @@ NGIRCd_Rehash( void ) static void Initialize_Signal_Handler( void ) { - /* Signal-Handler initialisieren: einige Signale - * werden ignoriert, andere speziell behandelt. */ - #ifdef HAVE_SIGACTION - /* sigaction() ist vorhanden */ - struct sigaction saction; - /* Signal-Struktur initialisieren */ memset( &saction, 0, sizeof( saction )); saction.sa_handler = Signal_Handler; #ifdef SA_RESTART @@ -508,27 +499,22 @@ Initialize_Signal_Handler( void ) saction.sa_flags |= SA_NOCLDWAIT; #endif - /* Signal-Handler einhaengen */ sigaction(SIGINT, &saction, NULL); sigaction(SIGQUIT, &saction, NULL); sigaction(SIGTERM, &saction, NULL); sigaction(SIGHUP, &saction, NULL); sigaction(SIGCHLD, &saction, NULL); - /* einige Signale ignorieren */ + /* we handle write errors properly; ignore SIGPIPE */ saction.sa_handler = SIG_IGN; sigaction(SIGPIPE, &saction, NULL); #else - /* kein sigaction() vorhanden */ - - /* Signal-Handler einhaengen */ signal(SIGINT, Signal_Handler); signal(SIGQUIT, Signal_Handler); signal(SIGTERM, Signal_Handler); signal(SIGHUP, Signal_Handler); signal(SIGCHLD, Signal_Handler); - /* einige Signale ignorieren */ signal(SIGPIPE, SIG_IGN); #endif } /* Initialize_Signal_Handler */ @@ -548,16 +534,17 @@ Signal_Handler( int Signal ) case SIGTERM: case SIGINT: case SIGQUIT: - /* wir soll(t)en uns wohl beenden ... */ + /* shut down sever */ NGIRCd_SignalQuit = true; break; case SIGHUP: - /* Konfiguration neu einlesen: */ + /* re-read configuration */ NGIRCd_SignalRehash = true; break; case SIGCHLD: - /* Child-Prozess wurde beendet. Zombies vermeiden: */ - while( waitpid( -1, NULL, WNOHANG ) > 0); + /* child-process exited, avoid zombies */ + while (waitpid( -1, NULL, WNOHANG) > 0) + ; break; #ifdef DEBUG default: diff --git a/src/ngircd/numeric.c b/src/ngircd/numeric.c index 74c5c12..c3d94c3 100644 --- a/src/ngircd/numeric.c +++ b/src/ngircd/numeric.c @@ -131,7 +131,7 @@ Announce_Server(CLIENT * Client, CLIENT * Server) if (Client_Hops(Server) == 1) c = Client_ThisServer(); else - c = Client_Introducer(Server); + c = Client_TopServer(Server); /* Inform new server about the one already registered in the network */ return IRC_WriteStrClientPrefix(Client, c, "SERVER %s %d %d :%s", diff --git a/src/ngircd/parse.c b/src/ngircd/parse.c index 6801997..5e3f08d 100644 --- a/src/ngircd/parse.c +++ b/src/ngircd/parse.c @@ -169,13 +169,12 @@ Parse_Request( CONN_ID Idx, char *Request ) Init_Request( &req ); - /* Fuehrendes und folgendes "Geraffel" verwerfen */ + /* remove leading & trailing whitespace */ ngt_TrimStr( Request ); - /* gibt es ein Prefix? */ if( Request[0] == ':' ) { - /* Prefix vorhanden */ + /* Prefix */ req.prefix = Request + 1; ptr = strchr( Request, ' ' ); if( ! ptr ) @@ -185,35 +184,30 @@ Parse_Request( CONN_ID Idx, char *Request ) } *ptr = '\0'; #ifndef STRICT_RFC - /* multiple Leerzeichen als Trenner zwischen - * Prefix und Befehl ignorieren */ + /* ignore multiple spaces between prefix and command */ while( *(ptr + 1) == ' ' ) ptr++; #endif start = ptr + 1; } else start = Request; - /* Befehl */ ptr = strchr( start, ' ' ); if( ptr ) { *ptr = '\0'; #ifndef STRICT_RFC - /* multiple Leerzeichen als Trenner vor - * Parametern ignorieren */ + /* ignore multiple spaces between parameters */ while( *(ptr + 1) == ' ' ) ptr++; #endif } req.command = start; - /* Argumente, Parameter */ + /* Arguments, Parameters */ if( ptr ) { - /* Prinzipiell gibt es welche :-) */ start = ptr + 1; while( start ) { - /* Parameter-String "zerlegen" */ if( start[0] == ':' ) { req.argv[req.argc] = start + 1; @@ -227,8 +221,6 @@ Parse_Request( CONN_ID Idx, char *Request ) { *ptr = '\0'; #ifndef STRICT_RFC - /* multiple Leerzeichen als - * Parametertrenner ignorieren */ while( *(ptr + 1) == ' ' ) ptr++; #endif } @@ -244,7 +236,6 @@ Parse_Request( CONN_ID Idx, char *Request ) } } - /* Daten validieren */ if( ! Validate_Prefix( Idx, &req, &closed )) return ! closed; if( ! Validate_Command( Idx, &req, &closed )) return ! closed; if( ! Validate_Args( Idx, &req, &closed )) return ! closed; @@ -283,39 +274,32 @@ Validate_Prefix( CONN_ID Idx, REQUEST *Req, bool *Closed ) *Closed = false; - /* ist ueberhaupt ein Prefix vorhanden? */ if( ! Req->prefix ) return true; - /* Client-Struktur der Connection ermitteln */ client = Conn_GetClient( Idx ); assert( client != NULL ); - /* nur validieren, wenn bereits registrierte Verbindung */ + /* only validate if this connection is already registered */ if(( Client_Type( client ) != CLIENT_USER ) && ( Client_Type( client ) != CLIENT_SERVER ) && ( Client_Type( client ) != CLIENT_SERVICE )) { - /* noch nicht registrierte Verbindung. - * Das Prefix wird ignoriert. */ + /* not registered, ignore prefix */ Req->prefix = NULL; return true; } - /* pruefen, ob der im Prefix angegebene Client bekannt ist */ + /* check if client in prefix is known */ c = Client_Search( Req->prefix ); if( ! c ) { - /* im Prefix angegebener Client ist nicht bekannt */ Log( LOG_ERR, "Invalid prefix \"%s\", client not known (connection %d, command %s)!?", Req->prefix, Idx, Req->command ); if( ! Conn_WriteStr( Idx, "ERROR :Invalid prefix \"%s\", client not known!?", Req->prefix )) *Closed = true; return false; } - /* pruefen, ob der Client mit dem angegebenen Prefix in Richtung - * des Senders liegt, d.h. sicherstellen, dass das Prefix nicht - * gefaelscht ist */ + /* check if the client named in the prefix is expected + * to come from that direction */ if( Client_NextHop( c ) != client ) { - /* das angegebene Prefix ist aus dieser Richtung, also - * aus der gegebenen Connection, ungueltig! */ Log( LOG_ERR, "Spoofed prefix \"%s\" from \"%s\" (connection %d, command %s)!", Req->prefix, Client_Mask( Conn_GetClient( Idx )), Idx, Req->command ); Conn_Close( Idx, NULL, "Spoofed prefix", true); *Closed = true; @@ -456,8 +440,6 @@ Handle_Numeric(CLIENT *client, REQUEST *Req) static bool Handle_Request( CONN_ID Idx, REQUEST *Req ) { - /* Client-Request verarbeiten. Bei einem schwerwiegenden Fehler - * wird die Verbindung geschlossen und false geliefert. */ CLIENT *client; bool result = true; int client_type; @@ -479,7 +461,6 @@ Handle_Request( CONN_ID Idx, REQUEST *Req ) cmd = My_Commands; while (cmd->name) { - /* Befehl suchen */ if (strcasecmp(Req->command, cmd->name) != 0) { cmd++; continue;