Merge "Add privacy check method" into tizen_2.1
[platform/framework/native/appfw.git] / src / security / FSec_AccessController.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file        FSec_AccessController.cpp
20  * @brief       This is the implementation for the _AccessController class.
21  */
22
23 #include <unique_ptr.h>
24 #include <FAppTypes.h>
25 #include <FAppApplication.h>
26 #include <FApp_AppInfo.h>
27 #include <FApp_AppManagerImpl.h>
28 #include <FAppPkg_PackageInfoImpl.h>
29 #include <FBaseSysLog.h>
30 #include <FBaseString.h>
31 #include <FBaseColArrayList.h>
32 #include <FBase_StringConverter.h>
33 #include <FIoFile.h>
34 #include <FIo_IpcClient.h>
35 #include <privacy_checker_client.h>
36 #include "FSec_AccessController.h"
37 #include "FSec_PrivilegeManager.h"
38 #include "FSec_PrivilegeManagerMessage.h"
39 #include "FSec_PrivilegeInfo.h"
40
41
42 using namespace Tizen::App;
43 using namespace Tizen::App::Package;
44 using namespace Tizen::Base;
45 using namespace Tizen::Base::Collection;
46 using namespace Tizen::Io;
47
48 static _IpcClient ipcClient;
49 static bool isConstructed = false;
50
51 namespace Tizen { namespace Security
52 {
53
54 _PrivilegeManager* _AccessController::__pPrivilegeManager = null;
55
56 static std::unique_ptr<String> pEncryptedPrivileges(null);
57 static std::unique_ptr<String> pChecksum(null);
58 static std::unique_ptr<String> pEncryptedVisibility(null);
59 static std::unique_ptr<String> pVisibilityChecksum(null);
60 static std::unique_ptr<ArrayList> pPrivilegeList(null);
61
62 _AccessController::_AccessController(void)
63 {
64
65 }
66
67 _AccessController::~_AccessController(void)
68 {
69         if (pPrivilegeList != null)
70         {
71                 pPrivilegeList->RemoveAll(true);
72         }
73 }
74
75 result
76 _AccessController::CheckSystemPrivilege(const PackageId& packageId, _Privilege privilege)
77 {
78         result r = E_SUCCESS;
79
80         bool ret = false;
81         std::unique_ptr<_PrivilegeInfo> pPrivilegeInfo(null);
82         String subAppId;
83         _PackageInfoImpl infoImpl;
84         String appType;
85         String webAppType(L"wgt");
86
87         SysTryReturnResult(NID_SEC, privilege < _MAX_PRIVILEGE_ENUM, E_INVALID_ARG, "The privilege enumerator is invalid");
88
89         packageId.SubString(0, MAX_APP_ID_SIZE, subAppId);
90
91         r = infoImpl.Construct(subAppId);
92         SysTryReturnResult(NID_SEC, r == E_SUCCESS, E_SYSTEM, "An unexpected system error occurred.");
93
94         appType = infoImpl.GetAppType();
95         if (appType.Equals(webAppType, true))
96         {
97                 return E_SUCCESS;
98         }
99
100         if (__pPrivilegeManager == null)
101         {
102                 __pPrivilegeManager = _PrivilegeManager::GetInstance();
103         }
104         SysTryReturnResult(NID_SEC, __pPrivilegeManager != null, E_SYSTEM, "An unexpected system error occurred.");
105
106         pPrivilegeInfo.reset(__pPrivilegeManager->RetrievePrivilegeInfoN(subAppId));
107         r = GetLastResult();
108
109         if (r == E_SUCCESS)
110         {
111                 // nothing to do.
112         }
113         else if (r == E_DATA_NOT_FOUND)
114         {
115                 SysLogException(NID_SEC, E_DATA_NOT_FOUND, "[E_DATA_NOT_FOUND] The privilege information does not exist.");
116                 goto CATCH;
117         }
118         else
119         {
120                 SysLogException(NID_SEC, E_SYSTEM, "[E_SYSTEM] An unexpected system error occurred.");
121                 return E_SYSTEM;
122         }
123
124         ret = pPrivilegeInfo->HasPrivilege(privilege);
125         if (!ret)
126         {
127                 r = E_PRIVILEGE_DENIED;
128                 goto CATCH;
129         }
130
131         r = CheckPrivacy(packageId, privilege);
132         SysTryReturnResult(NID_SEC, r == E_SUCCESS, E_USER_NOT_CONSENTED, "The user blocks an application from calling the method.");
133
134         return r;
135
136 CATCH:
137
138         SysLogException(NID_SEC,  r, "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
139
140         _AppManagerImpl* pAppManagerImpl = _AppManagerImpl::GetInstance();
141         pAppManagerImpl->TerminateApplications(packageId);
142
143         return r;
144 }
145
146 result
147 _AccessController::CheckSystemPrivilege(const PackageId& packageId, _Privilege privilege1, _Privilege privilege2)
148 {
149         result r = E_SUCCESS;
150
151         bool ret = false;
152         std::unique_ptr<_PrivilegeInfo> pPrivilegeInfo(null);
153         String subAppId;
154         _PackageInfoImpl infoImpl;
155         String appType;
156         String webAppType(L"wgt");
157
158         SysTryReturnResult(NID_SEC, privilege1 < _MAX_PRIVILEGE_ENUM, E_INVALID_ARG, "The privilege enumerator is invalid");
159         SysTryReturnResult(NID_SEC, privilege2 < _MAX_PRIVILEGE_ENUM, E_INVALID_ARG, "The privilege enumerator is invalid");
160
161         packageId.SubString(0, MAX_APP_ID_SIZE, subAppId);
162
163         r = infoImpl.Construct(subAppId);
164         SysTryReturnResult(NID_SEC, r == E_SUCCESS, E_SYSTEM, "An unexpected system error occurred.");
165
166         appType = infoImpl.GetAppType();
167         if (appType.Equals(webAppType, true))
168         {
169                 return E_SUCCESS;
170         }
171
172         if (__pPrivilegeManager == null)
173         {
174                 __pPrivilegeManager = _PrivilegeManager::GetInstance();
175         }
176         SysTryReturnResult(NID_SEC, __pPrivilegeManager != null, E_SYSTEM, "An unexpected system error occurred.");
177
178         pPrivilegeInfo.reset(__pPrivilegeManager->RetrievePrivilegeInfoN(subAppId));
179         r = GetLastResult();
180
181         if (r == E_SUCCESS)
182         {
183                 // nothing to do.
184         }
185         else if (r == E_DATA_NOT_FOUND)
186         {
187                 SysLogException(NID_SEC, E_DATA_NOT_FOUND, "[E_DATA_NOT_FOUND] The privilege information does not exist.");
188                 goto CATCH;
189         }
190         else
191         {
192                 SysLogException(NID_SEC, E_SYSTEM, "[E_SYSTEM] An unexpected system error occurred.");
193                 return E_SYSTEM;
194         }
195
196         ret = pPrivilegeInfo->HasPrivilegeEx(privilege1);
197         if (!ret)
198         {
199                 ret = pPrivilegeInfo->HasPrivilege(privilege2);
200                 if (!ret)
201                 {
202                         r = E_PRIVILEGE_DENIED;
203                         goto CATCH;
204                 }
205         }
206
207         r = CheckPrivacy(packageId, privilege2);
208         SysTryReturnResult(NID_SEC, r == E_SUCCESS, E_USER_NOT_CONSENTED, "The user blocks an application from calling the method.");
209
210         return r;
211
212 CATCH:
213
214         SysLogException(NID_SEC,  r, "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
215
216         _AppManagerImpl* pAppManagerImpl = _AppManagerImpl::GetInstance();
217         pAppManagerImpl->TerminateApplications(packageId);
218
219         return r;
220 }
221
222 result
223 _AccessController::CheckPrivilege(const PackageId& packageId, const String& privilege)
224 {
225         result r = E_SUCCESS;
226
227         bool ret = false;
228         std::unique_ptr<_PrivilegeInfo> pPrivilegeInfo(null);
229         String subAppId;
230         _PackageInfoImpl infoImpl;
231         String appType;
232         String webAppType(L"wgt");
233
234         packageId.SubString(0, MAX_APP_ID_SIZE, subAppId);
235
236         r = infoImpl.Construct(subAppId);
237         SysTryReturnResult(NID_SEC, r == E_SUCCESS, E_SYSTEM, "An unexpected system error occurred.");
238
239         appType = infoImpl.GetAppType();
240         if (appType.Equals(webAppType, true))
241         {
242                 return E_SUCCESS;
243         }
244
245         if (__pPrivilegeManager == null)
246         {
247                 __pPrivilegeManager = _PrivilegeManager::GetInstance();
248         }
249         SysTryReturnResult(NID_SEC, __pPrivilegeManager != null, E_SYSTEM, "An unexpected system error occurred.");
250
251         pPrivilegeInfo.reset(__pPrivilegeManager->RetrievePrivilegeInfoN(subAppId));
252         r = GetLastResult();
253
254         if (r == E_SUCCESS)
255         {
256                 // nothing to do.
257         }
258         else if (r == E_DATA_NOT_FOUND)
259         {
260                 SysLogException(NID_SEC, E_DATA_NOT_FOUND, "[E_DATA_NOT_FOUND] The privilege information does not exist.");
261                 goto CATCH;
262         }
263         else
264         {
265                 SysLogException(NID_SEC, E_SYSTEM, "[E_SYSTEM] An unexpected system error occurred.");
266                 return E_SYSTEM;
267         }
268
269         ret = pPrivilegeInfo->HasPrivilege(privilege);
270         if (!ret)
271         {
272                 r = E_PRIVILEGE_DENIED;
273                 goto CATCH;
274         }
275
276         r = CheckPrivacy(packageId, privilege);
277         SysTryReturnResult(NID_SEC, r == E_SUCCESS, E_USER_NOT_CONSENTED, "The user blocks an application from calling the method.");
278
279         return r;
280
281 CATCH:
282
283         SysLogException(NID_SEC,  r, "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
284
285         _AppManagerImpl* pAppManagerImpl = _AppManagerImpl::GetInstance();
286         pAppManagerImpl->TerminateApplications(packageId);
287
288         return r;
289 }
290
291 void
292 _AccessController::Initialize(void)
293 {
294         result r = E_SUCCESS;
295         result ipcResult = E_SUCCESS;
296
297         std::unique_ptr<IPC::Message> pCipherPrivilegeMessage(null);
298         std::unique_ptr<IPC::Message> pCipherVisibilityMessage(null);
299
300         r = ipcClient.Construct(L"osp.security.ipcserver.privilegemanager", null);
301         SysTryReturnVoidResult(NID_SEC, r == E_SUCCESS, E_SYSTEM, "Failed to construct the instance of IPC.");
302
303         pEncryptedPrivileges.reset(new (std::nothrow) String());
304         SysTryReturnVoidResult(NID_SEC, pEncryptedPrivileges != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
305
306         pChecksum.reset(new (std::nothrow) String());
307         SysTryReturnVoidResult(NID_SEC, pChecksum != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
308
309         pPrivilegeList.reset(new ArrayList());
310         SysTryReturnVoidResult(NID_SEC, pPrivilegeList != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
311
312         pPrivilegeList->Construct();
313
314         pCipherPrivilegeMessage.reset(new (std::nothrow) PrivilegeManagerMsg_retrieve(pEncryptedPrivileges.get(), pChecksum.get(), pPrivilegeList.get(), &r));
315         SysTryReturnVoidResult(NID_SEC, pCipherPrivilegeMessage != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
316
317         ipcResult = ipcClient.SendRequest(pCipherPrivilegeMessage.get());
318         SysTryReturnVoidResult(NID_SEC, ipcResult == E_SUCCESS, E_SYSTEM, "Failed to send IPC message.");
319         SysTryReturnVoidResult(NID_SEC, r == E_SUCCESS, r, "Failed to retrieve privilege information");
320
321         pEncryptedVisibility.reset(new (std::nothrow) String());
322         SysTryReturnVoidResult(NID_SEC, pEncryptedVisibility != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
323
324         pVisibilityChecksum.reset(new (std::nothrow) String());
325         SysTryReturnVoidResult(NID_SEC, pVisibilityChecksum != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
326
327         pCipherVisibilityMessage.reset(new (std::nothrow) PrivilegeManagerMsg_retrieveEx(pEncryptedVisibility.get(), pVisibilityChecksum.get(), &r));
328         SysTryReturnVoidResult(NID_SEC, pCipherVisibilityMessage != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
329
330         ipcResult = ipcClient.SendRequest(pCipherVisibilityMessage.get());
331         SysTryReturnVoidResult(NID_SEC, ipcResult == E_SUCCESS, E_SYSTEM, "Failed to send IPC message.");
332         SysTryReturnVoidResult(NID_SEC, r == E_SUCCESS, r, "Failed to retrieve privilege information");
333
334         isConstructed = true;
335
336         return;
337 }
338
339 result
340 _AccessController::CheckUserPrivilege(_Privilege privilege)
341 {
342         result r = E_SUCCESS;
343         static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;
344
345         bool ret = false;
346
347         _PrivilegeInfo privilegeInfo;
348
349         ClearLastResult();
350
351         SysTryReturnResult(NID_SEC, privilege < _MAX_PRIVILEGE_ENUM, E_INVALID_ARG, "The privilege enumerator is invalid");
352         //SysAssertf(privilegeLevelListTable[privilege][_PRV_API_VER_2_0] == _PRV_LEVEL_USER, "System-level privilege is passed to CheckUserPrivilege.");
353
354         int appType = _AppInfo::GetAppType();
355         PackageId packageId = _AppInfo::GetPackageId();
356         packageId[0] = packageId[0];
357
358         if ((appType & _APP_TYPE_WEB_APP) != _APP_TYPE_WEB_APP)
359         {
360             if (isConstructed != true)
361             {
362                 pthread_once(&onceBlock, Initialize);
363                 r = GetLastResult();
364                 if (IsFailed(r))
365                 {
366                         if (r == E_DATA_NOT_FOUND)
367                         {
368                                 SysLogException(NID_SEC, E_DATA_NOT_FOUND, "[E_DATA_NOT_FOUND] The privilege information does not exist.");
369                                 goto CATCH;
370                         }
371                         else
372                         {
373                                 onceBlock = PTHREAD_ONCE_INIT;
374                                         SysLogException(NID_SEC, r, "[%s] Propagated.", GetErrorMessage(r));
375                         }
376                                 return r;
377                 }
378             }
379
380                 if ((pEncryptedPrivileges != null) && (pChecksum != null) && (pEncryptedVisibility != null) && (pVisibilityChecksum != null))
381                 {
382                         r = privilegeInfo.Construct(packageId, *(pEncryptedPrivileges.get()), *(pChecksum.get()), *(pEncryptedVisibility.get()), *(pVisibilityChecksum.get()), pPrivilegeList.get());
383                         SysTryReturnResult(NID_SEC, r == E_SUCCESS, E_SYSTEM, "An unexpected system error occurred. %ls", packageId.GetPointer());
384
385                         SysLog(NID_SEC, "%ls is in the cache [client]", privilegeInfo.GetAppId().GetPointer());
386                 }
387                 else
388                 {
389                         SysLogException(NID_SEC, E_DATA_NOT_FOUND, "[E_DATA_NOT_FOUND] The privilege information does not exist.");
390                         r =  E_DATA_NOT_FOUND;
391                         goto CATCH;
392                 }
393
394                 ret = privilegeInfo.HasPrivilege(privilege);
395                 if (!ret)
396                 {
397                         r = E_PRIVILEGE_DENIED;
398                         goto CATCH;
399                 }
400         }
401
402         r = CheckPrivacy(packageId, privilege);
403         SysTryReturnResult(NID_SEC, r == E_SUCCESS, E_USER_NOT_CONSENTED, "The user blocks an application from calling the method.");
404
405         return r;
406
407 CATCH:
408
409         SysLogException(NID_SEC,  r, "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
410
411         _AppManagerImpl* pAppManagerImpl = _AppManagerImpl::GetInstance();
412         pAppManagerImpl->TerminateApplications(packageId);
413
414         return r;
415
416 }
417
418 result
419 _AccessController::CheckUserPrivilege(_Privilege privilege1, _Privilege privilege2)
420 {
421         result r = E_SUCCESS;
422         static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;
423
424         bool ret = false;
425
426         _PrivilegeInfo privilegeInfo;
427
428         ClearLastResult();
429
430         SysTryReturnResult(NID_SEC, privilege1 < _MAX_PRIVILEGE_ENUM, E_INVALID_ARG, "The privilege enumerator is invalid");
431         SysTryReturnResult(NID_SEC, privilege2 < _MAX_PRIVILEGE_ENUM, E_INVALID_ARG, "The privilege enumerator is invalid");
432         //SysAssertf(privilegeLevelListTable[privilege][_PRV_API_VER_2_0] == _PRV_LEVEL_USER, "System-level privilege is passed to CheckUserPrivilege.");
433
434         int appType = _AppInfo::GetAppType();
435         PackageId packageId = _AppInfo::GetPackageId();
436         packageId[0] = packageId[0];
437
438         if ((appType & _APP_TYPE_WEB_APP) != _APP_TYPE_WEB_APP)
439         {
440             if (isConstructed != true)
441             {
442                 pthread_once(&onceBlock, Initialize);
443                 r = GetLastResult();
444                 if (IsFailed(r))
445                 {
446                         if (r == E_DATA_NOT_FOUND)
447                         {
448                                 SysLogException(NID_SEC, E_DATA_NOT_FOUND, "[E_DATA_NOT_FOUND] The privilege information does not exist.");
449                                 goto CATCH;
450                         }
451                         else
452                         {
453                                 onceBlock = PTHREAD_ONCE_INIT;
454                                         SysLogException(NID_SEC, r, "[%s] Propagated.", GetErrorMessage(r));
455                         }
456                                 return r;
457                 }
458             }
459
460                 if ((pEncryptedPrivileges != null) && (pChecksum != null) && (pEncryptedVisibility != null) && (pVisibilityChecksum != null))
461                 {
462                         r = privilegeInfo.Construct(packageId, *(pEncryptedPrivileges.get()), *(pChecksum.get()), *(pEncryptedVisibility.get()), *(pVisibilityChecksum.get()), pPrivilegeList.get());
463                         SysTryReturnResult(NID_SEC, r == E_SUCCESS, E_SYSTEM, "An unexpected system error occurred. %ls", packageId.GetPointer());
464
465                         SysLog(NID_SEC, "%ls is in the cache [client]", privilegeInfo.GetAppId().GetPointer());
466                 }
467                 else
468                 {
469                         SysLogException(NID_SEC, E_DATA_NOT_FOUND, "[E_DATA_NOT_FOUND] The privilege information does not exist.");
470                         r =  E_DATA_NOT_FOUND;
471                         goto CATCH;
472                 }
473
474                 ret = privilegeInfo.HasPrivilegeEx(privilege1);
475                 if (!ret)
476                 {
477                         ret = privilegeInfo.HasPrivilege(privilege2);
478                         if (!ret)
479                         {
480                                 r = E_PRIVILEGE_DENIED;
481                                 goto CATCH;
482                         }
483                 }
484         }
485
486         r = CheckPrivacy(packageId, privilege2);
487         SysTryReturnResult(NID_SEC, r == E_SUCCESS, E_USER_NOT_CONSENTED, "The user blocks an application from calling the method.");
488
489         return r;
490
491 CATCH:
492
493         SysLogException(NID_SEC,  r, "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
494
495         _AppManagerImpl* pAppManagerImpl = _AppManagerImpl::GetInstance();
496         pAppManagerImpl->TerminateApplications(packageId);
497
498         return r;
499
500 }
501
502
503 result
504 _AccessController::CheckPrivilege(const String& privilege)
505 {
506         result r = E_SUCCESS;
507         static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;
508
509         bool ret = false;
510
511         _PrivilegeInfo privilegeInfo;
512
513         ClearLastResult();
514
515         int appType = _AppInfo::GetAppType();
516         PackageId packageId = _AppInfo::GetPackageId();
517         packageId[0] = packageId[0];
518
519         if ((appType & _APP_TYPE_WEB_APP) != _APP_TYPE_WEB_APP)
520         {
521                 if (isConstructed != true)
522                 {
523                         pthread_once(&onceBlock, Initialize);
524                         r = GetLastResult();
525                         if (IsFailed(r))
526                         {
527                                 if (r == E_DATA_NOT_FOUND)
528                                 {
529                                         SysLogException(NID_SEC, E_DATA_NOT_FOUND, "[E_DATA_NOT_FOUND] The privilege information does not exist.");
530                                         goto CATCH;
531                                 }
532                                 else
533                                 {
534                                         onceBlock = PTHREAD_ONCE_INIT;
535                                         SysLogException(NID_SEC, r, "[%s] Propagated.", GetErrorMessage(r));
536                                 }
537                                 return r;
538                         }
539                 }
540
541                 std::unique_ptr<IEnumerator> pEnum(null);
542                 pEnum.reset(pPrivilegeList->GetEnumeratorN());
543
544                 if ((pEncryptedPrivileges != null) && (pChecksum != null) && (pEncryptedVisibility != null) && (pVisibilityChecksum != null))
545                 {
546                         r = privilegeInfo.Construct(packageId, *(pEncryptedPrivileges.get()), *(pChecksum.get()), *(pEncryptedVisibility.get()), *(pVisibilityChecksum.get()), pPrivilegeList.get());
547                         SysTryReturnResult(NID_SEC, r == E_SUCCESS, E_SYSTEM, "An unexpected system error occurred. %ls", packageId.GetPointer());
548
549                         SysLog(NID_SEC, "%ls is in the cache [client]", privilegeInfo.GetAppId().GetPointer());
550                 }
551                 else
552                 {
553                         SysLogException(NID_SEC, E_DATA_NOT_FOUND, "[E_DATA_NOT_FOUND] The privilege information does not exist.");
554                         r =  E_DATA_NOT_FOUND;
555                         goto CATCH;
556                 }
557
558                 ret = privilegeInfo.HasPrivilege(privilege);
559                 if (!ret)
560                 {
561                         r = E_PRIVILEGE_DENIED;
562                         goto CATCH;
563                 }
564
565         }
566
567         r = CheckPrivacy(packageId, privilege);
568         SysTryReturnResult(NID_SEC, r == E_SUCCESS, E_USER_NOT_CONSENTED, "The user blocks an application from calling the method.");
569
570         return r;
571
572 CATCH:
573
574         SysLogException(NID_SEC,  r, "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
575
576         _AppManagerImpl* pAppManagerImpl = _AppManagerImpl::GetInstance();
577         pAppManagerImpl->TerminateApplications(packageId);
578
579         return r;
580 }
581
582 result
583 _AccessController::CheckPrivacy(const PackageId & packageId, _Privilege privilege)
584 {
585         result r = E_SUCCESS;
586         int ret = PRIV_MGR_ERROR_SUCCESS;
587
588         if (privacyListTable[privilege][_PRV_API_VER_2_0] != true)
589         {
590                 return r;
591         }
592
593         std::unique_ptr<char[]> pPackageId(null);
594         pPackageId.reset(_StringConverter::CopyToCharArrayN(packageId));
595         SysTryReturnResult(NID_SEC, pPackageId != null, E_SYSTEM, "An unexpected system error occurred.");
596
597         std::unique_ptr<char[]> pPrivilegeId(null);
598         String privilegeId(L"http://tizen.org/privilege/");
599         privilegeId.Append(privilegeListTable[privilege].privilegeString);
600
601         pPrivilegeId.reset(_StringConverter::CopyToCharArrayN(privilegeId));
602         SysTryReturnResult(NID_SEC, pPrivilegeId != null, E_SYSTEM, "An unexpected system error occurred.");
603
604         ret = privacy_checker_check_package_by_privilege(pPackageId.get(), pPrivilegeId.get());
605         if (ret != PRIV_MGR_ERROR_SUCCESS)
606         {
607                 r = E_USER_NOT_CONSENTED;
608                 SysLog(NID_SEC, "Result : FALSE [Privacy]");
609         }
610
611         return r;
612 }
613
614 result
615 _AccessController::CheckPrivacy(const PackageId & packageId, const String& privilege)
616 {
617         result r = E_SUCCESS;
618         int ret = PRIV_MGR_ERROR_SUCCESS;
619
620         std::unique_ptr<char[]> pPackageId(null);
621         pPackageId.reset(_StringConverter::CopyToCharArrayN(packageId));
622         SysTryReturnResult(NID_SEC, pPackageId != null, E_SYSTEM, "An unexpected system error occurred.");
623
624         std::unique_ptr<char[]> pPrivilegeId(null);
625         pPrivilegeId.reset(_StringConverter::CopyToCharArrayN(privilege));
626         SysTryReturnResult(NID_SEC, pPrivilegeId != null, E_SYSTEM, "An unexpected system error occurred.");
627
628         ret = privacy_checker_check_package_by_privilege(pPackageId.get(), pPrivilegeId.get());
629         if (ret != PRIV_MGR_ERROR_SUCCESS)
630         {
631                 r = E_USER_NOT_CONSENTED;
632                 SysLog(NID_SEC, "Result : FALSE [Privacy]");
633         }
634
635         return r;
636 }
637
638 }} //Tizen::Security