Annotation of embedaddon/strongswan/src/libimcv/imv/imv_session.c, revision 1.1

1.1     ! misho       1: /*
        !             2:  * Copyright (C) 2013-2015 Andreas Steffen
        !             3:  * HSR Hochschule fuer Technik Rapperswil
        !             4:  *
        !             5:  * This program is free software; you can redistribute it and/or modify it
        !             6:  * under the terms of the GNU General Public License as published by the
        !             7:  * Free Software Foundation; either version 2 of the License, or (at your
        !             8:  * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
        !             9:  *
        !            10:  * This program is distributed in the hope that it will be useful, but
        !            11:  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
        !            12:  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
        !            13:  * for more details.
        !            14:  */
        !            15: 
        !            16: #include "imv_session.h"
        !            17: 
        !            18: #include <tncif_identity.h>
        !            19: 
        !            20: #include <utils/debug.h>
        !            21: 
        !            22: typedef struct private_imv_session_t private_imv_session_t;
        !            23: 
        !            24: /**
        !            25:  * Private data of a imv_session_t object.
        !            26:  */
        !            27: struct private_imv_session_t {
        !            28: 
        !            29:        /**
        !            30:         * Public imv_session_t interface.
        !            31:         */
        !            32:        imv_session_t public;
        !            33: 
        !            34:        /**
        !            35:         * Unique Session ID
        !            36:         */
        !            37:        int session_id;
        !            38: 
        !            39:        /**
        !            40:         * Unique Product ID
        !            41:         */
        !            42:        int pid;
        !            43: 
        !            44:        /**
        !            45:         * Unique Device ID
        !            46:         */
        !            47:        int did;
        !            48: 
        !            49:        /**
        !            50:         * TNCCS connection ID
        !            51:         */
        !            52:        TNC_ConnectionID conn_id;
        !            53: 
        !            54:        /**
        !            55:         * Session creation time
        !            56:         */
        !            57:        time_t created;
        !            58: 
        !            59:        /**
        !            60:         * List of Access Requestor identities
        !            61:         */
        !            62:        linked_list_t *ar_identities;
        !            63: 
        !            64:        /**
        !            65:         * OS information
        !            66:         */
        !            67:        imv_os_info_t *os_info;
        !            68: 
        !            69:        /**
        !            70:         * Device ID
        !            71:         */
        !            72:        chunk_t device_id;
        !            73: 
        !            74:        /**
        !            75:         * Is Device ID trusted?
        !            76:         */
        !            77:        bool trusted;
        !            78: 
        !            79:        /**
        !            80:         * Have the workitems been generated?
        !            81:         */
        !            82:        bool policy_started;
        !            83: 
        !            84:        /**
        !            85:         * List of worklist items
        !            86:         */
        !            87:        linked_list_t *workitems;
        !            88: 
        !            89:        /**
        !            90:         * Reference count
        !            91:         */
        !            92:        refcount_t ref;
        !            93: 
        !            94: };
        !            95: 
        !            96: METHOD(imv_session_t, set_session_id, void,
        !            97:        private_imv_session_t *this, int session_id, int pid, int did)
        !            98: {
        !            99:        this->session_id = session_id;
        !           100:        this->pid = pid;
        !           101:        this->did = did;
        !           102: }
        !           103: 
        !           104: METHOD(imv_session_t, get_session_id, int,
        !           105:        private_imv_session_t *this, int *pid, int *did)
        !           106: {
        !           107:        if (pid)
        !           108:        {
        !           109:                *pid = this->pid;
        !           110:        }
        !           111:        if (did)
        !           112:        {
        !           113:                *did = this->did;
        !           114:        }
        !           115:        return this->session_id;
        !           116: }
        !           117: 
        !           118: METHOD(imv_session_t, get_connection_id, TNC_ConnectionID,
        !           119:        private_imv_session_t *this)
        !           120: {
        !           121:        return this->conn_id;
        !           122: }
        !           123: 
        !           124: METHOD(imv_session_t, set_creation_time, void,
        !           125:        private_imv_session_t *this, time_t created)
        !           126: {
        !           127:        this->created = created;
        !           128: }
        !           129: 
        !           130: METHOD(imv_session_t, get_creation_time, time_t,
        !           131:        private_imv_session_t *this)
        !           132: {
        !           133:        return this->created;
        !           134: }
        !           135: 
        !           136: METHOD(imv_session_t, create_ar_identities_enumerator, enumerator_t*,
        !           137:        private_imv_session_t *this)
        !           138: {
        !           139:        return this->ar_identities->create_enumerator(this->ar_identities);
        !           140: }
        !           141: 
        !           142: METHOD(imv_session_t, get_os_info, imv_os_info_t*,
        !           143:        private_imv_session_t *this)
        !           144: {
        !           145:        return this->os_info;
        !           146: }
        !           147: 
        !           148: METHOD(imv_session_t, set_device_id, void,
        !           149:        private_imv_session_t *this, chunk_t device_id)
        !           150: {
        !           151:        if (device_id.len == 0)
        !           152:        {
        !           153:                device_id = chunk_from_str("unknown");
        !           154:        }
        !           155:        if (this->device_id.len)
        !           156:        {
        !           157:                if (chunk_equals(device_id, this->device_id))
        !           158:                {
        !           159:                        return;
        !           160:                }
        !           161:                free(this->device_id.ptr);
        !           162:        }
        !           163:        this->device_id = chunk_clone(device_id);
        !           164: }
        !           165: 
        !           166: METHOD(imv_session_t, get_device_id, bool,
        !           167:        private_imv_session_t *this, chunk_t *device_id)
        !           168: {
        !           169:        if (this->device_id.len == 0)
        !           170:        {
        !           171:                return FALSE;
        !           172:        }
        !           173:        if (device_id)
        !           174:        {
        !           175:                *device_id = this->device_id;
        !           176:        }
        !           177:        return TRUE;
        !           178: }
        !           179: 
        !           180: METHOD(imv_session_t, set_device_trust, void,
        !           181:        private_imv_session_t *this, bool trusted)
        !           182: {
        !           183:        this->trusted = trusted;
        !           184: }
        !           185: 
        !           186: METHOD(imv_session_t, get_device_trust, bool,
        !           187:        private_imv_session_t *this)
        !           188: {
        !           189:        return this->trusted;
        !           190: }
        !           191: 
        !           192: METHOD(imv_session_t, set_policy_started, void,
        !           193:        private_imv_session_t *this, bool start)
        !           194: {
        !           195:        this->policy_started = start;
        !           196: }
        !           197: 
        !           198: METHOD(imv_session_t, get_policy_started, bool,
        !           199:        private_imv_session_t *this)
        !           200: {
        !           201:        return this->policy_started;
        !           202: }
        !           203: 
        !           204: METHOD(imv_session_t, insert_workitem, void,
        !           205:        private_imv_session_t *this, imv_workitem_t *workitem)
        !           206: {
        !           207:        this->workitems->insert_last(this->workitems, workitem);
        !           208: }
        !           209: 
        !           210: METHOD(imv_session_t, remove_workitem, void,
        !           211:        private_imv_session_t *this, enumerator_t *enumerator)
        !           212: {
        !           213:        this->workitems->remove_at(this->workitems, enumerator);
        !           214: }
        !           215: 
        !           216: METHOD(imv_session_t, create_workitem_enumerator, enumerator_t*,
        !           217:        private_imv_session_t *this)
        !           218: {
        !           219:        return this->workitems->create_enumerator(this->workitems);
        !           220: }
        !           221: 
        !           222: METHOD(imv_session_t, get_workitem_count, int,
        !           223:        private_imv_session_t *this, TNC_IMVID imv_id)
        !           224: {
        !           225:        enumerator_t *enumerator;
        !           226:        imv_workitem_t *workitem;
        !           227:        int count = 0;
        !           228: 
        !           229:        enumerator = this->workitems->create_enumerator(this->workitems);
        !           230:        while (enumerator->enumerate(enumerator, &workitem))
        !           231:        {
        !           232:                if (workitem->get_imv_id(workitem) == imv_id)
        !           233:                {
        !           234:                        count++;
        !           235:                }
        !           236:        }
        !           237:        enumerator->destroy(enumerator);
        !           238: 
        !           239:        return count;
        !           240: }
        !           241: 
        !           242: METHOD(imv_session_t, get_ref, imv_session_t*,
        !           243:        private_imv_session_t *this)
        !           244: {
        !           245:        ref_get(&this->ref);
        !           246: 
        !           247:        return &this->public;
        !           248: }
        !           249: 
        !           250: METHOD(imv_session_t, destroy, void,
        !           251:        private_imv_session_t *this)
        !           252: {
        !           253:        if (ref_put(&this->ref))
        !           254:        {
        !           255:                this->workitems->destroy_offset(this->workitems,
        !           256:                                                                 offsetof(imv_workitem_t, destroy));
        !           257:                this->os_info->destroy(this->os_info);
        !           258:                this->ar_identities->destroy_offset(this->ar_identities,
        !           259:                                                                         offsetof(tncif_identity_t, destroy));
        !           260:                free(this->device_id.ptr);
        !           261:                free(this);
        !           262:        }
        !           263: }
        !           264: 
        !           265: /**
        !           266:  * See header
        !           267:  */
        !           268: imv_session_t *imv_session_create(TNC_ConnectionID conn_id,
        !           269:                                                                  linked_list_t *ar_identities)
        !           270: {
        !           271:        private_imv_session_t *this;
        !           272: 
        !           273:        INIT(this,
        !           274:                .public = {
        !           275:                        .set_session_id = _set_session_id,
        !           276:                        .get_session_id = _get_session_id,
        !           277:                        .get_connection_id = _get_connection_id,
        !           278:                        .set_creation_time = _set_creation_time,
        !           279:                        .get_creation_time = _get_creation_time,
        !           280:                        .create_ar_identities_enumerator = _create_ar_identities_enumerator,
        !           281:                        .get_os_info = _get_os_info,
        !           282:                        .set_device_id = _set_device_id,
        !           283:                        .get_device_id = _get_device_id,
        !           284:                        .set_device_trust = _set_device_trust,
        !           285:                        .get_device_trust = _get_device_trust,
        !           286:                        .set_policy_started = _set_policy_started,
        !           287:                        .get_policy_started = _get_policy_started,
        !           288:                        .insert_workitem = _insert_workitem,
        !           289:                        .remove_workitem = _remove_workitem,
        !           290:                        .create_workitem_enumerator = _create_workitem_enumerator,
        !           291:                        .get_workitem_count = _get_workitem_count,
        !           292:                        .get_ref = _get_ref,
        !           293:                        .destroy = _destroy,
        !           294:                },
        !           295:                .conn_id = conn_id,
        !           296:                .ar_identities = ar_identities,
        !           297:                .os_info = imv_os_info_create(),
        !           298:                .workitems = linked_list_create(),
        !           299:                .ref = 1,
        !           300:        );
        !           301: 
        !           302:        return &this->public;
        !           303: }

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