Skip to content

Commit

Permalink
fcopy part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
netblue30 committed Nov 16, 2016
1 parent edcd62d commit 98159c0
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 340 deletions.
28 changes: 17 additions & 11 deletions gcov.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
#!/bin/bash

gcov_init() {
USER=`whoami`
firejail --help
firemon --help
/usr/lib/firejail/fnet --help
/usr/lib/firejail/fseccomp --help
/usr/lib/firejail/ftee --help
/usr/lib/firejail/fcopy --help
firecfg --help
sudo chown $USER:$USER `find .`
}

generate() {
lcov --capture -d src/firejail -d src/firemon -d src/fseccomp -d src/fnet -d src/ftee -d src/lib -d src/firecfg --output-file gcov-file
lcov --capture -d src/firejail -d src/firemon -d src/fcopy -d src/fseccomp -d src/fnet -d src/ftee -d src/lib -d src/firecfg --output-file gcov-file
rm -fr gcov-dir
genhtml gcov-file --output-directory gcov-dir
}

# init
USER=`whoami`
firejail --help
firemon --help
/usr/lib/firejail/fnet --help
/usr/lib/firejail/fseccomp --help
/usr/lib/firejail/ftee --help
/usr/lib/firejail/fcopy --help
firecfg --help
sudo chown $USER:$USER `find .`
gcov_init
generate
echo "press any key to continue, or Ctrl-C to exit"
read text


# running tests
make test-root
Expand Down
36 changes: 15 additions & 21 deletions src/fcopy/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,16 @@ static int fs_copydir(const char *infname, const struct stat *st, int ftype, str
if (size_limit_reached)
return 0;


char *outfname;
if (asprintf(&outfname, "%s%s", outpath, infname + strlen(inpath)) == -1)
errExit("asprintf");

//printf("outpaht %s\n", outpath);
//printf("inpath %s\n", inpath);
//printf("infname %s\n", infname);
//printf("outfname %s\n\n", outfname);

// don't copy it if we already have the file
struct stat s;
if (stat(outfname, &s) == 0) {
Expand Down Expand Up @@ -265,7 +271,7 @@ static void duplicate_link(const char *src, const char *dest, struct stat *s) {
static void usage(void) {
printf("Usage: fcopy src dest\n");
printf("Copy src file in dest directory. If src is a directory, copy all the files in\n");
printf("src recoursively\n");
printf("src recoursively. If the destination directory does not exist, it will be created.\n");
}

int main(int argc, char **argv) {
Expand All @@ -276,25 +282,16 @@ int i;
for (i = 0; i < argc; i++)
printf("*%s* ", argv[i]);
printf("\n");
}
#endif
}
#endif
if (argc != 3) {
fprintf(stderr, "Error fcopy: files missing\n");
usage();
exit(1);
}

int i;
int index = 1;
for (i = 1; i < (argc - 2); i++) {
if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") ==0) {
usage();
return 0;
}
}

// check the two files; remove ending /
char *src = argv[index];
char *src = argv[1];
int len = strlen(src);
if (src[len - 1] == '/')
src[len - 1] = '\0';
Expand All @@ -303,7 +300,7 @@ printf("\n");
exit(1);
}

char *dest = argv[index + 1];
char *dest = argv[2];
len = strlen(dest);
if (dest[len - 1] == '/')
dest[len - 1] = '\0';
Expand All @@ -313,14 +310,11 @@ printf("\n");
}


// the destination should be a directory; remove ending /
// the destination should be a directory;
struct stat s;
if (stat(dest, &s) == -1) {
fprintf(stderr, "Error fcopy: cannot find destination directory\n");
exit(1);
}
if (S_ISDIR(s.st_mode) == -1) {
fprintf(stderr, "Error fcopy: the destination should be a directory\n");
if (stat(dest, &s) == -1 ||
!S_ISDIR(s.st_mode)) {
fprintf(stderr, "Error fcopy: invalid destination directory\n");
exit(1);
}

Expand Down
4 changes: 1 addition & 3 deletions src/firejail/firejail.h
Original file line number Diff line number Diff line change
Expand Up @@ -490,8 +490,6 @@ void fs_private_template(void);
void fs_check_private_dir(void);
// check new private template home directory (--private-template= option) exit if it fails
void fs_check_private_template(void);
// check directory list specified by user (--private-home option) - exit if it fails
void fs_check_home_list(void);
void fs_private_home_list(void);


Expand Down Expand Up @@ -557,7 +555,6 @@ void network_del_run_file(pid_t pid);
void network_set_run_file(pid_t pid);

// fs_etc.c
void fs_check_etc_list(void);
void fs_private_etc_list(void);

// no_sandbox.c
Expand Down Expand Up @@ -681,6 +678,7 @@ void build_cmdline(char **command_line, char **window_title, int argc, char **ar
#define PATH_FNET (LIBDIR "/firejail/fnet")
#define PATH_FIREMON (PREFIX "/bin/firemon")
#define PATH_FSECCOMP (LIBDIR "/firejail/fseccomp")
#define PATH_FCOPY (LIBDIR "/firejail/fcopy")
// bitmapped filters for sbox_run
#define SBOX_ROOT (1 << 0) // run the sandbox as root
#define SBOX_USER (1 << 1) // run the sandbox as a regular user
Expand Down
31 changes: 0 additions & 31 deletions src/firejail/fs_etc.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,37 +62,6 @@ static int check_dir_or_file(const char *name) {
exit(1);
}

void fs_check_etc_list(void) {
EUID_ASSERT();
if (strstr(cfg.etc_private_keep, "..")) {
fprintf(stderr, "Error: invalid private etc list\n");
exit(1);
}

char *dlist = strdup(cfg.etc_private_keep);
if (!dlist)
errExit("strdup");

// build a new list only with the files found
char *newlist = malloc(strlen(cfg.etc_private_keep) + 1);
if (!newlist)
errExit("malloc");
*newlist = '\0';

char *ptr = strtok(dlist, ",");
if (check_dir_or_file(ptr))
strcat(newlist, ptr);
while ((ptr = strtok(NULL, ",")) != NULL) {
if (check_dir_or_file(ptr)) {
strcat(newlist, ",");
strcat(newlist, ptr);
}
}
cfg.etc_private_keep = newlist;

free(dlist);
}

static void duplicate(char *fname) {
// copy the file
if (arg_debug)
Expand Down

0 comments on commit 98159c0

Please sign in to comment.