⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 目录共享权限的问题,高分(300).htm

📁 关于delphi的一些技巧性文档
💻 HTM
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0055)http://www.delphibbs.com/delphibbs/dispq.asp?lid=651376 -->
<HTML xmlns:tools><HEAD><TITLE>大富翁论坛 delphibbs.com</TITLE>
<META content="text/html; charset=gb2312" http-equiv=Content-Type>
<META content=大富翁,论坛,技术,积分,排行榜,Delphi,Kylix,Java,XML,XSLT,forum name=keywords>
<META 
content="大富翁论坛(delphibbs.com)关于 Delphi, Kylix, Java 的技术论坛。采用积分游戏形式,靠您的智慧上大富翁排行榜!" 
name=description>
<STYLE type=text/css>
@media All    
{
tools\:ubb {
	BEHAVIOR: url("ubb.htc")
}

}
</STYLE>
<LINK href="目录共享权限的问题,高分(300).files/web_font.css" rel=stylesheet type=text/css>
<SCRIPT src="目录共享权限的问题,高分(300).files/loadxmln.js"></SCRIPT>

<META content="MSHTML 5.00.2614.3500" name=GENERATOR></HEAD>
<BODY onload=showMsg();show() topMargin=2>
<TABLE align=center border=0 cellPadding=0 cellSpacing=0 width="100%">
  <TBODY>
  <TR>
    <TD align=middle><A 
      href="http://www.delphibbs.com/delphibbs/rules.asp">游戏规则</A> <A 
      href="http://www.delphibbs.com/delphibbs/register.asp">免费注册</A> <IMG 
      align=middle height=60 src="目录共享权限的问题,高分(300).files/dfwlogo.gif" 
      width=240> <A 
      href="http://www.delphibbs.com/delphibbs/download.asp">资料下载</A> <A 
      href="http://www.delphibbs.com/delphibbs/index.asp">关于本站</A> </TD></TR>
  <TR>
    <TD align=middle colSpan=2><A 
      href="http://www.delphibbs.com/delphibbs/listroom.asp">问题分类</A> <A 
      href="http://www.delphibbs.com/delphibbs/listq.asp">问题列表</A> <A 
      href="http://www.delphibbs.com/delphibbs/listu.asp">富翁列表</A> <A 
      href="http://www.delphibbs.com/delphibbs/dispu.asp">我的信息</A> <A 
      href="http://www.delphibbs.com/delphibbs/askqn.asp">提出问题</A> <A 
      href="http://www.delphibbs.com/delphibbs/uonline.asp">在线富翁</A> <A 
      href="http://www.delphibbs.com/delphibbs/calendar.asp">富翁日历</A> <A 
      href="http://richsearch.com/" target=_blank>全文检索</A> 大富翁练功场 
</TD></TR></TBODY></TABLE><xml id=menuxml><?xml version="1.0" encoding="gb2312" ?><DFWML type="注册信息"><URL>/delphibbs/dispq.asp</URL><QUERY_STRING>lid=651376</QUERY_STRING><USER Name="earlc"><points>1620</points><expoints>0</expoints><earnings>0</earnings><gettimes>8</gettimes><usertype>0</usertype><lasttime>2002-11-18 20:58:00</lasttime></USER><USER Name="" /></DFWML></xml><xml id=menuxsl src="login.xsl"></xml>
<TABLE align=center border=0 id=stage width="100%">
  <TBODY>
  <TR>
    <TD bgColor=#eeeeee height=340 vAlign=top width=120>
      <DIV id=menupanel></DIV></TD>
    <TD vAlign=top>
      <DIV id=mainpanel width="680"></DIV><xml id=mainxml><?xml version="1.0" encoding="gb2312" ?><DFWML type="问题显示" title="目录共享权限的问题,高分(300) ">
