Beispiel #1
0
void CHmac32::SetKey(const Byte *key, size_t keySize)
{
  UInt32 keyTemp[kBlockSizeInWords];
  size_t i;
  for (i = 0; i < kBlockSizeInWords; i++)
    keyTemp[i] = 0;
  if(keySize > kBlockSize)
  {
    CContext sha;
    sha.Init();
    sha.Update(key, keySize);
    Byte digest[kDigestSize];
    sha.Final(digest);

    for (int i = 0 ; i < kDigestSizeInWords; i++)
      keyTemp[i] =
          ((UInt32)(digest[i * 4 + 0]) << 24) |
          ((UInt32)(digest[i * 4 + 1]) << 16) |
          ((UInt32)(digest[i * 4 + 2]) <<  8) |
          ((UInt32)(digest[i * 4 + 3]));
    keySize = kDigestSizeInWords;
  }
  else
    for (size_t i = 0; i < keySize; i++)
      keyTemp[i / 4] |= (key[i] << (24 - 8 * (i & 3)));
  for (i = 0; i < kBlockSizeInWords; i++)
    keyTemp[i] ^= 0x36363636;
  _sha.Init();
  _sha.Update(keyTemp, kBlockSizeInWords);
  for (i = 0; i < kBlockSizeInWords; i++)
    keyTemp[i] ^= 0x36363636 ^ 0x5C5C5C5C;
  _sha2.Init();
  _sha2.Update(keyTemp, kBlockSizeInWords);
}
STDMETHODIMP CPermissionChecker::HasAccess(
    BSTR bstrLocalUrl,
    VARIANT_BOOL *pfRetVal)
{
	HRESULT rc = E_FAIL;

	try
	{
		if (bstrLocalUrl == NULL || pfRetVal == NULL)
			return ::ReportError(E_POINTER);

		*pfRetVal = VARIANT_FALSE;

		CContext cxt;
		if ( cxt.Init( CContext::get_Server ) != S_OK )
		{
			return ::ReportError( E_NOINTERFACE );
		}

		// Map logical filename to a physical filesystem name
		CComBSTR bstrPhysicalFile;
		HRESULT  hr = cxt.Server()->MapPath(bstrLocalUrl, &bstrPhysicalFile);

		if (SUCCEEDED(hr))
			*pfRetVal = ::DoesUserHaveAccessToFile(bstrPhysicalFile);
		else // failed to map as URL, try as regular path
			*pfRetVal = ::DoesUserHaveAccessToFile(bstrLocalUrl);

	    rc = S_OK;
	}
	catch( alloc_err& )
	{
		rc = E_OUTOFMEMORY;
	}
	catch( ... )
	{
		rc = E_FAIL;
	}
	return rc;
}
STDMETHODIMP CAdRotator::get_GetAdvertisement(BSTR bstrVirtualPath, BSTR * pVal)
{
	SCODE rc = E_FAIL;
    
	try
	{
		USES_CONVERSION;

		CContext cxt;
		rc = cxt.Init( CContext::get_Server );
		if ( !FAILED(rc) )
		{
			CComBSTR bstrPhysicalPath;
			// determine the physical path
			if ( ( rc = cxt.Server()->MapPath( bstrVirtualPath, &bstrPhysicalPath ) ) == S_OK )
			{
				_TCHAR* szPath = OLE2T( bstrPhysicalPath );

				CAdFilePtr pAdFile = AdFile( szPath );
				
				if ( pAdFile.IsValid() )
				{
					// refresh the ad file (make sure it's up to date)
					pAdFile->Refresh();

					// block all writers
					CReader rdr( *pAdFile );

					// if the border hasn't been set, use the default from the ad file
					short nBorder;
					if ( m_nBorder < 0 )
					{
						nBorder = pAdFile->Border();
					}
					else
					{
						nBorder = m_nBorder;
					}

					CAdDescPtr pAd = pAdFile->RandomAd();
					if ( pAd.IsValid() )
					{
						// write out the HTML line for this ad
						StringOutStream ss;

						if ( m_bClickable && ( pAd->m_strLink.size() > 1 ) )
						{
							// use the href format
							ss	<< _T("<A HREF=\"") << pAdFile->Redirector()
								<< _T("?url=") << pAd->m_strLink
								<< _T("&image=") << pAd->m_strGif
								<< _T("\" ") << m_strTargetFrame << _T(">");
						}
						
						// now fill in the rest
						ss	<< _T("<IMG SRC=\"") << pAd->m_strGif
							<< _T("\" ALT=\"") << pAd->m_strAlt
							<< _T("\" WIDTH=") << pAdFile->Width()
							<< _T(" HEIGHT=") << pAdFile->Height();

						if ( pAdFile->HSpace() != CAdFile::defaultHSpace )
						{
							ss << _T(" HSPACE=") << pAdFile->HSpace();
						}
						if ( pAdFile->VSpace() != CAdFile::defaultVSpace )
						{
							ss << _T(" VSPACE=") << pAdFile->VSpace();
						}

						ss << _T(" BORDER=") << nBorder << _T(">");

						if ( m_bClickable && ( pAd->m_strLink.size() > 1 ) )
						{
							// put the trailing tag on
							ss << _T("</A>");
						}

						String str = ss.toString();
						
						if ( pVal )
						{
							if ( *pVal )
							{
								::SysFreeString( *pVal );
							}
							*pVal = T2BSTR( str.c_str() );
							THROW_IF_NULL( *pVal );
							rc = S_OK;
						}
						else
						{
							rc = E_POINTER;
						}
					}
				}
			}
		}
		else
		{
			_ASSERT(0);
			RaiseException( IDS_ERROR_NOSVR );
		}   // end if got server
	}
	catch ( alloc_err& )
	{
		rc = E_OUTOFMEMORY;
	}
	catch ( ... )
	{
		rc = E_FAIL;
	}
	return rc;
}