Changeset 3404

Show
Ignore:
Timestamp:
03/06/08 15:04:29 (10 months ago)
Author:
alonbl
Message:

Convert constant SC_PKCS11_MAX_VIRTUAL_SLOTS to configuration option.

Location:
trunk
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • trunk/etc/opensc.conf.in

    r3311 r3404  
    295295app opensc-pkcs11 { 
    296296        pkcs11 { 
     297                # Maximum Number of virtual slots. 
     298                # If there are more slots than defined here, 
     299                # the remaining slots will be hidden from PKCS#11. 
     300                max_virtual_slots = 8; 
     301 
    297302                # Maximum number of slots per smart card. 
    298303                # If the card has fewer keys than defined here, 
    299304                # the remaining number of slots will be empty. 
    300                 # 
    301                 # Note that there is currently a compile time 
    302                 # maximum on the overall number of slots 
    303                 # the pkcs11 module is able to handle. 
    304305                num_slots = 4; 
    305306 
  • trunk/src/pkcs11/misc.c

    r3176 r3404  
    318318         
    319319        /* Set defaults */ 
     320        conf->pkcs11_max_virtual_slots = SC_PKCS11_DEF_MAX_VIRTUAL_SLOTS; 
    320321        conf->num_slots = SC_PKCS11_DEF_SLOTS_PER_CARD; 
    321322        conf->hide_empty_tokens = 0; 
     
    336337                return; 
    337338 
     339        conf->pkcs11_max_virtual_slots = scconf_get_int(conf_block, "max_virtual_slots", conf->pkcs11_max_virtual_slots); 
    338340        conf->num_slots = scconf_get_int(conf_block, "num_slots", conf->num_slots); 
    339341        conf->hide_empty_tokens = scconf_get_bool(conf_block, "hide_empty_tokens", 0); 
  • trunk/src/pkcs11/pkcs11-global.c

    r3402 r3404  
    3232sc_context_t *context = NULL; 
    3333struct sc_pkcs11_pool session_pool; 
    34 struct sc_pkcs11_slot virtual_slots[SC_PKCS11_MAX_VIRTUAL_SLOTS]; 
     34struct sc_pkcs11_slot *virtual_slots = NULL; 
    3535struct sc_pkcs11_card card_table[SC_PKCS11_MAX_READERS]; 
    3636struct sc_pkcs11_config sc_pkcs11_conf; 
     
    193193 
    194194        rv = sc_pkcs11_init_lock((CK_C_INITIALIZE_ARGS_PTR) pInitArgs); 
    195         if (rv != CKR_OK)   { 
    196                 sc_release_context(context); 
    197                 context = NULL; 
    198         } 
     195        if (rv != CKR_OK) 
     196                goto out; 
    199197 
    200198        /* set context options */ 
     
    214212 
    215213        first_free_slot = 0; 
     214        virtual_slots = malloc(sizeof (*virtual_slots) * sc_pkcs11_conf.pkcs11_max_virtual_slots); 
     215        if (virtual_slots == NULL) { 
     216                rv = CKR_HOST_MEMORY; 
     217                goto out; 
     218        } 
    216219        pool_initialize(&session_pool, POOL_TYPE_SESSION); 
    217         for (i=0; i<SC_PKCS11_MAX_VIRTUAL_SLOTS; i++) 
     220        for (i=0; i<sc_pkcs11_conf.pkcs11_max_virtual_slots; i++) 
    218221                slot_initialize(i, &virtual_slots[i]); 
    219222        for (i=0; i<SC_PKCS11_MAX_READERS; i++) 
     
    226229        if (context != NULL) 
    227230                sc_debug(context, "C_Initialize: result = %d\n", rv); 
     231 
     232        if (rv != CKR_OK) { 
     233                if (context != NULL) { 
     234                        sc_release_context(context); 
     235                        context = NULL; 
     236                } 
     237                /* Release and destroy the mutex */ 
     238                sc_pkcs11_free_lock(); 
     239        } 
     240 
    228241        return rv; 
    229242} 
     
    249262        for (i=0; i < (int)sc_ctx_get_reader_count(context); i++) 
    250263                card_removed(i); 
     264 
     265        if (virtual_slots) { 
     266                free(virtual_slots); 
     267                virtual_slots = NULL; 
     268        } 
    251269 
    252270        sc_release_context(context); 
     
    303321                    CK_ULONG_PTR   pulCount)      /* receives the number of slots */ 
    304322{ 
    305         CK_SLOT_ID found[SC_PKCS11_MAX_VIRTUAL_SLOTS]; 
     323        CK_SLOT_ID found[sc_pkcs11_conf.pkcs11_max_virtual_slots]; 
    306324        int i; 
    307325        CK_ULONG numMatches; 
     
    322340 
    323341        numMatches = 0; 
    324         for (i=0; i<SC_PKCS11_MAX_VIRTUAL_SLOTS; i++) { 
     342        for (i=0; i<sc_pkcs11_conf.pkcs11_max_virtual_slots; i++) { 
    325343                slot = &virtual_slots[i]; 
    326344 
  • trunk/src/pkcs11/sc-pkcs11.h

    r3086 r3404  
    6161#endif 
    6262 
    63 #define SC_PKCS11_MAX_VIRTUAL_SLOTS     8 
     63#define SC_PKCS11_DEF_MAX_VIRTUAL_SLOTS 8 
    6464#define SC_PKCS11_DEF_SLOTS_PER_CARD    4 
    6565#define SC_PKCS11_MAX_READERS           SC_MAX_READERS 
     
    9191 
    9292struct sc_pkcs11_config { 
     93        unsigned int pkcs11_max_virtual_slots; 
    9394        unsigned int num_slots; 
    9495        unsigned char hide_empty_tokens; 
     
    336337extern struct sc_context *context; 
    337338extern struct sc_pkcs11_pool session_pool; 
    338 extern struct sc_pkcs11_slot virtual_slots[SC_PKCS11_MAX_VIRTUAL_SLOTS]; 
     339extern struct sc_pkcs11_slot *virtual_slots; 
    339340extern struct sc_pkcs11_card card_table[SC_PKCS11_MAX_READERS]; 
    340341extern struct sc_pkcs11_config sc_pkcs11_conf; 
  • trunk/src/pkcs11/slot.c

    r3086 r3404  
    6464                avail = sc_pkcs11_conf.num_slots; 
    6565 
    66         if (first_free_slot + avail > SC_PKCS11_MAX_VIRTUAL_SLOTS) 
    67                 avail = SC_PKCS11_MAX_VIRTUAL_SLOTS - first_free_slot; 
     66        if (first_free_slot + avail > sc_pkcs11_conf.pkcs11_max_virtual_slots) 
     67                avail = sc_pkcs11_conf.pkcs11_max_virtual_slots - first_free_slot; 
    6868        card->first_slot = first_free_slot; 
    6969        card->max_slots = avail; 
     
    166166                CK_SLOT_ID id; 
    167167 
    168                 for (id = 0; id < SC_PKCS11_MAX_VIRTUAL_SLOTS; id++) 
     168                for (id = 0; id < sc_pkcs11_conf.pkcs11_max_virtual_slots; id++) 
    169169                        virtual_slots[id].events = 0; 
    170170        } 
     
    185185        sc_debug(context, "%d: smart card removed\n", reader); 
    186186 
    187         for (i=0; i<SC_PKCS11_MAX_VIRTUAL_SLOTS; i++) { 
     187        for (i=0; i<sc_pkcs11_conf.pkcs11_max_virtual_slots; i++) { 
    188188                if (virtual_slots[i].card && 
    189189                    virtual_slots[i].card->reader == reader) 
     
    246246                return CKR_CRYPTOKI_NOT_INITIALIZED; 
    247247 
    248         if (id < 0 || id >= SC_PKCS11_MAX_VIRTUAL_SLOTS) 
     248        if (id < 0 || id >= sc_pkcs11_conf.pkcs11_max_virtual_slots) 
    249249                return CKR_SLOT_ID_INVALID; 
    250250                 
     
    325325 
    326326        card_detect_all(); 
    327         for (id = 0; id < SC_PKCS11_MAX_VIRTUAL_SLOTS; id++) { 
     327        for (id = 0; id < sc_pkcs11_conf.pkcs11_max_virtual_slots; id++) { 
    328328                slot = &virtual_slots[id]; 
    329329                if ((slot->events & SC_EVENT_CARD_INSERTED)