Using Win32 functions in Visual FoxPro Image Gallery
Security
..msdn
ConvertSidToStringSid
GetAce
GetAclInformation
GetFileSecurity
GetLengthSid
GetNamedSecurityInfo
GetSecurityDescriptorDacl
GetSecurityDescriptorOwner
ImpersonateLoggedOnUser
IsValidSid
IsWellKnownSid
LogonUser
LookupAccountName
LookupAccountSid
LsaClose
LsaEnumerateLogonSessions
LsaFreeMemory
LsaFreeReturnBuffer
LsaGetLogonSessionData
LsaLookupSids
LsaOpenPolicy
RevertToSelf
Code examples:
Accessing LSA Policy object (Local Security Authority)
Obtaining a handle to the desktop associated with the calling thread
Reading security permissions for NTFS files and folders
Reading security permissions for NTFS files and folders

User rating: 0/10 (0 votes)
Rate this code sample:
  • ~
More code examples    Listed functions    Add comment     W32 Constants      Translate this page Printer friendly version of this code sample
Before you begin:
This code sample includes a set of classes implementing several NTFS access control objects. Through these objects, like Access Control List (ACL) and Access Control Entry (ACE) and others, the OS defines access rights to files, folders (in particular) for different users and user groups.

The most familiar interface around NTFS access control objects is shown on the picture below.



An output from the code sample looks much simpler. It retrieves Security Identifiers (SID) for all accounts having allowed/denied access rights to the specified file.


The code also obtains Type, Flags and Mask values for each ACE. These values define access rights and properties like reading, writing, accessing attributes, taking ownership, inheritance and others.

 
  Members area. Log in to view this example.
 
  User name:
  Password:
 
 
  Forgot your password?
 
  Sign up for
the Membership
 
 


User rating: 0/10 (0 votes)
Rate this code sample:
  • ~
6728 bytes  
Created: 2006-05-30 10:48:23  
Modified: 2006-05-30 11:14:12  
Visits in 7 days: 147  
Listed functions:
GetAce
GetAclInformation
GetFileSecurity
GetLastError
GetSecurityDescriptorDacl
IsValidSid
LocalAlloc
LocalFree
LocalSize
LookupAccountSid
Printer friendly API declarations
My comment:
Read also:
Understanding Windows NTFS Permissions, by Derek Melber.

* * *
As you know, VFP strings are widely used instead of pointers in many API calls. Here is an example of GetFileSecurity API function being declared and called using such string as the third parameter passed by reference.

DECLARE INTEGER GetFileSecurity IN advapi32;
        STRING lpFileName, INTEGER RequestedInformation,;
        STRING @pSecurityDescriptor, INTEGER nLength,;
        INTEGER @lpnLengthNeeded

LOCAL cDescriptor, nBufsize
cDescriptor=REPLICATE(Chr(0), 256)
nBufsize=0

= GetFileSecurity(cFile, OWNER_SECURITY_INFORMATION,;
        @cDescriptor, LEN(cDescriptor), @nBufsize)

The code returns no error and the cDescriptor contains meaningful data on exit. But under certain circumstances, the cDescriptor fails while used in subsequent API calls like, for instance, GetSecurityDescriptorDacl.

I have found it far more reliable for this particular function to be declared with pSecurityDescriptor parameter set as Integer.

DECLARE INTEGER GetFileSecurity IN advapi32;
        STRING lpFileName, INTEGER RequestedInformation,;
        INTEGER pSecurityDescriptor, INTEGER nLength,;
        INTEGER @lpnLengthNeeded

Of course, it adds some extra code before and after the call. A memory block must be allocated and eventually released. A very simple LocalMem class handles this with no glitch.
Word Index links for this example:
Translate this page:
  Spanish    Portuguese    German    French    Italian  
FreeTranslation.com offers instant, free translations of text or web pages.
User Contributed Notes:
Walter | 2007-12-13 13:08:00
Hi, How can i get permission information from a file or folder which belongs to the current user?
Walter | 2007-12-13 19:47:18
How I can know if my user has write permission on a folder?

Copyright 2001-2017 News2News, Inc. Before reproducing or distributing any data from this site please ask for an approval from its owner. Unless otherwise specified, this page is for your personal and non-commercial use. The information on this page is presented AS IS, meaning that you may use it at your own risk. Microsoft Visual FoxPro and Windows are trade marks of Microsoft Corp. All other trademarks are the property of their respective owners. 

Privacy policy
Credits: PHP (4.4.9), an HTML-embedded scripting language, MySQL (5.6.38), the Open Source standard SQL database, AceHTML Freeware Version 4, freeware HTML Editor of choice.   Hosted by Korax Online Inc.
Last Topics Visited (54.91.171.137)
5 sec.Function: 'SetCurrentDirectory'
9 sec.Function: 'CeOidGetInfoEx'
15 sec.Function: 'CryptGetProvParam'
21 sec.Function: 'GetTempPath'
28 sec.Function: 'BlockInput'
34 sec.Function: 'GdipCreateBitmapFromGdiDib'
39 sec.Function: 'GetPriorityClass'
45 sec.Function: 'OpenSCManager'
51 sec.Function: 'HeapSize'
57 sec.Function: 'ExpandEnvironmentStrings'
Google
Advertise here!