sl@0: // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #define __INCLUDE_CAPABILITY_NAMES__ sl@0: #include sl@0: #include "inifile.h" sl@0: #include "datatype.h" sl@0: #include "log.h" sl@0: sl@0: #define MAX(a,b) ((a)<(b)?(b):(a)) sl@0: #define MAX3(a,b,c) MAX(MAX(a,b),c) sl@0: #define MAX4(a,b,c,d) MAX(MAX(a,b),MAX(c,d)) sl@0: sl@0: //Unicode text file prefix - FE,FF bytes. sl@0: static const TUint16 KUcs2Bom = 0xfeff; sl@0: sl@0: //Repository (ini) file - signature sl@0: _LIT(KSignature, "cenrep"); sl@0: static const TInt KSignatureLen = 6; sl@0: sl@0: //Repository (ini) file - version string and version number sl@0: _LIT(KVersion, "version"); sl@0: static const TInt KVersionLen = 7; sl@0: static const TUint KCurrentVersion = 1; sl@0: sl@0: //Repository (ini) file - supported types names sl@0: _LIT(KTypeInt, "int"); sl@0: _LIT(KTypeReal, "real"); sl@0: _LIT(KTypeString, "string"); sl@0: _LIT(KTypeString8, "string8"); sl@0: _LIT(KTypeBinary, "binary"); sl@0: sl@0: //Max type name length sl@0: static const TInt KMaxTypeLen = 9; sl@0: sl@0: //The symbol used in repository (ini) files to note null data sl@0: static const TChar KNullDataIndicator = '-'; sl@0: sl@0: // Section identifiers in the repository (ini) file sl@0: _LIT(KPlatSecSection, "[platsec]"); sl@0: static const TInt KPlatSecSectionLen = 9; sl@0: sl@0: _LIT(KOwnerSection, "[owner]"); sl@0: static const TInt KOwnerSectionLen = 7; sl@0: sl@0: _LIT(KTimeStampSection, "[timestamp]"); sl@0: static const TInt KTimeStampSectionLen = 11; sl@0: sl@0: _LIT(KMainSection, "[main]"); sl@0: static const TInt KMainSectionLen = 6; sl@0: sl@0: _LIT(KDefaultMetaSection, "[defaultmeta]"); sl@0: static const TInt KDefaultMetaSectionLen = 13 ; sl@0: sl@0: static const TInt KIniFileSectionLen = MAX4(KPlatSecSectionLen,KMainSectionLen,KTimeStampSectionLen, KDefaultMetaSectionLen); sl@0: sl@0: // Other useful string constants sl@0: _LIT(KMaskString, "mask"); sl@0: static const TInt KMaskLen = 4; sl@0: sl@0: _LIT(KReadAccessSidString, "sid_rd"); sl@0: _LIT(KReadAccessCapString, "cap_rd"); sl@0: _LIT(KWriteAccessSidString, "sid_wr"); sl@0: _LIT(KWriteAccessCapString, "cap_wr"); sl@0: _LIT(KAccessAlwaysPass, "alwayspass"); sl@0: _LIT(KAccessAlwaysFail, "alwaysfail"); sl@0: // could do max of _LITs above sl@0: static const TInt KMaxAccessTypeLen = 6; sl@0: sl@0: // longest capability string from CapabilityNames is 15 sl@0: static const TInt KMaxCapabilityStringLen = 20; sl@0: sl@0: static const TInt KBufLen = MAX3(KVersionLen, KSignatureLen, KIniFileSectionLen); sl@0: sl@0: sl@0: sl@0: const TUint KCr = '\r'; sl@0: const TUint KTab = '\t'; sl@0: const TUint KSpace = ' '; sl@0: sl@0: #ifdef CENTREP_CONV_TOOL sl@0: _LIT(KTransactFileName, "transact"); sl@0: _LIT(KCrNl, "\r\n"); sl@0: _LIT(KHexIntFormat, "0x%X"); sl@0: _LIT(KUidFormat, "0x%08X"); sl@0: _LIT(KRangeMetaFmt, "0x%X 0x%X 0x%08X"); sl@0: _LIT(KMaskMetaFmt, "0x%X mask = 0x%X 0x%08X"); sl@0: sl@0: _LIT(KRangePrefix, "0x%X 0x%X"); sl@0: _LIT(KMaskPrefix, "0x%08X mask = 0x%08X"); sl@0: #endif sl@0: sl@0: ///////////////////////////////////////////////////////////////////////////////////////////////// sl@0: // Local functions sl@0: sl@0: /** sl@0: The function checks if the file with aFile name exists. sl@0: @param aFile File name, including the full path. sl@0: @return 0, if the file does not exist, non-zero value otherwise. sl@0: @internalComponent sl@0: */ sl@0: /** sl@0: #ifdef CENTREP_CONV_TOOL sl@0: static TBool FileExists(const TDesC& aFile) sl@0: { sl@0: TEntry entry; sl@0: return TServerResources::iFs.Entry(aFile, entry) == KErrNone; sl@0: } sl@0: #endif sl@0: */ sl@0: sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: static TInt ReadFileL(RFile aFile, HBufC16*& aBuf) sl@0: { sl@0: TInt size; sl@0: TInt r = aFile.Size(size); sl@0: if(r!=KErrNone) sl@0: return r; sl@0: if(size<2) sl@0: return KErrCorrupt; sl@0: sl@0: TInt len = size/2-1; sl@0: aBuf = HBufC16::NewL(len); sl@0: TPtr16 ptr16 = aBuf->Des(); sl@0: TPtr8 ptr8((TUint8*)ptr16.Ptr(), 0, 2); sl@0: r = aFile.Read(ptr8, 2); sl@0: if(r!=KErrNone) sl@0: return r; sl@0: sl@0: if(*ptr16.Ptr()!=KUcs2Bom) sl@0: { sl@0: __CENTREP_TRACE("File not Ucs2. No BOM"); sl@0: return KErrCorrupt; sl@0: } sl@0: ptr8.Set((TUint8*)ptr16.Ptr(), 0, size-2); sl@0: r = aFile.Read(ptr8); sl@0: if(r!=KErrNone) sl@0: return r; sl@0: ptr16.SetLength(len); sl@0: sl@0: return KErrNone; sl@0: } sl@0: sl@0: static TBool IsNegativeNumber(TLex& aLex) sl@0: { sl@0: if (aLex.Peek()=='-') sl@0: return ETrue; sl@0: else sl@0: return EFalse; sl@0: } sl@0: sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: static TInt ReadNumberL(TLex& aLex, TUint32& aVal) sl@0: { sl@0: TRadix radix = EDecimal; sl@0: if(aLex.Peek()=='0') sl@0: { sl@0: aLex.Inc(); sl@0: if(aLex.Peek().GetLowerCase()=='x') sl@0: { sl@0: aLex.Inc(); sl@0: radix = EHex; sl@0: } sl@0: else sl@0: aLex.UnGet(); sl@0: } sl@0: sl@0: if(aLex.Val(aVal, radix)!=KErrNone) sl@0: return KErrCorrupt; sl@0: sl@0: return KErrNone; sl@0: } sl@0: sl@0: #ifdef CENTREP_CONV_TOOL sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: static void WriteBinary(TDes& aBuf, const HBufC8* aString) sl@0: { sl@0: if(aString) sl@0: { sl@0: TInt len = aString->Length(); sl@0: if(len==0) sl@0: aBuf.Append(KNullDataIndicator); sl@0: else sl@0: { sl@0: TPtr8 ptr8 = const_cast(aString)->Des(); sl@0: for(TInt i=0;iiFullName = HBufC::NewL(aFullFileName.Length()); sl@0: TPtr filename = aIniFile->iFullName->Des(); sl@0: filename.Copy(aFullFileName); sl@0: #endif sl@0: TInt rReadFile = ReadFileL(file,aIniFile->iBuf); sl@0: CleanupStack::PopAndDestroy(); //file sl@0: TInt rReadHeader=KErrNone; sl@0: if(rReadFile==KErrNone) sl@0: { sl@0: aIniFile->iLex.Assign(aIniFile->iBuf->Des()); sl@0: rReadHeader=aIniFile->ReadHeaderL(); sl@0: } sl@0: sl@0: if((rReadFile==KErrCorrupt) || ( rReadHeader==KErrCorrupt)) sl@0: { sl@0: return KErrCorrupt; sl@0: } sl@0: } sl@0: else sl@0: { sl@0: CleanupStack::Pop();//file sl@0: } sl@0: return r; sl@0: sl@0: sl@0: } sl@0: sl@0: CIniFileIn::~CIniFileIn() sl@0: { sl@0: delete iBuf; sl@0: #ifdef CENTREP_TRACE sl@0: delete iFullName; sl@0: #endif sl@0: } sl@0: sl@0: sl@0: TInt CIniFileIn::ReadHeaderL() sl@0: { sl@0: TBuf buf; sl@0: sl@0: // sl@0: // Check file signature sl@0: // sl@0: sl@0: SkipComments(); sl@0: sl@0: iLex.Mark(); sl@0: iLex.SkipCharacters(); sl@0: sl@0: if(iLex.TokenLength()>KSignatureLen) sl@0: { sl@0: __CENTREP_TRACE1("[%S] Invalid header signature",iFullName); sl@0: return(KErrCorrupt); sl@0: } sl@0: buf.CopyLC(iLex.MarkedToken()); sl@0: if(buf.Compare(KSignature)!=0) sl@0: { sl@0: __CENTREP_TRACE1("[%S] Invalid header signature",iFullName); sl@0: return(KErrCorrupt); sl@0: } sl@0: // sl@0: // Check file version sl@0: // sl@0: sl@0: SkipComments(); sl@0: sl@0: iLex.Mark(); sl@0: iLex.SkipCharacters(); sl@0: sl@0: if(iLex.TokenLength()>KVersionLen) sl@0: { sl@0: __CENTREP_TRACE1("[%S] Missing version keyword",iFullName); sl@0: return(KErrCorrupt); sl@0: } sl@0: buf.CopyLC(iLex.MarkedToken()); sl@0: if(buf.Compare(KVersion)!=0) sl@0: { sl@0: __CENTREP_TRACE1("[%S] Missing version keyword",iFullName); sl@0: return(KErrCorrupt); sl@0: } sl@0: iLex.SkipSpace(); sl@0: sl@0: TUint version; sl@0: iLex.Val(version); sl@0: if(version>KCurrentVersion) sl@0: { sl@0: __CENTREP_TRACE1("[%S] Invalid version number",iFullName); sl@0: return(KErrNotSupported); sl@0: } sl@0: return( KErrNone); sl@0: } sl@0: sl@0: void CIniFileIn::SkipComments() sl@0: { sl@0: for(;;) sl@0: { sl@0: iLex.SkipSpace(); sl@0: sl@0: if(iLex.Peek()!='#') sl@0: break; sl@0: sl@0: while(iLex.Get()!='\n' && !iLex.Eos()) {} sl@0: } sl@0: } sl@0: sl@0: void CIniFileIn::SkipEqualSign() sl@0: { sl@0: iLex.SkipSpace(); sl@0: if(iLex.Peek()=='=') sl@0: iLex.Get(); sl@0: sl@0: iLex.SkipSpace(); sl@0: } sl@0: sl@0: TInt CIniFileIn::ReadSettingOnlyL(TServerSetting& aSetting,TBool& aSingleMetaFound) sl@0: { sl@0: TInt ret = KErrNone; sl@0: sl@0: aSingleMetaFound=EFalse; sl@0: sl@0: SkipComments(); sl@0: iLex.SkipSpace(); sl@0: sl@0: if(iLex.Eos()) sl@0: return KErrNotFound; sl@0: sl@0: TUint32 key; sl@0: TInt r=ReadNumberL(iLex, key); sl@0: if(r!=KErrNone) sl@0: { sl@0: // returns either KErrCorrupt or KErrNone sl@0: __CENTREP_TRACE1("[%S] Invalid single setting id",iFullName); sl@0: return r; sl@0: } sl@0: aSetting.SetKey(key); sl@0: sl@0: iLex.SkipSpaceAndMark(); sl@0: iLex.SkipCharacters(); sl@0: sl@0: if(iLex.TokenLength()>KMaxTypeLen) sl@0: { sl@0: __CENTREP_TRACE1("[%S] Invalid key type, must be one of: [int,real,string,string8,binary]",iFullName); sl@0: return KErrCorrupt; sl@0: } sl@0: TBuf type; sl@0: type.CopyLC(iLex.MarkedToken()); sl@0: sl@0: iLex.SkipSpace(); sl@0: sl@0: if(type.Compare(KTypeInt)==0) sl@0: { sl@0: if (IsNegativeNumber(iLex)) sl@0: { sl@0: TInt i; sl@0: if(iLex.Val(i)!=KErrNone) sl@0: { sl@0: __CENTREP_TRACE1("[%S] Invalid negative integer value",iFullName); sl@0: return(KErrCorrupt); sl@0: } sl@0: aSetting.SetIntValue(i); sl@0: } sl@0: else sl@0: { sl@0: TUint32 i; sl@0: TInt r=ReadNumberL(iLex, i); sl@0: if(r!=KErrNone) sl@0: { sl@0: __CENTREP_TRACE1("[%S] Invalid integer value",iFullName); sl@0: return r; sl@0: } sl@0: aSetting.SetIntValue(i); sl@0: } sl@0: } sl@0: else if(type.Compare(KTypeReal)==0) sl@0: { sl@0: TReal r; sl@0: ret=iLex.Val(r,'.'); sl@0: //iLex.Val with TReal can return KErrNoMemory sl@0: if (ret!=KErrNone) sl@0: { sl@0: if (ret==KErrNoMemory) sl@0: User::LeaveNoMemory(); sl@0: else sl@0: { sl@0: __CENTREP_TRACE1("[%S] Invalid real value",iFullName); sl@0: return KErrCorrupt; sl@0: } sl@0: } sl@0: TReal* temp = new(ELeave)TReal(r); sl@0: aSetting.SetRealValue(temp); sl@0: temp = NULL; sl@0: } sl@0: else if(type.Compare(KTypeString)==0) sl@0: { sl@0: HBufC8* s; sl@0: ret = ReadStringL(s); sl@0: if(ret != KErrNone) sl@0: { sl@0: __CENTREP_TRACE1("[%S] Invalid string value",iFullName); sl@0: return KErrCorrupt; sl@0: } sl@0: aSetting.SetStrValue(s); sl@0: } sl@0: sl@0: else if(type.Compare(KTypeString8)==0) sl@0: { sl@0: HBufC8* s; sl@0: ret = ReadString16To8L(s); sl@0: if(ret != KErrNone) sl@0: { sl@0: __CENTREP_TRACE1("[%S] Invalid string8 value",iFullName); sl@0: return KErrCorrupt; sl@0: } sl@0: aSetting.SetStrValue(s); sl@0: } sl@0: sl@0: else if(type.Compare(KTypeBinary)==0) sl@0: { sl@0: HBufC8* s = NULL; sl@0: ret = ReadBinaryL(s); sl@0: if(ret != KErrNone) sl@0: { sl@0: __CENTREP_TRACE1("[%S] Invalid binary value",iFullName); sl@0: return KErrCorrupt; sl@0: } sl@0: aSetting.SetStrValue(s); sl@0: } sl@0: else sl@0: { sl@0: __CENTREP_TRACE1("[%S] Invalid key type, must be one of: [int,real,string,string8,binary]",iFullName); sl@0: return KErrCorrupt; sl@0: } sl@0: //skip any spaces or tabs sl@0: while(iLex.Peek()==KSpace || iLex.Peek()==KTab) sl@0: { sl@0: iLex.Inc(); sl@0: } sl@0: sl@0: TUint32 meta; sl@0: sl@0: /** sl@0: carriage return reached which means that there is no meta AND capabilities sl@0: defined for this key. Thus setting meta to NULL to be able to set a value sl@0: from default section later. sl@0: */ sl@0: if (iLex.Peek()==KCr) sl@0: { sl@0: meta = 0; sl@0: } sl@0: else sl@0: { sl@0: r=ReadNumberL(iLex, meta); sl@0: /** sl@0: If meta can not be read, it is not neccessary an error. sl@0: It might be not present for an individual key and it will be taken sl@0: from a default section. sl@0: If single meta is present, we need to remember so we can recognise a single sl@0: meta of 0 as distinct from no meta ( also sets meta to 0 ). sl@0: */ sl@0: if(r!=KErrNone) sl@0: meta = 0; sl@0: else sl@0: aSingleMetaFound=ETrue; sl@0: } sl@0: sl@0: aSetting.SetMeta(meta); sl@0: sl@0: return KErrNone; sl@0: } sl@0: sl@0: /** sl@0: Read an entire DefaultMeta section from ini file sl@0: and create FDefault metadata entries sl@0: sl@0: @internalTechnology sl@0: @return KErrNone, KErrCorrupt or KErrNotFound sl@0: */ sl@0: TInt CIniFileIn::ReadDefaultMetaSecSectionL(TUint32& aDefaultMeta, RDefaultMetaArray& aDefaultMetaRanges) sl@0: { sl@0: TBuf buf; sl@0: sl@0: // sl@0: // Check if a DefaultMeta section is present sl@0: // sl@0: sl@0: SkipComments(); sl@0: sl@0: // we will need this section later to write the out file... sl@0: iLex.Mark(iMainSectionMark); sl@0: sl@0: iLex.Mark(); sl@0: iLex.SkipCharacters(); sl@0: sl@0: if( iLex.TokenLength()!=KDefaultMetaSectionLen || sl@0: (buf.CopyLC( iLex.MarkedToken() ), buf.Compare( KDefaultMetaSection )!=0) ) sl@0: { sl@0: // Meta not available sl@0: iLex.UnGetToMark(); sl@0: return KErrNotFound; sl@0: } sl@0: sl@0: // sl@0: // Lets read Meta settings sl@0: // sl@0: sl@0: SkipComments(); sl@0: sl@0: // we might have a default Meta section first sl@0: if(KErrNone != ReadNumber(aDefaultMeta)) sl@0: { sl@0: // should we log that no default read policy? sl@0: } sl@0: sl@0: sl@0: // now lets try range policies sl@0: TInt r=ReadRangeMetaDefaultsL(aDefaultMetaRanges); sl@0: if(r!=KErrNone) sl@0: { sl@0: __CENTREP_TRACE1("[%S] Error parsing [defaultMeta]",iFullName); sl@0: return r; sl@0: } sl@0: iLex.Mark(iMainSectionMark); sl@0: return KErrNone; sl@0: } sl@0: sl@0: sl@0: /** sl@0: Reads Meta defaults as defined for range of indexes sl@0: sl@0: @internalTechnology sl@0: @return KErrNone, KErrCorrupt sl@0: */ sl@0: TInt CIniFileIn::ReadRangeMetaDefaultsL(RDefaultMetaArray& aDefaultMetaRanges) sl@0: { sl@0: TUint32 lowKey = 0; sl@0: TBuf buf; sl@0: sl@0: SkipComments(); sl@0: while(KErrNone == ReadNumber(lowKey)) sl@0: { sl@0: // highKey and mask needs to be zero'd every cycle... sl@0: TUint32 highKey = 0; sl@0: TUint32 mask = 0; sl@0: TUint32 defaultMeta = 0 ; sl@0: sl@0: iLex.SkipSpace(); sl@0: // may be not range but key & mask so lets check 'mask' keyword sl@0: if(!iLex.Peek().IsDigit()) sl@0: { sl@0: //so should be mask then... sl@0: iLex.Mark(); sl@0: while((iLex.Peek()!='=')&&(!iLex.Eos())) sl@0: { sl@0: iLex.Inc(); sl@0: sl@0: if(iLex.TokenLength() >= KMaskLen) sl@0: { sl@0: // so no '=' there sl@0: // not necessarily bad thing... could be space there first sl@0: break; sl@0: } sl@0: sl@0: } sl@0: sl@0: // check if KMaskLen is < buf length? sl@0: buf.CopyLC(iLex.MarkedToken()); sl@0: if(buf.Compare(KMaskString)!=0) sl@0: { sl@0: __CENTREP_TRACE1("[%S] Missing 'mask' keyword [defaultMeta]",iFullName); sl@0: return KErrCorrupt; sl@0: } sl@0: sl@0: iLex.SkipSpace(); sl@0: if('=' != iLex.Get()) sl@0: { sl@0: __CENTREP_TRACE1("[%S] Missing '=' for 'mask' keyword [defaultMeta]",iFullName); sl@0: return KErrCorrupt; sl@0: } sl@0: iLex.SkipSpace(); sl@0: TInt r=ReadNumberL(iLex,mask); sl@0: if(r!=KErrNone) sl@0: { sl@0: __CENTREP_TRACE1("[%S] Invalid 'mask' for keyspace range [defaultMeta]",iFullName); sl@0: return KErrCorrupt; sl@0: } sl@0: } sl@0: else sl@0: { sl@0: TInt r = ReadNumberL(iLex,highKey); sl@0: if(r!=KErrNone) sl@0: { sl@0: __CENTREP_TRACE1("[%S] Invalid end of range [defaultMeta]",iFullName); sl@0: return KErrCorrupt; sl@0: } sl@0: } sl@0: sl@0: sl@0: if(KErrNone == ReadNumber(defaultMeta)) sl@0: { sl@0: TSettingsDefaultMeta metaDefault(defaultMeta,lowKey, highKey, mask); sl@0: aDefaultMetaRanges.AppendL(metaDefault); sl@0: } sl@0: else sl@0: { sl@0: // unfortunately, we can't tell if we got here because the default sl@0: // meta was bad or because there was an invalid start value for the range. sl@0: __CENTREP_TRACE1("[%S] Range defined without default or bad start of range [defaultMeta]",iFullName); sl@0: // range specified with no default Meta! sl@0: return KErrCorrupt; sl@0: } sl@0: SkipComments(); sl@0: } sl@0: return KErrNone; sl@0: } sl@0: sl@0: /** sl@0: Read Owner section from ini file and extract owner UID sl@0: sl@0: @internalTechnology sl@0: @return KErrNone, KErrCorrupt or KErrNotFound sl@0: */ sl@0: TInt CIniFileIn::ReadOwnerSectionL(TUint32 &aOwnerUID) sl@0: { sl@0: TBuf buf; sl@0: sl@0: sl@0: sl@0: SkipComments(); sl@0: sl@0: // we will need this section later to write the out file... sl@0: iLex.Mark(iMainSectionMark); sl@0: sl@0: iLex.Mark(); sl@0: iLex.SkipCharacters(); sl@0: sl@0: if( iLex.TokenLength()!=KOwnerSectionLen || sl@0: (buf.CopyLC( iLex.MarkedToken() ), buf.Compare( KOwnerSection )!=0) ) sl@0: { sl@0: // Owner section not available sl@0: iLex.UnGetToMark(); sl@0: return KErrNotFound; sl@0: } sl@0: else sl@0: { sl@0: // Found an "owner" section - must be followed by a UID (hex number sl@0: // in format 0xnnnnn) to be valid! sl@0: iLex.SkipSpace() ; sl@0: if(iLex.Peek()=='0') sl@0: { sl@0: iLex.Inc(); sl@0: if(iLex.Peek().GetLowerCase()=='x') sl@0: { sl@0: iLex.Inc(); sl@0: if(iLex.Val(aOwnerUID, EHex)!=KErrNone) sl@0: { sl@0: __CENTREP_TRACE1("[%S] Invalid owner UID not valid hex digit [owner]",iFullName); sl@0: return KErrCorrupt; sl@0: } sl@0: } sl@0: else sl@0: { sl@0: __CENTREP_TRACE1("[%S] Invalid owner UID not valid hex digit [owner]",iFullName); sl@0: return KErrCorrupt; sl@0: } sl@0: } sl@0: else sl@0: { sl@0: __CENTREP_TRACE1("[%S] Invalid owner UID not valid hex digit [owner]",iFullName); sl@0: return KErrCorrupt; sl@0: } sl@0: } sl@0: sl@0: iLex.Mark(iMainSectionMark); sl@0: sl@0: return KErrNone; sl@0: } sl@0: sl@0: /** sl@0: Read Timestamp section from ini file and extract value as a TTime sl@0: sl@0: @internalTechnology sl@0: @return KErrNone, KErrCorrupt or KErrNotFound sl@0: */ sl@0: TInt CIniFileIn::ReadTimeStampSectionL(TTime &aTimeStamp) sl@0: { sl@0: TBuf<25> buf; sl@0: SkipComments(); sl@0: sl@0: // we will need this section later to write the out file... sl@0: iLex.Mark(iMainSectionMark); sl@0: sl@0: iLex.Mark(); sl@0: iLex.SkipCharacters(); sl@0: sl@0: buf.CopyLC( iLex.MarkedToken()); sl@0: sl@0: if( iLex.TokenLength()!=KTimeStampSectionLen || sl@0: (buf.Compare( KTimeStampSection )!=0) ) sl@0: { sl@0: // Timestamp section not available sl@0: iLex.UnGetToMark(); sl@0: return KErrNotFound; sl@0: } sl@0: else sl@0: { sl@0: // Found a "timestamp" section - must be followed by a a timestamp sl@0: // either in format... sl@0: // sl@0: // YYYYMMDD:HHMMSS.MMMMMM where: sl@0: // YYYY = 4 digit year sl@0: // MM = 2 digit numeric month sl@0: // DD = 2 digit numeric date sl@0: // HH = 2 digit hour sl@0: // MM = 2 digit minute sl@0: // SS = 2 digit second sl@0: // MMMMMM = 6 digit microseconds sl@0: // Note that this is the format used for constructing/initialising sl@0: // a TTime from a string. sl@0: // sl@0: // ...or a 64-bit integer which can be converted to sl@0: // to a TTime to be considered valid! sl@0: // sl@0: iLex.SkipSpace(); sl@0: iLex.Mark(); sl@0: iLex.SkipCharacters() ; sl@0: sl@0: buf.CopyLC(iLex.MarkedToken()) ; sl@0: if (aTimeStamp.Set(buf) !=KErrNone) sl@0: { sl@0: TInt64 intTimeStamp ; sl@0: iLex.UnGetToMark(); sl@0: if (iLex.Val(intTimeStamp) != KErrNone) sl@0: { sl@0: __CENTREP_TRACE1("[%S] Invalid time stamp [timestamp]",iFullName); sl@0: return KErrCorrupt; sl@0: } sl@0: else sl@0: { sl@0: aTimeStamp = intTimeStamp; sl@0: } sl@0: } sl@0: } sl@0: iLex.Mark(iMainSectionMark); sl@0: return KErrNone; sl@0: } sl@0: sl@0: /** sl@0: Read a setting and it's single policy ( if it exists ) sl@0: sl@0: @internalTechnology sl@0: @return KErrNone, KErrCorrupt sl@0: aSetting setting read from ini file sl@0: aSingleReadPolicy single read policy if any sl@0: aSingleWritePolicy single write policy if any sl@0: aSingleReadPolicyFound ETrue if single read policy found with this key, EFalse if not sl@0: aSingleWritePolicyFound ETrue if single write policy found with this key, EFalse if not sl@0: aSingleMetaFound ETrue if single metadata found with this key, EFalse if not sl@0: */ sl@0: TInt CIniFileIn::ReadSettingL(TServerSetting& aSetting,TSecurityPolicy& aSingleReadPolicy,TSecurityPolicy& aSingleWritePolicy, TBool& aSingleReadPolicyFound, TBool& aSingleWritePolicyFound, TBool& aSingleMetaFound) sl@0: { sl@0: aSingleReadPolicyFound = EFalse; sl@0: aSingleWritePolicyFound = EFalse; sl@0: sl@0: TInt error = ReadSettingOnlyL(aSetting, aSingleMetaFound); sl@0: if(KErrNone == error) sl@0: { sl@0: //Need to push into cleanupstack for string setting sl@0: aSetting.PushL(); sl@0: // when multiple policies enabled then read in a loop sl@0: sl@0: if (iLex.Peek() !=KCr) sl@0: { sl@0: // if neither read/write policy found we do not create TSettingsAccessPolicy at all... sl@0: TInt err=ReadRdPolicyL(aSingleReadPolicy); sl@0: if (err==KErrNone) sl@0: aSingleReadPolicyFound=ETrue; sl@0: else sl@0: { sl@0: //we need to return error code rather than assuming no single policy is found sl@0: if (err==KErrCorrupt || err==KErrNoMemory) sl@0: { sl@0: #ifdef CENTREP_TRACE sl@0: if (err == KErrCorrupt) sl@0: { sl@0: __CENTREP_TRACE1("[%S] Invalid read setting",iFullName); sl@0: } sl@0: #endif sl@0: aSetting.PopAndDestroy(); sl@0: return err; sl@0: } sl@0: //else if ret!=KErrNone very likely it is KErrNotFound so leave sl@0: //the state of the writePolicyFound to EFalse sl@0: } sl@0: sl@0: err=ReadWrPolicyL(aSingleWritePolicy); sl@0: if (err==KErrNone) sl@0: aSingleWritePolicyFound=ETrue; sl@0: else sl@0: { sl@0: //we need to return error code rather than assuming no single policy is found sl@0: if (err==KErrCorrupt || err==KErrNoMemory) sl@0: { sl@0: #ifdef CENTREP_TRACE sl@0: if (err == KErrCorrupt) sl@0: { sl@0: __CENTREP_TRACE1("[%S] Invalid write setting",iFullName); sl@0: } sl@0: #endif sl@0: aSetting.PopAndDestroy(); sl@0: return err; sl@0: } sl@0: //else if ret!=KErrNone very likely it is KErrNotFound so leave sl@0: //the state of the writePolicyFound to EFalse sl@0: } sl@0: } sl@0: sl@0: //Need to pop back the setting sl@0: aSetting.Pop(); sl@0: } sl@0: return error; sl@0: } sl@0: sl@0: TInt CIniFileIn::SkipPlatSecSectionL() sl@0: { sl@0: HBufC* platSecSection; sl@0: TInt r=GetPlatSecSectionLC(platSecSection); sl@0: if(platSecSection) sl@0: CleanupStack::PopAndDestroy(platSecSection); sl@0: return r; sl@0: } sl@0: sl@0: TInt CIniFileIn::SkipOwnerSectionL() sl@0: { sl@0: HBufC* ownerSection; sl@0: TInt r=GetOwnerSectionLC(ownerSection); sl@0: if(ownerSection) sl@0: CleanupStack::PopAndDestroy(ownerSection); sl@0: return r; sl@0: } sl@0: sl@0: TInt CIniFileIn::SkipDefaultMetaSectionL() sl@0: { sl@0: HBufC* section; sl@0: TInt r=GetDefaultMetaSectionLC(section); sl@0: if(section) sl@0: CleanupStack::PopAndDestroy(section); sl@0: return r; sl@0: } sl@0: sl@0: TInt CIniFileIn::SkipTimeStampSectionL() sl@0: { sl@0: HBufC* timeStampSection; sl@0: TInt r=GetTimeStampSectionLC(timeStampSection); sl@0: if(timeStampSection) sl@0: CleanupStack::PopAndDestroy(timeStampSection); sl@0: return r; sl@0: } sl@0: sl@0: /** sl@0: Read an entire PlatSec section from ini file sl@0: and create TSecurityPolicy for default access and for range of indexes sl@0: sl@0: @internalTechnology sl@0: @return KErrNone, KErrCorrupt or KErrNotFound sl@0: */ sl@0: TInt CIniFileIn::ReadPlatSecSectionL(TSecurityPolicy& aDefaultReadPolicy, TBool& aGotDefaultReadPolicy, sl@0: TSecurityPolicy& aDefaultWritePolicy, TBool& aGotDefaultWritePolicy, sl@0: RRangePolicyArray& aRangePolicies) sl@0: sl@0: { sl@0: TBuf buf; sl@0: sl@0: aGotDefaultReadPolicy = EFalse ; sl@0: aGotDefaultWritePolicy = EFalse ; sl@0: sl@0: // sl@0: // Check if the PlatSec section is present sl@0: // sl@0: SkipComments(); sl@0: sl@0: // we will need this section later to write the out file... sl@0: iLex.Mark(iMainSectionMark); sl@0: sl@0: iLex.Mark(); sl@0: iLex.SkipCharacters(); sl@0: sl@0: if( iLex.TokenLength()!=KPlatSecSectionLen || sl@0: (buf.CopyLC( iLex.MarkedToken() ), buf.Compare( KPlatSecSection )!=0) ) sl@0: { sl@0: // PlatSec section not available sl@0: iLex.UnGetToMark(); sl@0: return KErrNotFound; sl@0: } sl@0: sl@0: // sl@0: // Lets read the policies sl@0: // sl@0: sl@0: SkipComments(); sl@0: TInt r=KErrNone; sl@0: // we might have a default policies first sl@0: // check for default read policy sl@0: r=ReadRdPolicyL(aDefaultReadPolicy); sl@0: if (r==KErrNone) sl@0: aGotDefaultReadPolicy=ETrue; sl@0: else sl@0: { sl@0: //we need to return error code rather than assuming no default policy is found sl@0: if (r==KErrCorrupt || r==KErrNoMemory) sl@0: { sl@0: #ifdef CENTREP_TRACE sl@0: if (r == KErrCorrupt) sl@0: { sl@0: __CENTREP_TRACE1("[%S] Invalid read policy [platsec]",iFullName); sl@0: } sl@0: #endif sl@0: return r; sl@0: } sl@0: //else if ret!=KErrNone very likely it is KErrNotFound so leave sl@0: //the state of the writePolicyFound to EFalse sl@0: } sl@0: // check for default write policy sl@0: r=ReadWrPolicyL(aDefaultWritePolicy); sl@0: if (r==KErrNone) sl@0: aGotDefaultWritePolicy=ETrue; sl@0: else sl@0: { sl@0: //we need to return error code rather than assuming no default policy is found sl@0: if (r==KErrCorrupt || r==KErrNoMemory) sl@0: { sl@0: #ifdef CENTREP_TRACE sl@0: if (r == KErrCorrupt) sl@0: { sl@0: __CENTREP_TRACE1("[%S] Invalid write policy [platsec]",iFullName); sl@0: } sl@0: #endif sl@0: return r; sl@0: } sl@0: //else if ret!=KErrNone very likely it is KErrNotFound so leave sl@0: //the state of the writePolicyFound to EFalse sl@0: } sl@0: // now lets try range policies sl@0: r = ReadRangePoliciesL(aDefaultReadPolicy,aDefaultWritePolicy,aRangePolicies); sl@0: if(r!=KErrNone) sl@0: { sl@0: __CENTREP_TRACE1("[%S] Invalid range policy [platsec]",iFullName); sl@0: return KErrCorrupt; sl@0: } sl@0: // it must be the main section now so lets check sl@0: SkipComments(); sl@0: iLex.Mark(); sl@0: iLex.SkipCharacters(); sl@0: sl@0: if(iLex.TokenLength()>KBufLen) sl@0: return KErrCorrupt; sl@0: sl@0: buf.CopyLC(iLex.MarkedToken()); sl@0: if(buf.Compare(KMainSection)!=0) sl@0: { sl@0: return KErrCorrupt; sl@0: } sl@0: sl@0: iLex.Mark(iMainSectionMark); sl@0: sl@0: return KErrNone; sl@0: } sl@0: sl@0: /** sl@0: Reads TSecurityPolicy as defined for range of indexes sl@0: sl@0: @internalTechnology sl@0: @return KErrNone, KErrCorrupt sl@0: @leave KErrNotFound sl@0: */ sl@0: TInt CIniFileIn::ReadRangePoliciesL(const TSecurityPolicy& aDefaultReadPolicy, sl@0: const TSecurityPolicy& aDefaultWritePolicy, sl@0: RRangePolicyArray& aRangePolicies) sl@0: { sl@0: TUint32 lowKey = 0; sl@0: TBuf buf; sl@0: sl@0: SkipComments(); sl@0: while(KErrNone == ReadNumber(lowKey)) sl@0: { sl@0: // highKey and mask needs to be zero'd every cycle... sl@0: TUint32 highKey = 0; sl@0: TUint32 mask = 0; sl@0: iLex.SkipSpace(); sl@0: // may be not range but key & mask so lets check 'mask' keyword sl@0: if(!iLex.Peek().IsDigit()) sl@0: { sl@0: //so should be mask then... sl@0: iLex.Mark(); sl@0: while((iLex.Peek()!='=')&&(!iLex.Eos())) sl@0: { sl@0: iLex.Inc(); sl@0: sl@0: if(iLex.TokenLength() >= KMaskLen) sl@0: { sl@0: // so no '=' there sl@0: // not necessarily bad thing... could be space there first sl@0: break; sl@0: } sl@0: sl@0: } sl@0: sl@0: // check if KMaskLen is < buf length? sl@0: buf.CopyLC(iLex.MarkedToken()); sl@0: if(buf.Compare(KMaskString)!=0) sl@0: { sl@0: __CENTREP_TRACE1("[%S] Missing 'mask' keyword for range [platsec]",iFullName); sl@0: return KErrCorrupt; sl@0: } sl@0: sl@0: iLex.SkipSpace(); sl@0: if('=' != iLex.Get()) sl@0: { sl@0: __CENTREP_TRACE1("[%S] Missing '=' for 'mask' keyword for range [platsec]",iFullName); sl@0: return KErrCorrupt; sl@0: } sl@0: iLex.SkipSpace(); sl@0: TInt r = ReadNumberL(iLex,mask); sl@0: if(r!=KErrNone) sl@0: { sl@0: __CENTREP_TRACE1("[%S] Invalid value for 'mask' keyword [platsec]",iFullName); sl@0: return KErrCorrupt; sl@0: } sl@0: } sl@0: else sl@0: { sl@0: TInt r = ReadNumberL(iLex,highKey); sl@0: if(r!=KErrNone) sl@0: { sl@0: __CENTREP_TRACE1("[%S] Invalid end of range [platsec]",iFullName); sl@0: return KErrCorrupt; sl@0: } sl@0: } sl@0: TBool writePolicyFound = EFalse; sl@0: TBool readPolicyFound= EFalse; sl@0: TSecurityPolicy readPolicy; sl@0: TSecurityPolicy writePolicy; sl@0: sl@0: TInt ret=KErrNone; sl@0: ret=ReadRdPolicyL(readPolicy); sl@0: if (ret==KErrNone) sl@0: readPolicyFound=ETrue; sl@0: else sl@0: { sl@0: if (ret==KErrCorrupt || ret==KErrNoMemory) sl@0: { sl@0: #ifdef CENTREP_TRACE sl@0: if (ret == KErrCorrupt) sl@0: { sl@0: __CENTREP_TRACE1("[%S] Invalid read policy for range [platsec]",iFullName); sl@0: } sl@0: #endif sl@0: return ret; sl@0: } sl@0: //else if ret!=KErrNone very likely it is KErrNotFound so leave sl@0: //the state of the writePolicyFound to EFalse sl@0: } sl@0: ret=ReadWrPolicyL(writePolicy); sl@0: if (ret==KErrNone) sl@0: writePolicyFound=ETrue; sl@0: else sl@0: { sl@0: if (ret==KErrCorrupt || ret==KErrNoMemory) sl@0: { sl@0: #ifdef CENTREP_TRACE sl@0: if (ret == KErrCorrupt) sl@0: { sl@0: __CENTREP_TRACE1("[%S] Invalid write policy for range [platsec]",iFullName); sl@0: } sl@0: #endif sl@0: return ret; sl@0: } sl@0: //else if ret!=KErrNone very likely it is KErrNotFound so leave sl@0: //the state of the writePolicyFound to EFalse sl@0: } sl@0: //If only one of the policy is specified,need to set the other one to default value sl@0: //to prevent it from being uninitialized sl@0: if(readPolicyFound || writePolicyFound) sl@0: { sl@0: if (!readPolicyFound) sl@0: readPolicy=aDefaultReadPolicy; sl@0: if (!writePolicyFound) sl@0: writePolicy=aDefaultWritePolicy; sl@0: TSettingsAccessPolicy settingsPolicy(readPolicy,writePolicy, sl@0: lowKey, highKey, mask); sl@0: aRangePolicies.AppendL(settingsPolicy); sl@0: } sl@0: else sl@0: { sl@0: // range specified with no policies! sl@0: __CENTREP_TRACE1("[%S] Range specified with no policies [platsec]",iFullName); sl@0: return KErrCorrupt; sl@0: } sl@0: SkipComments(); sl@0: } sl@0: return KErrNone; sl@0: } sl@0: sl@0: /** sl@0: @internalTechnology sl@0: @return TCapability as converted from string description sl@0: @leave KErrNotFound sl@0: */ sl@0: TInt CIniFileIn::ReadCapabilityL(TCapability& aCapability) sl@0: { sl@0: iLex.SkipSpace(); sl@0: sl@0: if(iLex.Eos()) sl@0: User::Leave(KErrNotFound); sl@0: sl@0: // check if '=' still there and skip sl@0: SkipEqualSign(); sl@0: sl@0: iLex.Mark(); sl@0: sl@0: // potentially comma separated list of capabilities sl@0: // we read just one at the time sl@0: while(!iLex.Peek().IsSpace() && (iLex.Peek() != ',') && !iLex.Eos()) sl@0: { sl@0: iLex.Inc(); sl@0: if(iLex.TokenLength()>KMaxCapabilityStringLen) sl@0: { sl@0: __CENTREP_TRACE1("[%S] Invalid capability [platsec]",iFullName); sl@0: return KErrCorrupt; sl@0: } sl@0: } sl@0: sl@0: TBuf string; sl@0: string.CopyLC(iLex.MarkedToken()); sl@0: sl@0: // lets check against list of capabilities sl@0: TInt capability; sl@0: sl@0: // descriptors...desriptors - we need it for conversion from const char[] to TPtr sl@0: HBufC *cap = HBufC::NewLC(KMaxCapabilityStringLen); sl@0: TPtr capPtr = cap->Des() ; sl@0: HBufC8 *capNarrow = HBufC8::NewLC(KMaxCapabilityStringLen) ; sl@0: for(capability=0; capability(capability); sl@0: CleanupStack::PopAndDestroy(capNarrow); sl@0: CleanupStack::PopAndDestroy(cap); sl@0: return KErrNone; sl@0: } sl@0: } sl@0: CleanupStack::PopAndDestroy(capNarrow); sl@0: CleanupStack::PopAndDestroy(cap); sl@0: sl@0: // to satisfy compiler sl@0: aCapability=ECapability_Limit; sl@0: sl@0: __CENTREP_TRACE1("[%S] Invalid capability [platsec]",iFullName); sl@0: // we didn't find anything sl@0: return KErrCorrupt; sl@0: sl@0: } sl@0: sl@0: /** sl@0: @internalTechnology sl@0: @param aAlwaysPass will be true if the first capability is AlwaysPass sl@0: aAlwaysFail will be true if the first capability is AlwaysFail sl@0: */ sl@0: void CIniFileIn::CheckForAlwaysPassOrFailL(TBool& aAlwaysPass,TBool& aAlwaysFail) sl@0: { sl@0: iLex.SkipSpace(); sl@0: sl@0: if(iLex.Eos()) sl@0: User::Leave(KErrNotFound); sl@0: sl@0: // check if '=' still there and skip sl@0: SkipEqualSign(); sl@0: sl@0: iLex.Mark(); sl@0: // we are just checking if AlwaysPass has been set sl@0: while(!iLex.Peek().IsSpace() && !iLex.Eos()) sl@0: { sl@0: iLex.Inc(); sl@0: if(iLex.TokenLength()>KMaxCapabilityStringLen) sl@0: { sl@0: iLex.UnGetToMark(); sl@0: return; sl@0: } sl@0: sl@0: } sl@0: sl@0: TBuf string; sl@0: string.CopyLC(iLex.MarkedToken()); sl@0: sl@0: aAlwaysPass=(string.Compare(KAccessAlwaysPass)==0); sl@0: aAlwaysFail=(string.Compare(KAccessAlwaysFail)==0); sl@0: //if not either AlwaysPass or AlwaysFail reset the Lex position to Mark sl@0: if(!(aAlwaysPass || aAlwaysFail)) sl@0: iLex.UnGetToMark(); sl@0: } sl@0: sl@0: TInt CIniFileIn::ReadCapabilitiesL(TSecurityPolicy& aPolicy) sl@0: { sl@0: // we can have 0-7 capabilities sl@0: const TInt maxCapWithoutSid = 7; sl@0: TCapability capabilities[maxCapWithoutSid]; sl@0: TInt index = 0; sl@0: // initialise sl@0: for(index=0;index=maxCapWithoutSid) sl@0: { sl@0: __CENTREP_TRACE1("[%S] Too many read capabilities [platsec]",iFullName); sl@0: return KErrCorrupt; sl@0: } sl@0: // skip comma sl@0: iLex.SkipAndMark(1); sl@0: r=ReadCapabilityL(capabilities[index]); sl@0: if(r!=KErrNone) sl@0: return r; sl@0: // do we have yet more? sl@0: iLex.SkipSpace(); sl@0: index++; sl@0: } sl@0: TSecurityPolicy policy(static_cast(capabilities[0]), sl@0: static_cast(capabilities[1]), sl@0: static_cast(capabilities[2]), sl@0: static_cast(capabilities[3]), sl@0: static_cast(capabilities[4]), sl@0: static_cast(capabilities[5]), sl@0: static_cast(capabilities[6])); sl@0: aPolicy.Set(policy.Package()); sl@0: } sl@0: return KErrNone; sl@0: } sl@0: sl@0: TInt CIniFileIn::ReadSidAndCapabilitiesL(TSecurityPolicy& aPolicy,const TDesC& aPolicyType, sl@0: TSecureId& aSid) sl@0: { sl@0: //SID was specified we can have 0-3 capabilities sl@0: const TInt maxCapWithSid = 3; sl@0: sl@0: TCapability capabilities[maxCapWithSid]; sl@0: TInt index = 0; sl@0: for(index=0;index= KMaxAccessTypeLen) sl@0: { sl@0: // so no '=' there sl@0: // not necessarily bad thing... could be space there first sl@0: break; sl@0: } sl@0: sl@0: } sl@0: sl@0: TBuf string; sl@0: string.CopyLC(iLex.MarkedToken()); sl@0: sl@0: index = 0; sl@0: // lets check if there are any capabilities specified and if of correct type sl@0: if(0 == string.Compare(aPolicyType)) sl@0: { sl@0: //Need to check for AlwaysPass or AlwaysFail sl@0: TBool isAlwaysPass=EFalse; sl@0: TBool isAlwaysFail=EFalse; sl@0: CheckForAlwaysPassOrFailL(isAlwaysPass,isAlwaysFail); sl@0: if(isAlwaysPass || isAlwaysFail) sl@0: { sl@0: //default is set to EAlwaysFail sl@0: TSecurityPolicy policy; sl@0: if (isAlwaysPass) sl@0: policy=TSecurityPolicy(TSecurityPolicy::EAlwaysPass); sl@0: aPolicy.Set(policy.Package()); sl@0: } sl@0: else sl@0: { sl@0: // so we have some capabilities to read sl@0: TInt r = ReadCapabilityL(capabilities[index]); sl@0: if(r!=KErrNone) sl@0: return r; sl@0: // do we have more? sl@0: iLex.SkipSpace(); sl@0: index++; sl@0: while((iLex.Peek() == ',')) sl@0: { sl@0: //cannot permit more than 3 capabilities when followed by a SID sl@0: if (index>=maxCapWithSid) sl@0: { sl@0: __CENTREP_TRACE1("[%S] Too many read capabilities [platsec]",iFullName); sl@0: return KErrCorrupt; sl@0: } sl@0: // skip comma sl@0: iLex.SkipAndMark(1); sl@0: TInt r= ReadCapabilityL(capabilities[index]); sl@0: if(r!=KErrNone) sl@0: return r; sl@0: // do we have yet more? sl@0: iLex.SkipSpace(); sl@0: index++; sl@0: } sl@0: TSecurityPolicy policy(aSid,static_cast(capabilities[0]), sl@0: static_cast(capabilities[1]), sl@0: static_cast(capabilities[2])); sl@0: aPolicy.Set(policy.Package()); sl@0: } sl@0: } sl@0: else sl@0: { sl@0: // so no capabilities just SID sl@0: // and the token wasn't for us either sl@0: iLex.UnGetToMark(); sl@0: TSecurityPolicy policy(aSid); sl@0: aPolicy.Set(policy.Package()); sl@0: } sl@0: return KErrNone; sl@0: } sl@0: sl@0: sl@0: TInt CIniFileIn::ReadPolicyL(TSecurityPolicy& aPolicy,TInt aPolicyType) sl@0: { sl@0: sl@0: // lets check if there a SID is specified sl@0: iLex.SkipSpaceAndMark(); sl@0: sl@0: if(iLex.Eos()) sl@0: return KErrNotFound; sl@0: sl@0: while((iLex.Peek()!='=')&&(!iLex.Eos())) sl@0: { sl@0: iLex.Inc(); sl@0: sl@0: if(iLex.TokenLength() >= KMaxAccessTypeLen) sl@0: { sl@0: // so no '=' there sl@0: // not necessarily bad thing... could be space there first sl@0: break; sl@0: } sl@0: sl@0: } sl@0: sl@0: // we are looking for either KReadAccessSid, KReadAccessCap, KWriteAccessSid,KWriteAccessCap sl@0: TBuf accessString; sl@0: accessString.CopyLC(iLex.MarkedToken()); sl@0: iLex.SkipSpace(); sl@0: TInt returnCode = KErrNotFound; sl@0: // we expect a combination of sid_rd1 cap_rd1 sid_wr1 cap_wr1 sl@0: if(accessString.Compare(KReadAccessSidString)==0) sl@0: { sl@0: // we've got read - either SID or SID+CAP! Are we expecting read? sl@0: if(KReadPolicy == aPolicyType) sl@0: { sl@0: TUint32 sid; sl@0: SkipEqualSign(); sl@0: if (ReadNumber(sid) != KErrNone) sl@0: { sl@0: __CENTREP_TRACE1("[%S] Invalid SID (read)[platsec]",iFullName); sl@0: return KErrCorrupt; sl@0: } sl@0: TSecureId sidId(sid); sl@0: // so we read sid and now we expect cap_rd1=cap1,cap2,.. sl@0: // lets assume it's a SID+CAP for now sl@0: returnCode= ReadSidAndCapabilitiesL(aPolicy,KReadAccessCapString,sidId); sl@0: } sl@0: } sl@0: else if(accessString.Compare(KReadAccessCapString)==0) sl@0: { sl@0: // we've got read CAP only! Are we expecting read? sl@0: if(KReadPolicy == aPolicyType) sl@0: { sl@0: returnCode=ReadCapabilitiesL(aPolicy); sl@0: } sl@0: } sl@0: else if(accessString.Compare(KWriteAccessSidString)==0) sl@0: { sl@0: // we've got write - either SID or SID+CAP! Are we expecting read? sl@0: if(KWritePolicy == aPolicyType) sl@0: { sl@0: TUint32 sid; sl@0: SkipEqualSign(); sl@0: if(ReadNumber(sid)!=KErrNone) sl@0: { sl@0: __CENTREP_TRACE1("[%S] Invalid SID (write)[platsec]",iFullName); sl@0: return KErrCorrupt; sl@0: } sl@0: TSecureId sidId(sid); sl@0: // lets assume SID+CAP for now sl@0: returnCode= ReadSidAndCapabilitiesL(aPolicy,KWriteAccessCapString,sidId); sl@0: } sl@0: } sl@0: else if(accessString.Compare(KWriteAccessCapString)==0) sl@0: { sl@0: // we've got write CAP only! Are we expecting write? sl@0: if(KWritePolicy == aPolicyType) sl@0: { sl@0: returnCode=ReadCapabilitiesL(aPolicy); sl@0: } sl@0: } sl@0: if(KErrNone != returnCode) sl@0: iLex.UnGetToMark(); sl@0: sl@0: return returnCode; sl@0: } sl@0: sl@0: TInt CIniFileIn::ReadRdPolicyL(TSecurityPolicy& aReadPolicy) sl@0: { sl@0: return ReadPolicyL(aReadPolicy,KReadPolicy); sl@0: } sl@0: sl@0: TInt CIniFileIn::ReadWrPolicyL(TSecurityPolicy& aReadPolicy) sl@0: { sl@0: return ReadPolicyL(aReadPolicy,KWritePolicy); sl@0: } sl@0: sl@0: TInt CIniFileIn::ReadStringL(HBufC8*& aString) sl@0: { sl@0: iLex.Mark(); sl@0: sl@0: TChar c = iLex.Peek(); sl@0: TChar quote = 0; sl@0: if(c=='\'' || c=='\"') sl@0: { sl@0: iLex.SkipAndMark(1); sl@0: quote = c; sl@0: } sl@0: sl@0: TBool complete = EFalse; sl@0: sl@0: TInt len; sl@0: for(len=0;!iLex.Eos();len++) sl@0: { sl@0: c = iLex.Get(); sl@0: sl@0: if(quote ? c==quote : c.IsSpace()) sl@0: { sl@0: complete = ETrue; sl@0: break; sl@0: } sl@0: sl@0: if(c=='\\') sl@0: iLex.Get(); sl@0: } sl@0: sl@0: if(!complete || len>KMaxUnicodeStringLength) sl@0: return KErrCorrupt; sl@0: sl@0: aString = HBufC8::NewL(len*2); sl@0: TPtr8 ptr8 = aString->Des(); sl@0: ptr8.SetLength(len*2); sl@0: TPtr16 ptr16((TUint16*)ptr8.Ptr(), len, len); sl@0: sl@0: sl@0: iLex.UnGetToMark(); sl@0: sl@0: _LIT(KSpecialChars, "abfnrvt0"); sl@0: static TUint8 specialChars[] = { '\a', '\b', '\f', '\n', '\r', '\v', '\t', '\0' }; sl@0: for(TInt i=0;i=0) sl@0: c = specialChars[i]; sl@0: } sl@0: sl@0: ptr16[i] = (TUint16)c; sl@0: sl@0: } sl@0: sl@0: if(quote) sl@0: iLex.Inc(); // trailing quote sl@0: sl@0: return KErrNone; sl@0: } sl@0: sl@0: sl@0: sl@0: TInt CIniFileIn::ReadString16To8L(HBufC8*& aString) sl@0: { sl@0: iLex.Mark(); sl@0: sl@0: TChar c = iLex.Peek(); sl@0: TChar quote = 0; sl@0: if(c=='\'' || c=='\"') sl@0: { sl@0: iLex.SkipAndMark(1); sl@0: quote = c; sl@0: } sl@0: sl@0: TBool complete = EFalse; sl@0: sl@0: TInt len; sl@0: for(len=0;!iLex.Eos();len++) sl@0: { sl@0: c = iLex.Get(); sl@0: sl@0: if(quote ? c==quote : c.IsSpace()) sl@0: { sl@0: complete = ETrue; sl@0: break; sl@0: } sl@0: sl@0: if(c=='\\') sl@0: iLex.Get(); sl@0: } sl@0: sl@0: if(!complete || len>KMaxUnicodeStringLength) sl@0: return KErrCorrupt; sl@0: sl@0: aString = HBufC8::NewLC(len*2); sl@0: sl@0: HBufC16* tempBuffer = HBufC16::NewLC(len); sl@0: sl@0: TPtr16 ptr16 = tempBuffer->Des(); sl@0: TPtr8 ptr8 = aString->Des(); sl@0: ptr8.SetLength(len*2); sl@0: sl@0: sl@0: sl@0: iLex.UnGetToMark(); sl@0: sl@0: _LIT(KSpecialChars, "abfnrvt0"); sl@0: static TUint8 specialChars[] = { '\a', '\b', '\f', '\n', '\r', '\v', '\t', '\0' }; sl@0: for(TInt i=0;i=0) sl@0: c = specialChars[i]; sl@0: } sl@0: sl@0: ptr16.Append(c); sl@0: sl@0: } sl@0: sl@0: const TInt returnValue = CnvUtfConverter::ConvertFromUnicodeToUtf8(ptr8, ptr16); sl@0: if (returnValue==CnvUtfConverter::EErrorIllFormedInput) sl@0: { sl@0: CleanupStack::PopAndDestroy(tempBuffer); sl@0: CleanupStack::PopAndDestroy(aString); sl@0: return KErrCorrupt; sl@0: } sl@0: else if(returnValue<0) sl@0: User::Leave(KErrGeneral); sl@0: sl@0: CleanupStack::PopAndDestroy(tempBuffer); sl@0: CleanupStack::Pop(aString); sl@0: sl@0: if(quote) sl@0: iLex.Inc(); // trailing quote sl@0: sl@0: return KErrNone; sl@0: } sl@0: sl@0: TInt CIniFileIn::ReadBinaryL(HBufC8*& aString) sl@0: { sl@0: iLex.Mark(); sl@0: iLex.SkipCharacters(); sl@0: TInt len = iLex.TokenLength(); sl@0: iLex.UnGetToMark(); sl@0: sl@0: if(len==1 && iLex.Peek()==KNullDataIndicator) sl@0: { sl@0: iLex.Get(); sl@0: aString = HBufC8::NewL(0); sl@0: TPtr8 ptr8 = aString->Des(); sl@0: ptr8.SetLength(0); sl@0: return KErrNone; sl@0: } sl@0: sl@0: if(len>KMaxBinaryLength*2 || len%2) sl@0: { sl@0: delete aString; sl@0: return KErrCorrupt; sl@0: } sl@0: sl@0: len /= 2; sl@0: aString = HBufC8::NewL(len); sl@0: TPtr8 ptr8 = aString->Des(); sl@0: ptr8.SetLength(len); sl@0: sl@0: TBuf<2> buf(2); sl@0: for(TInt i=0;i buf; sl@0: TLexMark sectionMark; sl@0: aSection=NULL; sl@0: sl@0: SkipComments(); sl@0: sl@0: iLex.Mark(sectionMark); sl@0: sl@0: iLex.Mark(); sl@0: iLex.SkipCharacters(); sl@0: sl@0: if( (iLex.TokenLength() != aSectionId.Length()) && sl@0: (buf.CopyLC(iLex.MarkedToken()), buf.Compare( aSectionId )!=0) ) sl@0: { sl@0: // Expected section not found at this point in the file sl@0: // Note that this is not an error sl@0: iLex.UnGetToMark(); sl@0: return KErrNone; sl@0: } sl@0: sl@0: // sl@0: // Read in the section by grabbing text until we reach sl@0: // the start of another section. sl@0: // sl@0: while(!iLex.Eos()) sl@0: { sl@0: // Wait for any other section marker sl@0: SkipComments(); sl@0: sl@0: iLex.Mark(); sl@0: sl@0: iLex.SkipCharacters(); sl@0: sl@0: if(iLex.TokenLength() <= KBufLen) sl@0: { sl@0: buf.CopyLC(iLex.MarkedToken()); sl@0: if((buf.Compare(KMainSection) == 0) || sl@0: (buf.Compare(KOwnerSection) == 0) || sl@0: (buf.Compare(KPlatSecSection) == 0) || sl@0: (buf.Compare(KTimeStampSection) == 0) || sl@0: (buf.Compare(KDefaultMetaSection) == 0)) sl@0: { sl@0: iLex.Mark(iMainSectionMark); sl@0: iLex.UnGetToMark() ; sl@0: TPtrC lex = iLex.MarkedToken(sectionMark); sl@0: HBufC* section = HBufC::NewMaxLC(lex.Length()); //'\n' sl@0: TPtr ptr = section->Des(); sl@0: ptr.Copy(lex); sl@0: aSection=section; sl@0: return KErrNone; sl@0: } sl@0: } sl@0: } sl@0: return KErrCorrupt; sl@0: } sl@0: sl@0: TInt CIniFileIn::FindMainSectionL(void) sl@0: { sl@0: TBuf buf; sl@0: sl@0: // sl@0: // Check if a Main section is present sl@0: // sl@0: sl@0: SkipComments(); sl@0: sl@0: // we will need this section later to write the out file... sl@0: iLex.Mark(iMainSectionMark); sl@0: sl@0: iLex.Mark(); sl@0: iLex.SkipCharacters(); sl@0: sl@0: if( iLex.TokenLength()!=KMainSectionLen || sl@0: (buf.CopyLC( iLex.MarkedToken() ), buf.Compare( KMainSection )!=0) ) sl@0: { sl@0: // Meta not available sl@0: iLex.UnGetToMark(); sl@0: return KErrNotFound; sl@0: } sl@0: sl@0: iLex.Mark(iMainSectionMark); sl@0: return KErrNone ; sl@0: } sl@0: sl@0: #ifdef CENTREP_TRACE sl@0: HBufC* CIniFileIn::FullName() sl@0: { sl@0: return(iFullName); sl@0: } sl@0: #endif sl@0: sl@0: #ifdef CENTREP_CONV_TOOL sl@0: //=================================================================== sl@0: // TCompiledSecurityPolicy class sl@0: // Used for accessing private data members of TSecurityPolicy. It sl@0: // uses the fact that TSecurityPolicy class has a friend whose name sl@0: // is TCompiledSecurityPolicy. sl@0: // See dbms/tdbms/securitypolicy.h for similar strategy. sl@0: // sl@0: sl@0: // The longest possible security string is one that has 7 capabilities. sl@0: static const TInt KSecPolicyStrSize = KMaxCapabilityStringLen * 7 + 10; sl@0: sl@0: class TCompiledSecurityPolicy sl@0: { sl@0: public: sl@0: TCompiledSecurityPolicy(const TSecurityPolicy& aSecurityPolicy) : sl@0: iSecurityPolicy(aSecurityPolicy) { } sl@0: const TDesC& TextualizePolicyL(TCapAccessMode aMode); sl@0: sl@0: private: sl@0: enum THeaderType sl@0: { sl@0: EHdrSecureId, sl@0: EHdrCapability sl@0: }; sl@0: sl@0: TCapability CapabilityAt(TInt aIndex) const; sl@0: void DoCapabilitySection(TInt aMaxNumCaps); sl@0: void AppendModeHeader(TCapAccessMode aAccessMode, THeaderType aType); sl@0: sl@0: private: sl@0: const TSecurityPolicy& iSecurityPolicy; sl@0: TBuf iBuf; sl@0: }; sl@0: sl@0: ///////////////////////////////////////////////////////////////////////////////////////////////// sl@0: // CIniFileOut class sl@0: /** sl@0: Standard, phase-one CIniFileOut instance creation method. sl@0: The created CIniFileOut instance will use a temporary text file to store the repository settings. sl@0: CIniFileOut::CommitL() should be called at the end to finalize the changes. sl@0: @return A pointer to a fully constructed CIniFileOut instance. sl@0: @leave System-wide error codes, including KErrNoMemory. sl@0: */ sl@0: CIniFileOut* CIniFileOut::NewLC(RFs& aFs,const TDesC& aOutFileName) sl@0: { sl@0: CIniFileOut* inifile = new(ELeave) CIniFileOut(aFs); sl@0: CleanupStack::PushL(inifile); sl@0: inifile->ConstructL(aOutFileName); sl@0: return inifile; sl@0: } sl@0: sl@0: CIniFileOut::CIniFileOut(RFs& aFs) sl@0: : iCommited(EFalse), iTransFileBuf(4 * 1024),iFs(aFs)// 4K buffer size sl@0: { sl@0: } sl@0: sl@0: /** sl@0: Standard, phase-two CIniFileOut instance creation method. sl@0: Creates the transaction file. sl@0: Initializes transaction file buffer - iTransFileBuf instance. sl@0: @leave System-wide error codes, including KErrNoMemory. sl@0: */ sl@0: void CIniFileOut::ConstructL(const TDesC& aOutFileName) sl@0: { sl@0: iOutFileName=aOutFileName.AllocL(); sl@0: _LIT(KTmpExtension,"tmp"); sl@0: User::LeaveIfError(iTransFilePath.Set(aOutFileName, NULL, &(KTmpExtension()))); sl@0: User::LeaveIfError(iTransFile.Replace(iFs, iTransFilePath.FullName(), EFileWrite | EFileStreamText)); sl@0: iTransFileBuf.Attach(iTransFile, 0); sl@0: } sl@0: sl@0: /** sl@0: Closes and deletes the transaction file. sl@0: If CIniFileOut::CommitL() has not been called prior the destructor call, all the changes sl@0: will be lost. sl@0: */ sl@0: CIniFileOut::~CIniFileOut() sl@0: { sl@0: if (!iCommited) sl@0: { sl@0: iTransFileBuf.Close(); sl@0: // If a debug build - record error sl@0: TInt fileDeleteErr=iFs.Delete(iTransFilePath.FullName()); sl@0: #ifdef _DEBUG sl@0: if (fileDeleteErr != KErrNone) sl@0: { sl@0: RDebug::Print(_L("CIniFileOut::~CIniFileOut - Failed to delete file. Error = %d"), fileDeleteErr); sl@0: } sl@0: #else sl@0: (void)fileDeleteErr; sl@0: #endif sl@0: sl@0: } sl@0: delete iOutFileName; sl@0: } sl@0: sl@0: /** sl@0: The method writes supplied setting value to the output file. sl@0: @param aSetting Setting instance, which value has to be written to the output file. sl@0: @param accessPolicies A string descriptor, referencing related to aSetting access policies. sl@0: @leave System-wide error codes, including KErrNoMemory. sl@0: */ sl@0: void CIniFileOut::WriteSettingL(const TServerSetting& aSetting sl@0: #ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS sl@0: ,TUint32 aCreVersion sl@0: #endif sl@0: ) sl@0: { sl@0: iBuf.Zero(); sl@0: DoSettingL(aSetting sl@0: #ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS sl@0: ,aCreVersion sl@0: #endif sl@0: ); sl@0: WriteLineL(iBuf); sl@0: } sl@0: sl@0: void CIniFileOut::WriteSettingL(const TServerSetting& aSetting, sl@0: const TSettingsAccessPolicy& aAccessPolicy sl@0: #ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS sl@0: ,TUint32 aCreVersion sl@0: #endif sl@0: ) sl@0: { sl@0: iBuf.Zero(); sl@0: DoSettingL(aSetting sl@0: #ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS sl@0: ,aCreVersion sl@0: #endif sl@0: ); sl@0: iBuf.Append(KSpace); sl@0: #ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS sl@0: if (aCreVersion<2 || (aCreVersion>=2 && aAccessPolicy.iHighKey!=0)) sl@0: #endif sl@0: AppendSecurityPolicyL(aAccessPolicy.iReadAccessPolicy, ECapReadAccess); sl@0: iBuf.Append(KSpace); sl@0: #ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS sl@0: if (aCreVersion<2 || (aCreVersion>=2 && aAccessPolicy.iKeyMask!=0)) sl@0: #endif sl@0: AppendSecurityPolicyL(aAccessPolicy.iWriteAccessPolicy, ECapWriteAccess); sl@0: WriteLineL(iBuf); sl@0: } sl@0: sl@0: void CIniFileOut::DoSettingL(const TServerSetting& aSetting sl@0: #ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS sl@0: ,TUint32 aCreVersion sl@0: #endif sl@0: ) sl@0: { sl@0: iBuf.AppendNum(aSetting.Key(), EDecimal); sl@0: iBuf.Append(KSpace); sl@0: sl@0: ::AddSettingValueL(iBuf, aSetting); sl@0: sl@0: iBuf.Append(KSpace); sl@0: sl@0: if (!aSetting.Meta()) sl@0: { sl@0: iBuf.AppendNum(0, EDecimal); sl@0: } sl@0: else sl@0: { sl@0: #ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS sl@0: //need to check on the CRE Version too sl@0: TBool isClean=const_cast(aSetting).IsClean(); sl@0: if (aCreVersion<2 || (aCreVersion>=2 && (aSetting.IsIndividualMeta() || (!aSetting.IsIndividualMeta() && isClean )))) sl@0: { sl@0: TUint32 metaToWrite=aSetting.Meta(); sl@0: //special case sl@0: if (aCreVersion>=2 && isClean && aSetting.IsIndividualMeta()) sl@0: { sl@0: metaToWrite|=KMetaIndividual; sl@0: } sl@0: iBuf.AppendFormat(KHexIntFormat, metaToWrite); sl@0: } sl@0: #else sl@0: iBuf.AppendFormat(KHexIntFormat, aSetting.Meta()); sl@0: #endif sl@0: } sl@0: } sl@0: sl@0: /** sl@0: The method commits settings file changes. sl@0: If the commit operation fails, the existing settings file will stay unchanged. sl@0: @leave System-wide error codes. sl@0: */ sl@0: void CIniFileOut::CommitL() sl@0: { sl@0: iTransFileBuf.SynchL(); sl@0: iTransFileBuf.Close(); sl@0: sl@0: User::LeaveIfError(iFs.Replace(iTransFilePath.FullName(),*iOutFileName)); sl@0: sl@0: iCommited = ETrue; sl@0: } sl@0: sl@0: void CIniFileOut::WriteMainSectionHeaderL() sl@0: { sl@0: WriteLineL(KMainSection()); sl@0: } sl@0: sl@0: /** sl@0: Writes a text line to the repository file. sl@0: @param aData The string which will be written to the file as a single text line sl@0: @leave System-wide error codes sl@0: */ sl@0: void CIniFileOut::WriteLineL(const TDesC& aData) sl@0: { sl@0: iTransFileBuf.WriteL(reinterpret_cast (aData.Ptr()), aData.Size()); sl@0: iTransFileBuf.WriteL(reinterpret_cast (KCrNl().Ptr()), KCrNl().Size()); sl@0: } sl@0: sl@0: /** sl@0: Writes repository file header. sl@0: @leave System-wide error codes sl@0: */ sl@0: void CIniFileOut::WriteHeaderL() sl@0: { sl@0: TBuf<64> buf; sl@0: sl@0: buf.Append(KUcs2Bom); sl@0: buf.Append(KSignature); sl@0: WriteLineL(buf); sl@0: sl@0: buf.Zero(); sl@0: buf.Append(KVersion); sl@0: buf.Append(KSpace); sl@0: buf.AppendNum(KCurrentVersion); sl@0: buf.Append(KCrNl); sl@0: WriteLineL(buf); sl@0: } sl@0: sl@0: /** sl@0: Writes owner section to repository file. sl@0: */ sl@0: void CIniFileOut::WriteOwnerSectionL(TUid aOwner) sl@0: { sl@0: if (aOwner.iUid != 0) sl@0: { sl@0: WriteLineL(KOwnerSection()); sl@0: TBuf<32> buf; sl@0: buf.Format(KUidFormat, aOwner.iUid); sl@0: buf.Append(KCrNl); sl@0: WriteLineL(buf); sl@0: } sl@0: } sl@0: sl@0: /** sl@0: Writes time stamp to repository file. sl@0: @param aTime Time stamp sl@0: @leave System-wide error codes sl@0: */ sl@0: void CIniFileOut::WriteTimeStampL(const TTime& aTime) sl@0: { sl@0: if(aTime.Int64() != 0) sl@0: { sl@0: WriteLineL(KTimeStampSection()); sl@0: TBuf<32> buf; sl@0: buf.Num(aTime.Int64()); sl@0: buf.Append(KCrNl); sl@0: WriteLineL(buf); sl@0: } sl@0: } sl@0: sl@0: /** sl@0: Writes meta data to repository file. sl@0: @param aFileIn Input repository file sl@0: @leave System-wide error codes sl@0: */ sl@0: void CIniFileOut::WriteMetaDataL(TUint32 aDefaultMeta, sl@0: const RDefaultMetaArray& aDefaultMetaRanges) sl@0: { sl@0: if (!aDefaultMeta && !aDefaultMetaRanges.Count()) sl@0: { sl@0: return; sl@0: } sl@0: sl@0: WriteLineL(KDefaultMetaSection); sl@0: sl@0: if (aDefaultMeta) sl@0: { sl@0: iBuf.Format(KHexIntFormat, aDefaultMeta); sl@0: WriteLineL(iBuf); sl@0: } sl@0: sl@0: for (TInt i = 0; i=2 && aDefaultAccessPolicy.iHighKey!=0)) sl@0: AppendSecurityPolicyL(*(aDefaultAccessPolicy.GetReadAccessPolicy()), ECapReadAccess); sl@0: iBuf.Append(KSpace); sl@0: if (aCreVersion<2 || (aCreVersion>=2 && aDefaultAccessPolicy.iKeyMask!=0)) sl@0: AppendSecurityPolicyL(*(aDefaultAccessPolicy.GetWriteAccessPolicy()), ECapWriteAccess); sl@0: #else sl@0: AppendSecurityPolicyL(aDefaultReadPolicy, ECapReadAccess); sl@0: iBuf.Append(KSpace); sl@0: AppendSecurityPolicyL(aDefaultWritePolicy, ECapWriteAccess); sl@0: #endif sl@0: WriteLineL(iBuf); sl@0: sl@0: for(TInt i=0; i < aRangePolicies.Count(); i++) sl@0: { sl@0: const TSettingsAccessPolicy& e = aRangePolicies[i]; sl@0: if (e.iHighKey != 0) sl@0: { sl@0: iBuf.Format(KRangePrefix, e.iLowKey, e.iHighKey); sl@0: } sl@0: else sl@0: { sl@0: iBuf.Format(KMaskPrefix, e.iLowKey, e.iKeyMask); sl@0: } sl@0: sl@0: iBuf.Append(KSpace); sl@0: sl@0: AppendSecurityPolicyL(e.iReadAccessPolicy, ECapReadAccess); sl@0: iBuf.Append(KSpace); sl@0: AppendSecurityPolicyL(e.iWriteAccessPolicy, ECapWriteAccess); sl@0: WriteLineL(iBuf); sl@0: } sl@0: sl@0: WriteLineL(KCrNl()); sl@0: } sl@0: sl@0: void CIniFileOut::AppendSecurityPolicyL(const TSecurityPolicy& aPolicy, sl@0: TCapAccessMode aRdWrMode) sl@0: { sl@0: TCompiledSecurityPolicy policy(aPolicy); sl@0: iBuf.Append(policy.TextualizePolicyL(aRdWrMode)); sl@0: } sl@0: sl@0: ///////////////////////////////////////////////////////////////////////////////////////////////// sl@0: const TDesC& TCompiledSecurityPolicy::TextualizePolicyL(TCapAccessMode aMode) sl@0: { sl@0: iBuf.Zero(); sl@0: AppendModeHeader(aMode, EHdrCapability); sl@0: sl@0: switch (static_cast(iSecurityPolicy.iType)) sl@0: { sl@0: case TSecurityPolicy::ETypeFail: sl@0: iBuf.Append(KAccessAlwaysFail); sl@0: break; sl@0: case TSecurityPolicy::ETypePass: sl@0: iBuf.Append(KAccessAlwaysPass); sl@0: break; sl@0: case TSecurityPolicy::ETypeC3: sl@0: DoCapabilitySection(3); sl@0: break; sl@0: case TSecurityPolicy::ETypeC7: sl@0: DoCapabilitySection(7); sl@0: break; sl@0: case TSecurityPolicy::ETypeS3: sl@0: iBuf.Zero(); // erase the "cap_rd", replace with sid_rd sl@0: AppendModeHeader(aMode, EHdrSecureId); sl@0: iBuf.AppendNum(iSecurityPolicy.iSecureId); sl@0: sl@0: if (ECapability_HardLimit != iSecurityPolicy.iCaps[0]) sl@0: { sl@0: iBuf.Append(KSpace); sl@0: AppendModeHeader(aMode, EHdrCapability); sl@0: DoCapabilitySection(3); sl@0: } sl@0: break; sl@0: sl@0: default: sl@0: User::Leave(KErrCorrupt); sl@0: } // switch sl@0: sl@0: return iBuf; sl@0: } sl@0: sl@0: TCapability TCompiledSecurityPolicy::CapabilityAt(TInt aIndex) const sl@0: { sl@0: if (aIndex < 3) sl@0: { sl@0: return static_cast (iSecurityPolicy.iCaps[aIndex]); sl@0: } sl@0: else if(aIndex < 7) sl@0: { sl@0: return static_cast (iSecurityPolicy.iExtraCaps[aIndex - 3]); sl@0: } sl@0: return ECapability_None; sl@0: } sl@0: sl@0: // sl@0: void TCompiledSecurityPolicy::DoCapabilitySection(TInt aMaxNumCaps) sl@0: { sl@0: for (TInt i = 0; i < aMaxNumCaps; i++) sl@0: { sl@0: TCapability cap = CapabilityAt(i); sl@0: sl@0: if (cap<0 || cap>= ECapability_Limit) sl@0: { sl@0: return; sl@0: } sl@0: if (i > 0) sl@0: { sl@0: iBuf.Append(','); sl@0: } sl@0: sl@0: for (const char* p=CapabilityNames[cap]; *p; p++) sl@0: { sl@0: iBuf.Append((TUint16)*p); sl@0: } sl@0: } // for i sl@0: } sl@0: sl@0: void TCompiledSecurityPolicy::AppendModeHeader(TCapAccessMode aAccessMode, sl@0: THeaderType aType) sl@0: { sl@0: if (aAccessMode == ECapReadAccess) sl@0: { sl@0: if (aType == EHdrSecureId) sl@0: { sl@0: iBuf.Append(KReadAccessSidString); // "sid_rd" sl@0: } sl@0: else sl@0: { sl@0: iBuf.Append(KReadAccessCapString); // "cap_rd" sl@0: } sl@0: } sl@0: else sl@0: { sl@0: if (aType == EHdrSecureId) sl@0: { sl@0: iBuf.Append(KWriteAccessSidString); // "sid_wr" sl@0: } sl@0: else sl@0: { sl@0: iBuf.Append(KWriteAccessCapString); // "cap_wr" sl@0: } sl@0: } sl@0: iBuf.Append('='); sl@0: } sl@0: #endif //CENTREP_CONV_TOOL