File: exec-tool.c

package info (click to toggle)
lomiri-push-service 0.100.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,912 kB
  • sloc: python: 936; ansic: 288; makefile: 96; sh: 61
file content (72 lines) | stat: -rw-r--r-- 1,817 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
 * Copyright (C) 2022 Guido Berhoerster <guido+ubports@berhoerster.name>
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 3, as published
 * by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranties of
 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
 * PURPOSE.  See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
/*
 * invoked by lomiri-app-launch in order to look up the unprivileged helper
 * of a click app
 */
#include <stdlib.h>

#include <glib.h>
#include <lomiri-app-launch.h>

#include "find-helper.h"

int
main(int argc, char *argv[])
{
	int		status = EXIT_FAILURE;
	const gchar	*app_id;
	gchar		*package = NULL;
	gchar		*app = NULL;
	GError		*error = NULL;
	gchar		*exec_value = NULL;

	/*
	 * application ID for which the unprivileged helper needs to be lloked
	 * up
	 */
	app_id = g_getenv("APP_ID");
	if (app_id == NULL) {
		g_critical("no application ID passed via APP_ID");
		goto out;
	}

	if (!lomiri_app_launch_app_id_parse(app_id, &package, &app, NULL)) {
		g_critical("invalid application ID: %s", app_id);
		goto out;
	}

	exec_value = find_helper(package, app, &error);
	if (exec_value == NULL) {
		g_critical("%s", error->message);
		g_error_free(error);
		goto out;
	}

	if (!lomiri_app_launch_helper_set_exec(exec_value, NULL)) {
		g_critical("failed to set exec line for untrusted helper tool");
		goto out;
	}

	status = EXIT_SUCCESS;

out:
	g_free(app);
	g_free(package);
	g_free(exec_value);

	exit(status);
}