4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
8 http://www.apache.org/licenses/LICENSE-2.0
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
28 #include "secmgr-wrap.h"
30 static int check_defined(const void *data, const char *name)
34 syslog(LOG_ERR, "widget has no defined '%s' (temporary constraints)", name);
39 static int check_valid_string(const char *value, const char *name)
44 if (check_defined(value, name))
49 if (!isalnum(c) && !strchr(".-_", c)) {
50 syslog(LOG_ERR, "forbidden char %c in '%s' -> '%s' (temporary constraints)", c, name, value);
59 static int check_temporary_constraints(const struct wgt_desc *desc)
61 int result = check_valid_string(desc->id, "id");
62 result |= check_valid_string(desc->version, "version");
63 result |= check_defined(desc->icons, "icon");
64 result |= check_defined(desc->content_src, "content");
67 if (desc->icons->next) {
68 syslog(LOG_ERR, "widget has more than one icon defined (temporary constraints)");
75 static int check_permissions(const char *name, int required)
77 if (permission_exists(name)) {
78 if (request_permission(name)) {
79 debug("granted permission: %s", name);
80 } else if (required) {
81 syslog(LOG_ERR, "ungranted permission required: %s", name);
85 notice("ungranted permission optional: %s", name);
91 static int check_widget(const struct wgt_desc *desc)
94 const struct wgt_desc_feature *feature;
96 result = check_temporary_constraints(desc);
97 feature = desc->features;
99 if (!check_permissions(feature->name, feature->required))
101 feature = feature->next;
106 static int move_widget(const char *root, const struct wgt_desc *desc, int force)
108 char newdir[PATH_MAX];
111 rc = snprintf(newdir, sizeof newdir, "%s/%s/%s", root, desc->id, desc->version);
112 if (rc >= sizeof newdir) {
113 syslog(LOG_ERR, "path to long: %s/%s/%s", root, desc->id, desc->version);
118 return move_workdir(newdir, 1, force);
121 static int install_security(struct wgt_info *ifo)
125 rc = secmgr_init(wgt_info_desc(ifo)->
128 /* install the widget of the file */
129 void install_widget(const char *wgtfile, const char *root, int force)
131 struct wgt_info *ifo;
132 const struct wgt_desc *desc;
134 notice("-- INSTALLING widget %s --", wgtfile);
137 if (make_workdir_base(root, "UNPACK", 0)) {
138 syslog(LOG_ERR, "failed to create a working directory");
142 if (zread(wgtfile, 0))
145 if (check_all_signatures())
148 ifo = wgt_info_createat(workdirfd, NULL, 1, 1, 1);
152 desc = wgt_info_desc(ifo);
153 if (check_widget(desc))
156 if (move_widget(root, desc, force))