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