Mercurial > hg > freeDiameter
annotate extensions/app_radgw/rgwx_sample.c @ 256:042af0000c0a
Ported the auth plugin
author | Sebastien Decugis <sdecugis@nict.go.jp> |
---|---|
date | Fri, 16 Apr 2010 16:57:39 +0900 |
parents | cb4307a1cd29 |
children | 5df55136361b |
rev | line source |
---|---|
255
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
1 /********************************************************************************************************* |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
2 * Software License Agreement (BSD License) * |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
3 * Author: Sebastien Decugis <sdecugis@nict.go.jp> * |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
4 * * |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
5 * Copyright (c) 2009, WIDE Project and NICT * |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
6 * All rights reserved. * |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
7 * * |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
8 * Redistribution and use of this software in source and binary forms, with or without modification, are * |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
9 * permitted provided that the following conditions are met: * |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
10 * * |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
11 * * Redistributions of source code must retain the above * |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
12 * copyright notice, this list of conditions and the * |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
13 * following disclaimer. * |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
14 * * |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
15 * * Redistributions in binary form must reproduce the above * |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
16 * copyright notice, this list of conditions and the * |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
17 * following disclaimer in the documentation and/or other * |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
18 * materials provided with the distribution. * |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
19 * * |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
20 * * Neither the name of the WIDE Project or NICT nor the * |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
21 * names of its contributors may be used to endorse or * |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
22 * promote products derived from this software without * |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
23 * specific prior written permission of WIDE Project and * |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
24 * NICT. * |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
25 * * |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
27 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
28 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
29 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
32 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
34 *********************************************************************************************************/ |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
35 |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
36 /* Sample radius/diameter gateway plugin, for developers to see the structure of a plugin. */ |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
37 |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
38 #include "rgw_common.h" |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
39 |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
40 /* The state of this extension */ |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
41 struct rgwp_config { |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
42 /* In a real extension, we would store the parsed configuration file, and the states of the extension */ |
256
042af0000c0a
Ported the auth plugin
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
255
diff
changeset
|
43 int init; |
255
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
44 }; |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
45 |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
46 /* The function called at plugin initialization */ |
256
042af0000c0a
Ported the auth plugin
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
255
diff
changeset
|
47 static int sample_conf_parse ( char * conf_file, struct rgwp_config ** state ) |
255
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
48 { |
256
042af0000c0a
Ported the auth plugin
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
255
diff
changeset
|
49 TRACE_ENTRY("%p %p", conf_file, state); |
042af0000c0a
Ported the auth plugin
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
255
diff
changeset
|
50 CHECK_PARAMS(state); |
255
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
51 |
256
042af0000c0a
Ported the auth plugin
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
255
diff
changeset
|
52 CHECK_MALLOC( *state = malloc(sizeof(struct rgwp_config)) ); |
255
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
53 |
256
042af0000c0a
Ported the auth plugin
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
255
diff
changeset
|
54 (*state)->init = 1; |
255
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
55 |
256
042af0000c0a
Ported the auth plugin
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
255
diff
changeset
|
56 return 0; |
255
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
57 } |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
58 |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
59 /* This function is called when the plugin is unloaded, to cleanup all the states */ |
256
042af0000c0a
Ported the auth plugin
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
255
diff
changeset
|
60 static void sample_conf_free(struct rgwp_config * state) |
255
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
61 { |
256
042af0000c0a
Ported the auth plugin
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
255
diff
changeset
|
62 TRACE_ENTRY("%p", state); |
042af0000c0a
Ported the auth plugin
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
255
diff
changeset
|
63 CHECK_PARAMS_DO( state, ); |
042af0000c0a
Ported the auth plugin
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
255
diff
changeset
|
64 free(state); |
255
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
65 return; |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
66 } |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
67 |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
68 /* This function is called on incoming RADIUS messages. It should handle (some) RADIUS data and store into the Diameter message. */ |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
69 static int sample_rad_req( struct rgwp_config * cs, struct session * session, struct radius_msg * rad_req, struct radius_msg ** rad_ans, struct msg ** diam_fw, struct rgw_client * cli ) |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
70 { |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
71 TRACE_ENTRY("%p %p %p %p %p %p", cs, session, rad_req, rad_ans, diam_fw, cli); |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
72 CHECK_PARAMS(cs); |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
73 TRACE_DEBUG(INFO, "RADIUS/Diameter Sample plugin received a new RADIUS message."); |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
74 return 0; |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
75 } |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
76 |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
77 /* This function is called when a Diameter answer is coming back. It should remove the AVPs and add the attributes in the RADIUS message. */ |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
78 static int sample_diam_ans( struct rgwp_config * cs, struct session * session, struct msg ** diam_ans, struct radius_msg ** rad_fw, struct rgw_client * cli ) |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
79 { |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
80 TRACE_ENTRY("%p %p %p %p %p", cs, session, diam_ans, rad_fw, cli); |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
81 CHECK_PARAMS(cs); |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
82 TRACE_DEBUG(INFO, "RADIUS/Diameter Sample plugin received a new Diameter answer."); |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
83 return 0; |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
84 } |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
85 |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
86 |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
87 /* Finally, we declare the structure that will be loaded by main RADIUS/Diameter gateway extension */ |
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
88 struct rgw_api rgwp_descriptor = { |
256
042af0000c0a
Ported the auth plugin
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
255
diff
changeset
|
89 .rgwp_name = "sample", |
042af0000c0a
Ported the auth plugin
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
255
diff
changeset
|
90 .rgwp_conf_parse = sample_conf_parse, |
042af0000c0a
Ported the auth plugin
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
255
diff
changeset
|
91 .rgwp_conf_free = sample_conf_free, |
042af0000c0a
Ported the auth plugin
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
255
diff
changeset
|
92 .rgwp_rad_req = sample_rad_req, |
042af0000c0a
Ported the auth plugin
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
255
diff
changeset
|
93 .rgwp_diam_ans = sample_diam_ans |
255
cb4307a1cd29
Added two plugins for RADIUS/Diameter gateway debug.
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
94 }; |