Commit Graph

644 Commits

Author SHA1 Message Date
Jean-Pierre André
9a8aeeea13 Prevented locally defined headers from interfering with ntfs-3g ones
Order the include directories so that those defined for ntfs-3g have
priority over locally defined ones.
2018-08-02 16:47:16 +02:00
Jean-Pierre André
f862fcee00 Extended the allowed cluster size to 2MB
From Windows 10 Creators edition, the cluster size limit has been
extended to 2MB. This has implied redefining the boot sector field
"sectors_per_cluster" so that values greater than 128 can be recorded.
2018-06-01 16:29:01 +02:00
Jean-Pierre André
ad79372024 Checked whether the device to mount was forced read-only
Force the read-only mount mode when the device was set so through a
command "blockdev --setro".
2018-06-01 15:59:09 +02:00
Jean-Pierre André
1f8b751341 Double-checked whether record 15 is an extent of MFT
When extents are needed to store the runlist of the MFT, the first one
must be located in record 15 so that its location can be determined from
the part in the base extent. As this record is always marked in use,
determining whether it is not really in use requires a specific logic.
2018-02-13 09:06:49 +01:00
Jean-Pierre André
163635f08f Fixed displaying an inode number in an error message
In an error message, the inode number was displayed in decimal without
taking off its generation number, making it difficult to interpret.
2018-02-13 08:47:00 +01:00
Jean-Pierre André
85e208176f Stopped checking matches of MFTMirr against MFT at record 16
Since its 2017 edition, Windows 10 has stopped mirroring $MFT to the
full size of $MFTMirr leading to mounts of partitions with big clusters
to be rejected because of mismatches. With this patch, only 16 records
are checked, though mirroring is still done for all records in $MFTMirr.
2017-12-22 11:29:00 +01:00
Jean-Pierre André
9e92184b7c Allowed setting a file object id without defining its birth ids
Object ids can be used to locate files which have been move to another
volume. This is only possible when the birth ids are recorded, but in most
cases files reside on their birth volume and their birth ids are not set.
The patch enables setting a file id without changing its birth id, by
setting an extended attribute "system.ntfs_object_id" limited to 16
bytes.
2017-12-22 11:24:58 +01:00
Jean-Pierre André
67feb2c286 Relaxed limitations on security descriptors
Windows 10 brought security descriptors which contain ACE's related to
new ways of accessing files or directories. These ACE are now accepted
with minimal consistency checks. They are still ignored for translating
permissions and for Windows-type inheritance.
2017-08-11 09:34:31 +02:00
Jean-Pierre André
7a0cf11e1c Fixed expanding $STANDARD_INFORMATION with almost-full MFT record
When setting a security descriptor on an NTFS v1.2 format file in an
NTFS v3.0+ volume, NTFS-3G would migrate $STANDARD_INFORMATION to the
new format, which requires extending its size from 48 to 72 bytes.  If
this happened while the file's MFT record was almost full, and none of
the file's attributes could be made non-resident, and the file did not
have an attribute list attribute, then the operation would unexpectedly
fail with ENOENT.  Fix this by adding an attribute list to the file in
this situation.

(contributed by Eric Biggers)
2017-02-11 10:58:46 +01:00
Jean-Pierre André
17b56ccfa2 Allowed names with trailing dot or space on conditions
Windows places filenames with a trailing dot or space in the Win32
namespace and allows setting DOS names on such files.  This is true even
though on Windows such filenames can only be created and accessed using
WinNT-style paths and will confuse most Windows software.  Regardless,
because libntfs-3g did not allow setting DOS names on such files, in
some cases it was impossible to correctly restore, using libntfs-3g, a
directory structure that was created under Windows.

Update ntfs_set_ntfs_dos_name() to permit operating on a file that has a
long name with a trailing dot or space.  But continue to forbid creating
such names on a filesystem FUSE-mounted with the windows_name option.
Additionally, continue to forbid a trailing a dot or space in DOS names;
this matches the Windows behavior.

(contributed by Eric Biggers)
2017-02-11 10:54:51 +01:00
Jean-Pierre André
ea9b8a487c Fixed memory leak when failing to lookup an index
When an index could not be used, the search context was not freed
2017-02-11 10:29:39 +01:00
Jean-Pierre André
35cb222233 Removed unused argument from ntfs_make_symlink()
Now that the size of the reparse point attribute is no longer used by
the FUSE drivers to populate st_size for symlinks and junctions, it no
longer needs to be returned by ntfs_make_symlink().

(contributed by Eric Biggers)
2017-02-11 10:11:01 +01:00
Jean-Pierre André
376f4cbca7 Validated minimum size of mountpoint/symlink reparse points
valid_reparse_data() would read past the end of the reparse point buffer
if it was passed a malformed reparse point that had the tag for a
mountpoint or a symlink but had a data buffer smaller than expected.
Fix this by validating the buffer size.

