Debian Codegraph @

exec-tool/exec-tool.c

raw
1 /*
2 * Copyright (C) 2022 Guido Berhoerster <[email protected]>
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16 /*
17 * invoked by lomiri-app-launch in order to look up the unprivileged helper
18 * of a click app
19 */
20 #include <stdlib.h>
21
22 #include <glib.h>
23 #include <lomiri-app-launch.h>
24
25 #include "find-helper.h"
26
27 int
28 main(int argc, char *argv[])
29 {
30 int status = EXIT_FAILURE;
31 const gchar *app_id;
32 gchar *package = NULL;
33 gchar *app = NULL;
34 GError *error = NULL;
35 gchar *exec_value = NULL;
36
37 /*
38 * application ID for which the unprivileged helper needs to be lloked
39 * up
40 */
41 app_id = g_getenv("APP_ID");
42 if (app_id == NULL) {
43 g_critical("no application ID passed via APP_ID");
44 goto out;
45 }
46
47 if (!lomiri_app_launch_app_id_parse(app_id, &package, &app, NULL)) {
48 g_critical("invalid application ID: %s", app_id);
49 goto out;
50 }
51
52 exec_value = find_helper(package, app, &error);
53 if (exec_value == NULL) {
54 g_critical("%s", error->message);
55 g_error_free(error);
56 goto out;
57 }
58
59 if (!lomiri_app_launch_helper_set_exec(exec_value, NULL)) {
60 g_critical("failed to set exec line for untrusted helper tool");
61 goto out;
62 }
63
64 status = EXIT_SUCCESS;
65
66 out:
67 g_free(app);
68 g_free(package);
69 g_free(exec_value);
70
71 exit(status);
72 }