From 7b587995ba7f2fb4e3a8d23f4be0ad91f1ab066a Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Sat, 30 May 2015 15:48:20 -0500 Subject: [PATCH 1/1] New helper function: inode_has_security_descriptor() --- include/wimlib/inode.h | 13 +++++++++---- src/extract.c | 2 +- src/iterate_dir.c | 2 +- src/ntfs-3g_apply.c | 2 +- src/win32_apply.c | 2 +- 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/include/wimlib/inode.h b/include/wimlib/inode.h index 08f414d0..3fbb4039 100644 --- a/include/wimlib/inode.h +++ b/include/wimlib/inode.h @@ -157,10 +157,8 @@ struct wim_inode { /* Corresponds to 'security_id' in `struct wim_dentry_on_disk': The * index of this inode's security descriptor in the WIM image's table of - * security descriptors, or -1. Note: when a WIM image is loaded, - * wimlib sets out-of-bounds indices and values less than -1 in this - * field to -1. So the extraction code need not do an upper bound check - * after checking for -1 (or equivalently < 0). */ + * security descriptors, or -1 if this inode does not have a security + * descriptor. */ s32 i_security_id; /* Unknown field that we only read into memory so we can re-write it @@ -324,6 +322,13 @@ inode_has_children(const struct wim_inode *inode) return inode->i_children != NULL; } +/* Does the inode have a security descriptor? */ +static inline bool +inode_has_security_descriptor(const struct wim_inode *inode) +{ + return inode->i_security_id >= 0; +} + extern struct wim_inode_stream * inode_get_stream(const struct wim_inode *inode, int stream_type, const utf16lechar *stream_name); diff --git a/src/extract.c b/src/extract.c index 5fcf5248..cf8a2c92 100644 --- a/src/extract.c +++ b/src/extract.c @@ -1157,7 +1157,7 @@ inode_tally_features(const struct wim_inode *inode, else features->other_reparse_points++; } - if (inode->i_security_id != -1) + if (inode_has_security_descriptor(inode)) features->security_descriptors++; if (inode_has_unix_data(inode)) features->unix_data++; diff --git a/src/iterate_dir.c b/src/iterate_dir.c index 5bf138cc..451143a7 100644 --- a/src/iterate_dir.c +++ b/src/iterate_dir.c @@ -109,7 +109,7 @@ init_wimlib_dentry(struct wimlib_dir_entry *wdentry, struct wim_dentry *dentry, for (struct wim_dentry *d = dentry; !dentry_is_root(d); d = d->d_parent) wdentry->depth++; - if (inode->i_security_id >= 0) { + if (inode_has_security_descriptor(inode)) { struct wim_security_data *sd; sd = wim_get_current_security_data(wim); diff --git a/src/ntfs-3g_apply.c b/src/ntfs-3g_apply.c index f0386b12..10f514cd 100644 --- a/src/ntfs-3g_apply.c +++ b/src/ntfs-3g_apply.c @@ -385,7 +385,7 @@ ntfs_3g_set_metadata(ntfs_inode *ni, const struct wim_inode *inode, } /* Security descriptor */ - if ((inode->i_security_id >= 0) + if (inode_has_security_descriptor(inode) && !(extract_flags & WIMLIB_EXTRACT_FLAG_NO_ACLS)) { const void *desc; diff --git a/src/win32_apply.c b/src/win32_apply.c index 7bacac9d..f4a2d753 100644 --- a/src/win32_apply.c +++ b/src/win32_apply.c @@ -2451,7 +2451,7 @@ do_apply_metadata_to_file(HANDLE h, const struct wim_inode *inode, NTSTATUS status; /* Set security descriptor if present and not in NO_ACLS mode */ - if (inode->i_security_id >= 0 && + if (inode_has_security_descriptor(inode) && !(ctx->common.extract_flags & WIMLIB_EXTRACT_FLAG_NO_ACLS)) { const struct wim_security_data *sd; -- 2.43.0