jabberd2  2.3.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 
116 /* allowed mechanisms */
117 #define AR_MECH_TRAD_PLAIN (1<<0)
118 #define AR_MECH_TRAD_DIGEST (1<<1)
119 #define AR_MECH_TRAD_CRAMMD5 (1<<2)
120 
121 struct host_st {
123  const char *realm;
124 
126  const char *host_pemfile;
127 
129  const char *host_cachain;
130 
133 
136 
139 
143  const char *ar_register_oob;
145 
146 };
147 
148 struct c2s_st {
150  const char *id;
151 
153  const char *router_ip;
155  const char *router_user;
156  const char *router_pass;
157  const char *router_pemfile;
158  const char *router_cachain;
160 
163 
166 
171 
175 
178 #ifdef HAVE_SSL
179  mio_fd_t server_ssl_fd;
180 #endif
181 
184 
187 
190  const char *log_facility;
191  const char *log_ident;
192 
194  long long int packet_count;
195  const char *packet_stats;
196 
202 
204  const char *local_ip;
205 
208 
211 
213  const char *local_pemfile;
214 
216  const char *local_cachain;
217 
220 
223 
225  const char *http_forward;
226 
228  const char *pbx_pipe;
231 
234 
237 
240 
245 
246  time_t next_check;
247 
249  const char *ar_module_name;
250  authreg_t ar;
251 
255 
260 
262 
267 
272 
275 
278 
281 
284 
286  int started;
287 
289  int online;
290 
293  host_t vhost;
294 
297 };
298 
299 extern sig_atomic_t c2s_lost_router;
300 
301 C2S_API int c2s_router_mio_callback(mio_t m, mio_action_t a, mio_fd_t fd, void *data, void *arg);
302 C2S_API int c2s_router_sx_callback(sx_t s, sx_event_t e, void *data, void *arg);
303 
304 C2S_API void sm_start(sess_t sess, bres_t res);
305 C2S_API void sm_end(sess_t sess, bres_t res);
306 C2S_API void sm_create(sess_t sess, bres_t res);
307 C2S_API void sm_delete(sess_t sess, bres_t res);
308 C2S_API void sm_packet(sess_t sess, bres_t res, nad_t nad);
309 
310 C2S_API int bind_init(sx_env_t env, sx_plugin_t p, va_list args);
311 
312 C2S_API void c2s_pbx_init(c2s_t c2s);
313 
314 /* My IP Address plugin */
315 JABBERD2_API int address_init(sx_env_t env, sx_plugin_t p, va_list args);
316 
318 {
319  c2s_t c2s;
320 
322  void *private;
323 
325  int (*user_exists)(authreg_t ar, const char *username, const char *realm);
326 
328  int (*get_password)(authreg_t ar, const char *username, const char *realm, char password[257]);
329 
331  int (*check_password)(authreg_t ar, const char *username, const char *realm, char password[257]);
332 
334  int (*set_password)(authreg_t ar, const char *username, const char *realm, char password[257]);
335 
337  int (*create_user)(authreg_t ar, const char *username, const char *realm);
338  int (*delete_user)(authreg_t ar, const char *username, const char *realm);
339 
340  void (*free)(authreg_t ar);
341 
342  /* Additions at the end - to preserve offsets for existing modules */
343 
345  int (*user_authz_allowed)(authreg_t ar, const char *username, const char *realm, const char *requested_user);
346 
348  int (*create_challenge)(authreg_t ar, const char *username, const char *challenge, int maxlen);
349  int (*check_response)(authreg_t ar, const char *username, const char *realm, const char *challenge, const char *response);
350 };
351 
353 C2S_API authreg_t authreg_init(c2s_t c2s, const char *name);
354 
356 C2S_API void authreg_free(authreg_t ar);
357 
359 typedef int (*ar_module_init_fn)(authreg_t);
360 
362 C2S_API int authreg_process(c2s_t c2s, sess_t sess, nad_t nad);
363 
364 /*
365 int authreg_user_exists(authreg_t ar, const char *username, const char *realm);
366 int authreg_get_password(authreg_t ar, const char *username, const char *realm, char password[257]);
367 int authreg_check_password(authreg_t ar, const char *username, const char *realm, char password[257]);
368 int authreg_set_password(authreg_t ar, const char *username, const char *realm, char password[257]);
369 int authreg_create_user(authreg_t ar, const char *username, const char *realm);
370 int authreg_delete_user(authreg_t ar, const char *username, const char *realm);
371 void authreg_free(authreg_t ar);
372 */
373 
374 /* union for xhash_iter_get to comply with strict-alias rules for gcc3 */
375 union xhashv
376 {
377  void **val;
378  const char **char_val;
379  sess_t *sess_val;
380 };
381 
382 // Data for stream redirect errors
383 typedef struct stream_redirect_st
384 {
385  const char *to_address;
386  const char *to_port;
388 
C2S_API void sm_create(sess_t sess, bres_t res)
Definition: sm.c:76
struct bres_st * bres_t
Definition: c2s.h:54
int address_init(sx_env_t env, sx_plugin_t p, va_list args)
args: none
Definition: address.c:42
bres_t resources
Definition: c2s.h:103
int io_check_interval
time checks
Definition: c2s.h:242
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
int(* check_response)(authreg_t ar, const char *username, const char *realm, const char *challenge, const char *response)
Definition: c2s.h:349
int(* delete_user)(authreg_t ar, const char *username, const char *realm)
Definition: c2s.h:338
struct stream_redirect_st * stream_redirect_t
const char * log_facility
Definition: c2s.h:190
config_t config
config
Definition: c2s.h:183
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:225
c2s_t c2s
Definition: c2s.h:319
int ar_register_enable
registration
Definition: c2s.h:141
int started
this is true if we&#39;ve connected to the router at least once
Definition: c2s.h:286
unsigned int packet_count
Definition: c2s.h:98
access_t access
access controls
Definition: c2s.h:277
int(* check_password)(authreg_t ar, const char *username, const char *realm, char password[257])
check the given password against the stored password, 0 if equal, !0 if not equal (password auth) ...
Definition: c2s.h:331
xht conn_rates
Definition: c2s.h:261
#define JABBERD2_API
Definition: mio.h:39
int compression
enable Stream Compression
Definition: c2s.h:239
int retry_left
Definition: c2s.h:201
int conn_rate_seconds
Definition: c2s.h:258
an environment
Definition: sx.h:379
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:191
list of resources bound to session
Definition: c2s.h:59
int io_max_fds
max file descriptors
Definition: c2s.h:236
char * host_private_key_password
private key password
Definition: c2s.h:132
int io_check_keepalive
Definition: c2s.h:244
a plugin
Definition: sx.h:344
nad_t result
Definition: c2s.h:108
int ar_mechanisms
allowed mechanisms
Definition: c2s.h:253
holder for the config hash and nad
Definition: util.h:200
time_t next_check
Definition: c2s.h:246
const char * id
our id (hostname) with the router
Definition: c2s.h:150
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:135
int bind_init(sx_env_t env, sx_plugin_t p, va_list args)
plugin initialiser
Definition: bind.c:69
int stanza_size_limit
maximum stanza size
Definition: c2s.h:274
sx_t router
router&#39;s conn
Definition: c2s.h:173
mio_fd_t pbx_pipe_mio_fd
Definition: c2s.h:230
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:177
authreg_t ar
Definition: c2s.h:250
const char * router_pemfile
Definition: c2s.h:157
sx_t s
Definition: c2s.h:86
const char * ip
Definition: c2s.h:83
int stanza_rate_log
Definition: c2s.h:95
const char * router_cachain
Definition: c2s.h:158
const char * router_ip
how to connect to the router
Definition: c2s.h:153
const char * local_ip
ip to listen on
Definition: c2s.h:204
int authreg_process(c2s_t c2s, sess_t sess, nad_t nad)
processor for iq:auth and iq:register packets return 0 if handled, 1 if not handled ...
Definition: authreg.c:664
const char * router_private_key_password
Definition: c2s.h:159
int router_port
Definition: c2s.h:154
sx_plugin_t sx_ssl
Definition: c2s.h:169
mio_t mio
mio context
Definition: c2s.h:162
mio - manage i/o
holds the state for a single stream
Definition: sx.h:251
int retry_sleep
Definition: c2s.h:200
const char * ar_register_instructions
Definition: c2s.h:142
int stanza_rate_wait
Definition: c2s.h:271
int port
Definition: c2s.h:84
const char * to_address
Definition: c2s.h:385
void ** val
Definition: c2s.h:377
const char * smcomp
Definition: c2s.h:81
struct _log_st * log_t
Definition: log.h:48
int(* user_exists)(authreg_t ar, const char *username, const char *realm)
returns 1 if the user exists, 0 if not
Definition: c2s.h:325
struct c2s_st * c2s_t
Definition: c2s.h:53
int io_check_idle
Definition: c2s.h:243
const char * router_pass
Definition: c2s.h:156
log_type_t
Definition: log.h:41
const char * realm
our realm (SASL)
Definition: c2s.h:123
int bound
Definition: c2s.h:101
int ar_register_password
Definition: c2s.h:144
sess_t * sess_val
Definition: c2s.h:379
host_t host
host this session belongs to
Definition: c2s.h:89
int local_verify_mode
verify-mode
Definition: c2s.h:222
Definition: jid.h:42
int byte_rate_seconds
Definition: c2s.h:265
int local_port
unencrypted port
Definition: c2s.h:207
Definition: c2s.h:121
int(* create_user)(authreg_t ar, const char *username, const char *realm)
make or break the user (register / register remove)
Definition: c2s.h:337
xht hosts
hosts mapping
Definition: c2s.h:292
const char * host_pemfile
starttls pemfile
Definition: c2s.h:126
int conn_rate_total
connection rates
Definition: c2s.h:257
int c2s_router_sx_callback(sx_t s, sx_event_t e, void *data, void *arg)
Definition: c2s.c:700
struct authreg_st * authreg_t
Definition: c2s.h:56
int byte_rate_wait
Definition: c2s.h:266
sx_env_t sx_env
sx environment
Definition: c2s.h:168
int retry_init
connect retry
Definition: c2s.h:198
char c2s_id[44]
session id for this jid for us and them
Definition: c2s.h:63
int stanza_rate_seconds
Definition: c2s.h:270
xht sm_avail
availability of sms that we are servicing
Definition: c2s.h:296
Definition: c2s.h:148
C2S_API void sm_start(sess_t sess, bres_t res)
Definition: sm.c:66
host_t vhost
Definition: c2s.h:293
xht stream_redirects
stream redirection (see-other-host) on session connect
Definition: c2s.h:233
int conn_rate_wait
Definition: c2s.h:259
log_type_t log_type
log data
Definition: c2s.h:189
int retry_lost
Definition: c2s.h:199
sig_atomic_t c2s_lost_router
Definition: main.c:26
jqueue_t dead_sess
list of sess on the way out
Definition: c2s.h:283
int(* ar_module_init_fn)(authreg_t)
type for the module init function
Definition: c2s.h:359
#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:174
C2S_API void c2s_pbx_init(c2s_t c2s)
Definition: pbx.c:120
const char * to_port
Definition: c2s.h:386
int pbx_pipe_fd
Definition: c2s.h:229
long long int packet_count
packet counter
Definition: c2s.h:194
int rate_log
Definition: c2s.h:92
const char ** char_val
Definition: c2s.h:378
xht sessions
sessions
Definition: c2s.h:165
int(* create_challenge)(authreg_t ar, const char *username, const char *challenge, int maxlen)
Apple extensions for challenge/response authentication methods.
Definition: c2s.h:348
void(* free)(authreg_t ar)
Definition: c2s.h:340
rate_t rate
Definition: c2s.h:91
const char * packet_stats
Definition: c2s.h:195
const char * ar_module_name
auth/reg module
Definition: c2s.h:249
rate_t stanza_rate
Definition: c2s.h:94
Definition: mio.h:100
char auth_challenge[65]
Apple: session challenge for challenge-response authentication.
Definition: c2s.h:113
Definition: util.h:258
int local_ssl_port
encrypted port
Definition: c2s.h:210
sx_plugin_t sx_sasl
Definition: c2s.h:170
void authreg_free(authreg_t ar)
shutdown the authreg system
Definition: authreg.c:116
session packet handling
Definition: c2s.h:375
sx_event_t
things that can happen
Definition: sx.h:56
const char * ar_register_oob
Definition: c2s.h:143
c2s_t c2s
Definition: c2s.h:75
jqueue_t dead
list of sx_t on the way out
Definition: c2s.h:280
log_t log
logging
Definition: c2s.h:186
int(* user_authz_allowed)(authreg_t ar, const char *username, const char *realm, const char *requested_user)
returns 1 if the user is permitted to authorize as the requested_user, 0 if not.
Definition: c2s.h:345
const char * pbx_pipe
PBX integration named pipe.
Definition: c2s.h:228
int(* get_password)(authreg_t ar, const char *username, const char *realm, char password[257])
return this users cleartext password in the array (digest auth, password auth)
Definition: c2s.h:328
const char * router_user
Definition: c2s.h:155
char sm_id[41]
Definition: c2s.h:63
int host_require_starttls
require starttls
Definition: c2s.h:138
char skey[44]
Definition: c2s.h:79
authreg_t authreg_init(c2s_t c2s, const char *name)
get a handle for the named module
Definition: authreg.c:40
const char * local_private_key_password
private key password
Definition: c2s.h:219
int(* set_password)(authreg_t ar, const char *username, const char *realm, char password[257])
store this password (register)
Definition: c2s.h:334
int ar_ssl_mechanisms
Definition: c2s.h:254
int online
true if we&#39;re bound in the router
Definition: c2s.h:289
int sasl_authd
Definition: c2s.h:110
int active
Definition: c2s.h:105
int c2s_router_mio_callback(mio_t m, mio_action_t a, mio_fd_t fd, void *data, void *arg)
Definition: c2s.c:1365
C2S_API void sm_delete(sess_t sess, bres_t res)
Definition: sm.c:82
int stanza_rate_total
stanza rates
Definition: c2s.h:269
const char * local_pemfile
encrypted port pemfile
Definition: c2s.h:213
const char * local_cachain
encrypted port cachain file
Definition: c2s.h:216
bres_t next
Definition: c2s.h:67
const char * host_cachain
certificate chain
Definition: c2s.h:129
int byte_rate_total
byte rates (karma)
Definition: c2s.h:264