(contributed by Eric Biggers)
2017-02-11 10:00:34 +01:00
Jean-Pierre André
3c5fb9b352 Eliminated unnecessary strlen() in ntfs_get_ntfs_dos_name()
Since ntfs_ucstombs() returns the output string length, there is no need
to call strlen().

(contributed by Eric Biggers)
2017-02-11 09:58:30 +01:00
Jean-Pierre André
2052b46639 Fixed a possible buffer overrun in ntfs_utf16_to_utf8()
If an output buffer was provided, ntfs_utf16_to_utf8() limited the
output string length without the terminating null to 'outs_len'.  This
was incorrect because a terminating null was always added to the string,
causing a buffer overrun if the output string happened to have exactly
the maximum length.  This was a longstanding bug.  Fix it by leaving
space for a terminating null.

(contributed by Eric Biggers)
2017-02-11 09:51:17 +01:00
Jean-Pierre André
b9624542e0 Made utf16_to_utf8_size() always honor @outs_len
utf16_to_utf8_size() was not guaranteed to fail with ENAMETOOLONG if the
computed length was greater than @outs_len.  This could cause a buffer
overrun in ntfs_utf16_to_utf8().

(contributed by Eric Biggers)
2017-02-11 09:49:03 +01:00
Jean-Pierre André
fdefd8feba Fixed bad indentations (cosmetic) 2017-02-11 08:53:20 +01:00
Jean-Pierre André
32587b485c Improved opening/closing $Secure when un/mounting NTFS volume
Call ntfs_close_secure() earlier, check for error, and other cleanups

Signed-off-by: Eric Biggers <ebiggers3@gmail.com>
2016-09-02 08:30:07 +02:00
Jean-Pierre André
f86c4403ed Corrected validation of multi sector transfer protected records
The validation contained an off-by-one error.  The
expression '(u32)(usa_ofs + (usa_count * 2)) > size' used 'usa_count'
after it had been decremented to skip the update sequence number entry.
Consequently, the code could read out of bounds, up to two bytes past the
end of the MST-protected record.

Furthermore, as documented in the comment in layout.h for "NTFS_RECORD"
and also on MSDN for "MULTI_SECTOR_HEADER", the update sequence array
must end before the last le16 in the first logical sector --- not merely
before the end of the record.

Fix the validation and move it into a helper function, as it was done
identically in the read and write paths.

Signed-off-by: Eric Biggers <ebiggers3@gmail.com>
2016-07-28 16:26:21 +02:00
Jean-Pierre André
2840e84a97 Always opened $Secure when mounting NTFS volume
Currently, applications that wish to access security descriptors have to
explicitly open the volume's security descriptor index ("$Secure") using
ntfs_open_secure().  Applications are also responsible for closing the
index when done with it.  However, the cleanup function for doing,
ntfs_close_secure(), cannot be called easily by all applications because
it requires a SECURITY_CONTEXT argument, not simply the ntfs_volume.
Some applications therefore have to close the inode and index contexts
manually in order to clean up properly.

This proposal updates libntfs-3g to open $Secure unconditonally as part
of ntfs_mount(), so that applications do not have to worry about it.

This proposal updates libntfs-3g to open $Secure unconditonally as part
of ntfs_mount(), so that applications do not have to worry about it.

ntfs_close_secure() is updated to take in a ntfs_volume for internal use,
and ntfs_destroy_security_context() is now the function to call to free
memory associated with a SECURITY_CONTEXT rather than a ntfs_volume.

Some memory leaks in error paths of ntfs_open_secure() are also fixed.

Signed-off-by: Eric Biggers <ebiggers3@gmail.com>
2016-07-28 16:22:16 +02:00
Jean-Pierre André
e6cbd4d221 Removed unused variables
A few variables in xattrs.c are not used any more
2016-07-28 16:16:42 +02:00
Jean-Pierre André
043b0e6e73 Allowed using full library API on systems without extended attributes support
A number of functions in libntfs-3g are generally useful, but are tied to
extended attributes support and are not included when the library is
built on platforms without extended attributes support.

This proposal updates libntfs-3g to always include these functions.

The only tricky part is dealing with the XATTR_CREATE and XATTR_REPLACE
flags.  These flags are defined in <sys/xattr.h>, so they must be
redefined on platforms without extended attributes support.

Signed-off-by: Eric Biggers <ebiggers3@gmail.com>
2016-07-28 16:13:59 +02:00
Jean-Pierre André
4264f19acb Cleaned up file name collation code
- Update documentation for COLLATION_RULES
- Document how ntfs_names_full_collate() compares names
- Update comments and DEBUG code to reflect that ntfs_names_full_collate()
  always access 'upcase', even in CASE_SENSITIVE mode
