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.
30 #include "secmgr-wrap.h"
31 #include "utils-dir.h"
33 static int check_defined(const void *data, const char *name)
37 ERROR("widget has no defined '%s' (temporary constraints)", name);
42 static int check_valid_string(const char *value, const char *name)
47 if (check_defined(value, name))
52 if (!isalnum(c) && !strchr(".-_", c)) {
53 ERROR("forbidden char %c in '%s' -> '%s' (temporary constraints)", c, name, value);
62 static int check_temporary_constraints(const struct wgt_desc *desc)
64 int result = check_valid_string(desc->id, "id");
65 result |= check_valid_string(desc->version, "version");
66 result |= check_defined(desc->icons, "icon");
67 result |= check_defined(desc->content_src, "content");
70 if (desc->icons->next) {
71 ERROR("widget has more than one icon defined (temporary constraints)");
78 static int check_permissions(const char *name, int required)
80 if (permission_exists(name)) {
81 if (request_permission(name)) {
82 DEBUG("granted permission: %s", name);
83 } else if (required) {
84 ERROR("ungranted permission required: %s", name);
88 INFO("ungranted permission optional: %s", name);
94 static int check_widget(const struct wgt_desc *desc)
97 const struct wgt_desc_feature *feature;
99 result = check_temporary_constraints(desc);
100 feature = desc->features;
102 if (!check_permissions(feature->name, feature->required))
104 feature = feature->next;
109 static int move_widget(const char *root, const struct wgt_desc *desc, int force)
111 char newdir[PATH_MAX];
114 rc = snprintf(newdir, sizeof newdir, "%s/%s/%s", root, desc->id, desc->version);
115 if (rc >= sizeof newdir) {
116 ERROR("path to long in move_widget");
121 return move_workdir(newdir, 1, force);
124 static int install_icon(const struct wgt_desc *desc)
127 char target[PATH_MAX];
130 create_directory(FWK_ICON_DIR, 0755, 1);
131 rc = snprintf(link, sizeof link, "%s/%s@%s", FWK_ICON_DIR, desc->id, desc->version);
132 if (rc >= sizeof link) {
133 ERROR("link to long in install_icon");
138 rc = snprintf(target, sizeof target, "%s/%s", workdir, desc->icons->src);
139 if (rc >= sizeof target) {
140 ERROR("target to long in install_icon");
146 rc = symlink(target, link);
148 ERROR("can't create link %s -> %s", link, target);
152 static int install_security(const struct wgt_desc *desc)
154 char path[PATH_MAX], *head;
155 const char *icon, *perm;
156 int rc, len, lic, lf;
160 rc = secmgr_init(desc->id);
164 rc = secmgr_path_public_read_only(workdir);
168 /* instal the files */
169 head = stpcpy(path, workdir);
170 assert(sizeof path > (head - path));
171 len = (int)(sizeof path - (head - path));
173 ERROR("root path too long in install_security");
174 errno = ENAMETOOLONG;
179 icon = desc->icons->src;
180 lic = (int)strlen(icon);
184 f = file_of_index(i++);
185 lf = (int)strlen(f->name);
187 ERROR("path too long in install_security");
188 errno = ENAMETOOLONG;
191 strcpy(head, f->name);
192 if (lf <= lic && !memcmp(f->name, icon, lf) && (!f->name[lf] || f->name[lf] == '/'))
193 rc = secmgr_path_public_read_only(path);
195 rc = secmgr_path_read_only(path);
200 /* install the permissions */
201 perm = first_usable_permission();
203 rc = secmgr_permit(perm);
206 perm = next_usable_permission();
209 rc = secmgr_install();
217 /* install the widget of the file */
218 void install_widget(const char *wgtfile, const char *root, int force)
220 struct wgt_info *ifo;
221 const struct wgt_desc *desc;
223 NOTICE("-- INSTALLING widget %s --", wgtfile);
226 create_directory(root, 0755, 1);
227 if (make_workdir_base(root, "TMP", 0)) {
228 ERROR("failed to create a working directory");
232 if (zread(wgtfile, 0))
235 if (check_all_signatures())
238 ifo = wgt_info_createat(workdirfd, NULL, 1, 1, 1);
242 desc = wgt_info_desc(ifo);
243 if (check_widget(desc))
246 if (move_widget(root, desc, force))
249 if (install_icon(desc))
252 if (install_security(desc))