Add OOM exception handler
[platform/core/appfw/wgt-backend.git] / src / wgt / step / security / step_add_default_privileges.cc
1 // Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
2 // Use of this source code is governed by a apache 2.0 license that can be
3 // found in the LICENSE file.
4
5 #include "wgt/step/security/step_add_default_privileges.h"
6 #include <common/privileges.h>
7
8 #include <pkgmgrinfo_basic.h>
9
10 #include <cstdlib>
11 #include <cstring>
12 #include <memory>
13
14 namespace wgt {
15 namespace security {
16
17 common_installer::Step::Status StepAddDefaultPrivileges::precheck() {
18   if (!context_->manifest_data.get()) {
19     LOG(ERROR) << "Manifest data is not set";
20     return Status::ERROR;
21   }
22   return Status::OK;
23 }
24
25 common_installer::Step::Status StepAddDefaultPrivileges::process() {
26   manifest_x* m = context_->manifest_data.get();
27   privilege_x* privilege =
28       reinterpret_cast<privilege_x*>(calloc(1, sizeof(privilege_x)));
29   if (!privilege)
30     return Status::ERROR;
31   privilege->type = strdup(common_installer::kWebPrivilegeType);
32   if (!privilege->type) {
33     common_installer::FreePrivilegeX(privilege);
34     return Status::ERROR;
35   }
36   privilege->value = strdup(common_installer::privileges::kPrivForWebApp);
37   if (!privilege->value) {
38     common_installer::FreePrivilegeX(privilege);
39     return Status::ERROR;
40   }
41   m->privileges = g_list_append(m->privileges, privilege);
42   return Status::OK;
43 }
44
45 }  // namespace security
46 }  // namespace wgt