Get file/folder and their permissions on Windows lazarus / 23-Operating Systems ---------------------------------------------------------------------- ezlage · 2020-06-02 03:00 Hello everybody! Is possible to, using only Lazarus/FPC native stuff, get file or folders and their permissions inside streams on Windows? Could someone explain to me? Thanks! ---------------------------------------------------------------------- ASerge · 2020-06-02 18:49 Quote from: ezlage on June 02, 2020, 05:00:26 amIs possible to, using only Lazarus/FPC native stuff, get file or folders and their permissions inside streams on Windows? What is "inside streams"? The FPC includes headers for WinAPI functions (jwa....). and you can use WinApi to get permissions for directory and files, or (not and!) list of streams inside the file. ---------------------------------------------------------------------- ezlage · 2020-06-02 20:18 Hello ASerge! I want to load a file through some TStream type (store, transport, compress, encrypt, dedup and other purposes). But, when I restore the file, I need to write the exactly same permissions that the file had. Do you have any idea? Thanks! ---------------------------------------------------------------------- ASerge · 2020-06-03 17:30 Quote from: ezlage on June 02, 2020, 10:18:01 pmI want to load a file through some TStream type (store, transport, compress, encrypt, dedup and other purposes). But, when I restore the file, I need to write the exactly same permissions that the file had. Do you have any idea? On the same machine? In the same folder? ---------------------------------------------------------------------- ezlage · 2020-06-03 17:33 Quote from: ASerge on June 03, 2020, 07:30:17 pmQuote from: ezlage on June 02, 2020, 10:18:01 pmI want to load a file through some TStream type (store, transport, compress, encrypt, dedup and other purposes). But, when I restore the file, I need to write the exactly same permissions that the file had. Do you have any idea? On the same machine? In the same folder? Different machines too, also, different folders. It will be necessary to save folders permissions too. ---------------------------------------------------------------------- ASerge · 2020-06-03 22:01 Quote from: ezlage on June 03, 2020, 07:33:56 pmDifferent machines too, also, different folders. It will be necessary to save folders permissions too. In this form, the problem has no solution. On different machines, permissions may be incompatible in principle (different users, groups, and domains). Need to limit the requirements in some way. ---------------------------------------------------------------------- ezlage · 2020-06-03 22:54 Quote from: ASerge on June 04, 2020, 12:01:06 amQuote from: ezlage on June 03, 2020, 07:33:56 pmDifferent machines too, also, different folders. It will be necessary to save folders permissions too. In this form, the problem has no solution. On different machines, permissions may be incompatible in principle (different users, groups, and domains). Need to limit the requirements in some way. So, how a backup software works? I mean, I can start a backup right now and restore files, folders and permissions anywhere. I need to write something like this with Lazarus and FPC. Thank you very much! ---------------------------------------------------------------------- 440bx · 2020-06-03 23:19 Quote from: ezlage on June 04, 2020, 12:54:01 amSo, how backup software works? Backup software and, just about any piece of software that does file handling, is operating system specific.  IOW, it uses services that are O/S specific to open files, get their sizes, permissions, attributes, etc. The Pascal RTL and C's stdlib (among others) can, and do, hide some of the differences among various O/S(s) but, they can only go so far safely.  In addition to that, when it comes to backing up files, different O/S(s) provide different services that differ greatly in methodology and implementation. ---------------------------------------------------------------------- ezlage · 2020-06-03 23:43 Quote from: 440bx on June 04, 2020, 01:19:56 amQuote from: ezlage on June 04, 2020, 12:54:01 amSo, how backup software works? Backup software and, just about any piece of software that does file handling, is operating system specific.  IOW, it uses services that are O/S specific to open files, get their sizes, permissions, attributes, etc. The Pascal RTL and C's stdlib (among others) can, and do, hide some of the differences among various O/S(s) but, they can only go so far safely.  In addition to that, when it comes to backing up files, different O/S(s) provide different services that differ greatly in methodology and implementation. Thanks 440bx! Thanks ASerge! I will take a look at Microsoft documentation and try to figure out the Windows API routines capable of export File and Folder security info. ---------------------------------------------------------------------- TRon · 2020-06-03 23:57 @ezlage, Since (hidden) streams are a filesystem specific feature, you should be looking at NTFS documentation. That m$ decided to make use of this feature is another matter, and yes it might be able to help you out as they had to implement provisions for that. What is definitely not going to work, as already mentioned, is doing this across platforms. You might be able to get away with certain things as long as the platform is similar, but even then you have to deal with a lot of specifics (as already mentioned). ---------------------------------------------------------------------- ezlage · 2020-06-04 00:37 Quote from: TRon on June 04, 2020, 01:57:58 am@ezlage, Since (hidden) streams are a filesystem specific feature, you should be looking at NTFS documentation. That m$ decided to make use of this feature is another matter, and yes it might be able to help you out as they had to implement provisions for that. What is definitely not going to work, as already mentioned, is doing this across platforms. You might be able to get away with certain things as long as the platform is similar, but even then you have to deal with a lot of specifics (as already mentioned). I will do as you suggested, TRon! Thank you! ---------------------------------------------------------------------- ASBzone · 2020-06-04 02:37 Quote from: ezlage on June 04, 2020, 12:54:01 amSo, how a backup software works? I mean, I can start a backup right now and restore files, folders and permissions anywhere. I need to write something like this with Lazarus and FPC. Thank you very much! Backup software is capable of doing this only when the machines in question are from the same Active Directory domain.   If they aren't, there is no software which can make those permissions compatible at the destination. As has been already mentioned, you can certainly store the SID and ACLs of the permissions on the "source" system using the Windows APIs, but whether or not you will be able to apply those permissions to the destination will depend on the AD forest/domain configuration/relationship. ---------------------------------------------------------------------- ezlage · 2020-06-04 02:55 Quote from: ASBzone on June 04, 2020, 04:37:41 amQuote from: ezlage on June 04, 2020, 12:54:01 amSo, how a backup software works? I mean, I can start a backup right now and restore files, folders and permissions anywhere. I need to write something like this with Lazarus and FPC. Thank you very much! Backup software is capable of doing this only when the machines in question are from the same Active Directory domain.   If they aren't, there is no software which can make those permissions compatible at the destination. As has been already mentioned, you can certainly store the SID and ACLs of the permissions on the "source" system using the Windows APIs, but whether or not you will be able to apply those permissions to the destination will depend on the AD forest/domain configuration/relationship. Good point, ASBzone! Luckily, I won't need to restore outside my AD forest/domain. Thank you!