Browse code

auth_diameter: converted to the new module interface

Federico Cabiddu authored on 27/09/2018 15:13:37 • Victor Seva committed on 28/09/2018 11:03:26
Showing 1 changed files
... ...
@@ -96,16 +96,14 @@ static param_export_t params[] = {
96 96
 struct module_exports exports = {
97 97
 	"auth_diameter",
98 98
 	DEFAULT_DLFLAGS, /* dlopen flags */
99
-	cmds,          /* Exported functions */
100
-	params,        /* Exported parameters */
101
-	0,             /* exported statistics */
102
-	0,             /* exported MI functions */
103
-	0,             /* exported pseudo-variables */
104
-	0,             /* extra processes */
105
-	mod_init,      /* module initialization function */
106
-	0,             /* response function */
107
-	0,             /* destroy function */
108
-	mod_child_init /* child initialization function */
99
+	cmds,            /* Exported functions */
100
+	params,          /* Exported parameters */
101
+	0,               /* exported RPC methods */
102
+	0,               /* exported pseudo-variables */
103
+	0,               /* response function */
104
+	mod_init,        /* module initialization function */
105
+	mod_child_init,  /* child initialization function */
106
+	0                /* destroy function */
109 107
 };
110 108
 
111 109
 
Browse code

auth_diameter: init socketfd variable

- remove inline to functions that break the symbol linking

Daniel-Constantin Mierla authored on 09/12/2017 12:46:07
Showing 1 changed files
... ...
@@ -61,6 +61,7 @@ int diameter_is_user_in(struct sip_msg* _msg, char* group, char* _s2);
61 61
 char* diameter_client_host = "localhost";
62 62
 int diameter_client_port = 3000;
63 63
 int use_domain = 0;
64
+int sockfd = -1;
64 65
 
65 66
 rd_buf_t *rb;
66 67
 
Browse code

auth_diameter: removed svn id, history

Daniel-Constantin Mierla authored on 26/07/2017 20:32:39
Showing 1 changed files
... ...
@@ -1,6 +1,4 @@
1 1
 /*
2
- * $Id$ 
3
- *
4 2
  * Digest Authentication - Diameter support
5 3
  *
6 4
  * Copyright (C) 2001-2003 FhG Fokus
... ...
@@ -21,11 +19,6 @@
21 19
  * along with this program; if not, write to the Free Software 
22 20
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
23 21
  *
24
- * History:
25
- * -------
26
- *  
27
- *  
28
- * 2006-03-01 pseudo variables support for domain name (bogdan)
29 22
  */
30 23
 
31 24
 #include <stdio.h>
Browse code

core, lib, modules: updated include paths for header files

Daniel-Constantin Mierla authored on 07/12/2016 11:07:22
Showing 1 changed files
... ...
@@ -36,11 +36,11 @@
36 36
 #include <netinet/in.h>
37 37
 #include <netdb.h> 
38 38
 
39
-#include "../../sr_module.h"
40
-#include "../../error.h"
41
-#include "../../dprint.h"
42
-#include "../../pvar.h"
43
-#include "../../mem/mem.h"
39
+#include "../../core/sr_module.h"
40
+#include "../../core/error.h"
41
+#include "../../core/dprint.h"
42
+#include "../../core/pvar.h"
43
+#include "../../core/mem/mem.h"
44 44
 
45 45
 #include "diameter_msg.h"
46 46
 #include "auth_diameter.h"
Browse code

core, lib, modules: restructured source code tree

- new folder src/ to hold the source code for main project applications
- main.c is in src/
- all core files are subfolder are in src/core/
- modules are in src/modules/
- libs are in src/lib/
- application Makefiles are in src/
- application binary is built in src/ (src/kamailio)

Daniel-Constantin Mierla authored on 07/12/2016 11:03:51
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,264 @@
1
+/*
2
+ * $Id$ 
3
+ *
4
+ * Digest Authentication - Diameter support
5
+ *
6
+ * Copyright (C) 2001-2003 FhG Fokus
7
+ *
8
+ * This file is part of Kamailio, a free SIP server.
9
+ *
10
+ * Kamailio is free software; you can redistribute it and/or modify
11
+ * it under the terms of the GNU General Public License as published by
12
+ * the Free Software Foundation; either version 2 of the License, or
13
+ * (at your option) any later version
14
+ * 
15
+ * Kamailio is distributed in the hope that it will be useful,
16
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
+ * GNU General Public License for more details.
19
+ *
20
+ * You should have received a copy of the GNU General Public License 
21
+ * along with this program; if not, write to the Free Software 
22
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
23
+ *
24
+ * History:
25
+ * -------
26
+ *  
27
+ *  
28
+ * 2006-03-01 pseudo variables support for domain name (bogdan)
29
+ */
30
+
31
+#include <stdio.h>
32
+#include <stdlib.h>
33
+#include <string.h>
34
+#include <sys/types.h>
35
+#include <sys/socket.h>
36
+#include <netinet/in.h>
37
+#include <netdb.h> 
38
+
39
+#include "../../sr_module.h"
40
+#include "../../error.h"
41
+#include "../../dprint.h"
42
+#include "../../pvar.h"
43
+#include "../../mem/mem.h"
44
+
45
+#include "diameter_msg.h"
46
+#include "auth_diameter.h"
47
+#include "authorize.h"
48
+#include "tcp_comm.h"
49
+
50
+MODULE_VERSION
51
+
52
+
53
+/** SL API structure */
54
+sl_api_t slb;
55
+
56
+static int mod_init(void);                        /* Module initialization function*/
57
+static int mod_child_init(int r);                 /* Child initialization function*/
58
+static int auth_fixup(void** param, int param_no);
59
+static int group_fixup(void** param, int param_no);
60
+
61
+int diameter_www_authorize(struct sip_msg* _msg, char* _realm, char* _s2);
62
+int diameter_proxy_authorize(struct sip_msg* _msg, char* _realm, char* _s2);
63
+int diameter_is_user_in(struct sip_msg* _msg, char* group, char* _s2);
64
+
65
+/*
66
+ * Module parameter variables
67
+ */
68
+char* diameter_client_host = "localhost";
69
+int diameter_client_port = 3000;
70
+int use_domain = 0;
71
+
72
+rd_buf_t *rb;
73
+
74
+/*
75
+ * Exported functions
76
+ */
77
+static cmd_export_t cmds[] = {
78
+	{"diameter_www_authorize",   (cmd_function)diameter_www_authorize,   1, auth_fixup,
79
+			0, REQUEST_ROUTE},
80
+	{"diameter_proxy_authorize", (cmd_function)diameter_proxy_authorize, 1, auth_fixup,
81
+			0, REQUEST_ROUTE},
82
+	{"diameter_is_user_in",      (cmd_function)diameter_is_user_in,      2, group_fixup,
83
+			0, REQUEST_ROUTE},
84
+	{0, 0, 0, 0, 0, 0}
85
+};
86
+
87
+
88
+/*
89
+ * Exported parameters
90
+ */
91
+static param_export_t params[] = {
92
+	{"diameter_client_host", PARAM_STRING, &diameter_client_host},
93
+	{"diameter_client_port", INT_PARAM, &diameter_client_port},
94
+	{"use_domain", INT_PARAM, &use_domain},
95
+	{0, 0, 0}
96
+};
97
+
98
+
99
+/*
100
+ * Module interface
101
+ */
102
+struct module_exports exports = {
103
+	"auth_diameter",
104
+	DEFAULT_DLFLAGS, /* dlopen flags */
105
+	cmds,          /* Exported functions */
106
+	params,        /* Exported parameters */
107
+	0,             /* exported statistics */
108
+	0,             /* exported MI functions */
109
+	0,             /* exported pseudo-variables */
110
+	0,             /* extra processes */
111
+	mod_init,      /* module initialization function */
112
+	0,             /* response function */
113
+	0,             /* destroy function */
114
+	mod_child_init /* child initialization function */
115
+};
116
+
117
+
118
+/*
119
+ * Module initialization function
120
+ */
121
+static int mod_init(void)
122
+{
123
+	LM_DBG("auth_diameter - Initializing\n");
124
+
125
+	/* bind the SL API */
126
+	if (sl_load_api(&slb)!=0) {
127
+		LM_ERR("cannot bind to SL API\n");
128
+		return -1;
129
+	}
130
+	
131
+	return 0;
132
+}
133
+
134
+static int mod_child_init(int r)
135
+{	
136
+	/* open TCP connection */
137
+	LM_DBG("initializing TCP connection\n");
138
+
139
+	sockfd = init_mytcp(diameter_client_host, diameter_client_port);
140
+	if(sockfd==-1) 
141
+	{
142
+		LM_DBG("the TCP connection was not established\n");
143
+		return -1;
144
+	}
145
+
146
+	LM_DBG("the TCP connection was established on socket=%d\n", sockfd);
147
+	
148
+	rb = (rd_buf_t*)pkg_malloc(sizeof(rd_buf_t));
149
+	if(!rb)
150
+	{
151
+		LM_DBG("no more free pkg memory\n");
152
+		return -1;
153
+	}
154
+	rb->buf = 0;
155
+	rb->chall = 0;
156
+
157
+	return 0;
158
+}
159
+
160
+#if 0
161
+static void destroy(void)
162
+{
163
+	close_tcp_connection(sockfd);
164
+}
165
+#endif
166
+
167
+
168
+/*
169
+ * Convert char* parameter to pv_elem_t* parameter
170
+ */
171
+static int auth_fixup(void** param, int param_no)
172
+{
173
+	pv_elem_t *model;
174
+	str s;
175
+
176
+	if (param_no == 1) {
177
+		s.s = (char*)*param;
178
+		if (s.s==0 || s.s[0]==0) {
179
+			model = 0;
180
+		} else {
181
+			s.len = strlen(s.s);
182
+			if (pv_parse_format(&s,&model)<0) {
183
+				LM_ERR("pv_parse_format failed\n");
184
+				return E_OUT_OF_MEM;
185
+			}
186
+		}
187
+		*param = (void*)model;
188
+	}
189
+
190
+	return 0;
191
+}
192
+
193
+
194
+/*
195
+ * Authorize using Proxy-Authorization header field
196
+ */
197
+int diameter_proxy_authorize(struct sip_msg* _msg, char* _realm, char* _s2)
198
+{
199
+	/* realm parameter is converted in fixup */
200
+	return authorize(_msg, (pv_elem_t*)_realm, HDR_PROXYAUTH_T);
201
+}
202
+
203
+
204
+/*
205
+ * Authorize using WWW-Authorization header field
206
+ */
207
+int diameter_www_authorize(struct sip_msg* _msg, char* _realm, char* _s2)
208
+{
209
+	return authorize(_msg, (pv_elem_t*)_realm, HDR_AUTHORIZATION_T);
210
+}
211
+
212
+
213
+static int group_fixup(void** param, int param_no)
214
+{
215
+	str* s;
216
+
217
+	if (param_no == 1) 
218
+	{
219
+		if (!strcasecmp((char*)*param, "Request-URI")) 
220
+		{
221
+			*param = (void*)1;
222
+			goto end;
223
+		} 
224
+
225
+		if(!strcasecmp((char*)*param, "To")) 
226
+		{
227
+			*param = (void*)2;
228
+			goto end;
229
+		} 
230
+
231
+		if (!strcasecmp((char*)*param, "From")) 
232
+		{
233
+			*param = (void*)3;
234
+			goto end;
235
+		} 
236
+
237
+		if (!strcasecmp((char*)*param, "Credentials")) 
238
+		{
239
+			*param = (void*)4;
240
+			goto end;
241
+		}
242
+				
243
+		LM_ERR("unsupported Header Field identifier\n");
244
+		return E_UNSPEC;
245
+	} 
246
+	
247
+	if (param_no == 2) 
248
+	{
249
+		s = (str*)pkg_malloc(sizeof(str));
250
+		if (!s) 
251
+		{
252
+			LM_ERR("no pkg memory left\n");
253
+			return E_UNSPEC;
254
+		}
255
+		s->s = (char*)*param;
256
+		s->len = strlen(s->s);
257
+		*param = (void*)s;
258
+	}
259
+
260
+end:
261
+	return 0;
262
+}
263
+
264
+