]> wimlib.net Git - wimlib/blobdiff - src/security.c
Misc. fixes
[wimlib] / src / security.c
index 9c55ef2d30d09f0c5d6da72d3c64a8c7c2c9f05a..9b1ea21811485f64183a65a996ab7da6e3c3c894 100644 (file)
@@ -255,8 +255,12 @@ typedef struct {
  * entries anyway; however this ensures that that the security descriptors pass
  * the validation in libntfs-3g.
  */
-static void empty_sacl_fixup(u8 *descr, u64 *size_p)
+static void
+empty_sacl_fixup(u8 *descr, u64 *size_p)
 {
+       /* No-op if no NTFS-3g support, or if NTFS-3g is version 2013 or later
+        * */
+#if defined(WITH_NTFS_3G) && !defined(HAVE_NTFS_MNT_RDONLY)
        if (*size_p >= sizeof(SecurityDescriptor)) {
                SecurityDescriptor *sd = (SecurityDescriptor*)descr;
                u32 sacl_offset = le32_to_cpu(sd->sacl_offset);
@@ -265,6 +269,7 @@ static void empty_sacl_fixup(u8 *descr, u64 *size_p)
                        *size_p -= sizeof(ACL);
                }
        }
+#endif
 }
 
 /*
@@ -281,8 +286,9 @@ static void empty_sacl_fixup(u8 *descr, u64 *size_p)
  * Note: There is no `offset' argument because the security data is located at
  * the beginning of the metadata resource.
  */
-int read_security_data(const u8 metadata_resource[], u64 metadata_resource_len,
-                      struct wim_security_data **sd_p)
+int
+read_security_data(const u8 metadata_resource[], u64 metadata_resource_len,
+                  struct wim_security_data **sd_p)
 {
        struct wim_security_data *sd;
        const u8 *p;
@@ -431,7 +437,8 @@ out_free_sd:
 /*
  * Writes security data to an in-memory buffer.
  */
-u8 *write_security_data(const struct wim_security_data *sd, u8 *p)
+u8 *
+write_security_data(const struct wim_security_data *sd, u8 *p)
 {
        DEBUG("Writing security data (total_length = %"PRIu32", num_entries "
              "= %"PRIu32")", sd->total_length, sd->num_entries);
@@ -455,7 +462,8 @@ u8 *write_security_data(const struct wim_security_data *sd, u8 *p)
        return p;
 }
 
-static void print_acl(const u8 *p, const char *type)
+static void
+print_acl(const u8 *p, const char *type)
 {
        const ACL *acl = (const ACL*)p;
        u8 revision = acl->revision;
@@ -481,7 +489,8 @@ static void print_acl(const u8 *p, const char *type)
        putchar('\n');
 }
 
-static void print_sid(const u8 *p, const char *type)
+static void
+print_sid(const u8 *p, const char *type)
 {
        const SID *sid = (const SID*)p;
        printf("    [%s SID]\n", type);
@@ -497,7 +506,8 @@ static void print_sid(const u8 *p, const char *type)
        putchar('\n');
 }
 
-static void print_security_descriptor(const u8 *p, u64 size)
+static void
+print_security_descriptor(const u8 *p, u64 size)
 {
        const SecurityDescriptor *sd = (const SecurityDescriptor*)p;
        u8 revision      = sd->revision;
@@ -526,7 +536,8 @@ static void print_security_descriptor(const u8 *p, u64 size)
 /*
  * Prints the security data for a WIM file.
  */
-void print_security_data(const struct wim_security_data *sd)
+void
+print_security_data(const struct wim_security_data *sd)
 {
        wimlib_assert(sd != NULL);
 
@@ -543,7 +554,8 @@ void print_security_data(const struct wim_security_data *sd)
        putchar('\n');
 }
 
-void free_security_data(struct wim_security_data *sd)
+void
+free_security_data(struct wim_security_data *sd)
 {
        if (sd) {
                wimlib_assert(sd->refcnt != 0);
@@ -560,14 +572,17 @@ void free_security_data(struct wim_security_data *sd)
        }
 }
 
-#if defined(WITH_NTFS_3G) || defined(__CYGWIN__) || defined(__WIN32__)
+/* The security tree stuff is only needed when NTFS capture is supported, either
+ * through NTFS-3G or through a native Windows build. */
+#if defined(WITH_NTFS_3G) || defined(__WIN32__)
 struct sd_node {
        int security_id;
        u8 hash[SHA1_HASH_SIZE];
        struct rb_node rb_node;
 };
 
-static void free_sd_tree(struct rb_node *node)
+static void
+free_sd_tree(struct rb_node *node)
 {
        if (node) {
                free_sd_tree(node->rb_left);
@@ -577,13 +592,15 @@ static void free_sd_tree(struct rb_node *node)
 }
 
 /* Frees a security descriptor index set. */
-void destroy_sd_set(struct sd_set *sd_set)
+void
+destroy_sd_set(struct sd_set *sd_set)
 {
        free_sd_tree(sd_set->rb_root.rb_node);
 }
 
 /* Inserts a a new node into the security descriptor index tree. */
-static void insert_sd_node(struct sd_set *set, struct sd_node *new)
+static void
+insert_sd_node(struct sd_set *set, struct sd_node *new)
 {
        struct rb_root *root = &set->rb_root;
        struct rb_node **p = &(root->rb_node);
@@ -607,7 +624,8 @@ static void insert_sd_node(struct sd_set *set, struct sd_node *new)
 
 /* Returns the index of the security descriptor having a SHA1 message digest of
  * @hash.  If not found, return -1. */
-int lookup_sd(struct sd_set *set, const u8 hash[SHA1_HASH_SIZE])
+int
+lookup_sd(struct sd_set *set, const u8 hash[SHA1_HASH_SIZE])
 {
        struct rb_node *node = set->rb_root.rb_node;
 
@@ -631,8 +649,8 @@ int lookup_sd(struct sd_set *set, const u8 hash[SHA1_HASH_SIZE])
  * the security ID for it.  If a new security descriptor cannot be allocated,
  * return -1.
  */
-int sd_set_add_sd(struct sd_set *sd_set, const char descriptor[],
-                 size_t size)
+int
+sd_set_add_sd(struct sd_set *sd_set, const char descriptor[], size_t size)
 {
        u8 hash[SHA1_HASH_SIZE];
        int security_id;
@@ -686,4 +704,4 @@ out_free_node:
 out:
        return -1;
 }
-#endif /* WITH_NTFS_3G || __CYGWIN__ || __WIN32__ */
+#endif /* WITH_NTFS_3G || __WIN32__ */