
User permission for a file in WinNt
Quote:
>The API function I have to use to create a new user is 'NetUserAdd'. (Runs
>OK)
>To assign him to a new net local group, 'NetLocalGroupAddMembers' (Runs OK)
>To assign permissions user-folder, 'GetFileSecurity & SetFileSecurity' (oh,
>oh!)
>Regards and thank you.
Pablo:
Here's the declare's for GetFileSecurity, you should be able to translate to
SetFileSecurity pretty easily.
Const OWNER_SECURITY_INFORMATION = 1
Type ACL
AclRevision As Byte
Sbz1 As Byte
AclSize As Integer
AceCount As Integer
Sbz2 As Integer
End Type
Type SECURITY_DESCRIPTOR
Revision As Byte
Sbz1 As Byte
Control As Long
Owner As Long
Group As Long
Sacl As ACL
Dacl As ACL
End Type
Declare Function GetFileSecurity Lib "advapi32.dll" Alias "GetFileSecurityA"
_
(ByVal lpFileName As String, _
ByVal RequestedInformation As Long, _
SecurityDescriptor As Any, _
ByVal nLength As Long, _
lpnLengthNeeded As Long) As Long
Now, Security Descriptors are a variable length byte array, and can be very
large. You might want to set your byte array as sBuf(8096) As Byte or
something close. Then pass it as sBuf(0) when you call GetFileSecurity.
Generally the only way to know if you've got a long enough byte array is to
call GetFileSecurity and see if it works or not and check the value of
lpnLenthNeeded.
So a call to GetFileSecurity might look like:
Dim sBuf(8096) As Byte
Dim sinSecurityInfo As Long
Dim dwSDLength As Long
Dim dwSDLengthReqd As Long
Dim dwReturn As Long
dwSDLength = 255
sinSecurityInfo = OWNER_SECURITY_INFORMATION
dwreturn = GetFileSecurity(strFileName, _
sinSecurityInfo, _
sBuf(0), _
dwSDLength, _
dwSDLengthReqd)
In working with Security Descriptors and ACLs, the Type defs above really
only represent SD and ACL header information respectively. The SD can trail
on for many bytes following the header. So you have to use a bunch of other
api's to pull out information from the SD.
But I have to admit this stuff is like quick sand. The minute you think you
understand a bit, you find out that NT security is truly a bit complex.
Again I make my recommendation to look at Win32 Network Programming by
Ralph Davis, Addison Wesley Developers Press to begin to get a handle on
it. (I'm certainly a novice in this area myself.)
HTH
Steve Arbaugh
ATTAC Consulting Group
web: http://ourworld.compuserve.com/homepages/attac-cg/acgsoft.htm
To reply, remove ~ and nospm from address