From: Eric Biggers Date: Tue, 21 Aug 2012 22:48:01 +0000 (-0500) Subject: ntfs.c => ntfs-apply.c X-Git-Tag: v1.0.0~102 X-Git-Url: https://wimlib.net/git/?p=wimlib;a=commitdiff_plain;h=01efbb02603508a2272f859c87ec259560aa823d;ds=sidebyside ntfs.c => ntfs-apply.c --- diff --git a/Makefile.am b/Makefile.am index 9b00f8b9..5d2d00e8 100644 --- a/Makefile.am +++ b/Makefile.am @@ -31,8 +31,7 @@ libwim_la_SOURCES = \ src/lzx.h \ src/modify.c \ src/mount.c \ - src/ntfs.c \ - src/ntfs-3g_security.c \ + src/ntfs-apply.c \ src/resource.c \ src/security.c \ src/security.h \ @@ -53,6 +52,11 @@ libwim_la_SOURCES = \ src/xpress-decomp.c \ src/xpress.h +if WITH_NTFS_3G +libwim_la_SOURCES += src/ntfs-3g_security.c +endif + + EXTRA_libwim_la_SOURCES = src/sha1-ssse3.asm libwim_la_DEPENDENCIES = $(SSSE3_SHA1_OBJ) STRIP_FPIC = sh $(top_srcdir)/build-aux/strip_fPIC.sh diff --git a/configure.ac b/configure.ac index c67ca43e..af814b9d 100644 --- a/configure.ac +++ b/configure.ac @@ -158,6 +158,8 @@ else LIBNTFS_3G_LDADD= LIBNTFS_3G_CFLAGS= fi +AM_CONDITIONAL([WITH_NTFS_3G], [test "x$WITH_NTFS_3G" = "xyes"]) + AC_SUBST([LIBNTFS_3G_LDADD], [$LIBNTFS_3G_LDADD]) AC_SUBST([LIBNTFS_3G_CFLAGS], [$LIBNTFS_3G_CFLAGS]) diff --git a/src/dentry.c b/src/dentry.c index f5a3fe14..27937ab4 100644 --- a/src/dentry.c +++ b/src/dentry.c @@ -1045,19 +1045,15 @@ int read_dentry(const u8 metadata_resource[], u64 metadata_resource_len, * aligned on the next 8-byte boundary. Here's an example of the * aligned data: * - * 01000000400000006c786bbac58ede11b0bb00261870892ab6adb76fe63a3 - * e468fca86530d2effa16c786bbac58ede11b0bb00261870892a0000000000 - * 0000000000000000000000 + * 01000000 40000000 6c786bba c58ede11 b0bb0026 1870892a b6adb76f + * e63a3e46 8fca8653 0d2effa1 6c786bba c58ede11 b0bb0026 1870892a + * 00000000 00000000 00000000 00000000 * * Here's one interpretation of how the data is laid out. * * struct unknown { * u32 field1; (always 0x00000001) * u32 field2; (always 0x40000000) - * u16 field3; - * u32 field4; - * u32 field5; - * u32 field6; * u8 data[48]; (???) * u64 reserved1; (always 0) * u64 reserved2; (always 0) diff --git a/src/dentry.h b/src/dentry.h index db6481b1..613f6259 100644 --- a/src/dentry.h +++ b/src/dentry.h @@ -100,7 +100,7 @@ static inline bool ads_entry_has_name(const struct ads_entry *entry, } -/* In-memory structure for a directory entry. There is a directory tree for +/* In-memory structure for a WIM directory entry. There is a directory tree for * each image in the WIM. */ struct dentry { /* The parent of this directory entry. */ diff --git a/src/ntfs.c b/src/ntfs-apply.c similarity index 75% rename from src/ntfs.c rename to src/ntfs-apply.c index 317f60d6..300c3081 100644 --- a/src/ntfs.c +++ b/src/ntfs-apply.c @@ -35,7 +35,7 @@ #include struct ntfs_apply_args { - struct SECURITY_API *scapi; + ntfs_volume *vol; int extract_flags; WIMStruct *w; }; @@ -44,80 +44,6 @@ extern int _ntfs_set_file_security(ntfs_volume *vol, ntfs_inode *ni, u32 selection, const char *attr); extern int _ntfs_set_file_attributes(ntfs_inode *ni, s32 attrib); -/* - * Initializations before calling ntfs_get_file_security() - * ntfs_set_file_security() and ntfs_read_directory() - * - * Returns an (obscured) struct SECURITY_API* needed for further calls - * NULL if device is mounted (EBUSY) - */ - -static struct SECURITY_API *_ntfs_initialize_file_security(const char *device, - unsigned long flags) -{ - ntfs_volume *vol; - unsigned long mntflag; - int mnt; - struct SECURITY_API *scapi; - struct SECURITY_CONTEXT *scx; - - scapi = (struct SECURITY_API*)NULL; - mnt = ntfs_check_if_mounted(device, &mntflag); - if (!mnt && !(mntflag & NTFS_MF_MOUNTED)) { - vol = ntfs_mount(device, flags); - if (vol) { - scapi = (struct SECURITY_API*) - ntfs_malloc(sizeof(struct SECURITY_API)); - if (!ntfs_volume_get_free_space(vol) - && scapi) { - scapi->magic = MAGIC_API; - scapi->seccache = (struct PERMISSIONS_CACHE*)NULL; - scx = &scapi->security; - scx->vol = vol; - scx->uid = 0; - scx->gid = 0; - scx->pseccache = &scapi->seccache; - scx->vol->secure_flags = (1 << SECURITY_DEFAULT) | - (1 << SECURITY_RAW); - ntfs_open_secure(vol); - ntfs_build_mapping(scx,(const char*)NULL,TRUE); - } else { - if (scapi) - free(scapi); - else - errno = ENOMEM; - mnt = ntfs_umount(vol,FALSE); - scapi = (struct SECURITY_API*)NULL; - } - } - } else - errno = EBUSY; - return (scapi); -} - -/* - * JPA NTFS constants or structs - * should be moved to layout.h - */ - -#define ALIGN_SDS_BLOCK 0x40000 /* Alignment for a $SDS block */ -#define ALIGN_SDS_ENTRY 16 /* Alignment for a $SDS entry */ -#define STUFFSZ 0x4000 /* unitary stuffing size for $SDS */ -#define FIRST_SECURITY_ID 0x100 /* Lowest security id */ - /* Mask for attributes which can be forced */ -#define FILE_ATTR_SETTABLE ( FILE_ATTR_READONLY \ - | FILE_ATTR_HIDDEN \ - | FILE_ATTR_SYSTEM \ - | FILE_ATTR_ARCHIVE \ - | FILE_ATTR_TEMPORARY \ - | FILE_ATTR_OFFLINE \ - | FILE_ATTR_NOT_CONTENT_INDEXED ) - - - -#if 0 -#endif - static int extract_resource_to_ntfs_attr(WIMStruct *w, const struct resource_entry *entry, ntfs_attr *na) { @@ -181,6 +107,15 @@ static int write_ntfs_data_streams(ntfs_inode *ni, const struct dentry *dentry, return 0; } +/* + * Applies a WIM dentry to a NTFS filesystem. + * + * @dentry: The WIM dentry to apply + * @dir_ni: The NTFS inode for the parent directory + * @w: The WIMStruct for the WIM containing the image we are applying. + * + * @return: 0 on success; nonzero on failure. + */ static int __ntfs_apply_dentry(struct dentry *dentry, ntfs_inode *dir_ni, WIMStruct *w) { @@ -272,8 +207,7 @@ out: static int ntfs_apply_dentry(struct dentry *dentry, void *arg) { struct ntfs_apply_args *args = arg; - struct SECURITY_API *scapi = args->scapi; - ntfs_volume *vol = scapi->security.vol; + ntfs_volume *vol = args->vol; int extract_flags = args->extract_flags; WIMStruct *w = args->w; ntfs_inode *dir_ni; @@ -320,24 +254,25 @@ static int ntfs_apply_dentry(struct dentry *dentry, void *arg) static int do_ntfs_apply(WIMStruct *w, const char *device, int extract_flags) { - struct SECURITY_API *scapi; + ntfs_volume *vol; int ret; - scapi = _ntfs_initialize_file_security(device, 0); - if (!scapi) { + vol = ntfs_mount(device, 0); + if (!vol) { ERROR_WITH_ERRNO("Failed to mount NTFS volume `%s'", device); return WIMLIB_ERR_NTFS_3G; } struct ntfs_apply_args args = { - .scapi = scapi, + .vol = vol, .extract_flags = extract_flags, .w = w, }; ret = for_dentry_in_tree(wim_root_dentry(w), ntfs_apply_dentry, &args); - if (!ntfs_leave_file_security(scapi)) { + if (ntfs_umount(vol, FALSE) != 0) { ERROR_WITH_ERRNO("Failed to unmount NTFS volume"); - ret = WIMLIB_ERR_NTFS_3G; + if (ret == 0) + ret = WIMLIB_ERR_NTFS_3G; } return ret; } @@ -363,14 +298,16 @@ WIMLIBAPI int wimlib_apply_image_to_ntfs_volume(WIMStruct *w, int image, if (ret != 0) return ret; - /*if (getuid() != 0) {*/ - /*ERROR("We are not root, but NTFS-3g requires root privileges to set arbitrary");*/ - /*ERROR("security data on the NTFS filesystem. Please run this program as root");*/ - /*ERROR("if you want to extract a WIM image while preserving NTFS-specific");*/ - /*ERROR("information.");*/ +#if 0 + if (getuid() != 0) { + ERROR("We are not root, but NTFS-3g requires root privileges to set arbitrary"); + ERROR("security data on the NTFS filesystem. Please run this program as root"); + ERROR("if you want to extract a WIM image while preserving NTFS-specific"); + ERROR("information."); - /*return WIMLIB_ERR_NOT_ROOT;*/ - /*}*/ + return WIMLIB_ERR_NOT_ROOT; + } +#endif return do_ntfs_apply(w, device, flags); }