aboutsummaryrefslogtreecommitdiffstats
path: root/src/firecfg/util.c
diff options
context:
space:
mode:
authorLibravatar netblue30 <netblue30@yahoo.com>2017-09-25 07:38:01 -0400
committerLibravatar netblue30 <netblue30@yahoo.com>2017-09-25 07:38:01 -0400
commita6341b904c08b1feb51e264ab487d1f125222a10 (patch)
tree35ea50b8c8e561b710272a0e8ae9418541a32925 /src/firecfg/util.c
parentRemove whitelist from pinta (diff)
downloadfirejail-a6341b904c08b1feb51e264ab487d1f125222a10.tar.gz
firejail-a6341b904c08b1feb51e264ab487d1f125222a10.tar.zst
firejail-a6341b904c08b1feb51e264ab487d1f125222a10.zip
disable DBus activation in firecfg
Diffstat (limited to 'src/firecfg/util.c')
-rw-r--r--src/firecfg/util.c86
1 files changed, 86 insertions, 0 deletions
diff --git a/src/firecfg/util.c b/src/firecfg/util.c
new file mode 100644
index 000000000..4520e75e8
--- /dev/null
+++ b/src/firecfg/util.c
@@ -0,0 +1,86 @@
1/*
2 * Copyright (C) 2014-2017 Firejail Authors
3 *
4 * This file is part of firejail project
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19*/
20
21#include "firecfg.h"
22
23// return 1 if the program is found
24static int find(const char *program, const char *directory) {
25 int retval = 0;
26
27 char *fname;
28 if (asprintf(&fname, "/%s/%s", directory, program) == -1)
29 errExit("asprintf");
30
31 struct stat s;
32 if (stat(fname, &s) == 0) {
33 if (arg_debug)
34 printf("found %s in directory %s\n", program, directory);
35 retval = 1;
36 }
37
38 free(fname);
39 return retval;
40}
41
42
43// return 1 if program is installed on the system
44int which(const char *program) {
45 // check some well-known paths
46 if (find(program, "/bin") || find(program, "/usr/bin") ||
47 find(program, "/sbin") || find(program, "/usr/sbin") ||
48 find(program, "/usr/games"))
49 return 1;
50
51 // check environment
52 char *path1 = getenv("PATH");
53 if (path1) {
54 char *path2 = strdup(path1);
55 if (!path2)
56 errExit("strdup");
57
58 // use path2 to count the entries
59 char *ptr = strtok(path2, ":");
60 while (ptr) {
61 if (find(program, ptr)) {
62 free(path2);
63 return 1;
64 }
65 ptr = strtok(NULL, ":");
66 }
67 free(path2);
68 }
69
70 return 0;
71}
72
73// return 1 if the file is a link
74int is_link(const char *fname) {
75 assert(fname);
76 if (*fname == '\0')
77 return 0;
78
79 struct stat s;
80 if (lstat(fname, &s) == 0) {
81 if (S_ISLNK(s.st_mode))
82 return 1;
83 }
84
85 return 0;
86}