dialback.cc File Reference

main file of the dialback component implementing server to server connections More...

#include "dialback.h"

Data Structures

struct  _dialback_jid_with_xmlnode
struct  miodc
 little wrapper to keep our hash tables in check More...

Functions

int dialback_check_settings (db d, mio m, const char *server, int is_outgoing, int auth_type, int version)
char * dialback_randstr (void)
char * dialback_merlin (pool p, char const *secret, char const *to, char const *from, char const *challenge)
void dialback_miod_write (miod md, xmlnode x)
void dialback_miod_read (miod md, xmlnode x)
miod dialback_miod_new (db d, mio m)
void _dialback_miod_hash_cleanup (void *arg)
void dialback_miod_hash (miod md, xht ht, jid key)
char * dialback_ip_get (db d, jid host, char *ip)
void dialback_ip_set (db d, jid host, char *ip)
void _dialback_walk_out_established (xht h, const char *key, void *value, void *arg)
void _dialback_walk_out_connecting (xht h, const char *key, void *value, void *arg)
void _dialback_walk_in_established (xht h, const char *key, void *value, void *arg)
void _dialback_walk_in_connecting (xht h, const char *key, void *value, void *arg)
result dialback_packets (instance i, dpacket dp, void *arg)
void _dialback_beat_idle (xht h, const char *key, void *data, void *arg)
void _dialback_beat_in_idle (xht h, const char *key, void *data, void *arg)
void _dialback_beat_out_idle (xht h, const char *key, void *data, void *arg)
result dialback_beat_idle (void *arg)
const char * dialback_get_loopcheck_token (db d)
void dialback (instance i, xmlnode x)


Detailed Description

main file of the dialback component implementing server to server connections

This is the main file of the dialback component (module) of the Jabber server.

The dialback protocol is documented in XMPP-core. This module only supports identity verification using dialback, SASL is not supported.


Function Documentation

void _dialback_beat_idle ( xht  h,
const char *  key,
void *  data,
void *  arg 
)

callback for walking each miod-value host hash tree, close connections that have been idle to long

The timeout value is configured in the dialback component configuration using the <idletimeout/> element.

Parameters:
h the hash table containing all connections
key unused/ignored (the key of the value in the hash table)
data the value in the hash table = the structure holding the connection
arg unused/ignored

References miod_struct::d, mio_st::fd, miod_struct::last, log_debug2, LOGT_IO, miod_struct::m, mio_close(), mio_ip, mio_write(), db_struct::timeout_idle, and ZONE.

Referenced by dialback_beat_idle().

void _dialback_beat_in_idle ( xht  h,
const char *  key,
void *  data,
void *  arg 
)

callback for walking incoming connections, that are not authorized yet, checking for timeotus

Parameters:
h the hash table containing all connections
key unused/ignored (the key of the value in the hash table)
data the value in the hash table = the structure holding the connection
arg unused/ignored

References dbic_struct::d, mio_st::fd, log_debug2, LOGT_IO, dbic_struct::m, mio_close(), mio_ip, mio_write(), dbic_struct::stamp, db_struct::timeout_auth, and ZONE.

Referenced by dialback_beat_idle().

void _dialback_beat_out_idle ( xht  h,
const char *  key,
void *  data,
void *  arg 
)

callback for walking outgoing connections, that are not authorized yet, checking for timeotus

Parameters:
h the hash table containing all connections
key unused/ignored (the key of the value in the hash table)
data the value in the hash table = the structure holding the connection
arg unused/ignored

References dboc::d, mio_st::fd, log_debug2, LOGT_IO, dboc::m, mio_close(), mio_ip, mio_write(), dboc::stamp, db_struct::timeout_auth, and ZONE.

Referenced by dialback_beat_idle().

void _dialback_miod_hash_cleanup ( void *  arg  ) 

Unregister outgoing routings, that have been routed over this connection, that is closed now.

clean up a hashtable entry containing this miod

This function is called if the pool assocciated with the miod is freed.

Parameters:
arg pointer to the miodc structure

References miod_struct::count, miod_struct::d, mio_st::fd, xmppd::jabberid::get_domain(), xmppd::jabberid::get_resource(), miodc::ht, db_struct::i, db_struct::in_ok_db, jid_full(), miodc::key, log_debug2, log_record(), LOGT_AUTH, LOGT_CLEANUP, miod_struct::m, miodc::md, mio_ip, db_struct::out_ok_db, unregister_instance(), xhash_get(), xhash_zap(), and ZONE.

Referenced by dialback_miod_hash().

void _dialback_walk_in_connecting ( xht  h,
const char *  key,
void *  value,
void *  arg 
)

