int main(int argc, char* argv[]){ /* * ensure the following items are proper: * - this process has cap_sys_chroot=ep * - the config files are secure * - the config files are readable * - enough arguments were provided */ /* ensure this process has the required capabilities */ ensure_capsyschroot(argv[0]); /* ensure config file is only writable by root */ ensure_config_secure(); /* ensure config file is readable */ ensure_config_readable(); /* ensure there are enough arguments */ ensure_enough_arguments(argc, argv); /* * gather the following pieces of information: * - the command (and its arguments) to run in the chroot * - the path to the chroot * - the directory to be cwd in the chroot */ /* get command to run in chroot */ char* shell[2]; char** chroot_command = get_chroot_command(argc, argv, shell); /* get path to chroot */ char chroot_path[PATH_MAX]; get_chroot_path(argv,chroot_path); /* get cwd - will attempt to make this cwd in chroot */ char* chroot_cwd = getcwd(NULL, PATH_MAX); /* * run the command in the proper context: * - if we're in a chroot, break out * - chroot the new directory, ensuring cwd is within it. * - change cwd to desired directory if it exists; remain in / otherwise. * - run command * - if needed, abort cleanly */ /* break out of chroot */ break_out_of_chroot(); /* chroot to new directory */ chdir(chroot_path); chroot("."); /* change cwd in the chroot to what it was previously, if possible */ if(chdir(chroot_cwd) != 0) fprintf(stderr,"WARNING: \"%s\" not present in target client, falling back to root directory\n", chroot_cwd); /* We need to free previously allocated memory */ free(chroot_cwd); /* run command */ execvp(chroot_command[0], chroot_command); /* if there is an error, abort cleanly */ perror("execvp"); return 2; }
rtems_task Init( rtems_task_argument ignored) { int rc=0; puts( "\n\n*** FILE SYSTEM TEST ( " FILESYSTEM " ) ***" ); puts( "Initializing filesystem " FILESYSTEM ); test_initialize_filesystem(); rc=chroot(BASE_FOR_TEST); rtems_test_assert(rc==0); test(); break_out_of_chroot(); puts( "\n\nShutting down filesystem " FILESYSTEM ); test_shutdown_filesystem(); puts( "*** END OF FILE SYSTEM TEST ( " FILESYSTEM " ) ***" ); rtems_test_exit(0); }