Commit Graph

357 Commits

Author SHA1 Message Date
Holger Weiss 277e1dc3ff Offer CSI stream feature only if configured
Don't offer the CSI stream feature when mod_client_state isn't actually
configured to filter stanzas.  This makes sure clients won't send CSI
tags that end up being ignored.
2014-09-25 18:28:20 +02:00
Holger Weiss 56175fef1b Add new hook: c2s_post_auth_features
The c2s_post_auth_features hook can be used to extend the list of stream
features offered after authentication.
2014-09-25 18:15:33 +02:00
Holger Weiss 7aec0337e1 Remove invisible presence fields from c2s #state
Invisible presence isn't supported anymore, so the corresponding
ejabberd_c2s #state fields were unused.
2014-09-25 00:08:56 +02:00
Holger Weiss 0a9212583d XEP-0198: Support "resend_on_timeout: if_offline"
If "resend_on_timeout" is set to "if_offline", resend unacknowledged
stanzas only if no other resource is online when the session times out.
In other words, allow for sending them to offline storage, but nowhere
else.
2014-09-16 22:42:34 +02:00
Holger Weiss b8c98232b8 Support XEP-0352: Client State Indication 2014-09-11 17:44:29 +02:00
Evgeny Khramtsov 7a48e30523 Merge pull request #296 from weiss/remove-unused-clause
XEP-0198: Remove unused function clause
2014-09-07 07:27:17 +04:00
Holger Weiss 2ca563e328 XEP-0198: Remove unused function clause
In the 'wait_for_resume' state, #state.mgmt_pending_since is always
initialized.  fsm_next_state/2 takes care of that.
2014-09-06 20:39:38 +02:00
Holger Weiss 2e169167d4 XEP-0198: Change state on gen_tcp:send/2 failure
When Stream Management is enabled and a gen_tcp:send/2 call fails, go
into the 'wait_for_resume' state immediately.  This makes sure that
gen_tcp:send/2 won't be called again, which might avoid an Erlang issue
where gen_tcp:send/2 apparently hangs despite 'send_timeout' (and
'send_timeout_close') being set.
2014-09-06 20:34:32 +02:00
Holger Weiss 11b2921971 XEP-0198: Let fsm_next_state/2 check timeout value
Don't force the fsm_next_state/2 caller to check for 'mgmt_timeout = 0'.
2014-09-06 20:29:02 +02:00
Evgeniy Khramtsov fda73c3d16 Fix privacy checks of presence probes 2014-09-01 16:39:02 +04:00
Evgeniy Khramtsov a1ce33ebf8 Automatically remove IPs from ban, add the documentation 2014-08-27 13:25:49 +04:00
Evgeniy Khramtsov 2430e6691b Add mod_fail2ban 2014-08-27 13:17:56 +04:00
Holger Weiss 2802b6cee2 Allow for "max_ack_queue: infinity", as documented 2014-08-20 12:53:26 +02:00
Holger Weiss 2d4c39cd54 XEP-0198: Create shorter resume IDs
Omit the user and server name from the 'previd' value.
2014-08-15 10:56:59 +02:00
Holger Weiss 848e1497d1 XEP-0198: Gracefully handle broken 'previd'
Produce a proper error message instead of crashing when the 'previd'
value of a <resume/> request has an unexpected format.
2014-08-15 01:54:41 +02:00
Holger Weiss 2daf95e93f XEP-0198: Gracefully handle wrong credentials
Produce a proper error message instead of crashing when the JID encoded
in the 'previd' value of a <resume/> request is different from the
authenticated JID.
2014-08-15 01:53:47 +02:00
Evgeniy Khramtsov 3d3a4f7543 Fix events broadcasting via C2S 2014-07-22 19:42:49 +04:00
Holger Weiss 0cb9ea3643 XEP-0198: Cosmetic change: Reuse event handler
On stanza queue overflow, pass a message to self() using the exclamation
mark operator instead of send_all_state_event/2.  This allows for
reusing the existing handler for 'kick' events.
2014-05-28 11:24:38 +02:00
Holger Weiss 99ca8281fa XEP-0198: Terminate session on queue overflow
On queue overflow, terminate the c2s session instead of just dropping
items from the queue.  This makes sure all stanzas are either delivered
or bounced.
2014-05-27 22:56:33 +02:00
Evgeny Khramtsov 3a27b1dd0c Merge pull request #226 from weiss/simplify-state-change
XEP-0198: Cosmetic change: Simplify state change
2014-05-27 23:30:30 +04:00
Holger Weiss 50a4c5a6ab XEP-0198: Cosmetic change: Simplify state change
When the FSM goes into the 'wait_for_resume' state, let fsm_next_state/2
take care of updating #state.mgmt_state and of writing the log line.
This doesn't change the behavior, but simplifies the code.
2014-05-27 21:14:49 +02:00
Holger Weiss ed0c89f876 Let ejabberd_c2s always use fsm_next_state/2
Make sure any logic implemented in ejabberd_c2s:fsm_next_state/2 is
always applied.
2014-05-27 21:07:53 +02:00
Evgeny Khramtsov 702cddd4ff Merge pull request #220 from weiss/handle-send-failure
XEP-0198: Don't exit on socket send failure
2014-05-27 15:44:04 +04:00
Evgeny Khramtsov 4d1332c30f Merge pull request #222 from weiss/keep-session-on-failed-resume
XEP-0198: Don't drop session on failed resume
2014-05-27 15:38:26 +04:00
Evgeny Khramtsov 402fb9665d Merge pull request #221 from weiss/omit-redundant-guard
XEP-0198: Cosmetic change: Omit redundant guard
2014-05-27 15:34:34 +04:00
Evgeny Khramtsov b2e84405c1 Merge pull request #218 from weiss/omit-iq-xmlns
Omit XML namespace declaration for <iq/> stanzas
2014-05-27 15:32:02 +04:00
Holger Weiss 59f6efeaf7 XEP-0198: Don't drop session on failed resume
The 'previd' value provided by the client during a session resume
request includes the client's JID and ejabberd's session ID.  If there
is a session for the requested JID but with a different session ID,
resumption should fail, but that session shouldn't be closed.  This
commit makes sure the latter won't happen.

