Recent

Author Topic: Get file/folder and their permissions on Windows  (Read 979 times)

ezlage

  • Sr. Member
  • ****
  • Posts: 317
  • (Silêncio)
    • Lageteck
Get file/folder and their permissions on Windows
« on: June 02, 2020, 05:00:26 am »
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!
Sorry by my poor english.

Atenciosamente,

Ezequiel Lage
ezequiel@lageteck.com

https://github.com/ezlage

ASerge

  • Hero Member
  • *****
  • Posts: 1680
Re: Get file/folder and their permissions on Windows
« Reply #1 on: June 02, 2020, 08:49:17 pm »
Is 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

  • Sr. Member
  • ****
  • Posts: 317
  • (Silêncio)
    • Lageteck
Re: Get file/folder and their permissions on Windows
« Reply #2 on: June 02, 2020, 10:18:01 pm »
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!
« Last Edit: June 02, 2020, 10:19:52 pm by ezlage »
Sorry by my poor english.

Atenciosamente,

Ezequiel Lage
ezequiel@lageteck.com

https://github.com/ezlage

ASerge

  • Hero Member
  • *****
  • Posts: 1680
Re: Get file/folder and their permissions on Windows
« Reply #3 on: June 03, 2020, 07:30:17 pm »
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?
On the same machine? In the same folder?

ezlage

  • Sr. Member
  • ****
  • Posts: 317
  • (Silêncio)
    • Lageteck
Re: Get file/folder and their permissions on Windows
« Reply #4 on: June 03, 2020, 07:33:56 pm »
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?
On the same machine? In the same folder?

Different machines too, also, different folders. It will be necessary to save folders permissions too.
« Last Edit: June 03, 2020, 07:46:32 pm by ezlage »
Sorry by my poor english.

Atenciosamente,

Ezequiel Lage
ezequiel@lageteck.com

https://github.com/ezlage

ASerge

  • Hero Member
  • *****
  • Posts: 1680
Re: Get file/folder and their permissions on Windows
« Reply #5 on: June 04, 2020, 12:01:06 am »
Different 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

  • Sr. Member
  • ****
  • Posts: 317
  • (Silêncio)
    • Lageteck
Re: Get file/folder and their permissions on Windows
« Reply #6 on: June 04, 2020, 12:54:01 am »
Different 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!
« Last Edit: June 04, 2020, 01:07:27 am by ezlage »
Sorry by my poor english.

Atenciosamente,

Ezequiel Lage
ezequiel@lageteck.com

https://github.com/ezlage

440bx

  • Hero Member
  • *****
  • Posts: 2015
Re: Get file/folder and their permissions on Windows
« Reply #7 on: June 04, 2020, 01:19:56 am »
So, 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.

FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.

ezlage

  • Sr. Member
  • ****
  • Posts: 317
  • (Silêncio)
    • Lageteck
Re: Get file/folder and their permissions on Windows
« Reply #8 on: June 04, 2020, 01:43:07 am »
So, 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.
Sorry by my poor english.

Atenciosamente,

Ezequiel Lage
ezequiel@lageteck.com

https://github.com/ezlage

TRon

  • Hero Member
  • *****
  • Posts: 536
Re: Get file/folder and their permissions on Windows
« Reply #9 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).

ezlage

  • Sr. Member
  • ****
  • Posts: 317
  • (Silêncio)
    • Lageteck
Re: Get file/folder and their permissions on Windows
« Reply #10 on: June 04, 2020, 02:37:33 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!
Sorry by my poor english.

Atenciosamente,

Ezequiel Lage
ezequiel@lageteck.com

https://github.com/ezlage

ASBzone

  • Sr. Member
  • ****
  • Posts: 476
  • Automation leads to relaxation...
    • Free BrainWaveCC Console Utilities
Re: Get file/folder and their permissions on Windows
« Reply #11 on: June 04, 2020, 04:37:41 am »
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!

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.
-ASB: https://www.BrainWaveCC.com

Lazarus v2.0.11 r63516 / FPC v3.2.1-r46879 (via FpcUpDeluxe) -- Windows 64-bit install w/32-bit cross-compile
Primary System: Windows 10 Pro x64, Version 2004 (Build 19041.508)
Other Systems: Windows 10 Pro x64, Version 2004 or greater

ezlage

  • Sr. Member
  • ****
  • Posts: 317
  • (Silêncio)
    • Lageteck
Re: Get file/folder and their permissions on Windows
« Reply #12 on: June 04, 2020, 04:55:32 am »
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!

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!
Sorry by my poor english.

Atenciosamente,

Ezequiel Lage
ezequiel@lageteck.com

https://github.com/ezlage

 

TinyPortal © 2005-2018