Commit 5ff53a2c authored by netblue30's avatar netblue30

testing

parent ad14d091
......@@ -31,6 +31,11 @@
static char *devloop = NULL; // device file
static char *mntdir = NULL; // mount point in /tmp directory
static void err_loop(void) {
fprintf(stderr, "Error: cannot configure loopback device\n");
exit(1);
}
void appimage_set(const char *appimage) {
assert(appimage);
assert(devloop == NULL); // don't call this twice!
......@@ -61,35 +66,27 @@ void appimage_set(const char *appimage) {
// find or allocate a free loop device to use
EUID_ROOT();
int cfd = open("/dev/loop-control", O_RDWR);
if (cfd == -1) {
fprintf(stderr, "Error: /dev/loop-control interface is not supported by your kernel\n");
exit(1);
}
if (cfd == -1)
err_loop();
int devnr = ioctl(cfd, LOOP_CTL_GET_FREE);
if (devnr == -1) {
fprintf(stderr, "Error: cannot allocate a new loopback device\n");
exit(1);
}
if (devnr == -1)
err_loop();
close(cfd);
if (asprintf(&devloop, "/dev/loop%d", devnr) == -1)
errExit("asprintf");
int lfd = open(devloop, O_RDONLY);
if (lfd == -1) {
fprintf(stderr, "Error: cannot open %s\n", devloop);
exit(1);
}
if (ioctl(lfd, LOOP_SET_FD, ffd) == -1) {
fprintf(stderr, "Error: cannot configure the loopback device\n");
exit(1);
}
if (lfd == -1)
err_loop();
if (ioctl(lfd, LOOP_SET_FD, ffd) == -1)
err_loop();
if (size) {
struct loop_info64 info;
memset(&info, 0, sizeof(struct loop_info64));
info.lo_offset = size;
if (ioctl(lfd, LOOP_SET_STATUS64, &info) == -1)
errExit("configure appimage offset");
err_loop();
}
close(lfd);
......
......@@ -542,7 +542,7 @@ void fs_trace(void);
// fs_hostname.c
void fs_hostname(const char *hostname);
void fs_resolvconf(void);
char *fs_check_hosts_fiile(const char *fname);
char *fs_check_hosts_file(const char *fname);
void fs_store_hosts_file(void);
void fs_mount_hosts_file(void);
......
......@@ -34,7 +34,9 @@ void fs_machineid(void) {
// if --machine-id flag is inactive, do nothing
if (arg_machineid == 0)
return;
if (arg_debug)
printf("Generating a new machine-id\n");
// init random number generator
srand(time(NULL));
......
......@@ -127,7 +127,7 @@ void fs_resolvconf(void) {
}
}
char *fs_check_hosts_fiile(const char *fname) {
char *fs_check_hosts_file(const char *fname) {
assert(fname);
invalid_filename(fname);
char *rv = expand_home(fname, cfg.homedir);
......@@ -151,6 +151,9 @@ void fs_store_hosts_file(void) {
}
void fs_mount_hosts_file(void) {
if (arg_debug)
printf("Loading user hosts file\n");
// check /etc/hosts file
struct stat s;
if (stat("/etc/hosts", &s) == -1)
......
......@@ -1969,7 +1969,7 @@ int main(int argc, char **argv) {
}
else if (strncmp(argv[i], "--hosts-file=", 13) == 0)
cfg.hosts_file = fs_check_hosts_fiile(argv[i] + 13);
cfg.hosts_file = fs_check_hosts_file(argv[i] + 13);
#ifdef HAVE_NETWORK
else if (strcmp(argv[i], "--netfilter") == 0) {
......
......@@ -608,7 +608,7 @@ int profile_check_line(char *ptr, int lineno, const char *fname) {
// hosts-file
if (strncmp(ptr, "hosts-file ", 11) == 0) {
cfg.hosts_file = fs_check_hosts_fiile(ptr + 11);
cfg.hosts_file = fs_check_hosts_file(ptr + 11);
return 0;
}
......
......@@ -10,6 +10,12 @@ export MALLOC_PERTURB_=$(($RANDOM % 255 + 1))
echo "TESTING: DNS (test/environment/dns.exp)"
./dns.exp
echo "TESTING: machine-id (test/environment/machineid.exp)"
./machineid.exp
echo "TESTING: hosts file (test/environment/hostfile.exp)"
./hostfile.exp
echo "TESTING: doubledash (test/environment/doubledash.exp"
mkdir -- -testdir
touch -- -testdir/ttt
......
#!/usr/bin/expect -f
# This file is part of Firejail project
# Copyright (C) 2014-2017 Firejail Authors
# License GPL v2
set timeout 10
spawn $env(SHELL)
match_max 100000
send -- "firejail --debug --hosts-file=hostfile\r"
expect {
timeout {puts "TESTING ERROR 1\n";exit}
"Loading user hosts file"
}
expect {
timeout {puts "TESTING ERROR 2\n";exit}
"Child process initialized"
}
after 100
send -- "cat /etc/hosts\r"
expect {
timeout {puts "TESTING ERROR 3\n";exit}
"hostfile test"
}
send -- "exit\r"
after 100
puts "\nall done\n"
#!/usr/bin/expect -f
# This file is part of Firejail project
# Copyright (C) 2014-2017 Firejail Authors
# License GPL v2
set timeout 10
spawn $env(SHELL)
match_max 100000
send -- "firejail --debug --machine-id\r"
expect {
timeout {puts "TESTING ERROR 1\n";exit}
"Generating a new machine-id"
}
expect {
timeout {puts "TESTING ERROR 1\n";exit}
"Child process initialized"
}
after 100
send -- "exit\r"
after 100
puts "\nall done\n"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment