|
1 /* |
|
2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 /** |
|
20 @file |
|
21 */ |
|
22 |
|
23 #ifdef _MSC_VER |
|
24 #pragma warning (disable: 4786) |
|
25 #endif // _MSC_VER |
|
26 |
|
27 |
|
28 #include "siscapabilities.h" |
|
29 #include "utility_interface.h" |
|
30 #include <stdlib.h> |
|
31 #include <stdio.h> |
|
32 #include <sys/stat.h> |
|
33 |
|
34 typedef int TInt; |
|
35 typedef bool TBool; |
|
36 |
|
37 enum TCapability |
|
38 { |
|
39 ECapability_HardLimit = 255 |
|
40 }; |
|
41 |
|
42 const TInt KCapabilitySetMaxSize = (((TInt)ECapability_HardLimit + 7)>>3); |
|
43 |
|
44 LPWSTR TempFileName(); |
|
45 |
|
46 #include <seclib.h> |
|
47 |
|
48 CSISCapabilities::CSISCapabilities(const CSISCapabilities& aInitialiser) |
|
49 : CStructure<CSISFieldRoot::ESISCapabilities> (aInitialiser), |
|
50 iCapabilities(aInitialiser.iCapabilities), |
|
51 iCapabilitySetSize(0) |
|
52 { |
|
53 |
|
54 InsertMembers(); |
|
55 |
|
56 } |
|
57 |
|
58 std::string CSISCapabilities::Name() const |
|
59 { |
|
60 |
|
61 return "Capabilties"; |
|
62 |
|
63 } |
|
64 |
|
65 void CSISCapabilities::ExtractCapabilities(const std::wstring& aFileName) |
|
66 { |
|
67 SBinarySecurityInfo info; |
|
68 |
|
69 // This call has some rather innapropriate side effects when called |
|
70 // on a file that isn't an executable. |
|
71 // Here we redirect stderr, so that we don't see them. |
|
72 |
|
73 int oldStderr = 0; |
|
74 FILE* nulStderr; |
|
75 |
|
76 _dup2(oldStderr, 2); |
|
77 |
|
78 CSISException::ThrowIf(oldStderr == -1, CSISException::EFileProblem, "Failed in redirection operation"); |
|
79 |
|
80 #ifdef __TOOLS2_LINUX__ |
|
81 nulStderr = fopen("NULL", "w"); |
|
82 #else |
|
83 nulStderr = fopen("NUL:", "w"); |
|
84 #endif |
|
85 |
|
86 CSISException::ThrowIf(nulStderr == NULL, CSISException::EFileProblem, "Failed in redirection operation"); |
|
87 |
|
88 CSISException::ThrowIf(_dup2(_fileno(nulStderr), 2) == -1, CSISException::EFileProblem, "Failed in redirection operation"); |
|
89 TInt err = 1; |
|
90 char buffer[PATHMAX] = {0}; |
|
91 ConvertWideCharToMultiByte(aFileName.c_str(),-1,buffer,sizeof(buffer)); |
|
92 err = GetSecurityInfo(buffer, info); |
|
93 fflush(stdout); |
|
94 _dup2(oldStderr, 2); |
|
95 |
|
96 fclose(nulStderr); |
|
97 |
|
98 if (!err) |
|
99 { |
|
100 |
|
101 iCapabilitySetSize = 0; |
|
102 |
|
103 for (TInt i = KCapabilitySetMaxSize - 1; i > 0; i--) |
|
104 { |
|
105 |
|
106 if (!iCapabilitySetSize && info.iCapabilities[i]) |
|
107 { |
|
108 iCapabilitySetSize = i + 1; |
|
109 } |
|
110 |
|
111 iCapabilities |= info.iCapabilities[i]; |
|
112 iCapabilities = iCapabilities << 8; |
|
113 |
|
114 } |
|
115 |
|
116 iCapabilities |= info.iCapabilities[0]; |
|
117 |
|
118 if (iCapabilities && !iCapabilitySetSize) |
|
119 { |
|
120 iCapabilitySetSize = 1; |
|
121 } |
|
122 |
|
123 } |
|
124 } |
|
125 |
|
126 bool CSISCapabilities::WasteOfSpace() const |
|
127 { |
|
128 |
|
129 return (0 == iCapabilities); |
|
130 |
|
131 } |
|
132 |
|
133 void CSISCapabilities::Verify(const TUint32 aLanguages) const |
|
134 { |
|
135 |
|
136 CStructure <CSISFieldRoot::ESISCapabilities>::Verify (aLanguages); |
|
137 |
|
138 CSISException::ThrowIf(iCapabilitySetSize > sizeof(iCapabilities), |
|
139 CSISException::EVerification, |
|
140 "Capability set size if greater than this version of makesis is capable of storing"); |
|
141 |
|
142 } |
|
143 |
|
144 void CSISCapabilities::AddPackageEntry(std::wostream& aStream, bool aVerbose) const |
|
145 { |
|
146 if(WasteOfSpace() || !aVerbose) |
|
147 { |
|
148 return; |
|
149 } |
|
150 |
|
151 // Following neads to be printed only if aVerbose is true |
|
152 aStream << L"; Capabilities: "; |
|
153 int capability = 0; |
|
154 |
|
155 TUint32 capabilityField = iCapabilities.Value(); |
|
156 for (int i = 0; i < KCapabilitySetMaxSize; ++i, ++capability) |
|
157 { |
|
158 if (capabilityField & 0x01) |
|
159 { |
|
160 if (capability < NUMOFCAPABILITIES) |
|
161 { |
|
162 aStream << KCapabilityNames[capability] << L", "; |
|
163 } |
|
164 else |
|
165 { |
|
166 aStream << L"Unknown Capability (" << (capability + 1) << L"), "; |
|
167 } |
|
168 } |
|
169 |
|
170 capabilityField >>= 1; |
|
171 } |
|
172 aStream << std::endl; |
|
173 } |
|
174 |
|
175 void CSISCapabilities::GetCapabilityList(std::vector<std::wstring>& aCapList) const |
|
176 { |
|
177 int capability = 0; |
|
178 |
|
179 TUint32 capabilityField = iCapabilities.Value(); |
|
180 for (int i = 0; (i < KCapabilitySetMaxSize) && (0 != capabilityField); ++i, ++capability) |
|
181 { |
|
182 if (capabilityField & 0x01) |
|
183 { |
|
184 if (capability < NUMOFCAPABILITIES) |
|
185 { |
|
186 aCapList.push_back(KCapabilityNames[capability]); |
|
187 } |
|
188 else |
|
189 { |
|
190 wchar_t capName[35]; |
|
191 #ifdef _MSC_VER |
|
192 swprintf(capName, L"Unknown Capability (%d)", (capability + 1)); |
|
193 #else |
|
194 swprintf(capName, 35, L"Unknown Capability (%d)", (capability + 1)); |
|
195 #endif //_MSC_VER |
|
196 aCapList.push_back(capName); |
|
197 } |
|
198 } |
|
199 capabilityField >>= 1; |
|
200 } |
|
201 } |
|
202 |
|
203 |