diff options
author | netblue30 <netblue30@yahoo.com> | 2016-07-09 17:33:01 -0400 |
---|---|---|
committer | netblue30 <netblue30@yahoo.com> | 2016-07-09 17:33:01 -0400 |
commit | ab36d4527faf8eed995c62966fe35ca1062e212b (patch) | |
tree | 7e4a21593ebf3f77744eed36532518cd499cfc3f /src | |
parent | Merge pull request #624 from Fred-Barclay/mousetrap (diff) | |
download | firejail-ab36d4527faf8eed995c62966fe35ca1062e212b.tar.gz firejail-ab36d4527faf8eed995c62966fe35ca1062e212b.tar.zst firejail-ab36d4527faf8eed995c62966fe35ca1062e212b.zip |
removed --user
Diffstat (limited to 'src')
-rw-r--r-- | src/firejail/firejail.h | 3 | ||||
-rw-r--r-- | src/firejail/main.c | 1 | ||||
-rw-r--r-- | src/firejail/usage.c | 1 | ||||
-rw-r--r-- | src/firejail/user.c | 115 | ||||
-rw-r--r-- | src/man/firejail.txt | 8 |
5 files changed, 0 insertions, 128 deletions
diff --git a/src/firejail/firejail.h b/src/firejail/firejail.h index 590646f23..c18dacbbb 100644 --- a/src/firejail/firejail.h +++ b/src/firejail/firejail.h | |||
@@ -545,9 +545,6 @@ void fs_logger_print_log(pid_t pid); | |||
545 | // run_symlink.c | 545 | // run_symlink.c |
546 | void run_symlink(int argc, char **argv); | 546 | void run_symlink(int argc, char **argv); |
547 | 547 | ||
548 | // user.c | ||
549 | void check_user(int argc, char **argv); | ||
550 | |||
551 | // paths.c | 548 | // paths.c |
552 | char **build_paths(void); | 549 | char **build_paths(void); |
553 | 550 | ||
diff --git a/src/firejail/main.c b/src/firejail/main.c index a0225be15..35f825a07 100644 --- a/src/firejail/main.c +++ b/src/firejail/main.c | |||
@@ -900,7 +900,6 @@ int main(int argc, char **argv) { | |||
900 | else { | 900 | else { |
901 | // check --output option and execute it; | 901 | // check --output option and execute it; |
902 | check_output(argc, argv); // the function will not return if --output option was found | 902 | check_output(argc, argv); // the function will not return if --output option was found |
903 | check_user(argc, argv); // the function will not return if --user option was found | ||
904 | } | 903 | } |
905 | 904 | ||
906 | 905 | ||
diff --git a/src/firejail/usage.c b/src/firejail/usage.c index b67300618..6b7a666db 100644 --- a/src/firejail/usage.c +++ b/src/firejail/usage.c | |||
@@ -252,7 +252,6 @@ void usage(void) { | |||
252 | printf(" --tracelog - add a syslog message for every access to files or\n"); | 252 | printf(" --tracelog - add a syslog message for every access to files or\n"); |
253 | printf("\tdirectoires blacklisted by the security profile.\n\n"); | 253 | printf("\tdirectoires blacklisted by the security profile.\n\n"); |
254 | printf(" --tree - print a tree of all sandboxed processes.\n\n"); | 254 | printf(" --tree - print a tree of all sandboxed processes.\n\n"); |
255 | printf(" --user=new_user - switch the user before starting the sandbox.\n\n"); | ||
256 | printf(" --version - print program version and exit.\n\n"); | 255 | printf(" --version - print program version and exit.\n\n"); |
257 | #ifdef HAVE_WHITELIST | 256 | #ifdef HAVE_WHITELIST |
258 | printf(" --whitelist=dirname_or_filename - whitelist directory or file.\n\n"); | 257 | printf(" --whitelist=dirname_or_filename - whitelist directory or file.\n\n"); |
diff --git a/src/firejail/user.c b/src/firejail/user.c deleted file mode 100644 index a2f34392c..000000000 --- a/src/firejail/user.c +++ /dev/null | |||
@@ -1,115 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2014-2016 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 | #include "firejail.h" | ||
21 | #include <sys/types.h> | ||
22 | #include <sys/stat.h> | ||
23 | #include <unistd.h> | ||
24 | #include <grp.h> | ||
25 | #include <pwd.h> | ||
26 | |||
27 | |||
28 | void check_user(int argc, char **argv) { | ||
29 | EUID_ASSERT(); | ||
30 | int i; | ||
31 | char *user = NULL; | ||
32 | |||
33 | int found = 0; | ||
34 | for (i = 1; i < argc; i++) { | ||
35 | // check options | ||
36 | if (strcmp(argv[i], "--") == 0) | ||
37 | break; | ||
38 | if (strncmp(argv[i], "--", 2) != 0) | ||
39 | break; | ||
40 | |||
41 | // check user option | ||
42 | if (strncmp(argv[i], "--user=", 7) == 0) { | ||
43 | found = 1; | ||
44 | user = argv[i] + 7; | ||
45 | break; | ||
46 | } | ||
47 | } | ||
48 | if (!found) | ||
49 | return; | ||
50 | |||
51 | // check root | ||
52 | if (getuid() != 0) { | ||
53 | fprintf(stderr, "Error: you need to be root to use --user command line option\n"); | ||
54 | exit(1); | ||
55 | } | ||
56 | |||
57 | // switch user | ||
58 | struct passwd *pw = getpwnam(user); | ||
59 | if (!pw) { | ||
60 | fprintf(stderr, "Error: cannot find user %s\n", user); | ||
61 | exit(1); | ||
62 | } | ||
63 | |||
64 | printf("Switching to user %s, UID %d, GID %d\n", user, pw->pw_uid, pw->pw_gid); | ||
65 | int rv = initgroups(user, pw->pw_gid); | ||
66 | if (rv == -1) { | ||
67 | perror("initgroups"); | ||
68 | fprintf(stderr, "Error: cannot switch to user %s\n", user); | ||
69 | } | ||
70 | |||
71 | rv = setgid(pw->pw_gid); | ||
72 | if (rv == -1) { | ||
73 | perror("setgid"); | ||
74 | fprintf(stderr, "Error: cannot switch to user %s\n", user); | ||
75 | } | ||
76 | |||
77 | rv = setuid(pw->pw_uid); | ||
78 | if (rv == -1) { | ||
79 | perror("setuid"); | ||
80 | fprintf(stderr, "Error: cannot switch to user %s\n", user); | ||
81 | } | ||
82 | |||
83 | // build the new command line | ||
84 | int len = 0; | ||
85 | for (i = 0; i < argc; i++) { | ||
86 | len += strlen(argv[i]) + 1; // + ' ' | ||
87 | } | ||
88 | |||
89 | char *cmd = malloc(len + 1); // + '\0' | ||
90 | if (!cmd) | ||
91 | errExit("malloc"); | ||
92 | |||
93 | char *ptr = cmd; | ||
94 | int first = 1; | ||
95 | for (i = 0; i < argc; i++) { | ||
96 | if (strncmp(argv[i], "--user=", 7) == 0 && first) { | ||
97 | first = 0; | ||
98 | continue; | ||
99 | } | ||
100 | |||
101 | ptr += sprintf(ptr, "%s ", argv[i]); | ||
102 | } | ||
103 | |||
104 | // run command | ||
105 | char *a[4]; | ||
106 | a[0] = "/bin/bash"; | ||
107 | a[1] = "-c"; | ||
108 | a[2] = cmd; | ||
109 | a[3] = NULL; | ||
110 | |||
111 | execvp(a[0], a); | ||
112 | |||
113 | perror("execvp"); | ||
114 | exit(1); | ||
115 | } | ||
diff --git a/src/man/firejail.txt b/src/man/firejail.txt index 8d20cf36b..7c9cd98de 100644 --- a/src/man/firejail.txt +++ b/src/man/firejail.txt | |||
@@ -1485,15 +1485,7 @@ $ firejail \-\-tree | |||
1485 | 11969:netblue:firejail \-\-net=eth0 transmission-gtk | 1485 | 11969:netblue:firejail \-\-net=eth0 transmission-gtk |
1486 | .br | 1486 | .br |
1487 | 11970:netblue:transmission-gtk | 1487 | 11970:netblue:transmission-gtk |
1488 | .TP | ||
1489 | \fB\-\-user=new-user | ||
1490 | Switch the user before starting the sandbox. This command should be run as root. | ||
1491 | .br | ||
1492 | 1488 | ||
1493 | .br | ||
1494 | Example: | ||
1495 | .br | ||
1496 | # firejail \-\-user=www-data | ||
1497 | .TP | 1489 | .TP |
1498 | \fB\-\-version | 1490 | \fB\-\-version |
1499 | Print program version and exit. | 1491 | Print program version and exit. |