]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Add type values for cf_data_*
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 22 Nov 2016 22:08:58 +0000 (17:08 -0500)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 22 Nov 2016 22:08:58 +0000 (17:08 -0500)
src/include/conffile.h
src/main/client.c
src/main/conffile.c
src/main/interpreter.c
src/main/listen.c
src/main/modcall.c
src/main/modules.c
src/main/realms.c
src/main/tls/conf.c

index 4c5793e5ce8316ff9d57a9f25606395eb6678926..11c0c3e0a8e39a80b4a20f22dcac02c5dd4e43ea 100644 (file)
@@ -280,6 +280,17 @@ _Generic((_ct), \
 #define PW_BASE_TYPE(_t)               (0xff & (_t))
 /* @} **/
 
+typedef enum {
+       CF_DATA_TYPE_DEFAULT = 0,
+       CF_DATA_TYPE_CLIENT,
+       CF_DATA_TYPE_HOME_SERVER_POOL,
+       CF_DATA_TYPE_UNLANG,
+       CF_DATA_TYPE_PROTOCOL,
+       CF_DATA_TYPE_MODULE_INSTANCE,
+       CF_DATA_TYPE_CONNECTION_POOL,
+       CF_DATA_TYPE_TLS
+} cf_data_type_t;
+
 #define FR_SIZE_COND_CHECK(_name, _var, _cond, _new)\
 do {\
        if (!(_cond)) {\
index 2feda85980e312ad34cc530dfb1ed7728b3a6bc7..4839b826019da0f104af484ebb319fadde548931 100644 (file)
@@ -264,7 +264,7 @@ bool client_add(RADCLIENT_LIST *clients, RADCLIENT *client)
                         *      If the client list already exists, use that.
                         *      Otherwise, create a new client list.
                         */
-                       clients = cf_data_find(cs, 0, "clients");
+                       clients = cf_data_find(cs, CF_DATA_TYPE_CLIENT, "clients");
                        if (!clients) {
                                clients = client_list_init(cs);
                                if (!clients) {
@@ -272,7 +272,8 @@ bool client_add(RADCLIENT_LIST *clients, RADCLIENT *client)
                                        return false;
                                }
 
-                               if (cf_data_add(cs, 0, "clients", clients, (void (*)(void *)) client_list_free) < 0) {
+                               if (cf_data_add(cs, CF_DATA_TYPE_CLIENT,
+                                               "clients", clients, (void (*)(void *)) client_list_free) < 0) {
                                        ERROR("Failed to associate clients with virtual server %s", client->server);
                                        client_list_free(clients);
                                        return false;
@@ -692,7 +693,7 @@ RADCLIENT_LIST *client_list_parse_section(CONF_SECTION *section, UNUSED bool tls
        /*
         *      Associate the clients structure with the section.
         */
-       if (cf_data_add(section, 0, "clients", clients, NULL) < 0) {
+       if (cf_data_add(section, CF_DATA_TYPE_CLIENT, "clients", clients, NULL) < 0) {
                cf_log_err_cs(section, "Failed to associate clients with section %s", cf_section_name1(section));
                client_list_free(clients);
                return NULL;
index bc8d76840c073e3d331438fa6d00e4c6d0be17a1..a2a74c3137e259f8854535f4341476a9f2982a3b 100644 (file)
@@ -337,7 +337,7 @@ static FILE *cf_file_open(CONF_SECTION *cs, char const *filename)
        FILE *fp;
 
        top = cf_top_section(cs);
-       tree = cf_data_find(top, 0, "filename");
+       tree = cf_data_find(top, CF_DATA_TYPE_DEFAULT, "filename");
        if (!tree) return NULL;
 
        fp = fopen(filename, "r");
@@ -420,7 +420,7 @@ static bool cf_file_check(CONF_SECTION *cs, char const *filename, bool check_per
        int             fd;
 
        top = cf_top_section(cs);
-       tree = cf_data_find(top, 0, "filename");
+       tree = cf_data_find(top, CF_DATA_TYPE_DEFAULT, "filename");
        if (!tree) return false;
 
        file = talloc(tree, cf_file_t);
@@ -554,7 +554,7 @@ int cf_file_changed(CONF_SECTION *cs, rb_walker_t callback)
        rbtree_t *tree;
 
        top = cf_top_section(cs);
-       tree = cf_data_find(top, 0, "filename");
+       tree = cf_data_find(top, CF_DATA_TYPE_DEFAULT, "filename");
        if (!tree) return true;
 
        cb.rcode = CF_FILE_NONE;
@@ -3101,7 +3101,7 @@ static int cf_section_read(char const *filename, int *lineno, FILE *fp,
                        talloc_free(p);
                        css->name2 = talloc_typed_strdup(css, buff[2]);
 
-                       cf_data_add(css, 0, "if", cond, NULL);
+                       cf_data_add(css, CF_DATA_TYPE_UNLANG, "if", cond, NULL);
 
                add_section:
                        cf_item_add(this, &(css->item));
@@ -3549,7 +3549,7 @@ int cf_file_read(CONF_SECTION *cs, char const *filename)
        tree = rbtree_create(cs, filename_cmp, NULL, 0);
        if (!tree) return -1;
 
-       cf_data_add(cs, 0, "filename", tree, NULL);
+       cf_data_add(cs, CF_DATA_TYPE_DEFAULT, "filename", tree, NULL);
 
        /*
         *      Allocate temporary buffers on the heap (so we don't use *all* the stack space)
@@ -4363,7 +4363,7 @@ size_t cf_section_write(FILE *in_fp, CONF_SECTION *cs, int depth)
                 *      FIXME: check for "if" or "elsif".  And if so, print
                 *      out the parsed condition, instead of the input text
                 *
-                *      cf_data_find(cs, 0, "if");
+                *      cf_data_find(cs, CF_DATA_TYPE_UNLANG, "if");
                 */
 
                if (cs->name2) {
@@ -4371,7 +4371,7 @@ size_t cf_section_write(FILE *in_fp, CONF_SECTION *cs, int depth)
 
                        fputs(" ", fp);
 
-                       c = cf_data_find(cs, 0, "if");
+                       c = cf_data_find(cs, CF_DATA_TYPE_UNLANG, "if");
                        if (c) {
                                char buffer[1024];
 
index 1d8c3d8534fcdc690f10ce3a60a2d3ba9c0844ec..d6da368713ad808d73315c5f5af4ab18973e3aa7 100644 (file)
@@ -1199,7 +1199,7 @@ void unlang_push_section(REQUEST *request, CONF_SECTION *cs, rlm_rcode_t action)
         *      associated with sections.
         */
        if (cs) {
-               instruction = cf_data_find(cs, 0, "unlang");
+               instruction = cf_data_find(cs, CF_DATA_TYPE_UNLANG, "unlang");
                if (!instruction) {
                        REDEBUG("Failed to find pre-compiled unlang for section %s %s { ... }",
                                cf_section_name1(cs), cf_section_name2(cs));
index e1b8bb32ec1019888a49cdefd52c5fa973cc6bd9..10766ec80bb86f98a90a818916b7de63c5fc4cf1 100644 (file)
@@ -106,7 +106,7 @@ int listen_compile(CONF_SECTION *server, CONF_SECTION *cs)
 {
        rad_protocol_t const *proto;
 
-       proto = cf_data_find(cs, 0, "proto");
+       proto = cf_data_find(cs, CF_DATA_TYPE_PROTOCOL, "proto");
        if (!proto || !proto->compile) return 0;
 
        if (proto->compile(server, cs) < 0) {
@@ -223,13 +223,13 @@ int listen_bootstrap(CONF_SECTION *server, CONF_SECTION *cs, char const *server_
                        return -1;
                }
 
-               if (cf_data_find(cs, 0, "proto") != NULL) {
+               if (cf_data_find(cs, CF_DATA_TYPE_PROTOCOL, "proto") != NULL) {
                        cf_log_err_cs(cs, "Virtual server cannot have two protocols");
                        talloc_const_free(module);
                        return -1;
                }
 
-               cf_data_add(cs, 0, "proto", proto, NULL);
+               cf_data_add(cs, CF_DATA_TYPE_PROTOCOL, "proto", proto, NULL);
        }
 
        /*
index ee63bc7d5945b140a105faa622379ddcf45eedb2..65626469bf016d08405ac92a65932c78e0721587 100644 (file)
@@ -1546,7 +1546,7 @@ static unlang_t *compile_update(unlang_t *parent, unlang_compile_t *unlang_ctx,
        g->map = talloc_steal(g, head);
 
 #ifdef WITH_CONF_WRITE
-//     cf_data_add(cs, 0, "update", g->map, NULL); /* for output normalization */
+//     cf_data_add(cs, CF_DATA_TYPE_UNLANG, "update", g->map, NULL); /* for output normalization */
 #endif
 
        if (!pass2_fixup_update(g)) {
@@ -1768,7 +1768,7 @@ static unlang_t *compile_children(unlang_group_t *g, UNUSED unlang_t *parent, un
                        /*
                         *      Skip precompiled blocks.
                         */
-                       if (cf_data_find(subcs, 0, "unlang")) continue;
+                       if (cf_data_find(subcs, CF_DATA_TYPE_UNLANG, "unlang")) continue;
 
                        /*
                         *      "actions" apply to the current group.
@@ -2242,7 +2242,7 @@ static unlang_t *compile_if(unlang_t *parent, unlang_compile_t *unlang_ctx, CONF
                return NULL;
        }
 
-       cond = cf_data_find(cs, 0, "if");
+       cond = cf_data_find(cs, CF_DATA_TYPE_UNLANG, "if");
        rad_assert(cond != NULL);
 
        if (cond->type == COND_TYPE_FALSE) {
@@ -3036,7 +3036,7 @@ int unlang_compile(CONF_SECTION *cs, rlm_components_t component)
        /*
         *      Associate the unlang with the configuration section.
         */
-       cf_data_add(cs, 0, "unlang", c, NULL);
+       cf_data_add(cs, CF_DATA_TYPE_UNLANG, "unlang", c, NULL);
 
        dump_tree(c, c->debug_name);
        return 0;
index fd2e52747c736a350a3b965f45514dca858f285b..fb839672d681dd468d47716ef174ed2cd0ce20be 100644 (file)
@@ -172,12 +172,12 @@ int module_sibling_section_find(CONF_SECTION **out, CONF_SECTION *module, char c
        cp = cf_pair_find(module, name);
        if (!cp) return 0;
 
-       if (cf_data_find(module, 0, FIND_SIBLING_CF_KEY)) {
+       if (cf_data_find(module, CF_DATA_TYPE_CONNECTION_POOL, FIND_SIBLING_CF_KEY)) {
                cf_log_err_cp(cp, "Module reference loop found");
 
                return -1;
        }
-       cf_data_add(module, 0, FIND_SIBLING_CF_KEY, &loop, NULL);
+       cf_data_add(module, CF_DATA_TYPE_CONNECTION_POOL, FIND_SIBLING_CF_KEY, &loop, NULL);
 
        /*
         *      Item found, resolve it to a module instance.
@@ -191,7 +191,7 @@ int module_sibling_section_find(CONF_SECTION **out, CONF_SECTION *module, char c
         *      Remove the config data we added for loop
         *      detection.
         */
-       cf_data_remove(module, 0, FIND_SIBLING_CF_KEY);
+       cf_data_remove(module, CF_DATA_TYPE_CONNECTION_POOL, FIND_SIBLING_CF_KEY);
        if (!inst) {
                cf_log_err_cp(cp, "Unknown module instance \"%s\"", inst_name);
 
@@ -308,7 +308,7 @@ fr_connection_pool_t *module_connection_pool_init(CONF_SECTION *module,
         *      This allows modules to pass in the config sections
         *      they would like to use the connection pool from.
         */
-       pool = cf_data_find(cs, 0, CONNECTION_POOL_CF_KEY);
+       pool = cf_data_find(cs, CF_DATA_TYPE_CONNECTION_POOL, CONNECTION_POOL_CF_KEY);
        if (!pool) {
                DEBUG4("%s: No pool reference found for config item \"%s.pool\"", log_prefix, parent_name(cs));
                pool = fr_connection_pool_init(cs, cs, opaque, c, a, log_prefix);
@@ -317,7 +317,7 @@ fr_connection_pool_t *module_connection_pool_init(CONF_SECTION *module,
                fr_connection_pool_enable_triggers(pool, trigger_prefix, trigger_args);
 
                DEBUG4("%s: Adding pool reference %p to config item \"%s.pool\"", log_prefix, pool, parent_name(cs));
-               cf_data_add(cs, 0, CONNECTION_POOL_CF_KEY, pool, NULL);
+               cf_data_add(cs, CF_DATA_TYPE_CONNECTION_POOL, CONNECTION_POOL_CF_KEY, pool, NULL);
                return pool;
        }
        fr_connection_pool_ref(pool);
@@ -332,7 +332,7 @@ fr_connection_pool_t *module_connection_pool_init(CONF_SECTION *module,
        if (mycs != cs) {
                DEBUG4("%s: Copying pool reference %p from config item \"%s.pool\" to config item \"%s.pool\"",
                       log_prefix, pool, parent_name(cs), parent_name(mycs));
-               cf_data_add(mycs, 0, CONNECTION_POOL_CF_KEY, pool, NULL);
+               cf_data_add(mycs, CF_DATA_TYPE_CONNECTION_POOL, CONNECTION_POOL_CF_KEY, pool, NULL);
        }
 
        return pool;
@@ -383,7 +383,7 @@ module_instance_t *module_find(CONF_SECTION *modules, char const *asked_name)
        instance_name = asked_name;
        if (instance_name[0] == '-') instance_name++;
 
-       return (module_instance_t *)cf_data_find(modules, 0, instance_name);
+       return (module_instance_t *)cf_data_find(modules, CF_DATA_TYPE_CONNECTION_POOL, instance_name);
 }
 
 /** Find an existing module instance and verify it implements the specified method
@@ -886,7 +886,7 @@ static module_instance_t *module_bootstrap(CONF_SECTION *modules, CONF_SECTION *
        /*
         *      Remember the module for later.
         */
-       cf_data_add(modules, 0, instance->name, instance, NULL);
+       cf_data_add(modules, CF_DATA_TYPE_CONNECTION_POOL, instance->name, instance, NULL);
 
        return instance;
 }
index 5f4834b81bda7e201c17d34d85cb7f82ebb840be..4e35e80d6727ce4873fcc6d6aee8697821fd6b8a 100644 (file)
@@ -596,7 +596,7 @@ bool realm_home_server_add(home_server_t *home)
        /*
         *      Mark it as already processed
         */
-       cf_data_add(home->cs, 0, "home_server", (void *)null_free, null_free);
+       cf_data_add(home->cs, CF_DATA_TYPE_HOME_SERVER_POOL, "home_server", (void *)null_free, null_free);
 
        return true;
 }
@@ -1356,7 +1356,7 @@ static int server_pool_add(realm_config_t *rc,
 
        if (do_print) cf_log_info(cs, " }");
 
-       cf_data_add(cs, 0, "home_server_pool", pool, NULL);
+       cf_data_add(cs, CF_DATA_TYPE_HOME_SERVER_POOL, "home_server_pool", pool, NULL);
        (void) talloc_steal(cs, pool);
 
        rad_assert(pool->server_type != 0);
@@ -2232,7 +2232,7 @@ int realms_init(CONF_SECTION *config)
                /*
                 *      Pool was already loaded.
                 */
-               if (cf_data_find(cs, 0, "home_server_pool")) continue;
+               if (cf_data_find(cs, CF_DATA_TYPE_HOME_SERVER_POOL, "home_server_pool")) continue;
 
                type = pool_peek_type(config, cs);
                if (type == HOME_TYPE_INVALID) goto error;
index 2de479678e967902fd6e0227c1458bbf43da539a..0dbf2a9a73bf1e5bbf8d936cddd2f58343ee777d 100644 (file)
@@ -310,7 +310,7 @@ fr_tls_conf_t *tls_conf_parse_server(CONF_SECTION *cs)
         *      If cs has already been parsed there should be a cached copy
         *      of conf already stored, so just return that.
         */
-       conf = cf_data_find(cs, 0, "tls-conf");
+       conf = cf_data_find(cs, CF_DATA_TYPE_TLS, "tls-conf");
        if (conf) {
                DEBUG("Using cached TLS configuration from previous invocation");
                return conf;
@@ -432,7 +432,7 @@ fr_tls_conf_t *tls_conf_parse_server(CONF_SECTION *cs)
        /*
         *      Cache conf in cs in case we're asked to parse this again.
         */
-       cf_data_add(cs, 0, "tls-conf", conf, NULL);
+       cf_data_add(cs, CF_DATA_TYPE_TLS, "tls-conf", conf, NULL);
 
        return conf;
 }
@@ -442,7 +442,7 @@ fr_tls_conf_t *tls_conf_parse_client(CONF_SECTION *cs)
        fr_tls_conf_t *conf;
        uint32_t i;
 
-       conf = cf_data_find(cs, 0, "tls-conf");
+       conf = cf_data_find(cs, CF_DATA_TYPE_TLS, "tls-conf");
        if (conf) {
                DEBUG2("Using cached TLS configuration from previous invocation");
                return conf;