using namespace Tizen::Io;
+int
+PrivilegeHandler::GetPrivilegeLevel(const String& privilegeLevel)
+{
+ if(privilegeLevel.Equals(String(L"platform"), true))
+ {
+ return _API_VISIBILITY_PLATFORM;
+ }
+ else if(privilegeLevel.Equals(String(L"partner"), true))
+ {
+ return _API_VISIBILITY_PARTNER;
+ }
+
+ return _API_VISIBILITY_PUBLIC;
+}
+
+
result
-PrivilegeHandler::PickExternalPrivilege(const IList& fullPrivilegeList, IList& normalPrivilegeList, IList& externalPrivilegeList)
+PrivilegeHandler::PickExternalPrivilege(const IList& fullPrivilegeList, int visibilityLevel, IList& normalPrivilegeList, IList& externalPrivilegeList)
{
result r = E_SUCCESS;
String externalPrivilege;
- ArrayList privilegeList;
+ String externalPrivilegeLevel;
+ HashMap privilegeList;
Database privilegeDb;
DbEnumerator* pDbEnum;
- r = privilegeDb.Construct(EXTERNAL_PRIVILEGE_DB_NAME, "r");
+ r = privilegeList.Construct(32, 0.75);
TryReturnResultTag(OSP_INSTALLER, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
+ r = privilegeDb.Construct(EXTERNAL_PRIVILEGE_DB_NAME, "r");
+ TryReturnResultTag(OSP_INSTALLER, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
- pDbEnum = privilegeDb.QueryN(L"SELECT PRIVILEGE_ID FROM PrivilegeInfo");
+ pDbEnum = privilegeDb.QueryN(L"SELECT * FROM PrivilegeInfo");
TryReturnResultTag(OSP_INSTALLER, pDbEnum != null, E_DATABASE, E_DATABASE, "[E_DATABASE] Privilege database error.");
AppLog("------------------------------------------");
r = pDbEnum->GetStringAt(0, externalPrivilege);
TryReturnResultTag(OSP_INSTALLER, r == E_SUCCESS, E_DATABASE, E_DATABASE, "[E_DATABASE] Privilege database error.");
+ r = pDbEnum->GetStringAt(1, externalPrivilegeLevel);
+ TryReturnResultTag(OSP_INSTALLER, r == E_SUCCESS, E_DATABASE, E_DATABASE, "[E_DATABASE] Privilege database error.");
+
AppLog("%ls", externalPrivilege.GetPointer());
- privilegeList.Add(new String(externalPrivilege));
+ privilegeList.Add(new String(externalPrivilege), (new Integer(GetPrivilegeLevel(externalPrivilegeLevel))));
}
delete pDbEnum;
- IEnumerator* pEnum = fullPrivilegeList.GetEnumeratorN();
+ std::unique_ptr<IEnumerator> pEnum(null);
+ pEnum.reset(fullPrivilegeList.GetEnumeratorN());
+ TryReturnResultTag(OSP_INSTALLER, pEnum != null, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] An unexpected system error occurred.");
+
while(pEnum->MoveNext() == E_SUCCESS)
{
- String* tempString = static_cast<String*>(pEnum->GetCurrent());
+ String* pTempString = static_cast<String*>(pEnum->GetCurrent());
- if (privilegeList.Contains(*tempString))
+ if (privilegeList.ContainsKey(*pTempString))
{
- externalPrivilegeList.Add(new String(*tempString));
+ Integer* pPrivilegeLevel = static_cast<Integer*>(privilegeList.GetValue(*pTempString));
+ TryReturnResultTag(OSP_INSTALLER, pPrivilegeLevel != null, E_SYSTEM, E_SYSTEM, "[E_SYSTEM] An unexpected system error occurred.");
+
+ // To be removed
+ if (visibilityLevel != _API_VISIBILITY_NONE)
+ {
+ int privilegeLevel = pPrivilegeLevel->ToInt();
+ TryReturnResultTag(OSP_INSTALLER, privilegeLevel <= visibilityLevel, E_ILLEGAL_ACCESS, E_ILLEGAL_ACCESS,
+ "[E_ILLEGAL_ACCESS] The application does not have the privilege level to register [%ls]", pTempString->GetPointer());
+ }
+
+ externalPrivilegeList.Add(new String(*pTempString));
}
else
{
- normalPrivilegeList.Add(new String(*tempString));
+ normalPrivilegeList.Add(new String(*pTempString));
}
}
- delete pEnum;
privilegeList.RemoveAll(true);
return r;
}
goto CATCH;
}
- r = PickExternalPrivilege(privilegeList, normalPrivilegeList, stringPrivilegeList);
+ r = PickExternalPrivilege(privilegeList, _API_VISIBILITY_NONE, normalPrivilegeList, stringPrivilegeList);
if (r == E_SUCCESS)
{
pBitwisePrivilege = PackPrivilegeN(normalPrivilegeList);
goto CATCH;
}
- r = PickExternalPrivilege(privilegeList, normalPrivilegeList, stringPrivilegeList);
+ r = PickExternalPrivilege(privilegeList, visibilityLevel, normalPrivilegeList, stringPrivilegeList);
if (r == E_SUCCESS)
{
r = PackPrivilegeN(normalPrivilegeList, visibilityLevel, &pBitwisePrivilege);
TryReturnResultTag(OSP_INSTALLER, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
}
+ else if (r == E_ILLEGAL_ACCESS)
+ {
+ AppLogExceptionTag(OSP_INSTALLER, "[E_ILLEGAL_ACCESS] Unauthorized privileges are detected.");
+ return r;
+ }
else
{
AppLog("Working with normal PrivilegeDb.");