/*
- Copyright 2015 IoT.bzh
+ Copyright 2015, 2016, 2017 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 <errno.h>
#include <assert.h>
-#if 0
-#include <security-manager.h>
+#if SIMULATE_SECURITY_MANAGER
+#include "simulation/security-manager.h"
#else
-#include <stdio.h>
-#include <stdint.h>
-enum lib_retcode {
- SECURITY_MANAGER_SUCCESS,
- SECURITY_MANAGER_ERROR_INPUT_PARAM,
- SECURITY_MANAGER_ERROR_MEMORY,
- SECURITY_MANAGER_ERROR_REQ_NOT_COMPLETE,
- SECURITY_MANAGER_ERROR_AUTHENTICATION_FAILED,
- SECURITY_MANAGER_ERROR_ACCESS_DENIED
-};
-enum app_install_path_type {
- SECURITY_MANAGER_PATH_PUBLIC_RO,
- SECURITY_MANAGER_PATH_RO,
- SECURITY_MANAGER_PATH_RW
-};
-typedef void app_inst_req;
-static int diese = 0;
-#define security_manager_app_inst_req_free(r) \
- (printf("security_manager_app_inst_req_free(%p)\n",r),(void)0)
-
-#define security_manager_app_inst_req_new(pr) \
- (*(pr)=(void*)(intptr_t)(++diese), printf("security_manager_app_inst_req_new(%p)\n",*pr), SECURITY_MANAGER_SUCCESS)
-
-#define security_manager_app_inst_req_set_pkg_id(r,i) \
- (printf("security_manager_app_inst_req_set_pkg_id(%p,\"%s\")\n",r,i), SECURITY_MANAGER_SUCCESS)
-
-#define security_manager_app_inst_req_set_app_id(r,i) \
- (printf("security_manager_app_inst_req_set_app_id(%p,\"%s\")\n",r,i), SECURITY_MANAGER_SUCCESS)
-
-#define security_manager_app_inst_req_add_privilege(r,p) \
- (printf("security_manager_app_inst_req_add_privilege(%p,\"%s\")\n",r,p), SECURITY_MANAGER_SUCCESS)
-
-#define security_manager_app_inst_req_add_path(r,p,t) \
- (printf("security_manager_app_inst_req_add_path(%p,\"%s\",%d)\n",r,p,t), SECURITY_MANAGER_SUCCESS)
-
-#define security_manager_app_install(r) \
- (printf("security_manager_app_install(%p)\n",r), SECURITY_MANAGER_SUCCESS)
-
+#include <security-manager.h>
#endif
+#include "verbose.h"
#include "secmgr-wrap.h"
static app_inst_req *request = NULL;
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;
}
-int secmgr_init(const char *pkgid, const char *appid)
+int secmgr_init(const char *id)
{
int rc;
assert(request == NULL);
rc = security_manager_app_inst_req_new(&request);
- if (rc == SECURITY_MANAGER_SUCCESS) {
- rc = security_manager_app_inst_req_set_pkg_id(request, pkgid);
- if (rc == SECURITY_MANAGER_SUCCESS)
- rc = security_manager_app_inst_req_set_app_id(request, appid);
+ if (rc != SECURITY_MANAGER_SUCCESS)
+ 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)
+ 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)
+ ERROR("security_manager_app_inst_req_set_app_id failed");
+ }
}
if (rc != SECURITY_MANAGER_SUCCESS)
secmgr_cancel();
int rc;
assert(request != NULL);
rc = security_manager_app_install(request);
+ if (rc != SECURITY_MANAGER_SUCCESS)
+ 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);
}
int rc;
assert(request != NULL);
rc = security_manager_app_inst_req_add_privilege(request, permission);
+ if (rc != SECURITY_MANAGER_SUCCESS)
+ ERROR("security_manager_app_inst_add_privilege %s failed", permission);
return retcode(rc);
}
int rc;
assert(request != NULL);
rc = security_manager_app_inst_req_add_path(request, pathname, type);
+ if (rc != SECURITY_MANAGER_SUCCESS)
+ ERROR("security_manager_app_inst_add_path %s failed", pathname);
return retcode(rc);
}
int secmgr_path_public_read_only(const char *pathname)
{
- return addpath(pathname, SECURITY_MANAGER_PATH_PUBLIC_RO);
+ return addpath(pathname, SECURITY_MANAGER_PATH_RO);
}
int secmgr_path_read_only(const char *pathname)
return addpath(pathname, SECURITY_MANAGER_PATH_RW);
}
+int secmgr_prepare_exec(const char *appid)
+{
+ return retcode(security_manager_prepare_app(appid));
+}
+