SetNamedSecurityInfo() returns : Error: (1307)

Jean-Pierre Ribeauville 80 Reputation points
2024-07-03T08:25:49.16+00:00

Hi,

I'm curently trying to buid a chown.exe using Win32API SetNamedSecurityInfo() to change file ownership.

When running this .exe in elevated mode or if the new owner is the same as the current owner, it works file.

But when targetting an other user as targetted one , then

SetNamedSecurityInfo() returns : Error: (1307)

I'don't understand the second part of this documentation related to SetNamedSecurityInfo() :

/* The psidUser ... must be a legally formed SID, and either must match the

TokenUser in Token, or match a group in the TokenGroups in Token where the attributes on the group must include SE_GROUP_OWNER, and must not include

SE_GROUP_USE_FOR_DENY_ONLY.

*/

for info , the targetted owner SID seems correct:

string_sid: S-1-5-21-1628821419-446962477-3960074114-1009

Any help is welcome.

Thanks.

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,609 questions
{count} votes

Accepted answer
  1. RLWA32 45,476 Reputation points
    2024-07-03T09:14:40.02+00:00

    To set the owner SID in a security descriptor to a SID that is not in your own token you need to

    1. Run as Administrator
    2. Enable the SE_RESTORE_NAME privilege in your token

    From Privilege Constants documentation for SE_RESTORE_NAME - - "This privilege causes the system to grant all write access control to any file, regardless of the ACL specified for the file. Any access request other than write is still evaluated with the ACL. Additionally, this privilege enables you to set any valid user or group SID as the owner of a file."

    2 people found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.