Retail products


Traffic interception SDK

Control every TCP/IP network connection

  • Route connections via proxy
  • Redirect connections and modify the data
  • Block connections and applications
SSL interception SDK

View SSL in plaintext and modify it

  • View the SSL stream decrypted in plaintext
  • Redirect SSL connection and modify decrypted data
  • Browser shows "SSL lock" without warnings

Documentation


lspmap.cpp File Reference

#include "instlsp.h"

Include dependency graph for lspmap.cpp:

Go to the source code of this file.


Functions

void PrintProviders (WINSOCK_CATALOG Catalog, BOOL bLayeredOnly, BOOL bVerbose)
LSP_ENTRYBuildLspMap (WSAPROTOCOL_INFOW *pProviders, int iProviderCount, int *pLspCount)
void PrintLspMap (LSP_ENTRY *pLspMap, int iLspCount)
void FreeLspMap (LSP_ENTRY *pLspMap, int iLspCount)
int LspDependencyCheck (LSP_ENTRY *pLspMap, int iLspCount)
void UpdateLspMap (LSP_ENTRY *pLspMap, DWORD dwOldValue, DWORD dwNewValue)
void MapNewEntriesToOld (LSP_ENTRY *pEntry, WSAPROTOCOL_INFOW *pProvider, int iProviderCount)
int AddGuidToLspEntry (LSP_ENTRY *entry, GUID *guid, int *lpErrno)
void UpdateProviderOrder (LSP_ENTRY *UpdatedEntry, DWORD *OrderArray, int ArrayCount)
int MaxLayeredChainCount (LSP_ENTRY *pLspMap, int LspCount)

Function Documentation

int AddGuidToLspEntry ( LSP_ENTRY entry,
GUID *  guid,
int *  lpErrno 
)

Definition at line 853 of file lspmap.cpp.

00858 {
00859     BOOL    bFound;
00860     int     rc,
00861             i;
00862 
00863     if ( 0 == entry->Count )
00864     {
00865         entry->LayeredGuids = (GUID *) LspAlloc(
00866                 sizeof( GUID ),
00867                 lpErrno 
00868                 );
00869         if ( NULL == entry->LayeredGuids )
00870         {
00871             fprintf( stderr, "AddGuidToLspEntry: LspAlloc failed: %d\n", *lpErrno );
00872             goto cleanup;
00873         }
00874 
00875         memcpy( &entry->LayeredGuids[ 0 ], guid, sizeof( GUID ) );
00876 
00877         entry->LayeredGuidCount++;
00878     }
00879     else
00880     {
00881         // See if we've already seen this guid
00882         bFound = FALSE;
00883         for(i=0; i < entry->LayeredGuidCount ;i++)
00884         {
00885             rc = memcmp( &entry->LayeredGuids[ i ], guid, sizeof( GUID ) );
00886             if ( 0 == rc )
00887             {
00888                 bFound = TRUE;
00889                 break;
00890             }
00891         }
00892         if ( FALSE == bFound )
00893         {
00894             GUID    *tmpguid = NULL;
00895 
00896             // New GUID -- we need to add it to the array
00897             tmpguid = (GUID *) LspAlloc(
00898                     sizeof( GUID ) * ( entry->LayeredGuidCount + 1 ),
00899                     lpErrno
00900                     );
00901             if ( NULL == tmpguid )
00902             {
00903                 fprintf( stderr, "AddGuidToLspEntry: LspAlloc failed: %d\n", *lpErrno );
00904                 goto cleanup;
00905             }
00906 
00907             memcpy( tmpguid, entry->LayeredGuids, sizeof(GUID) * entry->LayeredGuidCount );
00908 
00909             memcpy( &tmpguid[ entry->LayeredGuidCount ], guid, sizeof( GUID ) );
00910 
00911             LspFree( entry->LayeredGuids );
00912 
00913             entry->LayeredGuids = tmpguid;
00914             entry->LayeredGuidCount++;
00915         }
00916     }
00917 
00918     return NO_ERROR;
00919 
00920 cleanup:
00921 
00922     return SOCKET_ERROR;
00923 }

LSP_ENTRY* BuildLspMap ( WSAPROTOCOL_INFOW *  pProviders,
int  iProviderCount,
int *  pLspCount 
)

