23
23
static sig_atomic_t router_shutdown = 0;
24
24
static sig_atomic_t router_logrotate = 0;
26
void router_signal(int signum)
26
static void router_signal(int signum)
28
28
router_shutdown = 1;
31
void router_signal_hup(int signum)
31
static void router_signal_hup(int signum)
33
33
router_logrotate = 1;
190
190
r->check_keepalive = j_atoi(config_get_one(r->config, "check.keepalive", 0), 0);
193
static int _router_sx_sasl_callback(int cb, void *arg, void **res, scod_t sd, void *cbarg) {
193
static int _router_sx_sasl_callback(int cb, void *arg, void ** res, sx_t s, void *cbarg) {
194
194
router_t r = (router_t) cbarg;
196
scod_cb_creds_t creds;
195
sx_sasl_creds_t creds;
196
static char buf[1024];
200
200
case sx_sasl_cb_GET_REALM:
202
strcpy((char *) res, "jabberd-router");
201
strcpy(buf, "jabberd-router");
203
return sx_sasl_ret_OK;
205
206
case sx_sasl_cb_GET_PASS:
206
creds = (scod_cb_creds_t) arg;
207
creds = (sx_sasl_creds_t) arg;
208
209
log_debug(ZONE, "sx sasl callback: get pass (authnid=%s, realm=%s)", creds->authnid, creds->realm);
210
*res = xhash_get(r->users, creds->authnid);
211
pass = xhash_get(r->users, creds->authnid);
213
return sx_sasl_ret_FAIL;
216
return sx_sasl_ret_OK;
216
219
case sx_sasl_cb_CHECK_PASS:
217
creds = (scod_cb_creds_t) arg;
220
creds = (sx_sasl_creds_t) arg;
219
222
log_debug(ZONE, "sx sasl callback: check pass (authnid=%s, realm=%s)", creds->authnid, creds->realm);
221
224
pass = xhash_get(r->users, creds->authnid);
222
225
if(pass == NULL || strcmp(creds->pass, pass) != 0)
226
return sx_sasl_ret_OK;
228
return sx_sasl_ret_FAIL;
227
231
case sx_sasl_cb_CHECK_AUTHZID:
228
creds = (scod_cb_creds_t) arg;
229
if(creds->authzid[0] == '\0')
230
strcpy(creds->authzid, creds->authnid);
232
if(strcmp(creds->authnid, creds->authzid) != 0) {
233
log_debug(ZONE, "authnid '%s' doesn't match authzid '%s'", creds->authnid, creds->authzid);
232
creds = (sx_sasl_creds_t) arg;
234
if (strcmp(creds->authnid, creds->authzid) == 0)
235
return sx_sasl_ret_OK;
237
return sx_sasl_ret_FAIL;
240
case sx_sasl_cb_CHECK_MECH:
242
if (strcasecmp((char *)arg,"DIGEST-MD5")==0)
243
return sx_sasl_ret_OK;
245
return sx_sasl_ret_FAIL;
252
return sx_sasl_ret_FAIL;
245
255
static void _router_time_checks(router_t r) {
256
266
xhash_iter_get(r->components, NULL, xhv.val);
258
268
if(r->check_keepalive > 0 && target->last_activity > 0 && now > target->last_activity + r->check_keepalive && target->s->state >= state_STREAM) {
259
log_debug(ZONE, "sending keepalive for %d", target->fd);
269
log_debug(ZONE, "sending keepalive for %d", target->fd->fd);
260
270
sx_raw_write(target->s, " ", 1);
262
272
} while(xhash_iter_next(r->components));
309
319
jabber_signal(SIGPIPE, SIG_IGN);
312
r = (router_t) malloc(sizeof(struct router_st));
313
memset(r, 0, sizeof(struct router_st));
322
r = (router_t) calloc(1, sizeof(struct router_st));
315
324
/* load our config */
316
325
r->config = config_new();
385
394
if(r->local_pemfile != NULL) {
386
r->sx_ssl = sx_env_plugin(r->sx_env, sx_ssl_init, r->local_pemfile, NULL);
395
r->sx_ssl = sx_env_plugin(r->sx_env, sx_ssl_init, NULL, r->local_pemfile, NULL, NULL);
387
396
if(r->sx_ssl == NULL)
388
397
log_write(r->log, LOG_ERR, "failed to load SSL pemfile, SSL disabled");
392
401
/* get sasl online */
393
r->sx_sasl = sx_env_plugin(r->sx_env, sx_sasl_init, _router_sx_sasl_callback, (void *) r, sd_flag_GET_PASS);
402
r->sx_sasl = sx_env_plugin(r->sx_env, sx_sasl_init, "jabberd-router", _router_sx_sasl_callback, (void *) r);
394
403
if(r->sx_sasl == NULL) {
395
404
log_write(r->log, LOG_ERR, "failed to initialise SASL context, aborting");
399
408
r->mio = mio_new(r->io_max_fds);
401
410
r->fd = mio_listen(r->mio, r->local_port, r->local_ip, router_mio_callback, (void *) r);
403
log_write(r->log, LOG_ERR, "[%s, port=%d] unable to listen (%s)", r->local_ip, r->local_port, strerror(errno));
412
log_write(r->log, LOG_ERR, "[%s, port=%d] unable to listen (%s)", r->local_ip, r->local_port, MIO_STRERROR(MIO_ERROR));
407
log_write(r->log, LOG_NOTICE, "[%s, port=%d] listening for incoming connections", r->local_ip, r->local_port, strerror(errno));
416
log_write(r->log, LOG_NOTICE, "[%s, port=%d] listening for incoming connections", r->local_ip, r->local_port, MIO_STRERROR(MIO_ERROR));
409
418
while(!router_shutdown)
417
426
r->log = log_new(r->log_type, r->log_ident, r->log_facility);
418
427
log_write(r->log, LOG_NOTICE, "log started");
429
log_write(r->log, LOG_NOTICE, "reloading filter ...");
420
433
router_logrotate = 0;