jabberd2  2.3.3
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 
146  const char *ar_register_oob;
148 
149 };
150 
151 struct c2s_st {
153  const char *id;
154 
156  const char *router_ip;
158  const char *router_user;
159  const char *router_pass;
160  const char *router_pemfile;
161  const char *router_cachain;
163 
166 
169 
174 
178 
181 #ifdef HAVE_SSL
182  mio_fd_t server_ssl_fd;
183 #endif
184 
187 
190 
193  const char *log_facility;
194  const char *log_ident;
195 
197  long long int packet_count;
198  const char *packet_stats;
199 
205 
207  const char *local_ip;
208 
211 
214 
216  const char *local_pemfile;
217 
219  const char *local_cachain;
220 
223 
226 
228  const char *http_forward;
229 
231  const char *pbx_pipe;
234 
237 
240 
243 
248 
249  time_t next_check;
250 
252  const char *ar_module_name;
253  authreg_t ar;
254 
258 
263 
265 
270 
275 
278 
281 
284 
287 
289  int started;
290 
292  int online;
293 
296  host_t vhost;
297 
300 };
301 
302 extern sig_atomic_t c2s_lost_router;
303 
304 C2S_API int c2s_router_mio_callback(mio_t m, mio_action_t a, mio_fd_t fd, void *data, void *arg);
305 C2S_API int c2s_router_sx_callback(sx_t s, sx_event_t e, void *data, void *arg);
306 
307 C2S_API void sm_start(sess_t sess, bres_t res);
308 C2S_API void sm_end(sess_t sess, bres_t res);
309 C2S_API void sm_create(sess_t sess, bres_t res);
310 C2S_API void sm_delete(sess_t sess, bres_t res);
311 C2S_API void sm_packet(sess_t sess, bres_t res, nad_t nad);
312 
313 C2S_API int bind_init(sx_env_t env, sx_plugin_t p, va_list args);
314 
315 C2S_API void c2s_pbx_init(c2s_t c2s);
316 
317 /* My IP Address plugin */
318 JABBERD2_API int address_init(sx_env_t env, sx_plugin_t p, va_list args);
319 
321 {
322  c2s_t c2s;
323 
325  void *private;
326 
328  int (*user_exists)(authreg_t ar, sess_t sess, const char *username,const char *realm);
329 
331  int (*get_password)(authreg_t ar, sess_t sess, const char *username, const char *realm, char password[257]);
332 
334  int (*check_password)(authreg_t ar, sess_t sess, const char *username, const char *realm, char password[257]);
335 
337  int (*set_password)(authreg_t ar, sess_t sess, const char *username, const char *realm, char password[257]);
338 
340  int (*create_user)(authreg_t ar, sess_t sess, const char *username, const char *realm);
341  int (*delete_user)(authreg_t ar, sess_t sess, const char *username, const char *realm);
342 
344  void (*sess_end)(authreg_t ar, sess_t sess);
345 
347  void (*free)(authreg_t ar);
348 
349  /* Additions at the end - to preserve offsets for existing modules */
350 
352  int (*user_authz_allowed)(authreg_t ar, sess_t sess, const char *username, const char *realm, const char *requested_user);
353 
355  int (*create_challenge)(authreg_t ar, sess_t sess, const char *username, const char *realm, char *challenge, int maxlen);
356  int (*check_response)(authreg_t ar, sess_t sess, const char *username, const char *realm, const char *challenge, const char *response);
357 };
358 
360 C2S_API authreg_t authreg_init(c2s_t c2s, const char *name);
361 
363 C2S_API void authreg_free(authreg_t ar);
364 
366 typedef int (*ar_module_init_fn)(authreg_t);
367 
369 C2S_API int authreg_process(c2s_t c2s, sess_t sess, nad_t nad);
370 
371 /*
372 int authreg_user_exists(authreg_t ar, const char *username, const char *realm);
373 int authreg_get_password(authreg_t ar, const char *username, const char *realm, char password[257]);
374 int authreg_check_password(authreg_t ar, const char *username, const char *realm, char password[257]);
375 int authreg_set_password(authreg_t ar, const char *username, const char *realm, char password[257]);
376 int authreg_create_user(authreg_t ar, const char *username, const char *realm);
377 int authreg_delete_user(authreg_t ar, const char *username, const char *realm);
378 void authreg_free(authreg_t ar);
379 */
380 
381 /* union for xhash_iter_get to comply with strict-alias rules for gcc3 */
382 union xhashv
383 {
384  void **val;
385  const char **char_val;
386  sess_t *sess_val;
387 };
388 
389 // Data for stream redirect errors
390 typedef struct stream_redirect_st
391 {
392  const char *to_address;
393  const char *to_port;
int(* check_password)(authreg_t ar, sess_t sess, 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:334
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:245
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:193
config_t config
config
Definition: c2s.h:186
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:1376
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:228
c2s_t c2s
Definition: c2s.h:322
int ar_register_enable
registration
Definition: c2s.h:144
int started
this is true if we've connected to the router at least once
Definition: c2s.h:289
unsigned int packet_count
Definition: c2s.h:98
access_t access
access controls
Definition: c2s.h:280
int(* get_password)(authreg_t ar, sess_t sess, const char *username, const char *realm, char password[257])
return this users cleartext password in the array (digest auth, password auth)
Definition: c2s.h:331
int(* create_challenge)(authreg_t ar, sess_t sess, const char *username, const char *realm, char *challenge, int maxlen)
Apple extensions for challenge/response authentication methods.
Definition: c2s.h:355
xht conn_rates
Definition: c2s.h:264
#define JABBERD2_API
Definition: mio.h:39
int(* user_exists)(authreg_t ar, sess_t sess, const char *username, const char *realm)
returns 1 if the user exists, 0 if not
Definition: c2s.h:328
int compression
enable Stream Compression
Definition: c2s.h:242
int retry_left
Definition: c2s.h:204
int conn_rate_seconds
Definition: c2s.h:261
an environment
Definition: sx.h:379
int(* ar_module_init_fn)(authreg_t)
type for the module init function
Definition: c2s.h:366
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:194
list of resources bound to session
Definition: c2s.h:59
int io_max_fds
max file descriptors
Definition: c2s.h:239
char * host_private_key_password
private key password
Definition: c2s.h:135
int io_check_keepalive
Definition: c2s.h:247
a plugin
Definition: sx.h:344
nad_t result
Definition: c2s.h:108
int ar_mechanisms
allowed mechanisms
Definition: c2s.h:256
holder for the config hash and nad
Definition: util.h:200
time_t next_check
Definition: c2s.h:249
const char * id
our id (hostname) with the router
Definition: c2s.h:153
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:277
int(* set_password)(authreg_t ar, sess_t sess, const char *username, const char *realm, char password[257])
store this password (register)
Definition: c2s.h:337
sx_t router
router's conn
Definition: c2s.h:176
mio_fd_t pbx_pipe_mio_fd
Definition: c2s.h:233
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:180
authreg_t ar
Definition: c2s.h:253
const char * router_pemfile
Definition: c2s.h:160
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:668
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:161
const char * router_ip
how to connect to the router
Definition: c2s.h:156
const char * local_ip
ip to listen on
Definition: c2s.h:207
int(* user_authz_allowed)(authreg_t ar, sess_t sess, 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:352
const char * router_private_key_password
Definition: c2s.h:162
int router_port
Definition: c2s.h:157
sx_plugin_t sx_ssl
Definition: c2s.h:172
void(* sess_end)(authreg_t ar, sess_t sess)
called prior to session being closed, to cleanup session specific private data
Definition: c2s.h:344
mio_t mio
mio context
Definition: c2s.h:165
mio - manage i/o
holds the state for a single stream
Definition: sx.h:251
int retry_sleep
Definition: c2s.h:203
const char * ar_register_instructions
Definition: c2s.h:145
int stanza_rate_wait
Definition: c2s.h:274
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:392
void ** val
Definition: c2s.h:384
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:246
const char * router_pass
Definition: c2s.h:159
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:147
sess_t * sess_val
Definition: c2s.h:386
host_t host
host this session belongs to
Definition: c2s.h:89
int local_verify_mode
verify-mode
Definition: c2s.h:225
Definition: jid.h:42
int byte_rate_seconds
Definition: c2s.h:268
int local_port
unencrypted port
Definition: c2s.h:210
Definition: c2s.h:124
xht hosts
hosts mapping
Definition: c2s.h:295
const char * host_pemfile
starttls pemfile
Definition: c2s.h:129
int conn_rate_total
connection rates
Definition: c2s.h:260
struct authreg_st * authreg_t
Definition: c2s.h:56
int byte_rate_wait
Definition: c2s.h:269
void * authreg_private
Definition: c2s.h:116
sx_env_t sx_env
sx environment
Definition: c2s.h:171
int retry_init
connect retry
Definition: c2s.h:201
char c2s_id[44]
session id for this jid for us and them
Definition: c2s.h:63
int stanza_rate_seconds
Definition: c2s.h:273
xht sm_avail
availability of sms that we are servicing
Definition: c2s.h:299
Definition: c2s.h:151
C2S_API void sm_start(sess_t sess, bres_t res)
Definition: sm.c:66
host_t vhost
Definition: c2s.h:296
xht stream_redirects
stream redirection (see-other-host) on session connect
Definition: c2s.h:236
int conn_rate_wait
Definition: c2s.h:262
log_type_t log_type
log data
Definition: c2s.h:192
int retry_lost
Definition: c2s.h:202
sig_atomic_t c2s_lost_router
Definition: main.c:26
jqueue_t dead_sess
list of sess on the way out
Definition: c2s.h:286
#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:177
C2S_API void c2s_pbx_init(c2s_t c2s)
Definition: pbx.c:120
const char * to_port
Definition: c2s.h:393
int pbx_pipe_fd
Definition: c2s.h:232
long long int packet_count
packet counter
Definition: c2s.h:197
int rate_log
Definition: c2s.h:92
const char ** char_val
Definition: c2s.h:385
xht sessions
sessions
Definition: c2s.h:168
int(* create_user)(authreg_t ar, sess_t sess, const char *username, const char *realm)
make or break the user (register / register remove)
Definition: c2s.h:340
rate_t rate
Definition: c2s.h:91
const char * packet_stats
Definition: c2s.h:198
const char * ar_module_name
auth/reg module
Definition: c2s.h:252
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:213
sx_plugin_t sx_sasl
Definition: c2s.h:173
session packet handling
Definition: c2s.h:382
sx_event_t
things that can happen
Definition: sx.h:56
C2S_API void authreg_free(authreg_t ar)
shut down
Definition: authreg.c:116
const char * ar_register_oob
Definition: c2s.h:146
c2s_t c2s
Definition: c2s.h:75
jqueue_t dead
list of sx_t on the way out
Definition: c2s.h:283
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:189
const char * pbx_pipe
PBX integration named pipe.
Definition: c2s.h:231
int(* check_response)(authreg_t ar, sess_t sess, const char *username, const char *realm, const char *challenge, const char *response)
Definition: c2s.h:356
const char * router_user
Definition: c2s.h:158
char sm_id[41]
Definition: c2s.h:63
int host_require_starttls
require starttls
Definition: c2s.h:141
char skey[44]
Definition: c2s.h:79
const char * local_private_key_password
private key password
Definition: c2s.h:222
int ar_ssl_mechanisms
Definition: c2s.h:257
int online
true if we're bound in the router
Definition: c2s.h:292
int sasl_authd
Definition: c2s.h:110
int active
Definition: c2s.h:105
void(* free)(authreg_t ar)
called prior to authreg shutdown
Definition: c2s.h:347
C2S_API void sm_delete(sess_t sess, bres_t res)
Definition: sm.c:82
int stanza_rate_total
stanza rates
Definition: c2s.h:272
const char * local_pemfile
encrypted port pemfile
Definition: c2s.h:216
const char * local_cachain
encrypted port cachain file
Definition: c2s.h:219
int(* delete_user)(authreg_t ar, sess_t sess, const char *username, const char *realm)
Definition: c2s.h:341
C2S_API int c2s_router_sx_callback(sx_t s, sx_event_t e, void *data, void *arg)
Definition: c2s.c:711
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:267