/** * main - Begin here * * Start from here. * * Return: 0 Success, the program worked * 1 Error, something went wrong */ int main(int argc, char **argv) { unsigned long mnt_flags = 0; int result = 0; ntfs_volume *vol; ntfs_log_set_handler(ntfs_log_handler_outerr); if (!parse_options(argc, argv)) return 1; utils_set_locale(); if (!opts.label) opts.noaction++; vol = utils_mount_volume(opts.device, (opts.noaction ? MS_RDONLY : 0) | (opts.force ? MS_RECOVER : 0)); if (!vol) return 1; if (opts.label) result = change_label(vol, mnt_flags, opts.label, opts.force); else result = print_label(vol, mnt_flags); ntfs_umount(vol, FALSE); return result; }
/** * main - Begin here * * Start from here. * * Return: 0 Success, the program worked * 1 Error, something went wrong */ int main(int argc, char **argv) { unsigned long mnt_flags = 0; int result = 0; ntfs_volume *vol; ntfs_log_set_handler(ntfs_log_handler_outerr); result = parse_options(argc, argv); if (result >= 0) return (result); result = 0; utils_set_locale(); if ((opts.label || opts.new_serial) && !opts.noaction && !opts.force && !ntfs_check_if_mounted(opts.device, &mnt_flags) && (mnt_flags & NTFS_MF_MOUNTED)) { ntfs_log_error("Cannot make changes to a mounted device\n"); result = 1; goto abort; } if (!opts.label && !opts.new_serial) opts.noaction++; vol = utils_mount_volume(opts.device, (opts.noaction ? NTFS_MNT_RDONLY : 0) | (opts.force ? NTFS_MNT_RECOVER : 0)); if (!vol) return 1; if (opts.new_serial) { result = set_new_serial(vol); if (result) goto unmount; } else { if (opts.verbose) result = print_serial(vol); } if (opts.label) result = change_label(vol, opts.label); else result = print_label(vol, mnt_flags); unmount : ntfs_umount(vol, FALSE); abort : /* "result" may be a negative reply of a library function */ return (result ? 1 : 0); }
/** * main - Begin here * * Start from here. * * Return: 0 Success, the program worked * 1 Error, something went wrong */ int main(int argc, char *argv[]) { ntfs_volume *vol; ntfs_inode *inode; ATTR_TYPES attr; int result = 1; ntfs_log_set_handler(ntfs_log_handler_stderr); if (!parse_options(argc, argv)) return 1; utils_set_locale(); vol = utils_mount_volume(opts.device, MS_RDONLY | (opts.force ? MS_RECOVER : 0)); if (!vol) { ntfs_log_perror("ERROR: couldn't mount volume"); return 1; } if (opts.inode != -1) inode = ntfs_inode_open(vol, opts.inode); else inode = ntfs_pathname_to_inode(vol, NULL, opts.file); if (!inode) { ntfs_log_perror("ERROR: Couldn't open inode"); return 1; } attr = AT_DATA; if (opts.attr != cpu_to_le32(-1)) attr = opts.attr; result = cat(vol, inode, attr, opts.attr_name, opts.attr_name_len); ntfs_inode_close(inode); ntfs_umount(vol, FALSE); return result; }
/** * main - Begin here * * Start from here. * * Return: 0 Success, the program worked * 1 Error, something went wrong */ int main(int argc, char *argv[]) { u8 *pfx_buf; char *password; ntfs_rsa_private_key rsa_key; ntfs_volume *vol; ntfs_inode *inode; ntfs_fek *fek; unsigned pfx_size; int res; NTFS_DF_TYPES df_type; char thumbprint[NTFS_SHA1_THUMBPRINT_SIZE]; #ifdef DEBUG ntfs_log_set_handler(ntfs_log_handler_stderr); #endif if (!parse_options(argc, argv)) return 1; utils_set_locale(); /* Initialize crypto in ntfs. */ if (ntfs_crypto_init()) { ntfs_log_error("Failed to initialize crypto. Aborting.\n"); return 1; } /* Load the PKCS#12 (.pfx) file containing the user's private key. */ if (ntfs_pkcs12_load_pfxfile(opts.keyfile, &pfx_buf, &pfx_size)) { ntfs_log_error("Failed to load key file. Aborting.\n"); ntfs_crypto_deinit(); return 1; } /* Ask the user for their password. */ password = getpass("Enter the password with which the private key was " "encrypted: "); if (!password) { ntfs_log_perror("Failed to obtain user password"); free(pfx_buf); ntfs_crypto_deinit(); return 1; } /* Obtain the user's private RSA key from the key file. */ rsa_key = ntfs_pkcs12_extract_rsa_key(pfx_buf, pfx_size, password, thumbprint, sizeof(thumbprint), &df_type); /* Destroy the password. */ memset(password, 0, strlen(password)); /* No longer need the pfx file contents. */ free(pfx_buf); if (!rsa_key) { ntfs_log_error("Failed to extract the private RSA key.\n"); ntfs_crypto_deinit(); return 1; } /* Mount the ntfs volume. */ vol = utils_mount_volume(opts.device, NTFS_MNT_RDONLY | (opts.force ? NTFS_MNT_RECOVER : 0)); if (!vol) { ntfs_log_error("Failed to mount ntfs volume. Aborting.\n"); ntfs_rsa_private_key_release(rsa_key); ntfs_crypto_deinit(); return 1; } /* Open the encrypted ntfs file. */ if (opts.inode != -1) inode = ntfs_inode_open(vol, opts.inode); else inode = ntfs_pathname_to_inode(vol, NULL, opts.file); if (!inode) { ntfs_log_error("Failed to open encrypted file. Aborting.\n"); ntfs_umount(vol, FALSE); ntfs_rsa_private_key_release(rsa_key); ntfs_crypto_deinit(); return 1; } /* Obtain the file encryption key of the encrypted file. */ fek = ntfs_inode_fek_get(inode, rsa_key, thumbprint, sizeof(thumbprint), df_type); ntfs_rsa_private_key_release(rsa_key); if (fek) { res = ntfs_cat_decrypt(inode, fek); ntfs_fek_release(fek); } else { ntfs_log_error("Failed to obtain file encryption key. " "Aborting.\n"); res = 1; } ntfs_inode_close(inode); ntfs_umount(vol, FALSE); ntfs_crypto_deinit(); return res; }
/** * main */ int main(int argc, char **argv) { unsigned long mnt_flags, ul; int err; ntfs_inode *ni; ntfs_volume *vol; #ifdef HAVE_WINDOWS_H char *unix_name; #endif vol = (ntfs_volume*)NULL; ntfs_log_set_handler(ntfs_log_handler_outerr); /* Initialize opts to zero / required values. */ memset(&opts, 0, sizeof(opts)); /* Parse command line options. */ parse_options(argc, argv); utils_set_locale(); /* Make sure the file system is not mounted. */ if (ntfs_check_if_mounted(dev_name, &mnt_flags)) ntfs_log_perror("Failed to determine whether %s is mounted", dev_name); else if (mnt_flags & NTFS_MF_MOUNTED) { ntfs_log_error("%s is mounted.\n", dev_name); if (!opts.force) err_exit((ntfs_volume*)NULL, "Refusing to run!\n"); fprintf(stderr, "ntfsfallocate forced anyway. Hope /etc/mtab " "is incorrect.\n"); } /* Mount the device. */ if (opts.no_action) { ntfs_log_quiet("Running in READ-ONLY mode!\n"); ul = NTFS_MNT_RDONLY; } else if (opts.force) ul = NTFS_MNT_RECOVER; else ul = 0; vol = ntfs_mount(dev_name, ul); if (!vol) err_exit(vol, "Failed to mount %s: %s\n", dev_name, strerror(errno)); if ((vol->flags & VOLUME_IS_DIRTY) && !opts.force) err_exit(vol, "Volume is dirty, please run chkdsk.\n"); if (ntfs_volume_get_free_space(vol)) err_exit(vol, "Failed to get free clusters %s: %s\n", dev_name, strerror(errno)); /* Open the specified inode. */ #ifdef HAVE_WINDOWS_H unix_name = (char*)malloc(strlen(file_name) + 1); if (unix_name) { int i; for (i=0; file_name[i]; i++) if (file_name[i] == '\\') unix_name[i] = '/'; else unix_name[i] = file_name[i]; unix_name[i] = 0; ni = ntfs_pathname_to_inode(vol, NULL, unix_name); free(unix_name); } else ni = (ntfs_inode*)NULL; #else ni = ntfs_pathname_to_inode(vol, NULL, file_name); #endif if (!ni) err_exit(vol, "Failed to open file \"%s\": %s\n", file_name, strerror(errno)); if (!opts.no_action) err = ntfs_fallocate(ni, opt_alloc_offs, opt_alloc_len); /* Close the inode. */ if (ntfs_inode_close(ni)) { err = -1; err_exit(vol, "Failed to close inode \"%s\" : %s\n", file_name, strerror(errno)); } /* Unmount the volume. */ err = ntfs_umount(vol, 0); vol = (ntfs_volume*)NULL; if (err) ntfs_log_perror("Warning: Failed to umount %s", dev_name); /* Free the attribute name if it exists. */ if (attr_name_len) ntfs_ucsfree(attr_name); ntfs_log_quiet("ntfsfallocate completed successfully. Have a nice day.\n"); return 0; }