mirror of
https://github.com/netblue30/firejail.git
synced 2026-05-15 06:06:02 -06:00
cleanup
This commit is contained in:
parent
1631170f02
commit
d5d0236c00
4 changed files with 0 additions and 152 deletions
2
gcov.sh
2
gcov.sh
|
|
@ -41,8 +41,6 @@ lcov -q --capture -d src/firejail -d src/firemon \
|
|||
make test-root
|
||||
generate
|
||||
sleep 2
|
||||
exit
|
||||
|
||||
|
||||
make test-network
|
||||
generate
|
||||
|
|
|
|||
|
|
@ -93,59 +93,3 @@ unsigned int count_paths(void) {
|
|||
assert(path_cnt);
|
||||
return path_cnt;
|
||||
}
|
||||
|
||||
// Return 1 if PROGRAM exists in $PATH and is runnable by the
|
||||
// invoking user (not root).
|
||||
// In other words, tests "will execvp(PROGRAM, ...) succeed?"
|
||||
int program_in_path(const char *program) {
|
||||
assert(program && *program);
|
||||
assert(strchr(program, '/') == 0);
|
||||
assert(strcmp(program, ".") != 0);
|
||||
assert(strcmp(program, "..") != 0);
|
||||
|
||||
if (!paths)
|
||||
init_paths();
|
||||
assert(paths);
|
||||
|
||||
size_t proglen = strlen(program);
|
||||
char *scratch = malloc(longest_path_elt + proglen + 2);
|
||||
if (!scratch)
|
||||
errExit("malloc");
|
||||
|
||||
int found = 0;
|
||||
size_t dlen;
|
||||
char **p;
|
||||
for (p = paths; *p; p++) {
|
||||
char *dir = *p;
|
||||
dlen = strlen(dir);
|
||||
|
||||
// init_paths should ensure that this is true; as long
|
||||
// as it is true, 'scratch' has enough space for "$p/$program".
|
||||
assert(dlen <= longest_path_elt);
|
||||
|
||||
memcpy(scratch, dir, dlen);
|
||||
scratch[dlen++] = '/';
|
||||
|
||||
// copy proglen+1 bytes to copy the nul terminator at
|
||||
// the end of 'program'.
|
||||
memcpy(scratch + dlen, program, proglen+1);
|
||||
|
||||
if (access(scratch, X_OK) == 0) {
|
||||
// must also verify that this is a regular file
|
||||
// ('x' permission means something different for directories).
|
||||
// exec follows symlinks, so use stat, not lstat.
|
||||
struct stat st;
|
||||
if (stat(scratch, &st)) {
|
||||
perror(scratch);
|
||||
exit(1);
|
||||
}
|
||||
if (S_ISREG(st.st_mode)) {
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
free(scratch);
|
||||
return found;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -569,19 +569,6 @@ char *clean_pathname(const char *path) {
|
|||
return rv;
|
||||
}
|
||||
|
||||
void check_unsigned(const char *str, const char *msg) {
|
||||
EUID_ASSERT();
|
||||
const char *ptr = str;
|
||||
while (*ptr != ' ' && *ptr != '\t' && *ptr != '\0') {
|
||||
if (!isdigit(*ptr)) {
|
||||
fprintf(stderr, "%s %s\n", msg, str);
|
||||
exit(1);
|
||||
}
|
||||
ptr++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#define BUFLEN 4096
|
||||
// find the first child for this parent; return 1 if error
|
||||
int find_child(pid_t parent, pid_t *child) {
|
||||
|
|
@ -865,86 +852,6 @@ uid_t get_group_id(const char *group) {
|
|||
}
|
||||
|
||||
|
||||
static int remove_callback(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf) {
|
||||
(void) sb;
|
||||
(void) typeflag;
|
||||
(void) ftwbuf;
|
||||
assert(fpath);
|
||||
|
||||
if (strcmp(fpath, ".") == 0)
|
||||
return 0;
|
||||
|
||||
if (remove(fpath)) { // removes the link not the actual file
|
||||
perror("remove");
|
||||
fprintf(stderr, "Error: cannot remove file from user .firejail directory: %s\n", fpath);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int remove_overlay_directory(void) {
|
||||
EUID_ASSERT();
|
||||
struct stat s;
|
||||
sleep(1);
|
||||
|
||||
char *path;
|
||||
if (asprintf(&path, "%s/.firejail", cfg.homedir) == -1)
|
||||
errExit("asprintf");
|
||||
|
||||
if (lstat(path, &s) == 0) {
|
||||
// deal with obvious problems such as symlinks and root ownership
|
||||
if (!S_ISDIR(s.st_mode)) {
|
||||
if (S_ISLNK(s.st_mode))
|
||||
fprintf(stderr, "Error: %s is a symbolic link\n", path);
|
||||
else
|
||||
fprintf(stderr, "Error: %s is not a directory\n", path);
|
||||
exit(1);
|
||||
}
|
||||
if (s.st_uid != getuid()) {
|
||||
fprintf(stderr, "Error: %s is not owned by the current user\n", path);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
pid_t child = fork();
|
||||
if (child < 0)
|
||||
errExit("fork");
|
||||
if (child == 0) {
|
||||
// open ~/.firejail, fails if there is any symlink
|
||||
int fd = safe_fd(path, O_PATH|O_DIRECTORY|O_NOFOLLOW|O_CLOEXEC);
|
||||
if (fd == -1)
|
||||
errExit("safe_fd");
|
||||
// chdir to ~/.firejail
|
||||
if (fchdir(fd) == -1)
|
||||
errExit("fchdir");
|
||||
close(fd);
|
||||
|
||||
EUID_ROOT();
|
||||
// FTW_PHYS - do not follow symbolic links
|
||||
if (nftw(".", remove_callback, 64, FTW_DEPTH | FTW_PHYS) == -1)
|
||||
errExit("nftw");
|
||||
|
||||
EUID_USER();
|
||||
// remove ~/.firejail
|
||||
if (rmdir(path) == -1)
|
||||
errExit("rmdir");
|
||||
#ifdef HAVE_GCOV
|
||||
__gcov_flush();
|
||||
#endif
|
||||
_exit(0);
|
||||
}
|
||||
// wait for the child to finish
|
||||
waitpid(child, NULL, 0);
|
||||
// check if ~/.firejail was deleted
|
||||
if (stat(path, &s) == -1)
|
||||
return 0;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void flush_stdin(void) {
|
||||
if (isatty(STDIN_FILENO)) {
|
||||
int cnt = 0;
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ rm -fr ~/_firejail_test_*
|
|||
echo "TESTING: /sys/fs access (test/fs/sys_fs.exp)"
|
||||
./sys_fs.exp
|
||||
|
||||
echo "TESTING: kmsg access (test/fs/kmsg.exp)"
|
||||
if [ -c /dev/kmsg ]; then
|
||||
echo "TESTING: kmsg access (test/fs/kmsg.exp)"
|
||||
./kmsg.exp
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue