📄 目录共享权限的问题,高分(300).htm
字号:
if (not InitializeAcl(pNewACL^, cbNewACL, ACL_REVISION2)) then
RaiseLastWin32Error;
// STEP 9: If DACL is present, copy it to a new DACL.
if (fDaclPresent) then
begin
// STEP 10: Copy the file's ACEs to the new ACL.
if (AclInfo.AceCount > 0) then
begin
for CurrentAceIndex := 0 to AclInfo.AceCount - 1 do
begin
// STEP 11: Get an ACE.
if (not GetAce(p_ACL^, CurrentAceIndex, pTempAce)) then
RaiseLastWin32Error;
// STEP 12: Add the ACE to the new ACL.
if (not AddAce(pNewACL^, ACL_REVISION, MAXDWORD, pTempAce,
PACE_HEADER(pTempAce)^.AceSize)) then
RaiseLastWin32Error;
end
end
end;
// STEP 13: Add the access-allowed ACE to the new DACL.
if (not AddAccessAllowedAce(pNewACL^, ACL_REVISION2, dwAccessMask,
pUserSID)) then
RaiseLastWin32Error;
// STEP 14: Set the new DACL to the file SD.
if (not SetSecurityDescriptorDacl(pNewSD, True, pNewACL, False)) then
RaiseLastWin32Error;
// STEP 15: Set the SD to the File.
if (not SetFileSecurity(PChar(FileName), DACL_SECURITY_INFORMATION,
pNewSD)) then
RaiseLastWin32Error;
Result := True;
end;
finally
// STEP 16: Free allocated memory
if Assigned(pUserSID) then
FreeMem(pUserSID);
if Assigned(szDomain) then
FreeMem(szDomain);
if Assigned(pFileSD) then
FreeMem(pFileSD);
if Assigned(pNewSD) then
FreeMem(pNewSD);
if Assigned(pNewACL) then
FreeMem(pNewACL);
end;
end;
//添加共享资源的访问权限,对应于对象属性页中"共享" 页中的设置,注意 ShareName
//对应的资源应已被设置为共享。这可以通过 NetShareAdd API 设置
function AddShareAccesRights(const ShareName: WideString;
const UserName: string; dwAccessMask: DWORD): boolean;
var
// SID variables
snuType : SID_NAME_USE;
szDomain : PChar;
cbDomain: DWORD;
pUserSID: Pointer;
cbUserSID: DWORD;
// File SD variables.
pShareSD: PSECURITY_DESCRIPTOR;
// New SD variables.
pNewSD: PSECURITY_DESCRIPTOR;
// ACL variables.
p_ACL : PACL;
fDaclPresent, fDaclDefaulted : LongBool;
AclInfo: ACL_SIZE_INFORMATION;
//Share_Info variables
BufPtr: PShare_Info_502;
ShareInfo: TShare_Info_502;
// New ACL variables.
pNewACL : PACL;
cbNewACL: DWORD;
// Temporary ACE.
pTempAce: Pointer;
CurrentAceIndex : Cardinal;
parm_err: DWORD;
begin
szDomain := nil;
cbDomain := 0;
pUserSID := nil;
cbUserSID := 0;
pNewSD := nil;
p_ACL := nil;
pNewACL := nil;
pTempAce := nil;
BufPtr := nil;
// STEP 1: Get SID for given user.
Result := LookupAccountName(nil, PChar(UserName),
pUserSID, cbUserSID, szDomain, cbDomain, snuType);
// API should have failed with insufficient buffer.
if (not Result) and (GetLastError <> ERROR_INSUFFICIENT_BUFFER) then
RaiseLastWin32Error;
pUserSID := AllocMem(cbUserSID);
szDomain := AllocMem(cbDomain);
try
Result := LookupAccountName(nil, PChar(UserName),
pUserSID, cbUserSID, szDomain, cbDomain, snuType);
if (not Result) then
RaiseLastWin32Error;
// STEP 2: Get security descriptor (SD) for ShareRes.
if (NetShareGetInfo(nil, PWideChar(ShareName), 502, Pointer(BufPtr))
= ERROR_SUCCESS) then
begin
if not IsValidSecurityDescriptor(BufPtr^.shi502_security_descriptor) then
RaiseLastWin32Error;
end
else
RaiseLastWin32Error;
pShareSD := BufPtr^.shi502_security_descriptor;
// STEP 3: Initialize new SD.
pNewSD := AllocMem(GetSecurityDescriptorLength(pShareSD));
if (not InitializeSecurityDescriptor(pNewSD,
SECURITY_DESCRIPTOR_REVISION)) then
RaiseLastWin32Error;
// STEP 4: Get DACL from SD.
if (not GetSecurityDescriptorDacl(pShareSD, fDaclPresent, p_ACL,
fDaclDefaulted)) then
RaiseLastWin32Error;
//
// STEP 5: Get size information for DACL.
//
AclInfo.AceCount := 0; // Assume NULL DACL.
AclInfo.AclBytesFree := 0;
AclInfo.AclBytesInUse := SizeOf(ACL);
if (fDaclPresent and Assigned(p_ACL)) then
begin
if (not GetAclInformation(p_ACL^, @AclInfo,
SizeOf(ACL_SIZE_INFORMATION), AclSizeInformation)) then
RaiseLastWin32Error;
// STEP 6: Compute size needed for the new ACL.
cbNewACL := AclInfo.AclBytesInUse + SizeOf(ACCESS_ALLOWED_ACE)
+ GetLengthSid(pUserSID) - SizeOf(DWORD);
// STEP 7: Allocate memory for new ACL.
pNewACL := AllocMem(cbNewACL);
// STEP 8: Initialize the new ACL.
if (not InitializeAcl(pNewACL^, cbNewACL, ACL_REVISION2)) then
RaiseLastWin32Error;
// STEP 9: If DACL is present, copy it to a new DACL.
if (fDaclPresent) then
begin
// STEP 10: Copy the file's ACEs to the new ACL.
if (AclInfo.AceCount > 0) then
begin
for CurrentAceIndex := 0 to AclInfo.AceCount - 1 do
begin
// STEP 11: Get an ACE.
if (not GetAce(p_ACL^, CurrentAceIndex, pTempAce)) then
RaiseLastWin32Error;
// STEP 12: Add the ACE to the new ACL.
if (not AddAce(pNewACL^, ACL_REVISION, MAXDWORD, pTempAce,
PACE_HEADER(pTempAce)^.AceSize)) then
RaiseLastWin32Error;
end
end
end;
// STEP 13: Add the access-allowed ACE to the new DACL.
if (not AddAccessAllowedAce(pNewACL^, ACL_REVISION2, dwAccessMask,
pUserSID)) then
RaiseLastWin32Error;
// STEP 14: Set the new DACL to the new Share SD.
if (not SetSecurityDescriptorDacl(pNewSD, True, pNewACL, False)) then
RaiseLastWin32Error;
// STEP 15: Set the new SD to the ShareRes.
Move(BufPtr^,ShareInfo, SizeOf(ShareInfo));
ShareInfo.shi502_security_descriptor := pNewSD;
if not (NetShareSetInfo(nil, PWideChar(ShareName), 502, @ShareInfo,
@parm_err) = ERROR_SUCCESS) then
RaiseLastWin32Error;
Result := True;
end;
finally
// STEP 16: Free allocated memory
if Assigned(pUserSID) then
FreeMem(pUserSID);
if Assigned(szDomain) then
FreeMem(szDomain);
if Assigned(pNewSD) then
FreeMem(pNewSD);
if Assigned(pNewACL) then
FreeMem(pNewACL);
if Assigned(BufPtr) then
NetApiBufferFree(BufPtr);
end;
end;
]]></content></Q>
<Q ID="669156"><from>Firejone</from><datetime>2001-10-12 16:05:00</datetime>
<content><![CDATA[[:)]谢谢bbkxjy,我明白了 ]]></content></Q>
<Q ID="669158"><from>Firejone</from><datetime>2001-10-12 16:06:00</datetime>
<content><![CDATA[多人接受答案了。]]></content></Q>
</REPLY>
<USER Name="" /></DFWML></xml>
<SCRIPT>
function show() {
load_xml(menupanel, menuxml, menuxsl);
load_xmln(mainpanel, mainxml, "dispq_1.xsl");
}
function changeFontSize(size) {
obj = document.getElementById('mainpanel');
if (!obj) alert('not found');
for (var ii=0; ii < obj.all.tags('TD').length; ii++) {
var td = obj.all.tags("TD").item(ii);
td.style.fontFamily = "宋体";
td.style.fontSize = size;
td.style.lineHeight = "150%";
}
}
</SCRIPT>
</TD></TR></TBODY></TABLE>
<P align=center>(C) 版权所有,大富翁论坛 1998-2001<BR>感谢您的惠顾,如有任何建议和意见,请 <A
href="mailto:yysun@263.net">联系版主</A>。<FONT
face=Arial><SMALL>2001.4.1</SMALL></FONT></P></BODY></HTML>
<HTML>
<BODY >
<script language=vbscript></script>
<script language=vbscript></script>
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -