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.
17 #define _BSD_SOURCE /* see readdir */
34 static const char appname[] = "wgtpkg-install";
35 static const char *root;
36 static char **permissions = NULL;
39 static void install(const char *wgtfile);
40 static void add_permissions(const char *list);
45 "usage: %s [-f] [-q] [-v] [-p list] rootdir wgtfile...\n"
47 " rootdir the root directory for installing\n"
48 " -p list a list of comma separated permissions to allow\n"
49 " -f force overwriting\n"
57 static struct option options[] = {
58 { "permissions", required_argument, NULL, 'p' },
59 { "force", no_argument, NULL, 'f' },
60 { "help", no_argument, NULL, 'h' },
61 { "quiet", no_argument, NULL, 'q' },
62 { "verbose", no_argument, NULL, 'v' },
66 /* install the widgets of the list */
67 int main(int ac, char **av)
72 openlog(appname, LOG_PERROR, LOG_AUTH);
78 i = getopt_long(ac, av, "hfqvp:", options, NULL);
96 add_permissions(optarg);
99 syslog(LOG_ERR, "missing argument value");
102 syslog(LOG_ERR, "unrecognized option");
109 syslog(LOG_ERR, "arguments are missing");
113 /* canonic names for files */
115 for (i = 0 ; av[i] != NULL ; i++) {
116 wpath = realpath(av[i], NULL);
118 syslog(LOG_ERR, "error while getting realpath of %dth widget: %s", i+1, av[i]);
125 /* install widgets */
132 /* checks if the permission 'name' is granted */
133 static int has_permission(const char *name)
135 char **p = permissions;
138 if (0 == strcmp(*p, name))
146 /* add permissions granted for installation */
147 static void add_permissions(const char *list)
152 static const char separators[] = " \t\n\r,";
155 iter = list + strspn(list, separators);
158 iter += strcspn(iter, separators);
159 iter += strspn(iter, separators);
170 ps = realloc(permissions, (1 + on + n) * sizeof * ps);
172 syslog(LOG_ERR, "Can't allocate memory for permissions");
179 iter = list + strspn(list, separators);
181 n = strcspn(iter, separators);
182 p = strndup(iter, n);
184 syslog(LOG_ERR, "Can't allocate permission");
187 if (has_permission(p))
194 iter += strspn(iter, separators);
199 static struct wgt *wgt_at_workdir()
210 syslog(LOG_ERR, "failed to allocate wgt");
215 rc = wgt_connectat(wgt, wfd, NULL);
217 syslog(LOG_ERR, "failed to connect wgt to workdir");
227 static int check_and_place()
230 struct wgt_info *ifo;
232 wgt = wgt_at_workdir();
236 ifo = wgt_info_get(wgt, 1, 1, 1);
241 wgt_info_dump(ifo, 1, "");
247 /* install the widget of the file */
248 static void install(const char *wgtfile)
250 notice("-- INSTALLING widget %s --", wgtfile);
253 if (make_workdir_base(root, "UNPACK", 0)) {
254 syslog(LOG_ERR, "failed to create a working directory");
258 if (enter_workdir(0))
261 if (zread(wgtfile, 0))
264 if (check_all_signatures())
267 if (check_and_place())