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 static int has_permission(const char *name)
134 char **p = permissions;
137 if (0 == strcmp(*p, name))
145 static void add_permissions(const char *list)
150 static const char separators[] = " \t\n\r,";
153 iter = list + strspn(list, separators);
156 iter += strcspn(iter, separators);
157 iter += strspn(iter, separators);
168 ps = realloc(permissions, (1 + on + n) * sizeof * ps);
170 syslog(LOG_ERR, "Can't allocate memory for permissions");
177 iter = list + strspn(list, separators);
179 n = strcspn(iter, separators);
180 p = strndup(iter, n);
182 syslog(LOG_ERR, "Can't allocate permission");
185 if (has_permission(p))
192 iter += strspn(iter, separators);
196 static struct wgt *wgt_at_workdir()
207 syslog(LOG_ERR, "failed to allocate wgt");
212 rc = wgt_connectat(wgt, wfd, NULL);
214 syslog(LOG_ERR, "failed to connect wgt to workdir");
224 static int check_and_place()
227 struct wgt_info *ifo;
229 wgt = wgt_at_workdir();
233 ifo = wgt_info_get(wgt, 1, 1, 1);
238 wgt_info_dump(ifo, 1, "");
244 /* install the widget of the file */
245 static void install(const char *wgtfile)
247 notice("-- INSTALLING widget %s --", wgtfile);
250 if (make_workdir_base(root, "UNPACK", 0)) {
251 syslog(LOG_ERR, "failed to create a working directory");
255 if (enter_workdir(0))
258 if (zread(wgtfile, 0))
261 if (check_all_signatures())
264 if (check_and_place())