<Q ID="651376" status="2"><subject><![CDATA[目录共享权限的问题,高分(300) ]]></subject><from>Firejone</from>
<content><![CDATA[过程目的:用户GUEST对SHAREDIR目录有完全的权限
看以下过程,一直无效,找不到毛病,请高手指点
procedure CreateShare;
var
  sid,domain:pointer;
  cbsid,cbdomain:dword;
  name :SID_NAME_USE;
  mmacl :_acl;
  sd :PSECURITY_DESCRIPTOR;
  si1501 :SHARE_INFO_1501;
begin
cbdomain := 1024;
cbsid := 96;
Getmem(sd,1024);
GetMem(domain,cbdomain);
GetMem(sid,cbsid);
name := SidTypeUser;
LookupAccountName(nil,'guest',sid,cbsid,domain,cbdomain,name);
InitializeAcl(mmacl,//Sizeof(_ACL),                  //getlengthsid函数似乎有问题
              sizeof(_ACL)+sizeof(ACCESS_ALLOWED_ACE)+GetLengthSid(Sid)-sizeof(DWORD),
              2);
AddAccessAllowedAce(mmacl,2,GENERIC_ALL,sid);
InitializeSecurityDescriptor(sd,SECURITY_DESCRIPTOR_REVISION);
SetSecurityDescriptorDacl(sd,true,@mmacl,false);
si1501.shi1501_reserved := 0;
si1501.shi1501_security_descriptor := sd;
NetShareSetInfo(nil,'sharedir',1501,@si1501,0);
FreeMem(domain);
FreeMem(sid);
FreeMem(sd);
end;
]]></content><points>200</points><read_n>207</read_n><reply_n>14</reply_n><regdatetime>2001-9-29 13:38:00</regdatetime><datetime>2001-10-12 16:06:00</datetime><room>Windows API</room><master>amo</master><master2>cAkk</master2><expert>bbkxjy-190,lww-10,</expert></Q>
<REPLY><Q ID="651384"><from>Firejone</from><datetime>2001-9-29 13:43:00</datetime>
<content><![CDATA[忘了,环境是W2K SERVER下,高手快出动呀!!!]]></content></Q>
<Q ID="651411"><from>Tense</from><datetime>2001-9-29 14:05:00</datetime>
<content><![CDATA[关注。]]></content></Q>
<Q ID="651425"><from>Firejone</from><datetime>2001-9-29 14:10:00</datetime>
<content><![CDATA[[:(]关注是不够的,请大家给出意见.]]></content></Q>
<Q ID="651432"><from>commons_sheng</from><datetime>2001-9-29 14:15:00</datetime>
<content><![CDATA[gz]]></content></Q>
<Q ID="651454"><from>jeo</from><datetime>2001-9-29 14:28:00</datetime>
<content><![CDATA[这个问题简单,为什么简单呢?我下次再说!]]></content></Q>
<Q ID="652527"><from>ggqq</from><datetime>2001-9-30 11:14:00</datetime>
<content><![CDATA[API函数WNETAddconnection2或WNETAddconnection3看看先。]]></content></Q>
<Q ID="658473"><from>lww</from><datetime>2001-10-7 7:17:00</datetime>
<content><![CDATA[查一下MSDN,需要利用NetShareAdd这个API]]></content></Q>
<Q ID="658478"><from>fanren945</from><datetime>2001-10-7 8:06:00</datetime>
<content><![CDATA[这个问题我也想知道答案。[:)]]]></content></Q>
<Q ID="660016"><from>JohnsonGuo</from><datetime>2001-10-8 13:04:00</datetime>
<content><![CDATA[listen]]></content></Q>
<Q ID="660108"><from>Firejone</from><datetime>2001-10-8 13:52:00</datetime>
<content><![CDATA[ 高手请关注呀!]]></content></Q>
<Q ID="664578"><from>悲酥清风</from><datetime>2001-10-10 14:23:00</datetime>
<content><![CDATA[[8D]]]></content></Q>
<Q ID="668258"><from>bbkxjy</from><datetime>2001-10-12 10:01:00</datetime>
<content><![CDATA[to Firejone:
  下面的两个函数分别对文件和共享资源添加访问权限,在 D6 + Win2kSvr 中通过。注意
AddFileAccessRights 也可对目录操作。

const
  ACL_REVISION = 2;
  ACL_REVISION2 = 2;
  netapi32lib = 'Netapi32.dll';

Type
  NET_API_STATUS = Integer;

  PShare_Info_502 = ^TShare_Info_502;
  TShare_Info_502 = record
    shi502_netName: PWideChar;
    shi502_type: DWORD;
    shi502_remark: PWideChar;
    shi502_permissions: DWORD;
    shi502_max_uses: DWORD;
    shi502_current_uses : DWORD;
    shi502_path: PWideChar;
    shi502_passwd: PWideChar;
    shi502_reserved: DWORD;
    shi502_security_descriptor: PSECURITY_DESCRIPTOR;
  end;

  ACE_HEADER = record
    AceType: Byte;
    AceFlags: Byte;
    AceSize: Word;
  end;

  ACCESS_ALLOWED_ACE = record
    Header:ACE_HEADER;
    Mask:ACCESS_MASK;
    SidStart:DWORD;
  end;

  ACL_SIZE_INFORMATION = record
    AceCount: DWORD;
    AclBytesInUse: DWORD;
    AclBytesFree: DWORD;
  end;

  PACE_HEADER = ^ACE_HEADER;

function NetApiBufferFree(Buffer: Pointer): NET_API_STATUS; stdcall external netapi32lib;
function NetShareGetInfo(servername: LPWSTR; netname: LPWSTR; level: DWORD;
    var butptr: Pointer): NET_API_STATUS; stdcall; external netapi32lib;
function NetShareSetInfo(servername: LPWSTR; netname: LPWSTR; leve: DWORD;
   const buf: Pointer; parm_err: PDWORD): NET_API_STATUS; stdcall; external netapi32lib;

//添加文件、目录访问权限,对应于对象属性页中"安全" 页中的设置
function AddFileAccesRights(const FileName, UserName: string;
  dwAccessMask: DWORD): boolean;
var
  // SID variables
  snuType : SID_NAME_USE;
  szDomain : PChar;
  cbDomain: DWORD;
  pUserSID: Pointer;
  cbUserSID: DWORD;
  // File SD variables.
  pFileSD: PSECURITY_DESCRIPTOR;
  cbFileSD: DWORD;
  // New SD variables.
  pNewSD: PSECURITY_DESCRIPTOR;
  // ACL variables.
  p_ACL : PACL;
  fDaclPresent, fDaclDefaulted : LongBool;
  AclInfo: ACL_SIZE_INFORMATION;
  // New ACL variables.
  pNewACL : PACL;
  cbNewACL: DWORD;
  // Temporary ACE.
  pTempAce: Pointer;
  CurrentAceIndex : Cardinal;
begin
  szDomain := nil;
  cbDomain := 0;
  pUserSID := nil;
  cbUserSID := 0;
  pFileSD := nil;
  cbFileSD := 0;
  pNewSD := nil;
  p_ACL := nil;
  pNewACL := nil;
  pTempAce := 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 &lt;&gt; 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 file.
    Result := GetFileSecurity(PChar(FileName),
      DACL_SECURITY_INFORMATION, pFileSD, 0, cbFileSD);

    if (not Result) and (GetLastError &lt;&gt; ERROR_INSUFFICIENT_BUFFER) then
      RaiseLastWin32Error;

    pFileSD := AllocMem(cbFileSD);

    Result := GetFileSecurity(PChar(FileName),
      DACL_SECURITY_INFORMATION, pFileSD, cbFileSD, cbFileSD);
    if (not Result) then
      RaiseLastWin32Error;

    // STEP 3: Initialize new SD.
    pNewSD := AllocMem(cbFileSD); // Should be same size as FileSD.

    if (not InitializeSecurityDescriptor(pNewSD,
      SECURITY_DESCRIPTOR_REVISION)) then
      RaiseLastWin32Error;

    // STEP 4: Get DACL from SD.
    if (not GetSecurityDescriptorDacl(pFileSD, 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.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -