jabberd2  2.6.1
c2s.h
Go to the documentation of this file.
1 /*
2  * jabberd - Jabber Open Source Server
3  * Copyright (c) 2002 Jeremie Miller, Thomas Muldowney,
4  * Ryan Eatmon, Robert Norris
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA
19  */
20 
21 #ifdef HAVE_CONFIG_H
22 # include <config.h>
23 #endif
24 
25 #include <expat.h>
26 
27 #include "mio/mio.h"
28 #include "sx/sx.h"
29 #include "util/util.h"
30 
31 #ifdef HAVE_SIGNAL_H
32 # include <signal.h>
33 #endif
34 #ifdef HAVE_SYS_STAT_H
35 # include <sys/stat.h>
36 #endif
37 
38 #ifdef _WIN32
39  #ifdef _USRDLL
40  #define DLLEXPORT __declspec(dllexport)
41  #define C2S_API __declspec(dllimport)
42  #else
43  #define DLLEXPORT __declspec(dllimport)
44  #define C2S_API __declspec(dllexport)
45  #endif
46 #else
47  #define DLLEXPORT
48  #define C2S_API
49 #endif
50 
51 /* forward declarations */
52 typedef struct host_st *host_t;
53 typedef struct c2s_st *c2s_t;
54 typedef struct bres_st *bres_t;
55 typedef struct sess_st *sess_t;
56 typedef struct authreg_st *authreg_t;
57 
59 struct bres_st {
63  char c2s_id[44], sm_id[41];
65  char sm_request[41];
66 
67  bres_t next;
68 };
69 
74 struct sess_st {
75  c2s_t c2s;
76 
78 
79  char skey[44];
80 
81  const char *smcomp; /* sm component servicing this session */
82 
83  const char *ip;
84  int port;
85 
87 
89  host_t host;
90 
92  int rate_log;
93 
96 
97  time_t last_activity;
98  unsigned int packet_count;
99 
100  /* count of bound resources */
101  int bound;
102  /* list of bound jids */
103  bres_t resources;
104 
105  int active;
106 
107  /* session related packet waiting for sm response */
109 
110  int sasl_authd; /* 1 = they did a sasl auth */
111 
113  char auth_challenge[65];
114 
115  /* Per user session authreg private data */
117 };
118 
119 /* allowed mechanisms */
120 #define AR_MECH_TRAD_PLAIN (1<<0)
121 #define AR_MECH_TRAD_DIGEST (1<<1)
122 #define AR_MECH_TRAD_CRAMMD5 (1<<2)
123 
124 struct host_st {
126  const char *realm;
127 
129  const char *host_pemfile;
130 
132  const char *host_cachain;
133 
136 
139 
142 
144  const char *host_ciphers;
145 
146  /* authreg module if different than default */
147  const char *ar_module_name;
148  authreg_t ar;
149 
153  const char *ar_register_oob;
155 };
156 
157 struct c2s_st {
159  const char *id;
160 
162  const char *router_ip;
164  const char *router_user;
165  const char *router_pass;
166  const char *router_pemfile;
167  const char *router_cachain;
169  const char *router_ciphers;
170 
173 
176 
181 
185 
188 #ifdef HAVE_SSL
189  mio_fd_t server_ssl_fd;
190 #endif
191 
194 
197 
200  const char *log_facility;
201  const char *log_ident;
202 
204  long long int packet_count;
205  const char *packet_stats;
206 
212 
214  const char *local_ip;
215 
218 
221 
223  const char *local_pemfile;
224 
226  const char *local_cachain;
227 
230 
233 
235  const char *local_ciphers;
236 
238  const char *http_forward;
239 
242 
244  const char *pbx_pipe;
247 
250 
253 
256 
261 
262  time_t next_check;
263 
265  const char *ar_module_name;
266  authreg_t ar;
267 
270 
274 
279 
281 
286 
291 
294 
297 
300 
303 
305  int started;
306 
308  int online;
309 
312  host_t vhost;
313 
316 };
317 
318 extern sig_atomic_t c2s_lost_router;
319 
320 C2S_API int c2s_router_mio_callback(mio_t m, mio_action_t a, mio_fd_t fd, void *data, void *arg);
321 C2S_API int c2s_router_sx_callback(sx_t s, sx_event_t e, void *data, void *arg);
322 
323 C2S_API void sm_start(sess_t sess, bres_t res);
324 C2S_API void sm_end(sess_t sess, bres_t res);
325 C2S_API void sm_create(sess_t sess, bres_t res);
326 C2S_API void sm_delete(sess_t sess, bres_t res);
327 C2S_API void sm_packet(sess_t sess, bres_t res, nad_t nad);
328 
329 C2S_API int bind_init(sx_env_t env, sx_plugin_t p, va_list args);
330 
331 C2S_API void c2s_pbx_init(c2s_t c2s);
332 
333 /* My IP Address plugin */
334 JABBERD2_API int address_init(sx_env_t env, sx_plugin_t p, va_list args);
335 
337 {
338  c2s_t c2s;
340 
342  void *handle;
343 
345  void *private;
346 
348  int (*user_exists)(authreg_t ar, sess_t sess, const char *username,const char *realm);
349 
351  int (*get_password)(authreg_t ar, sess_t sess, const char *username, const char *realm, char password[257]);
352 
354  int (*check_password)(authreg_t ar, sess_t sess, const char *username, const char *realm, char password[257]);
355 
357  int (*set_password)(authreg_t ar, sess_t sess, const char *username, const char *realm, char password[257]);
358 
360  int (*create_user)(authreg_t ar, sess_t sess, const char *username, const char *realm);
361  int (*delete_user)(authreg_t ar, sess_t sess, const char *username, const char *realm);
362 
364  void (*sess_end)(authreg_t ar, sess_t sess);
365 
367  void (*free)(authreg_t ar);
368 
369  /* Additions at the end - to preserve offsets for existing modules */
370 
372  int (*user_authz_allowed)(authreg_t ar, sess_t sess, const char *username, const char *realm, const char *requested_user);
373 
375  int (*create_challenge)(authreg_t ar, sess_t sess, const char *username, const char *realm, char *challenge, int maxlen);
376  int (*check_response)(authreg_t ar, sess_t sess, const char *username, const char *realm, const char *challenge, const char *response);
377 };
378 
380 C2S_API authreg_t authreg_init(c2s_t c2s, const char *name);
381 
383 C2S_API void authreg_free(authreg_t ar);
384 
386 typedef int (*ar_module_init_fn)(authreg_t);
387 
389 C2S_API int authreg_process(c2s_t c2s, sess_t sess, nad_t nad);
390 
391 /*
392 int authreg_user_exists(authreg_t ar, const char *username, const char *realm);
393 int authreg_get_password(authreg_t ar, const char *username, const char *realm, char password[257]);
394 int authreg_check_password(authreg_t ar, const char *username, const char *realm, char password[257]);
395 int authreg_set_password(authreg_t ar, const char *username, const char *realm, char password[257]);
396 int authreg_create_user(authreg_t ar, const char *username, const char *realm);
397 int authreg_delete_user(authreg_t ar, const char *username, const char *realm);
398 void authreg_free(authreg_t ar);
399 */
400 
401 /* union for xhash_iter_get to comply with strict-alias rules for gcc3 */
402 union xhashv
403 {
404  void **val;
405  const char **char_val;
406  sess_t *sess_val;
407 };
408 
409 // Data for stream redirect errors
410 typedef struct stream_redirect_st
411 {
412  const char *to_address;
413  const char *to_port;
C2S_API void sm_create(sess_t sess, bres_t res)
Definition: sm.c:76
struct bres_st * bres_t
Definition: c2s.h:54
bres_t resources
Definition: c2s.h:103
int io_check_interval
time checks
Definition: c2s.h:258
Definition: nad.h:93
struct sess_st * sess_t
Definition: c2s.h:55
C2S_API void sm_end(sess_t sess, bres_t res)
Definition: sm.c:72
struct stream_redirect_st * stream_redirect_t
const char * log_facility
Definition: c2s.h:200
config_t config
config
Definition: c2s.h:193
C2S_API int c2s_router_mio_callback(mio_t m, mio_action_t a, mio_fd_t fd, void *data, void *arg)
Definition: c2s.c:1343
mio_fd_t fd
Definition: c2s.h:77
char sm_request[41]
this holds the id of the current pending SM request
Definition: c2s.h:65
struct host_st * host_t
Definition: c2s.h:52
const char * http_forward
http forwarding URL
Definition: c2s.h:238
xht ar_modules
loaded auth/reg modules
Definition: c2s.h:269
c2s_t c2s
Definition: c2s.h:338
int ar_register_enable
registration
Definition: c2s.h:151
int started
this is true if we&#39;ve connected to the router at least once
Definition: c2s.h:305
unsigned int packet_count
Definition: c2s.h:98
access_t access
access controls
Definition: c2s.h:296
const char * router_ciphers
Definition: c2s.h:169
xht conn_rates
Definition: c2s.h:280
#define JABBERD2_API
Definition: mio.h:39
const char * host_ciphers
list of TLS ciphers
Definition: c2s.h:144
int compression
enable Stream Compression
Definition: c2s.h:255
int retry_left
Definition: c2s.h:211
int conn_rate_seconds
Definition: c2s.h:277
an environment
Definition: sx.h:382
int(* ar_module_init_fn)(authreg_t)
type for the module init function
Definition: c2s.h:386
C2S_API void sm_packet(sess_t sess, bres_t res, nad_t nad)
Definition: sm.c:86
const char * log_ident
Definition: c2s.h:201
list of resources bound to session
Definition: c2s.h:59
int io_max_fds
max file descriptors
Definition: c2s.h:252
char * host_private_key_password
private key password
Definition: c2s.h:135
int io_check_keepalive
Definition: c2s.h:260
a plugin
Definition: sx.h:347
nad_t result
Definition: c2s.h:108
int ar_mechanisms
allowed mechanisms
Definition: c2s.h:272
holder for the config hash and nad
Definition: util.h:200
time_t next_check
Definition: c2s.h:262
const char * id
our id (hostname) with the router
Definition: c2s.h:159
int initialized
loaded module handle
Definition: c2s.h:339
mio_action_t
these are the actions and a handler type assigned by the applicaiton using mio
Definition: mio.h:106
Definition: mio.h:109
int host_verify_mode
verify-mode
Definition: c2s.h:138
int stanza_size_limit
maximum stanza size
Definition: c2s.h:293
sx_t router
router&#39;s conn
Definition: c2s.h:183
mio_fd_t pbx_pipe_mio_fd
Definition: c2s.h:246
jid_t jid
full bound jid
Definition: c2s.h:61
time_t last_activity
Definition: c2s.h:97
mio_fd_t server_fd
listening sockets
Definition: c2s.h:187
authreg_t ar
Definition: c2s.h:266
const char * router_pemfile
Definition: c2s.h:166
sx_t s
Definition: c2s.h:86
C2S_API int authreg_process(c2s_t c2s, sess_t sess, nad_t nad)
the main authreg processor
Definition: authreg.c:680
JABBERD2_API int address_init(sx_env_t env, sx_plugin_t p, va_list args)
args: none
Definition: address.c:42
const char * ip
Definition: c2s.h:83
int stanza_rate_log
Definition: c2s.h:95
const char * router_cachain
Definition: c2s.h:167
const char * router_ip
how to connect to the router
Definition: c2s.h:162
const char * local_ip
ip to listen on
Definition: c2s.h:214
const char * router_private_key_password
Definition: c2s.h:168
int router_port
Definition: c2s.h:163
void sess_end(sess_t sess)
Definition: sess.c:85
sx_plugin_t sx_ssl
Definition: c2s.h:179
mio_t mio
mio context
Definition: c2s.h:172
mio - manage i/o
holds the state for a single stream
Definition: sx.h:253
int retry_sleep
Definition: c2s.h:210
const char * ar_register_instructions
Definition: c2s.h:152
int stanza_rate_wait
Definition: c2s.h:290
int port
Definition: c2s.h:84
C2S_API authreg_t authreg_init(c2s_t c2s, const char *name)
get a handle for a single module
Definition: authreg.c:40
const char * to_address
Definition: c2s.h:412
void ** val
Definition: c2s.h:404
const char * smcomp
Definition: c2s.h:81
struct _log_st * log_t
Definition: log.h:48
struct c2s_st * c2s_t
Definition: c2s.h:53
int io_check_idle
Definition: c2s.h:259
const char * router_pass
Definition: c2s.h:165
log_type_t
Definition: log.h:41
const char * realm
our realm (SASL)
Definition: c2s.h:126
int bound
Definition: c2s.h:101
int ar_register_password
Definition: c2s.h:154
sess_t * sess_val
Definition: c2s.h:406
authreg_t ar
Definition: c2s.h:148
host_t host
host this session belongs to
Definition: c2s.h:89
int local_verify_mode
verify-mode
Definition: c2s.h:232
Definition: jid.h:42
int byte_rate_seconds
Definition: c2s.h:284
int local_port
unencrypted port
Definition: c2s.h:217
Definition: c2s.h:124
xht hosts
hosts mapping
Definition: c2s.h:311
const char * host_pemfile
starttls pemfile
Definition: c2s.h:129
int conn_rate_total
connection rates
Definition: c2s.h:276
struct authreg_st * authreg_t
Definition: c2s.h:56
int byte_rate_wait
Definition: c2s.h:285
void * authreg_private
Definition: c2s.h:116
sx_env_t sx_env
sx environment
Definition: c2s.h:178
int retry_init
connect retry
Definition: c2s.h:208
char c2s_id[44]
session id for this jid for us and them
Definition: c2s.h:63
int stanza_rate_seconds
Definition: c2s.h:289
xht sm_avail
availability of sms that we are servicing
Definition: c2s.h:315
Definition: c2s.h:157
C2S_API void sm_start(sess_t sess, bres_t res)
Definition: sm.c:66
host_t vhost
Definition: c2s.h:312
const char * ar_module_name
Definition: c2s.h:147
xht stream_redirects
stream redirection (see-other-host) on session connect
Definition: c2s.h:249
int conn_rate_wait
Definition: c2s.h:278
log_type_t log_type
log data
Definition: c2s.h:199
int retry_lost
Definition: c2s.h:209
sig_atomic_t c2s_lost_router
Definition: main.c:28
jqueue_t dead_sess
list of sess on the way out
Definition: c2s.h:302
#define C2S_API
Definition: c2s.h:48
There is one instance of this struct per user who is logged in to this c2s instance.
Definition: c2s.h:74
mio_fd_t fd
Definition: c2s.h:184
C2S_API void c2s_pbx_init(c2s_t c2s)
Definition: pbx.c:120
const char * to_port
Definition: c2s.h:413
int pbx_pipe_fd
Definition: c2s.h:245
long long int packet_count
packet counter
Definition: c2s.h:204
int rate_log
Definition: c2s.h:92
const char ** char_val
Definition: c2s.h:405
int websocket
websocket support
Definition: c2s.h:241
xht sessions
sessions
Definition: c2s.h:175
const char * local_ciphers
list of TLS ciphers
Definition: c2s.h:235
rate_t rate
Definition: c2s.h:91
const char * packet_stats
Definition: c2s.h:205
const char * ar_module_name
default auth/reg module
Definition: c2s.h:265
rate_t stanza_rate
Definition: c2s.h:94
Definition: mio.h:100
Definition: util.h:258
int local_ssl_port
encrypted port
Definition: c2s.h:220
sx_plugin_t sx_sasl
Definition: c2s.h:180
session packet handling
Definition: c2s.h:402
void * handle
Definition: c2s.h:342
sx_event_t
things that can happen
Definition: sx.h:56
C2S_API void authreg_free(authreg_t ar)
shut down
Definition: authreg.c:130
const char * ar_register_oob
Definition: c2s.h:153
c2s_t c2s
Definition: c2s.h:75
jqueue_t dead
list of sx_t on the way out
Definition: c2s.h:299
C2S_API int bind_init(sx_env_t env, sx_plugin_t p, va_list args)
plugin initialiser
Definition: bind.c:69
log_t log
logging
Definition: c2s.h:196
const char * pbx_pipe
PBX integration named pipe.
Definition: c2s.h:244
const char * router_user
Definition: c2s.h:164
char sm_id[41]
Definition: c2s.h:63
int host_require_starttls
require starttls
Definition: c2s.h:141
const char * local_private_key_password
private key password
Definition: c2s.h:229
int ar_ssl_mechanisms
Definition: c2s.h:273
int online
true if we&#39;re bound in the router
Definition: c2s.h:308
int sasl_authd
Definition: c2s.h:110
int active
Definition: c2s.h:105
C2S_API void sm_delete(sess_t sess, bres_t res)
Definition: sm.c:82
int stanza_rate_total
stanza rates
Definition: c2s.h:288
const char * local_pemfile
encrypted port pemfile
Definition: c2s.h:223
const char * local_cachain
encrypted port cachain file
Definition: c2s.h:226
C2S_API int c2s_router_sx_callback(sx_t s, sx_event_t e, void *data, void *arg)
Definition: c2s.c:681
bres_t next
Definition: c2s.h:67
const char * host_cachain
certificate chain
Definition: c2s.h:132
int byte_rate_total
byte rates (karma)
Definition: c2s.h:283