iterate the xhash of connecting incomming connections and add items for them to a disco::items query

References _dialback_jid_with_xmlnode::id, jid_full(), JID_RESOURCE, jid_set(), NS_DISCO_ITEMS, _dialback_jid_with_xmlnode::x, xmlnode_insert_tag_ns(), and xmlnode_put_attrib_ns().

void _dialback_walk_in_established ( xht  h,
const char *  key,
void *  value,
void *  arg 
)

iterate the xhash of established incomming connections and add items for them to a disco::items query

References _dialback_jid_with_xmlnode::id, jid_full(), JID_RESOURCE, jid_set(), NS_DISCO_ITEMS, _dialback_jid_with_xmlnode::x, xmlnode_insert_tag_ns(), and xmlnode_put_attrib_ns().

void _dialback_walk_out_connecting ( xht  h,
const char *  key,
void *  value,
void *  arg 
)

iterate the xhash of connecting outgoing connections and add items for them to a disco::items query

References _dialback_jid_with_xmlnode::id, jid_full(), JID_RESOURCE, jid_set(), NS_DISCO_ITEMS, _dialback_jid_with_xmlnode::x, xmlnode_insert_tag_ns(), and xmlnode_put_attrib_ns().

void _dialback_walk_out_established ( xht  h,
const char *  key,
void *  value,
void *  arg 
)

iterate the xhash of established outgoing connections and add items for them to a disco::items query

References _dialback_jid_with_xmlnode::id, jid_full(), JID_RESOURCE, jid_set(), NS_DISCO_ITEMS, _dialback_jid_with_xmlnode::x, xmlnode_insert_tag_ns(), and xmlnode_put_attrib_ns().

void dialback ( instance  i,
xmlnode  x 
)

result dialback_beat_idle ( void *  arg  ) 

initiate walking the hash of existing s2s connections to check if they have been idle to long

called as a heartbeat function

Parameters:
arg pointer to the structure holding the context of the dialback component instance
Returns:
always r_DONE

References _dialback_beat_idle(), _dialback_beat_in_idle(), _dialback_beat_out_idle(), db_struct::in_id, db_struct::in_ok_db, log_debug2, LOGT_EXECFLOW, db_struct::out_connecting, db_struct::out_ok_db, r_DONE, xhash_walk(), and ZONE.

Referenced by dialback().

int dialback_check_settings ( db  d,
mio  m,
const char *  server,
int  is_outgoing,
int  auth_type,
int  version 
)

check TLS and authentication settings for a s2s connection

Parameters:
d the dialback instance
m the connection
server the host at the other end of the connection
is_outgoing 0 for an outgoing connection, 1 for an incoming connection
auth_type 0 for dialback, 1 for sasl
version 0 for a preXMPP stream, 1 for a XMPP1.0 stream
Returns:
0 if connection is not allowed, else connection is acceptable

References db_struct::hosts_auth, db_struct::hosts_tls, db_struct::i, instance_struct::id, j_atoi(), j_strcmp(), j_strncmp(), log_debug2, log_notice(), log_warn(), LOGT_IO, mio_close(), mio_is_encrypted(), mio_ssl_verify(), mio_tls_get_certtype(), mio_tls_get_characteristics(), mio_tls_get_compression(), mio_write(), mio_st::ssl, xhash_get_by_domain(), and ZONE.

Referenced by dialback_in_read_db(), dialback_in_verify(), and dialback_out_read().

const char* dialback_get_loopcheck_token ( db  d  ) 

we pass a token in the stream root to identify a looping connection to ourself. This generated the token of the server.

Parameters:
d the dialback instance
Returns:
the token to use

References hmac_sha1_ascii_r(), and db_struct::secret.

Referenced by dialback_in_read(), and dialback_out_read().

char* dialback_ip_get ( db  d,
jid  host,
char *  ip 
)

get the cached IP address for an external server

Parameters:
d db structure which contains the context of the dialback component instance
host the host for which we need the IP address
ip the IP if the caller already knows it (conveniance parameter)
Returns:
the IP of the external server

References xmppd::jabberid::get_domain(), xmppd::jabberid_pool::get_pool(), log_debug2, LOGT_IO, db_struct::nscache, pstrdup(), xhash_get(), xmlnode_get_attrib_ns(), and ZONE.

Referenced by dialback_out_packet().

void dialback_ip_set ( db  d,
jid  host,
char *  ip 
)

put an IP address in our DNS cache

Parameters:
d db structure which contains the context of the dialback component instance
host the host for which we put the IP address
ip the IP address