- Remove unneeded assignments to 'c1' and 'c2' in IGNORE_CASE mode

Signed-off-by: Eric Biggers <ebiggers3@gmail.com>
2016-07-28 16:10:14 +02:00
Jean-Pierre André
191e47ff9d Tolerated garbage put by Windows 10 into the last ACE
For some reason, Windows 10 sometimes inserts garbage after the
last ACE of an ACL. The ACL consistency check has to tolerate this.
2016-07-19 11:40:20 +02:00
Jean-Pierre André
b973c0bd3c Compiled out conditionally debug-oriented code
Although ntfs_log_trace() is defined to a no-op in non-DEBUG builds,
ntfs_attr_name_get() is not.  This function performs a string conversion
and a memory allocation, so it is nice to have the call to it compiled
out when not needed.

Signed-off-by: Eric Biggers <ebiggers3@gmail.com>
2016-06-22 12:01:25 +02:00
Jean-Pierre André
5693341f0d Fixed ntfs_delete() failure caused by string conversion error
It was possible for ntfs_attr_name_get() to set errno due to a wide
character string that could not be converted to a multibyte string.  This
caused ntfs_delete() to fail.

Fix by checking for a nonzero return value specifically from
ntfs_attr_lookup(), rather than assuming that nothing else sets errno.

Signed-off-by: Eric Biggers <ebiggers3@gmail.com>
2016-06-22 11:58:20 +02:00
Jean-Pierre André
cf6f265069 Switch to using the standard autoconf AC_HEADER_MAJOR macro
Switch to the standard autoconf AC_HEADER_MAJOR macro which takes care
of the ugly details like when to use mkdev.h and when to use sysmacros.h.
(requires <sys/types.h> to be included)
Also include these in all files that use major/minor/makedev funcs.

(Contributed by Mike Frysinger)
2016-05-31 08:33:10 +02:00
Jean-Pierre André
e7c5950117 Silenced a truncation warning in upper case table
The upper case value for 0x1d79 is 0xa77d, so the difference is 0x8a04,
which overflows in the table which defines the computation of upper case
values. Rewriting this difference as -0x75fc leads to the same result
in an upper case table truncated to two bytes, and this avoid the
compiler warning.
2016-05-31 08:24:23 +02:00
Jean-Pierre André
34f7bd7ff0 Used <sys/mkdev.h> instead of <sys/sysmacros.h> on OpenIndiana
On Solaris/OpenIndiana, use the macroes makedev(), major() and minor()
from <sys/mkdev.h>. Those from <sys/sysmacros.h> are inappropriate for
current builds.
2016-05-04 10:03:39 +02:00
Erik Larsson
f0370bfa9c unistr.c: Unify the two defines NOREVBOM and ALLOW_BROKEN_SURROGATES.
In the mailing list discussion we came to the conclusion that there
doesn't seem to be any reason to keep these declarations separate since
they address the same issue, namely libntfs-3g's tolerance for bad
Unicode data in filenames and other UTF-16 strings in the file system,
so merge the two defines into the new define ALLOW_BROKEN_UNICODE.
2016-04-12 17:02:40 +02:00
Erik Larsson
d9c61dd60e unistr.c: Enable encoding broken UTF-16 into broken UTF-8, A.K.A. WTF-8.
Windows filenames may contain invalid UTF-16 sequences (specifically
broken surrogate pairs), which cannot be converted to UTF-8 if we do
strict conversion.

This patch enables encoding broken UTF-16 into similarly broken UTF-8 by
encoding any surrogate character that don't have a match into a separate
3-byte UTF-8 sequence.

This is "sort of" valid UTF-8, but not valid Unicode since the code
points used for surrogate pair encoding are not supposed to occur in a
valid Unicode string... but on the other hand the source UTF-16 data is
also broken, so we aren't really making things any worse.

This format is sometimes referred to as WTF-8 (Wobbly Translation
Format, 8-bit encoding) and is a common solution to represent broken
UTF-16 as UTF-8.

It is a lossless round-trip conversion, i.e converting from broken
UTF-16 to "WTF-8" and back to UTF-16 yields the same broken UTF-16
sequence. Because of this property it enables accessing these files
by filename through ntfs-3g and the ntfsprogs (e.g. ls -la works as
expected).

