T
tank37
Unregistered / Unconfirmed
GUEST, unregistred user!
我在解决了ACL的权限控制问题的时候发现一个问题不知道改怎么办,希望大家多多讨论<br>在api的原型中枚举enum中的元素是4字节的,在Delphi中的枚举型的元素是一个字节的,不知道要如何处理。<br>关于SetEntriesInAcl原型<br>DWORD SetEntriesInAcl(<br> ULONG cCountOfExplicitEntries,<br> PEXPLICIT_ACCESS pListOfExplicitEntries,<br> PACL OldAcl,<br> PACL* NewAcl<br>);<br><br>typedef struct _EXPLICIT_ACCESS { <br> DWORD grfAccessPermissions;<br> ACCESS_MODE grfAccessMode;<br> DWORD grfInheritance;<br> TRUSTEE Trustee;<br>} EXPLICIT_ACCESS, *PEXPLICIT_ACCESS;<br><br>typedef enum _ACCESS_MODE<br>{<br> NOT_USED_ACCESS = 0, -------- 4 byte<br> GRANT_ACCESS, <br> SET_ACCESS, <br> DENY_ACCESS, <br> REVOKE_ACCESS, <br> SET_AUDIT_SUCCESS, <br> SET_AUDIT_FAILURE<br>} ACCESS_MODE;<br><br>原问题(已经解决,ACL的权限控制)<br>我把问题简单话的说明一下就是关于这个API的使用<br>SetEntriesInAcl<br>请大家快点帮忙看一下,在权限ACL真的搞不定了<br>用下面的方法调用后始终放回码始终是87<br>在winerror.h中87代表参数错误.<br>如果正确调用应当返回0,ERROR_SUCCESS<br><br>以下使用C++实现的,调试通过!!!可是用换成Delphi来写就是不对,请大家帮忙查<br>一下原因<br>#include <Aclapi.h><br> PACL pNewDACL = NULL;<br> EXPLICIT_ACCESS ea;<br> ZeroMemory(&ea, sizeof(EXPLICIT_ACCESS));<br> ea.grfAccessPermissions = GENERIC_ALL;<br> ea.grfAccessMode = SET_ACCESS ;<br> ea.grfInheritance= OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE;<br> ea.Trustee.TrusteeForm = TRUSTEE_IS_NAME;<br> ea.Trustee.TrusteeType=TRUSTEE_IS_USER;<br> ea.Trustee.ptstrName = "userACL";<br> printf("%i, %i, %i/n", SetEntriesInAclA(1, &ea, NULL, &pNewDACL), OBJECT_INHERIT_ACE, CONTAINER_INHERIT_ACE);<br> SetNamedSecurityInfoA("d://v//v",SE_FILE_OBJECT,DACL_SECURITY_INFORMATION,NULL,NULL,pNewDACL,NULL);<br> LocalFree((HLOCAL) pNewDACL); <br><br> printf("acl modifyed!/n");<br><br>以下是Delphi写的,就是SetEntriesInAcl返回值不对,测试通不过。<br>use AccCtrl, ACLApi;<br><br>procedure TForm1.Button2Click(Sender: TObject);<br>const<br> OBJECT_INHERIT_ACE = $1;<br> CONTAINER_INHERIT_ACE = $2;<br>var<br> pNewDACL: PACL;<br> ea: EXPLICIT_ACCESS;<br>begin<br> //CreateDirectory('d:/v/v', nil);<br> pNewDACL := nil;<br> ZeroMemory(@ea, SizeOf(EXPLICIT_ACCESS));<br> ea.grfAccessPermissions := GENERIC_ALL;<br> ea.grfAccessMode := SET_ACCESS;<br> ea.grfInheritance := OBJECT_INHERIT_ACE or CONTAINER_INHERIT_ACE;<br> ea.Trustee.TrusteeForm := TRUSTEE_IS_NAME;<br> ea.Trustee.TrusteeType := TRUSTEE_IS_USER;<br> ea.Trustee.ptstrName := 'userACL';<br> ShowMessage(IntToStr(SetEntriesInAcl(1, @ea, nil, pNewDACL)));<br> //SetNamedSecurityInfoA('d:/v/v',SE_FILE_OBJECT, DACL_SECURITY_INFORMATION, nil, nil, pNewDACL, nil);<br> ShowMessage('er-er-okey!');<br>End;