23 #include <stringprep.h>
64 if((f = fopen(pidfile,
"w+")) == NULL) {
65 log_write(c2s->
log, LOG_ERR,
"couldn't open %s for writing: %s", pidfile, strerror(errno));
69 if(fprintf(f,
"%d", pid) < 0) {
70 log_write(c2s->
log, LOG_ERR,
"couldn't write to %s: %s", pidfile, strerror(errno));
77 log_write(c2s->
log, LOG_INFO,
"process id is %d, written to %s", pid, pidfile);
82 char *str, *ip, *mask;
83 char *req_domain, *to_address, *to_port;
117 if(strcmp(str,
"file") == 0)
119 else if(strcmp(str,
"syslog") == 0)
163 for(i = 0; i < elem->
nvalues; i++)
167 log_write(c2s->
log, LOG_ERR,
"cannot allocate memory for new stream redirection record, aborting");
170 req_domain =
j_attr((
const char **) elem->
attrs[i],
"requested_domain");
171 to_address =
j_attr((
const char **) elem->
attrs[i],
"to_address");
172 to_port =
j_attr((
const char **) elem->
attrs[i],
"to_port");
174 if(req_domain == NULL || to_address == NULL || to_port == NULL) {
175 log_write(c2s->
log, LOG_ERR,
"Error reading a stream_redirect.redirect element from file, skipping");
240 if(str == NULL || strcmp(str,
"deny,allow") != 0)
248 for(i = 0; i < elem->
nvalues; i++)
251 mask =
j_attr((
const char **) elem->
attrs[i],
"mask");
257 mask =
"255.255.255.255";
266 for(i = 0; i < elem->
nvalues; i++)
269 mask =
j_attr((
const char **) elem->
attrs[i],
"mask");
275 mask =
"255.255.255.255";
291 log_write(c2s->
log, LOG_NOTICE,
"no local.id configured - skipping local domains configuration");
294 for(i = 0; i < elem->
nvalues; i++) {
297 log_write(c2s->
log, LOG_ERR,
"cannot allocate memory for new host, aborting");
301 realm =
j_attr((
const char **) elem->
attrs[i],
"realm");
304 strncpy(
id, elem->
values[i], 1024);
306 if (stringprep_nameprep(
id, 1024) != 0) {
307 log_write(c2s->
log, LOG_ERR,
"cannot stringprep id %s, aborting",
id);
352 if(! strcmp(
id,
"1")) {
361 strcpy(
id,
"default vHost");
367 log_write(c2s->
log, LOG_NOTICE,
"[%s] configured; realm=%s, registration %s, using PEM:%s",
377 if(c2s->
fd == NULL) {
378 if(errno == ECONNREFUSED)
392 char *my_realm, *mech;
394 static char buf[3072];
419 my_realm = host->
realm;
424 strncpy(buf, my_realm, 256);
427 log_debug(
ZONE,
"sx sasl callback: get realm: realm is '%s'", buf);
459 if (strcmp(creds->
pass, buf)==0)
504 strcpy(buf, jid.
node);
515 while(i<
sizeof(mechbuf) && mech[i]!=
'\0') {
516 mechbuf[i]=tolower(mech[i]);
524 if (strcmp(mechbuf,
"digest-md5") == 0) {
528 }
else if (strcmp(mechbuf,
"plain") == 0) {
539 r = snprintf(buf,
sizeof(buf),
"authreg.ssl-mechanisms.sasl.%s",mechbuf);
540 if (r < -1 || r >
sizeof(buf))
546 r = snprintf(buf,
sizeof(buf),
"authreg.mechanisms.sasl.%s",mechbuf);
547 if (r < -1 || r >
sizeof(buf))
598 JABBER_MAIN(
"jabberd2c2s",
"Jabber 2 C2S",
"Jabber Open Source Server: Client to Server",
"jabberd2router\0")
607 time_t check_time = 0;
608 const char *cli_id = 0;
611 umask((mode_t) 0027);
616 #ifdef HAVE_WINSOCK2_H
619 WORD wVersionRequested;
623 wVersionRequested = MAKEWORD( 2, 2 );
625 err = WSAStartup( wVersionRequested, &wsaData );
650 config_file = CONFIG_DIR
"/c2s.xml";
653 while((optchar = getopt(argc, argv,
"Dc:hi:?")) >= 0)
658 config_file = optarg;
664 printf(
"WARN: Debugging not enabled. Ignoring -D.\n");
670 case 'h':
case '?':
default:
672 "c2s - jabberd client-to-server connector (" VERSION
")\n"
673 "Usage: c2s <options>\n"
675 " -c <config> config file to use [default: " CONFIG_DIR
"/c2s.xml]\n"
676 " -i id Override <id> config element\n"
678 " -D Show debug output\n"
690 fputs(
"c2s: couldn't load config, aborting\n", stderr);
706 log_write(c2s->
log, LOG_NOTICE,
"no authreg module specified in config file");
731 log_write(c2s->
log, LOG_ERR,
"failed to load local SSL pemfile, SSL will not be available to clients");
740 log_write(c2s->
log, LOG_ERR,
"failed to load router SSL pemfile, channel to router will not be SSL encrypted");
752 #ifdef ENABLE_EXPERIMENTAL
763 log_write(c2s->
log, LOG_ERR,
"failed to initialise SASL context, aborting");
771 if(c2s->
mio == NULL) {
772 log_write(c2s->
log, LOG_ERR,
"failed to create MIO, aborting");
802 log_write(c2s->
log, LOG_NOTICE,
"reloading some configuration items ...");
809 char *req_domain, *to_address, *to_port;
814 elem =
config_get(conf,
"stream_redirect.redirect");
817 for(i = 0; i < elem->
nvalues; i++)
821 log_write(c2s->
log, LOG_ERR,
"cannot allocate memory for new stream redirection record, aborting");
824 req_domain =
j_attr((
const char **) elem->
attrs[i],
"requested_domain");
825 to_address =
j_attr((
const char **) elem->
attrs[i],
"to_address");
826 to_port =
j_attr((
const char **) elem->
attrs[i],
"to_port");
828 if(req_domain == NULL || to_address == NULL || to_port == NULL) {
829 log_write(c2s->
log, LOG_ERR,
"Error reading a stream_redirect.redirect element from file, skipping");
842 log_write(c2s->
log, LOG_WARNING,
"couldn't reload config (%s)", config_file);
850 log_write(c2s->
log, LOG_NOTICE,
"attempting reconnect");
876 if(sess->
ip != NULL) free(sess->
ip);
880 for(res = sess->
resources; res != NULL;) {
906 if(time(NULL) > check_time + 60) {
911 int fd = open(c2s->
packet_stats, O_TRUNC | O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR | S_IRGRP);
914 int len = snprintf(buf, 100,
"%lld\n", c2s->
packet_count);
915 if (write(fd, buf, len) != len) {
926 check_time = time(NULL);
947 if(sess->
ip != NULL) free(sess->
ip);
950 for(res = sess->
resources; res != NULL;) {
998 #ifdef HAVE_WINSOCK2_H