Changeset 256:042af0000c0a in freeDiameter
- Timestamp:
- Apr 16, 2010, 4:57:39 PM (14 years ago)
- Branch:
- default
- Phase:
- public
- Location:
- extensions/app_radgw
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/app_radgw/CMakeLists.txt
r255 r256 67 67 ENDMACRO(RGWX_ADD_PLUGIN) 68 68 69 70 ### Debug 69 71 # Example of plugin: 70 72 OPTION(BUILD_RGWX_SAMPLE "Build sample plugin? (for developers only)" OFF) … … 80 82 81 83 84 ### Authentication, Authorization messages translation. 85 OPTION(BUILD_RGWX_AUTH "Build Authentication & Authorization RADIUS translation plugin? (RFC2865, RFC3579)" ON) 86 IF (BUILD_RGWX_AUTH) 87 RGWX_ADD_PLUGIN(auth ${RG_COMMON_HEADER} rgwx_auth.c) 88 ENDIF (BUILD_RGWX_AUTH) 82 89 83 90 … … 104 111 # ENDIF (BUILD_SUB_ECHO_DROP) 105 112 # 106 # OPTION(BUILD_SUB_AUTH "Build RADIUS Authentication & Authorization sub-extension? (RFC2865, RFC3579)" ON)107 # IF (BUILD_SUB_AUTH)108 # ADD_DEFINITIONS(-DSUB_AUTH_VERBO=2)109 # ADD_LIBRARY(sub_auth MODULE ${RG_COMMON_HEADER} sub_auth.c)110 # TARGET_LINK_LIBRARIES(sub_auth rg_common)111 # ENDIF (BUILD_SUB_AUTH)112 #113 113 # OPTION(BUILD_SUB_ACCT "Build RADIUS Accounting sub-extension? (RFC2866)" ON) 114 114 # IF (BUILD_SUB_ACCT) -
extensions/app_radgw/rgw_common.h
r255 r256 56 56 /* This structure points to a RADIUS client description, the definition is not known to plugins */ 57 57 struct rgw_client; 58 /* This function is required to be able to translate user paswords */ 59 int rgw_clients_getkey(struct rgw_client * cli, unsigned char **key, size_t *key_len); 58 60 59 61 /* Each plugin must provide the following structure. */ 60 62 extern struct rgw_api { 63 /* The name of the plugin */ 64 const char * rgwp_name; 65 61 66 /* Parse the configuration file. It may be called several times with different configurations. 62 Returns NULL on errors. 63 Called even if no configuration file is passed (with NULL parameter then) */ 64 struct rgwp_config * (*rgwp_conf_parse) ( char * conf_file ); 67 Called even if no configuration file is passed (with NULL conf_file parameter then) */ 68 int (*rgwp_conf_parse) ( char * conf_file, struct rgwp_config ** state ); 65 69 66 /* Cleanup the configuration state when the daemon is exiting . */67 void (*rgwp_conf_free) (struct rgwp_config * conf);70 /* Cleanup the configuration state when the daemon is exiting (called even if state is NULL). */ 71 void (*rgwp_conf_free) (struct rgwp_config * state); 68 72 69 73 /* handle an incoming RADIUS message */ -
extensions/app_radgw/rgw_plugins.c
r255 r256 54 54 unsigned char *cc; /* array of command codes, or NULL for all cc */ 55 55 size_t cc_len; /* size of the previous array */ 56 57 char *plgname; /* basename of the plugin, for debug messages. To be freed when object is detroyed */58 char *conffile; /* configuration file passed to the extension, or "(null)". To be freed when object is destroyed */59 56 }; 60 57 … … 177 174 struct plg_descr * new; 178 175 int ret = 0; 179 char * tmp;180 176 181 177 TRACE_ENTRY("%p %p %d %p %zi", plgfile, conffile, type, codes_array, codes_sz); 182 178 183 179 CHECK_PARAMS( plgfile && type && codes_array && (cache_started == 0) ); 184 185 CHECK_MALLOC( tmp = strdup(plgfile) );186 180 187 181 CHECK_MALLOC( new = malloc(sizeof(struct plg_descr)) ); … … 189 183 190 184 fd_list_init(&new->chain, new); 191 192 /* Copy names, for debug */193 CHECK_MALLOC( new->plgname = strdup(basename(tmp)) ); /* basename is a stupid function :( */194 free(tmp);195 CHECK_MALLOC( new->conffile = conffile ?: strdup("(null)") );196 185 197 186 /* Try and load the plugin */ … … 212 201 } 213 202 214 /* Now parse the configuration file, this will initialize all extension states and store it in the returned pointer (the subextensions must be re-entrant) */ 203 TRACE_DEBUG(FULL, "Plugin '%s' found in file '%s'", new->descriptor->rgwp_name, plgfile); 204 205 /* Now parse the configuration file, this will initialize all plugin states and store it in the "cs" pointer (the plugin must be re-entrant, so no global state) */ 215 206 if (new->descriptor->rgwp_conf_parse) { 216 TRACE_DEBUG(FULL, "Parsing plugin conf file: %s", new->conffile ); 217 new->cs = (*(new->descriptor->rgwp_conf_parse))(conffile); 218 if (new->cs == NULL) { 219 fd_log_debug("An error occurred while parsing configuration file '%s' in plugin '%s', aborting...\n", new->conffile, new->plgname); 220 goto error; 221 } 222 TRACE_DEBUG(INFO, "RADIUS/Diameter gateway plugin '%s%s%s%s' initialized.", new->plgname, conffile ? " (" : "", conffile ? new->conffile : "", conffile ? ")" : ""); 207 CHECK_FCT_DO( (*(new->descriptor->rgwp_conf_parse))(conffile, &new->cs), 208 { 209 fd_log_debug("An error occurred while parsing configuration file '%s' in plugin '%s', aborting...\n", conffile, plgfile); 210 goto error; 211 } ); 223 212 } 224 213 … … 283 272 plg = (struct plg_descr *)ptr; 284 273 285 fd_log_debug(" %-25s ( % -25s) - types: %s%s, codes: ",286 plg-> plgname,287 basename(plg->conffile),274 fd_log_debug(" %-25s ( %p ) - types: %s%s, codes: ", 275 plg->descriptor->rgwp_name, 276 plg->cs, 288 277 plg->type & RGW_PLG_TYPE_AUTH ? "Au" : " ", 289 278 plg->type & RGW_PLG_TYPE_ACCT ? "Ac" : " "); … … 317 306 for (ptr = accel->plugins.next; ptr != &accel->plugins; ptr = ptr->next) { 318 307 struct plg_accel_item * item = (struct plg_accel_item *)ptr; 319 fd_log_debug(" %-15s (% s)\n", item->plg->plgname, basename(item->plg->conffile));308 fd_log_debug(" %-15s (%p)\n", item->plg->descriptor->rgwp_name, item->plg->cs); 320 309 } 321 310 } … … 326 315 for (ptr = accel->plugins.next; ptr != &accel->plugins; ptr = ptr->next) { 327 316 struct plg_accel_item * item = (struct plg_accel_item *)ptr; 328 fd_log_debug(" %-15s (% s)\n", item->plg->plgname, basename(item->plg->conffile));317 fd_log_debug(" %-15s (%p)\n", item->plg->descriptor->rgwp_name, item->plg->cs); 329 318 } 330 319 } … … 359 348 360 349 if (plg->descriptor->rgwp_rad_req) { 361 TRACE_DEBUG(ANNOYING, "Calling next plugin: %s", plg-> plgname);350 TRACE_DEBUG(ANNOYING, "Calling next plugin: %s", plg->descriptor->rgwp_name); 362 351 ret = (*plg->descriptor->rgwp_rad_req)(plg->cs, *session, &(*rad)->radius, &rad_ans, diam_msg, cli); 363 352 if (ret) 364 353 break; 365 354 } else { 366 TRACE_DEBUG(ANNOYING, "Skipping extension '%s' (NULL callback)", plg-> plgname);355 TRACE_DEBUG(ANNOYING, "Skipping extension '%s' (NULL callback)", plg->descriptor->rgwp_name); 367 356 } 368 357 } … … 420 409 421 410 if (plg->descriptor->rgwp_diam_ans) { 422 TRACE_DEBUG(ANNOYING, "Calling next plugin: %s", plg-> plgname);411 TRACE_DEBUG(ANNOYING, "Calling next plugin: %s", plg->descriptor->rgwp_name); 423 412 ret = (*plg->descriptor->rgwp_diam_ans)(plg->cs, session, diam_ans, rad_ans, (void *)cli); 424 413 if (ret) 425 414 break; 426 415 } else { 427 TRACE_DEBUG(ANNOYING, "Skipping extension '%s' (NULL callback)", plg-> plgname);416 TRACE_DEBUG(ANNOYING, "Skipping extension '%s' (NULL callback)", plg->descriptor->rgwp_name); 428 417 } 429 418 } … … 493 482 struct plg_descr * plg = (struct plg_descr *) plg_list.next; 494 483 fd_list_unlink(&plg->chain); 495 free(plg->conffile);496 484 free(plg->cc); 497 if (plg-> cs && plg->descriptor && plg->descriptor->rgwp_conf_free ) {498 TRACE_DEBUG(INFO, "RADIUS/Diameter gateway plugin '%s' cleaning up...", plg-> plgname);485 if (plg->descriptor && plg->descriptor->rgwp_conf_free ) { 486 TRACE_DEBUG(INFO, "RADIUS/Diameter gateway plugin '%s' cleaning up...", plg->descriptor->rgwp_name); 499 487 (*plg->descriptor->rgwp_conf_free)(plg->cs); 500 488 } 501 free(plg->plgname);502 dlclose(plg->dlo);489 if (plg->dlo) 490 dlclose(plg->dlo); 503 491 free(plg); 504 492 } -
extensions/app_radgw/rgwx_debug.c
r255 r256 38 38 #include "rgw_common.h" 39 39 40 struct rgwp_config { 41 char * confstring; 42 }; 43 44 /* The function called at plugin initialization */ 45 static struct rgwp_config * debug_conf_parse ( char * conf_file ) 40 /* Store the configuration string in the state */ 41 static int debug_conf_parse ( char * conf_file, struct rgwp_config ** state ) 46 42 { 47 struct rgwp_config * ret = NULL; 43 TRACE_ENTRY("%p %p", conf_file, state); 44 CHECK_PARAMS(state); 48 45 49 TRACE_ENTRY("%p", conf_file);46 *state = (void *)conf_file; 50 47 51 CHECK_MALLOC_DO( ret = malloc(sizeof(struct rgwp_config)), return NULL ); 52 53 ret->confstring = conf_file; 54 55 return ret; 48 return 0; 56 49 } 57 50 58 /* This function is called when the plugin is unloaded, to cleanup all the states */59 static void debug_conf_free(struct rgwp_config * cs)60 {61 TRACE_ENTRY("%p", cs);62 CHECK_PARAMS_DO( cs, );63 free(cs);64 return;65 }66 51 67 52 /* Function to display the content of a RADIUS message (more friendly way than radius_msg_dump) */ … … 91 76 TRACE_ENTRY("%p %p %p %p %p %p", cs, session, rad_req, rad_ans, diam_fw, cli); 92 77 93 fd_log_debug("------------- RADIUS/Diameter Request Debug%s%s%s -------------\n", cs ->confstring ? " [" : "", cs->confstring ?: "", cs->confstring? "]" : "");78 fd_log_debug("------------- RADIUS/Diameter Request Debug%s%s%s -------------\n", cs ? " [" : "", cs ? (char *)cs : "", cs ? "]" : ""); 94 79 95 80 if (!rad_req) { … … 114 99 } 115 100 116 fd_log_debug("=========== Debug%s%s%s complete =============\n", cs ->confstring ? " [" : "", cs->confstring ?: "", cs->confstring? "]" : "");101 fd_log_debug("=========== Debug%s%s%s complete =============\n", cs ? " [" : "", cs ? (char *)cs : "", cs ? "]" : ""); 117 102 118 103 return 0; … … 124 109 TRACE_ENTRY("%p %p %p %p %p", cs, session, diam_ans, rad_fw, cli); 125 110 126 fd_log_debug("------------- RADIUS/Diameter Answer Debug%s%s%s -------------\n", cs ->confstring ? " [" : "", cs->confstring ?: "", cs->confstring? "]" : "");111 fd_log_debug("------------- RADIUS/Diameter Answer Debug%s%s%s -------------\n", cs ? " [" : "", cs ? (char *)cs : "", cs ? "]" : ""); 127 112 128 113 if (!diam_ans || ! *diam_ans) { … … 140 125 } 141 126 142 fd_log_debug("=========== Debug%s%s%s complete =============\n", cs ->confstring ? " [" : "", cs->confstring ?: "", cs->confstring? "]" : "");127 fd_log_debug("=========== Debug%s%s%s complete =============\n", cs ? " [" : "", cs ? (char *)cs : "", cs ? "]" : ""); 143 128 return 0; 144 129 } … … 147 132 /* The exported symbol */ 148 133 struct rgw_api rgwp_descriptor = { 149 debug_conf_parse, 150 debug_conf_free, 151 debug_rad_req, 152 debug_diam_ans 134 .rgwp_name = "debug", 135 .rgwp_conf_parse = debug_conf_parse, 136 .rgwp_conf_free = NULL, 137 .rgwp_rad_req = debug_rad_req, 138 .rgwp_diam_ans = debug_diam_ans 153 139 }; -
extensions/app_radgw/rgwx_sample.c
r255 r256 41 41 struct rgwp_config { 42 42 /* In a real extension, we would store the parsed configuration file, and the states of the extension */ 43 int state;43 int init; 44 44 }; 45 45 46 46 /* The function called at plugin initialization */ 47 static struct rgwp_config * sample_conf_parse ( char * conf_file )47 static int sample_conf_parse ( char * conf_file, struct rgwp_config ** state ) 48 48 { 49 struct rgwp_config * ret = NULL; 49 TRACE_ENTRY("%p %p", conf_file, state); 50 CHECK_PARAMS(state); 50 51 51 TRACE_ENTRY("%p", conf_file);52 CHECK_MALLOC( *state = malloc(sizeof(struct rgwp_config)) ); 52 53 53 CHECK_MALLOC_DO( ret = malloc(sizeof(struct rgwp_config)), return NULL );54 (*state)->init = 1; 54 55 55 ret->state = 1; 56 57 return ret; 56 return 0; 58 57 } 59 58 60 59 /* This function is called when the plugin is unloaded, to cleanup all the states */ 61 static void sample_conf_free(struct rgwp_config * cs)60 static void sample_conf_free(struct rgwp_config * state) 62 61 { 63 TRACE_ENTRY("%p", cs);64 CHECK_PARAMS_DO( cs, );65 free( cs);62 TRACE_ENTRY("%p", state); 63 CHECK_PARAMS_DO( state, ); 64 free(state); 66 65 return; 67 66 } … … 88 87 /* Finally, we declare the structure that will be loaded by main RADIUS/Diameter gateway extension */ 89 88 struct rgw_api rgwp_descriptor = { 90 sample_conf_parse, 91 sample_conf_free, 92 sample_rad_req, 93 sample_diam_ans 89 .rgwp_name = "sample", 90 .rgwp_conf_parse = sample_conf_parse, 91 .rgwp_conf_free = sample_conf_free, 92 .rgwp_rad_req = sample_rad_req, 93 .rgwp_diam_ans = sample_diam_ans 94 94 };
Note: See TracChangeset
for help on using the changeset viewer.