Fix labelling of files of widgets
[src/app-framework-main.git] / src / secmgr-wrap.c
index 75c63ca..83a2660 100644 (file)
@@ -1,5 +1,7 @@
 /*
- Copyright 2015 IoT.bzh
+ Copyright (C) 2015-2020 IoT.bzh
+
+ author: José Bollo <jose.bollo@iot.bzh>
 
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
 #include <string.h>
 #include <errno.h>
 #include <assert.h>
-#include <syslog.h>
 
+#if SIMULATE_SECURITY_MANAGER
+#include "simulation/security-manager.h"
+#else
 #include <security-manager.h>
+#endif
 
+#include "verbose.h"
 #include "secmgr-wrap.h"
 
 static app_inst_req *request = NULL;
@@ -34,7 +40,7 @@ static int retcode(enum lib_retcode rc)
        case SECURITY_MANAGER_ERROR_REQ_NOT_COMPLETE: errno = EBADMSG; break;
        case SECURITY_MANAGER_ERROR_AUTHENTICATION_FAILED: errno = EPERM; break;
        case SECURITY_MANAGER_ERROR_ACCESS_DENIED: errno = EACCES; break;
-       default: errno = 0; break;
+       default: errno = ECANCELED; break;
        }
        return -1;
 }
@@ -45,15 +51,15 @@ int secmgr_init(const char *id)
        assert(request == NULL);
        rc = security_manager_app_inst_req_new(&request);
        if (rc != SECURITY_MANAGER_SUCCESS)
-               syslog(LOG_ERR, "security_manager_app_inst_req_new failed");
+               ERROR("security_manager_app_inst_req_new failed");
        else {
                rc = security_manager_app_inst_req_set_pkg_id(request, id);
                if (rc != SECURITY_MANAGER_SUCCESS)
-                       syslog(LOG_ERR, "security_manager_app_inst_req_set_pkg_id failed");
+                       ERROR("security_manager_app_inst_req_set_pkg_id failed");
                else {
                        rc = security_manager_app_inst_req_set_app_id(request, id);
                        if (rc != SECURITY_MANAGER_SUCCESS)
-                               syslog(LOG_ERR, "security_manager_app_inst_req_set_app_id failed");
+                               ERROR("security_manager_app_inst_req_set_app_id failed");
                }
        }
        if (rc != SECURITY_MANAGER_SUCCESS)
@@ -73,8 +79,19 @@ int secmgr_install()
        assert(request != NULL);
        rc = security_manager_app_install(request);
        if (rc != SECURITY_MANAGER_SUCCESS)
-               syslog(LOG_ERR, "security_manager_app_install failed");
-       security_manager_app_inst_req_free(request);
+               ERROR("security_manager_app_install failed");
+       secmgr_cancel();
+       return retcode(rc);
+}
+
+int secmgr_uninstall()
+{
+       int rc;
+       assert(request != NULL);
+       rc = security_manager_app_uninstall(request);
+       if (rc != SECURITY_MANAGER_SUCCESS)
+               ERROR("security_manager_app_uninstall failed");
+       secmgr_cancel();
        return retcode(rc);
 }
 
@@ -84,7 +101,7 @@ int secmgr_permit(const char *permission)
        assert(request != NULL);
        rc = security_manager_app_inst_req_add_privilege(request, permission);
        if (rc != SECURITY_MANAGER_SUCCESS)
-               syslog(LOG_ERR, "security_manager_app_inst_add_privilege %s failed", permission);
+               ERROR("security_manager_app_inst_add_privilege %s failed", permission);
        return retcode(rc);
 }
 
@@ -94,7 +111,7 @@ static int addpath(const char *pathname, enum app_install_path_type type)
        assert(request != NULL);
        rc = security_manager_app_inst_req_add_path(request, pathname, type);
        if (rc != SECURITY_MANAGER_SUCCESS)
-               syslog(LOG_ERR, "security_manager_app_inst_add_path %s failed", pathname);
+               ERROR("security_manager_app_inst_add_path %s failed", pathname);
        return retcode(rc);
 }
 
@@ -113,3 +130,13 @@ int secmgr_path_read_write(const char *pathname)
        return addpath(pathname, SECURITY_MANAGER_PATH_RW);
 }
 
+int secmgr_path_private(const char *pathname)
+{
+       return addpath(pathname, SECURITY_MANAGER_PATH_PRIVATE);
+}
+
+int secmgr_prepare_exec(const char *appid)
+{
+       return retcode(security_manager_prepare_app(appid));
+}
+