References xmppd::jabberid::get_domain(), log_debug2, LOGT_IO, NS_JABBERD_WRAPPER, db_struct::nscache, xhash_get(), xhash_put(), xmlnode_free(), xmlnode_get_attrib_ns(), xmlnode_new_tag_ns(), xmlnode_put_attrib_ns(), and ZONE.

Referenced by dialback_miod_hash().

char* dialback_merlin ( pool  p,
char const *  secret,
char const *  to,
char const *  from,
char const *  challenge 
)

convenience function to generate your dialback key (not thread-safe)

Note:
We generate a HMAC-SHA1 for the string "to from challenge" where the challenge is the stream id generated by the destination host. As the key for the HMAC-SHA1 we use the SHA1 hash of the secret.
Parameters:
p the memory pool used
secret our dialback secret
to the destination of the stream
from the source host of the stream
challenge the stream ID that should be verified
Returns:
the dialback key

References hmac_sha1_ascii_r(), log_debug2, LOGT_AUTH, pmalloco(), and ZONE.

Referenced by dialback_in_read_db(), dialback_out_connection(), and dialback_out_read().

void dialback_miod_hash ( miod  md,
xht  ht,
jid  key 
)

registering a connection in the hash of outgoing connections

Parameters:
md structure representing the outgoing connection
ht hash table containing all outgoing s2s connections
key destination with our source domain as the resource

References _dialback_miod_hash_cleanup(), miod_struct::d, dialback_ip_set(), mio_st::fd, xmppd::jabberid::get_domain(), miodc::ht, db_struct::i, jid_full(), jid_new(), miodc::key, log_debug2, LOGT_AUTH, miod_struct::m, miodc::md, mio_ip, db_struct::out_ok_db, mio_st::p, pmalloco(), pool_cleanup(), register_instance(), xhash_put(), and ZONE.

Referenced by dialback_in_read(), dialback_in_verify(), and dialback_out_read().

miod dialback_miod_new ( db  d,
mio  m 
)

create a new wrapper around a managed I/O connection to be able to keep track about idle connections and the state of the dialback

Parameters:
d structure that holds the context of the dialback component instance
m the managed I/O connection
Returns:
pointer to the allocated miod structure

References miod_struct::d, miod_struct::last, miod_struct::m, mio_st::p, and pmalloco().

Referenced by dialback_in_read(), dialback_in_verify(), and dialback_out_read().

void dialback_miod_read ( miod  md,
xmlnode  x 
)

process a packet that has been read from a managed I/O connection and update the idle time values

Parameters:
md structure holding the elements to keep track of idle time (and other elements)
x the xmlnode that has been read from the connection

References miod_struct::count, miod_struct::d, deliver(), dpacket_new(), db_struct::i, instance_struct::id, jpacket_new(), miod_struct::last, log_warn(), xmlnode_free(), and xmlnode_serialize_string().

Referenced by dialback_in_read_db().

void dialback_miod_write ( miod  md,
xmlnode  x 
)

write to a managed I/O connection and update the idle time values

Parameters:
md structure holding the mio handle and the elements to keep track of idle time
x the xmlnode that should be written to the connection

References miod_struct::count, miod_struct::last, miod_struct::m, and mio_write().

Referenced by dialback_out_packet(), and dialback_out_qflush().

result dialback_packets ( instance  i,
dpacket  dp,
void *  arg 
)

phandler callback, send packets to another server

This is where the dialback instance receives packets from the jabberd framework

Parameters:
i the dialback instance we are running in
dp the dialback packet
arg pointer to the db structure with the context of the dialback component instance
Returns:
always r_DONE

References dialback_in_verify(), dialback_out_packet(), xmppd::jabberid::get_domain(), db_struct::i, instance_struct::id, j_strcmp(), jid_new(), NS_DIALBACK, p_ROUTE, r_DONE, db_struct::std_ns_prefixes, dpacket_struct::type, dpacket_struct::x, xmlnode_free(), xmlnode_get_attrib_ns(), xmlnode_get_firstchild(), xmlnode_get_list_item(), xmlnode_get_name(), xmlnode_get_namespace(), xmlnode_get_tags(), xmlnode_hide_attrib_ns(), xmlnode_pool(), and xmlnode_put_attrib_ns().

Referenced by dialback().

char* dialback_randstr ( void   ) 

generate a random string (not thead-safe)

This function generates a random ASCII string.

Returns:
pointer to a string with 40 characters of random data

References shahash_r().

Referenced by dialback().


Generated on Wed Sep 10 01:59:47 2008 for jabberd14 by  doxygen 1.5.5