Latest Forum Posts

Latest News Posts
Coming Soon!
Social
Go Back   Techgage.com > Software > General Software

General Software Apple, Linux, Windows, alternative OS and software application chat here.

Reply
 
Thread Tools
Old 04-16-2012, 02:18 AM   #1
RainMotorsports
Partition Master
 
RainMotorsports's Avatar
 
Join Date: Jul 2011
Posts: 359
Default Windows File Permissions not inherited when moved only when copied?

I was writing a sync program for someone I mirror for and I noticed when I move the downloaded files after verifying the md5 the permissions are not inherited.

According to Brian Lich a Microsoft Moderator on Technet:
Quote:
When you move a file, it simply updates the file pointers and does not create a new file so the permissions will stay the same. When you copy a file, a new file is created and the permissions on the target folder are inherited. This has been by design for a long time.
I would lay down and accept this but there is a suggestion this isn't 100% the case? I mean he is indeed correct and copying the files from another location does give the new copies permissions of the target folder.

Normally I manually download the files from his primary mirror and cut paste them into the folder. The folder they are downloaded to does not have the permissions for the HTTP and FTP servers. The files moved via cut and paste inherit the permissions...

Not really an issue I can just do a copy and delete instead of a move in code. But is the behaviour of cut and paste in windows different than the Move in API?
__________________
Desktop i5 2500K @ 4.5Ghz | ASUS P8Z68-V PRO | 16GB Corsair Vengeance 1600 | Seasonic X750
MSI GTX570 TF III @ 950/1900/2300 | 2TB 5900 + 2X320GB 7200 RAID0 |
Zalman CNPS9900 MAX
Laptop ASUS G50VT | Core2Duo T9600 @ 3.3Ghz | 9800M GS/GTS @ 650/1625/900
Phone Galaxy SII Epic 4G Touch | CyanogenMod 9 (Nightly 6/20) | FF11 Kernel | FF18 Modem

Last edited by RainMotorsports; 04-16-2012 at 02:24 AM.
RainMotorsports is offline   Reply With Quote
Old 04-16-2012, 06:48 AM   #2
marfig
No ROM battery
 
marfig's Avatar
 
Join Date: May 2011
Posts: 784
Default

I suppose you are using the MoveFile() function in WinAPI?

If that's the case, security descriptors aren't moved with the file when moving across different volumes. This is also by design. Something that Brian Lich apparently forgot to mention, or just didn't think about it because it wasn't in context.

If you wish to preserve file permissions, you will want to use MoveFileEx() with the MOVEFILE_COPY_ALLOWED flag.

Code:
MoveFileEx(szSourceFile, szDestFile, MOVEFILE_COPY_ALLOWED);
That flag will instruct windows to move the file by copying it and then deleting the original, effectively moving the file security descriptors with it.

I don't use the WinAPI often. So you may want to check other means for fast sync. In any case, that's pretty fast in terms of program control. The function doesn't wait for the file to finish being copied and deleted. It just checks if it can be performed and instructs the OS to do it, returning control to the program immediately. If you do want for the function to wait until the operation is flushed to disk before moving to the next file, also use the MOVEFILE_WRITE_THROUGH flag.

Two notes:
1.
This isn't syncing obviously, since the original file would be deleted (and ACLs will be inherited). However the function still returns success if the original can't be deleted, which gives you room to use this function as a sync tool if you make sure to protect the original file from deletion first. But I'm also a bit confused as to why you are using MoveFile() in the context of folder sync

2.
Alternatively, you may want to use GetNamedSecurityInfo() to store the file ACL structure, followed by MoveFile() or CopyFile(), followed by SetNamedSecurityInfo() to set the ACL structure on the new file. This is, I suppose what Robocopy does and it ensures file permissions aren't inherited, but perfectly sync with the original.

And yes, the Windows explorer move and copy operations are performed by following these security descriptor rules.
__________________
NOX COOLBAY Side Window Black; NOX Apex 600w Modular; ASUS P7P55D-E Socket 1156, Sata 6Gb/s & USB 3.0;
Intel Quad Core i5 760 2.80 Ghz @ 3.60 Ghz, 8 Mb de cache; Gskill Ripjaws 4 Gb DDR3 1600 Mhz CL8 Dual Channel;
ASUS GEFORCE GTX 560 TI DC II 1024MB GDDR5; Samsung 1 Tb 32 Mb SpinPoint F3; NEC 24x Sata black
Artic Cooling Freezer 7 Pro Rev.2;
2x Samsung SyncMaster S43NW 8000:1 (1440x900)
Logitech K120 Keyboard and Logitech Performance Mouse MX

Last edited by marfig; 04-16-2012 at 07:12 AM.
marfig is offline   Reply With Quote
Old 04-16-2012, 05:37 PM   #3
RainMotorsports
Partition Master
 
RainMotorsports's Avatar
 
Join Date: Jul 2011
Posts: 359
Default

Well the problem is the file doesn't have the permissions it needs. So im trying to inherit from the destination rather than preserve the original. But either way you have me pointed in the right direction.

The "sync" is between 2 servers and is effectively manual but in code. The primary mirror is a linux server in which I can not install anything on and the secondary mirror is a windows server I have full control of. He provides a sync list that gets parsed. Files are downloaded from their public URL's, the checksum's in the sync list are verified and they are moved from the temporary location to their intended location.

Using MoveFile() the file only has the Users, Administrator, and Administrators permissions same as the folder they were downloaded to. The destination folder has additional permissions for the HTTP and FTP services. Back before i did this with my program I never ran into a problem inheriting permissions cutting and pasting so I was not understanding the behavior in windows.

I am sure there is a solution already out there but I have already written one that just needs some minor fixes. Truthfully i have been out of the saddle for 14 months it was nice to get back in and code for a day. This also allows us to do whats convenient for the "client".

As always marfig thank you.
__________________
Desktop i5 2500K @ 4.5Ghz | ASUS P8Z68-V PRO | 16GB Corsair Vengeance 1600 | Seasonic X750
MSI GTX570 TF III @ 950/1900/2300 | 2TB 5900 + 2X320GB 7200 RAID0 |
Zalman CNPS9900 MAX
Laptop ASUS G50VT | Core2Duo T9600 @ 3.3Ghz | 9800M GS/GTS @ 650/1625/900
Phone Galaxy SII Epic 4G Touch | CyanogenMod 9 (Nightly 6/20) | FF11 Kernel | FF18 Modem

Last edited by RainMotorsports; 04-16-2012 at 06:02 PM.
RainMotorsports is offline   Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
I am moved! Rob Williams Site and Forum Comments & Issues 4 05-06-2012 01:47 AM
Revamped Ribbon-based File Manager Coming to Windows 8 Rob Williams General Software 7 08-30-2011 06:33 PM
Firefox 6 Released; Introduces 'Permissions Manager' & Improved Dev Tools Rob Williams General Software 0 08-15-2011 10:28 AM
Update to private message permissions... Rob Williams Site and Forum Comments & Issues 4 03-15-2008 04:38 PM
Asus WL-700ge and .pst file caspervalentin1 Storage Devices and Memory 1 11-24-2007 01:25 AM


All times are GMT -4. The time now is 11:50 AM.