Navigation


Changeset 256:042af0000c0a in freeDiameter


Ignore:
Timestamp:
Apr 16, 2010, 4:57:39 PM (14 years ago)
Author:
Sebastien Decugis <sdecugis@nict.go.jp>
Branch:
default
Phase:
public
Message:

Ported the auth plugin

Location:
extensions/app_radgw
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • extensions/app_radgw/CMakeLists.txt

    r255 r256  
    6767ENDMACRO(RGWX_ADD_PLUGIN)
    6868
     69
     70### Debug
    6971# Example of plugin:
    7072OPTION(BUILD_RGWX_SAMPLE "Build sample plugin? (for developers only)" OFF)
     
    8082
    8183
     84### Authentication, Authorization messages translation.
     85OPTION(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)
    8289
    8390
     
    104111#       ENDIF (BUILD_SUB_ECHO_DROP)
    105112#
    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 #
    113113# OPTION(BUILD_SUB_ACCT "Build RADIUS Accounting sub-extension? (RFC2866)" ON)
    114114#       IF (BUILD_SUB_ACCT)
  • extensions/app_radgw/rgw_common.h

    r255 r256  
    5656/* This structure points to a RADIUS client description, the definition is not known to plugins */
    5757struct rgw_client;
     58/* This function is required to be able to translate user paswords */
     59int rgw_clients_getkey(struct rgw_client * cli, unsigned char **key, size_t *key_len);
    5860
    5961/* Each plugin must provide the following structure. */
    6062extern struct rgw_api {
     63        /* The name of the plugin */
     64        const char * rgwp_name;
     65
    6166        /* 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 );
    6569       
    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);
    6872
    6973        /* handle an incoming RADIUS message */
  • extensions/app_radgw/rgw_plugins.c

    r255 r256  
    5454        unsigned char           *cc;            /* array of command codes, or NULL for all cc */
    5555        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 */
    5956};
    6057
     
    177174        struct plg_descr * new;
    178175        int ret = 0;
    179         char * tmp;
    180176       
    181177        TRACE_ENTRY("%p %p %d %p %zi", plgfile, conffile, type, codes_array, codes_sz);
    182178       
    183179        CHECK_PARAMS( plgfile && type && codes_array && (cache_started == 0) );
    184        
    185         CHECK_MALLOC( tmp = strdup(plgfile) );
    186180       
    187181        CHECK_MALLOC( new = malloc(sizeof(struct plg_descr)) );
     
    189183       
    190184        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)") );
    196185       
    197186        /* Try and load the plugin */
     
    212201        }
    213202       
    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) */
    215206        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                        } );
    223212        }
    224213       
     
    283272                plg = (struct plg_descr *)ptr;
    284273               
    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,
    288277                                plg->type & RGW_PLG_TYPE_AUTH ? "Au" : "  ",
    289278                                plg->type & RGW_PLG_TYPE_ACCT ? "Ac" : "  ");
     
    317306                for (ptr = accel->plugins.next; ptr != &accel->plugins; ptr = ptr->next) {
    318307                        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);
    320309                }
    321310        }
     
    326315                for (ptr = accel->plugins.next; ptr != &accel->plugins; ptr = ptr->next) {
    327316                        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);
    329318                }
    330319        }
     
    359348               
    360349                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);
    362351                        ret = (*plg->descriptor->rgwp_rad_req)(plg->cs, *session, &(*rad)->radius, &rad_ans, diam_msg, cli);
    363352                        if (ret)
    364353                                break;
    365354                } 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);
    367356                }                                       
    368357        }
     
    420409               
    421410                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);
    423412                        ret = (*plg->descriptor->rgwp_diam_ans)(plg->cs, session, diam_ans, rad_ans, (void *)cli);
    424413                        if (ret)
    425414                                break;
    426415                } 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);
    428417                }                                       
    429418        }
     
    493482                struct plg_descr * plg = (struct plg_descr *) plg_list.next;
    494483                fd_list_unlink(&plg->chain);
    495                 free(plg->conffile);
    496484                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);
    499487                        (*plg->descriptor->rgwp_conf_free)(plg->cs);
    500488                }
    501                 free(plg->plgname);
    502                 dlclose(plg->dlo);
     489                if (plg->dlo)
     490                        dlclose(plg->dlo);
    503491                free(plg);
    504492        }
  • extensions/app_radgw/rgwx_debug.c

    r255 r256  
    3838#include "rgw_common.h"
    3939
    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 */
     41static int debug_conf_parse ( char * conf_file, struct rgwp_config ** state )
    4642{
    47         struct rgwp_config * ret = NULL;
     43        TRACE_ENTRY("%p %p", conf_file, state);
     44        CHECK_PARAMS(state);
    4845       
    49         TRACE_ENTRY("%p", conf_file);
     46        *state = (void *)conf_file;
    5047       
    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;
    5649}
    5750
    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 }
    6651
    6752/* Function to display the content of a RADIUS message (more friendly way than radius_msg_dump) */
     
    9176        TRACE_ENTRY("%p %p %p %p %p %p", cs, session, rad_req, rad_ans, diam_fw, cli);
    9277       
    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 ? "]" : "");
    9479       
    9580        if (!rad_req) {
     
    11499        }
    115100       
    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 ? "]" : "");
    117102       
    118103        return 0;
     
    124109        TRACE_ENTRY("%p %p %p %p %p", cs, session, diam_ans, rad_fw, cli);
    125110
    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 ? "]" : "");
    127112       
    128113        if (!diam_ans || ! *diam_ans) {
     
    140125        }
    141126       
    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 ? "]" : "");
    143128        return 0;
    144129}
     
    147132/* The exported symbol */
    148133struct 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
    153139};     
  • extensions/app_radgw/rgwx_sample.c

    r255 r256  
    4141struct rgwp_config {
    4242        /* In a real extension, we would store the parsed configuration file, and the states of the extension */
    43         int state;
     43        int init;
    4444};
    4545
    4646/* The function called at plugin initialization */
    47 static struct rgwp_config * sample_conf_parse ( char * conf_file )
     47static int sample_conf_parse ( char * conf_file, struct rgwp_config ** state )
    4848{
    49         struct rgwp_config * ret = NULL;
     49        TRACE_ENTRY("%p %p", conf_file, state);
     50        CHECK_PARAMS(state);
    5051       
    51         TRACE_ENTRY("%p", conf_file);
     52        CHECK_MALLOC( *state = malloc(sizeof(struct rgwp_config)) );
    5253       
    53         CHECK_MALLOC_DO( ret = malloc(sizeof(struct rgwp_config)), return NULL );
     54        (*state)->init = 1;
    5455       
    55         ret->state = 1;
    56        
    57         return ret;
     56        return 0;
    5857}
    5958
    6059/* This function is called when the plugin is unloaded, to cleanup all the states */
    61 static void sample_conf_free(struct rgwp_config * cs)
     60static void sample_conf_free(struct rgwp_config * state)
    6261{
    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);
    6665        return;
    6766}
     
    8887/* Finally, we declare the structure that will be loaded by main RADIUS/Diameter gateway extension */
    8988struct 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
    9494};     
Note: See TracChangeset for help on using the changeset viewer.