--- a/terminalsecurity/SCP/SCPPatternPlugin/src/SCPPatternPlugin.cpp Tue Aug 31 16:04:06 2010 +0300
+++ b/terminalsecurity/SCP/SCPPatternPlugin/src/SCPPatternPlugin.cpp Wed Sep 01 12:27:42 2010 +0100
@@ -24,9 +24,9 @@
#include <featmgr.h>
#include "SCPPatternPlugin.h"
-#include <scppatternpluginlang.rsg>
+#include <SCPPatternPluginLang.rsg>
#include "SCP_IDs.h"
-#include <SCPServerInterface.h>
+
@@ -85,6 +85,60 @@
return;
}
+
+// ----------------------------------------------------------------------------
+// CSCPPatternPlugin::GetResource
+// GetResource, opens the localisation filesystem
+// Status : Approved
+// ----------------------------------------------------------------------------
+//
+TInt CSCPPatternPlugin::GetResource()
+ {
+ Dprint( (_L("CSCPPatternPlugin::GetResource()") ));
+ // The resource has to be loaded manually since it is not an application.
+
+ if ( iFs == NULL )
+ {
+ return KErrNotReady;
+ }
+
+ // can't use resource here because it is not added yet....
+ TFileName resourceFile;
+ resourceFile.Append( KDriveZ );
+ resourceFile.Append( SCPPatternPluginSrcFile );
+ BaflUtils::NearestLanguageFile( *iFs, resourceFile );
+
+ TRAPD( err,
+ iRf.OpenL( *iFs, resourceFile );
+ iRf.ConfirmSignatureL();
+ );
+
+ return err;
+ }
+
+// ----------------------------------------------------------------------------
+// CSCPPatternPlugin::LoadResourceLC
+// LoadResourceLC, loads the localisation resource
+// Status : Approved
+// ----------------------------------------------------------------------------
+//
+HBufC16* CSCPPatternPlugin::LoadResourceLC( TInt aResId )
+ {
+ Dprint ( ( _L( "CSCPPatternPlugin::LoadResourceLC()" ) ) );
+
+ // load the actual resource
+ HBufC8* readBuffer = iRf.AllocReadLC( aResId );
+ // as we are expecting HBufC16...
+ const TPtrC16 ptrReadBuffer( (TText16*) readBuffer->Ptr(),
+ ( readBuffer->Length() + 1 ) >> 1 );
+ HBufC16* textBuffer=HBufC16::NewL( ptrReadBuffer.Length() );
+ *textBuffer=ptrReadBuffer;
+ CleanupStack::PopAndDestroy( readBuffer ); // readBuffer
+ CleanupStack::PushL( textBuffer );
+ return textBuffer;
+ }
+
+
// ----------------------------------------------------------------------------
// CSCPPatternPlugin::~CSCPPatternPlugin
// Destructor
@@ -108,10 +162,17 @@
// Status : Approved
// ----------------------------------------------------------------------------
//
-void CSCPPatternPlugin :: HandleEventL( TInt aID, CSCPParamObject& aParam, CSCPParamObject& aOutParam )
+CSCPParamObject* CSCPPatternPlugin::HandleEvent( TInt aID, CSCPParamObject& aParam )
{
+
Dprint ( ( _L( "CSCPPatternPlugin::HandleEvent()" ) ) );
+ // Make the ParamObject for success ack, Delete later
+ CSCPParamObject* retParams = NULL;
+
+ TBool errRaised;
+ errRaised = EFalse;
+
TBool isInvalid = EFalse;
// check for Case
@@ -160,17 +221,14 @@
if ( config.Get( (RTerminalControl3rdPartySession::EPasscodeDisallowSimple),
passcodedisallowsimple ) != KErrNone )
passcodedisallowsimple = EFalse;
- Dprint( ( _L( "CSCPPatternPlugin :: HandleEventL): EPasscodeMinLength :%d, EPasscodeMaxLength :%d, "), passcodeminlength,passcodemaxlength ) );
- Dprint( ( _L( "CSCPPatternPlugin :: HandleEventL): EPasscodeMaxRepeatedCharacters :%d, EPasscodeRequireCharsAndNumbers :%d"), passcodemaxrepeatedcharacters,passcoderequirecharsandnumbers ) );
- Dprint( ( _L( "CSCPPatternPlugin :: HandleEventL): EPasscodeRequireUpperAndLower :%d,minspecialcharacters :%d "), passcoderequireupperandlower ,passcodeminspecialcharacters) );
- Dprint( ( _L( "CSCPPatternPlugin :: HandleEventL): EPasscodeConsecutiveNumbers :%d, EPasscodeDisallowSimple :%d, "), passcodeconsecutivenumbers,passcodeminspecialcharacters ) );
+
// Get the password from the paramObject
TBuf<KSCPPasscodeMaxLength> password;
if ( aParam.Get( KSCPParamPassword, password ) != KErrNone )
{
// Nothing to do anymore
break;
- }
+ }
// The first rule is to check if securitycode has any
// forbidden chars, like WhiteSpace etc...
@@ -181,7 +239,12 @@
TChar::TCategory chCat = ch.GetCategory();
if ( ch.IsSpace() )
{
- aOutParam.Set( KSCPParamStatus, KErrArgument );
+ TRAPD( err, retParams = CSCPParamObject::NewL() );
+ if ( err == KErrNone )
+ {
+ retParams->Set( KSCPParamStatus, KErrArgument );
+ }
+
argumentError = ETrue;
break;
}
@@ -201,6 +264,15 @@
passcodeminspecialcharacters != 0 ||
passcodedisallowsimple)
{
+ // Get the filesystem for Resource
+ // If fail, bail out
+ TInt errgGR = GetResource();
+ if (errgGR != KErrNone)
+ {
+ errRaised = ETrue;
+ break; // Break out
+ }
+
// Declare the Check flags
TBool istoosimilar = EFalse;
TBool consecutively = EFalse;
@@ -214,41 +286,70 @@
TInt specialCount = 0; // for passcodeminspecialcharacters
TChar temp = '1';
+
+ // Prompt buf, iNote can show only 97 chars,
+ // without ... markings.
+ HBufC* hbuf = NULL;
+
// Check for required check or not.
if (passcodeminlength != 0)
{
// check for Min lenght
if ( password.Length() < passcodeminlength )
{
- //koya: return error code to SecUi
- Dprint ( ( _L( "EDeviceLockMinlength Failed" ) ) );
- aOutParam.AddtoFailedPolices(EDeviceLockMinlength);
isInvalid = ETrue;
+ TRAP_IGNORE(
+ hbuf = LoadAndFormatResL( R_SET_SEC_CODE_MIN, &passcodeminlength )
+ );
}
+ }
+ if (!hbuf)
+ {
// Check for required check or not.
+ if (passcodemaxlength!=0)
+ {
// Check for Max Lenght
- else if ( password.Length() > passcodemaxlength )
+ if ( password.Length() > passcodemaxlength )
{
- Dprint ( ( _L( "EDeviceLockMaxlength Failed" ) ) );
- aOutParam.AddtoFailedPolices(EDeviceLockMaxlength);
isInvalid = ETrue;
+ TRAP_IGNORE(
+ hbuf = LoadAndFormatResL( R_SET_SEC_CODE_MAX, &passcodemaxlength );
+ );
+ }
}
}
+ if (!hbuf)
+ {
// Check for required check or not.
if ( passcodemaxrepeatedcharacters != 0 )
{
// Check for TooManySameChars
TRAPD( err, istoosimilar = TooManySameCharsL(password,passcodemaxrepeatedcharacters) );
if ( ( err == KErrNone ) && ( istoosimilar ) )
- {
- Dprint ( ( _L( "EDeviceLockAllowedMaxRepeatedChars Failed" ) ) );
- aOutParam.AddtoFailedPolices(EDeviceLockAllowedMaxRepeatedChars);
- isInvalid = ETrue;
- }
+ {
+ if ( passcodemaxrepeatedcharacters > 1 )
+ {
+ isInvalid = ETrue;
+ TRAP_IGNORE(
+ hbuf = LoadAndFormatResL( R_SET_SEC_CODE_REPEATED,
+ &passcodemaxrepeatedcharacters );
+ );
+ }
+ else // passcodemaxrepeatedcharacters == 1
+ {
+ isInvalid = ETrue;
+ TRAP_IGNORE(
+ hbuf = LoadAndFormatResL( R_SET_SEC_CODE_REPEATED_ONCE );
+ );
+ }
+ }
}
+ }
+ if (!hbuf)
+ {
// Check for Alphadigit
if ( passcoderequirecharsandnumbers)
{
@@ -264,13 +365,17 @@
if (digitCount >= password.Length() || alphaCount >= password.Length()
|| digitCount == 0 || alphaCount == 0 )
{
- Dprint ( ( _L( "EDeviceLockRequireCharsAndNumbers Failed" ) ) );
- aOutParam.AddtoFailedPolices(EDeviceLockRequireCharsAndNumbers);
- isInvalid = ETrue;
+ isInvalid = ETrue;
+ TRAP_IGNORE(
+ hbuf = LoadAndFormatResL( R_SET_SEC_CODE_LETTERS_NUMBERS );
+ );
}
} // End of Alphadigit Check
+ }
+ if (!hbuf)
+ {
// passcodeconsecutivenumbers
if (passcodeconsecutivenumbers)
{
@@ -278,11 +383,57 @@
if ( consecutively )
{
- Dprint ( ( _L( "EDeviceLockConsecutiveNumbers Failed" ) ) );
- aOutParam.AddtoFailedPolices(EDeviceLockConsecutiveNumbers);
isInvalid = ETrue;
+ TRAP_IGNORE(
+ hbuf = LoadAndFormatResL( R_SET_SEC_CODE_CONSECUTIVE );
+ );
}
}
+ }
+
+ /*
+ if (!hbuf)
+ {
+ // Check for required check or not.
+ if (passcoderequireupperandlower)
+ {
+ // Count the IsDigits first and miinus them from the lenghth!
+ // Count the possible NUM's count first!
+ for (TInt numcounter=0; numcounter < password.Length(); numcounter++)
+ {
+ if ( static_cast<TChar>( password[numcounter] ).IsDigit() )
+ numberCount++;
+ }
+
+ // Check for Caps, both
+ for (TInt capscounter=0; capscounter < password.Length(); capscounter++)
+ {
+ if ( static_cast<TChar>( password[capscounter] ).IsUpper() )
+ upperCount++;
+
+ if ( static_cast<TChar>( password[capscounter] ).IsLower() )
+ lowerCount++;
+ }
+
+ if (upperCount >= (password.Length()-numberCount ) )
+ isallcaps = ETrue;
+
+ if (lowerCount >= (password.Length() -numberCount) )
+ isallsmall = ETrue;
+
+ if (isallsmall || isallcaps)
+ {
+ isInvalid = ETrue;
+ TRAP_IGNORE(
+ hbuf = LoadAndFormatResL( R_SET_SEC_CODE_UPPER_LOWER );
+ );
+ }
+ } // End of Caps check
+ }
+ */
+
+ if (!hbuf)
+ {
// Check for required check or not.
if (passcoderequireupperandlower)
{
@@ -300,11 +451,18 @@
if ( upperCount == 0 || lowerCount == 0)
{
- Dprint ( ( _L( "EDeviceLockRequireUpperAndLower Failed" ) ) );
- aOutParam.AddtoFailedPolices(EDeviceLockRequireUpperAndLower);
isInvalid = ETrue;
+ TRAP_IGNORE(
+ hbuf = LoadAndFormatResL( R_SET_SEC_CODE_UPPER_LOWER );
+ );
}
- }
+ }
+ }
+
+
+
+ if (!hbuf)
+ {
// Check for required check or not.
if (passcodeminspecialcharacters != 0)
{
@@ -316,13 +474,18 @@
if ( specialCount < passcodeminspecialcharacters )
{
- //koya: return error code to SecUi
- Dprint ( ( _L( "EDeviceLockMinSpecialCharacters Failed" ) ) );
- aOutParam.AddtoFailedPolices(EDeviceLockMinSpecialCharacters);
isInvalid = ETrue;
- }
+ TRAP_IGNORE(
+ hbuf = LoadAndFormatResL( R_SET_SEC_CODE_MIN_SPECIAL_CHARS,
+ &passcodeminspecialcharacters );
+ );
+ }
+
}
-
+ }
+
+ if (!hbuf)
+ {
if (passcodedisallowsimple)
{
for (TInt counter=0; counter< (password.Length()-1); counter++)
@@ -335,12 +498,12 @@
}
if (singlerepeat)
{
- //koya: return error code to SecUi
- Dprint ( ( _L( "EDeviceLockSingleCharRepeatNotAllowed Failed" ) ) );
- aOutParam.AddtoFailedPolices(EDeviceLockSingleCharRepeatNotAllowed);
isInvalid = ETrue;
+ TRAP_IGNORE(
+ hbuf = LoadAndFormatResL( R_SET_SEC_CODE_SINGLE_REPEAT ) );
}
-
+ if (!hbuf)
+ {
for (TInt counter=0; counter< (password.Length()-1); counter++)
{
//The consecutivity to be checked with only Alphanumeric characters.
@@ -364,18 +527,43 @@
}
if (consecutivechars)
{
- //koya: return error code to SecUi
- Dprint ( ( _L( "EDevicelockConsecutiveCharsNotAllowed Failed" ) ) );
- aOutParam.AddtoFailedPolices(EDevicelockConsecutiveCharsNotAllowed);
isInvalid = ETrue;
+ TRAP_IGNORE(
+ hbuf = LoadAndFormatResL( R_SET_SEC_CODE_CONSECUTIVE_CHARS ) );
}
- }
+ }
+ }
+ }
+
+
if ( isInvalid )
{
- aOutParam.Set( KSCPParamStatus, KErrSCPInvalidCode );
- }
+ // Create the result-object to return
+ TRAPD( err, retParams = CSCPParamObject::NewL() );
+
+ if ( err == KErrNone )
+ {
+ retParams->Set( KSCPParamStatus, KErrSCPInvalidCode );
+ retParams->Set( KSCPParamAction, KSCPActionShowUI );
+ retParams->Set( KSCPParamUIMode, KSCPUINote );
+
+ if ( hbuf != NULL )
+ {
+ FormatResourceString(*hbuf);
+ TPtr ptr = hbuf->Des();
+ retParams->Set( KSCPParamPromptText, ptr );
+ delete hbuf;
+ }
+ }
+ }
} // end of All Zero check
+ // All params were zero! no check!
+ else
+ {
+ retParams = NULL;
+ }
+
break;
} // KSCPEventValidate
@@ -399,11 +587,20 @@
|| paramID == (RTerminalControl3rdPartySession::EPasscodeMinSpecialCharacters)
|| paramID == (RTerminalControl3rdPartySession::EPasscodeDisallowSimple))
{
+
+ // OK, we're interested, check that the value is valid
+ TRAPD( err, retParams = CSCPParamObject::NewL() );
+
+ if ( err != KErrNone )
+ {
+ break; // Fatal, cannot create paramObject
+ }
+
// All of our params are TInts
TInt paramValue;
if ( aParam.Get( KSCPParamValue, paramValue ) != KErrNone )
{
- aOutParam.Set( KSCPParamStatus, KErrArgument );
+ retParams->Set( KSCPParamStatus, KErrGeneral );
break;
}
@@ -478,12 +675,29 @@
break;
}
- aOutParam.Set( KSCPParamStatus, retStatus );
+ retParams->Set( KSCPParamStatus, retStatus );
}
+ else
+ {
+ retParams = NULL;
+ }
+
break;
} //KSCPEventConfigurationQuery
} // switch ( aID )
+
+ // Check if Any errors were raised and handle it
+ if (errRaised)
+ {
+ if ( retParams != NULL )
+ {
+ delete retParams;
+ }
+ retParams = NULL;
+ }
+
// The caller will own this pointer from now on
+ return retParams;
}
// ----------------------------------------------------------------------------
@@ -602,4 +816,94 @@
return charTooManyInRow;
}
+
+// ----------------------------------------------------------------------------
+// CSCPPatternPlugin::LoadAndFormatResL
+// Load the given resouce, and format the string according to the TInt parameters
+// if given.
+//
+// Status : Approved
+// ----------------------------------------------------------------------------
+//
+HBufC* CSCPPatternPlugin::LoadAndFormatResL( TInt aResId, TInt* aParam1, TInt* aParam2 )
+ {
+ HBufC16* resource = NULL;
+ HBufC* hbuf = NULL;
+
+ resource = LoadResourceLC( aResId );
+ FormatResourceString(*resource);
+ TInt allocLen = 0;
+ if ( aParam1 != NULL )
+ {
+ allocLen += KSCPMaxIntLength;
+ }
+ if ( aParam2 != NULL )
+ {
+ allocLen += KSCPMaxIntLength;
+ }
+
+ hbuf = HBufC::NewL( resource->Length() + allocLen );
+
+ if ( ( aParam1 == NULL ) && ( aParam2 == NULL ) )
+ {
+ hbuf->Des().Copy( resource->Des() );
+ }
+ else
+ {
+ if ( aParam1 == NULL )
+ {
+ hbuf->Des().Format( resource->Des(), *aParam2 );
+ }
+ else if ( aParam2 == NULL )
+ {
+ hbuf->Des().Format(resource->Des(), *aParam1 );
+ }
+ else
+ {
+ hbuf->Des().Format(resource->Des(), *aParam1, *aParam2 );
+ }
+ }
+
+ CleanupStack::PopAndDestroy( resource );
+ return hbuf;
+ }
+
+// ----------------------------------------------------------------------------
+// CSCPPatternPlugin::FormatResourceString
+// The buffer that is passed is formatted to have only %i as a format specifier instead of %N or %0N etc.
+//
+// Status : Approved
+// ----------------------------------------------------------------------------
+//
+void CSCPPatternPlugin::FormatResourceString(HBufC16 &aResStr)
+{
+ TInt pos = 0;
+ TInt flag = 0;
+ TPtr16 bufPtr = aResStr.Des();
+ _LIT (mess1, "%N");
+ _LIT (mess2, "%i");
+ _LIT (mess3, "%0N");
+ _LIT (mess4, "%1N");
+
+ while ((pos = bufPtr.Find(mess1)) !=KErrNotFound)
+ {
+ bufPtr.Replace(pos,2,mess2);
+ flag = 1;
+ break;
+ }
+
+ if(flag == 0)
+ {
+ while ((pos = bufPtr.Find(mess3)) != KErrNotFound)
+ {
+ bufPtr.Replace(pos,3,mess2);
+ }
+
+ while ((pos = bufPtr.Find(mess4)) != KErrNotFound)
+ {
+ bufPtr.Replace(pos,3,mess2);
+ }
+ }
+}
+
// End of File