int main(int argc, char *argv[]) { int a_flag=0; int u_flag=0; int n_flag=0; char *n_name=NULL; char *n_blk_dev=NULL; char *fstab_file=NULL; struct fstab *fstab=NULL; klog_set_level(6); parse_options(argc, argv, &a_flag, &u_flag, &n_flag, &n_name, &n_blk_dev); /* The name of the fstab file is last, after the option */ fstab_file = argv[argc - 1]; fstab = fs_mgr_read_fstab(fstab_file); if (a_flag) { return fs_mgr_mount_all(fstab); } else if (n_flag) { return fs_mgr_do_mount(fstab, n_name, n_blk_dev, 0); } else if (u_flag) { return fs_mgr_unmount_all(fstab); } else { ERROR("%s: Internal error, unknown option\n", me); exit(1); } fs_mgr_free_fstab(fstab); /* Should not get here */ exit(1); }
// Check to see if a mountable volume has encryption requirements static int handle_encryptable(struct fstab *fstab, const struct fstab_rec* rec) { /* If this is block encryptable, need to trigger encryption */ if ( (rec->fs_mgr_flags & MF_FORCECRYPT) || (device_is_force_encrypted() && fs_mgr_is_encryptable(rec))) { if (umount(rec->mount_point) == 0) { return FS_MGR_MNTALL_DEV_NEEDS_ENCRYPTION; } else { WARNING("Could not umount %s (%s) - allow continue unencrypted\n", rec->mount_point, strerror(errno)); return FS_MGR_MNTALL_DEV_NOT_ENCRYPTED; } } // Deal with file level encryption if (rec->fs_mgr_flags & MF_FILEENCRYPTION) { // Default or not yet initialized encryption requires no more work here if (!e4crypt_non_default_key(rec->mount_point)) { INFO("%s is default file encrypted\n", rec->mount_point); return FS_MGR_MNTALL_DEV_DEFAULT_FILE_ENCRYPTED; } INFO("%s is non-default file encrypted\n", rec->mount_point); // Uses non-default key, so must unmount and set up temp file system if (umount(rec->mount_point)) { ERROR("Failed to umount %s - rebooting\n", rec->mount_point); return FS_MGR_MNTALL_FAIL; } if (fs_mgr_do_tmpfs_mount(rec->mount_point) != 0) { ERROR("Failed to mount a tmpfs at %s\n", rec->mount_point); return FS_MGR_MNTALL_FAIL; } // Mount data temporarily so we can access unencrypted dir char tmp_mnt[PATH_MAX]; strlcpy(tmp_mnt, rec->mount_point, sizeof(tmp_mnt)); strlcat(tmp_mnt, "/tmp_mnt", sizeof(tmp_mnt)); if (mkdir(tmp_mnt, 0700)) { ERROR("Failed to create temp mount point\n"); return FS_MGR_MNTALL_FAIL; } if (fs_mgr_do_mount(fstab, rec->mount_point, rec->blk_device, tmp_mnt)) { ERROR("Error temp mounting encrypted file system\n"); return FS_MGR_MNTALL_FAIL; } return FS_MGR_MNTALL_DEV_NON_DEFAULT_FILE_ENCRYPTED; } return FS_MGR_MNTALL_DEV_NOT_ENCRYPTED; }