Fix the boiler plate codes
[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 < _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 < _MAX_PRIVILEGE_ENUM, E_INVALID_ARG, "The privilege enumerator is invalid");
158         SysTryReturnResult(NID_SEC, 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 < _MAX_PRIVILEGE_ENUM, E_INVALID_ARG, "The privilege enumerator is invalid");
349         //SysAssertf(privilegeLevelListTable[privilege][_PRV_API_VER_2_0] == _PRV_LEVEL_USER, "System-level privilege is passed to CheckUserPrivilege.");
350
351         int appType = _AppInfo::GetAppType();
352         PackageId packageId = _AppInfo::GetPackageId();
353         packageId[0] = packageId[0];
354
355         if ((appType & _APP_TYPE_WEB_APP) != _APP_TYPE_WEB_APP)
356         {
357             if (isConstructed != true)
358             {
359                 pthread_once(&onceBlock, Initialize);
360                 r = GetLastResult();
361                 if (IsFailed(r))
362                 {
363                         if (r == E_DATA_NOT_FOUND)
364                         {
365                                 SysLogException(NID_SEC, E_DATA_NOT_FOUND, "[E_DATA_NOT_FOUND] The privilege information does not exist.");
366                                 goto CATCH;
367                         }
368                         else
369                         {
370                                 onceBlock = PTHREAD_ONCE_INIT;
371                                         SysLogException(NID_SEC, r, "[%s] Propagated.", GetErrorMessage(r));
372                         }
373                                 return r;
374                 }
375             }
376
377                 if ((pEncryptedPrivileges != null) && (pChecksum != null) && (pEncryptedVisibility != null) && (pVisibilityChecksum != null))
378                 {
379                         r = privilegeInfo.Construct(packageId, *(pEncryptedPrivileges.get()), *(pChecksum.get()), *(pEncryptedVisibility.get()), *(pVisibilityChecksum.get()), pPrivilegeList.get());
380                         SysTryReturnResult(NID_SEC, r == E_SUCCESS, E_SYSTEM, "An unexpected system error occurred. %ls", packageId.GetPointer());
381
382                         SysLog(NID_SEC, "%ls is in the cache [client]", privilegeInfo.GetAppId().GetPointer());
383                 }
384                 else
385                 {
386                         SysLogException(NID_SEC, E_DATA_NOT_FOUND, "[E_DATA_NOT_FOUND] The privilege information does not exist.");
387                         r =  E_DATA_NOT_FOUND;
388                         goto CATCH;
389                 }
390
391                 ret = privilegeInfo.HasPrivilege(privilege);
392                 if (!ret)
393                 {
394                         r = E_PRIVILEGE_DENIED;
395                         goto CATCH;
396                 }
397         }
398
399         r = CheckPrivacy(packageId, privilege);
400         SysTryReturnResult(NID_SEC, r == E_SUCCESS, E_USER_NOT_CONSENTED, "The user blocks an application from calling the method.");
401
402         return r;
403
404 CATCH:
405
406         SysLogException(NID_SEC,  r, "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
407
408         _AppManagerImpl* pAppManagerImpl = _AppManagerImpl::GetInstance();
409         pAppManagerImpl->TerminateApplications(packageId);
410
411         return r;
412
413 }
414
415 result
416 _AccessController::CheckUserPrivilege(_Privilege privilege1, _Privilege privilege2)
417 {
418         result r = E_SUCCESS;
419         bool ret = false;
420
421         _PrivilegeInfo privilegeInfo;
422
423         ClearLastResult();
424
425         SysTryReturnResult(NID_SEC, privilege1 < _MAX_PRIVILEGE_ENUM, E_INVALID_ARG, "The privilege enumerator is invalid");
426         SysTryReturnResult(NID_SEC, privilege2 < _MAX_PRIVILEGE_ENUM, E_INVALID_ARG, "The privilege enumerator is invalid");
427         //SysAssertf(privilegeLevelListTable[privilege][_PRV_API_VER_2_0] == _PRV_LEVEL_USER, "System-level privilege is passed to CheckUserPrivilege.");
428
429         int appType = _AppInfo::GetAppType();
430         PackageId packageId = _AppInfo::GetPackageId();
431         packageId[0] = packageId[0];
432
433         if ((appType & _APP_TYPE_WEB_APP) != _APP_TYPE_WEB_APP)
434         {
435             if (isConstructed != true)
436             {
437                 pthread_once(&onceBlock, Initialize);
438                 r = GetLastResult();
439                 if (IsFailed(r))
440                 {
441                         if (r == E_DATA_NOT_FOUND)
442                         {
443                                 SysLogException(NID_SEC, E_DATA_NOT_FOUND, "[E_DATA_NOT_FOUND] The privilege information does not exist.");
444                                 goto CATCH;
445                         }
446                         else
447                         {
448                                 onceBlock = PTHREAD_ONCE_INIT;
449                                         SysLogException(NID_SEC, r, "[%s] Propagated.", GetErrorMessage(r));
450                         }
451                                 return r;
452                 }
453             }
454
455                 if ((pEncryptedPrivileges != null) && (pChecksum != null) && (pEncryptedVisibility != null) && (pVisibilityChecksum != null))
456                 {
457                         r = privilegeInfo.Construct(packageId, *(pEncryptedPrivileges.get()), *(pChecksum.get()), *(pEncryptedVisibility.get()), *(pVisibilityChecksum.get()), pPrivilegeList.get());
458                         SysTryReturnResult(NID_SEC, r == E_SUCCESS, E_SYSTEM, "An unexpected system error occurred. %ls", packageId.GetPointer());
459
460                         SysLog(NID_SEC, "%ls is in the cache [client]", privilegeInfo.GetAppId().GetPointer());
461                 }
462                 else
463                 {
464                         SysLogException(NID_SEC, E_DATA_NOT_FOUND, "[E_DATA_NOT_FOUND] The privilege information does not exist.");
465                         r =  E_DATA_NOT_FOUND;
466                         goto CATCH;
467                 }
468
469                 ret = privilegeInfo.HasPrivilegeEx(privilege1);
470                 if (!ret)
471                 {
472                         ret = privilegeInfo.HasPrivilege(privilege2);
473                         if (!ret)
474                         {
475                                 r = E_PRIVILEGE_DENIED;
476                                 goto CATCH;
477                         }
478                 }
479         }
480
481         r = CheckPrivacy(packageId, privilege2);
482         SysTryReturnResult(NID_SEC, r == E_SUCCESS, E_USER_NOT_CONSENTED, "The user blocks an application from calling the method.");
483
484         return r;
485
486 CATCH:
487
488         SysLogException(NID_SEC,  r, "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
489
490         _AppManagerImpl* pAppManagerImpl = _AppManagerImpl::GetInstance();
491         pAppManagerImpl->TerminateApplications(packageId);
492
493         return r;
494
495 }
496
497
498 result
499 _AccessController::CheckPrivilege(const String& privilege)
500 {
501         result r = E_SUCCESS;
502         bool ret = false;
503
504         _PrivilegeInfo privilegeInfo;
505
506         ClearLastResult();
507
508         int appType = _AppInfo::GetAppType();
509         PackageId packageId = _AppInfo::GetPackageId();
510         packageId[0] = packageId[0];
511
512         if ((appType & _APP_TYPE_WEB_APP) != _APP_TYPE_WEB_APP)
513         {
514                 if (isConstructed != true)
515                 {
516                         pthread_once(&onceBlock, Initialize);
517                         r = GetLastResult();
518                         if (IsFailed(r))
519                         {
520                                 if (r == E_DATA_NOT_FOUND)
521                                 {
522                                         SysLogException(NID_SEC, E_DATA_NOT_FOUND, "[E_DATA_NOT_FOUND] The privilege information does not exist.");
523                                         goto CATCH;
524                                 }
525                                 else
526                                 {
527                                         onceBlock = PTHREAD_ONCE_INIT;
528                                         SysLogException(NID_SEC, r, "[%s] Propagated.", GetErrorMessage(r));
529                                 }
530                                 return r;
531                         }
532                 }
533
534                 std::unique_ptr<IEnumerator> pEnum(null);
535                 pEnum.reset(pPrivilegeList->GetEnumeratorN());
536
537                 if ((pEncryptedPrivileges != null) && (pChecksum != null) && (pEncryptedVisibility != null) && (pVisibilityChecksum != null))
538                 {
539                         r = privilegeInfo.Construct(packageId, *(pEncryptedPrivileges.get()), *(pChecksum.get()), *(pEncryptedVisibility.get()), *(pVisibilityChecksum.get()), pPrivilegeList.get());
540                         SysTryReturnResult(NID_SEC, r == E_SUCCESS, E_SYSTEM, "An unexpected system error occurred. %ls", packageId.GetPointer());
541
542                         SysLog(NID_SEC, "%ls is in the cache [client]", privilegeInfo.GetAppId().GetPointer());
543                 }
544                 else
545                 {
546                         SysLogException(NID_SEC, E_DATA_NOT_FOUND, "[E_DATA_NOT_FOUND] The privilege information does not exist.");
547                         r =  E_DATA_NOT_FOUND;
548                         goto CATCH;
549                 }
550
551                 ret = privilegeInfo.HasPrivilege(privilege);
552                 if (!ret)
553                 {
554                         r = E_PRIVILEGE_DENIED;
555                         goto CATCH;
556                 }
557
558         }
559
560         r = CheckPrivacy(packageId, privilege);
561         SysTryReturnResult(NID_SEC, r == E_SUCCESS, E_USER_NOT_CONSENTED, "The user blocks an application from calling the method.");
562
563         return r;
564
565 CATCH:
566
567         SysLogException(NID_SEC,  r, "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
568
569         _AppManagerImpl* pAppManagerImpl = _AppManagerImpl::GetInstance();
570         pAppManagerImpl->TerminateApplications(packageId);
571
572         return r;
573 }
574
575 result
576 _AccessController::CheckPrivacy(const PackageId & packageId, _Privilege privilege)
577 {
578         result r = E_SUCCESS;
579         int ret = PRIV_MGR_ERROR_SUCCESS;
580
581         if (privacyListTable[privilege][_PRV_API_VER_2_0] != true)
582         {
583                 return r;
584         }
585
586         std::unique_ptr<char[]> pPackageId(null);
587         pPackageId.reset(_StringConverter::CopyToCharArrayN(packageId));
588         SysTryReturnResult(NID_SEC, pPackageId != null, E_SYSTEM, "An unexpected system error occurred.");
589
590         std::unique_ptr<char[]> pPrivilegeId(null);
591         String privilegeId(L"http://tizen.org/privilege/");
592         privilegeId.Append(privilegeListTable[privilege].privilegeString);
593
594         pPrivilegeId.reset(_StringConverter::CopyToCharArrayN(privilegeId));
595         SysTryReturnResult(NID_SEC, pPrivilegeId != null, E_SYSTEM, "An unexpected system error occurred.");
596
597         ret = privacy_checker_check_package_by_privilege(pPackageId.get(), pPrivilegeId.get());
598         if (ret != PRIV_MGR_ERROR_SUCCESS)
599         {
600                 r = E_USER_NOT_CONSENTED;
601                 SysLog(NID_SEC, "Result : FALSE [Privacy]");
602         }
603
604         return r;
605 }
606
607 result
608 _AccessController::CheckPrivacy(const PackageId & packageId, const String& privilege)
609 {
610         result r = E_SUCCESS;
611         int ret = PRIV_MGR_ERROR_SUCCESS;
612
613         std::unique_ptr<char[]> pPackageId(null);
614         pPackageId.reset(_StringConverter::CopyToCharArrayN(packageId));
615         SysTryReturnResult(NID_SEC, pPackageId != null, E_SYSTEM, "An unexpected system error occurred.");
616
617         std::unique_ptr<char[]> pPrivilegeId(null);
618         pPrivilegeId.reset(_StringConverter::CopyToCharArrayN(privilege));
619         SysTryReturnResult(NID_SEC, pPrivilegeId != null, E_SYSTEM, "An unexpected system error occurred.");
620
621         ret = privacy_checker_check_package_by_privilege(pPackageId.get(), pPrivilegeId.get());
622         if (ret != PRIV_MGR_ERROR_SUCCESS)
623         {
624                 r = E_USER_NOT_CONSENTED;
625                 SysLog(NID_SEC, "Result : FALSE [Privacy]");
626         }
627
628         return r;
629 }
630
631 }} //Tizen::Security