From 38dcb707ef9a5f7101a1b52becb831cc05a8da07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Pierre=20Andr=C3=A9?= Date: Thu, 22 May 2014 09:19:52 +0200 Subject: [PATCH] Improved the ownership definition when inheriting and user mapping fails When using the Windows permission inheritance mode and the current user has not been mapped, try to derive a reasonable user from the parent directory. --- libntfs-3g/security.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/libntfs-3g/security.c b/libntfs-3g/security.c index bf8fd6e0..576f769e 100644 --- a/libntfs-3g/security.c +++ b/libntfs-3g/security.c @@ -3787,7 +3787,6 @@ static le32 build_inherited_id(struct SECURITY_CONTEXT *scx, BIGSID defusid; BIGSID defgsid; int offpacl; - int offowner; int offgroup; SECURITY_DESCRIPTOR_RELATIVE *pnhead; ACL *pnacl; @@ -3805,10 +3804,22 @@ static le32 build_inherited_id(struct SECURITY_CONTEXT *scx, if (scx->mapping[MAPUSERS]) { usid = ntfs_find_usid(scx->mapping[MAPUSERS], scx->uid, (SID*)&defusid); gsid = ntfs_find_gsid(scx->mapping[MAPGROUPS], scx->gid, (SID*)&defgsid); +#if OWNERFROMACL + /* Get approximation of parent owner when cannot map */ + if (!gsid) + gsid = adminsid; + if (!usid) { + usid = ntfs_acl_owner(parentattr); + if (!ntfs_is_user_sid(gsid)) + gsid = usid; + } +#else + /* Define owner as root when cannot map */ if (!usid) usid = adminsid; if (!gsid) gsid = adminsid; +#endif } else { /* * If there is no user mapping, we have to copy owner @@ -3816,8 +3827,14 @@ static le32 build_inherited_id(struct SECURITY_CONTEXT *scx, * Windows never has to do that, because it can always * rely on a user mapping */ +#if OWNERFROMACL + usid = ntfs_acl_owner(parentattr); +#else + int offowner; + offowner = le32_to_cpu(pphead->owner); usid = (const SID*)&parentattr[offowner]; +#endif offgroup = le32_to_cpu(pphead->group); gsid = (const SID*)&parentattr[offgroup]; }