23 #define MAX_JID 3072 // node(1023) + '@'(1) + domain(1023) + '/'(1) + resource(1023) + '\0'(1)
24 #define MAX_MESSAGE 65535
25 #define SECS_PER_DAY 86400
26 #define BYTES_PER_MEG 1048576
41 for(i = 0; i < routes->
ncomp; i++) {
55 log_debug(
ZONE,
"advertising %s to all routes (unavail=%d)", domain, unavail);
80 assert((
int) (routes->
name != NULL));
81 assert((
int) (routes->
comp != NULL));
82 assert(routes->
ncomp);
85 for(i = 0; i < routes->
ncomp; i++)
86 if(routes->
comp[i] == dest)
89 log_debug(
ZONE,
"informing component about %.*s", keylen, key);
106 log_debug(
ZONE,
"handshake isn't long enough to be a sha1 hash");
120 hash = (
char *) malloc(
sizeof(
char) * hashlen);
127 if(strncmp(hash,
NAD_CDATA(nad, 0), 40) == 0) {
154 if(routes->
name) free(routes->
name);
155 if(routes->
comp) free(routes->
comp);
165 routes->
name = strdup(name);
166 routes->
rtype = rtype;
173 if(routes->
rtype != rtype)
174 log_write(comp->
r->
log, LOG_ERR,
"Mixed route types for '%s' bind request", name);
176 return routes->
ncomp;
184 if(routes == NULL)
return;
186 if(routes->
ncomp > 1) {
187 for(i = 0; i < routes->
ncomp; i++) {
188 if(routes->
comp[i] == comp) {
189 if(i != routes->
ncomp - 1) {
210 log_debug(
ZONE,
"no or invalid 'name' on bind packet, bouncing");
217 c = strchr(user,
'@');
218 if(c != NULL) *c =
'\0';
221 log_write(comp->
r->
log, LOG_NOTICE,
"[%s, port=%d] tried to bind '%s', but their username (%s) is not permitted to bind other names", comp->
ip, comp->
port, name->
domain, user);
232 log_write(comp->
r->
log, LOG_NOTICE,
"[%s, port=%d] tried to bind '%s', but it's already bound", comp->
ip, comp->
port, name->
domain);
241 for(alias = comp->
r->
aliases; alias != NULL; alias = alias->
next)
243 log_write(comp->
r->
log, LOG_NOTICE,
"[%s, port=%d] tried to bind '%s', but that name is aliased", comp->
ip, comp->
port);
255 log_write(comp->
r->
log, LOG_NOTICE,
"[%s, port=%d] tried to bind '%s' as the default route, but their username (%s) is not permitted to set a default route", comp->
ip, comp->
port, name->
domain, user);
265 log_write(comp->
r->
log, LOG_NOTICE,
"[%s, port=%d] tried to bind '%s' as the default route, but one already exists", comp->
ip, comp->
port, name->
domain);
281 log_write(comp->
r->
log, LOG_NOTICE,
"[%s, port=%d] tried to bind '%s' as a log sink, but their username (%s) is not permitted to do this", comp->
ip, comp->
port, name->
domain, user);
315 for(alias = comp->
r->
aliases; alias != NULL; alias = alias->
next) {
337 log_debug(
ZONE,
"no or invalid 'name' on unbind packet, bouncing");
344 log_write(comp->
r->
log, LOG_NOTICE,
"[%s, port=%d] tried to unbind '%s', but it's not bound to this component", comp->
ip, comp->
port, name->
domain);
377 if(comp->
tq != NULL) {
406 log_debug(
ZONE,
"copying route to '%.*s' (%s, port %d)", keylen, key, comp->
ip, comp->
port);
414 int atype, ato, afrom;
418 jid_t to = NULL, from = NULL;
428 log_debug(
ZONE,
"dropping error packet, trying to avoid loops");
442 if(to == NULL || from == NULL) {
443 log_debug(
ZONE,
"unicast route with missing or invalid to or from, bouncing");
453 log_write(comp->
r->
log, LOG_NOTICE,
"[%s, port=%d] tried to send a packet from '%s', but that name is not bound to this component", comp->
ip, comp->
port, from->domain);
476 if(targets == NULL) {
486 if(targets == NULL) {
498 if(targets->
ncomp == 1) {
502 switch(targets->
rtype) {
512 log_write(comp->
r->
log, LOG_ERR,
"Cannot get destination for multiple route: %.*s", len, out);
522 log_write(comp->
r->
log, LOG_ERR,
"Cannot get source for multiple route: %.*s", len, out);
526 log_write(comp->
r->
log, LOG_ERR,
"Multiple components bound to single component route '%s'", targets->
name);
529 if(to->
node == NULL || strlen(to->
node) == 0) {
536 unsigned char hashval[20];
542 val = (
unsigned int *) hashval;
544 for(i=1; i < 20 / (
sizeof(
unsigned int)/
sizeof(
unsigned char)); i++, val++) {
552 if (to->
_user != NULL )
554 if (to->
_full != NULL )
557 dest = dest % targets->
ncomp;
560 target = targets->
comp[dest];
571 jid_t jid_msg_from = NULL;
572 jid_t jid_msg_to = NULL;
573 jid_t jid_route_from = NULL;
574 jid_t jid_route_to = NULL;
577 ((attr_route_from =
nad_find_attr(nad, 0, -1,
"from", NULL)) >= 0) &&
578 ((attr_route_to =
nad_find_attr(nad, 0, -1,
"to", NULL)) >= 0) &&
579 ((strncmp(
NAD_AVAL(nad, attr_route_to),
"c2s", 3)) != 0) &&
582 ((attr_msg_from =
nad_find_attr(nad, 1, -1,
"from", NULL)) >= 0) &&
583 ((attr_msg_to =
nad_find_attr(nad, 1, -1,
"to", NULL)) >= 0) &&
589 if (jid_msg_from != NULL)
591 if (jid_msg_to != NULL)
593 if (jid_route_from != NULL)
595 if (jid_route_to != NULL)
605 if(
NAD_AVAL_L(nad, atype) == 9 && strncmp(
"broadcast",
NAD_AVAL(nad, atype), 9) == 0) {
607 log_debug(
ZONE,
"broadcast route with missing or invalid from, bouncing");
617 log_write(comp->
r->
log, LOG_NOTICE,
"[%s, port=%d] tried to send a packet from '%s', but that name is not bound to this component", comp->
ip, comp->
port, from->domain);
650 if(comp->
tq == NULL) {
653 log_write(comp->
r->
log, LOG_NOTICE,
"[%s, port=%d] throttling packets on request", comp->
ip, comp->
port);
658 log_write(comp->
r->
log, LOG_NOTICE,
"[%s, port=%d] unthrottling packets on request", comp->
ip, comp->
port);
674 int rlen, len, attr, ns, sns, n;
701 if(comp->
rate != NULL) {
706 log_write(comp->
r->
log, LOG_NOTICE,
"[%s, port=%d] is being byte rate limited", comp->
ip, comp->
port);
728 len = recv(comp->
fd->
fd, buf->
data, rlen, 0);
731 if(comp->
rate != NULL && len > 0) {
789 if(s->
ns == NULL || strcmp(
"jabber:component:accept", s->
ns) != 0)
817 for(alias = comp->
r->
aliases; alias != NULL; alias = alias->
next)
839 for(alias = comp->
r->
aliases; alias != NULL; alias = alias->
next) {
886 log_debug(
ZONE,
"invalid or missing 'to' address on legacy packet, dropping it");
893 log_debug(
ZONE,
"invalid or missing 'from' address on legacy packet, dropping it");
968 if (n->
data == comp->
fd)
break;
981 log_write(r->
log, LOG_NOTICE,
"[%d] [%s] access denied by configuration", fd->
fd, ip);
993 log_write(r->
log, LOG_NOTICE,
"[%d] [%s] is being rate limited", fd->
fd, ip);
1008 local_key = (
char *) malloc(keylen + 1);
1009 memcpy(local_key, key, keylen);
1010 local_key[keylen] = 0;
1015 log_write(comp->
r->
log, LOG_NOTICE,
"[%.*s] default route offline", keylen, key);
1020 log_write(comp->
r->
log, LOG_NOTICE,
"[%.*s] offline", keylen, key);
1032 int namelen =
sizeof(sa), port, nbytes;
1041 ioctl(fd->
fd, FIONREAD, &nbytes);
1072 if(comp->
tq != NULL)
1087 getpeername(fd->
fd, (
struct sockaddr *) &sa, &namelen);
1090 log_write(r->
log, LOG_NOTICE,
"[%s, port=%d] connect", (
char *) data, port);
1136 struct stat filestat;
1138 short int new_msg_file = 0;
1140 int nad_body_len = 0;
1141 long int nad_body_start = 0;
1143 char *nad_body = NULL;
1146 assert((
int) (nad != NULL));
1150 time_pos = ctime(&t);
1151 time_sz = strlen(time_pos);
1153 time_pos[time_sz-1]=
' ';
1161 if (nad_body_len > 0) {
1164 log_write(r->
log, LOG_NOTICE,
"message_log received a message with empty body");
1172 if (nad_body == NULL) {
1177 nad_body_start = nad_body;
1180 for (body_count = 0; (nad_body < nad_body_start + nad_body_len) && (body_count < (
MAX_MESSAGE*2)-3); nad_body++) {
1181 if (*nad_body ==
'\n') {
1182 body[body_count++] =
'\\';
1183 body[body_count++] =
'n';
1185 body[body_count++] = *nad_body;
1188 body[body_count] =
'\0';
1191 umask((mode_t) 0077);
1198 log_write(r->
log, LOG_ERR,
"Unable to open message log for writing: %s", strerror(errno));
1203 if (! fprintf(message_file,
"# This message log is created by the jabberd router.\n"))
1205 log_write(r->
log, LOG_ERR,
"Unable to write to message log: %s", strerror(errno));
1208 fprintf(message_file,
"# See router.xml for logging options.\n");
1209 fprintf(message_file,
"# Format: (Date)<tab>(From JID)<tab>(To JID)<tab>(Message Body)<line end>\n");
1212 if (! fprintf(message_file,
"%s\t%s\t%s\t%s\n", time_pos, msg_from, msg_to, body))
1214 log_write(r->
log, LOG_ERR,
"Unable to write to message log: %s", strerror(errno));
1218 fclose(message_file);