Definition at line 110 of file lspmap.cpp.

00115 {
00116     LSP_ENTRY *pLsps = NULL,
00117                lsptmp;
00118     DWORD     *pBaseList = NULL;
00119     int        iLspCount = 0,
00120                iSortLspCount = 0,
00121                iOrphanCount = 0,
00122                iBaseCount = 0,
00123                iProviderPathLen,
00124                ErrorCode,
00125                LspOrder,
00126                start,
00127                end,
00128                idx,
00129                rc,
00130                i, j, k;
00131 
00132     // Retrieve how many orphaned chain entries are present
00133     iOrphanCount = CountOrphanedChainEntries( pProviders, iProviderCount );
00134 
00135     // Retrieve the LSP count
00136     iSortLspCount = iLspCount = GetProviderCount( pProviders, iProviderCount, LAYERED_PROTOCOL );
00137 
00138     if ( ( 0 == iOrphanCount ) && ( 0 == iLspCount ) )
00139     {
00140         fprintf( stderr, "BuildLspMap: No LSP installed on the system!\n");
00141         goto cleanup;
00142     }
00143 
00144     // If orphaned entries are present, create another LSP_ENTRY and put all orphaned
00145     //      entries there.
00146     if ( iOrphanCount > 0 )
00147         iLspCount++;
00148 
00149     // Allocate space for our structure which represents the LSPs installed
00150     pLsps = (LSP_ENTRY *) LspAlloc(
00151             sizeof( LSP_ENTRY ) * iLspCount,
00152            &ErrorCode
00153             );
00154     if ( NULL == pLsps )
00155     {
00156         fprintf( stderr, "BuildLspMap: LspAlloc failed: %d\n", ErrorCode );
00157         goto cleanup;
00158     }
00159 
00160     // If orphaned entries are present, allocate space to hold them
00161     if ( iOrphanCount > 0 )
00162     {
00163         pLsps[ iLspCount-1 ].LayeredEntries = (WSAPROTOCOL_INFOW *)LspAlloc(
00164                 sizeof(WSAPROTOCOL_INFOW) * iOrphanCount, &ErrorCode );
00165         if ( NULL == pLsps[ iLspCount-1 ].LayeredEntries )
00166         {
00167             fprintf( stderr, "BuildLspMap: LspAlloc failed: %d\n", ErrorCode );
00168             goto cleanup;
00169         }
00170 
00171         pLsps[ iLspCount-1 ].OrphanedEntries = TRUE;
00172         pLsps[ iLspCount-1 ].Count = iOrphanCount;
00173 
00174         //
00175         // Find the orphaned entries and save them off
00176         //
00177         idx = 0;
00178         for(i=0; i < iProviderCount ;i++)
00179         {
00180             // Only investigate protocol chain entries (i.e. chainlen > 1)
00181             if ( pProviders[ i ].ProtocolChain.ChainLen > 1 )
00182             {
00183                 // Walk the catalog and look for the dummy entry (i.e. the ID in 
00184                 //    chain entry 0)
00185                 for(j=0; j < iProviderCount ;j++) 
00186                 {
00187                     if ( i == j )
00188                         continue;
00189 
00190                     if ( pProviders[ i ].ProtocolChain.ChainEntries[ 0 ] ==
00191                          pProviders[ j ].dwCatalogEntryId )
00192                     {
00193                         break;
00194                     }
00195                 }
00196                 if ( j >= iProviderCount )
00197                 {
00198                     // If j is past iProviderCount, no match was found so this is
00199                     //    an orphaned entry...save it off
00200                     memcpy( &pLsps[ iLspCount-1 ].LayeredEntries[ idx ],
00201                             &pProviders[ i ],
00202                              sizeof( WSAPROTOCOL_INFOW )
00203                           );
00204                     rc = AddGuidToLspEntry( &pLsps[ iLspCount-1 ], &pProviders[ i ].ProviderId,
00205                             &ErrorCode );
00206                     if ( SOCKET_ERROR == rc )
00207                     {
00208                         fprintf( stderr, "BuildLspMap: AddGuidToLspEntry failed: %d\n", ErrorCode );
00209                         goto cleanup;
00210                     }
00211                         
00212                     idx++;
00213                 }
00214             }
00215         }
00216     }
00217 
00218     //
00219     // Build a list of the valid LSPs installed on the system
00220     //
00221     idx = 0;
00222     for(i=0; i < iProviderCount ;i++)
00223     {
00224         if ( LAYERED_PROTOCOL == pProviders[ i ].ProtocolChain.ChainLen )
00225         {
00226             // Copy the dummy entry
00227             memcpy( &pLsps[ idx ].DummyEntry, &pProviders[ i ], sizeof( WSAPROTOCOL_INFOW ) );
00228 
00229             // Get the DLL path
00230             iProviderPathLen = MAX_PATH-1;
00231             rc = WSCGetProviderPath(
00232                     &pLsps[ idx ].DummyEntry.ProviderId,
00233                      pLsps[ idx ].wszLspDll,
00234                     &iProviderPathLen,
00235                     &ErrorCode
00236                      );
00237             if ( SOCKET_ERROR == rc )
00238             {
00239                 fprintf( stderr, "BuildLspMap: WSCGetProviderPath failed: %d\n", ErrorCode );
00240                 goto cleanup;
00241             }
00242 
00243             //
00244             // Now go find all the layered entries associated with the dummy provider
00245             //
00246 
00247             // First get the count
00248             for(j=0; j < iProviderCount ;j++)
00249             {
00250                 //
00251                 // Compare only the first entry against the dummy ID. Otherwise, 
00252                 //    we may pick up more than the provider's owned by this LSP 
00253                 //    (it may pick up other providers layered over this LSP.
00254                 //
00255                 if ( ( pProviders[ j ].ProtocolChain.ChainLen > 1 ) &&
00256                      ( pProviders[ j ].ProtocolChain.ChainEntries[ 0 ] ==
00257                        pLsps[ idx ].DummyEntry.dwCatalogEntryId ) 
00258                    )
00259                 // if ( IsIdInChain( &pProviders[ j ], pLsps[ idx ].DummyEntry.dwCatalogEntryId ) )
00260                 {
00261                     pLsps[idx].Count++;
00262                 }
00263             }
00264 
00265             // Allocate space
00266             pLsps[ idx ].LayeredEntries = (WSAPROTOCOL_INFOW *) LspAlloc(
00267                     sizeof( WSAPROTOCOL_INFOW ) * pLsps[ idx ].Count,
00268                    &ErrorCode
00269                     );
00270             if ( NULL == pLsps[ idx ].LayeredEntries )
00271             {
00272                 fprintf( stderr, "BuildLspMap: LspAlloc failed: %d\n", ErrorCode );
00273                 goto cleanup;
00274             }
00275 
00276             pLsps[ idx ].LayerChanged = (int *) LspAlloc(
00277                     sizeof( int ) * pLsps[ idx ].Count,
00278                    &ErrorCode
00279                     );
00280             if ( NULL == pLsps[ idx ].LayerChanged )
00281             {
00282                 fprintf( stderr, "BuildLspMap: LspAlloc failed: %d\n", ErrorCode );
00283                 goto cleanup;
00284             }
00285 
00286             // Now go find the entries
00287             pLsps[idx].Count = 0;
00288             for(j=0; j < iProviderCount ;j++)
00289             {
00290                 if ( ( pProviders[ j ].ProtocolChain.ChainLen > 1 ) &&
00291                      ( pProviders[ j ].ProtocolChain.ChainEntries[ 0 ] ==
00292                        pLsps[ idx ].DummyEntry.dwCatalogEntryId ) 
00293                    )
00294                 {
00295                     memcpy( 
00296                            &pLsps[ idx ].LayeredEntries[pLsps[ idx ].Count],
00297                            &pProviders[ j ],
00298                             sizeof( WSAPROTOCOL_INFOW )
00299                             );
00300 
00301                     pLsps[idx].MaxChainLength = MAX( 
00302                             pLsps[ idx ].MaxChainLength,
00303                             pLsps[ idx ].LayeredEntries[ pLsps[idx].Count ].ProtocolChain.ChainLen 
00304                             );
00305 
00306                     // Mark this entry as visited
00307                     pProviders[ j ].dwProviderReserved = 1;
00308 
00309                     // Keep track of how many GUIDs are used to install the layered entries
00310                     rc = AddGuidToLspEntry( &pLsps[ idx ], &pProviders[ j ].ProviderId, &ErrorCode );
00311                     if ( SOCKET_ERROR == rc )
00312                     {
00313                         fprintf( stderr, "BuildLspMap: AddGuidToLspEntry failed: %d\n", ErrorCode );
00314                         goto cleanup;
00315                     }
00316 
00317                     pLsps[ idx ].Count++;
00318                 }
00319             }
00320 
00321             pLsps[ idx ].LspOrder = MAX_PROTOCOL_CHAIN;
00322 
00323             idx++;      // Increment index into the map
00324         }
00325     }
00326 
00327     //
00328     // We now have an array of "LSPs" -- now order them
00329     //
00330 
00331     // First get a list of base provider IDs
00332     iBaseCount = GetProviderCount( pProviders, iProviderCount, BASE_PROTOCOL );
00333     if ( 0 == iBaseCount )
00334     {
00335         fprintf( stderr, "BuildLspMap: GetProviderCount(BASE_PROTOCOL) returned zero!\n" );
00336         goto cleanup;
00337     }
00338 
00339     // Allocate space for the array of base provider ID's
00340     pBaseList = (DWORD *) LspAlloc(
00341             sizeof( DWORD ) * iBaseCount,
00342            &ErrorCode
00343             );
00344     if ( NULL == pBaseList )
00345     {
00346         fprintf( stderr, "BuildLspMap: HeapAlloc failed: %d\n", ErrorCode );
00347         goto cleanup;
00348     }
00349 
00350     //
00351     // Copy the base provider ID's to our array -- this array contains the catalog
00352     // IDs of only base providers which will be used next to determine the order
00353     // in which LSPs were installed.
00354     //
00355     idx = 0;
00356     for(i=0; i < iProviderCount ;i++)
00357     {
00358         if ( BASE_PROTOCOL == pProviders[ i ].ProtocolChain.ChainLen )
00359         {
00360             pBaseList[ idx++ ] = pProviders[ i ].dwCatalogEntryId;
00361         }
00362     }
00363 
00364     //
00365     // For each layered protocol entry of an LSP find the lowest index in the protocol
00366     // chain where a base provider resides. A protocol chain should always terminate
00367     // in a base provider.
00368     //
00369     for(LspOrder = 1; LspOrder < MAX_PROTOCOL_CHAIN ;LspOrder++)
00370     {
00371         for(i=0; i < iSortLspCount ;i++)
00372         {
00373             for(j=0; j < pLsps[ i ].Count ;j++)
00374             {
00375                 for(k=0; k < iBaseCount ;k++)
00376                 {
00377                     if ( pLsps[ i ].LayeredEntries[ j ].ProtocolChain.ChainEntries[ LspOrder ] ==
00378                          pBaseList[ k ] )
00379                     {
00380                         pLsps[ i ].LspOrder = MIN( pLsps[ i ].LspOrder, LspOrder );
00381                         break;
00382                     }
00383                 }
00384             }
00385         }
00386     }
00387 
00388     //
00389     // Sort the entries according to the LspOrder field
00390     //
00391     for(i=0; i < iSortLspCount ;i++)
00392     {
00393         for(j=i; j < iSortLspCount ;j++)
00394         {
00395             if ( pLsps[ i ].LspOrder > pLsps[ j ].LspOrder )
00396             {
00397                 // Exchange positions
00398                 memcpy( &lsptmp,     &pLsps[ i ], sizeof( LSP_ENTRY ) );
00399                 memcpy( &pLsps[ i ], &pLsps[ j ], sizeof( LSP_ENTRY ) );
00400                 memcpy( &pLsps[ j ], &lsptmp,     sizeof( LSP_ENTRY ) );
00401             }
00402         }
00403     }
00404 
00405     //
00406     // Now need to sort by MaxChainLength withing the LspOrder groupings
00407     //
00408     for(LspOrder=1; LspOrder < MAX_PROTOCOL_CHAIN ;LspOrder++)
00409     {
00410         // Find the start and end positions within the array for the given
00411         // LspOrder value
00412         start = -1;
00413         end   = -1;
00414 
00415         for(i=0; i < iSortLspCount ;i++)
00416         {
00417             if ( pLsps[ i ].LspOrder == LspOrder )
00418             {
00419                 start = i;
00420                 break;
00421             }
00422         }
00423 
00424         //
00425         // Find the end position which is the LSP Map entry whose LspOrder
00426         // value doesn't match the current one. This will give us the range
00427         // of LSP entries whose LspOrder value is identical -- we need to
00428         // sort the LSPs of the same LspOrder according to the MaxChainLength
00429         //
00430         if ( -1 != start )
00431         {
00432             for(j=start; j < iSortLspCount ;j++)
00433             {
00434                 if ( pLsps[ j ].LspOrder != LspOrder )
00435                 {
00436                     end = j - 1;
00437                     break;
00438                 }
00439             }
00440         }
00441         
00442         //
00443         // If the following is true then all entries have the same order
00444         // value. We still need to sort by MaxChainLength so set the end
00445         // to the last LSP 
00446         //
00447         if ( ( -1 != start ) && ( -1 == end ) )
00448         {
00449             end = iSortLspCount - 1;
00450         }
00451 
00452         if ( ( -1 != start ) && ( -1 != end ) )
00453         {
00454             for(i=start; i < end ;i++)
00455             {
00456                 for(j=i; j < end ;j++)
00457                 {
00458                     if ( pLsps[ i ].MaxChainLength > pLsps[ j ].MaxChainLength )
00459                     {
00460                         memcpy( &lsptmp,     &pLsps[ i ], sizeof( LSP_ENTRY ) );
00461                         memcpy( &pLsps[ i ], &pLsps[ j ], sizeof( LSP_ENTRY ) );
00462                         memcpy( &pLsps[ j ], &lsptmp,     sizeof( LSP_ENTRY ) );
00463                     }
00464                 }
00465             }
00466         }
00467     }
00468 
00469     // Add the LSP dependency info to the map
00470     rc = LspDependencyCheck( pLsps, iSortLspCount );
00471     if ( SOCKET_ERROR == rc )
00472     {
00473         FreeLspMap( pLsps, iLspCount );
00474         pLsps = NULL;
00475         iLspCount = 0;
00476         goto cleanup;
00477     }
00478 
00479 cleanup:
00480     
00481     if ( NULL != pLspCount )
00482         *pLspCount = iLspCount;
00483 
00484     if ( NULL != pBaseList )
00485         LspFree( pBaseList );
00486 
00487     return pLsps;
00488 }

