"Fossies" - the Fresh Open Source Software Archive

Member "muscle/util/SharedFilterSessionFactory.cpp" (8 Jun 2019, 3124 Bytes) of package /linux/privat/muscle7.30.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "SharedFilterSessionFactory.cpp" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 7.12_vs_7.13.

    1 /* This file is Copyright 2000-2013 Meyer Sound Laboratories Inc.  See the included LICENSE.txt file for details. */  
    2 
    3 #include "util/SharedFilterSessionFactory.h"
    4 #include "util/NetworkUtilityFunctions.h"
    5 #include "util/MiscUtilityFunctions.h"
    6 
    7 namespace muscle {
    8 
    9 SharedFilterSessionFactory :: SharedFilterSessionFactory(const ReflectSessionFactoryRef & slaveRef, const String & sharedMemName, bool isGrantList, bool defaultPass)
   10    : ProxySessionFactory(slaveRef)
   11    , _sharedMemName(sharedMemName)
   12    , _isGrantList(isGrantList)
   13    , _defaultPass(defaultPass)
   14 {
   15    // empty
   16 }
   17 
   18 SharedFilterSessionFactory :: ~SharedFilterSessionFactory()
   19 {
   20    // empty
   21 }
   22 
   23 AbstractReflectSessionRef SharedFilterSessionFactory :: CreateSession(const String & clientIP, const IPAddressAndPort & iap)
   24 {
   25    TCHECKPOINT;
   26    return ((GetSlave()())&&(IsAccessAllowedForIP(iap.GetIPAddress().IsStandardLoopbackDeviceAddress()?localhostIP:Inet_AtoN(clientIP())))) ? GetSlave()()->CreateSession(clientIP, iap) : AbstractReflectSessionRef();
   27 }
   28 
   29 bool SharedFilterSessionFactory :: IsAccessAllowedForIP(const IPAddress & ip) const
   30 {
   31    bool allowAccess = _defaultPass;
   32    if (ip != invalidIP)
   33    {
   34       // demand-setup the shared-memory object, and then lock it for read-only access
   35       if (((_sharedMemory.GetAreaSize() > 0)||(_sharedMemory.SetArea(_sharedMemName(), 0, false) == B_NO_ERROR))&&(_sharedMemory.LockAreaReadOnly() == B_NO_ERROR))
   36       {
   37          Queue<NetworkInterfaceInfo> ifs;
   38          bool gotIFs = false;  // we'll demand-allocate them
   39 
   40          allowAccess = !_isGrantList;  // if there is a list, you're off it unless you're on it!
   41 
   42          const IPAddress * ips = reinterpret_cast<const IPAddress *>(_sharedMemory());
   43          const uint32 numIPs = _sharedMemory.GetAreaSize()/sizeof(IPAddress);
   44          for (uint32 i=0; i<numIPs; i++)
   45          {
   46             IPAddress nextIP = ips[i];
   47 #ifdef MUSCLE_AVOID_IPV6
   48             if (nextIP == ip)
   49 #else
   50             if (nextIP.EqualsIgnoreInterfaceIndex(ip))  // FogBugz #7490
   51 #endif
   52             {
   53                allowAccess = _isGrantList;
   54                break;
   55             }
   56             else if (nextIP.IsStandardLoopbackDeviceAddress())
   57             {
   58                if (gotIFs == false)
   59                {
   60                   (void) GetNetworkInterfaceInfos(ifs);
   61                   gotIFs = true;
   62                }
   63 
   64                // Special case for the localhost IP... see if it matches any of our localhost's known IP addresses
   65                bool matchedLocal = false;
   66                for (uint32 j=0; j<ifs.GetNumItems(); j++)
   67                {
   68 #ifdef MUSCLE_AVOID_IPV6
   69                   if (ifs[j].GetLocalAddress() == ip)
   70 #else
   71                   if (ifs[j].GetLocalAddress().EqualsIgnoreInterfaceIndex(ip))  // FogBugz #7490
   72 #endif
   73                   {
   74                      allowAccess = _isGrantList;
   75                      matchedLocal = true;
   76                      break;
   77                   }
   78                }
   79                if (matchedLocal) break;
   80             }
   81          }
   82 
   83          _sharedMemory.UnlockArea(); 
   84       }
   85    }
   86    return allowAccess;
   87 }
   88 
   89 } // end namespace muscle