|
1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #define __INCLUDE_CAPABILITY_NAMES__ |
|
17 #include <utf.h> |
|
18 #include "inifile.h" |
|
19 #include "datatype.h" |
|
20 #include "log.h" |
|
21 |
|
22 #define MAX(a,b) ((a)<(b)?(b):(a)) |
|
23 #define MAX3(a,b,c) MAX(MAX(a,b),c) |
|
24 #define MAX4(a,b,c,d) MAX(MAX(a,b),MAX(c,d)) |
|
25 |
|
26 //Unicode text file prefix - FE,FF bytes. |
|
27 static const TUint16 KUcs2Bom = 0xfeff; |
|
28 |
|
29 //Repository (ini) file - signature |
|
30 _LIT(KSignature, "cenrep"); |
|
31 static const TInt KSignatureLen = 6; |
|
32 |
|
33 //Repository (ini) file - version string and version number |
|
34 _LIT(KVersion, "version"); |
|
35 static const TInt KVersionLen = 7; |
|
36 static const TUint KCurrentVersion = 1; |
|
37 |
|
38 //Repository (ini) file - supported types names |
|
39 _LIT(KTypeInt, "int"); |
|
40 _LIT(KTypeReal, "real"); |
|
41 _LIT(KTypeString, "string"); |
|
42 _LIT(KTypeString8, "string8"); |
|
43 _LIT(KTypeBinary, "binary"); |
|
44 |
|
45 //Max type name length |
|
46 static const TInt KMaxTypeLen = 9; |
|
47 |
|
48 //The symbol used in repository (ini) files to note null data |
|
49 static const TChar KNullDataIndicator = '-'; |
|
50 |
|
51 // Section identifiers in the repository (ini) file |
|
52 _LIT(KPlatSecSection, "[platsec]"); |
|
53 static const TInt KPlatSecSectionLen = 9; |
|
54 |
|
55 _LIT(KOwnerSection, "[owner]"); |
|
56 static const TInt KOwnerSectionLen = 7; |
|
57 |
|
58 _LIT(KTimeStampSection, "[timestamp]"); |
|
59 static const TInt KTimeStampSectionLen = 11; |
|
60 |
|
61 _LIT(KMainSection, "[main]"); |
|
62 static const TInt KMainSectionLen = 6; |
|
63 |
|
64 _LIT(KDefaultMetaSection, "[defaultmeta]"); |
|
65 static const TInt KDefaultMetaSectionLen = 13 ; |
|
66 |
|
67 static const TInt KIniFileSectionLen = MAX4(KPlatSecSectionLen,KMainSectionLen,KTimeStampSectionLen, KDefaultMetaSectionLen); |
|
68 |
|
69 // Other useful string constants |
|
70 _LIT(KMaskString, "mask"); |
|
71 static const TInt KMaskLen = 4; |
|
72 |
|
73 _LIT(KReadAccessSidString, "sid_rd"); |
|
74 _LIT(KReadAccessCapString, "cap_rd"); |
|
75 _LIT(KWriteAccessSidString, "sid_wr"); |
|
76 _LIT(KWriteAccessCapString, "cap_wr"); |
|
77 _LIT(KAccessAlwaysPass, "alwayspass"); |
|
78 _LIT(KAccessAlwaysFail, "alwaysfail"); |
|
79 // could do max of _LITs above |
|
80 static const TInt KMaxAccessTypeLen = 6; |
|
81 |
|
82 // longest capability string from CapabilityNames is 15 |
|
83 static const TInt KMaxCapabilityStringLen = 20; |
|
84 |
|
85 static const TInt KBufLen = MAX3(KVersionLen, KSignatureLen, KIniFileSectionLen); |
|
86 |
|
87 |
|
88 |
|
89 const TUint KCr = '\r'; |
|
90 const TUint KTab = '\t'; |
|
91 const TUint KSpace = ' '; |
|
92 |
|
93 #ifdef CENTREP_CONV_TOOL |
|
94 _LIT(KTransactFileName, "transact"); |
|
95 _LIT(KCrNl, "\r\n"); |
|
96 _LIT(KHexIntFormat, "0x%X"); |
|
97 _LIT(KUidFormat, "0x%08X"); |
|
98 _LIT(KRangeMetaFmt, "0x%X 0x%X 0x%08X"); |
|
99 _LIT(KMaskMetaFmt, "0x%X mask = 0x%X 0x%08X"); |
|
100 |
|
101 _LIT(KRangePrefix, "0x%X 0x%X"); |
|
102 _LIT(KMaskPrefix, "0x%08X mask = 0x%08X"); |
|
103 #endif |
|
104 |
|
105 ///////////////////////////////////////////////////////////////////////////////////////////////// |
|
106 // Local functions |
|
107 |
|
108 /** |
|
109 The function checks if the file with aFile name exists. |
|
110 @param aFile File name, including the full path. |
|
111 @return 0, if the file does not exist, non-zero value otherwise. |
|
112 @internalComponent |
|
113 */ |
|
114 /** |
|
115 #ifdef CENTREP_CONV_TOOL |
|
116 static TBool FileExists(const TDesC& aFile) |
|
117 { |
|
118 TEntry entry; |
|
119 return TServerResources::iFs.Entry(aFile, entry) == KErrNone; |
|
120 } |
|
121 #endif |
|
122 */ |
|
123 |
|
124 /** |
|
125 @internalComponent |
|
126 */ |
|
127 static TInt ReadFileL(RFile aFile, HBufC16*& aBuf) |
|
128 { |
|
129 TInt size; |
|
130 TInt r = aFile.Size(size); |
|
131 if(r!=KErrNone) |
|
132 return r; |
|
133 if(size<2) |
|
134 return KErrCorrupt; |
|
135 |
|
136 TInt len = size/2-1; |
|
137 aBuf = HBufC16::NewL(len); |
|
138 TPtr16 ptr16 = aBuf->Des(); |
|
139 TPtr8 ptr8((TUint8*)ptr16.Ptr(), 0, 2); |
|
140 r = aFile.Read(ptr8, 2); |
|
141 if(r!=KErrNone) |
|
142 return r; |
|
143 |
|
144 if(*ptr16.Ptr()!=KUcs2Bom) |
|
145 { |
|
146 __CENTREP_TRACE("File not Ucs2. No BOM"); |
|
147 return KErrCorrupt; |
|
148 } |
|
149 ptr8.Set((TUint8*)ptr16.Ptr(), 0, size-2); |
|
150 r = aFile.Read(ptr8); |
|
151 if(r!=KErrNone) |
|
152 return r; |
|
153 ptr16.SetLength(len); |
|
154 |
|
155 return KErrNone; |
|
156 } |
|
157 |
|
158 static TBool IsNegativeNumber(TLex& aLex) |
|
159 { |
|
160 if (aLex.Peek()=='-') |
|
161 return ETrue; |
|
162 else |
|
163 return EFalse; |
|
164 } |
|
165 |
|
166 /** |
|
167 @internalComponent |
|
168 */ |
|
169 static TInt ReadNumberL(TLex& aLex, TUint32& aVal) |
|
170 { |
|
171 TRadix radix = EDecimal; |
|
172 if(aLex.Peek()=='0') |
|
173 { |
|
174 aLex.Inc(); |
|
175 if(aLex.Peek().GetLowerCase()=='x') |
|
176 { |
|
177 aLex.Inc(); |
|
178 radix = EHex; |
|
179 } |
|
180 else |
|
181 aLex.UnGet(); |
|
182 } |
|
183 |
|
184 if(aLex.Val(aVal, radix)!=KErrNone) |
|
185 return KErrCorrupt; |
|
186 |
|
187 return KErrNone; |
|
188 } |
|
189 |
|
190 #ifdef CENTREP_CONV_TOOL |
|
191 /** |
|
192 @internalComponent |
|
193 */ |
|
194 static void WriteBinary(TDes& aBuf, const HBufC8* aString) |
|
195 { |
|
196 if(aString) |
|
197 { |
|
198 TInt len = aString->Length(); |
|
199 if(len==0) |
|
200 aBuf.Append(KNullDataIndicator); |
|
201 else |
|
202 { |
|
203 TPtr8 ptr8 = const_cast<HBufC8*>(aString)->Des(); |
|
204 for(TInt i=0;i<len;i++) |
|
205 aBuf.AppendNumFixedWidth(ptr8[i], EHex, 2); |
|
206 } |
|
207 } |
|
208 else |
|
209 { |
|
210 aBuf.Append(KNullDataIndicator); |
|
211 } |
|
212 } |
|
213 |
|
214 /** |
|
215 The function writes setting value into the supplied buffer (aBuf). |
|
216 @param aBuf The buffer where the setting value will be appended. |
|
217 @param aSetting Reference to the setting object |
|
218 @leave KErrGeneral If the supplied setting object has unknown type. |
|
219 @internalComponent |
|
220 */ |
|
221 static void AddSettingValueL(TDes& aBuf, const TServerSetting& aSetting) |
|
222 { |
|
223 switch(aSetting.Type()) |
|
224 { |
|
225 case TServerSetting::EInt: |
|
226 aBuf.Append(KTypeInt); |
|
227 aBuf.Append(KSpace); |
|
228 aBuf.AppendNum(aSetting.GetIntValue()); |
|
229 break; |
|
230 case TServerSetting::EReal: |
|
231 aBuf.Append(KTypeReal); |
|
232 aBuf.Append(KSpace); |
|
233 aBuf.AppendNum(aSetting.GetRealValue(), TRealFormat()); |
|
234 break; |
|
235 case TServerSetting::EString: |
|
236 aBuf.Append(KTypeBinary); |
|
237 aBuf.Append(KSpace); |
|
238 WriteBinary(aBuf, aSetting.GetStrValue()); |
|
239 break; |
|
240 default: |
|
241 User::Leave(KErrGeneral); //unknown setting type |
|
242 break; |
|
243 } |
|
244 } |
|
245 #endif |
|
246 |
|
247 ///////////////////////////////////////////////////////////////////////////////////////////////// |
|
248 // CIniFileIn class |
|
249 |
|
250 TInt CIniFileIn::NewLC(RFs& aFs,CIniFileIn*& aIniFile,const TDesC& aFullFileName) |
|
251 { |
|
252 aIniFile = new(ELeave) CIniFileIn(aFs); |
|
253 CleanupStack::PushL(aIniFile); |
|
254 RFile file; |
|
255 CleanupClosePushL(file); |
|
256 TInt r = file.Open(aFs, aFullFileName, EFileRead|EFileStreamText); |
|
257 if(r==KErrNone) |
|
258 { |
|
259 |
|
260 #ifdef CENTREP_TRACE |
|
261 aIniFile->iFullName = HBufC::NewL(aFullFileName.Length()); |
|
262 TPtr filename = aIniFile->iFullName->Des(); |
|
263 filename.Copy(aFullFileName); |
|
264 #endif |
|
265 TInt rReadFile = ReadFileL(file,aIniFile->iBuf); |
|
266 CleanupStack::PopAndDestroy(); //file |
|
267 TInt rReadHeader=KErrNone; |
|
268 if(rReadFile==KErrNone) |
|
269 { |
|
270 aIniFile->iLex.Assign(aIniFile->iBuf->Des()); |
|
271 rReadHeader=aIniFile->ReadHeaderL(); |
|
272 } |
|
273 |
|
274 if((rReadFile==KErrCorrupt) || ( rReadHeader==KErrCorrupt)) |
|
275 { |
|
276 return KErrCorrupt; |
|
277 } |
|
278 } |
|
279 else |
|
280 { |
|
281 CleanupStack::Pop();//file |
|
282 } |
|
283 return r; |
|
284 |
|
285 |
|
286 } |
|
287 |
|
288 CIniFileIn::~CIniFileIn() |
|
289 { |
|
290 delete iBuf; |
|
291 #ifdef CENTREP_TRACE |
|
292 delete iFullName; |
|
293 #endif |
|
294 } |
|
295 |
|
296 |
|
297 TInt CIniFileIn::ReadHeaderL() |
|
298 { |
|
299 TBuf<KBufLen> buf; |
|
300 |
|
301 // |
|
302 // Check file signature |
|
303 // |
|
304 |
|
305 SkipComments(); |
|
306 |
|
307 iLex.Mark(); |
|
308 iLex.SkipCharacters(); |
|
309 |
|
310 if(iLex.TokenLength()>KSignatureLen) |
|
311 { |
|
312 __CENTREP_TRACE1("[%S] Invalid header signature",iFullName); |
|
313 return(KErrCorrupt); |
|
314 } |
|
315 buf.CopyLC(iLex.MarkedToken()); |
|
316 if(buf.Compare(KSignature)!=0) |
|
317 { |
|
318 __CENTREP_TRACE1("[%S] Invalid header signature",iFullName); |
|
319 return(KErrCorrupt); |
|
320 } |
|
321 // |
|
322 // Check file version |
|
323 // |
|
324 |
|
325 SkipComments(); |
|
326 |
|
327 iLex.Mark(); |
|
328 iLex.SkipCharacters(); |
|
329 |
|
330 if(iLex.TokenLength()>KVersionLen) |
|
331 { |
|
332 __CENTREP_TRACE1("[%S] Missing version keyword",iFullName); |
|
333 return(KErrCorrupt); |
|
334 } |
|
335 buf.CopyLC(iLex.MarkedToken()); |
|
336 if(buf.Compare(KVersion)!=0) |
|
337 { |
|
338 __CENTREP_TRACE1("[%S] Missing version keyword",iFullName); |
|
339 return(KErrCorrupt); |
|
340 } |
|
341 iLex.SkipSpace(); |
|
342 |
|
343 TUint version; |
|
344 iLex.Val(version); |
|
345 if(version>KCurrentVersion) |
|
346 { |
|
347 __CENTREP_TRACE1("[%S] Invalid version number",iFullName); |
|
348 return(KErrNotSupported); |
|
349 } |
|
350 return( KErrNone); |
|
351 } |
|
352 |
|
353 void CIniFileIn::SkipComments() |
|
354 { |
|
355 for(;;) |
|
356 { |
|
357 iLex.SkipSpace(); |
|
358 |
|
359 if(iLex.Peek()!='#') |
|
360 break; |
|
361 |
|
362 while(iLex.Get()!='\n' && !iLex.Eos()) {} |
|
363 } |
|
364 } |
|
365 |
|
366 void CIniFileIn::SkipEqualSign() |
|
367 { |
|
368 iLex.SkipSpace(); |
|
369 if(iLex.Peek()=='=') |
|
370 iLex.Get(); |
|
371 |
|
372 iLex.SkipSpace(); |
|
373 } |
|
374 |
|
375 TInt CIniFileIn::ReadSettingOnlyL(TServerSetting& aSetting,TBool& aSingleMetaFound) |
|
376 { |
|
377 TInt ret = KErrNone; |
|
378 |
|
379 aSingleMetaFound=EFalse; |
|
380 |
|
381 SkipComments(); |
|
382 iLex.SkipSpace(); |
|
383 |
|
384 if(iLex.Eos()) |
|
385 return KErrNotFound; |
|
386 |
|
387 TUint32 key; |
|
388 TInt r=ReadNumberL(iLex, key); |
|
389 if(r!=KErrNone) |
|
390 { |
|
391 // returns either KErrCorrupt or KErrNone |
|
392 __CENTREP_TRACE1("[%S] Invalid single setting id",iFullName); |
|
393 return r; |
|
394 } |
|
395 aSetting.SetKey(key); |
|
396 |
|
397 iLex.SkipSpaceAndMark(); |
|
398 iLex.SkipCharacters(); |
|
399 |
|
400 if(iLex.TokenLength()>KMaxTypeLen) |
|
401 { |
|
402 __CENTREP_TRACE1("[%S] Invalid key type, must be one of: [int,real,string,string8,binary]",iFullName); |
|
403 return KErrCorrupt; |
|
404 } |
|
405 TBuf<KMaxTypeLen> type; |
|
406 type.CopyLC(iLex.MarkedToken()); |
|
407 |
|
408 iLex.SkipSpace(); |
|
409 |
|
410 if(type.Compare(KTypeInt)==0) |
|
411 { |
|
412 if (IsNegativeNumber(iLex)) |
|
413 { |
|
414 TInt i; |
|
415 if(iLex.Val(i)!=KErrNone) |
|
416 { |
|
417 __CENTREP_TRACE1("[%S] Invalid negative integer value",iFullName); |
|
418 return(KErrCorrupt); |
|
419 } |
|
420 aSetting.SetIntValue(i); |
|
421 } |
|
422 else |
|
423 { |
|
424 TUint32 i; |
|
425 TInt r=ReadNumberL(iLex, i); |
|
426 if(r!=KErrNone) |
|
427 { |
|
428 __CENTREP_TRACE1("[%S] Invalid integer value",iFullName); |
|
429 return r; |
|
430 } |
|
431 aSetting.SetIntValue(i); |
|
432 } |
|
433 } |
|
434 else if(type.Compare(KTypeReal)==0) |
|
435 { |
|
436 TReal r; |
|
437 ret=iLex.Val(r,'.'); |
|
438 //iLex.Val with TReal can return KErrNoMemory |
|
439 if (ret!=KErrNone) |
|
440 { |
|
441 if (ret==KErrNoMemory) |
|
442 User::LeaveNoMemory(); |
|
443 else |
|
444 { |
|
445 __CENTREP_TRACE1("[%S] Invalid real value",iFullName); |
|
446 return KErrCorrupt; |
|
447 } |
|
448 } |
|
449 TReal* temp = new(ELeave)TReal(r); |
|
450 aSetting.SetRealValue(temp); |
|
451 temp = NULL; |
|
452 } |
|
453 else if(type.Compare(KTypeString)==0) |
|
454 { |
|
455 HBufC8* s; |
|
456 ret = ReadStringL(s); |
|
457 if(ret != KErrNone) |
|
458 { |
|
459 __CENTREP_TRACE1("[%S] Invalid string value",iFullName); |
|
460 return KErrCorrupt; |
|
461 } |
|
462 aSetting.SetStrValue(s); |
|
463 } |
|
464 |
|
465 else if(type.Compare(KTypeString8)==0) |
|
466 { |
|
467 HBufC8* s; |
|
468 ret = ReadString16To8L(s); |
|
469 if(ret != KErrNone) |
|
470 { |
|
471 __CENTREP_TRACE1("[%S] Invalid string8 value",iFullName); |
|
472 return KErrCorrupt; |
|
473 } |
|
474 aSetting.SetStrValue(s); |
|
475 } |
|
476 |
|
477 else if(type.Compare(KTypeBinary)==0) |
|
478 { |
|
479 HBufC8* s = NULL; |
|
480 ret = ReadBinaryL(s); |
|
481 if(ret != KErrNone) |
|
482 { |
|
483 __CENTREP_TRACE1("[%S] Invalid binary value",iFullName); |
|
484 return KErrCorrupt; |
|
485 } |
|
486 aSetting.SetStrValue(s); |
|
487 } |
|
488 else |
|
489 { |
|
490 __CENTREP_TRACE1("[%S] Invalid key type, must be one of: [int,real,string,string8,binary]",iFullName); |
|
491 return KErrCorrupt; |
|
492 } |
|
493 //skip any spaces or tabs |
|
494 while(iLex.Peek()==KSpace || iLex.Peek()==KTab) |
|
495 { |
|
496 iLex.Inc(); |
|
497 } |
|
498 |
|
499 TUint32 meta; |
|
500 |
|
501 /** |
|
502 carriage return reached which means that there is no meta AND capabilities |
|
503 defined for this key. Thus setting meta to NULL to be able to set a value |
|
504 from default section later. |
|
505 */ |
|
506 if (iLex.Peek()==KCr) |
|
507 { |
|
508 meta = 0; |
|
509 } |
|
510 else |
|
511 { |
|
512 r=ReadNumberL(iLex, meta); |
|
513 /** |
|
514 If meta can not be read, it is not neccessary an error. |
|
515 It might be not present for an individual key and it will be taken |
|
516 from a default section. |
|
517 If single meta is present, we need to remember so we can recognise a single |
|
518 meta of 0 as distinct from no meta ( also sets meta to 0 ). |
|
519 */ |
|
520 if(r!=KErrNone) |
|
521 meta = 0; |
|
522 else |
|
523 aSingleMetaFound=ETrue; |
|
524 } |
|
525 |
|
526 aSetting.SetMeta(meta); |
|
527 |
|
528 return KErrNone; |
|
529 } |
|
530 |
|
531 /** |
|
532 Read an entire DefaultMeta section from ini file |
|
533 and create FDefault metadata entries |
|
534 |
|
535 @internalTechnology |
|
536 @return KErrNone, KErrCorrupt or KErrNotFound |
|
537 */ |
|
538 TInt CIniFileIn::ReadDefaultMetaSecSectionL(TUint32& aDefaultMeta, RDefaultMetaArray& aDefaultMetaRanges) |
|
539 { |
|
540 TBuf<KBufLen> buf; |
|
541 |
|
542 // |
|
543 // Check if a DefaultMeta section is present |
|
544 // |
|
545 |
|
546 SkipComments(); |
|
547 |
|
548 // we will need this section later to write the out file... |
|
549 iLex.Mark(iMainSectionMark); |
|
550 |
|
551 iLex.Mark(); |
|
552 iLex.SkipCharacters(); |
|
553 |
|
554 if( iLex.TokenLength()!=KDefaultMetaSectionLen || |
|
555 (buf.CopyLC( iLex.MarkedToken() ), buf.Compare( KDefaultMetaSection )!=0) ) |
|
556 { |
|
557 // Meta not available |
|
558 iLex.UnGetToMark(); |
|
559 return KErrNotFound; |
|
560 } |
|
561 |
|
562 // |
|
563 // Lets read Meta settings |
|
564 // |
|
565 |
|
566 SkipComments(); |
|
567 |
|
568 // we might have a default Meta section first |
|
569 if(KErrNone != ReadNumber(aDefaultMeta)) |
|
570 { |
|
571 // should we log that no default read policy? |
|
572 } |
|
573 |
|
574 |
|
575 // now lets try range policies |
|
576 TInt r=ReadRangeMetaDefaultsL(aDefaultMetaRanges); |
|
577 if(r!=KErrNone) |
|
578 { |
|
579 __CENTREP_TRACE1("[%S] Error parsing [defaultMeta]",iFullName); |
|
580 return r; |
|
581 } |
|
582 iLex.Mark(iMainSectionMark); |
|
583 return KErrNone; |
|
584 } |
|
585 |
|
586 |
|
587 /** |
|
588 Reads Meta defaults as defined for range of indexes |
|
589 |
|
590 @internalTechnology |
|
591 @return KErrNone, KErrCorrupt |
|
592 */ |
|
593 TInt CIniFileIn::ReadRangeMetaDefaultsL(RDefaultMetaArray& aDefaultMetaRanges) |
|
594 { |
|
595 TUint32 lowKey = 0; |
|
596 TBuf<KBufLen> buf; |
|
597 |
|
598 SkipComments(); |
|
599 while(KErrNone == ReadNumber(lowKey)) |
|
600 { |
|
601 // highKey and mask needs to be zero'd every cycle... |
|
602 TUint32 highKey = 0; |
|
603 TUint32 mask = 0; |
|
604 TUint32 defaultMeta = 0 ; |
|
605 |
|
606 iLex.SkipSpace(); |
|
607 // may be not range but key & mask so lets check 'mask' keyword |
|
608 if(!iLex.Peek().IsDigit()) |
|
609 { |
|
610 //so should be mask then... |
|
611 iLex.Mark(); |
|
612 while((iLex.Peek()!='=')&&(!iLex.Eos())) |
|
613 { |
|
614 iLex.Inc(); |
|
615 |
|
616 if(iLex.TokenLength() >= KMaskLen) |
|
617 { |
|
618 // so no '=' there |
|
619 // not necessarily bad thing... could be space there first |
|
620 break; |
|
621 } |
|
622 |
|
623 } |
|
624 |
|
625 // check if KMaskLen is < buf length? |
|
626 buf.CopyLC(iLex.MarkedToken()); |
|
627 if(buf.Compare(KMaskString)!=0) |
|
628 { |
|
629 __CENTREP_TRACE1("[%S] Missing 'mask' keyword [defaultMeta]",iFullName); |
|
630 return KErrCorrupt; |
|
631 } |
|
632 |
|
633 iLex.SkipSpace(); |
|
634 if('=' != iLex.Get()) |
|
635 { |
|
636 __CENTREP_TRACE1("[%S] Missing '=' for 'mask' keyword [defaultMeta]",iFullName); |
|
637 return KErrCorrupt; |
|
638 } |
|
639 iLex.SkipSpace(); |
|
640 TInt r=ReadNumberL(iLex,mask); |
|
641 if(r!=KErrNone) |
|
642 { |
|
643 __CENTREP_TRACE1("[%S] Invalid 'mask' for keyspace range [defaultMeta]",iFullName); |
|
644 return KErrCorrupt; |
|
645 } |
|
646 } |
|
647 else |
|
648 { |
|
649 TInt r = ReadNumberL(iLex,highKey); |
|
650 if(r!=KErrNone) |
|
651 { |
|
652 __CENTREP_TRACE1("[%S] Invalid end of range [defaultMeta]",iFullName); |
|
653 return KErrCorrupt; |
|
654 } |
|
655 } |
|
656 |
|
657 |
|
658 if(KErrNone == ReadNumber(defaultMeta)) |
|
659 { |
|
660 TSettingsDefaultMeta metaDefault(defaultMeta,lowKey, highKey, mask); |
|
661 aDefaultMetaRanges.AppendL(metaDefault); |
|
662 } |
|
663 else |
|
664 { |
|
665 // unfortunately, we can't tell if we got here because the default |
|
666 // meta was bad or because there was an invalid start value for the range. |
|
667 __CENTREP_TRACE1("[%S] Range defined without default or bad start of range [defaultMeta]",iFullName); |
|
668 // range specified with no default Meta! |
|
669 return KErrCorrupt; |
|
670 } |
|
671 SkipComments(); |
|
672 } |
|
673 return KErrNone; |
|
674 } |
|
675 |
|
676 /** |
|
677 Read Owner section from ini file and extract owner UID |
|
678 |
|
679 @internalTechnology |
|
680 @return KErrNone, KErrCorrupt or KErrNotFound |
|
681 */ |
|
682 TInt CIniFileIn::ReadOwnerSectionL(TUint32 &aOwnerUID) |
|
683 { |
|
684 TBuf<KBufLen> buf; |
|
685 |
|
686 |
|
687 |
|
688 SkipComments(); |
|
689 |
|
690 // we will need this section later to write the out file... |
|
691 iLex.Mark(iMainSectionMark); |
|
692 |
|
693 iLex.Mark(); |
|
694 iLex.SkipCharacters(); |
|
695 |
|
696 if( iLex.TokenLength()!=KOwnerSectionLen || |
|
697 (buf.CopyLC( iLex.MarkedToken() ), buf.Compare( KOwnerSection )!=0) ) |
|
698 { |
|
699 // Owner section not available |
|
700 iLex.UnGetToMark(); |
|
701 return KErrNotFound; |
|
702 } |
|
703 else |
|
704 { |
|
705 // Found an "owner" section - must be followed by a UID (hex number |
|
706 // in format 0xnnnnn) to be valid! |
|
707 iLex.SkipSpace() ; |
|
708 if(iLex.Peek()=='0') |
|
709 { |
|
710 iLex.Inc(); |
|
711 if(iLex.Peek().GetLowerCase()=='x') |
|
712 { |
|
713 iLex.Inc(); |
|
714 if(iLex.Val(aOwnerUID, EHex)!=KErrNone) |
|
715 { |
|
716 __CENTREP_TRACE1("[%S] Invalid owner UID not valid hex digit [owner]",iFullName); |
|
717 return KErrCorrupt; |
|
718 } |
|
719 } |
|
720 else |
|
721 { |
|
722 __CENTREP_TRACE1("[%S] Invalid owner UID not valid hex digit [owner]",iFullName); |
|
723 return KErrCorrupt; |
|
724 } |
|
725 } |
|
726 else |
|
727 { |
|
728 __CENTREP_TRACE1("[%S] Invalid owner UID not valid hex digit [owner]",iFullName); |
|
729 return KErrCorrupt; |
|
730 } |
|
731 } |
|
732 |
|
733 iLex.Mark(iMainSectionMark); |
|
734 |
|
735 return KErrNone; |
|
736 } |
|
737 |
|
738 /** |
|
739 Read Timestamp section from ini file and extract value as a TTime |
|
740 |
|
741 @internalTechnology |
|
742 @return KErrNone, KErrCorrupt or KErrNotFound |
|
743 */ |
|
744 TInt CIniFileIn::ReadTimeStampSectionL(TTime &aTimeStamp) |
|
745 { |
|
746 TBuf<25> buf; |
|
747 SkipComments(); |
|
748 |
|
749 // we will need this section later to write the out file... |
|
750 iLex.Mark(iMainSectionMark); |
|
751 |
|
752 iLex.Mark(); |
|
753 iLex.SkipCharacters(); |
|
754 |
|
755 buf.CopyLC( iLex.MarkedToken()); |
|
756 |
|
757 if( iLex.TokenLength()!=KTimeStampSectionLen || |
|
758 (buf.Compare( KTimeStampSection )!=0) ) |
|
759 { |
|
760 // Timestamp section not available |
|
761 iLex.UnGetToMark(); |
|
762 return KErrNotFound; |
|
763 } |
|
764 else |
|
765 { |
|
766 // Found a "timestamp" section - must be followed by a a timestamp |
|
767 // either in format... |
|
768 // |
|
769 // YYYYMMDD:HHMMSS.MMMMMM where: |
|
770 // YYYY = 4 digit year |
|
771 // MM = 2 digit numeric month |
|
772 // DD = 2 digit numeric date |
|
773 // HH = 2 digit hour |
|
774 // MM = 2 digit minute |
|
775 // SS = 2 digit second |
|
776 // MMMMMM = 6 digit microseconds |
|
777 // Note that this is the format used for constructing/initialising |
|
778 // a TTime from a string. |
|
779 // |
|
780 // ...or a 64-bit integer which can be converted to |
|
781 // to a TTime to be considered valid! |
|
782 // |
|
783 iLex.SkipSpace(); |
|
784 iLex.Mark(); |
|
785 iLex.SkipCharacters() ; |
|
786 |
|
787 buf.CopyLC(iLex.MarkedToken()) ; |
|
788 if (aTimeStamp.Set(buf) !=KErrNone) |
|
789 { |
|
790 TInt64 intTimeStamp ; |
|
791 iLex.UnGetToMark(); |
|
792 if (iLex.Val(intTimeStamp) != KErrNone) |
|
793 { |
|
794 __CENTREP_TRACE1("[%S] Invalid time stamp [timestamp]",iFullName); |
|
795 return KErrCorrupt; |
|
796 } |
|
797 else |
|
798 { |
|
799 aTimeStamp = intTimeStamp; |
|
800 } |
|
801 } |
|
802 } |
|
803 iLex.Mark(iMainSectionMark); |
|
804 return KErrNone; |
|
805 } |
|
806 |
|
807 /** |
|
808 Read a setting and it's single policy ( if it exists ) |
|
809 |
|
810 @internalTechnology |
|
811 @return KErrNone, KErrCorrupt |
|
812 aSetting setting read from ini file |
|
813 aSingleReadPolicy single read policy if any |
|
814 aSingleWritePolicy single write policy if any |
|
815 aSingleReadPolicyFound ETrue if single read policy found with this key, EFalse if not |
|
816 aSingleWritePolicyFound ETrue if single write policy found with this key, EFalse if not |
|
817 aSingleMetaFound ETrue if single metadata found with this key, EFalse if not |
|
818 */ |
|
819 TInt CIniFileIn::ReadSettingL(TServerSetting& aSetting,TSecurityPolicy& aSingleReadPolicy,TSecurityPolicy& aSingleWritePolicy, TBool& aSingleReadPolicyFound, TBool& aSingleWritePolicyFound, TBool& aSingleMetaFound) |
|
820 { |
|
821 aSingleReadPolicyFound = EFalse; |
|
822 aSingleWritePolicyFound = EFalse; |
|
823 |
|
824 TInt error = ReadSettingOnlyL(aSetting, aSingleMetaFound); |
|
825 if(KErrNone == error) |
|
826 { |
|
827 //Need to push into cleanupstack for string setting |
|
828 aSetting.PushL(); |
|
829 // when multiple policies enabled then read in a loop |
|
830 |
|
831 if (iLex.Peek() !=KCr) |
|
832 { |
|
833 // if neither read/write policy found we do not create TSettingsAccessPolicy at all... |
|
834 TInt err=ReadRdPolicyL(aSingleReadPolicy); |
|
835 if (err==KErrNone) |
|
836 aSingleReadPolicyFound=ETrue; |
|
837 else |
|
838 { |
|
839 //we need to return error code rather than assuming no single policy is found |
|
840 if (err==KErrCorrupt || err==KErrNoMemory) |
|
841 { |
|
842 #ifdef CENTREP_TRACE |
|
843 if (err == KErrCorrupt) |
|
844 { |
|
845 __CENTREP_TRACE1("[%S] Invalid read setting",iFullName); |
|
846 } |
|
847 #endif |
|
848 aSetting.PopAndDestroy(); |
|
849 return err; |
|
850 } |
|
851 //else if ret!=KErrNone very likely it is KErrNotFound so leave |
|
852 //the state of the writePolicyFound to EFalse |
|
853 } |
|
854 |
|
855 err=ReadWrPolicyL(aSingleWritePolicy); |
|
856 if (err==KErrNone) |
|
857 aSingleWritePolicyFound=ETrue; |
|
858 else |
|
859 { |
|
860 //we need to return error code rather than assuming no single policy is found |
|
861 if (err==KErrCorrupt || err==KErrNoMemory) |
|
862 { |
|
863 #ifdef CENTREP_TRACE |
|
864 if (err == KErrCorrupt) |
|
865 { |
|
866 __CENTREP_TRACE1("[%S] Invalid write setting",iFullName); |
|
867 } |
|
868 #endif |
|
869 aSetting.PopAndDestroy(); |
|
870 return err; |
|
871 } |
|
872 //else if ret!=KErrNone very likely it is KErrNotFound so leave |
|
873 //the state of the writePolicyFound to EFalse |
|
874 } |
|
875 } |
|
876 |
|
877 //Need to pop back the setting |
|
878 aSetting.Pop(); |
|
879 } |
|
880 return error; |
|
881 } |
|
882 |
|
883 TInt CIniFileIn::SkipPlatSecSectionL() |
|
884 { |
|
885 HBufC* platSecSection; |
|
886 TInt r=GetPlatSecSectionLC(platSecSection); |
|
887 if(platSecSection) |
|
888 CleanupStack::PopAndDestroy(platSecSection); |
|
889 return r; |
|
890 } |
|
891 |
|
892 TInt CIniFileIn::SkipOwnerSectionL() |
|
893 { |
|
894 HBufC* ownerSection; |
|
895 TInt r=GetOwnerSectionLC(ownerSection); |
|
896 if(ownerSection) |
|
897 CleanupStack::PopAndDestroy(ownerSection); |
|
898 return r; |
|
899 } |
|
900 |
|
901 TInt CIniFileIn::SkipDefaultMetaSectionL() |
|
902 { |
|
903 HBufC* section; |
|
904 TInt r=GetDefaultMetaSectionLC(section); |
|
905 if(section) |
|
906 CleanupStack::PopAndDestroy(section); |
|
907 return r; |
|
908 } |
|
909 |
|
910 TInt CIniFileIn::SkipTimeStampSectionL() |
|
911 { |
|
912 HBufC* timeStampSection; |
|
913 TInt r=GetTimeStampSectionLC(timeStampSection); |
|
914 if(timeStampSection) |
|
915 CleanupStack::PopAndDestroy(timeStampSection); |
|
916 return r; |
|
917 } |
|
918 |
|
919 /** |
|
920 Read an entire PlatSec section from ini file |
|
921 and create TSecurityPolicy for default access and for range of indexes |
|
922 |
|
923 @internalTechnology |
|
924 @return KErrNone, KErrCorrupt or KErrNotFound |
|
925 */ |
|
926 TInt CIniFileIn::ReadPlatSecSectionL(TSecurityPolicy& aDefaultReadPolicy, TBool& aGotDefaultReadPolicy, |
|
927 TSecurityPolicy& aDefaultWritePolicy, TBool& aGotDefaultWritePolicy, |
|
928 RRangePolicyArray& aRangePolicies) |
|
929 |
|
930 { |
|
931 TBuf<KBufLen> buf; |
|
932 |
|
933 aGotDefaultReadPolicy = EFalse ; |
|
934 aGotDefaultWritePolicy = EFalse ; |
|
935 |
|
936 // |
|
937 // Check if the PlatSec section is present |
|
938 // |
|
939 SkipComments(); |
|
940 |
|
941 // we will need this section later to write the out file... |
|
942 iLex.Mark(iMainSectionMark); |
|
943 |
|
944 iLex.Mark(); |
|
945 iLex.SkipCharacters(); |
|
946 |
|
947 if( iLex.TokenLength()!=KPlatSecSectionLen || |
|
948 (buf.CopyLC( iLex.MarkedToken() ), buf.Compare( KPlatSecSection )!=0) ) |
|
949 { |
|
950 // PlatSec section not available |
|
951 iLex.UnGetToMark(); |
|
952 return KErrNotFound; |
|
953 } |
|
954 |
|
955 // |
|
956 // Lets read the policies |
|
957 // |
|
958 |
|
959 SkipComments(); |
|
960 TInt r=KErrNone; |
|
961 // we might have a default policies first |
|
962 // check for default read policy |
|
963 r=ReadRdPolicyL(aDefaultReadPolicy); |
|
964 if (r==KErrNone) |
|
965 aGotDefaultReadPolicy=ETrue; |
|
966 else |
|
967 { |
|
968 //we need to return error code rather than assuming no default policy is found |
|
969 if (r==KErrCorrupt || r==KErrNoMemory) |
|
970 { |
|
971 #ifdef CENTREP_TRACE |
|
972 if (r == KErrCorrupt) |
|
973 { |
|
974 __CENTREP_TRACE1("[%S] Invalid read policy [platsec]",iFullName); |
|
975 } |
|
976 #endif |
|
977 return r; |
|
978 } |
|
979 //else if ret!=KErrNone very likely it is KErrNotFound so leave |
|
980 //the state of the writePolicyFound to EFalse |
|
981 } |
|
982 // check for default write policy |
|
983 r=ReadWrPolicyL(aDefaultWritePolicy); |
|
984 if (r==KErrNone) |
|
985 aGotDefaultWritePolicy=ETrue; |
|
986 else |
|
987 { |
|
988 //we need to return error code rather than assuming no default policy is found |
|
989 if (r==KErrCorrupt || r==KErrNoMemory) |
|
990 { |
|
991 #ifdef CENTREP_TRACE |
|
992 if (r == KErrCorrupt) |
|
993 { |
|
994 __CENTREP_TRACE1("[%S] Invalid write policy [platsec]",iFullName); |
|
995 } |
|
996 #endif |
|
997 return r; |
|
998 } |
|
999 //else if ret!=KErrNone very likely it is KErrNotFound so leave |
|
1000 //the state of the writePolicyFound to EFalse |
|
1001 } |
|
1002 // now lets try range policies |
|
1003 r = ReadRangePoliciesL(aDefaultReadPolicy,aDefaultWritePolicy,aRangePolicies); |
|
1004 if(r!=KErrNone) |
|
1005 { |
|
1006 __CENTREP_TRACE1("[%S] Invalid range policy [platsec]",iFullName); |
|
1007 return KErrCorrupt; |
|
1008 } |
|
1009 // it must be the main section now so lets check |
|
1010 SkipComments(); |
|
1011 iLex.Mark(); |
|
1012 iLex.SkipCharacters(); |
|
1013 |
|
1014 if(iLex.TokenLength()>KBufLen) |
|
1015 return KErrCorrupt; |
|
1016 |
|
1017 buf.CopyLC(iLex.MarkedToken()); |
|
1018 if(buf.Compare(KMainSection)!=0) |
|
1019 { |
|
1020 return KErrCorrupt; |
|
1021 } |
|
1022 |
|
1023 iLex.Mark(iMainSectionMark); |
|
1024 |
|
1025 return KErrNone; |
|
1026 } |
|
1027 |
|
1028 /** |
|
1029 Reads TSecurityPolicy as defined for range of indexes |
|
1030 |
|
1031 @internalTechnology |
|
1032 @return KErrNone, KErrCorrupt |
|
1033 @leave KErrNotFound |
|
1034 */ |
|
1035 TInt CIniFileIn::ReadRangePoliciesL(const TSecurityPolicy& aDefaultReadPolicy, |
|
1036 const TSecurityPolicy& aDefaultWritePolicy, |
|
1037 RRangePolicyArray& aRangePolicies) |
|
1038 { |
|
1039 TUint32 lowKey = 0; |
|
1040 TBuf<KBufLen> buf; |
|
1041 |
|
1042 SkipComments(); |
|
1043 while(KErrNone == ReadNumber(lowKey)) |
|
1044 { |
|
1045 // highKey and mask needs to be zero'd every cycle... |
|
1046 TUint32 highKey = 0; |
|
1047 TUint32 mask = 0; |
|
1048 iLex.SkipSpace(); |
|
1049 // may be not range but key & mask so lets check 'mask' keyword |
|
1050 if(!iLex.Peek().IsDigit()) |
|
1051 { |
|
1052 //so should be mask then... |
|
1053 iLex.Mark(); |
|
1054 while((iLex.Peek()!='=')&&(!iLex.Eos())) |
|
1055 { |
|
1056 iLex.Inc(); |
|
1057 |
|
1058 if(iLex.TokenLength() >= KMaskLen) |
|
1059 { |
|
1060 // so no '=' there |
|
1061 // not necessarily bad thing... could be space there first |
|
1062 break; |
|
1063 } |
|
1064 |
|
1065 } |
|
1066 |
|
1067 // check if KMaskLen is < buf length? |
|
1068 buf.CopyLC(iLex.MarkedToken()); |
|
1069 if(buf.Compare(KMaskString)!=0) |
|
1070 { |
|
1071 __CENTREP_TRACE1("[%S] Missing 'mask' keyword for range [platsec]",iFullName); |
|
1072 return KErrCorrupt; |
|
1073 } |
|
1074 |
|
1075 iLex.SkipSpace(); |
|
1076 if('=' != iLex.Get()) |
|
1077 { |
|
1078 __CENTREP_TRACE1("[%S] Missing '=' for 'mask' keyword for range [platsec]",iFullName); |
|
1079 return KErrCorrupt; |
|
1080 } |
|
1081 iLex.SkipSpace(); |
|
1082 TInt r = ReadNumberL(iLex,mask); |
|
1083 if(r!=KErrNone) |
|
1084 { |
|
1085 __CENTREP_TRACE1("[%S] Invalid value for 'mask' keyword [platsec]",iFullName); |
|
1086 return KErrCorrupt; |
|
1087 } |
|
1088 } |
|
1089 else |
|
1090 { |
|
1091 TInt r = ReadNumberL(iLex,highKey); |
|
1092 if(r!=KErrNone) |
|
1093 { |
|
1094 __CENTREP_TRACE1("[%S] Invalid end of range [platsec]",iFullName); |
|
1095 return KErrCorrupt; |
|
1096 } |
|
1097 } |
|
1098 TBool writePolicyFound = EFalse; |
|
1099 TBool readPolicyFound= EFalse; |
|
1100 TSecurityPolicy readPolicy; |
|
1101 TSecurityPolicy writePolicy; |
|
1102 |
|
1103 TInt ret=KErrNone; |
|
1104 ret=ReadRdPolicyL(readPolicy); |
|
1105 if (ret==KErrNone) |
|
1106 readPolicyFound=ETrue; |
|
1107 else |
|
1108 { |
|
1109 if (ret==KErrCorrupt || ret==KErrNoMemory) |
|
1110 { |
|
1111 #ifdef CENTREP_TRACE |
|
1112 if (ret == KErrCorrupt) |
|
1113 { |
|
1114 __CENTREP_TRACE1("[%S] Invalid read policy for range [platsec]",iFullName); |
|
1115 } |
|
1116 #endif |
|
1117 return ret; |
|
1118 } |
|
1119 //else if ret!=KErrNone very likely it is KErrNotFound so leave |
|
1120 //the state of the writePolicyFound to EFalse |
|
1121 } |
|
1122 ret=ReadWrPolicyL(writePolicy); |
|
1123 if (ret==KErrNone) |
|
1124 writePolicyFound=ETrue; |
|
1125 else |
|
1126 { |
|
1127 if (ret==KErrCorrupt || ret==KErrNoMemory) |
|
1128 { |
|
1129 #ifdef CENTREP_TRACE |
|
1130 if (ret == KErrCorrupt) |
|
1131 { |
|
1132 __CENTREP_TRACE1("[%S] Invalid write policy for range [platsec]",iFullName); |
|
1133 } |
|
1134 #endif |
|
1135 return ret; |
|
1136 } |
|
1137 //else if ret!=KErrNone very likely it is KErrNotFound so leave |
|
1138 //the state of the writePolicyFound to EFalse |
|
1139 } |
|
1140 //If only one of the policy is specified,need to set the other one to default value |
|
1141 //to prevent it from being uninitialized |
|
1142 if(readPolicyFound || writePolicyFound) |
|
1143 { |
|
1144 if (!readPolicyFound) |
|
1145 readPolicy=aDefaultReadPolicy; |
|
1146 if (!writePolicyFound) |
|
1147 writePolicy=aDefaultWritePolicy; |
|
1148 TSettingsAccessPolicy settingsPolicy(readPolicy,writePolicy, |
|
1149 lowKey, highKey, mask); |
|
1150 aRangePolicies.AppendL(settingsPolicy); |
|
1151 } |
|
1152 else |
|
1153 { |
|
1154 // range specified with no policies! |
|
1155 __CENTREP_TRACE1("[%S] Range specified with no policies [platsec]",iFullName); |
|
1156 return KErrCorrupt; |
|
1157 } |
|
1158 SkipComments(); |
|
1159 } |
|
1160 return KErrNone; |
|
1161 } |
|
1162 |
|
1163 /** |
|
1164 @internalTechnology |
|
1165 @return TCapability as converted from string description |
|
1166 @leave KErrNotFound |
|
1167 */ |
|
1168 TInt CIniFileIn::ReadCapabilityL(TCapability& aCapability) |
|
1169 { |
|
1170 iLex.SkipSpace(); |
|
1171 |
|
1172 if(iLex.Eos()) |
|
1173 User::Leave(KErrNotFound); |
|
1174 |
|
1175 // check if '=' still there and skip |
|
1176 SkipEqualSign(); |
|
1177 |
|
1178 iLex.Mark(); |
|
1179 |
|
1180 // potentially comma separated list of capabilities |
|
1181 // we read just one at the time |
|
1182 while(!iLex.Peek().IsSpace() && (iLex.Peek() != ',') && !iLex.Eos()) |
|
1183 { |
|
1184 iLex.Inc(); |
|
1185 if(iLex.TokenLength()>KMaxCapabilityStringLen) |
|
1186 { |
|
1187 __CENTREP_TRACE1("[%S] Invalid capability [platsec]",iFullName); |
|
1188 return KErrCorrupt; |
|
1189 } |
|
1190 } |
|
1191 |
|
1192 TBuf<KMaxCapabilityStringLen> string; |
|
1193 string.CopyLC(iLex.MarkedToken()); |
|
1194 |
|
1195 // lets check against list of capabilities |
|
1196 TInt capability; |
|
1197 |
|
1198 // descriptors...desriptors - we need it for conversion from const char[] to TPtr |
|
1199 HBufC *cap = HBufC::NewLC(KMaxCapabilityStringLen); |
|
1200 TPtr capPtr = cap->Des() ; |
|
1201 HBufC8 *capNarrow = HBufC8::NewLC(KMaxCapabilityStringLen) ; |
|
1202 for(capability=0; capability<ECapability_Limit; capability++) |
|
1203 { |
|
1204 // CapabilityNames is const char[] |
|
1205 *capNarrow = (const TUint8 *)CapabilityNames[capability]; |
|
1206 |
|
1207 capPtr.Copy(*capNarrow); |
|
1208 capPtr.LowerCase(); |
|
1209 if(0 == string.Compare(capPtr)) |
|
1210 { |
|
1211 aCapability=static_cast<TCapability>(capability); |
|
1212 CleanupStack::PopAndDestroy(capNarrow); |
|
1213 CleanupStack::PopAndDestroy(cap); |
|
1214 return KErrNone; |
|
1215 } |
|
1216 } |
|
1217 CleanupStack::PopAndDestroy(capNarrow); |
|
1218 CleanupStack::PopAndDestroy(cap); |
|
1219 |
|
1220 // to satisfy compiler |
|
1221 aCapability=ECapability_Limit; |
|
1222 |
|
1223 __CENTREP_TRACE1("[%S] Invalid capability [platsec]",iFullName); |
|
1224 // we didn't find anything |
|
1225 return KErrCorrupt; |
|
1226 |
|
1227 } |
|
1228 |
|
1229 /** |
|
1230 @internalTechnology |
|
1231 @param aAlwaysPass will be true if the first capability is AlwaysPass |
|
1232 aAlwaysFail will be true if the first capability is AlwaysFail |
|
1233 */ |
|
1234 void CIniFileIn::CheckForAlwaysPassOrFailL(TBool& aAlwaysPass,TBool& aAlwaysFail) |
|
1235 { |
|
1236 iLex.SkipSpace(); |
|
1237 |
|
1238 if(iLex.Eos()) |
|
1239 User::Leave(KErrNotFound); |
|
1240 |
|
1241 // check if '=' still there and skip |
|
1242 SkipEqualSign(); |
|
1243 |
|
1244 iLex.Mark(); |
|
1245 // we are just checking if AlwaysPass has been set |
|
1246 while(!iLex.Peek().IsSpace() && !iLex.Eos()) |
|
1247 { |
|
1248 iLex.Inc(); |
|
1249 if(iLex.TokenLength()>KMaxCapabilityStringLen) |
|
1250 { |
|
1251 iLex.UnGetToMark(); |
|
1252 return; |
|
1253 } |
|
1254 |
|
1255 } |
|
1256 |
|
1257 TBuf<KMaxCapabilityStringLen> string; |
|
1258 string.CopyLC(iLex.MarkedToken()); |
|
1259 |
|
1260 aAlwaysPass=(string.Compare(KAccessAlwaysPass)==0); |
|
1261 aAlwaysFail=(string.Compare(KAccessAlwaysFail)==0); |
|
1262 //if not either AlwaysPass or AlwaysFail reset the Lex position to Mark |
|
1263 if(!(aAlwaysPass || aAlwaysFail)) |
|
1264 iLex.UnGetToMark(); |
|
1265 } |
|
1266 |
|
1267 TInt CIniFileIn::ReadCapabilitiesL(TSecurityPolicy& aPolicy) |
|
1268 { |
|
1269 // we can have 0-7 capabilities |
|
1270 const TInt maxCapWithoutSid = 7; |
|
1271 TCapability capabilities[maxCapWithoutSid]; |
|
1272 TInt index = 0; |
|
1273 // initialise |
|
1274 for(index=0;index<maxCapWithoutSid;index++) |
|
1275 capabilities[index] = ECapability_None; |
|
1276 |
|
1277 index = 0; |
|
1278 |
|
1279 // lets read the first capability... there must be at least one! |
|
1280 TBool isAlwaysPass=EFalse; |
|
1281 TBool isAlwaysFail=EFalse; |
|
1282 CheckForAlwaysPassOrFailL(isAlwaysPass,isAlwaysFail); |
|
1283 if(isAlwaysPass || isAlwaysFail) |
|
1284 { |
|
1285 //default is set to EAlwaysFail |
|
1286 TSecurityPolicy policy; |
|
1287 if (isAlwaysPass) |
|
1288 policy=TSecurityPolicy(TSecurityPolicy::EAlwaysPass); |
|
1289 aPolicy.Set(policy.Package()); |
|
1290 } |
|
1291 else |
|
1292 { |
|
1293 TInt r=ReadCapabilityL(capabilities[index]); |
|
1294 if(r!=KErrNone) |
|
1295 return r; |
|
1296 |
|
1297 // do we have more? |
|
1298 iLex.SkipSpace(); |
|
1299 index++; |
|
1300 while((iLex.Peek() == ',')) |
|
1301 { |
|
1302 //if capabilities supplied is more than allowed return KErrCorrupt |
|
1303 if (index>=maxCapWithoutSid) |
|
1304 { |
|
1305 __CENTREP_TRACE1("[%S] Too many read capabilities [platsec]",iFullName); |
|
1306 return KErrCorrupt; |
|
1307 } |
|
1308 // skip comma |
|
1309 iLex.SkipAndMark(1); |
|
1310 r=ReadCapabilityL(capabilities[index]); |
|
1311 if(r!=KErrNone) |
|
1312 return r; |
|
1313 // do we have yet more? |
|
1314 iLex.SkipSpace(); |
|
1315 index++; |
|
1316 } |
|
1317 TSecurityPolicy policy(static_cast<TCapability>(capabilities[0]), |
|
1318 static_cast<TCapability>(capabilities[1]), |
|
1319 static_cast<TCapability>(capabilities[2]), |
|
1320 static_cast<TCapability>(capabilities[3]), |
|
1321 static_cast<TCapability>(capabilities[4]), |
|
1322 static_cast<TCapability>(capabilities[5]), |
|
1323 static_cast<TCapability>(capabilities[6])); |
|
1324 aPolicy.Set(policy.Package()); |
|
1325 } |
|
1326 return KErrNone; |
|
1327 } |
|
1328 |
|
1329 TInt CIniFileIn::ReadSidAndCapabilitiesL(TSecurityPolicy& aPolicy,const TDesC& aPolicyType, |
|
1330 TSecureId& aSid) |
|
1331 { |
|
1332 //SID was specified we can have 0-3 capabilities |
|
1333 const TInt maxCapWithSid = 3; |
|
1334 |
|
1335 TCapability capabilities[maxCapWithSid]; |
|
1336 TInt index = 0; |
|
1337 for(index=0;index<maxCapWithSid;index++) |
|
1338 capabilities[index] = ECapability_None; |
|
1339 |
|
1340 // lets see what we have here... |
|
1341 iLex.SkipSpaceAndMark(); |
|
1342 |
|
1343 // we are looking for a string terminated by '=' |
|
1344 // up to a certain length.... |
|
1345 while((iLex.Peek()!='=')&&(!iLex.Eos())) |
|
1346 { |
|
1347 iLex.Inc(); |
|
1348 |
|
1349 if(iLex.TokenLength() >= KMaxAccessTypeLen) |
|
1350 { |
|
1351 // so no '=' there |
|
1352 // not necessarily bad thing... could be space there first |
|
1353 break; |
|
1354 } |
|
1355 |
|
1356 } |
|
1357 |
|
1358 TBuf<KMaxAccessTypeLen> string; |
|
1359 string.CopyLC(iLex.MarkedToken()); |
|
1360 |
|
1361 index = 0; |
|
1362 // lets check if there are any capabilities specified and if of correct type |
|
1363 if(0 == string.Compare(aPolicyType)) |
|
1364 { |
|
1365 //Need to check for AlwaysPass or AlwaysFail |
|
1366 TBool isAlwaysPass=EFalse; |
|
1367 TBool isAlwaysFail=EFalse; |
|
1368 CheckForAlwaysPassOrFailL(isAlwaysPass,isAlwaysFail); |
|
1369 if(isAlwaysPass || isAlwaysFail) |
|
1370 { |
|
1371 //default is set to EAlwaysFail |
|
1372 TSecurityPolicy policy; |
|
1373 if (isAlwaysPass) |
|
1374 policy=TSecurityPolicy(TSecurityPolicy::EAlwaysPass); |
|
1375 aPolicy.Set(policy.Package()); |
|
1376 } |
|
1377 else |
|
1378 { |
|
1379 // so we have some capabilities to read |
|
1380 TInt r = ReadCapabilityL(capabilities[index]); |
|
1381 if(r!=KErrNone) |
|
1382 return r; |
|
1383 // do we have more? |
|
1384 iLex.SkipSpace(); |
|
1385 index++; |
|
1386 while((iLex.Peek() == ',')) |
|
1387 { |
|
1388 //cannot permit more than 3 capabilities when followed by a SID |
|
1389 if (index>=maxCapWithSid) |
|
1390 { |
|
1391 __CENTREP_TRACE1("[%S] Too many read capabilities [platsec]",iFullName); |
|
1392 return KErrCorrupt; |
|
1393 } |
|
1394 // skip comma |
|
1395 iLex.SkipAndMark(1); |
|
1396 TInt r= ReadCapabilityL(capabilities[index]); |
|
1397 if(r!=KErrNone) |
|
1398 return r; |
|
1399 // do we have yet more? |
|
1400 iLex.SkipSpace(); |
|
1401 index++; |
|
1402 } |
|
1403 TSecurityPolicy policy(aSid,static_cast<TCapability>(capabilities[0]), |
|
1404 static_cast<TCapability>(capabilities[1]), |
|
1405 static_cast<TCapability>(capabilities[2])); |
|
1406 aPolicy.Set(policy.Package()); |
|
1407 } |
|
1408 } |
|
1409 else |
|
1410 { |
|
1411 // so no capabilities just SID |
|
1412 // and the token wasn't for us either |
|
1413 iLex.UnGetToMark(); |
|
1414 TSecurityPolicy policy(aSid); |
|
1415 aPolicy.Set(policy.Package()); |
|
1416 } |
|
1417 return KErrNone; |
|
1418 } |
|
1419 |
|
1420 |
|
1421 TInt CIniFileIn::ReadPolicyL(TSecurityPolicy& aPolicy,TInt aPolicyType) |
|
1422 { |
|
1423 |
|
1424 // lets check if there a SID is specified |
|
1425 iLex.SkipSpaceAndMark(); |
|
1426 |
|
1427 if(iLex.Eos()) |
|
1428 return KErrNotFound; |
|
1429 |
|
1430 while((iLex.Peek()!='=')&&(!iLex.Eos())) |
|
1431 { |
|
1432 iLex.Inc(); |
|
1433 |
|
1434 if(iLex.TokenLength() >= KMaxAccessTypeLen) |
|
1435 { |
|
1436 // so no '=' there |
|
1437 // not necessarily bad thing... could be space there first |
|
1438 break; |
|
1439 } |
|
1440 |
|
1441 } |
|
1442 |
|
1443 // we are looking for either KReadAccessSid, KReadAccessCap, KWriteAccessSid,KWriteAccessCap |
|
1444 TBuf<KMaxAccessTypeLen> accessString; |
|
1445 accessString.CopyLC(iLex.MarkedToken()); |
|
1446 iLex.SkipSpace(); |
|
1447 TInt returnCode = KErrNotFound; |
|
1448 // we expect a combination of sid_rd1 cap_rd1 sid_wr1 cap_wr1 |
|
1449 if(accessString.Compare(KReadAccessSidString)==0) |
|
1450 { |
|
1451 // we've got read - either SID or SID+CAP! Are we expecting read? |
|
1452 if(KReadPolicy == aPolicyType) |
|
1453 { |
|
1454 TUint32 sid; |
|
1455 SkipEqualSign(); |
|
1456 if (ReadNumber(sid) != KErrNone) |
|
1457 { |
|
1458 __CENTREP_TRACE1("[%S] Invalid SID (read)[platsec]",iFullName); |
|
1459 return KErrCorrupt; |
|
1460 } |
|
1461 TSecureId sidId(sid); |
|
1462 // so we read sid and now we expect cap_rd1=cap1,cap2,.. |
|
1463 // lets assume it's a SID+CAP for now |
|
1464 returnCode= ReadSidAndCapabilitiesL(aPolicy,KReadAccessCapString,sidId); |
|
1465 } |
|
1466 } |
|
1467 else if(accessString.Compare(KReadAccessCapString)==0) |
|
1468 { |
|
1469 // we've got read CAP only! Are we expecting read? |
|
1470 if(KReadPolicy == aPolicyType) |
|
1471 { |
|
1472 returnCode=ReadCapabilitiesL(aPolicy); |
|
1473 } |
|
1474 } |
|
1475 else if(accessString.Compare(KWriteAccessSidString)==0) |
|
1476 { |
|
1477 // we've got write - either SID or SID+CAP! Are we expecting read? |
|
1478 if(KWritePolicy == aPolicyType) |
|
1479 { |
|
1480 TUint32 sid; |
|
1481 SkipEqualSign(); |
|
1482 if(ReadNumber(sid)!=KErrNone) |
|
1483 { |
|
1484 __CENTREP_TRACE1("[%S] Invalid SID (write)[platsec]",iFullName); |
|
1485 return KErrCorrupt; |
|
1486 } |
|
1487 TSecureId sidId(sid); |
|
1488 // lets assume SID+CAP for now |
|
1489 returnCode= ReadSidAndCapabilitiesL(aPolicy,KWriteAccessCapString,sidId); |
|
1490 } |
|
1491 } |
|
1492 else if(accessString.Compare(KWriteAccessCapString)==0) |
|
1493 { |
|
1494 // we've got write CAP only! Are we expecting write? |
|
1495 if(KWritePolicy == aPolicyType) |
|
1496 { |
|
1497 returnCode=ReadCapabilitiesL(aPolicy); |
|
1498 } |
|
1499 } |
|
1500 if(KErrNone != returnCode) |
|
1501 iLex.UnGetToMark(); |
|
1502 |
|
1503 return returnCode; |
|
1504 } |
|
1505 |
|
1506 TInt CIniFileIn::ReadRdPolicyL(TSecurityPolicy& aReadPolicy) |
|
1507 { |
|
1508 return ReadPolicyL(aReadPolicy,KReadPolicy); |
|
1509 } |
|
1510 |
|
1511 TInt CIniFileIn::ReadWrPolicyL(TSecurityPolicy& aReadPolicy) |
|
1512 { |
|
1513 return ReadPolicyL(aReadPolicy,KWritePolicy); |
|
1514 } |
|
1515 |
|
1516 TInt CIniFileIn::ReadStringL(HBufC8*& aString) |
|
1517 { |
|
1518 iLex.Mark(); |
|
1519 |
|
1520 TChar c = iLex.Peek(); |
|
1521 TChar quote = 0; |
|
1522 if(c=='\'' || c=='\"') |
|
1523 { |
|
1524 iLex.SkipAndMark(1); |
|
1525 quote = c; |
|
1526 } |
|
1527 |
|
1528 TBool complete = EFalse; |
|
1529 |
|
1530 TInt len; |
|
1531 for(len=0;!iLex.Eos();len++) |
|
1532 { |
|
1533 c = iLex.Get(); |
|
1534 |
|
1535 if(quote ? c==quote : c.IsSpace()) |
|
1536 { |
|
1537 complete = ETrue; |
|
1538 break; |
|
1539 } |
|
1540 |
|
1541 if(c=='\\') |
|
1542 iLex.Get(); |
|
1543 } |
|
1544 |
|
1545 if(!complete || len>KMaxUnicodeStringLength) |
|
1546 return KErrCorrupt; |
|
1547 |
|
1548 aString = HBufC8::NewL(len*2); |
|
1549 TPtr8 ptr8 = aString->Des(); |
|
1550 ptr8.SetLength(len*2); |
|
1551 TPtr16 ptr16((TUint16*)ptr8.Ptr(), len, len); |
|
1552 |
|
1553 |
|
1554 iLex.UnGetToMark(); |
|
1555 |
|
1556 _LIT(KSpecialChars, "abfnrvt0"); |
|
1557 static TUint8 specialChars[] = { '\a', '\b', '\f', '\n', '\r', '\v', '\t', '\0' }; |
|
1558 for(TInt i=0;i<len;i++) |
|
1559 { |
|
1560 c = iLex.Get(); |
|
1561 |
|
1562 if(c=='\\') |
|
1563 { |
|
1564 c = iLex.Get(); |
|
1565 TInt i = KSpecialChars().Locate(c); |
|
1566 if(i>=0) |
|
1567 c = specialChars[i]; |
|
1568 } |
|
1569 |
|
1570 ptr16[i] = (TUint16)c; |
|
1571 |
|
1572 } |
|
1573 |
|
1574 if(quote) |
|
1575 iLex.Inc(); // trailing quote |
|
1576 |
|
1577 return KErrNone; |
|
1578 } |
|
1579 |
|
1580 |
|
1581 |
|
1582 TInt CIniFileIn::ReadString16To8L(HBufC8*& aString) |
|
1583 { |
|
1584 iLex.Mark(); |
|
1585 |
|
1586 TChar c = iLex.Peek(); |
|
1587 TChar quote = 0; |
|
1588 if(c=='\'' || c=='\"') |
|
1589 { |
|
1590 iLex.SkipAndMark(1); |
|
1591 quote = c; |
|
1592 } |
|
1593 |
|
1594 TBool complete = EFalse; |
|
1595 |
|
1596 TInt len; |
|
1597 for(len=0;!iLex.Eos();len++) |
|
1598 { |
|
1599 c = iLex.Get(); |
|
1600 |
|
1601 if(quote ? c==quote : c.IsSpace()) |
|
1602 { |
|
1603 complete = ETrue; |
|
1604 break; |
|
1605 } |
|
1606 |
|
1607 if(c=='\\') |
|
1608 iLex.Get(); |
|
1609 } |
|
1610 |
|
1611 if(!complete || len>KMaxUnicodeStringLength) |
|
1612 return KErrCorrupt; |
|
1613 |
|
1614 aString = HBufC8::NewLC(len*2); |
|
1615 |
|
1616 HBufC16* tempBuffer = HBufC16::NewLC(len); |
|
1617 |
|
1618 TPtr16 ptr16 = tempBuffer->Des(); |
|
1619 TPtr8 ptr8 = aString->Des(); |
|
1620 ptr8.SetLength(len*2); |
|
1621 |
|
1622 |
|
1623 |
|
1624 iLex.UnGetToMark(); |
|
1625 |
|
1626 _LIT(KSpecialChars, "abfnrvt0"); |
|
1627 static TUint8 specialChars[] = { '\a', '\b', '\f', '\n', '\r', '\v', '\t', '\0' }; |
|
1628 for(TInt i=0;i<len;i++) |
|
1629 { |
|
1630 c = iLex.Get(); |
|
1631 |
|
1632 if(c=='\\') |
|
1633 { |
|
1634 c = iLex.Get(); |
|
1635 TInt i = KSpecialChars().Locate(c); |
|
1636 if(i>=0) |
|
1637 c = specialChars[i]; |
|
1638 } |
|
1639 |
|
1640 ptr16.Append(c); |
|
1641 |
|
1642 } |
|
1643 |
|
1644 const TInt returnValue = CnvUtfConverter::ConvertFromUnicodeToUtf8(ptr8, ptr16); |
|
1645 if (returnValue==CnvUtfConverter::EErrorIllFormedInput) |
|
1646 { |
|
1647 CleanupStack::PopAndDestroy(tempBuffer); |
|
1648 CleanupStack::PopAndDestroy(aString); |
|
1649 return KErrCorrupt; |
|
1650 } |
|
1651 else if(returnValue<0) |
|
1652 User::Leave(KErrGeneral); |
|
1653 |
|
1654 CleanupStack::PopAndDestroy(tempBuffer); |
|
1655 CleanupStack::Pop(aString); |
|
1656 |
|
1657 if(quote) |
|
1658 iLex.Inc(); // trailing quote |
|
1659 |
|
1660 return KErrNone; |
|
1661 } |
|
1662 |
|
1663 TInt CIniFileIn::ReadBinaryL(HBufC8*& aString) |
|
1664 { |
|
1665 iLex.Mark(); |
|
1666 iLex.SkipCharacters(); |
|
1667 TInt len = iLex.TokenLength(); |
|
1668 iLex.UnGetToMark(); |
|
1669 |
|
1670 if(len==1 && iLex.Peek()==KNullDataIndicator) |
|
1671 { |
|
1672 iLex.Get(); |
|
1673 aString = HBufC8::NewL(0); |
|
1674 TPtr8 ptr8 = aString->Des(); |
|
1675 ptr8.SetLength(0); |
|
1676 return KErrNone; |
|
1677 } |
|
1678 |
|
1679 if(len>KMaxBinaryLength*2 || len%2) |
|
1680 { |
|
1681 delete aString; |
|
1682 return KErrCorrupt; |
|
1683 } |
|
1684 |
|
1685 len /= 2; |
|
1686 aString = HBufC8::NewL(len); |
|
1687 TPtr8 ptr8 = aString->Des(); |
|
1688 ptr8.SetLength(len); |
|
1689 |
|
1690 TBuf<2> buf(2); |
|
1691 for(TInt i=0;i<len;i++) |
|
1692 { |
|
1693 buf[0] = (TUint8)iLex.Get(); |
|
1694 buf[1] = (TUint8)iLex.Get(); |
|
1695 TLex lex(buf); |
|
1696 if(lex.Val(ptr8[i], EHex)!=KErrNone) |
|
1697 { |
|
1698 delete aString; |
|
1699 return KErrCorrupt; |
|
1700 } |
|
1701 } |
|
1702 return KErrNone; |
|
1703 } |
|
1704 |
|
1705 TInt CIniFileIn::ReadNumber(TUint32& aVal) |
|
1706 { |
|
1707 iLex.SkipSpace(); |
|
1708 |
|
1709 if(iLex.Eos()) |
|
1710 return KErrNotFound; |
|
1711 |
|
1712 TRadix radix = EDecimal; |
|
1713 if(iLex.Peek()=='0') |
|
1714 { |
|
1715 iLex.Inc(); |
|
1716 if(iLex.Peek().GetLowerCase()=='x') |
|
1717 { |
|
1718 iLex.Inc(); |
|
1719 radix = EHex; |
|
1720 } |
|
1721 else |
|
1722 iLex.UnGet(); |
|
1723 } |
|
1724 |
|
1725 return iLex.Val(aVal, radix); |
|
1726 } |
|
1727 |
|
1728 |
|
1729 TInt CIniFileIn::GetOwnerSectionLC(HBufC*& aSection) |
|
1730 { |
|
1731 return( GetSectionLC(KOwnerSection(), aSection)); |
|
1732 } |
|
1733 |
|
1734 TInt CIniFileIn::GetDefaultMetaSectionLC(HBufC*& aSection) |
|
1735 { |
|
1736 return( GetSectionLC(KDefaultMetaSection(), aSection)); |
|
1737 } |
|
1738 |
|
1739 TInt CIniFileIn::GetTimeStampSectionLC(HBufC*& aSection) |
|
1740 { |
|
1741 return( GetSectionLC(KTimeStampSection(), aSection)); |
|
1742 } |
|
1743 |
|
1744 TInt CIniFileIn::GetPlatSecSectionLC(HBufC*& aSection) |
|
1745 { |
|
1746 return( GetSectionLC(KPlatSecSection(), aSection)); |
|
1747 } |
|
1748 |
|
1749 TInt CIniFileIn::GetSectionLC(const TDesC16& aSectionId, HBufC*& aSection) |
|
1750 { |
|
1751 TBuf<KBufLen> buf; |
|
1752 TLexMark sectionMark; |
|
1753 aSection=NULL; |
|
1754 |
|
1755 SkipComments(); |
|
1756 |
|
1757 iLex.Mark(sectionMark); |
|
1758 |
|
1759 iLex.Mark(); |
|
1760 iLex.SkipCharacters(); |
|
1761 |
|
1762 if( (iLex.TokenLength() != aSectionId.Length()) && |
|
1763 (buf.CopyLC(iLex.MarkedToken()), buf.Compare( aSectionId )!=0) ) |
|
1764 { |
|
1765 // Expected section not found at this point in the file |
|
1766 // Note that this is not an error |
|
1767 iLex.UnGetToMark(); |
|
1768 return KErrNone; |
|
1769 } |
|
1770 |
|
1771 // |
|
1772 // Read in the section by grabbing text until we reach |
|
1773 // the start of another section. |
|
1774 // |
|
1775 while(!iLex.Eos()) |
|
1776 { |
|
1777 // Wait for any other section marker |
|
1778 SkipComments(); |
|
1779 |
|
1780 iLex.Mark(); |
|
1781 |
|
1782 iLex.SkipCharacters(); |
|
1783 |
|
1784 if(iLex.TokenLength() <= KBufLen) |
|
1785 { |
|
1786 buf.CopyLC(iLex.MarkedToken()); |
|
1787 if((buf.Compare(KMainSection) == 0) || |
|
1788 (buf.Compare(KOwnerSection) == 0) || |
|
1789 (buf.Compare(KPlatSecSection) == 0) || |
|
1790 (buf.Compare(KTimeStampSection) == 0) || |
|
1791 (buf.Compare(KDefaultMetaSection) == 0)) |
|
1792 { |
|
1793 iLex.Mark(iMainSectionMark); |
|
1794 iLex.UnGetToMark() ; |
|
1795 TPtrC lex = iLex.MarkedToken(sectionMark); |
|
1796 HBufC* section = HBufC::NewMaxLC(lex.Length()); //'\n' |
|
1797 TPtr ptr = section->Des(); |
|
1798 ptr.Copy(lex); |
|
1799 aSection=section; |
|
1800 return KErrNone; |
|
1801 } |
|
1802 } |
|
1803 } |
|
1804 return KErrCorrupt; |
|
1805 } |
|
1806 |
|
1807 TInt CIniFileIn::FindMainSectionL(void) |
|
1808 { |
|
1809 TBuf<KBufLen> buf; |
|
1810 |
|
1811 // |
|
1812 // Check if a Main section is present |
|
1813 // |
|
1814 |
|
1815 SkipComments(); |
|
1816 |
|
1817 // we will need this section later to write the out file... |
|
1818 iLex.Mark(iMainSectionMark); |
|
1819 |
|
1820 iLex.Mark(); |
|
1821 iLex.SkipCharacters(); |
|
1822 |
|
1823 if( iLex.TokenLength()!=KMainSectionLen || |
|
1824 (buf.CopyLC( iLex.MarkedToken() ), buf.Compare( KMainSection )!=0) ) |
|
1825 { |
|
1826 // Meta not available |
|
1827 iLex.UnGetToMark(); |
|
1828 return KErrNotFound; |
|
1829 } |
|
1830 |
|
1831 iLex.Mark(iMainSectionMark); |
|
1832 return KErrNone ; |
|
1833 } |
|
1834 |
|
1835 #ifdef CENTREP_TRACE |
|
1836 HBufC* CIniFileIn::FullName() |
|
1837 { |
|
1838 return(iFullName); |
|
1839 } |
|
1840 #endif |
|
1841 |
|
1842 #ifdef CENTREP_CONV_TOOL |
|
1843 //=================================================================== |
|
1844 // TCompiledSecurityPolicy class |
|
1845 // Used for accessing private data members of TSecurityPolicy. It |
|
1846 // uses the fact that TSecurityPolicy class has a friend whose name |
|
1847 // is TCompiledSecurityPolicy. |
|
1848 // See dbms/tdbms/securitypolicy.h for similar strategy. |
|
1849 // |
|
1850 |
|
1851 // The longest possible security string is one that has 7 capabilities. |
|
1852 static const TInt KSecPolicyStrSize = KMaxCapabilityStringLen * 7 + 10; |
|
1853 |
|
1854 class TCompiledSecurityPolicy |
|
1855 { |
|
1856 public: |
|
1857 TCompiledSecurityPolicy(const TSecurityPolicy& aSecurityPolicy) : |
|
1858 iSecurityPolicy(aSecurityPolicy) { } |
|
1859 const TDesC& TextualizePolicyL(TCapAccessMode aMode); |
|
1860 |
|
1861 private: |
|
1862 enum THeaderType |
|
1863 { |
|
1864 EHdrSecureId, |
|
1865 EHdrCapability |
|
1866 }; |
|
1867 |
|
1868 TCapability CapabilityAt(TInt aIndex) const; |
|
1869 void DoCapabilitySection(TInt aMaxNumCaps); |
|
1870 void AppendModeHeader(TCapAccessMode aAccessMode, THeaderType aType); |
|
1871 |
|
1872 private: |
|
1873 const TSecurityPolicy& iSecurityPolicy; |
|
1874 TBuf<KSecPolicyStrSize> iBuf; |
|
1875 }; |
|
1876 |
|
1877 ///////////////////////////////////////////////////////////////////////////////////////////////// |
|
1878 // CIniFileOut class |
|
1879 /** |
|
1880 Standard, phase-one CIniFileOut instance creation method. |
|
1881 The created CIniFileOut instance will use a temporary text file to store the repository settings. |
|
1882 CIniFileOut::CommitL() should be called at the end to finalize the changes. |
|
1883 @return A pointer to a fully constructed CIniFileOut instance. |
|
1884 @leave System-wide error codes, including KErrNoMemory. |
|
1885 */ |
|
1886 CIniFileOut* CIniFileOut::NewLC(RFs& aFs,const TDesC& aOutFileName) |
|
1887 { |
|
1888 CIniFileOut* inifile = new(ELeave) CIniFileOut(aFs); |
|
1889 CleanupStack::PushL(inifile); |
|
1890 inifile->ConstructL(aOutFileName); |
|
1891 return inifile; |
|
1892 } |
|
1893 |
|
1894 CIniFileOut::CIniFileOut(RFs& aFs) |
|
1895 : iCommited(EFalse), iTransFileBuf(4 * 1024),iFs(aFs)// 4K buffer size |
|
1896 { |
|
1897 } |
|
1898 |
|
1899 /** |
|
1900 Standard, phase-two CIniFileOut instance creation method. |
|
1901 Creates the transaction file. |
|
1902 Initializes transaction file buffer - iTransFileBuf instance. |
|
1903 @leave System-wide error codes, including KErrNoMemory. |
|
1904 */ |
|
1905 void CIniFileOut::ConstructL(const TDesC& aOutFileName) |
|
1906 { |
|
1907 iOutFileName=aOutFileName.AllocL(); |
|
1908 _LIT(KTmpExtension,"tmp"); |
|
1909 User::LeaveIfError(iTransFilePath.Set(aOutFileName, NULL, &(KTmpExtension()))); |
|
1910 User::LeaveIfError(iTransFile.Replace(iFs, iTransFilePath.FullName(), EFileWrite | EFileStreamText)); |
|
1911 iTransFileBuf.Attach(iTransFile, 0); |
|
1912 } |
|
1913 |
|
1914 /** |
|
1915 Closes and deletes the transaction file. |
|
1916 If CIniFileOut::CommitL() has not been called prior the destructor call, all the changes |
|
1917 will be lost. |
|
1918 */ |
|
1919 CIniFileOut::~CIniFileOut() |
|
1920 { |
|
1921 if (!iCommited) |
|
1922 { |
|
1923 iTransFileBuf.Close(); |
|
1924 // If a debug build - record error |
|
1925 TInt fileDeleteErr=iFs.Delete(iTransFilePath.FullName()); |
|
1926 #ifdef _DEBUG |
|
1927 if (fileDeleteErr != KErrNone) |
|
1928 { |
|
1929 RDebug::Print(_L("CIniFileOut::~CIniFileOut - Failed to delete file. Error = %d"), fileDeleteErr); |
|
1930 } |
|
1931 #else |
|
1932 (void)fileDeleteErr; |
|
1933 #endif |
|
1934 |
|
1935 } |
|
1936 delete iOutFileName; |
|
1937 } |
|
1938 |
|
1939 /** |
|
1940 The method writes supplied setting value to the output file. |
|
1941 @param aSetting Setting instance, which value has to be written to the output file. |
|
1942 @param accessPolicies A string descriptor, referencing related to aSetting access policies. |
|
1943 @leave System-wide error codes, including KErrNoMemory. |
|
1944 */ |
|
1945 void CIniFileOut::WriteSettingL(const TServerSetting& aSetting |
|
1946 #ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS |
|
1947 ,TUint32 aCreVersion |
|
1948 #endif |
|
1949 ) |
|
1950 { |
|
1951 iBuf.Zero(); |
|
1952 DoSettingL(aSetting |
|
1953 #ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS |
|
1954 ,aCreVersion |
|
1955 #endif |
|
1956 ); |
|
1957 WriteLineL(iBuf); |
|
1958 } |
|
1959 |
|
1960 void CIniFileOut::WriteSettingL(const TServerSetting& aSetting, |
|
1961 const TSettingsAccessPolicy& aAccessPolicy |
|
1962 #ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS |
|
1963 ,TUint32 aCreVersion |
|
1964 #endif |
|
1965 ) |
|
1966 { |
|
1967 iBuf.Zero(); |
|
1968 DoSettingL(aSetting |
|
1969 #ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS |
|
1970 ,aCreVersion |
|
1971 #endif |
|
1972 ); |
|
1973 iBuf.Append(KSpace); |
|
1974 #ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS |
|
1975 if (aCreVersion<2 || (aCreVersion>=2 && aAccessPolicy.iHighKey!=0)) |
|
1976 #endif |
|
1977 AppendSecurityPolicyL(aAccessPolicy.iReadAccessPolicy, ECapReadAccess); |
|
1978 iBuf.Append(KSpace); |
|
1979 #ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS |
|
1980 if (aCreVersion<2 || (aCreVersion>=2 && aAccessPolicy.iKeyMask!=0)) |
|
1981 #endif |
|
1982 AppendSecurityPolicyL(aAccessPolicy.iWriteAccessPolicy, ECapWriteAccess); |
|
1983 WriteLineL(iBuf); |
|
1984 } |
|
1985 |
|
1986 void CIniFileOut::DoSettingL(const TServerSetting& aSetting |
|
1987 #ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS |
|
1988 ,TUint32 aCreVersion |
|
1989 #endif |
|
1990 ) |
|
1991 { |
|
1992 iBuf.AppendNum(aSetting.Key(), EDecimal); |
|
1993 iBuf.Append(KSpace); |
|
1994 |
|
1995 ::AddSettingValueL(iBuf, aSetting); |
|
1996 |
|
1997 iBuf.Append(KSpace); |
|
1998 |
|
1999 if (!aSetting.Meta()) |
|
2000 { |
|
2001 iBuf.AppendNum(0, EDecimal); |
|
2002 } |
|
2003 else |
|
2004 { |
|
2005 #ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS |
|
2006 //need to check on the CRE Version too |
|
2007 TBool isClean=const_cast<TServerSetting&>(aSetting).IsClean(); |
|
2008 if (aCreVersion<2 || (aCreVersion>=2 && (aSetting.IsIndividualMeta() || (!aSetting.IsIndividualMeta() && isClean )))) |
|
2009 { |
|
2010 TUint32 metaToWrite=aSetting.Meta(); |
|
2011 //special case |
|
2012 if (aCreVersion>=2 && isClean && aSetting.IsIndividualMeta()) |
|
2013 { |
|
2014 metaToWrite|=KMetaIndividual; |
|
2015 } |
|
2016 iBuf.AppendFormat(KHexIntFormat, metaToWrite); |
|
2017 } |
|
2018 #else |
|
2019 iBuf.AppendFormat(KHexIntFormat, aSetting.Meta()); |
|
2020 #endif |
|
2021 } |
|
2022 } |
|
2023 |
|
2024 /** |
|
2025 The method commits settings file changes. |
|
2026 If the commit operation fails, the existing settings file will stay unchanged. |
|
2027 @leave System-wide error codes. |
|
2028 */ |
|
2029 void CIniFileOut::CommitL() |
|
2030 { |
|
2031 iTransFileBuf.SynchL(); |
|
2032 iTransFileBuf.Close(); |
|
2033 |
|
2034 User::LeaveIfError(iFs.Replace(iTransFilePath.FullName(),*iOutFileName)); |
|
2035 |
|
2036 iCommited = ETrue; |
|
2037 } |
|
2038 |
|
2039 void CIniFileOut::WriteMainSectionHeaderL() |
|
2040 { |
|
2041 WriteLineL(KMainSection()); |
|
2042 } |
|
2043 |
|
2044 /** |
|
2045 Writes a text line to the repository file. |
|
2046 @param aData The string which will be written to the file as a single text line |
|
2047 @leave System-wide error codes |
|
2048 */ |
|
2049 void CIniFileOut::WriteLineL(const TDesC& aData) |
|
2050 { |
|
2051 iTransFileBuf.WriteL(reinterpret_cast <const TUint8*> (aData.Ptr()), aData.Size()); |
|
2052 iTransFileBuf.WriteL(reinterpret_cast <const TUint8*> (KCrNl().Ptr()), KCrNl().Size()); |
|
2053 } |
|
2054 |
|
2055 /** |
|
2056 Writes repository file header. |
|
2057 @leave System-wide error codes |
|
2058 */ |
|
2059 void CIniFileOut::WriteHeaderL() |
|
2060 { |
|
2061 TBuf<64> buf; |
|
2062 |
|
2063 buf.Append(KUcs2Bom); |
|
2064 buf.Append(KSignature); |
|
2065 WriteLineL(buf); |
|
2066 |
|
2067 buf.Zero(); |
|
2068 buf.Append(KVersion); |
|
2069 buf.Append(KSpace); |
|
2070 buf.AppendNum(KCurrentVersion); |
|
2071 buf.Append(KCrNl); |
|
2072 WriteLineL(buf); |
|
2073 } |
|
2074 |
|
2075 /** |
|
2076 Writes owner section to repository file. |
|
2077 */ |
|
2078 void CIniFileOut::WriteOwnerSectionL(TUid aOwner) |
|
2079 { |
|
2080 if (aOwner.iUid != 0) |
|
2081 { |
|
2082 WriteLineL(KOwnerSection()); |
|
2083 TBuf<32> buf; |
|
2084 buf.Format(KUidFormat, aOwner.iUid); |
|
2085 buf.Append(KCrNl); |
|
2086 WriteLineL(buf); |
|
2087 } |
|
2088 } |
|
2089 |
|
2090 /** |
|
2091 Writes time stamp to repository file. |
|
2092 @param aTime Time stamp |
|
2093 @leave System-wide error codes |
|
2094 */ |
|
2095 void CIniFileOut::WriteTimeStampL(const TTime& aTime) |
|
2096 { |
|
2097 if(aTime.Int64() != 0) |
|
2098 { |
|
2099 WriteLineL(KTimeStampSection()); |
|
2100 TBuf<32> buf; |
|
2101 buf.Num(aTime.Int64()); |
|
2102 buf.Append(KCrNl); |
|
2103 WriteLineL(buf); |
|
2104 } |
|
2105 } |
|
2106 |
|
2107 /** |
|
2108 Writes meta data to repository file. |
|
2109 @param aFileIn Input repository file |
|
2110 @leave System-wide error codes |
|
2111 */ |
|
2112 void CIniFileOut::WriteMetaDataL(TUint32 aDefaultMeta, |
|
2113 const RDefaultMetaArray& aDefaultMetaRanges) |
|
2114 { |
|
2115 if (!aDefaultMeta && !aDefaultMetaRanges.Count()) |
|
2116 { |
|
2117 return; |
|
2118 } |
|
2119 |
|
2120 WriteLineL(KDefaultMetaSection); |
|
2121 |
|
2122 if (aDefaultMeta) |
|
2123 { |
|
2124 iBuf.Format(KHexIntFormat, aDefaultMeta); |
|
2125 WriteLineL(iBuf); |
|
2126 } |
|
2127 |
|
2128 for (TInt i = 0; i<aDefaultMetaRanges.Count(); i++) |
|
2129 { |
|
2130 const TSettingsDefaultMeta& entry = aDefaultMetaRanges[i]; |
|
2131 if (entry.HighKey()) |
|
2132 { |
|
2133 iBuf.Format(KRangeMetaFmt, entry.LowKey(), entry.HighKey(), |
|
2134 entry.GetDefaultMetadata()); |
|
2135 } |
|
2136 else |
|
2137 { |
|
2138 iBuf.Format(KMaskMetaFmt, entry.LowKey(), entry.KeyMask(), |
|
2139 entry.GetDefaultMetadata()); |
|
2140 } |
|
2141 WriteLineL(iBuf); |
|
2142 } |
|
2143 |
|
2144 WriteLineL(KCrNl()); |
|
2145 } |
|
2146 |
|
2147 /** |
|
2148 Writes platsec info to repository file. |
|
2149 @param aFileIn Input repository file |
|
2150 @leave System-wide error codes |
|
2151 */ |
|
2152 #ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS |
|
2153 void CIniFileOut::WritePlatSecL(const TSettingsAccessPolicy& aDefaultAccessPolicy, |
|
2154 const RRangePolicyArray& aRangePolicies,TUint32 aCreVersion) |
|
2155 #else |
|
2156 void CIniFileOut::WritePlatSecL(const TSecurityPolicy& aDefaultReadPolicy, |
|
2157 const TSecurityPolicy& aDefaultWritePolicy, |
|
2158 const RRangePolicyArray& aRangePolicies) |
|
2159 #endif |
|
2160 { |
|
2161 WriteLineL(KPlatSecSection); |
|
2162 |
|
2163 iBuf.Zero(); |
|
2164 #ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS |
|
2165 if (aCreVersion<2 || (aCreVersion>=2 && aDefaultAccessPolicy.iHighKey!=0)) |
|
2166 AppendSecurityPolicyL(*(aDefaultAccessPolicy.GetReadAccessPolicy()), ECapReadAccess); |
|
2167 iBuf.Append(KSpace); |
|
2168 if (aCreVersion<2 || (aCreVersion>=2 && aDefaultAccessPolicy.iKeyMask!=0)) |
|
2169 AppendSecurityPolicyL(*(aDefaultAccessPolicy.GetWriteAccessPolicy()), ECapWriteAccess); |
|
2170 #else |
|
2171 AppendSecurityPolicyL(aDefaultReadPolicy, ECapReadAccess); |
|
2172 iBuf.Append(KSpace); |
|
2173 AppendSecurityPolicyL(aDefaultWritePolicy, ECapWriteAccess); |
|
2174 #endif |
|
2175 WriteLineL(iBuf); |
|
2176 |
|
2177 for(TInt i=0; i < aRangePolicies.Count(); i++) |
|
2178 { |
|
2179 const TSettingsAccessPolicy& e = aRangePolicies[i]; |
|
2180 if (e.iHighKey != 0) |
|
2181 { |
|
2182 iBuf.Format(KRangePrefix, e.iLowKey, e.iHighKey); |
|
2183 } |
|
2184 else |
|
2185 { |
|
2186 iBuf.Format(KMaskPrefix, e.iLowKey, e.iKeyMask); |
|
2187 } |
|
2188 |
|
2189 iBuf.Append(KSpace); |
|
2190 |
|
2191 AppendSecurityPolicyL(e.iReadAccessPolicy, ECapReadAccess); |
|
2192 iBuf.Append(KSpace); |
|
2193 AppendSecurityPolicyL(e.iWriteAccessPolicy, ECapWriteAccess); |
|
2194 WriteLineL(iBuf); |
|
2195 } |
|
2196 |
|
2197 WriteLineL(KCrNl()); |
|
2198 } |
|
2199 |
|
2200 void CIniFileOut::AppendSecurityPolicyL(const TSecurityPolicy& aPolicy, |
|
2201 TCapAccessMode aRdWrMode) |
|
2202 { |
|
2203 TCompiledSecurityPolicy policy(aPolicy); |
|
2204 iBuf.Append(policy.TextualizePolicyL(aRdWrMode)); |
|
2205 } |
|
2206 |
|
2207 ///////////////////////////////////////////////////////////////////////////////////////////////// |
|
2208 const TDesC& TCompiledSecurityPolicy::TextualizePolicyL(TCapAccessMode aMode) |
|
2209 { |
|
2210 iBuf.Zero(); |
|
2211 AppendModeHeader(aMode, EHdrCapability); |
|
2212 |
|
2213 switch (static_cast<TSecurityPolicy::TType>(iSecurityPolicy.iType)) |
|
2214 { |
|
2215 case TSecurityPolicy::ETypeFail: |
|
2216 iBuf.Append(KAccessAlwaysFail); |
|
2217 break; |
|
2218 case TSecurityPolicy::ETypePass: |
|
2219 iBuf.Append(KAccessAlwaysPass); |
|
2220 break; |
|
2221 case TSecurityPolicy::ETypeC3: |
|
2222 DoCapabilitySection(3); |
|
2223 break; |
|
2224 case TSecurityPolicy::ETypeC7: |
|
2225 DoCapabilitySection(7); |
|
2226 break; |
|
2227 case TSecurityPolicy::ETypeS3: |
|
2228 iBuf.Zero(); // erase the "cap_rd", replace with sid_rd |
|
2229 AppendModeHeader(aMode, EHdrSecureId); |
|
2230 iBuf.AppendNum(iSecurityPolicy.iSecureId); |
|
2231 |
|
2232 if (ECapability_HardLimit != iSecurityPolicy.iCaps[0]) |
|
2233 { |
|
2234 iBuf.Append(KSpace); |
|
2235 AppendModeHeader(aMode, EHdrCapability); |
|
2236 DoCapabilitySection(3); |
|
2237 } |
|
2238 break; |
|
2239 |
|
2240 default: |
|
2241 User::Leave(KErrCorrupt); |
|
2242 } // switch |
|
2243 |
|
2244 return iBuf; |
|
2245 } |
|
2246 |
|
2247 TCapability TCompiledSecurityPolicy::CapabilityAt(TInt aIndex) const |
|
2248 { |
|
2249 if (aIndex < 3) |
|
2250 { |
|
2251 return static_cast <TCapability> (iSecurityPolicy.iCaps[aIndex]); |
|
2252 } |
|
2253 else if(aIndex < 7) |
|
2254 { |
|
2255 return static_cast <TCapability> (iSecurityPolicy.iExtraCaps[aIndex - 3]); |
|
2256 } |
|
2257 return ECapability_None; |
|
2258 } |
|
2259 |
|
2260 // |
|
2261 void TCompiledSecurityPolicy::DoCapabilitySection(TInt aMaxNumCaps) |
|
2262 { |
|
2263 for (TInt i = 0; i < aMaxNumCaps; i++) |
|
2264 { |
|
2265 TCapability cap = CapabilityAt(i); |
|
2266 |
|
2267 if (cap<0 || cap>= ECapability_Limit) |
|
2268 { |
|
2269 return; |
|
2270 } |
|
2271 if (i > 0) |
|
2272 { |
|
2273 iBuf.Append(','); |
|
2274 } |
|
2275 |
|
2276 for (const char* p=CapabilityNames[cap]; *p; p++) |
|
2277 { |
|
2278 iBuf.Append((TUint16)*p); |
|
2279 } |
|
2280 } // for i |
|
2281 } |
|
2282 |
|
2283 void TCompiledSecurityPolicy::AppendModeHeader(TCapAccessMode aAccessMode, |
|
2284 THeaderType aType) |
|
2285 { |
|
2286 if (aAccessMode == ECapReadAccess) |
|
2287 { |
|
2288 if (aType == EHdrSecureId) |
|
2289 { |
|
2290 iBuf.Append(KReadAccessSidString); // "sid_rd" |
|
2291 } |
|
2292 else |
|
2293 { |
|
2294 iBuf.Append(KReadAccessCapString); // "cap_rd" |
|
2295 } |
|
2296 } |
|
2297 else |
|
2298 { |
|
2299 if (aType == EHdrSecureId) |
|
2300 { |
|
2301 iBuf.Append(KWriteAccessSidString); // "sid_wr" |
|
2302 } |
|
2303 else |
|
2304 { |
|
2305 iBuf.Append(KWriteAccessCapString); // "cap_wr" |
|
2306 } |
|
2307 } |
|
2308 iBuf.Append('='); |
|
2309 } |
|
2310 #endif //CENTREP_CONV_TOOL |