In practice, this will only make a difference in odd corner cases.
2014-05-23 23:38:04 +02:00
Holger Weiss 737b0ae5dc XEP-0198: Cosmetic change: Omit redundant guard
The stream management state is never 'pending' when the c2s FSM is in
the 'session_established' state.
2014-05-23 20:46:17 +02:00
Holger Weiss ab9667f917 XEP-0198: Don't exit on socket send failure
If stream management is enabled, don't exit the c2s process when
ejabberd_socket:send/2 fails, but close the socket instead.  This gives
the client a chance to resume the session.

Thanks go to Matthias Rieber for reporting the issue, providing detailed
logs, and testing the fix.
2014-05-23 11:38:54 +02:00
Badlop 735bd95659 Merge branch 'check-packet-type' of git://github.com/weiss/ejabberd into weiss-check-packet-type
Conflicts:
	src/ejabberd_c2s.erl
2014-05-21 18:45:28 +02:00
Holger Weiss 6b996061a2 Omit XML namespace declaration for <iq/> stanzas
Only the child elements of <iq/> stanzas are qualified by the namespaces
in question, not the <iq/> stanzas themselves.

This change just clarifies the code.  It doesn't alter the behaviour, as
those <iq/> stanzas are handed over to jlib:iq_to_xml/1, and that
function ignores the 'xmlns' attribute anyway.
2014-05-21 00:07:57 +02:00
Radosław Szymczyszyn 5726636053 Fix check_from/2 formatting 2014-05-20 12:31:28 +01:00
Radosław Szymczyszyn b7a542e074 Sanitize copy-pasted get_statustag/1 2014-05-20 12:28:14 +01:00
Radosław Szymczyszyn 9c37450fe4 Fix formatting 2014-05-20 12:26:33 +01:00
Radosław Szymczyszyn c39ce133de Build proceed/compressed elements in a sane way 2014-05-20 11:52:02 +01:00
Holger Weiss 6e8dd5bdff Don't miss incoming presence updates 2014-05-14 01:04:38 +02:00
Holger Weiss f6da708b02 XEP-0198: Check whether routed packets are stanzas
Only stanzas are subject to stream management, so when XEP-0198 support
is enabled, we must distinguish them from non-stanza elements.  This
commit adds a send_packet/2 function that can be used in place of
send_stanza/2 or send_element/2 whenever a packet is delivered that
might or might not be a stanza.
2014-05-12 19:20:25 +02:00
Holger Weiss 9121ca14de Rename disconnect_user/2 command
The mod_admin_extra module provides a kick_session/4 command.  Rename
the disconnect_user/2 command to kick_user/2 for consistency.
2014-05-12 12:44:40 +02:00
Holger Weiss 6d5bfcfe9b XEP-0198: Improve handling of too large 'h' values
If the client says that it handled more stanzas than we sent (due to a
bug in the client's or in our code), increase our outgoing stanza count
accordingly.  There's no point in sticking to the old value even if it
was correct, as the client surely won't fix its count during the current
session.
2014-05-09 18:28:14 +02:00
Holger Weiss 15369ff9d7 XEP-0198: Reject <resume/> with negative 'h' value
Make sure the 'h' attribute sent with a <resume/> request is
nonnegative, as mandated by XEP-0198.

We already have this check for <a/> elements.
2014-05-09 18:01:31 +02:00
Holger Weiss a60fda7df4 XEP-0198: Don't warn on invalid ACK elements
Do not log a warning (but only a debug message) if the client sends an
invalid </a> packet.  Some clients do that occasionally, and there's
nothing server admininistrators could do about that.
2014-05-09 17:54:12 +02:00
Holger Weiss d343447cc9 Merge remote-tracking branch 'processone/master' into xep-0198
Conflicts:
	doc/guide.tex
	src/ejabberd_c2s.erl
2014-05-06 21:41:29 +02:00
Holger Weiss 8b1f92575a XEP-0198: Use "mgmt_" prefix for all #state fields
Prefix all ejabberd_c2s #state fields that are used for stream
management with "mgmt_".
2014-05-06 07:27:10 +02:00
Holger Weiss 3b3f3b9131 XEP-0198: Don't log protocol issues
There are corner cases where certain clients acknowledge more stanzas
than they received.  Nothing really bad will happen in those cases, and
server administrators can't do anything about such issues anyway.
2014-05-05 01:11:14 +02:00
Holger Weiss 32abcbca6c XEP-0198: Accept stream elements in pending state
Due to timing issues, ejabberd_c2s might receive stream elements from
the client while the session is waiting for stream resumption.  Those
elements are now accepted.
2014-05-05 00:02:55 +02:00
Holger Weiss a0917a8e9b XEP-0198: Log message when waiting for resumption
Log an informational message when a session goes into the pending state
(waiting for resumption) after the connection was lost.  Administrators
may well be interested in this state change when looking into issues.
2014-05-04 23:08:42 +02:00
Evgeny Khramtsov c545b3de6d Merge pull request #178 from hamano/devel
undefined ejabberd_socket:get_conn_type/1
2014-04-30 21:49:54 +04:00
Holger Weiss ebbceab93f Translate disconnect_user/2 string sent to client 2014-04-29 11:56:28 +02:00
Holger Weiss bb2c8b59f8 Avoid #state.lang type errors in corner cases
If #state.lang is used before being initialized to some binary string,
the translation code would crash.
2014-04-29 11:41:24 +02:00
Holger Weiss a21d2298af XEP-0198: Turn some warnings into info messages
Don't log warnings on events that will happen during normal operation.
2014-04-28 01:01:30 +02:00
HAMANO Tsukasa 219f9276d1 undefined ejabberd_socket:get_conn_type/1 2014-04-24 12:42:22 +09:00
Alexey Shchepin f93758a3cd Merge pull request #160 from runcom/protocol_options
Add option to specify openssl options
2014-04-15 19:01:21 +04:00
badlop 285c4c17cf Merge pull request #146 from jamielinux/master
Update FSF address
2014-04-11 13:35:46 +02:00
Antonio Murdaca fbf71f86f3 Add option to specify openssl options 2014-04-08 18:46:52 +02:00
Holger Weiss c114eb3736 XEP-0198: Don't bounce/resend forwarded messages
On connection timeout, drop any messages that were forwarded by some
encapsulating protocol, such as XEP-0280 carbon copies or XEP-0313
archive messages.  Bouncing or resending them could easily lead to
unexpected results.
2014-04-07 21:21:11 +02:00
Badlop ac0e199d36 Provide meaningful text to user when admin kicks session (EJAB-1455) 2014-03-26 16:01:37 +01:00
Holger Weiss a97c716352 XEP-0198: Bounce unacked stanzas by default
If the new "resend_on_timeout" option is set to false (which it is by
default), bounce any unacknowledged stanzas instead of re-routing them.
2014-03-25 23:23:38 +01:00
Holger Weiss 2da6933bb7 Remove "fun" element from c2s #state
Memory consumption wise, local "fun" references are quite expensive.
2014-03-22 20:25:43 +01:00
Holger Weiss e360c56f87 Support XEP-0198 session resumption
Implement the optional session resumption feature described in XEP-0198.
A client that supports this feature may now resume the previous session
(within a configurable number of seconds) if the connection was lost.
During resumption, ejabberd will retransmit any stanzas that hadn't been
acknowledged by the client.
2014-03-19 00:51:33 +01:00
Holger Weiss 88a200e100 Remove some commented out code
The code that had been commented out at some earlier point in time would
now break XEP-0198.
2014-03-16 00:12:47 +01:00
Badlop 633d47f784 Update copyright dates to 2014 (EJAB-1679) 2014-03-13 12:30:57 +01:00
Holger Weiss 7d594086c3 Add initial XEP-0198 support (EJAB-532)
Implement partial support for XEP-0198: Stream Management.  After
successful negotiation of this feature, the server requests an ACK for
each stanza transmitted to the client and responds to ACK requests
issued by the client.  On session termination, the server re-routes any
unacknowledged stanzas.  The length of the pending queue can be limited
by setting the "max_ack_queue" option to some integer value (default:
500).  XEP-0198 support can be disabled entirely by setting the
"stream_management" option to false (default: true).

So far, stream management is implemented only for c2s connections, and
the optional stream resumption feature also described in XEP-0198 is not
(yet) supported.

This addition was originally based on a patch provided by Magnus Henoch
and updated by Grzegorz Grasza.  Their code implements an early draft of
XEP-0198 for some previous version of ejabberd.  It has since been
rewritten almost entirely.
2014-03-12 23:34:14 +01:00
Jamie Nguyen 8538997d61 Update FSF address 2014-02-22 10:27:40 +00:00
Alexey Shchepin 9422164dda Clear SASL state after finishing auth 2014-01-21 13:44:29 +02:00
Alexey Shchepin cbbfd921b4 Fix for the previous commit 2014-01-21 11:54:18 +02:00
Alexey Shchepin d63be79df9 Use 'to' field only in the first client stream initialization 2014-01-20 16:06:05 +02:00
Badlop 5a1300bc70 Add access rule to mod_roster (EJAB-72) 2013-12-04 14:57:44 +01:00
Alexey Shchepin 1dd94ac0d0 Support for OpenSSL ciphers list in ejabberd_c2s, ejabberd_s2s_in and ejabberd_s2s_out 2013-11-28 19:39:11 +02:00
Evgeniy Khramtsov 91a74e3e27 Change configuration file format to YAML 2013-08-21 22:17:59 +10:00
Evgeniy Khramtsov a2ead99c83 Make it possible to enable/disable TLS compression 2013-07-17 22:46:18 +10:00
Evgeniy Khramtsov f9390f3e9a Fix some dialyzer warnings 2013-06-24 20:04:56 +10:00
Evgeniy Khramtsov 4dc80dddd4 Fix all calls to functions of p1_tls application 2013-06-20 18:40:44 +10:00
Alexey Shchepin 862a08e9eb Fixed conversion to ezlib 2013-06-17 16:33:25 +03:00
Evgeniy Khramtsov 7865c6a146 Don't include sub-elements in IQ results where it's not required
by the corresponding spec (RFC or XEP).
2013-06-17 16:09:54 +03:00
Evgeniy Khramtsov 4d8f770624 Switch to rebar build tool
Use dynamic Rebar configuration
Make iconv dependency optional
Disable transient_supervisors compile option
Add hipe compilation support
Only compile ibrowse and lhttpc when needed
Make it possible to generate an OTP application release
Add --enable-debug compile option
Add --enable-all compiler option
Add --enable-tools configure option
Add --with-erlang configure option.
Add --enable-erlang-version-check configure option.
Add lager support
Improve the test suite
2013-06-13 11:11:02 +02:00
Paul Donohue b33a482582 Fix error when generating random binary strings 2013-04-19 15:30:13 -04:00
Evgeniy Khramtsov 0d80e7e68a Get rid of references to non-existent module 2013-03-29 19:38:01 +10:00
Evgeniy Khramtsov 299a0f823a Fix several refactoring related bugs 2013-03-29 19:23:52 +10:00
Badlop 9deb294328 Accumulated patch to binarize and indent code 2013-03-14 10:33:02 +01:00
Alexey Shchepin 0ae400533c Update copyright dates 2013-01-24 16:25:13 +02:00
Badlop 2dc2769c92 Log IP address when auth attempt fails (thanks to Zach Calvert) 2012-08-27 17:40:01 +02:00
Alexey Shchepin b1e2538488 Update copyright dates 2012-02-23 17:52:34 +02:00
Evgeniy Khramtsov 944791e888 Fix presence problem after first unavailable (thanks to Christopher Faulet) (EJAB-1466) 2011-11-09 15:09:02 +10:00
Badlop a0f8a2c3a4 New option resource_conflict defines server action (thanks to Lee Boynton)(EJAB-650) 2011-08-17 19:44:39 +02:00
Badlop e80b92b481 Preliminary patch for SASL SCRAM-SHA-1 (thanks to Stephen Röttger)(EJAB-1196) 2011-08-16 00:25:03 +02:00
Badlop bfebcebeb7 Support XEP-0191 Simple Communications Blocking (thanks to Stephan Maka)(EJAB-695) 2011-05-27 11:47:22 +02:00
Christophe Romain fd52f2cb7d update copyright up to 2011 2011-02-14 13:50:55 +01:00
Badlop 36166aa40e Comment unused code 2011-01-28 12:11:34 +01:00
Mickaël Rémond bd43505db9 Use route instead of send_element to go through standard workflow Offline messages should thus be tracked for ack if needed (TEXTO-226).
Signed-off-by: Evgeniy Khramtsov <ekhramtsov@process-one.net>
2011-01-04 15:21:10 +01:00
Evgeniy Khramtsov 4c8b034874 Change c2s state before offline messages resending 2010-12-28 21:09:15 +09:00
Christophe Romain f0a848ef45 fix pubsub cross domain eventing (EJAB-1340) 2010-12-02 13:56:45 +01:00
Christopher tofu Zorn 3e24408710 add the ability to send raw xml packets over http bind 2010-11-29 20:05:37 +01:00
Evgeniy Khramtsov b8d6aee1ce Merge branch 'caps' into 2.1.x
Conflicts:
	src/ejabberd_c2s.erl
2010-11-24 16:45:05 +09:00
Badlop 9b88fd6646 Fix some English strings 2010-11-19 13:44:30 +01:00
Andreas Köhler 510fd8cf73 Before forwarding last activity requests to a user, check that the user's presence is visible for From
According to XEP-0012, 4. Online User Query, "if the requesting entity
is not authorized to view the user's presence information (normally via
a presence subscription as defined in XMPP IM), the user's server MUST
NOT deliver the IQ-get to an available resource but instead MUST return
a <forbidden/> error in response to the last activity request."

So check for a subscription of from of the jid and bare jid and whether
outgoing presences to From are allowed.

Fixes problem 3 of EJAB-1158.
2010-11-10 15:40:01 +01:00
Andreas Köhler 080922a3de Remove dead code for NS_VCARD iq packets from ejabberd_c2s
For EJAB-1045, the special NS_VCARD block for handling incoming vcard
iqs on behalf of clients has already been restricted to cases where the
user or resource part of the recipient is empty. But then the packets
should not have been routed to the c2s process anyway. This patch
completely removes it.
2010-11-10 15:40:00 +01:00
Andreas Köhler cb7d8c8ead Use ejabberd_c2s:privacy_check_packet/5 for all those hook folded runs in the c2s module 2010-11-10 15:39:59 +01:00
Andreas Köhler c47252aea1 Use c2s state data as user and server in ejabberd_c2s:is_privacy_allow
is_privacy_allow is only used in ejabberd_c2s:handle_info/3 to determine
for a few presence types whether the packet is allowed to be forwarded
to the user's client. This only makes sense if To#jid.user and
To#jid.server match StateData#state.user and StateData#state.server.

Also, add the atom in as parameter to a new argument Dir of
is_privacy_allow and extract from that function
privacy_check_packet(StateData, From, To, Packet, Dir) which runs the
privavcy check without converting allow/deny to true/false.
2010-11-10 15:39:57 +01:00
Evgeniy Khramtsov 1f16e4783c Take care of xml:lang attribute in unauthenticated stanzas as well 2010-11-06 13:58:52 +09:00
Evgeniy Khramtsov c4289095e0 Do not store long language tag to avoid possible DoS/flood attacks 2010-11-05 05:10:18 +09:00