void FreeLspMap ( LSP_ENTRY pLspMap,
int  iLspCount 
)

Definition at line 583 of file lspmap.cpp.

00587 {
00588     int     i;
00589 
00590     for(i=0; i < iLspCount ;i++)
00591     {
00592         // Free the layered providers first
00593         if ( NULL != pLspMap[ i ].LayeredEntries )
00594             LspFree( pLspMap[ i ].LayeredEntries );
00595 
00596         if ( NULL != pLspMap[ i ].LayeredGuids )
00597             LspFree( pLspMap[ i ].LayeredGuids );
00598 
00599         if ( NULL != pLspMap[ i ].LayerChanged )
00600             LspFree( pLspMap[ i ].LayerChanged );
00601 
00602         if ( NULL != pLspMap[ i ].DependentLspIndexArray )
00603             LspFree( pLspMap[ i ].DependentLspIndexArray );
00604     }
00605     LspFree( pLspMap );
00606 }

int LspDependencyCheck ( LSP_ENTRY pLspMap,
int  iLspCount 
)

Definition at line 621 of file lspmap.cpp.

00625 {
00626     BOOL        bDependent;
00627     int         iCheckLspIndex = 0,
00628                 ret = SOCKET_ERROR,
00629                *tmpArray = NULL,
00630                 ErrorCode,
00631                 i, j, k, l;
00632 
00633     // For each LSP entry, find its dependencies
00634     for(i=0; i < iLspCount ;i++)
00635     {
00636         iCheckLspIndex = i;
00637 
00638         // Search all other LSPs for dependencies on this entry
00639         for(j=0; j < iLspCount ;j++)
00640         {
00641             // Skip checking against the same one were currently looking at
00642             if ( j == iCheckLspIndex )
00643                 continue;
00644 
00645             bDependent = FALSE;
00646 
00647             // Check the dummy catalog entry against all the chains for the LSP we're
00648             // currently looking at
00649             for(k=0; k < pLspMap[ j ].Count ;k++)
00650             {
00651                 if ( IsIdInChain(
00652                            &pLspMap[ j ].LayeredEntries[ k ],
00653                             pLspMap[ iCheckLspIndex ].DummyEntry.dwCatalogEntryId )
00654                    )
00655                 {
00656                     // Allocate an array for the dependent LSP indices
00657                     tmpArray = (int *) LspAlloc(
00658                             sizeof( int ) * ( pLspMap[ iCheckLspIndex ].DependentCount + 1),
00659                            &ErrorCode
00660                             );
00661                     if ( NULL == tmpArray )
00662                     {
00663                         fprintf( stderr, "CheckLspDependency: LspAlloc failed: %d\n", ErrorCode );
00664                         goto cleanup;
00665                     }
00666 
00667                     // If one already exists, copy the existing array into the new one
00668                     if ( NULL != pLspMap[ iCheckLspIndex ].DependentLspIndexArray )
00669                     {
00670                         memcpy( 
00671                                 tmpArray + 1,
00672                                 pLspMap[ iCheckLspIndex ].DependentLspIndexArray,
00673                                 sizeof( int ) * pLspMap[ iCheckLspIndex ].DependentCount
00674                                 );
00675 
00676                         // Free the existing array
00677                         LspFree( pLspMap[ iCheckLspIndex ].DependentLspIndexArray );
00678                     }
00679                     
00680                     // Assign the new array and increment the count
00681                     pLspMap[ iCheckLspIndex ].DependentLspIndexArray = tmpArray;
00682                     pLspMap[ iCheckLspIndex ].DependentLspIndexArray[ 0 ] = j;
00683                     pLspMap[ iCheckLspIndex ].DependentCount++;
00684 
00685                     bDependent = TRUE;
00686                 }
00687             }
00688 
00689             //
00690             // If a dependency already exists, don't bother checking the layered protocol
00691             // chains for one
00692             //
00693             if ( TRUE == bDependent )
00694                 continue;
00695 
00696             //
00697             // Now check whether each layered protocol entry ID is present in any
00698             // of the layered protocol entry chains of the LSP we're currently
00699             // looking at.
00700             //
00701             for(l=0; l < pLspMap[ iCheckLspIndex ].Count ;l++)
00702             {
00703                 bDependent = FALSE;
00704 
00705                 // Check against each layered entry
00706                 for(k=0; k < pLspMap[ j ].Count ;k++ )
00707                 {
00708                     if ( IsIdInChain(
00709                            &pLspMap[ j ].LayeredEntries[ k ],
00710                             pLspMap[ iCheckLspIndex ].LayeredEntries[ l ].dwCatalogEntryId )
00711                        )
00712                     {
00713                         {
00714                             tmpArray = (int *) LspAlloc(
00715                                     sizeof( int ) * ( pLspMap[ iCheckLspIndex ].DependentCount + 1),
00716                                     &ErrorCode
00717                                     );
00718                             if ( NULL == tmpArray )
00719                             {
00720                                 fprintf( stderr, "CheckLspDependency: LspAlloc failed: %d\n", ErrorCode );
00721                                 goto cleanup;
00722                             }
00723 
00724                             if ( NULL != pLspMap[ iCheckLspIndex ].DependentLspIndexArray )
00725                             {
00726                                 memcpy( 
00727                                         tmpArray + 1,
00728                                         pLspMap[ iCheckLspIndex ].DependentLspIndexArray,
00729                                         sizeof( int ) * pLspMap[ iCheckLspIndex ].DependentCount
00730                                       );
00731 
00732                                 LspFree( pLspMap[ iCheckLspIndex ].DependentLspIndexArray );
00733                             }
00734 
00735                             pLspMap[ iCheckLspIndex ].DependentLspIndexArray = tmpArray;
00736                             pLspMap[ iCheckLspIndex ].DependentLspIndexArray[ 0 ] = j;
00737                             pLspMap[ iCheckLspIndex ].DependentCount++;
00738 
00739                             bDependent = TRUE;
00740                             break;
00741                         }
00742                     }
00743                 }
00744 
00745                 if ( TRUE == bDependent )  
00746                     break;
00747             }
00748         }
00749     }
00750     
00751     ret = NO_ERROR;
00752 
00753 cleanup:
00754 
00755     return ret;
00756 }

