jabberd2  2.3.2
plugins.h
Go to the documentation of this file.
1 /*
2  * jabberd - Jabber Open Source Server
3  * Copyright (c) 2002-2007 Jeremie Miller, Thomas Muldowney,
4  * Ryan Eatmon, Robert Norris, Tomasz Sterna
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 #ifndef INCL_SX_PLUGINS_H
22 #define INCL_SX_PLUGINS_H
23 
25 #define SX_SSL_WRAPPER (1<<0)
26 #define SX_SSL_STARTTLS_OFFER (1<<1)
27 #define SX_SSL_STARTTLS_REQUIRE (1<<2)
29 #define SX_SASL_OFFER (1<<3)
31 #define SX_COMPRESS_WRAPPER (1<<4)
32 #define SX_COMPRESS_OFFER (1<<5)
33 
34 
36 #define SX_SSL_MAGIC (0x01)
37 
38 
40 /* prefix 0x0. is taken by sx core errors in sx.h */
41 #define SX_ERR_SSL (0x010)
42 #define SX_ERR_STARTTLS_FAILURE (0x011)
43 
44 #define SX_ERR_COMPRESS (0x020)
45 #define SX_ERR_COMPRESS_FAILURE (0x021)
46 
47 
48 #define SX_CONN_EXTERNAL_ID_MAX_COUNT 8
49 
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53 
54 
55 /* SSL plugin */
56 #ifdef HAVE_SSL
57 
58 #include <openssl/md5.h>
59 #include <openssl/ssl.h>
60 #include <openssl/err.h>
61 #include <openssl/x509v3.h>
62 
63 
65 JABBERD2_API int sx_ssl_init(sx_env_t env, sx_plugin_t p, va_list args);
66 
68 JABBERD2_API int sx_ssl_server_addcert(sx_plugin_t p, const char *name, const char *pemfile, const char *cachain, int mode, const char *private_key_password);
69 
71 JABBERD2_API int sx_ssl_client_starttls(sx_plugin_t p, sx_t s, const char *pemfile, const char *private_key_password);
72 
73 /* previous states */
74 #define SX_SSL_STATE_NONE (0)
75 #define SX_SSL_STATE_WANT_READ (1)
76 #define SX_SSL_STATE_WANT_WRITE (2)
77 #define SX_SSL_STATE_ERROR (3)
78 
80 typedef struct _sx_ssl_conn_st {
81  /* id and ssf for sasl external auth */
82  char *external_id[SX_CONN_EXTERNAL_ID_MAX_COUNT];
83 
84  SSL *ssl;
85 
86  BIO *wbio, *rbio;
87 
88  jqueue_t wq;
89 
90  int last_state;
91 
92  char *pemfile;
93 
94  char *private_key_password;
95 } *_sx_ssl_conn_t;
96 
97 #endif /* HAVE_SSL */
98 
99 
100 /* SASL plugin */
101 
103 JABBERD2_API int sx_sasl_init(sx_env_t env, sx_plugin_t p, va_list args);
104 
106 typedef int (*sx_sasl_callback_t)(int cb, void *arg, void **res, sx_t s, void *cbarg);
107 
108 /* callbacks */
109 #define sx_sasl_cb_GET_REALM (0x00)
110 #define sx_sasl_cb_GET_PASS (0x01)
111 #define sx_sasl_cb_CHECK_PASS (0x02)
112 #define sx_sasl_cb_CHECK_AUTHZID (0x03)
113 #define sx_sasl_cb_GEN_AUTHZID (0x04)
114 #define sx_sasl_cb_CHECK_MECH (0x05)
115 
116 /* error codes */
117 #define sx_sasl_ret_OK (0)
118 #define sx_sasl_ret_FAIL (1)
119 
121 JABBERD2_API int sx_sasl_auth(sx_plugin_t p, sx_t s, const char *appname, const char *mech, const char *user, const char *pass);
122 
123 /* for passing auth data to callback */
124 typedef struct sx_sasl_creds_st {
125  const char *authnid;
126  const char *realm;
127  const char *authzid;
128  const char *pass;
129 } *sx_sasl_creds_t;
130 
131 
132 /* Stream Compression plugin */
133 #ifdef HAVE_LIBZ
134 
135 #include <zlib.h>
136 
138 JABBERD2_API int sx_compress_init(sx_env_t env, sx_plugin_t p, va_list args);
139 
140 /* allocation chunk for decompression */
141 #define SX_COMPRESS_CHUNK 16384
142 
144 typedef struct _sx_compress_conn_st {
145  /* zlib streams for deflate() and inflate() */
146  z_stream wstrm, rstrm;
147 
148  /* buffers for compressed and decompressed data */
149  sx_buf_t wbuf, rbuf;
150 
151 } *_sx_compress_conn_t;
152 
153 #endif /* HAVE_LIBZ */
154 
155 
156 /* Stanza Acknowledgements plugin */
158 JABBERD2_API int sx_ack_init(sx_env_t env, sx_plugin_t p, va_list args);
159 
160 
161 #ifdef __cplusplus
162 }
163 #endif
164 
165 
166 #endif /* INCL_SX_PLUGINS_H */
int sx_ssl_server_addcert(sx_plugin_t p, const char *name, const char *pemfile, const char *cachain, int mode, const char *password)
args: name, pemfile, cachain, mode
Definition: ssl.c:881
Definition: sx.h:113
#define JABBERD2_API
Definition: mio.h:39
an environment
Definition: sx.h:379
a plugin
Definition: sx.h:344
JABBERD2_API int sx_ack_init(sx_env_t env, sx_plugin_t p, va_list args)
init function
Definition: ack.c:103
const char * authnid
Definition: plugins.h:125
holds the state for a single stream
Definition: sx.h:251
struct sx_sasl_creds_st * sx_sasl_creds_t
const char * authzid
Definition: plugins.h:127
const char * realm
Definition: plugins.h:126
JABBERD2_API int sx_sasl_init(sx_env_t env, sx_plugin_t p, va_list args)
init function
Definition: sasl.c:821
JABBERD2_API int sx_sasl_auth(sx_plugin_t p, sx_t s, const char *appname, const char *mech, const char *user, const char *pass)
trigger for client auth
Definition: sasl.c:874
int(* sx_sasl_callback_t)(int cb, void *arg, void **res, sx_t s, void *cbarg)
the callback function
Definition: plugins.h:106
int sx_ssl_init(sx_env_t env, sx_plugin_t p, va_list args)
args: name, pemfile, cachain, mode
Definition: ssl.c:833
int sx_compress_init(sx_env_t env, sx_plugin_t p, va_list args)
args: none
Definition: compress.c:331
const char * pass
Definition: plugins.h:128
#define SX_CONN_EXTERNAL_ID_MAX_COUNT
Definition: plugins.h:48
int sx_ssl_client_starttls(sx_plugin_t p, sx_t s, const char *pemfile, const char *private_key_password)
Definition: ssl.c:1012