Annotation of embedaddon/strongswan/src/libcharon/plugins/ext_auth/ext_auth_plugin.c, revision 1.1

1.1     ! misho       1: /*
        !             2:  * Copyright (c) 2014 Vyronas Tsingaras (vtsingaras@it.auth.gr)
        !             3:  * Copyright (C) 2014 Martin Willi
        !             4:  * Copyright (C) 2014 revosec AG
        !             5:  *
        !             6:  * Permission is hereby granted, free of charge, to any person obtaining a copy
        !             7:  * of this software and associated documentation files (the "Software"), to deal
        !             8:  * in the Software without restriction, including without limitation the rights
        !             9:  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        !            10:  * copies of the Software, and to permit persons to whom the Software is
        !            11:  * furnished to do so, subject to the following conditions:
        !            12:  *
        !            13:  * The above copyright notice and this permission notice shall be included in
        !            14:  * all copies or substantial portions of the Software.
        !            15:  *
        !            16:  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        !            17:  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        !            18:  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        !            19:  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        !            20:  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        !            21:  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
        !            22:  * THE SOFTWARE.
        !            23:  */
        !            24: 
        !            25: #include "ext_auth_plugin.h"
        !            26: #include "ext_auth_listener.h"
        !            27: 
        !            28: #include <daemon.h>
        !            29: 
        !            30: typedef struct private_ext_auth_plugin_t private_ext_auth_plugin_t;
        !            31: 
        !            32: /**
        !            33:  * private data of ext_auth plugin
        !            34:  */
        !            35: struct private_ext_auth_plugin_t {
        !            36: 
        !            37:        /**
        !            38:         * implements plugin interface
        !            39:         */
        !            40:        ext_auth_plugin_t public;
        !            41: 
        !            42:        /**
        !            43:         * Listener verifying peers during authorization
        !            44:         */
        !            45:        ext_auth_listener_t *listener;
        !            46: };
        !            47: 
        !            48: METHOD(plugin_t, get_name, char*,
        !            49:        private_ext_auth_plugin_t *this)
        !            50: {
        !            51:        return "ext-auth";
        !            52: }
        !            53: 
        !            54: /**
        !            55:  * Create a listener instance, NULL on error
        !            56:  */
        !            57: static ext_auth_listener_t* create_listener()
        !            58: {
        !            59:        char *script;
        !            60: 
        !            61:        script = lib->settings->get_str(lib->settings,
        !            62:                                        "%s.plugins.ext-auth.script", NULL, lib->ns);
        !            63:        if (!script)
        !            64:        {
        !            65:                DBG1(DBG_CFG, "no script for ext-auth script defined, disabled");
        !            66:                return NULL;
        !            67:        }
        !            68:        DBG1(DBG_CFG, "using ext-auth script '%s'", script);
        !            69:        return ext_auth_listener_create(script);
        !            70: }
        !            71: 
        !            72: /**
        !            73:  * Register listener
        !            74:  */
        !            75: static bool plugin_cb(private_ext_auth_plugin_t *this,
        !            76:                                          plugin_feature_t *feature, bool reg, void *cb_data)
        !            77: {
        !            78:        if (reg)
        !            79:        {
        !            80:                this->listener = create_listener();
        !            81:                if (!this->listener)
        !            82:                {
        !            83:                        return FALSE;
        !            84:                }
        !            85:                charon->bus->add_listener(charon->bus, &this->listener->listener);
        !            86:        }
        !            87:        else
        !            88:        {
        !            89:                if (this->listener)
        !            90:                {
        !            91:                        charon->bus->remove_listener(charon->bus, &this->listener->listener);
        !            92:                        this->listener->destroy(this->listener);
        !            93:                }
        !            94:        }
        !            95:        return TRUE;
        !            96: }
        !            97: 
        !            98: METHOD(plugin_t, get_features, int,
        !            99:        private_ext_auth_plugin_t *this, plugin_feature_t *features[])
        !           100: {
        !           101:        static plugin_feature_t f[] = {
        !           102:                PLUGIN_CALLBACK((plugin_feature_callback_t)plugin_cb, NULL),
        !           103:                        PLUGIN_PROVIDE(CUSTOM, "ext_auth"),
        !           104:        };
        !           105:        *features = f;
        !           106:        return countof(f);
        !           107: }
        !           108: 
        !           109: 
        !           110: METHOD(plugin_t, reload, bool,
        !           111:        private_ext_auth_plugin_t *this)
        !           112: {
        !           113:        ext_auth_listener_t *listener;
        !           114: 
        !           115:        /* reload new listener overlapped */
        !           116:        listener = create_listener();
        !           117:        if (listener)
        !           118:        {
        !           119:                charon->bus->add_listener(charon->bus, &listener->listener);
        !           120:        }
        !           121:        if (this->listener)
        !           122:        {
        !           123:                charon->bus->remove_listener(charon->bus, &this->listener->listener);
        !           124:                this->listener->destroy(this->listener);
        !           125:        }
        !           126:        this->listener = listener;
        !           127: 
        !           128:        return TRUE;
        !           129: }
        !           130: 
        !           131: METHOD(plugin_t, destroy, void,
        !           132:        private_ext_auth_plugin_t *this)
        !           133: {
        !           134:        free(this);
        !           135: }
        !           136: 
        !           137: /**
        !           138:  * Plugin constructor
        !           139:  */
        !           140: plugin_t *ext_auth_plugin_create()
        !           141: {
        !           142:        private_ext_auth_plugin_t *this;
        !           143: 
        !           144:        INIT(this,
        !           145:                .public = {
        !           146:                        .plugin = {
        !           147:                                .get_name = _get_name,
        !           148:                                .get_features = _get_features,
        !           149:                                .reload = _reload,
        !           150:                                .destroy = _destroy,
        !           151:                        },
        !           152:                },
        !           153:        );
        !           154: 
        !           155:        return &this->public.plugin;
        !           156: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>