00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include "../../sr_module.h"
00035 #include "../../mem/mem.h"
00036 #include "../../parser/digest/digest_parser.h"
00037 #include "../../parser/digest/digest.h"
00038 #include "../../parser/parse_uri.h"
00039 #include "../../parser/parse_from.h"
00040 #include "../../usr_avp.h"
00041 #include "../../ut.h"
00042 #include "../../config.h"
00043 #include "../../radius.h"
00044 #include "../../mod_fix.h"
00045 #include "misc_radius.h"
00046 #include "functions.h"
00047 #include "extra.h"
00048
00049 MODULE_VERSION
00050
00051 static int mod_init(void);
00052 static void destroy(void);
00053
00054
00055 static char *radius_config = DEFAULT_RADIUSCLIENT_CONF;
00056 static int caller_service_type = -1;
00057 static int callee_service_type = -1;
00058 static int group_service_type = -1;
00059 static int uri_service_type = -1;
00060 int use_sip_uri_host = 0;
00061
00062 void *rh;
00063 static char *caller_extra_str = 0;
00064 struct extra_attr *caller_extra = 0;
00065 static char *callee_extra_str = 0;
00066 struct extra_attr *callee_extra = 0;
00067 static char *group_extra_str = 0;
00068 struct extra_attr *group_extra = 0;
00069 static char *uri_extra_str = 0;
00070 struct extra_attr *uri_extra = 0;
00071
00072 struct attr caller_attrs[SA_STATIC_MAX+MAX_EXTRA];
00073 struct attr callee_attrs[SA_STATIC_MAX+MAX_EXTRA];
00074 struct attr group_attrs[SA_STATIC_MAX+MAX_EXTRA];
00075 struct attr uri_attrs[SA_STATIC_MAX+MAX_EXTRA];
00076 struct val caller_vals[RV_STATIC_MAX];
00077 struct val callee_vals[EV_STATIC_MAX];
00078 struct val group_vals[GV_STATIC_MAX];
00079 struct val uri_vals[UV_STATIC_MAX];
00080
00081
00082
00083
00084
00085 static cmd_export_t cmds[] = {
00086 {"radius_load_caller_avps", (cmd_function)radius_load_caller_avps, 1,
00087 fixup_spve_null, 0, REQUEST_ROUTE | FAILURE_ROUTE},
00088 {"radius_load_callee_avps", (cmd_function)radius_load_callee_avps, 1,
00089 fixup_spve_null, 0, REQUEST_ROUTE | FAILURE_ROUTE},
00090 {"radius_is_user_in", (cmd_function)radius_is_user_in, 2,
00091 fixup_spve_str, 0,
00092 REQUEST_ROUTE|FAILURE_ROUTE|BRANCH_ROUTE|LOCAL_ROUTE},
00093 {"radius_does_uri_exist", (cmd_function)radius_does_uri_exist_0,
00094 0, 0, 0, REQUEST_ROUTE|LOCAL_ROUTE},
00095 {"radius_does_uri_exist", (cmd_function)radius_does_uri_exist_1,
00096 1, fixup_pvar_null, fixup_free_pvar_null, REQUEST_ROUTE|LOCAL_ROUTE},
00097 {"radius_does_uri_user_exist",
00098 (cmd_function)radius_does_uri_user_exist_0,
00099 0, 0, 0, REQUEST_ROUTE|LOCAL_ROUTE},
00100 {"radius_does_uri_user_exist",
00101 (cmd_function)radius_does_uri_user_exist_1,
00102 1, fixup_pvar_null, fixup_free_pvar_null, REQUEST_ROUTE|LOCAL_ROUTE},
00103 {0, 0, 0, 0, 0, 0}
00104 };
00105
00106
00107
00108
00109
00110 static param_export_t params[] = {
00111 {"radius_config", STR_PARAM, &radius_config },
00112 {"caller_service_type", INT_PARAM, &caller_service_type},
00113 {"callee_service_type", INT_PARAM, &callee_service_type},
00114 {"group_service_type", INT_PARAM, &group_service_type },
00115 {"uri_service_type", INT_PARAM, &uri_service_type },
00116 {"caller_extra", STR_PARAM, &caller_extra_str },
00117 {"callee_extra", STR_PARAM, &callee_extra_str },
00118 {"group_extra", STR_PARAM, &group_extra_str },
00119 {"uri_extra", STR_PARAM, &uri_extra_str },
00120 {"use_sip_uri_host", INT_PARAM, &use_sip_uri_host},
00121 {0, 0, 0}
00122 };
00123
00124
00125 struct module_exports exports = {
00126 "misc_radius",
00127 DEFAULT_DLFLAGS,
00128 cmds,
00129 params,
00130 0,
00131 0,
00132 0,
00133 0,
00134 mod_init,
00135 0,
00136 destroy,
00137 0
00138 };
00139
00140
00141
00142 #define SET_STATIC(_attrs) \
00143 do { \
00144 memset((_attrs), 0, sizeof((_attrs))); \
00145 (_attrs)[SA_SERVICE_TYPE].n = "Service-Type"; \
00146 (_attrs)[SA_USER_NAME].n = "User-Name"; \
00147 (_attrs)[SA_SIP_AVP].n = "SIP-AVP"; \
00148 (_attrs)[SA_SIP_GROUP].n = "SIP-Group"; \
00149 if (use_sip_uri_host) { \
00150 (_attrs)[SA_SIP_URI_HOST].n = "SIP-URI-Host"; \
00151 } else { \
00152 (_attrs)[SA_SIP_URI_HOST].n = "User-Name"; \
00153 } \
00154 n = SA_STATIC_MAX; \
00155 }while(0)
00156
00157
00158 static int mod_init(void)
00159 {
00160 int n;
00161
00162 LM_INFO("initializing...\n");
00163
00164
00165 if ((rh = rc_read_config(radius_config)) == NULL) {
00166 LM_ERR("failed to open radius config file: %s\n", radius_config);
00167 return -1;
00168 }
00169
00170
00171 if (rc_read_dictionary(rh, rc_conf_str(rh, "dictionary")) != 0) {
00172 LM_ERR("failed to read radius dictionary\n");
00173 return -1;
00174 }
00175
00176
00177 init_extra_engine();
00178
00179
00180 if (caller_extra_str &&
00181 (caller_extra=parse_extra_str(caller_extra_str)) == 0 ) {
00182 LM_ERR("failed to parse caller_extra parameter\n");
00183 return -1;
00184 }
00185 if (callee_extra_str &&
00186 (callee_extra=parse_extra_str(callee_extra_str)) == 0 ) {
00187 LM_ERR("failed to parse callee_extra parameter\n");
00188 return -1;
00189 }
00190 if (group_extra_str &&
00191 (group_extra=parse_extra_str(group_extra_str)) == 0 ) {
00192 LM_ERR("failed to parse group_extra parameter\n");
00193 return -1;
00194 }
00195 if (uri_extra_str &&
00196 (uri_extra=parse_extra_str(uri_extra_str)) == 0 ) {
00197 LM_ERR("failed to parse uri_extra parameter\n");
00198 return -1;
00199 }
00200
00201 SET_STATIC(caller_attrs);
00202 n += extra2attrs(caller_extra, caller_attrs, n);
00203 memset(caller_vals, 0, sizeof(caller_vals));
00204 caller_vals[RV_SIP_CALLER_AVPS].n = "SIP-Caller-AVPs";
00205 INIT_AV(rh, caller_attrs, n, caller_vals, RV_STATIC_MAX, "misc_radius",
00206 -1, -1);
00207 if (caller_service_type != -1) {
00208 caller_vals[RV_SIP_CALLER_AVPS].v = caller_service_type;
00209 }
00210
00211 SET_STATIC(callee_attrs);
00212 n += extra2attrs(callee_extra, callee_attrs, n);
00213 memset(callee_vals, 0, sizeof(callee_vals));
00214 callee_vals[EV_SIP_CALLEE_AVPS].n = "SIP-Callee-AVPs";
00215 INIT_AV(rh, callee_attrs, n, callee_vals, EV_STATIC_MAX, "misc_radius",
00216 -1, -1);
00217 if (callee_service_type != -1) {
00218 callee_vals[EV_SIP_CALLEE_AVPS].v = callee_service_type;
00219 }
00220
00221 SET_STATIC(group_attrs);
00222 n += extra2attrs(group_extra, group_attrs, n);
00223 memset(group_vals, 0, sizeof(group_vals));
00224 group_vals[GV_GROUP_CHECK].n = "Group-Check";
00225 INIT_AV(rh, group_attrs, n, group_vals, RV_STATIC_MAX, "misc_radius",
00226 -1, -1);
00227 if (group_service_type != -1) {
00228 group_vals[GV_GROUP_CHECK].v = group_service_type;
00229 }
00230 SET_STATIC(uri_attrs);
00231 n += extra2attrs(uri_extra, uri_attrs, n);
00232 memset(uri_vals, 0, sizeof(uri_vals));
00233 uri_vals[UV_CALL_CHECK].n = "Call-Check";
00234 INIT_AV(rh, uri_attrs, n, uri_vals, UV_STATIC_MAX, "misc_radius",
00235 -1, -1);
00236 if (uri_service_type != -1) {
00237 uri_vals[UV_CALL_CHECK].v = uri_service_type;
00238 }
00239
00240 return 0;
00241 }
00242
00243
00244 static void destroy(void)
00245 {
00246 if (caller_extra) destroy_extras(caller_extra);
00247 if (callee_extra) destroy_extras(callee_extra);
00248 if (group_extra) destroy_extras(group_extra);
00249 if (uri_extra) destroy_extras(group_extra);
00250 }