Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copying file security permissions

I'm copying a file from folder A to folder B and then trying to copy the file permissions. Here are the basic steps I'm using:

  1. CopyFile(source, target)
  2. GetNamedSecurityInfo(source, GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION)
  3. Print source SD using ConvertSecurityDescriptorToStringSecurityDescriptor
  4. SetNamedSecurityInfo(target, GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION)
  5. GetNamedSecurityInfo(target, GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION)
  6. Print target SD using ConvertSecurityDescriptorToStringSecurityDescriptor

At #3 I get this SD:

G:S-1-5-21-1454471165-1482476501-839522115-513D:AI(A;ID;0x1200a9;;;BU)(A;ID;0x1301bf;;;PU)(A;ID;FA;;;BA)(A;ID;FA;;;SY)(A;ID;FA;;;S-1-5-21-1454471165-1482476501-839522115-1004)

At #6 I get

G:S-1-5-21-1454471165-1482476501-839522115-513D:AI(A;ID;0x1301bf;;;PU)(A;ID;FA;;;BA)(A;ID;FA;;;SY)

The call to SetNamedSecurityInfo returns ERROR_SUCCESS, yet the results are the source and target file do not have the same SDs. Why is that? What am I doing wrong here?

like image 769
Charles Avatar asked Dec 04 '25 20:12

Charles


2 Answers

SHFileOperation can copy files together with their security attributes, but from your other question I see you're concerned that this won't work within a service. Maybe the following newsgroup discussions will provide some useful information for you:

  • Copy NTFS files with security
  • How to copy a disk file or directory with ALL attributes?
  • Copying files with security attributes
like image 50
ChrisN Avatar answered Dec 06 '25 11:12

ChrisN


Robocopy from the server tools kit http://www.microsoft.com/downloads/details.aspx?familyid=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=en
Will copy all NTFS settigs and ACLs, it's also more robust and reliable than copy/xcopy

like image 31
Martin Beckett Avatar answered Dec 06 '25 09:12

Martin Beckett



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!