To disable this behaviour you can pass the preprocessor/compiler flag
'-DALLOW_BROKEN_SURROGATES=0' when building ntfs-3g.
2016-04-08 05:39:48 +02:00
Jean-Pierre André
48e1c132c7 Removed declarations for using acls.c outside ntfs-3g
The declarations for using acls.c within secaudit on Windows are not used
any more and can be dropped.
2016-04-07 09:32:26 +02:00
Jean-Pierre André
9693dd2fc1 Added a usn field to RESTART_PAGE_HEADER
Prepare merging ntfsrecover.h into logfile.h by adding a usn field to
RESTART_PAGE_HEADER. As this changes the record size, ignore the new
field in existing code.
2016-04-06 10:58:25 +02:00
Jean-Pierre André
88451c8069 Made a full check for whether a user extended attribute is allowed
User extended attributes should only be set on files and directories,
not on symlinks, sockets, devices, etc. For safety they are also
forbidden on metadata files, but should be allowed on the root
directory. For files based on reparse points, requests are made
to the plugin to determine the type.
2016-04-06 10:17:27 +02:00
Jean-Pierre André
31430ae01a Returned an error code for an exclusive access violation on Windows
Translate to Windows error code STATUS_SHARING_VIOLATION to Unix error
code EBUSY.
2016-04-06 10:08:01 +02:00
Jean-Pierre André
e8170f588f Fixed the maximum size of an ACL
Define the maximum size of an ACL as results from the maximum number of
sub-authorities defined in layout.h
2016-04-06 10:02:23 +02:00
Jean-Pierre André
8a1358fff4 Enabled fallback to read-only mount when volume is hibernated
When a volume is found hibernated (or prepared for fast restarting),
it is force-mounted as read-only.
2016-04-06 09:51:47 +02:00
Jean-Pierre André
366c20e8a2 Silenced fixup warnings when allocating a new MFT record
When creating a new MFT record, do not issue a warning if the current
record has bad fixups. These warnings are meaningless, difficult to
interpret and cause unneeded worries.
2016-04-06 09:32:18 +02:00
Jean-Pierre André
da33b0328f Used plugins to process reparse points
The new "system compression" files used by Windows 10 make use of reparse
points to record the compression parameters, and a specific named data
stream is used to store the compressed data. With this patch, processing
of reparse points can be done by an external plugin only loaded as needed.
Junctions and symlinks, which are also based on reparse points, are now
processed by "internal plugins".
2016-04-06 09:10:35 +02:00
Erik Larsson
62b5c91420 Fix compiler warnings about mismatching printf format / argument type.
For 64-bit (e.g. x86_64) Linux the 64-bit wide types resolve to long,
not long long as is the case in 32-bit (e.g. i386) Linux. So we need an
explicit cast to long long for 64-bit types since the format string must
specify the 'll' modifier in order to print 64-bit values.
2016-02-16 09:30:49 +01:00
Jean-Pierre André
d2197785f4 Avoided pointer cast when checking record types
Some compilers issue warning when casting a pointer to a pointer to
a different type.
When checking a record magic, there is no need to cast pointers.
2016-02-15 11:54:33 +01:00
Erik Larsson
abb2266147 mft.c: Fix compiler warning about mismatching format/argument type.
The expression is promoted to 'int' implicitly so we explicitly cast it
to 'u8'.
2016-02-11 13:52:59 +01:00
Erik Larsson
33cb3087b5 efs.c: Fix incorrect type of local variables 'newsize' and 'oldsize'.
These variable are only ever assigned to/from s64 values, so their type
should be s64, not u64. This fixes a compiler warning about
signed/unsigned comparison.
2016-02-08 18:42:53 +01:00
Erik Larsson
9893ea9ee6 Merge endianness fixes.
Conflicts:
	libntfs-3g/attrib.c
2016-01-28 09:22:42 +01:00
Erik Larsson
701cd61cca volume.c: Fix passing bad pointer type to ntfs_is_[baad|mft]_recordp. 2016-01-25 11:31:12 +01:00
Erik Larsson
8aa2769d70 mst.c: Fix mixed native/little-endian usage of variable 'usn'. 2016-01-25 11:30:13 +01:00
Erik Larsson
84f042e739 reparse.c: Fix big-endian bug when converting file name to lowercase.
When looking up the lowercase equivalent of a Unicode character in
ntfs_fix_file_name, no byte swapping was performed on the ntfschar used
as index into the 'locase' array. This would lead to very strange
results on big-endian systems.
2016-01-04 10:19:05 +01:00
Erik Larsson
9cf04fd2cd Fix incorrect usage of native/little-endian types, signed types, etc.
This is harmless with regard to code generation but if we turn on strict
type checking these type mismatches will result in errors.
2015-12-21 23:55:31 +01:00
Erik Larsson
f076fae75a Fix endianness issues in log and terminal output.
This commit addresses issues where little-endian variables are emitted
raw to a log or output stream which is to be interpreted by the user.

Outputting data in non-native endianness can cause confusion for anybody
attempting to debug issues with a file system.
2015-12-21 23:31:09 +01:00
Erik Larsson
dfa4a6647f Fix code to use const_cpu_to_X/const_X_to_cpu macros for constants.
This enables the compiler to optimize this code in cases where compiler
support for endianness swapping is not present.
2015-12-21 23:21:00 +01:00