NSS Library Init: Difference between revisions

Line 66: Line 66:
Scenario 1.
Scenario 1.


#. Application calls NSS_Init(). NSS_Init uses configdir to decide what PKCS #11 modules to load and what databases softoken opens.
#Application calls NSS_Init(). NSS_Init uses configdir to decide what PKCS #11 modules to load and what databases softoken opens.
#. Library then calls NSS_Init(). Library ends up using whatever application already openned (in general, this ok, it make sense the the application controls what databases are used by all libraries it uses).
#Library then calls NSS_Init(). Library ends up using whatever application already openned (in general, this ok, it make sense the the application controls what databases are used by all libraries it uses).
#*< at this point only the application specified databases are open >
#*< at this point only the application specified databases are open >
 
#Library noticed that NSS was initializied already and does not call shutdown (hopefully).
3. Library noticed that NSS was initializied already and does not call shutdown (hopefully).
#Application calls shutdown. NSS shuts down. Note, if the library had not reached '3' above and continues to use NSS, BadThings(tm) happen.
 
4. Application calls shutdown. NSS shuts down. Note, if the library had not reached '3' above and continues to use NSS, BadThings(tm) happen.


Scenario 2.
Scenario 2.


1. Library calls NSS_Init(). NSS is opened based on the library's default configuration (needed because the library may be used in a non-NSS app.
#Library calls NSS_Init(). NSS is opened based on the library's default configuration (needed because the library may be used in a non-NSS app.
 
#Application calls NSS_Init(). -- none of the application config directories are opened because NSS has already been initialized.
2. Application calls NSS_Init(). -- none of the application config directories are opened because NSS has already been initialized.
#*< at this point only the library specified databases are open >
 
#Library calls NSS_Shutdown() because the library did not see any users of NSS_Init(). NSS shuts down. The application is hosed if it tries to use NSS.
< at this point only the library specified databases are open >
#Application calls shutdown. NSS shuts down (if it wasn't already shutdown from step 3). Again BadThings happen if the library didn't shutdown at step 3 and continues to use NSS.
 
3. Library calls NSS_Shutdown() because the library did not see any users of NSS_Init(). NSS shuts down. The application is hosed if it tries to use NSS.
 
4. Application calls shutdown. NSS shuts down (if it wasn't already shutdown from step 3). Again BadThings happen if the library didn't shutdown at step 3 and continues to use NSS.




Line 91: Line 85:
Scenario 1.
Scenario 1.


1. Application calls NSS_init() - Same as Scenario 1 step 1 today.
#Application calls NSS_init() - Same as Scenario 1 step 1 today.
 
#Library calls NSS_InitContext() - Application databases remain open, In addition those databases specified by the Library (that aren't already the same as those by the Application database) are opened as all. These are now visible to anyone making NSS calls.
2. Library calls NSS_InitContext() - Application databases remain open, In addition those databases specified by the Library (that aren't already the same as those by the Application database) are opened as all. These are now visible to anyone making NSS calls.
#*< at this point the union of the databases specified by the library and the application are opened>
 
#Library shutdowns calling NSS_ShutdownContext(). - NSS_ShutdownContext 'closes' the NSSInitContext and decrements the library open count. It notices that someone has called NSS_Init, so NSS is not shutdown yet. (if someone had not called NSS_Init, and the library open count had gone to zero, this call will shut down NSS).
< at this point the union of the databases specified by the library and the application are opened>
#Application calls:
 
##NSS_Shutdown() - Same effect as Scenario 1 step 4 today (NSS Shutdowns, if the library is open and still using NSS, it's hosed).
3. Library shutdowns calling NSS_ShutdownContext(). - NSS_ShutdownContext 'closes' the NSSInitContext and decrements the library open count. It notices that someone has called NSS_Init, so NSS is not shutdown yet. (if someone had not called NSS_Init, and the library open count had gone to zero, this call will shut down NSS).
##NSS_ShutdownContext(NULL) - NSS does not shutdown if there is any libraries open, but the internal nss_is_init flag that NSS_Init uses for idempotency is turned off (a future NSS_Init will try to open new databases). If all the libraries are closed, NSS shuts down normally.
 
4. Application calls:
    4a. NSS_Shutdown() - Same effect as Scenario 1 step 4 today (NSS Shutdowns, if the library is open and still using NSS, it's hosed).
    4b. NSS_ShutdownContext(NULL) - NSS does not shutdown if there is any libraries open, but the internal nss_is_init flag that NSS_Init uses for idempotency is turned off (a future NSS_Init will try to open new databases). If all the libraries are closed, NSS shuts down normally.


Scenario 2.
Scenario 2.


1. Library calls NSS_InitContext(). NSS is opened same as Scenario 2 step 1 today. Note, that the internal nss_is_init flag will not be set, the library open count is incremented and a context is returned.
#Library calls NSS_InitContext(). NSS is opened same as Scenario 2 step 1 today. Note, that the internal nss_is_init flag will not be set, the library open count is incremented and a context is returned.
 
#Application calls NSS_Init() - databases in the application's config that were not already opened are now opened. (of course the internal nss_is_init flag will now be set).
2. Application calls NSS_Init() - databases in the application's config that were not already opened are now opened. (of course the internal nss_is_init flag will now be set).
#*< at this point the union of the databases specified by the library and the application are opened>
 
#Library shuts down calling NSS_ShutdownContext(). Same as scenario 1 step 3 proposal.
< at this point the union of the databases specified by the library and the application are opened>
#Application calls a shutdown function: same as scenario 1 step 4 proposal.
 
3. Library shuts down calling NSS_ShutdownContext(). Same as scenario 1 step 3 proposal.
 
4. Application calls a shutdown function: same as scenario 1 step 4 proposal.


Note 1 things: NSS_Init and NSS_Shutdown function like the do today. Applications that use them can depend on them just like the do today.
Note 1 things: NSS_Init and NSS_Shutdown function like the do today. Applications that use them can depend on them just like the do today.
439

edits