├── tests ├── empty.xml ├── failed_to_load_002.xml ├── include_me.xml ├── includeme2.xml ├── subdir │ └── includeme.xml ├── test_include.xml ├── failed_to_load_003.xml ├── failed_to_load_004.xml ├── Makefile.am └── test_config.xml ├── win32 ├── include │ ├── unistd.h │ ├── idn-int.h │ ├── version.h.in │ ├── version.wxi.in │ ├── ac-stdint.h │ └── win32_port.h ├── jabberd2.ico ├── jabberd2.rc ├── setup │ ├── bitmaps │ │ ├── banner.jpg │ │ ├── header.png │ │ ├── background.jpg │ │ └── background.png │ ├── sasl.wxs │ ├── make-config.pl │ ├── server.pem │ ├── ca │ │ └── ca.c │ ├── setup.wixproj │ ├── libraries.wxs │ └── setup.wxs └── router │ └── fnmatch.h ├── README ├── ChangeLog ├── subst ├── inet_aton.c ├── Makefile.am ├── inet_pton.c ├── strndup.c ├── timegm.c ├── inet_ntop.c ├── dirent.h ├── gettimeofday.c ├── syslog.h ├── subst.h ├── dirent.c └── syslog.c ├── etc ├── jabberd-router.conf.in ├── jabberd-c2s.conf.in ├── jabberd-s2s.conf.in ├── jabberd-sm.conf.in ├── jabberd-sm.service.in ├── jabberd-router.service.in ├── templates │ ├── roster.xml.dist.in │ └── Makefile.am ├── router-users.xml.dist.in ├── jabberd-c2s.service.in ├── jabberd-s2s.service.in ├── jabberd.service.in ├── jabberd.cfg.dist.in ├── Makefile.am └── router-filter.xml.dist.in ├── tools ├── pam_jabberd ├── git ├── Makefile.am ├── jabberd2.schema ├── db-update.sqlite ├── pipe-auth.pl ├── db-jd14-2-jd2.sql ├── db-update.mysql └── jabberd.rc ├── mio ├── Makefile.am ├── mio_kqueue.c ├── mio_epoll.c ├── mio_poll.c ├── mio_select.c ├── mio.c └── mio_wsasync.c ├── s2s ├── Makefile.am ├── db.c └── util.c ├── router ├── Makefile.am └── user.c ├── sx ├── Makefile.am ├── sasl.h ├── env.c └── chain.c ├── util ├── Makefile.am ├── misc.c ├── pqueue.h ├── misc.h ├── datetime.h ├── base64.h ├── hex.c ├── sha1.h ├── log.h ├── crypt_blowfish.h ├── inaddr.h ├── xhash.h ├── rate.c ├── jqueue.c ├── pqueue.c ├── util_compat.h ├── xdata.h └── pool.h ├── docs ├── layout └── dev │ ├── c2s-pipe-authenticator │ ├── c2s-authreg │ ├── component-protocol │ ├── sm-c2s-protocol │ ├── sm-storage-types │ └── sm-presence-logic ├── c2s ├── Makefile.am ├── address.c ├── bind.c └── sm.c ├── contrib ├── README └── cyrus-sasl-digest-md5-fix.diff ├── man ├── Makefile.am ├── jabberd.8.in ├── s2s.8.in ├── c2s.8.in ├── router.8.in └── sm.8.in ├── Makefile.am ├── .gitignore ├── license-header ├── README.config ├── .travis.yml ├── jabberd2.pro ├── storage ├── authreg_anon.c └── authreg_ntlogon.c ├── sm ├── mod_validate.c ├── feature.c ├── mod_echo.c ├── mod_iq_ping.c ├── mod_active.c ├── mod_pep.c ├── mod_deliver.c └── mod_iq_time.c └── TODO /tests/empty.xml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /win32/include/unistd.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | See README.md 2 | -------------------------------------------------------------------------------- /tests/failed_to_load_002.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /tests/includeme2.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /tests/subdir/includeme.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- 1 | See https://github.com/jabberd2/jabberd2/commits 2 | -------------------------------------------------------------------------------- /subst/inet_aton.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RDFS/jabberd2/master/subst/inet_aton.c -------------------------------------------------------------------------------- /win32/jabberd2.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RDFS/jabberd2/master/win32/jabberd2.ico -------------------------------------------------------------------------------- /win32/jabberd2.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RDFS/jabberd2/master/win32/jabberd2.rc -------------------------------------------------------------------------------- /win32/include/idn-int.h: -------------------------------------------------------------------------------- 1 | #define LOCALEDIR "." 2 | #include "config.h" 3 | #include "ac-stdint.h" 4 | -------------------------------------------------------------------------------- /win32/setup/bitmaps/banner.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RDFS/jabberd2/master/win32/setup/bitmaps/banner.jpg -------------------------------------------------------------------------------- /win32/setup/bitmaps/header.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RDFS/jabberd2/master/win32/setup/bitmaps/header.png -------------------------------------------------------------------------------- /win32/setup/bitmaps/background.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RDFS/jabberd2/master/win32/setup/bitmaps/background.jpg -------------------------------------------------------------------------------- /win32/setup/bitmaps/background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RDFS/jabberd2/master/win32/setup/bitmaps/background.png -------------------------------------------------------------------------------- /tests/test_include.xml: -------------------------------------------------------------------------------- 1 | 2 | includeme2.xml 3 | subdir/includeme.xml 4 | -------------------------------------------------------------------------------- /tests/failed_to_load_003.xml: -------------------------------------------------------------------------------- 1 | 2 | asdfgh${invalid}zxcvbn --> 3 | -------------------------------------------------------------------------------- /tests/failed_to_load_004.xml: -------------------------------------------------------------------------------- 1 | 2 | asdfgh${later}zxcvbn --> 3 | qwerty 4 | -------------------------------------------------------------------------------- /win32/include/version.h.in: -------------------------------------------------------------------------------- 1 | #define SVN_REVISION $WCREV$ 2 | #define SVN_VERSION "2.2svn$WCREV$" 3 | #define SVN_FILEVERSION 2,2,0,$WCREV$ 4 | #define SVN_URL "$WCURL$" 5 | -------------------------------------------------------------------------------- /etc/jabberd-router.conf.in: -------------------------------------------------------------------------------- 1 | description "jabberd Router component" 2 | 3 | start on runlevel [2345] 4 | stop on runlevel [!2345] 5 | 6 | respawn 7 | 8 | exec sudo -u jabber @bindir@/@jabberd_router_bin@ 9 | -------------------------------------------------------------------------------- /etc/jabberd-c2s.conf.in: -------------------------------------------------------------------------------- 1 | description "jabberd Client-2-Server component" 2 | 3 | start on runlevel [2345] 4 | stop on runlevel [!2345] 5 | 6 | respawn 7 | 8 | exec sudo -u jabber @bindir@/@jabberd_c2s_bin@ 9 | -------------------------------------------------------------------------------- /etc/jabberd-s2s.conf.in: -------------------------------------------------------------------------------- 1 | description "jabberd Server-2-Server component" 2 | 3 | start on runlevel [2345] 4 | stop on runlevel [!2345] 5 | 6 | respawn 7 | 8 | exec sudo -u jabber @bindir@/@jabberd_s2s_bin@ 9 | -------------------------------------------------------------------------------- /etc/jabberd-sm.conf.in: -------------------------------------------------------------------------------- 1 | description "jabberd Session Manager component" 2 | 3 | start on runlevel [2345] 4 | stop on runlevel [!2345] 5 | 6 | respawn 7 | 8 | exec sudo -u jabber @bindir@/@jabberd_sm_bin@ 9 | -------------------------------------------------------------------------------- /tools/pam_jabberd: -------------------------------------------------------------------------------- 1 | #%PAM-1.0 2 | #/etc/pam.d/jabberd 3 | 4 | auth required pam_nologin.so 5 | auth include system-auth 6 | account include system-auth 7 | session include system-auth 8 | -------------------------------------------------------------------------------- /etc/jabberd-sm.service.in: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Jabber IM Session Manager 3 | After=network.target 4 | BindTo=jabberd.service 5 | 6 | [Service] 7 | User=jabber 8 | ExecStart=@bindir@/@jabberd_sm_bin@ -c @sysconfdir@/sm.xml 9 | 10 | [Install] 11 | WantedBy=multi-user.target 12 | -------------------------------------------------------------------------------- /win32/include/version.wxi.in: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /etc/jabberd-router.service.in: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Jabber Router XML Packet Distributior 3 | After=network.target 4 | BindTo=jabberd.service 5 | 6 | [Service] 7 | User=jabber 8 | ExecStart=@bindir@/@jabberd_router_bin@ -c @sysconfdir@/router.xml 9 | 10 | [Install] 11 | WantedBy=multi-user.target 12 | -------------------------------------------------------------------------------- /etc/templates/roster.xml.dist.in: -------------------------------------------------------------------------------- 1 | 3 | 4 | 7 | 8 | -------------------------------------------------------------------------------- /etc/router-users.xml.dist.in: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | jabberd 6 | secret 7 | 8 | 9 | 12 | -------------------------------------------------------------------------------- /mio/Makefile.am: -------------------------------------------------------------------------------- 1 | LIBTOOL += --quiet 2 | AM_CPPFLAGS = -I@top_srcdir@ 3 | 4 | noinst_LTLIBRARIES = libmio.la 5 | 6 | noinst_HEADERS = mio.h mio_impl.h mio_epoll.h mio_poll.h mio_select.h mio_kqueue.h mio_wsasync.h 7 | 8 | libmio_la_SOURCES = mio.c mio_epoll.c mio_poll.c mio_select.c mio_kqueue.c mio_wsasync.c 9 | libmio_la_LIBADD = @LDFLAGS@ 10 | -------------------------------------------------------------------------------- /etc/jabberd-c2s.service.in: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Jabber Client To Server Connector 3 | Requires=jabberd-router.service 4 | After=network.target jabberd-router.service 5 | BindTo=jabberd.service 6 | 7 | [Service] 8 | User=jabber 9 | ExecStart=@bindir@/@jabberd_c2s_bin@ -c @sysconfdir@/c2s.xml 10 | 11 | [Install] 12 | WantedBy=multi-user.target 13 | -------------------------------------------------------------------------------- /etc/jabberd-s2s.service.in: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Jabber Server To Server Connector 3 | Requires=jabberd-router.service 4 | After=network.target jabberd-router.service 5 | BindTo=jabberd.service 6 | 7 | [Service] 8 | User=jabber 9 | ExecStart=@bindir@/@jabberd_s2s_bin@ -c @sysconfdir@/s2s.xml 10 | 11 | [Install] 12 | WantedBy=multi-user.target 13 | -------------------------------------------------------------------------------- /subst/Makefile.am: -------------------------------------------------------------------------------- 1 | LIBTOOL += --quiet 2 | 3 | noinst_LTLIBRARIES = libsubst.la 4 | 5 | noinst_HEADERS = dirent.h getopt.h ip6_misc.h subst.h syslog.h 6 | 7 | libsubst_la_SOURCES = dirent.c getopt.c gettimeofday.c inet_aton.c inet_ntop.c inet_pton.c snprintf.c syslog.c strndup.c timegm.c 8 | libsubst_la_LIBADD = @LDFLAGS@ 9 | libsubst_la_LDFLAGS = -export-dynamic 10 | -------------------------------------------------------------------------------- /mio/mio_kqueue.c: -------------------------------------------------------------------------------- 1 | /* 2 | MIO -- Managed Input/Output 3 | --------------------------- 4 | */ 5 | 6 | #ifdef HAVE_CONFIG_H 7 | # include 8 | #endif 9 | 10 | #include "mio.h" 11 | 12 | 13 | #ifdef MIO_KQUEUE 14 | #include "mio_kqueue.h" 15 | #include "mio_impl.h" 16 | 17 | mio_t mio_kqueue_new(int maxfd) 18 | { 19 | return _mio_new(maxfd); 20 | } 21 | #endif 22 | -------------------------------------------------------------------------------- /s2s/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CPPFLAGS = -DCONFIG_DIR=\"$(sysconfdir)\" -I@top_srcdir@ 2 | 3 | LIBTOOL += --quiet 4 | 5 | bin_PROGRAMS = s2s 6 | 7 | noinst_HEADERS = s2s.h 8 | s2s_SOURCES = in.c main.c out.c router.c db.c util.c 9 | 10 | s2s_LDADD = $(top_builddir)/sx/libsx.la \ 11 | $(top_builddir)/mio/libmio.la \ 12 | $(top_builddir)/util/libutil.la 13 | if USE_LIBSUBST 14 | s2s_LDADD += $(top_builddir)/subst/libsubst.la 15 | endif 16 | -------------------------------------------------------------------------------- /router/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CPPFLAGS = -DCONFIG_DIR=\"$(sysconfdir)\" -I@top_srcdir@ 2 | 3 | LIBTOOL += --quiet 4 | 5 | bin_PROGRAMS = router 6 | 7 | noinst_HEADERS = router.h 8 | router_SOURCES = aci.c main.c router.c user.c filter.c 9 | 10 | router_LDADD = $(top_builddir)/sx/libsx.la \ 11 | $(top_builddir)/mio/libmio.la \ 12 | $(top_builddir)/util/libutil.la 13 | if USE_LIBSUBST 14 | router_LDADD += $(top_builddir)/subst/libsubst.la 15 | endif 16 | -------------------------------------------------------------------------------- /etc/jabberd.service.in: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Jabber Server 3 | Requires=jabberd-router.service jabberd-sm.service jabberd-c2s.service jabberd-s2s.service 4 | After=network.target jabberd-router.service jabberd-sm.service jabberd-c2s.service jabberd-s2s.service 5 | BindTo=jabberd-router.service jabberd-sm.service jabberd-c2s.service jabberd-s2s.service 6 | 7 | [Service] 8 | Type=oneshot 9 | ExecStart=/bin/true 10 | RemainAfterExit=yes 11 | 12 | [Install] 13 | WantedBy=multi-user.target 14 | -------------------------------------------------------------------------------- /sx/Makefile.am: -------------------------------------------------------------------------------- 1 | LIBTOOL += --quiet 2 | AM_CPPFLAGS = -I@top_srcdir@ 3 | 4 | noinst_LTLIBRARIES = libsx.la 5 | noinst_HEADERS = plugins.h sasl.h sx.h 6 | 7 | libsx_la_SOURCES = callback.c chain.c client.c env.c error.c io.c server.c sx.c sasl.c ack.c 8 | libsx_la_LIBADD = @LDFLAGS@ 9 | 10 | if HAVE_SSL 11 | libsx_la_SOURCES += ssl.c 12 | endif 13 | 14 | if HAVE_LIBZ 15 | libsx_la_SOURCES += compress.c 16 | endif 17 | 18 | if USE_WEBSOCKET 19 | libsx_la_SOURCES += websocket.c 20 | endif 21 | -------------------------------------------------------------------------------- /tools/git: -------------------------------------------------------------------------------- 1 | ChangeLog log format: 2 | git log --pretty=format:'%ai %aN <%aE>%n\t* %s\n' 3 | 4 | New release: 5 | git co -b 2.X.0 6 | vim configure.ac 7 | git commit configure.ac -m "2.X.0 release" 8 | git tag -s jabberd-2.X.0 9 | autoreconf -fi 10 | ./configure 11 | make dist 12 | git push github tag jabberd-2.X.0 13 | gzip -dc jabberd-2.X.0.tar.gz | xz -9 > jabberd-2.X.0.tar.xz 14 | gpg --armor --detach-sign jabberd-2.X.0.tar.gz 15 | gpg --armor --detach-sign jabberd-2.X.0.tar.xz 16 | 17 | -------------------------------------------------------------------------------- /util/Makefile.am: -------------------------------------------------------------------------------- 1 | LIBTOOL += --quiet 2 | AM_CPPFLAGS = -I@top_srcdir@ 3 | 4 | noinst_LTLIBRARIES = libutil.la 5 | 6 | noinst_HEADERS = inaddr.h md5.h sha1.h util.h util_compat.h xdata.h nad.h pool.h xhash.h uri.h jid.h base64.h datetime.h log.h crypt_blowfish.h 7 | 8 | libutil_la_SOURCES = access.c base64.c config.c datetime.c hex.c inaddr.c jid.c jqueue.c jsignal.c log.c md5.c nad.c pool.c rate.c serial.c sha1.c stanza.c str.c xdata.c xhash.c crypt_blowfish.c 9 | 10 | libutil_la_LIBADD = @LDFLAGS@ -------------------------------------------------------------------------------- /docs/layout: -------------------------------------------------------------------------------- 1 | jabber2/ 2 | 3 | docs/ - Documentation 4 | code/ - Doxygen generated 5 | dev/ - Hacker docs 6 | 7 | mio/ - Managed Input/Ouput (FD event processor) 8 | sx/ - Streams for XML (Jabber connection / stream library) 9 | util/ - Utilities (config, logging, NADs, hashtables, etc) 10 | 11 | c2s/ - Client-to-server 12 | router/ - XML router 13 | sm/ - Session manager 14 | s2s/ - Server-to-server 15 | -------------------------------------------------------------------------------- /tests/Makefile.am: -------------------------------------------------------------------------------- 1 | LIBTOOL += --quiet 2 | AM_CPPFLAGS = -I@top_srcdir@ -DSRCDIR="\"$(srcdir)\"" 3 | 4 | EXTRA_DIST = *.xml subdir 5 | 6 | TESTS = check_nad check_config 7 | 8 | check_PROGRAMS = check_nad check_config 9 | 10 | check_nad_SOURCES = check_nad.c 11 | check_nad_CFLAGS = $(CHECK_CFLAGS) 12 | check_nad_LDADD = $(top_builddir)/util/libutil.la $(CHECK_LIBS) 13 | 14 | check_config_SOURCES = check_config.c 15 | check_config_CFLAGS = $(CHECK_CFLAGS) 16 | check_config_LDADD = $(top_builddir)/util/libutil.la $(CHECK_LIBS) 17 | -------------------------------------------------------------------------------- /win32/include/ac-stdint.h: -------------------------------------------------------------------------------- 1 | #ifndef _AC_STDINT_H 2 | #define _AC_STDINT_H 1 3 | #ifndef _GENERATED_STDINT_H 4 | #define _GENERATED_STDINT_H 5 | 6 | #define uint8_t unsigned char 7 | #define uint16_t unsigned short 8 | #define uint32_t unsigned int 9 | #define int8_t signed char 10 | #define int16_t signed short 11 | #define int32_t signed int 12 | 13 | #define gint16 int16_t 14 | 15 | #ifdef _WIN64 16 | typedef __int64 ssize_t; 17 | #else 18 | typedef _W64 int ssize_t; 19 | #endif 20 | 21 | #endif 22 | #endif 23 | -------------------------------------------------------------------------------- /win32/setup/sasl.wxs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /c2s/Makefile.am: -------------------------------------------------------------------------------- 1 | LIBTOOL += --quiet 2 | 3 | bin_PROGRAMS = c2s 4 | 5 | c2s_SOURCES = authreg.c bind.c c2s.c main.c sm.c pbx.c pbx_commands.c address.c 6 | c2s_CPPFLAGS = -DCONFIG_DIR=\"$(sysconfdir)\" -DLIBRARY_DIR=\"$(pkglibdir)\" -I@top_srcdir@ 7 | c2s_LDFLAGS = -export-dynamic 8 | 9 | noinst_HEADERS = c2s.h 10 | 11 | c2s_LDADD = $(top_builddir)/sx/libsx.la \ 12 | $(top_builddir)/mio/libmio.la \ 13 | $(top_builddir)/util/libutil.la 14 | if USE_LIBSUBST 15 | c2s_LDADD += $(top_builddir)/subst/libsubst.la 16 | endif 17 | if USE_WEBSOCKET 18 | c2s_LDADD += -lhttp_parser 19 | endif 20 | -------------------------------------------------------------------------------- /etc/jabberd.cfg.dist.in: -------------------------------------------------------------------------------- 1 | # 2 | # jabberd config file 3 | # 4 | # 5 | # This file tells the jabberd wrapper what programs to launch, 6 | # and the config files to launch them with. If the config file 7 | # is left out, then the system default will be used. 8 | # 9 | # To run multiple Session Managers, just list them all seperatly 10 | # and provide the path to the appropriate config files. 11 | # 12 | # program [ path to config file ] 13 | # 14 | 15 | @jabberd_router_bin@ @sysconfdir@/router.xml 16 | @jabberd_sm_bin@ @sysconfdir@/sm.xml 17 | @jabberd_s2s_bin@ @sysconfdir@/s2s.xml 18 | @jabberd_c2s_bin@ @sysconfdir@/c2s.xml 19 | -------------------------------------------------------------------------------- /win32/setup/make-config.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | my @file = <>; 4 | 5 | $_ = join '', @file; 6 | s/\r//gi; 7 | s/localhost\.localdomain/localhost/gi; 8 | s/\@(?:bindir|sysconfdir|localstatedir)\@/./gi; 9 | s/\@(?:pkglibdir)\@/modules/gi; 10 | s/\/jabberd\/(?:pid|log|db|stats)//gi; 11 | s/we use the MySQL driver for all storage/we use the SQLite driver for all storage/gi; 12 | s/mysql<\/driver>/sqlite<\/driver>/gi; 13 | s/mysql<\/module>/sqlite<\/module>/gi; 14 | s/type='syslog'/type='file'/gi; 15 | s/\s*[^\n]*/\n$1/gi; 16 | s/localhost/localhost/gi; 17 | 18 | print; 19 | -------------------------------------------------------------------------------- /contrib/README: -------------------------------------------------------------------------------- 1 | This directory contains patches to the code which you may or may 2 | not find useful. They are modifications to the main source which 3 | would have had a detrimental affect towards jabberd2's goal of 4 | 100% xmpp compliance. Or they simply were not deemed appropriate 5 | to add into the main source dist. However, there are situations 6 | in which this code may be of use, so the patches are kept here. 7 | 8 | These patches are not maintained by jabberd2 team and may or may 9 | not be out of date. You are have been warned. 10 | 11 | Good Luck 12 | 13 | 14 | patch-flash-v2 15 | -------------- 16 | This modifies c2s in order to allow macromedia's embrace and extend 17 | proprietary mark-up language to inter-operate with j2. 18 | -------------------------------------------------------------------------------- /man/Makefile.am: -------------------------------------------------------------------------------- 1 | man_MANS = jabberd.8 c2s.8 router.8 s2s.8 sm.8 2 | EXTRA_DIST = jabberd.8.in c2s.8.in router.8.in s2s.8.in sm.8.in 3 | 4 | LIBTOOL += --quiet 5 | 6 | jabberd_bin = router sm s2s c2s 7 | 8 | edit = sed \ 9 | -e 's,@sysconfdir\@,$(sysconfdir),g' \ 10 | -e 's,@VERSION\@,$(VERSION),g' 11 | 12 | $(man_MANS): 13 | @echo "generating $@ from $@.in"; \ 14 | edit='$(edit)'; \ 15 | list='$(jabberd_bin)'; for p in $$list; do \ 16 | bin=`echo "$$p" | sed 's,^.*/,,;$(transform);s/$$/$(EXEEXT)/'`; \ 17 | edit="$$edit -e s,@jabberd_$$p\_bin\\@,$$bin,g"; \ 18 | done; \ 19 | rm -f $@ $@.tmp; \ 20 | eval "$$edit < @srcdir@/$@.in > $@.tmp"; \ 21 | mv $@.tmp $@ 22 | 23 | clean-local: 24 | rm -f $(man_MANS) 25 | -------------------------------------------------------------------------------- /subst/inet_pton.c: -------------------------------------------------------------------------------- 1 | #ifdef HAVE_CONFIG_H 2 | # include "config.h" 3 | #endif 4 | 5 | #if !defined(HAVE_INET_PTON) && defined(_WIN32) 6 | #ifdef JABBERD2_EXPORTS 7 | # define JABBERD2_API __declspec(dllexport) 8 | #else /* JABBERD2_EXPORTS */ 9 | # define JABBERD2_API __declspec(dllimport) 10 | #endif /* JABBERD2_EXPORTS */ 11 | 12 | #include "ac-stdint.h" 13 | 14 | #include "ip6_misc.h" 15 | 16 | #include 17 | 18 | #ifndef EAFNOSUPPORT 19 | #define EAFNOSUPPORT 97 /* not present in errno.h provided with VC */ 20 | #endif 21 | 22 | JABBERD2_API int 23 | inet_pton(int af, const char *src, void *dst) 24 | { 25 | if (af != AF_INET) { 26 | errno = EAFNOSUPPORT; 27 | return -1; 28 | } 29 | return inet_aton (src, dst); 30 | } 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | EXTRA_DIST = Doxyfile.in README.md README.win32 README.protocol README.config contrib docs win32 2 | 3 | LIBTOOL += --quiet 4 | 5 | SUBDIRS = etc man 6 | if USE_LIBSUBST 7 | SUBDIRS += subst 8 | endif 9 | SUBDIRS += tools mio sx util c2s router s2s storage sm 10 | if ENABLE_TESTS 11 | SUBDIRS += tests 12 | endif 13 | 14 | .PHONY: docs cppcheck 15 | 16 | docs: Doxyfile 17 | @doxygen 18 | 19 | cppcheck: 20 | cppcheck --force --quiet --report-progress -j6 --std=c99 -DSIGHUP -DSIGPIPE --enable=warning,performance,portability,information,missingInclude . 21 | 22 | dist-hook: 23 | if grep 'AC_INIT.*dev' configure.ac ; then echo "Remove 'dev' version flag first!"; exit 1; else : ; fi 24 | find $(distdir) -depth \( -name CVS -o -name .svn -o -name .git \) -exec rm -rf {} \; 25 | -------------------------------------------------------------------------------- /win32/include/win32_port.h: -------------------------------------------------------------------------------- 1 | #ifndef _WIN32_PORT_H 2 | #define _WIN32_PORT_H 3 | 4 | #define FD_SETSIZE 16384 5 | 6 | /* Declare we support Win2000 & IE4. 7 | * Needed to avoid inet_ntop & inet_ption Vista SDK inclusion. */ 8 | #define WINVER 0x0500 9 | #define _WIN32_WINNT 0x0500 10 | #define _WIN32_IE 0x0400 11 | #define _RICHEDIT_VER 0x0100 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #define CONFIG_DIR "." 19 | #define LIBRARY_DIR "." 20 | 21 | #ifndef S_IRUSR 22 | #define S_IRUSR 0 23 | #endif 24 | #ifndef S_IWUSR 25 | #define S_IWUSR 0 26 | #endif 27 | #ifndef S_IRGRP 28 | #define S_IRGRP 0 29 | #endif 30 | 31 | #ifdef _DEBUG 32 | #define DEBUG 1 33 | #endif 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .libs/ 2 | .deps/ 3 | *.o 4 | *.lo 5 | *.la 6 | *.so 7 | *~ 8 | *.swp 9 | jabberd2.pro.* 10 | Makefile 11 | Makefile.in 12 | aclocal.m4 13 | ac-stdint.h 14 | autom4te.cache 15 | config.guess 16 | config.h 17 | config.h.in 18 | config.log 19 | config.status 20 | config.sub 21 | configure 22 | depcomp 23 | Doxyfile 24 | INSTALL 25 | install-sh 26 | libtool 27 | ltmain.sh 28 | missing 29 | stamp-h1 30 | compile 31 | c2s/c2s 32 | etc/*.conf 33 | etc/*.cfg.dist 34 | etc/*.xml.dist 35 | etc/*.service 36 | etc/templates/*.xml.dist 37 | man/c2s.8 38 | man/jabberd.8 39 | man/resolver.8 40 | man/router.8 41 | man/s2s.8 42 | man/sm.8 43 | router/router 44 | s2s/s2s 45 | sm/sm 46 | tools/jabberd 47 | tests/config/configtest 48 | docs/code 49 | /tests/check_config 50 | /tests/check_nad 51 | /test-driver 52 | -------------------------------------------------------------------------------- /docs/dev/c2s-pipe-authenticator: -------------------------------------------------------------------------------- 1 | c2s startup 2 | pipe init 3 | - create socketpair 4 | - fork 5 | - attach pair to stdio 6 | - exec prog 7 | 8 | Commands return OK or NO, followed by return values 9 | 10 | Init: 11 | 12 | [auth process running] 13 | <<< OK USER-EXISTS GET-PASSWORD CHECK-PASSWORD SET-PASSWORD CREATE-USER DESTROY-USER FREE 14 | 15 | >>> USER-EXISTS user [realm] 16 | <<< OK 17 | <<< NO 18 | 19 | >>> GET-PASSWORD user [realm] 20 | <<< OK encoded_pass 21 | <<< NO 22 | 23 | >>> CHECK-PASSWORD user encoded_pass [realm] 24 | <<< OK 25 | <<< NO 26 | 27 | >>> SET-PASSWORD user encoded_pass [realm] 28 | <<< OK 29 | <<< NO 30 | 31 | >>> CREATE-USER user [realm] 32 | <<< OK 33 | <<< NO 34 | 35 | >>> DELETE-USER user [realm] 36 | <<< OK 37 | <<< NO 38 | 39 | >>> FREE 40 | [auth process exits] 41 | -------------------------------------------------------------------------------- /man/jabberd.8.in: -------------------------------------------------------------------------------- 1 | .TH jabberd 8 "28 August 2003" "@VERSION@" "jabberd project" 2 | .SH NAME 3 | jabberd \- jabberd startup script 4 | .SH SYNOPSIS 5 | .B jabberd 6 | .I [-h] [-c config] [-D] 7 | .SH DESCRIPTION 8 | .BR jabberd 9 | is a script that runs the various components that make up the jabberd "server". 10 | .SH OPTIONS 11 | .TP 12 | .B \-h 13 | Show summary of options. 14 | .TP 15 | .B \-c 16 | Alternate configuration file to use. The compiled-in default is @sysconfdir@/jabberd.cfg 17 | .TP 18 | .B \-D 19 | Print debugging output. You should configure jabberd with the --enable-debug switch to enable this. 20 | .SH SEE ALSO 21 | .BR @jabberd_c2s_bin@ (8) 22 | .BR @jabberd_router_bin@ (8) 23 | .BR @jabberd_s2s_bin@ (8) 24 | .BR @jabberd_sm_bin@ (8) 25 | .SH AUTHOR 26 | Robert Norris 27 | -------------------------------------------------------------------------------- /subst/strndup.c: -------------------------------------------------------------------------------- 1 | #ifdef HAVE_CONFIG_H 2 | # include "config.h" 3 | #endif /* HAVE_CONFIG_H */ 4 | 5 | #ifndef HAVE_STRNDUP 6 | 7 | #include 8 | 9 | /* jabberd2 Windows DLL */ 10 | #ifndef JABBERD2_API 11 | # ifdef _WIN32 12 | # ifdef JABBERD2_EXPORTS 13 | # define JABBERD2_API __declspec(dllexport) 14 | # else /* JABBERD2_EXPORTS */ 15 | # define JABBERD2_API __declspec(dllimport) 16 | # endif /* JABBERD2_EXPORTS */ 17 | # else /* _WIN32 */ 18 | # define JABBERD2_API extern 19 | # endif /* _WIN32 */ 20 | #endif /* JABBERD2_API */ 21 | 22 | JABBERD2_API char *strndup(char *str, size_t len) 23 | { 24 | char *dup = (char *)malloc(len+1); 25 | if (dup) { 26 | strncpy(dup,str,len); 27 | dup[len]= '\0'; 28 | } 29 | return dup; 30 | } 31 | #endif /* HAVE_STRNDUP */ 32 | -------------------------------------------------------------------------------- /docs/dev/c2s-authreg: -------------------------------------------------------------------------------- 1 | Simple authentication (iq:auth) flow: 2 | 3 | state: STREAM 4 | 5 | >>> iq:auth get 6 | <<< iq:auth result containing auth methods 7 | >>> iq:auth set 8 | verify credentials 9 | start session 10 | <<< iq:auth result 11 | 12 | Registration (iq:register) flow: 13 | 14 | state: STREAM 15 | 16 | >>> iq:register get 17 | <<< iq:register result containing required fields (username & password) 18 | >>> iq:register set 19 | create user 20 | <<< iq:register 21 | 22 | Registration remove flow: 23 | 24 | state: OPEN 25 | 26 | >>> iq:register set containing remove tag 27 | stop session 28 | destroy user 29 | <<< iq:register result 30 | <<< disconnect 31 | 32 | Password change flow: 33 | 34 | state: OPEN 35 | >>> iq:register set 36 | save password 37 | <<< iq:register result 38 | -------------------------------------------------------------------------------- /tools/Makefile.am: -------------------------------------------------------------------------------- 1 | LIBTOOL += --quiet 2 | 3 | bin_SCRIPTS = jabberd 4 | EXTRA_DIST = db-setup.mysql db-update.mysql db-setup.pgsql db-update.pgsql db-setup.oracle db-setup.sqlite db-update.sqlite \ 5 | jabberd.in jabberd.rc pipe-auth.pl jabberd-authpipe-pam-0.1.pl pam_jabberd jabberd2.schema \ 6 | db-jd14-2-jd2.sql migrate-jd14dir-2-sqlite.pl migrate.pl \ 7 | bdb2mysql.rb bdbdump.pl 8 | 9 | edit = sed \ 10 | -e 's,@sysconfdir\@,$(sysconfdir),g' \ 11 | -e 's,@VERSION\@,$(VERSION),g' \ 12 | -e 's,@bindir\@,$(bindir),g' \ 13 | -e 's,@libexecdir\@,$(libexecdir),g' 14 | 15 | $(bin_SCRIPTS): $(EXTRA_DIST) 16 | @echo "generating $@ from $@.in"; \ 17 | rm -f $@ $@.tmp; \ 18 | $(edit) < @srcdir@/$@.in > $@.tmp; \ 19 | chmod +x $@.tmp; \ 20 | mv $@.tmp $@ 21 | 22 | clean-local: 23 | rm -f $(bin_SCRIPTS) 24 | -------------------------------------------------------------------------------- /man/s2s.8.in: -------------------------------------------------------------------------------- 1 | .TH @jabberd_s2s_bin@ 8 "28 August 2003" "@VERSION@" "jabberd project" 2 | .SH NAME 3 | @jabberd_s2s_bin@ \- server-to-server connector 4 | .SH SYNOPSIS 5 | .B @jabberd_s2s_bin@ 6 | .I [-h] [-c config] [-D] 7 | .SH DESCRIPTION 8 | .BR @jabberd_s2s_bin@ 9 | manages connections between local components and other Jabber servers. 10 | .SH OPTIONS 11 | .TP 12 | .B \-h 13 | Show summary of options. 14 | .TP 15 | .B \-c 16 | Alternate configuration file to use. The compiled-in default is @sysconfdir@/s2s.xml. 17 | .TP 18 | .B \-D 19 | Print debugging output. You should configure jabberd with the --enable-debug switch to enable this. 20 | .SH SEE ALSO 21 | .BR jabberd (8) 22 | .BR @jabberd_c2s_bin@ (8) 23 | .BR @jabberd_router_bin@ (8) 24 | .BR @jabberd_sm_bin@ (8) 25 | .SH AUTHOR 26 | Robert Norris 27 | -------------------------------------------------------------------------------- /man/c2s.8.in: -------------------------------------------------------------------------------- 1 | .TH @jabberd_c2s_bin@ 8 "28 August 2003" "@VERSION@" "jabberd project" 2 | .SH NAME 3 | @jabberd_c2s_bin@ \- client-to-server connector 4 | .SH SYNOPSIS 5 | .B @jabberd_c2s_bin@ 6 | .I [-h] [-c config] [-D] 7 | .SH DESCRIPTION 8 | .BR @jabberd_c2s_bin@ 9 | accepts incoming connections from clients, performs authentication and registration functions, and communicates with the session manager on their behalf. 10 | .SH OPTIONS 11 | .TP 12 | .B \-h 13 | Show summary of options. 14 | .TP 15 | .B \-c 16 | Alternate configuration file to use. The compiled-in default is @sysconfdir@/c2s.xml. 17 | .TP 18 | .B \-D 19 | Print debugging output. You should configure jabberd with the --enable-debug switch to enable this. 20 | .SH SEE ALSO 21 | .BR jabberd (8) 22 | .BR @jabberd_router_bin@ (8) 23 | .BR @jabberd_s2s_bin@ (8) 24 | .BR @jabberd_sm_bin@ (8) 25 | .SH AUTHOR 26 | Robert Norris 27 | -------------------------------------------------------------------------------- /man/router.8.in: -------------------------------------------------------------------------------- 1 | .TH @jabberd_router_bin@ 8 "28 August 2003" "@VERSION@" "jabberd project" 2 | .SH NAME 3 | @jabberd_router_bin@ \- XML packet distributor 4 | .SH SYNOPSIS 5 | .B @jabberd_router_bin@ 6 | .I [-h] [-c config] [-D] 7 | .SH DESCRIPTION 8 | .BR @jabberd_router_bin@ 9 | is the core component of the jabberd system. It passes XML packets between the components, and manages the entry and exit of components onto the network. 10 | .SH OPTIONS 11 | .TP 12 | .B \-h 13 | Show summary of options. 14 | .TP 15 | .B \-c 16 | Alternate configuration file to use. The compiled-in default is @sysconfdir@/router.xml. 17 | .TP 18 | .B \-D 19 | Print debugging output. You should configure jabberd with the --enable-debug switch to enable this. 20 | .SH SEE ALSO 21 | .BR jabberd (8) 22 | .BR @jabberd_c2s_bin@ (8) 23 | .BR @jabberd_s2s_bin@ (8) 24 | .BR @jabberd_sm_bin@ (8) 25 | .SH AUTHOR 26 | Robert Norris 27 | -------------------------------------------------------------------------------- /man/sm.8.in: -------------------------------------------------------------------------------- 1 | .TH @jabberd_sm_bin@ 8 "28 August 2003" "@VERSION@" "jabberd project" 2 | .SH NAME 3 | @jabberd_sm_bin@ \- Jabber IM session manager 4 | .SH SYNOPSIS 5 | .B @jabberd_sm_bin@ 6 | .I [-h] [-c config] [-D] 7 | .SH DESCRIPTION 8 | .BR @jabberd_sm_bin@ 9 | provides instant messaging services to Jabber clients. It performs all the essential instant messaging services like rosters, presence tracking, message distribution and subscriptions, plus more advanced features. 10 | .SH OPTIONS 11 | .TP 12 | .B \-h 13 | Show summary of options. 14 | .TP 15 | .B \-c 16 | Alternate configuration file to use. The compiled-in default is @sysconfdir@/sm.xml. 17 | .TP 18 | .B \-D 19 | Print debugging output. You should configure jabberd with the --enable-debug switch to enable this. 20 | .SH SEE ALSO 21 | .BR jabberd (8) 22 | .BR @jabberd_c2s_bin@ (8) 23 | .BR @jabberd_router_bin@ (8) 24 | .BR @jabberd_s2s_bin@ (8) 25 | .SH AUTHOR 26 | Robert Norris 27 | -------------------------------------------------------------------------------- /license-header: -------------------------------------------------------------------------------- 1 | /* 2 | * jabberd - Jabber Open Source Server 3 | * Copyright (c) 2002-2008 Jeremie Miller, Thomas Muldowney, 4 | * Ryan Eatmon, Robert Norris, Tomasz Sterna 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA 19 | */ 20 | 21 | -------------------------------------------------------------------------------- /tests/test_config.xml: -------------------------------------------------------------------------------- 1 | 2 | id_from_config 3 | value if id is ${id} 4 | 5 | 1234567 6 | 7 | 8 | 9 | 111${test.value}222 10 | 11 | 12 | qwerty 13 | asdfgh${test_key}zxcvbn 14 | 15 | 16 | qwerty 17 | asdfgh${later}zxcvbn 18 | 19 | 20 | 1 21 | 2 22 | 3 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /etc/templates/Makefile.am: -------------------------------------------------------------------------------- 1 | templatesdir = $(sysconfdir)/templates 2 | 3 | LIBTOOL += --quiet 4 | 5 | templates_DATA = roster.xml.dist 6 | EXTRA_DIST = roster.xml.dist.in 7 | 8 | edit = sed \ 9 | -e 's,@sysconfdir\@,$(sysconfdir),g' \ 10 | -e 's,@localstatedir\@,$(localstatedir),g' \ 11 | -e 's,@bindir\@,$(bindir),g' 12 | 13 | $(templates_DATA): 14 | @echo "generating $@ from $@.in"; \ 15 | rm -f $@ $@.tmp; \ 16 | $(edit) < @srcdir@/$@.in > $@.tmp; \ 17 | mv $@.tmp $@ 18 | 19 | install-data-hook: 20 | @list='$(templates_DATA)'; for p in $$list; do \ 21 | dest=`echo $$p | sed -e s/.dist//`; \ 22 | if test -f $(DESTDIR)$(templatesdir)/$$dest; then \ 23 | echo "$@ will not overwrite existing $(DESTDIR)$(templatesdir)/$$dest"; \ 24 | else \ 25 | echo " $(INSTALL_DATA) $$p $(DESTDIR)$(templatesdir)/$$dest"; \ 26 | $(INSTALL_DATA) $$p $(DESTDIR)$(templatesdir)/$$dest; \ 27 | fi; \ 28 | done 29 | 30 | clean-local: 31 | rm -f $(templates_DATA) 32 | -------------------------------------------------------------------------------- /README.config: -------------------------------------------------------------------------------- 1 | 2 | *** Configuration values substitution *** 3 | 4 | Node data in config is refernced as ${node.name}, for example ${id} wil be replaced with value of node 5 | 6 | - First occurence of node is used for substitution. 7 | For instance,value of 'asd' wil be 'value1', not 'value2' in following sample: 8 | 9 | 10 | value1 11 | value2 12 | ${qqq} 13 | 14 | 15 | - Multiple variable substitution is supported '${qqq}_${qqq}' from example above will be substituted as 'value1_value1' 16 | 17 | - Nested substitution is supported. var3 will contain 'prefix_value-of-v_suffix' in sample below: 18 | 19 | 20 | value-of-v 21 | prefix_${var1}_suffix 22 | ${var2} 23 | 24 | 25 | - ${..} is replaced with node's content defined above only. 26 | ${some.node} must be used after val otherwise warning will be logged. 27 | The following config will cause warning upon loading: 28 | 29 | 30 | ${var1} 31 | value-of-v 32 | 33 | -------------------------------------------------------------------------------- /subst/timegm.c: -------------------------------------------------------------------------------- 1 | #ifdef HAVE_CONFIG_H 2 | # include "config.h" 3 | #endif 4 | 5 | #ifndef HAVE_TIMEGM 6 | #include 7 | #include 8 | #include 9 | 10 | #if !defined(HAVE_SNPRINTF) || defined(HAVE_BROKEN_SNPRINTF) 11 | int ap_snprintf(char *, size_t, const char *, ...); 12 | # define snprintf ap_snprintf 13 | #endif 14 | 15 | /* jabberd2 Windows DLL */ 16 | #ifndef JABBERD2_API 17 | # ifdef _WIN32 18 | # ifdef JABBERD2_EXPORTS 19 | # define JABBERD2_API __declspec(dllexport) 20 | # else /* JABBERD2_EXPORTS */ 21 | # define JABBERD2_API __declspec(dllimport) 22 | # endif /* JABBERD2_EXPORTS */ 23 | # else /* _WIN32 */ 24 | # define JABBERD2_API extern 25 | # endif /* _WIN32 */ 26 | #endif /* JABBERD2_API */ 27 | 28 | JABBERD2_API time_t timegm(struct tm *tm) 29 | { 30 | time_t ret; 31 | char *tz; 32 | 33 | /* save current timezone and set UTC */ 34 | tz = getenv("TZ"); 35 | putenv("TZ=UTC"); /* use Coordinated Universal Time (i.e. zero offset) */ 36 | tzset(); 37 | 38 | ret = mktime(tm); 39 | if(tz) 40 | { 41 | char buf[256]; 42 | snprintf(buf, sizeof(buf), "TZ=%s", tz); 43 | putenv(buf); 44 | } else 45 | putenv("TZ="); 46 | tzset(); 47 | 48 | return ret; 49 | } 50 | #endif 51 | -------------------------------------------------------------------------------- /mio/mio_epoll.c: -------------------------------------------------------------------------------- 1 | /* 2 | * jabberd - Jabber Open Source Server 3 | * Copyright (c) 2002 Jeremie Miller, Thomas Muldowney, 4 | * Ryan Eatmon, Robert Norris, Christof Meerwald 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA 19 | */ 20 | 21 | /* 22 | MIO -- Managed Input/Output 23 | --------------------------- 24 | */ 25 | 26 | #ifdef HAVE_CONFIG_H 27 | # include 28 | #endif 29 | 30 | #include "mio.h" 31 | 32 | 33 | #ifdef MIO_EPOLL 34 | #include "mio_epoll.h" 35 | #include "mio_impl.h" 36 | 37 | mio_t mio_epoll_new(int maxfd) 38 | { 39 | return _mio_new(maxfd); 40 | } 41 | #endif 42 | -------------------------------------------------------------------------------- /mio/mio_poll.c: -------------------------------------------------------------------------------- 1 | /* 2 | * jabberd - Jabber Open Source Server 3 | * Copyright (c) 2002 Jeremie Miller, Thomas Muldowney, 4 | * Ryan Eatmon, Robert Norris, Christof Meerwald 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA 19 | */ 20 | 21 | /* 22 | MIO -- Managed Input/Output 23 | --------------------------- 24 | */ 25 | 26 | #ifdef HAVE_CONFIG_H 27 | # include 28 | #endif 29 | 30 | #include "mio.h" 31 | 32 | 33 | #ifdef MIO_POLL 34 | #include "mio_poll.h" 35 | #include "mio_impl.h" 36 | 37 | mio_t mio_poll_new(int maxfd) 38 | { 39 | return _mio_new(maxfd); 40 | } 41 | #endif 42 | -------------------------------------------------------------------------------- /mio/mio_select.c: -------------------------------------------------------------------------------- 1 | /* 2 | * jabberd - Jabber Open Source Server 3 | * Copyright (c) 2002 Jeremie Miller, Thomas Muldowney, 4 | * Ryan Eatmon, Robert Norris, Christof Meerwald 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA 19 | */ 20 | 21 | /* 22 | MIO -- Managed Input/Output 23 | --------------------------- 24 | */ 25 | 26 | #ifdef HAVE_CONFIG_H 27 | # include 28 | #endif 29 | 30 | #include "mio.h" 31 | 32 | 33 | #ifdef MIO_SELECT 34 | #include "mio_select.h" 35 | #include "mio_impl.h" 36 | 37 | mio_t mio_select_new(int maxfd) 38 | { 39 | return _mio_new(maxfd); 40 | } 41 | #endif 42 | -------------------------------------------------------------------------------- /tools/jabberd2.schema: -------------------------------------------------------------------------------- 1 | # attribyte types 2 | attributetype ( 1.3.6.1.4.1.8381.2.7 3 | NAME 'jabberPassword' 4 | DESC 'Password of Jabber user when using LDAPFULL authreg module' 5 | SYNTAX 1.3.6.1.4.1.1466.115.121.1.40{128} 6 | SINGLE-VALUE ) 7 | 8 | attributetype ( 1.3.6.1.4.1.8381.2.8 9 | NAME 'jabberPublishedGroup' 10 | DESC 'Name of group to add to when publishing user with roster template' 11 | EQUALITY caseExactMatch 12 | SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 ) 13 | 14 | attributetype ( 1.3.6.1.4.1.8381.2.9 15 | NAME 'jabberPublishedItem' 16 | DESC 'If set and has non-zero value, permit publishing Jabber user with template' 17 | EQUALITY integerMatch 18 | SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 19 | SINGLE-VALUE ) 20 | 21 | # objectclasses 22 | objectclass ( 1.3.6.1.4.1.8381.1.3 23 | NAME 'descriptionObject' 24 | DESC 'Object with description attribute' 25 | SUP top AUXILIARY 26 | MAY ( description ) 27 | ) 28 | objectclass ( 1.3.6.1.4.1.8381.1.5 29 | NAME 'structuralObject' 30 | DESC 'Structural object' 31 | SUP top STRUCTURAL 32 | ) 33 | objectclass ( 1.3.6.1.4.1.8381.1.6 34 | NAME 'jabberExtendedObject' 35 | DESC 'Extended Jabber entry' 36 | SUP top AUXILIARY 37 | MAY ( jabberPassword $ jabberPublishedItem $ jabberPublishedGroup ) ) 38 | 39 | -------------------------------------------------------------------------------- /tools/db-update.sqlite: -------------------------------------------------------------------------------- 1 | -- 2 | -- This updates jabberd2 sqlite databases created prior to 2.1.19. 3 | -- 4 | -- sqlite3 jabberd2.db < db-setup.sqlite 5 | -- 6 | 7 | ALTER TABLE "authreg" ADD COLUMN "token" TEXT; 8 | ALTER TABLE "authreg" ADD COLUMN "sequence" INTEGER; 9 | ALTER TABLE "authreg" ADD COLUMN "hash" TEXT; 10 | 11 | ALTER TABLE "vcard" ADD COLUMN "jabberid" TEXT; 12 | ALTER TABLE "vcard" ADD COLUMN "mailer" TEXT; 13 | ALTER TABLE "vcard" ADD COLUMN "uid" TEXT; 14 | 15 | ALTER TABLE "status" ADD COLUMN "xml" TEXT; 16 | 17 | -- 18 | -- Published roster items 19 | -- Used by: mod_roster_publish 20 | -- 21 | CREATE TABLE "published-roster" ( 22 | "collection-owner" TEXT NOT NULL, 23 | "object-sequence" INTEGER PRIMARY KEY, 24 | "jid" TEXT NOT NULL, 25 | "group" TEXT, 26 | "name" TEXT, 27 | "to" BOOLEAN NOT NULL, 28 | "from" BOOLEAN NOT NULL, 29 | "ask" INTEGER NOT NULL ); 30 | 31 | CREATE INDEX i_pubrosteri_owner ON "published-roster"("collection-owner"); 32 | 33 | -- 34 | -- Published roster groups 35 | -- Used by: mod_roster_publish 36 | -- 37 | CREATE TABLE "published-roster-groups" ( 38 | "collection-owner" TEXT NOT NULL, 39 | "object-sequence" INTEGER PRIMARY KEY, 40 | "groupname" TEXT NOT NULL ); 41 | 42 | CREATE INDEX i_pubrosterg_owner ON "published-roster-groups"("collection-owner"); 43 | 44 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | compiler: 3 | - clang 4 | - gcc 5 | env: 6 | global: 7 | # The next declaration is the encrypted COVERITY_SCAN_TOKEN, created 8 | # via the "travis encrypt" command using the project repo's public key 9 | - secure: "TbTVVcmerA7qH1XVEvHhIfal17PnDd3MSzb2PZ8G0ocydlqxgZijGkDwcYtRSUYGkFi7NZHYceM9XZRpkIK/xX9eZR8cvzGwSWmPaFaoUVdbDXHSQvCTMRQmDXEaecZXUXYplGqzduPbhgFl4vDJNLMnFvzwhGf9E7CSClkM7tY=" 10 | before_install: 11 | - sudo apt-get update -qq 12 | - sudo apt-get install -qq autoconf-archive 13 | - sudo apt-get install -qq libssl-dev libgsasl7-dev libdb-dev libpam0g-dev libmysqlclient-dev libpq-dev libldap2-dev libsqlite3-dev libidn11-dev libexpat1-dev libudns-dev check 14 | before_script: autoreconf -fi 15 | script: ./configure --enable-ssl --enable-mysql --enable-pgsql --enable-sqlite --enable-db --enable-ldap --enable-pam --enable-pipe --enable-anon --enable-fs --without-subst && make && make check 16 | addons: 17 | coverity_scan: 18 | project: 19 | name: "jabberd2/jabberd2" 20 | description: "Build submitted via Travis CI" 21 | notification_email: tomek@xiaoka.com 22 | build_command_prepend: "./configure --enable-ssl --enable-mysql --enable-pgsql --enable-sqlite --enable-db --enable-ldap --enable-pam --enable-pipe --enable-anon --enable-fs --without-subst" 23 | build_command: "make -j 4" 24 | branch_pattern: coverity_scan 25 | -------------------------------------------------------------------------------- /jabberd2.pro: -------------------------------------------------------------------------------- 1 | DEFINES += HAVE_CONFIG_H 2 | DEFINES += USE_WEBSOCKET HAVE_SSL HAVE_LIBZ HAVE_CRYPT 3 | DEFINES += STORAGE_LDAP 4 | HEADERS += config.h \ 5 | $$files(c2s/*.h) \ 6 | $$files(mio/*.h) \ 7 | $$files(router/*.h) \ 8 | $$files(s2s/*.h) \ 9 | $$files(sm/*.h) \ 10 | $$files(storage/*.h) \ 11 | $$files(subst/*.h) \ 12 | $$files(sx/*.h) \ 13 | $$files(util/*.h) 14 | SOURCES += $$files(c2s/*.c) \ 15 | $$files(mio/*.c) \ 16 | $$files(router/*.c) \ 17 | $$files(s2s/*.c) \ 18 | $$files(sm/*.c) \ 19 | $$files(storage/*.c) \ 20 | $$files(subst/*.c) \ 21 | $$files(sx/*.c) \ 22 | $$files(tests/*.c) \ 23 | $$files(util/*.c) 24 | INCLUDEPATH += $$PWD 25 | CONFIG += depend_includepath 26 | OTHER_FILES += configure.ac \ 27 | Makefile.am \ 28 | c2s/Makefile.am \ 29 | mio/Makefile.am \ 30 | router/Makefile.am \ 31 | s2s/Makefile.am \ 32 | sm/Makefile.am \ 33 | storage/Makefile.am \ 34 | sx/Makefile.am \ 35 | tests/Makefile.am \ 36 | util/Makefile.am \ 37 | $$files(etc/*) \ 38 | Doxyfile.in \ 39 | NEWS \ 40 | TODO \ 41 | README.md 42 | -------------------------------------------------------------------------------- /docs/dev/component-protocol: -------------------------------------------------------------------------------- 1 | C == component, R == router. 2 | This all happens in state_OPEN (ie after auth). 3 | These elements are scoped by the 'http://jabberd.jabberstudio.org/ns/component/1.0' namespace. 4 | 5 | Joining the network 6 | ------------------- 7 | 8 | Bind a name to this component: 9 | 10 | C: [options] 11 | R: 12 | or 13 | R: 14 | 15 | Options: 16 | 17 | Sets this component as the default route 18 | Make this component a log sink (receives copies of all packets) 19 | 20 | Unbind a name: 21 | 22 | C: 23 | R: 24 | 25 | 26 | Domain advertisement 27 | ------------------- 28 | 29 | Domain online: 30 | 31 | R: 32 | 33 | Domain offline: 34 | 35 | R: 36 | 37 | 38 | Sending packets 39 | --------------- 40 | 41 | Send a unicast packet: 42 | 43 | C: 44 | 45 | 46 | 47 | Send a broadcast packet: 48 | 49 | C: 50 | 51 | 52 | 53 | 54 | Throttling packets 55 | ------------------ 56 | 57 | (Un)throttle packets (toggle): 58 | 59 | C: 60 | R: 61 | -------------------------------------------------------------------------------- /storage/authreg_anon.c: -------------------------------------------------------------------------------- 1 | /* 2 | * jabberd - Jabber Open Source Server 3 | * Copyright (c) 2002 Jeremie Miller, Thomas Muldowney, 4 | * Ryan Eatmon, Robert Norris 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA 19 | */ 20 | 21 | /* this is a simple anonymous plugin. It uses the check_password method to 22 | * force authentication to succeed regardless of what credentials the client 23 | * provides 24 | */ 25 | 26 | #include "c2s.h" 27 | 28 | static int _ar_anon_user_exists(authreg_t ar, sess_t sess, const char *username, const char *realm) 29 | { 30 | /* always exists */ 31 | return 1; 32 | } 33 | 34 | /** start me up */ 35 | DLLEXPORT int ar_init(authreg_t ar) 36 | { 37 | ar->user_exists = _ar_anon_user_exists; 38 | 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /util/misc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * jabberd - Jabber Open Source Server 3 | * Copyright (c) 2002-2004 Jeremie Miller, Thomas Muldowney, 4 | * Ryan Eatmon, Robert Norris 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA 19 | */ 20 | 21 | #include "misc.h" 22 | 23 | #include 24 | #include 25 | 26 | #define BLOCKSIZE (1024) 27 | 28 | int misc_realloc(void **blocks, int len) { 29 | void *nblocks; 30 | int nlen; 31 | 32 | /* round up to standard block sizes */ 33 | nlen = (((len - 1) / BLOCKSIZE) + 1) * BLOCKSIZE; 34 | 35 | /* keep trying till we get it */ 36 | if((nblocks = realloc(*blocks, nlen)) == NULL) { 37 | fprintf(stderr, "fatal: out of memory\n"); 38 | abort(); 39 | } 40 | 41 | *blocks = nblocks; 42 | return nlen; 43 | } 44 | -------------------------------------------------------------------------------- /util/pqueue.h: -------------------------------------------------------------------------------- 1 | /* 2 | * jabberd - Jabber Open Source Server 3 | * Copyright (c) 2002-2004 Jeremie Miller, Thomas Muldowney, 4 | * Ryan Eatmon, Robert Norris 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA 19 | */ 20 | 21 | /** @file util/pqueue.h 22 | * @brief priority queues 23 | * @author Robert Norris 24 | * $Date: 2004/05/05 23:49:38 $ 25 | * $Revision: 1.1 $ 26 | */ 27 | 28 | #ifndef INCL_UTIL_PQUEUE_H 29 | #define INCL_UTIL_PQUEUE_H 1 30 | 31 | #include "pool.h" 32 | 33 | /* opaque decl */ 34 | typedef struct _pqueue_st *pqueue_t; 35 | 36 | JABBERD2_API pqueue_t pqueue_new(pool_t p); 37 | JABBERD2_API void pqueue_push(pqueue_t q, void *data, int pri); 38 | JABBERD2_API void *pqueue_pull(pqueue_t q); 39 | JABBERD2_API int pqueue_size(pqueue_t q); 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /win32/router/fnmatch.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 1991 Free Software Foundation, Inc. 2 | This file is part of the GNU C Library. 3 | 4 | The GNU C Library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Library General Public License as 6 | published by the Free Software Foundation; either version 2 of the 7 | License, or (at your option) any later version. 8 | 9 | The GNU C Library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | Library General Public License for more details. 13 | 14 | You should have received a copy of the GNU Library General Public 15 | License along with the GNU C Library; see the file COPYING.LIB. If 16 | not, write to the Free Software Foundation, Inc., 675 Mass Ave, 17 | Cambridge, MA 02139, USA. */ 18 | 19 | #ifndef _FNMATCH_H 20 | 21 | #define _FNMATCH_H 1 22 | 23 | /* Bits set in the FLAGS argument to `fnmatch'. */ 24 | #define FNM_PATHNAME (1 << 0)/* No wildcard can ever match `/'. */ 25 | #define FNM_NOESCAPE (1 << 1)/* Backslashes don't quote special chars. */ 26 | #define FNM_PERIOD (1 << 2)/* Leading `.' is matched only explicitly. */ 27 | #define __FNM_FLAGS (FNM_PATHNAME|FNM_NOESCAPE|FNM_PERIOD) 28 | 29 | /* Value returned by `fnmatch' if STRING does not match PATTERN. */ 30 | #define FNM_NOMATCH 1 31 | 32 | /* Match STRING against the filename pattern PATTERN, 33 | returning zero if it matches, FNM_NOMATCH if not. */ 34 | extern int fnmatch(); 35 | 36 | #endif /* fnmatch.h */ 37 | -------------------------------------------------------------------------------- /sx/sasl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * jabberd - Jabber Open Source Server 3 | * Copyright (c) 2002 Jeremie Miller, Thomas Muldowney, 4 | * Ryan Eatmon, Robert Norris 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA 19 | */ 20 | 21 | #ifndef INCL_SX_SASL_H 22 | #define INCL_SX_SASL_H 23 | 24 | /* RFC 3290 defines a number of failure messages */ 25 | #define _sasl_err_ABORTED "aborted" 26 | #define _sasl_err_INCORRECT_ENCODING "incorrect-encoding" 27 | #define _sasl_err_INVALID_AUTHZID "invalid-authzid" 28 | #define _sasl_err_INVALID_MECHANISM "invalid-mechanism" 29 | #define _sasl_err_MALFORMED_REQUEST "malformed-request" 30 | #define _sasl_err_MECH_TOO_WEAK "mechanism-too-weak" 31 | #define _sasl_err_NOT_AUTHORIZED "not-authorized" 32 | #define _sasl_err_TEMPORARY_FAILURE "temporary-auth-failure" 33 | #define _sasl_err_INTERNAL_SERVER_ERROR "internal-server-error" 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /subst/inet_ntop.c: -------------------------------------------------------------------------------- 1 | #ifdef HAVE_CONFIG_H 2 | # include "config.h" 3 | #endif 4 | 5 | #if !defined(HAVE_INET_NTOP) && defined(_WIN32) 6 | #ifdef JABBERD2_EXPORTS 7 | # define JABBERD2_API __declspec(dllexport) 8 | #else /* JABBERD2_EXPORTS */ 9 | # define JABBERD2_API __declspec(dllimport) 10 | #endif /* JABBERD2_EXPORTS */ 11 | 12 | #include "ac-stdint.h" 13 | 14 | #include "ip6_misc.h" 15 | 16 | #include 17 | #include 18 | 19 | #ifndef INET_ADDRSTRLEN 20 | #define INET_ADDRSTRLEN 16 21 | #endif 22 | 23 | static const char * 24 | inet_ntop_v4 (const void *src, char *dst, size_t size) 25 | { 26 | const char digits[] = "0123456789"; 27 | int i; 28 | struct in_addr *addr = (struct in_addr *)src; 29 | u_long a = ntohl(addr->s_addr); 30 | const char *orig_dst = dst; 31 | 32 | if (size < INET_ADDRSTRLEN) { 33 | errno = ENOSPC; 34 | return NULL; 35 | } 36 | for (i = 0; i < 4; ++i) { 37 | int n = (a >> (24 - i * 8)) & 0xFF; 38 | int non_zerop = 0; 39 | 40 | if (non_zerop || n / 100 > 0) { 41 | *dst++ = digits[n / 100]; 42 | n %= 100; 43 | non_zerop = 1; 44 | } 45 | if (non_zerop || n / 10 > 0) { 46 | *dst++ = digits[n / 10]; 47 | n %= 10; 48 | non_zerop = 1; 49 | } 50 | *dst++ = digits[n]; 51 | if (i != 3) 52 | *dst++ = '.'; 53 | } 54 | *dst++ = '\0'; 55 | return orig_dst; 56 | } 57 | 58 | JABBERD2_API const char * 59 | inet_ntop(int af, const void *src, char *dst, size_t size) 60 | { 61 | switch (af) { 62 | case AF_INET : 63 | return inet_ntop_v4 (src, dst, size); 64 | default : 65 | errno = WSAEAFNOSUPPORT; 66 | return NULL; 67 | } 68 | } 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /c2s/address.c: -------------------------------------------------------------------------------- 1 | /* 2 | * jabberd - Jabber Open Source Server 3 | * Copyright (c) 2007 Tomasz Sterna 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; version 2 of the License 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA 17 | */ 18 | 19 | /* 20 | * this sx plugin implements My IP Address extension 21 | * as described in http://delta.affinix.com/specs/xmppstream.html#myip 22 | */ 23 | 24 | #include "c2s.h" 25 | 26 | /** sx features callback */ 27 | static void _address_features(sx_t s, sx_plugin_t p, nad_t nad) { 28 | int ns; 29 | 30 | /* offer feature only when not authenticated yet */ 31 | if(s->state >= state_OPEN) 32 | return; 33 | 34 | _sx_debug(ZONE, "adding address feature"); 35 | 36 | ns = nad_add_namespace(nad, uri_ADDRESS_FEATURE, NULL); 37 | nad_append_elem(nad, ns, "address", 1); 38 | nad_append_cdata(nad, s->ip, strlen(s->ip), 2); 39 | } 40 | 41 | /** args: none */ 42 | int address_init(sx_env_t env, sx_plugin_t p, va_list args) { 43 | log_debug(ZONE, "initialising address sx plugin"); 44 | 45 | p->features = _address_features; 46 | 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /util/misc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * jabberd - Jabber Open Source Server 3 | * Copyright (c) 2002-2004 Jeremie Miller, Thomas Muldowney, 4 | * Ryan Eatmon, Robert Norris 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA 19 | */ 20 | 21 | /** @file util/misc.h 22 | * @brief Miscellaneous utilities 23 | * @author Robert Norris 24 | * $Revision: 1.1 $ 25 | * $Date: 2004/05/01 00:51:10 $ 26 | */ 27 | 28 | #ifndef INCL_UTIL_MISC_H 29 | #define INCL_UTIL_MISC_H 1 30 | 31 | /* jabberd2 Windows DLL */ 32 | #ifndef JABBERD2_API 33 | # ifdef _WIN32 34 | # ifdef JABBERD2_EXPORTS 35 | # define JABBERD2_API __declspec(dllexport) 36 | # else /* JABBERD2_EXPORTS */ 37 | # define JABBERD2_API __declspec(dllimport) 38 | # endif /* JABBERD2_EXPORTS */ 39 | # else /* _WIN32 */ 40 | # define JABBERD2_API extern 41 | # endif /* _WIN32 */ 42 | #endif /* JABBERD2_API */ 43 | 44 | JABBERD2_API int misc_realloc(void **blocks, int len); 45 | #define misc_alloc(blocks, size, len) if((size) > len) len = misc_realloc((void **) &(blocks), (size)) 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /mio/mio.c: -------------------------------------------------------------------------------- 1 | /* 2 | * jabberd - Jabber Open Source Server 3 | * Copyright (c) 2002 Jeremie Miller, Thomas Muldowney, 4 | * Ryan Eatmon, Robert Norris, Christof Meerwald 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA 19 | */ 20 | 21 | /* 22 | MIO -- Managed Input/Output 23 | --------------------------- 24 | */ 25 | 26 | #ifdef HAVE_CONFIG_H 27 | # include 28 | #endif 29 | 30 | #include "mio.h" 31 | 32 | mio_t mio_kqueue_new(int maxfd); 33 | mio_t mio_epoll_new(int maxfd); 34 | mio_t mio_poll_new(int maxfd); 35 | mio_t mio_select_new(int maxfd); 36 | mio_t mio_wsasync_new(int maxfd); 37 | 38 | mio_t mio_new(int maxfd) 39 | { 40 | mio_t m = NULL; 41 | 42 | #ifdef MIO_KQUEUE 43 | m = mio_kqueue_new(maxfd); 44 | if (m != NULL) return m; 45 | #endif 46 | 47 | #ifdef MIO_EPOLL 48 | m = mio_epoll_new(maxfd); 49 | if (m != NULL) return m; 50 | #endif 51 | 52 | #ifdef MIO_WSASYNC 53 | m = mio_wsasync_new(maxfd); 54 | if (m != NULL) return m; 55 | #endif 56 | 57 | #ifdef MIO_SELECT 58 | m = mio_select_new(maxfd); 59 | if (m != NULL) return m; 60 | #endif 61 | 62 | #ifdef MIO_POLL 63 | m = mio_poll_new(maxfd); 64 | if (m != NULL) return m; 65 | #endif 66 | 67 | return m; 68 | } 69 | -------------------------------------------------------------------------------- /etc/Makefile.am: -------------------------------------------------------------------------------- 1 | LIBTOOL += --quiet 2 | 3 | sysconf_DATA = c2s.xml.dist router.xml.dist s2s.xml.dist sm.xml.dist jabberd.cfg.dist router-users.xml.dist router-filter.xml.dist 4 | initdir = $(prefix)/etc/init 5 | init_DATA = jabberd-c2s.conf jabberd-router.conf jabberd-s2s.conf jabberd-sm.conf 6 | systemddir = $(prefix)/lib/systemd/system 7 | systemd_DATA = jabberd-sm.service jabberd.service jabberd-s2s.service jabberd-router.service jabberd-c2s.service 8 | configs = $(sysconf_DATA) $(init_DATA) $(systemd_DATA) 9 | EXTRA_DIST = $(sysconf_DATA:%.dist=%.dist.in) $(init_DATA:%.conf=%.conf.in) $(systemd_DATA:%.service=%.service.in) 10 | 11 | SUBDIRS = templates 12 | 13 | jabberd_bin = router sm s2s c2s 14 | 15 | edit = sed \ 16 | -e 's,@package\@,$(PACKAGE),g' \ 17 | -e 's,@sysconfdir\@,$(sysconfdir),g' \ 18 | -e 's,@localstatedir\@,$(localstatedir),g' \ 19 | -e 's,@bindir\@,$(bindir),g' \ 20 | -e 's,@libdir\@,$(libdir),g' \ 21 | -e 's,@pkglibdir\@,$(pkglibdir),g' 22 | 23 | $(configs): $(sysconf_DATA:%.dist=@srcdir@/%.dist.in) $(init_DATA:%.conf=@srcdir@/%.conf.in) $(systemd_DATA:%.service=%.service.in) 24 | @echo "generating $@ from $@.in"; \ 25 | edit='$(edit)'; \ 26 | list='$(jabberd_bin)'; for p in $$list; do \ 27 | bin=`echo "$$p" | sed 's,^.*/,,;$(transform);s/$$/$(EXEEXT)/'`; \ 28 | edit="$$edit -e s,@jabberd_$$p\_bin\\@,$$bin,g"; \ 29 | done; \ 30 | rm -f $@ $@.tmp; \ 31 | eval "$$edit < @srcdir@/$@.in > $@.tmp"; \ 32 | mv $@.tmp $@ 33 | 34 | install-data-hook: 35 | @list='$(sysconf_DATA)'; for p in $$list; do \ 36 | dest=`echo $$p | sed -e s/.dist//`; \ 37 | if test -f $(DESTDIR)$(sysconfdir)/$$dest; then \ 38 | echo "$@ will not overwrite existing $(DESTDIR)$(sysconfdir)/$$dest"; \ 39 | else \ 40 | echo " $(INSTALL_DATA) $$p $(DESTDIR)$(sysconfdir)/$$dest"; \ 41 | $(INSTALL_DATA) $$p $(DESTDIR)$(sysconfdir)/$$dest; \ 42 | fi; \ 43 | done 44 | 45 | clean-local: 46 | rm -f $(configs) 47 | -------------------------------------------------------------------------------- /subst/dirent.h: -------------------------------------------------------------------------------- 1 | #ifndef DIRENT_INCLUDED 2 | #define DIRENT_INCLUDED 3 | 4 | #ifdef HAVE_CONFIG_H 5 | # include "config.h" 6 | #endif 7 | 8 | /* jabberd2 Windows DLL */ 9 | #ifndef JABBERD2_API 10 | # ifdef _WIN32 11 | # ifdef JABBERD2_EXPORTS 12 | # define JABBERD2_API __declspec(dllexport) 13 | # else /* JABBERD2_EXPORTS */ 14 | # define JABBERD2_API __declspec(dllimport) 15 | # endif /* JABBERD2_EXPORTS */ 16 | # else /* _WIN32 */ 17 | # define JABBERD2_API extern 18 | # endif /* _WIN32 */ 19 | #endif /* JABBERD2_API */ 20 | 21 | #if !defined(HAVE_DIRENT_H) && !defined(HAVE_NDIR_H) && !defined(HAVE_SYS_DIR_H) && !defined(HAVE_SYS_NDIR_H) 22 | #ifdef HAVE__FINDFIRST 23 | 24 | /* 25 | 26 | Declaration of POSIX directory browsing functions and types for Win32. 27 | 28 | Author: Kevlin Henney (kevlin@acm.org, kevlin@curbralan.com) 29 | History: Created March 1997. Updated June 2003. 30 | Rights: See end of file. 31 | 32 | */ 33 | 34 | #ifdef __cplusplus 35 | extern "C" 36 | { 37 | #endif 38 | 39 | #include 40 | 41 | typedef struct DIR DIR; 42 | 43 | struct dirent 44 | { 45 | char *d_name; 46 | }; 47 | 48 | JABBERD2_API DIR *opendir(const char *); 49 | JABBERD2_API int closedir(DIR *); 50 | JABBERD2_API struct dirent *readdir(DIR *); 51 | JABBERD2_API void rewinddir(DIR *); 52 | 53 | /* 54 | 55 | Copyright Kevlin Henney, 1997, 2003. All rights reserved. 56 | 57 | Permission to use, copy, modify, and distribute this software and its 58 | documentation for any purpose is hereby granted without fee, provided 59 | that this copyright and permissions notice appear in all copies and 60 | derivatives. 61 | 62 | This software is supplied "as is" without express or implied warranty. 63 | 64 | But that said, if there are any problems please get in touch. 65 | 66 | */ 67 | 68 | #ifdef __cplusplus 69 | } 70 | #endif 71 | 72 | #endif 73 | #endif 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /win32/setup/server.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIICkTCCAfoCAQEwDQYJKoZIhvcNAQEEBQAwgZAxCzAJBgNVBAYTAlBMMRIwEAYD 3 | VQQIEwlMb2NhbGhvc3QxEjAQBgNVBAcTCUxvY2FsaG9zdDESMBAGA1UEChMJTG9j 4 | YWxob3N0MRIwEAYDVQQLEwlsb2NhbGhvc3QxEjAQBgNVBAMTCWxvY2FsaG9zdDEd 5 | MBsGCSqGSIb3DQEJARYOcm9vdEBsb2NhbGhvc3QwHhcNMDcwNTIwMTk0ODQxWhcN 6 | MDkwNTE5MTk0ODQxWjCBkDELMAkGA1UEBhMCUEwxEjAQBgNVBAgTCUxvY2FsaG9z 7 | dDESMBAGA1UEBxMJTG9jYWxob3N0MRIwEAYDVQQKEwlMb2NhbGhvc3QxEjAQBgNV 8 | BAsTCWxvY2FsaG9zdDESMBAGA1UEAxMJbG9jYWxob3N0MR0wGwYJKoZIhvcNAQkB 9 | Fg5yb290QGxvY2FsaG9zdDCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA09CK 10 | 77keFhMiohXpGDbsrCKRYyIK4f0VXyQla1xLRPW6PCseLGhpVx9GZ13v+cOQex4d 11 | tkOHCuziiwRP1biPr+nzBFbcMY440VptVouvMnzmYIDds7PgfMtxAHMTYsdTGZAh 12 | szC8q7Tt43I/LWTC53YeazGWo7wMb7NEaap0jNUCAwEAATANBgkqhkiG9w0BAQQF 13 | AAOBgQCA5EwLji0OTYu4HzsOqHzBWU3oVmp77mOziivU+ZlmnIODBfvtFxod++Gh 14 | ZxVxQorl1g+s7z5EyfPDjBCfUbJihw5aEwEE8a7ca+hWm53FQcZLUtF3SyukwOfi 15 | f9d39bB2ZKensQjwpnJj3ykbIyYxw3S/u8VoKI6UHQ7XaqIxbw== 16 | -----END CERTIFICATE----- 17 | -----BEGIN RSA PRIVATE KEY----- 18 | MIICXgIBAAKBgQDT0IrvuR4WEyKiFekYNuysIpFjIgrh/RVfJCVrXEtE9bo8Kx4s 19 | aGlXH0ZnXe/5w5B7Hh22Q4cK7OKLBE/VuI+v6fMEVtwxjjjRWm1Wi68yfOZggN2z 20 | s+B8y3EAcxNix1MZkCGzMLyrtO3jcj8tZMLndh5rMZajvAxvs0RpqnSM1QIDAQAB 21 | AoGBAK0GOqhOgKwpn23mFg3ot/Z5GmhvY5JtaarZXRPRRc8kJ6iE1FYUSJCZhKpl 22 | iuVtAjYASOcdTE/5Z6mFsS11YTEmorCwoND1AKRYRppHkaysBurZnrZjrxfkQYg6 23 | kpQHWcVio5vpXCAU80LNPgdzLTzrxciVfMDw9E9p5+W7HBghAkEA6+1HiejEBOkD 24 | XGdfsZw8f/RoztTjNPA4WwLjEcqqi38XE8YTf7G+YvBAIb64i92KUpSdS4W+TKrE 25 | P0Cogw83zQJBAOXWExa6i03/rVsn/CY+1q/i8/LZw91q2Vxc+Vt5loa7q8cvdcwe 26 | I3/Bwowr3tyEcYTxTqVRNMmiXgmk6WOQESkCQQCgBd1UKVFrkzD4aBV8PuC6WWkN 27 | gVBrA9T1xkuGMdTjsVxRyTRIlKLyMMsPGHHMTIQZ5zuZkim1js51qMGjw5qxAkEA 28 | qNtnuNoiwJJotcEhsqOWLTDrk29ERGdc/Evec8NXwPMemD+ZJva5lAIxwbP1j0PK 29 | 9yYmZrTLuJwOxL0hLyHISQJAdNbJG/CsGotPfuzDDVOLREvphsQKNdwII2t/wZAX 30 | zpDX5mGyPowqw1KF0vYNouDbyQV65xK92gbyFbWNwPrK8A== 31 | -----END RSA PRIVATE KEY----- 32 | -------------------------------------------------------------------------------- /sm/mod_validate.c: -------------------------------------------------------------------------------- 1 | /* 2 | * jabberd - Jabber Open Source Server 3 | * Copyright (c) 2002 Jeremie Miller, Thomas Muldowney, 4 | * Ryan Eatmon, Robert Norris 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA 19 | */ 20 | 21 | #include "sm.h" 22 | 23 | /** @file sm/mod_validate.c 24 | * @brief packet validator 25 | * @author Robert Norris 26 | * $Date: 2005/08/17 07:48:28 $ 27 | * $Revision: 1.15 $ 28 | */ 29 | 30 | static mod_ret_t _validate_in_sess(mod_instance_t mi, sess_t sess, pkt_t pkt) 31 | { 32 | /* only want message, presence and iq */ 33 | if(!(pkt->type & pkt_MESSAGE || pkt->type & pkt_PRESENCE || pkt->type & pkt_IQ || pkt->type & pkt_S10N)) { 34 | log_debug(ZONE, "we only take message, presence and iq packets"); 35 | return -stanza_err_BAD_REQUEST; 36 | } 37 | 38 | return mod_PASS; 39 | } 40 | 41 | static mod_ret_t _validate_in_router(mod_instance_t mi, pkt_t pkt) 42 | { 43 | return _validate_in_sess(mi, NULL, pkt); 44 | } 45 | 46 | DLLEXPORT int module_init(mod_instance_t mi, const char *arg) { 47 | module_t mod = mi->mod; 48 | 49 | if(mod->init) return 0; 50 | 51 | mod->in_sess = _validate_in_sess; 52 | mod->in_router = _validate_in_router; 53 | 54 | return 0; 55 | } 56 | -------------------------------------------------------------------------------- /win32/setup/ca/ca.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #undef RtlZeroMemory 4 | NTSYSAPI VOID NTAPI RtlZeroMemory(VOID UNALIGNED *Destination, SIZE_T Length); 5 | 6 | #include 7 | #include 8 | 9 | #pragma comment(linker, "/EXPORT:CheckPaths=_CheckPaths@4") 10 | 11 | BOOL __stdcall _DllMainCRTStartup(HINSTANCE hInstance, DWORD dwReason, LPVOID lpData) 12 | { 13 | return TRUE; 14 | } 15 | 16 | struct 17 | { 18 | LPCTSTR file; 19 | LPCTSTR var; 20 | } filesTest[] = { 21 | {"c2s.xml", "C2S.XML.EXISTS"}, 22 | {"resolver.xml", "RESOLVER.XML.EXISTS"}, 23 | {"router.xml", "ROUTER.XML.EXISTS"}, 24 | {"router-filter.xml", "ROUTER_FILTER.XML.EXISTS"}, 25 | {"router-users.xml", "ROUTER_USERS.XML.EXISTS"}, 26 | {"s2s.xml", "S2S.XML.EXISTS"}, 27 | {"sm.xml", "SM.XML.EXISTS"}, 28 | {"server.pem", "SERVER.PEM.EXISTS"}, 29 | {"sqlite.db", "SQLITE.DB.EXISTS"}, 30 | {NULL, NULL} 31 | }; 32 | 33 | UINT __stdcall CheckPaths(MSIHANDLE hInstall) 34 | { 35 | TCHAR installDir[MAX_PATH], filePath[MAX_PATH]; 36 | DWORD installDirLen = MAX_PATH; 37 | int i; 38 | 39 | MsiGetProperty(hInstall, "INSTALLDIR", installDir, &installDirLen); 40 | installDir[installDirLen] = 0; 41 | for(i = 0; filesTest[i].file; i++) 42 | { 43 | WIN32_FIND_DATA fd; 44 | HANDLE hff; 45 | BOOL bFound = FALSE; 46 | 47 | if(installDirLen > 0 && installDirLen + lstrlen(filesTest[i].file) + 2 < MAX_PATH) 48 | { 49 | wsprintf(filePath, "%s%s%s", 50 | installDir, 51 | installDir[installDirLen - 1] == '\\' ? "" : "\\", 52 | filesTest[i].file); 53 | 54 | ZeroMemory(&fd, sizeof(fd)); 55 | if(INVALID_HANDLE_VALUE != (hff = FindFirstFile(filePath, &fd))) 56 | { 57 | FindClose(hff); 58 | if(!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) 59 | bFound = TRUE; 60 | } 61 | } 62 | MsiSetProperty(hInstall, filesTest[i].var, bFound ? filePath : ""); 63 | } 64 | 65 | return ERROR_SUCCESS; 66 | } 67 | -------------------------------------------------------------------------------- /win32/setup/setup.wixproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 3.0 4 | {8504d60e-b1c4-4fe8-a5c2-3f36b1a5e2bd} 5 | 2.0 6 | jabberd-svn-win32 7 | Package 8 | $(ProgramFiles)\Windows Installer XML v3\bin\ 9 | en-US 10 | 11 | 12 | ..\bin\debug\ 13 | obj\Debug\ 14 | Debug 15 | en-US 16 | 17 | 18 | ..\bin\ 19 | obj\Release\ 20 | 21 | en-US 22 | 23 | 24 | True 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | C:\Program Files\Windows Installer XML v3\bin\WixUIExtension.dll 37 | 38 | 39 | C:\Program Files\Windows Installer XML v3\bin\WixUtilExtension.dll 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /util/datetime.h: -------------------------------------------------------------------------------- 1 | /* 2 | * jabberd - Jabber Open Source Server 3 | * Copyright (c) 2002-2004 Jeremie Miller, Thomas Muldowney, 4 | * Ryan Eatmon, Robert Norris 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA 19 | */ 20 | 21 | /** @file util/datetime.h 22 | * @brief ISO 8610 / JEP 82 date/time manipulation 23 | * @author Robert Norris 24 | * $Date: 2004/05/05 23:49:38 $ 25 | * $Revision: 1.1 $ 26 | */ 27 | 28 | #ifndef INCL_UTIL_DATETIME_H 29 | #define INCL_UTIL_DATETIME_H 1 30 | 31 | #ifdef HAVE_CONFIG_H 32 | # include 33 | #endif 34 | 35 | #include 36 | 37 | /* jabberd2 Windows DLL */ 38 | #ifndef JABBERD2_API 39 | # ifdef _WIN32 40 | # ifdef JABBERD2_EXPORTS 41 | # define JABBERD2_API __declspec(dllexport) 42 | # else /* JABBERD2_EXPORTS */ 43 | # define JABBERD2_API __declspec(dllimport) 44 | # endif /* JABBERD2_EXPORTS */ 45 | # else /* _WIN32 */ 46 | # define JABBERD2_API extern 47 | # endif /* _WIN32 */ 48 | #endif /* JABBERD2_API */ 49 | 50 | typedef enum { 51 | dt_DATE = 1, 52 | dt_TIME = 2, 53 | dt_DATETIME = 3, 54 | dt_LEGACY = 4 55 | } datetime_t; 56 | 57 | JABBERD2_API time_t datetime_in(char *date); 58 | JABBERD2_API void datetime_out(time_t t, datetime_t type, const char *date, int datelen); 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /util/base64.h: -------------------------------------------------------------------------------- 1 | /* 2 | * jabberd - Jabber Open Source Server 3 | * Copyright (c) 2002-2004 Jeremie Miller, Thomas Muldowney, 4 | * Ryan Eatmon, Robert Norris 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA 19 | */ 20 | 21 | /** @file util/base64.h 22 | * @brief Base64 encoding 23 | * @author Apache Software Foundation 24 | * $Date: 2004/05/17 05:03:13 $ 25 | * $Revision: 1.1 $ 26 | */ 27 | 28 | #ifndef INCL_UTIL_BASE64_H 29 | #define INCL_UTIL_BASE64_H 1 30 | 31 | /* jabberd2 Windows DLL */ 32 | #ifndef JABBERD2_API 33 | # ifdef _WIN32 34 | # ifdef JABBERD2_EXPORTS 35 | # define JABBERD2_API __declspec(dllexport) 36 | # else /* JABBERD2_EXPORTS */ 37 | # define JABBERD2_API __declspec(dllimport) 38 | # endif /* JABBERD2_EXPORTS */ 39 | # else /* _WIN32 */ 40 | # define JABBERD2_API extern 41 | # endif /* _WIN32 */ 42 | #endif /* JABBERD2_API */ 43 | 44 | /* base64 functions */ 45 | JABBERD2_API int apr_base64_decode_len(const char *bufcoded); 46 | JABBERD2_API int apr_base64_decode(char *bufplain, const char *bufcoded); 47 | JABBERD2_API int apr_base64_encode_len(int len); 48 | JABBERD2_API int apr_base64_encode(char *encoded, const unsigned char *string, int len); 49 | 50 | /* convenience, result string must be free()'d by caller */ 51 | JABBERD2_API char *b64_encode(char *buf, int len); 52 | JABBERD2_API char *b64_decode(char *buf); 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /sm/feature.c: -------------------------------------------------------------------------------- 1 | /* 2 | * jabberd - Jabber Open Source Server 3 | * Copyright (c) 2002 Jeremie Miller, Thomas Muldowney, 4 | * Ryan Eatmon, Robert Norris 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA 19 | */ 20 | 21 | #include "sm.h" 22 | 23 | /** @file sm/feature.c 24 | * @brief feature registration 25 | * @author Robert Norris 26 | * $Date: 2005/08/17 11:10:12 $ 27 | * $Revision: 1.9 $ 28 | */ 29 | 30 | /* 31 | * these are simple wrappers around xhash for the moment. perhaps a little 32 | * redundant, but they will give a good abstraction, and make it easier to 33 | * add stuff in the future .. f-neg comes to mind. 34 | */ 35 | 36 | /** register a feature */ 37 | void feature_register(sm_t sm, const char *feature) 38 | { 39 | log_debug(ZONE, "registering feature %s", feature); 40 | 41 | xhash_put(sm->features, pstrdup(xhash_pool(sm->features), feature), (void *) ((long) xhash_get(sm->features, feature) + 1)); 42 | } 43 | 44 | /** unregister feature */ 45 | void feature_unregister(sm_t sm, const char *feature) 46 | { 47 | int refcount = (int) (long) xhash_get(sm->features, feature); 48 | 49 | log_debug(ZONE, "unregistering feature %s", feature); 50 | 51 | if (refcount == 1) { 52 | xhash_zap(sm->features, feature); 53 | } else if (refcount > 1) { 54 | xhash_put(sm->features, feature, (void *) ((long) refcount - 1)); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /win32/setup/libraries.wxs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /etc/router-filter.xml.dist.in: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 49 | 50 | 51 | 54 | -------------------------------------------------------------------------------- /subst/gettimeofday.c: -------------------------------------------------------------------------------- 1 | /* 2 | * $PostgreSQL: /cvsroot/pgsql-server/src/port/gettimeofday.c,v 1.3 2003/11/29 19:52:13 pgsql Exp $ 3 | * 4 | * Copyright (c) 2003 SRA, Inc. 5 | * Copyright (c) 2003 SKC, Inc. 6 | * 7 | * Permission to use, copy, modify, and distribute this software and 8 | * its documentation for any purpose, without fee, and without a 9 | * written agreement is hereby granted, provided that the above 10 | * copyright notice and this paragraph and the following two 11 | * paragraphs appear in all copies. 12 | * 13 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT, 14 | * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING 15 | * LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS 16 | * DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED 17 | * OF THE POSSIBILITY OF SUCH DAMAGE. 18 | * 19 | * THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS 22 | * IS" BASIS, AND THE AUTHOR HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, 23 | * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 24 | */ 25 | 26 | #ifdef HAVE_CONFIG_H 27 | # include "config.h" 28 | #endif 29 | 30 | #ifndef HAVE_GETTIMEOFDAY 31 | 32 | #include "ac-stdint.h" 33 | 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | #include "subst.h" 41 | 42 | /* FILETIME of Jan 1 1970 00:00:00. */ 43 | static const unsigned __int64 epoch = 116444736000000000L; 44 | 45 | /* 46 | * timezone information is stored outside the kernel so tzp isn't used anymore. 47 | */ 48 | 49 | int 50 | gettimeofday(struct timeval * tp, struct timezone * tzp) 51 | { 52 | FILETIME file_time; 53 | SYSTEMTIME system_time; 54 | ULARGE_INTEGER ularge; 55 | 56 | GetSystemTime(&system_time); 57 | SystemTimeToFileTime(&system_time, &file_time); 58 | ularge.LowPart = file_time.dwLowDateTime; 59 | ularge.HighPart = file_time.dwHighDateTime; 60 | 61 | tp->tv_sec = (long) ((ularge.QuadPart - epoch) / 10000000L); 62 | tp->tv_usec = (long) (system_time.wMilliseconds * 1000); 63 | 64 | return 0; 65 | } 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /s2s/db.c: -------------------------------------------------------------------------------- 1 | /* 2 | * jabberd - Jabber Open Source Server 3 | * Copyright (c) 2002 Jeremie Miller, Thomas Muldowney, 4 | * Ryan Eatmon, Robert Norris 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA 19 | */ 20 | 21 | /* 22 | * this is a minimal sx plugin that hacks the "jabber:server:dialback" 23 | * onto outgoing connections and adds "urn:xmpp:features:dialback" feature 24 | */ 25 | 26 | #include "s2s.h" 27 | 28 | #define S2S_DB_NS_DECL " xmlns:db='" uri_DIALBACK "'" 29 | #define S2S_DB_NS_DECL_LEN (uri_DIALBACK_L + 12) 30 | 31 | static void _s2s_db_header(sx_t s, sx_plugin_t p, sx_buf_t buf) { 32 | 33 | if(!(s->flags & S2S_DB_HEADER)) 34 | return; 35 | 36 | log_debug(ZONE, "hacking dialback namespace decl onto stream header"); 37 | 38 | /* get enough space */ 39 | _sx_buffer_alloc_margin(buf, 0, S2S_DB_NS_DECL_LEN + 2); 40 | 41 | /* overwrite the trailing ">" with a decl followed by a new ">" */ 42 | memcpy(&buf->data[buf->len - 1], S2S_DB_NS_DECL ">", S2S_DB_NS_DECL_LEN+1); 43 | buf->len += S2S_DB_NS_DECL_LEN; 44 | } 45 | 46 | /** sx features callback */ 47 | static void _s2s_db_features(sx_t s, sx_plugin_t p, nad_t nad) { 48 | int ns; 49 | 50 | ns = nad_add_namespace(nad, uri_URN_DIALBACK, NULL); 51 | nad_append_elem(nad, ns, "dialback", 1); 52 | nad_append_elem(nad, -1, "required", 2); 53 | } 54 | 55 | int s2s_db_init(sx_env_t env, sx_plugin_t p, va_list args) { 56 | log_debug(ZONE, "initialising dialback sx plugin"); 57 | 58 | p->header = _s2s_db_header; 59 | p->features = _s2s_db_features; 60 | 61 | return 0; 62 | } 63 | -------------------------------------------------------------------------------- /util/hex.c: -------------------------------------------------------------------------------- 1 | /* 2 | * jabberd - Jabber Open Source Server 3 | * Copyright (c) 2002-2003 Jeremie Miller, Thomas Muldowney, 4 | * Ryan Eatmon, Robert Norris 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA 19 | */ 20 | 21 | /* simple hex conversion functions */ 22 | 23 | #include "util.h" 24 | 25 | /** turn raw into hex - out must be (inlen*2)+1 */ 26 | void hex_from_raw(const unsigned char *in, int inlen, char *out) { 27 | int i, h, l; 28 | 29 | for(i = 0; i < inlen; i++) { 30 | h = in[i] & 0xf0; 31 | h >>= 4; 32 | l = in[i] & 0x0f; 33 | out[i * 2] = (h >= 0x0 && h <= 0x9) ? (h + 0x30) : (h + 0x57); 34 | out[i * 2 + 1] = (l >= 0x0 && l <= 0x9) ? (l + 0x30) : (l + 0x57); 35 | } 36 | out[i * 2] = '\0'; 37 | } 38 | 39 | /** turn hex into raw - out must be (inlen/2) */ 40 | int hex_to_raw(const char *in, int inlen, char *out) { 41 | int i, o, h, l; 42 | 43 | /* need +ve even input */ 44 | if(inlen == 0 || (inlen / 2 * 2) != inlen) 45 | return 1; 46 | 47 | for(i = o = 0; i < inlen; i += 2, o++) { 48 | h = (in[i] >= 0x30 && in[i] <= 0x39) ? (in[i] - 0x30) : (in[i] >= 0x41 && in[i] <= 0x64) ? (in[i] - 0x36) : (in[i] >= 0x61 && in[i] <= 0x66) ? (in[i] - 0x56) : -1; 49 | l = (in[i + 1] >= 0x30 && in[i + 1] <= 0x39) ? (in[i + 1] - 0x30) : (in[i + 1] >= 0x41 && in[i + 1] <= 0x64) ? (in[i + 1] - 0x36) : (in[i + 1] >= 0x61 && in[i + 1] <= 0x66) ? (in[i + 1] - 0x56) : -1; 50 | 51 | if(h < 0 || l < 0) 52 | return 1; 53 | 54 | out[o] = (h << 4) + l; 55 | } 56 | 57 | return 0; 58 | } 59 | -------------------------------------------------------------------------------- /sx/env.c: -------------------------------------------------------------------------------- 1 | /* 2 | * jabberd - Jabber Open Source Server 3 | * Copyright (c) 2002 Jeremie Miller, Thomas Muldowney, 4 | * Ryan Eatmon, Robert Norris 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA 19 | */ 20 | 21 | #include "sx.h" 22 | 23 | sx_env_t sx_env_new(void) { 24 | sx_env_t env; 25 | 26 | env = (sx_env_t) calloc(1, sizeof(struct _sx_env_st)); 27 | 28 | return env; 29 | } 30 | 31 | void sx_env_free(sx_env_t env) { 32 | int i; 33 | 34 | assert((int) (env != NULL)); 35 | 36 | /* !!! usage counts */ 37 | 38 | for(i = 0; i < env->nplugins; i++) { 39 | if(env->plugins[i]->unload != NULL) 40 | (env->plugins[i]->unload)(env->plugins[i]); 41 | free(env->plugins[i]); 42 | } 43 | 44 | free(env->plugins); 45 | free(env); 46 | } 47 | 48 | sx_plugin_t sx_env_plugin(sx_env_t env, sx_plugin_init_t init, ...) { 49 | sx_plugin_t p; 50 | int ret; 51 | va_list args; 52 | 53 | assert((int) (env != NULL)); 54 | assert((int) (init != NULL)); 55 | 56 | va_start(args, init); 57 | 58 | p = (sx_plugin_t) calloc(1, sizeof(struct _sx_plugin_st)); 59 | 60 | p->env = env; 61 | p->index = env->nplugins; 62 | 63 | ret = (init)(env, p, args); 64 | va_end(args); 65 | 66 | if(ret != 0) { 67 | free(p); 68 | return NULL; 69 | } 70 | 71 | env->plugins = (sx_plugin_t *) realloc(env->plugins, sizeof(sx_plugin_t) * (env->nplugins + 1)); 72 | env->plugins[env->nplugins] = p; 73 | env->nplugins++; 74 | 75 | _sx_debug(ZONE, "plugin initialised (index %d)", p->index); 76 | 77 | return p; 78 | } 79 | -------------------------------------------------------------------------------- /util/sha1.h: -------------------------------------------------------------------------------- 1 | /* 2 | * jabberd - Jabber Open Source Server 3 | * Copyright (c) 2002-2003 Jeremie Miller, Thomas Muldowney, 4 | * Ryan Eatmon, Robert Norris 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA 19 | */ 20 | 21 | /* sha1 functions */ 22 | 23 | #ifndef INCL_SHA1_H 24 | #define INCL_SHA1_H 25 | 26 | /* jabberd2 Windows DLL */ 27 | #ifndef JABBERD2_API 28 | # ifdef _WIN32 29 | # ifdef JABBERD2_EXPORTS 30 | # define JABBERD2_API __declspec(dllexport) 31 | # else /* JABBERD2_EXPORTS */ 32 | # define JABBERD2_API __declspec(dllimport) 33 | # endif /* JABBERD2_EXPORTS */ 34 | # else /* _WIN32 */ 35 | # define JABBERD2_API extern 36 | # endif /* _WIN32 */ 37 | #endif /* JABBERD2_API */ 38 | 39 | /* use OpenSSL functions when available */ 40 | #ifdef HAVE_SSL 41 | #include 42 | 43 | #define sha1_state_t SHA_CTX 44 | #define sha1_init(c) SHA1_Init(c) 45 | #define sha1_append(c, data, len) SHA1_Update(c, data, len); 46 | #define sha1_finish(c, md) SHA1_Final(md, c) 47 | #define sha1_hash(data, len, md) SHA1(data, len, md); 48 | 49 | #else 50 | 51 | #include 52 | 53 | typedef struct sha1_state_s { 54 | uint32_t H[5]; 55 | uint32_t W[80]; 56 | int lenW; 57 | uint32_t sizeHi,sizeLo; 58 | } sha1_state_t; 59 | 60 | JABBERD2_API void sha1_init(sha1_state_t *ctx); 61 | JABBERD2_API void sha1_append(sha1_state_t *ctx, const unsigned char *dataIn, int len); 62 | JABBERD2_API void sha1_finish(sha1_state_t *ctx, unsigned char hashout[20]); 63 | JABBERD2_API void sha1_hash(const unsigned char *dataIn, int len, unsigned char hashout[20]); 64 | 65 | #endif 66 | 67 | #endif /* HAVE_SSL */ 68 | -------------------------------------------------------------------------------- /docs/dev/sm-c2s-protocol: -------------------------------------------------------------------------------- 1 | If any action fails, the component returns it with sm:failed='1' on the 2 | session element. We don't use the route type at all anymore, that is 3 | reserved for _routing_ errors. This has the nice side effect of allowing 4 | us to distinguish between "session ended" and "sm crashed". 5 | 6 | No bounce must result from a failed action. 7 | 8 | The namespace URL is "http://jabberd.jabberstudio.org/ns/session/1.0" 9 | 10 | 11 | c2s->sm: start session 12 | 13 | 14 | 15 | 16 | 17 | sm->c2s: session started 18 | 19 | 20 | 21 | 22 | 23 | 24 | c2s->sm: end session 25 | 26 | 27 | 28 | 29 | 30 | sm->c2s: session ended 31 | 32 | 33 | 34 | 35 | 36 | 37 | c2s->sm: send packet 38 | 39 | 40 | 41 | ... 42 | 43 | 44 | 45 | sm->c2s: send packet 46 | 47 | 48 | 49 | ... 50 | 51 | 52 | 53 | 54 | c2s->sm: create user 55 | 56 | 57 | 58 | 59 | 60 | sm->c2s: user created 61 | 62 | 63 | 64 | 65 | 66 | 67 | c2s->sm: delete user 68 | 69 | 70 | 71 | 72 | 73 | sm->c2s: user deleteed 74 | 75 | 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /util/log.h: -------------------------------------------------------------------------------- 1 | /* 2 | * jabberd - Jabber Open Source Server 3 | * Copyright (c) 2002-2004 Jeremie Miller, Thomas Muldowney, 4 | * Ryan Eatmon, Robert Norris 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA 19 | */ 20 | 21 | /** @file util/log.h 22 | * @brief logging functions 23 | * @author Robert Norris 24 | * $Revision: 1.1 $ 25 | * $Date: 2004/04/30 00:53:54 $ 26 | */ 27 | 28 | #ifndef INCL_UTIL_LOG_H 29 | #define INCL_UTIL_LOG_H 1 30 | 31 | #ifdef HAVE_CONFIG_H 32 | # include 33 | #endif 34 | 35 | #ifdef HAVE_SYSLOG_H 36 | # include 37 | #endif 38 | 39 | #include "pool.h" 40 | 41 | typedef enum { 42 | log_STDOUT, 43 | log_SYSLOG, 44 | log_FILE 45 | } log_type_t; 46 | 47 | /* opaque decl */ 48 | typedef struct _log_st *log_t; 49 | 50 | JABBERD2_API log_t log_new(pool_t p, log_type_t type, const char *ident, const char *facility); 51 | JABBERD2_API void log_write(log_t log, int level, const char *msgfmt, ...); 52 | 53 | /* debug logging */ 54 | #if defined(DEBUG) && 0 55 | JABBERD2_API int log_debug_flag; 56 | void log_debug(char *file, int line, const char *subsys, const char *msgfmt, ...); 57 | 58 | # define log_debug_get_flag() log_debug_flag 59 | # define log_debug_set_flag(f) (log_debug_flag = f ? 1 : 0) 60 | # define log_debug(...) if(log_debug_flag) __log_debug(__FILE__,__LINE__,0,__VA_ARGS__) 61 | # define log_debug_subsys(...) if(log_debug_flag) __log_debug(__FILE__,__LINE__,__VA_ARGS__) 62 | #else 63 | # define log_debug_get_flag() (0) 64 | # define log_debug_set_flag(f) 65 | # define log_debug(...) 66 | # define log_debug_subsys(...) 67 | #endif 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /util/crypt_blowfish.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Written by Solar Designer in 2000-2011. 3 | * No copyright is claimed, and the software is hereby placed in the public 4 | * domain. In case this attempt to disclaim copyright and place the software 5 | * in the public domain is deemed null and void, then the software is 6 | * Copyright (c) 2000-2011 Solar Designer and it is hereby released to the 7 | * general public under the following terms: 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted. 11 | * 12 | * There's ABSOLUTELY NO WARRANTY, express or implied. 13 | * 14 | * See crypt_blowfish.c for more information. 15 | */ 16 | 17 | #ifndef _CRYPT_BLOWFISH_H 18 | #define _CRYPT_BLOWFISH_H 19 | 20 | #ifndef __GNUC__ 21 | #undef __const 22 | #define __const const 23 | #endif 24 | 25 | extern char *bcrypt(__const char *key, __const char *setting); 26 | extern char *crypt_r(__const char *key, __const char *setting, void *data); 27 | 28 | #ifndef __SKIP_OW 29 | extern char *crypt_rn(__const char *key, __const char *setting, 30 | void *data, int size); 31 | extern char *crypt_ra(__const char *key, __const char *setting, 32 | void **data, int *size); 33 | extern char *bcrypt_gensalt(__const char *prefix, unsigned long count, 34 | __const char *input, int size); 35 | extern char *crypt_gensalt_rn(__const char *prefix, unsigned long count, 36 | __const char *input, int size, char *output, int output_size); 37 | extern char *crypt_gensalt_ra(__const char *prefix, unsigned long count, 38 | __const char *input, int size); 39 | #endif 40 | 41 | extern int _crypt_output_magic(const char *setting, char *output, int size); 42 | extern char *_crypt_blowfish_rn(const char *key, const char *setting, 43 | char *output, int size); 44 | extern char *_crypt_gensalt_blowfish_rn(const char *prefix, 45 | unsigned long count, 46 | const char *input, int size, char *output, int output_size); 47 | extern unsigned char _crypt_itoa64[]; 48 | extern char *_crypt_gensalt_traditional_rn(const char *prefix, 49 | unsigned long count, 50 | const char *input, int size, char *output, int output_size); 51 | extern char *_crypt_gensalt_extended_rn(const char *prefix, 52 | unsigned long count, 53 | const char *input, int size, char *output, int output_size); 54 | extern char *_crypt_gensalt_md5_rn(const char *prefix, unsigned long count, 55 | const char *input, int size, char *output, int output_size); 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /util/inaddr.h: -------------------------------------------------------------------------------- 1 | /* 2 | * jabberd - Jabber Open Source Server 3 | * Copyright (c) 2002 Jeremie Miller, Thomas Muldowney, 4 | * Ryan Eatmon, Robert Norris 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA 19 | */ 20 | 21 | #ifndef INCL_INADDR_H 22 | #define INCL_INADDR_H 23 | 24 | #ifdef HAVE_CONFIG_H 25 | # include 26 | #endif 27 | 28 | #include "ac-stdint.h" 29 | 30 | #ifdef HAVE_STRING_H 31 | #include 32 | #endif 33 | 34 | #ifdef HAVE_NETINET_IN_H 35 | #include 36 | #endif 37 | 38 | #ifdef HAVE_ARPA_INET_H 39 | #include 40 | #endif 41 | 42 | #ifdef HAVE_SYS_SOCKET_H 43 | #include 44 | #endif 45 | 46 | #ifdef USE_LIBSUBST 47 | #include "subst/subst.h" 48 | #endif 49 | 50 | /* jabberd2 Windows DLL */ 51 | #ifndef JABBERD2_API 52 | # ifdef _WIN32 53 | # ifdef JABBERD2_EXPORTS 54 | # define JABBERD2_API __declspec(dllexport) 55 | # else /* JABBERD2_EXPORTS */ 56 | # define JABBERD2_API __declspec(dllimport) 57 | # endif /* JABBERD2_EXPORTS */ 58 | # else /* _WIN32 */ 59 | # define JABBERD2_API extern 60 | # endif /* _WIN32 */ 61 | #endif /* JABBERD2_API */ 62 | 63 | #ifdef __cplusplus 64 | extern "C" { 65 | #endif 66 | 67 | /* 68 | * helpers for ip addresses 69 | */ 70 | 71 | #include 72 | 73 | JABBERD2_API int j_inet_pton(const char *src, struct sockaddr_storage *dst); 74 | JABBERD2_API const char *j_inet_ntop(struct sockaddr_storage* src, char* dst, size_t size); 75 | JABBERD2_API int j_inet_getport(struct sockaddr_storage *sa); 76 | JABBERD2_API int j_inet_setport(struct sockaddr_storage *sa, in_port_t port); 77 | JABBERD2_API socklen_t j_inet_addrlen(struct sockaddr_storage *sa); 78 | 79 | #ifdef __cplusplus 80 | } 81 | #endif 82 | 83 | #endif /* INCL_UTIL_H */ 84 | 85 | 86 | -------------------------------------------------------------------------------- /mio/mio_wsasync.c: -------------------------------------------------------------------------------- 1 | /* 2 | * jabberd - Jabber Open Source Server 3 | * Copyright (c) 2007 Adam Strzelecki 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA 18 | */ 19 | 20 | /* 21 | MIO -- Managed Input/Output 22 | --------------------------- 23 | */ 24 | 25 | #ifdef HAVE_CONFIG_H 26 | # include 27 | #endif 28 | 29 | #include "mio.h" 30 | 31 | 32 | #ifdef MIO_WSASYNC 33 | #include "mio_wsasync.h" 34 | #include "mio_impl.h" 35 | 36 | mio_t mio_wsasync_new(int maxfd) 37 | { 38 | return _mio_new(maxfd); 39 | } 40 | 41 | LONG CALLBACK _mio_wnd_proc(HWND hwnd, UINT msg, WPARAM wParam, LONG lParam) 42 | { 43 | if(msg == WM_TIMER) { 44 | return 1; 45 | } else if(msg >= WM_MIO_EVENT) { 46 | mio_priv_t m = (mio_priv_t)(GetWindowLongPtr(hwnd, GWLP_USERDATA)); 47 | if(msg - WM_MIO_EVENT >= m->count) { 48 | mio_debug(ZONE, "mio event %d on socket id %d out of socket bounds %d", WSAGETSELECTEVENT(lParam), msg - WM_MIO_EVENT, m->count); 49 | return 0; 50 | } 51 | if(!m->fds[msg - WM_MIO_EVENT].event & WSAGETSELECTEVENT(lParam)) { 52 | mio_debug(ZONE, "unmatched mio event %d on socket #%d", WSAGETSELECTEVENT(lParam), m->fds[msg - WM_MIO_EVENT].mio_fd.fd); 53 | return 0; 54 | } 55 | m->select_fd = &m->fds[msg - WM_MIO_EVENT]; 56 | m->select_fd->revent = WSAGETSELECTEVENT(lParam); 57 | mio_debug(ZONE, "get mio event %d on socket #%d", m->select_fd->revent, m->select_fd->mio_fd.fd); \ 58 | return 1; 59 | } else if(msg == WM_CREATE) { 60 | SetWindowLongPtr(hwnd, GWLP_USERDATA, 61 | (LONG_PTR)((LPCREATESTRUCT)lParam)->lpCreateParams); 62 | } else { 63 | return DefWindowProc(hwnd, msg, wParam, lParam); 64 | } 65 | return 0; 66 | } 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /sm/mod_echo.c: -------------------------------------------------------------------------------- 1 | /* 2 | * jabberd - Jabber Open Source Server 3 | * Copyright (c) 2002 Jeremie Miller, Thomas Muldowney, 4 | * Ryan Eatmon, Robert Norris 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA 19 | */ 20 | 21 | #include "sm.h" 22 | 23 | /** @file sm/mod_echo.c 24 | * @brief message echo 25 | * @author Robert Norris 26 | * $Date: 2005/08/17 07:48:28 $ 27 | * $Revision: 1.9 $ 28 | */ 29 | 30 | static mod_ret_t _echo_pkt_sm(mod_instance_t mi, pkt_t pkt) 31 | { 32 | jid_t jid; 33 | char *resource = (char *) mi->mod->private; 34 | 35 | /* answer to probes and subscription requests */ 36 | if(pkt->type == pkt_PRESENCE_PROBE || pkt->type == pkt_S10N) { 37 | log_debug(ZONE, "answering presence probe/sub from %s with /echo resource", jid_full(pkt->from)); 38 | 39 | /* send presence */ 40 | jid = jid_new(jid_user(pkt->to), -1); 41 | jid_reset_components(jid, jid->node, jid->domain, resource); 42 | pkt_router(pkt_create(mi->mod->mm->sm, "presence", NULL, jid_user(pkt->from), jid_full(jid))); 43 | jid_free(jid); 44 | } 45 | 46 | /* we want messages addressed to /echo */ 47 | if(!(pkt->type & pkt_MESSAGE) || strcmp(pkt->to->resource, "echo") != 0) 48 | return mod_PASS; 49 | 50 | log_debug(ZONE, "echo request from %s", jid_full(pkt->from)); 51 | 52 | /* swap to and from and return it */ 53 | pkt_router(pkt_tofrom(pkt)); 54 | 55 | return mod_HANDLED; 56 | } 57 | 58 | DLLEXPORT int module_init(mod_instance_t mi, const char *arg) { 59 | module_t mod = mi->mod; 60 | 61 | if(mod->init) return 0; 62 | 63 | /* store /echo resource for use when answering probes */ 64 | mod->private = "echo"; 65 | 66 | mod->pkt_sm = _echo_pkt_sm; 67 | /* data is static so nothing to free */ 68 | /* mod->free = _echo_free; */ 69 | 70 | return 0; 71 | } 72 | -------------------------------------------------------------------------------- /sm/mod_iq_ping.c: -------------------------------------------------------------------------------- 1 | /* 2 | * jabberd - Jabber Open Source Server 3 | * Copyright (c) 2002 Jeremie Miller, Thomas Muldowney, 4 | * Ryan Eatmon, Robert Norris 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA 19 | */ 20 | 21 | #include "sm.h" 22 | 23 | /** @file sm/mod_iq_ping.c 24 | * @brief xmpp ping 25 | * @author Tomasz Sieprawski 26 | * $Date: 2007/04/06 xx:xx:xx $ 27 | * $Revision: 1.0 $ 28 | */ 29 | 30 | static int ns_PING = 0; 31 | 32 | void _iq_ping_reply(pkt_t pkt) { 33 | int ns, elem; 34 | 35 | ns = nad_find_scoped_namespace(pkt->nad, urn_PING, NULL); 36 | elem = nad_find_elem(pkt->nad, 1, ns, "ping", 1); 37 | if (elem>=0) 38 | nad_drop_elem(pkt->nad, elem); 39 | 40 | nad_set_attr(pkt->nad, 1, -1, "type", "result", 6); 41 | 42 | return; 43 | } 44 | 45 | static mod_ret_t _iq_ping_in_sess(mod_instance_t mi, sess_t sess, pkt_t pkt) { 46 | if(pkt->to != NULL || pkt->type != pkt_IQ || pkt->ns != ns_PING) 47 | return mod_PASS; 48 | _iq_ping_reply(pkt); 49 | pkt_sess(pkt, sess); 50 | return mod_HANDLED; 51 | } 52 | 53 | static mod_ret_t _iq_ping_pkt_sm(mod_instance_t mi, pkt_t pkt) { 54 | if(pkt->type != pkt_IQ || pkt->ns != ns_PING) 55 | return mod_PASS; 56 | _iq_ping_reply(pkt); 57 | pkt_router(pkt_tofrom(pkt)); 58 | return mod_HANDLED; 59 | } 60 | 61 | static void _iq_ping_free(module_t mod) { 62 | sm_unregister_ns(mod->mm->sm, urn_PING); 63 | feature_unregister(mod->mm->sm, urn_PING); 64 | } 65 | 66 | DLLEXPORT int module_init(mod_instance_t mi, const char *arg) { 67 | module_t mod = mi->mod; 68 | 69 | if(mod->init) return 0; 70 | 71 | mod->in_sess = _iq_ping_in_sess; 72 | mod->pkt_sm = _iq_ping_pkt_sm; 73 | mod->free = _iq_ping_free; 74 | 75 | ns_PING = sm_register_ns(mod->mm->sm, urn_PING); 76 | feature_register(mod->mm->sm, urn_PING); 77 | 78 | return 0; 79 | } 80 | -------------------------------------------------------------------------------- /sm/mod_active.c: -------------------------------------------------------------------------------- 1 | /* 2 | * jabberd - Jabber Open Source Server 3 | * Copyright (c) 2002-2003 Jeremie Miller, Thomas Muldowney, 4 | * Ryan Eatmon, Robert Norris 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA 19 | */ 20 | 21 | /** @file sm/mod_active.c 22 | * @brief active user management 23 | * @author Robert Norris 24 | * $Date: 2005/08/17 07:48:28 $ 25 | * $Revision: 1.8 $ 26 | */ 27 | 28 | #include "sm.h" 29 | 30 | static int _active_user_load(mod_instance_t mi, user_t user) { 31 | os_t os; 32 | os_object_t o; 33 | 34 | /* get their active status */ 35 | if(storage_get(user->sm->st, "active", jid_user(user->jid), NULL, &os) == st_SUCCESS && os_iter_first(os)) { 36 | o = os_iter_object(os); 37 | os_object_get_time(os, o, "time", &user->active); 38 | os_free(os); 39 | } else 40 | /* can't load them if they're inactive */ 41 | return 1; 42 | 43 | return 0; 44 | } 45 | 46 | static int _active_user_create(mod_instance_t mi, jid_t jid) { 47 | time_t t; 48 | os_t os; 49 | os_object_t o; 50 | 51 | log_debug(ZONE, "activating user %s", jid_user(jid)); 52 | 53 | t = time(NULL); 54 | 55 | os = os_new(); 56 | o = os_object_new(os); 57 | os_object_put_time(o, "time", &t); 58 | storage_put(mi->sm->st, "active", jid_user(jid), os); 59 | os_free(os); 60 | 61 | return 0; 62 | } 63 | 64 | static void _active_user_delete(mod_instance_t mi, jid_t jid) { 65 | log_debug(ZONE, "deactivating user %s", jid_user(jid)); 66 | 67 | storage_delete(mi->sm->st, "active", jid_user(jid), NULL); 68 | } 69 | 70 | DLLEXPORT int module_init(mod_instance_t mi, const char *arg) { 71 | module_t mod = mi->mod; 72 | 73 | if(mod->init) return 0; 74 | 75 | mod->user_load = _active_user_load; 76 | mod->user_create = _active_user_create; 77 | mod->user_delete = _active_user_delete; 78 | 79 | return 0; 80 | } 81 | -------------------------------------------------------------------------------- /s2s/util.c: -------------------------------------------------------------------------------- 1 | /* 2 | * jabberd - Jabber Open Source Server 3 | * Copyright (c) 2002 Jeremie Miller, Thomas Muldowney, 4 | * Ryan Eatmon, Robert Norris 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA 19 | */ 20 | 21 | #define _GNU_SOURCE 22 | #include 23 | 24 | #include "s2s.h" 25 | 26 | /** generate a local/remote route key */ 27 | char *s2s_route_key(pool_t p, const char *local, const char *remote) { 28 | char *key; 29 | 30 | if(local == NULL) local = ""; 31 | if(remote == NULL) remote = ""; 32 | 33 | if(p == NULL) 34 | key = (char *) malloc(strlen(local) + strlen(remote) + 2); 35 | else 36 | key = (char *) pmalloc(p, strlen(local) + strlen(remote) + 2); 37 | 38 | sprintf(key, "%s/%s", local, remote); 39 | 40 | return key; 41 | } 42 | 43 | /** match route key - used for searching route hash */ 44 | int s2s_route_key_match(char *local, const char *remote, const char *rkey, int rkeylen) { 45 | char *klocal, *kremote; 46 | int ret; 47 | 48 | klocal = strndup(rkey, rkeylen); 49 | kremote = strchr(klocal, '/'); 50 | if(kremote != NULL) *kremote++ = '\0'; 51 | 52 | ret = (local == NULL || (klocal != NULL && !strcmp(local, klocal))) 53 | && (remote == NULL || (kremote != NULL && !strcmp(remote, kremote))); 54 | 55 | free(klocal); 56 | 57 | return ret; 58 | } 59 | 60 | /** generate a dialback key */ 61 | char *s2s_db_key(pool_t p, const char *secret, const char *remote, const char *id) { 62 | char hash[41], buf[1024]; 63 | 64 | _sx_debug(ZONE, "generating dialback key, secret %s, remote %s, id %s", secret, remote, id); 65 | 66 | shahash_r(secret, hash); 67 | 68 | snprintf(buf, 1024, "%s%s", hash, remote); 69 | shahash_r(buf, hash); 70 | 71 | snprintf(buf, 1024, "%s%s", hash, id); 72 | shahash_r(buf, hash); 73 | 74 | _sx_debug(ZONE, "dialback key generated: %s", hash); 75 | 76 | if(p == NULL) 77 | return strdup(hash); 78 | else 79 | return pstrdup(p, hash); 80 | } 81 | -------------------------------------------------------------------------------- /util/xhash.h: -------------------------------------------------------------------------------- 1 | /* 2 | * jabberd - Jabber Open Source Server 3 | * Copyright (c) 2002-2004 Jeremie Miller, Thomas Muldowney, 4 | * Ryan Eatmon, Robert Norris 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA 19 | */ 20 | 21 | /** @file util/xhash.h 22 | * @brief hashtables 23 | * $Date: 2004/04/30 00:53:55 $ 24 | * $Revision: 1.1 $ 25 | */ 26 | 27 | #ifndef INCL_UTIL_XHASH_H 28 | #define INCL_UTIL_XHASH_H 1 29 | 30 | #ifdef HAVE_CONFIG_H 31 | # include 32 | #endif 33 | 34 | #include "pool.h" 35 | 36 | typedef struct xhn_struct 37 | { 38 | struct xhn_struct *next; 39 | struct xhn_struct *prev; 40 | const char *key; 41 | int keylen; 42 | void *val; 43 | } *xhn, _xhn; 44 | 45 | typedef struct xht_struct 46 | { 47 | pool_t p; 48 | int prime; 49 | int dirty; 50 | int count; 51 | struct xhn_struct *zen; 52 | struct xhn_struct *free_list; // list of zaped elements to be reused. 53 | int iter_bucket; 54 | xhn iter_node; 55 | int *stat; 56 | } *xht, _xht; 57 | 58 | JABBERD2_API xht xhash_new(int prime); 59 | JABBERD2_API void xhash_put(xht h, const char *key, void *val); 60 | JABBERD2_API void xhash_putx(xht h, const char *key, int len, void *val); 61 | JABBERD2_API void *xhash_get(xht h, const char *key); 62 | JABBERD2_API void *xhash_getx(xht h, const char *key, int len); 63 | JABBERD2_API void xhash_zap(xht h, const char *key); 64 | JABBERD2_API void xhash_zapx(xht h, const char *key, int len); 65 | JABBERD2_API void xhash_stat(xht h); 66 | JABBERD2_API void xhash_free(xht h); 67 | typedef void (*xhash_walker)(const char *key, int keylen, void *val, void *arg); 68 | JABBERD2_API void xhash_walk(xht h, xhash_walker w, void *arg); 69 | JABBERD2_API int xhash_dirty(xht h); 70 | JABBERD2_API int xhash_count(xht h); 71 | JABBERD2_API pool_t xhash_pool(xht h); 72 | 73 | /* iteration functions */ 74 | JABBERD2_API int xhash_iter_first(xht h); 75 | JABBERD2_API int xhash_iter_next(xht h); 76 | JABBERD2_API void xhash_iter_zap(xht h); 77 | JABBERD2_API int xhash_iter_get(xht h, const char **key, int *keylen, void **val); 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /c2s/bind.c: -------------------------------------------------------------------------------- 1 | /* 2 | * jabberd - Jabber Open Source Server 3 | * Copyright (c) 2002-2003 Jeremie Miller, Thomas Muldowney, 4 | * Ryan Eatmon, Robert Norris 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA 19 | */ 20 | 21 | /** @file c2s/bind.c 22 | * @brief xmpp resource binding 23 | * @author Robert Norris 24 | * $Date: 2005/06/02 04:48:24 $ 25 | * $Revision: 1.9 $ 26 | */ 27 | 28 | #include "c2s.h" 29 | 30 | /** sx features callback */ 31 | static void _bind_features(sx_t s, sx_plugin_t p, nad_t nad) { 32 | int ns; 33 | 34 | if(s->auth_id == NULL) { 35 | c2s_t c2s; 36 | host_t host; 37 | 38 | log_debug(ZONE, "not auth'd, offering auth and register"); 39 | 40 | ns = nad_add_namespace(nad, uri_IQAUTH, NULL); 41 | nad_append_elem(nad, ns, "auth", 1); 42 | 43 | c2s = (c2s_t) p->private; 44 | host = xhash_get(c2s->hosts, s->req_to); 45 | if(! host) host = c2s->vhost; 46 | if(host && host->ar_register_enable) { 47 | ns = nad_add_namespace(nad, uri_IQREGISTER, NULL); 48 | nad_append_elem(nad, ns, "register", 1); 49 | } 50 | } else { 51 | log_debug(ZONE, "auth'd, offering resource bind and session"); 52 | 53 | ns = nad_add_namespace(nad, uri_BIND, NULL); 54 | nad_append_elem(nad, ns, "bind", 1); 55 | nad_append_elem(nad, -1, "required", 2); 56 | nad->scope = ns; 57 | nad_append_elem(nad, ns, "unbind", 1); 58 | #ifdef ENABLE_SUPERSEDED 59 | ns = nad_add_namespace(nad, uri_XSESSION, NULL); 60 | nad_append_elem(nad, ns, "session", 1); 61 | #endif 62 | ns = nad_add_namespace(nad, uri_ROSTERVER, NULL); 63 | nad_append_elem(nad, ns, "ver", 1); 64 | } 65 | } 66 | 67 | /** plugin initialiser */ 68 | /** args: c2s */ 69 | int bind_init(sx_env_t env, sx_plugin_t p, va_list args) { 70 | c2s_t c2s; 71 | 72 | log_debug(ZONE, "initialising resource bind sx plugin"); 73 | 74 | c2s = va_arg(args, c2s_t); 75 | 76 | p->features = _bind_features; 77 | p->private = (void *) c2s; 78 | 79 | return 0; 80 | } 81 | -------------------------------------------------------------------------------- /util/rate.c: -------------------------------------------------------------------------------- 1 | /* 2 | * jabberd - Jabber Open Source Server 3 | * Copyright (c) 2002 Jeremie Miller, Thomas Muldowney, 4 | * Ryan Eatmon, Robert Norris 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA 19 | */ 20 | 21 | /* rate controls (for implementing connect-limiting or karma) */ 22 | 23 | #include "util.h" 24 | 25 | rate_t rate_new(int total, int seconds, int wait) 26 | { 27 | rate_t rt = (rate_t) calloc(1, sizeof(struct rate_st)); 28 | 29 | rt->total = total; 30 | rt->seconds = seconds; 31 | rt->wait = wait; 32 | 33 | return rt; 34 | } 35 | 36 | void rate_free(rate_t rt) 37 | { 38 | free(rt); 39 | } 40 | 41 | void rate_reset(rate_t rt) 42 | { 43 | rt->time = 0; 44 | rt->count = 0; 45 | rt->bad = 0; 46 | } 47 | 48 | void rate_add(rate_t rt, int count) 49 | { 50 | time_t now; 51 | 52 | now = time(NULL); 53 | 54 | /* rate expired */ 55 | if(now - rt->time >= rt->seconds) 56 | rate_reset(rt); 57 | 58 | rt->count += count; 59 | 60 | /* first event, so set the time */ 61 | if(rt->time == 0) 62 | rt->time = now; 63 | 64 | /* uhoh, they stuffed up */ 65 | if(rt->count >= rt->total) 66 | rt->bad = now; 67 | } 68 | 69 | int rate_left(rate_t rt) 70 | { 71 | /* if we're bad, then there's none left */ 72 | if(rt->bad != 0) 73 | return 0; 74 | 75 | return rt->total - rt->count; 76 | } 77 | 78 | int rate_check(rate_t rt) 79 | { 80 | /* not tracking */ 81 | if(rt->time == 0) 82 | return 1; 83 | 84 | /* under the limit */ 85 | if(rt->count < rt->total) 86 | return 1; 87 | 88 | /* currently bad */ 89 | if(rt->bad != 0) 90 | { 91 | /* wait over, they're good again */ 92 | if(time(NULL) - rt->bad >= rt->wait) 93 | { 94 | rate_reset(rt); 95 | return 1; 96 | } 97 | 98 | /* keep them waiting */ 99 | return 0; 100 | } 101 | 102 | /* they're inside the time, and not bad yet */ 103 | return 1; 104 | } 105 | -------------------------------------------------------------------------------- /subst/syslog.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2001 Internet Software Consortium. 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM 9 | * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL 10 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL 11 | * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, 12 | * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING 13 | * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, 14 | * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION 15 | * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | */ 17 | 18 | /* $Id: syslog.h,v 1.5 2005/06/02 04:48:25 zion Exp $ */ 19 | 20 | #ifdef HAVE_CONFIG_H 21 | # include "config.h" 22 | #endif 23 | 24 | /* jabberd2 Windows DLL */ 25 | #ifndef JABBERD2_API 26 | # ifdef _WIN32 27 | # ifdef JABBERD2_EXPORTS 28 | # define JABBERD2_API __declspec(dllexport) 29 | # else /* JABBERD2_EXPORTS */ 30 | # define JABBERD2_API __declspec(dllimport) 31 | # endif /* JABBERD2_EXPORTS */ 32 | # else /* _WIN32 */ 33 | # define JABBERD2_API extern 34 | # endif /* _WIN32 */ 35 | #endif /* JABBERD2_API */ 36 | 37 | #ifndef HAVE_SYSLOG_H 38 | 39 | #ifndef _SYSLOG_H 40 | #define _SYSLOG_H 41 | 42 | #include 43 | 44 | /* Constant definitions for openlog() */ 45 | #define LOG_PID 1 46 | #define LOG_CONS 2 47 | /* NT event log does not support facility level */ 48 | #define LOG_KERN 0 49 | #define LOG_USER 0 50 | #define LOG_MAIL 0 51 | #define LOG_DAEMON 0 52 | #define LOG_AUTH 0 53 | #define LOG_SYSLOG 0 54 | #define LOG_LPR 0 55 | #define LOG_LOCAL0 0 56 | #define LOG_LOCAL1 0 57 | #define LOG_LOCAL2 0 58 | #define LOG_LOCAL3 0 59 | #define LOG_LOCAL4 0 60 | #define LOG_LOCAL5 0 61 | #define LOG_LOCAL6 0 62 | #define LOG_LOCAL7 0 63 | 64 | #define LOG_EMERG 0 /* system is unusable */ 65 | #define LOG_ALERT 1 /* action must be taken immediately */ 66 | #define LOG_CRIT 2 /* critical conditions */ 67 | #define LOG_ERR 3 /* error conditions */ 68 | #define LOG_WARNING 4 /* warning conditions */ 69 | #define LOG_NOTICE 5 /* normal but signification condition */ 70 | #define LOG_INFO 6 /* informational */ 71 | #define LOG_DEBUG 7 /* debug-level messages */ 72 | 73 | JABBERD2_API void 74 | syslog(int level, const char *fmt, ...); 75 | 76 | JABBERD2_API void 77 | openlog(const char *, int, ...); 78 | 79 | JABBERD2_API void 80 | closelog(void); 81 | 82 | #endif 83 | 84 | #endif 85 | -------------------------------------------------------------------------------- /tools/pipe-auth.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl -w 2 | 3 | # 4 | # Sample pipe authenticator module. You can use this as a basis for your 5 | # own auth/reg module. See docs/dev/c2s-pipe-authenticator for details 6 | # about the protocol. 7 | # 8 | # This code is hereby placed into the public domain. 9 | # 10 | 11 | use strict; 12 | 13 | use MIME::Base64; 14 | 15 | # Flush output immediately. 16 | $| = 1; 17 | 18 | # On startup, we have to inform c2s of the functions we can deal with. USER-EXISTS is not optional. 19 | print "OK USER-EXISTS GET-PASSWORD CHECK-PASSWORD SET-PASSWORD CREATE-USER DESTROY-USER FREE\n"; 20 | 21 | # Our main loop 22 | my $buf; 23 | while(sysread (STDIN, $buf, 1024) > 0) 24 | { 25 | my ($cmd, @args) = split ' ', $buf; 26 | $cmd =~ tr/[A-Z]/[a-z]/; 27 | $cmd =~ tr/-/_/; 28 | 29 | eval "print _cmd_$cmd(\@args), '\n'"; 30 | } 31 | 32 | # Determine if the requested user exists. 33 | sub _cmd_user_exists 34 | { 35 | my ($user, $realm) = @_; 36 | 37 | # !!! return "OK" if user exists; 38 | 39 | return "NO"; 40 | } 41 | 42 | # Retrieve the user's password. 43 | sub _cmd_get_password 44 | { 45 | my ($user, $realm) = @_; 46 | 47 | # !!! $pass = [password in database]; 48 | # return "NO" if not $pass; 49 | # $encoded_pass = encode_base64($pass); 50 | # return "OK $encoded_pass" if $encoded_pass; 51 | 52 | return "NO"; 53 | } 54 | 55 | # Compare the given password with the stored password. 56 | sub _cmd_check_password 57 | { 58 | my ($user, $encoded_pass, $realm) = @_; 59 | 60 | # !!! $pass = decode_base64($encoded_pass); 61 | # return "NO" if not $pass; 62 | # $spass = [password in database]; 63 | # return "OK" if $pass eq $spass; 64 | 65 | return "NO"; 66 | } 67 | 68 | # Store the password in the database. 69 | sub _cmd_set_password 70 | { 71 | my ($user, $encoded_pass, $realm) = @_; 72 | 73 | # !!! $pass = decode_base64($encoded_pass); 74 | # return "NO" if not $pass; 75 | # $fail = [store $pass in database]; 76 | # return "OK" if not $fail; 77 | 78 | return "NO"; 79 | } 80 | 81 | # Create a user in the database (with no auth credentials). 82 | sub _cmd_create_user 83 | { 84 | my ($user, $realm) = @_; 85 | 86 | # !!! $fail = [create user in database] 87 | # return "OK" if not $fail; 88 | 89 | return "NO"; 90 | } 91 | 92 | # Delete a user and associated credentials. 93 | sub _cmd_delete_user 94 | { 95 | my ($user, $realm) = @_; 96 | 97 | # !!! $fail = [delete user in database] 98 | # return "OK" if not $fail; 99 | 100 | return "NO"; 101 | } 102 | 103 | # c2s shutting down, do the same. 104 | sub _cmd_free 105 | { 106 | # !!! free data 107 | # close database handles 108 | 109 | exit(0); 110 | } 111 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | TODO for 2.0 2 | ------------ 3 | 4 | Roster templates may not be working properly (esp. with multiple items). 5 | Check and fix if necessary. 6 | 7 | 8 | Make sure that available presence in response to a s10n accept arrives 9 | after the type='subscribed' (see chat with Nathan Walp) 10 | 11 | 12 | c2s may not be properly detecting client connections dropping. I feel 13 | like I've checked this numerous times, so check once more, once and for 14 | all. 15 | 16 | 17 | Modify user-load chain calls to indicate if the user is being loaded for 18 | a session, or just for delivery. Don't load rosters (and other large 19 | things) in that case. 20 | 21 | ========== 22 | 23 | The requirement for this is that large presence broadcasts (for the 24 | same host) result in many users being loaded for delivery, only to 25 | find out that they have no sessions online, and then being unloaded 26 | again. If we could stop some parts of the user data being loaded when 27 | the user is loaded only for packet delivery, then the overhead could 28 | be kept to a minimum. 29 | 30 | Privacy lists make this hard, if not impossible. Privacy lists must be 31 | loaded at packet delivery time, because the user may have a default 32 | list. That default list may have rules based on roster group, so the 33 | roster must be loaded. 34 | 35 | A partial solution might be to have a module that runs in in-router 36 | before mod_privacy, that watches for presence packets and drops them 37 | if the user is not online. This should work, because even if the 38 | presence packet was allowed by the default privacy list, it'll get 39 | dropped anyway because mod_deliver would find later that there are no 40 | sessions online. 41 | 42 | This doesn't fix the problem completely though because mod_privacy 43 | needs the user's roster loaded in order to process a default list with 44 | rules based on roster group. There's no way for mod_privacy to call 45 | into mod_roster to get it to load the roster on demand. 46 | 47 | Long term, there's a couple of possibilities. In general, I believe 48 | its reasonable to either have all user data loaded, or none of it - 49 | anything in between requires a measure of the "importance" of certain 50 | data (which doesn't scale and is highly subjective) or a on-demand 51 | system of loading data, which requires dependency graphs and 52 | inter-module communication. This stuff isn't impossible, but I don't 53 | want to go there if I can help it. 54 | 55 | It might be better to simply implement a (configurable) delay before 56 | unused user data is unloaded. This will still mean that the first 57 | presence broadcast can get sluggish, but after this things should chug 58 | along nicely. 59 | 60 | A patch for the partial soltuion mentioned above has been implemented, 61 | as _presence_in_router(). This is not a complete fix, but does 62 | workaround the most common case. 63 | 64 | ========== 65 | -------------------------------------------------------------------------------- /storage/authreg_ntlogon.c: -------------------------------------------------------------------------------- 1 | /* 2 | * jabberd - Jabber Open Source Server 3 | * Copyright (c) 2005 Adam Strzelecki 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA 18 | */ 19 | 20 | /* this plugin uses NT logon LogonUser authentication */ 21 | 22 | #include "c2s.h" 23 | 24 | #ifdef _WIN32 25 | 26 | typedef BOOL (CALLBACK FNLOGONUSERA)(LPTSTR, LPTSTR, LPTSTR, DWORD, DWORD, PHANDLE); 27 | FNLOGONUSERA *_LogonUserA = NULL; 28 | HANDLE hModule = NULL; 29 | 30 | static int _ar_ntlogon_user_exists(authreg_t ar, sess_t sess, const char *username, const char *realm) 31 | { 32 | /* we can't check if a user exists, so we just assume we have them all the time */ 33 | return 1; 34 | } 35 | 36 | static int _ar_ntlogon_check_password(authreg_t ar, sess_t sess, const char *username, const char *realm, char password[257]) 37 | { 38 | HANDLE hToken = NULL; 39 | if(!_LogonUserA) return 1; 40 | if(!_LogonUserA(username, realm, password, 41 | LOGON32_LOGON_NETWORK, 42 | LOGON32_PROVIDER_DEFAULT, &hToken)) 43 | { 44 | log_write(ar->c2s->log, LOG_ERR, "ntlogon: user '%s', realm '%s' logon failed", username, realm); 45 | return 1; 46 | } 47 | 48 | log_write(ar->c2s->log, LOG_NOTICE, "ntlogon: user '%s', realm '%s' logged in", username, realm); 49 | CloseHandle(hToken); 50 | return 0; 51 | } 52 | 53 | static void _ar_ntlogon_free(authreg_t ar) 54 | { 55 | if(hModule) FreeLibrary(hModule); 56 | } 57 | 58 | /** start me up */ 59 | DLLEXPORT int ar_init(authreg_t ar) 60 | { 61 | if(!(hModule = LoadLibraryA("Advapi32.dll"))) 62 | { 63 | log_write(ar->c2s->log, LOG_ERR, "ntlogon: module requires Windows NT or higher OS"); 64 | return 1; 65 | } 66 | 67 | if(!(_LogonUserA = (FNLOGONUSERA *)GetProcAddress(hModule, "LogonUserA"))) 68 | { 69 | log_write(ar->c2s->log, LOG_ERR, "ntlogon: entry point for LogonUserA cannot be found"); 70 | return 1; 71 | } 72 | 73 | ar->user_exists = _ar_ntlogon_user_exists; 74 | ar->check_password = _ar_ntlogon_check_password; 75 | ar->free = _ar_ntlogon_free; 76 | 77 | /* reset mechanism to digest only */ 78 | /* 79 | ar->c2s->ar_mechanisms &= AR_MECH_TRAD_PLAIN; 80 | ar->c2s->ar_ssl_mechanisms &= AR_MECH_TRAD_PLAIN; 81 | */ 82 | 83 | log_write(ar->c2s->log, LOG_NOTICE, "ntlogon: module initialised"); 84 | 85 | return 0; 86 | } 87 | 88 | #else /* _WIN32 */ 89 | 90 | DLLEXPORT int ar_init(authreg_t ar) 91 | { 92 | log_write(ar->c2s->log, LOG_ERR, "ntlogon: module is not supported on non-Windows platforms"); 93 | return 1; 94 | } 95 | 96 | #endif 97 | -------------------------------------------------------------------------------- /tools/db-jd14-2-jd2.sql: -------------------------------------------------------------------------------- 1 | -- 2 | -- This script migrates jabberd14 xdb_sql postgresql data 3 | -- to jabberd2 postgres storage 4 | -- 5 | 6 | -- \i db-setup.pgsql 7 | 8 | -- notatki: 9 | -- wszystko pozostale skonwertowac konwerterem jajcusia 10 | -- zmodyfikowac formularz modyfikacji danych usera 11 | -- zmodyfikowac proces odzyskiwania hasla 12 | ALTER TABLE recovery RENAME COLUMN mailaddress TO email; 13 | ALTER TABLE recovery ADD COLUMN "collection-owner" text; 14 | UPDATE recovery SET "collection-owner" = username || '@' || realm; 15 | ALTER TABLE recovery ALTER COLUMN "collection-owner" SET not null; 16 | ALTER TABLE recovery DROP COLUMN username; 17 | ALTER TABLE recovery DROP COLUMN realm; 18 | 19 | CREATE TABLE userdata ( 20 | "collection-owner" text PRIMARY KEY, 21 | lastmodified timestamp not null default current_timestamp, 22 | name varchar(256), 23 | email varchar(512), 24 | wwwstatus boolean not null default false, 25 | profilesearch boolean not null default true ); 26 | INSERT INTO userdata ("collection-owner",lastmodified,name,email,wwwstatus,profilesearch) SELECT u.username || '@' || u.realm, COALESCE(lastmodified,now()), name, mailaddress, wwwstatus, profilesearch FROM useroptions AS u LEFT JOIN mailaddresses AS m ON (u.username = m.username AND u.realm = m.realm); 27 | DROP TABLE mailaddresses; 28 | DROP TABLE useroptions; 29 | 30 | -- 31 | -- Drop unconvertable and unused tables first 32 | -- 33 | DROP TABLE presence; 34 | DROP TABLE roster; -- It's support is buggy in jabberd14 so I haven't used it. 35 | 36 | -- 37 | -- Convert user data 38 | -- 39 | ALTER TABLE authreg ADD COLUMN created timestamp DEFAULT current_timestamp; 40 | INSERT INTO authreg (username,realm,password) SELECT username,realm,password FROM users; 41 | DROP TABLE users; 42 | 43 | -- 44 | -- Convert offline storage 45 | -- 46 | ALTER TABLE queue ADD COLUMN storetime timestamp not null default current_timestamp; 47 | INSERT INTO queue ("collection-owner",xml,storetime) SELECT username || '@' || realm, xml, storetime FROM messages WHERE xml != ''; 48 | DROP TABLE messages; 49 | 50 | -- 51 | -- Convert vCard data 52 | -- 53 | INSERT INTO vcard ("collection-owner", 54 | "fn","nickname","url","tel","email","title","role", 55 | "bday","tz", 56 | "n-family","n-given","n-middle","n-prefix","n-suffix", 57 | "adr-street","adr-extadd","adr-pobox","adr-locality","adr-region","adr-pcode","adr-country", 58 | "geo-lat","geo-lon","org-orgname","org-orgunit","agent-extval","sort-string","desc","note", 59 | "photo-type","photo-binval","photo-extval","logo-type","logo-binval","logo-extval", 60 | "sound-phonetic","sound-binval","sound-extval","key-type","key-cred","rev" 61 | ) SELECT username || '@' || realm, 62 | display_name,nickname,homepage,landline,email,job_title,org_role, 63 | TRIM(TO_CHAR(birth_year,'0000'))||'-'||TRIM(TO_CHAR(birth_month,'00'))||'-'||TRIM(TO_CHAR(birth_dayofmonth,'00')),'', 64 | family_name,given_name,middle_name,name_prefix,name_suffix, 65 | street,building || ' / ' || room,postalbox,locality,region,postalcode,country, 66 | lat,lon,org_name,org_unit,'','',description,'JEP-0054 vcard-temp', 67 | photo_data_mime,photo_data,photo_url,'','','', 68 | '','','','',pgpkey,timestamp FROM userprofile; 69 | 70 | DROP TABLE userprofile; 71 | 72 | -- 73 | -- Convert iq-last data 74 | -- 75 | INSERT INTO logout ("collection-owner",time) SELECT username || '@' || realm, (substring(substring(xml from 'last=.[0-9]+') from '[0-9]+'))::integer FROM last; 76 | DROP TABLE last; 77 | -------------------------------------------------------------------------------- /docs/dev/sm-storage-types: -------------------------------------------------------------------------------- 1 | This is a list of the DB collections types that the SM uses, and their fields. 2 | 3 | type: active 4 | user: core 5 | fields: time os_type_INTEGER 6 | 7 | If a user has a stored value for "active" then they "exist" for the purposes 8 | of routing and delivery. The value is the time (in seconds since the epoch) 9 | that they were first "created". This value is stored in user->active, which 10 | is used by mod_offline and mod_roster to determine if it should bother 11 | processing messages and subscription requests. 12 | 13 | 14 | type: logout 15 | user: mod_iq_last 16 | fields: time os_type_INTEGER 17 | 18 | This stores the time (in seconds since the epoch) of the last session that 19 | logged out. This is used to provide an iq:last response when there are no 20 | sessions online. 21 | 22 | 23 | type: roster-items 24 | user: mod_roster 25 | fields: jid os_type_STRING 26 | name os_type_STRING 27 | to os_type_BOOLEAN 28 | from os_type_BOOLEAN 29 | ask os_type_BOOLEAN 30 | 31 | This stores the roster items that make a user's roster. 32 | 33 | 34 | type: roster-groups 35 | user: mod_roster 36 | fields: jid os_type_STRING 37 | group os_type_STRING 38 | 39 | This stores the groups associated with each of a user's roster items. 40 | 41 | 42 | type: vcard 43 | user: mod_iq_vcard 44 | fields: 45 | fn os_type_STRING 46 | nickname os_type_STRING 47 | url os_type_STRING 48 | tel os_type_STRING 49 | email os_type_STRING 50 | title os_type_STRING 51 | role os_type_STRING 52 | bday os_type_STRING 53 | desc os_type_STRING 54 | n-given os_type_STRING 55 | n-family os_type_STRING 56 | adr-street os_type_STRING 57 | adr-extadd os_type_STRING 58 | adr-locality os_type_STRING 59 | adr-region os_type_STRING 60 | adr-pcode os_type_STRING 61 | adr-country os_type_STRING 62 | org-orgname os_type_STRING 63 | org-orgunit os_type_STRING 64 | 65 | Stores the various fields the make up the user's vcard. 66 | 67 | 68 | type: queue 69 | user: mod_offline 70 | fields: xml os_type_NAD 71 | 72 | This stores messages and s10n requests that are waiting to be delivered 73 | to the user. Each DB row contains a single complete packet. 74 | 75 | 76 | type: private 77 | user: mod_iq_private 78 | fields: ns os_type_STRING 79 | xml os_type_NAD 80 | 81 | This stores user private data (iq:private). ns holds the namespace (for 82 | fast lookup), and xml holds the complete packet (actually a copy of the 83 | original IQ set that stored the packet). 84 | 85 | 86 | type: motd-messages 87 | user: mod_announce 88 | fields: xml os_type_NAD 89 | 90 | This stores the current "message of the day" message. There is only one 91 | motd at any one time. 92 | 93 | 94 | type: motd-times 95 | user: mod_announce 96 | fields: time os_type_INTEGER 97 | 98 | This stores the time of the last motd message that a user received. It 99 | is used to determine whether to send the current motd to the user. 100 | -------------------------------------------------------------------------------- /sm/mod_pep.c: -------------------------------------------------------------------------------- 1 | /* 2 | * jabberd - Jabber Open Source Server 3 | * Copyright (c) 2009 Tomasz Sterna 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA 18 | */ 19 | 20 | #include "sm.h" 21 | 22 | /* 23 | * XEP-0163 is some lunatic nightmare... 24 | * 25 | * If you want it - YOU implement it! 26 | */ 27 | 28 | /** @file sm/mod_pep.c 29 | * @brief XEP-0163: Personal Eventing Protocol 30 | * @author Tomasz Sterna 31 | */ 32 | 33 | #define uri_PUBSUB "http://jabber.org/protocol/pubsub" 34 | static int ns_PUBSUB = 0; 35 | 36 | static mod_ret_t _pep_in_sess(mod_instance_t mi, sess_t sess, pkt_t pkt) { 37 | int ns, elem; 38 | 39 | /* only handle private sets and gets */ 40 | if((pkt->type != pkt_IQ && pkt->type != pkt_IQ_SET) || pkt->ns != ns_PUBSUB) 41 | return mod_PASS; 42 | 43 | /* we're only interested in no to, to our host, or to us */ 44 | if(pkt->to != NULL && jid_compare_user(sess->jid, pkt->to) != 0 && strcmp(sess->jid->domain, jid_user(pkt->to)) != 0) 45 | return mod_PASS; 46 | 47 | ns = nad_find_scoped_namespace(pkt->nad, uri_PUBSUB, NULL); 48 | elem = nad_find_elem(pkt->nad, 1, ns, "pubsub", 1); 49 | 50 | log_debug(ZONE, "_pep_in_sess() %d %d", ns, elem); 51 | return mod_PASS; 52 | } 53 | 54 | static mod_ret_t _pep_out_sess(mod_instance_t mi, sess_t sess, pkt_t pkt) { 55 | /* add pep identity to disco results from bare JID */ 56 | if(!(pkt->type & pkt_IQ) || pkt->ns != ns_DISCO_INFO || (pkt->from != NULL && strcmp(jid_user(sess->jid), jid_full(pkt->from)))) 57 | return mod_PASS; 58 | 59 | /* add PEP identity */ 60 | nad_append_elem(pkt->nad, -1, "identity", 3); 61 | nad_append_attr(pkt->nad, -1, "category", "pubsub"); 62 | nad_append_attr(pkt->nad, -1, "type", "pep"); 63 | 64 | nad_append_elem(pkt->nad, -1, "feature", 3); 65 | nad_append_attr(pkt->nad, -1, "var", uri_PUBSUB "#access-presence"); 66 | nad_append_elem(pkt->nad, -1, "feature", 3); 67 | nad_append_attr(pkt->nad, -1, "var", uri_PUBSUB "#auto-create"); 68 | nad_append_elem(pkt->nad, -1, "feature", 3); 69 | nad_append_attr(pkt->nad, -1, "var", uri_PUBSUB "#auto-subscribe"); 70 | nad_append_elem(pkt->nad, -1, "feature", 3); 71 | nad_append_attr(pkt->nad, -1, "var", uri_PUBSUB "#filtered-notifications"); 72 | nad_append_elem(pkt->nad, -1, "feature", 3); 73 | nad_append_attr(pkt->nad, -1, "var", uri_PUBSUB "#publish"); 74 | 75 | return mod_PASS; 76 | } 77 | 78 | DLLEXPORT int module_init(mod_instance_t mi, const char *arg) { 79 | module_t mod = mi->mod; 80 | 81 | if(mod->init) return 0; 82 | 83 | mod->in_sess = _pep_in_sess; 84 | mod->out_sess = _pep_out_sess; 85 | 86 | ns_PUBSUB = sm_register_ns(mod->mm->sm, uri_PUBSUB); 87 | feature_register(mod->mm->sm, uri_PUBSUB); 88 | 89 | return 0; 90 | } 91 | -------------------------------------------------------------------------------- /subst/subst.h: -------------------------------------------------------------------------------- 1 | /* 2 | * jabberd - Jabber Open Source Server 3 | * Copyright (c) 2002-2004 Jeremie Miller, Thomas Muldowney, 4 | * Ryan Eatmon, Robert Norris 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA 19 | */ 20 | 21 | /* substituted functions */ 22 | 23 | #ifndef INCL_SUBST_H 24 | #define INCL_SUBST_H 1 25 | 26 | #ifdef HAVE_CONFIG_H 27 | # include 28 | #endif 29 | #if defined (HAVE_STDARG_H) 30 | #include 31 | #endif 32 | /* jabberd2 Windows DLL */ 33 | #ifndef JABBERD2_API 34 | # ifdef _WIN32 35 | # ifdef JABBERD2_EXPORTS 36 | # define JABBERD2_API __declspec(dllexport) 37 | # else /* JABBERD2_EXPORTS */ 38 | # define JABBERD2_API __declspec(dllimport) 39 | # endif /* JABBERD2_EXPORTS */ 40 | # else /* _WIN32 */ 41 | # define JABBERD2_API extern 42 | # endif /* _WIN32 */ 43 | #endif /* JABBERD2_API */ 44 | 45 | #if !defined(HAVE_SNPRINTF) || defined(HAVE_BROKEN_SNPRINTF) 46 | JABBERD2_API int ap_snprintf(char *, size_t, const char *, ...); 47 | # define snprintf ap_snprintf 48 | #endif 49 | 50 | #if !defined(HAVE_VSNPRINTF) || defined(HAVE_BROKEN_VSNPRINTF) 51 | JABBERD2_API int ap_vsnprintf(char *, size_t, const char *, va_list ap); 52 | # define vsnprintf ap_vsnprintf 53 | #endif 54 | 55 | #ifndef HAVE_GETOPT 56 | # include "getopt.h" 57 | #endif 58 | 59 | #ifndef HAVE_SYSLOG_H 60 | # include "syslog.h" 61 | #endif 62 | 63 | #ifndef HAVE_GETTIMEOFDAY 64 | 65 | # if defined(HAVE_SYS_TIME_H) 66 | # include 67 | # elif defined(HAVE_SYS_TIMEB_H) 68 | # include 69 | # endif 70 | 71 | struct timezone { 72 | int tz_minuteswest; 73 | int tz_dsttime; 74 | }; 75 | 76 | JABBERD2_API int gettimeofday(struct timeval *tp, struct timezone *tz); 77 | #endif 78 | 79 | #ifdef HAVE_WINSOCK2_H 80 | # include 81 | # include "ip6_misc.h" 82 | 83 | # define EWOULDBLOCK WSAEWOULDBLOCK 84 | # define ECONNREFUSED WSAECONNREFUSED 85 | # define EINPROGRESS WSAEINPROGRESS 86 | #endif 87 | 88 | #ifndef HAVE_INET_ATON 89 | JABBERD2_API int inet_aton(const char *cp, struct in_addr *addr); 90 | #endif 91 | #ifndef HAVE_INET_NTOP 92 | JABBERD2_API const char *inet_ntop(int af, const void *src, char *dst, size_t size); 93 | #endif 94 | #ifndef HAVE_INET_PTON 95 | JABBERD2_API int inet_pton(int af, const char *src, void *dst); 96 | #endif 97 | 98 | #ifndef HAVE_IN_PORT_T 99 | typedef uint16_t in_port_t; 100 | #endif 101 | 102 | #ifdef HAVE__MKDIR 103 | # define mkdir(a,b) _mkdir(a) 104 | #endif 105 | 106 | #ifndef HAVE_STRNDUP 107 | JABBERD2_API char *strndup(char *str, size_t len); 108 | #endif 109 | 110 | #ifndef HAVE_TIMEGM 111 | #include 112 | JABBERD2_API time_t timegm (struct tm *tm); 113 | #endif 114 | 115 | #endif 116 | -------------------------------------------------------------------------------- /util/jqueue.c: -------------------------------------------------------------------------------- 1 | /* 2 | * jabberd - Jabber Open Source Server 3 | * Copyright (c) 2002 Jeremie Miller, Thomas Muldowney, 4 | * Ryan Eatmon, Robert Norris 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA 19 | */ 20 | 21 | /* priority jqueues */ 22 | 23 | #include "util.h" 24 | 25 | jqueue_t jqueue_new(void) { 26 | pool_t p; 27 | jqueue_t q; 28 | 29 | p = pool_new(); 30 | q = (jqueue_t) pmalloco(p, sizeof(struct _jqueue_st)); 31 | 32 | q->p = p; 33 | q->init_time = time(NULL); 34 | 35 | return q; 36 | } 37 | 38 | void jqueue_free(jqueue_t q) { 39 | assert((int) (q != NULL)); 40 | 41 | pool_free(q->p); 42 | } 43 | 44 | void jqueue_push(jqueue_t q, void *data, int priority) { 45 | _jqueue_node_t qn, scan; 46 | 47 | assert((int) (q != NULL)); 48 | 49 | q->size++; 50 | 51 | /* node from the cache, or make a new one */ 52 | qn = q->cache; 53 | if(qn != NULL) 54 | q->cache = qn->next; 55 | else 56 | qn = (_jqueue_node_t) pmalloc(q->p, sizeof(struct _jqueue_node_st)); 57 | 58 | qn->data = data; 59 | qn->priority = priority; 60 | 61 | qn->next = NULL; 62 | qn->prev = NULL; 63 | 64 | /* first one */ 65 | if(q->back == NULL && q->front == NULL) { 66 | q->back = qn; 67 | q->front = qn; 68 | 69 | return; 70 | } 71 | 72 | /* find the first node with priority <= to us */ 73 | for(scan = q->back; scan != NULL && scan->priority > priority; scan = scan->next); 74 | 75 | /* didn't find one, so we have top priority - push us on the front */ 76 | if(scan == NULL) { 77 | qn->prev = q->front; 78 | qn->prev->next = qn; 79 | q->front = qn; 80 | 81 | return; 82 | } 83 | 84 | /* push us in front of scan */ 85 | qn->next = scan; 86 | qn->prev = scan->prev; 87 | 88 | if(scan->prev != NULL) 89 | scan->prev->next = qn; 90 | else 91 | q->back = qn; 92 | 93 | scan->prev = qn; 94 | } 95 | 96 | void *jqueue_pull(jqueue_t q) { 97 | void *data; 98 | _jqueue_node_t qn; 99 | 100 | assert((int) (q != NULL)); 101 | 102 | if(q->front == NULL) 103 | return NULL; 104 | 105 | data = q->front->data; 106 | 107 | qn = q->front; 108 | 109 | if(qn->prev != NULL) 110 | qn->prev->next = NULL; 111 | 112 | q->front = qn->prev; 113 | 114 | /* node to cache for later reuse */ 115 | qn->next = q->cache; 116 | q->cache = qn; 117 | 118 | if(q->front == NULL) 119 | q->back = NULL; 120 | 121 | q->size--; 122 | 123 | return data; 124 | } 125 | 126 | int jqueue_size(jqueue_t q) { 127 | return q->size; 128 | } 129 | 130 | time_t jqueue_age(jqueue_t q) { 131 | return time(NULL) - q->init_time; 132 | } 133 | -------------------------------------------------------------------------------- /docs/dev/sm-presence-logic: -------------------------------------------------------------------------------- 1 | This is the logic employed by the presence tracker. The business rules 2 | are implemented in the SM core (sm/pres.c). The triggers (protocol 3 | specifics) are implemented in the Presence module (sm/mod_presence.c). 4 | 5 | XMPP version (no "invisible" presence) 6 | -------------------------------------- 7 | 8 | There are three sets of JIDs: 9 | T: trusted - these may see our presence ("from" or "both" in roster) 10 | A: available - these have been sent directed available presence 11 | E: error - these bounced presence updates 12 | 13 | Business rules: 14 | 15 | B1. Broadcasting available presence: 16 | forward to all in T, unless or E 17 | 18 | B2. Broadcasting unavailable presence: 19 | forward to all in T and A, unless in E 20 | clear A and E 21 | 22 | B3. Remote presence probe: 23 | respond if in T 24 | remove from E 25 | 26 | B4. Remote presence update: 27 | forward to all sessions with priority >= 0 28 | 29 | B5. Remote presence error: 30 | add to E 31 | remove from A 32 | 33 | B6. Directed available presence: 34 | forward 35 | add to A (unless in T) 36 | remove from E 37 | 38 | B7. Directed unavailable presence: 39 | forward 40 | remove from A and E 41 | 42 | Triggers: 43 | 44 | T1. 45 | T2. 46 | T3. 47 | T4. or 48 | T5. 49 | T6. 50 | T7. 51 | 52 | 53 | Jabber version (XMPP + "invisible" presence) 54 | -------------------------------------------- 55 | 56 | There are three sets of JIDs: 57 | T: trusted - these may see our presence ("from" or "both" in roster) 58 | A: available - these have been sent directed available presence 59 | E: error - these bounced presence updates 60 | 61 | There is also an "invisible" flag, I. 62 | 63 | Business rules: 64 | 65 | B1. Broadcasting available presence: 66 | forward to all in T, unless in E 67 | clear I 68 | 69 | B2. Broadcasting unavailable presence: 70 | forward to all in T and A, unless in E 71 | clear A and E 72 | clear I 73 | 74 | B3. Broadcasting invisible presence: 75 | send unavailable to all in T, unless in A or E 76 | set I 77 | 78 | B4. Remote presence probe: 79 | respond if in T and I clear 80 | respond if in T and in A and I set 81 | remove from E 82 | 83 | B5. Remote presence update: 84 | forward to all sessions with priority >= 0 85 | 86 | B6. Remote presence error: 87 | add to E 88 | remove from A 89 | 90 | B7. Directed available presence: 91 | forward 92 | add to A (unless in T) 93 | remove from E 94 | 95 | B8. Directed unavailable presence: 96 | forward 97 | remove from A and E 98 | 99 | Triggers: 100 | 101 | T1. 102 | T2. 103 | T3. () 104 | T4. 105 | T5. or 106 | T6. 107 | T7. 108 | T8. 109 | -------------------------------------------------------------------------------- /win32/setup/setup.wxs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 21 | 23 | 24 | 25 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | NOT Installed 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 68 | VC9SP1RTM OR VC9SP1RTM_VISTA OR VC9SP1RTM_WINDOWS7 69 | 70 | 71 | NOT NEWER_VER_FOUND 72 | 73 | 74 | 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /tools/db-update.mysql: -------------------------------------------------------------------------------- 1 | -- 2 | -- This updates and creates indexes for jabberd2 mysql databases created prior to 2.0s6. 3 | -- Run this using the mysql interactive terminal: 4 | -- 5 | -- mysql> \. db-update.mysql 6 | -- 7 | 8 | USE jabberd2; 9 | 10 | -- Change the primary keys on collection-owner to normal indexes so as not to 11 | -- enforce uniqueness on the first 255 chars of otherwise different JIDs 12 | 13 | ALTER TABLE `active` DROP PRIMARY KEY; 14 | ALTER TABLE `active` ADD INDEX ( `collection-owner` ( 255 ) ); 15 | 16 | ALTER TABLE `logout` DROP PRIMARY KEY; 17 | ALTER TABLE `logout` ADD INDEX ( `collection-owner` ( 255 ) ); 18 | 19 | ALTER TABLE `vcard` DROP PRIMARY KEY; 20 | ALTER TABLE `vcard` ADD INDEX ( `collection-owner` ( 255 ) ); 21 | 22 | ALTER TABLE `motd-message` DROP PRIMARY KEY; 23 | ALTER TABLE `motd-message` ADD INDEX ( `collection-owner` ( 255 ) ); 24 | 25 | ALTER TABLE `motd-times` DROP PRIMARY KEY; 26 | ALTER TABLE `motd-times` ADD INDEX ( `collection-owner` ( 255 ) ); 27 | 28 | ALTER TABLE `privacy-default` DROP PRIMARY KEY; 29 | ALTER TABLE `privacy-default` ADD INDEX ( `collection-owner` ( 255 ) ); 30 | 31 | -- Add indexes on collection-owner for tables that should have them 32 | 33 | ALTER TABLE `disco-items` ADD INDEX ( `collection-owner` ( 255 ) ); 34 | ALTER TABLE `roster-items` ADD INDEX ( `collection-owner` ( 255 ) ); 35 | ALTER TABLE `roster-groups` ADD INDEX ( `collection-owner` ( 255 ) ); 36 | ALTER TABLE `privacy-items` ADD INDEX ( `collection-owner` ( 255 ) ); 37 | ALTER TABLE `private` ADD INDEX ( `collection-owner` ( 255 ) ); 38 | ALTER TABLE `queue` ADD INDEX ( `collection-owner` ( 255 ) ); 39 | ALTER TABLE `vacation-settings` ADD INDEX ( `collection-owner` ( 255 ) ); 40 | 41 | -- Add indexes on username and realm for authreg 42 | 43 | ALTER TABLE `authreg` ADD INDEX ( `username` ( 255 ) ); 44 | ALTER TABLE `authreg` ADD INDEX ( `realm` ( 255 ) ); 45 | 46 | -- Change the field type of xml in queue and private to allow storage > 64K 47 | -- (MEDIUMTEXT will allow up to 16M) 48 | 49 | ALTER TABLE `queue` CHANGE `xml` `xml` MEDIUMTEXT DEFAULT NULL; 50 | ALTER TABLE `private` CHANGE `xml` `xml` MEDIUMTEXT DEFAULT NULL; 51 | 52 | -- Remove 256-char limit on username in authreg table 53 | 54 | ALTER TABLE `authreg` CHANGE `username` `username` TEXT DEFAULT NULL; 55 | 56 | --- Change keys on object-sequence to primary keys - note that mysql's index 57 | --- limit of 255 characters prevents the possibility of using collection-owner 58 | --- as the primary key (as a JID can be longer than that) 59 | 60 | ALTER TABLE `active` DROP INDEX `object-sequence` , ADD PRIMARY KEY ( `object-sequence` ); 61 | ALTER TABLE `disco-items` DROP INDEX `object-sequence` , ADD PRIMARY KEY ( `object-sequence` ); 62 | ALTER TABLE `logout` DROP INDEX `object-sequence` , ADD PRIMARY KEY ( `object-sequence` ); 63 | ALTER TABLE `motd-message` DROP INDEX `object-sequence` , ADD PRIMARY KEY ( `object-sequence` ); 64 | ALTER TABLE `motd-times` DROP INDEX `object-sequence` , ADD PRIMARY KEY ( `object-sequence` ); 65 | ALTER TABLE `privacy-default` DROP INDEX `object-sequence` , ADD PRIMARY KEY ( `object-sequence` ); 66 | ALTER TABLE `privacy-items` DROP INDEX `object-sequence` , ADD PRIMARY KEY ( `object-sequence` ); 67 | ALTER TABLE `private` DROP INDEX `object-sequence` , ADD PRIMARY KEY ( `object-sequence` ); 68 | ALTER TABLE `queue` DROP INDEX `object-sequence` , ADD PRIMARY KEY ( `object-sequence` ); 69 | ALTER TABLE `roster-groups` DROP INDEX `object-sequence` , ADD PRIMARY KEY ( `object-sequence` ); 70 | ALTER TABLE `roster-items` DROP INDEX `object-sequence` , ADD PRIMARY KEY ( `object-sequence` ); 71 | ALTER TABLE `vacation-settings` DROP INDEX `object-sequence` , ADD PRIMARY KEY ( `object-sequence` ); 72 | ALTER TABLE `vcard` DROP INDEX `object-sequence` , ADD PRIMARY KEY ( `object-sequence` ); 73 | -------------------------------------------------------------------------------- /util/pqueue.c: -------------------------------------------------------------------------------- 1 | /* 2 | * jabberd - Jabber Open Source Server 3 | * Copyright (c) 2002 Jeremie Miller, Thomas Muldowney, 4 | * Ryan Eatmon, Robert Norris 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA 19 | */ 20 | 21 | /* priority queues */ 22 | 23 | #include "pqueue.h" 24 | 25 | #include "pool.h" 26 | 27 | #include /* to get NULL */ 28 | #include 29 | 30 | typedef struct _pqueue_node_st *_pqueue_node_t; 31 | struct _pqueue_node_st { 32 | void *data; 33 | 34 | int priority; 35 | 36 | _pqueue_node_t next; 37 | _pqueue_node_t prev; 38 | }; 39 | 40 | struct _pqueue_st { 41 | pool_t p; 42 | _pqueue_node_t cache; 43 | 44 | _pqueue_node_t front; 45 | _pqueue_node_t back; 46 | 47 | int size; 48 | }; 49 | 50 | pqueue_t pqueue_new(pool_t p) { 51 | pqueue_t q; 52 | 53 | q = (pqueue_t) pmalloco(p, sizeof(struct _pqueue_st)); 54 | 55 | q->p = p; 56 | 57 | return q; 58 | } 59 | 60 | void pqueue_push(pqueue_t q, void *data, int priority) { 61 | _pqueue_node_t qn, scan; 62 | 63 | assert((q != NULL)); 64 | 65 | q->size++; 66 | 67 | /* node from the cache, or make a new one */ 68 | qn = q->cache; 69 | if(qn != NULL) 70 | q->cache = qn->next; 71 | else 72 | qn = (_pqueue_node_t) pmalloc(q->p, sizeof(struct _pqueue_node_st)); 73 | 74 | qn->data = data; 75 | qn->priority = priority; 76 | 77 | qn->next = NULL; 78 | qn->prev = NULL; 79 | 80 | /* first one */ 81 | if(q->back == NULL && q->front == NULL) { 82 | q->back = qn; 83 | q->front = qn; 84 | 85 | return; 86 | } 87 | 88 | /* find the first node with priority <= to us */ 89 | for(scan = q->back; scan != NULL && scan->priority > priority; scan = scan->next); 90 | 91 | /* didn't find one, so we have top priority - push us on the front */ 92 | if(scan == NULL) { 93 | qn->prev = q->front; 94 | qn->prev->next = qn; 95 | q->front = qn; 96 | 97 | return; 98 | } 99 | 100 | /* push us in front of scan */ 101 | qn->next = scan; 102 | qn->prev = scan->prev; 103 | 104 | if(scan->prev != NULL) 105 | scan->prev->next = qn; 106 | else 107 | q->back = qn; 108 | 109 | scan->prev = qn; 110 | } 111 | 112 | void *pqueue_pull(pqueue_t q) { 113 | void *data; 114 | _pqueue_node_t qn; 115 | 116 | assert((q != NULL)); 117 | 118 | if(q->front == NULL) 119 | return NULL; 120 | 121 | data = q->front->data; 122 | 123 | qn = q->front; 124 | 125 | if(qn->prev != NULL) 126 | qn->prev->next = NULL; 127 | 128 | q->front = qn->prev; 129 | 130 | /* node to cache for later reuse */ 131 | qn->next = q->cache; 132 | q->cache = qn; 133 | 134 | if(q->front == NULL) 135 | q->back = NULL; 136 | 137 | q->size--; 138 | 139 | return data; 140 | } 141 | 142 | int pqueue_size(pqueue_t q) { 143 | return q->size; 144 | } 145 | -------------------------------------------------------------------------------- /sm/mod_deliver.c: -------------------------------------------------------------------------------- 1 | /* 2 | * jabberd - Jabber Open Source Server 3 | * Copyright (c) 2002 Jeremie Miller, Thomas Muldowney, 4 | * Ryan Eatmon, Robert Norris 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA 19 | */ 20 | 21 | #include "sm.h" 22 | 23 | /** @file sm/mod_deliver.c 24 | * @brief packet delivery 25 | * @author Robert Norris 26 | * $Date: 2005/08/17 07:48:28 $ 27 | * $Revision: 1.18 $ 28 | */ 29 | 30 | static mod_ret_t _deliver_in_sess(mod_instance_t mi, sess_t sess, pkt_t pkt) 31 | { 32 | /* ensure from is set correctly if not already by client */ 33 | if(pkt->from == NULL || jid_compare_user(pkt->from, sess->jid) != 0 34 | || (!(pkt->type & pkt_PRESENCE) && !(pkt->type & pkt_S10N) 35 | && jid_compare_full(pkt->from, sess->jid) != 0)) { 36 | if(pkt->from != NULL) 37 | jid_free(pkt->from); 38 | 39 | pkt->from = jid_dup(sess->jid); 40 | nad_set_attr(pkt->nad, 1, -1, "from", jid_full(pkt->from), 0); 41 | } 42 | 43 | /* no to address means its to us */ 44 | if(pkt->to == NULL) { 45 | /* drop iq-result packets */ 46 | /* user client is confirming all iq-set, but we usually do not track these 47 | * confirmations and we need to drop it here, not loop back to client */ 48 | if(pkt->type == pkt_IQ_RESULT) { 49 | pkt_free(pkt); 50 | return mod_HANDLED; 51 | } 52 | 53 | /* iq packets without to should have been already handled by modules */ 54 | if(pkt->type & pkt_IQ) { 55 | return -stanza_err_FEATURE_NOT_IMPLEMENTED; 56 | } 57 | 58 | /* supplant user jid as 'to' */ 59 | pkt->to = jid_dup(sess->jid); 60 | nad_set_attr(pkt->nad, 1, -1, "to", jid_full(pkt->to), 0); 61 | } 62 | 63 | /* let it go on the wire */ 64 | pkt_router(pkt); 65 | 66 | return mod_HANDLED; 67 | } 68 | 69 | static mod_ret_t _deliver_pkt_user(mod_instance_t mi, user_t user, pkt_t pkt) 70 | { 71 | sess_t sess; 72 | 73 | /* if there's a resource, send it direct */ 74 | if(*pkt->to->resource != '\0') { 75 | /* find the session */ 76 | sess = sess_match(user, pkt->to->resource); 77 | 78 | /* and send it straight there */ 79 | if(sess != NULL) { 80 | pkt_sess(pkt, sess); 81 | return mod_HANDLED; 82 | } 83 | 84 | /* no session */ 85 | if(pkt->type & pkt_PRESENCE) { 86 | pkt_free(pkt); 87 | return mod_HANDLED; 88 | 89 | } else if(pkt->type & pkt_IQ) 90 | return -stanza_err_SERVICE_UNAVAILABLE; 91 | 92 | /* unmatched messages will fall through (XMPP-IM r20 s11 rule 2) */ 93 | } 94 | 95 | return mod_PASS; 96 | } 97 | 98 | DLLEXPORT int module_init(mod_instance_t mi, const char *arg) { 99 | module_t mod = mi->mod; 100 | 101 | if(mod->init) return 0; 102 | 103 | mod->in_sess = _deliver_in_sess; 104 | mod->pkt_user = _deliver_pkt_user; 105 | 106 | feature_register(mod->mm->sm, "message"); 107 | 108 | return 0; 109 | } 110 | -------------------------------------------------------------------------------- /sx/chain.c: -------------------------------------------------------------------------------- 1 | /* 2 | * jabberd - Jabber Open Source Server 3 | * Copyright (c) 2002 Jeremie Miller, Thomas Muldowney, 4 | * Ryan Eatmon, Robert Norris 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA 19 | */ 20 | 21 | /* manage and run the io and nad chains */ 22 | 23 | #include "sx.h" 24 | 25 | void _sx_chain_io_plugin(sx_t s, sx_plugin_t p) { 26 | _sx_chain_t cn, tail; 27 | 28 | _sx_debug(ZONE, "adding io plugin"); 29 | 30 | cn = (_sx_chain_t) malloc(sizeof(struct _sx_chain_st)); 31 | cn->p = p; 32 | 33 | if(s->wio == NULL) { 34 | s->wio = cn; 35 | cn->wnext = NULL; 36 | } else { 37 | cn->wnext = s->wio; 38 | s->wio = cn; 39 | } 40 | 41 | if(s->rio == NULL) 42 | s->rio = cn; 43 | else { 44 | for(tail = s->rio; tail->rnext != NULL; tail = tail->rnext); 45 | tail->rnext = cn; 46 | } 47 | cn->rnext = NULL; 48 | } 49 | 50 | void _sx_chain_nad_plugin(sx_t s, sx_plugin_t p) { 51 | _sx_chain_t cn, tail; 52 | 53 | _sx_debug(ZONE, "adding nad plugin"); 54 | 55 | cn = (_sx_chain_t) malloc(sizeof(struct _sx_chain_st)); 56 | cn->p = p; 57 | 58 | if(s->wnad == NULL) { 59 | s->wnad = cn; 60 | cn->wnext = NULL; 61 | } else { 62 | cn->wnext = s->wnad; 63 | s->wnad = cn; 64 | } 65 | 66 | if(s->rnad == NULL) 67 | s->rnad = cn; 68 | else { 69 | for(tail = s->rnad; tail->rnext != NULL; tail = tail->rnext); 70 | tail->rnext = cn; 71 | } 72 | cn->rnext = NULL; 73 | } 74 | 75 | int _sx_chain_io_write(sx_t s, sx_buf_t buf) { 76 | _sx_chain_t scan; 77 | int ret = 1; 78 | 79 | _sx_debug(ZONE, "calling io write chain"); 80 | 81 | for(scan = s->wio; scan != NULL; scan = scan->wnext) 82 | if(scan->p->wio != NULL) 83 | if((ret = (scan->p->wio)(s, scan->p, buf)) <= 0) 84 | return ret; 85 | 86 | return ret; 87 | } 88 | 89 | int _sx_chain_io_read(sx_t s, sx_buf_t buf) { 90 | _sx_chain_t scan; 91 | int ret = 1; 92 | 93 | _sx_debug(ZONE, "calling io read chain"); 94 | 95 | for(scan = s->rio; scan != NULL; scan = scan->rnext) 96 | if(scan->p->rio != NULL) 97 | if((ret = (scan->p->rio)(s, scan->p, buf)) <= 0) 98 | return ret; 99 | 100 | return ret; 101 | } 102 | 103 | int _sx_chain_nad_write(sx_t s, nad_t nad, int elem) { 104 | _sx_chain_t scan; 105 | 106 | _sx_debug(ZONE, "calling nad write chain"); 107 | 108 | for(scan = s->wnad; scan != NULL; scan = scan->wnext) 109 | if(scan->p->wnad != NULL) 110 | if((scan->p->wnad)(s, scan->p, nad, elem) == 0) 111 | return 0; 112 | 113 | return 1; 114 | } 115 | 116 | int _sx_chain_nad_read(sx_t s, nad_t nad) { 117 | _sx_chain_t scan; 118 | 119 | _sx_debug(ZONE, "calling nad read chain"); 120 | 121 | for(scan = s->rnad; scan != NULL; scan = scan->rnext) 122 | if(scan->p->rnad != NULL) 123 | if((scan->p->rnad)(s, scan->p, nad) == 0) 124 | return 0; 125 | 126 | return 1; 127 | } 128 | -------------------------------------------------------------------------------- /util/util_compat.h: -------------------------------------------------------------------------------- 1 | /* 2 | * jabberd - Jabber Open Source Server 3 | * Copyright (c) 2002 Jeremie Miller, Thomas Muldowney, 4 | * Ryan Eatmon, Robert Norris 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA 19 | */ 20 | 21 | #ifdef HAVE_CONFIG_H 22 | # include 23 | #endif 24 | 25 | #ifndef INCL_UTIL_COMPAT_H 26 | #define INCL_UTIL_COMPAT_H 27 | 28 | #ifdef __cplusplus 29 | extern "C" { 30 | #endif 31 | 32 | /** 33 | * @file util/util_compat.h 34 | * @brief define the structures that could be missing in old libc implementations 35 | */ 36 | 37 | #ifndef PF_INET6 38 | # define PF_INET6 10 /**< protcol family for IPv6 */ 39 | #endif 40 | 41 | #ifndef AF_INET6 42 | # define AF_INET6 PF_INET6 /**< address family for IPv6 */ 43 | #endif 44 | 45 | #ifndef INET6_ADDRSTRLEN 46 | # define INET6_ADDRSTRLEN 46 /**< maximum length of the string 47 | representation of an IPv6 address */ 48 | #endif 49 | 50 | 51 | #ifndef IN6_IS_ADDR_V4MAPPED 52 | /** check if an IPv6 is just a mapped IPv4 address */ 53 | #define IN6_IS_ADDR_V4MAPPED(a) \ 54 | ((*(const uint32_t *)(const void *)(&(a)->s6_addr[0]) == 0) && \ 55 | (*(const uint32_t *)(const void *)(&(a)->s6_addr[4]) == 0) && \ 56 | (*(const uint32_t *)(const void *)(&(a)->s6_addr[8]) == ntohl(0x0000ffff))) 57 | #endif 58 | 59 | #ifndef HAVE_SA_FAMILY_T 60 | typedef unsigned short sa_family_t; 61 | #endif 62 | 63 | #ifndef HAVE_STRUCT_IN6_ADDR 64 | /** 65 | * structure that contains a plain IPv6 address (only defined if 66 | * not contained in the libc 67 | */ 68 | struct in6_addr { 69 | uint8_t s6_addr[16]; /**< IPv6 address */ 70 | }; 71 | #endif /* NO_IN6_ADDR */ 72 | 73 | #ifndef HAVE_STRUCT_SOCKADDR_IN6 74 | /** 75 | * structure that contains an IPv6 including some additional attributes 76 | * (only defined if not contained in the libc) 77 | */ 78 | struct sockaddr_in6 { 79 | #ifdef SIN6_LEN 80 | uint8_t sin6_len; /**< length of this struct */ 81 | #endif /* SIN6_LEN */ 82 | sa_family_t sin6_family; /**< address family (AF_INET6) */ 83 | in_port_t sin6_port; /**< transport layer port # */ 84 | uint32_t sin6_flowinfo; /**< IPv6 traffic class and flow info */ 85 | struct in6_addr sin6_addr; /**< IPv6 address */ 86 | uint32_t sin6_scope_id; /**< set of interfaces for a scope */ 87 | }; 88 | #endif /* NO_SOCKADDR_IN6 */ 89 | 90 | #ifndef HAVE_STRUCT_SOCKADDR_STORAGE 91 | /** 92 | * container for sockaddr_in and sockaddr_in6 structures, handled like 93 | * an object in jabberd2 code 94 | * (this definition is not fully compatible with RFC 2553, 95 | * but it is enough for us) */ 96 | #define _SS_PADSIZE (128-sizeof(sa_family_t)) 97 | struct sockaddr_storage { 98 | sa_family_t ss_family; /**< address family */ 99 | char __ss_pad[_SS_PADSIZE]; /**< padding to a size of 128 bytes */ 100 | }; 101 | #endif /* NO_SOCKADDR_STORAGE */ 102 | 103 | #ifndef SSL_OP_NO_TICKET 104 | #define SSL_OP_NO_TICKET 0x00004000L 105 | #endif 106 | 107 | #ifdef __cplusplus 108 | } 109 | #endif 110 | 111 | #endif /* INCL_UTIL_H */ 112 | -------------------------------------------------------------------------------- /sm/mod_iq_time.c: -------------------------------------------------------------------------------- 1 | /* 2 | * jabberd - Jabber Open Source Server 3 | * Copyright (c) 2002 Jeremie Miller, Thomas Muldowney, 4 | * Ryan Eatmon, Robert Norris 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA 19 | */ 20 | 21 | #include "sm.h" 22 | 23 | /** @file sm/mod_iq_time.c 24 | * @brief entity time 25 | * @author Robert Norris 26 | * $Date: 2005/08/17 07:48:28 $ 27 | * $Revision: 1.14 $ 28 | */ 29 | 30 | #ifdef ENABLE_SUPERSEDED 31 | static int ns_TIME = 0; 32 | #endif 33 | static int ns_URN_TIME = 0; 34 | 35 | #ifdef HAVE_TZNAME 36 | extern char *tzname[]; 37 | #endif 38 | 39 | static mod_ret_t _iq_time_pkt_sm(mod_instance_t mi, pkt_t pkt) 40 | { 41 | time_t t; 42 | struct tm *tm; 43 | char buf[64]; 44 | char *c; 45 | 46 | /* we only want to play with iq:time gets */ 47 | #ifdef ENABLE_SUPERSEDED 48 | if(pkt->type != pkt_IQ || (pkt->ns != ns_TIME && pkt->ns != ns_URN_TIME)) 49 | #else 50 | if(pkt->type != pkt_IQ || pkt->ns != ns_URN_TIME) 51 | #endif 52 | return mod_PASS; 53 | 54 | t = time(NULL); 55 | tm = localtime(&t); 56 | #ifdef HAVE_TZSET 57 | tzset(); 58 | #endif 59 | 60 | #ifdef ENABLE_SUPERSEDED 61 | if(pkt->ns == ns_TIME) { 62 | datetime_out(t, dt_LEGACY, buf, 64); 63 | nad_insert_elem(pkt->nad, 2, NAD_ENS(pkt->nad, 1), "utc", buf); 64 | 65 | strcpy(buf, asctime(tm)); 66 | c = strchr(buf, '\n'); 67 | if(c != NULL) 68 | *c = '\0'; 69 | nad_insert_elem(pkt->nad, 2, NAD_ENS(pkt->nad, 1), "display", buf); 70 | #if defined(HAVE_STRUCT_TM_TM_ZONE) 71 | nad_insert_elem(pkt->nad, 2, NAD_ENS(pkt->nad, 1), "tz", (char *) tm->tm_zone); 72 | #elif defined(HAVE_TZNAME) 73 | nad_insert_elem(pkt->nad, 2, NAD_ENS(pkt->nad, 1), "tz", tzname[0]); 74 | #endif 75 | } else { 76 | #endif /* ENABLE_SUPERSEDED */ 77 | 78 | datetime_out(t, dt_DATETIME, buf, 64); 79 | nad_insert_elem(pkt->nad, 2, NAD_ENS(pkt->nad, 1), "utc", buf); 80 | #ifdef HAVE_TZSET 81 | snprintf(buf, 64, "%+03d:%02d", -((int)timezone)/(60*60), -((int)timezone)%(60*60)); 82 | #else 83 | snprintf(buf, 64, "%+03d:%02d", (int) tm->tm_gmtoff/(60*60), (int) tm->tm_gmtoff%(60*60)); 84 | #endif 85 | nad_insert_elem(pkt->nad, 2, NAD_ENS(pkt->nad, 1), "tzo", buf); 86 | 87 | #ifdef ENABLE_SUPERSEDED 88 | } 89 | #endif 90 | /* tell them */ 91 | nad_set_attr(pkt->nad, 1, -1, "type", "result", 6); 92 | pkt_router(pkt_tofrom(pkt)); 93 | 94 | return mod_HANDLED; 95 | } 96 | 97 | static void _iq_time_free(module_t mod) { 98 | sm_unregister_ns(mod->mm->sm, uri_TIME); 99 | feature_unregister(mod->mm->sm, uri_TIME); 100 | } 101 | 102 | DLLEXPORT int module_init(mod_instance_t mi, const char *arg) { 103 | module_t mod = mi->mod; 104 | 105 | if(mod->init) return 0; 106 | 107 | mod->pkt_sm = _iq_time_pkt_sm; 108 | mod->free = _iq_time_free; 109 | 110 | #ifdef ENABLE_SUPERSEDED 111 | ns_TIME = sm_register_ns(mod->mm->sm, uri_TIME); 112 | feature_register(mod->mm->sm, uri_TIME); 113 | #endif 114 | ns_URN_TIME = sm_register_ns(mod->mm->sm, urn_TIME); 115 | feature_register(mod->mm->sm, urn_TIME); 116 | 117 | return 0; 118 | } 119 | -------------------------------------------------------------------------------- /c2s/sm.c: -------------------------------------------------------------------------------- 1 | /* 2 | * jabberd - Jabber Open Source Server 3 | * Copyright (c) 2002 Jeremie Miller, Thomas Muldowney, 4 | * Ryan Eatmon, Robert Norris 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA 19 | */ 20 | 21 | #include "c2s.h" 22 | 23 | /** generate a new session request id */ 24 | static void _sm_generate_id(sess_t sess, bres_t res, const char *type) { 25 | char str[3094]; /* JID=3071 chars max + time = 12 chars max + type = 10 chars max + terminator = 3094 */ 26 | 27 | snprintf(str, 3094, "%s%d%s", type, (int) time(NULL), jid_full(res->jid)); 28 | str[3093] = '\0'; 29 | 30 | shahash_r(str, res->sm_request); 31 | } 32 | 33 | /** make a new action route */ 34 | static nad_t _sm_build_route(sess_t sess, bres_t res, const char *action, const char *target, const char *id) { 35 | nad_t nad; 36 | int ns, ans; 37 | 38 | nad = nad_new(); 39 | 40 | ns = nad_add_namespace(nad, uri_COMPONENT, NULL); 41 | nad_append_elem(nad, ns, "route", 0); 42 | 43 | nad_append_attr(nad, -1, "to", sess->smcomp?sess->smcomp:((char *) res->jid->domain)); 44 | nad_append_attr(nad, -1, "from", sess->c2s->id); 45 | 46 | ans = nad_add_namespace(nad, uri_SESSION, "sc"); 47 | nad_append_elem(nad, ans, "session", 1); 48 | 49 | if(res->c2s_id[0] != '\0') 50 | nad_append_attr(nad, ans, "c2s", res->c2s_id); 51 | if(res->sm_id[0] != '\0') 52 | nad_append_attr(nad, ans, "sm", res->sm_id); 53 | 54 | nad_append_attr(nad, -1, "action", action); 55 | 56 | if(target != NULL) 57 | nad_append_attr(nad, -1, "target", target); 58 | if(id != NULL) 59 | nad_append_attr(nad, -1, "id", id); 60 | 61 | log_debug(ZONE, "built new route nad for %s action %s target %s id %s", jid_full(res->jid), action, target, id); 62 | 63 | return nad; 64 | } 65 | 66 | void sm_start(sess_t sess, bres_t res) { 67 | _sm_generate_id(sess, res, "start"); 68 | 69 | sx_nad_write(sess->c2s->router, _sm_build_route(sess, res, "start", jid_full(res->jid), res->sm_request)); 70 | } 71 | 72 | void sm_end(sess_t sess, bres_t res) { 73 | sx_nad_write(sess->c2s->router, _sm_build_route(sess, res, "end", NULL, NULL)); 74 | } 75 | 76 | void sm_create(sess_t sess, bres_t res) { 77 | _sm_generate_id(sess, res, "create"); 78 | 79 | sx_nad_write(sess->c2s->router, _sm_build_route(sess, res, "create", jid_user(res->jid), res->sm_request)); 80 | } 81 | 82 | void sm_delete(sess_t sess, bres_t res) { 83 | sx_nad_write(sess->c2s->router, _sm_build_route(sess, res, "delete", jid_user(res->jid), NULL)); 84 | } 85 | 86 | void sm_packet(sess_t sess, bres_t res, nad_t nad) { 87 | int ns; 88 | 89 | ns = nad_add_namespace(nad, uri_COMPONENT, NULL); 90 | nad_wrap_elem(nad, 0, ns, "route"); 91 | 92 | nad_set_attr(nad, 0, -1, "to", sess->smcomp?sess->smcomp:((char *) res->jid->domain), 0); 93 | nad_set_attr(nad, 0, -1, "from", sess->c2s->id, 0); 94 | 95 | ns = nad_append_namespace(nad, 1, uri_SESSION, "sc"); 96 | 97 | nad_set_attr(nad, 1, ns, "c2s", res->c2s_id, 0); 98 | if(res->c2s_id[0] != '\0') 99 | nad_set_attr(nad, 1, ns, "sm", res->sm_id, 0); 100 | 101 | sx_nad_write(sess->c2s->router, nad); 102 | } 103 | -------------------------------------------------------------------------------- /router/user.c: -------------------------------------------------------------------------------- 1 | /* 2 | * jabberd - Jabber Open Source Server 3 | * Copyright (c) 2002-2003 Jeremie Miller, Thomas Muldowney, 4 | * Ryan Eatmon, Robert Norris 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA 19 | */ 20 | 21 | #include "router.h" 22 | 23 | /** user table manager */ 24 | 25 | int user_table_load(router_t r) { 26 | const char *userfile; 27 | FILE *f; 28 | long size; 29 | char *buf; 30 | nad_t nad; 31 | int nusers, user, name, secret; 32 | 33 | log_debug(ZONE, "loading user table"); 34 | 35 | if(r->users != NULL) 36 | xhash_free(r->users); 37 | 38 | r->users = xhash_new(51); 39 | 40 | userfile = config_get_one(r->config, "local.users", 0); 41 | if(userfile == NULL) 42 | userfile = CONFIG_DIR "/router-users.xml"; 43 | 44 | f = fopen(userfile, "rb"); 45 | if(f == NULL) { 46 | log_write(r->log, LOG_ERR, "couldn't open user table file %s: %s", userfile, strerror(errno)); 47 | return 1; 48 | } 49 | 50 | fseek(f, 0, SEEK_END); 51 | size = ftell(f); 52 | if(size < 0) { 53 | log_write(r->log, LOG_ERR, "couldn't seek user table file %s: %s", userfile, strerror(errno)); 54 | fclose(f); 55 | return 1; 56 | } 57 | if(size == 0) { 58 | log_write(r->log, LOG_ERR, "empty user table file %s", userfile); 59 | fclose(f); 60 | return 1; 61 | } 62 | fseek(f, 0, SEEK_SET); 63 | 64 | buf = (char *) malloc(sizeof(char) * size); 65 | 66 | if (fread(buf, 1, size, f) != size || ferror(f)) { 67 | log_write(r->log, LOG_ERR, "couldn't read from user table file: %s", strerror(errno)); 68 | free(buf); 69 | fclose(f); 70 | return 1; 71 | } 72 | 73 | fclose(f); 74 | 75 | nad = nad_parse(buf, size); 76 | if(nad == NULL) { 77 | log_write(r->log, LOG_ERR, "couldn't parse user table"); 78 | free(buf); 79 | return 1; 80 | } 81 | 82 | free(buf); 83 | 84 | nusers = 0; 85 | user = nad_find_elem(nad, 0, -1, "user", 1); 86 | while(user >= 0) { 87 | name = nad_find_elem(nad, user, -1, "name", 1); 88 | secret = nad_find_elem(nad, user, -1, "secret", 1); 89 | 90 | if(name < 0 || secret < 0 || NAD_CDATA_L(nad, name) <= 0 || NAD_CDATA_L(nad, secret) <= 0) { 91 | log_write(r->log, LOG_ERR, "malformed user entry in user table file, skipping"); 92 | continue; 93 | } 94 | 95 | log_debug(ZONE, "remembering user '%.*s'", NAD_CDATA_L(nad, name), NAD_CDATA(nad, name)); 96 | 97 | xhash_put(r->users, pstrdupx(xhash_pool(r->users), NAD_CDATA(nad, name), NAD_CDATA_L(nad, name)), pstrdupx(xhash_pool(r->users), NAD_CDATA(nad, secret), NAD_CDATA_L(nad, secret))); 98 | 99 | nusers++; 100 | 101 | user = nad_find_elem(nad, user, -1, "user", 0); 102 | } 103 | 104 | nad_free(nad); 105 | 106 | log_write(r->log, LOG_NOTICE, "loaded user table (%d users)", nusers); 107 | 108 | r->users_load = time(NULL); 109 | 110 | return 0; 111 | } 112 | 113 | void user_table_unload(router_t r) { 114 | 115 | if(r->users != NULL) 116 | xhash_free(r->users); 117 | r->users = NULL; 118 | 119 | return; 120 | } 121 | -------------------------------------------------------------------------------- /subst/dirent.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Implementation of POSIX directory browsing functions and types for Win32. 4 | 5 | Author: Kevlin Henney (kevlin@acm.org, kevlin@curbralan.com) 6 | History: Created March 1997. Updated June 2003. 7 | Rights: See end of file. 8 | 9 | */ 10 | 11 | #ifdef HAVE_CONFIG_H 12 | # include "config.h" 13 | #endif 14 | 15 | #if !defined(HAVE_DIRENT_H) && !defined(HAVE_NDIR_H) && !defined(HAVE_SYS_DIR_H) && !defined(HAVE_SYS_NDIR_H) 16 | #ifdef HAVE__FINDFIRST 17 | 18 | #include "dirent.h" 19 | 20 | #include 21 | #include /* _findfirst and _findnext set errno iff they return -1 */ 22 | #include 23 | #include 24 | 25 | #ifdef __cplusplus 26 | extern "C" 27 | { 28 | #endif 29 | 30 | struct DIR 31 | { 32 | long handle; /* -1 for failed rewind */ 33 | struct _finddata_t info; 34 | struct dirent result; /* d_name null iff first time */ 35 | char *name; /* null-terminated char string */ 36 | }; 37 | 38 | DIR *opendir(const char *name) 39 | { 40 | DIR *dir = 0; 41 | 42 | if(name && name[0]) 43 | { 44 | size_t base_length = strlen(name); 45 | const char *all = /* search pattern must end with suitable wildcard */ 46 | strchr("/\\", name[base_length - 1]) ? "*" : "/*"; 47 | 48 | if((dir = (DIR *) malloc(sizeof *dir)) != 0 && 49 | (dir->name = (char *) malloc(base_length + strlen(all) + 1)) != 0) 50 | { 51 | strcat(strcpy(dir->name, name), all); 52 | 53 | if((dir->handle = (long) _findfirst(dir->name, &dir->info)) != -1) 54 | { 55 | dir->result.d_name = 0; 56 | } 57 | else /* rollback */ 58 | { 59 | free(dir->name); 60 | free(dir); 61 | dir = 0; 62 | } 63 | } 64 | else /* rollback */ 65 | { 66 | free(dir); 67 | dir = 0; 68 | errno = ENOMEM; 69 | } 70 | } 71 | else 72 | { 73 | errno = EINVAL; 74 | } 75 | 76 | return dir; 77 | } 78 | 79 | int closedir(DIR *dir) 80 | { 81 | int result = -1; 82 | 83 | if(dir) 84 | { 85 | if(dir->handle != -1) 86 | { 87 | result = _findclose(dir->handle); 88 | } 89 | 90 | free(dir->name); 91 | free(dir); 92 | } 93 | 94 | if(result == -1) /* map all errors to EBADF */ 95 | { 96 | errno = EBADF; 97 | } 98 | 99 | return result; 100 | } 101 | 102 | struct dirent *readdir(DIR *dir) 103 | { 104 | struct dirent *result = 0; 105 | 106 | if(dir && dir->handle != -1) 107 | { 108 | if(!dir->result.d_name || _findnext(dir->handle, &dir->info) != -1) 109 | { 110 | result = &dir->result; 111 | result->d_name = dir->info.name; 112 | } 113 | } 114 | else 115 | { 116 | errno = EBADF; 117 | } 118 | 119 | return result; 120 | } 121 | 122 | void rewinddir(DIR *dir) 123 | { 124 | if(dir && dir->handle != -1) 125 | { 126 | _findclose(dir->handle); 127 | dir->handle = (long) _findfirst(dir->name, &dir->info); 128 | dir->result.d_name = 0; 129 | } 130 | else 131 | { 132 | errno = EBADF; 133 | } 134 | } 135 | 136 | #ifdef __cplusplus 137 | } 138 | #endif 139 | 140 | #endif 141 | #endif 142 | 143 | /* 144 | 145 | Copyright Kevlin Henney, 1997, 2003. All rights reserved. 146 | 147 | Permission to use, copy, modify, and distribute this software and its 148 | documentation for any purpose is hereby granted without fee, provided 149 | that this copyright and permissions notice appear in all copies and 150 | derivatives. 151 | 152 | This software is supplied "as is" without express or implied warranty. 153 | 154 | But that said, if there are any problems please get in touch. 155 | 156 | */ 157 | -------------------------------------------------------------------------------- /contrib/cyrus-sasl-digest-md5-fix.diff: -------------------------------------------------------------------------------- 1 | Pulled from CVS, Ident strings removed to let the patch apply pretty cleanly. 2 | 3 | =================================================================== 4 | RCS file: /afs/andrew.cmu.edu/system/cvs/src/sasl/plugins/digestmd5.c,v 5 | retrieving revision 1.183 6 | retrieving revision 1.184 7 | diff -u -r1.183 -r1.184 8 | --- src/sasl/plugins/digestmd5.c 2006/11/27 20:41:55 1.183 9 | +++ src/sasl/plugins/digestmd5.c 2007/02/14 17:16:14 1.184 10 | @@ -556,12 +556,17 @@ 11 | return SASL_OK; 12 | } 13 | 14 | +static int is_lws_char (char c) 15 | +{ 16 | + return (c == ' ' || c == HT || c == CR || c == LF); 17 | +} 18 | + 19 | static char *skip_lws (char *s) 20 | { 21 | if (!s) return NULL; 22 | 23 | /* skipping spaces: */ 24 | - while (s[0] == ' ' || s[0] == HT || s[0] == CR || s[0] == LF) { 25 | + while (is_lws_char(s[0])) { 26 | if (s[0] == '\0') break; 27 | s++; 28 | } 29 | @@ -750,17 +755,30 @@ 30 | static void get_pair(char **in, char **name, char **value) 31 | { 32 | char *endpair; 33 | - /* int inQuotes; */ 34 | char *curp = *in; 35 | *name = NULL; 36 | *value = NULL; 37 | 38 | if (curp == NULL) return; 39 | - if (curp[0] == '\0') return; 40 | - 41 | - /* skipping spaces: */ 42 | - curp = skip_lws(curp); 43 | - 44 | + 45 | + while (curp[0] != '\0') { 46 | + /* skipping spaces: */ 47 | + curp = skip_lws(curp); 48 | + 49 | + /* 'LWS "," LWS "," ...' is allowed by the DIGEST-MD5 ABNF */ 50 | + if (curp[0] == ',') { 51 | + curp++; 52 | + } else { 53 | + break; 54 | + } 55 | + } 56 | + 57 | + if (curp[0] == '\0') { 58 | + /* End of the string is not an error */ 59 | + *name = ""; 60 | + return; 61 | + } 62 | + 63 | *name = curp; 64 | 65 | curp = skip_token(curp,1); 66 | @@ -787,22 +805,24 @@ 67 | endpair = unquote (curp); 68 | if (endpair == NULL) { /* Unbalanced quotes */ 69 | *name = NULL; 70 | + *value = NULL; 71 | return; 72 | } 73 | - if (endpair[0] != ',') { 74 | - if (endpair[0]!='\0') { 75 | - *endpair++ = '\0'; 76 | - } 77 | + 78 | + /* An optional LWS is allowed after the value. Skip it. */ 79 | + if (is_lws_char (endpair[0])) { 80 | + /* Remove the trailing LWS from the value */ 81 | + *endpair++ = '\0'; 82 | + endpair = skip_lws(endpair); 83 | } 84 | - 85 | - endpair = skip_lws(endpair); 86 | - 87 | + 88 | /* syntax check: MUST be '\0' or ',' */ 89 | if (endpair[0] == ',') { 90 | endpair[0] = '\0'; 91 | endpair++; /* skipping <,> */ 92 | } else if (endpair[0] != '\0') { 93 | *name = NULL; 94 | + *value = NULL; 95 | return; 96 | } 97 | 98 | @@ -2090,9 +2110,17 @@ 99 | char *name = NULL, *value = NULL; 100 | get_pair(&in, &name, &value); 101 | 102 | - if (name == NULL) 103 | - break; 104 | + if (name == NULL) { 105 | + SETERROR(sparams->utils, 106 | + "Parse error"); 107 | + result = SASL_BADAUTH; 108 | + goto FreeAllMem; 109 | + } 110 | 111 | + if (*name == '\0') { 112 | + break; 113 | + } 114 | + 115 | /* Extracting parameters */ 116 | 117 | /* 118 | @@ -3222,10 +3250,14 @@ 119 | /* if parse error */ 120 | if (name == NULL) { 121 | params->utils->seterror(params->utils->conn, 0, "Parse error"); 122 | - result = SASL_FAIL; 123 | + result = SASL_BADAUTH; 124 | goto FreeAllocatedMem; 125 | } 126 | 127 | + if (*name == '\0') { 128 | + break; 129 | + } 130 | + 131 | if (strcasecmp(name, "realm") == 0) { 132 | nrealm++; 133 | 134 | @@ -3887,9 +3919,14 @@ 135 | if (name == NULL) { 136 | params->utils->seterror(params->utils->conn, 0, 137 | "DIGEST-MD5 Received Garbage"); 138 | + result = SASL_BADAUTH; 139 | break; 140 | } 141 | 142 | + if (*name == '\0') { 143 | + break; 144 | + } 145 | + 146 | if (strcasecmp(name, "rspauth") == 0) { 147 | 148 | if (strcmp(text->response_value, value) != 0) { 149 | -------------------------------------------------------------------------------- /util/xdata.h: -------------------------------------------------------------------------------- 1 | /* 2 | * jabberd - Jabber Open Source Server 3 | * Copyright (c) 2002-2003 Jeremie Miller, Thomas Muldowney, 4 | * Ryan Eatmon, Robert Norris 5 | * 6 | * This program is free software; you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation; either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program; if not, write to the Free Software 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA 19 | */ 20 | 21 | /* prototypes for xdata */ 22 | 23 | #ifndef INCL_XDATA_H 24 | #define INCL_XDATA_H 25 | 26 | #include "util.h" 27 | 28 | typedef struct _xdata_st *xdata_t; 29 | typedef struct _xdata_field_st *xdata_field_t; 30 | typedef struct _xdata_option_st *xdata_option_t; 31 | typedef struct _xdata_item_st *xdata_item_t; 32 | 33 | typedef enum { 34 | xd_type_NONE, 35 | xd_type_FORM, 36 | xd_type_RESULT, 37 | xd_type_SUBMIT, 38 | xd_type_CANCEL 39 | } xdata_type_t; 40 | 41 | struct _xdata_st { 42 | pool_t p; 43 | 44 | xdata_type_t type; 45 | 46 | char *title; 47 | char *instructions; 48 | 49 | xdata_field_t fields, flast; 50 | xdata_field_t rfields, rflast; /* reported fields */ 51 | 52 | xdata_item_t items, ilast; 53 | }; 54 | 55 | typedef enum { 56 | xd_field_NONE, 57 | xd_field_BOOLEAN, 58 | xd_field_FIXED, 59 | xd_field_HIDDEN, 60 | xd_field_JID_MULTI, 61 | xd_field_JID_SINGLE, 62 | xd_field_LIST_MULTI, 63 | xd_field_LIST_SINGLE, 64 | xd_field_TEXT_MULTI, 65 | xd_field_TEXT_PRIVATE, 66 | xd_field_TEXT_SINGLE 67 | } xdata_field_type_t; 68 | 69 | struct _xdata_field_st { 70 | pool_t p; 71 | 72 | xdata_field_type_t type; 73 | 74 | char *var; 75 | 76 | char *label; 77 | 78 | char *desc; 79 | 80 | int required; 81 | 82 | char **values; 83 | int nvalues; 84 | 85 | xdata_option_t options, olast; 86 | 87 | xdata_field_t next; 88 | }; 89 | 90 | struct _xdata_option_st { 91 | pool_t p; 92 | 93 | char *label; 94 | char *value; 95 | 96 | xdata_option_t next; 97 | }; 98 | 99 | struct _xdata_item_st { 100 | pool_t p; 101 | 102 | xdata_field_t fields, flast; 103 | 104 | xdata_item_t next; 105 | }; 106 | 107 | /** creation */ 108 | JABBERD2_API xdata_t xdata_new(xdata_type_t type, const char *title, const char *instructions); 109 | JABBERD2_API xdata_t xdata_parse(nad_t nad, int root); 110 | 111 | /** new field */ 112 | JABBERD2_API xdata_field_t xdata_field_new(xdata_t xd, xdata_field_type_t type, const char *var, const char *label, const char *desc, int required); 113 | 114 | /** new item */ 115 | JABBERD2_API xdata_item_t xdata_item_new(xdata_t xd); 116 | 117 | /** field insertion */ 118 | JABBERD2_API void xdata_add_field(xdata_t xd, xdata_field_t xdf); 119 | JABBERD2_API void xdata_add_rfield(xdata_t xd, xdata_field_t xdf); 120 | JABBERD2_API void xdata_add_field_item(xdata_item_t item, xdata_field_t xdf); 121 | 122 | /** item insertion */ 123 | JABBERD2_API void xdata_add_item(xdata_t xd, xdata_item_t xdi); 124 | 125 | /** option insertion */ 126 | JABBERD2_API void xdata_add_option(xdata_field_t xdf, const char *value, int lvalue, const char *label, int llabel); 127 | 128 | /** value insertion */ 129 | JABBERD2_API void xdata_add_value(xdata_field_t xdf, const char *value, int vlen); 130 | 131 | #endif 132 | -------------------------------------------------------------------------------- /util/pool.h: -------------------------------------------------------------------------------- 1 | /* 2 | * jabberd - Jabber Open Source Server 3 | * Pool-based memory management routines. 4 | * 5 | * Copyright (c) 2002-2004 Jeremie Miller, Thomas Muldowney, 6 | * Ryan Eatmon, Robert Norris 7 | * 8 | * This program is free software; you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation; either version 2 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program; if not, write to the Free Software 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA 21 | */ 22 | 23 | #ifndef INCL_UTIL_POOL_H 24 | #define INCL_UTIL_POOL_H 1 25 | 26 | #ifdef HAVE_CONFIG_H 27 | # include 28 | #endif 29 | 30 | /* jabberd2 Windows DLL */ 31 | #ifndef JABBERD2_API 32 | # ifdef _WIN32 33 | # ifdef JABBERD2_EXPORTS 34 | # define JABBERD2_API __declspec(dllexport) 35 | # else /* JABBERD2_EXPORTS */ 36 | # define JABBERD2_API __declspec(dllimport) 37 | # endif /* JABBERD2_EXPORTS */ 38 | # else /* _WIN32 */ 39 | # define JABBERD2_API extern 40 | # endif /* _WIN32 */ 41 | #endif /* JABBERD2_API */ 42 | 43 | #ifdef POOL_DEBUG 44 | /* prime number for top # of pools debugging */ 45 | #define POOL_NUM 40009 46 | #endif 47 | 48 | /** 49 | * pool_cleanup_t - callback type which is associated 50 | * with a pool entry; invoked when the pool entry is 51 | * free'd 52 | **/ 53 | typedef void (*pool_cleanup_t)(void *arg); 54 | 55 | /** 56 | * pheap - singular allocation of memory 57 | **/ 58 | struct pheap 59 | { 60 | void *block; 61 | int size, used; 62 | }; 63 | 64 | /** 65 | * pfree - a linked list node which stores an 66 | * allocation chunk, plus a callback 67 | **/ 68 | struct pfree 69 | { 70 | pool_cleanup_t f; 71 | void *arg; 72 | struct pheap *heap; 73 | struct pfree *next; 74 | }; 75 | 76 | /** 77 | * pool - base node for a pool. Maintains a linked list 78 | * of pool entries (pfree) 79 | **/ 80 | typedef struct pool_struct 81 | { 82 | int size; 83 | struct pfree *cleanup; 84 | struct pfree *cleanup_tail; 85 | struct pheap *heap; 86 | #ifdef POOL_DEBUG 87 | char name[8], zone[32]; 88 | int lsize; 89 | #endif 90 | } _pool, *pool_t; 91 | 92 | #ifdef POOL_DEBUG 93 | # define pool_new() _pool_new(__FILE__,__LINE__) 94 | # define pool_heap(i) _pool_new_heap(i,__FILE__,__LINE__) 95 | #else 96 | # define pool_heap(i) _pool_new_heap(i,NULL,0) 97 | # define pool_new() _pool_new(NULL,0) 98 | #endif 99 | 100 | JABBERD2_API pool_t _pool_new(const char *file, int line); /* new pool :) */ 101 | JABBERD2_API pool_t _pool_new_heap(int size, const char *file, int line); /* creates a new memory pool with an initial heap size */ 102 | JABBERD2_API void *pmalloc(pool_t, int size); /* wrapper around malloc, takes from the pool, cleaned up automatically */ 103 | JABBERD2_API void *pmalloc_x(pool_t p, int size, char c); /* Wrapper around pmalloc which prefils buffer with c */ 104 | JABBERD2_API void *pmalloco(pool_t p, int size); /* YAPW for zeroing the block */ 105 | JABBERD2_API char *pstrdup(pool_t p, const char *src); /* wrapper around strdup, gains mem from pool */ 106 | JABBERD2_API char *pstrdupx(pool_t p, const char *src, int len); /* use given len */ 107 | JABBERD2_API void pool_stat(int full); /* print to stderr the changed pools and reset */ 108 | JABBERD2_API void pool_cleanup(pool_t p, pool_cleanup_t fn, void *arg); /* calls f(arg) before the pool is freed during cleanup */ 109 | JABBERD2_API void pool_free(pool_t p); /* calls the cleanup functions, frees all the data on the pool, and deletes the pool itself */ 110 | JABBERD2_API int pool_size(pool_t p); /* returns total bytes allocated in this pool */ 111 | 112 | 113 | #endif 114 | -------------------------------------------------------------------------------- /tools/jabberd.rc: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Raymond 25DEC2003 support@bigriverinfotech.com 4 | # /etc/rc.d/init.d/jabberd2 5 | # init script for jabberd2 processes 6 | # Tested under jabberd-2.0rc2 and Fedora 1.0 only 7 | # 8 | # processname: jabberd2 9 | # description: jabberd2 is the next generation of the jabberd server 10 | # chkconfig: 2345 85 15 11 | # 12 | if [ -f /etc/init.d/functions ]; then 13 | . /etc/init.d/functions 14 | elif [ -f /etc/rc.d/init.d/functions ]; then 15 | . /etc/rc.d/init.d/functions 16 | else 17 | echo -e "\ajabberd2: unable to locate functions lib. Cannot continue." 18 | exit -1 19 | fi 20 | # 21 | progs="router sm c2s s2s" 22 | progsPath="/usr/local/bin" 23 | confPath="/usr/local/etc/jabberd" 24 | pidPath="/usr/local/var/jabberd/pid" 25 | statusCol="echo -ne \\033[60G" 26 | statusColorOK="echo -ne \\033[1;32m" 27 | statusColorFailed="echo -ne \\033[1;31m" 28 | statusColorNormal="echo -ne \\033[0;39m" 29 | retval=0 30 | # 31 | StatusOK ( ) { 32 | ${statusCol} 33 | echo -n "[ " 34 | ${statusColorOK} 35 | echo -n "OK" 36 | ${statusColorNormal} 37 | echo " ]" 38 | return 0 39 | } 40 | # 41 | StatusFailed ( ) { 42 | echo -ne "\a" 43 | ${statusCol} 44 | echo -n "[" 45 | ${statusColorFailed} 46 | echo -n "FAILED" 47 | ${statusColorNormal} 48 | echo "]" 49 | return 0 50 | } 51 | # 52 | ReqBins ( ) { 53 | for prog in ${progs}; do 54 | if [ ! -x ${progsPath}/${prog} ]; then 55 | echo -n "jabberd2 binary [${prog}] not found." 56 | StatusFailed 57 | echo "Cannot continue." 58 | return -1 59 | fi 60 | done 61 | return 0 62 | } 63 | # 64 | ReqConfs ( ) { 65 | for prog in ${progs}; do 66 | if [ ! -f ${confPath}/${prog}.xml ]; then 67 | echo -n "jabberd2 configuration [${prog}.xml] not found." 68 | StatusFailed 69 | echo "Cannot continue." 70 | return -1 71 | fi 72 | done 73 | return 0 74 | } 75 | # 76 | ReqDirs ( ) { 77 | if [ ! -d ${pidPath} ]; then 78 | echo -n "jabberd2 PID directory not found. Cannot continue." 79 | StatusFailed 80 | return -1 81 | fi 82 | return 0 83 | } 84 | # 85 | Start ( ) { 86 | for req in ReqBins ReqConfs ReqDirs; do 87 | ${req} 88 | retval=$? 89 | [ ${retval} == 0 ] || return ${retval} 90 | done 91 | echo "Initializing jabberd2 processes ..." 92 | for prog in ${progs}; do 93 | if [ $( pidof -s ${prog} ) ]; then 94 | echo -ne "\tprocess [${prog}] already running" 95 | StatusFailed 96 | sleep 1 97 | continue 98 | fi 99 | echo -ne "\tStarting ${prog}: " 100 | if [ ${prog} == "router" ]; then 101 | ports="5347" 102 | elif [ ${prog} == "c2s" ]; then 103 | ports="5222 5223" 104 | elif [ ${prog} == "s2s" ]; then 105 | ports="5269" 106 | else 107 | ports="" 108 | fi 109 | for port in ${ports}; do 110 | if [ $( netstat --numeric-ports --listening --protocol=inet | 111 | gawk '{ print $4 }' | 112 | gawk -F : '{ print $NF }' | 113 | grep -c ${port}$ ) -ne "0" ]; then 114 | StatusFailed 115 | echo -e "\tPort ${port} is currently in use. Cannot continue" 116 | echo -e "\tIs a Jabber 1.x server running?" 117 | Stop 118 | let retval=-1 119 | break 2 120 | fi 121 | done 122 | rm -f /var/lock/subsys/${prog} 123 | rm -f ${pidPath}/${prog}.pid 124 | args="-c ${confPath}/${prog}.xml" 125 | ${progsPath}/${prog} ${args} >/dev/null 2>&1 <&1 & 126 | retval=$? 127 | if [ ${retval} == 0 ]; then 128 | StatusOK 129 | touch /var/lock/subsys/${prog} 130 | else 131 | StatusFailed 132 | Stop 133 | let retval=-1 134 | break 135 | fi 136 | sleep 1 137 | done 138 | return ${retval} 139 | } 140 | # 141 | Stop ( ) { 142 | echo "Terminating jabberd2 processes ..." 143 | for prog in ${progs}; do 144 | echo -ne "\tStopping ${prog}: " 145 | killproc ${prog} 146 | retval=$? 147 | if [ ${retval} == 0 ]; then 148 | rm -f /var/lock/subsys/${prog} 149 | rm -f ${pidPath}/${prog}.pid 150 | fi 151 | echo 152 | sleep 1 153 | done 154 | return ${retval} 155 | } 156 | # 157 | case "$1" in 158 | start) 159 | Start 160 | ;; 161 | stop) 162 | Stop 163 | ;; 164 | restart) 165 | Stop 166 | Start 167 | ;; 168 | condrestart) 169 | if [ -f /var/lock/subsys/${prog} ]; then 170 | Stop 171 | sleep 3 172 | Start 173 | fi 174 | ;; 175 | *) 176 | echo "Usage: $0 {start|stop|restart|condrestart}" 177 | let retval=-1 178 | esac 179 | exit ${retval} 180 | # 181 | # eof 182 | -------------------------------------------------------------------------------- /subst/syslog.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2001 Internet Software Consortium. 3 | * 4 | * Permission to use, copy, modify, and distribute this software for any 5 | * purpose with or without fee is hereby granted, provided that the above 6 | * copyright notice and this permission notice appear in all copies. 7 | * 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM 9 | * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL 10 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL 11 | * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, 12 | * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING 13 | * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, 14 | * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION 15 | * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | */ 17 | 18 | /* $Id: syslog.c,v 1.5 2005/06/02 04:48:25 zion Exp $ */ 19 | 20 | #ifdef HAVE_CONFIG_H 21 | # include "config.h" 22 | #endif 23 | 24 | #if !defined(HAVE_SYSLOG_H) && defined(HAVE_REPORTEVENT) 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include "syslog.h" 32 | 33 | static HANDLE hAppLog = NULL; 34 | static FILE *log_stream; 35 | static int debug_level = 0; 36 | 37 | static struct dsn_c_pvt_sfnt { 38 | int val; 39 | const char *strval; 40 | } facilities[] = { 41 | { LOG_KERN, "kern" }, 42 | { LOG_USER, "user" }, 43 | { LOG_MAIL, "mail" }, 44 | { LOG_DAEMON, "daemon" }, 45 | { LOG_AUTH, "auth" }, 46 | { LOG_SYSLOG, "syslog" }, 47 | { LOG_LPR, "lpr" }, 48 | #ifdef LOG_NEWS 49 | { LOG_NEWS, "news" }, 50 | #endif 51 | #ifdef LOG_UUCP 52 | { LOG_UUCP, "uucp" }, 53 | #endif 54 | #ifdef LOG_CRON 55 | { LOG_CRON, "cron" }, 56 | #endif 57 | #ifdef LOG_AUTHPRIV 58 | { LOG_AUTHPRIV, "authpriv" }, 59 | #endif 60 | #ifdef LOG_FTP 61 | { LOG_FTP, "ftp" }, 62 | #endif 63 | { LOG_LOCAL0, "local0"}, 64 | { LOG_LOCAL1, "local1"}, 65 | { LOG_LOCAL2, "local2"}, 66 | { LOG_LOCAL3, "local3"}, 67 | { LOG_LOCAL4, "local4"}, 68 | { LOG_LOCAL5, "local5"}, 69 | { LOG_LOCAL6, "local6"}, 70 | { LOG_LOCAL7, "local7"}, 71 | { LOG_USER, "log_user"}, 72 | { 0, NULL } 73 | }; 74 | 75 | /* 76 | * Log to the NT Event Log 77 | */ 78 | void 79 | syslog(int level, const char *fmt, ...) { 80 | va_list ap; 81 | char buf[1024]; 82 | const char *str[1]; 83 | 84 | str[0] = buf; 85 | 86 | va_start(ap, fmt); 87 | vsprintf(buf, fmt, ap); 88 | va_end(ap); 89 | 90 | /* Make sure that the channel is open to write the event */ 91 | if (hAppLog != NULL) { 92 | switch (level) { 93 | case LOG_INFO: 94 | case LOG_NOTICE: 95 | case LOG_DEBUG: 96 | ReportEvent(hAppLog, EVENTLOG_INFORMATION_TYPE, 0, 97 | 0, NULL, 1, 0, str, NULL); 98 | break; 99 | case LOG_WARNING: 100 | ReportEvent(hAppLog, EVENTLOG_WARNING_TYPE, 0, 101 | 0, NULL, 1, 0, str, NULL); 102 | break; 103 | default: 104 | ReportEvent(hAppLog, EVENTLOG_ERROR_TYPE, 0, 105 | 0, NULL, 1, 0, str, NULL); 106 | break; 107 | } 108 | } 109 | } 110 | 111 | /* 112 | * Initialize event logging 113 | */ 114 | void 115 | openlog(const char *name, int flags, ...) { 116 | /* Get a handle to the Application event log */ 117 | hAppLog = RegisterEventSource(NULL, name); 118 | } 119 | 120 | /* 121 | * Close the Handle to the application Event Log 122 | * We don't care whether or not we succeeded so ignore return values 123 | * In fact if we failed then we would have nowhere to put the message 124 | */ 125 | void 126 | closelog() { 127 | DeregisterEventSource(hAppLog); 128 | } 129 | 130 | #endif 131 | --------------------------------------------------------------------------------