Esempio n. 1
0
/*
 * Main entry point:
 */
int MAIN(int argc, char **argv)
{
    // First print GPL information:
    printf("%s %s [%s] Copyright (C) 2017 basil\n", PROGRAM_NAME_LONG,
        PROGRAM_VERSION, PLATFORM);
    puts("License GPLv3+: GNU GPL version 3 or later "
        "<http://gnu.org/licenses/gpl.html>.");
    puts("This is free software: you are free to change and redistribute it.");
    puts("There is NO WARRANTY, to the extent permitted by law.");
    putchar('\n');

    // Process options:
    options_init(argc, argv);

    // Initialise various components (order is important!).
    log_init();
    trace("changing to home directory %s", PROGRAM_DIR);
    chdir_home();
    trace("installing files (if required)");
    install_files();
    trace("initialising user configuration");
    config_init();
    trace("initialising tunnel management");
    tunnel_init();

    // Initialise the sockets library (if required on this platform).
    trace("initialising sockets");
    init_sockets();

    // Get number of threads.
    int num_threads =
        (options_get()->seen_num_threads?  options_get()->val_num_threads:
            NUM_THREADS_DEFAULT);
    if (num_threads < 1 || num_threads > NUM_THREADS_MAX)
    {
        error("unable to spawn %d threads; expected a number within the "
            "range 1..%u", num_threads, NUM_THREADS_MAX);
    }

    // Create configuration server thread.
    trace("launching configuration server thread");
    if (thread_lock_init(&config_lock))
    {
        error("unable to initialise global configuration lock");
    }
    thread_t config_thread;
    if (!options_get()->seen_no_ui &&
        thread_create(&config_thread, configuration_thread, NULL) != 0)
    {
        error("unable to create configuration server thread");
    }

    // Open the packet capture/injection device driver.
    trace("initialising packet capture");
    if (!options_get()->seen_no_capture)
    {
        init_capture();
    }

    // Open the tunnels.
    trace("initialising tunnels");
    tunnel_file_read();
    tunnel_open();

    // Go to sleep if we are not capturing packets.
    while (options_get()->seen_no_capture)
    {
        sleeptime(UINT64_MAX);
    }

    // Start worker threads.
    for (int i = 1; i < num_threads; i++)
    {
        thread_t work_thread;
        if (thread_create(&work_thread, worker_thread, NULL) != 0)
        {
            error("unable to create worker thread");
        }
    }
    worker_thread((void *)0);

    return EXIT_SUCCESS;
}
Esempio n. 2
0
int main(int argc, char* argv[], char* env[]) {
	int ret = 0;
	int device = 0;
	struct stat status;

	console = open("/dev/console", O_WRONLY);
	dup2(console, 1);
	dup2(console, 2);
	envp = env;

	puts("Searching for disk...\n");
	while (stat("/dev/disk0s1", &status) != 0) {
		sleep(1);
	}
	puts("\n\n\n\n\n");
	puts("Pois0nDisk - by Chronic-Dev Team\n");

	puts("Mounting filesystem...\n");
	if (hfs_mount("/dev/disk0s1", "/mnt", MNT_ROOTFS | MNT_RDONLY) != 0) {
		if (hfs_mount("/dev/disk0s1s1", "/mnt", MNT_ROOTFS | MNT_RDONLY) != 0) {
			puts("Unable to mount filesystem!\n");
			return -1;

		} else {
			device = DEVICE_ATV;
		}
	}
	puts("Filesystem mounted\n");

	puts("Mounting devices...\n");
	if (mount("devfs", "/mnt/dev", 0, NULL) != 0) {
		puts("Unable to mount devices!\n");
		unmount("/mnt", 0);
		return -1;
	}
	puts("Devices mounted\n");

	puts("Checking root filesystem...\n");
	if(device == DEVICE_ATV) {
		ret = fsexec(fsck_hfs_atv, env);
	} else {
		ret = fsexec(fsck_hfs, env);
	}
	if (ret != 0) {
		puts("Unable to check root filesystem!\n");
		unmount("/mnt/dev", 0);
		unmount("/mnt", 0);
		return -1;
	}
	puts("Root filesystem checked\n");

	puts("Checking user filesystem...\n");
	if(device == DEVICE_ATV) {
		fsexec(fsck_hfs_user_atv, env);
	} else {
		fsexec(fsck_hfs_user, env);
		fsexec(fsck_hfs_user_old, env);
	}
	puts("User filesystem checked\n");

	puts("Updating filesystem...\n");
	if(device == DEVICE_ATV) {
		ret = hfs_mount("/dev/disk0s1s1", "/mnt", MNT_ROOTFS | MNT_UPDATE);
	} else {
		ret = hfs_mount("/dev/disk0s1", "/mnt", MNT_ROOTFS | MNT_UPDATE);
	}
	if (ret != 0) {
		puts("Unable to update filesystem!\n");
		unmount("/mnt/dev", 0);
		unmount("/mnt", 0);
		return -1;
	}
	puts("Filesystem updated\n");

	puts("Mounting user filesystem...\n");
	mkdir("/mnt/private/var2", 0755);

	if(device == DEVICE_ATV) {
		if (hfs_mount("/dev/disk0s1s2", "/mnt/private/var2", 0) != 0) {
			puts("Unable to mount user filesystem!\n");
			return -1;
		}

	} else {
		if (hfs_mount("/dev/disk0s2s1", "/mnt/private/var2", 0) != 0) {
			if (hfs_mount("/dev/disk0s2", "/mnt/private/var2", 0) != 0) {
				puts("Unable to mount user filesystem!\n");
				return -1;

			} else {
				device = DEVICE_OLD;
			}

		} else {
			device = DEVICE_NEW;
		}
	}
	puts("User filesystem mounted\n");

	puts("Installing files...\n");
	if (install_files(device) != 0) {
		puts("Failed to install files!\n");
		unmount("/mnt/private/var2", 0);
		rmdir("/mnt/private/var2");
		unmount("/mnt/dev", 0);
		unmount("/mnt", 0);
		return -1;
	}
	puts("Installation complete\n");
	sync();

	puts("Unmounting disks...\n");
	rmdir("/mnt/private/var2");
	unmount("/mnt/private/var2", 0);
	unmount("/mnt/dev", 0);
	unmount("/mnt", 0);

	puts("Flushing buffers...\n");
	sync();

	puts("Rebooting device...\n");
	close(console);
	reboot(1);

	return 0;
}