void MapNewEntriesToOld ( LSP_ENTRY pEntry,
WSAPROTOCOL_INFOW *  pProvider,
int  iProviderCount 
)

Definition at line 817 of file lspmap.cpp.

00822 {
00823     int     i, j;
00824 
00825     for(i=0; i < pEntry->Count ;i++)
00826     {
00827         for(j=0; j < iProviderCount ;j++)
00828         {
00829             if ( IsEqualProtocolEntries( &pEntry->LayeredEntries[ i ], &pProvider[ j ] ) )
00830             {
00831                 pEntry->LayeredEntries[ i ].dwProviderReserved = 
00832                         pProvider[ j ].dwCatalogEntryId;
00833 
00834                 dbgprint( "Mapped old %d to new %d\n",
00835                         pEntry->LayeredEntries[ i ].dwCatalogEntryId,
00836                         pProvider[ j ].dwCatalogEntryId
00837                         );
00838 
00839                 break;
00840             }
00841         }
00842     }
00843 }

int MaxLayeredChainCount ( LSP_ENTRY pLspMap,
int  LspCount 
)

Definition at line 971 of file lspmap.cpp.

00975 {
00976     int MaxSize = 0,
00977         i;
00978 
00979     for(i=0; i < LspCount ;i++)
00980     {
00981         MaxSize = MAX( MaxSize, pLspMap[ i ].Count );
00982     }
00983 
00984     return MaxSize;
00985 }

void PrintLspMap ( LSP_ENTRY pLspMap,
int  iLspCount 
)

Definition at line 498 of file lspmap.cpp.

00502 {
00503     WCHAR   szGuidString[ MAX_PATH ];
00504     int     i, j, k;
00505 
00506     if ( NULL == pLspMap )
00507     {
00508         printf( "\tNo LSPs currently installed\n\n" );
00509         goto cleanup;
00510     }
00511   
00512     for(i=0; i < iLspCount ;i++)
00513     {
00514         if ( pLspMap[ i ].OrphanedEntries != TRUE )
00515         {
00516             // Display the LSP name and its DLL (and path)
00517             printf( "%3d LSP: %ws   DLL '%ws' ID: %d\n", 
00518                     i, 
00519                     pLspMap[ i ].DummyEntry.szProtocol,
00520                     pLspMap[ i ].wszLspDll,
00521                     pLspMap[ i ].DummyEntry.dwCatalogEntryId
00522                     );
00523 
00524             // Display the GUIDs under which the layered entries of this LSP are installed
00525             printf( "\t LSP Installed under %d GUIDs\n", pLspMap[ i ].LayeredGuidCount );
00526             for(k=0; k < pLspMap[ i ].LayeredGuidCount ;k++)
00527             {
00528                 StringFromGUID2( pLspMap[ i ].LayeredGuids[ k ], szGuidString, MAX_PATH-1 );
00529                 printf( "\t\t%ws\n", szGuidString );
00530             }
00531         }
00532         else
00533         {
00534             printf("Orphaned layered chain entries:\n");
00535         }
00536 
00537         // Display the layered entries and the protocol chains
00538         for(j=0; j < pLspMap[ i ].Count ;j++)
00539         {
00540             printf( "\t Layer %-5d \"%ws\" \n\t       Chain %d [ ", 
00541                     pLspMap[ i ].LayeredEntries[ j ].dwCatalogEntryId,
00542                     pLspMap[ i ].LayeredEntries[ j ].szProtocol,
00543                     pLspMap[ i ].LayeredEntries[ j ].ProtocolChain.ChainLen
00544                     );
00545 
00546             for(k=0; k < pLspMap[ i ].LayeredEntries[ j ].ProtocolChain.ChainLen ;k++)
00547             {
00548                 printf( "%d ", pLspMap[ i ].LayeredEntries[ j ].ProtocolChain.ChainEntries[ k ] );
00549             }
00550             printf( "]\n" );
00551         }
00552 
00553         // Display any LSPs which depend on this one (i.e. other LSPs layered over this one)
00554         printf( "\t Dependent LSPs:\n" );
00555         if ( pLspMap[ i ].DependentCount == 0 )
00556             printf( "\t\tNone\n");
00557         else
00558         {
00559             for(j=0; j < pLspMap[ i ].DependentCount ;j++)
00560             {
00561                 printf("\t\t%d %ws\n",
00562                         pLspMap[ pLspMap[ i ].DependentLspIndexArray[ j ] ].DummyEntry.dwCatalogEntryId,
00563                         pLspMap[ pLspMap[ i ].DependentLspIndexArray[ j ] ].DummyEntry.szProtocol
00564                         );
00565             }
00566         }
00567 
00568         printf( "\n" );
00569     }
00570 
00571 cleanup:
00572 
00573     return;
00574 }

void PrintProviders ( WINSOCK_CATALOG  Catalog,
BOOL  bLayeredOnly,
BOOL  bVerbose 
)

Definition at line 35 of file lspmap.cpp.

00040 {
00041     WSAPROTOCOL_INFOW  *pProtocolInfo = NULL;
00042     INT                 iProtocolCount = 0,
00043                         i;
00044 
00045     // Enumerate catalog and print it
00046     pProtocolInfo = EnumerateProviders( Catalog, &iProtocolCount );
00047     if ( NULL == pProtocolInfo )
00048     {
00049         fprintf( stderr, "PrintProviders: Unable to enumerate catalog!\n" );
00050         goto cleanup;
00051     }
00052 
00053     for(i=0; i < iProtocolCount ;i++)
00054     {
00055         if ( FALSE == bLayeredOnly )
00056         {
00057             // Print all providers
00058             if ( TRUE == bVerbose )
00059                 PrintProtocolInfo( &pProtocolInfo[ i ] );
00060             else
00061                 printf("%04d - %S\n", 
00062                         pProtocolInfo[ i ].dwCatalogEntryId,
00063                         pProtocolInfo[ i ].szProtocol
00064                         );
00065         }
00066         else if ( LAYERED_PROTOCOL == pProtocolInfo[ i ].ProtocolChain.ChainLen )
00067         {
00068             // Print only layered providers
00069             if ( TRUE == bVerbose )
00070                 PrintProtocolInfo( &pProtocolInfo[ i ] );
00071             else
00072                 printf("%04d - %S\n", 
00073                         pProtocolInfo[ i ].dwCatalogEntryId,
00074                         pProtocolInfo[ i ].szProtocol
00075                         );
00076         }
00077     }
00078     
00079 cleanup:
00080 
00081     if ( NULL != pProtocolInfo )
00082         FreeProviders( pProtocolInfo );
00083 
00084     return;
00085 }

