19126SWyllys.Ingersoll@Sun.COM /*
29126SWyllys.Ingersoll@Sun.COM * Common Public License Version 0.5
39126SWyllys.Ingersoll@Sun.COM *
49126SWyllys.Ingersoll@Sun.COM * THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF
59126SWyllys.Ingersoll@Sun.COM * THIS COMMON PUBLIC LICENSE ("AGREEMENT"). ANY USE,
69126SWyllys.Ingersoll@Sun.COM * REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES
79126SWyllys.Ingersoll@Sun.COM * RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
89126SWyllys.Ingersoll@Sun.COM *
99126SWyllys.Ingersoll@Sun.COM * 1. DEFINITIONS
109126SWyllys.Ingersoll@Sun.COM *
119126SWyllys.Ingersoll@Sun.COM * "Contribution" means:
129126SWyllys.Ingersoll@Sun.COM * a) in the case of the initial Contributor, the
139126SWyllys.Ingersoll@Sun.COM * initial code and documentation distributed under
149126SWyllys.Ingersoll@Sun.COM * this Agreement, and
159126SWyllys.Ingersoll@Sun.COM *
169126SWyllys.Ingersoll@Sun.COM * b) in the case of each subsequent Contributor:
179126SWyllys.Ingersoll@Sun.COM * i) changes to the Program, and
189126SWyllys.Ingersoll@Sun.COM * ii) additions to the Program;
199126SWyllys.Ingersoll@Sun.COM *
209126SWyllys.Ingersoll@Sun.COM * where such changes and/or additions to the Program
219126SWyllys.Ingersoll@Sun.COM * originate from and are distributed by that
229126SWyllys.Ingersoll@Sun.COM * particular Contributor. A Contribution 'originates'
239126SWyllys.Ingersoll@Sun.COM * from a Contributor if it was added to the Program
249126SWyllys.Ingersoll@Sun.COM * by such Contributor itself or anyone acting on such
259126SWyllys.Ingersoll@Sun.COM * Contributor's behalf. Contributions do not include
269126SWyllys.Ingersoll@Sun.COM * additions to the Program which: (i) are separate
279126SWyllys.Ingersoll@Sun.COM * modules of software distributed in conjunction with
289126SWyllys.Ingersoll@Sun.COM * the Program under their own license agreement, and
299126SWyllys.Ingersoll@Sun.COM * (ii) are not derivative works of the Program.
309126SWyllys.Ingersoll@Sun.COM *
319126SWyllys.Ingersoll@Sun.COM *
329126SWyllys.Ingersoll@Sun.COM * "Contributor" means any person or entity that distributes
339126SWyllys.Ingersoll@Sun.COM * the Program.
349126SWyllys.Ingersoll@Sun.COM *
359126SWyllys.Ingersoll@Sun.COM * "Licensed Patents " mean patent claims licensable by a
369126SWyllys.Ingersoll@Sun.COM * Contributor which are necessarily infringed by the use or
379126SWyllys.Ingersoll@Sun.COM * sale of its Contribution alone or when combined with the
389126SWyllys.Ingersoll@Sun.COM * Program.
399126SWyllys.Ingersoll@Sun.COM *
409126SWyllys.Ingersoll@Sun.COM * "Program" means the Contributions distributed in
419126SWyllys.Ingersoll@Sun.COM * accordance with this Agreement.
429126SWyllys.Ingersoll@Sun.COM *
439126SWyllys.Ingersoll@Sun.COM * "Recipient" means anyone who receives the Program under
449126SWyllys.Ingersoll@Sun.COM * this Agreement, including all Contributors.
459126SWyllys.Ingersoll@Sun.COM *
469126SWyllys.Ingersoll@Sun.COM * 2. GRANT OF RIGHTS
479126SWyllys.Ingersoll@Sun.COM *
489126SWyllys.Ingersoll@Sun.COM * a) Subject to the terms of this Agreement, each
499126SWyllys.Ingersoll@Sun.COM * Contributor hereby grants Recipient a
509126SWyllys.Ingersoll@Sun.COM * no - exclusive, worldwide, royalt - free copyright
519126SWyllys.Ingersoll@Sun.COM * license to reproduce, prepare derivative works of,
529126SWyllys.Ingersoll@Sun.COM * publicly display, publicly perform, distribute and
539126SWyllys.Ingersoll@Sun.COM * sublicense the Contribution of such Contributor, if
549126SWyllys.Ingersoll@Sun.COM * any, and such derivative works, in source code and
559126SWyllys.Ingersoll@Sun.COM * object code form.
569126SWyllys.Ingersoll@Sun.COM *
579126SWyllys.Ingersoll@Sun.COM * b) Subject to the terms of this Agreement, each
589126SWyllys.Ingersoll@Sun.COM * Contributor hereby grants Recipient a
599126SWyllys.Ingersoll@Sun.COM * no - exclusive, worldwide, royalt - free patent
609126SWyllys.Ingersoll@Sun.COM * license under Licensed Patents to make, use, sell,
619126SWyllys.Ingersoll@Sun.COM * offer to sell, import and otherwise transfer the
629126SWyllys.Ingersoll@Sun.COM * Contribution of such Contributor, if any, in source
639126SWyllys.Ingersoll@Sun.COM * code and object code form. This patent license
649126SWyllys.Ingersoll@Sun.COM * shall apply to the combination of the Contribution
659126SWyllys.Ingersoll@Sun.COM * and the Program if, at the time the Contribution is
669126SWyllys.Ingersoll@Sun.COM * added by the Contributor, such addition of the
679126SWyllys.Ingersoll@Sun.COM * Contribution causes such combination to be covered
689126SWyllys.Ingersoll@Sun.COM * by the Licensed Patents. The patent license shall
699126SWyllys.Ingersoll@Sun.COM * not apply to any other combinations which include
709126SWyllys.Ingersoll@Sun.COM * the Contribution. No hardware per se is licensed
719126SWyllys.Ingersoll@Sun.COM * hereunder.
729126SWyllys.Ingersoll@Sun.COM *
739126SWyllys.Ingersoll@Sun.COM * c) Recipient understands that although each
749126SWyllys.Ingersoll@Sun.COM * Contributor grants the licenses to its
759126SWyllys.Ingersoll@Sun.COM * Contributions set forth herein, no assurances are
769126SWyllys.Ingersoll@Sun.COM * provided by any Contributor that the Program does
779126SWyllys.Ingersoll@Sun.COM * not infringe the patent or other intellectual
789126SWyllys.Ingersoll@Sun.COM * property rights of any other entity. Each
799126SWyllys.Ingersoll@Sun.COM * Contributor disclaims any liability to Recipient
809126SWyllys.Ingersoll@Sun.COM * for claims brought by any other entity based on
819126SWyllys.Ingersoll@Sun.COM * infringement of intellectual property rights or
829126SWyllys.Ingersoll@Sun.COM * otherwise. As a condition to exercising the rights
839126SWyllys.Ingersoll@Sun.COM * and licenses granted hereunder, each Recipient
849126SWyllys.Ingersoll@Sun.COM * hereby assumes sole responsibility to secure any
859126SWyllys.Ingersoll@Sun.COM * other intellectual property rights needed, if any.
869126SWyllys.Ingersoll@Sun.COM *
879126SWyllys.Ingersoll@Sun.COM * For example, if a third party patent license is
889126SWyllys.Ingersoll@Sun.COM * required to allow Recipient to distribute the
899126SWyllys.Ingersoll@Sun.COM * Program, it is Recipient's responsibility to
909126SWyllys.Ingersoll@Sun.COM * acquire that license before distributing the
919126SWyllys.Ingersoll@Sun.COM * Program.
929126SWyllys.Ingersoll@Sun.COM *
939126SWyllys.Ingersoll@Sun.COM * d) Each Contributor represents that to its
949126SWyllys.Ingersoll@Sun.COM * knowledge it has sufficient copyright rights in its
959126SWyllys.Ingersoll@Sun.COM * Contribution, if any, to grant the copyright
969126SWyllys.Ingersoll@Sun.COM * license set forth in this Agreement.
979126SWyllys.Ingersoll@Sun.COM *
989126SWyllys.Ingersoll@Sun.COM * 3. REQUIREMENTS
999126SWyllys.Ingersoll@Sun.COM *
1009126SWyllys.Ingersoll@Sun.COM * A Contributor may choose to distribute the Program in
1019126SWyllys.Ingersoll@Sun.COM * object code form under its own license agreement, provided
1029126SWyllys.Ingersoll@Sun.COM * that:
1039126SWyllys.Ingersoll@Sun.COM * a) it complies with the terms and conditions of
1049126SWyllys.Ingersoll@Sun.COM * this Agreement; and
1059126SWyllys.Ingersoll@Sun.COM *
1069126SWyllys.Ingersoll@Sun.COM * b) its license agreement:
1079126SWyllys.Ingersoll@Sun.COM * i) effectively disclaims on behalf of all
1089126SWyllys.Ingersoll@Sun.COM * Contributors all warranties and conditions, express
1099126SWyllys.Ingersoll@Sun.COM * and implied, including warranties or conditions of
1109126SWyllys.Ingersoll@Sun.COM * title and no - infringement, and implied warranties
1119126SWyllys.Ingersoll@Sun.COM * or conditions of merchantability and fitness for a
1129126SWyllys.Ingersoll@Sun.COM * particular purpose;
1139126SWyllys.Ingersoll@Sun.COM *
1149126SWyllys.Ingersoll@Sun.COM * ii) effectively excludes on behalf of all
1159126SWyllys.Ingersoll@Sun.COM * Contributors all liability for damages, including
1169126SWyllys.Ingersoll@Sun.COM * direct, indirect, special, incidental and
1179126SWyllys.Ingersoll@Sun.COM * consequential damages, such as lost profits;
1189126SWyllys.Ingersoll@Sun.COM *
1199126SWyllys.Ingersoll@Sun.COM * iii) states that any provisions which differ from
1209126SWyllys.Ingersoll@Sun.COM * this Agreement are offered by that Contributor
1219126SWyllys.Ingersoll@Sun.COM * alone and not by any other party; and
1229126SWyllys.Ingersoll@Sun.COM *
1239126SWyllys.Ingersoll@Sun.COM * iv) states that source code for the Program is
1249126SWyllys.Ingersoll@Sun.COM * available from such Contributor, and informs
1259126SWyllys.Ingersoll@Sun.COM * licensees how to obtain it in a reasonable manner
1269126SWyllys.Ingersoll@Sun.COM * on or through a medium customarily used for
1279126SWyllys.Ingersoll@Sun.COM * software exchange.
1289126SWyllys.Ingersoll@Sun.COM *
1299126SWyllys.Ingersoll@Sun.COM * When the Program is made available in source code form:
1309126SWyllys.Ingersoll@Sun.COM * a) it must be made available under this Agreement;
1319126SWyllys.Ingersoll@Sun.COM * and
1329126SWyllys.Ingersoll@Sun.COM * b) a copy of this Agreement must be included with
1339126SWyllys.Ingersoll@Sun.COM * each copy of the Program.
1349126SWyllys.Ingersoll@Sun.COM *
1359126SWyllys.Ingersoll@Sun.COM * Contributors may not remove or alter any copyright notices
1369126SWyllys.Ingersoll@Sun.COM * contained within the Program.
1379126SWyllys.Ingersoll@Sun.COM *
1389126SWyllys.Ingersoll@Sun.COM * Each Contributor must identify itself as the originator of
1399126SWyllys.Ingersoll@Sun.COM * its Contribution, if any, in a manner that reasonably
1409126SWyllys.Ingersoll@Sun.COM * allows subsequent Recipients to identify the originator of
1419126SWyllys.Ingersoll@Sun.COM * the Contribution.
1429126SWyllys.Ingersoll@Sun.COM *
1439126SWyllys.Ingersoll@Sun.COM *
1449126SWyllys.Ingersoll@Sun.COM * 4. COMMERCIAL DISTRIBUTION
1459126SWyllys.Ingersoll@Sun.COM *
1469126SWyllys.Ingersoll@Sun.COM * Commercial distributors of software may accept certain
1479126SWyllys.Ingersoll@Sun.COM * responsibilities with respect to end users, business
1489126SWyllys.Ingersoll@Sun.COM * partners and the like. While this license is intended to
1499126SWyllys.Ingersoll@Sun.COM * facilitate the commercial use of the Program, the
1509126SWyllys.Ingersoll@Sun.COM * Contributor who includes the Program in a commercial
1519126SWyllys.Ingersoll@Sun.COM * product offering should do so in a manner which does not
1529126SWyllys.Ingersoll@Sun.COM * create potential liability for other Contributors.
1539126SWyllys.Ingersoll@Sun.COM * Therefore, if a Contributor includes the Program in a
1549126SWyllys.Ingersoll@Sun.COM * commercial product offering, such Contributor ("Commercial
1559126SWyllys.Ingersoll@Sun.COM * Contributor") hereby agrees to defend and indemnify every
1569126SWyllys.Ingersoll@Sun.COM * other Contributor ("Indemnified Contributor") against any
1579126SWyllys.Ingersoll@Sun.COM * losses, damages and costs (collectively "Losses") arising
1589126SWyllys.Ingersoll@Sun.COM * from claims, lawsuits and other legal actions brought by a
1599126SWyllys.Ingersoll@Sun.COM * third party against the Indemnified Contributor to the
1609126SWyllys.Ingersoll@Sun.COM * extent caused by the acts or omissions of such Commercial
1619126SWyllys.Ingersoll@Sun.COM * Contributor in connection with its distribution of the
1629126SWyllys.Ingersoll@Sun.COM * Program in a commercial product offering. The obligations
1639126SWyllys.Ingersoll@Sun.COM * in this section do not apply to any claims or Losses
1649126SWyllys.Ingersoll@Sun.COM * relating to any actual or alleged intellectual property
1659126SWyllys.Ingersoll@Sun.COM * infringement. In order to qualify, an Indemnified
1669126SWyllys.Ingersoll@Sun.COM * Contributor must: a) promptly notify the Commercial
1679126SWyllys.Ingersoll@Sun.COM * Contributor in writing of such claim, and b) allow the
1689126SWyllys.Ingersoll@Sun.COM * Commercial Contributor to control, and cooperate with the
1699126SWyllys.Ingersoll@Sun.COM * Commercial Contributor in, the defense and any related
1709126SWyllys.Ingersoll@Sun.COM * settlement negotiations. The Indemnified Contributor may
1719126SWyllys.Ingersoll@Sun.COM * participate in any such claim at its own expense.
1729126SWyllys.Ingersoll@Sun.COM *
1739126SWyllys.Ingersoll@Sun.COM *
1749126SWyllys.Ingersoll@Sun.COM * For example, a Contributor might include the Program in a
1759126SWyllys.Ingersoll@Sun.COM * commercial product offering, Product X. That Contributor
1769126SWyllys.Ingersoll@Sun.COM * is then a Commercial Contributor. If that Commercial
1779126SWyllys.Ingersoll@Sun.COM * Contributor then makes performance claims, or offers
1789126SWyllys.Ingersoll@Sun.COM * warranties related to Product X, those performance claims
1799126SWyllys.Ingersoll@Sun.COM * and warranties are such Commercial Contributor's
1809126SWyllys.Ingersoll@Sun.COM * responsibility alone. Under this section, the Commercial
1819126SWyllys.Ingersoll@Sun.COM * Contributor would have to defend claims against the other
1829126SWyllys.Ingersoll@Sun.COM * Contributors related to those performance claims and
1839126SWyllys.Ingersoll@Sun.COM * warranties, and if a court requires any other Contributor
1849126SWyllys.Ingersoll@Sun.COM * to pay any damages as a result, the Commercial Contributor
1859126SWyllys.Ingersoll@Sun.COM * must pay those damages.
1869126SWyllys.Ingersoll@Sun.COM *
1879126SWyllys.Ingersoll@Sun.COM *
1889126SWyllys.Ingersoll@Sun.COM * 5. NO WARRANTY
1899126SWyllys.Ingersoll@Sun.COM *
1909126SWyllys.Ingersoll@Sun.COM * EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE
1919126SWyllys.Ingersoll@Sun.COM * PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT
1929126SWyllys.Ingersoll@Sun.COM * WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR
1939126SWyllys.Ingersoll@Sun.COM * IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR
1949126SWyllys.Ingersoll@Sun.COM * CONDITIONS OF TITLE, NO - INFRINGEMENT, MERCHANTABILITY OR
1959126SWyllys.Ingersoll@Sun.COM * FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely
1969126SWyllys.Ingersoll@Sun.COM * responsible for determining the appropriateness of using
1979126SWyllys.Ingersoll@Sun.COM * and distributing the Program and assumes all risks
1989126SWyllys.Ingersoll@Sun.COM * associated with its exercise of rights under this
1999126SWyllys.Ingersoll@Sun.COM * Agreement, including but not limited to the risks and
2009126SWyllys.Ingersoll@Sun.COM * costs of program errors, compliance with applicable laws,
2019126SWyllys.Ingersoll@Sun.COM * damage to or loss of data, programs or equipment, and
2029126SWyllys.Ingersoll@Sun.COM * unavailability or interruption of operations.
2039126SWyllys.Ingersoll@Sun.COM *
2049126SWyllys.Ingersoll@Sun.COM * 6. DISCLAIMER OF LIABILITY
2059126SWyllys.Ingersoll@Sun.COM * EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER
2069126SWyllys.Ingersoll@Sun.COM * RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY
2079126SWyllys.Ingersoll@Sun.COM * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
2089126SWyllys.Ingersoll@Sun.COM * OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION
2099126SWyllys.Ingersoll@Sun.COM * LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF
2109126SWyllys.Ingersoll@Sun.COM * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2119126SWyllys.Ingersoll@Sun.COM * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
2129126SWyllys.Ingersoll@Sun.COM * OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE
2139126SWyllys.Ingersoll@Sun.COM * OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE
2149126SWyllys.Ingersoll@Sun.COM * POSSIBILITY OF SUCH DAMAGES.
2159126SWyllys.Ingersoll@Sun.COM *
2169126SWyllys.Ingersoll@Sun.COM * 7. GENERAL
2179126SWyllys.Ingersoll@Sun.COM *
2189126SWyllys.Ingersoll@Sun.COM * If any provision of this Agreement is invalid or
2199126SWyllys.Ingersoll@Sun.COM * unenforceable under applicable law, it shall not affect
2209126SWyllys.Ingersoll@Sun.COM * the validity or enforceability of the remainder of the
2219126SWyllys.Ingersoll@Sun.COM * terms of this Agreement, and without further action by the
2229126SWyllys.Ingersoll@Sun.COM * parties hereto, such provision shall be reformed to the
2239126SWyllys.Ingersoll@Sun.COM * minimum extent necessary to make such provision valid and
2249126SWyllys.Ingersoll@Sun.COM * enforceable.
2259126SWyllys.Ingersoll@Sun.COM *
2269126SWyllys.Ingersoll@Sun.COM *
2279126SWyllys.Ingersoll@Sun.COM * If Recipient institutes patent litigation against a
2289126SWyllys.Ingersoll@Sun.COM * Contributor with respect to a patent applicable to
2299126SWyllys.Ingersoll@Sun.COM * software (including a cros - claim or counterclaim in a
2309126SWyllys.Ingersoll@Sun.COM * lawsuit), then any patent licenses granted by that
2319126SWyllys.Ingersoll@Sun.COM * Contributor to such Recipient under this Agreement shall
2329126SWyllys.Ingersoll@Sun.COM * terminate as of the date such litigation is filed. In
2339126SWyllys.Ingersoll@Sun.COM * addition, If Recipient institutes patent litigation
2349126SWyllys.Ingersoll@Sun.COM * against any entity (including a cros - claim or
2359126SWyllys.Ingersoll@Sun.COM * counterclaim in a lawsuit) alleging that the Program
2369126SWyllys.Ingersoll@Sun.COM * itself (excluding combinations of the Program with other
2379126SWyllys.Ingersoll@Sun.COM * software or hardware) infringes such Recipient's
2389126SWyllys.Ingersoll@Sun.COM * patent(s), then such Recipient's rights granted under
2399126SWyllys.Ingersoll@Sun.COM * Section 2(b) shall terminate as of the date such
2409126SWyllys.Ingersoll@Sun.COM * litigation is filed.
2419126SWyllys.Ingersoll@Sun.COM *
2429126SWyllys.Ingersoll@Sun.COM * All Recipient's rights under this Agreement shall
2439126SWyllys.Ingersoll@Sun.COM * terminate if it fails to comply with any of the material
2449126SWyllys.Ingersoll@Sun.COM * terms or conditions of this Agreement and does not cure
2459126SWyllys.Ingersoll@Sun.COM * such failure in a reasonable period of time after becoming
2469126SWyllys.Ingersoll@Sun.COM * aware of such noncompliance. If all Recipient's rights
2479126SWyllys.Ingersoll@Sun.COM * under this Agreement terminate, Recipient agrees to cease
2489126SWyllys.Ingersoll@Sun.COM * use and distribution of the Program as soon as reasonably
2499126SWyllys.Ingersoll@Sun.COM * practicable. However, Recipient's obligations under this
2509126SWyllys.Ingersoll@Sun.COM * Agreement and any licenses granted by Recipient relating
2519126SWyllys.Ingersoll@Sun.COM * to the Program shall continue and survive.
2529126SWyllys.Ingersoll@Sun.COM *
2539126SWyllys.Ingersoll@Sun.COM * Everyone is permitted to copy and distribute copies of
2549126SWyllys.Ingersoll@Sun.COM * this Agreement, but in order to avoid inconsistency the
2559126SWyllys.Ingersoll@Sun.COM * Agreement is copyrighted and may only be modified in the
2569126SWyllys.Ingersoll@Sun.COM * following manner. The Agreement Steward reserves the right
2579126SWyllys.Ingersoll@Sun.COM * to publish new versions (including revisions) of this
2589126SWyllys.Ingersoll@Sun.COM * Agreement from time to time. No one other than the
2599126SWyllys.Ingersoll@Sun.COM * Agreement Steward has the right to modify this Agreement.
2609126SWyllys.Ingersoll@Sun.COM *
2619126SWyllys.Ingersoll@Sun.COM * IBM is the initial Agreement Steward. IBM may assign the
2629126SWyllys.Ingersoll@Sun.COM * responsibility to serve as the Agreement Steward to a
2639126SWyllys.Ingersoll@Sun.COM * suitable separate entity. Each new version of the
2649126SWyllys.Ingersoll@Sun.COM * Agreement will be given a distinguishing version number.
2659126SWyllys.Ingersoll@Sun.COM * The Program (including Contributions) may always be
2669126SWyllys.Ingersoll@Sun.COM * distributed subject to the version of the Agreement under
2679126SWyllys.Ingersoll@Sun.COM * which it was received. In addition, after a new version of
2689126SWyllys.Ingersoll@Sun.COM * the Agreement is published, Contributor may elect to
2699126SWyllys.Ingersoll@Sun.COM * distribute the Program (including its Contributions) under
2709126SWyllys.Ingersoll@Sun.COM * the new version. Except as expressly stated in Sections
2719126SWyllys.Ingersoll@Sun.COM * 2(a) and 2(b) above, Recipient receives no rights or
2729126SWyllys.Ingersoll@Sun.COM * licenses to the intellectual property of any Contributor
2739126SWyllys.Ingersoll@Sun.COM * under this Agreement, whether expressly, by implication,
2749126SWyllys.Ingersoll@Sun.COM * estoppel or otherwise. All rights in the Program not
2759126SWyllys.Ingersoll@Sun.COM * expressly granted under this Agreement are reserved.
2769126SWyllys.Ingersoll@Sun.COM *
2779126SWyllys.Ingersoll@Sun.COM *
2789126SWyllys.Ingersoll@Sun.COM * This Agreement is governed by the laws of the State of New
2799126SWyllys.Ingersoll@Sun.COM * York and the intellectual property laws of the United
2809126SWyllys.Ingersoll@Sun.COM * States of America. No party to this Agreement will bring a
2819126SWyllys.Ingersoll@Sun.COM * legal action under this Agreement more than one year after
2829126SWyllys.Ingersoll@Sun.COM * the cause of action arose. Each party waives its rights to
2839126SWyllys.Ingersoll@Sun.COM * a jury trial in any resulting litigation.
2849126SWyllys.Ingersoll@Sun.COM *
2859126SWyllys.Ingersoll@Sun.COM *
2869126SWyllys.Ingersoll@Sun.COM *
2879126SWyllys.Ingersoll@Sun.COM * (C) COPYRIGHT International Business Machines Corp. 2001, 2002
2889126SWyllys.Ingersoll@Sun.COM */
2899126SWyllys.Ingersoll@Sun.COM /*
2909126SWyllys.Ingersoll@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
2919126SWyllys.Ingersoll@Sun.COM * Use is subject to license terms.
2929126SWyllys.Ingersoll@Sun.COM */
2939126SWyllys.Ingersoll@Sun.COM
2949126SWyllys.Ingersoll@Sun.COM #include "tpmtok_int.h"
2959126SWyllys.Ingersoll@Sun.COM
2969126SWyllys.Ingersoll@Sun.COM pthread_rwlock_t obj_list_rw_mutex = PTHREAD_RWLOCK_INITIALIZER;
2979126SWyllys.Ingersoll@Sun.COM
2989126SWyllys.Ingersoll@Sun.COM static CK_RV
2999126SWyllys.Ingersoll@Sun.COM object_mgr_search_shm_for_obj(TOK_OBJ_ENTRY *,
3009126SWyllys.Ingersoll@Sun.COM CK_ULONG, CK_ULONG, OBJECT *, CK_ULONG *);
3019126SWyllys.Ingersoll@Sun.COM static CK_RV object_mgr_update_from_shm(TSS_HCONTEXT);
3029126SWyllys.Ingersoll@Sun.COM static CK_RV object_mgr_check_shm(TSS_HCONTEXT, OBJECT *);
3039126SWyllys.Ingersoll@Sun.COM
304*9453SWyllys.Ingersoll@Sun.COM static CK_RV
check_object_access(SESSION * sess,OBJECT * o)305*9453SWyllys.Ingersoll@Sun.COM check_object_access(SESSION *sess, OBJECT *o)
3069126SWyllys.Ingersoll@Sun.COM {
307*9453SWyllys.Ingersoll@Sun.COM CK_BBOOL sess_obj, priv_obj;
308*9453SWyllys.Ingersoll@Sun.COM CK_RV rc = CKR_OK;
3099126SWyllys.Ingersoll@Sun.COM
310*9453SWyllys.Ingersoll@Sun.COM /*
311*9453SWyllys.Ingersoll@Sun.COM * check whether session has permissions to create the object, etc
312*9453SWyllys.Ingersoll@Sun.COM *
313*9453SWyllys.Ingersoll@Sun.COM * Object R/O R/W R/O R/W R/W
314*9453SWyllys.Ingersoll@Sun.COM * Type Public Public User User SO
315*9453SWyllys.Ingersoll@Sun.COM * -------------------------------------------------------------
316*9453SWyllys.Ingersoll@Sun.COM * Public session R/W R/W R/W R/W R/W
317*9453SWyllys.Ingersoll@Sun.COM * Private session R/W R/W
318*9453SWyllys.Ingersoll@Sun.COM * Public token R/O R/W R/O R/W R/W
319*9453SWyllys.Ingersoll@Sun.COM * Private token R/O R/W
320*9453SWyllys.Ingersoll@Sun.COM */
3219126SWyllys.Ingersoll@Sun.COM sess_obj = object_is_session_object(o);
3229126SWyllys.Ingersoll@Sun.COM priv_obj = object_is_private(o);
3239126SWyllys.Ingersoll@Sun.COM
3249126SWyllys.Ingersoll@Sun.COM if (sess->session_info.state == CKS_RO_PUBLIC_SESSION) {
3259126SWyllys.Ingersoll@Sun.COM if (priv_obj) {
3269126SWyllys.Ingersoll@Sun.COM rc = CKR_USER_NOT_LOGGED_IN;
3279126SWyllys.Ingersoll@Sun.COM goto done;
3289126SWyllys.Ingersoll@Sun.COM }
3299126SWyllys.Ingersoll@Sun.COM
330*9453SWyllys.Ingersoll@Sun.COM if (!sess_obj) {
3319126SWyllys.Ingersoll@Sun.COM rc = CKR_SESSION_READ_ONLY;
3329126SWyllys.Ingersoll@Sun.COM goto done;
3339126SWyllys.Ingersoll@Sun.COM }
3349126SWyllys.Ingersoll@Sun.COM }
3359126SWyllys.Ingersoll@Sun.COM
3369126SWyllys.Ingersoll@Sun.COM if (sess->session_info.state == CKS_RO_USER_FUNCTIONS) {
3379126SWyllys.Ingersoll@Sun.COM if (! sess_obj) {
3389126SWyllys.Ingersoll@Sun.COM rc = CKR_SESSION_READ_ONLY;
3399126SWyllys.Ingersoll@Sun.COM goto done;
3409126SWyllys.Ingersoll@Sun.COM }
3419126SWyllys.Ingersoll@Sun.COM }
3429126SWyllys.Ingersoll@Sun.COM
3439126SWyllys.Ingersoll@Sun.COM if (sess->session_info.state == CKS_RW_PUBLIC_SESSION) {
3449126SWyllys.Ingersoll@Sun.COM if (priv_obj) {
3459126SWyllys.Ingersoll@Sun.COM rc = CKR_USER_NOT_LOGGED_IN;
3469126SWyllys.Ingersoll@Sun.COM goto done;
3479126SWyllys.Ingersoll@Sun.COM }
3489126SWyllys.Ingersoll@Sun.COM }
3499126SWyllys.Ingersoll@Sun.COM
3509126SWyllys.Ingersoll@Sun.COM if (sess->session_info.state == CKS_RW_SO_FUNCTIONS) {
3519126SWyllys.Ingersoll@Sun.COM if (priv_obj) {
3529126SWyllys.Ingersoll@Sun.COM rc = CKR_USER_NOT_LOGGED_IN;
3539126SWyllys.Ingersoll@Sun.COM goto done;
3549126SWyllys.Ingersoll@Sun.COM }
3559126SWyllys.Ingersoll@Sun.COM }
356*9453SWyllys.Ingersoll@Sun.COM done:
357*9453SWyllys.Ingersoll@Sun.COM return (rc);
358*9453SWyllys.Ingersoll@Sun.COM }
3599126SWyllys.Ingersoll@Sun.COM
360*9453SWyllys.Ingersoll@Sun.COM CK_RV
object_mgr_add(SESSION * sess,CK_ATTRIBUTE * pTemplate,CK_ULONG ulCount,CK_OBJECT_HANDLE * handle)361*9453SWyllys.Ingersoll@Sun.COM object_mgr_add(SESSION * sess,
362*9453SWyllys.Ingersoll@Sun.COM CK_ATTRIBUTE * pTemplate,
363*9453SWyllys.Ingersoll@Sun.COM CK_ULONG ulCount,
364*9453SWyllys.Ingersoll@Sun.COM CK_OBJECT_HANDLE * handle)
365*9453SWyllys.Ingersoll@Sun.COM {
366*9453SWyllys.Ingersoll@Sun.COM OBJECT * o = NULL;
367*9453SWyllys.Ingersoll@Sun.COM CK_BBOOL priv_obj, sess_obj;
368*9453SWyllys.Ingersoll@Sun.COM CK_RV rc;
369*9453SWyllys.Ingersoll@Sun.COM
370*9453SWyllys.Ingersoll@Sun.COM if (! sess || ! pTemplate || ! handle) {
371*9453SWyllys.Ingersoll@Sun.COM return (CKR_FUNCTION_FAILED);
372*9453SWyllys.Ingersoll@Sun.COM }
373*9453SWyllys.Ingersoll@Sun.COM
374*9453SWyllys.Ingersoll@Sun.COM rc = pthread_mutex_lock(&obj_list_mutex);
375*9453SWyllys.Ingersoll@Sun.COM if (rc != CKR_OK)
376*9453SWyllys.Ingersoll@Sun.COM return (CKR_FUNCTION_FAILED);
377*9453SWyllys.Ingersoll@Sun.COM
378*9453SWyllys.Ingersoll@Sun.COM rc = object_create(pTemplate, ulCount, &o);
379*9453SWyllys.Ingersoll@Sun.COM if (rc != CKR_OK) {
380*9453SWyllys.Ingersoll@Sun.COM goto done;
381*9453SWyllys.Ingersoll@Sun.COM }
382*9453SWyllys.Ingersoll@Sun.COM rc = check_object_access(sess, o);
383*9453SWyllys.Ingersoll@Sun.COM if (rc != CKR_OK)
384*9453SWyllys.Ingersoll@Sun.COM goto done;
385*9453SWyllys.Ingersoll@Sun.COM
386*9453SWyllys.Ingersoll@Sun.COM /*
387*9453SWyllys.Ingersoll@Sun.COM * okay, object is created and the session permissions look okay.
388*9453SWyllys.Ingersoll@Sun.COM * add the object to the appropriate list and assign an object handle
389*9453SWyllys.Ingersoll@Sun.COM */
390*9453SWyllys.Ingersoll@Sun.COM sess_obj = object_is_session_object(o);
391*9453SWyllys.Ingersoll@Sun.COM priv_obj = object_is_private(o);
3929126SWyllys.Ingersoll@Sun.COM
3939126SWyllys.Ingersoll@Sun.COM if (sess_obj) {
3949126SWyllys.Ingersoll@Sun.COM o->session = sess;
3959126SWyllys.Ingersoll@Sun.COM (void) memset(o->name, 0x00, sizeof (CK_BYTE) * 8);
3969126SWyllys.Ingersoll@Sun.COM
3979126SWyllys.Ingersoll@Sun.COM sess_obj_list = dlist_add_as_first(sess_obj_list, o);
3989126SWyllys.Ingersoll@Sun.COM } else {
3999126SWyllys.Ingersoll@Sun.COM CK_BYTE current[8];
4009126SWyllys.Ingersoll@Sun.COM CK_BYTE next[8];
4019126SWyllys.Ingersoll@Sun.COM
4029126SWyllys.Ingersoll@Sun.COM rc = XProcLock(xproclock);
4039126SWyllys.Ingersoll@Sun.COM if (rc != CKR_OK) {
4049126SWyllys.Ingersoll@Sun.COM goto done;
4059126SWyllys.Ingersoll@Sun.COM } else {
4069126SWyllys.Ingersoll@Sun.COM
4079126SWyllys.Ingersoll@Sun.COM if (priv_obj) {
4089126SWyllys.Ingersoll@Sun.COM if (global_shm->num_priv_tok_obj >=
4099126SWyllys.Ingersoll@Sun.COM MAX_TOK_OBJS) {
4109126SWyllys.Ingersoll@Sun.COM rc = CKR_HOST_MEMORY;
4119126SWyllys.Ingersoll@Sun.COM (void) XProcUnLock(xproclock);
4129126SWyllys.Ingersoll@Sun.COM goto done;
4139126SWyllys.Ingersoll@Sun.COM }
4149126SWyllys.Ingersoll@Sun.COM } else {
4159126SWyllys.Ingersoll@Sun.COM if (global_shm->num_publ_tok_obj >=
4169126SWyllys.Ingersoll@Sun.COM MAX_TOK_OBJS) {
4179126SWyllys.Ingersoll@Sun.COM rc = CKR_HOST_MEMORY;
4189126SWyllys.Ingersoll@Sun.COM (void) XProcUnLock(xproclock);
4199126SWyllys.Ingersoll@Sun.COM goto done;
4209126SWyllys.Ingersoll@Sun.COM }
4219126SWyllys.Ingersoll@Sun.COM }
4229126SWyllys.Ingersoll@Sun.COM
4239126SWyllys.Ingersoll@Sun.COM (void) memcpy(current,
4249126SWyllys.Ingersoll@Sun.COM &nv_token_data->next_token_object_name, 8);
4259126SWyllys.Ingersoll@Sun.COM
4269126SWyllys.Ingersoll@Sun.COM o->session = NULL;
4279126SWyllys.Ingersoll@Sun.COM (void) memcpy(&o->name, current, 8);
4289126SWyllys.Ingersoll@Sun.COM
4299126SWyllys.Ingersoll@Sun.COM (void) compute_next_token_obj_name(current, next);
4309126SWyllys.Ingersoll@Sun.COM
4319126SWyllys.Ingersoll@Sun.COM (void) memcpy(&nv_token_data->next_token_object_name,
4329126SWyllys.Ingersoll@Sun.COM next, 8);
4339126SWyllys.Ingersoll@Sun.COM
4349126SWyllys.Ingersoll@Sun.COM rc = save_token_object(sess->hContext, o);
4359126SWyllys.Ingersoll@Sun.COM if (rc != CKR_OK) {
4369126SWyllys.Ingersoll@Sun.COM (void) XProcUnLock(xproclock);
4379126SWyllys.Ingersoll@Sun.COM goto done;
4389126SWyllys.Ingersoll@Sun.COM }
4399126SWyllys.Ingersoll@Sun.COM
4409126SWyllys.Ingersoll@Sun.COM (void) object_mgr_add_to_shm(o);
4419126SWyllys.Ingersoll@Sun.COM (void) XProcUnLock(xproclock);
4429126SWyllys.Ingersoll@Sun.COM
4439126SWyllys.Ingersoll@Sun.COM (void) save_token_data(nv_token_data);
4449126SWyllys.Ingersoll@Sun.COM }
4459126SWyllys.Ingersoll@Sun.COM
4469126SWyllys.Ingersoll@Sun.COM if (priv_obj)
4479126SWyllys.Ingersoll@Sun.COM priv_token_obj_list =
4489126SWyllys.Ingersoll@Sun.COM dlist_add_as_last(priv_token_obj_list, o);
4499126SWyllys.Ingersoll@Sun.COM else
4509126SWyllys.Ingersoll@Sun.COM publ_token_obj_list =
4519126SWyllys.Ingersoll@Sun.COM dlist_add_as_last(publ_token_obj_list, o);
4529126SWyllys.Ingersoll@Sun.COM }
4539126SWyllys.Ingersoll@Sun.COM
4549126SWyllys.Ingersoll@Sun.COM rc = object_mgr_add_to_map(sess, o, handle);
4559126SWyllys.Ingersoll@Sun.COM if (rc != CKR_OK) {
4569126SWyllys.Ingersoll@Sun.COM DL_NODE *node = NULL;
4579126SWyllys.Ingersoll@Sun.COM
4589126SWyllys.Ingersoll@Sun.COM if (sess_obj) {
4599126SWyllys.Ingersoll@Sun.COM node = dlist_find(sess_obj_list, o);
4609126SWyllys.Ingersoll@Sun.COM if (node)
4619126SWyllys.Ingersoll@Sun.COM sess_obj_list =
4629126SWyllys.Ingersoll@Sun.COM dlist_remove_node(sess_obj_list, node);
4639126SWyllys.Ingersoll@Sun.COM } else {
4649126SWyllys.Ingersoll@Sun.COM (void) delete_token_object(o);
4659126SWyllys.Ingersoll@Sun.COM
4669126SWyllys.Ingersoll@Sun.COM if (priv_obj) {
4679126SWyllys.Ingersoll@Sun.COM node = dlist_find(priv_token_obj_list, o);
4689126SWyllys.Ingersoll@Sun.COM if (node)
4699126SWyllys.Ingersoll@Sun.COM priv_token_obj_list =
4709126SWyllys.Ingersoll@Sun.COM dlist_remove_node(
4719126SWyllys.Ingersoll@Sun.COM priv_token_obj_list, node);
4729126SWyllys.Ingersoll@Sun.COM } else {
4739126SWyllys.Ingersoll@Sun.COM node = dlist_find(publ_token_obj_list, o);
4749126SWyllys.Ingersoll@Sun.COM if (node)
4759126SWyllys.Ingersoll@Sun.COM publ_token_obj_list =
4769126SWyllys.Ingersoll@Sun.COM dlist_remove_node(
4779126SWyllys.Ingersoll@Sun.COM publ_token_obj_list, node);
4789126SWyllys.Ingersoll@Sun.COM }
4799126SWyllys.Ingersoll@Sun.COM
4809126SWyllys.Ingersoll@Sun.COM rc = XProcLock(xproclock);
4819126SWyllys.Ingersoll@Sun.COM if (rc != CKR_OK) {
4829126SWyllys.Ingersoll@Sun.COM goto done;
4839126SWyllys.Ingersoll@Sun.COM }
4849126SWyllys.Ingersoll@Sun.COM (void) object_mgr_del_from_shm(o);
4859126SWyllys.Ingersoll@Sun.COM
4869126SWyllys.Ingersoll@Sun.COM (void) XProcUnLock(xproclock);
4879126SWyllys.Ingersoll@Sun.COM }
4889126SWyllys.Ingersoll@Sun.COM }
4899126SWyllys.Ingersoll@Sun.COM
4909126SWyllys.Ingersoll@Sun.COM done:
4919126SWyllys.Ingersoll@Sun.COM (void) pthread_mutex_unlock(&obj_list_mutex);
4929126SWyllys.Ingersoll@Sun.COM
4939126SWyllys.Ingersoll@Sun.COM if ((rc != CKR_OK) && (o != NULL))
4949126SWyllys.Ingersoll@Sun.COM (void) object_free(o);
4959126SWyllys.Ingersoll@Sun.COM
4969126SWyllys.Ingersoll@Sun.COM return (rc);
4979126SWyllys.Ingersoll@Sun.COM }
4989126SWyllys.Ingersoll@Sun.COM
4999126SWyllys.Ingersoll@Sun.COM CK_RV
object_mgr_add_to_map(SESSION * sess,OBJECT * obj,CK_OBJECT_HANDLE * handle)5009126SWyllys.Ingersoll@Sun.COM object_mgr_add_to_map(SESSION * sess,
5019126SWyllys.Ingersoll@Sun.COM OBJECT * obj,
5029126SWyllys.Ingersoll@Sun.COM CK_OBJECT_HANDLE * handle) {
5039126SWyllys.Ingersoll@Sun.COM OBJECT_MAP *map_node = NULL;
5049126SWyllys.Ingersoll@Sun.COM
5059126SWyllys.Ingersoll@Sun.COM if (! sess || ! obj || ! handle) {
5069126SWyllys.Ingersoll@Sun.COM return (CKR_FUNCTION_FAILED);
5079126SWyllys.Ingersoll@Sun.COM }
5089126SWyllys.Ingersoll@Sun.COM
5099126SWyllys.Ingersoll@Sun.COM map_node = (OBJECT_MAP *)malloc(sizeof (OBJECT_MAP));
5109126SWyllys.Ingersoll@Sun.COM if (! map_node) {
5119126SWyllys.Ingersoll@Sun.COM return (CKR_HOST_MEMORY);
5129126SWyllys.Ingersoll@Sun.COM }
5139126SWyllys.Ingersoll@Sun.COM map_node->handle = next_object_handle++;
5149126SWyllys.Ingersoll@Sun.COM map_node->session = sess;
5159126SWyllys.Ingersoll@Sun.COM map_node->ptr = obj;
5169126SWyllys.Ingersoll@Sun.COM
5179126SWyllys.Ingersoll@Sun.COM if (obj->session != NULL)
5189126SWyllys.Ingersoll@Sun.COM map_node->is_session_obj = TRUE;
5199126SWyllys.Ingersoll@Sun.COM else
5209126SWyllys.Ingersoll@Sun.COM map_node->is_session_obj = FALSE;
5219126SWyllys.Ingersoll@Sun.COM
5229126SWyllys.Ingersoll@Sun.COM // add the new map entry to the list
5239126SWyllys.Ingersoll@Sun.COM if (pthread_rwlock_wrlock(&obj_list_rw_mutex)) {
5249126SWyllys.Ingersoll@Sun.COM return (CKR_FUNCTION_FAILED);
5259126SWyllys.Ingersoll@Sun.COM }
5269126SWyllys.Ingersoll@Sun.COM object_map = dlist_add_as_first(object_map, map_node);
5279126SWyllys.Ingersoll@Sun.COM (void) pthread_rwlock_unlock(&obj_list_rw_mutex);
5289126SWyllys.Ingersoll@Sun.COM
5299126SWyllys.Ingersoll@Sun.COM *handle = map_node->handle;
5309126SWyllys.Ingersoll@Sun.COM return (CKR_OK);
5319126SWyllys.Ingersoll@Sun.COM }
5329126SWyllys.Ingersoll@Sun.COM
5339126SWyllys.Ingersoll@Sun.COM // object_mgr_copy()
5349126SWyllys.Ingersoll@Sun.COM //
5359126SWyllys.Ingersoll@Sun.COM // algorithm:
5369126SWyllys.Ingersoll@Sun.COM // 1) find the old object
5379126SWyllys.Ingersoll@Sun.COM // 2) get the template from the old object
5389126SWyllys.Ingersoll@Sun.COM // 3) merge in the new object's template
5399126SWyllys.Ingersoll@Sun.COM // 4) perform class - specific sanity checks
5409126SWyllys.Ingersoll@Sun.COM //
5419126SWyllys.Ingersoll@Sun.COM CK_RV
object_mgr_copy(SESSION * sess,CK_ATTRIBUTE * pTemplate,CK_ULONG ulCount,CK_OBJECT_HANDLE old_handle,CK_OBJECT_HANDLE * new_handle)5429126SWyllys.Ingersoll@Sun.COM object_mgr_copy(SESSION * sess,
5439126SWyllys.Ingersoll@Sun.COM CK_ATTRIBUTE * pTemplate,
5449126SWyllys.Ingersoll@Sun.COM CK_ULONG ulCount,
5459126SWyllys.Ingersoll@Sun.COM CK_OBJECT_HANDLE old_handle,
5469126SWyllys.Ingersoll@Sun.COM CK_OBJECT_HANDLE * new_handle)
5479126SWyllys.Ingersoll@Sun.COM {
5489126SWyllys.Ingersoll@Sun.COM OBJECT *old_obj = NULL;
5499126SWyllys.Ingersoll@Sun.COM OBJECT *new_obj = NULL;
5509126SWyllys.Ingersoll@Sun.COM CK_BBOOL priv_obj;
5519126SWyllys.Ingersoll@Sun.COM CK_BBOOL sess_obj;
5529126SWyllys.Ingersoll@Sun.COM CK_RV rc;
5539126SWyllys.Ingersoll@Sun.COM
5549126SWyllys.Ingersoll@Sun.COM if (! sess || ! pTemplate || ! new_handle) {
5559126SWyllys.Ingersoll@Sun.COM return (CKR_FUNCTION_FAILED);
5569126SWyllys.Ingersoll@Sun.COM }
5579126SWyllys.Ingersoll@Sun.COM
5589126SWyllys.Ingersoll@Sun.COM rc = pthread_mutex_lock(&obj_list_mutex);
5599126SWyllys.Ingersoll@Sun.COM if (rc != CKR_OK)
5609126SWyllys.Ingersoll@Sun.COM return (CKR_FUNCTION_FAILED);
5619126SWyllys.Ingersoll@Sun.COM
5629126SWyllys.Ingersoll@Sun.COM rc = object_mgr_find_in_map1(sess->hContext, old_handle, &old_obj);
5639126SWyllys.Ingersoll@Sun.COM if (rc != CKR_OK) {
5649126SWyllys.Ingersoll@Sun.COM goto done;
5659126SWyllys.Ingersoll@Sun.COM }
5669126SWyllys.Ingersoll@Sun.COM rc = object_copy(pTemplate, ulCount, old_obj, &new_obj);
5679126SWyllys.Ingersoll@Sun.COM if (rc != CKR_OK) {
5689126SWyllys.Ingersoll@Sun.COM goto done;
5699126SWyllys.Ingersoll@Sun.COM }
5709126SWyllys.Ingersoll@Sun.COM
571*9453SWyllys.Ingersoll@Sun.COM rc = check_object_access(sess, new_obj);
572*9453SWyllys.Ingersoll@Sun.COM if (rc != CKR_OK)
573*9453SWyllys.Ingersoll@Sun.COM goto done;
574*9453SWyllys.Ingersoll@Sun.COM
5759126SWyllys.Ingersoll@Sun.COM sess_obj = object_is_session_object(new_obj);
5769126SWyllys.Ingersoll@Sun.COM priv_obj = object_is_private(new_obj);
5779126SWyllys.Ingersoll@Sun.COM
5789126SWyllys.Ingersoll@Sun.COM if (sess_obj) {
5799126SWyllys.Ingersoll@Sun.COM new_obj->session = sess;
5809126SWyllys.Ingersoll@Sun.COM (void) memset(&new_obj->name, 0x00, sizeof (CK_BYTE) * 8);
5819126SWyllys.Ingersoll@Sun.COM
5829126SWyllys.Ingersoll@Sun.COM sess_obj_list = dlist_add_as_first(sess_obj_list, new_obj);
5839126SWyllys.Ingersoll@Sun.COM } else {
5849126SWyllys.Ingersoll@Sun.COM CK_BYTE current[8];
5859126SWyllys.Ingersoll@Sun.COM CK_BYTE next[8];
5869126SWyllys.Ingersoll@Sun.COM
5879126SWyllys.Ingersoll@Sun.COM rc = XProcLock(xproclock);
5889126SWyllys.Ingersoll@Sun.COM if (rc != CKR_OK) {
5899126SWyllys.Ingersoll@Sun.COM goto done;
5909126SWyllys.Ingersoll@Sun.COM } else {
5919126SWyllys.Ingersoll@Sun.COM if (priv_obj) {
5929126SWyllys.Ingersoll@Sun.COM if (global_shm->num_priv_tok_obj >=
5939126SWyllys.Ingersoll@Sun.COM MAX_TOK_OBJS) {
5949126SWyllys.Ingersoll@Sun.COM (void) XProcUnLock(xproclock);
5959126SWyllys.Ingersoll@Sun.COM rc = CKR_HOST_MEMORY;
5969126SWyllys.Ingersoll@Sun.COM goto done;
5979126SWyllys.Ingersoll@Sun.COM }
5989126SWyllys.Ingersoll@Sun.COM } else {
5999126SWyllys.Ingersoll@Sun.COM if (global_shm->num_publ_tok_obj >=
6009126SWyllys.Ingersoll@Sun.COM MAX_TOK_OBJS) {
6019126SWyllys.Ingersoll@Sun.COM (void) XProcUnLock(xproclock);
6029126SWyllys.Ingersoll@Sun.COM rc = CKR_HOST_MEMORY;
6039126SWyllys.Ingersoll@Sun.COM goto done;
6049126SWyllys.Ingersoll@Sun.COM }
6059126SWyllys.Ingersoll@Sun.COM }
6069126SWyllys.Ingersoll@Sun.COM (void) memcpy(current,
6079126SWyllys.Ingersoll@Sun.COM &nv_token_data->next_token_object_name, 8);
6089126SWyllys.Ingersoll@Sun.COM
6099126SWyllys.Ingersoll@Sun.COM new_obj->session = NULL;
6109126SWyllys.Ingersoll@Sun.COM (void) memcpy(&new_obj->name, current, 8);
6119126SWyllys.Ingersoll@Sun.COM
6129126SWyllys.Ingersoll@Sun.COM (void) compute_next_token_obj_name(current, next);
6139126SWyllys.Ingersoll@Sun.COM (void) memcpy(&nv_token_data->next_token_object_name,
6149126SWyllys.Ingersoll@Sun.COM next, 8);
6159126SWyllys.Ingersoll@Sun.COM
6169126SWyllys.Ingersoll@Sun.COM rc = save_token_object(sess->hContext, new_obj);
6179126SWyllys.Ingersoll@Sun.COM if (rc != CKR_OK) {
6189126SWyllys.Ingersoll@Sun.COM (void) XProcUnLock(xproclock);
6199126SWyllys.Ingersoll@Sun.COM goto done;
6209126SWyllys.Ingersoll@Sun.COM }
6219126SWyllys.Ingersoll@Sun.COM
6229126SWyllys.Ingersoll@Sun.COM (void) object_mgr_add_to_shm(new_obj);
6239126SWyllys.Ingersoll@Sun.COM
6249126SWyllys.Ingersoll@Sun.COM (void) XProcUnLock(xproclock);
6259126SWyllys.Ingersoll@Sun.COM
6269126SWyllys.Ingersoll@Sun.COM (void) save_token_data(nv_token_data);
6279126SWyllys.Ingersoll@Sun.COM }
6289126SWyllys.Ingersoll@Sun.COM
6299126SWyllys.Ingersoll@Sun.COM if (priv_obj)
6309126SWyllys.Ingersoll@Sun.COM priv_token_obj_list = dlist_add_as_last(
6319126SWyllys.Ingersoll@Sun.COM priv_token_obj_list, new_obj);
6329126SWyllys.Ingersoll@Sun.COM else
6339126SWyllys.Ingersoll@Sun.COM publ_token_obj_list = dlist_add_as_last(
6349126SWyllys.Ingersoll@Sun.COM publ_token_obj_list, new_obj);
6359126SWyllys.Ingersoll@Sun.COM }
6369126SWyllys.Ingersoll@Sun.COM
6379126SWyllys.Ingersoll@Sun.COM rc = object_mgr_add_to_map(sess, new_obj, new_handle);
6389126SWyllys.Ingersoll@Sun.COM if (rc != CKR_OK) {
6399126SWyllys.Ingersoll@Sun.COM DL_NODE *node = NULL;
6409126SWyllys.Ingersoll@Sun.COM
6419126SWyllys.Ingersoll@Sun.COM if (sess_obj) {
6429126SWyllys.Ingersoll@Sun.COM node = dlist_find(sess_obj_list, new_obj);
6439126SWyllys.Ingersoll@Sun.COM if (node)
6449126SWyllys.Ingersoll@Sun.COM sess_obj_list = dlist_remove_node(
6459126SWyllys.Ingersoll@Sun.COM sess_obj_list, node);
6469126SWyllys.Ingersoll@Sun.COM } else {
6479126SWyllys.Ingersoll@Sun.COM (void) delete_token_object(new_obj);
6489126SWyllys.Ingersoll@Sun.COM
6499126SWyllys.Ingersoll@Sun.COM if (priv_obj) {
6509126SWyllys.Ingersoll@Sun.COM node = dlist_find(priv_token_obj_list, new_obj);
6519126SWyllys.Ingersoll@Sun.COM if (node)
6529126SWyllys.Ingersoll@Sun.COM priv_token_obj_list = dlist_remove_node(
6539126SWyllys.Ingersoll@Sun.COM priv_token_obj_list, node);
6549126SWyllys.Ingersoll@Sun.COM } else {
6559126SWyllys.Ingersoll@Sun.COM node = dlist_find(publ_token_obj_list, new_obj);
6569126SWyllys.Ingersoll@Sun.COM if (node)
6579126SWyllys.Ingersoll@Sun.COM publ_token_obj_list = dlist_remove_node(
6589126SWyllys.Ingersoll@Sun.COM publ_token_obj_list, node);
6599126SWyllys.Ingersoll@Sun.COM }
6609126SWyllys.Ingersoll@Sun.COM
6619126SWyllys.Ingersoll@Sun.COM rc = XProcLock(xproclock);
6629126SWyllys.Ingersoll@Sun.COM if (rc != CKR_OK) {
6639126SWyllys.Ingersoll@Sun.COM goto done;
6649126SWyllys.Ingersoll@Sun.COM }
6659126SWyllys.Ingersoll@Sun.COM (void) object_mgr_del_from_shm(new_obj);
6669126SWyllys.Ingersoll@Sun.COM
6679126SWyllys.Ingersoll@Sun.COM (void) XProcUnLock(xproclock);
6689126SWyllys.Ingersoll@Sun.COM }
6699126SWyllys.Ingersoll@Sun.COM }
6709126SWyllys.Ingersoll@Sun.COM
6719126SWyllys.Ingersoll@Sun.COM done:
6729126SWyllys.Ingersoll@Sun.COM (void) pthread_mutex_unlock(&obj_list_mutex);
6739126SWyllys.Ingersoll@Sun.COM
6749126SWyllys.Ingersoll@Sun.COM if ((rc != CKR_OK) && (new_obj != NULL))
6759126SWyllys.Ingersoll@Sun.COM (void) object_free(new_obj);
6769126SWyllys.Ingersoll@Sun.COM
6779126SWyllys.Ingersoll@Sun.COM return (rc);
6789126SWyllys.Ingersoll@Sun.COM }
6799126SWyllys.Ingersoll@Sun.COM
6809126SWyllys.Ingersoll@Sun.COM //
6819126SWyllys.Ingersoll@Sun.COM // determines whether the session is allowed to create an object. creates
6829126SWyllys.Ingersoll@Sun.COM // the object but doesn't add the object to any object lists or to the
6839126SWyllys.Ingersoll@Sun.COM // process' object map.
6849126SWyllys.Ingersoll@Sun.COM //
6859126SWyllys.Ingersoll@Sun.COM CK_RV
object_mgr_create_skel(SESSION * sess,CK_ATTRIBUTE * pTemplate,CK_ULONG ulCount,CK_ULONG mode,CK_ULONG obj_type,CK_ULONG sub_class,OBJECT ** obj)6869126SWyllys.Ingersoll@Sun.COM object_mgr_create_skel(SESSION * sess,
6879126SWyllys.Ingersoll@Sun.COM CK_ATTRIBUTE * pTemplate,
6889126SWyllys.Ingersoll@Sun.COM CK_ULONG ulCount,
6899126SWyllys.Ingersoll@Sun.COM CK_ULONG mode,
6909126SWyllys.Ingersoll@Sun.COM CK_ULONG obj_type,
6919126SWyllys.Ingersoll@Sun.COM CK_ULONG sub_class,
6929126SWyllys.Ingersoll@Sun.COM OBJECT ** obj)
6939126SWyllys.Ingersoll@Sun.COM {
6949126SWyllys.Ingersoll@Sun.COM OBJECT *o = NULL;
6959126SWyllys.Ingersoll@Sun.COM CK_RV rc;
6969126SWyllys.Ingersoll@Sun.COM CK_BBOOL priv_obj;
6979126SWyllys.Ingersoll@Sun.COM CK_BBOOL sess_obj;
6989126SWyllys.Ingersoll@Sun.COM
6999126SWyllys.Ingersoll@Sun.COM if (! sess || ! obj) {
7009126SWyllys.Ingersoll@Sun.COM return (CKR_FUNCTION_FAILED);
7019126SWyllys.Ingersoll@Sun.COM }
7029126SWyllys.Ingersoll@Sun.COM if (! pTemplate && (ulCount != 0)) {
7039126SWyllys.Ingersoll@Sun.COM return (CKR_FUNCTION_FAILED);
7049126SWyllys.Ingersoll@Sun.COM }
7059126SWyllys.Ingersoll@Sun.COM rc = object_create_skel(pTemplate, ulCount,
7069126SWyllys.Ingersoll@Sun.COM mode, obj_type, sub_class, &o);
7079126SWyllys.Ingersoll@Sun.COM if (rc != CKR_OK) {
7089126SWyllys.Ingersoll@Sun.COM return (rc);
7099126SWyllys.Ingersoll@Sun.COM }
7109126SWyllys.Ingersoll@Sun.COM sess_obj = object_is_session_object(o);
7119126SWyllys.Ingersoll@Sun.COM priv_obj = object_is_private(o);
7129126SWyllys.Ingersoll@Sun.COM
7139126SWyllys.Ingersoll@Sun.COM if (sess->session_info.state == CKS_RO_PUBLIC_SESSION) {
7149126SWyllys.Ingersoll@Sun.COM if (priv_obj) {
7159126SWyllys.Ingersoll@Sun.COM (void) object_free(o);
7169126SWyllys.Ingersoll@Sun.COM return (CKR_USER_NOT_LOGGED_IN);
7179126SWyllys.Ingersoll@Sun.COM }
7189126SWyllys.Ingersoll@Sun.COM
7199126SWyllys.Ingersoll@Sun.COM if (! sess_obj) {
7209126SWyllys.Ingersoll@Sun.COM (void) object_free(o);
7219126SWyllys.Ingersoll@Sun.COM return (CKR_SESSION_READ_ONLY);
7229126SWyllys.Ingersoll@Sun.COM }
7239126SWyllys.Ingersoll@Sun.COM }
7249126SWyllys.Ingersoll@Sun.COM
7259126SWyllys.Ingersoll@Sun.COM if (sess->session_info.state == CKS_RO_USER_FUNCTIONS) {
7269126SWyllys.Ingersoll@Sun.COM if (! sess_obj) {
7279126SWyllys.Ingersoll@Sun.COM (void) object_free(o);
7289126SWyllys.Ingersoll@Sun.COM return (CKR_SESSION_READ_ONLY);
7299126SWyllys.Ingersoll@Sun.COM }
7309126SWyllys.Ingersoll@Sun.COM }
7319126SWyllys.Ingersoll@Sun.COM
7329126SWyllys.Ingersoll@Sun.COM if (sess->session_info.state == CKS_RW_PUBLIC_SESSION) {
7339126SWyllys.Ingersoll@Sun.COM if (priv_obj) {
7349126SWyllys.Ingersoll@Sun.COM (void) object_free(o);
7359126SWyllys.Ingersoll@Sun.COM return (CKR_USER_NOT_LOGGED_IN);
7369126SWyllys.Ingersoll@Sun.COM }
7379126SWyllys.Ingersoll@Sun.COM }
7389126SWyllys.Ingersoll@Sun.COM
7399126SWyllys.Ingersoll@Sun.COM if (sess->session_info.state == CKS_RW_SO_FUNCTIONS) {
7409126SWyllys.Ingersoll@Sun.COM if (priv_obj) {
7419126SWyllys.Ingersoll@Sun.COM (void) object_free(o);
7429126SWyllys.Ingersoll@Sun.COM return (CKR_USER_NOT_LOGGED_IN);
7439126SWyllys.Ingersoll@Sun.COM }
7449126SWyllys.Ingersoll@Sun.COM }
7459126SWyllys.Ingersoll@Sun.COM
7469126SWyllys.Ingersoll@Sun.COM *obj = o;
7479126SWyllys.Ingersoll@Sun.COM return (CKR_OK);
7489126SWyllys.Ingersoll@Sun.COM }
7499126SWyllys.Ingersoll@Sun.COM
7509126SWyllys.Ingersoll@Sun.COM CK_RV
object_mgr_create_final(SESSION * sess,OBJECT * obj,CK_OBJECT_HANDLE * handle)7519126SWyllys.Ingersoll@Sun.COM object_mgr_create_final(SESSION * sess,
7529126SWyllys.Ingersoll@Sun.COM OBJECT * obj,
7539126SWyllys.Ingersoll@Sun.COM CK_OBJECT_HANDLE * handle)
7549126SWyllys.Ingersoll@Sun.COM {
7559126SWyllys.Ingersoll@Sun.COM CK_BBOOL sess_obj;
7569126SWyllys.Ingersoll@Sun.COM CK_BBOOL priv_obj;
7579126SWyllys.Ingersoll@Sun.COM CK_RV rc;
7589126SWyllys.Ingersoll@Sun.COM
7599126SWyllys.Ingersoll@Sun.COM if (!sess || !obj || !handle)
7609126SWyllys.Ingersoll@Sun.COM return (CKR_FUNCTION_FAILED);
7619126SWyllys.Ingersoll@Sun.COM
7629126SWyllys.Ingersoll@Sun.COM rc = pthread_mutex_lock(&obj_list_mutex);
7639126SWyllys.Ingersoll@Sun.COM if (rc != CKR_OK)
7649126SWyllys.Ingersoll@Sun.COM return (CKR_FUNCTION_FAILED);
7659126SWyllys.Ingersoll@Sun.COM
7669126SWyllys.Ingersoll@Sun.COM sess_obj = object_is_session_object(obj);
7679126SWyllys.Ingersoll@Sun.COM priv_obj = object_is_private(obj);
7689126SWyllys.Ingersoll@Sun.COM
7699126SWyllys.Ingersoll@Sun.COM if (sess_obj) {
7709126SWyllys.Ingersoll@Sun.COM obj->session = sess;
7719126SWyllys.Ingersoll@Sun.COM (void) memset(obj->name, 0x0, sizeof (CK_BYTE) * 8);
7729126SWyllys.Ingersoll@Sun.COM
7739126SWyllys.Ingersoll@Sun.COM sess_obj_list = dlist_add_as_first(sess_obj_list, obj);
7749126SWyllys.Ingersoll@Sun.COM } else {
7759126SWyllys.Ingersoll@Sun.COM CK_BYTE current[8];
7769126SWyllys.Ingersoll@Sun.COM CK_BYTE next[8];
7779126SWyllys.Ingersoll@Sun.COM
7789126SWyllys.Ingersoll@Sun.COM rc = XProcLock(xproclock);
7799126SWyllys.Ingersoll@Sun.COM if (rc != CKR_OK) {
7809126SWyllys.Ingersoll@Sun.COM goto done;
7819126SWyllys.Ingersoll@Sun.COM } else {
7829126SWyllys.Ingersoll@Sun.COM if (priv_obj) {
7839126SWyllys.Ingersoll@Sun.COM if (global_shm->num_priv_tok_obj >=
7849126SWyllys.Ingersoll@Sun.COM MAX_TOK_OBJS) {
7859126SWyllys.Ingersoll@Sun.COM (void) XProcUnLock(xproclock);
7869126SWyllys.Ingersoll@Sun.COM rc = CKR_HOST_MEMORY;
7879126SWyllys.Ingersoll@Sun.COM goto done;
7889126SWyllys.Ingersoll@Sun.COM }
7899126SWyllys.Ingersoll@Sun.COM } else {
7909126SWyllys.Ingersoll@Sun.COM if (global_shm->num_publ_tok_obj >=
7919126SWyllys.Ingersoll@Sun.COM MAX_TOK_OBJS) {
7929126SWyllys.Ingersoll@Sun.COM (void) XProcUnLock(xproclock);
7939126SWyllys.Ingersoll@Sun.COM rc = CKR_HOST_MEMORY;
7949126SWyllys.Ingersoll@Sun.COM goto done;
7959126SWyllys.Ingersoll@Sun.COM }
7969126SWyllys.Ingersoll@Sun.COM }
7979126SWyllys.Ingersoll@Sun.COM (void) memcpy(current,
7989126SWyllys.Ingersoll@Sun.COM &nv_token_data->next_token_object_name, 8);
7999126SWyllys.Ingersoll@Sun.COM
8009126SWyllys.Ingersoll@Sun.COM obj->session = NULL;
8019126SWyllys.Ingersoll@Sun.COM (void) memcpy(&obj->name, current, 8);
8029126SWyllys.Ingersoll@Sun.COM
8039126SWyllys.Ingersoll@Sun.COM (void) compute_next_token_obj_name(current, next);
8049126SWyllys.Ingersoll@Sun.COM (void) memcpy(&nv_token_data->next_token_object_name,
8059126SWyllys.Ingersoll@Sun.COM next, 8);
8069126SWyllys.Ingersoll@Sun.COM
8079126SWyllys.Ingersoll@Sun.COM rc = save_token_object(sess->hContext, obj);
8089126SWyllys.Ingersoll@Sun.COM if (rc != CKR_OK) {
8099126SWyllys.Ingersoll@Sun.COM (void) XProcUnLock(xproclock);
8109126SWyllys.Ingersoll@Sun.COM goto done;
8119126SWyllys.Ingersoll@Sun.COM }
8129126SWyllys.Ingersoll@Sun.COM
8139126SWyllys.Ingersoll@Sun.COM (void) object_mgr_add_to_shm(obj);
8149126SWyllys.Ingersoll@Sun.COM
8159126SWyllys.Ingersoll@Sun.COM (void) XProcUnLock(xproclock);
8169126SWyllys.Ingersoll@Sun.COM
8179126SWyllys.Ingersoll@Sun.COM (void) save_token_data(nv_token_data);
8189126SWyllys.Ingersoll@Sun.COM }
8199126SWyllys.Ingersoll@Sun.COM
8209126SWyllys.Ingersoll@Sun.COM if (priv_obj)
8219126SWyllys.Ingersoll@Sun.COM priv_token_obj_list = dlist_add_as_last(
8229126SWyllys.Ingersoll@Sun.COM priv_token_obj_list, obj);
8239126SWyllys.Ingersoll@Sun.COM else
8249126SWyllys.Ingersoll@Sun.COM publ_token_obj_list = dlist_add_as_last(
8259126SWyllys.Ingersoll@Sun.COM publ_token_obj_list, obj);
8269126SWyllys.Ingersoll@Sun.COM }
8279126SWyllys.Ingersoll@Sun.COM
8289126SWyllys.Ingersoll@Sun.COM rc = object_mgr_add_to_map(sess, obj, handle);
8299126SWyllys.Ingersoll@Sun.COM if (rc != CKR_OK) {
8309126SWyllys.Ingersoll@Sun.COM DL_NODE *node = NULL;
8319126SWyllys.Ingersoll@Sun.COM
8329126SWyllys.Ingersoll@Sun.COM if (sess_obj) {
8339126SWyllys.Ingersoll@Sun.COM node = dlist_find(sess_obj_list, obj);
8349126SWyllys.Ingersoll@Sun.COM if (node)
8359126SWyllys.Ingersoll@Sun.COM sess_obj_list = dlist_remove_node(
8369126SWyllys.Ingersoll@Sun.COM sess_obj_list, node);
8379126SWyllys.Ingersoll@Sun.COM } else {
8389126SWyllys.Ingersoll@Sun.COM (void) delete_token_object(obj);
8399126SWyllys.Ingersoll@Sun.COM
8409126SWyllys.Ingersoll@Sun.COM if (priv_obj) {
8419126SWyllys.Ingersoll@Sun.COM node = dlist_find(priv_token_obj_list, obj);
8429126SWyllys.Ingersoll@Sun.COM if (node)
8439126SWyllys.Ingersoll@Sun.COM priv_token_obj_list = dlist_remove_node(
8449126SWyllys.Ingersoll@Sun.COM priv_token_obj_list, node);
8459126SWyllys.Ingersoll@Sun.COM } else {
8469126SWyllys.Ingersoll@Sun.COM node = dlist_find(publ_token_obj_list, obj);
8479126SWyllys.Ingersoll@Sun.COM if (node)
8489126SWyllys.Ingersoll@Sun.COM publ_token_obj_list = dlist_remove_node(
8499126SWyllys.Ingersoll@Sun.COM publ_token_obj_list, node);
8509126SWyllys.Ingersoll@Sun.COM }
8519126SWyllys.Ingersoll@Sun.COM
8529126SWyllys.Ingersoll@Sun.COM rc = XProcLock(xproclock);
8539126SWyllys.Ingersoll@Sun.COM if (rc != CKR_OK) {
8549126SWyllys.Ingersoll@Sun.COM goto done;
8559126SWyllys.Ingersoll@Sun.COM }
8569126SWyllys.Ingersoll@Sun.COM (void) object_mgr_del_from_shm(obj);
8579126SWyllys.Ingersoll@Sun.COM
8589126SWyllys.Ingersoll@Sun.COM (void) XProcUnLock(xproclock);
8599126SWyllys.Ingersoll@Sun.COM }
8609126SWyllys.Ingersoll@Sun.COM }
8619126SWyllys.Ingersoll@Sun.COM
8629126SWyllys.Ingersoll@Sun.COM done:
8639126SWyllys.Ingersoll@Sun.COM (void) pthread_mutex_unlock(&obj_list_mutex);
8649126SWyllys.Ingersoll@Sun.COM
8659126SWyllys.Ingersoll@Sun.COM return (rc);
8669126SWyllys.Ingersoll@Sun.COM }
8679126SWyllys.Ingersoll@Sun.COM
8689126SWyllys.Ingersoll@Sun.COM CK_RV
object_mgr_destroy_object(SESSION * sess,CK_OBJECT_HANDLE handle)8699126SWyllys.Ingersoll@Sun.COM object_mgr_destroy_object(SESSION * sess,
8709126SWyllys.Ingersoll@Sun.COM CK_OBJECT_HANDLE handle)
8719126SWyllys.Ingersoll@Sun.COM {
8729126SWyllys.Ingersoll@Sun.COM OBJECT * obj = NULL;
8739126SWyllys.Ingersoll@Sun.COM CK_BBOOL sess_obj;
8749126SWyllys.Ingersoll@Sun.COM CK_BBOOL priv_obj;
8759126SWyllys.Ingersoll@Sun.COM CK_RV rc;
8769126SWyllys.Ingersoll@Sun.COM
8779126SWyllys.Ingersoll@Sun.COM if (! sess)
8789126SWyllys.Ingersoll@Sun.COM return (CKR_FUNCTION_FAILED);
8799126SWyllys.Ingersoll@Sun.COM
8809126SWyllys.Ingersoll@Sun.COM rc = pthread_mutex_lock(&obj_list_mutex);
8819126SWyllys.Ingersoll@Sun.COM if (rc != CKR_OK)
8829126SWyllys.Ingersoll@Sun.COM return (CKR_FUNCTION_FAILED);
8839126SWyllys.Ingersoll@Sun.COM
8849126SWyllys.Ingersoll@Sun.COM rc = object_mgr_find_in_map1(sess->hContext, handle, &obj);
8859126SWyllys.Ingersoll@Sun.COM if (rc != CKR_OK) {
8869126SWyllys.Ingersoll@Sun.COM goto done;
8879126SWyllys.Ingersoll@Sun.COM }
888*9453SWyllys.Ingersoll@Sun.COM
889*9453SWyllys.Ingersoll@Sun.COM rc = check_object_access(sess, obj);
890*9453SWyllys.Ingersoll@Sun.COM if (rc != CKR_OK)
891*9453SWyllys.Ingersoll@Sun.COM goto done;
892*9453SWyllys.Ingersoll@Sun.COM
8939126SWyllys.Ingersoll@Sun.COM sess_obj = object_is_session_object(obj);
8949126SWyllys.Ingersoll@Sun.COM priv_obj = object_is_private(obj);
8959126SWyllys.Ingersoll@Sun.COM
8969126SWyllys.Ingersoll@Sun.COM if (sess_obj) {
8979126SWyllys.Ingersoll@Sun.COM DL_NODE *node;
8989126SWyllys.Ingersoll@Sun.COM
8999126SWyllys.Ingersoll@Sun.COM node = dlist_find(sess_obj_list, obj);
9009126SWyllys.Ingersoll@Sun.COM if (node) {
9019126SWyllys.Ingersoll@Sun.COM (void) object_mgr_remove_from_map(handle);
9029126SWyllys.Ingersoll@Sun.COM
9039126SWyllys.Ingersoll@Sun.COM (void) object_free(obj);
9049126SWyllys.Ingersoll@Sun.COM sess_obj_list = dlist_remove_node(
9059126SWyllys.Ingersoll@Sun.COM sess_obj_list, node);
9069126SWyllys.Ingersoll@Sun.COM
9079126SWyllys.Ingersoll@Sun.COM rc = CKR_OK;
9089126SWyllys.Ingersoll@Sun.COM goto done;
9099126SWyllys.Ingersoll@Sun.COM }
9109126SWyllys.Ingersoll@Sun.COM } else {
9119126SWyllys.Ingersoll@Sun.COM DL_NODE *node = NULL;
9129126SWyllys.Ingersoll@Sun.COM
9139126SWyllys.Ingersoll@Sun.COM (void) delete_token_object(obj);
9149126SWyllys.Ingersoll@Sun.COM
9159126SWyllys.Ingersoll@Sun.COM if (priv_obj)
9169126SWyllys.Ingersoll@Sun.COM node = dlist_find(priv_token_obj_list, obj);
9179126SWyllys.Ingersoll@Sun.COM else
9189126SWyllys.Ingersoll@Sun.COM node = dlist_find(publ_token_obj_list, obj);
9199126SWyllys.Ingersoll@Sun.COM
9209126SWyllys.Ingersoll@Sun.COM if (node) {
9219126SWyllys.Ingersoll@Sun.COM rc = XProcLock(xproclock);
9229126SWyllys.Ingersoll@Sun.COM if (rc != CKR_OK) {
9239126SWyllys.Ingersoll@Sun.COM goto done;
9249126SWyllys.Ingersoll@Sun.COM }
9259126SWyllys.Ingersoll@Sun.COM (void) object_mgr_del_from_shm(obj);
9269126SWyllys.Ingersoll@Sun.COM
9279126SWyllys.Ingersoll@Sun.COM (void) XProcUnLock(xproclock);
9289126SWyllys.Ingersoll@Sun.COM
9299126SWyllys.Ingersoll@Sun.COM (void) object_mgr_remove_from_map(handle);
9309126SWyllys.Ingersoll@Sun.COM
9319126SWyllys.Ingersoll@Sun.COM (void) object_free(obj);
9329126SWyllys.Ingersoll@Sun.COM
9339126SWyllys.Ingersoll@Sun.COM if (priv_obj)
9349126SWyllys.Ingersoll@Sun.COM priv_token_obj_list = dlist_remove_node(
9359126SWyllys.Ingersoll@Sun.COM priv_token_obj_list, node);
9369126SWyllys.Ingersoll@Sun.COM else
9379126SWyllys.Ingersoll@Sun.COM publ_token_obj_list = dlist_remove_node(
9389126SWyllys.Ingersoll@Sun.COM publ_token_obj_list, node);
9399126SWyllys.Ingersoll@Sun.COM
9409126SWyllys.Ingersoll@Sun.COM rc = CKR_OK;
9419126SWyllys.Ingersoll@Sun.COM goto done;
9429126SWyllys.Ingersoll@Sun.COM }
9439126SWyllys.Ingersoll@Sun.COM }
9449126SWyllys.Ingersoll@Sun.COM
9459126SWyllys.Ingersoll@Sun.COM rc = CKR_FUNCTION_FAILED;
9469126SWyllys.Ingersoll@Sun.COM done:
9479126SWyllys.Ingersoll@Sun.COM (void) pthread_mutex_unlock(&obj_list_mutex);
9489126SWyllys.Ingersoll@Sun.COM
9499126SWyllys.Ingersoll@Sun.COM return (rc);
9509126SWyllys.Ingersoll@Sun.COM }
9519126SWyllys.Ingersoll@Sun.COM
9529126SWyllys.Ingersoll@Sun.COM CK_RV
object_mgr_destroy_token_objects(TSS_HCONTEXT hContext)9539126SWyllys.Ingersoll@Sun.COM object_mgr_destroy_token_objects(TSS_HCONTEXT hContext)
9549126SWyllys.Ingersoll@Sun.COM {
9559126SWyllys.Ingersoll@Sun.COM CK_BBOOL locked2 = FALSE;
9569126SWyllys.Ingersoll@Sun.COM CK_RV rc;
9579126SWyllys.Ingersoll@Sun.COM
9589126SWyllys.Ingersoll@Sun.COM rc = pthread_mutex_lock(&obj_list_mutex);
9599126SWyllys.Ingersoll@Sun.COM if (rc != CKR_OK)
9609126SWyllys.Ingersoll@Sun.COM return (CKR_FUNCTION_FAILED);
9619126SWyllys.Ingersoll@Sun.COM
9629126SWyllys.Ingersoll@Sun.COM while (publ_token_obj_list) {
9639126SWyllys.Ingersoll@Sun.COM OBJECT *obj = (OBJECT *)publ_token_obj_list->data;
9649126SWyllys.Ingersoll@Sun.COM
9659126SWyllys.Ingersoll@Sun.COM CK_OBJECT_HANDLE handle;
9669126SWyllys.Ingersoll@Sun.COM
9679126SWyllys.Ingersoll@Sun.COM rc = object_mgr_find_in_map2(hContext, obj, &handle);
9689126SWyllys.Ingersoll@Sun.COM if (rc == CKR_OK) {
9699126SWyllys.Ingersoll@Sun.COM (void) object_mgr_remove_from_map(handle);
9709126SWyllys.Ingersoll@Sun.COM }
9719126SWyllys.Ingersoll@Sun.COM (void) delete_token_object(obj);
9729126SWyllys.Ingersoll@Sun.COM (void) object_free(obj);
9739126SWyllys.Ingersoll@Sun.COM
9749126SWyllys.Ingersoll@Sun.COM publ_token_obj_list = dlist_remove_node(
9759126SWyllys.Ingersoll@Sun.COM publ_token_obj_list, publ_token_obj_list);
9769126SWyllys.Ingersoll@Sun.COM }
9779126SWyllys.Ingersoll@Sun.COM
9789126SWyllys.Ingersoll@Sun.COM while (priv_token_obj_list) {
9799126SWyllys.Ingersoll@Sun.COM OBJECT *obj = (OBJECT *)priv_token_obj_list->data;
9809126SWyllys.Ingersoll@Sun.COM
9819126SWyllys.Ingersoll@Sun.COM CK_OBJECT_HANDLE handle;
9829126SWyllys.Ingersoll@Sun.COM
9839126SWyllys.Ingersoll@Sun.COM rc = object_mgr_find_in_map2(hContext, obj, &handle);
9849126SWyllys.Ingersoll@Sun.COM if (rc == CKR_OK) {
9859126SWyllys.Ingersoll@Sun.COM (void) object_mgr_remove_from_map(handle);
9869126SWyllys.Ingersoll@Sun.COM }
9879126SWyllys.Ingersoll@Sun.COM (void) delete_token_object(obj);
9889126SWyllys.Ingersoll@Sun.COM (void) object_free(obj);
9899126SWyllys.Ingersoll@Sun.COM
9909126SWyllys.Ingersoll@Sun.COM priv_token_obj_list = dlist_remove_node(
9919126SWyllys.Ingersoll@Sun.COM priv_token_obj_list, priv_token_obj_list);
9929126SWyllys.Ingersoll@Sun.COM }
9939126SWyllys.Ingersoll@Sun.COM
9949126SWyllys.Ingersoll@Sun.COM // now we want to purge the token object list in shared memory
9959126SWyllys.Ingersoll@Sun.COM //
9969126SWyllys.Ingersoll@Sun.COM rc = XProcLock(xproclock);
9979126SWyllys.Ingersoll@Sun.COM if (rc == CKR_OK) {
9989126SWyllys.Ingersoll@Sun.COM locked2 = TRUE;
9999126SWyllys.Ingersoll@Sun.COM
10009126SWyllys.Ingersoll@Sun.COM global_shm->num_priv_tok_obj = 0;
10019126SWyllys.Ingersoll@Sun.COM global_shm->num_publ_tok_obj = 0;
10029126SWyllys.Ingersoll@Sun.COM
10039126SWyllys.Ingersoll@Sun.COM (void) memset(&global_shm->publ_tok_objs, 0x0,
10049126SWyllys.Ingersoll@Sun.COM MAX_TOK_OBJS * sizeof (TOK_OBJ_ENTRY));
10059126SWyllys.Ingersoll@Sun.COM (void) memset(&global_shm->priv_tok_objs, 0x0,
10069126SWyllys.Ingersoll@Sun.COM MAX_TOK_OBJS * sizeof (TOK_OBJ_ENTRY));
10079126SWyllys.Ingersoll@Sun.COM }
10089126SWyllys.Ingersoll@Sun.COM
10099126SWyllys.Ingersoll@Sun.COM done:
10109126SWyllys.Ingersoll@Sun.COM (void) pthread_mutex_unlock(&obj_list_mutex);
10119126SWyllys.Ingersoll@Sun.COM
10129126SWyllys.Ingersoll@Sun.COM if (locked2 == TRUE) (void) XProcUnLock(xproclock);
10139126SWyllys.Ingersoll@Sun.COM
10149126SWyllys.Ingersoll@Sun.COM return (rc);
10159126SWyllys.Ingersoll@Sun.COM }
10169126SWyllys.Ingersoll@Sun.COM
10179126SWyllys.Ingersoll@Sun.COM //
10189126SWyllys.Ingersoll@Sun.COM // Locates the specified object in the map
10199126SWyllys.Ingersoll@Sun.COM // without going and checking for cache update
10209126SWyllys.Ingersoll@Sun.COM //
10219126SWyllys.Ingersoll@Sun.COM CK_RV
object_mgr_find_in_map_nocache(CK_OBJECT_HANDLE handle,OBJECT ** ptr)10229126SWyllys.Ingersoll@Sun.COM object_mgr_find_in_map_nocache(CK_OBJECT_HANDLE handle,
10239126SWyllys.Ingersoll@Sun.COM OBJECT ** ptr) {
10249126SWyllys.Ingersoll@Sun.COM DL_NODE * node = NULL;
10259126SWyllys.Ingersoll@Sun.COM OBJECT * obj = NULL;
10269126SWyllys.Ingersoll@Sun.COM
10279126SWyllys.Ingersoll@Sun.COM if (! ptr) {
10289126SWyllys.Ingersoll@Sun.COM return (CKR_FUNCTION_FAILED);
10299126SWyllys.Ingersoll@Sun.COM }
10309126SWyllys.Ingersoll@Sun.COM if (pthread_rwlock_rdlock(&obj_list_rw_mutex)) {
10319126SWyllys.Ingersoll@Sun.COM return (CKR_FUNCTION_FAILED);
10329126SWyllys.Ingersoll@Sun.COM }
10339126SWyllys.Ingersoll@Sun.COM node = object_map;
10349126SWyllys.Ingersoll@Sun.COM while (node) {
10359126SWyllys.Ingersoll@Sun.COM OBJECT_MAP *map = (OBJECT_MAP *)node->data;
10369126SWyllys.Ingersoll@Sun.COM
10379126SWyllys.Ingersoll@Sun.COM if (map->handle == handle) {
10389126SWyllys.Ingersoll@Sun.COM obj = map->ptr;
10399126SWyllys.Ingersoll@Sun.COM break;
10409126SWyllys.Ingersoll@Sun.COM }
10419126SWyllys.Ingersoll@Sun.COM
10429126SWyllys.Ingersoll@Sun.COM node = node->next;
10439126SWyllys.Ingersoll@Sun.COM }
10449126SWyllys.Ingersoll@Sun.COM (void) pthread_rwlock_unlock(&obj_list_rw_mutex);
10459126SWyllys.Ingersoll@Sun.COM
10469126SWyllys.Ingersoll@Sun.COM if (obj == NULL || node == NULL) {
10479126SWyllys.Ingersoll@Sun.COM return (CKR_OBJECT_HANDLE_INVALID);
10489126SWyllys.Ingersoll@Sun.COM }
10499126SWyllys.Ingersoll@Sun.COM
10509126SWyllys.Ingersoll@Sun.COM if (object_is_session_object(obj) == TRUE) {
10519126SWyllys.Ingersoll@Sun.COM *ptr = obj;
10529126SWyllys.Ingersoll@Sun.COM return (CKR_OK);
10539126SWyllys.Ingersoll@Sun.COM }
10549126SWyllys.Ingersoll@Sun.COM
10559126SWyllys.Ingersoll@Sun.COM *ptr = obj;
10569126SWyllys.Ingersoll@Sun.COM return (CKR_OK);
10579126SWyllys.Ingersoll@Sun.COM }
10589126SWyllys.Ingersoll@Sun.COM
10599126SWyllys.Ingersoll@Sun.COM CK_RV
object_mgr_find_in_map1(TSS_HCONTEXT hContext,CK_OBJECT_HANDLE handle,OBJECT ** ptr)10609126SWyllys.Ingersoll@Sun.COM object_mgr_find_in_map1(
10619126SWyllys.Ingersoll@Sun.COM TSS_HCONTEXT hContext,
10629126SWyllys.Ingersoll@Sun.COM CK_OBJECT_HANDLE handle,
10639126SWyllys.Ingersoll@Sun.COM OBJECT ** ptr)
10649126SWyllys.Ingersoll@Sun.COM {
10659126SWyllys.Ingersoll@Sun.COM DL_NODE * node = NULL;
10669126SWyllys.Ingersoll@Sun.COM OBJECT * obj = NULL;
10679126SWyllys.Ingersoll@Sun.COM
10689126SWyllys.Ingersoll@Sun.COM if (! ptr) {
10699126SWyllys.Ingersoll@Sun.COM return (CKR_FUNCTION_FAILED);
10709126SWyllys.Ingersoll@Sun.COM }
10719126SWyllys.Ingersoll@Sun.COM if (pthread_rwlock_rdlock(&obj_list_rw_mutex)) {
10729126SWyllys.Ingersoll@Sun.COM return (CKR_FUNCTION_FAILED);
10739126SWyllys.Ingersoll@Sun.COM }
10749126SWyllys.Ingersoll@Sun.COM node = object_map;
10759126SWyllys.Ingersoll@Sun.COM while (node) {
10769126SWyllys.Ingersoll@Sun.COM OBJECT_MAP *map = (OBJECT_MAP *)node->data;
10779126SWyllys.Ingersoll@Sun.COM
10789126SWyllys.Ingersoll@Sun.COM if (map->handle == handle) {
10799126SWyllys.Ingersoll@Sun.COM obj = map->ptr;
10809126SWyllys.Ingersoll@Sun.COM break;
10819126SWyllys.Ingersoll@Sun.COM }
10829126SWyllys.Ingersoll@Sun.COM
10839126SWyllys.Ingersoll@Sun.COM node = node->next;
10849126SWyllys.Ingersoll@Sun.COM }
10859126SWyllys.Ingersoll@Sun.COM (void) pthread_rwlock_unlock(&obj_list_rw_mutex);
10869126SWyllys.Ingersoll@Sun.COM
10879126SWyllys.Ingersoll@Sun.COM if (obj == NULL || node == NULL) {
10889126SWyllys.Ingersoll@Sun.COM return (CKR_OBJECT_HANDLE_INVALID);
10899126SWyllys.Ingersoll@Sun.COM }
10909126SWyllys.Ingersoll@Sun.COM
10919126SWyllys.Ingersoll@Sun.COM if (object_is_session_object(obj) == TRUE) {
10929126SWyllys.Ingersoll@Sun.COM *ptr = obj;
10939126SWyllys.Ingersoll@Sun.COM return (CKR_OK);
10949126SWyllys.Ingersoll@Sun.COM }
10959126SWyllys.Ingersoll@Sun.COM
10969126SWyllys.Ingersoll@Sun.COM (void) object_mgr_check_shm(hContext, obj);
10979126SWyllys.Ingersoll@Sun.COM
10989126SWyllys.Ingersoll@Sun.COM *ptr = obj;
10999126SWyllys.Ingersoll@Sun.COM return (CKR_OK);
11009126SWyllys.Ingersoll@Sun.COM }
11019126SWyllys.Ingersoll@Sun.COM
11029126SWyllys.Ingersoll@Sun.COM CK_RV
object_mgr_find_in_map2(TSS_HCONTEXT hContext,OBJECT * obj,CK_OBJECT_HANDLE * handle)11039126SWyllys.Ingersoll@Sun.COM object_mgr_find_in_map2(
11049126SWyllys.Ingersoll@Sun.COM TSS_HCONTEXT hContext,
11059126SWyllys.Ingersoll@Sun.COM OBJECT * obj,
11069126SWyllys.Ingersoll@Sun.COM CK_OBJECT_HANDLE * handle)
11079126SWyllys.Ingersoll@Sun.COM {
11089126SWyllys.Ingersoll@Sun.COM DL_NODE * node = NULL;
11099126SWyllys.Ingersoll@Sun.COM CK_OBJECT_HANDLE h = (CK_OBJECT_HANDLE)NULL;
11109126SWyllys.Ingersoll@Sun.COM
11119126SWyllys.Ingersoll@Sun.COM if (! obj || ! handle) {
11129126SWyllys.Ingersoll@Sun.COM return (CKR_FUNCTION_FAILED);
11139126SWyllys.Ingersoll@Sun.COM }
11149126SWyllys.Ingersoll@Sun.COM if (pthread_rwlock_rdlock(&obj_list_rw_mutex)) {
11159126SWyllys.Ingersoll@Sun.COM return (CKR_FUNCTION_FAILED);
11169126SWyllys.Ingersoll@Sun.COM }
11179126SWyllys.Ingersoll@Sun.COM node = object_map;
11189126SWyllys.Ingersoll@Sun.COM while (node) {
11199126SWyllys.Ingersoll@Sun.COM OBJECT_MAP *map = (OBJECT_MAP *)node->data;
11209126SWyllys.Ingersoll@Sun.COM
11219126SWyllys.Ingersoll@Sun.COM if (map->ptr == obj) {
11229126SWyllys.Ingersoll@Sun.COM h = map->handle;
11239126SWyllys.Ingersoll@Sun.COM break;
11249126SWyllys.Ingersoll@Sun.COM }
11259126SWyllys.Ingersoll@Sun.COM
11269126SWyllys.Ingersoll@Sun.COM node = node->next;
11279126SWyllys.Ingersoll@Sun.COM }
11289126SWyllys.Ingersoll@Sun.COM (void) pthread_rwlock_unlock(&obj_list_rw_mutex);
11299126SWyllys.Ingersoll@Sun.COM
11309126SWyllys.Ingersoll@Sun.COM if (node == NULL) {
11319126SWyllys.Ingersoll@Sun.COM return (CKR_OBJECT_HANDLE_INVALID);
11329126SWyllys.Ingersoll@Sun.COM }
11339126SWyllys.Ingersoll@Sun.COM
11349126SWyllys.Ingersoll@Sun.COM if (object_is_session_object(obj) == TRUE) {
11359126SWyllys.Ingersoll@Sun.COM *handle = h;
11369126SWyllys.Ingersoll@Sun.COM return (CKR_OK);
11379126SWyllys.Ingersoll@Sun.COM }
11389126SWyllys.Ingersoll@Sun.COM
11399126SWyllys.Ingersoll@Sun.COM (void) object_mgr_check_shm(hContext, obj);
11409126SWyllys.Ingersoll@Sun.COM
11419126SWyllys.Ingersoll@Sun.COM *handle = h;
11429126SWyllys.Ingersoll@Sun.COM return (CKR_OK);
11439126SWyllys.Ingersoll@Sun.COM }
11449126SWyllys.Ingersoll@Sun.COM
11459126SWyllys.Ingersoll@Sun.COM CK_RV
object_mgr_find_init(SESSION * sess,CK_ATTRIBUTE * pTemplate,CK_ULONG ulCount)11469126SWyllys.Ingersoll@Sun.COM object_mgr_find_init(SESSION * sess,
11479126SWyllys.Ingersoll@Sun.COM CK_ATTRIBUTE * pTemplate,
11489126SWyllys.Ingersoll@Sun.COM CK_ULONG ulCount)
11499126SWyllys.Ingersoll@Sun.COM {
11509126SWyllys.Ingersoll@Sun.COM if (! sess) {
11519126SWyllys.Ingersoll@Sun.COM return (CKR_FUNCTION_FAILED);
11529126SWyllys.Ingersoll@Sun.COM }
11539126SWyllys.Ingersoll@Sun.COM if (sess->find_active != FALSE) {
11549126SWyllys.Ingersoll@Sun.COM return (CKR_OPERATION_ACTIVE);
11559126SWyllys.Ingersoll@Sun.COM }
11569126SWyllys.Ingersoll@Sun.COM // initialize the found object list. if it doesn't exist, allocate
11579126SWyllys.Ingersoll@Sun.COM // a list big enough for 10 handles. we'll reallocate if we need more
11589126SWyllys.Ingersoll@Sun.COM //
11599126SWyllys.Ingersoll@Sun.COM if (sess->find_list != NULL) {
11609126SWyllys.Ingersoll@Sun.COM (void) memset(sess->find_list, 0x0,
11619126SWyllys.Ingersoll@Sun.COM sess->find_len * sizeof (CK_OBJECT_HANDLE));
11629126SWyllys.Ingersoll@Sun.COM } else {
11639126SWyllys.Ingersoll@Sun.COM sess->find_list = (CK_OBJECT_HANDLE *)malloc(
11649126SWyllys.Ingersoll@Sun.COM 10 * sizeof (CK_OBJECT_HANDLE));
11659126SWyllys.Ingersoll@Sun.COM if (! sess->find_list) {
11669126SWyllys.Ingersoll@Sun.COM return (CKR_HOST_MEMORY);
11679126SWyllys.Ingersoll@Sun.COM } else {
11689126SWyllys.Ingersoll@Sun.COM (void) memset(sess->find_list, 0x0,
11699126SWyllys.Ingersoll@Sun.COM 10 * sizeof (CK_OBJECT_HANDLE));
11709126SWyllys.Ingersoll@Sun.COM sess->find_len = 10;
11719126SWyllys.Ingersoll@Sun.COM }
11729126SWyllys.Ingersoll@Sun.COM }
11739126SWyllys.Ingersoll@Sun.COM
11749126SWyllys.Ingersoll@Sun.COM sess->find_count = 0;
11759126SWyllys.Ingersoll@Sun.COM sess->find_idx = 0;
11769126SWyllys.Ingersoll@Sun.COM
11779126SWyllys.Ingersoll@Sun.COM // --- need to grab the object lock here
11789126SWyllys.Ingersoll@Sun.COM if (pthread_mutex_lock(&obj_list_mutex))
11799126SWyllys.Ingersoll@Sun.COM return (CKR_FUNCTION_FAILED);
11809126SWyllys.Ingersoll@Sun.COM
11819126SWyllys.Ingersoll@Sun.COM (void) object_mgr_update_from_shm(sess->hContext);
11829126SWyllys.Ingersoll@Sun.COM
11839126SWyllys.Ingersoll@Sun.COM // which objects can be return (ed:
11849126SWyllys.Ingersoll@Sun.COM //
11859126SWyllys.Ingersoll@Sun.COM // Public Session: public session objects, public token objects
11869126SWyllys.Ingersoll@Sun.COM // User Session: all session objects, all token objects
11879126SWyllys.Ingersoll@Sun.COM // SO session: public session objects, public token objects
11889126SWyllys.Ingersoll@Sun.COM //
11899126SWyllys.Ingersoll@Sun.COM switch (sess->session_info.state) {
11909126SWyllys.Ingersoll@Sun.COM case CKS_RO_PUBLIC_SESSION:
11919126SWyllys.Ingersoll@Sun.COM case CKS_RW_PUBLIC_SESSION:
11929126SWyllys.Ingersoll@Sun.COM case CKS_RW_SO_FUNCTIONS:
11939126SWyllys.Ingersoll@Sun.COM (void) object_mgr_find_build_list(sess, pTemplate,
11949126SWyllys.Ingersoll@Sun.COM ulCount, publ_token_obj_list, TRUE);
11959126SWyllys.Ingersoll@Sun.COM (void) object_mgr_find_build_list(sess, pTemplate,
11969126SWyllys.Ingersoll@Sun.COM ulCount, sess_obj_list, TRUE);
11979126SWyllys.Ingersoll@Sun.COM break;
11989126SWyllys.Ingersoll@Sun.COM
11999126SWyllys.Ingersoll@Sun.COM case CKS_RO_USER_FUNCTIONS:
12009126SWyllys.Ingersoll@Sun.COM case CKS_RW_USER_FUNCTIONS:
12019126SWyllys.Ingersoll@Sun.COM (void) object_mgr_find_build_list(sess, pTemplate,
12029126SWyllys.Ingersoll@Sun.COM ulCount, priv_token_obj_list, FALSE);
12039126SWyllys.Ingersoll@Sun.COM (void) object_mgr_find_build_list(sess, pTemplate,
12049126SWyllys.Ingersoll@Sun.COM ulCount, publ_token_obj_list, FALSE);
12059126SWyllys.Ingersoll@Sun.COM (void) object_mgr_find_build_list(sess, pTemplate,
12069126SWyllys.Ingersoll@Sun.COM ulCount, sess_obj_list, FALSE);
12079126SWyllys.Ingersoll@Sun.COM break;
12089126SWyllys.Ingersoll@Sun.COM }
12099126SWyllys.Ingersoll@Sun.COM (void) pthread_mutex_unlock(&obj_list_mutex);
12109126SWyllys.Ingersoll@Sun.COM
12119126SWyllys.Ingersoll@Sun.COM sess->find_active = TRUE;
12129126SWyllys.Ingersoll@Sun.COM
12139126SWyllys.Ingersoll@Sun.COM return (CKR_OK);
12149126SWyllys.Ingersoll@Sun.COM }
12159126SWyllys.Ingersoll@Sun.COM
12169126SWyllys.Ingersoll@Sun.COM CK_RV
object_mgr_find_build_list(SESSION * sess,CK_ATTRIBUTE * pTemplate,CK_ULONG ulCount,DL_NODE * obj_list,CK_BBOOL public_only)12179126SWyllys.Ingersoll@Sun.COM object_mgr_find_build_list(SESSION * sess,
12189126SWyllys.Ingersoll@Sun.COM CK_ATTRIBUTE * pTemplate,
12199126SWyllys.Ingersoll@Sun.COM CK_ULONG ulCount,
12209126SWyllys.Ingersoll@Sun.COM DL_NODE * obj_list,
12219126SWyllys.Ingersoll@Sun.COM CK_BBOOL public_only)
12229126SWyllys.Ingersoll@Sun.COM {
12239126SWyllys.Ingersoll@Sun.COM OBJECT * obj = NULL;
12249126SWyllys.Ingersoll@Sun.COM DL_NODE * node = NULL;
12259126SWyllys.Ingersoll@Sun.COM CK_OBJECT_HANDLE handle;
12269126SWyllys.Ingersoll@Sun.COM CK_BBOOL is_priv;
12279126SWyllys.Ingersoll@Sun.COM CK_BBOOL match;
12289126SWyllys.Ingersoll@Sun.COM CK_BBOOL hw_feature = FALSE;
12299126SWyllys.Ingersoll@Sun.COM CK_BBOOL hidden_object = FALSE;
12309126SWyllys.Ingersoll@Sun.COM CK_RV rc;
12319126SWyllys.Ingersoll@Sun.COM CK_ATTRIBUTE * attr;
12329126SWyllys.Ingersoll@Sun.COM unsigned int i;
12339126SWyllys.Ingersoll@Sun.COM
12349126SWyllys.Ingersoll@Sun.COM if (! sess) {
12359126SWyllys.Ingersoll@Sun.COM return (CKR_FUNCTION_FAILED);
12369126SWyllys.Ingersoll@Sun.COM }
12379126SWyllys.Ingersoll@Sun.COM if (! obj_list)
12389126SWyllys.Ingersoll@Sun.COM return (CKR_OK);
12399126SWyllys.Ingersoll@Sun.COM // PKCS#11 v2.11 (pg. 79): "When searching using C_FindObjectsInit
12409126SWyllys.Ingersoll@Sun.COM // and C_FindObjects, hardware feature objects are not returned
12419126SWyllys.Ingersoll@Sun.COM // unless the CKA_CLASS attribute in the template has the value
12429126SWyllys.Ingersoll@Sun.COM // CKO_HW_FEATURE." So, we check for CKO_HW_FEATURE and if its set,
12439126SWyllys.Ingersoll@Sun.COM // we'll find these objects below. - KEY
12449126SWyllys.Ingersoll@Sun.COM for (i = 0; i < ulCount; i++) {
12459126SWyllys.Ingersoll@Sun.COM if (pTemplate[i].type == CKA_CLASS) {
12469126SWyllys.Ingersoll@Sun.COM if (*(CK_ULONG *)pTemplate[i].pValue ==
12479126SWyllys.Ingersoll@Sun.COM CKO_HW_FEATURE) {
12489126SWyllys.Ingersoll@Sun.COM hw_feature = TRUE;
12499126SWyllys.Ingersoll@Sun.COM break;
12509126SWyllys.Ingersoll@Sun.COM }
12519126SWyllys.Ingersoll@Sun.COM }
12529126SWyllys.Ingersoll@Sun.COM
12539126SWyllys.Ingersoll@Sun.COM if (pTemplate[i].type == CKA_HIDDEN) {
12549126SWyllys.Ingersoll@Sun.COM if (*(CK_BBOOL *)pTemplate[i].pValue == TRUE) {
12559126SWyllys.Ingersoll@Sun.COM hidden_object = TRUE;
12569126SWyllys.Ingersoll@Sun.COM break;
12579126SWyllys.Ingersoll@Sun.COM }
12589126SWyllys.Ingersoll@Sun.COM }
12599126SWyllys.Ingersoll@Sun.COM }
12609126SWyllys.Ingersoll@Sun.COM
12619126SWyllys.Ingersoll@Sun.COM node = obj_list;
12629126SWyllys.Ingersoll@Sun.COM while (node) {
12639126SWyllys.Ingersoll@Sun.COM match = FALSE;
12649126SWyllys.Ingersoll@Sun.COM obj = (OBJECT *)node->data;
12659126SWyllys.Ingersoll@Sun.COM is_priv = object_is_private(obj);
12669126SWyllys.Ingersoll@Sun.COM
12679126SWyllys.Ingersoll@Sun.COM
12689126SWyllys.Ingersoll@Sun.COM if ((is_priv == FALSE) || (public_only == FALSE)) {
12699126SWyllys.Ingersoll@Sun.COM if (pTemplate == NULL || ulCount == 0)
12709126SWyllys.Ingersoll@Sun.COM match = TRUE;
12719126SWyllys.Ingersoll@Sun.COM else
12729126SWyllys.Ingersoll@Sun.COM match = template_compare(pTemplate,
12739126SWyllys.Ingersoll@Sun.COM ulCount, obj->template);
12749126SWyllys.Ingersoll@Sun.COM }
12759126SWyllys.Ingersoll@Sun.COM
12769126SWyllys.Ingersoll@Sun.COM if (match) {
12779126SWyllys.Ingersoll@Sun.COM rc = object_mgr_find_in_map2(sess->hContext, obj,
12789126SWyllys.Ingersoll@Sun.COM &handle);
12799126SWyllys.Ingersoll@Sun.COM if (rc != CKR_OK) {
12809126SWyllys.Ingersoll@Sun.COM rc = object_mgr_add_to_map(sess, obj, &handle);
12819126SWyllys.Ingersoll@Sun.COM if (rc != CKR_OK) {
12829126SWyllys.Ingersoll@Sun.COM return (CKR_FUNCTION_FAILED);
12839126SWyllys.Ingersoll@Sun.COM }
12849126SWyllys.Ingersoll@Sun.COM }
12859126SWyllys.Ingersoll@Sun.COM if (rc == CKR_OK) {
12869126SWyllys.Ingersoll@Sun.COM if ((hw_feature == FALSE) &&
12879126SWyllys.Ingersoll@Sun.COM (template_attribute_find(obj->template,
12889126SWyllys.Ingersoll@Sun.COM CKA_CLASS, &attr) == TRUE)) {
12899126SWyllys.Ingersoll@Sun.COM if (*(CK_OBJECT_CLASS *)attr->pValue ==
12909126SWyllys.Ingersoll@Sun.COM CKO_HW_FEATURE)
12919126SWyllys.Ingersoll@Sun.COM goto next_loop;
12929126SWyllys.Ingersoll@Sun.COM }
12939126SWyllys.Ingersoll@Sun.COM
12949126SWyllys.Ingersoll@Sun.COM if ((hidden_object == FALSE) &&
12959126SWyllys.Ingersoll@Sun.COM (template_attribute_find(obj->template,
12969126SWyllys.Ingersoll@Sun.COM CKA_HIDDEN, &attr) == TRUE)) {
12979126SWyllys.Ingersoll@Sun.COM if (*(CK_BBOOL *)attr->pValue == TRUE)
12989126SWyllys.Ingersoll@Sun.COM goto next_loop;
12999126SWyllys.Ingersoll@Sun.COM }
13009126SWyllys.Ingersoll@Sun.COM
13019126SWyllys.Ingersoll@Sun.COM sess->find_list[ sess->find_count ] = handle;
13029126SWyllys.Ingersoll@Sun.COM sess->find_count++;
13039126SWyllys.Ingersoll@Sun.COM
13049126SWyllys.Ingersoll@Sun.COM if (sess->find_count >= sess->find_len) {
13059126SWyllys.Ingersoll@Sun.COM sess->find_len += 15;
13069126SWyllys.Ingersoll@Sun.COM sess->find_list =
13079126SWyllys.Ingersoll@Sun.COM (CK_OBJECT_HANDLE *)realloc(
13089126SWyllys.Ingersoll@Sun.COM sess->find_list, sess->find_len *
13099126SWyllys.Ingersoll@Sun.COM sizeof (CK_OBJECT_HANDLE));
13109126SWyllys.Ingersoll@Sun.COM if (! sess->find_list) {
13119126SWyllys.Ingersoll@Sun.COM return (CKR_HOST_MEMORY);
13129126SWyllys.Ingersoll@Sun.COM }
13139126SWyllys.Ingersoll@Sun.COM }
13149126SWyllys.Ingersoll@Sun.COM }
13159126SWyllys.Ingersoll@Sun.COM }
13169126SWyllys.Ingersoll@Sun.COM next_loop:
13179126SWyllys.Ingersoll@Sun.COM node = node->next;
13189126SWyllys.Ingersoll@Sun.COM }
13199126SWyllys.Ingersoll@Sun.COM
13209126SWyllys.Ingersoll@Sun.COM return (CKR_OK);
13219126SWyllys.Ingersoll@Sun.COM }
13229126SWyllys.Ingersoll@Sun.COM
13239126SWyllys.Ingersoll@Sun.COM CK_RV
object_mgr_find_final(SESSION * sess)13249126SWyllys.Ingersoll@Sun.COM object_mgr_find_final(SESSION *sess)
13259126SWyllys.Ingersoll@Sun.COM {
13269126SWyllys.Ingersoll@Sun.COM if (! sess) {
13279126SWyllys.Ingersoll@Sun.COM return (CKR_FUNCTION_FAILED);
13289126SWyllys.Ingersoll@Sun.COM }
13299126SWyllys.Ingersoll@Sun.COM if (sess->find_active == FALSE) {
13309126SWyllys.Ingersoll@Sun.COM return (CKR_OPERATION_NOT_INITIALIZED);
13319126SWyllys.Ingersoll@Sun.COM }
13329126SWyllys.Ingersoll@Sun.COM free(sess->find_list);
13339126SWyllys.Ingersoll@Sun.COM sess->find_list = NULL;
13349126SWyllys.Ingersoll@Sun.COM sess->find_count = 0;
13359126SWyllys.Ingersoll@Sun.COM sess->find_idx = 0;
13369126SWyllys.Ingersoll@Sun.COM sess->find_active = FALSE;
13379126SWyllys.Ingersoll@Sun.COM
13389126SWyllys.Ingersoll@Sun.COM return (CKR_OK);
13399126SWyllys.Ingersoll@Sun.COM }
13409126SWyllys.Ingersoll@Sun.COM
13419126SWyllys.Ingersoll@Sun.COM CK_RV
object_mgr_get_attribute_values(SESSION * sess,CK_OBJECT_HANDLE handle,CK_ATTRIBUTE * pTemplate,CK_ULONG ulCount)13429126SWyllys.Ingersoll@Sun.COM object_mgr_get_attribute_values(SESSION * sess,
13439126SWyllys.Ingersoll@Sun.COM CK_OBJECT_HANDLE handle,
13449126SWyllys.Ingersoll@Sun.COM CK_ATTRIBUTE * pTemplate,
13459126SWyllys.Ingersoll@Sun.COM CK_ULONG ulCount)
13469126SWyllys.Ingersoll@Sun.COM {
13479126SWyllys.Ingersoll@Sun.COM OBJECT * obj;
13489126SWyllys.Ingersoll@Sun.COM CK_BBOOL priv_obj;
13499126SWyllys.Ingersoll@Sun.COM CK_RV rc;
13509126SWyllys.Ingersoll@Sun.COM
13519126SWyllys.Ingersoll@Sun.COM if (! pTemplate) {
13529126SWyllys.Ingersoll@Sun.COM return (CKR_FUNCTION_FAILED);
13539126SWyllys.Ingersoll@Sun.COM }
13549126SWyllys.Ingersoll@Sun.COM rc = pthread_mutex_lock(&obj_list_mutex);
13559126SWyllys.Ingersoll@Sun.COM if (rc != CKR_OK)
13569126SWyllys.Ingersoll@Sun.COM return (CKR_FUNCTION_FAILED);
13579126SWyllys.Ingersoll@Sun.COM
13589126SWyllys.Ingersoll@Sun.COM rc = object_mgr_find_in_map1(sess->hContext, handle, &obj);
13599126SWyllys.Ingersoll@Sun.COM if (rc != CKR_OK) {
13609126SWyllys.Ingersoll@Sun.COM goto done;
13619126SWyllys.Ingersoll@Sun.COM }
13629126SWyllys.Ingersoll@Sun.COM priv_obj = object_is_private(obj);
13639126SWyllys.Ingersoll@Sun.COM
13649126SWyllys.Ingersoll@Sun.COM if (priv_obj == TRUE) {
13659126SWyllys.Ingersoll@Sun.COM if (sess->session_info.state == CKS_RO_PUBLIC_SESSION ||
13669126SWyllys.Ingersoll@Sun.COM sess->session_info.state == CKS_RW_PUBLIC_SESSION) {
13679126SWyllys.Ingersoll@Sun.COM rc = CKR_USER_NOT_LOGGED_IN;
13689126SWyllys.Ingersoll@Sun.COM goto done;
13699126SWyllys.Ingersoll@Sun.COM }
13709126SWyllys.Ingersoll@Sun.COM }
13719126SWyllys.Ingersoll@Sun.COM
13729126SWyllys.Ingersoll@Sun.COM rc = object_get_attribute_values(obj, pTemplate, ulCount);
13739126SWyllys.Ingersoll@Sun.COM done:
13749126SWyllys.Ingersoll@Sun.COM (void) pthread_mutex_unlock(&obj_list_mutex);
13759126SWyllys.Ingersoll@Sun.COM
13769126SWyllys.Ingersoll@Sun.COM return (rc);
13779126SWyllys.Ingersoll@Sun.COM }
13789126SWyllys.Ingersoll@Sun.COM
13799126SWyllys.Ingersoll@Sun.COM CK_RV
object_mgr_get_object_size(TSS_HCONTEXT hContext,CK_OBJECT_HANDLE handle,CK_ULONG * size)13809126SWyllys.Ingersoll@Sun.COM object_mgr_get_object_size(
13819126SWyllys.Ingersoll@Sun.COM TSS_HCONTEXT hContext,
13829126SWyllys.Ingersoll@Sun.COM CK_OBJECT_HANDLE handle,
13839126SWyllys.Ingersoll@Sun.COM CK_ULONG * size)
13849126SWyllys.Ingersoll@Sun.COM {
13859126SWyllys.Ingersoll@Sun.COM OBJECT * obj;
13869126SWyllys.Ingersoll@Sun.COM CK_RV rc;
13879126SWyllys.Ingersoll@Sun.COM
13889126SWyllys.Ingersoll@Sun.COM rc = pthread_mutex_lock(&obj_list_mutex);
13899126SWyllys.Ingersoll@Sun.COM if (rc != CKR_OK)
13909126SWyllys.Ingersoll@Sun.COM return (CKR_FUNCTION_FAILED);
13919126SWyllys.Ingersoll@Sun.COM
13929126SWyllys.Ingersoll@Sun.COM rc = object_mgr_find_in_map1(hContext, handle, &obj);
13939126SWyllys.Ingersoll@Sun.COM if (rc != CKR_OK) {
13949126SWyllys.Ingersoll@Sun.COM rc = CKR_OBJECT_HANDLE_INVALID;
13959126SWyllys.Ingersoll@Sun.COM goto done;
13969126SWyllys.Ingersoll@Sun.COM }
13979126SWyllys.Ingersoll@Sun.COM
13989126SWyllys.Ingersoll@Sun.COM *size = object_get_size(obj);
13999126SWyllys.Ingersoll@Sun.COM
14009126SWyllys.Ingersoll@Sun.COM done:
14019126SWyllys.Ingersoll@Sun.COM (void) pthread_mutex_unlock(&obj_list_mutex);
14029126SWyllys.Ingersoll@Sun.COM return (rc);
14039126SWyllys.Ingersoll@Sun.COM }
14049126SWyllys.Ingersoll@Sun.COM
14059126SWyllys.Ingersoll@Sun.COM
14069126SWyllys.Ingersoll@Sun.COM // object_mgr_invalidate_handle1()
14079126SWyllys.Ingersoll@Sun.COM //
14089126SWyllys.Ingersoll@Sun.COM // Returns: TRUE if successfully removes the node
14099126SWyllys.Ingersoll@Sun.COM // FALSE if cannot remove the node (not found, etc)
14109126SWyllys.Ingersoll@Sun.COM //
14119126SWyllys.Ingersoll@Sun.COM CK_BBOOL
object_mgr_invalidate_handle1(CK_OBJECT_HANDLE handle)14129126SWyllys.Ingersoll@Sun.COM object_mgr_invalidate_handle1(CK_OBJECT_HANDLE handle)
14139126SWyllys.Ingersoll@Sun.COM {
14149126SWyllys.Ingersoll@Sun.COM DL_NODE *node = NULL;
14159126SWyllys.Ingersoll@Sun.COM
14169126SWyllys.Ingersoll@Sun.COM if (pthread_rwlock_wrlock(&obj_list_rw_mutex)) {
14179126SWyllys.Ingersoll@Sun.COM return (CKR_FUNCTION_FAILED);
14189126SWyllys.Ingersoll@Sun.COM }
14199126SWyllys.Ingersoll@Sun.COM node = object_map;
14209126SWyllys.Ingersoll@Sun.COM
14219126SWyllys.Ingersoll@Sun.COM while (node) {
14229126SWyllys.Ingersoll@Sun.COM OBJECT_MAP *map = (OBJECT_MAP *)node->data;
14239126SWyllys.Ingersoll@Sun.COM
14249126SWyllys.Ingersoll@Sun.COM if (map->handle == handle) {
14259126SWyllys.Ingersoll@Sun.COM object_map = dlist_remove_node(object_map, node);
14269126SWyllys.Ingersoll@Sun.COM free(map);
14279126SWyllys.Ingersoll@Sun.COM (void) pthread_rwlock_unlock(&obj_list_rw_mutex);
14289126SWyllys.Ingersoll@Sun.COM return (TRUE);
14299126SWyllys.Ingersoll@Sun.COM }
14309126SWyllys.Ingersoll@Sun.COM
14319126SWyllys.Ingersoll@Sun.COM node = node->next;
14329126SWyllys.Ingersoll@Sun.COM }
14339126SWyllys.Ingersoll@Sun.COM (void) pthread_rwlock_unlock(&obj_list_rw_mutex);
14349126SWyllys.Ingersoll@Sun.COM return (FALSE);
14359126SWyllys.Ingersoll@Sun.COM }
14369126SWyllys.Ingersoll@Sun.COM
14379126SWyllys.Ingersoll@Sun.COM // object_mgr_invalidate_handle2()
14389126SWyllys.Ingersoll@Sun.COM //
14399126SWyllys.Ingersoll@Sun.COM // Returns: TRUE if successfully removes the node
14409126SWyllys.Ingersoll@Sun.COM // FALSE if cannot remove the node (not found, etc)
14419126SWyllys.Ingersoll@Sun.COM //
14429126SWyllys.Ingersoll@Sun.COM CK_BBOOL
object_mgr_invalidate_handle2(OBJECT * obj)14439126SWyllys.Ingersoll@Sun.COM object_mgr_invalidate_handle2(OBJECT *obj)
14449126SWyllys.Ingersoll@Sun.COM {
14459126SWyllys.Ingersoll@Sun.COM DL_NODE *node = NULL;
14469126SWyllys.Ingersoll@Sun.COM
14479126SWyllys.Ingersoll@Sun.COM if (! obj)
14489126SWyllys.Ingersoll@Sun.COM return (FALSE);
14499126SWyllys.Ingersoll@Sun.COM if (pthread_rwlock_wrlock(&obj_list_rw_mutex)) {
14509126SWyllys.Ingersoll@Sun.COM return (CKR_FUNCTION_FAILED);
14519126SWyllys.Ingersoll@Sun.COM }
14529126SWyllys.Ingersoll@Sun.COM node = object_map;
14539126SWyllys.Ingersoll@Sun.COM
14549126SWyllys.Ingersoll@Sun.COM while (node) {
14559126SWyllys.Ingersoll@Sun.COM OBJECT_MAP *map = (OBJECT_MAP *)node->data;
14569126SWyllys.Ingersoll@Sun.COM if (map->ptr == obj) {
14579126SWyllys.Ingersoll@Sun.COM object_map = dlist_remove_node(object_map, node);
14589126SWyllys.Ingersoll@Sun.COM free(map);
14599126SWyllys.Ingersoll@Sun.COM (void) pthread_rwlock_unlock(&obj_list_rw_mutex);
14609126SWyllys.Ingersoll@Sun.COM return (TRUE);
14619126SWyllys.Ingersoll@Sun.COM }
14629126SWyllys.Ingersoll@Sun.COM node = node->next;
14639126SWyllys.Ingersoll@Sun.COM }
14649126SWyllys.Ingersoll@Sun.COM (void) pthread_rwlock_unlock(&obj_list_rw_mutex);
14659126SWyllys.Ingersoll@Sun.COM
14669126SWyllys.Ingersoll@Sun.COM return (FALSE);
14679126SWyllys.Ingersoll@Sun.COM }
14689126SWyllys.Ingersoll@Sun.COM
14699126SWyllys.Ingersoll@Sun.COM // object_mgr_purge_session_objects()
14709126SWyllys.Ingersoll@Sun.COM //
14719126SWyllys.Ingersoll@Sun.COM // Args: SESSION *
14729126SWyllys.Ingersoll@Sun.COM // SESS_OBJ_TYPE: can be ALL, PRIVATE or PUBLIC
14739126SWyllys.Ingersoll@Sun.COM //
14749126SWyllys.Ingersoll@Sun.COM // Remove all session objects owned by the specified session satisfying
14759126SWyllys.Ingersoll@Sun.COM // the 'type' requirements
14769126SWyllys.Ingersoll@Sun.COM //
14779126SWyllys.Ingersoll@Sun.COM CK_BBOOL
object_mgr_purge_session_objects(SESSION * sess,SESS_OBJ_TYPE type)14789126SWyllys.Ingersoll@Sun.COM object_mgr_purge_session_objects(SESSION * sess,
14799126SWyllys.Ingersoll@Sun.COM SESS_OBJ_TYPE type)
14809126SWyllys.Ingersoll@Sun.COM {
14819126SWyllys.Ingersoll@Sun.COM DL_NODE *node = NULL;
14829126SWyllys.Ingersoll@Sun.COM DL_NODE *next = NULL;
14839126SWyllys.Ingersoll@Sun.COM OBJECT *obj = NULL;
14849126SWyllys.Ingersoll@Sun.COM CK_BBOOL del;
14859126SWyllys.Ingersoll@Sun.COM CK_RV rc;
14869126SWyllys.Ingersoll@Sun.COM
14879126SWyllys.Ingersoll@Sun.COM if (!sess)
14889126SWyllys.Ingersoll@Sun.COM return (FALSE);
14899126SWyllys.Ingersoll@Sun.COM
14909126SWyllys.Ingersoll@Sun.COM rc = pthread_mutex_lock(&obj_list_mutex);
14919126SWyllys.Ingersoll@Sun.COM if (rc != CKR_OK)
14929126SWyllys.Ingersoll@Sun.COM return (FALSE);
14939126SWyllys.Ingersoll@Sun.COM
14949126SWyllys.Ingersoll@Sun.COM node = sess_obj_list;
14959126SWyllys.Ingersoll@Sun.COM
14969126SWyllys.Ingersoll@Sun.COM while (node) {
14979126SWyllys.Ingersoll@Sun.COM obj = (OBJECT *)node->data;
14989126SWyllys.Ingersoll@Sun.COM del = FALSE;
14999126SWyllys.Ingersoll@Sun.COM
15009126SWyllys.Ingersoll@Sun.COM if (obj->session == sess) {
15019126SWyllys.Ingersoll@Sun.COM if (type == PRIVATE) {
15029126SWyllys.Ingersoll@Sun.COM if (object_is_private(obj))
15039126SWyllys.Ingersoll@Sun.COM del = TRUE;
15049126SWyllys.Ingersoll@Sun.COM } else if (type == PUBLIC) {
15059126SWyllys.Ingersoll@Sun.COM if (object_is_public(obj))
15069126SWyllys.Ingersoll@Sun.COM del = TRUE;
15079126SWyllys.Ingersoll@Sun.COM } else if (type == ALL)
15089126SWyllys.Ingersoll@Sun.COM del = TRUE;
15099126SWyllys.Ingersoll@Sun.COM }
15109126SWyllys.Ingersoll@Sun.COM if (del == TRUE) {
15119126SWyllys.Ingersoll@Sun.COM
15129126SWyllys.Ingersoll@Sun.COM CK_OBJECT_HANDLE handle;
15139126SWyllys.Ingersoll@Sun.COM CK_RV rc;
15149126SWyllys.Ingersoll@Sun.COM
15159126SWyllys.Ingersoll@Sun.COM rc = object_mgr_find_in_map2(sess->hContext, obj,
15169126SWyllys.Ingersoll@Sun.COM &handle);
15179126SWyllys.Ingersoll@Sun.COM if (rc == CKR_OK) {
15189126SWyllys.Ingersoll@Sun.COM (void) object_mgr_invalidate_handle1(handle);
15199126SWyllys.Ingersoll@Sun.COM (void) object_free(obj);
15209126SWyllys.Ingersoll@Sun.COM }
15219126SWyllys.Ingersoll@Sun.COM
15229126SWyllys.Ingersoll@Sun.COM next = node->next;
15239126SWyllys.Ingersoll@Sun.COM sess_obj_list = dlist_remove_node(sess_obj_list, node);
15249126SWyllys.Ingersoll@Sun.COM node = next;
15259126SWyllys.Ingersoll@Sun.COM }
15269126SWyllys.Ingersoll@Sun.COM else
15279126SWyllys.Ingersoll@Sun.COM node = node->next;
15289126SWyllys.Ingersoll@Sun.COM }
15299126SWyllys.Ingersoll@Sun.COM
15309126SWyllys.Ingersoll@Sun.COM (void) pthread_mutex_unlock(&obj_list_mutex);
15319126SWyllys.Ingersoll@Sun.COM
15329126SWyllys.Ingersoll@Sun.COM return (TRUE);
15339126SWyllys.Ingersoll@Sun.COM }
15349126SWyllys.Ingersoll@Sun.COM
15359126SWyllys.Ingersoll@Sun.COM //
15369126SWyllys.Ingersoll@Sun.COM // This routine cleans up the list of token objects. in general, we don't
15379126SWyllys.Ingersoll@Sun.COM // need to do this but when tracing memory leaks, it's best that we free
15389126SWyllys.Ingersoll@Sun.COM // everything that we've allocated.
15399126SWyllys.Ingersoll@Sun.COM //
15409126SWyllys.Ingersoll@Sun.COM CK_BBOOL
object_mgr_purge_token_objects(TSS_HCONTEXT hContext)15419126SWyllys.Ingersoll@Sun.COM object_mgr_purge_token_objects(TSS_HCONTEXT hContext)
15429126SWyllys.Ingersoll@Sun.COM {
15439126SWyllys.Ingersoll@Sun.COM DL_NODE *node = NULL;
15449126SWyllys.Ingersoll@Sun.COM DL_NODE *next = NULL;
15459126SWyllys.Ingersoll@Sun.COM OBJECT *obj = NULL;
15469126SWyllys.Ingersoll@Sun.COM CK_RV rc;
15479126SWyllys.Ingersoll@Sun.COM
15489126SWyllys.Ingersoll@Sun.COM rc = pthread_mutex_lock(&obj_list_mutex);
15499126SWyllys.Ingersoll@Sun.COM if (rc != CKR_OK)
15509126SWyllys.Ingersoll@Sun.COM return (FALSE);
15519126SWyllys.Ingersoll@Sun.COM
15529126SWyllys.Ingersoll@Sun.COM node = publ_token_obj_list;
15539126SWyllys.Ingersoll@Sun.COM while (publ_token_obj_list) {
15549126SWyllys.Ingersoll@Sun.COM CK_OBJECT_HANDLE handle;
15559126SWyllys.Ingersoll@Sun.COM CK_RV rc;
15569126SWyllys.Ingersoll@Sun.COM
15579126SWyllys.Ingersoll@Sun.COM obj = (OBJECT *)node->data;
15589126SWyllys.Ingersoll@Sun.COM
15599126SWyllys.Ingersoll@Sun.COM rc = object_mgr_find_in_map2(hContext, obj, &handle);
15609126SWyllys.Ingersoll@Sun.COM if (rc == CKR_OK) {
15619126SWyllys.Ingersoll@Sun.COM (void) object_mgr_invalidate_handle1(handle);
15629126SWyllys.Ingersoll@Sun.COM }
15639126SWyllys.Ingersoll@Sun.COM (void) object_free(obj);
15649126SWyllys.Ingersoll@Sun.COM
15659126SWyllys.Ingersoll@Sun.COM next = node->next;
15669126SWyllys.Ingersoll@Sun.COM publ_token_obj_list = dlist_remove_node(
15679126SWyllys.Ingersoll@Sun.COM publ_token_obj_list, node);
15689126SWyllys.Ingersoll@Sun.COM node = next;
15699126SWyllys.Ingersoll@Sun.COM }
15709126SWyllys.Ingersoll@Sun.COM
15719126SWyllys.Ingersoll@Sun.COM node = priv_token_obj_list;
15729126SWyllys.Ingersoll@Sun.COM
15739126SWyllys.Ingersoll@Sun.COM while (priv_token_obj_list) {
15749126SWyllys.Ingersoll@Sun.COM CK_OBJECT_HANDLE handle;
15759126SWyllys.Ingersoll@Sun.COM CK_RV rc;
15769126SWyllys.Ingersoll@Sun.COM
15779126SWyllys.Ingersoll@Sun.COM obj = (OBJECT *)node->data;
15789126SWyllys.Ingersoll@Sun.COM
15799126SWyllys.Ingersoll@Sun.COM rc = object_mgr_find_in_map2(hContext, obj, &handle);
15809126SWyllys.Ingersoll@Sun.COM if (rc == CKR_OK)
15819126SWyllys.Ingersoll@Sun.COM (void) object_mgr_invalidate_handle1(handle);
15829126SWyllys.Ingersoll@Sun.COM (void) object_free(obj);
15839126SWyllys.Ingersoll@Sun.COM
15849126SWyllys.Ingersoll@Sun.COM next = node->next;
15859126SWyllys.Ingersoll@Sun.COM priv_token_obj_list = dlist_remove_node(
15869126SWyllys.Ingersoll@Sun.COM priv_token_obj_list, node);
15879126SWyllys.Ingersoll@Sun.COM node = next;
15889126SWyllys.Ingersoll@Sun.COM }
15899126SWyllys.Ingersoll@Sun.COM
15909126SWyllys.Ingersoll@Sun.COM (void) pthread_mutex_unlock(&obj_list_mutex);
15919126SWyllys.Ingersoll@Sun.COM
15929126SWyllys.Ingersoll@Sun.COM return (TRUE);
15939126SWyllys.Ingersoll@Sun.COM }
15949126SWyllys.Ingersoll@Sun.COM
15959126SWyllys.Ingersoll@Sun.COM CK_BBOOL
object_mgr_purge_private_token_objects(TSS_HCONTEXT hContext)15969126SWyllys.Ingersoll@Sun.COM object_mgr_purge_private_token_objects(TSS_HCONTEXT hContext) {
15979126SWyllys.Ingersoll@Sun.COM OBJECT * obj = NULL;
15989126SWyllys.Ingersoll@Sun.COM DL_NODE * node = NULL;
15999126SWyllys.Ingersoll@Sun.COM DL_NODE * next = NULL;
16009126SWyllys.Ingersoll@Sun.COM CK_RV rc;
16019126SWyllys.Ingersoll@Sun.COM
16029126SWyllys.Ingersoll@Sun.COM rc = pthread_mutex_lock(&obj_list_mutex);
16039126SWyllys.Ingersoll@Sun.COM if (rc != CKR_OK)
16049126SWyllys.Ingersoll@Sun.COM return (FALSE);
16059126SWyllys.Ingersoll@Sun.COM
16069126SWyllys.Ingersoll@Sun.COM node = priv_token_obj_list;
16079126SWyllys.Ingersoll@Sun.COM while (priv_token_obj_list) {
16089126SWyllys.Ingersoll@Sun.COM CK_OBJECT_HANDLE handle;
16099126SWyllys.Ingersoll@Sun.COM CK_RV rc;
16109126SWyllys.Ingersoll@Sun.COM
16119126SWyllys.Ingersoll@Sun.COM obj = (OBJECT *)node->data;
16129126SWyllys.Ingersoll@Sun.COM
16139126SWyllys.Ingersoll@Sun.COM rc = object_mgr_find_in_map2(hContext, obj, &handle);
16149126SWyllys.Ingersoll@Sun.COM if (rc == CKR_OK) {
16159126SWyllys.Ingersoll@Sun.COM (void) object_mgr_invalidate_handle1(handle);
16169126SWyllys.Ingersoll@Sun.COM }
16179126SWyllys.Ingersoll@Sun.COM
16189126SWyllys.Ingersoll@Sun.COM (void) object_free(obj);
16199126SWyllys.Ingersoll@Sun.COM
16209126SWyllys.Ingersoll@Sun.COM next = node->next;
16219126SWyllys.Ingersoll@Sun.COM priv_token_obj_list = dlist_remove_node(
16229126SWyllys.Ingersoll@Sun.COM priv_token_obj_list, node);
16239126SWyllys.Ingersoll@Sun.COM node = next;
16249126SWyllys.Ingersoll@Sun.COM }
16259126SWyllys.Ingersoll@Sun.COM
16269126SWyllys.Ingersoll@Sun.COM (void) pthread_mutex_unlock(&obj_list_mutex);
16279126SWyllys.Ingersoll@Sun.COM
16289126SWyllys.Ingersoll@Sun.COM return (TRUE);
16299126SWyllys.Ingersoll@Sun.COM }
16309126SWyllys.Ingersoll@Sun.COM
16319126SWyllys.Ingersoll@Sun.COM CK_RV
object_mgr_remove_from_map(CK_OBJECT_HANDLE handle)16329126SWyllys.Ingersoll@Sun.COM object_mgr_remove_from_map(CK_OBJECT_HANDLE handle)
16339126SWyllys.Ingersoll@Sun.COM {
16349126SWyllys.Ingersoll@Sun.COM DL_NODE *node = NULL;
16359126SWyllys.Ingersoll@Sun.COM
16369126SWyllys.Ingersoll@Sun.COM if (pthread_rwlock_wrlock(&obj_list_rw_mutex)) {
16379126SWyllys.Ingersoll@Sun.COM return (CKR_FUNCTION_FAILED);
16389126SWyllys.Ingersoll@Sun.COM }
16399126SWyllys.Ingersoll@Sun.COM node = object_map;
16409126SWyllys.Ingersoll@Sun.COM while (node) {
16419126SWyllys.Ingersoll@Sun.COM OBJECT_MAP *map = (OBJECT_MAP *)node->data;
16429126SWyllys.Ingersoll@Sun.COM if (map->handle == handle) {
16439126SWyllys.Ingersoll@Sun.COM object_map = dlist_remove_node(object_map, node);
16449126SWyllys.Ingersoll@Sun.COM free(map);
16459126SWyllys.Ingersoll@Sun.COM (void) pthread_rwlock_unlock(&obj_list_rw_mutex);
16469126SWyllys.Ingersoll@Sun.COM return (CKR_OK);
16479126SWyllys.Ingersoll@Sun.COM }
16489126SWyllys.Ingersoll@Sun.COM node = node->next;
16499126SWyllys.Ingersoll@Sun.COM }
16509126SWyllys.Ingersoll@Sun.COM (void) pthread_rwlock_unlock(&obj_list_rw_mutex);
16519126SWyllys.Ingersoll@Sun.COM
16529126SWyllys.Ingersoll@Sun.COM return (CKR_FUNCTION_FAILED);
16539126SWyllys.Ingersoll@Sun.COM }
16549126SWyllys.Ingersoll@Sun.COM
16559126SWyllys.Ingersoll@Sun.COM CK_RV
object_mgr_restore_obj(CK_BYTE * data,OBJECT * oldObj)16569126SWyllys.Ingersoll@Sun.COM object_mgr_restore_obj(CK_BYTE *data, OBJECT *oldObj)
16579126SWyllys.Ingersoll@Sun.COM {
16589126SWyllys.Ingersoll@Sun.COM OBJECT * obj = NULL;
16599126SWyllys.Ingersoll@Sun.COM CK_BBOOL priv;
16609126SWyllys.Ingersoll@Sun.COM CK_RV rc;
16619126SWyllys.Ingersoll@Sun.COM
16629126SWyllys.Ingersoll@Sun.COM if (! data) {
16639126SWyllys.Ingersoll@Sun.COM return (CKR_FUNCTION_FAILED);
16649126SWyllys.Ingersoll@Sun.COM }
16659126SWyllys.Ingersoll@Sun.COM if (oldObj != NULL) {
16669126SWyllys.Ingersoll@Sun.COM obj = oldObj;
16679126SWyllys.Ingersoll@Sun.COM rc = object_restore(data, &obj, TRUE);
16689126SWyllys.Ingersoll@Sun.COM } else {
16699126SWyllys.Ingersoll@Sun.COM rc = object_restore(data, &obj, FALSE);
16709126SWyllys.Ingersoll@Sun.COM if (rc == CKR_OK) {
16719126SWyllys.Ingersoll@Sun.COM priv = object_is_private(obj);
16729126SWyllys.Ingersoll@Sun.COM
16739126SWyllys.Ingersoll@Sun.COM if (priv)
16749126SWyllys.Ingersoll@Sun.COM priv_token_obj_list = dlist_add_as_last(
16759126SWyllys.Ingersoll@Sun.COM priv_token_obj_list, obj);
16769126SWyllys.Ingersoll@Sun.COM else
16779126SWyllys.Ingersoll@Sun.COM publ_token_obj_list = dlist_add_as_last(
16789126SWyllys.Ingersoll@Sun.COM publ_token_obj_list, obj);
16799126SWyllys.Ingersoll@Sun.COM
1680*9453SWyllys.Ingersoll@Sun.COM (void) XProcLock(xproclock);
16819126SWyllys.Ingersoll@Sun.COM
16829126SWyllys.Ingersoll@Sun.COM if (priv) {
16839126SWyllys.Ingersoll@Sun.COM if (global_shm->priv_loaded == FALSE) {
16849126SWyllys.Ingersoll@Sun.COM if (global_shm->num_priv_tok_obj <
16859126SWyllys.Ingersoll@Sun.COM MAX_TOK_OBJS)
16869126SWyllys.Ingersoll@Sun.COM (void) object_mgr_add_to_shm(
16879126SWyllys.Ingersoll@Sun.COM obj);
16889126SWyllys.Ingersoll@Sun.COM else
16899126SWyllys.Ingersoll@Sun.COM rc = CKR_HOST_MEMORY;
16909126SWyllys.Ingersoll@Sun.COM }
16919126SWyllys.Ingersoll@Sun.COM } else {
16929126SWyllys.Ingersoll@Sun.COM if (global_shm->publ_loaded == FALSE) {
16939126SWyllys.Ingersoll@Sun.COM if (global_shm->num_publ_tok_obj <
16949126SWyllys.Ingersoll@Sun.COM MAX_TOK_OBJS)
16959126SWyllys.Ingersoll@Sun.COM (void) object_mgr_add_to_shm(
16969126SWyllys.Ingersoll@Sun.COM obj);
16979126SWyllys.Ingersoll@Sun.COM else
16989126SWyllys.Ingersoll@Sun.COM rc = CKR_HOST_MEMORY;
16999126SWyllys.Ingersoll@Sun.COM }
17009126SWyllys.Ingersoll@Sun.COM }
17019126SWyllys.Ingersoll@Sun.COM
17029126SWyllys.Ingersoll@Sun.COM (void) XProcUnLock(xproclock);
17039126SWyllys.Ingersoll@Sun.COM }
17049126SWyllys.Ingersoll@Sun.COM }
17059126SWyllys.Ingersoll@Sun.COM
17069126SWyllys.Ingersoll@Sun.COM // make the callers have to have the mutes
17079126SWyllys.Ingersoll@Sun.COM // to many grab it now.
17089126SWyllys.Ingersoll@Sun.COM return (rc);
17099126SWyllys.Ingersoll@Sun.COM }
17109126SWyllys.Ingersoll@Sun.COM
17119126SWyllys.Ingersoll@Sun.COM CK_RV
object_mgr_set_attribute_values(SESSION * sess,CK_OBJECT_HANDLE handle,CK_ATTRIBUTE * pTemplate,CK_ULONG ulCount)17129126SWyllys.Ingersoll@Sun.COM object_mgr_set_attribute_values(SESSION * sess,
17139126SWyllys.Ingersoll@Sun.COM CK_OBJECT_HANDLE handle,
17149126SWyllys.Ingersoll@Sun.COM CK_ATTRIBUTE * pTemplate,
17159126SWyllys.Ingersoll@Sun.COM CK_ULONG ulCount)
17169126SWyllys.Ingersoll@Sun.COM {
17179126SWyllys.Ingersoll@Sun.COM OBJECT * obj;
17189126SWyllys.Ingersoll@Sun.COM CK_BBOOL sess_obj, priv_obj;
17199126SWyllys.Ingersoll@Sun.COM CK_BBOOL modifiable;
17209126SWyllys.Ingersoll@Sun.COM CK_RV rc;
17219126SWyllys.Ingersoll@Sun.COM
17229126SWyllys.Ingersoll@Sun.COM if (! pTemplate) {
17239126SWyllys.Ingersoll@Sun.COM return (CKR_FUNCTION_FAILED);
17249126SWyllys.Ingersoll@Sun.COM }
17259126SWyllys.Ingersoll@Sun.COM rc = pthread_mutex_lock(&obj_list_mutex);
17269126SWyllys.Ingersoll@Sun.COM if (rc != CKR_OK)
17279126SWyllys.Ingersoll@Sun.COM return (CKR_FUNCTION_FAILED);
17289126SWyllys.Ingersoll@Sun.COM
17299126SWyllys.Ingersoll@Sun.COM rc = object_mgr_find_in_map1(sess->hContext, handle, &obj);
17309126SWyllys.Ingersoll@Sun.COM if (rc != CKR_OK) {
17319126SWyllys.Ingersoll@Sun.COM (void) pthread_mutex_unlock(&obj_list_mutex);
17329126SWyllys.Ingersoll@Sun.COM return (CKR_OBJECT_HANDLE_INVALID);
17339126SWyllys.Ingersoll@Sun.COM }
17349126SWyllys.Ingersoll@Sun.COM (void) pthread_mutex_unlock(&obj_list_mutex);
17359126SWyllys.Ingersoll@Sun.COM
17369126SWyllys.Ingersoll@Sun.COM modifiable = object_is_modifiable(obj);
17379126SWyllys.Ingersoll@Sun.COM sess_obj = object_is_session_object(obj);
17389126SWyllys.Ingersoll@Sun.COM priv_obj = object_is_private(obj);
17399126SWyllys.Ingersoll@Sun.COM
17409126SWyllys.Ingersoll@Sun.COM if (! modifiable) {
17419126SWyllys.Ingersoll@Sun.COM return (CKR_ATTRIBUTE_READ_ONLY);
17429126SWyllys.Ingersoll@Sun.COM }
1743*9453SWyllys.Ingersoll@Sun.COM rc = check_object_access(sess, obj);
1744*9453SWyllys.Ingersoll@Sun.COM if (rc != CKR_OK)
1745*9453SWyllys.Ingersoll@Sun.COM return (rc);
17469126SWyllys.Ingersoll@Sun.COM
17479126SWyllys.Ingersoll@Sun.COM rc = object_set_attribute_values(obj, pTemplate, ulCount);
17489126SWyllys.Ingersoll@Sun.COM if (rc != CKR_OK) {
17499126SWyllys.Ingersoll@Sun.COM return (rc);
17509126SWyllys.Ingersoll@Sun.COM }
17519126SWyllys.Ingersoll@Sun.COM if (! sess_obj) {
17529126SWyllys.Ingersoll@Sun.COM TOK_OBJ_ENTRY *entry = NULL;
17539126SWyllys.Ingersoll@Sun.COM CK_ULONG index;
17549126SWyllys.Ingersoll@Sun.COM
17559126SWyllys.Ingersoll@Sun.COM obj->count_lo++;
17569126SWyllys.Ingersoll@Sun.COM if (obj->count_lo == 0)
17579126SWyllys.Ingersoll@Sun.COM obj->count_hi++;
17589126SWyllys.Ingersoll@Sun.COM
17599126SWyllys.Ingersoll@Sun.COM rc = save_token_object(sess->hContext, obj);
17609126SWyllys.Ingersoll@Sun.COM if (rc != CKR_OK)
17619126SWyllys.Ingersoll@Sun.COM return (rc);
17629126SWyllys.Ingersoll@Sun.COM
17639126SWyllys.Ingersoll@Sun.COM rc = XProcLock(xproclock);
17649126SWyllys.Ingersoll@Sun.COM if (rc != CKR_OK) {
17659126SWyllys.Ingersoll@Sun.COM return (rc);
17669126SWyllys.Ingersoll@Sun.COM }
17679126SWyllys.Ingersoll@Sun.COM if (priv_obj) {
17689126SWyllys.Ingersoll@Sun.COM rc = object_mgr_search_shm_for_obj(
17699126SWyllys.Ingersoll@Sun.COM global_shm->priv_tok_objs,
17709126SWyllys.Ingersoll@Sun.COM 0, global_shm->num_priv_tok_obj - 1,
17719126SWyllys.Ingersoll@Sun.COM obj, &index);
17729126SWyllys.Ingersoll@Sun.COM
17739126SWyllys.Ingersoll@Sun.COM if (rc != CKR_OK) {
17749126SWyllys.Ingersoll@Sun.COM (void) XProcUnLock(xproclock);
17759126SWyllys.Ingersoll@Sun.COM return (rc);
17769126SWyllys.Ingersoll@Sun.COM }
17779126SWyllys.Ingersoll@Sun.COM
17789126SWyllys.Ingersoll@Sun.COM entry = &global_shm->priv_tok_objs[index];
17799126SWyllys.Ingersoll@Sun.COM } else {
17809126SWyllys.Ingersoll@Sun.COM rc = object_mgr_search_shm_for_obj(
17819126SWyllys.Ingersoll@Sun.COM global_shm->publ_tok_objs,
17829126SWyllys.Ingersoll@Sun.COM 0, global_shm->num_publ_tok_obj - 1,
17839126SWyllys.Ingersoll@Sun.COM obj, &index);
17849126SWyllys.Ingersoll@Sun.COM if (rc != CKR_OK) {
17859126SWyllys.Ingersoll@Sun.COM (void) XProcUnLock(xproclock);
17869126SWyllys.Ingersoll@Sun.COM return (rc);
17879126SWyllys.Ingersoll@Sun.COM }
17889126SWyllys.Ingersoll@Sun.COM
17899126SWyllys.Ingersoll@Sun.COM entry = &global_shm->publ_tok_objs[index];
17909126SWyllys.Ingersoll@Sun.COM }
17919126SWyllys.Ingersoll@Sun.COM
17929126SWyllys.Ingersoll@Sun.COM entry->count_lo = obj->count_lo;
17939126SWyllys.Ingersoll@Sun.COM entry->count_hi = obj->count_hi;
17949126SWyllys.Ingersoll@Sun.COM
17959126SWyllys.Ingersoll@Sun.COM (void) XProcUnLock(xproclock);
17969126SWyllys.Ingersoll@Sun.COM }
17979126SWyllys.Ingersoll@Sun.COM
17989126SWyllys.Ingersoll@Sun.COM return (rc);
17999126SWyllys.Ingersoll@Sun.COM }
18009126SWyllys.Ingersoll@Sun.COM
18019126SWyllys.Ingersoll@Sun.COM CK_RV
object_mgr_add_to_shm(OBJECT * obj)18029126SWyllys.Ingersoll@Sun.COM object_mgr_add_to_shm(OBJECT *obj)
18039126SWyllys.Ingersoll@Sun.COM {
18049126SWyllys.Ingersoll@Sun.COM TOK_OBJ_ENTRY * entry = NULL;
18059126SWyllys.Ingersoll@Sun.COM CK_BBOOL priv;
18069126SWyllys.Ingersoll@Sun.COM
18079126SWyllys.Ingersoll@Sun.COM priv = object_is_private(obj);
18089126SWyllys.Ingersoll@Sun.COM
18099126SWyllys.Ingersoll@Sun.COM if (priv)
18109126SWyllys.Ingersoll@Sun.COM entry = &global_shm->priv_tok_objs[
18119126SWyllys.Ingersoll@Sun.COM global_shm->num_priv_tok_obj];
18129126SWyllys.Ingersoll@Sun.COM else
18139126SWyllys.Ingersoll@Sun.COM entry = &global_shm->publ_tok_objs[
18149126SWyllys.Ingersoll@Sun.COM global_shm->num_publ_tok_obj];
18159126SWyllys.Ingersoll@Sun.COM
18169126SWyllys.Ingersoll@Sun.COM entry->deleted = FALSE;
18179126SWyllys.Ingersoll@Sun.COM entry->count_lo = 0;
18189126SWyllys.Ingersoll@Sun.COM entry->count_hi = 0;
18199126SWyllys.Ingersoll@Sun.COM (void) memcpy(entry->name, obj->name, 8);
18209126SWyllys.Ingersoll@Sun.COM
18219126SWyllys.Ingersoll@Sun.COM if (priv) {
18229126SWyllys.Ingersoll@Sun.COM global_shm->num_priv_tok_obj++;
18239126SWyllys.Ingersoll@Sun.COM } else {
18249126SWyllys.Ingersoll@Sun.COM global_shm->num_publ_tok_obj++;
18259126SWyllys.Ingersoll@Sun.COM }
18269126SWyllys.Ingersoll@Sun.COM
18279126SWyllys.Ingersoll@Sun.COM return (CKR_OK);
18289126SWyllys.Ingersoll@Sun.COM }
18299126SWyllys.Ingersoll@Sun.COM
18309126SWyllys.Ingersoll@Sun.COM CK_RV
object_mgr_del_from_shm(OBJECT * obj)18319126SWyllys.Ingersoll@Sun.COM object_mgr_del_from_shm(OBJECT *obj)
18329126SWyllys.Ingersoll@Sun.COM {
18339126SWyllys.Ingersoll@Sun.COM CK_ULONG index, count;
18349126SWyllys.Ingersoll@Sun.COM CK_BBOOL priv;
18359126SWyllys.Ingersoll@Sun.COM CK_RV rc;
18369126SWyllys.Ingersoll@Sun.COM
18379126SWyllys.Ingersoll@Sun.COM priv = object_is_private(obj);
18389126SWyllys.Ingersoll@Sun.COM
18399126SWyllys.Ingersoll@Sun.COM if (priv) {
18409126SWyllys.Ingersoll@Sun.COM rc = object_mgr_search_shm_for_obj(global_shm->priv_tok_objs,
18419126SWyllys.Ingersoll@Sun.COM 0, global_shm->num_priv_tok_obj - 1, obj, &index);
18429126SWyllys.Ingersoll@Sun.COM if (rc != CKR_OK) {
18439126SWyllys.Ingersoll@Sun.COM return (CKR_FUNCTION_FAILED);
18449126SWyllys.Ingersoll@Sun.COM }
18459126SWyllys.Ingersoll@Sun.COM
18469126SWyllys.Ingersoll@Sun.COM global_shm->num_priv_tok_obj--;
18479126SWyllys.Ingersoll@Sun.COM if (index > global_shm->num_priv_tok_obj) {
18489126SWyllys.Ingersoll@Sun.COM count = index - global_shm->num_priv_tok_obj;
18499126SWyllys.Ingersoll@Sun.COM } else {
18509126SWyllys.Ingersoll@Sun.COM count = global_shm->num_priv_tok_obj - index;
18519126SWyllys.Ingersoll@Sun.COM }
18529126SWyllys.Ingersoll@Sun.COM
18539126SWyllys.Ingersoll@Sun.COM if (count > 0) {
18549126SWyllys.Ingersoll@Sun.COM (void) memcpy((char *)&global_shm->priv_tok_objs[index],
18559126SWyllys.Ingersoll@Sun.COM (char *)&global_shm->priv_tok_objs[index + 1],
18569126SWyllys.Ingersoll@Sun.COM sizeof (TOK_OBJ_ENTRY) * count);
18579126SWyllys.Ingersoll@Sun.COM
18589126SWyllys.Ingersoll@Sun.COM (void) memset((char *)&global_shm->priv_tok_objs[
18599126SWyllys.Ingersoll@Sun.COM global_shm->num_priv_tok_obj + 1], 0,
18609126SWyllys.Ingersoll@Sun.COM sizeof (TOK_OBJ_ENTRY));
18619126SWyllys.Ingersoll@Sun.COM } else {
18629126SWyllys.Ingersoll@Sun.COM (void) memset((char *)&global_shm->priv_tok_objs[
18639126SWyllys.Ingersoll@Sun.COM global_shm->num_priv_tok_obj], 0,
18649126SWyllys.Ingersoll@Sun.COM sizeof (TOK_OBJ_ENTRY));
18659126SWyllys.Ingersoll@Sun.COM }
18669126SWyllys.Ingersoll@Sun.COM } else {
18679126SWyllys.Ingersoll@Sun.COM rc = object_mgr_search_shm_for_obj(global_shm->publ_tok_objs,
18689126SWyllys.Ingersoll@Sun.COM 0, global_shm->num_publ_tok_obj - 1, obj, &index);
18699126SWyllys.Ingersoll@Sun.COM if (rc != CKR_OK) {
18709126SWyllys.Ingersoll@Sun.COM return (CKR_FUNCTION_FAILED);
18719126SWyllys.Ingersoll@Sun.COM }
18729126SWyllys.Ingersoll@Sun.COM global_shm->num_publ_tok_obj--;
18739126SWyllys.Ingersoll@Sun.COM
18749126SWyllys.Ingersoll@Sun.COM if (index > global_shm->num_publ_tok_obj) {
18759126SWyllys.Ingersoll@Sun.COM count = index - global_shm->num_publ_tok_obj;
18769126SWyllys.Ingersoll@Sun.COM } else {
18779126SWyllys.Ingersoll@Sun.COM count = global_shm->num_publ_tok_obj - index;
18789126SWyllys.Ingersoll@Sun.COM }
18799126SWyllys.Ingersoll@Sun.COM
18809126SWyllys.Ingersoll@Sun.COM if (count > 0) {
18819126SWyllys.Ingersoll@Sun.COM (void) memcpy((char *)&global_shm->publ_tok_objs[index],
18829126SWyllys.Ingersoll@Sun.COM (char *)&global_shm->publ_tok_objs[index + 1],
18839126SWyllys.Ingersoll@Sun.COM sizeof (TOK_OBJ_ENTRY) * count);
18849126SWyllys.Ingersoll@Sun.COM (void) memset((char *)&global_shm->publ_tok_objs[
18859126SWyllys.Ingersoll@Sun.COM global_shm->num_publ_tok_obj + 1], 0,
18869126SWyllys.Ingersoll@Sun.COM sizeof (TOK_OBJ_ENTRY));
18879126SWyllys.Ingersoll@Sun.COM } else {
18889126SWyllys.Ingersoll@Sun.COM (void) memset((char *)&global_shm->publ_tok_objs[
18899126SWyllys.Ingersoll@Sun.COM global_shm->num_publ_tok_obj], 0,
18909126SWyllys.Ingersoll@Sun.COM sizeof (TOK_OBJ_ENTRY));
18919126SWyllys.Ingersoll@Sun.COM }
18929126SWyllys.Ingersoll@Sun.COM }
18939126SWyllys.Ingersoll@Sun.COM
18949126SWyllys.Ingersoll@Sun.COM return (CKR_OK);
18959126SWyllys.Ingersoll@Sun.COM }
18969126SWyllys.Ingersoll@Sun.COM
18979126SWyllys.Ingersoll@Sun.COM static CK_RV
object_mgr_check_shm(TSS_HCONTEXT hContext,OBJECT * obj)18989126SWyllys.Ingersoll@Sun.COM object_mgr_check_shm(TSS_HCONTEXT hContext, OBJECT *obj)
18999126SWyllys.Ingersoll@Sun.COM {
19009126SWyllys.Ingersoll@Sun.COM TOK_OBJ_ENTRY * entry = NULL;
19019126SWyllys.Ingersoll@Sun.COM CK_BBOOL priv;
19029126SWyllys.Ingersoll@Sun.COM CK_ULONG index;
19039126SWyllys.Ingersoll@Sun.COM CK_RV rc;
19049126SWyllys.Ingersoll@Sun.COM
19059126SWyllys.Ingersoll@Sun.COM
19069126SWyllys.Ingersoll@Sun.COM priv = object_is_private(obj);
19079126SWyllys.Ingersoll@Sun.COM
19089126SWyllys.Ingersoll@Sun.COM if (priv) {
19099126SWyllys.Ingersoll@Sun.COM rc = object_mgr_search_shm_for_obj(
19109126SWyllys.Ingersoll@Sun.COM global_shm->priv_tok_objs,
19119126SWyllys.Ingersoll@Sun.COM 0, global_shm->num_priv_tok_obj - 1, obj, &index);
19129126SWyllys.Ingersoll@Sun.COM if (rc != CKR_OK) {
19139126SWyllys.Ingersoll@Sun.COM return (CKR_FUNCTION_FAILED);
19149126SWyllys.Ingersoll@Sun.COM }
19159126SWyllys.Ingersoll@Sun.COM entry = &global_shm->priv_tok_objs[index];
19169126SWyllys.Ingersoll@Sun.COM } else {
19179126SWyllys.Ingersoll@Sun.COM rc = object_mgr_search_shm_for_obj(
19189126SWyllys.Ingersoll@Sun.COM global_shm->publ_tok_objs,
19199126SWyllys.Ingersoll@Sun.COM 0, global_shm->num_publ_tok_obj - 1, obj, &index);
19209126SWyllys.Ingersoll@Sun.COM if (rc != CKR_OK) {
19219126SWyllys.Ingersoll@Sun.COM return (CKR_FUNCTION_FAILED);
19229126SWyllys.Ingersoll@Sun.COM }
19239126SWyllys.Ingersoll@Sun.COM entry = &global_shm->publ_tok_objs[index];
19249126SWyllys.Ingersoll@Sun.COM }
19259126SWyllys.Ingersoll@Sun.COM
19269126SWyllys.Ingersoll@Sun.COM if ((obj->count_hi == entry->count_hi) &&
19279126SWyllys.Ingersoll@Sun.COM (obj->count_lo == entry->count_lo))
19289126SWyllys.Ingersoll@Sun.COM return (CKR_OK);
19299126SWyllys.Ingersoll@Sun.COM rc = reload_token_object(hContext, obj);
19309126SWyllys.Ingersoll@Sun.COM return (rc);
19319126SWyllys.Ingersoll@Sun.COM }
19329126SWyllys.Ingersoll@Sun.COM
19339126SWyllys.Ingersoll@Sun.COM /*ARGSUSED*/
19349126SWyllys.Ingersoll@Sun.COM static CK_RV
object_mgr_search_shm_for_obj(TOK_OBJ_ENTRY * obj_list,CK_ULONG lo,CK_ULONG hi,OBJECT * obj,CK_ULONG * index)19359126SWyllys.Ingersoll@Sun.COM object_mgr_search_shm_for_obj(
19369126SWyllys.Ingersoll@Sun.COM TOK_OBJ_ENTRY *obj_list,
19379126SWyllys.Ingersoll@Sun.COM CK_ULONG lo,
19389126SWyllys.Ingersoll@Sun.COM CK_ULONG hi,
19399126SWyllys.Ingersoll@Sun.COM OBJECT *obj,
19409126SWyllys.Ingersoll@Sun.COM CK_ULONG *index)
19419126SWyllys.Ingersoll@Sun.COM {
19429126SWyllys.Ingersoll@Sun.COM CK_ULONG idx;
19439126SWyllys.Ingersoll@Sun.COM if (obj->index == 0) {
19449126SWyllys.Ingersoll@Sun.COM for (idx = lo; idx <= hi; idx++) {
19459126SWyllys.Ingersoll@Sun.COM if (memcmp(obj->name, obj_list[idx].name, 8) == 0) {
19469126SWyllys.Ingersoll@Sun.COM *index = idx;
19479126SWyllys.Ingersoll@Sun.COM obj->index = idx;
19489126SWyllys.Ingersoll@Sun.COM return (CKR_OK);
19499126SWyllys.Ingersoll@Sun.COM }
19509126SWyllys.Ingersoll@Sun.COM }
19519126SWyllys.Ingersoll@Sun.COM } else {
19529126SWyllys.Ingersoll@Sun.COM if (memcmp(obj->name, obj_list[obj->index].name, 8) == 0) {
19539126SWyllys.Ingersoll@Sun.COM *index = obj->index;
19549126SWyllys.Ingersoll@Sun.COM return (CKR_OK);
19559126SWyllys.Ingersoll@Sun.COM } else {
19569126SWyllys.Ingersoll@Sun.COM for (idx = lo; idx <= hi; idx++) {
19579126SWyllys.Ingersoll@Sun.COM if (memcmp(obj->name,
19589126SWyllys.Ingersoll@Sun.COM obj_list[idx].name, 8) == 0) {
19599126SWyllys.Ingersoll@Sun.COM *index = idx;
19609126SWyllys.Ingersoll@Sun.COM obj->index = idx;
19619126SWyllys.Ingersoll@Sun.COM return (CKR_OK);
19629126SWyllys.Ingersoll@Sun.COM }
19639126SWyllys.Ingersoll@Sun.COM }
19649126SWyllys.Ingersoll@Sun.COM }
19659126SWyllys.Ingersoll@Sun.COM }
19669126SWyllys.Ingersoll@Sun.COM return (CKR_FUNCTION_FAILED);
19679126SWyllys.Ingersoll@Sun.COM }
19689126SWyllys.Ingersoll@Sun.COM
19699126SWyllys.Ingersoll@Sun.COM static CK_RV
object_mgr_update_publ_tok_obj_from_shm(TSS_HCONTEXT hContext)19709126SWyllys.Ingersoll@Sun.COM object_mgr_update_publ_tok_obj_from_shm(TSS_HCONTEXT hContext)
19719126SWyllys.Ingersoll@Sun.COM {
19729126SWyllys.Ingersoll@Sun.COM DL_NODE * node = NULL;
19739126SWyllys.Ingersoll@Sun.COM DL_NODE * next = NULL;
19749126SWyllys.Ingersoll@Sun.COM TOK_OBJ_ENTRY * te = NULL;
19759126SWyllys.Ingersoll@Sun.COM OBJECT * obj = NULL;
19769126SWyllys.Ingersoll@Sun.COM CK_OBJECT_HANDLE handle;
19779126SWyllys.Ingersoll@Sun.COM CK_ULONG index;
19789126SWyllys.Ingersoll@Sun.COM int val;
19799126SWyllys.Ingersoll@Sun.COM CK_RV rc;
19809126SWyllys.Ingersoll@Sun.COM
19819126SWyllys.Ingersoll@Sun.COM node = publ_token_obj_list;
19829126SWyllys.Ingersoll@Sun.COM index = 0;
19839126SWyllys.Ingersoll@Sun.COM
19849126SWyllys.Ingersoll@Sun.COM while ((node != NULL) && (index < global_shm->num_publ_tok_obj)) {
19859126SWyllys.Ingersoll@Sun.COM te = &global_shm->publ_tok_objs[index];
19869126SWyllys.Ingersoll@Sun.COM obj = (OBJECT *)node->data;
19879126SWyllys.Ingersoll@Sun.COM
19889126SWyllys.Ingersoll@Sun.COM val = memcmp(obj->name, te->name, 8);
19899126SWyllys.Ingersoll@Sun.COM
19909126SWyllys.Ingersoll@Sun.COM // 3 cases:
19919126SWyllys.Ingersoll@Sun.COM // 1) object in local list but not in the global list,
19929126SWyllys.Ingersoll@Sun.COM // need to remove from local list
19939126SWyllys.Ingersoll@Sun.COM // 2) object in both lists, need to compare counters
19949126SWyllys.Ingersoll@Sun.COM // and update as needed
19959126SWyllys.Ingersoll@Sun.COM // 3) object in global list but not in the local list,
19969126SWyllys.Ingersoll@Sun.COM // need to add the object here.
19979126SWyllys.Ingersoll@Sun.COM //
19989126SWyllys.Ingersoll@Sun.COM if (val < 0) {
19999126SWyllys.Ingersoll@Sun.COM rc = object_mgr_find_in_map2(hContext, obj, &handle);
20009126SWyllys.Ingersoll@Sun.COM if (rc == CKR_OK) {
20019126SWyllys.Ingersoll@Sun.COM (void) object_mgr_remove_from_map(handle);
20029126SWyllys.Ingersoll@Sun.COM }
20039126SWyllys.Ingersoll@Sun.COM (void) object_free(obj);
20049126SWyllys.Ingersoll@Sun.COM
20059126SWyllys.Ingersoll@Sun.COM next = node->next;
20069126SWyllys.Ingersoll@Sun.COM publ_token_obj_list = dlist_remove_node(
20079126SWyllys.Ingersoll@Sun.COM publ_token_obj_list, node);
20089126SWyllys.Ingersoll@Sun.COM
20099126SWyllys.Ingersoll@Sun.COM } else if (val == 0) {
20109126SWyllys.Ingersoll@Sun.COM if ((te->count_hi != obj->count_hi) ||
20119126SWyllys.Ingersoll@Sun.COM (te->count_lo != obj->count_lo)) {
20129126SWyllys.Ingersoll@Sun.COM (void) reload_token_object(hContext, obj);
20139126SWyllys.Ingersoll@Sun.COM obj->count_hi = te->count_hi;
20149126SWyllys.Ingersoll@Sun.COM obj->count_lo = te->count_lo;
20159126SWyllys.Ingersoll@Sun.COM }
20169126SWyllys.Ingersoll@Sun.COM
20179126SWyllys.Ingersoll@Sun.COM next = node->next;
20189126SWyllys.Ingersoll@Sun.COM index++;
20199126SWyllys.Ingersoll@Sun.COM } else {
20209126SWyllys.Ingersoll@Sun.COM DL_NODE *new_node = NULL;
20219126SWyllys.Ingersoll@Sun.COM OBJECT *new_obj = NULL;
20229126SWyllys.Ingersoll@Sun.COM
20239126SWyllys.Ingersoll@Sun.COM new_obj = (OBJECT *)malloc(sizeof (OBJECT));
20249126SWyllys.Ingersoll@Sun.COM (void) memset(new_obj, 0x0, sizeof (OBJECT));
20259126SWyllys.Ingersoll@Sun.COM
20269126SWyllys.Ingersoll@Sun.COM (void) memcpy(new_obj->name, te->name, 8);
20279126SWyllys.Ingersoll@Sun.COM (void) reload_token_object(hContext, new_obj);
20289126SWyllys.Ingersoll@Sun.COM
20299126SWyllys.Ingersoll@Sun.COM new_node = (DL_NODE *)malloc(sizeof (DL_NODE));
20309126SWyllys.Ingersoll@Sun.COM new_node->data = new_obj;
20319126SWyllys.Ingersoll@Sun.COM
20329126SWyllys.Ingersoll@Sun.COM new_node->next = node->next;
20339126SWyllys.Ingersoll@Sun.COM node->next = new_node;
20349126SWyllys.Ingersoll@Sun.COM new_node->prev = node;
20359126SWyllys.Ingersoll@Sun.COM
20369126SWyllys.Ingersoll@Sun.COM next = new_node->next;
20379126SWyllys.Ingersoll@Sun.COM index++;
20389126SWyllys.Ingersoll@Sun.COM }
20399126SWyllys.Ingersoll@Sun.COM
20409126SWyllys.Ingersoll@Sun.COM node = next;
20419126SWyllys.Ingersoll@Sun.COM }
20429126SWyllys.Ingersoll@Sun.COM
20439126SWyllys.Ingersoll@Sun.COM if ((node == NULL) && (index < global_shm->num_publ_tok_obj)) {
20449126SWyllys.Ingersoll@Sun.COM OBJECT *new_obj = NULL;
20459126SWyllys.Ingersoll@Sun.COM unsigned int i;
20469126SWyllys.Ingersoll@Sun.COM
20479126SWyllys.Ingersoll@Sun.COM for (i = index; i < global_shm->num_publ_tok_obj; i++) {
20489126SWyllys.Ingersoll@Sun.COM new_obj = (OBJECT *)malloc(sizeof (OBJECT));
20499126SWyllys.Ingersoll@Sun.COM (void) memset(new_obj, 0x0, sizeof (OBJECT));
20509126SWyllys.Ingersoll@Sun.COM
20519126SWyllys.Ingersoll@Sun.COM te = &global_shm->publ_tok_objs[index];
20529126SWyllys.Ingersoll@Sun.COM
20539126SWyllys.Ingersoll@Sun.COM (void) memcpy(new_obj->name, te->name, 8);
20549126SWyllys.Ingersoll@Sun.COM (void) reload_token_object(hContext, new_obj);
20559126SWyllys.Ingersoll@Sun.COM
20569126SWyllys.Ingersoll@Sun.COM publ_token_obj_list = dlist_add_as_last(
20579126SWyllys.Ingersoll@Sun.COM publ_token_obj_list, new_obj);
20589126SWyllys.Ingersoll@Sun.COM }
20599126SWyllys.Ingersoll@Sun.COM } else if ((node != NULL) && (index >= global_shm->num_publ_tok_obj)) {
20609126SWyllys.Ingersoll@Sun.COM while (node) {
20619126SWyllys.Ingersoll@Sun.COM obj = (OBJECT *)node->data;
20629126SWyllys.Ingersoll@Sun.COM
20639126SWyllys.Ingersoll@Sun.COM rc = object_mgr_find_in_map2(hContext, obj, &handle);
20649126SWyllys.Ingersoll@Sun.COM if (rc == CKR_OK) {
20659126SWyllys.Ingersoll@Sun.COM (void) object_mgr_remove_from_map(handle);
20669126SWyllys.Ingersoll@Sun.COM }
20679126SWyllys.Ingersoll@Sun.COM (void) object_free(obj);
20689126SWyllys.Ingersoll@Sun.COM
20699126SWyllys.Ingersoll@Sun.COM next = node->next;
20709126SWyllys.Ingersoll@Sun.COM publ_token_obj_list = dlist_remove_node(
20719126SWyllys.Ingersoll@Sun.COM publ_token_obj_list, node);
20729126SWyllys.Ingersoll@Sun.COM
20739126SWyllys.Ingersoll@Sun.COM node = next;
20749126SWyllys.Ingersoll@Sun.COM }
20759126SWyllys.Ingersoll@Sun.COM }
20769126SWyllys.Ingersoll@Sun.COM
20779126SWyllys.Ingersoll@Sun.COM return (CKR_OK);
20789126SWyllys.Ingersoll@Sun.COM }
20799126SWyllys.Ingersoll@Sun.COM
20809126SWyllys.Ingersoll@Sun.COM static CK_RV
object_mgr_update_priv_tok_obj_from_shm(TSS_HCONTEXT hContext)20819126SWyllys.Ingersoll@Sun.COM object_mgr_update_priv_tok_obj_from_shm(TSS_HCONTEXT hContext)
20829126SWyllys.Ingersoll@Sun.COM {
20839126SWyllys.Ingersoll@Sun.COM DL_NODE * node = NULL;
20849126SWyllys.Ingersoll@Sun.COM DL_NODE * next = NULL;
20859126SWyllys.Ingersoll@Sun.COM TOK_OBJ_ENTRY * te = NULL;
20869126SWyllys.Ingersoll@Sun.COM OBJECT * obj = NULL;
20879126SWyllys.Ingersoll@Sun.COM CK_OBJECT_HANDLE handle;
20889126SWyllys.Ingersoll@Sun.COM CK_ULONG index;
20899126SWyllys.Ingersoll@Sun.COM int val;
20909126SWyllys.Ingersoll@Sun.COM CK_RV rc;
20919126SWyllys.Ingersoll@Sun.COM
20929126SWyllys.Ingersoll@Sun.COM node = priv_token_obj_list;
20939126SWyllys.Ingersoll@Sun.COM index = 0;
20949126SWyllys.Ingersoll@Sun.COM
20959126SWyllys.Ingersoll@Sun.COM if (! (global_login_state == CKS_RW_USER_FUNCTIONS ||
20969126SWyllys.Ingersoll@Sun.COM global_login_state == CKS_RO_USER_FUNCTIONS)) {
20979126SWyllys.Ingersoll@Sun.COM return (CKR_OK);
20989126SWyllys.Ingersoll@Sun.COM }
20999126SWyllys.Ingersoll@Sun.COM
21009126SWyllys.Ingersoll@Sun.COM while ((node != NULL) && (index < global_shm->num_priv_tok_obj)) {
21019126SWyllys.Ingersoll@Sun.COM te = &global_shm->priv_tok_objs[index];
21029126SWyllys.Ingersoll@Sun.COM obj = (OBJECT *)node->data;
21039126SWyllys.Ingersoll@Sun.COM
21049126SWyllys.Ingersoll@Sun.COM val = memcmp(obj->name, te->name, 8);
21059126SWyllys.Ingersoll@Sun.COM
21069126SWyllys.Ingersoll@Sun.COM if (val < 0) {
21079126SWyllys.Ingersoll@Sun.COM rc = object_mgr_find_in_map2(hContext, obj, &handle);
21089126SWyllys.Ingersoll@Sun.COM if (rc == CKR_OK) {
21099126SWyllys.Ingersoll@Sun.COM (void) object_mgr_remove_from_map(handle);
21109126SWyllys.Ingersoll@Sun.COM }
21119126SWyllys.Ingersoll@Sun.COM (void) object_free(obj);
21129126SWyllys.Ingersoll@Sun.COM
21139126SWyllys.Ingersoll@Sun.COM next = node->next;
21149126SWyllys.Ingersoll@Sun.COM priv_token_obj_list = dlist_remove_node(
21159126SWyllys.Ingersoll@Sun.COM priv_token_obj_list, node);
21169126SWyllys.Ingersoll@Sun.COM
21179126SWyllys.Ingersoll@Sun.COM } else if (val == 0) {
21189126SWyllys.Ingersoll@Sun.COM if ((te->count_hi != obj->count_hi) ||
21199126SWyllys.Ingersoll@Sun.COM (te->count_lo != obj->count_lo)) {
21209126SWyllys.Ingersoll@Sun.COM (void) reload_token_object(hContext, obj);
21219126SWyllys.Ingersoll@Sun.COM obj->count_hi = te->count_hi;
21229126SWyllys.Ingersoll@Sun.COM obj->count_lo = te->count_lo;
21239126SWyllys.Ingersoll@Sun.COM }
21249126SWyllys.Ingersoll@Sun.COM
21259126SWyllys.Ingersoll@Sun.COM next = node->next;
21269126SWyllys.Ingersoll@Sun.COM index++;
21279126SWyllys.Ingersoll@Sun.COM } else {
21289126SWyllys.Ingersoll@Sun.COM DL_NODE *new_node = NULL;
21299126SWyllys.Ingersoll@Sun.COM OBJECT *new_obj = NULL;
21309126SWyllys.Ingersoll@Sun.COM
21319126SWyllys.Ingersoll@Sun.COM new_obj = (OBJECT *)malloc(sizeof (OBJECT));
21329126SWyllys.Ingersoll@Sun.COM (void) memset(new_obj, 0x0, sizeof (OBJECT));
21339126SWyllys.Ingersoll@Sun.COM
21349126SWyllys.Ingersoll@Sun.COM (void) memcpy(new_obj->name, te->name, 8);
21359126SWyllys.Ingersoll@Sun.COM (void) reload_token_object(hContext, new_obj);
21369126SWyllys.Ingersoll@Sun.COM
21379126SWyllys.Ingersoll@Sun.COM new_node = (DL_NODE *)malloc(sizeof (DL_NODE));
21389126SWyllys.Ingersoll@Sun.COM new_node->data = new_obj;
21399126SWyllys.Ingersoll@Sun.COM
21409126SWyllys.Ingersoll@Sun.COM new_node->next = node->next;
21419126SWyllys.Ingersoll@Sun.COM node->next = new_node;
21429126SWyllys.Ingersoll@Sun.COM new_node->prev = node;
21439126SWyllys.Ingersoll@Sun.COM
21449126SWyllys.Ingersoll@Sun.COM next = new_node->next;
21459126SWyllys.Ingersoll@Sun.COM index++;
21469126SWyllys.Ingersoll@Sun.COM }
21479126SWyllys.Ingersoll@Sun.COM
21489126SWyllys.Ingersoll@Sun.COM node = next;
21499126SWyllys.Ingersoll@Sun.COM }
21509126SWyllys.Ingersoll@Sun.COM
21519126SWyllys.Ingersoll@Sun.COM if ((node == NULL) && (index < global_shm->num_priv_tok_obj)) {
21529126SWyllys.Ingersoll@Sun.COM OBJECT *new_obj = NULL;
21539126SWyllys.Ingersoll@Sun.COM unsigned int i;
21549126SWyllys.Ingersoll@Sun.COM
21559126SWyllys.Ingersoll@Sun.COM for (i = index; i < global_shm->num_priv_tok_obj; i++) {
21569126SWyllys.Ingersoll@Sun.COM new_obj = (OBJECT *)malloc(sizeof (OBJECT));
21579126SWyllys.Ingersoll@Sun.COM (void) memset(new_obj, 0x0, sizeof (OBJECT));
21589126SWyllys.Ingersoll@Sun.COM
21599126SWyllys.Ingersoll@Sun.COM te = &global_shm->priv_tok_objs[index];
21609126SWyllys.Ingersoll@Sun.COM
21619126SWyllys.Ingersoll@Sun.COM (void) memcpy(new_obj->name, te->name, 8);
21629126SWyllys.Ingersoll@Sun.COM (void) reload_token_object(hContext, new_obj);
21639126SWyllys.Ingersoll@Sun.COM
21649126SWyllys.Ingersoll@Sun.COM priv_token_obj_list = dlist_add_as_last(
21659126SWyllys.Ingersoll@Sun.COM priv_token_obj_list, new_obj);
21669126SWyllys.Ingersoll@Sun.COM }
21679126SWyllys.Ingersoll@Sun.COM } else if ((node != NULL) && (index >= global_shm->num_priv_tok_obj)) {
21689126SWyllys.Ingersoll@Sun.COM while (node) {
21699126SWyllys.Ingersoll@Sun.COM obj = (OBJECT *)node->data;
21709126SWyllys.Ingersoll@Sun.COM
21719126SWyllys.Ingersoll@Sun.COM rc = object_mgr_find_in_map2(hContext, obj, &handle);
21729126SWyllys.Ingersoll@Sun.COM if (rc == CKR_OK) {
21739126SWyllys.Ingersoll@Sun.COM (void) object_mgr_remove_from_map(handle);
21749126SWyllys.Ingersoll@Sun.COM }
21759126SWyllys.Ingersoll@Sun.COM (void) object_free(obj);
21769126SWyllys.Ingersoll@Sun.COM
21779126SWyllys.Ingersoll@Sun.COM next = node->next;
21789126SWyllys.Ingersoll@Sun.COM priv_token_obj_list = dlist_remove_node(
21799126SWyllys.Ingersoll@Sun.COM priv_token_obj_list, node);
21809126SWyllys.Ingersoll@Sun.COM
21819126SWyllys.Ingersoll@Sun.COM node = next;
21829126SWyllys.Ingersoll@Sun.COM }
21839126SWyllys.Ingersoll@Sun.COM }
21849126SWyllys.Ingersoll@Sun.COM
21859126SWyllys.Ingersoll@Sun.COM return (CKR_OK);
21869126SWyllys.Ingersoll@Sun.COM }
21879126SWyllys.Ingersoll@Sun.COM
21889126SWyllys.Ingersoll@Sun.COM static CK_RV
object_mgr_update_from_shm(TSS_HCONTEXT hContext)21899126SWyllys.Ingersoll@Sun.COM object_mgr_update_from_shm(TSS_HCONTEXT hContext)
21909126SWyllys.Ingersoll@Sun.COM {
21919126SWyllys.Ingersoll@Sun.COM (void) object_mgr_update_publ_tok_obj_from_shm(hContext);
21929126SWyllys.Ingersoll@Sun.COM (void) object_mgr_update_priv_tok_obj_from_shm(hContext);
21939126SWyllys.Ingersoll@Sun.COM
21949126SWyllys.Ingersoll@Sun.COM return (CKR_OK);
21959126SWyllys.Ingersoll@Sun.COM }
21969126SWyllys.Ingersoll@Sun.COM
21979126SWyllys.Ingersoll@Sun.COM /*ARGSUSED*/
21989126SWyllys.Ingersoll@Sun.COM CK_BBOOL
object_mgr_purge_map(SESSION * sess,SESS_OBJ_TYPE type)21999126SWyllys.Ingersoll@Sun.COM object_mgr_purge_map(
22009126SWyllys.Ingersoll@Sun.COM SESSION *sess,
22019126SWyllys.Ingersoll@Sun.COM SESS_OBJ_TYPE type)
22029126SWyllys.Ingersoll@Sun.COM {
22039126SWyllys.Ingersoll@Sun.COM DL_NODE *node = NULL;
22049126SWyllys.Ingersoll@Sun.COM DL_NODE *next = NULL;
22059126SWyllys.Ingersoll@Sun.COM
22069126SWyllys.Ingersoll@Sun.COM if (pthread_rwlock_wrlock(&obj_list_rw_mutex)) {
22079126SWyllys.Ingersoll@Sun.COM return (CKR_FUNCTION_FAILED);
22089126SWyllys.Ingersoll@Sun.COM }
22099126SWyllys.Ingersoll@Sun.COM node = object_map;
22109126SWyllys.Ingersoll@Sun.COM while (node) {
22119126SWyllys.Ingersoll@Sun.COM OBJECT_MAP *map = (OBJECT_MAP *)node->data;
22129126SWyllys.Ingersoll@Sun.COM OBJECT *obj = (OBJECT *)map->ptr;
22139126SWyllys.Ingersoll@Sun.COM next = node->next;
22149126SWyllys.Ingersoll@Sun.COM if (type == PRIVATE) {
22159126SWyllys.Ingersoll@Sun.COM if (object_is_private(obj)) {
22169126SWyllys.Ingersoll@Sun.COM object_map = dlist_remove_node(
22179126SWyllys.Ingersoll@Sun.COM object_map, node);
22189126SWyllys.Ingersoll@Sun.COM free(map);
22199126SWyllys.Ingersoll@Sun.COM }
22209126SWyllys.Ingersoll@Sun.COM }
22219126SWyllys.Ingersoll@Sun.COM if (type == PUBLIC) {
22229126SWyllys.Ingersoll@Sun.COM if (object_is_public(obj)) {
22239126SWyllys.Ingersoll@Sun.COM object_map = dlist_remove_node(
22249126SWyllys.Ingersoll@Sun.COM object_map, node);
22259126SWyllys.Ingersoll@Sun.COM free(map);
22269126SWyllys.Ingersoll@Sun.COM }
22279126SWyllys.Ingersoll@Sun.COM }
22289126SWyllys.Ingersoll@Sun.COM node = next;
22299126SWyllys.Ingersoll@Sun.COM }
22309126SWyllys.Ingersoll@Sun.COM (void) pthread_rwlock_unlock(&obj_list_rw_mutex);
22319126SWyllys.Ingersoll@Sun.COM
22329126SWyllys.Ingersoll@Sun.COM return (TRUE);
22339126SWyllys.Ingersoll@Sun.COM }
2234