From c9172f66cfaf4bc83280c1bcfce77380222023b7 Mon Sep 17 00:00:00 2001 From: szaka Date: Sun, 2 Sep 2007 12:38:29 +0000 Subject: [PATCH] add ntfs_security_hash(): hash of a security descriptor (Anton Altaparmakov) --- include/ntfs-3g/security.h | 3 +++ libntfs-3g/security.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/include/ntfs-3g/security.h b/include/ntfs-3g/security.h index e903f672..04cc30a9 100644 --- a/include/ntfs-3g/security.h +++ b/include/ntfs-3g/security.h @@ -55,4 +55,7 @@ extern char *ntfs_sid_to_mbs(const SID *sid, char *sid_str, extern void ntfs_generate_guid(GUID *guid); extern int ntfs_sd_add_everyone(ntfs_inode *ni); +extern le32 ntfs_security_hash(const SECURITY_DESCRIPTOR_RELATIVE *sd, + const u32 len); + #endif /* defined _NTFS_SECURITY_H */ diff --git a/libntfs-3g/security.c b/libntfs-3g/security.c index 926a1829..2729ae08 100644 --- a/libntfs-3g/security.c +++ b/libntfs-3g/security.c @@ -43,6 +43,7 @@ #include "attrib.h" #include "security.h" #include "misc.h" +#include "bitmap.h" /* * The zero GUID. @@ -338,3 +339,30 @@ int ntfs_sd_add_everyone(ntfs_inode *ni) return ret; } +/** + * ntfs_security_hash - calculate the hash of a security descriptor + * @sd: self-relative security descriptor whose hash to calculate + * @length: size in bytes of the security descritor @sd + * + * Calculate the hash of the self-relative security descriptor @sd of length + * @length bytes. + * + * This hash is used in the $Secure system file as the primary key for the $SDH + * index and is also stored in the header of each security descriptor in the + * $SDS data stream as well as in the index data of both the $SII and $SDH + * indexes. In all three cases it forms part of the SDS_ENTRY_HEADER + * structure. + * + * Return the calculated security hash in little endian. + */ +le32 ntfs_security_hash(const SECURITY_DESCRIPTOR_RELATIVE *sd, const u32 len) +{ + const le32 *pos = (le32 *)sd; + const le32 *end = pos + (len >> 2); + u32 hash = 0; + + while (pos < end) + hash = le32_to_cpup(pos++) + ntfs_rol32(hash, 3); + return cpu_to_le32(hash); +} +