aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt5
-rw-r--r--doc/writing-config.xml.md5
-rw-r--r--src/wgtpkg-install.c42
3 files changed, 35 insertions, 17 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9ade5bc..0b643c8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -42,8 +42,7 @@ setc(afm_confdir "${CMAKE_INSTALL_FULL_SYSCONFDIR}/${afm_name}")
setc(afm_datadir "${CMAKE_INSTALL_FULL_DATADIR}/${afm_name}")
setc(afm_appdir "${afm_datadir}/applications")
setc(afm_icondir "${afm_datadir}/icons")
-setc(afm_prefix "urn:agl:")
-setc(afm_prefix_permission "${afm_prefix}perm:")
+setc(afm_prefix "urn:AGL:")
setc(afm_prefix_binding "${afm_prefix}binding:")
setc(afm_user_appdir "app-data")
setc(wgtpkg_trusted_cert_dir "${afm_confdir}/certs")
@@ -53,7 +52,7 @@ macro(defstr name value)
endmacro(defstr)
defstr(FWK_CONFIG_DIR "${afm_confdir}")
-defstr(FWK_PREFIX_PERMISSION "${afm_prefix_permission}")
+defstr(FWK_PREFIX "${afm_prefix}")
defstr(FWK_PREFIX_BINDING "${afm_prefix_binding}")
defstr(FWK_ICON_DIR "${afm_icondir}")
defstr(FWK_APP_DIR "${afm_appdir}")
diff --git a/doc/writing-config.xml.md b/doc/writing-config.xml.md
index 54172ff..9010112 100644
--- a/doc/writing-config.xml.md
+++ b/doc/writing-config.xml.md
@@ -190,8 +190,9 @@ Each required permission must be explicited using a <param> entry.
The value is either:
-- required: the permission is really needed.
-- optional: the permission isn't mandatory
+- required: the permission is mandatorily needed except if the feature
+isn't required (required="false") and in that case it is optional.
+- optional: the permission is optional
### feature name="urn:AGL:defined-permissions"
diff --git a/src/wgtpkg-install.c b/src/wgtpkg-install.c
index c4e70e3..b5f0a40 100644
--- a/src/wgtpkg-install.c
+++ b/src/wgtpkg-install.c
@@ -38,6 +38,10 @@
#include "secmgr-wrap.h"
#include "utils-dir.h"
+static const char permission_required[] = "required";
+static const char permission_optional[] = "optional";
+static const char feature_required_permissions[] = FWK_PREFIX "required-permissions";
+
static int check_defined(const void *data, const char *name)
{
if (data)
@@ -89,20 +93,34 @@ static int check_temporary_constraints(const struct wgt_desc *desc)
return 0;
}
-static int check_permissions(const char *name, int required)
+static int set_required_permissions(struct wgt_desc_param *params, int required)
{
- if (permission_exists(name)) {
- if (request_permission(name)) {
- DEBUG("granted permission: %s", name);
- } else if (required) {
- ERROR("ungranted permission required: %s", name);
+ int optional;
+
+ while (params) {
+ /* check the value */
+ if (!strcmp(params->value, permission_required))
+ optional = !required;
+ else if (!strcmp(params->value, permission_optional))
+ optional = 1;
+ else {
+ ERROR("unexpected parameter value: %s found for %s", params->value, params->name);
errno = EPERM;
- return 0;
+ return -1;
+ }
+ /* set the permission */
+ if (request_permission(params->name)) {
+ DEBUG("granted permission: %s", params->name);
+ } else if (optional) {
+ INFO("optional permission ungranted: %s", params->name);
} else {
- INFO("ungranted permission optional: %s", name);
+ ERROR("ungranted permission required: %s", params->name);
+ errno = EPERM;
+ return -1;
}
+ params = params->next;
}
- return 1;
+ return 0;
}
static int check_widget(const struct wgt_desc *desc)
@@ -112,9 +130,9 @@ static int check_widget(const struct wgt_desc *desc)
result = check_temporary_constraints(desc);
feature = desc->features;
- while(feature) {
- if (!check_permissions(feature->name, feature->required))
- result = -1;
+ while(result >= 0 && feature) {
+ if (!strcmp(feature->name, feature_required_permissions))
+ result = set_required_permissions(feature->params, feature->required);
feature = feature->next;
}
return result;