void UpdateLspMap ( LSP_ENTRY pLspMap,
DWORD  dwOldValue,
DWORD  dwNewValue 
)

Definition at line 773 of file lspmap.cpp.

00778 {
00779     int i, j;
00780 
00781     // Go through all providers beloging to this LSP
00782     for(i=0; i < pLspMap->Count ;i++)
00783     {
00784         // Go through the protocol chain and update references if they match
00785         for(j=0; j < pLspMap->LayeredEntries[ i ].ProtocolChain.ChainLen ;j++)
00786         {
00787             if ( pLspMap->LayeredEntries[ i ].ProtocolChain.ChainEntries[ j ] == 
00788                     dwOldValue 
00789                )
00790             {
00791                 pLspMap->LayeredEntries[ i ].ProtocolChain.ChainEntries[ j ] = 
00792                         dwNewValue;
00793             }
00794         }
00795     }
00796 
00797     return;
00798 }

void UpdateProviderOrder ( LSP_ENTRY UpdatedEntry,
DWORD *  OrderArray,
int  ArrayCount 
)

Definition at line 939 of file lspmap.cpp.

00944 {
00945     int     i, j;
00946 
00947 
00948     for(i=0; i < UpdatedEntry->Count ;i++)
00949     {
00950         for(j=0; j < ArrayCount ;j++)
00951         {
00952             // Replace an occurence of the old value with the new value
00953             if ( OrderArray[ j ] == UpdatedEntry->LayeredEntries[ i ].dwCatalogEntryId )
00954             {
00955                 OrderArray[ j ] = UpdatedEntry->LayeredEntries[ i ].dwProviderReserved;
00956             }
00957         }
00958     }
00959 }