1N/A/*
1N/A * Common Public License Version 0.5
1N/A *
1N/A * THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF
1N/A * THIS COMMON PUBLIC LICENSE ("AGREEMENT"). ANY USE,
1N/A * REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES
1N/A * RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
1N/A *
1N/A * 1. DEFINITIONS
1N/A *
1N/A * "Contribution" means:
1N/A * a) in the case of the initial Contributor, the
1N/A * initial code and documentation distributed under
1N/A * this Agreement, and
1N/A *
1N/A * b) in the case of each subsequent Contributor:
1N/A * i) changes to the Program, and
1N/A * ii) additions to the Program;
1N/A *
1N/A * where such changes and/or additions to the Program
1N/A * originate from and are distributed by that
1N/A * particular Contributor. A Contribution 'originates'
1N/A * from a Contributor if it was added to the Program
1N/A * by such Contributor itself or anyone acting on such
1N/A * Contributor's behalf. Contributions do not include
1N/A * additions to the Program which: (i) are separate
1N/A * modules of software distributed in conjunction with
1N/A * the Program under their own license agreement, and
1N/A * (ii) are not derivative works of the Program.
1N/A *
1N/A *
1N/A * "Contributor" means any person or entity that distributes
1N/A * the Program.
1N/A *
1N/A * "Licensed Patents " mean patent claims licensable by a
1N/A * Contributor which are necessarily infringed by the use or
1N/A * sale of its Contribution alone or when combined with the
1N/A * Program.
1N/A *
1N/A * "Program" means the Contributions distributed in
1N/A * accordance with this Agreement.
1N/A *
1N/A * "Recipient" means anyone who receives the Program under
1N/A * this Agreement, including all Contributors.
1N/A *
1N/A * 2. GRANT OF RIGHTS
1N/A *
1N/A * a) Subject to the terms of this Agreement, each
1N/A * Contributor hereby grants Recipient a
1N/A * no - exclusive, worldwide, royalt - free copyright
1N/A * license to reproduce, prepare derivative works of,
1N/A * publicly display, publicly perform, distribute and
1N/A * sublicense the Contribution of such Contributor, if
1N/A * any, and such derivative works, in source code and
1N/A * object code form.
1N/A *
1N/A * b) Subject to the terms of this Agreement, each
1N/A * Contributor hereby grants Recipient a
1N/A * no - exclusive, worldwide, royalt - free patent
1N/A * license under Licensed Patents to make, use, sell,
1N/A * offer to sell, import and otherwise transfer the
1N/A * Contribution of such Contributor, if any, in source
1N/A * code and object code form. This patent license
1N/A * shall apply to the combination of the Contribution
1N/A * and the Program if, at the time the Contribution is
1N/A * added by the Contributor, such addition of the
1N/A * Contribution causes such combination to be covered
1N/A * by the Licensed Patents. The patent license shall
1N/A * not apply to any other combinations which include
1N/A * the Contribution. No hardware per se is licensed
1N/A * hereunder.
1N/A *
1N/A * c) Recipient understands that although each
1N/A * Contributor grants the licenses to its
1N/A * Contributions set forth herein, no assurances are
1N/A * provided by any Contributor that the Program does
1N/A * not infringe the patent or other intellectual
1N/A * property rights of any other entity. Each
1N/A * Contributor disclaims any liability to Recipient
1N/A * for claims brought by any other entity based on
1N/A * infringement of intellectual property rights or
1N/A * otherwise. As a condition to exercising the rights
1N/A * and licenses granted hereunder, each Recipient
1N/A * hereby assumes sole responsibility to secure any
1N/A * other intellectual property rights needed, if any.
1N/A *
1N/A * For example, if a third party patent license is
1N/A * required to allow Recipient to distribute the
1N/A * Program, it is Recipient's responsibility to
1N/A * acquire that license before distributing the
1N/A * Program.
1N/A *
1N/A * d) Each Contributor represents that to its
1N/A * knowledge it has sufficient copyright rights in its
1N/A * Contribution, if any, to grant the copyright
1N/A * license set forth in this Agreement.
1N/A *
1N/A * 3. REQUIREMENTS
1N/A *
1N/A * A Contributor may choose to distribute the Program in
1N/A * object code form under its own license agreement, provided
1N/A * that:
1N/A * a) it complies with the terms and conditions of
1N/A * this Agreement; and
1N/A *
1N/A * b) its license agreement:
1N/A * i) effectively disclaims on behalf of all
1N/A * Contributors all warranties and conditions, express
1N/A * and implied, including warranties or conditions of
1N/A * title and no - infringement, and implied warranties
1N/A * or conditions of merchantability and fitness for a
1N/A * particular purpose;
1N/A *
1N/A * ii) effectively excludes on behalf of all
1N/A * Contributors all liability for damages, including
1N/A * direct, indirect, special, incidental and
1N/A * consequential damages, such as lost profits;
1N/A *
1N/A * iii) states that any provisions which differ from
1N/A * this Agreement are offered by that Contributor
1N/A * alone and not by any other party; and
1N/A *
1N/A * iv) states that source code for the Program is
1N/A * available from such Contributor, and informs
1N/A * licensees how to obtain it in a reasonable manner
1N/A * on or through a medium customarily used for
1N/A * software exchange.
1N/A *
1N/A * When the Program is made available in source code form:
1N/A * a) it must be made available under this Agreement;
1N/A * and
1N/A * b) a copy of this Agreement must be included with
1N/A * each copy of the Program.
1N/A *
1N/A * Contributors may not remove or alter any copyright notices
1N/A * contained within the Program.
1N/A *
1N/A * Each Contributor must identify itself as the originator of
1N/A * its Contribution, if any, in a manner that reasonably
1N/A * allows subsequent Recipients to identify the originator of
1N/A * the Contribution.
1N/A *
1N/A *
1N/A * 4. COMMERCIAL DISTRIBUTION
1N/A *
1N/A * Commercial distributors of software may accept certain
1N/A * responsibilities with respect to end users, business
1N/A * partners and the like. While this license is intended to
1N/A * facilitate the commercial use of the Program, the
1N/A * Contributor who includes the Program in a commercial
1N/A * product offering should do so in a manner which does not
1N/A * create potential liability for other Contributors.
1N/A * Therefore, if a Contributor includes the Program in a
1N/A * commercial product offering, such Contributor ("Commercial
1N/A * Contributor") hereby agrees to defend and indemnify every
1N/A * other Contributor ("Indemnified Contributor") against any
1N/A * losses, damages and costs (collectively "Losses") arising
1N/A * from claims, lawsuits and other legal actions brought by a
1N/A * third party against the Indemnified Contributor to the
1N/A * extent caused by the acts or omissions of such Commercial
1N/A * Contributor in connection with its distribution of the
1N/A * Program in a commercial product offering. The obligations
1N/A * in this section do not apply to any claims or Losses
1N/A * relating to any actual or alleged intellectual property
1N/A * infringement. In order to qualify, an Indemnified
1N/A * Contributor must: a) promptly notify the Commercial
1N/A * Contributor in writing of such claim, and b) allow the
1N/A * Commercial Contributor to control, and cooperate with the
1N/A * Commercial Contributor in, the defense and any related
1N/A * settlement negotiations. The Indemnified Contributor may
1N/A * participate in any such claim at its own expense.
1N/A *
1N/A *
1N/A * For example, a Contributor might include the Program in a
1N/A * commercial product offering, Product X. That Contributor
1N/A * is then a Commercial Contributor. If that Commercial
1N/A * Contributor then makes performance claims, or offers
1N/A * warranties related to Product X, those performance claims
1N/A * and warranties are such Commercial Contributor's
1N/A * responsibility alone. Under this section, the Commercial
1N/A * Contributor would have to defend claims against the other
1N/A * Contributors related to those performance claims and
1N/A * warranties, and if a court requires any other Contributor
1N/A * to pay any damages as a result, the Commercial Contributor
1N/A * must pay those damages.
1N/A *
1N/A *
1N/A * 5. NO WARRANTY
1N/A *
1N/A * EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE
1N/A * PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT
1N/A * WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR
1N/A * IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR
1N/A * CONDITIONS OF TITLE, NO - INFRINGEMENT, MERCHANTABILITY OR
1N/A * FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely
1N/A * responsible for determining the appropriateness of using
1N/A * and distributing the Program and assumes all risks
1N/A * associated with its exercise of rights under this
1N/A * Agreement, including but not limited to the risks and
1N/A * costs of program errors, compliance with applicable laws,
1N/A * damage to or loss of data, programs or equipment, and
1N/A * unavailability or interruption of operations.
1N/A *
1N/A * 6. DISCLAIMER OF LIABILITY
1N/A * EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER
1N/A * RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY
1N/A * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
1N/A * OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION
1N/A * LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF
1N/A * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1N/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
1N/A * OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE
1N/A * OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE
1N/A * POSSIBILITY OF SUCH DAMAGES.
1N/A *
1N/A * 7. GENERAL
1N/A *
1N/A * If any provision of this Agreement is invalid or
1N/A * unenforceable under applicable law, it shall not affect
1N/A * the validity or enforceability of the remainder of the
1N/A * terms of this Agreement, and without further action by the
1N/A * parties hereto, such provision shall be reformed to the
1N/A * minimum extent necessary to make such provision valid and
1N/A * enforceable.
1N/A *
1N/A *
1N/A * If Recipient institutes patent litigation against a
1N/A * Contributor with respect to a patent applicable to
1N/A * software (including a cros - claim or counterclaim in a
1N/A * lawsuit), then any patent licenses granted by that
1N/A * Contributor to such Recipient under this Agreement shall
1N/A * terminate as of the date such litigation is filed. In
1N/A * addition, If Recipient institutes patent litigation
1N/A * against any entity (including a cros - claim or
1N/A * counterclaim in a lawsuit) alleging that the Program
1N/A * itself (excluding combinations of the Program with other
1N/A * software or hardware) infringes such Recipient's
1N/A * patent(s), then such Recipient's rights granted under
1N/A * Section 2(b) shall terminate as of the date such
1N/A * litigation is filed.
1N/A *
1N/A * All Recipient's rights under this Agreement shall
1N/A * terminate if it fails to comply with any of the material
1N/A * terms or conditions of this Agreement and does not cure
1N/A * such failure in a reasonable period of time after becoming
1N/A * aware of such noncompliance. If all Recipient's rights
1N/A * under this Agreement terminate, Recipient agrees to cease
1N/A * use and distribution of the Program as soon as reasonably
1N/A * practicable. However, Recipient's obligations under this
1N/A * Agreement and any licenses granted by Recipient relating
1N/A * to the Program shall continue and survive.
1N/A *
1N/A * Everyone is permitted to copy and distribute copies of
1N/A * this Agreement, but in order to avoid inconsistency the
1N/A * Agreement is copyrighted and may only be modified in the
1N/A * following manner. The Agreement Steward reserves the right
1N/A * to publish new versions (including revisions) of this
1N/A * Agreement from time to time. No one other than the
1N/A * Agreement Steward has the right to modify this Agreement.
1N/A *
1N/A * IBM is the initial Agreement Steward. IBM may assign the
1N/A * responsibility to serve as the Agreement Steward to a
1N/A * suitable separate entity. Each new version of the
1N/A * Agreement will be given a distinguishing version number.
1N/A * The Program (including Contributions) may always be
1N/A * distributed subject to the version of the Agreement under
1N/A * which it was received. In addition, after a new version of
1N/A * the Agreement is published, Contributor may elect to
1N/A * distribute the Program (including its Contributions) under
1N/A * the new version. Except as expressly stated in Sections
1N/A * 2(a) and 2(b) above, Recipient receives no rights or
1N/A * licenses to the intellectual property of any Contributor
1N/A * under this Agreement, whether expressly, by implication,
1N/A * estoppel or otherwise. All rights in the Program not
1N/A * expressly granted under this Agreement are reserved.
1N/A *
1N/A *
1N/A * This Agreement is governed by the laws of the State of New
1N/A * York and the intellectual property laws of the United
1N/A * States of America. No party to this Agreement will bring a
1N/A * legal action under this Agreement more than one year after
1N/A * the cause of action arose. Each party waives its rights to
1N/A * a jury trial in any resulting litigation.
1N/A *
1N/A *
1N/A *
1N/A * (C) COPYRIGHT International Business Machines Corp. 2001, 2002
1N/A */
1N/A/*
1N/A * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
1N/A */
1N/A
1N/A#include "tpmtok_int.h"
1N/A
1N/Apthread_rwlock_t obj_list_rw_mutex = PTHREAD_RWLOCK_INITIALIZER;
1N/A
1N/Astatic CK_RV
1N/Aobject_mgr_search_shm_for_obj(TOK_OBJ_ENTRY *,
1N/A CK_ULONG, CK_ULONG, OBJECT *, CK_ULONG *);
1N/Astatic CK_RV object_mgr_update_from_shm(TSS_HCONTEXT);
1N/Astatic CK_RV object_mgr_check_shm(TSS_HCONTEXT, OBJECT *);
1N/A
1N/Astatic CK_RV
1N/Acheck_object_access(SESSION *sess, OBJECT *o)
1N/A{
1N/A CK_BBOOL sess_obj, priv_obj;
1N/A CK_RV rc = CKR_OK;
1N/A
1N/A /*
1N/A * check whether session has permissions to create the object, etc
1N/A *
1N/A * Object R/O R/W R/O R/W R/W
1N/A * Type Public Public User User SO
1N/A * -------------------------------------------------------------
1N/A * Public session R/W R/W R/W R/W R/W
1N/A * Private session R/W R/W
1N/A * Public token R/O R/W R/O R/W R/W
1N/A * Private token R/O R/W
1N/A */
1N/A sess_obj = object_is_session_object(o);
1N/A priv_obj = object_is_private(o);
1N/A
1N/A if (sess->session_info.state == CKS_RO_PUBLIC_SESSION) {
1N/A if (priv_obj) {
1N/A rc = CKR_USER_NOT_LOGGED_IN;
1N/A goto done;
1N/A }
1N/A
1N/A if (!sess_obj) {
1N/A rc = CKR_SESSION_READ_ONLY;
1N/A goto done;
1N/A }
1N/A }
1N/A
1N/A if (sess->session_info.state == CKS_RO_USER_FUNCTIONS) {
1N/A if (! sess_obj) {
1N/A rc = CKR_SESSION_READ_ONLY;
1N/A goto done;
1N/A }
1N/A }
1N/A
1N/A if (sess->session_info.state == CKS_RW_PUBLIC_SESSION) {
1N/A if (priv_obj) {
1N/A rc = CKR_USER_NOT_LOGGED_IN;
1N/A goto done;
1N/A }
1N/A }
1N/A
1N/A if (sess->session_info.state == CKS_RW_SO_FUNCTIONS) {
1N/A if (priv_obj) {
1N/A rc = CKR_USER_NOT_LOGGED_IN;
1N/A goto done;
1N/A }
1N/A }
1N/Adone:
1N/A return (rc);
1N/A}
1N/A
1N/ACK_RV
1N/Aobject_mgr_add(SESSION * sess,
1N/A CK_ATTRIBUTE * pTemplate,
1N/A CK_ULONG ulCount,
1N/A CK_OBJECT_HANDLE * handle)
1N/A{
1N/A OBJECT * o = NULL;
1N/A CK_BBOOL priv_obj, sess_obj;
1N/A CK_RV rc;
1N/A
1N/A if (! sess || ! pTemplate || ! handle) {
1N/A return (CKR_FUNCTION_FAILED);
1N/A }
1N/A
1N/A rc = pthread_mutex_lock(&obj_list_mutex);
1N/A if (rc != CKR_OK)
1N/A return (CKR_FUNCTION_FAILED);
1N/A
1N/A rc = object_create(pTemplate, ulCount, &o);
1N/A if (rc != CKR_OK) {
1N/A goto done;
1N/A }
1N/A rc = check_object_access(sess, o);
1N/A if (rc != CKR_OK)
1N/A goto done;
1N/A
1N/A /*
1N/A * okay, object is created and the session permissions look okay.
1N/A * add the object to the appropriate list and assign an object handle
1N/A */
1N/A sess_obj = object_is_session_object(o);
1N/A priv_obj = object_is_private(o);
1N/A
1N/A if (sess_obj) {
1N/A o->session = sess;
1N/A (void) memset(o->name, 0x00, sizeof (CK_BYTE) * 8);
1N/A
1N/A sess_obj_list = dlist_add_as_first(sess_obj_list, o);
1N/A } else {
1N/A CK_BYTE current[8];
1N/A CK_BYTE next[8];
1N/A
1N/A rc = XProcLock(xproclock);
1N/A if (rc != CKR_OK) {
1N/A goto done;
1N/A } else {
1N/A
1N/A if (priv_obj) {
1N/A if (global_shm->num_priv_tok_obj >=
1N/A MAX_TOK_OBJS) {
1N/A rc = CKR_HOST_MEMORY;
1N/A (void) XProcUnLock(xproclock);
1N/A goto done;
1N/A }
1N/A } else {
1N/A if (global_shm->num_publ_tok_obj >=
1N/A MAX_TOK_OBJS) {
1N/A rc = CKR_HOST_MEMORY;
1N/A (void) XProcUnLock(xproclock);
1N/A goto done;
1N/A }
1N/A }
1N/A
1N/A (void) memcpy(current,
1N/A &nv_token_data->next_token_object_name, 8);
1N/A
1N/A o->session = NULL;
1N/A (void) memcpy(&o->name, current, 8);
1N/A
1N/A (void) compute_next_token_obj_name(current, next);
1N/A
1N/A (void) memcpy(&nv_token_data->next_token_object_name,
1N/A next, 8);
1N/A
1N/A rc = save_token_object(sess->hContext, o);
1N/A if (rc != CKR_OK) {
1N/A (void) XProcUnLock(xproclock);
1N/A goto done;
1N/A }
1N/A
1N/A (void) object_mgr_add_to_shm(o);
1N/A (void) XProcUnLock(xproclock);
1N/A
1N/A (void) save_token_data(nv_token_data);
1N/A }
1N/A
1N/A if (priv_obj)
1N/A priv_token_obj_list =
1N/A dlist_add_as_last(priv_token_obj_list, o);
1N/A else
1N/A publ_token_obj_list =
1N/A dlist_add_as_last(publ_token_obj_list, o);
1N/A }
1N/A
1N/A rc = object_mgr_add_to_map(sess, o, handle);
1N/A if (rc != CKR_OK) {
1N/A DL_NODE *node = NULL;
1N/A
1N/A if (sess_obj) {
1N/A node = dlist_find(sess_obj_list, o);
1N/A if (node)
1N/A sess_obj_list =
1N/A dlist_remove_node(sess_obj_list, node);
1N/A } else {
1N/A (void) delete_token_object(o);
1N/A
1N/A if (priv_obj) {
1N/A node = dlist_find(priv_token_obj_list, o);
1N/A if (node)
1N/A priv_token_obj_list =
1N/A dlist_remove_node(
1N/A priv_token_obj_list, node);
1N/A } else {
1N/A node = dlist_find(publ_token_obj_list, o);
1N/A if (node)
1N/A publ_token_obj_list =
1N/A dlist_remove_node(
1N/A publ_token_obj_list, node);
1N/A }
1N/A
1N/A rc = XProcLock(xproclock);
1N/A if (rc != CKR_OK) {
1N/A goto done;
1N/A }
1N/A (void) object_mgr_del_from_shm(o);
1N/A
1N/A (void) XProcUnLock(xproclock);
1N/A }
1N/A }
1N/A
1N/Adone:
1N/A (void) pthread_mutex_unlock(&obj_list_mutex);
1N/A
1N/A if ((rc != CKR_OK) && (o != NULL))
1N/A (void) object_free(o);
1N/A
1N/A return (rc);
1N/A}
1N/A
1N/ACK_RV
1N/Aobject_mgr_add_to_map(SESSION * sess,
1N/A OBJECT * obj,
1N/A CK_OBJECT_HANDLE * handle) {
1N/A OBJECT_MAP *map_node = NULL;
1N/A
1N/A if (! sess || ! obj || ! handle) {
1N/A return (CKR_FUNCTION_FAILED);
1N/A }
1N/A
1N/A map_node = (OBJECT_MAP *)malloc(sizeof (OBJECT_MAP));
1N/A if (! map_node) {
1N/A return (CKR_HOST_MEMORY);
1N/A }
1N/A map_node->handle = next_object_handle++;
1N/A map_node->session = sess;
1N/A map_node->ptr = obj;
1N/A
1N/A if (obj->session != NULL)
1N/A map_node->is_session_obj = TRUE;
1N/A else
1N/A map_node->is_session_obj = FALSE;
1N/A
1N/A // add the new map entry to the list
1N/A if (pthread_rwlock_wrlock(&obj_list_rw_mutex)) {
1N/A free(map_node);
1N/A return (CKR_FUNCTION_FAILED);
1N/A }
1N/A object_map = dlist_add_as_first(object_map, map_node);
1N/A (void) pthread_rwlock_unlock(&obj_list_rw_mutex);
1N/A
1N/A *handle = map_node->handle;
1N/A return (CKR_OK);
1N/A}
1N/A
1N/A// object_mgr_copy()
1N/A//
1N/A// algorithm:
1N/A// 1) find the old object
1N/A// 2) get the template from the old object
1N/A// 3) merge in the new object's template
1N/A// 4) perform class - specific sanity checks
1N/A//
1N/ACK_RV
1N/Aobject_mgr_copy(SESSION * sess,
1N/A CK_ATTRIBUTE * pTemplate,
1N/A CK_ULONG ulCount,
1N/A CK_OBJECT_HANDLE old_handle,
1N/A CK_OBJECT_HANDLE * new_handle)
1N/A{
1N/A OBJECT *old_obj = NULL;
1N/A OBJECT *new_obj = NULL;
1N/A CK_BBOOL priv_obj;
1N/A CK_BBOOL sess_obj;
1N/A CK_RV rc;
1N/A
1N/A if (! sess || ! pTemplate || ! new_handle) {
1N/A return (CKR_FUNCTION_FAILED);
1N/A }
1N/A
1N/A rc = pthread_mutex_lock(&obj_list_mutex);
1N/A if (rc != CKR_OK)
1N/A return (CKR_FUNCTION_FAILED);
1N/A
1N/A rc = object_mgr_find_in_map1(sess->hContext, old_handle, &old_obj);
1N/A if (rc != CKR_OK) {
1N/A goto done;
1N/A }
1N/A rc = object_copy(pTemplate, ulCount, old_obj, &new_obj);
1N/A if (rc != CKR_OK) {
1N/A goto done;
1N/A }
1N/A
1N/A rc = check_object_access(sess, new_obj);
1N/A if (rc != CKR_OK)
1N/A goto done;
1N/A
1N/A sess_obj = object_is_session_object(new_obj);
1N/A priv_obj = object_is_private(new_obj);
1N/A
1N/A if (sess_obj) {
1N/A new_obj->session = sess;
1N/A (void) memset(&new_obj->name, 0x00, sizeof (CK_BYTE) * 8);
1N/A
1N/A sess_obj_list = dlist_add_as_first(sess_obj_list, new_obj);
1N/A } else {
1N/A CK_BYTE current[8];
1N/A CK_BYTE next[8];
1N/A
1N/A rc = XProcLock(xproclock);
1N/A if (rc != CKR_OK) {
1N/A goto done;
1N/A } else {
1N/A if (priv_obj) {
1N/A if (global_shm->num_priv_tok_obj >=
1N/A MAX_TOK_OBJS) {
1N/A (void) XProcUnLock(xproclock);
1N/A rc = CKR_HOST_MEMORY;
1N/A goto done;
1N/A }
1N/A } else {
1N/A if (global_shm->num_publ_tok_obj >=
1N/A MAX_TOK_OBJS) {
1N/A (void) XProcUnLock(xproclock);
1N/A rc = CKR_HOST_MEMORY;
1N/A goto done;
1N/A }
1N/A }
1N/A (void) memcpy(current,
1N/A &nv_token_data->next_token_object_name, 8);
1N/A
1N/A new_obj->session = NULL;
1N/A (void) memcpy(&new_obj->name, current, 8);
1N/A
1N/A (void) compute_next_token_obj_name(current, next);
1N/A (void) memcpy(&nv_token_data->next_token_object_name,
1N/A next, 8);
1N/A
1N/A rc = save_token_object(sess->hContext, new_obj);
1N/A if (rc != CKR_OK) {
1N/A (void) XProcUnLock(xproclock);
1N/A goto done;
1N/A }
1N/A
1N/A (void) object_mgr_add_to_shm(new_obj);
1N/A
1N/A (void) XProcUnLock(xproclock);
1N/A
1N/A (void) save_token_data(nv_token_data);
1N/A }
1N/A
1N/A if (priv_obj)
1N/A priv_token_obj_list = dlist_add_as_last(
1N/A priv_token_obj_list, new_obj);
1N/A else
1N/A publ_token_obj_list = dlist_add_as_last(
1N/A publ_token_obj_list, new_obj);
1N/A }
1N/A
1N/A rc = object_mgr_add_to_map(sess, new_obj, new_handle);
1N/A if (rc != CKR_OK) {
1N/A DL_NODE *node = NULL;
1N/A
1N/A if (sess_obj) {
1N/A node = dlist_find(sess_obj_list, new_obj);
1N/A if (node)
1N/A sess_obj_list = dlist_remove_node(
1N/A sess_obj_list, node);
1N/A } else {
1N/A (void) delete_token_object(new_obj);
1N/A
1N/A if (priv_obj) {
1N/A node = dlist_find(priv_token_obj_list, new_obj);
1N/A if (node)
1N/A priv_token_obj_list = dlist_remove_node(
1N/A priv_token_obj_list, node);
1N/A } else {
1N/A node = dlist_find(publ_token_obj_list, new_obj);
1N/A if (node)
1N/A publ_token_obj_list = dlist_remove_node(
1N/A publ_token_obj_list, node);
1N/A }
1N/A
1N/A rc = XProcLock(xproclock);
1N/A if (rc != CKR_OK) {
1N/A goto done;
1N/A }
1N/A (void) object_mgr_del_from_shm(new_obj);
1N/A
1N/A (void) XProcUnLock(xproclock);
1N/A }
1N/A }
1N/A
1N/Adone:
1N/A (void) pthread_mutex_unlock(&obj_list_mutex);
1N/A
1N/A if ((rc != CKR_OK) && (new_obj != NULL))
1N/A (void) object_free(new_obj);
1N/A
1N/A return (rc);
1N/A}
1N/A
1N/A//
1N/A// determines whether the session is allowed to create an object. creates
1N/A// the object but doesn't add the object to any object lists or to the
1N/A// process' object map.
1N/A//
1N/ACK_RV
1N/Aobject_mgr_create_skel(SESSION * sess,
1N/A CK_ATTRIBUTE * pTemplate,
1N/A CK_ULONG ulCount,
1N/A CK_ULONG mode,
1N/A CK_ULONG obj_type,
1N/A CK_ULONG sub_class,
1N/A OBJECT ** obj)
1N/A{
1N/A OBJECT *o = NULL;
1N/A CK_RV rc;
1N/A CK_BBOOL priv_obj;
1N/A CK_BBOOL sess_obj;
1N/A
1N/A if (! sess || ! obj) {
1N/A return (CKR_FUNCTION_FAILED);
1N/A }
1N/A if (! pTemplate && (ulCount != 0)) {
1N/A return (CKR_FUNCTION_FAILED);
1N/A }
1N/A rc = object_create_skel(pTemplate, ulCount,
1N/A mode, obj_type, sub_class, &o);
1N/A if (rc != CKR_OK) {
1N/A return (rc);
1N/A }
1N/A sess_obj = object_is_session_object(o);
1N/A priv_obj = object_is_private(o);
1N/A
1N/A if (sess->session_info.state == CKS_RO_PUBLIC_SESSION) {
1N/A if (priv_obj) {
1N/A (void) object_free(o);
1N/A return (CKR_USER_NOT_LOGGED_IN);
1N/A }
1N/A
1N/A if (! sess_obj) {
1N/A (void) object_free(o);
1N/A return (CKR_SESSION_READ_ONLY);
1N/A }
1N/A }
1N/A
1N/A if (sess->session_info.state == CKS_RO_USER_FUNCTIONS) {
1N/A if (! sess_obj) {
1N/A (void) object_free(o);
1N/A return (CKR_SESSION_READ_ONLY);
1N/A }
1N/A }
1N/A
1N/A if (sess->session_info.state == CKS_RW_PUBLIC_SESSION) {
1N/A if (priv_obj) {
1N/A (void) object_free(o);
1N/A return (CKR_USER_NOT_LOGGED_IN);
1N/A }
1N/A }
1N/A
1N/A if (sess->session_info.state == CKS_RW_SO_FUNCTIONS) {
1N/A if (priv_obj) {
1N/A (void) object_free(o);
1N/A return (CKR_USER_NOT_LOGGED_IN);
1N/A }
1N/A }
1N/A
1N/A *obj = o;
1N/A return (CKR_OK);
1N/A}
1N/A
1N/ACK_RV
1N/Aobject_mgr_create_final(SESSION * sess,
1N/A OBJECT * obj,
1N/A CK_OBJECT_HANDLE * handle)
1N/A{
1N/A CK_BBOOL sess_obj;
1N/A CK_BBOOL priv_obj;
1N/A CK_RV rc;
1N/A
1N/A if (!sess || !obj || !handle)
1N/A return (CKR_FUNCTION_FAILED);
1N/A
1N/A rc = pthread_mutex_lock(&obj_list_mutex);
1N/A if (rc != CKR_OK)
1N/A return (CKR_FUNCTION_FAILED);
1N/A
1N/A sess_obj = object_is_session_object(obj);
1N/A priv_obj = object_is_private(obj);
1N/A
1N/A if (sess_obj) {
1N/A obj->session = sess;
1N/A (void) memset(obj->name, 0x0, sizeof (CK_BYTE) * 8);
1N/A
1N/A sess_obj_list = dlist_add_as_first(sess_obj_list, obj);
1N/A } else {
1N/A CK_BYTE current[8];
1N/A CK_BYTE next[8];
1N/A
1N/A rc = XProcLock(xproclock);
1N/A if (rc != CKR_OK) {
1N/A goto done;
1N/A } else {
1N/A if (priv_obj) {
1N/A if (global_shm->num_priv_tok_obj >=
1N/A MAX_TOK_OBJS) {
1N/A (void) XProcUnLock(xproclock);
1N/A rc = CKR_HOST_MEMORY;
1N/A goto done;
1N/A }
1N/A } else {
1N/A if (global_shm->num_publ_tok_obj >=
1N/A MAX_TOK_OBJS) {
1N/A (void) XProcUnLock(xproclock);
1N/A rc = CKR_HOST_MEMORY;
1N/A goto done;
1N/A }
1N/A }
1N/A (void) memcpy(current,
1N/A &nv_token_data->next_token_object_name, 8);
1N/A
1N/A obj->session = NULL;
1N/A (void) memcpy(&obj->name, current, 8);
1N/A
1N/A (void) compute_next_token_obj_name(current, next);
1N/A (void) memcpy(&nv_token_data->next_token_object_name,
1N/A next, 8);
1N/A
1N/A rc = save_token_object(sess->hContext, obj);
1N/A if (rc != CKR_OK) {
1N/A (void) XProcUnLock(xproclock);
1N/A goto done;
1N/A }
1N/A
1N/A (void) object_mgr_add_to_shm(obj);
1N/A
1N/A (void) XProcUnLock(xproclock);
1N/A
1N/A (void) save_token_data(nv_token_data);
1N/A }
1N/A
1N/A if (priv_obj)
1N/A priv_token_obj_list = dlist_add_as_last(
1N/A priv_token_obj_list, obj);
1N/A else
1N/A publ_token_obj_list = dlist_add_as_last(
1N/A publ_token_obj_list, obj);
1N/A }
1N/A
1N/A rc = object_mgr_add_to_map(sess, obj, handle);
1N/A if (rc != CKR_OK) {
1N/A DL_NODE *node = NULL;
1N/A
1N/A if (sess_obj) {
1N/A node = dlist_find(sess_obj_list, obj);
1N/A if (node)
1N/A sess_obj_list = dlist_remove_node(
1N/A sess_obj_list, node);
1N/A } else {
1N/A (void) delete_token_object(obj);
1N/A
1N/A if (priv_obj) {
1N/A node = dlist_find(priv_token_obj_list, obj);
1N/A if (node)
1N/A priv_token_obj_list = dlist_remove_node(
1N/A priv_token_obj_list, node);
1N/A } else {
1N/A node = dlist_find(publ_token_obj_list, obj);
1N/A if (node)
1N/A publ_token_obj_list = dlist_remove_node(
1N/A publ_token_obj_list, node);
1N/A }
1N/A
1N/A rc = XProcLock(xproclock);
1N/A if (rc != CKR_OK) {
1N/A goto done;
1N/A }
1N/A (void) object_mgr_del_from_shm(obj);
1N/A
1N/A (void) XProcUnLock(xproclock);
1N/A }
1N/A }
1N/A
1N/Adone:
1N/A (void) pthread_mutex_unlock(&obj_list_mutex);
1N/A
1N/A return (rc);
1N/A}
1N/A
1N/ACK_RV
1N/Aobject_mgr_destroy_object(SESSION * sess,
1N/A CK_OBJECT_HANDLE handle)
1N/A{
1N/A OBJECT * obj = NULL;
1N/A CK_BBOOL sess_obj;
1N/A CK_BBOOL priv_obj;
1N/A CK_RV rc;
1N/A
1N/A if (! sess)
1N/A return (CKR_FUNCTION_FAILED);
1N/A
1N/A rc = pthread_mutex_lock(&obj_list_mutex);
1N/A if (rc != CKR_OK)
1N/A return (CKR_FUNCTION_FAILED);
1N/A
1N/A rc = object_mgr_find_in_map1(sess->hContext, handle, &obj);
1N/A if (rc != CKR_OK) {
1N/A goto done;
1N/A }
1N/A
1N/A rc = check_object_access(sess, obj);
1N/A if (rc != CKR_OK)
1N/A goto done;
1N/A
1N/A sess_obj = object_is_session_object(obj);
1N/A priv_obj = object_is_private(obj);
1N/A
1N/A if (sess_obj) {
1N/A DL_NODE *node;
1N/A
1N/A node = dlist_find(sess_obj_list, obj);
1N/A if (node) {
1N/A (void) object_mgr_remove_from_map(handle);
1N/A
1N/A (void) object_free(obj);
1N/A sess_obj_list = dlist_remove_node(
1N/A sess_obj_list, node);
1N/A
1N/A rc = CKR_OK;
1N/A goto done;
1N/A }
1N/A } else {
1N/A DL_NODE *node = NULL;
1N/A
1N/A (void) delete_token_object(obj);
1N/A
1N/A if (priv_obj)
1N/A node = dlist_find(priv_token_obj_list, obj);
1N/A else
1N/A node = dlist_find(publ_token_obj_list, obj);
1N/A
1N/A if (node) {
1N/A rc = XProcLock(xproclock);
1N/A if (rc != CKR_OK) {
1N/A goto done;
1N/A }
1N/A (void) object_mgr_del_from_shm(obj);
1N/A
1N/A (void) XProcUnLock(xproclock);
1N/A
1N/A (void) object_mgr_remove_from_map(handle);
1N/A
1N/A (void) object_free(obj);
1N/A
1N/A if (priv_obj)
1N/A priv_token_obj_list = dlist_remove_node(
1N/A priv_token_obj_list, node);
1N/A else
1N/A publ_token_obj_list = dlist_remove_node(
1N/A publ_token_obj_list, node);
1N/A
1N/A rc = CKR_OK;
1N/A goto done;
1N/A }
1N/A }
1N/A
1N/A rc = CKR_FUNCTION_FAILED;
1N/Adone:
1N/A (void) pthread_mutex_unlock(&obj_list_mutex);
1N/A
1N/A return (rc);
1N/A}
1N/A
1N/ACK_RV
1N/Aobject_mgr_destroy_token_objects(TSS_HCONTEXT hContext)
1N/A{
1N/A CK_BBOOL locked2 = FALSE;
1N/A CK_RV rc;
1N/A
1N/A rc = pthread_mutex_lock(&obj_list_mutex);
1N/A if (rc != CKR_OK)
1N/A return (CKR_FUNCTION_FAILED);
1N/A
1N/A while (publ_token_obj_list) {
1N/A OBJECT *obj = (OBJECT *)publ_token_obj_list->data;
1N/A
1N/A CK_OBJECT_HANDLE handle;
1N/A
1N/A rc = object_mgr_find_in_map2(hContext, obj, &handle);
1N/A if (rc == CKR_OK) {
1N/A (void) object_mgr_remove_from_map(handle);
1N/A }
1N/A (void) delete_token_object(obj);
1N/A (void) object_free(obj);
1N/A
1N/A publ_token_obj_list = dlist_remove_node(
1N/A publ_token_obj_list, publ_token_obj_list);
1N/A }
1N/A
1N/A while (priv_token_obj_list) {
1N/A OBJECT *obj = (OBJECT *)priv_token_obj_list->data;
1N/A
1N/A CK_OBJECT_HANDLE handle;
1N/A
1N/A rc = object_mgr_find_in_map2(hContext, obj, &handle);
1N/A if (rc == CKR_OK) {
1N/A (void) object_mgr_remove_from_map(handle);
1N/A }
1N/A (void) delete_token_object(obj);
1N/A (void) object_free(obj);
1N/A
1N/A priv_token_obj_list = dlist_remove_node(
1N/A priv_token_obj_list, priv_token_obj_list);
1N/A }
1N/A
1N/A // now we want to purge the token object list in shared memory
1N/A //
1N/A rc = XProcLock(xproclock);
1N/A if (rc == CKR_OK) {
1N/A locked2 = TRUE;
1N/A
1N/A global_shm->num_priv_tok_obj = 0;
1N/A global_shm->num_publ_tok_obj = 0;
1N/A
1N/A (void) memset(&global_shm->publ_tok_objs, 0x0,
1N/A MAX_TOK_OBJS * sizeof (TOK_OBJ_ENTRY));
1N/A (void) memset(&global_shm->priv_tok_objs, 0x0,
1N/A MAX_TOK_OBJS * sizeof (TOK_OBJ_ENTRY));
1N/A }
1N/A
1N/Adone:
1N/A (void) pthread_mutex_unlock(&obj_list_mutex);
1N/A
1N/A if (locked2 == TRUE) (void) XProcUnLock(xproclock);
1N/A
1N/A return (rc);
1N/A}
1N/A
1N/A//
1N/A// Locates the specified object in the map
1N/A// without going and checking for cache update
1N/A//
1N/ACK_RV
1N/Aobject_mgr_find_in_map_nocache(CK_OBJECT_HANDLE handle,
1N/A OBJECT ** ptr) {
1N/A DL_NODE * node = NULL;
1N/A OBJECT * obj = NULL;
1N/A
1N/A if (! ptr) {
1N/A return (CKR_FUNCTION_FAILED);
1N/A }
1N/A if (pthread_rwlock_rdlock(&obj_list_rw_mutex)) {
1N/A return (CKR_FUNCTION_FAILED);
1N/A }
1N/A node = object_map;
1N/A while (node) {
1N/A OBJECT_MAP *map = (OBJECT_MAP *)node->data;
1N/A
1N/A if (map->handle == handle) {
1N/A obj = map->ptr;
1N/A break;
1N/A }
1N/A
1N/A node = node->next;
1N/A }
1N/A (void) pthread_rwlock_unlock(&obj_list_rw_mutex);
1N/A
1N/A if (obj == NULL || node == NULL) {
1N/A return (CKR_OBJECT_HANDLE_INVALID);
1N/A }
1N/A
1N/A if (object_is_session_object(obj) == TRUE) {
1N/A *ptr = obj;
1N/A return (CKR_OK);
1N/A }
1N/A
1N/A *ptr = obj;
1N/A return (CKR_OK);
1N/A}
1N/A
1N/ACK_RV
1N/Aobject_mgr_find_in_map1(
1N/A TSS_HCONTEXT hContext,
1N/A CK_OBJECT_HANDLE handle,
1N/A OBJECT ** ptr)
1N/A{
1N/A DL_NODE * node = NULL;
1N/A OBJECT * obj = NULL;
1N/A
1N/A if (! ptr) {
1N/A return (CKR_FUNCTION_FAILED);
1N/A }
1N/A if (pthread_rwlock_rdlock(&obj_list_rw_mutex)) {
1N/A return (CKR_FUNCTION_FAILED);
1N/A }
1N/A node = object_map;
1N/A while (node) {
1N/A OBJECT_MAP *map = (OBJECT_MAP *)node->data;
1N/A
1N/A if (map->handle == handle) {
1N/A obj = map->ptr;
1N/A break;
1N/A }
1N/A
1N/A node = node->next;
1N/A }
1N/A (void) pthread_rwlock_unlock(&obj_list_rw_mutex);
1N/A
1N/A if (obj == NULL || node == NULL) {
1N/A return (CKR_OBJECT_HANDLE_INVALID);
1N/A }
1N/A
1N/A if (object_is_session_object(obj) == TRUE) {
1N/A *ptr = obj;
1N/A return (CKR_OK);
1N/A }
1N/A
1N/A (void) object_mgr_check_shm(hContext, obj);
1N/A
1N/A *ptr = obj;
1N/A return (CKR_OK);
1N/A}
1N/A
1N/ACK_RV
1N/Aobject_mgr_find_in_map2(
1N/A TSS_HCONTEXT hContext,
1N/A OBJECT * obj,
1N/A CK_OBJECT_HANDLE * handle)
1N/A{
1N/A DL_NODE * node = NULL;
1N/A CK_OBJECT_HANDLE h = (CK_OBJECT_HANDLE)NULL;
1N/A
1N/A if (! obj || ! handle) {
1N/A return (CKR_FUNCTION_FAILED);
1N/A }
1N/A if (pthread_rwlock_rdlock(&obj_list_rw_mutex)) {
1N/A return (CKR_FUNCTION_FAILED);
1N/A }
1N/A node = object_map;
1N/A while (node) {
1N/A OBJECT_MAP *map = (OBJECT_MAP *)node->data;
1N/A
1N/A if (map->ptr == obj) {
1N/A h = map->handle;
1N/A break;
1N/A }
1N/A
1N/A node = node->next;
1N/A }
1N/A (void) pthread_rwlock_unlock(&obj_list_rw_mutex);
1N/A
1N/A if (node == NULL) {
1N/A return (CKR_OBJECT_HANDLE_INVALID);
1N/A }
1N/A
1N/A if (object_is_session_object(obj) == TRUE) {
1N/A *handle = h;
1N/A return (CKR_OK);
1N/A }
1N/A
1N/A (void) object_mgr_check_shm(hContext, obj);
1N/A
1N/A *handle = h;
1N/A return (CKR_OK);
1N/A}
1N/A
1N/ACK_RV
1N/Aobject_mgr_find_init(SESSION * sess,
1N/A CK_ATTRIBUTE * pTemplate,
1N/A CK_ULONG ulCount)
1N/A{
1N/A if (! sess) {
1N/A return (CKR_FUNCTION_FAILED);
1N/A }
1N/A if (sess->find_active != FALSE) {
1N/A return (CKR_OPERATION_ACTIVE);
1N/A }
1N/A // initialize the found object list. if it doesn't exist, allocate
1N/A // a list big enough for 10 handles. we'll reallocate if we need more
1N/A //
1N/A if (sess->find_list != NULL) {
1N/A (void) memset(sess->find_list, 0x0,
1N/A sess->find_len * sizeof (CK_OBJECT_HANDLE));
1N/A } else {
1N/A sess->find_list = (CK_OBJECT_HANDLE *)malloc(
1N/A 10 * sizeof (CK_OBJECT_HANDLE));
1N/A if (! sess->find_list) {
1N/A return (CKR_HOST_MEMORY);
1N/A } else {
1N/A (void) memset(sess->find_list, 0x0,
1N/A 10 * sizeof (CK_OBJECT_HANDLE));
1N/A sess->find_len = 10;
1N/A }
1N/A }
1N/A
1N/A sess->find_count = 0;
1N/A sess->find_idx = 0;
1N/A
1N/A // --- need to grab the object lock here
1N/A if (pthread_mutex_lock(&obj_list_mutex))
1N/A return (CKR_FUNCTION_FAILED);
1N/A
1N/A (void) object_mgr_update_from_shm(sess->hContext);
1N/A
1N/A // which objects can be return (ed:
1N/A //
1N/A // Public Session: public session objects, public token objects
1N/A // User Session: all session objects, all token objects
1N/A // SO session: public session objects, public token objects
1N/A //
1N/A switch (sess->session_info.state) {
1N/A case CKS_RO_PUBLIC_SESSION:
1N/A case CKS_RW_PUBLIC_SESSION:
1N/A case CKS_RW_SO_FUNCTIONS:
1N/A (void) object_mgr_find_build_list(sess, pTemplate,
1N/A ulCount, publ_token_obj_list, TRUE);
1N/A (void) object_mgr_find_build_list(sess, pTemplate,
1N/A ulCount, sess_obj_list, TRUE);
1N/A break;
1N/A
1N/A case CKS_RO_USER_FUNCTIONS:
1N/A case CKS_RW_USER_FUNCTIONS:
1N/A (void) object_mgr_find_build_list(sess, pTemplate,
1N/A ulCount, priv_token_obj_list, FALSE);
1N/A (void) object_mgr_find_build_list(sess, pTemplate,
1N/A ulCount, publ_token_obj_list, FALSE);
1N/A (void) object_mgr_find_build_list(sess, pTemplate,
1N/A ulCount, sess_obj_list, FALSE);
1N/A break;
1N/A }
1N/A (void) pthread_mutex_unlock(&obj_list_mutex);
1N/A
1N/A sess->find_active = TRUE;
1N/A
1N/A return (CKR_OK);
1N/A}
1N/A
1N/ACK_RV
1N/Aobject_mgr_find_build_list(SESSION * sess,
1N/A CK_ATTRIBUTE * pTemplate,
1N/A CK_ULONG ulCount,
1N/A DL_NODE * obj_list,
1N/A CK_BBOOL public_only)
1N/A{
1N/A OBJECT * obj = NULL;
1N/A DL_NODE * node = NULL;
1N/A CK_OBJECT_HANDLE handle;
1N/A CK_BBOOL is_priv;
1N/A CK_BBOOL match;
1N/A CK_BBOOL hw_feature = FALSE;
1N/A CK_BBOOL hidden_object = FALSE;
1N/A CK_RV rc;
1N/A CK_ATTRIBUTE * attr;
1N/A unsigned int i;
1N/A
1N/A if (! sess) {
1N/A return (CKR_FUNCTION_FAILED);
1N/A }
1N/A if (! obj_list)
1N/A return (CKR_OK);
1N/A // PKCS#11 v2.11 (pg. 79): "When searching using C_FindObjectsInit
1N/A // and C_FindObjects, hardware feature objects are not returned
1N/A // unless the CKA_CLASS attribute in the template has the value
1N/A // CKO_HW_FEATURE." So, we check for CKO_HW_FEATURE and if its set,
1N/A // we'll find these objects below. - KEY
1N/A for (i = 0; i < ulCount; i++) {
1N/A if (pTemplate[i].type == CKA_CLASS) {
1N/A if (*(CK_ULONG *)pTemplate[i].pValue ==
1N/A CKO_HW_FEATURE) {
1N/A hw_feature = TRUE;
1N/A break;
1N/A }
1N/A }
1N/A
1N/A if (pTemplate[i].type == CKA_HIDDEN) {
1N/A if (*(CK_BBOOL *)pTemplate[i].pValue == TRUE) {
1N/A hidden_object = TRUE;
1N/A break;
1N/A }
1N/A }
1N/A }
1N/A
1N/A node = obj_list;
1N/A while (node) {
1N/A match = FALSE;
1N/A obj = (OBJECT *)node->data;
1N/A is_priv = object_is_private(obj);
1N/A
1N/A
1N/A if ((is_priv == FALSE) || (public_only == FALSE)) {
1N/A if (pTemplate == NULL || ulCount == 0)
1N/A match = TRUE;
1N/A else
1N/A match = template_compare(pTemplate,
1N/A ulCount, obj->template);
1N/A }
1N/A
1N/A if (match) {
1N/A rc = object_mgr_find_in_map2(sess->hContext, obj,
1N/A &handle);
1N/A if (rc != CKR_OK) {
1N/A rc = object_mgr_add_to_map(sess, obj, &handle);
1N/A if (rc != CKR_OK) {
1N/A return (CKR_FUNCTION_FAILED);
1N/A }
1N/A }
1N/A if (rc == CKR_OK) {
1N/A if ((hw_feature == FALSE) &&
1N/A (template_attribute_find(obj->template,
1N/A CKA_CLASS, &attr) == TRUE)) {
1N/A if (*(CK_OBJECT_CLASS *)attr->pValue ==
1N/A CKO_HW_FEATURE)
1N/A goto next_loop;
1N/A }
1N/A
1N/A if ((hidden_object == FALSE) &&
1N/A (template_attribute_find(obj->template,
1N/A CKA_HIDDEN, &attr) == TRUE)) {
1N/A if (*(CK_BBOOL *)attr->pValue == TRUE)
1N/A goto next_loop;
1N/A }
1N/A
1N/A sess->find_list[ sess->find_count ] = handle;
1N/A sess->find_count++;
1N/A
1N/A if (sess->find_count >= sess->find_len) {
1N/A sess->find_len += 15;
1N/A sess->find_list =
1N/A (CK_OBJECT_HANDLE *)realloc(
1N/A sess->find_list, sess->find_len *
1N/A sizeof (CK_OBJECT_HANDLE));
1N/A if (! sess->find_list) {
1N/A return (CKR_HOST_MEMORY);
1N/A }
1N/A }
1N/A }
1N/A }
1N/A next_loop:
1N/A node = node->next;
1N/A }
1N/A
1N/A return (CKR_OK);
1N/A}
1N/A
1N/ACK_RV
1N/Aobject_mgr_find_final(SESSION *sess)
1N/A{
1N/A if (! sess) {
1N/A return (CKR_FUNCTION_FAILED);
1N/A }
1N/A if (sess->find_active == FALSE) {
1N/A return (CKR_OPERATION_NOT_INITIALIZED);
1N/A }
1N/A free(sess->find_list);
1N/A sess->find_list = NULL;
1N/A sess->find_count = 0;
1N/A sess->find_idx = 0;
1N/A sess->find_active = FALSE;
1N/A
1N/A return (CKR_OK);
1N/A}
1N/A
1N/ACK_RV
1N/Aobject_mgr_get_attribute_values(SESSION * sess,
1N/A CK_OBJECT_HANDLE handle,
1N/A CK_ATTRIBUTE * pTemplate,
1N/A CK_ULONG ulCount)
1N/A{
1N/A OBJECT * obj;
1N/A CK_BBOOL priv_obj;
1N/A CK_RV rc;
1N/A
1N/A if (! pTemplate) {
1N/A return (CKR_FUNCTION_FAILED);
1N/A }
1N/A rc = pthread_mutex_lock(&obj_list_mutex);
1N/A if (rc != CKR_OK)
1N/A return (CKR_FUNCTION_FAILED);
1N/A
1N/A rc = object_mgr_find_in_map1(sess->hContext, handle, &obj);
1N/A if (rc != CKR_OK) {
1N/A goto done;
1N/A }
1N/A priv_obj = object_is_private(obj);
1N/A
1N/A if (priv_obj == TRUE) {
1N/A if (sess->session_info.state == CKS_RO_PUBLIC_SESSION ||
1N/A sess->session_info.state == CKS_RW_PUBLIC_SESSION) {
1N/A rc = CKR_USER_NOT_LOGGED_IN;
1N/A goto done;
1N/A }
1N/A }
1N/A
1N/A rc = object_get_attribute_values(obj, pTemplate, ulCount);
1N/Adone:
1N/A (void) pthread_mutex_unlock(&obj_list_mutex);
1N/A
1N/A return (rc);
1N/A}
1N/A
1N/ACK_RV
1N/Aobject_mgr_get_object_size(
1N/A TSS_HCONTEXT hContext,
1N/A CK_OBJECT_HANDLE handle,
1N/A CK_ULONG * size)
1N/A{
1N/A OBJECT * obj;
1N/A CK_RV rc;
1N/A
1N/A rc = pthread_mutex_lock(&obj_list_mutex);
1N/A if (rc != CKR_OK)
1N/A return (CKR_FUNCTION_FAILED);
1N/A
1N/A rc = object_mgr_find_in_map1(hContext, handle, &obj);
1N/A if (rc != CKR_OK) {
1N/A rc = CKR_OBJECT_HANDLE_INVALID;
1N/A goto done;
1N/A }
1N/A
1N/A *size = object_get_size(obj);
1N/A
1N/Adone:
1N/A (void) pthread_mutex_unlock(&obj_list_mutex);
1N/A return (rc);
1N/A}
1N/A
1N/A
1N/A// object_mgr_invalidate_handle1()
1N/A//
1N/A// Returns: TRUE if successfully removes the node
1N/A// FALSE if cannot remove the node (not found, etc)
1N/A//
1N/ACK_BBOOL
1N/Aobject_mgr_invalidate_handle1(CK_OBJECT_HANDLE handle)
1N/A{
1N/A DL_NODE *node = NULL;
1N/A
1N/A if (pthread_rwlock_wrlock(&obj_list_rw_mutex)) {
1N/A return (CKR_FUNCTION_FAILED);
1N/A }
1N/A node = object_map;
1N/A
1N/A while (node) {
1N/A OBJECT_MAP *map = (OBJECT_MAP *)node->data;
1N/A
1N/A if (map->handle == handle) {
1N/A object_map = dlist_remove_node(object_map, node);
1N/A free(map);
1N/A (void) pthread_rwlock_unlock(&obj_list_rw_mutex);
1N/A return (TRUE);
1N/A }
1N/A
1N/A node = node->next;
1N/A }
1N/A (void) pthread_rwlock_unlock(&obj_list_rw_mutex);
1N/A return (FALSE);
1N/A}
1N/A
1N/A// object_mgr_invalidate_handle2()
1N/A//
1N/A// Returns: TRUE if successfully removes the node
1N/A// FALSE if cannot remove the node (not found, etc)
1N/A//
1N/ACK_BBOOL
1N/Aobject_mgr_invalidate_handle2(OBJECT *obj)
1N/A{
1N/A DL_NODE *node = NULL;
1N/A
1N/A if (! obj)
1N/A return (FALSE);
1N/A if (pthread_rwlock_wrlock(&obj_list_rw_mutex)) {
1N/A return (CKR_FUNCTION_FAILED);
1N/A }
1N/A node = object_map;
1N/A
1N/A while (node) {
1N/A OBJECT_MAP *map = (OBJECT_MAP *)node->data;
1N/A if (map->ptr == obj) {
1N/A object_map = dlist_remove_node(object_map, node);
1N/A free(map);
1N/A (void) pthread_rwlock_unlock(&obj_list_rw_mutex);
1N/A return (TRUE);
1N/A }
1N/A node = node->next;
1N/A }
1N/A (void) pthread_rwlock_unlock(&obj_list_rw_mutex);
1N/A
1N/A return (FALSE);
1N/A}
1N/A
1N/A// object_mgr_purge_session_objects()
1N/A//
1N/A// Args: SESSION *
1N/A// SESS_OBJ_TYPE: can be ALL, PRIVATE or PUBLIC
1N/A//
1N/A// Remove all session objects owned by the specified session satisfying
1N/A// the 'type' requirements
1N/A//
1N/ACK_BBOOL
1N/Aobject_mgr_purge_session_objects(SESSION * sess,
1N/A SESS_OBJ_TYPE type)
1N/A{
1N/A DL_NODE *node = NULL;
1N/A DL_NODE *next = NULL;
1N/A OBJECT *obj = NULL;
1N/A CK_BBOOL del;
1N/A CK_RV rc;
1N/A
1N/A if (!sess)
1N/A return (FALSE);
1N/A
1N/A rc = pthread_mutex_lock(&obj_list_mutex);
1N/A if (rc != CKR_OK)
1N/A return (FALSE);
1N/A
1N/A node = sess_obj_list;
1N/A
1N/A while (node) {
1N/A obj = (OBJECT *)node->data;
1N/A del = FALSE;
1N/A
1N/A if (obj->session == sess) {
1N/A if (type == PRIVATE) {
1N/A if (object_is_private(obj))
1N/A del = TRUE;
1N/A } else if (type == PUBLIC) {
1N/A if (object_is_public(obj))
1N/A del = TRUE;
1N/A } else if (type == ALL)
1N/A del = TRUE;
1N/A }
1N/A if (del == TRUE) {
1N/A
1N/A CK_OBJECT_HANDLE handle;
1N/A CK_RV rc;
1N/A
1N/A rc = object_mgr_find_in_map2(sess->hContext, obj,
1N/A &handle);
1N/A if (rc == CKR_OK) {
1N/A (void) object_mgr_invalidate_handle1(handle);
1N/A (void) object_free(obj);
1N/A }
1N/A
1N/A next = node->next;
1N/A sess_obj_list = dlist_remove_node(sess_obj_list, node);
1N/A node = next;
1N/A }
1N/A else
1N/A node = node->next;
1N/A }
1N/A
1N/A (void) pthread_mutex_unlock(&obj_list_mutex);
1N/A
1N/A return (TRUE);
1N/A}
1N/A
1N/A//
1N/A// This routine cleans up the list of token objects. in general, we don't
1N/A// need to do this but when tracing memory leaks, it's best that we free
1N/A// everything that we've allocated.
1N/A//
1N/ACK_BBOOL
1N/Aobject_mgr_purge_token_objects(TSS_HCONTEXT hContext)
1N/A{
1N/A DL_NODE *node = NULL;
1N/A DL_NODE *next = NULL;
1N/A OBJECT *obj = NULL;
1N/A CK_RV rc;
1N/A
1N/A rc = pthread_mutex_lock(&obj_list_mutex);
1N/A if (rc != CKR_OK)
1N/A return (FALSE);
1N/A
1N/A node = publ_token_obj_list;
1N/A while (publ_token_obj_list) {
1N/A CK_OBJECT_HANDLE handle;
1N/A CK_RV rc;
1N/A
1N/A obj = (OBJECT *)node->data;
1N/A
1N/A rc = object_mgr_find_in_map2(hContext, obj, &handle);
1N/A if (rc == CKR_OK) {
1N/A (void) object_mgr_invalidate_handle1(handle);
1N/A }
1N/A (void) object_free(obj);
1N/A
1N/A next = node->next;
1N/A publ_token_obj_list = dlist_remove_node(
1N/A publ_token_obj_list, node);
1N/A node = next;
1N/A }
1N/A
1N/A node = priv_token_obj_list;
1N/A
1N/A while (priv_token_obj_list) {
1N/A CK_OBJECT_HANDLE handle;
1N/A CK_RV rc;
1N/A
1N/A obj = (OBJECT *)node->data;
1N/A
1N/A rc = object_mgr_find_in_map2(hContext, obj, &handle);
1N/A if (rc == CKR_OK)
1N/A (void) object_mgr_invalidate_handle1(handle);
1N/A (void) object_free(obj);
1N/A
1N/A next = node->next;
1N/A priv_token_obj_list = dlist_remove_node(
1N/A priv_token_obj_list, node);
1N/A node = next;
1N/A }
1N/A
1N/A (void) pthread_mutex_unlock(&obj_list_mutex);
1N/A
1N/A return (TRUE);
1N/A}
1N/A
1N/ACK_BBOOL
1N/Aobject_mgr_purge_private_token_objects(TSS_HCONTEXT hContext) {
1N/A OBJECT * obj = NULL;
1N/A DL_NODE * node = NULL;
1N/A DL_NODE * next = NULL;
1N/A CK_RV rc;
1N/A
1N/A rc = pthread_mutex_lock(&obj_list_mutex);
1N/A if (rc != CKR_OK)
1N/A return (FALSE);
1N/A
1N/A node = priv_token_obj_list;
1N/A while (priv_token_obj_list) {
1N/A CK_OBJECT_HANDLE handle;
1N/A CK_RV rc;
1N/A
1N/A obj = (OBJECT *)node->data;
1N/A
1N/A rc = object_mgr_find_in_map2(hContext, obj, &handle);
1N/A if (rc == CKR_OK) {
1N/A (void) object_mgr_invalidate_handle1(handle);
1N/A }
1N/A
1N/A (void) object_free(obj);
1N/A
1N/A next = node->next;
1N/A priv_token_obj_list = dlist_remove_node(
1N/A priv_token_obj_list, node);
1N/A node = next;
1N/A }
1N/A
1N/A (void) pthread_mutex_unlock(&obj_list_mutex);
1N/A
1N/A return (TRUE);
1N/A}
1N/A
1N/ACK_RV
1N/Aobject_mgr_remove_from_map(CK_OBJECT_HANDLE handle)
1N/A{
1N/A DL_NODE *node = NULL;
1N/A
1N/A if (pthread_rwlock_wrlock(&obj_list_rw_mutex)) {
1N/A return (CKR_FUNCTION_FAILED);
1N/A }
1N/A node = object_map;
1N/A while (node) {
1N/A OBJECT_MAP *map = (OBJECT_MAP *)node->data;
1N/A if (map->handle == handle) {
1N/A object_map = dlist_remove_node(object_map, node);
1N/A free(map);
1N/A (void) pthread_rwlock_unlock(&obj_list_rw_mutex);
1N/A return (CKR_OK);
1N/A }
1N/A node = node->next;
1N/A }
1N/A (void) pthread_rwlock_unlock(&obj_list_rw_mutex);
1N/A
1N/A return (CKR_FUNCTION_FAILED);
1N/A}
1N/A
1N/ACK_RV
1N/Aobject_mgr_restore_obj(CK_BYTE *data, OBJECT *oldObj)
1N/A{
1N/A OBJECT * obj = NULL;
1N/A CK_BBOOL priv;
1N/A CK_RV rc;
1N/A
1N/A if (! data) {
1N/A return (CKR_FUNCTION_FAILED);
1N/A }
1N/A if (oldObj != NULL) {
1N/A obj = oldObj;
1N/A rc = object_restore(data, &obj, TRUE);
1N/A } else {
1N/A rc = object_restore(data, &obj, FALSE);
1N/A if (rc == CKR_OK) {
1N/A priv = object_is_private(obj);
1N/A
1N/A if (priv)
1N/A priv_token_obj_list = dlist_add_as_last(
1N/A priv_token_obj_list, obj);
1N/A else
1N/A publ_token_obj_list = dlist_add_as_last(
1N/A publ_token_obj_list, obj);
1N/A
1N/A (void) XProcLock(xproclock);
1N/A
1N/A if (priv) {
1N/A if (global_shm->priv_loaded == FALSE) {
1N/A if (global_shm->num_priv_tok_obj <
1N/A MAX_TOK_OBJS)
1N/A (void) object_mgr_add_to_shm(
1N/A obj);
1N/A else
1N/A rc = CKR_HOST_MEMORY;
1N/A }
1N/A } else {
1N/A if (global_shm->publ_loaded == FALSE) {
1N/A if (global_shm->num_publ_tok_obj <
1N/A MAX_TOK_OBJS)
1N/A (void) object_mgr_add_to_shm(
1N/A obj);
1N/A else
1N/A rc = CKR_HOST_MEMORY;
1N/A }
1N/A }
1N/A
1N/A (void) XProcUnLock(xproclock);
1N/A }
1N/A }
1N/A
1N/A // make the callers have to have the mutes
1N/A // to many grab it now.
1N/A return (rc);
1N/A}
1N/A
1N/ACK_RV
1N/Aobject_mgr_set_attribute_values(SESSION * sess,
1N/A CK_OBJECT_HANDLE handle,
1N/A CK_ATTRIBUTE * pTemplate,
1N/A CK_ULONG ulCount)
1N/A{
1N/A OBJECT * obj;
1N/A CK_BBOOL sess_obj, priv_obj;
1N/A CK_BBOOL modifiable;
1N/A CK_RV rc;
1N/A
1N/A if (! pTemplate) {
1N/A return (CKR_FUNCTION_FAILED);
1N/A }
1N/A rc = pthread_mutex_lock(&obj_list_mutex);
1N/A if (rc != CKR_OK)
1N/A return (CKR_FUNCTION_FAILED);
1N/A
1N/A rc = object_mgr_find_in_map1(sess->hContext, handle, &obj);
1N/A if (rc != CKR_OK) {
1N/A (void) pthread_mutex_unlock(&obj_list_mutex);
1N/A return (CKR_OBJECT_HANDLE_INVALID);
1N/A }
1N/A (void) pthread_mutex_unlock(&obj_list_mutex);
1N/A
1N/A modifiable = object_is_modifiable(obj);
1N/A sess_obj = object_is_session_object(obj);
1N/A priv_obj = object_is_private(obj);
1N/A
1N/A if (! modifiable) {
1N/A return (CKR_ATTRIBUTE_READ_ONLY);
1N/A }
1N/A rc = check_object_access(sess, obj);
1N/A if (rc != CKR_OK)
1N/A return (rc);
1N/A
1N/A rc = object_set_attribute_values(obj, pTemplate, ulCount);
1N/A if (rc != CKR_OK) {
1N/A return (rc);
1N/A }
1N/A if (! sess_obj) {
1N/A TOK_OBJ_ENTRY *entry = NULL;
1N/A CK_ULONG index;
1N/A
1N/A obj->count_lo++;
1N/A if (obj->count_lo == 0)
1N/A obj->count_hi++;
1N/A
1N/A rc = save_token_object(sess->hContext, obj);
1N/A if (rc != CKR_OK)
1N/A return (rc);
1N/A
1N/A rc = XProcLock(xproclock);
1N/A if (rc != CKR_OK) {
1N/A return (rc);
1N/A }
1N/A if (priv_obj) {
1N/A rc = object_mgr_search_shm_for_obj(
1N/A global_shm->priv_tok_objs,
1N/A 0, global_shm->num_priv_tok_obj - 1,
1N/A obj, &index);
1N/A
1N/A if (rc != CKR_OK) {
1N/A (void) XProcUnLock(xproclock);
1N/A return (rc);
1N/A }
1N/A
1N/A entry = &global_shm->priv_tok_objs[index];
1N/A } else {
1N/A rc = object_mgr_search_shm_for_obj(
1N/A global_shm->publ_tok_objs,
1N/A 0, global_shm->num_publ_tok_obj - 1,
1N/A obj, &index);
1N/A if (rc != CKR_OK) {
1N/A (void) XProcUnLock(xproclock);
1N/A return (rc);
1N/A }
1N/A
1N/A entry = &global_shm->publ_tok_objs[index];
1N/A }
1N/A
1N/A entry->count_lo = obj->count_lo;
1N/A entry->count_hi = obj->count_hi;
1N/A
1N/A (void) XProcUnLock(xproclock);
1N/A }
1N/A
1N/A return (rc);
1N/A}
1N/A
1N/ACK_RV
1N/Aobject_mgr_add_to_shm(OBJECT *obj)
1N/A{
1N/A TOK_OBJ_ENTRY * entry = NULL;
1N/A CK_BBOOL priv;
1N/A
1N/A priv = object_is_private(obj);
1N/A
1N/A if (priv)
1N/A entry = &global_shm->priv_tok_objs[
1N/A global_shm->num_priv_tok_obj];
1N/A else
1N/A entry = &global_shm->publ_tok_objs[
1N/A global_shm->num_publ_tok_obj];
1N/A
1N/A entry->deleted = FALSE;
1N/A entry->count_lo = 0;
1N/A entry->count_hi = 0;
1N/A (void) memcpy(entry->name, obj->name, 8);
1N/A
1N/A if (priv) {
1N/A global_shm->num_priv_tok_obj++;
1N/A } else {
1N/A global_shm->num_publ_tok_obj++;
1N/A }
1N/A
1N/A return (CKR_OK);
1N/A}
1N/A
1N/ACK_RV
1N/Aobject_mgr_del_from_shm(OBJECT *obj)
1N/A{
1N/A CK_ULONG index, count;
1N/A CK_BBOOL priv;
1N/A CK_RV rc;
1N/A
1N/A priv = object_is_private(obj);
1N/A
1N/A if (priv) {
1N/A rc = object_mgr_search_shm_for_obj(global_shm->priv_tok_objs,
1N/A 0, global_shm->num_priv_tok_obj - 1, obj, &index);
1N/A if (rc != CKR_OK) {
1N/A return (CKR_FUNCTION_FAILED);
1N/A }
1N/A
1N/A global_shm->num_priv_tok_obj--;
1N/A if (index > global_shm->num_priv_tok_obj) {
1N/A count = index - global_shm->num_priv_tok_obj;
1N/A } else {
1N/A count = global_shm->num_priv_tok_obj - index;
1N/A }
1N/A
1N/A if (count > 0) {
1N/A (void) memcpy((char *)&global_shm->priv_tok_objs[index],
1N/A (char *)&global_shm->priv_tok_objs[index + 1],
1N/A sizeof (TOK_OBJ_ENTRY) * count);
1N/A
1N/A (void) memset((char *)&global_shm->priv_tok_objs[
1N/A global_shm->num_priv_tok_obj + 1], 0,
1N/A sizeof (TOK_OBJ_ENTRY));
1N/A } else {
1N/A (void) memset((char *)&global_shm->priv_tok_objs[
1N/A global_shm->num_priv_tok_obj], 0,
1N/A sizeof (TOK_OBJ_ENTRY));
1N/A }
1N/A } else {
1N/A rc = object_mgr_search_shm_for_obj(global_shm->publ_tok_objs,
1N/A 0, global_shm->num_publ_tok_obj - 1, obj, &index);
1N/A if (rc != CKR_OK) {
1N/A return (CKR_FUNCTION_FAILED);
1N/A }
1N/A global_shm->num_publ_tok_obj--;
1N/A
1N/A if (index > global_shm->num_publ_tok_obj) {
1N/A count = index - global_shm->num_publ_tok_obj;
1N/A } else {
1N/A count = global_shm->num_publ_tok_obj - index;
1N/A }
1N/A
1N/A if (count > 0) {
1N/A (void) memcpy((char *)&global_shm->publ_tok_objs[index],
1N/A (char *)&global_shm->publ_tok_objs[index + 1],
1N/A sizeof (TOK_OBJ_ENTRY) * count);
1N/A (void) memset((char *)&global_shm->publ_tok_objs[
1N/A global_shm->num_publ_tok_obj + 1], 0,
1N/A sizeof (TOK_OBJ_ENTRY));
1N/A } else {
1N/A (void) memset((char *)&global_shm->publ_tok_objs[
1N/A global_shm->num_publ_tok_obj], 0,
1N/A sizeof (TOK_OBJ_ENTRY));
1N/A }
1N/A }
1N/A
1N/A return (CKR_OK);
1N/A}
1N/A
1N/Astatic CK_RV
1N/Aobject_mgr_check_shm(TSS_HCONTEXT hContext, OBJECT *obj)
1N/A{
1N/A TOK_OBJ_ENTRY * entry = NULL;
1N/A CK_BBOOL priv;
1N/A CK_ULONG index;
1N/A CK_RV rc;
1N/A
1N/A
1N/A priv = object_is_private(obj);
1N/A
1N/A if (priv) {
1N/A rc = object_mgr_search_shm_for_obj(
1N/A global_shm->priv_tok_objs,
1N/A 0, global_shm->num_priv_tok_obj - 1, obj, &index);
1N/A if (rc != CKR_OK) {
1N/A return (CKR_FUNCTION_FAILED);
1N/A }
1N/A entry = &global_shm->priv_tok_objs[index];
1N/A } else {
1N/A rc = object_mgr_search_shm_for_obj(
1N/A global_shm->publ_tok_objs,
1N/A 0, global_shm->num_publ_tok_obj - 1, obj, &index);
1N/A if (rc != CKR_OK) {
1N/A return (CKR_FUNCTION_FAILED);
1N/A }
1N/A entry = &global_shm->publ_tok_objs[index];
1N/A }
1N/A
1N/A if ((obj->count_hi == entry->count_hi) &&
1N/A (obj->count_lo == entry->count_lo))
1N/A return (CKR_OK);
1N/A rc = reload_token_object(hContext, obj);
1N/A return (rc);
1N/A}
1N/A
1N/A/*ARGSUSED*/
1N/Astatic CK_RV
1N/Aobject_mgr_search_shm_for_obj(
1N/A TOK_OBJ_ENTRY *obj_list,
1N/A CK_ULONG lo,
1N/A CK_ULONG hi,
1N/A OBJECT *obj,
1N/A CK_ULONG *index)
1N/A{
1N/A CK_ULONG idx;
1N/A if (obj->index == 0) {
1N/A for (idx = lo; idx <= hi; idx++) {
1N/A if (memcmp(obj->name, obj_list[idx].name, 8) == 0) {
1N/A *index = idx;
1N/A obj->index = idx;
1N/A return (CKR_OK);
1N/A }
1N/A }
1N/A } else {
1N/A if (memcmp(obj->name, obj_list[obj->index].name, 8) == 0) {
1N/A *index = obj->index;
1N/A return (CKR_OK);
1N/A } else {
1N/A for (idx = lo; idx <= hi; idx++) {
1N/A if (memcmp(obj->name,
1N/A obj_list[idx].name, 8) == 0) {
1N/A *index = idx;
1N/A obj->index = idx;
1N/A return (CKR_OK);
1N/A }
1N/A }
1N/A }
1N/A }
1N/A return (CKR_FUNCTION_FAILED);
1N/A}
1N/A
1N/Astatic CK_RV
1N/Aobject_mgr_update_publ_tok_obj_from_shm(TSS_HCONTEXT hContext)
1N/A{
1N/A DL_NODE * node = NULL;
1N/A DL_NODE * next = NULL;
1N/A TOK_OBJ_ENTRY * te = NULL;
1N/A OBJECT * obj = NULL;
1N/A CK_OBJECT_HANDLE handle;
1N/A CK_ULONG index;
1N/A int val;
1N/A CK_RV rc;
1N/A
1N/A node = publ_token_obj_list;
1N/A index = 0;
1N/A
1N/A while ((node != NULL) && (index < global_shm->num_publ_tok_obj)) {
1N/A te = &global_shm->publ_tok_objs[index];
1N/A obj = (OBJECT *)node->data;
1N/A
1N/A val = memcmp(obj->name, te->name, 8);
1N/A
1N/A // 3 cases:
1N/A // 1) object in local list but not in the global list,
1N/A // need to remove from local list
1N/A // 2) object in both lists, need to compare counters
1N/A // and update as needed
1N/A // 3) object in global list but not in the local list,
1N/A // need to add the object here.
1N/A //
1N/A if (val < 0) {
1N/A rc = object_mgr_find_in_map2(hContext, obj, &handle);
1N/A if (rc == CKR_OK) {
1N/A (void) object_mgr_remove_from_map(handle);
1N/A }
1N/A (void) object_free(obj);
1N/A
1N/A next = node->next;
1N/A publ_token_obj_list = dlist_remove_node(
1N/A publ_token_obj_list, node);
1N/A
1N/A } else if (val == 0) {
1N/A if ((te->count_hi != obj->count_hi) ||
1N/A (te->count_lo != obj->count_lo)) {
1N/A (void) reload_token_object(hContext, obj);
1N/A obj->count_hi = te->count_hi;
1N/A obj->count_lo = te->count_lo;
1N/A }
1N/A
1N/A next = node->next;
1N/A index++;
1N/A } else {
1N/A DL_NODE *new_node = NULL;
1N/A OBJECT *new_obj = NULL;
1N/A
1N/A new_obj = (OBJECT *)malloc(sizeof (OBJECT));
1N/A (void) memset(new_obj, 0x0, sizeof (OBJECT));
1N/A
1N/A (void) memcpy(new_obj->name, te->name, 8);
1N/A (void) reload_token_object(hContext, new_obj);
1N/A
1N/A new_node = (DL_NODE *)malloc(sizeof (DL_NODE));
1N/A new_node->data = new_obj;
1N/A
1N/A new_node->next = node->next;
1N/A node->next = new_node;
1N/A new_node->prev = node;
1N/A
1N/A next = new_node->next;
1N/A index++;
1N/A }
1N/A
1N/A node = next;
1N/A }
1N/A
1N/A if ((node == NULL) && (index < global_shm->num_publ_tok_obj)) {
1N/A OBJECT *new_obj = NULL;
1N/A unsigned int i;
1N/A
1N/A for (i = index; i < global_shm->num_publ_tok_obj; i++) {
1N/A new_obj = (OBJECT *)malloc(sizeof (OBJECT));
1N/A (void) memset(new_obj, 0x0, sizeof (OBJECT));
1N/A
1N/A te = &global_shm->publ_tok_objs[index];
1N/A
1N/A (void) memcpy(new_obj->name, te->name, 8);
1N/A (void) reload_token_object(hContext, new_obj);
1N/A
1N/A publ_token_obj_list = dlist_add_as_last(
1N/A publ_token_obj_list, new_obj);
1N/A }
1N/A } else if ((node != NULL) && (index >= global_shm->num_publ_tok_obj)) {
1N/A while (node) {
1N/A obj = (OBJECT *)node->data;
1N/A
1N/A rc = object_mgr_find_in_map2(hContext, obj, &handle);
1N/A if (rc == CKR_OK) {
1N/A (void) object_mgr_remove_from_map(handle);
1N/A }
1N/A (void) object_free(obj);
1N/A
1N/A next = node->next;
1N/A publ_token_obj_list = dlist_remove_node(
1N/A publ_token_obj_list, node);
1N/A
1N/A node = next;
1N/A }
1N/A }
1N/A
1N/A return (CKR_OK);
1N/A}
1N/A
1N/Astatic CK_RV
1N/Aobject_mgr_update_priv_tok_obj_from_shm(TSS_HCONTEXT hContext)
1N/A{
1N/A DL_NODE * node = NULL;
1N/A DL_NODE * next = NULL;
1N/A TOK_OBJ_ENTRY * te = NULL;
1N/A OBJECT * obj = NULL;
1N/A CK_OBJECT_HANDLE handle;
1N/A CK_ULONG index;
1N/A int val;
1N/A CK_RV rc;
1N/A
1N/A node = priv_token_obj_list;
1N/A index = 0;
1N/A
1N/A if (! (global_login_state == CKS_RW_USER_FUNCTIONS ||
1N/A global_login_state == CKS_RO_USER_FUNCTIONS)) {
1N/A return (CKR_OK);
1N/A }
1N/A
1N/A while ((node != NULL) && (index < global_shm->num_priv_tok_obj)) {
1N/A te = &global_shm->priv_tok_objs[index];
1N/A obj = (OBJECT *)node->data;
1N/A
1N/A val = memcmp(obj->name, te->name, 8);
1N/A
1N/A if (val < 0) {
1N/A rc = object_mgr_find_in_map2(hContext, obj, &handle);
1N/A if (rc == CKR_OK) {
1N/A (void) object_mgr_remove_from_map(handle);
1N/A }
1N/A (void) object_free(obj);
1N/A
1N/A next = node->next;
1N/A priv_token_obj_list = dlist_remove_node(
1N/A priv_token_obj_list, node);
1N/A
1N/A } else if (val == 0) {
1N/A if ((te->count_hi != obj->count_hi) ||
1N/A (te->count_lo != obj->count_lo)) {
1N/A (void) reload_token_object(hContext, obj);
1N/A obj->count_hi = te->count_hi;
1N/A obj->count_lo = te->count_lo;
1N/A }
1N/A
1N/A next = node->next;
1N/A index++;
1N/A } else {
1N/A DL_NODE *new_node = NULL;
1N/A OBJECT *new_obj = NULL;
1N/A
1N/A new_obj = (OBJECT *)malloc(sizeof (OBJECT));
1N/A (void) memset(new_obj, 0x0, sizeof (OBJECT));
1N/A
1N/A (void) memcpy(new_obj->name, te->name, 8);
1N/A (void) reload_token_object(hContext, new_obj);
1N/A
1N/A new_node = (DL_NODE *)malloc(sizeof (DL_NODE));
1N/A new_node->data = new_obj;
1N/A
1N/A new_node->next = node->next;
1N/A node->next = new_node;
1N/A new_node->prev = node;
1N/A
1N/A next = new_node->next;
1N/A index++;
1N/A }
1N/A
1N/A node = next;
1N/A }
1N/A
1N/A if ((node == NULL) && (index < global_shm->num_priv_tok_obj)) {
1N/A OBJECT *new_obj = NULL;
1N/A unsigned int i;
1N/A
1N/A for (i = index; i < global_shm->num_priv_tok_obj; i++) {
1N/A new_obj = (OBJECT *)malloc(sizeof (OBJECT));
1N/A (void) memset(new_obj, 0x0, sizeof (OBJECT));
1N/A
1N/A te = &global_shm->priv_tok_objs[index];
1N/A
1N/A (void) memcpy(new_obj->name, te->name, 8);
1N/A (void) reload_token_object(hContext, new_obj);
1N/A
1N/A priv_token_obj_list = dlist_add_as_last(
1N/A priv_token_obj_list, new_obj);
1N/A }
1N/A } else if ((node != NULL) && (index >= global_shm->num_priv_tok_obj)) {
1N/A while (node) {
1N/A obj = (OBJECT *)node->data;
1N/A
1N/A rc = object_mgr_find_in_map2(hContext, obj, &handle);
1N/A if (rc == CKR_OK) {
1N/A (void) object_mgr_remove_from_map(handle);
1N/A }
1N/A (void) object_free(obj);
1N/A
1N/A next = node->next;
1N/A priv_token_obj_list = dlist_remove_node(
1N/A priv_token_obj_list, node);
1N/A
1N/A node = next;
1N/A }
1N/A }
1N/A
1N/A return (CKR_OK);
1N/A}
1N/A
1N/Astatic CK_RV
1N/Aobject_mgr_update_from_shm(TSS_HCONTEXT hContext)
1N/A{
1N/A (void) object_mgr_update_publ_tok_obj_from_shm(hContext);
1N/A (void) object_mgr_update_priv_tok_obj_from_shm(hContext);
1N/A
1N/A return (CKR_OK);
1N/A}
1N/A
1N/A/*ARGSUSED*/
1N/ACK_BBOOL
1N/Aobject_mgr_purge_map(
1N/A SESSION *sess,
1N/A SESS_OBJ_TYPE type)
1N/A{
1N/A DL_NODE *node = NULL;
1N/A DL_NODE *next = NULL;
1N/A
1N/A if (pthread_rwlock_wrlock(&obj_list_rw_mutex)) {
1N/A return (CKR_FUNCTION_FAILED);
1N/A }
1N/A node = object_map;
1N/A while (node) {
1N/A OBJECT_MAP *map = (OBJECT_MAP *)node->data;
1N/A OBJECT *obj = (OBJECT *)map->ptr;
1N/A next = node->next;
1N/A if (type == PRIVATE) {
1N/A if (object_is_private(obj)) {
1N/A object_map = dlist_remove_node(
1N/A object_map, node);
1N/A free(map);
1N/A }
1N/A }
1N/A if (type == PUBLIC) {
1N/A if (object_is_public(obj)) {
1N/A object_map = dlist_remove_node(
1N/A object_map, node);
1N/A free(map);
1N/A }
1N/A }
1N/A node = next;
1N/A }
1N/A (void) pthread_rwlock_unlock(&obj_list_rw_mutex);
1N/A
1N/A return (TRUE);
1N/A}