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.
29 #include "secmgr-wrap.h"
30 #include "utils-dir.h"
32 static int check_defined(const void *data, const char *name)
36 ERROR("widget has no defined '%s' (temporary constraints)", name);
41 static int check_valid_string(const char *value, const char *name)
46 if (check_defined(value, name))
51 if (!isalnum(c) && !strchr(".-_", c)) {
52 ERROR("forbidden char %c in '%s' -> '%s' (temporary constraints)", c, name, value);
61 static int check_temporary_constraints(const struct wgt_desc *desc)
63 int result = check_valid_string(desc->id, "id");
64 result |= check_valid_string(desc->version, "version");
65 result |= check_defined(desc->icons, "icon");
66 result |= check_defined(desc->content_src, "content");
69 if (desc->icons->next) {
70 ERROR("widget has more than one icon defined (temporary constraints)");
77 static int check_permissions(const char *name, int required)
79 if (permission_exists(name)) {
80 if (request_permission(name)) {
81 DEBUG("granted permission: %s", name);
82 } else if (required) {
83 ERROR("ungranted permission required: %s", name);
87 INFO("ungranted permission optional: %s", name);
93 static int check_widget(const struct wgt_desc *desc)
96 const struct wgt_desc_feature *feature;
98 result = check_temporary_constraints(desc);
99 feature = desc->features;
101 if (!check_permissions(feature->name, feature->required))
103 feature = feature->next;
108 static int move_widget(const char *root, const struct wgt_desc *desc, int force)
110 char newdir[PATH_MAX];
113 rc = snprintf(newdir, sizeof newdir, "%s/%s/%s", root, desc->id, desc->version);
114 if (rc >= sizeof newdir) {
115 ERROR("path to long in move_widget");
120 return move_workdir(newdir, 1, force);
123 static int install_icon(const struct wgt_desc *desc)
126 char target[PATH_MAX];
129 create_directory(FWK_ICON_DIR, 0755, 1);
130 rc = snprintf(link, sizeof link, "%s/%s@%s", FWK_ICON_DIR, desc->id, desc->version);
131 if (rc >= sizeof link) {
132 ERROR("link to long in install_icon");
137 rc = snprintf(target, sizeof target, "%s/%s", workdir, desc->icons->src);
138 if (rc >= sizeof target) {
139 ERROR("target to long in install_icon");
145 rc = symlink(target, link);
147 ERROR("can't create link %s -> %s", link, target);
151 static int install_security(const struct wgt_desc *desc)
153 char path[PATH_MAX], *head;
154 const char *icon, *perm;
155 int rc, len, lic, lf;
159 rc = secmgr_init(desc->id);
163 rc = secmgr_path_public_read_only(workdir);
167 /* instal the files */
168 head = stpcpy(path, workdir);
169 assert(sizeof path > (head - path));
170 len = (int)(sizeof path - (head - path));
172 ERROR("root path too long in install_security");
173 errno = ENAMETOOLONG;
178 icon = desc->icons->src;
179 lic = (int)strlen(icon);
183 f = file_of_index(i++);
184 lf = (int)strlen(f->name);
186 ERROR("path too long in install_security");
187 errno = ENAMETOOLONG;
190 strcpy(head, f->name);
191 if (lf <= lic && !memcmp(f->name, icon, lf) && (!f->name[lf] || f->name[lf] == '/'))
192 rc = secmgr_path_public_read_only(path);
194 rc = secmgr_path_read_only(path);
199 /* install the permissions */
200 perm = first_usable_permission();
202 rc = secmgr_permit(perm);
205 perm = next_usable_permission();
208 rc = secmgr_install();
216 /* install the widget of the file */
217 void install_widget(const char *wgtfile, const char *root, int force)
219 struct wgt_info *ifo;
220 const struct wgt_desc *desc;
222 NOTICE("-- INSTALLING widget %s --", wgtfile);
225 create_directory(root, 0755, 1);
226 if (make_workdir_base(root, "TMP", 0)) {
227 ERROR("failed to create a working directory");
231 if (zread(wgtfile, 0))
234 if (check_all_signatures())
237 ifo = wgt_info_createat(workdirfd, NULL, 1, 1, 1);
241 desc = wgt_info_desc(ifo);
242 if (check_widget(desc))
245 if (move_widget(root, desc, force))
248 if (install_icon(desc))
251 if (install_security(desc))