Revise doxygen
[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 bool isConstructed = false;
47 static std::unique_ptr<_IpcClient> pIpcClient(null);
48 static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;
49 static pthread_once_t ipcOnceBlock = 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         bool ret = false;
79
80         SysTryReturnResult(NID_SEC, (privilege >= 0) && (privilege < _MAX_PRIVILEGE_ENUM), E_INVALID_ARG, "The privilege enumerator is invalid");
81
82         String subAppId;
83         packageId.SubString(0, MAX_APP_ID_SIZE, subAppId);
84
85         _PackageInfoImpl infoImpl;
86         result r = infoImpl.Construct(subAppId);
87         SysTryReturnResult(NID_SEC, r == E_SUCCESS, E_SYSTEM, "An unexpected system error occurred.");
88
89         String webAppType(L"wgt");
90         String appType = infoImpl.GetAppType();
91         if (appType.Equals(webAppType, true))
92         {
93                 return E_SUCCESS;
94         }
95
96         if (__pPrivilegeManager == null)
97         {
98                 __pPrivilegeManager = _PrivilegeManager::GetInstance();
99         }
100         SysTryReturnResult(NID_SEC, __pPrivilegeManager != null, E_SYSTEM, "An unexpected system error occurred.");
101
102         std::unique_ptr<_PrivilegeInfo> pPrivilegeInfo(__pPrivilegeManager->RetrievePrivilegeInfoN(subAppId));
103         r = GetLastResult();
104
105         if (r == E_SUCCESS)
106         {
107                 // nothing to do.
108         }
109         else if (r == E_DATA_NOT_FOUND)
110         {
111                 SysLogException(NID_SEC, E_DATA_NOT_FOUND, "[E_DATA_NOT_FOUND] The privilege information does not exist.");
112                 goto CATCH;
113         }
114         else
115         {
116                 SysLogException(NID_SEC, E_SYSTEM, "[E_SYSTEM] An unexpected system error occurred.");
117                 return E_SYSTEM;
118         }
119
120         ret = pPrivilegeInfo->HasPrivilege(privilege);
121         if (!ret)
122         {
123                 r = E_PRIVILEGE_DENIED;
124                 goto CATCH;
125         }
126
127         r = CheckPrivacy(packageId, privilege);
128         SysTryReturnResult(NID_SEC, r == E_SUCCESS, E_USER_NOT_CONSENTED, "The user blocks an application from calling the method.");
129
130         return r;
131
132 CATCH:
133
134         SysLogException(NID_SEC,  r, "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
135
136         _AppManagerImpl* pAppManagerImpl = _AppManagerImpl::GetInstance();
137         pAppManagerImpl->TerminateApplications(packageId);
138
139         return r;
140 }
141
142 result
143 _AccessController::CheckSystemPrivilege(const PackageId& packageId, _Privilege privilege1, _Privilege privilege2)
144 {
145         bool ret = false;
146
147         SysTryReturnResult(NID_SEC, (privilege1 >= 0) && (privilege1 < _MAX_PRIVILEGE_ENUM), E_INVALID_ARG, "The privilege enumerator is invalid");
148         SysTryReturnResult(NID_SEC, (privilege2 >= 0) && (privilege2 < _MAX_PRIVILEGE_ENUM), E_INVALID_ARG, "The privilege enumerator is invalid");
149
150         String subAppId;
151         packageId.SubString(0, MAX_APP_ID_SIZE, subAppId);
152
153         _PackageInfoImpl infoImpl;
154         result r = infoImpl.Construct(subAppId);
155         SysTryReturnResult(NID_SEC, r == E_SUCCESS, E_SYSTEM, "An unexpected system error occurred.");
156
157         String webAppType(L"wgt");
158         String appType = infoImpl.GetAppType();
159         if (appType.Equals(webAppType, true))
160         {
161                 return E_SUCCESS;
162         }
163
164         if (__pPrivilegeManager == null)
165         {
166                 __pPrivilegeManager = _PrivilegeManager::GetInstance();
167         }
168         SysTryReturnResult(NID_SEC, __pPrivilegeManager != null, E_SYSTEM, "An unexpected system error occurred.");
169
170         std::unique_ptr<_PrivilegeInfo> pPrivilegeInfo(__pPrivilegeManager->RetrievePrivilegeInfoN(subAppId));
171         r = GetLastResult();
172
173         if (r == E_SUCCESS)
174         {
175                 // nothing to do.
176         }
177         else if (r == E_DATA_NOT_FOUND)
178         {
179                 SysLogException(NID_SEC, E_DATA_NOT_FOUND, "[E_DATA_NOT_FOUND] The privilege information does not exist.");
180                 goto CATCH;
181         }
182         else
183         {
184                 SysLogException(NID_SEC, E_SYSTEM, "[E_SYSTEM] An unexpected system error occurred.");
185                 return E_SYSTEM;
186         }
187
188         ret = pPrivilegeInfo->HasPrivilegeEx(privilege1);
189         if (!ret)
190         {
191                 ret = pPrivilegeInfo->HasPrivilege(privilege2);
192                 if (!ret)
193                 {
194                         r = E_PRIVILEGE_DENIED;
195                         goto CATCH;
196                 }
197         }
198
199         r = CheckPrivacy(packageId, privilege2);
200         SysTryReturnResult(NID_SEC, r == E_SUCCESS, E_USER_NOT_CONSENTED, "The user blocks an application from calling the method.");
201
202         return r;
203
204 CATCH:
205
206         SysLogException(NID_SEC,  r, "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
207
208         _AppManagerImpl* pAppManagerImpl = _AppManagerImpl::GetInstance();
209         pAppManagerImpl->TerminateApplications(packageId);
210
211         return r;
212 }
213
214 result
215 _AccessController::CheckPrivilege(const PackageId& packageId, const String& privilege)
216 {
217         bool ret = false;
218
219         String subAppId;
220         packageId.SubString(0, MAX_APP_ID_SIZE, subAppId);
221
222         _PackageInfoImpl infoImpl;
223         result r = infoImpl.Construct(subAppId);
224         SysTryReturnResult(NID_SEC, r == E_SUCCESS, E_SYSTEM, "An unexpected system error occurred.");
225
226         String webAppType(L"wgt");
227         String appType = infoImpl.GetAppType();
228         if (appType.Equals(webAppType, true))
229         {
230                 return E_SUCCESS;
231         }
232
233         if (__pPrivilegeManager == null)
234         {
235                 __pPrivilegeManager = _PrivilegeManager::GetInstance();
236         }
237         SysTryReturnResult(NID_SEC, __pPrivilegeManager != null, E_SYSTEM, "An unexpected system error occurred.");
238
239         std::unique_ptr<_PrivilegeInfo> pPrivilegeInfo(__pPrivilegeManager->RetrievePrivilegeInfoN(subAppId));
240         r = GetLastResult();
241
242         if (r == E_SUCCESS)
243         {
244                 // nothing to do.
245         }
246         else if (r == E_DATA_NOT_FOUND)
247         {
248                 SysLogException(NID_SEC, E_DATA_NOT_FOUND, "[E_DATA_NOT_FOUND] The privilege information does not exist.");
249                 goto CATCH;
250         }
251         else
252         {
253                 SysLogException(NID_SEC, E_SYSTEM, "[E_SYSTEM] An unexpected system error occurred.");
254                 return E_SYSTEM;
255         }
256
257         ret = pPrivilegeInfo->HasPrivilege(privilege);
258         if (!ret)
259         {
260                 r = E_PRIVILEGE_DENIED;
261                 goto CATCH;
262         }
263
264         r = CheckPrivacy(packageId, privilege);
265         SysTryReturnResult(NID_SEC, r == E_SUCCESS, E_USER_NOT_CONSENTED, "The user blocks an application from calling the method.");
266
267         return r;
268
269 CATCH:
270
271         SysLogException(NID_SEC,  r, "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
272
273         _AppManagerImpl* pAppManagerImpl = _AppManagerImpl::GetInstance();
274         pAppManagerImpl->TerminateApplications(packageId);
275
276         return r;
277 }
278
279 void
280 _AccessController::InitIpcClient(void)
281 {
282         std::unique_ptr<_IpcClient> pLocalIpcClient(new (std::nothrow) _IpcClient);
283         SysTryReturnVoidResult(NID_SEC, pLocalIpcClient != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
284
285         result r = pLocalIpcClient->Construct(L"osp.security.ipcserver.privilegemanager", null);
286         SysTryReturnVoidResult(NID_SEC, r == E_SUCCESS, E_SYSTEM, "Failed to construct the instance of IPC.");
287
288         pIpcClient = std::move(pLocalIpcClient);
289         return;
290 }
291
292 void
293 _AccessController::Initialize(void)
294 {
295         result r = E_SUCCESS;
296
297     if (pIpcClient == null)
298     {
299         pthread_once(&ipcOnceBlock, InitIpcClient);
300         r = GetLastResult();
301         if (IsFailed(r))
302         {
303                 ipcOnceBlock = PTHREAD_ONCE_INIT;
304                         SysLogException(NID_SEC, r, "[%s] Propagated.", GetErrorMessage(r));
305                         return;
306         }
307     }
308
309         pEncryptedPrivileges.reset(new (std::nothrow) String());
310         SysTryReturnVoidResult(NID_SEC, pEncryptedPrivileges != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
311
312         pChecksum.reset(new (std::nothrow) String());
313         SysTryReturnVoidResult(NID_SEC, pChecksum != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
314
315         pPrivilegeList.reset(new ArrayList());
316         SysTryReturnVoidResult(NID_SEC, pPrivilegeList != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
317         pPrivilegeList->Construct();
318
319         std::unique_ptr<IPC::Message> pCipherPrivilegeMessage(new (std::nothrow) PrivilegeManagerMsg_retrieve(pEncryptedPrivileges.get(), pChecksum.get(), pPrivilegeList.get(), &r));
320         SysTryReturnVoidResult(NID_SEC, pCipherPrivilegeMessage != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
321
322         result ipcResult = pIpcClient->SendRequest(pCipherPrivilegeMessage.get());
323         SysTryReturnVoidResult(NID_SEC, ipcResult == E_SUCCESS, E_SYSTEM, "Failed to send IPC message.");
324         SysTryReturnVoidResult(NID_SEC, r == E_SUCCESS, r, "Failed to retrieve privilege information");
325
326         pEncryptedVisibility.reset(new (std::nothrow) String());
327         SysTryReturnVoidResult(NID_SEC, pEncryptedVisibility != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
328
329         pVisibilityChecksum.reset(new (std::nothrow) String());
330         SysTryReturnVoidResult(NID_SEC, pVisibilityChecksum != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
331
332         std::unique_ptr<IPC::Message> pCipherVisibilityMessage(new (std::nothrow) PrivilegeManagerMsg_retrieveEx(pEncryptedVisibility.get(), pVisibilityChecksum.get(), &r));
333         SysTryReturnVoidResult(NID_SEC, pCipherVisibilityMessage != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
334
335         ipcResult = pIpcClient->SendRequest(pCipherVisibilityMessage.get());
336         SysTryReturnVoidResult(NID_SEC, ipcResult == E_SUCCESS, E_SYSTEM, "Failed to send IPC message.");
337         SysTryReturnVoidResult(NID_SEC, r == E_SUCCESS, r, "Failed to retrieve privilege information");
338
339         isConstructed = true;
340         return;
341 }
342
343 result
344 _AccessController::CheckUserPrivilege(_Privilege privilege)
345 {
346         result r = E_SUCCESS;
347         bool ret = false;
348         _PrivilegeInfo privilegeInfo;
349         ClearLastResult();
350
351         SysTryReturnResult(NID_SEC, (privilege >= 0) && (privilege < _MAX_PRIVILEGE_ENUM), E_INVALID_ARG, "The privilege enumerator is invalid");
352
353         int appType = _AppInfo::GetAppType();
354         PackageId packageId = _AppInfo::GetPackageId();
355         packageId[0] = packageId[0];
356
357         if ((appType & _APP_TYPE_WEB_APP) != _APP_TYPE_WEB_APP)
358         {
359             if (isConstructed != true)
360             {
361                 pthread_once(&onceBlock, Initialize);
362                 r = GetLastResult();
363                 if (IsFailed(r))
364                 {
365                         if (r == E_DATA_NOT_FOUND)
366                         {
367                                 SysLogException(NID_SEC, E_DATA_NOT_FOUND, "[E_DATA_NOT_FOUND] The privilege information does not exist.");
368                                 goto CATCH;
369                         }
370                         else
371                         {
372                                 onceBlock = PTHREAD_ONCE_INIT;
373                                         SysLogException(NID_SEC, r, "[%s] Propagated.", GetErrorMessage(r));
374                         }
375                                 return r;
376                 }
377             }
378
379                 if ((pEncryptedPrivileges != null) && (pChecksum != null) && (pEncryptedVisibility != null) && (pVisibilityChecksum != null))
380                 {
381                         r = privilegeInfo.Construct(packageId, *(pEncryptedPrivileges.get()), *(pChecksum.get()), *(pEncryptedVisibility.get()), *(pVisibilityChecksum.get()), pPrivilegeList.get());
382                         SysTryReturnResult(NID_SEC, r == E_SUCCESS, E_SYSTEM, "An unexpected system error occurred. %ls", packageId.GetPointer());
383
384                         SysLog(NID_SEC, "%ls is in the cache [client]", privilegeInfo.GetAppId().GetPointer());
385                 }
386                 else
387                 {
388                         SysLogException(NID_SEC, E_DATA_NOT_FOUND, "[E_DATA_NOT_FOUND] The privilege information does not exist.");
389                         r =  E_DATA_NOT_FOUND;
390                         goto CATCH;
391                 }
392
393                 ret = privilegeInfo.HasPrivilege(privilege);
394                 if (!ret)
395                 {
396                         r = E_PRIVILEGE_DENIED;
397                         goto CATCH;
398                 }
399         }
400
401         r = CheckPrivacy(packageId, privilege);
402         SysTryReturnResult(NID_SEC, r == E_SUCCESS, E_USER_NOT_CONSENTED, "The user blocks an application from calling the method.");
403
404         return r;
405
406 CATCH:
407
408         SysLogException(NID_SEC,  r, "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
409
410         _AppManagerImpl* pAppManagerImpl = _AppManagerImpl::GetInstance();
411         pAppManagerImpl->TerminateApplications(packageId);
412
413         return r;
414
415 }
416
417 result
418 _AccessController::CheckUserPrivilege(_Privilege privilege1, _Privilege privilege2)
419 {
420         result r = E_SUCCESS;
421         bool ret = false;
422         _PrivilegeInfo privilegeInfo;
423         ClearLastResult();
424
425         SysTryReturnResult(NID_SEC, (privilege1 >= 0) && (privilege1 < _MAX_PRIVILEGE_ENUM), E_INVALID_ARG, "The privilege enumerator is invalid");
426         SysTryReturnResult(NID_SEC, (privilege2 >= 0) && (privilege2 < _MAX_PRIVILEGE_ENUM), E_INVALID_ARG, "The privilege enumerator is invalid");
427
428         int appType = _AppInfo::GetAppType();
429         PackageId packageId = _AppInfo::GetPackageId();
430         packageId[0] = packageId[0];
431
432         if ((appType & _APP_TYPE_WEB_APP) != _APP_TYPE_WEB_APP)
433         {
434             if (isConstructed != true)
435             {
436                 pthread_once(&onceBlock, Initialize);
437                 r = GetLastResult();
438                 if (IsFailed(r))
439                 {
440                         if (r == E_DATA_NOT_FOUND)
441                         {
442                                 SysLogException(NID_SEC, E_DATA_NOT_FOUND, "[E_DATA_NOT_FOUND] The privilege information does not exist.");
443                                 goto CATCH;
444                         }
445                         else
446                         {
447                                 onceBlock = PTHREAD_ONCE_INIT;
448                                         SysLogException(NID_SEC, r, "[%s] Propagated.", GetErrorMessage(r));
449                         }
450                                 return r;
451                 }
452             }
453
454                 if ((pEncryptedPrivileges != null) && (pChecksum != null) && (pEncryptedVisibility != null) && (pVisibilityChecksum != null))
455                 {
456                         r = privilegeInfo.Construct(packageId, *(pEncryptedPrivileges.get()), *(pChecksum.get()), *(pEncryptedVisibility.get()), *(pVisibilityChecksum.get()), pPrivilegeList.get());
457                         SysTryReturnResult(NID_SEC, r == E_SUCCESS, E_SYSTEM, "An unexpected system error occurred. %ls", packageId.GetPointer());
458
459                         SysLog(NID_SEC, "%ls is in the cache [client]", privilegeInfo.GetAppId().GetPointer());
460                 }
461                 else
462                 {
463                         SysLogException(NID_SEC, E_DATA_NOT_FOUND, "[E_DATA_NOT_FOUND] The privilege information does not exist.");
464                         r =  E_DATA_NOT_FOUND;
465                         goto CATCH;
466                 }
467
468                 ret = privilegeInfo.HasPrivilegeEx(privilege1);
469                 if (!ret)
470                 {
471                         ret = privilegeInfo.HasPrivilege(privilege2);
472                         if (!ret)
473                         {
474                                 r = E_PRIVILEGE_DENIED;
475                                 goto CATCH;
476                         }
477                 }
478         }
479
480         r = CheckPrivacy(packageId, privilege2);
481         SysTryReturnResult(NID_SEC, r == E_SUCCESS, E_USER_NOT_CONSENTED, "The user blocks an application from calling the method.");
482
483         return r;
484
485 CATCH:
486
487         SysLogException(NID_SEC,  r, "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
488
489         _AppManagerImpl* pAppManagerImpl = _AppManagerImpl::GetInstance();
490         pAppManagerImpl->TerminateApplications(packageId);
491
492         return r;
493
494 }
495
496
497 result
498 _AccessController::CheckPrivilege(const String& privilege)
499 {
500         result r = E_SUCCESS;
501         bool ret = false;
502         _PrivilegeInfo privilegeInfo;
503         ClearLastResult();
504
505         int appType = _AppInfo::GetAppType();
506         PackageId packageId = _AppInfo::GetPackageId();
507         packageId[0] = packageId[0];
508
509         if ((appType & _APP_TYPE_WEB_APP) != _APP_TYPE_WEB_APP)
510         {
511                 if (isConstructed != true)
512                 {
513                         pthread_once(&onceBlock, Initialize);
514                         r = GetLastResult();
515                         if (IsFailed(r))
516                         {
517                                 if (r == E_DATA_NOT_FOUND)
518                                 {
519                                         SysLogException(NID_SEC, E_DATA_NOT_FOUND, "[E_DATA_NOT_FOUND] The privilege information does not exist.");
520                                         goto CATCH;
521                                 }
522                                 else
523                                 {
524                                         onceBlock = PTHREAD_ONCE_INIT;
525                                         SysLogException(NID_SEC, r, "[%s] Propagated.", GetErrorMessage(r));
526                                 }
527                                 return r;
528                         }
529                 }
530
531                 std::unique_ptr<IEnumerator> pEnum(null);
532                 pEnum.reset(pPrivilegeList->GetEnumeratorN());
533
534                 if ((pEncryptedPrivileges != null) && (pChecksum != null) && (pEncryptedVisibility != null) && (pVisibilityChecksum != null))
535                 {
536                         r = privilegeInfo.Construct(packageId, *(pEncryptedPrivileges.get()), *(pChecksum.get()), *(pEncryptedVisibility.get()), *(pVisibilityChecksum.get()), pPrivilegeList.get());
537                         SysTryReturnResult(NID_SEC, r == E_SUCCESS, E_SYSTEM, "An unexpected system error occurred. %ls", packageId.GetPointer());
538
539                         SysLog(NID_SEC, "%ls is in the cache [client]", privilegeInfo.GetAppId().GetPointer());
540                 }
541                 else
542                 {
543                         SysLogException(NID_SEC, E_DATA_NOT_FOUND, "[E_DATA_NOT_FOUND] The privilege information does not exist.");
544                         r =  E_DATA_NOT_FOUND;
545                         goto CATCH;
546                 }
547
548                 ret = privilegeInfo.HasPrivilege(privilege);
549                 if (!ret)
550                 {
551                         r = E_PRIVILEGE_DENIED;
552                         goto CATCH;
553                 }
554
555         }
556
557         r = CheckPrivacy(packageId, privilege);
558         SysTryReturnResult(NID_SEC, r == E_SUCCESS, E_USER_NOT_CONSENTED, "The user blocks an application from calling the method.");
559
560         return r;
561
562 CATCH:
563
564         SysLogException(NID_SEC,  r, "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
565
566         _AppManagerImpl* pAppManagerImpl = _AppManagerImpl::GetInstance();
567         pAppManagerImpl->TerminateApplications(packageId);
568
569         return r;
570 }
571
572 result
573 _AccessController::CheckPrivacy(const PackageId & packageId, _Privilege privilege)
574 {
575         result r = E_SUCCESS;
576
577         if (privacyListTable[privilege] != true)
578         {
579                 return r;
580         }
581
582         std::unique_ptr<char[]> pPackageId(null);
583         pPackageId.reset(_StringConverter::CopyToCharArrayN(packageId));
584         SysTryReturnResult(NID_SEC, pPackageId != null, E_SYSTEM, "An unexpected system error occurred.");
585
586         std::unique_ptr<char[]> pPrivilegeId(null);
587         String privilegeId(L"http://tizen.org/privilege/");
588         privilegeId.Append(privilegeListTable[privilege].privilegeString);
589
590         pPrivilegeId.reset(_StringConverter::CopyToCharArrayN(privilegeId));
591         SysTryReturnResult(NID_SEC, pPrivilegeId != null, E_SYSTEM, "An unexpected system error occurred.");
592
593         int ret = privacy_checker_check_package_by_privilege(pPackageId.get(), pPrivilegeId.get());
594         if (ret != PRIV_MGR_ERROR_SUCCESS)
595         {
596                 r = E_USER_NOT_CONSENTED;
597                 SysLog(NID_SEC, "Result : FALSE [Privacy]");
598         }
599
600         return r;
601 }
602
603 result
604 _AccessController::CheckPrivacy(const PackageId & packageId, const String& privilege)
605 {
606         result r = E_SUCCESS;
607
608         std::unique_ptr<char[]> pPackageId(null);
609         pPackageId.reset(_StringConverter::CopyToCharArrayN(packageId));
610         SysTryReturnResult(NID_SEC, pPackageId != null, E_SYSTEM, "An unexpected system error occurred.");
611
612         std::unique_ptr<char[]> pPrivilegeId(null);
613         pPrivilegeId.reset(_StringConverter::CopyToCharArrayN(privilege));
614         SysTryReturnResult(NID_SEC, pPrivilegeId != null, E_SYSTEM, "An unexpected system error occurred.");
615
616         int ret = privacy_checker_check_package_by_privilege(pPackageId.get(), pPrivilegeId.get());
617         if (ret != PRIV_MGR_ERROR_SUCCESS)
618         {
619                 r = E_USER_NOT_CONSENTED;
620                 SysLog(NID_SEC, "Result : FALSE [Privacy]");
621         }
622
623         return r;
624 }
625
626 }} //Tizen::Security