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