目录共享权限的问题,高分(300) (200分)

  • 主题发起人 主题发起人 Firejone
  • 开始时间 开始时间
F

Firejone

Unregistered / Unconfirmed
GUEST, unregistred user!
过程目的:用户GUEST对SHAREDIR目录有完全的权限<br>看以下过程,一直无效,找不到毛病,请高手指点<br>procedure CreateShare;<br>var<br>&nbsp; sid,domain:pointer;<br>&nbsp; cbsid,cbdomain:dword;<br>&nbsp; name :SID_NAME_USE;<br>&nbsp; mmacl :_acl;<br>&nbsp; sd :PSECURITY_DESCRIPTOR;<br>&nbsp; si1501 :SHARE_INFO_1501;<br>begin<br>cbdomain := 1024;<br>cbsid := 96;<br>Getmem(sd,1024);<br>GetMem(domain,cbdomain);<br>GetMem(sid,cbsid);<br>name := SidTypeUser;<br>LookupAccountName(nil,'guest',sid,cbsid,domain,cbdomain,name);<br>InitializeAcl(mmacl,//Sizeof(_ACL), &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//getlengthsid函数似乎有问题<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sizeof(_ACL)+sizeof(ACCESS_ALLOWED_ACE)+GetLengthSid(Sid)-sizeof(DWORD),<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2);<br>AddAccessAllowedAce(mmacl,2,GENERIC_ALL,sid);<br>InitializeSecurityDescriptor(sd,SECURITY_DESCRIPTOR_REVISION);<br>SetSecurityDescriptorDacl(sd,true,@mmacl,false);<br>si1501.shi1501_reserved := 0;<br>si1501.shi1501_security_descriptor := sd;<br>NetShareSetInfo(nil,'sharedir',1501,@si1501,0);<br>FreeMem(domain);<br>FreeMem(sid);<br>FreeMem(sd);<br>end;<br>
 
忘了,环境是W2K SERVER下,高手快出动呀!!!
 
[:(]关注是不够的,请大家给出意见.
 
这个问题简单,为什么简单呢?我下次再说!
 
API函数WNETAddconnection2或WNETAddconnection3看看先。
 
查一下MSDN,需要利用NetShareAdd这个API
 
这个问题我也想知道答案。[:)]
 
高手请关注呀!
 
to Firejone:<br>&nbsp; 下面的两个函数分别对文件和共享资源添加访问权限,在 D6 + Win2kSvr 中通过。注意<br>AddFileAccessRights 也可对目录操作。<br><br>const<br>&nbsp; ACL_REVISION = 2;<br>&nbsp; ACL_REVISION2 = 2;<br>&nbsp; netapi32lib = 'Netapi32.dll';<br><br>Type<br>&nbsp; NET_API_STATUS = Integer;<br><br>&nbsp; PShare_Info_502 = ^TShare_Info_502;<br>&nbsp; TShare_Info_502 = record<br>&nbsp; &nbsp; shi502_netName: PWideChar;<br>&nbsp; &nbsp; shi502_type: DWORD;<br>&nbsp; &nbsp; shi502_remark: PWideChar;<br>&nbsp; &nbsp; shi502_permissions: DWORD;<br>&nbsp; &nbsp; shi502_max_uses: DWORD;<br>&nbsp; &nbsp; shi502_current_uses : DWORD;<br>&nbsp; &nbsp; shi502_path: PWideChar;<br>&nbsp; &nbsp; shi502_passwd: PWideChar;<br>&nbsp; &nbsp; shi502_reserved: DWORD;<br>&nbsp; &nbsp; shi502_security_descriptor: PSECURITY_DESCRIPTOR;<br>&nbsp; end;<br><br>&nbsp; ACE_HEADER = record<br>&nbsp; &nbsp; AceType: Byte;<br>&nbsp; &nbsp; AceFlags: Byte;<br>&nbsp; &nbsp; AceSize: Word;<br>&nbsp; end;<br><br>&nbsp; ACCESS_ALLOWED_ACE = record<br>&nbsp; &nbsp; Header:ACE_HEADER;<br>&nbsp; &nbsp; Mask:ACCESS_MASK;<br>&nbsp; &nbsp; SidStart:DWORD;<br>&nbsp; end;<br><br>&nbsp; ACL_SIZE_INFORMATION = record<br>&nbsp; &nbsp; AceCount: DWORD;<br>&nbsp; &nbsp; AclBytesInUse: DWORD;<br>&nbsp; &nbsp; AclBytesFree: DWORD;<br>&nbsp; end;<br><br>&nbsp; PACE_HEADER = ^ACE_HEADER;<br><br>function NetApiBufferFree(Buffer: Pointer): NET_API_STATUS; stdcall external netapi32lib;<br>function NetShareGetInfo(servername: LPWSTR; netname: LPWSTR; level: DWORD;<br>&nbsp; &nbsp; var butptr: Pointer): NET_API_STATUS; stdcall; external netapi32lib;<br>function NetShareSetInfo(servername: LPWSTR; netname: LPWSTR; leve: DWORD;<br>&nbsp; &nbsp;const buf: Pointer; parm_err: PDWORD): NET_API_STATUS; stdcall; external netapi32lib;<br><br>//添加文件、目录访问权限,对应于对象属性页中"安全" 页中的设置<br>function AddFileAccesRights(const FileName, UserName: string;<br>&nbsp; dwAccessMask: DWORD): boolean;<br>var<br>&nbsp; // SID variables<br>&nbsp; snuType : SID_NAME_USE;<br>&nbsp; szDomain : PChar;<br>&nbsp; cbDomain: DWORD;<br>&nbsp; pUserSID: Pointer;<br>&nbsp; cbUserSID: DWORD;<br>&nbsp; // File SD variables.<br>&nbsp; pFileSD: PSECURITY_DESCRIPTOR;<br>&nbsp; cbFileSD: DWORD;<br>&nbsp; // New SD variables.<br>&nbsp; pNewSD: PSECURITY_DESCRIPTOR;<br>&nbsp; // ACL variables.<br>&nbsp; p_ACL : PACL;<br>&nbsp; fDaclPresent, fDaclDefaulted : LongBool;<br>&nbsp; AclInfo: ACL_SIZE_INFORMATION;<br>&nbsp; // New ACL variables.<br>&nbsp; pNewACL : PACL;<br>&nbsp; cbNewACL: DWORD;<br>&nbsp; // Temporary ACE.<br>&nbsp; pTempAce: Pointer;<br>&nbsp; CurrentAceIndex : Cardinal;<br>begin<br>&nbsp; szDomain := nil;<br>&nbsp; cbDomain := 0;<br>&nbsp; pUserSID := nil;<br>&nbsp; cbUserSID := 0;<br>&nbsp; pFileSD := nil;<br>&nbsp; cbFileSD := 0;<br>&nbsp; pNewSD := nil;<br>&nbsp; p_ACL := nil;<br>&nbsp; pNewACL := nil;<br>&nbsp; pTempAce := nil;<br><br>&nbsp; //<br>&nbsp; // STEP 1: Get SID for given user.<br>&nbsp; //<br>&nbsp; Result := LookupAccountName(nil, PChar(UserName),<br>&nbsp; &nbsp; pUserSID, cbUserSID, szDomain, cbDomain, snuType);<br><br>&nbsp; // API should have failed with insufficient buffer.<br>&nbsp; if (not Result) and (GetLastError &lt;&gt; ERROR_INSUFFICIENT_BUFFER) then<br>&nbsp; &nbsp; RaiseLastWin32Error;<br><br>&nbsp; pUserSID := AllocMem(cbUserSID);<br>&nbsp; szDomain := AllocMem(cbDomain);<br>&nbsp; try<br>&nbsp; &nbsp; Result := LookupAccountName(nil, PChar(UserName),<br>&nbsp; &nbsp; &nbsp; &nbsp;pUserSID, cbUserSID, szDomain, cbDomain, snuType);<br><br>&nbsp; &nbsp; if (not Result) then<br>&nbsp; &nbsp; &nbsp; RaiseLastWin32Error;<br><br>&nbsp; &nbsp; // STEP 2: Get security descriptor (SD) for file.<br>&nbsp; &nbsp; Result := GetFileSecurity(PChar(FileName),<br>&nbsp; &nbsp; &nbsp; DACL_SECURITY_INFORMATION, pFileSD, 0, cbFileSD);<br><br>&nbsp; &nbsp; if (not Result) and (GetLastError &lt;&gt; ERROR_INSUFFICIENT_BUFFER) then<br>&nbsp; &nbsp; &nbsp; RaiseLastWin32Error;<br><br>&nbsp; &nbsp; pFileSD := AllocMem(cbFileSD);<br><br>&nbsp; &nbsp; Result := GetFileSecurity(PChar(FileName),<br>&nbsp; &nbsp; &nbsp; DACL_SECURITY_INFORMATION, pFileSD, cbFileSD, cbFileSD);<br>&nbsp; &nbsp; if (not Result) then<br>&nbsp; &nbsp; &nbsp; RaiseLastWin32Error;<br><br>&nbsp; &nbsp; // STEP 3: Initialize new SD.<br>&nbsp; &nbsp; pNewSD := AllocMem(cbFileSD); // Should be same size as FileSD.<br><br>&nbsp; &nbsp; if (not InitializeSecurityDescriptor(pNewSD,<br>&nbsp; &nbsp; &nbsp; SECURITY_DESCRIPTOR_REVISION)) then<br>&nbsp; &nbsp; &nbsp; RaiseLastWin32Error;<br><br>&nbsp; &nbsp; // STEP 4: Get DACL from SD.<br>&nbsp; &nbsp; if (not GetSecurityDescriptorDacl(pFileSD, fDaclPresent, p_ACL,<br>&nbsp; &nbsp; &nbsp; fDaclDefaulted)) then<br>&nbsp; &nbsp; &nbsp; RaiseLastWin32Error;<br>&nbsp; &nbsp; // STEP 5: Get size information for DACL.<br>&nbsp; &nbsp; AclInfo.AceCount := 0; // Assume NULL DACL.<br>&nbsp; &nbsp; AclInfo.AclBytesFree := 0;<br>&nbsp; &nbsp; AclInfo.AclBytesInUse := SizeOf(ACL);<br><br>&nbsp; &nbsp; if (fDaclPresent and Assigned(p_ACL)) then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; if (not GetAclInformation(p_ACL^, @AclInfo,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SizeOf(ACL_SIZE_INFORMATION), AclSizeInformation)) then<br>&nbsp; &nbsp; &nbsp; &nbsp; RaiseLastWin32Error;<br><br>&nbsp; &nbsp; &nbsp; // STEP 6: Compute size needed for the new ACL.<br>&nbsp; &nbsp; &nbsp; cbNewACL := AclInfo.AclBytesInUse + SizeOf(ACCESS_ALLOWED_ACE)<br>&nbsp; &nbsp; &nbsp; &nbsp; + GetLengthSid(pUserSID) - SizeOf(DWORD);<br><br>&nbsp; &nbsp; &nbsp; // STEP 7: Allocate memory for new ACL.<br>&nbsp; &nbsp; &nbsp; pNewACL := AllocMem(cbNewACL);<br><br>&nbsp; &nbsp; &nbsp; // STEP 8: Initialize the new ACL.<br>&nbsp; &nbsp; &nbsp; if (not InitializeAcl(pNewACL^, cbNewACL, ACL_REVISION2)) then<br>&nbsp; &nbsp; &nbsp; &nbsp; RaiseLastWin32Error;<br>&nbsp; &nbsp; &nbsp; // STEP 9: If DACL is present, copy it to a new DACL.<br>&nbsp; &nbsp; &nbsp; if (fDaclPresent) then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; // STEP 10: Copy the file's ACEs to the new ACL.<br>&nbsp; &nbsp; &nbsp; &nbsp; if (AclInfo.AceCount &gt; 0) then<br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for CurrentAceIndex := 0 to AclInfo.AceCount - 1 do<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // STEP 11: Get an ACE.<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (not GetAce(p_ACL^, CurrentAceIndex, pTempAce)) then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RaiseLastWin32Error;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // STEP 12: Add the ACE to the new ACL.<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (not AddAce(pNewACL^, ACL_REVISION, MAXDWORD, pTempAce,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PACE_HEADER(pTempAce)^.AceSize)) then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RaiseLastWin32Error;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end<br>&nbsp; &nbsp; &nbsp; &nbsp; end<br>&nbsp; &nbsp; &nbsp; end;<br><br>&nbsp; &nbsp; &nbsp; // STEP 13: Add the access-allowed ACE to the new DACL.<br>&nbsp; &nbsp; &nbsp; if (not AddAccessAllowedAce(pNewACL^, ACL_REVISION2, dwAccessMask,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pUserSID)) then<br>&nbsp; &nbsp; &nbsp; &nbsp; RaiseLastWin32Error;<br><br>&nbsp; &nbsp; &nbsp; // STEP 14: Set the new DACL to the file SD.<br>&nbsp; &nbsp; &nbsp; if (not SetSecurityDescriptorDacl(pNewSD, True, pNewACL, False)) then<br>&nbsp; &nbsp; &nbsp; &nbsp; RaiseLastWin32Error;<br><br>&nbsp; &nbsp; &nbsp; // STEP 15: Set the SD to the File.<br>&nbsp; &nbsp; &nbsp; if (not SetFileSecurity(PChar(FileName), DACL_SECURITY_INFORMATION,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pNewSD)) then<br>&nbsp; &nbsp; &nbsp; &nbsp; RaiseLastWin32Error;<br>&nbsp; &nbsp; &nbsp; Result := True;<br>&nbsp; &nbsp; end;<br>&nbsp; finally<br>&nbsp; &nbsp; // STEP 16: Free allocated memory<br>&nbsp; &nbsp; if Assigned(pUserSID) then<br>&nbsp; &nbsp; &nbsp; FreeMem(pUserSID);<br>&nbsp; &nbsp; if Assigned(szDomain) then<br>&nbsp; &nbsp; &nbsp; FreeMem(szDomain);<br>&nbsp; &nbsp; if Assigned(pFileSD) then<br>&nbsp; &nbsp; &nbsp; FreeMem(pFileSD);<br>&nbsp; &nbsp; if Assigned(pNewSD) then<br>&nbsp; &nbsp; &nbsp; FreeMem(pNewSD);<br>&nbsp; &nbsp; if Assigned(pNewACL) then<br>&nbsp; &nbsp; &nbsp; FreeMem(pNewACL);<br>&nbsp; end;<br>end;<br>//添加共享资源的访问权限,对应于对象属性页中"共享" 页中的设置,注意 ShareName<br>//对应的资源应已被设置为共享。这可以通过 NetShareAdd API 设置<br>function AddShareAccesRights(const ShareName: WideString;<br>&nbsp; const UserName: string; dwAccessMask: DWORD): boolean;<br>var<br>&nbsp; // SID variables<br>&nbsp; snuType : SID_NAME_USE;<br>&nbsp; szDomain : PChar;<br>&nbsp; cbDomain: DWORD;<br>&nbsp; pUserSID: Pointer;<br>&nbsp; cbUserSID: DWORD;<br>&nbsp; // File SD variables.<br>&nbsp; pShareSD: PSECURITY_DESCRIPTOR;<br>&nbsp; // New SD variables.<br>&nbsp; pNewSD: PSECURITY_DESCRIPTOR;<br>&nbsp; // ACL variables.<br>&nbsp; p_ACL : PACL;<br>&nbsp; fDaclPresent, fDaclDefaulted : LongBool;<br>&nbsp; AclInfo: ACL_SIZE_INFORMATION;<br>&nbsp; //Share_Info variables<br>&nbsp; BufPtr: PShare_Info_502;<br>&nbsp; ShareInfo: TShare_Info_502;<br>&nbsp; // New ACL variables.<br>&nbsp; pNewACL : PACL;<br>&nbsp; cbNewACL: DWORD;<br>&nbsp; // Temporary ACE.<br>&nbsp; pTempAce: Pointer;<br>&nbsp; CurrentAceIndex : Cardinal;<br>&nbsp; parm_err: DWORD;<br>begin<br>&nbsp; szDomain := nil;<br>&nbsp; cbDomain := 0;<br>&nbsp; pUserSID := nil;<br>&nbsp; cbUserSID := 0;<br>&nbsp; pNewSD := nil;<br>&nbsp; p_ACL := nil;<br>&nbsp; pNewACL := nil;<br>&nbsp; pTempAce := nil;<br>&nbsp; BufPtr := nil;<br><br>&nbsp; // STEP 1: Get SID for given user.<br>&nbsp; Result := LookupAccountName(nil, PChar(UserName),<br>&nbsp; &nbsp; pUserSID, cbUserSID, szDomain, cbDomain, snuType);<br><br>&nbsp; // API should have failed with insufficient buffer.<br>&nbsp; if (not Result) and (GetLastError &lt;&gt; ERROR_INSUFFICIENT_BUFFER) then<br>&nbsp; &nbsp; RaiseLastWin32Error;<br><br>&nbsp; pUserSID := AllocMem(cbUserSID);<br>&nbsp; szDomain := AllocMem(cbDomain);<br>&nbsp; try<br>&nbsp; &nbsp; Result := LookupAccountName(nil, PChar(UserName),<br>&nbsp; &nbsp; &nbsp; &nbsp;pUserSID, cbUserSID, szDomain, cbDomain, snuType);<br><br>&nbsp; &nbsp; if (not Result) then<br>&nbsp; &nbsp; &nbsp; RaiseLastWin32Error;<br><br>&nbsp; &nbsp; // STEP 2: Get security descriptor (SD) for ShareRes.<br>&nbsp; &nbsp; if (NetShareGetInfo(nil, PWideChar(ShareName), 502, Pointer(BufPtr))<br>&nbsp; &nbsp; &nbsp; = ERROR_SUCCESS) then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; if not IsValidSecurityDescriptor(BufPtr^.shi502_security_descriptor) then<br>&nbsp; &nbsp; &nbsp; &nbsp; RaiseLastWin32Error;<br>&nbsp; &nbsp; end<br>&nbsp; &nbsp; else<br>&nbsp; &nbsp; &nbsp; RaiseLastWin32Error;<br><br>&nbsp; &nbsp; pShareSD := BufPtr^.shi502_security_descriptor;<br>&nbsp; &nbsp; // STEP 3: Initialize new SD.<br>&nbsp; &nbsp; pNewSD := AllocMem(GetSecurityDescriptorLength(pShareSD));<br><br>&nbsp; &nbsp; if (not InitializeSecurityDescriptor(pNewSD,<br>&nbsp; &nbsp; &nbsp; SECURITY_DESCRIPTOR_REVISION)) then<br>&nbsp; &nbsp; &nbsp; RaiseLastWin32Error;<br><br>&nbsp; &nbsp; // STEP 4: Get DACL from SD.<br>&nbsp; &nbsp; if (not GetSecurityDescriptorDacl(pShareSD, fDaclPresent, p_ACL,<br>&nbsp; &nbsp; &nbsp; fDaclDefaulted)) then<br>&nbsp; &nbsp; &nbsp; RaiseLastWin32Error;<br>&nbsp; &nbsp; //<br>&nbsp; &nbsp; // STEP 5: Get size information for DACL.<br>&nbsp; &nbsp; //<br>&nbsp; &nbsp; AclInfo.AceCount := 0; // Assume NULL DACL.<br>&nbsp; &nbsp; AclInfo.AclBytesFree := 0;<br>&nbsp; &nbsp; AclInfo.AclBytesInUse := SizeOf(ACL);<br><br>&nbsp; &nbsp; if (fDaclPresent and Assigned(p_ACL)) then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; if (not GetAclInformation(p_ACL^, @AclInfo,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SizeOf(ACL_SIZE_INFORMATION), AclSizeInformation)) then<br>&nbsp; &nbsp; &nbsp; &nbsp; RaiseLastWin32Error;<br><br>&nbsp; &nbsp; &nbsp; // STEP 6: Compute size needed for the new ACL.<br>&nbsp; &nbsp; &nbsp; cbNewACL := AclInfo.AclBytesInUse + SizeOf(ACCESS_ALLOWED_ACE)<br>&nbsp; &nbsp; &nbsp; &nbsp; + GetLengthSid(pUserSID) - SizeOf(DWORD);<br><br>&nbsp; &nbsp; &nbsp; // STEP 7: Allocate memory for new ACL.<br>&nbsp; &nbsp; &nbsp; pNewACL := AllocMem(cbNewACL);<br><br>&nbsp; &nbsp; &nbsp; // STEP 8: Initialize the new ACL.<br>&nbsp; &nbsp; &nbsp; if (not InitializeAcl(pNewACL^, cbNewACL, ACL_REVISION2)) then<br>&nbsp; &nbsp; &nbsp; &nbsp; RaiseLastWin32Error;<br>&nbsp; &nbsp; &nbsp; // STEP 9: If DACL is present, copy it to a new DACL.<br>&nbsp; &nbsp; &nbsp; if (fDaclPresent) then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; // STEP 10: Copy the file's ACEs to the new ACL.<br>&nbsp; &nbsp; &nbsp; &nbsp; if (AclInfo.AceCount &gt; 0) then<br>&nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for CurrentAceIndex := 0 to AclInfo.AceCount - 1 do<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // STEP 11: Get an ACE.<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (not GetAce(p_ACL^, CurrentAceIndex, pTempAce)) then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RaiseLastWin32Error;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // STEP 12: Add the ACE to the new ACL.<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (not AddAce(pNewACL^, ACL_REVISION, MAXDWORD, pTempAce,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PACE_HEADER(pTempAce)^.AceSize)) then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RaiseLastWin32Error;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end<br>&nbsp; &nbsp; &nbsp; &nbsp; end<br>&nbsp; &nbsp; &nbsp; end;<br><br>&nbsp; &nbsp; &nbsp; // STEP 13: Add the access-allowed ACE to the new DACL.<br>&nbsp; &nbsp; &nbsp; if (not AddAccessAllowedAce(pNewACL^, ACL_REVISION2, dwAccessMask,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pUserSID)) then<br>&nbsp; &nbsp; &nbsp; &nbsp; RaiseLastWin32Error;<br><br>&nbsp; &nbsp; &nbsp; // STEP 14: Set the new DACL to the new Share SD.<br>&nbsp; &nbsp; &nbsp; if (not SetSecurityDescriptorDacl(pNewSD, True, pNewACL, False)) then<br>&nbsp; &nbsp; &nbsp; &nbsp; RaiseLastWin32Error;<br><br>&nbsp; &nbsp; &nbsp; // STEP 15: Set the new SD to the ShareRes.<br>&nbsp; &nbsp; &nbsp; Move(BufPtr^,ShareInfo, SizeOf(ShareInfo));<br>&nbsp; &nbsp; &nbsp; ShareInfo.shi502_security_descriptor := pNewSD;<br>&nbsp; &nbsp; &nbsp; if not (NetShareSetInfo(nil, PWideChar(ShareName), 502, @ShareInfo,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @parm_err) = ERROR_SUCCESS) then<br>&nbsp; &nbsp; &nbsp; &nbsp; RaiseLastWin32Error;<br><br>&nbsp; &nbsp; &nbsp; Result := True;<br>&nbsp; &nbsp; end;<br>&nbsp; finally<br>&nbsp; &nbsp; // STEP 16: Free allocated memory<br>&nbsp; &nbsp; if Assigned(pUserSID) then<br>&nbsp; &nbsp; &nbsp; FreeMem(pUserSID);<br>&nbsp; &nbsp; if Assigned(szDomain) then<br>&nbsp; &nbsp; &nbsp; FreeMem(szDomain);<br>&nbsp; &nbsp; if Assigned(pNewSD) then<br>&nbsp; &nbsp; &nbsp; FreeMem(pNewSD);<br>&nbsp; &nbsp; if Assigned(pNewACL) then<br>&nbsp; &nbsp; &nbsp; FreeMem(pNewACL);<br>&nbsp; &nbsp; if Assigned(BufPtr) then<br>&nbsp; &nbsp; &nbsp; NetApiBufferFree(BufPtr);<br>&nbsp; end;<br>end;<br>
 
[:)]谢谢bbkxjy,我明白了
 
多人接受答案了。
 
有没有哪位朋友给一个例子给我看看?就是应用上面朋友给的函数的使用例子?<br>function AddShareAccesRights(const ShareName: WideString;<br>&nbsp; const UserName: string; dwAccessMask: DWORD): boolean;<br>这里的deAccessmask究竟应该是怎样的数据?<br>我不明白,希望有人能给我答复.
 
后退
顶部