<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>JEDI Windows API &#187; DACL</title>
	<atom:link href="http://blog.delphi-jedi.net/tag/dacl/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.delphi-jedi.net</link>
	<description>Joint Endeavor of Delphi Innovators of Windows Programming</description>
	<lastBuildDate>Wed, 19 Oct 2011 18:52:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Setting Folder Security</title>
		<link>http://blog.delphi-jedi.net/2010/03/24/setting-folder-security/</link>
		<comments>http://blog.delphi-jedi.net/2010/03/24/setting-folder-security/#comments</comments>
		<pubDate>Wed, 24 Mar 2010 18:03:38 +0000</pubDate>
		<dc:creator>Christian Wimmer</dc:creator>
				<category><![CDATA[JEDI Windows Security Code Lib]]></category>
		<category><![CDATA[ACL]]></category>
		<category><![CDATA[DACL]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[JWSCL]]></category>
		<category><![CDATA[permission]]></category>

		<guid isPermaLink="false">http://blog.delphi-jedi.net/?p=721</guid>
		<description><![CDATA[This article describes some ways how to set the security on a folder using JWSCL. Usually, we want to add some rights for a particular user to a folder so she gets access. I can say that is a heck of work to do with WinAPI. But still with JWSCL we need to consider some [...]]]></description>
			<content:encoded><![CDATA[<p>This article describes some ways how to set the security on a folder using JWSCL. Usually, we want to add some rights for a particular user to a folder so she gets access. I can say that is a heck of work to do with WinAPI. But still with JWSCL we need to consider some things. <span id="more-721"></span></p>
<p>The following code creates a folder named &#8220;JWSCLTest&#8221; and applies a DACL that allows full control to everyone. The folder will inherit its security settings to child folders and files (check the afXXX flags).</p>
<pre class="brush:delphi">const JWSCLTestFolder = 'JWSCLTestFolder';

var
  SD : TJwSecurityDescriptor;
  pSA : PSecurityAttributes;
begin
  JwInitWellKnownSIDs;

  SD := TJwSecurityDescriptor.Create;
  try
    SD.DACL.Add(TJwDiscretionaryAccessControlEntryAllow.Create(nil,
      [afContainerInheritAce, afObjectInheritAce], FILE_ALL_ACCESS, JwWorldSID));

    pSA := SD.Create_SA();
    try
      Win32Check(CreateDirectory(JWSCLTestFolder, pSA));
    finally
      SD.Free_SA(pSA); //remember to free pointer
    end;
  finally
    SD.Free;
  end;
end.
</pre>
<p>CreateDirectory receives a security attributes structure that is applied to the folder directly. However, in this way the parent security descriptor is not inherited to our folder. This is called a protected DACL because the inheritance flow is stopped. So we get a folder with only one Access Control Entry (ACE) : Everyone (aka World SID).  To remedy that we can copy the ACEs from the parent folder to our own folder:</p>
<pre class="brush:delphi">procedure MergeParentDACL(const Location : String; TargetSD : TJwSecurityDescriptor);
var DirSD : TJwSecureFileObject;
begin
  DirSD := TJwSecureFileObject.Create(Location);
  try
    TargetSD.DACL.AddACEs(DirSD.DACL);
  finally
    DirSD.Free;
  end;
end;

var
  DirSD : TJwSecureFileObject;

  SD, SD2 : TJwSecurityDescriptor;
  pSA : PSecurityAttributes;
begin
  JwInitWellKnownSIDs;

  SD := TJwSecurityDescriptor.Create;

  try
    SD.DACL.Add(TJwDiscretionaryAccessControlEntryAllow.Create(nil,
      [afContainerInheritAce, afObjectInheritAce], FILE_ALL_ACCESS, JwWorldSID));

    MergeParentDACL('.', SD);

    pSA := SD.Create_SA();
    try
      Win32Check(CreateDirectory(JWSCLTestFolder, pSA));
    finally
      SD.Free_SA(pSA);
    end;
  finally
    SD.Free;
  end;
end.
</pre>
<p>The function <em>MergeParentDACL</em> receives the location of the parent folder and retrieves its security settings. Then its DACL is copied to the target security descriptor. JWSCL with <em>TargetSD.DACL.AddACEs</em> makes sure that the order of the ACEs are still correct (first deny then allow entries) by moving them accordingly.</p>
<p>In addition, there is a second, much easier way to achieve the same result.</p>
<pre class="brush:delphi">var
  SD : TJwSecurityDescriptor;
  DirSD : TJwSecureFileObject;
begin
  JwInitWellKnownSIDs;

  Win32Check(CreateDirectory(JWSCLTestFolder, nil));

  DirSD := TJwSecureFileObject.Create(JWSCLTestFolder);
  try
    SD := DirSD.GetSecurityDescriptor([siDaclSecurityInformation]);
    try
      SD.DACL.Add(TJwDiscretionaryAccessControlEntryAllow.Create(nil,
        [afContainerInheritAce, afObjectInheritAce], FILE_ALL_ACCESS, JwWorldSID));

      DirSD.SetSecurityDescriptor(SD, [siDaclSecurityInformation]);
    finally
      SD.Free;
    end;
  finally
    DirSD.Free;
  end;
</pre>
<p>In this way we didn&#8217;t set the security descriptor directly when the folder was created. Nevertheless we get a combination of inheritace ACEs plus the explicit one (JwWorldSID).</p>
<h3>Note</h3>
<p>It is always a good idea to check whether SD.DACL (in above codes) is nil and if so ignore it or create a new and empty one to be used instead. It is always possible that a file or folder comes with a nil DACL which means either no access at all (flag DACLpresent) or everyone has full access (flag DACLpresent not available).</p>
<h3>I used the following JEDI units:</h3>
<pre class="brush:delphi">uses
  JwaWindows,

  JwsclDescriptor,
  JwsclTypes,
  JwsclConstants,
  JwsclKnownSid,
  JwsclAcl,
  JwsclMapping,
  JwsclSecureObjects,
  JwsclSid,
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.delphi-jedi.net/2010/03/24/setting-folder-security/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Restrict access to process</title>
		<link>http://blog.delphi-jedi.net/2008/11/08/restrict-access-to-process/</link>
		<comments>http://blog.delphi-jedi.net/2008/11/08/restrict-access-to-process/#comments</comments>
		<pubDate>Sat, 08 Nov 2008 21:58:11 +0000</pubDate>
		<dc:creator>Christian Wimmer</dc:creator>
				<category><![CDATA[JEDI Windows Security Code Lib]]></category>
		<category><![CDATA[DACL]]></category>
		<category><![CDATA[JWSCL]]></category>
		<category><![CDATA[Process]]></category>

		<guid isPermaLink="false">http://blog.delphi-jedi.net/?p=271</guid>
		<description><![CDATA[The following code is really simple. It restricts access to the current process. In this way no other process can open the process handle and for example terminate this process. uses &#160; JwaWindows, &#160; JwsclSecureObjects, &#160; JwsclDescriptor, &#160; JwsclToken, &#160; JwsclTypes, &#160; JwsclAcl, &#160; JwsclKnownSid; var &#160; SD : TJwSecurityDescriptor; &#160; hProcess : TJwProcessHandle; begin [...]]]></description>
			<content:encoded><![CDATA[<p>The following code is really simple. It restricts access to the current process. In this way no other process can open the process handle and for example terminate this process.</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw1">uses</span><br />
&nbsp; JwaWindows,<br />
&nbsp; JwsclSecureObjects,<br />
&nbsp; JwsclDescriptor,<br />
&nbsp; JwsclToken,<br />
&nbsp; JwsclTypes,<br />
&nbsp; JwsclAcl,<br />
&nbsp; JwsclKnownSid;</p>
<p><span class="kw1">var</span><br />
&nbsp; SD : TJwSecurityDescriptor;<br />
&nbsp; hProcess : TJwProcessHandle;<br />
<span class="kw1">begin</span><br />
&nbsp; JwInitWellKnownSIDs;</p>
<p>&nbsp; hProcess := OpenProcess<span class="br0">&#40;</span>READ_CONTROL <span class="kw1">or</span> WRITE_DAC, <span class="kw2">false</span>, GetCurrentProcessId<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; <span class="kw1">if</span> hProcess &lt;&gt; <span class="nu0">0</span> <span class="kw1">then</span><br />
&nbsp; <span class="kw1">try</span><br />
&nbsp; &nbsp; SD := TJwSecureGeneralObject.<span class="me1">GetSecurityInfo</span><span class="br0">&#40;</span>hProcess,SE_KERNEL_OBJECT, <span class="br0">&#91;</span>siDaclSecurityInformation<span class="br0">&#93;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="kw1">try</span><br />
&nbsp; &nbsp; &nbsp; SD.<span class="me1">DACL</span>.<span class="me1">Clear</span>;<br />
&nbsp; &nbsp; &nbsp; SD.<span class="me1">DACL</span>.<span class="me1">Add</span><span class="br0">&#40;</span>TJwDiscretionaryAccessControlEntryAllow.<span class="me1">Create</span><span class="br0">&#40;</span><span class="kw2">nil</span>, <span class="br0">&#91;</span><span class="br0">&#93;</span>, GENERIC_ALL, JwLocalSystemSID<span class="br0">&#41;</span><span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; <span class="co1">//allow read access to the current user</span><br />
&nbsp; &nbsp; &nbsp; SD.<span class="me1">DACL</span>.<span class="me1">Add</span><span class="br0">&#40;</span>TJwDiscretionaryAccessControlEntryAllow.<span class="me1">Create</span><span class="br0">&#40;</span><span class="kw2">nil</span>, <span class="br0">&#91;</span><span class="br0">&#93;</span>, GENERIC_READ, JwSecurityProcessUserSID<span class="br0">&#41;</span><span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; TJwSecureGeneralObject.<span class="me1">SetSecurityInfo</span><span class="br0">&#40;</span>hProcess, SE_KERNEL_OBJECT, <span class="br0">&#91;</span>siDaclSecurityInformation<span class="br0">&#93;</span>, SD<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="kw1">finally</span><br />
&nbsp; &nbsp; &nbsp; SD.<span class="me1">Free</span>;<br />
&nbsp; &nbsp; <span class="kw1">end</span>;<br />
&nbsp; <span class="kw1">finally</span><br />
&nbsp; &nbsp; CloseHandle<span class="br0">&#40;</span>hProcess<span class="br0">&#41;</span>;<br />
&nbsp; <span class="kw1">end</span>;<br />
<span class="kw1">end</span>;</div>
<p>However there are some problems:</p>
<ol>
<li>This code does not prevent the user from reverting the process DACL to the original state. An owner of the process can always change the DACL even if she is not listed in it. So the code just prevents a beginner from closing the application forcefully.</li>
<li>Any user with the DEBUG privilege can open the process with full access using <em>OpenProcess</em>. The taskmanager uses this way to terminate a process &#8211; if TaskManager is started with administrative rights.</li>
</ol>
<p>The only way to prevent a restricted user from terminating the application is to run the process with a foreign account (e.g. CreateProcessAsUser) and make sure that the user is not listed in the DACL. However if this user gets the DEBUG privilege the game is over.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.delphi-jedi.net/2008/11/08/restrict-access-to-process/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Setting file security with JWSCL</title>
		<link>http://blog.delphi-jedi.net/2008/04/28/setting-file-security-with-jwscl/</link>
		<comments>http://blog.delphi-jedi.net/2008/04/28/setting-file-security-with-jwscl/#comments</comments>
		<pubDate>Mon, 28 Apr 2008 16:12:39 +0000</pubDate>
		<dc:creator>Christian Wimmer</dc:creator>
				<category><![CDATA[JEDI Windows Security Code Lib]]></category>
		<category><![CDATA[ACL]]></category>
		<category><![CDATA[DACL]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[folder]]></category>
		<category><![CDATA[JWSCL]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[Token]]></category>

		<guid isPermaLink="false">http://blog.delphi-jedi.net/?p=170</guid>
		<description><![CDATA[Sometimes it is necessary to change the security settings of a file or folder for getting or denying write access. With JWSCL this task is made very easy. However there are some pitfalls to avoid. The following code will also be available in the example section of the source code. The application gets a file [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes it is necessary to change the security settings of a file or folder for getting or denying write access. With JWSCL this task is made very easy. However there are some pitfalls to avoid.</p>
<p>The following code will also be available in the example section of the source code. The application gets a file or folder name as parameter and tries to add the user with full access control. It even tries to get ownership if it can&#8217;t change the access control list.</p>
<p>First of all we need some JWSCL classes:</p>
<ul>
<li>TJwSecurityDescriptor<br />
A security descriptor contains all information about security of an object. It contains the owner and the access control list (also some other thing, we don&#8217;t need here)</li>
<li>TJwSecureFileObject<br />
This class provides methods to read and write security information on a file or folder. Despite its name it does also support folders. It even supports inheritance.<br />
You can access a file or folder through its name, a handle or the VCL class TFileStream.</li>
<li>TJwDAccessControlList<br />
This class contains methods to maintain a discreationary access control list (DACL). A DACL contains a list of users and their possible access on the object.</li>
<li>TJwSecurityId<br />
Every user is identified by a unique number which is maintained by this class.</li>
<li>TJwSecurityToken<br />
Every logged on user gets a security pass which contains information what she can do or not. We mainly use it to retrieve the user&#8217;s SID (TJwSecurityID)</li>
</ul>
<p>These classes are stored in the JWSCL units. We use the following ones:</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw1">uses</span><br />
&nbsp;JwaWindows,<br />
&nbsp;JwsclSid,<br />
&nbsp;JwsclToken,<br />
&nbsp;JwsclACl,<br />
&nbsp;JwsclDescriptor,<br />
&nbsp;JwsclSecureObjects,<br />
&nbsp;JwsclKnownSid;</div>
<p>The units above are necessary and contain all the classes described earlier Of course we have to declare the classes:</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw1">var</span><br />
&nbsp; UserToken : TJwSecurityToken;<br />
&nbsp; SD : TJwSecurityDescriptor;<br />
&nbsp; FileObject : TJwSecureFileObject;<br />
&nbsp; Owner : TJwSecurityId;<br />
&nbsp; DACL : TJwDAccessControlList;<br />
<span class="kw1">begin</span><br />
&nbsp; <span class="kw1">if</span> <span class="kw1">not</span> <span class="kw3">FileExists</span><span class="br0">&#40;</span><span class="kw3">ParamStr</span><span class="br0">&#40;</span><span class="nu0">1</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="kw1">then</span><br />
&nbsp; &nbsp; <span class="kw3">exit</span>;</div>
<p>This example also shows how we can add well known Security Identifiers (SID) to a secured object. We have to initialize them. The variable JwWorldSID will then contain the correct SID for group Everyone. If we didn&#8217;t call it, we would get nil instead.<br />
JwInitWellKnownSIDs;</p>
<p>The next steps are creating the classes. We get the user name through her token and save the SID into Owner.<br />
Later we will use the Owner instance to add it into the security information of the object.</p>
<div class="dean_ch" style="white-space: wrap;">UserToken := TJwSecurityToken.<span class="me1">CreateTokenEffective</span><span class="br0">&#40;</span>MAXIMUM_ALLOWED<span class="br0">&#41;</span>;<br />
Owner := UserToken.<span class="me1">GetTokenOwner</span>;<br />
<span class="kw1">try</span><br />
&nbsp; FileObject := TJwSecureFileObject.<span class="me1">Create</span><span class="br0">&#40;</span><span class="kw3">ParamStr</span><span class="br0">&#40;</span><span class="nu0">1</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
<p>The actual class which does all the work on the file/folder is TJwSecureFileObject. We just apply the first parameter.</p>
<p>Notice: A user can only change security information of an object if she has the right to do it. There are two options to allow it.</p>
<ol>
<li>The user is listed in the DACL. Additionally the right WRITE_DAC is granted for her.</li>
<li>The user is the owner. In this case she don&#8217;t need to be listed and allowed in the DACL. It is automatically granted</li>
</ol>
<p>We can check both version in one call.</p>
<div class="dean_ch" style="white-space: wrap;"> &nbsp;<span class="kw1">try</span><br />
&nbsp; <span class="kw1">if</span> <span class="kw1">not</span> FileObject.<span class="me1">AccessCheck</span><span class="br0">&#40;</span>WRITE_DAC<span class="br0">&#41;</span><br />
&nbsp; <span class="kw1">begin</span></div>
<p>This call is very easy. If we can&#8217;t change the DACL, we can try to become the owner. The only way to become an owner is to enable a privilege called SE_TAKE_OWNERSHIP_NAME. It is usually only granted to Administrators.</p>
<div class="dean_ch" style="white-space: wrap;"> &nbsp; &nbsp; JwEnablePrivilege<span class="br0">&#40;</span>SE_TAKE_OWNERSHIP_NAME, pst_Enable<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; FileObject.<span class="me1">Owner</span> := Owner;<br />
&nbsp; <span class="kw1">end</span>;</div>
<p>JwEnablePrivilege will fail, if it can&#8217;t activate the privilege. Otherwise we can set the file/folder&#8217;s owner to the token user.</p>
<p>The main work is done here. We get the default DACL from the existing object and adapt it.</p>
<div class="dean_ch" style="white-space: wrap;"> &nbsp; &nbsp;DACL := FileObject.<span class="me1">DACL</span>;</div>
<p>Adaption is done by adding the user to the DACL with full control. We additionally allow the Everyone group to demonstrate the well known Sids initialized by JwInitWellKnownSIDs. The last parameters (false) define that we don&#8217;t want the list to free the given SIDs (Owner and JwWorldSid) automatically.</p>
<div class="dean_ch" style="white-space: wrap;"> &nbsp; &nbsp;DACL.<span class="me1">Add</span><span class="br0">&#40;</span>TJwDiscretionaryAccessControlEntryAllow.<span class="me1">Create</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#40;</span><span class="kw2">nil</span>, <span class="br0">&#91;</span><span class="br0">&#93;</span>, GENERIC_ALL, Owner, <span class="kw2">false</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; DACL.<span class="me1">Add</span><span class="br0">&#40;</span>TJwDiscretionaryAccessControlEntryAllow.<span class="me1">Create</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#40;</span><span class="kw2">nil</span>, <span class="br0">&#91;</span><span class="br0">&#93;</span>, GENERIC_READ, JwWorldSID, <span class="kw2">false</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
<p>And finally we reset the DACL.</p>
<div class="dean_ch" style="white-space: wrap;"> &nbsp; &nbsp;FileObject.<span class="me1">SetDACL</span><span class="br0">&#40;</span>DACL<span class="br0">&#41;</span>;</div>
<p>The DACL of the file or folder will receive the newly created control entries in addition to its existing ones. If it contains inherited entries (entries from a parent folder) they will be conserved. However if you don&#8217;t retrieve the DACL and just use an empty one, all previously existing entries which are not inherited will be removed. Of course the inherited entries will still remain intact.</p>
<p>And of course we free all allocated resources</p>
<div class="dean_ch" style="white-space: wrap;"> &nbsp;<span class="kw1">finally</span><br />
&nbsp; &nbsp; FileObject.<span class="me1">Free</span>;<br />
&nbsp; <span class="kw1">end</span>;</p>
<p><span class="kw1">finally</span><br />
&nbsp; Owner.<span class="me1">Free</span>;<br />
&nbsp; UserToken.<span class="me1">Free</span>;<br />
<span class="kw1">end</span>;<br />
<span class="kw1">end</span>.</div>
<p>Since I cut the source code into pieces, I&#8217;ll show it here in full glory</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw1">program</span> SetFileSecurity;</p>
<p><span class="coMULTI">{$APPTYPE CONSOLE}</span></p>
<p><span class="kw1">uses</span><br />
&nbsp; SysUtils,<br />
&nbsp; JwaWindows,<br />
&nbsp; JwsclSid,<br />
&nbsp; JwsclToken,<br />
&nbsp; JwsclAcl,<br />
&nbsp; JwsclDescriptor,<br />
&nbsp; JwsclSecureObjects,<br />
&nbsp; JwsclKnownSid;</p>
<p><span class="kw1">var</span><br />
&nbsp; UserToken : TJwSecurityToken;<br />
&nbsp; SD : TJwSecurityDescriptor;<br />
&nbsp; FileObject : TJwSecureFileObject;<br />
&nbsp; Owner : TJwSecurityId;<br />
&nbsp; DACL : TJwDAccessControlList;<br />
<span class="kw1">begin</span><br />
&nbsp; <span class="kw1">if</span> <span class="kw1">not</span> <span class="kw3">FileExists</span><span class="br0">&#40;</span><span class="kw3">ParamStr</span><span class="br0">&#40;</span><span class="nu0">1</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="kw1">then</span><br />
&nbsp; &nbsp; <span class="kw3">exit</span>;</p>
<p>&nbsp; JwInitWellKnownSIDs;</p>
<p>&nbsp; UserToken := TJwSecurityToken.<span class="me1">CreateTokenEffective</span><span class="br0">&#40;</span>MAXIMUM_ALLOWED<span class="br0">&#41;</span>;<br />
&nbsp; Owner := UserToken.<span class="me1">GetTokenOwner</span>;<br />
&nbsp; <span class="kw1">try</span><br />
&nbsp; &nbsp; FileObject := TJwSecureFileObject.<span class="me1">Create</span><span class="br0">&#40;</span><span class="kw3">ParamStr</span><span class="br0">&#40;</span><span class="nu0">1</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="kw1">try</span><br />
&nbsp; &nbsp; &nbsp; <span class="co1">//Make me owner if we cant access DACL</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="kw1">not</span> FileObject.<span class="me1">AccessCheck</span><span class="br0">&#40;</span>WRITE_DAC<span class="br0">&#41;</span> <span class="kw1">then</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw1">begin</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//try to become owner</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; JwEnablePrivilege<span class="br0">&#40;</span>SE_TAKE_OWNERSHIP_NAME, pst_Enable<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; FileObject.<span class="me1">Owner</span> := Owner;<br />
&nbsp; &nbsp; &nbsp; <span class="kw1">end</span>;</p>
<p>&nbsp; &nbsp; &nbsp; DACL := FileObject.<span class="me1">DACL</span>;<br />
&nbsp; &nbsp; &nbsp; DACL.<span class="me1">Add</span><span class="br0">&#40;</span>TJwDiscretionaryAccessControlEntryAllow.<span class="me1">Create</span><span class="br0">&#40;</span><span class="kw2">nil</span>, <span class="br0">&#91;</span><span class="br0">&#93;</span>, GENERIC_ALL, Owner, <span class="kw2">false</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; DACL.<span class="me1">Add</span><span class="br0">&#40;</span>TJwDiscretionaryAccessControlEntryAllow.<span class="me1">Create</span><span class="br0">&#40;</span><span class="kw2">nil</span>, <span class="br0">&#91;</span><span class="br0">&#93;</span>, GENERIC_READ, JwWorldSID, <span class="kw2">false</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</p>
<p>&nbsp; &nbsp; &nbsp; FileObject.<span class="me1">SetDACL</span><span class="br0">&#40;</span>DACL<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="kw1">finally</span><br />
&nbsp; &nbsp; &nbsp; FileObject.<span class="me1">Free</span>;<br />
&nbsp; &nbsp; <span class="kw1">end</span>;</p>
<p>&nbsp; <span class="kw1">finally</span><br />
&nbsp; &nbsp; Owner.<span class="me1">Free</span>;<br />
&nbsp; &nbsp; UserToken.<span class="me1">Free</span>;<br />
&nbsp; <span class="kw1">end</span>;<br />
<span class="kw1">end</span>.</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.delphi-jedi.net/2008/04/28/setting-file-security-with-jwscl/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>How to use a Security Attribute structure Part #2</title>
		<link>http://blog.delphi-jedi.net/2008/03/22/how-to-use-a-security-attribute-structure-part-2/</link>
		<comments>http://blog.delphi-jedi.net/2008/03/22/how-to-use-a-security-attribute-structure-part-2/#comments</comments>
		<pubDate>Sat, 22 Mar 2008 16:40:55 +0000</pubDate>
		<dc:creator>Christian Wimmer</dc:creator>
				<category><![CDATA[Common]]></category>
		<category><![CDATA[DACL]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[inheritance]]></category>
		<category><![CDATA[JWSCL]]></category>
		<category><![CDATA[permission]]></category>

		<guid isPermaLink="false">http://blog.delphi-jedi.net/2008/03/22/how-to-use-a-security-attribute-structure-part-2/</guid>
		<description><![CDATA[This discussion continues How to use a SecurityAttribute structure. Last time we used the SecurityAttribute parameter in CreateFile to change the security descriptor of the newly created file. However this approach did not add inherited access control elements from the parent folder. We are about to change that. Filesystem and Registry-key inheritance is implemented since [...]]]></description>
			<content:encoded><![CDATA[<p>This discussion continues <a href="http://blog.delphi-jedi.net/2008/03/04/how-to-use-a-security-attribute-structure" title="Go to blog.">How to use a SecurityAttribute structure</a>.</p>
<p>Last time we used the SecurityAttribute parameter in CreateFile to change the security descriptor of the newly created file. However this approach did not add inherited access control elements from the parent folder. We are about to change that.</p>
<p>Filesystem and Registry-key inheritance is implemented since Windows 2000 and also can be added to Windows NT 4 by installing an update. It is a really convenient way to set security over many files in a complex folder tree.</p>
<p>So what did we last time?</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw1">var</span> SD : TJwSecurityDescriptor;<br />
&nbsp; &nbsp; &nbsp;AliceSid : TJwSecurityId;<br />
&nbsp; &nbsp; &nbsp;SecAttrPtr : PSecurityAttributes;<br />
&nbsp; &nbsp; &nbsp;Handle : <span class="kw4">THandle</span>;<br />
<span class="kw1">begin</span><br />
&nbsp; <span class="kw3">DeleteFile</span><span class="br0">&#40;</span><span class="st0">&#8216;testfile&#8217;</span><span class="br0">&#41;</span>; </p>
<p>&nbsp; SD := TJwSecurityDescriptor.<span class="me1">CreateDefaultByToken</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; AliceSid := TJwSecurityId.<span class="me1">Create</span><span class="br0">&#40;</span><span class="st0">&#8221;</span>,<span class="st0">&#8216;Alice&#8217;</span><span class="br0">&#41;</span>;<br />
&nbsp; SD.<span class="me1">DACL</span>.<span class="me1">Add</span><span class="br0">&#40;</span>TJwDiscretionaryAccessControlEntryAllow.<span class="me1">Create</span><span class="br0">&#40;</span><span class="kw2">nil</span>, <span class="br0">&#91;</span><span class="br0">&#93;</span>, GENERIC_READ, AliceSid, <span class="kw2">true</span><span class="br0">&#41;</span><span class="br0">&#41;</span>; </p>
<p>&nbsp; SecAttrPtr := SD.<span class="me1">Create_SA</span><span class="br0">&#40;</span><span class="br0">&#41;</span>; </p>
<p>&nbsp; <span class="kw1">try</span><br />
&nbsp; &nbsp; Handle := jwaWindows.<span class="me1">CreateFile</span><span class="br0">&#40;</span><span class="st0">&#8216;testfile&#8217;</span>, FILE_ALL_ACCESS, <span class="nu0">0</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw4">Pointer</span><span class="br0">&#40;</span>SecAttrPtr<span class="br0">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CREATE_NEW, FILE_ATTRIBUTE_NORMAL,<span class="nu0">0</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="kw1">if</span> handle = ERROR_INVALID_HANDLE <span class="kw1">then</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw3">RaiseLastOSError</span>;<br />
&nbsp; <span class="kw1">finally</span><br />
&nbsp; &nbsp; SD.<span class="me1">Free</span>;<br />
&nbsp; <span class="kw1">end</span>;<br />
&#8230;</div>
<p>This code assigns a simple security descriptor. In my tests there was no way to let CreateFile add the inherited elements to the DACL. Luckily there are several ways to do so.</p>
<ol>
<li>Get the inherited access elements from the parent and add them to our DACL by hand</li>
<li>Let the system handle inheritance</li>
<li>Do the second way much faster</li>
</ol>
<p><u>1. Get the inherited access elements from the parent and add them to our DACL by hand</u></p>
<p>The first choice needs a lot of work to do. First we need all the inheritable access control elements from the parent folders. This would become very nasty if we had to recursively go up to all parent folders to get the elements. However we are lucky because all inherited ACEs are always available through the direct parent container (if they are not blocked).<br />
Because I will need more time to describe this approach. I&#8217;m going to skip this part for now and discuss it in a separate blog entry.</p>
<p><u>2. Let the system handle inheritance</u></p>
<p><strong>JWSCL </strong>supports inheritance of file, folder and registry keys with the classes <em><a href="http://jwscldoc.delphi-jedi.net/JwsclSecureObjects.TJwSecureFileObject.html">TJwSecureFileObject</a> </em>and <a href="http://jwscldoc.delphi-jedi.net/JwsclSecureObjects.TJwSecureRegistryKey.html"><em>TJwSecureRegistryKey</em></a>. We are going to use only <em>TJwSecureFileObject </em>for our task. However changing permissons and inheritance of a registry key is straight forward and is much the same job as it is with files and folders.</p>
<p><em>TJwSecureFileObject </em>offers three ways to adapt security of a file or folder. You can use a file/folder handle (retrieved by <em>CreateFile</em>), a file or folder name or you use the VCL class <em>TFileStream</em>. However the last variant has some disadvantages like not being able to work with folders.</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw1">var</span> SD : TJwSecurityDescriptor;<br />
&nbsp; &nbsp; AliceSid : TJwSecurityId;<br />
&nbsp; &nbsp; SecAttrPtr : PSecurityAttributes;<br />
&nbsp; &nbsp; Handle : <span class="kw4">THandle</span>;<br />
&nbsp; &nbsp; <span class="kw3">Sec</span> : TJwSecureFileObject;<br />
&nbsp; &nbsp; DACL : TJwDAccessControlList;<br />
<span class="kw1">begin</span> </p>
<p>&nbsp; &#8230;<br />
&nbsp; <span class="me1">SecAttrPtr</span> := SD.<span class="me1">Create_SA</span><span class="br0">&#40;</span><span class="br0">&#41;</span>; </p>
<p>&nbsp; <span class="kw1">try</span><br />
&nbsp; &nbsp; Handle := jwaWindows.<span class="me1">CreateFile</span><span class="br0">&#40;</span><span class="st0">&#8216;testfile&#8217;</span>, FILE_ALL_ACCESS, <span class="nu0">0</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw4">Pointer</span><span class="br0">&#40;</span>SecAttrPtr<span class="br0">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CREATE_NEW, FILE_ATTRIBUTE_NORMAL,<span class="nu0">0</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="kw1">if</span> handle = ERROR_INVALID_HANDLE <span class="kw1">then</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw3">RaiseLastOSError</span>;<br />
&nbsp; <span class="kw1">finally</span><br />
&nbsp; &nbsp; SD.<span class="me1">Free</span>;<br />
&nbsp; <span class="kw1">end</span>; </p>
<p>&nbsp; CloseHandle<span class="br0">&#40;</span>Handle<span class="br0">&#41;</span>;<br />
&nbsp; <span class="kw3">Sec</span> := TJwSecureFileObject.<span class="me1">Create</span><span class="br0">&#40;</span><span class="st0">&#8216;testfile&#8217;</span><span class="br0">&#41;</span>;<br />
&nbsp; DACL := <span class="kw3">Sec</span>.<span class="me1">GetDACL</span>;<br />
&nbsp; <span class="kw1">try</span><br />
&nbsp; &nbsp; <span class="kw3">Sec</span>.<span class="me1">SetDACL</span><span class="br0">&#40;</span>DACL,apUnprotected<span class="br0">&#41;</span>;<br />
&nbsp; <span class="kw1">finally</span><br />
&nbsp; &nbsp; DACL.<span class="me1">Free</span>;<br />
&nbsp; &nbsp; <span class="kw3">Sec</span>.<span class="me1">Free</span>;<br />
&nbsp; <span class="kw1">end</span>;<br />
&#8230;</div>
<p><em>TJwSecureFileObject </em>retrieves the DACL of the file after newly created file was opened. The method <em>SetDACL </em>sets the DACL back but also removes the protection flag from security descriptor control. Thus all the inherited access elements flow to the file&#8217;s access control list.</p>
<p><u>3. Do the second way which is much less to write<br />
</u></p>
<p><em>TJwSecureFileObject </em>offers class methods to act with file or folders much faster. We can either restore the inheritance flow by using the file/folder name&#8230;</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw1">begin</span><br />
&nbsp; <span class="kw3">DeleteFile</span><span class="br0">&#40;</span><span class="st0">&#8216;testfile&#8217;</span><span class="br0">&#41;</span>;<br />
&nbsp; &#8230;<br />
&nbsp; <span class="me1">TJwSecureFileObject</span>.<span class="me1">RestoreInheritanceFlow</span><span class="br0">&#40;</span><span class="st0">&#8216;testfile&#8217;</span><span class="br0">&#41;</span>;<br />
&nbsp; &#8230;</div>
<p>or reestablish the inheritance flow by using a file handle.</p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw1">begin</span><br />
&nbsp; <span class="kw3">DeleteFile</span><span class="br0">&#40;</span><span class="st0">&#8216;testfile&#8217;</span><span class="br0">&#41;</span>;<br />
&nbsp; <span class="kw1">try</span><br />
&nbsp; &nbsp; Handle := jwaWindows.<span class="me1">CreateFile</span><span class="br0">&#40;</span><span class="st0">&#8216;testfile&#8217;</span>, FILE_ALL_ACCESS, <span class="nu0">0</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw4">Pointer</span><span class="br0">&#40;</span>SecAttrPtr<span class="br0">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CREATE_NEW, FILE_ATTRIBUTE_NORMAL,<span class="nu0">0</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp;<span class="kw1">if</span> handle = ERROR_INVALID_HANDLE <span class="kw1">then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span class="kw3">RaiseLastOSError</span>;<br />
&nbsp; &nbsp; TJwSecureFileObject.<span class="me1">RestoreInheritanceFlow</span><span class="br0">&#40;</span>Handle<span class="br0">&#41;</span>;<br />
&nbsp; <span class="kw1">finally</span> &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; SD.<span class="me1">Free</span>; &nbsp; <br />
&nbsp; <span class="kw1">end</span>;</div>
<p>You can use one way or the other.</p>
<p><strong>Tell me how you liked this blog entry by adding a comment.</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.delphi-jedi.net/2008/03/22/how-to-use-a-security-attribute-structure-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Vista: integrity label</title>
		<link>http://blog.delphi-jedi.net/2007/10/27/jwscl-entry/</link>
		<comments>http://blog.delphi-jedi.net/2007/10/27/jwscl-entry/#comments</comments>
		<pubDate>Sat, 27 Oct 2007 14:01:56 +0000</pubDate>
		<dc:creator>Christian Wimmer</dc:creator>
				<category><![CDATA[JEDI Windows Security Code Lib]]></category>
		<category><![CDATA[DACL]]></category>
		<category><![CDATA[integrity label]]></category>
		<category><![CDATA[JWSCL]]></category>
		<category><![CDATA[level]]></category>
		<category><![CDATA[mandatory]]></category>
		<category><![CDATA[security descriptor]]></category>

		<guid isPermaLink="false">http://blog.delphi-jedi.net/2007/10/27/jwscl-entry/</guid>
		<description><![CDATA[I just found this complete example project. It shows how to get the integrity label of a file/folder in Windows Vista. Get Vista integrity label source. program IL; &#160; {$APPTYPE CONSOLE} &#160; uses &#160; Dialogs, &#160; JwaVista, &#160; jwaWindows, &#160; JwsclSecureObjects, &#160; JwsclDescriptor, &#160; JwsclMapping, &#160; JwsclAcl, &#160; JwsclTypes, &#160; SysUtils; &#160; var Path : [...]]]></description>
			<content:encoded><![CDATA[<p>I just found this complete example project. It shows how to get the integrity label of a file/folder in Windows Vista.<br />
Get <a title="Vista integrity label source" href="http://blog.delphi-jedi.net/wp-content/uploads/2008/03/vista-integrity-label-source.zip">Vista integrity label source</a>.<span id="more-3"></span></p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw1">program</span> IL; &nbsp;</p>
<p><span class="coMULTI">{$APPTYPE CONSOLE}</span> &nbsp;</p>
<p><span class="kw1">uses</span><br />
&nbsp; Dialogs,<br />
&nbsp; JwaVista,<br />
&nbsp; jwaWindows,<br />
&nbsp; JwsclSecureObjects,<br />
&nbsp; JwsclDescriptor,<br />
&nbsp; JwsclMapping,<br />
&nbsp; JwsclAcl,<br />
&nbsp; JwsclTypes,<br />
&nbsp; SysUtils; &nbsp;</p>
<p><span class="kw1">var</span> Path : <span class="kw4">String</span>;<br />
&nbsp; &nbsp; IsDir : <span class="kw4">Boolean</span>;<br />
&nbsp; &nbsp; SD : TJwSecurityDescriptor; &nbsp;</p>
<p>&nbsp; &nbsp; H : HANDLE;<br />
<span class="kw1">begin</span><br />
&nbsp; Path := <span class="kw3">ParamStr</span><span class="br0">&#40;</span><span class="nu0">1</span><span class="br0">&#41;</span>;<br />
&nbsp; <span class="kw1">if</span> <span class="kw1">not</span> <span class="kw3">FileExists</span><span class="br0">&#40;</span>Path<span class="br0">&#41;</span> <span class="kw1">and</span> <span class="kw1">not</span> <span class="kw3">DirectoryExists</span><span class="br0">&#40;</span>Path<span class="br0">&#41;</span> <span class="kw1">then</span><br />
&nbsp; &nbsp; <span class="kw3">exit</span>; &nbsp;</p>
<p>&nbsp; IsDir := <span class="kw1">not</span> <span class="kw3">FileExists</span><span class="br0">&#40;</span>Path<span class="br0">&#41;</span> <span class="kw1">and</span> <span class="kw3">DirectoryExists</span><span class="br0">&#40;</span>Path<span class="br0">&#41;</span>; &nbsp;</p>
<p>&nbsp; H := CreateFile<span class="br0">&#40;</span><br />
&nbsp; &nbsp; <span class="kw4">PChar</span><span class="br0">&#40;</span>Path<span class="br0">&#41;</span>,<span class="co1">//LPCTSTR lpFileName,</span><br />
&nbsp; &nbsp; STANDARD_RIGHTS_READ,<span class="co1">//__in &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;DWORD dwDesiredAccess,</span><br />
&nbsp; &nbsp; <span class="nu0">0</span>,<span class="co1">//__in &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;DWORD dwShareMode,</span><br />
&nbsp; &nbsp; <span class="kw2">nil</span> ,<span class="co1">//__in &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;LPSECURITY_ATTRIBUTES lpSecurityAttributes,</span><br />
&nbsp; &nbsp; OPEN_EXISTING,<span class="co1">//__in &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;DWORD dwCreationDisposition,</span><br />
&nbsp; &nbsp; FILE_FLAG_BACKUP_SEMANTICS,<span class="co1">//__in &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;DWORD dwFlagsAndAttributes,</span><br />
&nbsp; &nbsp; <span class="nu0">0</span><span class="co1">//__in &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;HANDLE hTemplateFile</span><br />
&nbsp; <span class="br0">&#41;</span>; &nbsp;</p>
<p>&nbsp; <span class="kw1">if</span> H = INVALID_HANDLE_VALUE <span class="kw1">then</span><br />
&nbsp; &nbsp; <span class="kw3">RaiseLastOSError</span>; &nbsp;</p>
<p>&nbsp; <span class="kw1">try</span><br />
&nbsp; &nbsp; <span class="coMULTI">{We could also directly use GetNamedSecurityInfo}</span><br />
&nbsp; &nbsp; SD := TJwSecureGeneralObject.<span class="me1">GetSecurityInfo</span><span class="br0">&#40;</span>H,SE_FILE_OBJECT,<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span class="br0">&#91;</span>siDaclSecurityInformation,siLabelSecurityInformation<span class="br0">&#93;</span><span class="br0">&#41;</span>; &nbsp;</p>
<p>&nbsp; &nbsp; <span class="kw1">if</span> <span class="kw3">Assigned</span><span class="br0">&#40;</span>SD<span class="br0">&#41;</span> <span class="kw1">then</span><br />
&nbsp; &nbsp; <span class="kw1">begin</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw1">if</span> IsDir <span class="kw1">then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">Writeln</span><span class="br0">&#40;</span>SD.<span class="me1">DACL</span>.<span class="me1">GetTextMap</span><span class="br0">&#40;</span>TJwSecurityFileFolderMapping<span class="br0">&#41;</span><span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw1">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">Writeln</span><span class="br0">&#40;</span>SD.<span class="me1">DACL</span>.<span class="me1">GetTextMap</span><span class="br0">&#40;</span>TJwSecurityFileMapping<span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; <span class="kw1">end</span>; &nbsp;</p>
<p>&nbsp; &nbsp; <span class="kw1">if</span> SD.<span class="me1">AuditACL</span>.<span class="me1">HasMandatoryLabel</span> <span class="kw1">then</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw3">Writeln</span><span class="br0">&#40;</span>SD.<span class="me1">AuditACL</span>.<span class="me1">MandatoryLabel</span>.<span class="me1">SID</span>.<span class="me1">GetText</span><span class="br0">&#41;</span>; &nbsp;</p>
<p>&nbsp; &nbsp; SD.<span class="me1">Free</span>;<br />
&nbsp; <span class="kw1">except</span><br />
&nbsp; &nbsp; <span class="kw1">On</span> E : Exception <span class="kw1">do</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw3">Writeln</span><span class="br0">&#40;</span>E.<span class="me1">Message</span><span class="br0">&#41;</span>; &nbsp;</p>
<p>&nbsp; <span class="kw1">end</span>; &nbsp;</p>
<p>&nbsp; CloseHandle<span class="br0">&#40;</span>H<span class="br0">&#41;</span>; &nbsp;</p>
<p>&nbsp; <span class="kw3">Writeln</span>;<br />
&nbsp; <span class="kw3">writeln</span><span class="br0">&#40;</span><span class="st0">&#8216;[Hit return]&#8216;</span><span class="br0">&#41;</span>;<br />
&nbsp; <span class="kw3">readln</span>;<br />
<span class="kw1">end</span>.</div>
<p><strong><span style="text-decoration: underline;"> There is also a second way to get the integrity label.</span></strong></p>
<div class="dean_ch" style="white-space: wrap;"><span class="kw1">program</span> MandatoryLabel;</p>
<p><span class="coMULTI">{$APPTYPE CONSOLE}</span></p>
<p><span class="kw1">uses</span><br />
&nbsp; JwaWindows, JwaVista, JwsclSecureObjects, JwsclACL, JwsclTypes;</p>
<p><span class="kw1">var</span> F : TJwSecureFileObject;<br />
&nbsp; &nbsp; aLabel : TJwSystemMandatoryAccessControlEntry;<br />
<span class="kw1">begin</span><br />
&nbsp; F := TJwSecureFileObject.<span class="me1">Create</span><span class="br0">&#40;</span><span class="st0">&#8216;C:\&#8217;</span><span class="br0">&#41;</span>;<br />
&nbsp; <span class="kw1">try</span><br />
&nbsp; &nbsp; aLabel := F.<span class="me1">GetMandatoryLabel</span>;<br />
&nbsp; &nbsp; <span class="kw1">if</span> <span class="kw3">Assigned</span><span class="br0">&#40;</span>aLabel<span class="br0">&#41;</span> <span class="kw1">then</span><br />
&nbsp; &nbsp; <span class="kw1">begin</span><br />
&nbsp; &nbsp; &nbsp; <span class="kw3">Writeln</span><span class="br0">&#40;</span>aLabel.<span class="me1">GetText</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; <span class="kw1">if</span> aLabel.<span class="me1">GetMandatoryLevelType</span> = MandatoryLevelHigh <span class="kw1">then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">writeln</span><span class="br0">&#40;</span><span class="st0">&#8216;High integrity level&#8217;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; aLabel.<span class="me1">Free</span>;<br />
&nbsp; &nbsp; <span class="kw1">end</span>;<br />
&nbsp; <span class="kw1">finally</span><br />
&nbsp; &nbsp; F.<span class="me1">Free</span>;<br />
&nbsp; <span class="kw1">end</span>;<br />
<span class="kw1">end</span>.</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.delphi-jedi.net/2007/10/27/jwscl-entry/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

